gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8f3dc1ec8f3dc1ectests: delivery allow-list for the stopped server's network errors uses the gate port, not 8700mre8f3dc1ec/project.hl

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

Branches

Latest commits

  • 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
  • 5885f1c9ident mission 013 step 2: stopgap reload removed (in-place sign-in/out reach the shell via emit, notices back, route-marked main menu), gates updatedmre
  • 734ac0a9ident mission 013 step 1: re-vendor Hybriel ce6f2e0a (plugins whole; bin/ is git-ignored)mre
  • b37875ccident mission 012 part 3: real-Chrome fixes (brand 44 px, identity form width), e2e walk, report, logmre
  • f989c2ebident mission 012: stopgap reload after in-place sign-in/sign-out (until hybriel#193), gates wait for cold start, welcome end reloadsmre
  • 443291d4ident mission 012: /start on its own shell (no account), browser gate 152/0, reportmre
  • 021dd0fcident mission 012: browser gate waits cold start (IDENT_COLD_MS), header selectors, e2e checks; shell events from a page do not reach it (probe), current not marked, account-bar link 44 pxmre
  • 97f77b07ident mission 012 (WIP): onto the layouts theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ContentFirst, styles cut, check-theme gatemre
  • 8e4f435bpaths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • fa288f63ident mission 011: report wording (Intl zone names)mre
  • 961fae01ident mission 011: report, LOG, STATUSmre
  • 65348039ident#7: delivery gate — console check split at the gate's own server restart (49 checks)mre