feat(pos-app): unify merchant API into single client#395
feat(pos-app): unify merchant API into single client#395ignaciosantise merged 3 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @ignaciosantise's task in 3m 27s —— View job PR Review: feat(pos-app): unify merchant API into single client
Found 6 issue(s)Issue 1: Missing timeout on external fetch in Vercel proxyID: transactions-proxy-fetch-timeout-d2f1 Context:
Recommendation: const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
const response = await fetch(`${normalizedBaseUrl}${endpoint}`, {
signal: controller.signal,
headers: { ... },
});
clearTimeout(timeoutId);Issue 2: Security model shift not documented — API key now client-forwarded to proxyID: brk-api-transactions-require-client-apikey-f5d9 Context:
Recommendation: Add a migration note in AGENTS.md or README that operators should remove the old server env vars and ensure Issue 3: merchantId not URL-encoded in native transactions endpoint pathID: transactions-native-merchantid-urlencode-c4a7 Context:
Recommendation: const endpoint = `/merchants/${encodeURIComponent(merchantId)}/payments${queryString ? `?${queryString}` : ""}`;Issue 4: AGENTS.md reports stale versionCode; app.json not incremented for this featureID: agents-md-versioncode-stale-increment-b3e8 Context:
Recommendation: Increment Issue 5: console.error in Vercel serverless functionID: api-transactions-console-error-logs-a8f5 Context:
Recommendation: Remove the Issue 6: Redundant, weaker merchantId guard in native transactions.tsID: transactions-native-redundant-merchantid-check-f2a3 Context:
Recommendation: Either remove the early check (rely on Data classification: No issues found — no hardcoded secrets, credentials correctly read from secure storage at runtime. Breaking changes summary: Deletion of |
There was a problem hiding this comment.
Pull request overview
This pull request consolidates the separate Merchant Portal API integration into the unified Payment API, eliminating code duplication and simplifying credential management across both native and web platforms.
Changes:
- Extracted
getApiHeaders()to shared client module to eliminate duplication - Updated both native and web transaction services to use unified API client with consistent authentication
- Modified Vercel proxy to forward unified auth headers (
Api-Key,Merchant-Id, SDK headers) to the backend API - Removed obsolete merchant-specific client, environment variables, and documentation references
- Fixed test mock to preserve real
getApiHeaders()after module export migration
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
dapps/pos-app/services/transactions.web.ts |
Web version now passes API key via header to proxy instead of relying on server-side config |
dapps/pos-app/services/transactions.ts |
Native version switched from merchant-client to unified apiClient with getApiHeaders() |
dapps/pos-app/services/payment.ts |
Removed duplicate getApiHeaders() implementation, now imports from client module |
dapps/pos-app/services/merchant-client.ts |
Deleted entire duplicate API client implementation |
dapps/pos-app/services/client.ts |
Added exported getApiHeaders() function with authentication logic |
dapps/pos-app/api/transactions.ts |
Proxy updated to forward unified auth headers instead of separate merchant portal key |
dapps/pos-app/__tests__/services/payment.test.ts |
Fixed mock to use jest.requireActual() pattern to preserve getApiHeaders() |
dapps/pos-app/AGENTS.md |
Updated documentation to reflect unified API and added test maintenance guidance |
dapps/pos-app/.env.example |
Removed obsolete EXPO_PUBLIC_MERCHANT_API_URL and EXPO_PUBLIC_MERCHANT_PORTAL_API_KEY |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Consolidate to single base URL (EXPO_PUBLIC_API_URL) for both Payment and Merchant APIs, removing EXPO_PUBLIC_MERCHANT_API_URL. Delete redundant merchant-client.ts and reuse apiClient. Extract getApiHeaders() to shared client module for payment endpoints. Merchant endpoints retain separate auth via EXPO_PUBLIC_MERCHANT_PORTAL_API_KEY since the Merchants API has its own auth layer. Added TODOs for when APIs unify auth. Fix incomplete test mock after module export migration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
842345d to
2450da6
Compare
Summary
Consolidate Payment and Merchant APIs to use a single base URL (
EXPO_PUBLIC_API_URL), eliminating the separateEXPO_PUBLIC_MERCHANT_API_URL. The Merchant Portal API retains its own authentication (EXPO_PUBLIC_MERCHANT_PORTAL_API_KEY) since it currently has a separate auth layer from the Payment API.merchant-client.ts— reuse sharedapiClientfromclient.ts(same base URL)getApiHeaders()toclient.tsas shared helper for payment endpointsapiClientwith merchant portal API key (x-api-keyheader)EXPO_PUBLIC_MERCHANT_PORTAL_API_KEYserver-side; client only sendsx-merchant-idEXPO_PUBLIC_MERCHANT_API_URLfrom.env.example(no longer needed)payment.test.tsaftergetApiHeaders()module migrationnpm testto AGENTS.md pre-commit checklist + mock maintenance guidancegraph LR subgraph "Before" PA1["Payment API"] -->|"EXPO_PUBLIC_API_URL<br/>Api-Key (partner)"| API1["Backend"] MA1["Merchant API"] -->|"EXPO_PUBLIC_MERCHANT_API_URL<br/>x-api-key (portal)"| API2["Backend"] end subgraph "After" PA2["Payment API"] -->|"EXPO_PUBLIC_API_URL<br/>Api-Key (partner)"| API3["Backend"] MA2["Merchant API"] -->|"EXPO_PUBLIC_API_URL<br/>x-api-key (portal)"| API3 endTest plan
npm test)🤖 Generated with Claude Code