create-ailk 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-catalog.md +50 -53
- package/dist/cli.js +19 -9
- package/dist/lib/apply-module-patches.d.ts +47 -0
- package/dist/lib/apply-module-patches.js +370 -0
- package/dist/lib/extract-module-bundle.d.ts +51 -3
- package/dist/lib/extract-module-bundle.js +327 -28
- package/dist/lib/fetch-module.d.ts +3 -38
- package/dist/lib/fetch-module.js +26 -8
- package/dist/lib/fetch-template.d.ts +20 -0
- package/dist/lib/fetch-template.js +129 -0
- package/dist/lib/module-license-gate.d.ts +10 -0
- package/dist/lib/module-license-gate.js +13 -4
- package/dist/lib/paid-paths.d.ts +16 -0
- package/dist/lib/paid-paths.js +90 -0
- package/dist/module-architecture.d.ts +197 -23
- package/dist/module-architecture.js +820 -25
- package/dist/parse-args.d.ts +9 -2
- package/dist/parse-args.js +46 -1
- package/dist/programmatic.d.ts +28 -2
- package/dist/programmatic.js +115 -8
- package/dist/surfaces.d.ts +12 -36
- package/dist/surfaces.js +77 -5
- package/dist/sync-routes.js +31 -1
- package/dist/template-manifest.d.ts +92 -0
- package/dist/template-manifest.js +168 -0
- package/dist/template-names.d.ts +41 -0
- package/dist/template-names.js +44 -0
- package/package.json +3 -2
- package/site-templates/marketing-site-free/ailk-template.json +8 -0
- package/site-templates/marketing-site-free/content/en/Pricing/pricing.mdx +103 -0
- package/site-templates/marketing-site-free/content/en/PrivacyPage/privacy.mdx +79 -0
- package/site-templates/marketing-site-free/content/en/TermsPage/terms.mdx +80 -0
- package/site-templates/marketing-site-free/provenance.json +4 -0
- package/templates/.claude/agents/web.md +2 -3
- package/templates/.claude/rules/architecture.md +5 -5
- package/templates/.claude/skills/README.md +2 -1
- package/templates/.env.example +21 -9
- package/templates/CONVENTIONS.md +6 -7
- package/templates/apps/api/.env.example +9 -0
- package/templates/apps/api/CLAUDE.md +33 -5
- package/templates/apps/api/package.json +0 -1
- package/templates/apps/api/src/__tests__/cors.test.ts +195 -0
- package/templates/apps/api/src/__tests__/module-exclusion.test.ts +60 -2
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +159 -0
- package/templates/apps/api/src/__tests__/workspace-module-registration.test.ts +166 -0
- package/templates/apps/api/src/config/__tests__/modules.test.ts +76 -0
- package/templates/apps/api/src/config/index.ts +19 -0
- package/templates/apps/api/src/config/modules.ts +12 -14
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +3 -0
- package/templates/apps/api/src/lib/__tests__/slice-load.test.ts +89 -0
- package/templates/apps/api/src/lib/slice-load.ts +90 -0
- package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +52 -32
- package/templates/apps/api/src/openapi/__tests__/spec-identity.test.ts +182 -0
- package/templates/apps/api/src/openapi/__tests__/surface-drift.test.ts +293 -0
- package/templates/apps/api/src/openapi/index.ts +9 -3
- package/templates/apps/api/src/openapi/spec.ts +505 -65
- package/templates/apps/api/src/openapi/surface-drift.ts +195 -0
- package/templates/apps/api/src/routes/content/__tests__/create.test.ts +14 -0
- package/templates/apps/api/src/routes/content/__tests__/delete.test.ts +14 -0
- package/templates/apps/api/src/routes/content/__tests__/update.test.ts +14 -0
- package/templates/apps/api/src/routes/content/index.ts +38 -11
- package/templates/apps/api/src/routes/project-listings/__tests__/configured-application.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/founder-identity.test.ts +796 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +38 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/resume-email.test.ts +814 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/site-key.test.ts +24 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/structured-address.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/index.ts +37 -10
- package/templates/apps/api/src/routes/project-listings/me.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/patch-draft.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/public.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/respond.ts +11 -0
- package/templates/apps/api/src/routes/project-listings/resume-token.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/start.ts +30 -0
- package/templates/apps/api/src/routes/project-listings/submit.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/verify-email.ts +150 -0
- package/templates/apps/api/src/server.ts +504 -137
- package/templates/apps/api/src/services/deliverable-fulfillment.ts +10 -0
- package/templates/apps/api/src/services/listing-config.ts +58 -0
- package/templates/apps/api/src/services/project-listing-resume-email.ts +326 -0
- package/templates/apps/api/src/services/project-listings.ts +229 -4
- package/templates/apps/api/src/vercel-handler.ts +60 -26
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +2 -2
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +21 -0
- package/templates/apps/mcp/__tests__/config/modules.test.ts +78 -0
- package/templates/apps/mcp/__tests__/module-exclusion.test.ts +1 -1
- package/templates/apps/mcp/src/config/modules.ts +14 -13
- package/templates/apps/mcp/src/server.ts +8 -4
- package/templates/apps/mcp/src/tools/index.ts +7 -22
- package/templates/apps/web/.env.example +15 -0
- package/templates/apps/web/app/[locale]/(authed)/{waitlist/__tests__ → __tests__}/gate.test.tsx +4 -4
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +1 -0
- package/templates/apps/web/app/[locale]/pricing/page.tsx +40 -0
- package/templates/apps/web/app/[locale]/privacy/page.tsx +40 -0
- package/templates/apps/web/app/[locale]/terms/page.tsx +40 -0
- package/templates/apps/web/app/llms.txt/route.ts +12 -9
- package/templates/apps/web/jest.config.cjs +19 -13
- package/templates/apps/web/lib/__tests__/server-api.test.ts +61 -0
- package/templates/apps/web/lib/server-api.ts +28 -12
- package/templates/apps/web/messages/en.json +58 -0
- package/templates/apps/web/next.config.mjs +1 -3
- package/templates/apps/web/package.json +0 -6
- package/templates/apps/web/public/android-chrome-192x192.png +0 -0
- package/templates/apps/web/public/android-chrome-512x512.png +0 -0
- package/templates/apps/web/public/apple-touch-icon.png +0 -0
- package/templates/apps/web/public/favicon-16x16.png +0 -0
- package/templates/apps/web/public/favicon-32x32.png +0 -0
- package/templates/apps/web/public/favicon.ico +0 -0
- package/templates/apps/web/public/favicon.svg +6 -3
- package/templates/apps/web/public/lockup-horizontal.svg +4 -0
- package/templates/apps/web/public/logomark.svg +4 -0
- package/templates/apps/web/public/site.webmanifest +2 -2
- package/templates/apps/web/public/wordmark.svg +4 -0
- package/templates/database/CHANGELOG.md +47 -0
- package/templates/database/inbox/schema.prisma +67 -0
- package/templates/database/migrations/20260914120000_listing_founder_identity/migration.sql +123 -0
- package/templates/database/package.json +1 -1
- package/templates/package.json +1 -1
- package/templates/.claude/skills/scaffold-commerce/SKILL.md +0 -807
- package/templates/.claude/skills/scaffold-commerce/references/lookup-keys-template.md +0 -71
- package/templates/.claude/skills/scaffold-commerce/references/marketplace-brand-pages.md +0 -83
- package/templates/.claude/skills/scaffold-commerce/templates/checkout-route.template.ts +0 -370
- package/templates/.claude/skills/scaffold-commerce/templates/invoice-route.template.ts +0 -376
- package/templates/.claude/skills/scaffold-commerce/templates/marketplace-cta-route.tsx.tmpl +0 -72
- package/templates/.claude/skills/scaffold-commerce/templates/payment-link-route.template.ts +0 -471
- package/templates/.claude/skills/scaffold-commerce/templates/portal-route.template.ts +0 -365
- package/templates/.claude/skills/scaffold-commerce/templates/stripe-config.template.ts +0 -60
- package/templates/.claude/skills/scaffold-commerce/templates/subscription-route.template.ts +0 -446
- package/templates/apps/api/src/__tests__/server.test.ts +0 -253
- package/templates/apps/api/src/bin/deliverable-resend.ts +0 -144
- package/templates/apps/api/src/bin/deliverable-upload.ts +0 -114
- package/templates/apps/api/src/bin/followup-sweep.ts +0 -44
- package/templates/apps/api/src/bin/listing-csv-sweep.ts +0 -46
- package/templates/apps/api/src/bin/seed-presets.ts +0 -58
- package/templates/apps/api/src/bin/seed-waitlist-experiments.ts +0 -104
- package/templates/apps/api/src/bin/session-retention-sweep.ts +0 -46
- package/templates/apps/api/src/lib/__tests__/stripe.test.ts +0 -74
- package/templates/apps/api/src/lib/stripe.ts +0 -52
- package/templates/apps/api/src/lib/tenant-db.ts +0 -225
- package/templates/apps/api/src/lib/ws-token.ts +0 -91
- package/templates/apps/api/src/middleware/tenant.ts +0 -99
- package/templates/apps/api/src/routes/billing/__tests__/portal.test.ts +0 -450
- package/templates/apps/api/src/routes/billing/__tests__/read.test.ts +0 -262
- package/templates/apps/api/src/routes/billing/__tests__/usage.test.ts +0 -436
- package/templates/apps/api/src/routes/billing/index.ts +0 -36
- package/templates/apps/api/src/routes/billing/portal.ts +0 -182
- package/templates/apps/api/src/routes/billing/read.ts +0 -75
- package/templates/apps/api/src/routes/billing/usage.ts +0 -153
- package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +0 -687
- package/templates/apps/api/src/routes/checkout/index.ts +0 -13
- package/templates/apps/api/src/routes/checkout/sessions.ts +0 -197
- package/templates/apps/api/src/routes/deliverables/__tests__/index.test.ts +0 -393
- package/templates/apps/api/src/routes/deliverables/index.ts +0 -200
- package/templates/apps/api/src/routes/flow-checkouts/__tests__/index.test.ts +0 -443
- package/templates/apps/api/src/routes/flow-checkouts/index.ts +0 -82
- package/templates/apps/api/src/routes/flows/README.md +0 -147
- package/templates/apps/api/src/routes/flows/__tests__/index.test.ts +0 -752
- package/templates/apps/api/src/routes/flows/__tests__/recommender.test.ts +0 -671
- package/templates/apps/api/src/routes/flows/index.ts +0 -202
- package/templates/apps/api/src/routes/flows/recommender.ts +0 -443
- package/templates/apps/api/src/routes/project-listings/__tests__/copy-edit.test.ts +0 -815
- package/templates/apps/api/src/routes/project-listings/__tests__/me-route-precedence.test.ts +0 -221
- package/templates/apps/api/src/routes/project-listings/__tests__/tenant-isolation.test.ts +0 -566
- package/templates/apps/api/src/routes/project-listings/get.ts +0 -70
- package/templates/apps/api/src/routes/project-listings/list.ts +0 -47
- package/templates/apps/api/src/routes/project-listings/patch.ts +0 -136
- package/templates/apps/api/src/routes/schedule/__tests__/index.test.ts +0 -490
- package/templates/apps/api/src/routes/schedule/index.ts +0 -249
- package/templates/apps/api/src/routes/slack/__tests__/actions.test.ts +0 -385
- package/templates/apps/api/src/routes/slack/actions.ts +0 -177
- package/templates/apps/api/src/routes/slack/index.ts +0 -38
- package/templates/apps/api/src/routes/waitlist-experiments/__tests__/tenant-isolation.test.ts +0 -577
- package/templates/apps/api/src/routes/waitlist-experiments/comparison.ts +0 -78
- package/templates/apps/api/src/routes/waitlist-experiments/index.ts +0 -41
- package/templates/apps/api/src/routes/waitlist-experiments/list.ts +0 -64
- package/templates/apps/api/src/routes/waitlist-experiments/respond.ts +0 -42
- package/templates/apps/api/src/routes/waitlist-experiments/signup.ts +0 -84
- package/templates/apps/api/src/routes/waitlist-experiments/signups.ts +0 -119
- package/templates/apps/api/src/routes/waitlist-signups/__tests__/index.test.ts +0 -238
- package/templates/apps/api/src/routes/waitlist-signups/index.ts +0 -101
- package/templates/apps/api/src/routes/webhooks/README.md +0 -80
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +0 -315
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +0 -247
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +0 -270
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +0 -198
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +0 -633
- package/templates/apps/api/src/routes/webhooks/index.ts +0 -41
- package/templates/apps/api/src/routes/webhooks/stripe.ts +0 -481
- package/templates/apps/api/src/routes/workspaces/__tests__/config-tenant-isolation.test.ts +0 -356
- package/templates/apps/api/src/routes/workspaces/__tests__/tenant-isolation.test.ts +0 -671
- package/templates/apps/api/src/routes/workspaces/config.ts +0 -125
- package/templates/apps/api/src/routes/workspaces/index.ts +0 -194
- package/templates/apps/api/src/routes/workspaces/sessions.ts +0 -218
- package/templates/apps/api/src/services/__tests__/flow-aggregate.test.ts +0 -425
- package/templates/apps/api/src/services/__tests__/flow-engine.test.ts +0 -2840
- package/templates/apps/api/src/services/__tests__/lead-promotion.test.ts +0 -393
- package/templates/apps/api/src/services/__tests__/listing-csv-sweep.test.ts +0 -560
- package/templates/apps/api/src/services/__tests__/listing-promotion.test.ts +0 -684
- package/templates/apps/api/src/services/__tests__/playbook-compile.test.ts +0 -406
- package/templates/apps/api/src/services/__tests__/playbook-render.test.ts +0 -290
- package/templates/apps/api/src/services/__tests__/project-listing-decision.test.ts +0 -736
- package/templates/apps/api/src/services/__tests__/project-listing-flow.test.ts +0 -475
- package/templates/apps/api/src/services/__tests__/project-listing-issue.test.ts +0 -340
- package/templates/apps/api/src/services/__tests__/recommender-capture.test.ts +0 -983
- package/templates/apps/api/src/services/__tests__/tenant-context-cascade.test.ts +0 -71
- package/templates/apps/api/src/services/__tests__/tenant-context.test.ts +0 -379
- package/templates/apps/api/src/services/__tests__/usage-metering.test.ts +0 -768
- package/templates/apps/api/src/services/__tests__/waitlist-dashboard.test.ts +0 -1314
- package/templates/apps/api/src/services/__tests__/waitlist-experiments.test.ts +0 -341
- package/templates/apps/api/src/services/__tests__/waitlist-followup.test.ts +0 -567
- package/templates/apps/api/src/services/__tests__/waitlist-scoring.test.ts +0 -474
- package/templates/apps/api/src/services/__tests__/waitlist-signups.test.ts +0 -354
- package/templates/apps/api/src/services/flow-aggregate.ts +0 -232
- package/templates/apps/api/src/services/flow-checkouts.ts +0 -123
- package/templates/apps/api/src/services/flow-engine.ts +0 -1296
- package/templates/apps/api/src/services/lead-promotion.ts +0 -176
- package/templates/apps/api/src/services/listing-csv-sweep.ts +0 -455
- package/templates/apps/api/src/services/listing-promotion.ts +0 -342
- package/templates/apps/api/src/services/playbook-compile.ts +0 -398
- package/templates/apps/api/src/services/playbook-render.ts +0 -263
- package/templates/apps/api/src/services/project-listing-decision.ts +0 -510
- package/templates/apps/api/src/services/project-listing-flow.ts +0 -426
- package/templates/apps/api/src/services/project-listing-issue.ts +0 -251
- package/templates/apps/api/src/services/recommender-capture.ts +0 -835
- package/templates/apps/api/src/services/scheduling/cal-provider.ts +0 -392
- package/templates/apps/api/src/services/scheduling/index.ts +0 -63
- package/templates/apps/api/src/services/scheduling/types.ts +0 -88
- package/templates/apps/api/src/services/tenant-context.ts +0 -451
- package/templates/apps/api/src/services/usage-metering.ts +0 -699
- package/templates/apps/api/src/services/waitlist-dashboard.ts +0 -947
- package/templates/apps/api/src/services/waitlist-experiments.ts +0 -213
- package/templates/apps/api/src/services/waitlist-followup.ts +0 -486
- package/templates/apps/api/src/services/waitlist-scoring.ts +0 -166
- package/templates/apps/api/src/services/waitlist-signups.ts +0 -165
- package/templates/apps/mcp/__tests__/schedule_tools.test.ts +0 -242
- package/templates/apps/mcp/src/tools/create_booking.ts +0 -58
- package/templates/apps/mcp/src/tools/get_event_meta.ts +0 -55
- package/templates/apps/mcp/src/tools/get_flow.ts +0 -61
- package/templates/apps/mcp/src/tools/list_availability.ts +0 -67
- package/templates/apps/mcp/src/tools/submit_flow_step.ts +0 -83
- package/templates/apps/web/app/[locale]/(authed)/waitlist/[experimentId]/page.tsx +0 -309
- package/templates/apps/web/app/[locale]/(authed)/waitlist/[experimentId]/signups/[leadId]/page.tsx +0 -149
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/comparison.test.tsx +0 -273
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/list.test.tsx +0 -171
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/signup.test.tsx +0 -179
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ExperimentsTable.tsx +0 -116
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/OfferFunnelTable.tsx +0 -66
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/RollupTicker.tsx +0 -61
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ScoreTrace.tsx +0 -114
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/SignupsTable.tsx +0 -139
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/WaitlistComparisonTabs.tsx +0 -85
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/status-badges.tsx +0 -67
- package/templates/apps/web/app/[locale]/(authed)/waitlist/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/blog/[[...slug]]/page.tsx +0 -178
- package/templates/apps/web/app/[locale]/dev/purchase/__tests__/actions.test.ts +0 -160
- package/templates/apps/web/app/[locale]/dev/purchase/error.tsx +0 -25
- package/templates/apps/web/app/[locale]/dev/purchase/page.tsx +0 -117
- package/templates/apps/web/app/[locale]/dev/purchase/purchase.actions.ts +0 -58
- package/templates/apps/web/app/[locale]/docs/[[...slug]]/page.tsx +0 -119
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/checkout.actions.test.ts +0 -287
- package/templates/apps/web/app/[locale]/flows/[slug]/checkout.actions.ts +0 -254
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -532
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -121
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.checkout.test.tsx +0 -457
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -396
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/projects/apply/ListingApplicationClient.tsx +0 -110
- package/templates/apps/web/app/[locale]/projects/apply/__tests__/ListingApplicationClient.test.tsx +0 -96
- package/templates/apps/web/app/[locale]/schedule/__tests__/page.test.tsx +0 -117
- package/templates/apps/web/app/[locale]/schedule/confirmed/__tests__/page.test.tsx +0 -96
- package/templates/apps/web/app/[locale]/schedule/confirmed/page.tsx +0 -92
- package/templates/apps/web/app/[locale]/schedule/page.tsx +0 -82
- package/templates/apps/web/content/en/blog/README.txt +0 -25
- package/templates/apps/web/content/en/docs/index.mdx +0 -28
- package/templates/apps/web/lib/__mocks__/source-server.js +0 -31
- package/templates/apps/web/lib/blog-list-data.ts +0 -95
- package/templates/apps/web/lib/blog-post-data.ts +0 -79
- package/templates/apps/web/lib/source.ts +0 -34
- package/templates/apps/web/public/logomark-dark.svg +0 -4
- package/templates/apps/web/public/logomark-light.svg +0 -4
- package/templates/apps/web/source.config.ts +0 -78
|
@@ -28,10 +28,10 @@ other.
|
|
|
28
28
|
- Need database access? Only `apps/api` and `apps/mcp` import
|
|
29
29
|
`@working-theory/database`. `apps/web` never reads the database directly — it
|
|
30
30
|
goes through the HTTP API.
|
|
31
|
-
- Cross-cutting integrations (auth,
|
|
32
|
-
|
|
33
|
-
`@working-theory/
|
|
34
|
-
|
|
31
|
+
- Cross-cutting integrations (auth, email, analytics) go through their
|
|
32
|
+
wrapper packages: `@working-theory/auth-client`, `@working-theory/email`,
|
|
33
|
+
`@working-theory/analytics`. Never import `next-auth`, `resend`, etc.
|
|
34
|
+
directly.
|
|
35
35
|
|
|
36
36
|
## What you can verify, what you can't
|
|
37
37
|
|
|
@@ -62,5 +62,5 @@ These never appear in source code:
|
|
|
62
62
|
by being named on a ban-list. Live keys live in your deployment
|
|
63
63
|
platform's secrets store, never in source files or `.env`.
|
|
64
64
|
- Direct vendor SDK imports outside the wrapper packages
|
|
65
|
-
(`import '
|
|
65
|
+
(`import 'resend'` outside `@working-theory/email`, etc.).
|
|
66
66
|
- Hardcoded production database URLs in committed files.
|
|
@@ -17,12 +17,13 @@ local project's issues.
|
|
|
17
17
|
| -------------------- | ------------------------------------------------------ | ---------------------------------------------------- |
|
|
18
18
|
| `suggest-site-pages` | Generic page-type suggestions by category | coming soon — issue #361 (working-theory-labs/ai-launch-kit) |
|
|
19
19
|
| `scaffold-page` | Generate a page with the appropriate schema.org type | coming soon — issue #362 (working-theory-labs/ai-launch-kit) |
|
|
20
|
-
| `scaffold-commerce` | Sell stuff: external store link or direct payments | coming soon — issue #363 (working-theory-labs/ai-launch-kit) |
|
|
21
20
|
| `scaffold-auth` | Wire up an auth flow against `@working-theory/auth-client` | coming soon — issue #364 (working-theory-labs/ai-launch-kit) |
|
|
22
21
|
| `audit-site` | Run `ailk audit` and explain the results | coming soon — issue #365 (working-theory-labs/ai-launch-kit) |
|
|
23
22
|
| `add-schema` | Add Product / Service / FAQ schema to an existing page | coming soon — issue #366 (working-theory-labs/ai-launch-kit) |
|
|
24
23
|
| `provision-config` | Generate `vercel.json` and environment templates | coming soon — issue #367 (working-theory-labs/ai-launch-kit) |
|
|
25
24
|
|
|
25
|
+
`scaffold-commerce` is delivered with the commerce module (`--modules commerce`, licensed).
|
|
26
|
+
|
|
26
27
|
## How a skill ships
|
|
27
28
|
|
|
28
29
|
When a skill is built upstream, this directory will contain a
|
package/templates/.env.example
CHANGED
|
@@ -98,11 +98,20 @@ CONTENT_BACKEND=mdx
|
|
|
98
98
|
# default.
|
|
99
99
|
# RESEND_AUDIENCE_ID=
|
|
100
100
|
#
|
|
101
|
-
# The public base URL this API is reachable at
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
101
|
+
# The public base URL this API is reachable at, e.g. https://api.example.com
|
|
102
|
+
# (no trailing slash). This is the API's OWN origin — distinct from
|
|
103
|
+
# FRONTEND_URL (the site the browser loads) and from `_site.mdx`'s `baseUrl`
|
|
104
|
+
# (the site's public web origin). A deployment typically serves the site from
|
|
105
|
+
# example.com and this API from api.example.com, so neither of the other two
|
|
106
|
+
# can stand in for it. Two consumers:
|
|
107
|
+
#
|
|
108
|
+
# 1. The deliverable-delivery download link (#3961 D5):
|
|
109
|
+
# `${AILK_PUBLIC_API_URL}/v1/deliverables/:grantId`. Unset means a
|
|
110
|
+
# relative link (base ""), which is not usable from an email client — set
|
|
111
|
+
# this in any deployment that uses the `deliverables` block.
|
|
112
|
+
# 2. The OpenAPI `servers` block (#5306). Unset degrades to a single
|
|
113
|
+
# document-relative server (`/`), which an agent resolves against the
|
|
114
|
+
# origin it fetched the spec from — correct, just less explicit.
|
|
106
115
|
# AILK_PUBLIC_API_URL=
|
|
107
116
|
#
|
|
108
117
|
# The apps/api origin @working-theory/api-client calls from
|
|
@@ -313,11 +322,14 @@ CONTENT_BACKEND=mdx
|
|
|
313
322
|
# apps/api's origin as seen from apps/web's SERVER process — the api-client's
|
|
314
323
|
# base URL (getApiBase(), packages/api-client/src/http.ts) for every flow
|
|
315
324
|
# Server Action call (flows.get / submitStep / save / checkout). AILK_API_URL
|
|
316
|
-
# wins;
|
|
325
|
+
# wins; NEXT_PUBLIC_AILK_API_URL (apps/web/.env.example) is the fallback, and
|
|
326
|
+
# is also what getApiBase() resolves in the BROWSER, where only a
|
|
327
|
+
# NEXT_PUBLIC_-prefixed name is inlined (#5397); NEXT_PUBLIC_API_URL is still
|
|
328
|
+
# read after it as a DEPRECATED fallback for deployments that set it under the
|
|
329
|
+
# old behaviour — do not set it in a new one. All unset resolves to
|
|
317
330
|
# http://localhost:3001 (local dev only — off-localhost every save / checkout
|
|
318
|
-
# call fails as `network`).
|
|
319
|
-
#
|
|
320
|
-
# every apps/web deployment whose API is not on localhost.
|
|
331
|
+
# call fails as `network`). Set AILK_API_URL on every apps/web deployment whose
|
|
332
|
+
# API is not on localhost.
|
|
321
333
|
# AILK_API_URL=http://localhost:3001
|
|
322
334
|
#
|
|
323
335
|
# NEXT_PUBLIC_ENABLED_LOCALES — do NOT set by hand. Baked at build time by
|
package/templates/CONVENTIONS.md
CHANGED
|
@@ -174,13 +174,12 @@ Vendor SDKs are imported only inside their `@working-theory/*` wrapper. The
|
|
|
174
174
|
wrapper exports a typed, project-flavored interface; your code imports
|
|
175
175
|
from the wrapper.
|
|
176
176
|
|
|
177
|
-
| Vendor | Wrapper package
|
|
178
|
-
| ------------------- |
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
| Prisma | `@working-theory/database` | `apps/api`, `apps/mcp` |
|
|
177
|
+
| Vendor | Wrapper package | Where you use it |
|
|
178
|
+
| ------------------- | ----------------------------- | ---------------------- |
|
|
179
|
+
| NextAuth | `@working-theory/auth-client` | `apps/api`, `apps/web` |
|
|
180
|
+
| Resend / Nodemailer | `@working-theory/email` | `apps/api` |
|
|
181
|
+
| Analytics | `@working-theory/analytics` | `apps/web`, `apps/api` |
|
|
182
|
+
| Prisma | `@working-theory/database` | `apps/api`, `apps/mcp` |
|
|
184
183
|
|
|
185
184
|
The wrapper is where retries, signature verification, error mapping,
|
|
186
185
|
and config defaults live. Don't reinvent them per consumer.
|
|
@@ -58,6 +58,15 @@ STRIPE_WEBHOOK_SECRET=whsec_xxx
|
|
|
58
58
|
# (#4288) lands as a second value here with no change to the section.
|
|
59
59
|
# SCHEDULING_PROVIDER=cal
|
|
60
60
|
|
|
61
|
+
# =============================================================================
|
|
62
|
+
# Paid modules (D-44, #5368)
|
|
63
|
+
# =============================================================================
|
|
64
|
+
# Comma-separated allowlist of installed paid modules, e.g.
|
|
65
|
+
# "multi-tenant,scheduling". Unset (the default) or "" means NO paid modules
|
|
66
|
+
# — installed modules enable themselves explicitly. Recognized keys: docs,
|
|
67
|
+
# multi-tenant, scheduling, content-write. Must match apps/mcp's value.
|
|
68
|
+
# AILK_ENABLED_MODULES=
|
|
69
|
+
|
|
61
70
|
# ── Project listings — site addressing (#5048 D2) ───────────────────────────
|
|
62
71
|
# AILK_SITE_ID is this deployment's own site identifier. Unset means "default".
|
|
63
72
|
# It is read SERVER-SIDE only; no request body carries a site identifier.
|
|
@@ -8,6 +8,26 @@ Inherits root `CLAUDE.md`. This file adds API-specific rules.
|
|
|
8
8
|
- Persistence: configurable adapter (default DB; file fallback so OSS works without DB config)
|
|
9
9
|
- Email: operator-notification stub at OSS; routing pipeline at Pro (in `@working-theory/*`)
|
|
10
10
|
|
|
11
|
+
## Deploy path
|
|
12
|
+
|
|
13
|
+
**The supported deploy path is plain `tsc` output, traced and compiled by `@vercel/node`.** `vercel.json` sets `framework: null` and routes every request to `/api/index.ts`; `build:vercel` runs `prisma generate` and two package builds and does NOT compile `apps/api` — Vercel's own builder does, through `nodeFileTrace`. That tracer is what decides which files ship.
|
|
14
|
+
|
|
15
|
+
**Bundling `apps/api` is NOT a supported deploy path** (#5334). This is a property of the analysers, not a policy:
|
|
16
|
+
|
|
17
|
+
- Paid-module slices are loaded through an indirect dynamic `import()`, because a string literal at the call site would make `tsc` resolve a path the OSS strip removes (#5182).
|
|
18
|
+
- esbuild bundles a dynamic `import()` **only** when its argument is a string literal at the call site — the same predicate `tsc` resolves on. So no expression shape satisfies both the strip and a bundler.
|
|
19
|
+
- In a bundled build the specifier therefore survives verbatim and Node resolves it against the **bundle's output directory** rather than its source module's: `"./list.js"`, written in `src/routes/project-listings/index.ts`, becomes `dist/list.js` and does not exist. esbuild emits no warning. The throw lands inside `build()`, which is construction, so **every route 500s rather than one** — measured in production, nine hours of total API outage on a consuming site.
|
|
20
|
+
|
|
21
|
+
If a dependency is forcing you toward a bundler (an extensionless relative import in a published `dist`, say), fix the dependency's packaging — don't bundle `apps/api`. If you bundle anyway, `loadSlice()` (`src/lib/slice-load.ts`) makes the failure say so at boot instead of failing mute; it does not make bundling work.
|
|
22
|
+
|
|
23
|
+
Three gates hold this together. Run them from the repo root, with `apps/api/dist` built:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm slice-reachability:check # every slice specifier is reachable to @vercel/nft
|
|
27
|
+
pnpm artifact-boots:check # the traced artifact boots and answers /health 200
|
|
28
|
+
pnpm bundled-build:check # a bundled build fails, and says why
|
|
29
|
+
```
|
|
30
|
+
|
|
11
31
|
## API ↔ MCP parity (hard rule)
|
|
12
32
|
|
|
13
33
|
Every endpoint here has a 1:1 MCP tool in `apps/mcp`. When you add, change, or remove an endpoint, update the MCP tool in the same PR. CI enforces — broken parity fails the build.
|
|
@@ -17,8 +37,9 @@ Every endpoint here has a 1:1 MCP tool in `apps/mcp`. When you add, change, or r
|
|
|
17
37
|
Routes are versioned under `/v1/*`:
|
|
18
38
|
|
|
19
39
|
- `/v1/leads/{submit,subscribe,callback}` — lead capture, newsletter subscription, callback request
|
|
20
|
-
- `/v1/flows/:slug` (GET), `/v1/flows/:slug/steps` (POST) — serve a flow config + submit a step's answers; server-side per-step partial-state persistence (#3956)
|
|
21
|
-
- `/v1/flows/:slug/aggregate` (GET) — anonymous, site-scoped per-question response counts across all completed respondents for the results reveal (#4771): respondents are completed `FlowSession` rows (not `Lead` rows — a recommending-mode respondent has no Lead until the email moment), question metadata + the chart flag come from the `WaitlistExperiment` register, and only `resultsReveal`-flagged `single`/`multi` questions are returned (`src/services/flow-aggregate.ts`). No individual answer, email, name, session id, or score in the response; no auth. No MCP twin — recorded exception (an agent walking a flow already gets everything it needs from `submit_flow_step`'s own response; "how everyone else answered" changes none of it).
|
|
40
|
+
- `/v1/flows/:slug` (GET), `/v1/flows/:slug/steps` (POST) — serve a flow config + submit a step's answers; server-side per-step partial-state persistence (#3956). Module: `signal-collectors` (D-48, #5366) — registers only when the module is enabled; MCP twins `get_flow`/`submit_flow_step` carry the same `module` tag (D7).
|
|
41
|
+
- `/v1/flows/:slug/aggregate` (GET) — anonymous, site-scoped per-question response counts across all completed respondents for the results reveal (#4771): respondents are completed `FlowSession` rows (not `Lead` rows — a recommending-mode respondent has no Lead until the email moment), question metadata + the chart flag come from the `WaitlistExperiment` register, and only `resultsReveal`-flagged `single`/`multi` questions are returned (`src/services/flow-aggregate.ts`). No individual answer, email, name, session id, or score in the response; no auth. Module: `signal-collectors`. No MCP twin — recorded exception (an agent walking a flow already gets everything it needs from `submit_flow_step`'s own response; "how everyone else answered" changes none of it).
|
|
42
|
+
- `/v1/deliverables/:grantId` (GET) — the capability-token download route for gated PDFs and reports, including client deliverables (#3961 D5); the token itself is the sole gate, no auth preHandler applies (`src/routes/deliverables/index.ts`). Module: `signal-collectors` (D-48, #5366). No MCP twin — identity-bound capability-link download (#3591 exception, the same shape as `/v1/waitlist-signups/me`).
|
|
22
43
|
- `/v1/flows/:slug/save` (POST), `/v1/flows/:slug/checkout` (POST) — the recommender's email moment (#4841): `save` creates the FlowSession + Lead (+ the T+0 DeliverableGrant) for the permalink's answers; `checkout` does the same, records the `FlowCheckout` buyer row at a SERVER-recomputed `price()` (the body carries no amount — `flowCheckoutInputSchema` is strict), and opens a Stripe TEST-mode Checkout Session whose metadata carries the permalink + offer key (`src/routes/flows/recommender.ts`, `src/services/recommender-capture.ts`, `packages/stripe-client`'s `createQuotedCheckoutSession`). Anonymous, rate-limited; a non-`sk_test_` key is refused before any side effect. No MCP twin — recorded exception: an agent walking a flow has no email to give and no card to pay with; the anonymous MCP surface is identity-blind.
|
|
23
44
|
- `/v1/content/{types,:type,:type/:slug}` — public content reads
|
|
24
45
|
- `/v1/auth/tokens`, `/v1/user/{profile,data/:key}` — local auth + user data
|
|
@@ -28,9 +49,11 @@ Routes are versioned under `/v1/*`:
|
|
|
28
49
|
- `/v1/schedule/availability` (GET), `/v1/schedule/event-meta` (GET), `/v1/schedule/book` (POST) — anonymous scheduling proxy behind the provider seam (`src/services/scheduling/`); Cal.com v2 today, a self-hosted engine later, same three calls. `event-meta` is the meta-only read (title · duration · description · price) so rendering an event's facts never fetches an availability window (#4633). `CAL_API_KEY` is read server-side only. MCP twins: `list_availability` / `get_event_meta` / `create_booking` (#4416, #4633)
|
|
29
50
|
- `/v1/aeo/score` (POST), `/v1/aeo/score/example` (GET) — anonymous instant AEO score for a respondent-supplied URL, and the bundled pre-launch example, both fed by the SSRF-guarded crawler at `@working-theory/aeo/fetch` and the pure scorer at `@working-theory/aeo` (`src/services/aeo-score.ts`, #4666). No MCP twin — recorded exception, brief D7 (exposing an arbitrary-URL crawler to anonymous agents is a security-posture decision; `apps/mcp/src/tools/audit.ts` deliberately stays same-origin-locked instead).
|
|
30
51
|
- `/v1/waitlist-experiments` (GET), `/v1/waitlist-experiments/:experimentId` (GET), `/v1/waitlist-experiments/:experimentId/signups` (GET), `/v1/waitlist-experiments/:experimentId/signups/:leadId` (GET) — the operator-dashboard read API for Parallel Waitlist Validation (#4665 D7, B0): tenant-scoped list + rollup, per-waitlist comparison, paginated signups, and a signup drill-down over A1's `WaitlistExperiment` / `WaitlistScore` / `Lead` rows (`src/services/waitlist-dashboard.ts`, #4671). Role floor `owner|admin` (signup PII); the platform-operator scope (`isSentinel(organizationId) && role === "owner"`, ALSO requiring `AILK_OPERATOR_EMAIL` to be set — fail-closed, PR #4687) sees every site, an ordinary owner/admin sees only its own `siteId`. No MCP twin — identity-bound tenant routes (#3591 exception, same shape as `/v1/billing/*`).
|
|
31
|
-
- `/v1/waitlist-signups/me` (GET, `?experimentKey=<slug>`) — the respondent read (#4731): a signed-in, **email-verified** user's OWN newest signup for one experiment (`experimentKey`, `waitlistKey`, `completedAt`, `tier`, `score`, `aeoScore`, `answers.q3` — seven fields, nothing more; `src/services/waitlist-signups.ts` is the only read path). Registered in `authScope` only (auth, no tenant guard — a respondent has no workspace). Identity is `request.userId`; the email is the `User`'s, never a parameter; `emailVerified !== true` → 403 `email_unverified` before any `Lead` read; no match → 404 `signup_not_found`; every read scoped to `currentSiteId()`. No MCP twin — identity-bound (#3591 exception).
|
|
52
|
+
- `/v1/waitlist-signups/me` (GET, `?experimentKey=<slug>`) — the respondent read (#4731): a signed-in, **email-verified** user's OWN newest signup for one experiment (`experimentKey`, `waitlistKey`, `completedAt`, `tier`, `score`, `aeoScore`, `answers.q3` — seven fields, nothing more; `src/services/waitlist-signups.ts` is the only read path). Registered in `authScope` only (auth, no tenant guard — a respondent has no workspace). Identity is `request.userId`; the email is the `User`'s, never a parameter; `emailVerified !== true` → 403 `email_unverified` before any `Lead` read; no match → 404 `signup_not_found`; every read scoped to `currentSiteId()`. Module: `signal-collectors` (D-48, #5366). No MCP twin — identity-bound (#3591 exception).
|
|
32
53
|
- `/v1/flow-checkouts/me` (GET) — the respondent purchases read (#4984, FEAT-022 M2): a signed-in, **email-verified** user's OWN `FlowCheckout` rows, newest first, `[]` when none (`id`, `flowSlug`, `experimentKey`, `offerKey`, `status`, `amountMinor`, `currency`, `period`, `completedAt`, `createdAt` — ten fields, nothing more; `src/services/flow-checkouts.ts` is the only read path). Registered in `authScope` only, beside `/v1/waitlist-signups/me`. Identity is `request.userId`; rows are joined through the promotion link (`Lead.promotedUserId = userId`, `src/services/lead-promotion.ts`) — never by an email, and no query parameter is read; `emailVerified !== true` → 403 `email_unverified` before any `Lead` read; every read scoped to `currentSiteId()`. No MCP twin — identity-bound (#3591 exception).
|
|
33
|
-
- `/v1/project-listings/me` (GET) — the FOUNDER'S OWN listings read (#5295): a signed-in user's own `ProjectListing` rows, newest first, `[]` when none. Registered in `authScope` only, beside `/v1/flow-checkouts/me` — a founder is not a workspace member, so the tenant guard's default-deny would answer 403 for their own submission. Identity is `request.userId`; rows are joined through the owner link (`ProjectListing.ownerUserId = userId`, stamped by `src/services/listing-promotion.ts`) — **never** by `founderEmail`, at any stage, and no query parameter is read. `founderEmail` is an unverified string typed into an anonymous form, so a read-time email match would hand one of two people sharing an address the other's submission. The row shape is `projectListingDraftSchema` (the founder-facing shape the anonymous draft read already uses — no `siteId`, `leadId`, `decidedBy`, `issueUrl`, or `experimentKey`). The route is ADDITIVE: `PROJECT_LISTING_ROLES` stays `owner|admin` and the tenant-scoped list/get/patch routes are unchanged. No MCP twin — identity-bound (#3591 exception).
|
|
54
|
+
- `/v1/project-listings/me` (GET) — the FOUNDER'S OWN listings read (#5295): a signed-in user's own `ProjectListing` rows, newest first, `[]` when none. Registered in `authScope` only, beside `/v1/flow-checkouts/me` — a founder is not a workspace member, so the tenant guard's default-deny would answer 403 for their own submission. Identity is `request.userId`; rows are joined through the owner link (`ProjectListing.ownerUserId = userId`, stamped by `src/services/listing-promotion.ts`) — **never** by `founderEmail`, at any stage, and no query parameter is read. `founderEmail` is an unverified string typed into an anonymous form, so a read-time email match would hand one of two people sharing an address the other's submission. The row shape is `projectListingDraftSchema` (the founder-facing shape the anonymous draft read already uses — no `siteId`, `leadId`, `decidedBy`, `issueUrl`, or `experimentKey`). The route is ADDITIVE: `PROJECT_LISTING_ROLES` stays `owner|admin` and the tenant-scoped list/get/patch routes are unchanged. Module: `signal-collectors` (D-48, #5366) — not severable from the anonymous listing-application routes below (same static barrel, D4). No MCP twin — identity-bound (#3591 exception).
|
|
55
|
+
- `/v1/project-listings/{start,submit}` (POST), `/v1/project-listings/:id` (PATCH, draft), `/v1/project-listings/public` (GET) — the anonymous founder's-application lifecycle (#4998, reshaped by #5036): draft start/patch/submit plus the public shelves read, identity-blind and rate-limited alongside the leads routes. Module: `signal-collectors`. No MCP twin — anonymous form-lifecycle routes, not agent-facing.
|
|
56
|
+
- `/v1/slack/actions` (POST) — the project-listing operator decision (Slack Approve/Reject, #4999): verifies the Slack signature, applies the decision via `src/services/project-listing-decision.ts`. Module: `signal-collectors`. No MCP twin — a Slack-signed webhook, not agent-facing.
|
|
34
57
|
|
|
35
58
|
The workspace site-config routes are **identity-bound tenant routes** (guarded by the tenant preHandler; the write scope is the caller's active workspace, never a body-supplied id). Like the sibling `/v1/workspaces/*` routes they have **no anonymous MCP twin** — the OSS MCP surface is identity-blind (`apps/mcp/CLAUDE.md`), so the "1:1 MCP tool" rule above does not apply to them; the tenant-scoped authed MCP surface is tracked in #3591. The `/v1/billing/*` and `/v1/waitlist-experiments/*` routes are the same shape — identity-bound tenant routes, admin/settings-facing rather than agent-facing, no MCP twin.
|
|
36
59
|
|
|
@@ -118,8 +141,13 @@ sweep's own DB constraint (never a caller-side lock).
|
|
|
118
141
|
- Don't return 200 with `{ ok: false }`.
|
|
119
142
|
- Don't read MDX directly — use `@working-theory/content-adapters`.
|
|
120
143
|
- Don't put session state in `apps/api`. It's stateless.
|
|
144
|
+
- Don't bundle `apps/api` (esbuild, rollup, webpack). Slice specifiers cannot survive it — see `## Deploy path`.
|
|
145
|
+
|
|
146
|
+
Last updated: 2026-09-14 — doc-sync: signal-collectors module extraction (D-48, #5366) — added the `module: signal-collectors` note to the flows/waitlist-signups-me/project-listings-me endpoints, added the previously-undocumented `/v1/deliverables/:grantId`, `/v1/project-listings/{start,submit,:id,public}` and `/v1/slack/actions` rows — verified against `apps/api/src/server.ts` and each route's own header.
|
|
147
|
+
|
|
148
|
+
Prior: 2026-09-12 — doc-sync: added the `## Deploy path` section and the matching `## What NOT to do` line (#5334), recording that bundling `apps/api` is not a supported deploy path and naming the three gates — verified against `apps/api/vercel.json`, `apps/api/src/lib/slice-load.ts` and `scripts/check-bundled-build-diagnoses.ts`.
|
|
121
149
|
|
|
122
|
-
|
|
150
|
+
Prior: 2026-09-12 — doc-sync: added `GET /v1/project-listings/me` (#5295), the auth-scoped founder read joined on the owner link, to Endpoint conventions — verified against `apps/api/src/routes/project-listings/me.ts` and `apps/api/src/server.ts`.
|
|
123
151
|
|
|
124
152
|
Prior: 2026-09-07 — doc-sync: added `listing-csv:sweep` (#5001), the weekly founder-CSV sweep, to `## Scheduled sweeps (external cron)` — verified against `apps/api/src/bin/listing-csv-sweep.ts` and `apps/api/package.json`.
|
|
125
153
|
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"@working-theory/observability": "workspace:*",
|
|
47
47
|
"@working-theory/schema": "workspace:*",
|
|
48
48
|
"@working-theory/site-config": "workspace:*",
|
|
49
|
-
"@working-theory/stripe-client": "workspace:*",
|
|
50
49
|
"@working-theory/validation": "workspace:*",
|
|
51
50
|
"dotenv": "^17.4.2",
|
|
52
51
|
"fastify": "^5.12.1",
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file cors.test.ts
|
|
3
|
+
* @description CORS preflight contract (#5397).
|
|
4
|
+
*
|
|
5
|
+
* The one test file that does NOT mock `@fastify/cors`. Its siblings
|
|
6
|
+
* (`server.test.ts`, `module-exclusion.test.ts`, `index.test.ts`) stub the
|
|
7
|
+
* plugin at the module boundary, which is why the defect this file pins was
|
|
8
|
+
* invisible to the whole suite: with the plugin mocked, the registration
|
|
9
|
+
* options are never read and no preflight is ever answered. The plugin needs
|
|
10
|
+
* no live infrastructure — it is a header writer — so the real one runs here.
|
|
11
|
+
*
|
|
12
|
+
* The defect: `@fastify/cors` defaults `methods` to `GET,HEAD,POST`
|
|
13
|
+
* (node_modules/@fastify/cors/index.js `defaultOptions`), and `server.ts`
|
|
14
|
+
* passed only `origin` + `credentials`. So the preflight for
|
|
15
|
+
* `PATCH /v1/project-listings/drafts/:id` answered
|
|
16
|
+
* `access-control-allow-methods: GET, HEAD, POST` and the browser refused the
|
|
17
|
+
* request — a split-origin site could create a listing draft but never save
|
|
18
|
+
* one. Observed against the salessmyth/samhenry deploy, 2026-09-13.
|
|
19
|
+
*
|
|
20
|
+
* Each case rebuilds the module graph (`jest.resetModules()`) because
|
|
21
|
+
* `config/index.ts` snapshots `FRONTEND_URL` and `NODE_ENV` at import time.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Mocked for the same reasons the sibling suites give: rate-limit wants a live
|
|
25
|
+
// store, and @working-theory/email pulls an ESM-only transitive dep that
|
|
26
|
+
// jest-resolve cannot load in CommonJS mode. `@fastify/cors` is deliberately
|
|
27
|
+
// NOT mocked — it is the subject.
|
|
28
|
+
jest.mock("@fastify/rate-limit", () => jest.fn().mockResolvedValue(undefined));
|
|
29
|
+
|
|
30
|
+
jest.mock("@working-theory/email", () => ({
|
|
31
|
+
sendLeadNotification: jest.fn().mockResolvedValue({ ok: true }),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
import { REGISTERED_ROUTES_DECORATOR } from "../openapi/spec";
|
|
35
|
+
import type { RegisteredRoute } from "../openapi/surface-drift";
|
|
36
|
+
|
|
37
|
+
const FRONTEND_URL = "https://site.example.com";
|
|
38
|
+
const FOREIGN_ORIGIN = "https://attacker.example.net";
|
|
39
|
+
|
|
40
|
+
// The route the defect was found on: ListingApplicationFlow's `patchDraft`
|
|
41
|
+
// runs in the browser on every advance after step one.
|
|
42
|
+
const DRAFT_PATCH_URL = "/v1/project-listings/drafts/listing_abc123";
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- server is typed via Fastify generics; explicit any avoids pulling in the full FastifyInstance type here
|
|
45
|
+
type App = any;
|
|
46
|
+
|
|
47
|
+
const ENV_KEYS = ["FRONTEND_URL", "NODE_ENV"] as const;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Build a server whose `config` was resolved from `env`. Restores the prior
|
|
51
|
+
* environment through `restoreEnv()` in `afterEach`.
|
|
52
|
+
*/
|
|
53
|
+
async function buildWith(env: {
|
|
54
|
+
FRONTEND_URL?: string;
|
|
55
|
+
NODE_ENV: string;
|
|
56
|
+
}): Promise<App> {
|
|
57
|
+
for (const key of ENV_KEYS) {
|
|
58
|
+
const value = env[key];
|
|
59
|
+
if (value === undefined) {
|
|
60
|
+
delete process.env[key];
|
|
61
|
+
} else {
|
|
62
|
+
process.env[key] = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
jest.resetModules();
|
|
66
|
+
|
|
67
|
+
const { build } = require("../server") as typeof import("../server");
|
|
68
|
+
return build();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Issue a CORS preflight the way a browser would. */
|
|
72
|
+
function preflight(
|
|
73
|
+
app: App,
|
|
74
|
+
origin: string,
|
|
75
|
+
method: string,
|
|
76
|
+
url = DRAFT_PATCH_URL,
|
|
77
|
+
) {
|
|
78
|
+
return app.inject({
|
|
79
|
+
method: "OPTIONS",
|
|
80
|
+
url,
|
|
81
|
+
headers: {
|
|
82
|
+
origin,
|
|
83
|
+
"access-control-request-method": method,
|
|
84
|
+
"access-control-request-headers": "authorization,content-type",
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** `Access-Control-Allow-Methods` as an uppercased, trimmed set. */
|
|
90
|
+
function allowedMethods(response: {
|
|
91
|
+
headers: Record<string, unknown>;
|
|
92
|
+
}): string[] {
|
|
93
|
+
const header = response.headers["access-control-allow-methods"];
|
|
94
|
+
if (typeof header !== "string") return [];
|
|
95
|
+
return header.split(",").map((method) => method.trim().toUpperCase());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
describe("CORS preflight (#5397)", () => {
|
|
99
|
+
const priorEnv = new Map<string, string | undefined>(
|
|
100
|
+
ENV_KEYS.map((key) => [key, process.env[key]]),
|
|
101
|
+
);
|
|
102
|
+
let app: App;
|
|
103
|
+
|
|
104
|
+
afterEach(async () => {
|
|
105
|
+
if (app) {
|
|
106
|
+
await app.close();
|
|
107
|
+
app = undefined;
|
|
108
|
+
}
|
|
109
|
+
for (const [key, value] of priorEnv) {
|
|
110
|
+
if (value === undefined) {
|
|
111
|
+
delete process.env[key];
|
|
112
|
+
} else {
|
|
113
|
+
process.env[key] = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
jest.resetModules();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("allows PATCH and the authorization header for the configured FRONTEND_URL origin", async () => {
|
|
120
|
+
// ARRANGE
|
|
121
|
+
app = await buildWith({ FRONTEND_URL, NODE_ENV: "production" });
|
|
122
|
+
|
|
123
|
+
// ACT
|
|
124
|
+
const response = await preflight(app, FRONTEND_URL, "PATCH");
|
|
125
|
+
|
|
126
|
+
// ASSERT — the origin is allowed, with credentials, exactly as before.
|
|
127
|
+
expect(response.headers["access-control-allow-origin"]).toBe(FRONTEND_URL);
|
|
128
|
+
expect(response.headers["access-control-allow-credentials"]).toBe("true");
|
|
129
|
+
// ...and the method the browser asked about is in the answer. Without an
|
|
130
|
+
// explicit `methods` option this is `GET, HEAD, POST` and the browser
|
|
131
|
+
// refuses the PATCH.
|
|
132
|
+
expect(allowedMethods(response)).toEqual(
|
|
133
|
+
expect.arrayContaining(["GET", "HEAD", "POST", "PATCH"]),
|
|
134
|
+
);
|
|
135
|
+
// The bearer token ListingApplicationFlow sends must survive the preflight.
|
|
136
|
+
const allowHeaders = String(
|
|
137
|
+
response.headers["access-control-allow-headers"] ?? "",
|
|
138
|
+
).toLowerCase();
|
|
139
|
+
expect(allowHeaders).toContain("authorization");
|
|
140
|
+
expect(allowHeaders).toContain("content-type");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("refuses a preflight from an origin other than FRONTEND_URL in production", async () => {
|
|
144
|
+
// ARRANGE
|
|
145
|
+
app = await buildWith({ FRONTEND_URL, NODE_ENV: "production" });
|
|
146
|
+
|
|
147
|
+
// ACT
|
|
148
|
+
const response = await preflight(app, FOREIGN_ORIGIN, "PATCH");
|
|
149
|
+
|
|
150
|
+
// ASSERT — with a STRING `origin` option, @fastify/cors echoes the
|
|
151
|
+
// configured origin rather than the requester's
|
|
152
|
+
// (`getAccessControlAllowOriginHeader`), and the refusal is the browser's:
|
|
153
|
+
// it blocks any response whose allow-origin is not its own origin. So the
|
|
154
|
+
// contract to pin is that the foreign origin is never named back, and the
|
|
155
|
+
// wildcard never appears — `credentials: true` with `*` would let any site
|
|
156
|
+
// read credentialed responses (the security-review M1 posture server.ts
|
|
157
|
+
// already documents). Widening `methods` must not widen WHO may use them.
|
|
158
|
+
const allowOrigin = response.headers["access-control-allow-origin"];
|
|
159
|
+
expect(allowOrigin).not.toBe(FOREIGN_ORIGIN);
|
|
160
|
+
expect(allowOrigin).not.toBe("*");
|
|
161
|
+
expect(allowOrigin).toBe(FRONTEND_URL);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("advertises every method the registered route table actually serves", async () => {
|
|
165
|
+
// ARRANGE — every paid module on, so the widest route surface is measured.
|
|
166
|
+
process.env.AILK_ENABLED_MODULES = "multi-tenant,scheduling,content-write";
|
|
167
|
+
try {
|
|
168
|
+
app = await buildWith({ FRONTEND_URL, NODE_ENV: "production" });
|
|
169
|
+
await app.ready();
|
|
170
|
+
|
|
171
|
+
// ACT
|
|
172
|
+
const response = await preflight(app, FRONTEND_URL, "GET", "/health");
|
|
173
|
+
const advertised = allowedMethods(response);
|
|
174
|
+
const registered = new Set(
|
|
175
|
+
(app[REGISTERED_ROUTES_DECORATOR] as RegisteredRoute[]).map((route) =>
|
|
176
|
+
route.method.toUpperCase(),
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// ASSERT — a route added in a method nobody added to the CORS list is
|
|
181
|
+
// unreachable from a browser on a split-origin deploy. This is the drift
|
|
182
|
+
// guard: add a DELETE route, and this fails until `methods` says DELETE.
|
|
183
|
+
// Reported as a set so a drift names every missing method at once.
|
|
184
|
+
const missing = [...registered].filter(
|
|
185
|
+
(method) => !advertised.includes(method),
|
|
186
|
+
);
|
|
187
|
+
expect(missing).toEqual([]);
|
|
188
|
+
// HEAD is never in the route table (Fastify synthesises it from GET, and
|
|
189
|
+
// server.ts's onRoute hook drops it), so assert it separately.
|
|
190
|
+
expect(advertised).toContain("HEAD");
|
|
191
|
+
} finally {
|
|
192
|
+
delete process.env.AILK_ENABLED_MODULES;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -67,6 +67,43 @@ const MODULE_ROUTES: Record<string, { method: 'GET' | 'POST'; url: string }[]> =
|
|
|
67
67
|
],
|
|
68
68
|
scheduling: [{ method: 'GET', url: '/v1/schedule/availability' }],
|
|
69
69
|
'content-write': [{ method: 'POST', url: '/v1/content/BlogPosting' }],
|
|
70
|
+
// D-48 signal-collectors (#5366). Each route is chosen so a REGISTERED
|
|
71
|
+
// handler never itself answers 404 without seed data (an unregistered
|
|
72
|
+
// route is Fastify's own 404, so a route whose "not found" business
|
|
73
|
+
// outcome is also 404 — /v1/flows/:slug with a real slug,
|
|
74
|
+
// /v1/deliverables/:grantId, which is a deliberately uniform 404 by
|
|
75
|
+
// design — would be ambiguous evidence either way):
|
|
76
|
+
// - /v1/flows/INVALID_SLUG fails flowSlugSchema's kebab-case regex ->
|
|
77
|
+
// 400, before any flow lookup (flowsScope gate)
|
|
78
|
+
// - /v1/waitlist-signups/me is authScope-only (no tenant guard) -> 401
|
|
79
|
+
// with no session (one of two authScope gates, D2)
|
|
80
|
+
// - /v1/slack/actions with no signature -> 401/503, never 404
|
|
81
|
+
// (webhooksScope gate)
|
|
82
|
+
// NOT any /v1/project-listings/* static path (D4's authScope gate, or
|
|
83
|
+
// the leadsScope gate's four anonymous routes): whenever this static
|
|
84
|
+
// route is unregistered, multi-tenant's tenant-scoped parametric
|
|
85
|
+
// /v1/project-listings/:id (registered whenever multi-tenant is enabled,
|
|
86
|
+
// which every case below does) matches the last path segment as an :id
|
|
87
|
+
// value and answers 401 (auth required) instead of Fastify's own 404 —
|
|
88
|
+
// a real routing precedence effect (server.ts's own comment on
|
|
89
|
+
// projectListingMeRoute), confirmed for both /me and /public, not a
|
|
90
|
+
// gating defect but ambiguous evidence for this test's shape.
|
|
91
|
+
'signal-collectors': [
|
|
92
|
+
{ method: 'GET', url: '/v1/flows/INVALID_SLUG' },
|
|
93
|
+
{ method: 'GET', url: '/v1/waitlist-signups/me' },
|
|
94
|
+
{ method: 'POST', url: '/v1/slack/actions' },
|
|
95
|
+
],
|
|
96
|
+
// D-47 commerce (#5364): checkout, the Stripe webhook receiver, the
|
|
97
|
+
// flow-checkouts read and the recommender's two email-moment routes —
|
|
98
|
+
// one representative route per registration site server.ts gates on
|
|
99
|
+
// isModuleEnabled("commerce").
|
|
100
|
+
commerce: [
|
|
101
|
+
{ method: 'POST', url: '/v1/checkout/sessions' },
|
|
102
|
+
{ method: 'POST', url: '/v1/webhooks/stripe' },
|
|
103
|
+
{ method: 'GET', url: '/v1/flow-checkouts/me' },
|
|
104
|
+
{ method: 'POST', url: '/v1/flows/x/checkout' },
|
|
105
|
+
{ method: 'POST', url: '/v1/flows/x/save' },
|
|
106
|
+
],
|
|
70
107
|
};
|
|
71
108
|
|
|
72
109
|
const ALL_MODULES = Object.keys(MODULE_ROUTES);
|
|
@@ -103,8 +140,8 @@ describe('Module exclusion — registration vanishes with the module (S1, #5088)
|
|
|
103
140
|
},
|
|
104
141
|
);
|
|
105
142
|
|
|
106
|
-
it('with every module enabled
|
|
107
|
-
app = await build();
|
|
143
|
+
it('with every module explicitly enabled, every module route registers — no over-exclusion', async () => {
|
|
144
|
+
app = await withEnabledModules(ALL_MODULES.join(','), () => build());
|
|
108
145
|
for (const routes of Object.values(MODULE_ROUTES)) {
|
|
109
146
|
for (const { method, url } of routes) {
|
|
110
147
|
const res = await app.inject({ method, url });
|
|
@@ -138,4 +175,25 @@ describe('Module exclusion — registration vanishes with the module (S1, #5088)
|
|
|
138
175
|
}
|
|
139
176
|
}
|
|
140
177
|
});
|
|
178
|
+
|
|
179
|
+
// D-44 / #5368: an unset AILK_ENABLED_MODULES is now the same as an
|
|
180
|
+
// explicit empty string — no paid module registers by default.
|
|
181
|
+
it('with AILK_ENABLED_MODULES unset (the new default), every module route 404s', async () => {
|
|
182
|
+
delete process.env.AILK_ENABLED_MODULES;
|
|
183
|
+
app = await build();
|
|
184
|
+
const health = await app.inject({ method: 'GET', url: '/health' });
|
|
185
|
+
expect(health.statusCode).toBe(200);
|
|
186
|
+
const contentTypes = await app.inject({
|
|
187
|
+
method: 'GET',
|
|
188
|
+
url: '/v1/content/types',
|
|
189
|
+
});
|
|
190
|
+
expect(contentTypes.statusCode).not.toBe(404);
|
|
191
|
+
|
|
192
|
+
for (const routes of Object.values(MODULE_ROUTES)) {
|
|
193
|
+
for (const { method, url } of routes) {
|
|
194
|
+
const res = await app.inject({ method, url });
|
|
195
|
+
expect(res.statusCode).toBe(404);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
141
199
|
});
|