gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc980856cc980856cRecord successful subscriptions deployment and live checksmrec980856c/lib/subscriptions-api.hl

2.0 KB

  1. // Thin token-only wrappers; cookies, project keys and ident access keys do not own subscriptions.
  2. import { Response } from 'hl:http1'
  3. import { userOfBearer } from './users.hl'
  4. import { jsonErrorAt } from './jsoncheck.hl'
  5. import { hdr, fail, unauthorizedFor, wantsMarkdown } from './api-helpers.hl'
  6. import { subscriptionsFor, createSubscription, removeSubscription, subscriptionDelta } from './subscriptions.hl'
  7. static answer = (status, data, markdown) => {
  8. return new Response(markdown ? data : JSON.stringify(data), { status = status headers = hdr({ 'Content-Type' = markdown ? 'text/markdown; charset=utf-8' : 'application/json; charset=utf-8' 'Cache-Control' = 'no-store' 'Vary' = 'Accept' }) })
  9. }
  10. static result = (r, status) => { return answer(r.error != null ? (r.forbidden == true ? 403 : (r.status != null ? r.status : 400)) : status, r, false) }
  11. static subscriptionsApi = (route, req) => {
  12. if (req.method != 'GET' && req.method != 'POST') { return fail(405, 'GET or POST') }
  13. u = userOfBearer(req.headers['authorization'])
  14. if (u == null) { return unauthorizedFor('subscriptions') }
  15. if (req.method == 'GET') { return result(subscriptionsFor(u), 200) }
  16. if (req.body == null || req.body == '' || req.body.length > 32768 || jsonErrorAt(req.body) >= 0) { return fail(400, 'invalid JSON body (maximum 32768 characters)') }
  17. return result(createSubscription(u, JSON.parse(req.body)), 201)
  18. }
  19. static deltaApi = (route, req) => {
  20. if (req.method != 'GET') { return fail(405, 'GET only') }
  21. u = userOfBearer(req.headers['authorization'])
  22. if (u == null) { return unauthorizedFor('subscriptions') }
  23. md = wantsMarkdown(req)
  24. q = req.query != null ? req.query : {}
  25. r = subscriptionDelta(route.params.id, u, q.peek == '1', md)
  26. if (r.error != null) { return result(r, 200) }
  27. return answer(200, md ? r.text : r.data, md)
  28. }
  29. static removeSubscriptionApi = (route, req) => {
  30. if (req.method != 'POST') { return fail(405, 'POST only') }
  31. u = userOfBearer(req.headers['authorization'])
  32. if (u == null) { return unauthorizedFor('subscriptions') }
  33. return result(removeSubscription(route.params.id, u), 200)
  34. }

Branches

Latest commits

  • c980856cRecord successful subscriptions deployment and live checksmre
  • 4b4710adMerge branch 's51-subscriptions'mre
  • a731ef7eTickets conductor: S51 reviewed, deploy stepmre
  • b487b05aRecord verified direct push protocol handoffmre
  • 74e34cc3Verify encrypted push secrets and direct push retry semanticsmre
  • a1ac5cd0Push subscription notices directly to signed HyperConductor chat endpointsmre
  • d662ad27Remove superseded waker service for direct chat push protocolmre
  • c0ac927aTickets conductor: S51 redo for push protocolmre
  • ff2e8701Finalize subscription build verification and handoff reportmre
  • 07c6daeeTickets conductor: push allowlist URLsmre
  • 8517d14cTickets conductor: Hermes push endpointmre
  • aa4e192cTickets conductor: brief 027 push protocol changemre
  • 54bc5fe1Harden delta relevance, overflow caps and retry verificationmre
  • 8d8e2053Document subscription contract and exercise delta deliverymre
  • fd23726aAdd subscription delta API and signed wake bridgemre
  • c5d28fb5Tickets conductor: S51 startedmre
  • fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
  • e448e656Tickets conductor: STATUS #51mre
  • 1c10857bTickets conductor: P51 eval, brief 027mre
  • e725969dTickets conductor: #51 directionmre