Repository navigation
[Task 8] Authenticated Support Desk feedback #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
63064b6
cde88a3
cf73bf7
0234452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # Support Desk composition (pegma.dev) | ||
|
|
||
| Public host composition notes for authenticated product feedback on | ||
| [pegma.dev](https://pegma.dev). This is the ecosystem's Cloudflare reference | ||
| environment for Support Desk customer create / list / read / reply. | ||
|
|
||
| ## Packages | ||
|
|
||
| Exact published versions: | ||
|
|
||
| - `@pegma/support-desk-application@0.1.0` | ||
| - `@pegma/support-desk-contracts@0.1.0` | ||
| - `@pegma/support-desk-core@0.1.0` | ||
| - `@pegma/support-desk-templates@0.1.0` | ||
| - `@pegma/authorization-core@0.1.2` (AccessContext resolution) | ||
|
|
||
| Peers already present on the host: `@pegma/storage-core@0.4.0`, | ||
| `@pegma/storage-cloudflare-d1@0.4.0`, `@pegma/sessions@0.1.0`, | ||
| `@pegma/rate-limit@0.1.0`, `@pegma/identity@0.1.0`, `@pegma/spine@0.1.1`. | ||
|
|
||
| ## Storage namespace | ||
|
|
||
| Support Desk uses the existing `IDENTITY_DB` D1 binding. Isolation is by | ||
| collection name, not by sharing Identity mail cursors or session rows: | ||
|
|
||
| | Concern | Collection / host key | | ||
| | --- | --- | | ||
| | Tickets, messages, audit, commands | `support-desk.records.v1` | | ||
| | Customer ticket index | `support-desk.customer-ticket-index.v1` | | ||
| | Ticket numbers | `support-desk.ticket-numbers.v1` | | ||
| | Queue projection | `support-desk.queue-index.v1` | | ||
| | Host maintenance cursors | `pegma-dev-support-maintenance` | | ||
|
|
||
| Identity keeps its own collections and `pegma-dev-maintenance` cursors. The | ||
| two never share a cursor key. | ||
|
|
||
| ## Authorization | ||
|
|
||
| Any authenticated pegma.dev account receives customer permissions through host | ||
| AccessContext defaults (no paid entitlement): | ||
|
|
||
| - `support.ticket.create` | ||
| - `support.ticket.read.own` | ||
| - `support.ticket.reply.own` | ||
|
|
||
| `principalId` is the Identity principal / account id from the server-side | ||
| session (`__Host-pegma_session`). Browser-supplied identity fields are ignored. | ||
|
|
||
| ## Categories and markers | ||
|
|
||
| Allowlist: `feedback`, `bug`, `feature_request`, `documentation`, `question`. | ||
|
|
||
| Display marker: `[PEG-{number}]`. Public tracking URL: | ||
|
|
||
| `https://pegma.dev/feedback/ticket/?id={ticketId}` | ||
|
|
||
| ## HTTP boundary | ||
|
|
||
| Worker routes (same-origin session + CSRF `X-Pegma-CSRF`): | ||
|
|
||
| | Method | Path | Notes | | ||
| | --- | --- | --- | | ||
| | `GET` | `/api/support/categories` | Auth required | | ||
| | `GET` | `/api/support/tickets` | List own tickets | | ||
| | `POST` | `/api/support/tickets` | Create (rate-limited) | | ||
| | `GET` | `/api/support/tickets/:id` | Read own; missing/non-owned → same 404 | | ||
| | `POST` | `/api/support/tickets/:id/replies` | Reply (rate-limited) | | ||
|
|
||
| Durable rate-limit policies (separate from Identity): | ||
|
|
||
| - `pegma.support.ticket.create` | ||
| - `pegma.support.ticket.reply` | ||
|
|
||
| Site pages: `/feedback` (create + list), `/feedback/ticket/?id=…` (read + reply; static shell). | ||
|
|
||
| ## Maintenance and health | ||
|
|
||
| Minute cron runs Support Desk queue repair and inactive projection sweep with | ||
| independent cursors, plus Support Desk rate-limit sweeps. Mail send for support | ||
| notifications is deferred (templates are defined; create/reply omit | ||
| notification for this first host PR). | ||
|
|
||
| Health always reports Support Desk package detail without message content. A | ||
| store probe runs only when `SUPPORT_HEALTH_PROBE` is exactly `"true"`. | ||
|
|
||
| ## Privacy and retention intent | ||
|
|
||
| - Tickets are private conversations between the authenticated requester and | ||
| authorized operators. | ||
| - Feedback is not automatically published to the roadmap, documentation, or | ||
| GitHub Issues. | ||
| - Staff UI is deferred. | ||
| - Queue projection terminal retention follows Support Desk's default | ||
| (30 days) for inactive projection rows; authoritative ticket retention and | ||
| export/redaction procedures remain host operational policy and will be | ||
| documented further before accepting production-sensitive data at scale. | ||
|
|
||
| Built in the open by RetireGolden, LLC. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| const statusNode = document.querySelector('#ticket-status'); | ||
| const signedOut = document.querySelector('#ticket-signed-out'); | ||
| const detail = document.querySelector('#ticket-detail'); | ||
| const heading = document.querySelector('#ticket-heading'); | ||
| const meta = document.querySelector('#ticket-meta'); | ||
| const messageList = document.querySelector('#message-list'); | ||
| const replyForm = document.querySelector('#reply-form'); | ||
| const ticketId = new URL(window.location.href).searchParams.get('id') ?? ''; | ||
|
|
||
| let csrfToken = ''; | ||
|
|
||
| function showStatus(message, isError = false) { | ||
| statusNode.textContent = message; | ||
| statusNode.dataset.tone = isError ? 'error' : 'neutral'; | ||
| } | ||
|
|
||
| async function api(path, init = {}) { | ||
| const headers = new Headers(init.headers); | ||
| if (init.body !== undefined) { | ||
| headers.set('Content-Type', 'application/json'); | ||
| } | ||
| if (csrfToken !== '') { | ||
| headers.set('X-Pegma-CSRF', csrfToken); | ||
| } | ||
| const response = await fetch(path, { | ||
| ...init, | ||
| headers, | ||
| credentials: 'same-origin', | ||
| }); | ||
| const body = await response.json(); | ||
| if (!response.ok) { | ||
| const error = new Error( | ||
| typeof body.error === 'string' ? body.error : 'request_failed', | ||
| ); | ||
| error.status = response.status; | ||
| throw error; | ||
| } | ||
| return body; | ||
| } | ||
|
|
||
| function renderMessages(messages) { | ||
| messageList.replaceChildren(); | ||
| for (const message of messages) { | ||
| const item = document.createElement('li'); | ||
| const who = document.createElement('strong'); | ||
| who.textContent = | ||
| message.authorKind === 'customer' | ||
| ? 'You' | ||
| : message.authorKind === 'staff' | ||
| ? 'Pegma' | ||
| : 'System'; | ||
| const when = document.createElement('span'); | ||
| when.className = 'form-note'; | ||
| when.textContent = new Date(message.createdAt).toLocaleString(); | ||
| const body = document.createElement('p'); | ||
| body.textContent = message.body; | ||
| item.append(who, ' · ', when, body); | ||
| messageList.append(item); | ||
| } | ||
| } | ||
|
|
||
| function renderTicket(view) { | ||
| heading.textContent = `${view.ticket.marker} ${view.ticket.subject}`; | ||
| meta.textContent = `${view.ticket.status} · ${view.ticket.category ?? 'uncategorized'}`; | ||
| renderMessages(view.messages); | ||
| } | ||
|
|
||
| async function loadTicket() { | ||
| if (ticketId === '') { | ||
| showStatus('Missing ticket id.', true); | ||
| return; | ||
| } | ||
| const idDisplay = document.querySelector('#ticket-id-display'); | ||
| if (idDisplay) idDisplay.textContent = ticketId; | ||
| try { | ||
| await api('/api/identity/account'); | ||
| } catch (error) { | ||
| if (error.status === 401) { | ||
| signedOut.hidden = false; | ||
| detail.hidden = true; | ||
| showStatus('Sign in to view this ticket.'); | ||
| return; | ||
| } | ||
| throw error; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| try { | ||
| const view = await api( | ||
| `/api/support/tickets/${encodeURIComponent(ticketId)}`, | ||
| ); | ||
| if (typeof view.csrfToken === 'string') { | ||
| csrfToken = view.csrfToken; | ||
| } | ||
| signedOut.hidden = true; | ||
| detail.hidden = false; | ||
| renderTicket(view); | ||
| showStatus('Ticket loaded.'); | ||
| } catch (error) { | ||
| signedOut.hidden = true; | ||
| detail.hidden = true; | ||
| if (error.status === 401) { | ||
| signedOut.hidden = false; | ||
| showStatus('Sign in to view this ticket.'); | ||
| return; | ||
| } | ||
| if (error.status === 404) { | ||
| showStatus('Ticket not found.', true); | ||
| return; | ||
| } | ||
| showStatus(`Could not load ticket: ${error.message}`, true); | ||
| } | ||
| } | ||
|
|
||
| replyForm.addEventListener('submit', async (event) => { | ||
| event.preventDefault(); | ||
| try { | ||
| const form = new FormData(replyForm); | ||
| showStatus('Sending reply…'); | ||
| const view = await api( | ||
| `/api/support/tickets/${encodeURIComponent(ticketId)}/replies`, | ||
| { | ||
| method: 'POST', | ||
| body: JSON.stringify({ body: form.get('body') }), | ||
| }, | ||
| ); | ||
| replyForm.reset(); | ||
| renderTicket(view); | ||
| showStatus('Reply sent.'); | ||
| } catch (error) { | ||
| showStatus(`Could not send reply: ${error.message}`, true); | ||
| } | ||
| }); | ||
|
|
||
| loadTicket(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadTicket() preflights
/api/identity/accountand rethrows any error that is not status 401. loadTicket() is invoked without a rejection handler. Identity runtime unavailability (503), network failure, or non-JSON responses therefore become unhandled promise rejections while the page remains on "Loading ticket…". The list page (feedback.js) handles the same class of failure with a user-visible status message; the ticket page does not.Suggestion: In the identity preflight catch, treat non-401 failures the same way as the ticket-load catch: set detail hidden, call showStatus with a clear unavailable message, and return. Do not rethrow.