tickets
All repositories: gitoria
14.4 KB
// project.hl — tickets.worldapi.org: THE MAP. Config, routes and WHO HEARS WHAT; the logic lives in lib/.//// WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):// tickets, their states and relations (parent / blocked-by) lib/tickets.hl (state names, page shapes: lib/tickets-helpers.hl)// the history of a ticket (events) lib/events.hl// comments: edit, delete, like (mission 016) lib/comments.hl (the page draws them: components/comments/)// files attached to a comment (tickets#27, mission 017) lib/attachments.hl (the API's multipart body: lib/multipart.hl)// projects, members, roles, slugs lib/projects.hl// users, login through ident, API tokens, sessions lib/users.hl// invites to a project (ident#22) lib/invites.hl// connecting an app to a project (ticket #21) lib/connections.hl// Markdown in text fields / the Markdown read view lib/markdown.hl / lib/mdview.hl// the JSON API + /login/callback, /connect, /tickets/:ref lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)// subscription deltas and signed private wakes (#51) lib/subscriptions.hl / lib/subscription-wakes.hl// the event stream for programs, GET /api/events (#26) lib/stream.hl (numbered rows, filters, SSE)// the ticket #20 data migration (every start) lib/migrate.hl// the ticket-file format of the import lib/import.hl (the import tool: tools/import.hl)// shared small helpers (env, storage dir, URLs, sorting, Vienna time) lib/util.hl// pages: shell, list, ticket, inbox, you, new project, settings, connect components/*.hl; CSS components/styles.hlimport WebFramework from 'hl:web'import { env, exit } from 'hl:proc'import Styles from './components/styles.hl'import { hearStream } from './lib/stream.hl'import { wakeForRow, wakeCompleted, sweepWakes } from './lib/subscription-wakes.hl'import { completions } from 'hl:fetch'import { every } from 'hl:time'import { subscriptionsApi, deltaApi, removeSubscriptionApi } from './lib/subscriptions-api.hl'import { dark, darker } from './shared/tokens.hl'import { migrateAtStartup } from './lib/migrate.hl'import { tagOf, identUrl, publicUrl } from './lib/users.hl'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'import TicketList from './components/ticket_list.hl'import Ticket from './components/ticket.hl'import Inbox from './components/inbox.hl'import You from './components/you.hl'import NewProject from './components/new_project.hl'import Settings from './components/settings.hl'import Connect from './components/connect.hl'import Problem from './components/problem.hl'static siteName = "tickets"appTitle = siteNamestyles = Styles// 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;// 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// (attachments are served by /api/attachments/:id). `frame-ancestors` cannot be set from a meta (Byrodin's nginx / hl:web's header hook).meta = [{ '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'" }{ name = 'referrer' content = 'same-origin' }]// ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org does it: hl:web's own web app manifest// (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service worker// (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg, a ticket stub, is the source;// the PNGs and favicon.ico are rendered from it with rsvg-convert / magick, README "PWA"). The theme colour is the// header's background (darker, as tracker), the splash background the page's (dark) — both off the tokens, not written out again.appThemeColor = darker.valueappBackgroundColor = dark.valueappIcons = [{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }]appTouchIcon = '/icons/apple-touch-icon.png'appFavicon = '/icons/icon.svg'// OFFLINE: the shell and `/` — `/` IS the ticket list, so offline it shows the list as this browser last loaded it,// and the shell (components/main.hl) says "You are offline". Its value-form emits are never queued. Other pages are// not kept, except a project list (/<slug>, same component) this browser visited; the rest get hl:web's// "Unavailable offline" page.offline = [ TicketList ]// ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------routes = [{ pattern = "/api/subscriptions" function = subscriptionsApi }{ pattern = "/api/subscriptions/:id/delta" function = deltaApi }{ pattern = "/api/subscriptions/:id/remove" function = removeSubscriptionApi }{ pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }// the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline){ pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'no-cache' } }// the login button's return (ticket #7): it needs the request's session and the framework's session store, BY REFERENCE{ pattern = "/login/callback" function = loginRoute }{ pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }// ticket #26: every change, live, for programs (Server-Sent Events; lib/stream.hl){ pattern = "/api/events" function = getEvents }{ pattern = "/api/tickets" function = postTicket }{ pattern = "/api/tickets/:ref" function = getTicket }{ pattern = "/api/tickets/:ref/comments" function = postComment }// mission 016: a comment's author edits / deletes it, a member likes it (lib/comments.hl); :comment = its event id{ pattern = "/api/tickets/:ref/comments/:comment/edit" function = postCommentEdit }{ pattern = "/api/tickets/:ref/comments/:comment/delete" function = postCommentDelete }{ pattern = "/api/tickets/:ref/comments/:comment/like" function = postCommentLike }{ pattern = "/api/tickets/:ref/state" function = postState }// tickets#27: an attached file, for the members of its project (lib/attachments.hl){ pattern = "/api/attachments/:id" function = getAttachment }{ pattern = "/api/tickets/:ref/edit" function = postEdit }{ pattern = "/api/tickets/:ref/assign" function = postAssign }{ pattern = "/api/tickets/:ref/parent" function = postParent }{ pattern = "/api/tickets/:ref/blocked-by" function = postBlockers }{ pattern = "/api/projects" function = getProjects }{ pattern = "/api/inbox" function = getInbox }{ pattern = "/api/projects/:slug" function = getProject }{ pattern = "/api/projects/:slug/members" function = postMembers }{ pattern = "/api/projects/:slug/members/remove" function = postMemberRemove }{ pattern = "/api/projects/:slug/invites" function = postInvites }{ pattern = "/api/connect/exchange" function = connectExchange }{ pattern = "/api/projects/:slug/connections" function = projectConnections }{ pattern = "/api/projects/:slug/connections/remove" function = projectDisconnect }{ pattern = "/connect" function = connectStart }{ pattern = "/api/projects/:slug/tickets" function = projectTickets }{ pattern = "/api/projects/:slug/tickets/:number/move" function = postProjectMove }{ pattern = "/api/projects/:slug/tickets/:number" function = getProjectTicket }{ pattern = "/api/projects/:slug/tickets/:number/comments" function = postProjectComment }{ pattern = "/api/projects/:slug/tickets/:number/comments/:comment/edit" function = postProjectCommentEdit }{ pattern = "/api/projects/:slug/tickets/:number/comments/:comment/delete" function = postProjectCommentDelete }{ pattern = "/api/projects/:slug/tickets/:number/comments/:comment/like" function = postProjectCommentLike }{ pattern = "/api/projects/:slug/tickets/:number/state" function = postProjectState }{ pattern = "/api/projects/:slug/tickets/:number/edit" function = postProjectEdit }{ pattern = "/api/projects/:slug/tickets/:number/assign" function = postProjectAssign }{ pattern = "/api/projects/:slug/tickets/:number/parent" function = postProjectParent }{ pattern = "/api/projects/:slug/tickets/:number/blocked-by" function = postProjectBlockers }{ pattern = "/" component = TicketList }{ pattern = "/project/:projectName" component = TicketList }{ pattern = "/state/:stateSlug" component = TicketList }{ pattern = "/project/:projectName/state/:stateSlug" component = TicketList }{ pattern = "/inbox" component = Inbox }{ pattern = "/new-project" component = NewProject }{ pattern = "/connect/:nonce" component = Connect }// tickets#42: the reason a login or a connection request was refused (lib/problems.hl codes); /login/callback and /connect redirect here{ pattern = "/login/failed/:why" component = Problem }{ pattern = "/connect/failed/:why" component = Problem }{ pattern = "/projects/:projectSlug/settings" component = Settings }{ pattern = "/you" component = You }// OLD PAGE URLS → 301 to the short ones (ticket #25): `/tickets/<old global number or uuid>`, `/projects/<slug>`,// `/projects/<slug>/<number>`, `/projects/<slug>/tickets/<number>`{ pattern = "/tickets/:ref" function = oldTicketPage }{ pattern = "/projects/:slug" function = oldProjectPage }{ pattern = "/projects/:slug/:number" function = oldProjectTicketPage }{ pattern = "/projects/:slug/tickets/:number" function = oldProjectTicketPage }// THE SHORT PAGE URLS (ticket #25): the project `/<slug>`, a ticket `/<slug>/<number>`. They match any first// segment, so they come last in the app routes; hl:web puts its own URLs first.{ pattern = "/:projectName" component = TicketList }{ pattern = "/:projectSlug/:ticketNumber" component = Ticket }]// WHO GETS THE PUSH: tickets and events are public (reading needs no login). A frame// reaches a connection only if a mounted component listens for it.// `signedIn` / `signedOut` (ticket #7) go to the tabs of ONE session: the one whose login// carries that random tag (session.data.tag, set at login) — every page of it switches to// logged in / out without a reload.audience = {ticketCreated = (row, session) => { return true }ticketEvent = (ticketId, ev, row, session) => { return true }// mission 016: a comment was edited, deleted or (un)liked — the ticket page swaps that history rowcommentChanged = (ticketId, ev, session) => { return true }// ticket #4: the relation views (tickets-helpers.hl relationViewOf) of a ticket and its related onesticketsRelated = (views, session) => { return true }// ticket #21: an app was connected / disconnected — the project page refreshes its lineconnectionsChanged = (slug, session) => { return true }signedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }signedOut = (tag, session) => { return tag != null && tagOf(session) == tag }}sessionDir = env('TICKETS_SESSIONS') != null ? env('TICKETS_SESSIONS') : nullport = env('TICKETS_PORT') != null ? toNumber(env('TICKETS_PORT')) : 8350// THE LISTENER's interface (mission 010, deploy to Byrodin): hl:web reads HL_HOST (or HOST)// itself (hybriel#24): 127.0.0.1 on Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).// TICKETS_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,// half-copied .hl files must not be re-analysed); unset = on, as before.watching = env('TICKETS_WATCH') != '0'// THE MIGRATION of ticket #20 (lib/migrate.hl): idempotent, runs at every startmigrateAtStartup()// uploadMax (tickets#27): the largest file a page's emit may carry = lib/attachments.hl maxFileBytes (10 MiB; inlined, as a manifest value)// 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// 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).behindHttps = publicUrl.startsWith('https://')server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, uploadMax = 10485760, sessionMaxAge = 3122064000, sessionSecure = behindHttps)useLoginSessions(server.sessions)// THE GLOBAL ERROR HANDLER (ticket #7): a plugin's failure — above all hl:fetch's refused /// timed-out exchange with ident (users.hl exchangeCode, invites.hl) — arrives here instead of aborting the// request with a 500 that shows source paths; the failed call yields null and the caller answers// it ("ident did not answer"). Every absorbed error is logged.on Error(e) {if (e.phase == 'startup') { console.log('tickets: startup error: ' + e.message) exit(1) }console.log('error absorbed: ' + e.message)}// Subscription dispatcher wiring; standby cannot send, main reconciles its numbered rows.hearStream(wakeForRow)__native('eventloop.register', completions(), 'subscriptionWakeCompleted')on subscriptionWakeCompleted(ev) { wakeCompleted(ev) }wakeTimer = every(1)on wakeTimer.tick() { sweepWakes(false) }sweepWakes(true)
Branches
Latest commits
- b8fdeee9Merge branch 'p39-routes' into mainTickets
- a0187a0a|||PR Remove redundant route-order loopmre
- 369e4b9cMerge branch 'k40-lists' into mainTickets
- 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
- 610d8e8aMerge branch 'records-t39' into mainTickets
- 32bcdf24|||PR records: GO P39 K40mre
- 4123c6d1Merge branch 'records-t38' into mainTickets
- 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