gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit41da352541da3525Tickets conductor: flake cause, T36 deploy stepmre41da3525/project.hl

14.5 KB

  1. // project.hl — tickets.worldapi.org: THE MAP. Config, routes and WHO HEARS WHAT; the logic lives in lib/.
  2. //
  3. // WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):
  4. // tickets, their states and relations (parent / blocked-by) lib/tickets.hl (state names, page shapes: lib/tickets-helpers.hl)
  5. // the history of a ticket (events) lib/events.hl
  6. // comments: edit, delete, like (mission 016) lib/comments.hl (the page draws them: components/comments/)
  7. // files attached to a comment (tickets#27, mission 017) lib/attachments.hl (the API's multipart body: lib/multipart.hl)
  8. // projects, members, roles, slugs lib/projects.hl
  9. // users, login through ident, API tokens, sessions lib/users.hl
  10. // invites to a project (ident#22) lib/invites.hl
  11. // connecting an app to a project (ticket #21) lib/connections.hl
  12. // Markdown in text fields / the Markdown read view lib/markdown.hl / lib/mdview.hl
  13. // the JSON API + /login/callback, /connect, /tickets/:ref lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)
  14. // the event stream for programs, GET /api/events (#26) lib/stream.hl (numbered rows, filters, SSE)
  15. // the ticket #20 data migration (every start) lib/migrate.hl
  16. // the ticket-file format of the import lib/import.hl (the import tool: tools/import.hl)
  17. // shared small helpers (env, storage dir, URLs, sorting, Vienna time) lib/util.hl
  18. // pages: shell, list, ticket, inbox, you, new project, settings, connect components/*.hl; CSS components/styles.hl
  19. import WebFramework from 'hl:web'
  20. import { env, exit } from 'hl:proc'
  21. import Styles from './components/styles.hl'
  22. import { dark, darker } from './shared/tokens.hl'
  23. import { migrateAll } from './lib/migrate.hl'
  24. import { tagOf, identUrl, publicUrl } from './lib/users.hl'
  25. import { getAttachment, getEvents, postTicket, getTicket, postComment, postCommentEdit, postCommentDelete, postCommentLike, postState, postEdit, postAssign, postParent, postBlockers, getProjects, getInbox, getProject, postMembers, postMemberRemove, postInvites, connectExchange, projectConnections, projectDisconnect, connectStart, projectTickets, getProjectTicket, postProjectComment, postProjectCommentEdit, postProjectCommentDelete, postProjectCommentLike, postProjectState, postProjectEdit, postProjectAssign, postProjectParent, postProjectBlockers, oldTicketPage, oldProjectPage, oldProjectTicketPage, loginCallback } from './lib/api.hl'
  26. import TicketList from './components/ticket_list.hl'
  27. import Ticket from './components/ticket.hl'
  28. import Inbox from './components/inbox.hl'
  29. import You from './components/you.hl'
  30. import NewProject from './components/new_project.hl'
  31. import Settings from './components/settings.hl'
  32. import Connect from './components/connect.hl'
  33. import Problem from './components/problem.hl'
  34. static siteName = "tickets"
  35. appTitle = siteName
  36. styles = Styles
  37. // THE PAGES' POLICY, as <meta> (hl:web sets no response header on a page yet: reports/ST-sec.md). No <base>, no plugins, no forms to other sites;
  38. // scripts: hl:web's boot module is inline ('unsafe-inline'), ident's selector.js and its fetches go to IDENT_URL; images: this site only
  39. // (attachments are served by /api/attachments/:id). `frame-ancestors` cannot be set from a meta (Byrodin's nginx / hl:web's header hook).
  40. meta = [
  41. { 'http-equiv' = 'Content-Security-Policy' content = "default-src 'self'; script-src 'self' 'unsafe-inline' " + identUrl + "; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' " + identUrl + "; object-src 'none'; base-uri 'none'; form-action 'self' " + identUrl + "; frame-src " + identUrl + "; worker-src 'self'; manifest-src 'self'" }
  42. { name = 'referrer' content = 'same-origin' }
  43. ]
  44. // ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org does it: hl:web's own web app manifest
  45. // (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service worker
  46. // (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg, a ticket stub, is the source;
  47. // the PNGs and favicon.ico are rendered from it with rsvg-convert / magick, README "PWA"). The theme colour is the
  48. // header's background (darker, as tracker), the splash background the page's (dark) — both off the tokens, not written out again.
  49. appThemeColor = darker.value
  50. appBackgroundColor = dark.value
  51. appIcons = [
  52. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  53. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  54. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  55. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  56. ]
  57. appTouchIcon = '/icons/apple-touch-icon.png'
  58. appFavicon = '/icons/icon.svg'
  59. // OFFLINE: the shell and `/` — `/` IS the ticket list, so offline it shows the list as this browser last loaded it,
  60. // and the shell (components/main.hl) says "You are offline". Its value-form emits are never queued. Other pages are
  61. // not kept, except a project list (/<slug>, same component) this browser visited; the rest get hl:web's
  62. // "Unavailable offline" page.
  63. offline = [ TicketList ]
  64. // ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------
  65. routes = [
  66. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  67. // the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  68. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  69. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  70. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  71. { pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  72. // the login button's return (ticket #7): it needs the request's session and the framework's session store, BY REFERENCE
  73. { pattern = "/login/callback" function = (route, req) => { return loginCallback(route, &req, &server.sessions) } }
  74. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  75. // ticket #26: every change, live, for programs (Server-Sent Events; lib/stream.hl)
  76. { pattern = "/api/events" function = getEvents }
  77. { pattern = "/api/tickets" function = postTicket }
  78. { pattern = "/api/tickets/:ref" function = getTicket }
  79. { pattern = "/api/tickets/:ref/comments" function = postComment }
  80. // mission 016: a comment's author edits / deletes it, a member likes it (lib/comments.hl); :comment = its event id
  81. { pattern = "/api/tickets/:ref/comments/:comment/edit" function = postCommentEdit }
  82. { pattern = "/api/tickets/:ref/comments/:comment/delete" function = postCommentDelete }
  83. { pattern = "/api/tickets/:ref/comments/:comment/like" function = postCommentLike }
  84. { pattern = "/api/tickets/:ref/state" function = postState }
  85. // tickets#27: an attached file, for the members of its project (lib/attachments.hl)
  86. { pattern = "/api/attachments/:id" function = getAttachment }
  87. { pattern = "/api/tickets/:ref/edit" function = postEdit }
  88. { pattern = "/api/tickets/:ref/assign" function = postAssign }
  89. { pattern = "/api/tickets/:ref/parent" function = postParent }
  90. { pattern = "/api/tickets/:ref/blocked-by" function = postBlockers }
  91. { pattern = "/api/projects" function = getProjects }
  92. { pattern = "/api/inbox" function = getInbox }
  93. { pattern = "/api/projects/:slug" function = getProject }
  94. { pattern = "/api/projects/:slug/members" function = postMembers }
  95. { pattern = "/api/projects/:slug/members/remove" function = postMemberRemove }
  96. { pattern = "/api/projects/:slug/invites" function = postInvites }
  97. { pattern = "/api/connect/exchange" function = connectExchange }
  98. { pattern = "/api/projects/:slug/connections" function = projectConnections }
  99. { pattern = "/api/projects/:slug/connections/remove" function = projectDisconnect }
  100. { pattern = "/connect" function = connectStart }
  101. { pattern = "/api/projects/:slug/tickets" function = projectTickets }
  102. { pattern = "/api/projects/:slug/tickets/:number" function = getProjectTicket }
  103. { pattern = "/api/projects/:slug/tickets/:number/comments" function = postProjectComment }
  104. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/edit" function = postProjectCommentEdit }
  105. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/delete" function = postProjectCommentDelete }
  106. { pattern = "/api/projects/:slug/tickets/:number/comments/:comment/like" function = postProjectCommentLike }
  107. { pattern = "/api/projects/:slug/tickets/:number/state" function = postProjectState }
  108. { pattern = "/api/projects/:slug/tickets/:number/edit" function = postProjectEdit }
  109. { pattern = "/api/projects/:slug/tickets/:number/assign" function = postProjectAssign }
  110. { pattern = "/api/projects/:slug/tickets/:number/parent" function = postProjectParent }
  111. { pattern = "/api/projects/:slug/tickets/:number/blocked-by" function = postProjectBlockers }
  112. { pattern = "/" component = TicketList }
  113. { pattern = "/project/:projectName" component = TicketList }
  114. { pattern = "/state/:stateSlug" component = TicketList }
  115. { pattern = "/project/:projectName/state/:stateSlug" component = TicketList }
  116. { pattern = "/inbox" component = Inbox }
  117. { pattern = "/new-project" component = NewProject }
  118. { pattern = "/connect/:nonce" component = Connect }
  119. // tickets#42: the reason a login or a connection request was refused (lib/problems.hl codes); /login/callback and /connect redirect here
  120. { pattern = "/login/failed/:why" component = Problem }
  121. { pattern = "/connect/failed/:why" component = Problem }
  122. { pattern = "/projects/:projectSlug/settings" component = Settings }
  123. { pattern = "/you" component = You }
  124. // OLD PAGE URLS → 301 to the short ones (ticket #25): `/tickets/<old global number or uuid>`, `/projects/<slug>`,
  125. // `/projects/<slug>/<number>`, `/projects/<slug>/tickets/<number>`
  126. { pattern = "/tickets/:ref" function = oldTicketPage }
  127. { pattern = "/projects/:slug" function = oldProjectPage }
  128. { pattern = "/projects/:slug/:number" function = oldProjectTicketPage }
  129. { pattern = "/projects/:slug/tickets/:number" function = oldProjectTicketPage }
  130. // THE SHORT PAGE URLS (ticket #25): the project `/<slug>`, a ticket `/<slug>/<number>`. They match any first
  131. // segment, so they come last — and below, after the construction, behind hl:web's own urls too (`lastPage`)
  132. { pattern = "/:projectName" component = TicketList lastPage = true }
  133. { pattern = "/:projectSlug/:ticketNumber" component = Ticket lastPage = true }
  134. ]
  135. // WHO GETS THE PUSH: tickets and events are public (reading needs no login). A frame
  136. // reaches a connection only if a mounted component listens for it.
  137. // `signedIn` / `signedOut` (ticket #7) go to the tabs of ONE session: the one whose login
  138. // carries that random tag (session.data.tag, set at login) — every page of it switches to
  139. // logged in / out without a reload.
  140. audience = {
  141. ticketCreated = (row, session) => { return true }
  142. ticketEvent = (ticketId, ev, row, session) => { return true }
  143. // mission 016: a comment was edited, deleted or (un)liked — the ticket page swaps that history row
  144. commentChanged = (ticketId, ev, session) => { return true }
  145. // ticket #4: the relation views (tickets-helpers.hl relationViewOf) of a ticket and its related ones
  146. ticketsRelated = (views, session) => { return true }
  147. // ticket #21: an app was connected / disconnected — the project page refreshes its line
  148. connectionsChanged = (slug, session) => { return true }
  149. signedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }
  150. signedOut = (tag, session) => { return tag != null && tagOf(session) == tag }
  151. }
  152. sessionDir = env('TICKETS_SESSIONS') != null ? env('TICKETS_SESSIONS') : null
  153. port = env('TICKETS_PORT') != null ? toNumber(env('TICKETS_PORT')) : 8350
  154. // THE LISTENER's interface (mission 010, deploy to Byrodin): hl:web reads HL_HOST (or HOST)
  155. // itself (hybriel#24): 127.0.0.1 on Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).
  156. // TICKETS_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,
  157. // half-copied .hl files must not be re-analysed); unset = on, as before.
  158. watching = env('TICKETS_WATCH') != '0'
  159. // THE MIGRATION of ticket #20 (lib/migrate.hl): idempotent, runs at every start
  160. for (line of migrateAll()) { console.log('migrated: ' + line) }
  161. // uploadMax (tickets#27): the largest file a page's emit may carry = lib/attachments.hl maxFileBytes (10 MiB; inlined, as a manifest value)
  162. // SECURITY (mission ST, ST2): behind https (TICKETS_PUBLIC_URL, https on Byrodin) the session cookie gets the `Secure` flag. Its NAME stays hl:web's
  163. // default (hlsid) and it has no new lifetime: a session cookie issued before stays valid, nobody is signed out (creator 2026-10-23: logins never expire).
  164. behindHttps = publicUrl.startsWith('https://')
  165. server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, uploadMax = 10485760, sessionMaxAge = 3122064000, sessionSecure = behindHttps)
  166. // THE SHORT PAGE URLS GO BEHIND hl:web's OWN (ticket #25). The first match answers, and hl:web APPENDS its urls
  167. // (/__hl/app.css, /__hl/emit, /__hl/sw.js …, the component modules /components/<file>.hl) to the table while it is
  168. // constructed: left where they are, `/:projectSlug/:ticketNumber` answered /__hl/app.css and /components/ticket.hl
  169. // with a ticket page. They stay in the table above (hl:web serves the modules of the components routes mount, and
  170. // the service worker knows them as pages) and are moved to the end of the router's table here — the one that
  171. // answers requests and that the browser gets for its links. A first segment any route answers is a reserved slug
  172. // (lib/projects.hl reservedSlugs; the gate checks both).
  173. pagesFirst = []
  174. pagesLast = []
  175. for (r of server.router.routes) { if (r.lastPage == true) { pagesLast[] = r } else { pagesFirst[] = r } }
  176. for (r of pagesLast) { pagesFirst[] = r }
  177. server.router.routes = pagesFirst
  178. // THE GLOBAL ERROR HANDLER (ticket #7): a plugin's failure — above all hl:fetch's refused /
  179. // timed-out exchange with ident (users.hl exchangeCode, invites.hl) — arrives here instead of aborting the
  180. // request with a 500 that shows source paths; the failed call yields null and the caller answers
  181. // it ("ident did not answer"). Every absorbed error is logged.
  182. on Error(e) {
  183. if (e.phase == 'startup') { console.log('tickets: startup error: ' + e.message) exit(1) }
  184. console.log('error absorbed: ' + e.message)
  185. }

Branches

Latest commits

  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre
  • 467d7286Tickets conductor: T36 done, deploy questionmre
  • 8542fc8aTickets conductor: T36 proof reviewedmre
  • 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre
  • 6a82097fTickets conductor: Arachne W228 on day35 flakemre
  • 0ee5a6f2Tickets conductor: T36 resumedmre
  • 9149c165Tickets conductor: T36 diagnosismre
  • 91713313Tickets conductor: T36 report 1mre
  • 756315d2Tickets conductor: T36 startedmre
  • 0814ce6bTickets conductor: brief 025 tickets#36 style formmre
  • 1b6916c4Tickets conductor: Atlas handover tickets#36mre
  • aab95226Tickets conductor: worldapi-conductor paths, deploy blocker = read-only diskmre
  • 6372b06dTickets conductor: worker port slotmre
  • 836af31cTickets conductor: token pathsmre
  • b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre