gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5561a0cb5561a0cbreport I4-mobilemre5561a0cb/project.hl

9.2 KB

  1. // project.hl — ident.worldapi.org: THE MAP. Config, routes and wiring; the logic lives in lib/. Concept: CONCEPT.md
  2. // (the creator's).
  3. //
  4. // WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):
  5. // the login: email → code, limits per address / IP, the code page lib/login.hl (codes, IP buckets: lib/login-helpers.hl)
  6. // the account, its sessions, sign out everywhere, time zone lib/accounts.hl
  7. // identities, the short id, avatar lib/identities.hl (checks, label: lib/identities-helpers.hl)
  8. // apps, connections, the login button + exchange, an invite's login lib/apps.hl (checks, return URL: lib/apps-helpers.hl)
  9. // the identity selector (pick ids, the choice) lib/selector.hl (browser half: selector.js)
  10. // invites (ident#22) lib/invites.hl (checks: lib/invites-helpers.hl)
  11. // notifications: kinds, sending, inbox, per-app switches lib/notify.hl (checks, orders: lib/notify-helpers.hl)
  12. // mail (codes, invitations; IDENT_MAIL_SINK) lib/mail.hl
  13. // delivery: the daily mail at 17:00 in the user's zone, urgent at once lib/delivery.hl (texts, clock: lib/delivery-helpers.hl)
  14. // the function routes (/login, /api/*, /invite/:token, /code) lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)
  15. // shared small helpers (storage dir, env, lists, text checks) lib/util.hl
  16. // an identity's page, "Used in" (ident#26) lib/usedin.hl (texts: lib/usedin-helpers.hl; page: components/identity.hl)
  17. // pages: shell, sign-in + identities, start, apps, inbox, per-app components/*.hl; CSS components/styles.hl
  18. //
  19. // THE FLOWS (README "How apps use ident", "How apps send notifications", "Invites"):
  20. // GET /login?key=<api key>&return=<url> → error page, or → /signin/<rid> (sign in, choose the identity,
  21. // → <return url>?ident_code=<one-time code>)
  22. // POST /api/exchange { key, secret, code } → { identity } (the identity's short id only)
  23. // GET /selector.js, GET /api/selector/identities?key=, POST /api/selector/choose?key= {identity} → { code }
  24. // POST /api/code { email } → { email } | 400/429 { error } (a function route: the per-IP limit needs the request)
  25. // GET /code, /signin/<rid>/code the code form for this session's pending address, or → / resp. /signin/<rid>
  26. // Deploy (Byrodin): HL_HOST=127.0.0.1 binds loopback only (hl:web reads HL_HOST, hybriel#24),
  27. // IDENT_PORT the port.
  28. import WebFramework from 'hl:web'
  29. import { env } from 'hl:proc'
  30. import Styles from './components/styles.hl'
  31. import { dark, darker } from './shared/tokens.hl'
  32. import { appLogin, apiExchange, apiMigrateIds, apiCode, apiSelectorIdentities, apiSelectorChoose, apiInvites, apiInvitesList, apiInvitesGet, apiInvitesRevoke, inviteLink, apiKinds, apiNotify, apiOnline, notFoundApi, notFoundPage, codePage } from './lib/api.hl'
  33. import Mail from './lib/mail.hl'
  34. import Delivery from './lib/delivery.hl'
  35. import { sessionHooks, dropUserSessions } from './lib/accounts.hl'
  36. import { shortIdsBackfilled } from './lib/identities.hl'
  37. // ident#23: statics run on first use — touching it here gives every older identity its short id at boot
  38. console.log('ident: ' + shortIdsBackfilled + ' identities got their short id')
  39. import Home from './components/home.hl'
  40. import Start from './components/start.hl'
  41. import Apps from './components/apps.hl'
  42. import Inbox from './components/inbox.hl'
  43. import Identity from './components/identity.hl'
  44. import AppSettings from './components/appsettings.hl'
  45. import NotFound from './components/notfound.hl'
  46. static siteName = "ident"
  47. appTitle = siteName
  48. styles = Styles
  49. // ---- THE INSTALLABLE APP (mission 046, as calendar#3): hl:web generates the web app manifest
  50. // (/__hl/manifest.webmanifest, linked in every head with the apple-touch-icon and theme-color)
  51. // from these, and the service worker (/__hl/sw.js) from `offline`. No JavaScript of ours.
  52. // Icons: icons/ (icon.svg is the source, README "PWA"). Theme colour = the header's colour (token
  53. // `darker`), background `dark` — the same in every app (mission 046); the icon carries the accent.
  54. appThemeColor = darker.value
  55. appBackgroundColor = dark.value
  56. appFavicon = '/favicon.ico'
  57. appTouchIcon = '/icons/apple-touch-icon.png'
  58. appIcons = [
  59. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  60. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  61. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  62. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  63. ]
  64. // OFFLINE, WITHOUT PERSONAL DATA: the worker keeps only `/start` (components/start.hl, a page
  65. // with no data — never `/`, whose copy would hold the signed-in address and identities) and the
  66. // shell's assets. The installed app starts at `/start` (appManifest); online the shell's probe
  67. // (main.hl) sends it on to `/`, offline the header says it is offline. Every other page offline
  68. // is the worker's "Unavailable offline" (README "PWA").
  69. offline = [ Start ]
  70. appManifest = { start_url = '/start' }
  71. // ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------
  72. routes = [
  73. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  74. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  75. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  76. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  77. { pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  78. { pattern = "/login" function = appLogin }
  79. { pattern = "/api/exchange" function = apiExchange }
  80. { pattern = "/api/migrate-ids" function = apiMigrateIds }
  81. { pattern = "/api/code" function = apiCode }
  82. { pattern = "/api/selector/identities" function = apiSelectorIdentities }
  83. { pattern = "/api/selector/choose" function = apiSelectorChoose }
  84. { pattern = "/api/invites" function = apiInvites }
  85. { pattern = "/api/invites/list" function = apiInvitesList }
  86. { pattern = "/api/invites/get" function = apiInvitesGet }
  87. { pattern = "/api/invites/revoke" function = apiInvitesRevoke }
  88. { pattern = "/invite/:token" function = inviteLink }
  89. { pattern = "/api/kinds" function = apiKinds }
  90. { pattern = "/api/notify" function = apiNotify }
  91. { pattern = "/selector.js" file = "./selector.js" headers = { 'Cache-Control' = 'no-cache' } }
  92. { pattern = "/avatar.js" file = "./avatar.js" headers = { 'Cache-Control' = 'no-cache' } }
  93. // the offline probe of the shell (components/main.hl): 204
  94. { pattern = "/api/online" function = apiOnline }
  95. { pattern = "/api/*" function = notFoundApi }
  96. // THE CODE PAGE (ident#20): renders Home through the framework's page render — it needs the server, BY REFERENCE
  97. { pattern = "/code" function = (route, req) => { return codePage(route, req, &server, Home) } }
  98. { pattern = "/signin/:rid/code" function = (route, req) => { return codePage(route, req, &server, Home) } }
  99. { pattern = "/" component = Home }
  100. { pattern = "/start" component = Start }
  101. { pattern = "/signin/:rid" component = Home }
  102. { pattern = "/apps" component = Apps }
  103. { pattern = "/identity/:iid" component = Identity }
  104. { pattern = "/inbox" component = Inbox }
  105. { pattern = "/inbox/:cid" component = AppSettings }
  106. // anything else: the 404 page, in the shell (last: every route above wins)
  107. { pattern = "/*" function = (route, req) => { return notFoundPage(route, req, &server, NotFound) } }
  108. ]
  109. // the mailer's result handlers live on an INSTANCE of lib/mail.hl
  110. mail = new Mail()
  111. // THE DAILY MAIL's clock (one round a minute) lives on an INSTANCE of lib/delivery.hl
  112. delivery = new Delivery()
  113. sessionDir = env('IDENT_SESSIONS') != null ? env('IDENT_SESSIONS') : null
  114. port = env('IDENT_PORT') != null ? toNumber(env('IDENT_PORT')) : 8351
  115. // THE LISTENER's interface: hl:web reads HL_HOST (or HOST) itself (hybriel#24): 127.0.0.1 on
  116. // Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).
  117. // IDENT_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,
  118. // half-copied .hl files must not be re-analysed); unset = on, as before.
  119. watching = env('IDENT_WATCH') != '0'
  120. // WHO A PUSHED EVENT IS FOR: "signed out everywhere" reaches every open connection whose
  121. // session is the account's (checked before dropUserSessions clears the sessions).
  122. audience = {
  123. signedOutAll = (accountId, session) => { return session != null && session.user != null && session.user.id == accountId }
  124. }
  125. // ident's OWN COOKIE NAME. Cookies are per host, not per port: with the default `hlsid` an app
  126. // on the same host (tickets on :8350) and ident would overwrite each other's session cookie
  127. // → hl:web's `sessionCookie` setting (hybriel#10/#17).
  128. sessionCookie = 'identsid'
  129. server = new WebFramework(routes = routes, styles = styles, audience = audience, minify = true, port = port, watchMode = watching, sessionCookie = sessionCookie)
  130. // SIGN OUT EVERYWHERE deletes every session of the account (ticket #19, lib/accounts.hl dropUserSessions): the
  131. // session store is this server's
  132. sessionHooks.dropUser = (userId) => { return dropUserSessions(&server, userId) }

Branches

Latest commits

  • 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
  • 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