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
- 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
- 23971fb7ident#49: media queries in the language's @media formmre
- 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
- aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
- ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
- dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
- d277633cident#27: README: identity access and the introspect endpointmre
- e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
- 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
- a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
- d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
- ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
- 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
- c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
- 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