Repository navigation
fix(stripe-webhook): resolve stripe the way the deployed api does - #927
Conversation
`stripe-webhook/deno.json` pinned `npm:[email protected]`, a version npm never published — its 14.x line ends at 14.25.0. `index.ts:2` does `import Stripe from 'stripe'`, so the import could never resolve and deno could not load the function at all. ## Not dead code, which is what I expected to find #923 guessed the `api` function had taken over Stripe webhooks and this was a leftover to delete. It has not. `api/routes/webhooks.ts` is a webhook MANAGEMENT CRUD API, and `api/routes/payments.ts` has no `constructEvent`, no `stripe-signature` — nothing in the repo receives Stripe events except this file. Meanwhile the deployed api does create payment intents (`payments.ts:774`) and records a terminal status only when Stripe confirms synchronously: confirm: Boolean(paymentMethodId) status: paymentIntent.status === "succeeded" ? "succeeded" : "pending" Nothing else writes `payment_transactions.status`. So this handler is load-bearing for every outcome that is not instant — 3DS/SCA, later failures, cancellations. Filed separately as the deployment gap it is; this commit only makes the code valid and visible. ## The fix is a deletion, not a repin `packages/supabase/package.json` declares `"stripe": "20.4.1"`, and that is how the deployed api resolves a bare `import("stripe")` — it has no stripe entry in its own import map. This function was overriding that with a nonexistent version. Removing its `deno.json` lets it inherit `functions/deno.json` exactly like the notify-* siblings that already type-check clean, and leaves one Stripe version in the codebase instead of two. Migrated to the lazy `getStripeClass()` shape `api/routes/payments.ts` uses, for the reason that file uses it: a top-level runtime import is evaluated at module load, which is where this file called `createFetchHttpClient()` and `createSubtleCryptoProvider()`. Those now run inside the handler. `STRIPE_API_VERSION` moves from '2024-06-20' to '2025-11-17.clover', matching payments.ts and _shared/id-verification-api.ts. ## Result before: deno could not load it — "Could not find npm package 'stripe'" after: Check index.ts, 0 errors `TYPECHECK_BASELINE.json`'s `uncheckable` map is now empty. All 26 edge functions are genuinely checked, with no acknowledged gaps — 13 of them at a clean zero. Left alone: the file is not `deno fmt` clean, and was not before this change (CI only fmt-checks `functions/api`). Running the formatter rewrote 161 lines and buried a 29-line change, so the reformat is reverted and the drift stays pre-existing. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Merging on a green run, with one caveat recorded rather than glossed: the type-check ratchet did not run in CI for this PR.
I ran it locally instead: and That path filter is a real hole in #924, not just an inconvenience here: I claimed there that 12 functions were "held at zero", and that is only true for PRs that happen to also touch |
#929) #924 added a ratchet that type-checks all 26 edge functions and claimed 12 of them were "held at zero". That was only true for PRs that also happened to touch `functions/api/**`. The step lived in api-tests.yml, which is path-filtered: paths: - 'packages/supabase/functions/api/**' - 'packages/supabase/migrations/**' - ... So a new type error in notify-publish, trpc or any of the other 24 never ran the check that was supposed to catch it. #927 demonstrated it: that PR changed `functions/stripe-webhook/` specifically to make it type-check for the first time, went green, and the ratchet never fired. I verified it by hand instead, which is exactly the manual step a gate exists to remove. Moved to ci.yml, hung off the existing `gate` job with a new `edge_fn` filter covering `packages/supabase/functions/**`, `packages/supabase/package.json` and the script itself. ci.yml runs on every PR, so the filter — not the workflow's trigger — decides. Kept as its own job rather than folded into an existing one: it needs deno, which nothing else in ci.yml does, and it should be skippable when no function changed. No pnpm install — the script imports only node: builtins. Removed from api-tests.yml along with the Node setup that existed solely for it. That job goes back to what its name says: linting and formatting the REST API code. This is the same class of defect the ratchet was built to fix — a check that cannot fail on the thing it is meant to guard. It just moved from `continue-on-error: true` to a path filter. Co-authored-by: Claude Opus 5 <[email protected]>
Closes #923.
stripe-webhook/deno.jsonpinnednpm:[email protected]— a version npm never published (the 14.x line ends at 14.25.0).index.ts:2doesimport Stripe from 'stripe', so the import could never resolve and deno could not load the function at all.Not dead code — which is the opposite of what I expected
#923 guessed the
apifunction had taken over Stripe webhooks and this was a leftover to delete. It hasn't.api/routes/webhooks.tsis a webhook management CRUD API (list/create endpoints)api/routes/payments.tshas noconstructEvent, nostripe-signatureNothing in the repo receives Stripe events except this file.
Meanwhile the deployed api creates payment intents (
payments.ts:774) and records a terminal status only when Stripe confirms synchronously:Nothing else writes
payment_transactions.status. So this handler is load-bearing for every outcome that isn't instant — 3DS/SCA, later failures, cancellations. That gap is real and this PR does not close it — the function still isn't indeploy-functions.shand Stripe would need an endpoint pointed at it. Filed separately; this change only makes the code valid and visible.The fix is a deletion, not a repin
packages/supabase/package.jsondeclares"stripe": "20.4.1", and that is how the deployed api resolves a bareimport("stripe")— it has no stripe entry in its own import map. This function was overriding that with a nonexistent version.Removing its
deno.jsonentirely lets it inheritfunctions/deno.jsonexactly like thenotify-*siblings that already type-check clean, and leaves one Stripe version in the codebase instead of two.Also migrated to the lazy
getStripeClass()shapepayments.tsuses, for the reason that file uses it: a top-level runtime import is evaluated at module load, which is where this file calledcreateFetchHttpClient()andcreateSubtleCryptoProvider(). Those now run inside the handler.STRIPE_API_VERSIONmoves'2024-06-20'→'2025-11-17.clover', matchingpayments.tsand_shared/id-verification-api.ts.Result
TYPECHECK_BASELINE.json'suncheckablemap is now empty. All 26 edge functions are genuinely checked with no acknowledged gaps — 13 of them at a clean zero.Left alone deliberately
The file is not
deno fmtclean, and was not before this change — CI only fmt-checksfunctions/api. Running the formatter rewrote 161 lines and buried a 29-line change, so I reverted the reformat and left the drift pre-existing. Same call I made on the siblingTabsfiles in Scaffald/ui#42.What is not verified
The 14 → 20 jump crosses several Stripe API versions, and the event shapes this handler parses (
payment_intent.succeeded/payment_failed/canceled,last_payment_error.message,cancellation_reason) are not exercised by any test — there is no Stripe test-mode fixture here. Type-checking proves it compiles against stripe 20.4.1's types, not that it handles a real 2025-11-17 event correctly. That verification belongs with whoever deploys it.🤖 Generated with Claude Code