gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf7-hookseee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmref7-hooks/project.hl

13.3 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. // identity access, one key per identity (ident#27) lib/access.hl (page: components/access.hl; the app's check: POST /api/introspect)
  18. // pages: shell, sign-in + identities, start, apps, inbox, per-app components/*.hl; CSS components/styles.hl
  19. // /docs, what ident is (ident#45): the text is docs/IDENT.md lib/docs.hl (page: components/docs.hl)
  20. //
  21. // THE FLOWS (README "How apps use ident", "How apps send notifications", "Invites"):
  22. // GET /login?key=<api key>&return=<url> → error page, or → /signin/<rid> (sign in, choose the identity,
  23. // → <return url>?ident_code=<one-time code>)
  24. // POST /api/exchange { key, secret, code, fields? } → { identity, + the asked fields }, POST /api/profile (ident#11)
  25. // GET /selector.js, GET /api/selector/identities?key=, POST /api/selector/choose?key= {identity} → { code }
  26. // POST /api/code { email } → { email } | 400/429 { error } (a function route: the per-IP limit needs the request)
  27. // GET /code, /signin/<rid>/code the code form for this session's pending address, or → / resp. /signin/<rid>
  28. // Deploy (Byrodin): HL_HOST=127.0.0.1 binds loopback only (hl:web reads HL_HOST, hybriel#24),
  29. // IDENT_PORT the port.
  30. import WebFramework from 'hl:web'
  31. import { exit } from 'hl:proc'
  32. import { envString } from './lib/util.hl'
  33. import Styles from './components/styles.hl'
  34. import { dark, darker } from './shared/tokens.hl'
  35. import { appLogin, apiExchange, apiProfile, apiMigrateIds, apiCode, apiSelectorIdentities, apiSelectorChoose, apiInvites, apiInvitesList, apiInvitesGet, apiInvitesRevoke, inviteLink, apiKinds, apiNotify, apiIntrospect, apiOnline, notFoundApi, notFoundRoute, codeRoute, signinCodeRoute, embedSigninRoute, embedGo, welcomeRoute, pageServer } from './lib/api.hl'
  36. import Mail from './lib/mail.hl'
  37. import Delivery from './lib/delivery.hl'
  38. import { sessionHooks, dropSessionUser, signedOutAudience } from './lib/accounts.hl'
  39. import { shortIdsBackfilled } from './lib/identities.hl'
  40. import { gitoriaWildcardAdded } from './lib/apps.hl'
  41. // ident#23: statics run on first use — touching it here gives every older identity its short id at boot
  42. console.log('ident: ' + shortIdsBackfilled + ' identities got their short id')
  43. console.log('ident: ' + gitoriaWildcardAdded + ' app got the wildcard origin of its repo addresses')
  44. import Home from './components/home.hl'
  45. import Start from './components/start.hl'
  46. import Apps from './components/apps.hl'
  47. import Access from './components/access.hl'
  48. import Inbox from './components/inbox.hl'
  49. import Identity from './components/identity.hl'
  50. import AppSettings from './components/appsettings.hl'
  51. import NotFound from './components/notfound.hl'
  52. import Embed from './components/embed.hl'
  53. import ErrorPage from './components/error.hl'
  54. import Docs from './components/docs.hl'
  55. static siteName = "ident"
  56. appTitle = siteName
  57. // THE PAGES' POLICY, as <meta> (hl:web has no setting for response headers of a page: reports/SI-sec.md). No <base>, no plugin
  58. // objects, forms only to ident itself, no frames in, connections only to ident itself; the pages need their inline module
  59. // (hl:web's boot script) so scripts keep 'unsafe-inline'. `frame-ancestors` and X-Frame-Options cannot be set from a meta.
  60. meta = [
  61. { 'http-equiv' = 'Content-Security-Policy' content = "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: http: https:; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-src 'none'; worker-src 'self'; manifest-src 'self'" }
  62. { name = 'referrer' content = 'same-origin' }
  63. ]
  64. styles = Styles
  65. // ---- THE INSTALLABLE APP (mission 046, as calendar#3): hl:web generates the web app manifest
  66. // (/__hl/manifest.webmanifest, linked in every head with the apple-touch-icon and theme-color)
  67. // from these, and the service worker (/__hl/sw.js) from `offline`. No JavaScript of ours.
  68. // Icons: icons/ (icon.svg is the source, README "PWA"). Theme colour = the header's colour (token
  69. // `darker`), background `dark` — the same in every app (mission 046); the icon carries the accent.
  70. appThemeColor = darker.value
  71. appBackgroundColor = dark.value
  72. appFavicon = '/favicon.ico'
  73. appTouchIcon = '/icons/apple-touch-icon.png'
  74. appIcons = [
  75. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  76. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  77. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  78. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  79. ]
  80. // OFFLINE, WITHOUT PERSONAL DATA: the worker keeps only `/start` (components/start.hl, a page
  81. // with no data — never `/`, whose copy would hold the signed-in address and identities) and the
  82. // shell's assets. The installed app starts at `/start` (appManifest); online the shell's probe
  83. // (main.hl) sends it on to `/`, offline the header says it is offline. Every other page offline
  84. // is the worker's "Unavailable offline" (README "PWA").
  85. offline = [ Start ]
  86. appManifest = { start_url = '/start' }
  87. // ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------
  88. routes = [
  89. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  90. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  91. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  92. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  93. { pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  94. { pattern = "/login" function = appLogin }
  95. // the login error page (ident#41) is rendered by lib/api-helpers.hl errorPage; this entry (behind the function route, which wins) only registers its component and its Style
  96. { pattern = "/login" component = ErrorPage }
  97. { pattern = "/api/exchange" function = apiExchange }
  98. { pattern = "/api/profile" function = apiProfile }
  99. { pattern = "/api/migrate-ids" function = apiMigrateIds }
  100. { pattern = "/api/code" function = apiCode }
  101. { pattern = "/api/selector/identities" function = apiSelectorIdentities }
  102. { pattern = "/api/selector/choose" function = apiSelectorChoose }
  103. { pattern = "/api/invites" function = apiInvites }
  104. { pattern = "/api/invites/list" function = apiInvitesList }
  105. { pattern = "/api/invites/get" function = apiInvitesGet }
  106. { pattern = "/api/invites/revoke" function = apiInvitesRevoke }
  107. { pattern = "/invite/:token" function = inviteLink }
  108. { pattern = "/api/introspect" function = apiIntrospect }
  109. { pattern = "/api/kinds" function = apiKinds }
  110. { pattern = "/api/notify" function = apiNotify }
  111. { pattern = "/selector.js" file = "./selector.js" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  112. { pattern = "/avatar.js" file = "./avatar.js" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  113. // the offline probe of the shell (components/main.hl): 204
  114. { pattern = "/api/online" function = apiOnline }
  115. { pattern = "/api/*" function = notFoundApi }
  116. // THE CODE PAGE (ident#20): renders Home through the framework's page render — it needs the server, BY REFERENCE
  117. { pattern = "/code" function = codeRoute }
  118. { pattern = "/signin/:rid/code" function = signinCodeRoute }
  119. { pattern = "/signin/:rid/welcome" function = welcomeRoute }
  120. { pattern = "/embed/signin" function = embedSigninRoute }
  121. { pattern = "/embed/go" function = embedGo }
  122. // the frame's page is rendered by embedSignin (above, it wins); this entry only registers the component and its shell with the client
  123. { pattern = "/embed/signin" component = Embed }
  124. { pattern = "/" component = Home }
  125. { pattern = "/start" component = Start }
  126. { pattern = "/signin/:rid" component = Home }
  127. { pattern = "/apps" component = Apps }
  128. { pattern = "/identity/:iid" component = Identity }
  129. { pattern = "/access" component = Access }
  130. { pattern = "/inbox" component = Inbox }
  131. { pattern = "/inbox/:cid" component = AppSettings }
  132. // what ident is and how it works (ident#45): docs/IDENT.md, public
  133. { pattern = "/docs" component = Docs }
  134. // anything else: the 404 page, in the shell (last: every route above wins)
  135. { pattern = "/*" function = notFoundRoute }
  136. ]
  137. // the mailer's result handlers live on an INSTANCE of lib/mail.hl
  138. mail = new Mail()
  139. // THE DAILY MAIL's clock (one round a minute) lives on an INSTANCE of lib/delivery.hl
  140. delivery = new Delivery()
  141. sessionDir = envString('IDENT_SESSIONS', null, true)
  142. port = toNumber(envString('IDENT_PORT', '8351', true))
  143. // THE LISTENER's interface: hl:web reads HL_HOST (or HOST) itself (hybriel#24): 127.0.0.1 on
  144. // Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).
  145. // IDENT_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,
  146. // half-copied .hl files must not be re-analysed); unset = on, as before.
  147. watching = envString('IDENT_WATCH', null, true) != '0'
  148. // WHO A PUSHED EVENT IS FOR: "signed out everywhere" reaches every open connection whose
  149. // session is the account's (checked before dropUserSessions clears the sessions).
  150. audience = {
  151. signedOutAll = signedOutAudience
  152. }
  153. // ident's OWN COOKIE NAME. Cookies are per host, not per port: with the default `hlsid` an app
  154. // on the same host (tickets on :8350) and ident would overwrite each other's session cookie
  155. // → hl:web's `sessionCookie` setting (hybriel#10/#17).
  156. // SECURITY (mission SI): behind https (IDENT_PUBLIC_URL starts with https://, as on Byrodin) the cookie is `Secure` and carries
  157. // the `__Host-` prefix — a browser then refuses to let any sibling host (another *.worldapi.org app) plant or overwrite it
  158. // with a Domain cookie (session fixation: hl:web keeps the session id across the sign-in, hybriel gap in reports/SI-sec.md).
  159. // Dev and the gates run on http: the old name, no flag.
  160. publicUrl = envString('IDENT_PUBLIC_URL', null, true)
  161. behindHttps = publicUrl != null && publicUrl.startsWith('https://')
  162. sessionCookie = behindHttps ? '__Host-identsid' : 'identsid'
  163. // ident takes no file in any emit (the avatar travels as a small data URL string): /__hl/upload is open to a session nobody
  164. // signed in (it mints one), so its default of 1 GiB per upload was an anonymous memory sink. Nothing may be uploaded here.
  165. uploadMax = 0
  166. // hl:web now adds X-Frame-Options: SAMEORIGIN to every answer that names none. ident's embed page names its framing apps by
  167. // `frame-ancestors` (lib/api-helpers.hl framedBy), which cannot be said in X-Frame-Options, so the default is switched off;
  168. // every other answer keeps the framework's CSP `frame-ancestors 'self'` and ident's own DENY headers.
  169. pageHeaders = { 'X-Frame-Options' = null }
  170. server = new WebFramework(routes = routes, styles = styles, audience = audience, minify = true, port = port, watchMode = watching, sessionCookie = sessionCookie, sessionSecure = behindHttps, uploadMax = uploadMax, sessionMaxAge = 3122064000, pageHeaders = pageHeaders)
  171. // SIGN OUT EVERYWHERE deletes every session of the account (ticket #19, lib/accounts.hl dropUserSessions): the
  172. // session store is this server's
  173. pageServer.server = server
  174. sessionHooks.server = server
  175. sessionHooks.dropUser = dropSessionUser
  176. // A fault while the program starts is fatal (hybriel#65): exit 1 at once, so the container's start fails visibly instead of
  177. // serving a half-started app. A fault in the event loop (a request, a delivery) is only logged; the server keeps serving.
  178. on Error(e) {
  179. if (e.phase == 'startup') {
  180. console.log('ident: startup error: ' + e.message)
  181. exit(1)
  182. }
  183. console.log('ident: error: ' + e.message)
  184. }

Branches

Latest commits

  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
  • 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
  • e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
  • 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre
  • f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
  • b323265aMerge branch 'f5-styles' into mainIdent
  • 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
  • f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
  • 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre
  • 00235f21ident#33: the per-app notification switches move into appsettings.hl's Stylemre
  • 2249945cident#33: the inbox and connection list rules move into inbox.hl's Stylemre
  • f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre