feat(pos): add secure dashboard bridge - #608
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Claude finished @ignaciosantise's task in 3m 50s —— View job PR Review: feat(pos): add secure dashboard bridge
🚨 PR Too Large
Found 4 issue(s)Issue 1: Legacy
|
There was a problem hiding this comment.
Pull request overview
Adds a locked-origin, in-memory postMessage bridge for the pos-app web runtime so embedded POS API operations are executed by the parent dashboard (server-side), while removing URL / legacy postMessage credential intake and adjusting UI flows accordingly.
Changes:
- Introduces a POS bridge transport (
pos-bridge.ts+usePosBridgeStore) and a web hook (use-pos-bridge) to configure it after settings hydration. - Routes web payment/transaction services through the bridge when configured, otherwise preserves the existing direct proxy behavior.
- Updates Settings/Home/Failure UI logic to reflect bridge mode (read-only merchant identity, hides local API-key UI, adjusted setup gating) and replaces legacy URL-credential tests with bridge tests.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dapps/pos-app/utils/pos-bridge-ui.ts | New helper functions to drive bridge-mode UI gating and setup state. |
| dapps/pos-app/store/usePosBridgeStore.ts | Adds runtime-only Zustand store for bridge configuration state (non-persisted). |
| dapps/pos-app/services/transactions.web.ts | Uses the bridge for get-transactions when configured; otherwise keeps proxy flow. |
| dapps/pos-app/services/pos-bridge.ts | Implements the locked parent/origin transport + request/response correlation + timeout. |
| dapps/pos-app/services/payment.web.ts | Routes start/status/cancel payment calls through the bridge when configured. |
| dapps/pos-app/hooks/use-url-credentials.ts | Removes URL/postMessage credential intake hook. |
| dapps/pos-app/hooks/use-pos-bridge.ts | Adds bridge initialization/configuration hook and readiness announcement. |
| dapps/pos-app/app/settings.tsx | Makes bridge-managed merchant ID read-only; hides local key UI in bridge mode. |
| dapps/pos-app/app/payment-failure.tsx | Changes invalid-key routing logic to avoid sending bridge users to Settings. |
| dapps/pos-app/app/index.tsx | Updates “terminal configured” gating to allow bridge mode (no local API key). |
| dapps/pos-app/app/_layout.tsx | Swaps legacy URL-credential hook for the new bridge hook. |
| dapps/pos-app/tests/utils/pos-bridge-ui.test.ts | Adds unit coverage for the new UI helper logic. |
| dapps/pos-app/tests/services/web-bridge-services.test.ts | Adds coverage ensuring web services avoid local key/fetch in bridge mode. |
| dapps/pos-app/tests/services/pos-bridge.test.ts | Adds transport-level tests (validation, locking, timeouts, concurrency). |
| dapps/pos-app/tests/hooks/use-url-credentials.test.ts | Removes tests for the deleted URL/postMessage credential intake flow. |
| dapps/pos-app/tests/hooks/use-pos-bridge.test.ts | Adds tests for bridge hook behavior and legacy credential ignoring. |
Suppressed comments (1)
dapps/pos-app/hooks/use-pos-bridge.ts:62
- If
clearCustomerApiKey()throws during initialization (e.g., secure storage unavailable),initialize()rejects andpos-readyis never posted, leaving the embedded POS unable to configure. Catch and ignore (or log) this error so bridge setup can continue.
if (window.parent !== window) {
// Do not retain an old local key while an embedded POS is waiting for
// bridge configuration. No URL or legacy credential fallback exists.
await clearCustomerApiKey();
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Interaction
sequenceDiagram participant POS as POS iframe participant Dashboard as Dashboard browser participant Action as Dashboard server action participant Proxy as POS /api proxy POS->>Dashboard: pos-ready (protocol v1) Dashboard->>POS: pos-bridge-config (merchant ID only) POS->>Dashboard: pos-api-request (request ID + fixed operation) Dashboard->>Action: authenticated, validated request Action->>Proxy: server-side request with partner API key Proxy-->>Action: payment result or structured error Action-->>Dashboard: bridge result Dashboard->>POS: pos-api-response (matching request ID)The partner API key never enters the POS iframe, browser storage, browser network requests, or postMessage payloads.
Validation
npm run lintnpm test -- --runInBand __tests__/hooks/use-pos-bridge.test.ts __tests__/services/pos-bridge.test.ts __tests__/services/web-bridge-services.test.ts __tests__/utils/pos-bridge-ui.test.tsFull test suite has one pre-existing payment-error copy assertion failure; full format check has two unrelated existing formatting findings.