ident
All repositories: gitoria
4.6 KB
// lib/notify-helpers.hl — what lib/notify.hl looks up: the checks of a kind name, a text and a URL, the time// stamp, the two orders (newest first, by name), on/off words. No table access. Statics only.import { timestamp } from 'hl:time'import { countOf, hasControl, urlChars } from './util.hl'static maxName = 60static maxText = 2000static maxUrl = 2000static bool = (v) => { return v == true }static onOff = (b) => { return b ? 'on' : 'off' }// "YYYY-MM-DD HH:MM UTC" (hl:time knows no zones, hybriel #11)static stamp = (ms) => {if (ms == null) { return '' }t = timestamp(ms)return t.slice(0, 10) + ' ' + t.slice(11, 16) + ' UTC'}// NEWEST FIRST by `created` (a tie by the id); insertion sort by hand (no list sort(), hybriel #6)static idAfter = (a, b) => {let i = 0while (i < a.length && i < b.length) {let x = a.charCodeAt(i)let y = b.charCodeAt(i)if (x != y) { return x > y }i = i + 1}return a.length > b.length}static newerThan = (a, b) => {ca = a.created == null ? 0 : a.createdcb = b.created == null ? 0 : b.createdif (ca != cb) { return ca > cb }return idAfter(a.id, b.id)}static newestFirst = (list) => {out = []if (countOf(list) == 0) { return out }for (x of list) { out.push(x) }let i = 1while (i < out.length) {let cur = out[i]let j = i - 1while (j >= 0 && newerThan(cur, out[j])) {out[j + 1] = out[j]j = j - 1}out[j + 1] = curi = i + 1}return out}// kinds by name, A-Z (char codes)static nameBefore = (a, b) => {x = a.name.toLowerCase()y = b.name.toLowerCase()let i = 0while (i < x.length && i < y.length) {if (x.charCodeAt(i) != y.charCodeAt(i)) { return x.charCodeAt(i) < y.charCodeAt(i) }i = i + 1}return x.length < y.length}static byName = (list) => {out = []if (countOf(list) == 0) { return out }for (x of list) { out.push(x) }let i = 1while (i < out.length) {let cur = out[i]let j = i - 1while (j >= 0 && nameBefore(cur, out[j])) {out[j + 1] = out[j]j = j - 1}out[j + 1] = curi = i + 1}return out}// ---- validation -------------------------------------------------------------------------// A KIND NAME / NOTIFICATION NAME: trimmed, 1-60 chars, one line. Answers { name } or { error }.static checkKindName = (v, what) => {if (v == null || hlTypeName(v) != 'String') { return { error = 'field ' + what + ' must be a string' } }t = v.trim()if (t == '') { return { error = 'field ' + what + ' is empty' } }if (t.length > maxName) { return { error = 'field ' + what + ' is longer than ' + maxName + ' characters' } }if (hasControl(t)) { return { error = 'field ' + what + ' contains a control character' } }return { name = t }}// THE TEXT: 1-2000 chars (Markdown by the worldapi convention; shown as plain text with// its line breaks); tab, line feed and carriage return are the only control charactersstatic checkText = (v) => {if (v == null || hlTypeName(v) != 'String') { return { error = 'field text must be a string' } }t = v.trim()if (t == '') { return { error = 'field text is empty' } }if (t.length > maxText) { return { error = 'field text is longer than ' + maxText + ' characters' } }let i = 0while (i < t.length) {let c = t.charCodeAt(i)if ((c < 32 && c != 9 && c != 10 && c != 13) || c == 127) { return { error = 'field text contains a control character' } }i = i + 1}return { text = t }}// AN ICON / ACTION LINK: an absolute http(s) URL, printable URL characters only, ≤ 2000static checkUrl = (v, what) => {if (v == null || hlTypeName(v) != 'String') { return { error = 'field ' + what + ' must be a string' } }t = v.trim()if (t.length > maxUrl) { return { error = 'field ' + what + ' is longer than ' + maxUrl + ' characters' } }let i = 0while (i < t.length) {if (!urlChars.includes(t[i])) { return { error = 'field ' + what + ' contains a character that is not allowed in a URL' } }i = i + 1}lower = t.toLowerCase()scheme = lower.slice(0, 7) == 'http://' ? 7 : (lower.slice(0, 8) == 'https://' ? 8 : 0)if (scheme == 0) { return { error = 'field ' + what + ' must be an http:// or https:// URL' } }rest = t.slice(scheme, t.length)if (rest == '' || rest[0] == '/' || rest[0] == '?') { return { error = 'field ' + what + ' has no host' } }return { url = t }}// a user's switch over the app's preset: 'on' / 'off', or '' = the presetstatic switchValue = (userValue, preset) => {if (userValue == 'on') { return true }if (userValue == 'off') { return false }return preset}static kindRowOut = (k) => { return { name = k.name push = bool(k.push) email = bool(k.email) } }static unreadCount = (rows) => {let n = 0for (r of rows) { if (r.unread) { n = n + 1 } }return n}
Branches
Latest commits
- 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
- 147744bftests/migration: the fixture app origin follows MIGRATION_GATE_TESTAPP_PORT (oldstore-009 OLD_TESTAPP)mre
- 48cd36bctests/migration: ports from env (MIGRATION_GATE_PORT, MIGRATION_GATE_TESTAPP_PORT); 8395/8396 were taken by a foreign servermre
- 3d9b2fd8docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 19b7e3c3deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- c8a596f4re-vendor Hybriel 66c3db71 (web batch 4); e2e: main menu marked after in-place sign-in is a normal check; report 014mre
- 8f3dc1ectests: delivery allow-list for the stopped server's network errors uses the gate port, not 8700mre
- 9cc8eddftests: notify and iplimit gate Chrome ports from env (NOTIFY_GATE_CHROME, IPLIMIT_GATE_CHROME_A/B)mre
- d6da2d02tests: delivery and migration gate ports from env (DELIVERY_GATE_PORT, DELIVERY_GATE_CHROME, MIGRATION_GATE_CHROME) — hard-coded 8700-8719 collided with a worker during deploymre
- 7276a008ident mission 013: re-vendor Hybriel master f9614007 (#200, #202 mpackdb copy fix); gates and e2e rerunmre
- e13e30c3ident mission 013: report, mission, repro, LOGmre
- eff734f3ident mission 013: in-place sign-out also closes the code step (no leftover code form); checksmre
- b7a61546ident mission 013: e2e — in-place main-menu mark kept as a known gapmre
- 59b43d81ident mission 013: sign out everywhere keeps this browser's own (signed-out) session so the page goes on in placemre
- 716e14ffident mission 013: browser gate — Bob signs out everywhere (no second code request)mre