gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcd3641a1cd3641a1|||PR records: day72 deploy live, tickets closedmrecd3641a1/project.hl

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

Branches

Latest commits

  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre
  • 0788e65f|||PR re-vendor Hybriel day72mre
  • e2a6bdcfMerge branch 'records-t35' into mainTickets
  • d8d54df1|||PR records: R35 day72 + #40mre
  • 8a7f475aMerge branch 'records-t33' into mainTickets