Repository navigation
feat(facility): API keys and webhooks management for facility system … - #167
Conversation
|
@Bolajiomo99 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@Bolajiomo99 Thanks for the PR. It can't be merged yet. To unblock it: Merge conflicts: this branch conflicts with Push to this same branch and CI will re-run. Once it's green and conflict-free, it'll be reviewed for merge. |
|
@Bolajiomo99 This PR now has merge conflicts with git fetch upstream # upstream = https://github.com/DocForum/docforum-web.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-leaseThe usual culprits are shared docs like Automated message. It won't repeat unless the PR conflicts again after your next push. |
|
@Bolajiomo99 CI is failing on this branch against the latest Frontend (typecheck + test + build)
This PR also conflicts with |
ccda56d to
914e815
Compare
|
@Bolajiomo99 This PR now has merge conflicts with git fetch upstream # upstream = https://github.com/DocForum/docforum-web.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-leaseThe usual culprits are shared docs like Automated message. It won't repeat unless the PR conflicts again after your next push. |
|
Kindly review and merge |
afeezorobsco-cyber
left a comment
There was a problem hiding this comment.
Sweep: malware scan clean, CI green.
feat(facility): API keys and webhooks management for facility system integrations
Closes #55
Branch:
feat/api-keys-and-webhooks-management-for-facilityCommit:
22105e3Phase: W4 — Facility core flow (PRD §4 facility integration/fulfillment surfaces)
Depends on: DocForum/docforum-core#125 (facility API keys with HMAC signing) and DocForum/docforum-core#126 (signed outbound webhooks). Neither has landed yet, so this is built against the documented assumed contracts recorded in
ARCHITECTURE_ESSENTIALS.md→ “Known assumptions — Phase W4”.Summary
Labs and pharmacies can now integrate their own software without opening a support ticket:
localStorage,sessionStorage, URLs, logs, or the React Query caches after the dialog closes.The new page lives at
/facility/integrationsand is linked from the header nav and every facility tab bar.Description / What changed and why
1. Types (
src/types/models.ts)Added a new “Phase W4 — API keys & webhooks” section mirroring the assumed
docforum-corecontract (hard rule 2 — no parallel frontend-only shapes):FacilityApiKeyCreatedApiKey(only response carryingsecret)CreateApiKeyInputWebhookEventTypeWebhookEndpointCreatedWebhookEndpoint(only response carryingsigningSecret)CreateWebhookInputWebhookDeliveryStatusWebhookDeliveryRedeliverResponseThe full secret is deliberately absent from
FacilityApiKeyand the full signing secret is absent fromWebhookEndpoint, so ordinary list responses cannot leak them.2. Service layer (
src/services/integrations-service.ts)All calls go through
apiFetchinapi-client.ts— no directfetch, no Stellar/escrow calls (hard rule 1):listApiKeys,createApiKey,revokeApiKeylistWebhookEndpoints,createWebhookEndpoint,deleteWebhookEndpointlistWebhookDeliveries,sendTestDelivery,redeliverWebhook3. Hooks (
src/features/integrations/hooks/useIntegrations.ts)React Query queries/mutations namespaced by
['facility', facilityId, …]:useApiKeys,useWebhookEndpoints,useWebhookDeliveriesuseCreateApiKey,useRevokeApiKey,useCreateWebhookEndpoint,useDeleteWebhookEndpoint,useSendTestDelivery,useRedeliverWebhookgcTime: 0, so the mutation result (which contains the one-time secret) is evicted as soon as the dialog observer is removed.4. Feature UI (
src/features/integrations/)IntegrationsView— page header, integration docs link, owner-only access check.ApiKeysPanel— active key table, revoked-key section, create/revoke actions.CreateApiKeyDialog— name form → secret-once screen with warning + copy.WebhooksPanel— endpoint cards with URL, active state, secret prefix, events, last delivery, send-test/recent-deliveries/delete actions.CreateWebhookDialog— URL + event subscriptions → signing-secret-once screen with warning + copy.WebhookDeliveries— recent deliveries table (event, status, response code/error, attempts, delivered time) with redelivery forfailed/pending.Integrations.module.css— responsive styles consistent with the existing facility CSS modules.Integrations.test.tsx— 15 component tests (see below).5. Routing and navigation
src/pages/FacilityIntegrationsPage.tsx— facility tab nav +<IntegrationsView />.src/App.tsx—facility/integrationsroute declared before thefacility/*catch-all, wrapped inRequireAuth allowedRoles={['facility']}.src/components/Layout.tsx— “Integrations” header link for facility users.FacilityDashboardPage,FacilityPaymentsPage,FacilityTeamPage,OrderVerifyPage— Integrations tab added to each facility tab bar.6. Mock API (MSW)
src/mocks/fixtures.ts— seeded fake API keys, webhook endpoints, and deliveries (allexample.test, clearly labelled “fake”).src/mocks/handlers/integrations.ts— list/create/revoke keys, list/create/delete endpoints, list/test/redeliver deliveries. Create responses return the secret once; stored records omit it.src/mocks/handlers.ts— handler registration.src/mocks/handlers.test.ts— 5 new integration tests driven through the real service layer.7. Documentation / roadmap
ROADMAP.md— issue [Phase W4] API keys and webhooks management for facility system integrations #55 marked complete under Phase W4 and a changelog line added.ARCHITECTURE_ESSENTIALS.md— new “Phase W4 — API keys & webhooks” known-assumptions section documenting every assumed endpoint/shape, the one-time-secret rule, and owner-only expectations.Security / edge-case handling
mutation.reset()and create mutations usegcTime: 0; tests assert the secret is absent from both the query and mutation caches after close.localStorage,sessionStorage, URLs, or logs; a test asserts storage is clean.FacilityApiKey/WebhookEndpointtypes and mock handlers omit full secrets — only prefixes are listed.http(s)before submit is enabled.failedandpendingrows expose “Redeliver”; successful rows do not.facility; the view additionally checks ownership.Tests
New component tests (
src/features/integrations/components/Integrations.test.tsx) — 15 testsNew MSW handler tests (
src/mocks/handlers.test.ts) — 5 testsActual local verification
GitHub Actions will run the same gates on this branch.
Screenshots
All captured in
screenshots/at desktop 1440×1000 and mobile 390×844.Integrations page
Create API key
API key secret shown once
Create webhook endpoint
Webhook signing secret shown once
Recent deliveries
Definition of done mapping
/facility/integrations)ROADMAP.mdupdated (status + changelog)ARCHITECTURE_ESSENTIALS.md“Known assumptions — Phase W4” updatednpm run typecheckgreennpm testgreen (393 tests)npm run buildgreennpm run check:distgreen (no mocks in production bundle)How to manually verify
Open:
Then:
Run the automated suite with:
npm run typecheck npm test npm run build npm run check:distArchitecture / repo-rule compliance
docforum-escrowor Stellar calls from this repo — everything goes throughdocforum-core’s API.src/types/models.ts; no parallel frontend-only entity shapes.pages/ components/ features/ hooks/ services/ store/ types/preserved.ROADMAP.mdupdated.Known assumptions / follow-ups
Because
docforum-core#125 and #126 have not landed, the endpoint shapes are assumptions and are documented inARCHITECTURE_ESSENTIALS.md:GET/POST /facilities/:facilityId/api-keysDELETE /facilities/:facilityId/api-keys/:keyIdGET/POST /facilities/:facilityId/webhooksDELETE /facilities/:facilityId/webhooks/:endpointIdGET/POST /facilities/:facilityId/webhooks/:endpointId/deliveriesand/testPOST /facilities/:facilityId/webhooks/:endpointId/deliveries/:deliveryId/redeliverorder.created,order.assigned,order.fulfilled,order.cancelled,payment.released,payment.refundedrevokedAtrather than hard-deleting itShould the real contracts differ, the only places to reconcile are
src/types/models.ts,src/services/integrations-service.ts, and the mock handlers.Potential follow-up issues (not in scope for #55):
docforum-corecontract reconciliation once [Platform] Real-user Web Vitals monitoring (privacy-preserving) #125/[Platform] Search across my own records (appointments, orders, results, messages) #126 land.docforum-core’sdocs/api/README.mdbecause no dedicated docs page exists yet).