gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6bfbd3f26bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre6bfbd3f2/lib/notify-helpers.hl

4.6 KB

  1. // lib/notify-helpers.hl — what lib/notify.hl looks up: the checks of a kind name, a text and a URL, the time
  2. // stamp, the two orders (newest first, by name), on/off words. No table access. Statics only.
  3. import { timestamp } from 'hl:time'
  4. import { countOf, hasControl, urlChars } from './util.hl'
  5. static maxName = 60
  6. static maxText = 2000
  7. static maxUrl = 2000
  8. static bool = (v) => { return v == true }
  9. static onOff = (b) => { return b ? 'on' : 'off' }
  10. // "YYYY-MM-DD HH:MM UTC" (hl:time knows no zones, hybriel #11)
  11. static stamp = (ms) => {
  12. if (ms == null) { return '' }
  13. t = timestamp(ms)
  14. return t.slice(0, 10) + ' ' + t.slice(11, 16) + ' UTC'
  15. }
  16. // NEWEST FIRST by `created` (a tie by the id); insertion sort by hand (no list sort(), hybriel #6)
  17. static idAfter = (a, b) => {
  18. let i = 0
  19. while (i < a.length && i < b.length) {
  20. let x = a.charCodeAt(i)
  21. let y = b.charCodeAt(i)
  22. if (x != y) { return x > y }
  23. i = i + 1
  24. }
  25. return a.length > b.length
  26. }
  27. static newerThan = (a, b) => {
  28. ca = a.created == null ? 0 : a.created
  29. cb = b.created == null ? 0 : b.created
  30. if (ca != cb) { return ca > cb }
  31. return idAfter(a.id, b.id)
  32. }
  33. static newestFirst = (list) => {
  34. out = []
  35. if (countOf(list) == 0) { return out }
  36. for (x of list) { out.push(x) }
  37. let i = 1
  38. while (i < out.length) {
  39. let cur = out[i]
  40. let j = i - 1
  41. while (j >= 0 && newerThan(cur, out[j])) {
  42. out[j + 1] = out[j]
  43. j = j - 1
  44. }
  45. out[j + 1] = cur
  46. i = i + 1
  47. }
  48. return out
  49. }
  50. // kinds by name, A-Z (char codes)
  51. static nameBefore = (a, b) => {
  52. x = a.name.toLowerCase()
  53. y = b.name.toLowerCase()
  54. let i = 0
  55. while (i < x.length && i < y.length) {
  56. if (x.charCodeAt(i) != y.charCodeAt(i)) { return x.charCodeAt(i) < y.charCodeAt(i) }
  57. i = i + 1
  58. }
  59. return x.length < y.length
  60. }
  61. static byName = (list) => {
  62. out = []
  63. if (countOf(list) == 0) { return out }
  64. for (x of list) { out.push(x) }
  65. let i = 1
  66. while (i < out.length) {
  67. let cur = out[i]
  68. let j = i - 1
  69. while (j >= 0 && nameBefore(cur, out[j])) {
  70. out[j + 1] = out[j]
  71. j = j - 1
  72. }
  73. out[j + 1] = cur
  74. i = i + 1
  75. }
  76. return out
  77. }
  78. // ---- validation -------------------------------------------------------------------------
  79. // A KIND NAME / NOTIFICATION NAME: trimmed, 1-60 chars, one line. Answers { name } or { error }.
  80. static checkKindName = (v, what) => {
  81. if (v == null || hlTypeName(v) != 'String') { return { error = 'field ' + what + ' must be a string' } }
  82. t = v.trim()
  83. if (t == '') { return { error = 'field ' + what + ' is empty' } }
  84. if (t.length > maxName) { return { error = 'field ' + what + ' is longer than ' + maxName + ' characters' } }
  85. if (hasControl(t)) { return { error = 'field ' + what + ' contains a control character' } }
  86. return { name = t }
  87. }
  88. // THE TEXT: 1-2000 chars (Markdown by the worldapi convention; shown as plain text with
  89. // its line breaks); tab, line feed and carriage return are the only control characters
  90. static checkText = (v) => {
  91. if (v == null || hlTypeName(v) != 'String') { return { error = 'field text must be a string' } }
  92. t = v.trim()
  93. if (t == '') { return { error = 'field text is empty' } }
  94. if (t.length > maxText) { return { error = 'field text is longer than ' + maxText + ' characters' } }
  95. let i = 0
  96. while (i < t.length) {
  97. let c = t.charCodeAt(i)
  98. if ((c < 32 && c != 9 && c != 10 && c != 13) || c == 127) { return { error = 'field text contains a control character' } }
  99. i = i + 1
  100. }
  101. return { text = t }
  102. }
  103. // AN ICON / ACTION LINK: an absolute http(s) URL, printable URL characters only, ≤ 2000
  104. static checkUrl = (v, what) => {
  105. if (v == null || hlTypeName(v) != 'String') { return { error = 'field ' + what + ' must be a string' } }
  106. t = v.trim()
  107. if (t.length > maxUrl) { return { error = 'field ' + what + ' is longer than ' + maxUrl + ' characters' } }
  108. let i = 0
  109. while (i < t.length) {
  110. if (!urlChars.includes(t[i])) { return { error = 'field ' + what + ' contains a character that is not allowed in a URL' } }
  111. i = i + 1
  112. }
  113. lower = t.toLowerCase()
  114. scheme = lower.slice(0, 7) == 'http://' ? 7 : (lower.slice(0, 8) == 'https://' ? 8 : 0)
  115. if (scheme == 0) { return { error = 'field ' + what + ' must be an http:// or https:// URL' } }
  116. rest = t.slice(scheme, t.length)
  117. if (rest == '' || rest[0] == '/' || rest[0] == '?') { return { error = 'field ' + what + ' has no host' } }
  118. return { url = t }
  119. }
  120. // a user's switch over the app's preset: 'on' / 'off', or '' = the preset
  121. static switchValue = (userValue, preset) => {
  122. if (userValue == 'on') { return true }
  123. if (userValue == 'off') { return false }
  124. return preset
  125. }
  126. static kindRowOut = (k) => { return { name = k.name push = bool(k.push) email = bool(k.email) } }
  127. static unreadCount = (rows) => {
  128. let n = 0
  129. for (r of rows) { if (r.unread) { n = n + 1 } }
  130. return n
  131. }

Branches

Latest commits

  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • 80965c08ident#28: README says the deploy goes through the standbymre
  • 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
  • a544b261ident#28: README names the new vendored Hybrielmre
  • 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
  • 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
  • f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre
  • d8be66ebident: report and log line for the widget cache and frame height changemre
  • 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre
  • a22d2daaident#31: the sign-in frame is no taller than the tallest step needs (plain CSS height per width), gate check for itmre
  • a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemre
  • 5c481bfdident#31: sign in to ident inside the selector's panel (email, code, identity in an iframe; a new address goes to ident in the same tab and comes back)mre
  • 061abfe2ident: the apps gate waits until the test app's login button stops moving before it clicks (the page grows after load and the click missed about every second run)mre
  • 45f7e4daident: the user menu's Sign out waits for the server before it reloads (the apps gate failed because the session could still be signed in)mre
  • f07658c7ident: home page shows the account once (account bar removed, the user menu carries email, Sign out, Sign out everywhere); wildcard origins https://*.domain for apps on many subdomains; gates follow (WIP: gates not re-run after the last edits)mre
  • f2c43bbbtheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 6d4f996esessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 029eb5e5deploy: security gate (tests/security.mjs)mre
  • d3c065a8security audit (SI): uploadMax 0, Secure __Host- cookie behind https, headers on function routes/files, page CSP+referrer meta, app/identity caps, tests/security.mjs, reportmre
  • 5561a0cbreport I4-mobilemre