gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd662ad27d662ad27Remove superseded waker service for direct chat push protocolmred662ad27/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

  • d662ad27Remove superseded waker service for direct chat push protocolmre
  • ff2e8701Finalize subscription build verification and handoff reportmre
  • 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
  • 1b5c63ddTickets conductor: P51 startedmre
  • 9f13fbdaTickets conductor: brief 026 prioritymre
  • acc477d9Tickets conductor: brief 026 + Vinzenz recommendationsmre
  • 9233a734Tickets conductor: brief 026 completemre
  • 5da589fdTickets conductor: brief 026 + Gitoria's answermre
  • a3cd5329Tickets conductor: tickets#51 opened, brief 026 draftmre
  • 6f6e5797Tickets conductor: STATUS wordingmre
  • 957de51fTickets conductor: T36 live, #36 review, #50 donemre
  • bc2fde32Merge branch 'main' into t36-stylemre
  • b7ca093atests: wait for the new row and normalize editor marker spacesmre