gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita77d1b22a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemrea77d1b22/lib/util.hl

4.6 KB

  1. // lib/util.hl — SMALL SHARED HELPERS of ident (mission 009, code order): the storage directory and env numbers,
  2. // lists and records, ids, text checks, the email shape, oldest-first order. Each one exists once; the topic files
  3. // import what they use. Statics only.
  4. import { env } from 'hl:proc'
  5. import { isZone } from 'hl:time'
  6. // IDENT_STORAGE names another table DIRECTORY (the gates run on their own). Relative
  7. // paths resolve against the ENTRY SCRIPT's directory — tools must pass an absolute one.
  8. static dir = env('IDENT_STORAGE') != null ? env('IDENT_STORAGE') : './storage/mpackdb'
  9. static envNumber = (name, fallback) => {
  10. v = env(name)
  11. if (v == null || v == '') { return fallback }
  12. n = toNumber(v)
  13. return n == null ? fallback : n
  14. }
  15. // an empty list written to hl:mpackdb comes back as an empty hybrid (`.length` null)
  16. static countOf = (list) => {
  17. if (list == null) { return 0 }
  18. n = list.length
  19. return n == null ? 0 : n
  20. }
  21. static first = (list) => { return countOf(list) > 0 ? list[0] : null }
  22. static str = (v) => { return v == null ? '' : v }
  23. static isList = (v) => { return v != null && hlTypeName(v) == 'Hybrid' && v.length != null }
  24. static isObject = (v) => { return v != null && hlTypeName(v) == 'Hybrid' && v.length == null }
  25. // A PUBLIC ID is an mpackdb UUID: a non-empty string (a number is never one — an old
  26. // numeric id from before mission 009 finds nothing)
  27. static isId = (v) => { return v != null && hlTypeName(v) == 'String' && v.length > 0 && v.length <= 64 }
  28. // every record is written as a whole (hl:mpackdb's update replaces it)
  29. static merged = (rec, changes) => {
  30. out = {}
  31. for (k of rec.keys()) { out[k] = rec[k] }
  32. for (k of changes.keys()) { out[k] = changes[k] }
  33. return out
  34. }
  35. // OLDEST FIRST: by the stored `created`, a tie by the id (never by key order)
  36. static olderThan = (a, b) => {
  37. ca = a.created == null ? 0 : a.created
  38. cb = b.created == null ? 0 : b.created
  39. if (ca != cb) { return ca < cb }
  40. return a.id < b.id // strings order by code point (hybriel#2)
  41. }
  42. // a found list, oldest first (insertion sort by hand: no list sort(), hybriel #6)
  43. static oldestFirst = (list) => {
  44. out = []
  45. if (countOf(list) == 0) { return out }
  46. for (x of list) { out.push(x) }
  47. let i = 1
  48. while (i < out.length) {
  49. let cur = out[i]
  50. let j = i - 1
  51. while (j >= 0 && olderThan(cur, out[j])) {
  52. out[j + 1] = out[j]
  53. j = j - 1
  54. }
  55. out[j + 1] = cur
  56. i = i + 1
  57. }
  58. return out
  59. }
  60. // ---- text checks ------------------------------------------------------------------------
  61. // no control characters (a field is one line of text)
  62. static hasControl = (s) => {
  63. let i = 0
  64. while (i < s.length) {
  65. let c = s.charCodeAt(i)
  66. if (c < 32 || c == 127) { return true }
  67. i = i + 1
  68. }
  69. return false
  70. }
  71. // the characters a URL may hold (a return URL, a notification's icon / link)
  72. static urlChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~:/?&=%+,;@!$()*[]'
  73. // AN EMAIL ADDRESS: lowercased and trimmed, then a plain whitelist shape
  74. static normEmail = (email) => { return email == null ? '' : ('' + email).trim().toLowerCase() }
  75. static validEmail = (email) => {
  76. if (email == null || email.length < 3 || email.length > 200) { return false }
  77. at = email.indexOf('@')
  78. if (at < 1 || at != email.lastIndexOf('@') || at == email.length - 1) { return false }
  79. if (!email.slice(at + 1, email.length).includes('.')) { return false }
  80. // a whitelist: the language has no escapes to name a CR or a tab with
  81. ok = 'abcdefghijklmnopqrstuvwxyz0123456789.-_+@'
  82. let i = 0
  83. while (i < email.length) {
  84. if (!ok.includes(email[i])) { return false }
  85. i = i + 1
  86. }
  87. return true
  88. }
  89. // A TIME ZONE is an IANA name as the browser reports it (`Europe/Vienna`, `UTC`,
  90. // `America/Argentina/Buenos_Aires`, `Etc/GMT+5`). The server checks the shape, then asks hl:time's zone database
  91. // (hybriel#5, `isZone`: the system's tz files); the page checks the name against the browser's own list
  92. // (Intl.supportedValuesOf) before it sends it.
  93. static zoneChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/_+-'
  94. static checkTimeZone = (tz) => {
  95. if (tz == null || hlTypeName(tz) != 'String') { return { error = 'the time zone must be a string' } }
  96. t = tz.trim()
  97. if (t == '') { return { error = 'the time zone is empty' } }
  98. if (t.length > 64) { return { error = 'the time zone name is too long' } }
  99. let i = 0
  100. while (i < t.length) {
  101. if (!zoneChars.includes(t[i])) { return { error = 'that is not a time zone name (like Europe/Vienna)' } }
  102. i = i + 1
  103. }
  104. if (t[0] == '/' || t[t.length - 1] == '/' || t.includes('//')) { return { error = 'that is not a time zone name (like Europe/Vienna)' } }
  105. if (!isZone(t)) { return { error = 'unknown time zone: ' + t } }
  106. return { timeZone = t }
  107. }

Branches

Latest commits

  • 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
  • 4ca2ed20404 page in the shell (viewport, status 404, way home); phone: account actions live in the user menu so the open menu covers nothing; mobile gate; signoutall waits for a cold startmre
  • 9baad745tests: browser gate waits for the reloaded document (offline reload race under CPU throttle); HL_CPU_THROTTLE knobmre
  • b96796bdtests: wait for hydration before real clicks after a navigation (H2)mre
  • 9722964fre-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c9b196c9tests/iplimit: wait for the welcome form itself after B's first login (identities list renders before it); mission 017 reportmre
  • 72e0f587ident#26: identity page with "Used in" (app, since, last use, Notif. chip, empty state); lastLogin recorded at exchange; gates + lisbeth E2E; mission 016 reportmre
  • 94576fbcident#26 WIP: identity page /identity/:iid with "Used in" (app, since, last use, Notif. chip), lastLogin recorded at exchange, "Used in…" link on the identities list; apps gate 4b, e2e-usedin.mjsmre
  • 349cb502tests/invites: wait for hydration on the code page before entering the code (native GET submit raced the welcome form); mission 015 reportmre
  • d1bf4720tests: no hard-coded ports — every gate's ports and fixture origins come from <GATE>_PORT / _CHROME env (defaults unchanged; Bob/fixture origins follow, selector cookie name too)mre
  • 6280c92fre-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre