Repository navigation
fix: stripe expand depth + WorkOS invite for static admin key - #4207
Merged
Merged
Conversation
- getAllOpenInvoices passed a 5-level expand path; Stripe caps it at 4, so every "all open invoices" call failed and returned []. Drop the deep expand and resolve product names via stripe.products.retrieve with a per-call cache, mirroring getRevenueEvents. - POST /members/by-email Path 1 passed `inviterUserId: 'admin_api_key'` (the synthetic ADMIN_API_KEY user id) when the caller authed via the static API key, which WorkOS rejected with "User not found: 'admin_api_key'". Omit inviterUserId for that auth path; audit log still records inviter_email. Adds regression tests for both: a Stripe stub that 400s on >4-level expand, and a by-email integration test that asserts inviterUserId is omitted when isStaticAdminApiKey is set. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
getAllOpenInvoices wrapped its work in try/catch that returned [] on any
error, which is exactly what hid the original 4-level-expand bug as "No
pending invoices found" for admins. Drop the swallow; the sole caller
(list_pending_invoices admin handler) already has its own try/catch that
returns a structured `{ success: false, error }` response.
Pin tests harder against the original bugs:
- Stripe: split into two tests — one that asserts every expand path the
function sends is <=4 levels, and a second that confirms a Stripe-side
error reaches the caller via `rejects.toThrow`.
- by-email: assert `'inviterUserId' in args === false` rather than
`=== undefined`, so a regression that re-introduces an explicit
`inviterUserId: undefined` (or 'admin_api_key') fails.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 8, 2026
Contributor
Author
|
Issue #4208 proposes audit-log enrichment for every static-admin-gated mutation ( Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two production errors surfaced by Addie's system-error channel.
1. Stripe —
getAllOpenInvoicesexceeds 4-level expand capserver/src/billing/stripe-client.tspassedexpand: ['data.customer', 'data.lines.data.price.product']oninvoices.list.data.lines.data.price.productis 5 levels and Stripe capsexpandat 4, so Stripe returned a 400 and the function silently swallowed it and returned[]. Effect: every admin "all open invoices" call was empty.Fix: drop the deep expand and resolve product names via
stripe.products.retrievewith a per-callMapcache. Mirrors the existing pattern ingetRevenueEvents(same file).2. WorkOS —
sendInvitationrejects syntheticadmin_api_keyuserPOST /api/organizations/:orgId/members/by-email(Path 1: WorkOS user does not exist yet) passedinviterUserId: user.id. When the caller authenticates via the staticADMIN_API_KEY,user.id === 'admin_api_key'(synthetic — seeserver/src/middleware/auth.ts:745), and WorkOS respondsUser not found: 'admin_api_key'. The endpoint already special-cases the static-admin path for the membership lookup; it now also omitsinviterUserIdfor that path. Audit attribution remains via the existinginviter_emailfield on the audit log entry. Unblocks the Triton incident-script flow (scripts/incidents/2026-04-triton-promote-hayem.ts).Test plan
npx vitest run tests/billing/stripe-client.test.ts— added two regression tests:expandpath > 4 levels; asserts no path the function sends exceeds 4 levels.productids; assertsproduct_nameis populated via separateproducts.retrieveand that the cache prevents N+1.DATABASE_URL=... npx vitest run server/tests/integration/member-by-email-policy.test.ts— added two regression tests:inviterUserIdis set to the caller's id.req.user.id = 'admin_api_key',req.isStaticAdminApiKey = true):inviterUserIdisundefined, all other fields unchanged.tsc --project server/tsconfig.json --noEmittest:unit,test:test-dynamic-imports,test:callapi-state-change,typecheck)🤖 Generated with Claude Code