From 8ac1e8b31f70b521c3eddc040719ecc3f930fbcf Mon Sep 17 00:00:00 2001 From: Rahul Varghese Date: Thu, 15 Oct 2026 02:00:53 +0530 Subject: [PATCH] SP4: ready to instantiate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The as-built status names the PRs, every departure from upstream (proxy.ts, the ssr 0.12 cookie adapters, the awaited cookies()/createClient()/params, Stripe's fetch client and async webhook verification, the per-call admin client, the React 19 JSX type, Next 16's tsconfig rewrite, the flat eslint config with the template's patterns allowed, package.json scripts and dependencies), the versions with their reasons, what was verified (locally under wrangler dev with fixture vars and dummy Worker secrets, the offline migration plan, terraform validate, Checks on #2–#4) and what was not (the Supabase and migration applies, a live deploy and a real Stripe round-trip, gated on a linked workspace and the product's Stripe keys). The README's local-stack note says pnpm approve-builds, which is what pnpm 10 needs. The epic is completed. Orun-Task: SP-5 Co-Authored-By: Claude Fable 5.1 --- README.md | 6 +- specs/epics/README.md | 2 +- .../IMPLEMENTATION-STATUS.md | 202 +++++++++++++++++- specs/epics/subscription-payments/README.md | 4 +- specs/epics/subscription-payments/epic.yaml | 2 +- .../implementation-plan.md | 10 +- 6 files changed, 209 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a64e8e9..28cd190 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,10 @@ Supabase URL and anon key as vars. The upstream README (`apps/web/README.md`) describes local development with the Supabase CLI and Docker (`pnpm --filter @app/web supabase:start`, …). pnpm 10 blocks the `supabase` package's postinstall, which downloads the CLI -binary; run `pnpm approve-builds` (or `pnpm rebuild supabase`) once if you -want the local stack. CI never needs it. +binary; run `pnpm approve-builds` once and pick `supabase` if you want the +local stack (it allow-lists the package in your checkout's +`pnpm-workspace.yaml`; a plain `pnpm rebuild` does not run a blocked script). +CI never needs it: the runner applies the schema. ## How it maps to Vercel diff --git a/specs/epics/README.md b/specs/epics/README.md index 5011543..9d5152b 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`subscription-payments/`](./subscription-payments/) | **SP** | Draft | Vercel's Next.js Subscription Payments Starter, equivalent in code and function, on Cloudflare Workers with Supabase provisioned and migrated through Orun | +| [`subscription-payments/`](./subscription-payments/) | **SP** | ✅ Shipped | Vercel's Next.js Subscription Payments Starter, equivalent in code and function, on Cloudflare Workers with Supabase provisioned and migrated through Orun | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/subscription-payments/IMPLEMENTATION-STATUS.md b/specs/epics/subscription-payments/IMPLEMENTATION-STATUS.md index 3c1c2df..568011e 100644 --- a/specs/epics/subscription-payments/IMPLEMENTATION-STATUS.md +++ b/specs/epics/subscription-payments/IMPLEMENTATION-STATUS.md @@ -5,12 +5,202 @@ the code departed from `design.md` or from the upstream template. | Milestone | State | PR | |---|---|---| -| SP0 — the spec | In progress | — | -| SP1 — the app on Workers | Pending | — | -| SP2 — the schema through db-migrate | Pending | — | -| SP3 — the Supabase project from Terraform | Pending | — | -| SP4 — ready to instantiate | Pending | — | +| SP0 — the spec | ✅ Shipped | [#1](https://github.com/sourceplane/subscription-payments/pull/1) | +| SP1 — the app on Workers | ✅ Shipped | [#2](https://github.com/sourceplane/subscription-payments/pull/2) | +| SP2 — the schema through db-migrate | ✅ Shipped (planned offline; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/subscription-payments/pull/3) | +| SP3 — the Supabase project from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#4](https://github.com/sourceplane/subscription-payments/pull/4) | +| SP4 — ready to instantiate | ✅ Shipped | [#5](https://github.com/sourceplane/subscription-payments/pull/5) | ## Departures from the upstream template -Filled in as the milestones land. +The template is Next 14 / React 18 / `@supabase/ssr` 0.1 / eslint 8; +`@opennextjs/cloudflare` needs Next ≥ 15.5, so the port runs on Next 16.3.8 +and React 19. Only what Next 16 and Workers force changed; everything below +is the complete list. + +### `middleware.ts` → `proxy.ts` + +Next 16 names the middleware file `proxy.ts` and its export `proxy`. Same +matcher, same `updateSession`; `utils/supabase/middleware.ts` keeps its +name. OpenNext 1.20 bundles it as Node.js middleware (an experimental +warning at build; it works). + +### `@supabase/ssr` 0.12: `getAll` / `setAll` cookie adapters + +The 0.1 `get` / `set` / `remove` cookie API no longer exists. +`utils/supabase/middleware.ts` and `utils/supabase/server.ts` use the +`getAll` / `setAll` pair; the request-and-response cookie dance in the +middleware and the try/catch in the server client (a Server Component +cannot set cookies) are preserved. + +### `cookies()` is async: `createClient()` is async and awaited + +`utils/supabase/server.ts`'s `createClient` awaits `cookies()` and is +therefore `async`; every caller awaits it — `app/page.tsx`, +`app/account/page.tsx`, `app/auth/callback/route.ts`, +`app/auth/reset_password/route.ts`, `app/signin/[id]/page.tsx`, +`components/ui/Navbar/Navbar.tsx`, `utils/stripe/server.ts` (two) and +`utils/auth-helpers/server.ts` (eight). `cookies()` itself is awaited in +`utils/auth-helpers/server.ts` (two), `app/signin/page.tsx` (the component +is `async` now) and `app/signin/[id]/page.tsx`. + +### `params` / `searchParams` are Promises + +`app/signin/[id]/page.tsx` takes `props` and awaits `props.params` and +`props.searchParams` before the template's logic runs unchanged. + +### Stripe on Workers + +`utils/stripe/config.ts` passes `httpClient: Stripe.createFetchHttpClient()`. +`app/api/webhooks/route.ts` verifies with +`await stripe.webhooks.constructEventAsync(body, sig, webhookSecret, +undefined, Stripe.createSubtleCryptoProvider())` instead of the synchronous +`constructEvent`. `stripe` stays on the template's v14 (both adapters are +there); `@stripe/stripe-js` stays at 2.4.0. + +### The service-role client is built per call + +`utils/supabase/admin.ts` built its `createClient(url || '', key || '')` +at module scope. `next build` evaluates `app/api/webhooks/route.ts` while +collecting page data, and supabase-js throws `supabaseUrl is required.` on +an empty URL — so a build without a Supabase project (Checks, a fresh +clone) failed, which on Vercel the integration's env vars hid. +`supabaseAdmin` is a function now (`supabaseAdmin().from(...)` at its ten +call sites), which is also Supabase's guidance for serverless and the +Workers-correct shape (the environment is populated per request). The +rejected alternative was injecting fixture values into a credential-free +build from `next.config.mjs`. + +### React 19 types + +`components/ui/AuthForms/OauthSignIn.tsx`: `JSX.Element` → +`React.JSX.Element` (the global `JSX` namespace is gone). + +### `tsconfig.json`: Next 16's mandatory rewrite + +`next build` rewrites `moduleResolution` to `bundler` and `jsx` to +`react-jsx` and adds `.next/dev/types/**/*.ts` to `include`; those three +changes are committed, in the template's formatting. `bundler` resolution +is also what lets `@opennextjs/cloudflare/config` resolve. `target: es5`, +`baseUrl: "."` (the template's bare `utils/...` and `types_db` imports rely +on it) and everything else stay. + +### `package.json` + +Scripts: `dev` is `next dev` (Next 16 removed `--turbo`; Turbopack is the +default), `lint` is `eslint .` (`next lint` is removed), and `build`, +`preview`, `typecheck` and `wire:fixture` are the port's. The `prettier-fix`, +`stripe:*` and `supabase:*` scripts are as written. Dependencies: `next` +16.3.8, `react` / `react-dom` ^19.2.1, `@supabase/ssr` ^0.12.7, +`@opennextjs/cloudflare`, `wrangler`; devDependencies `eslint` ^9, +`eslint-config-next` 16.3.8, `@types/react*` ^19, `@types/node` ^22. The +template's `eslint-config-prettier`, `eslint-plugin-react` and +`eslint-plugin-tailwindcss` devDependencies are dropped: no eslint config in +the template referenced them (it shipped none). `prettier` and +`prettier-plugin-tailwindcss` stay, as do `.prettierrc.json` and +`.prettierignore`. + +### eslint-config-next 16 flat config, with the template's patterns allowed + +The template had no eslint config and ran `next lint`, which Next 16 +removed. `eslint.config.mjs` is what `create-next-app` writes for Next 16 +(`core-web-vitals` + `typescript`), and the rules that set brings and the +template was never written against are off, each named with its reason: +`@typescript-eslint/no-explicit-any`, `@typescript-eslint/ban-ts-comment`, +`@typescript-eslint/no-non-null-asserted-optional-chain`, +`react/no-unescaped-entities`, `no-var`, `prefer-const`; +`react-hooks/rules-of-hooks` only for `components/ui/Navbar/Navlinks.tsx` +and `components/ui/AuthForms/*.tsx` (the `redirectMethod === 'client' ? +useRouter() : null` switch, settled by a constant); +`@typescript-eslint/no-require-imports` only for `*.config.js`, so +`tailwind.config.js` and `postcss.config.js` stay CommonJS as shipped +(supabase-starter converted its `tailwind.config.ts` to an import instead; +here the file is `.js` and `components.json` names it). `types_db.ts` is +ignored by eslint: upstream commits it as UTF-16 LE with a BOM (the +Supabase CLI's output), which eslint's parser rejects as binary and tsc +reads fine. Thirteen warnings remain (``, unused `error` bindings, +an effect dependency) — the template's, left as written. + +### `next.config.mjs` (new) + +The template had none. `output: "standalone"` and `outputFileTracingRoot` += the monorepo root, which `@opennextjs/cloudflare` requires. + +### `tests/web/tsconfig.json` + +Typechecks the app's files through the test imports under the app's own +strictness (`noUncheckedIndexedAccess` off, `baseUrl` = `apps/web`) rather +than the shared `tooling/tsconfig/web.json` defaults, so the template's +code is not held to rules it was not written against. + +### Left as upstream wrote it, on purpose + +`getURL()` in `utils/helpers.ts` still falls back to +`NEXT_PUBLIC_VERCEL_URL`; it is unset here, `NEXT_PUBLIC_SITE_URL` is set +first and wins, and the fallback is harmless. `.env.local.example` still +carries the local Supabase CLI's URL and demo anon key. `supabase/` +(config.toml, the migration, seed.sql), `schema.sql`, `fixtures/` and +`types_db.ts` are in `apps/web` for local Supabase-CLI / Stripe-CLI +development; the `@saas/db` runner applies the same SQL in CI. The +`supabase` npm devDependency stays for the `supabase:*` scripts; pnpm 10 +blocks its postinstall (the CLI download) and warns at install — +`pnpm approve-builds` once for the local stack. `lucide-react` 0.330.0's +peer range stops at React 18; pnpm warns and the icons render. + +### Additions around the template + +`proxy.ts` (above), `component.yaml`, `wrangler.template.jsonc`, +`wiring.fixture.json`, `.dev.vars.example`, `open-next.config.ts`, +`turbo.json`, `eslint.config.mjs`, `next.config.mjs` in `apps/web`; +`packages/db` (the control migration + `010_subscriptions_init/up.sql`, +which is `supabase/migrations/20230530034630_init.sql` byte for byte), +`infra/db-migrate`, `infra/terraform/supabase`, `tests/web`, `tests/db`. +The app component depends on `supabase` and `db-migrate` (supabase-starter +depended on `supabase` alone): the pricing page reads the tables the +webhook fills. + +### Versions + +| Package | Version | Why | +|---|---|---| +| next | 16.3.8 | newest inside `@opennextjs/cloudflare` 1.20.11's range (16.4.x fails at Worker boot) | +| react, react-dom | ^19.2.1 (19.3.1) | Next 16 requires React 19 | +| @supabase/ssr | ^0.12.7 | the template's ^0.1 has the retired cookie API | +| @supabase/supabase-js | ^2.43.4 (2.117.3) | the template's range, resolved fresh | +| stripe | ^14.25.0 (14.25.0) | kept: v14 has `createFetchHttpClient` and `constructEventAsync` | +| @stripe/stripe-js | 2.4.0 | kept | +| @opennextjs/cloudflare | ^1.20.11 | static-assets incremental cache + `populateCache local`; Next 16 `proxy.ts` as Node.js middleware | +| wrangler | ^4.151.0 | current | +| eslint, eslint-config-next | ^9.27 (9.39.5), 16.3.8 | the template's eslint 8 / eslint-config-next 14.1 pair has no Next 16 config | +| typescript | ^5.8.3 (5.9.3) | the template's ^5.4.5 range, bumped with the monorepo | +| tailwindcss | ^3.4.4 (3.4.19) | kept (Tailwind 3) | +| lucide-react | 0.330.0 | kept; React 19 peer warning | +| supabase (CLI) | ^1.172.2 (1.226.4) | kept; postinstall blocked by pnpm 10 | + +## Verified + +- Local: `pnpm install`, `pnpm run wire:fixture`, `pnpm typecheck`, + `pnpm lint` (0 errors, 13 warnings), `pnpm test` (19 tests in `tests/web`, + 3 in `tests/db`), `pnpm build` (`@saas/db` to `dist`, the Worker to + `apps/web/.open-next`) green; `pnpm --filter @saas/db run manifest:check` + passes; `node packages/db/dist/runner/cli.js plan --env stage` lists + `000_control_baseline` and `010_subscriptions_init`. +- `wrangler dev` over the built Worker with the fixture vars and a dummy + `.dev.vars`: `/` 200 (the template's "No subscription pricing plans + found" state — the fixture host answers nothing), `/signin` 307 → + `/signin/password_signin`, `/signin/password_signin` and `/signin/signup` + 200 (password, magic-link, third-party and sign-up links present), + `/account` signed out 307 → `/signin`, `POST /api/webhooks` unsigned 400 + "Webhook secret not found.", with a bad signature 400 "Webhook Error: No + signatures found matching the expected signature for payload. …" + (SubtleCrypto verification on workerd), `/nope` 404. +- `terraform init -backend=false && terraform validate` green on + `infra/terraform/supabase` (supabase/supabase 1.5.1). +- CI: `Checks` green on #2, #3 and #4 (install, wire, typecheck, lint, test, + build); the Orun `plan` job skips until `ORUN_CI` is set. +- Not verified: an apply of the Supabase root, an apply of the migration + (both need the product linked to an Orun workspace with Supabase and + Cloudflare connections), a live deploy, and a real Stripe round-trip + (Checkout → webhook → `subscriptions` row), which needs the product's + Stripe keys as Worker secrets and products created through the webhook. + Supabase's auth Site URL must then be set to the Worker's origin (README). diff --git a/specs/epics/subscription-payments/README.md b/specs/epics/subscription-payments/README.md index de9a097..da38513 100644 --- a/specs/epics/subscription-payments/README.md +++ b/specs/epics/subscription-payments/README.md @@ -8,7 +8,7 @@ The upstream code stays the code: the `@supabase/ssr` clients and the session-re | Field | Value | |-------|-------| -| Status | Draft | +| Status | ✅ Shipped — SP0–SP4 landed (#1–#5); Supabase and migration applies and the live deploy gated on a linked workspace, Stripe keys on the product | | Cluster | **SP** (SP0–SP4) | | Owner(s) | `apps/web` (the app) · `tests/web` (helper and webhook tests) · `packages/db` + `infra/db-migrate` + `tests/db` (the schema) · `infra/terraform/supabase` (the project) | | Builds on | `lumen` conventions — the `supabase` Terraform root, the `@saas/db` runner and `db-migrate` component, the orun-secrets wiring; `supabase-starter` for the app-on-Workers shape; `cirrus-baseline` conventions for the repository shape | @@ -16,7 +16,7 @@ The upstream code stays the code: the `@supabase/ssr` clients and the session-re | Changes | Adds the Workers build, the monorepo wrapper, tests, the migrations package, the db-migrate component, the Supabase root and the deploy contract; the template's code changes only where Next 16 / Workers force it (every change is in `IMPLEMENTATION-STATUS.md`) | | Decisions locked | (1) OpenNext on Workers + Static Assets. (2) The anon key is a wrangler var, not a secret: RLS protects the data; the service-role key and the two Stripe secrets are Worker secrets. (3) `wrangler.jsonc` is rendered per environment from the wiring document; never committed. (4) The schema is applied by the `@saas/db` runner through Supabase's Management API, from the template's `init.sql` verbatim — not by `supabase db push` in CI. (5) No Hyperdrive: the app speaks PostgREST over HTTPS, never a Postgres socket. (6) `stripe` stays on v14: it already has the fetch client and async webhook verification. | | Gate | SP1 is the first user-visible rung. SP2 and SP3 need a workspace with a Supabase connection to apply; they are verified by `plan` / `terraform validate`. Checkout and the webhook need the product's Stripe keys as Worker secrets (the one manual step, see `design.md` §3). | -| Shipped as | — | +| Shipped as | `main` after [#5](https://github.com/sourceplane/subscription-payments/pull/5); verified locally under `wrangler dev` with fixture vars and dummy Worker secrets | ## Read order diff --git a/specs/epics/subscription-payments/epic.yaml b/specs/epics/subscription-payments/epic.yaml index 4b987ed..65289c5 100644 --- a/specs/epics/subscription-payments/epic.yaml +++ b/specs/epics/subscription-payments/epic.yaml @@ -9,7 +9,7 @@ metadata: spec: title: "Vercel's Next.js Subscription Payments Starter on Cloudflare Workers + Supabase" summary: "The Vercel nextjs-subscription-payments template — Supabase Auth with cookie sessions through @supabase/ssr, a Postgres schema of users, customers, products, prices and subscriptions kept in sync by Stripe webhooks, Stripe Checkout and the Customer Portal — runs on Cloudflare Workers + Static Assets through @opennextjs/cloudflare, with the Supabase project provisioned by Terraform through Orun (the Lumen baseline's supabase root) and its schema applied by the db-migrate component from the template's own migration. The template's code stays the code; what moves is where it runs, where the project comes from, and how its secrets reach the Worker." - state: draft + state: completed milestones: - name: "SP0 — the spec" exitCriteria: diff --git a/specs/epics/subscription-payments/implementation-plan.md b/specs/epics/subscription-payments/implementation-plan.md index 1526f8f..0dbaba0 100644 --- a/specs/epics/subscription-payments/implementation-plan.md +++ b/specs/epics/subscription-payments/implementation-plan.md @@ -3,7 +3,7 @@ Milestones land in order; each task is one pull request on an `orun/SP-n-` branch with an `Orun-Task: SP-n` trailer. -## SP0 — the spec +## SP0 — the spec ✅ This doc set, `epic.yaml` and the task contracts, merged to `main`. @@ -11,7 +11,7 @@ This doc set, `epic.yaml` and the task contracts, merged to `main`. - the five documents and `epic.yaml` are on `main` - `tasks/SP-1..SP-5.TaskContract.yaml` exist -## SP1 — the app on Workers +## SP1 — the app on Workers ✅ `apps/web` is the upstream template with the Workers build around it, on Next 16 / React 19 with only the forced changes (`proxy.ts`, the ssr 0.12 @@ -26,7 +26,7 @@ helpers, the auth settings and the webhook route's decisions. - `wrangler dev` answers `/` with the pricing page, `/signin` with a 307 to `/signin/password_signin`, a signed-out `/account` with a 307 to `/signin`, and an unsigned `POST /api/webhooks` with 400 "Webhook secret not found." - the sign-in views render (`/signin/password_signin`, `/signin/signup`) -## SP2 — the schema through db-migrate +## SP2 — the schema through db-migrate ✅ `packages/db` is `@saas/db` with the control migration and `010_subscriptions_init/up.sql` (the template's `init.sql`, byte for byte) @@ -39,7 +39,7 @@ manifest and the offline plan. - `node packages/db/dist/runner/cli.js plan --env stage` lists `000_control_baseline` and `010_subscriptions_init` - `tests/db` is green in `Checks` -## SP3 — the Supabase project from Terraform +## SP3 — the Supabase project from Terraform ✅ `infra/terraform/supabase` provisions a project per environment and publishes URL, keys, DB URL and the wiring document; `apps/web/component.yaml` @@ -51,7 +51,7 @@ the Worker and the deploy read. - the component's `secretEnv` keys match the root's `secretOutputs` - the fixture's wiring keys match the template's tokens (`wire:fixture` renders) -## SP4 — ready to instantiate +## SP4 — ready to instantiate ✅ README (run, test, preview, deploy, Stripe fixtures / webhook / secrets, the Supabase auth Site URL), `IMPLEMENTATION-STATUS.md` with PRs and