Skip to content

fix(stripe-webhook): resolve stripe the way the deployed api does - #927

Merged
thinkclay merged 1 commit into
mainfrom
fix/retire-stripe-webhook
Sep 27, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/retire-stripe-webhook

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #923.

stripe-webhook/deno.json pinned npm:[email protected] — a version npm never published (the 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 the opposite of what I expected

#923 guessed the api function had taken over Stripe webhooks and this was a leftover to delete. It hasn't.

  • api/routes/webhooks.ts is a webhook management CRUD API (list/create endpoints)
  • api/routes/payments.ts has no constructEvent, no stripe-signature

Nothing 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:

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 isn't instant — 3DS/SCA, later failures, cancellations. That gap is real and this PR does not close it — the function still isn't in deploy-functions.sh and 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.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 entirely 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.

Also migrated to the lazy getStripeClass() shape 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 '2024-06-20' → '2025-11-17.clover', matching payments.ts and _shared/id-verification-api.ts.

Result

before:  error: Could not find npm package 'stripe' matching '14.26.0'
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 deliberately

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 I reverted the reformat and left the drift pre-existing. Same call I made on the sibling Tabs files 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

`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]>
@thinkclay

Copy link
Copy Markdown
Contributor Author

Merging on a green run, with one caveat recorded rather than glossed: the type-check ratchet did not run in CI for this PR.

api-tests.yml is path-filtered to packages/supabase/functions/api/**, and this PR only touches functions/stripe-webhook/ plus the baseline. So the job that would have verified stripe-webhook now type-checks — the whole point of the change — never fired.

I ran it locally instead:

✓ Edge function type errors within baseline (380 total — … stripe-webhook 0 …)

and deno check --node-modules-dir=auto index.ts on the function exits 0 where it previously could not load at all.

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 api. A new type error in notify-publish or trpc would sail through. Fixing it next — the ratchet wants to hang off ci.yml's existing gate job, which already filters on packages/**, rather than living behind an api-only filter.

@thinkclay
thinkclay merged commit f2d3d08 into main Sep 27, 2026
9 checks passed
@thinkclay
thinkclay deleted the fix/retire-stripe-webhook branch September 27, 2026 00:11
thinkclay added a commit that referenced this pull request Sep 27, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(stripe-webhook): pins npm:[email protected], a version that does not exist — deno cannot load the function at all

1 participant