create-ailk 0.21.0 → 0.23.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.json +186 -8
- package/component-catalog.md +9 -7
- package/dist/add-module.js +20 -14
- package/dist/add-route.d.ts +55 -1
- package/dist/add-route.js +294 -12
- package/dist/cli.js +27 -10
- package/dist/derive-architecture.d.ts +12 -3
- package/dist/derive-architecture.js +20 -8
- package/dist/design-package.js +7 -2
- package/dist/lib/design-checks.js +4 -2
- package/dist/lib/env-catalog.js +5 -5
- package/dist/lib/npm-auth.d.ts +9 -0
- package/dist/lib/npm-auth.js +48 -0
- package/dist/lib/scaffold-render-sweep.d.ts +3 -2
- package/dist/lib/scaffold-render-sweep.js +5 -8
- package/dist/module-architecture.js +99 -9
- package/dist/paid-sections.d.ts +21 -2
- package/dist/paid-sections.js +69 -7
- package/dist/programmatic.js +19 -5
- package/dist/seed-flows.d.ts +4 -1
- package/dist/seed-flows.js +50 -4
- package/dist/site-chrome.d.ts +8 -0
- package/dist/site-chrome.js +17 -1
- package/dist/spoke-checkout.d.ts +65 -41
- package/dist/spoke-checkout.js +208 -430
- package/dist/starter-grid.d.ts +0 -3
- package/dist/starter-grid.js +24 -14
- package/dist/surfaces.js +52 -26
- package/dist/sync-routes.d.ts +38 -1
- package/dist/sync-routes.js +187 -13
- package/dist/template-record.d.ts +4 -3
- package/dist/template-record.js +8 -4
- package/dist/topology.js +25 -1
- package/dist/update.js +15 -0
- package/package.json +3 -3
- package/site-templates/_base/content/en/NewsletterSignup/newsletter.mdx +4 -49
- package/site-templates/_base/content/en/Pricing/pricing.mdx +3 -21
- package/site-templates/designs/minimalism/DESIGN.md +1 -1
- package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +23 -20
- package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +28 -14
- package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +15 -39
- package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +38 -34
- package/site-templates/marketing-site-free/content/en/NewsletterSignup/newsletter.mdx +6 -43
- package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +14 -31
- package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +26 -25
- package/site-templates/shapes/local-business-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
- package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +14 -31
- package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +26 -25
- package/site-templates/shapes/organization-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
- package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +14 -31
- package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +26 -25
- package/site-templates/shapes/person-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
- package/templates/.env.example +9 -7
- package/templates/.github/workflows/ci.yml +13 -0
- package/templates/README.md +1 -0
- package/templates/_gitignore +4 -0
- package/templates/apps/api/.env.example +27 -0
- package/templates/apps/api/CLAUDE.md +87 -17
- package/templates/apps/api/package.json +1 -0
- package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +2 -0
- package/templates/apps/api/src/bin/stripe-connections-rekey.ts +45 -0
- package/templates/apps/api/src/config/__tests__/stripe-connection-key.test.ts +185 -0
- package/templates/apps/api/src/config/index.ts +109 -0
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +3 -0
- package/templates/apps/api/src/lib/__tests__/consent-store.test.ts +19 -0
- package/templates/apps/api/src/lib/__tests__/flow-completion-store.test.ts +149 -0
- package/templates/apps/api/src/lib/__tests__/flow-rename-race.db.test.ts +116 -0
- package/templates/apps/api/src/lib/consent-store.ts +28 -0
- package/templates/apps/api/src/lib/error-serializer.ts +74 -7
- package/templates/apps/api/src/lib/flow-completion-store.ts +136 -0
- package/templates/apps/api/src/lib/hub-sign-in-store.ts +38 -2
- package/templates/apps/api/src/lib/proposal-paid-store.ts +21 -4
- package/templates/apps/api/src/lib/stripe.ts +74 -4
- package/templates/apps/api/src/lib/webhook-idempotency.ts +66 -2
- package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +14 -3
- package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +218 -0
- package/templates/apps/api/src/middleware/__tests__/write-budget.test.ts +174 -0
- package/templates/apps/api/src/middleware/auth.ts +13 -6
- package/templates/apps/api/src/middleware/rate-limit.ts +226 -4
- package/templates/apps/api/src/openapi/spec.ts +33 -3
- package/templates/apps/api/src/routes/auth/__tests__/hub-sign-in.test.ts +49 -0
- package/templates/apps/api/src/routes/auth/hub-sign-in.ts +41 -0
- package/templates/apps/api/src/routes/billing/plan-checkout.ts +325 -0
- package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +11 -0
- package/templates/apps/api/src/routes/checkout/__tests__/offerings-authorization.test.ts +1300 -0
- package/templates/apps/api/src/routes/checkout/__tests__/session.test.ts +11 -0
- package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +49 -0
- package/templates/apps/api/src/routes/checkout/session.ts +57 -25
- package/templates/apps/api/src/routes/checkout/sessions.ts +232 -82
- package/templates/apps/api/src/routes/consent/__tests__/account.test.ts +386 -0
- package/templates/apps/api/src/routes/consent/__tests__/sign-up-rate-limit.test.ts +160 -0
- package/templates/apps/api/src/routes/consent/account.ts +268 -0
- package/templates/apps/api/src/routes/consent/index.ts +15 -7
- package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +36 -0
- package/templates/apps/api/src/routes/content/__tests__/offerings.test.ts +731 -0
- package/templates/apps/api/src/routes/content/__tests__/pricing.test.ts +753 -0
- package/templates/apps/api/src/routes/content/__tests__/shown-offerings.test.ts +762 -0
- package/templates/apps/api/src/routes/content/get-page.ts +4 -0
- package/templates/apps/api/src/routes/content/index.ts +16 -2
- package/templates/apps/api/src/routes/content/offerings.ts +184 -0
- package/templates/apps/api/src/routes/content/pricing.ts +176 -0
- package/templates/apps/api/src/routes/content/shown-offerings.ts +229 -0
- package/templates/apps/api/src/routes/leads/__tests__/magnet-completion.test.ts +515 -0
- package/templates/apps/api/src/routes/leads/index.ts +164 -7
- package/templates/apps/api/src/routes/webhooks/README.md +66 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-checkout-consent.test.ts +649 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-offerings.test.ts +814 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +80 -68
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +5 -5
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +8 -2
- package/templates/apps/api/src/routes/webhooks/index.ts +23 -0
- package/templates/apps/api/src/routes/webhooks/stripe-offerings.ts +384 -0
- package/templates/apps/api/src/routes/webhooks/stripe.ts +245 -36
- package/templates/apps/api/src/server.ts +163 -46
- package/templates/apps/api/src/services/__tests__/checkout-plan.test.ts +313 -0
- package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +51 -2
- package/templates/apps/api/src/services/__tests__/keyless-workspace-predicate.test.ts +234 -0
- package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +1383 -133
- package/templates/apps/api/src/services/__tests__/magnet-completion.test.ts +389 -0
- package/templates/apps/api/src/services/__tests__/person.test.ts +232 -1
- package/templates/apps/api/src/services/__tests__/plan-offerings.test.ts +444 -0
- package/templates/apps/api/src/services/checkout-buyer.ts +100 -4
- package/templates/apps/api/src/services/consent.ts +95 -0
- package/templates/apps/api/src/services/deliverable-fulfillment.ts +13 -5
- package/templates/apps/api/src/services/entitlements.ts +157 -1
- package/templates/apps/api/src/services/lead-routing.ts +431 -47
- package/templates/apps/api/src/services/magnet-completion.ts +242 -0
- package/templates/apps/api/src/services/offerings/__tests__/catalog.test.ts +295 -0
- package/templates/apps/api/src/services/offerings/__tests__/checkout-session-record.test.ts +268 -0
- package/templates/apps/api/src/services/offerings/__tests__/connection.test.ts +868 -0
- package/templates/apps/api/src/services/offerings/__tests__/fixtures.ts +416 -0
- package/templates/apps/api/src/services/offerings/__tests__/org-products.test.ts +396 -0
- package/templates/apps/api/src/services/offerings/__tests__/readers.test.ts +681 -0
- package/templates/apps/api/src/services/offerings/__tests__/source.test.ts +231 -0
- package/templates/apps/api/src/services/offerings/catalog.ts +308 -0
- package/templates/apps/api/src/services/offerings/checkout-authorization.ts +385 -0
- package/templates/apps/api/src/services/offerings/checkout-session-record.ts +192 -0
- package/templates/apps/api/src/services/offerings/connection.ts +1003 -0
- package/templates/apps/api/src/services/offerings/index.ts +614 -0
- package/templates/apps/api/src/services/offerings/source.ts +140 -0
- package/templates/apps/api/src/services/offerings/store.ts +150 -0
- package/templates/apps/api/src/services/person.ts +164 -17
- package/templates/apps/api/src/services/plan-offerings.ts +125 -0
- package/templates/apps/api/src/services/public-site-resolver.ts +27 -15
- package/templates/apps/mcp/CLAUDE.md +22 -14
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +9 -4
- package/templates/apps/mcp/__tests__/get_offerings.test.ts +358 -0
- package/templates/apps/mcp/__tests__/get_pricing.test.ts +364 -0
- package/templates/apps/mcp/__tests__/http-transport.test.ts +4 -4
- package/templates/apps/mcp/__tests__/module-exclusion.test.ts +2 -2
- package/templates/apps/mcp/__tests__/server.test.ts +13 -11
- package/templates/apps/mcp/__tests__/start_purchase.test.ts +208 -12
- package/templates/apps/mcp/__tests__/tools/purchase.test.ts +11 -11
- package/templates/apps/mcp/src/lib/shown-offerings.ts +105 -0
- package/templates/apps/mcp/src/server.ts +5 -0
- package/templates/apps/mcp/src/tools/get_offerings.ts +47 -30
- package/templates/apps/mcp/src/tools/get_pricing.ts +40 -40
- package/templates/apps/mcp/src/tools/purchase.ts +30 -2
- package/templates/apps/mcp/src/workspace-server.ts +15 -0
- package/templates/apps/web/.env.example +24 -31
- package/templates/apps/web/CLAUDE.md +393 -9
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +6 -2
- package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +5 -4
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +5 -1
- package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +2 -0
- package/templates/apps/web/app/[locale]/(auth)/layout.tsx +3 -14
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +2 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +5 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +160 -8
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +12 -9
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +105 -2
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +36 -3
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +47 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +60 -22
- package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +16 -8
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +85 -31
- package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +18 -4
- package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +3 -1
- package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +7 -4
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +227 -207
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +17 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +143 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +4 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +385 -89
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +5 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +44 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +68 -34
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -8
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +39 -151
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +61 -0
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +143 -140
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +40 -6
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +68 -54
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +5 -1
- package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +189 -0
- package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +295 -0
- package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +120 -0
- package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +23 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +319 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +172 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +149 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +141 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +424 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +72 -11
- package/templates/apps/web/app/[locale]/careers/page.tsx +129 -5
- package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +139 -0
- package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +136 -0
- package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +114 -0
- package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +51 -0
- package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +17 -1
- package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +79 -4
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +160 -13
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +466 -36
- package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +172 -57
- package/templates/apps/web/app/[locale]/contact/intake-script.ts +26 -0
- package/templates/apps/web/app/[locale]/contact/page.tsx +99 -60
- package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +341 -4
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +43 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +200 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +197 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +257 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +69 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +430 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +21 -9
- package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +35 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +352 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +12 -73
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +10 -31
- package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/layout.tsx +55 -4
- package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +174 -104
- package/templates/apps/web/app/[locale]/newsletter/page.tsx +95 -58
- package/templates/apps/web/app/[locale]/page.tsx +13 -1
- package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +7 -0
- package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +599 -0
- package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +216 -0
- package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +236 -0
- package/templates/apps/web/app/[locale]/pricing/page.tsx +367 -6
- package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +2 -2
- package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +4 -1
- package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/thanks/[slug]/AccountInviteLink.tsx +89 -0
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/AccountInviteLink.test.tsx +104 -0
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +38 -0
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +9 -0
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +17 -0
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +62 -3
- package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +70 -18
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +30 -9
- package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +1 -1
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +114 -0
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +20 -3
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +44 -1
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +22 -3
- package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/route.ts +316 -0
- package/templates/apps/web/app/api/offerings/checkout/__tests__/route.test.ts +810 -0
- package/templates/apps/web/auth.ts +28 -2
- package/templates/apps/web/lib/__tests__/account-invite.test.ts +63 -0
- package/templates/apps/web/lib/__tests__/auth-routes.test.ts +27 -1
- package/templates/apps/web/lib/__tests__/consent-policies.test.ts +23 -0
- package/templates/apps/web/lib/__tests__/deck-page.test.ts +7 -1
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +265 -0
- package/templates/apps/web/lib/__tests__/magnet-routes.test.ts +57 -0
- package/templates/apps/web/lib/__tests__/newsletter.actions.test.ts +293 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +601 -0
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +101 -25
- package/templates/apps/web/lib/account-invite.ts +37 -0
- package/templates/apps/web/lib/auth-routes.ts +36 -2
- package/templates/apps/web/lib/checkout-config.ts +16 -0
- package/templates/apps/web/lib/consent-policies.ts +22 -0
- package/templates/apps/web/lib/deck-page.ts +7 -0
- package/templates/apps/web/lib/deliverable-grant.ts +18 -0
- package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +111 -0
- package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +88 -32
- package/templates/apps/web/lib/in-page-magnet.ts +416 -0
- package/templates/apps/web/lib/magnet-routes.ts +42 -0
- package/templates/apps/web/lib/modules.generated.ts +9 -0
- package/templates/apps/web/lib/newsletter.actions.ts +202 -0
- package/templates/apps/web/lib/offerings-pricing.ts +326 -0
- package/templates/apps/web/lib/posting-title.ts +17 -0
- package/templates/apps/web/lib/prisma-for-auth.ts +8 -0
- package/templates/apps/web/lib/sign-up-agreements.ts +449 -0
- package/templates/apps/web/lib/site-chrome.ts +2 -0
- package/templates/apps/web/lib/telemetry-scrub.ts +5 -1
- package/templates/apps/web/messages/en.json +71 -20
- package/templates/apps/web/middleware.ts +12 -2
- package/templates/apps/web/package.json +1 -0
- package/templates/apps/web/security-headers.config.ts +17 -0
- package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +187 -0
- package/templates/apps/web/src/lib/__tests__/rate-limit.test.ts +67 -0
- package/templates/apps/web/src/lib/lead-write.ts +90 -0
- package/templates/apps/web/src/lib/rate-limit.ts +79 -0
- package/templates/content/en/BlogList/blog.mdx +4 -71
- package/templates/content/en/BookCall/book-a-call.mdx +1 -41
- package/templates/content/en/BookCall/onsite-estimate.mdx +1 -17
- package/templates/content/en/BookCall/onsite-service.mdx +1 -17
- package/templates/content/en/BookCall/start-project.mdx +1 -17
- package/templates/content/en/ContactPage/contact.mdx +6 -63
- package/templates/content/en/HomePage/home.mdx +3 -21
- package/templates/database/CHANGELOG.md +69 -0
- package/templates/database/__tests__/consent-source-checkout-migration.test.ts +79 -0
- package/templates/database/__tests__/flow-completion-migration.test.ts +115 -0
- package/templates/database/__tests__/flow-completion.db.test.ts +136 -0
- package/templates/database/__tests__/in-page-magnets-migration.test.ts +161 -0
- package/templates/database/__tests__/offerings-checkout-session.db.test.ts +270 -0
- package/templates/database/__tests__/offerings-migration.test.ts +197 -0
- package/templates/database/__tests__/offerings-shown-price-ids-migration.test.ts +86 -0
- package/templates/database/__tests__/offerings.db.test.ts +303 -0
- package/templates/database/__tests__/seed.test.ts +64 -1
- package/templates/database/auth/schema.prisma +4 -0
- package/templates/database/config/schema.prisma +91 -0
- package/templates/database/inbox/schema.prisma +17 -2
- package/templates/database/migrations/20261018120000_flow_completion/migration.sql +52 -0
- package/templates/database/migrations/20261019120000_consent_source_checkout/migration.sql +27 -0
- package/templates/database/migrations/20261020120000_offerings_data_model/migration.sql +146 -0
- package/templates/database/migrations/20261021120000_offerings_checkout_session/migration.sql +77 -0
- package/templates/database/migrations/20261022120000_in_page_magnets/migration.sql +45 -0
- package/templates/database/migrations/20261023120000_offerings_shown_price_ids/migration.sql +47 -0
- package/templates/database/migrations/20261024120000_organization_plan_checkout_session/migration.sql +16 -0
- package/templates/database/package.json +1 -1
- package/templates/database/seed.ts +62 -3
- package/versions.json +35 -35
- package/site-templates/marketing-site-free/content/en/Pricing/pricing.mdx +0 -199
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up.actions.ts +0 -125
- package/templates/apps/web/app/[locale]/downloads/__tests__/page-renderer-migration.test.tsx +0 -93
- package/templates/apps/web/app/[locale]/downloads/page.tsx +0 -37
- package/templates/apps/web/app/[locale]/newsletter/__tests__/newsletter.actions.test.ts +0 -139
- package/templates/apps/web/app/[locale]/newsletter/newsletter.actions.ts +0 -93
- package/templates/apps/web/lib/__tests__/meeting-slugs.test.ts +0 -120
- package/templates/apps/web/lib/meeting-slugs.ts +0 -63
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The Offerings buy route (#9051, spec
|
|
7
|
+
* docs/specs/9051-the-offerings-buy-route-api-spec.md AC-1, AC-2, AC-4–AC-6).
|
|
8
|
+
*
|
|
9
|
+
* The real api-client, mapper, `resolveBaseUrl`, `FALLBACK_BASE_URL` and
|
|
10
|
+
* `resolveCommerceClaim` run; only the licence read and `fetch` are stubbed.
|
|
11
|
+
* `fetch` routes by path: the shown-set read and the session POST each answer
|
|
12
|
+
* the case's own stub. The incoming request is addressed to `evil.example`
|
|
13
|
+
* with a buyer cookie, so a redirect built from the request or a forwarded
|
|
14
|
+
* cookie fails AC-1. The clock moves 16 seconds before every case, so no case
|
|
15
|
+
* reads another's shared answer, and each case brings its own visitor
|
|
16
|
+
* address, so none spends another's start budget.
|
|
17
|
+
*/
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
|
|
21
|
+
import { checkLicense } from "@working-theory/license";
|
|
22
|
+
import {
|
|
23
|
+
workspaceShownSetSchema,
|
|
24
|
+
type OfferingsPrice,
|
|
25
|
+
type OfferingsProduct,
|
|
26
|
+
} from "@working-theory/validation";
|
|
27
|
+
|
|
28
|
+
jest.mock("@working-theory/license", () => ({
|
|
29
|
+
checkLicense: jest.fn(),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
import { GET } from "../[lookupKey]/route";
|
|
33
|
+
|
|
34
|
+
const mockCheckLicense = checkLicense as jest.MockedFunction<
|
|
35
|
+
typeof checkLicense
|
|
36
|
+
>;
|
|
37
|
+
type LicenseShape = Awaited<ReturnType<typeof checkLicense>>;
|
|
38
|
+
|
|
39
|
+
/** Point the mocked reader at a licence shape, filling only the fields
|
|
40
|
+
* `resolveCommerceClaim` reads (`revoked`, `features`). */
|
|
41
|
+
function licenceResolves(result: Partial<LicenseShape>): void {
|
|
42
|
+
mockCheckLicense.mockResolvedValue(result as LicenseShape);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ROUTE_SOURCE = readFileSync(
|
|
46
|
+
join(__dirname, "..", "[lookupKey]", "route.ts"),
|
|
47
|
+
"utf8",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const API = "https://api.example.test";
|
|
51
|
+
const CHECKOUT_URL = "https://checkout.stripe.com/c/pay/cs_test_a1";
|
|
52
|
+
const SUCCESS_URL =
|
|
53
|
+
"https://shop.example.com/purchase/success?session_id={CHECKOUT_SESSION_ID}";
|
|
54
|
+
const CANCEL_URL = "https://shop.example.com/pricing";
|
|
55
|
+
const REFUSAL_LINE = /^\[offerings-checkout\] refused reason=[a-z0-9_]+$/;
|
|
56
|
+
|
|
57
|
+
// ─── The fixture: a wire shown set (no ids), parsed before use ──────────────
|
|
58
|
+
|
|
59
|
+
const PERIOD_INTERVAL = {
|
|
60
|
+
monthly: "month",
|
|
61
|
+
yearly: "year",
|
|
62
|
+
once: null,
|
|
63
|
+
} as const;
|
|
64
|
+
|
|
65
|
+
function price(
|
|
66
|
+
plan: string,
|
|
67
|
+
period: OfferingsPrice["period"],
|
|
68
|
+
amount: number,
|
|
69
|
+
): OfferingsPrice {
|
|
70
|
+
return {
|
|
71
|
+
priceId: `price_${plan.replace(/-/g, "")}${period}`,
|
|
72
|
+
lookupKey: `${plan}_${period}`,
|
|
73
|
+
plan,
|
|
74
|
+
period,
|
|
75
|
+
interval: PERIOD_INTERVAL[period],
|
|
76
|
+
amount,
|
|
77
|
+
currency: "usd",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function product(
|
|
82
|
+
plan: string,
|
|
83
|
+
ailkGroup: OfferingsProduct["ailkGroup"],
|
|
84
|
+
prices: OfferingsPrice[],
|
|
85
|
+
): OfferingsProduct {
|
|
86
|
+
return {
|
|
87
|
+
productId: `prod_${plan.replace(/-/g, "")}`,
|
|
88
|
+
plan,
|
|
89
|
+
name: plan,
|
|
90
|
+
description: null,
|
|
91
|
+
marketingFeatures: [],
|
|
92
|
+
unitLabel: null,
|
|
93
|
+
note: null,
|
|
94
|
+
termsNote: null,
|
|
95
|
+
ailkGroup,
|
|
96
|
+
ailkOrder: null,
|
|
97
|
+
prices,
|
|
98
|
+
recommended: false,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const wireShownSetSchema = workspaceShownSetSchema.partial({
|
|
103
|
+
workspaceId: true,
|
|
104
|
+
organizationId: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function wireShownSet(
|
|
108
|
+
options: { state?: "current" | "expired"; withGrowth?: boolean } = {},
|
|
109
|
+
): unknown {
|
|
110
|
+
const offerings = [
|
|
111
|
+
...(options.withGrowth === false
|
|
112
|
+
? []
|
|
113
|
+
: [
|
|
114
|
+
product("growth", "plan", [
|
|
115
|
+
price("growth", "monthly", 4900),
|
|
116
|
+
price("growth", "yearly", 49000),
|
|
117
|
+
]),
|
|
118
|
+
]),
|
|
119
|
+
product("seo-audit", "addon", [price("seo-audit", "monthly", 1950)]),
|
|
120
|
+
];
|
|
121
|
+
return wireShownSetSchema.parse({
|
|
122
|
+
productIds: offerings.map((o) => o.productId),
|
|
123
|
+
recommended: { plan: null, addon: null },
|
|
124
|
+
offerings,
|
|
125
|
+
state: options.state ?? "current",
|
|
126
|
+
snapshotAt: "2026-10-18T00:00:00.000Z",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ─── The stubbed API ────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
type Answer =
|
|
133
|
+
| { status: number; json: unknown }
|
|
134
|
+
| { status: number; text: string }
|
|
135
|
+
| "reject"
|
|
136
|
+
| "hang";
|
|
137
|
+
|
|
138
|
+
const SHOWN: Answer = {
|
|
139
|
+
status: 200,
|
|
140
|
+
json: { ok: true, data: { status: "shown", shownSet: wireShownSet() } },
|
|
141
|
+
};
|
|
142
|
+
const STARTED: Answer = {
|
|
143
|
+
status: 201,
|
|
144
|
+
json: { sessionId: "cs_test_a1", url: CHECKOUT_URL },
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
let shownAnswer: Answer;
|
|
148
|
+
let postAnswer: Answer;
|
|
149
|
+
|
|
150
|
+
function respond(answer: Answer): Promise<Response> {
|
|
151
|
+
if (answer === "reject") return Promise.reject(new TypeError("fetch failed"));
|
|
152
|
+
if (answer === "hang") return new Promise<Response>(() => {});
|
|
153
|
+
if ("text" in answer) {
|
|
154
|
+
return Promise.resolve(
|
|
155
|
+
new Response(answer.text, { status: answer.status }),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return Promise.resolve(
|
|
159
|
+
new Response(JSON.stringify(answer.json), {
|
|
160
|
+
status: answer.status,
|
|
161
|
+
headers: { "content-type": "application/json" },
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const fetchMock = jest.fn(
|
|
167
|
+
(input: string | URL | Request, _init?: RequestInit) => {
|
|
168
|
+
const url = new URL(String(input));
|
|
169
|
+
if (url.pathname === "/v1/content/shown-offerings")
|
|
170
|
+
return respond(shownAnswer);
|
|
171
|
+
if (url.pathname === "/v1/checkout/sessions") return respond(postAnswer);
|
|
172
|
+
return Promise.reject(new Error(`unexpected fetch ${url.pathname}`));
|
|
173
|
+
},
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
function postCalls(): { url: string; init: RequestInit }[] {
|
|
177
|
+
return fetchMock.mock.calls
|
|
178
|
+
.filter(
|
|
179
|
+
([input]) => new URL(String(input)).pathname === "/v1/checkout/sessions",
|
|
180
|
+
)
|
|
181
|
+
.map(([input, init]) => ({ url: String(input), init: init ?? {} }));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function shownCalls(): number {
|
|
185
|
+
return fetchMock.mock.calls.filter(
|
|
186
|
+
([input]) =>
|
|
187
|
+
new URL(String(input)).pathname === "/v1/content/shown-offerings",
|
|
188
|
+
).length;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function postHeaders(call: { init: RequestInit }): Record<string, string> {
|
|
192
|
+
const lower: Record<string, string> = {};
|
|
193
|
+
for (const [name, value] of Object.entries(
|
|
194
|
+
(call.init.headers ?? {}) as Record<string, string>,
|
|
195
|
+
)) {
|
|
196
|
+
lower[name.toLowerCase()] = value;
|
|
197
|
+
}
|
|
198
|
+
return lower;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ─── The env, the console and the clock ─────────────────────────────────────
|
|
202
|
+
|
|
203
|
+
const env = process.env as Record<string, string | undefined>;
|
|
204
|
+
const ENV_NAMES = [
|
|
205
|
+
"AILK_API_URL",
|
|
206
|
+
"NEXT_PUBLIC_AILK_API_URL",
|
|
207
|
+
"NEXT_PUBLIC_API_URL",
|
|
208
|
+
"NEXT_PUBLIC_BASE_URL",
|
|
209
|
+
"NODE_ENV",
|
|
210
|
+
"OSS_API_INTERNAL_SECRET",
|
|
211
|
+
"AILK_SPOKE_KEY",
|
|
212
|
+
] as const;
|
|
213
|
+
const savedEnv = Object.fromEntries(ENV_NAMES.map((name) => [name, env[name]]));
|
|
214
|
+
|
|
215
|
+
const CONSOLE_METHODS = ["log", "info", "warn", "error", "debug"] as const;
|
|
216
|
+
let consoleSpies: jest.SpyInstance[] = [];
|
|
217
|
+
let warnSpy: jest.SpyInstance;
|
|
218
|
+
|
|
219
|
+
const realFetch = global.fetch;
|
|
220
|
+
|
|
221
|
+
let addressCounter = 0;
|
|
222
|
+
/** A visitor address no other case uses. */
|
|
223
|
+
function freshAddress(): string {
|
|
224
|
+
addressCounter += 1;
|
|
225
|
+
return `10.20.${Math.floor(addressCounter / 250)}.${(addressCounter % 250) + 1}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
beforeAll(() => {
|
|
229
|
+
jest.useFakeTimers({
|
|
230
|
+
doNotFake: ["nextTick", "setImmediate", "clearImmediate", "queueMicrotask"],
|
|
231
|
+
});
|
|
232
|
+
jest.setSystemTime(Date.UTC(2026, 9, 18, 12, 0, 0));
|
|
233
|
+
global.fetch = fetchMock as jest.Mock;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
afterAll(() => {
|
|
237
|
+
jest.useRealTimers();
|
|
238
|
+
global.fetch = realFetch;
|
|
239
|
+
for (const name of ENV_NAMES) {
|
|
240
|
+
if (savedEnv[name] === undefined) delete env[name];
|
|
241
|
+
else env[name] = savedEnv[name];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
beforeEach(() => {
|
|
246
|
+
jest.setSystemTime(Date.now() + 16_000);
|
|
247
|
+
for (const name of ENV_NAMES) delete env[name];
|
|
248
|
+
env.AILK_API_URL = API;
|
|
249
|
+
env.NEXT_PUBLIC_BASE_URL = "https://shop.example.com";
|
|
250
|
+
env.NODE_ENV = "test";
|
|
251
|
+
shownAnswer = SHOWN;
|
|
252
|
+
postAnswer = STARTED;
|
|
253
|
+
fetchMock.mockClear();
|
|
254
|
+
mockCheckLicense.mockReset();
|
|
255
|
+
licenceResolves({ features: ["commerce"] });
|
|
256
|
+
consoleSpies = CONSOLE_METHODS.map((method) =>
|
|
257
|
+
jest.spyOn(console, method).mockImplementation(() => {}),
|
|
258
|
+
);
|
|
259
|
+
warnSpy = consoleSpies[CONSOLE_METHODS.indexOf("warn")]!;
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
afterEach(() => {
|
|
263
|
+
for (const spy of consoleSpies) spy.mockRestore();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// ─── The request ────────────────────────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A buyer's card click on `key`: a top-level same-origin navigation to the
|
|
270
|
+
* wrong host, with a session cookie and a fresh forwarded address. A header
|
|
271
|
+
* set to `null` is left out.
|
|
272
|
+
*/
|
|
273
|
+
function buyRequest(
|
|
274
|
+
key: string,
|
|
275
|
+
options: { method?: string; headers?: Record<string, string | null> } = {},
|
|
276
|
+
): Request {
|
|
277
|
+
const headers: Record<string, string | null> = {
|
|
278
|
+
host: "evil.example",
|
|
279
|
+
cookie: "better-auth.session_token=abc",
|
|
280
|
+
"sec-fetch-mode": "navigate",
|
|
281
|
+
"sec-fetch-dest": "document",
|
|
282
|
+
"sec-fetch-site": "same-origin",
|
|
283
|
+
"x-forwarded-for": freshAddress(),
|
|
284
|
+
...options.headers,
|
|
285
|
+
};
|
|
286
|
+
const sent = new Headers();
|
|
287
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
288
|
+
if (value !== null) sent.set(name, value);
|
|
289
|
+
}
|
|
290
|
+
return new Request(`https://evil.example/api/offerings/checkout/${key}`, {
|
|
291
|
+
method: options.method ?? "GET",
|
|
292
|
+
headers: sent,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function buy(
|
|
297
|
+
key: string,
|
|
298
|
+
request: Request = buyRequest(key),
|
|
299
|
+
): Promise<Response> {
|
|
300
|
+
return GET(request, { params: Promise.resolve({ lookupKey: key }) });
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Every argument of every console call, as text. */
|
|
304
|
+
function consoleText(): string {
|
|
305
|
+
return consoleSpies
|
|
306
|
+
.flatMap((spy) => spy.mock.calls.flat())
|
|
307
|
+
.map((arg) => String(arg))
|
|
308
|
+
.join("\n");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async function expectStarted(res: Response, url = CHECKOUT_URL): Promise<void> {
|
|
312
|
+
expect(res.status).toBe(303);
|
|
313
|
+
expect(res.headers.get("location")).toBe(url);
|
|
314
|
+
expect(res.headers.get("cache-control")).toBe("no-store");
|
|
315
|
+
expect(await res.text()).toBe("");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Refused: 303 to `/pricing`, no-store, no body, one fixed warn line, no key anywhere. */
|
|
319
|
+
async function expectRefused(
|
|
320
|
+
res: Response,
|
|
321
|
+
key: string,
|
|
322
|
+
reason?: string,
|
|
323
|
+
): Promise<void> {
|
|
324
|
+
expect(res.status).toBe(303);
|
|
325
|
+
expect(res.headers.get("location")).toBe("/pricing");
|
|
326
|
+
expect(res.headers.get("cache-control")).toBe("no-store");
|
|
327
|
+
const body = await res.text();
|
|
328
|
+
expect(body).toBe("");
|
|
329
|
+
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
330
|
+
expect(warnSpy.mock.calls[0]).toHaveLength(1);
|
|
331
|
+
expect(warnSpy.mock.calls[0]![0]).toMatch(REFUSAL_LINE);
|
|
332
|
+
if (reason) {
|
|
333
|
+
expect(warnSpy.mock.calls[0]![0]).toBe(
|
|
334
|
+
`[offerings-checkout] refused reason=${reason}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
for (const spy of consoleSpies) {
|
|
338
|
+
if (spy !== warnSpy) expect(spy).not.toHaveBeenCalled();
|
|
339
|
+
}
|
|
340
|
+
expect(consoleText()).not.toContain(key);
|
|
341
|
+
for (const [, value] of res.headers) expect(value).not.toContain(key);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ─── AC-1 ───────────────────────────────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
describe("AC-1 — a shown key on a connected site starts its Checkout", () => {
|
|
347
|
+
it.each(["growth_monthly", "growth_yearly"])(
|
|
348
|
+
"answers 303 to the API's Checkout URL for %s, posting the full key and site-origin redirects",
|
|
349
|
+
async (key) => {
|
|
350
|
+
const res = await buy(key);
|
|
351
|
+
await expectStarted(res);
|
|
352
|
+
|
|
353
|
+
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
354
|
+
expect(new URL(String(fetchMock.mock.calls[0]![0])).pathname).toBe(
|
|
355
|
+
"/v1/content/shown-offerings",
|
|
356
|
+
);
|
|
357
|
+
const [call] = postCalls();
|
|
358
|
+
expect(call!.url).toBe(`${API}/v1/checkout/sessions`);
|
|
359
|
+
expect(call!.init.method).toBe("POST");
|
|
360
|
+
expect(JSON.parse(String(call!.init.body))).toEqual({
|
|
361
|
+
productCode: key,
|
|
362
|
+
successUrl: SUCCESS_URL,
|
|
363
|
+
cancelUrl: CANCEL_URL,
|
|
364
|
+
});
|
|
365
|
+
expect(postHeaders(call!).cookie).toBeUndefined();
|
|
366
|
+
for (const spy of consoleSpies) expect(spy).not.toHaveBeenCalled();
|
|
367
|
+
},
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
it("forwards the visitor's x-forwarded-for, never the cookie", async () => {
|
|
371
|
+
await expectStarted(
|
|
372
|
+
await buy(
|
|
373
|
+
"growth_monthly",
|
|
374
|
+
buyRequest("growth_monthly", {
|
|
375
|
+
headers: { "x-forwarded-for": "203.0.113.7" },
|
|
376
|
+
}),
|
|
377
|
+
),
|
|
378
|
+
);
|
|
379
|
+
const headers = postHeaders(postCalls()[0]!);
|
|
380
|
+
expect(headers["x-forwarded-for"]).toBe("203.0.113.7");
|
|
381
|
+
expect(headers.cookie).toBeUndefined();
|
|
382
|
+
expect(headers.origin).toBeUndefined();
|
|
383
|
+
expect(headers.authorization).toBeUndefined();
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("forwards x-real-ip as x-forwarded-for when no x-forwarded-for came in", async () => {
|
|
387
|
+
await expectStarted(
|
|
388
|
+
await buy(
|
|
389
|
+
"growth_monthly",
|
|
390
|
+
buyRequest("growth_monthly", {
|
|
391
|
+
headers: { "x-forwarded-for": null, "x-real-ip": "198.51.100.9" },
|
|
392
|
+
}),
|
|
393
|
+
),
|
|
394
|
+
);
|
|
395
|
+
const headers = postHeaders(postCalls()[0]!);
|
|
396
|
+
expect(headers["x-forwarded-for"]).toBe("198.51.100.9");
|
|
397
|
+
expect(headers.cookie).toBeUndefined();
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("forwards x-real-ip when the incoming x-forwarded-for is empty", async () => {
|
|
401
|
+
await expectStarted(
|
|
402
|
+
await buy(
|
|
403
|
+
"growth_monthly",
|
|
404
|
+
buyRequest("growth_monthly", {
|
|
405
|
+
headers: { "x-forwarded-for": "", "x-real-ip": "198.51.100.10" },
|
|
406
|
+
}),
|
|
407
|
+
),
|
|
408
|
+
);
|
|
409
|
+
expect(postHeaders(postCalls()[0]!)["x-forwarded-for"]).toBe(
|
|
410
|
+
"198.51.100.10",
|
|
411
|
+
);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("sends x-internal-auth from OSS_API_INTERNAL_SECRET to an https API", async () => {
|
|
415
|
+
env.OSS_API_INTERNAL_SECRET = "s3cret";
|
|
416
|
+
await expectStarted(await buy("growth_monthly"));
|
|
417
|
+
expect(postHeaders(postCalls()[0]!)["x-internal-auth"]).toBe("s3cret");
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("sends no x-internal-auth when OSS_API_INTERNAL_SECRET is unset", async () => {
|
|
421
|
+
await expectStarted(await buy("growth_monthly"));
|
|
422
|
+
expect(postHeaders(postCalls()[0]!)["x-internal-auth"]).toBeUndefined();
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("never sends the secret from a spoke; the spoke's own key goes instead", async () => {
|
|
426
|
+
env.OSS_API_INTERNAL_SECRET = "s3cret";
|
|
427
|
+
env.AILK_SPOKE_KEY = "spk_test_1";
|
|
428
|
+
await expectStarted(await buy("growth_monthly"));
|
|
429
|
+
const headers = postHeaders(postCalls()[0]!);
|
|
430
|
+
expect(headers["x-internal-auth"]).toBeUndefined();
|
|
431
|
+
expect(headers["x-ailk-spoke-key"]).toBe("spk_test_1");
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("never sends the secret over clear text to a remote API", async () => {
|
|
435
|
+
env.OSS_API_INTERNAL_SECRET = "s3cret";
|
|
436
|
+
env.AILK_API_URL = "http://api.remote.example";
|
|
437
|
+
await expectStarted(await buy("growth_monthly"));
|
|
438
|
+
const [call] = postCalls();
|
|
439
|
+
expect(call!.url).toBe("http://api.remote.example/v1/checkout/sessions");
|
|
440
|
+
expect(postHeaders(call!)["x-internal-auth"]).toBeUndefined();
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// ─── AC-2 ───────────────────────────────────────────────────────────────────
|
|
445
|
+
|
|
446
|
+
describe("AC-2 — a refused key, an ungrammatical key and an unconnected site return to /pricing", () => {
|
|
447
|
+
it.each([
|
|
448
|
+
[404, { error: "unknown-product-code" }],
|
|
449
|
+
[503, { error: "tenant_unresolved" }],
|
|
450
|
+
])("refuses when the API answers %i", async (status, json) => {
|
|
451
|
+
postAnswer = { status, json };
|
|
452
|
+
await expectRefused(
|
|
453
|
+
await buy("growth_monthly"),
|
|
454
|
+
"growth_monthly",
|
|
455
|
+
`api_${status}`,
|
|
456
|
+
);
|
|
457
|
+
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
458
|
+
expect(postCalls()).toHaveLength(1);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it.each([
|
|
462
|
+
"Growth_monthly",
|
|
463
|
+
"growth",
|
|
464
|
+
"growth_weekly",
|
|
465
|
+
"growth_monthly_x",
|
|
466
|
+
`${"a".repeat(41)}_monthly`,
|
|
467
|
+
])("refuses the ungrammatical key %s with no fetch", async (key) => {
|
|
468
|
+
await expectRefused(await buy(key), key, "ungrammatical");
|
|
469
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("refuses an unconnected site after the read, with no POST", async () => {
|
|
473
|
+
shownAnswer = {
|
|
474
|
+
status: 200,
|
|
475
|
+
json: { ok: true, data: { status: "unconnected" } },
|
|
476
|
+
};
|
|
477
|
+
await expectRefused(
|
|
478
|
+
await buy("growth_monthly"),
|
|
479
|
+
"growth_monthly",
|
|
480
|
+
"unconnected",
|
|
481
|
+
);
|
|
482
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
483
|
+
expect(postCalls()).toHaveLength(0);
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// ─── AC-4 ───────────────────────────────────────────────────────────────────
|
|
488
|
+
|
|
489
|
+
describe("AC-4 — every other outcome returns to /pricing, without throwing and within its bound", () => {
|
|
490
|
+
it.each([400, 401, 429, 500, 502])(
|
|
491
|
+
"refuses when the API answers %i",
|
|
492
|
+
async (status) => {
|
|
493
|
+
postAnswer = { status, json: { error: "x" } };
|
|
494
|
+
await expectRefused(
|
|
495
|
+
await buy("growth_monthly"),
|
|
496
|
+
"growth_monthly",
|
|
497
|
+
`api_${status}`,
|
|
498
|
+
);
|
|
499
|
+
},
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
it.each([
|
|
503
|
+
"http://checkout.stripe.com/c/pay/x",
|
|
504
|
+
"javascript:alert(1)",
|
|
505
|
+
"/purchase/success",
|
|
506
|
+
"",
|
|
507
|
+
"https://user:pw@checkout.stripe.com/c/pay/x",
|
|
508
|
+
"https://checkout.stripe.com/c/pay/x\r\nSet-Cookie: a=b",
|
|
509
|
+
"https://checkout.stripe.com/c/pay/ü",
|
|
510
|
+
"https://checkout.stripe.com",
|
|
511
|
+
])("refuses a 201 whose url is %j", async (url) => {
|
|
512
|
+
postAnswer = { status: 201, json: { sessionId: "cs_test_a1", url } };
|
|
513
|
+
await expectRefused(
|
|
514
|
+
await buy("growth_monthly"),
|
|
515
|
+
"growth_monthly",
|
|
516
|
+
"bad_answer",
|
|
517
|
+
);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it("refuses a 201 with no url", async () => {
|
|
521
|
+
postAnswer = { status: 201, json: { sessionId: "cs_test_a1" } };
|
|
522
|
+
await expectRefused(
|
|
523
|
+
await buy("growth_monthly"),
|
|
524
|
+
"growth_monthly",
|
|
525
|
+
"bad_answer",
|
|
526
|
+
);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it("refuses a 201 whose body is not JSON", async () => {
|
|
530
|
+
postAnswer = { status: 201, text: "<html>ok</html>" };
|
|
531
|
+
await expectRefused(
|
|
532
|
+
await buy("growth_monthly"),
|
|
533
|
+
"growth_monthly",
|
|
534
|
+
"bad_answer",
|
|
535
|
+
);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("refuses when the POST fetch rejects", async () => {
|
|
539
|
+
postAnswer = "reject";
|
|
540
|
+
await expectRefused(
|
|
541
|
+
await buy("growth_monthly"),
|
|
542
|
+
"growth_monthly",
|
|
543
|
+
"unreachable",
|
|
544
|
+
);
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
it("refuses a POST that never settles once 10 seconds pass", async () => {
|
|
548
|
+
postAnswer = "hang";
|
|
549
|
+
const pending = buy("growth_monthly");
|
|
550
|
+
await jest.advanceTimersByTimeAsync(10_000);
|
|
551
|
+
await expectRefused(await pending, "growth_monthly", "unreachable");
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it.each<[string, Answer]>([
|
|
555
|
+
["empty", { status: 200, json: { ok: true, data: { status: "empty" } } }],
|
|
556
|
+
[
|
|
557
|
+
"an expired set",
|
|
558
|
+
{
|
|
559
|
+
status: 200,
|
|
560
|
+
json: {
|
|
561
|
+
ok: true,
|
|
562
|
+
data: {
|
|
563
|
+
status: "shown",
|
|
564
|
+
shownSet: wireShownSet({ state: "expired" }),
|
|
565
|
+
},
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
],
|
|
569
|
+
[
|
|
570
|
+
"a set without the key",
|
|
571
|
+
{
|
|
572
|
+
status: 200,
|
|
573
|
+
json: {
|
|
574
|
+
ok: true,
|
|
575
|
+
data: {
|
|
576
|
+
status: "shown",
|
|
577
|
+
shownSet: wireShownSet({ withGrowth: false }),
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
],
|
|
582
|
+
["a 500", { status: 500, json: { error: "internal" } }],
|
|
583
|
+
["a rejected read", "reject"],
|
|
584
|
+
])(
|
|
585
|
+
"refuses with no POST when the shown read is %s",
|
|
586
|
+
async (_label, answer) => {
|
|
587
|
+
shownAnswer = answer;
|
|
588
|
+
await expectRefused(
|
|
589
|
+
await buy("growth_monthly"),
|
|
590
|
+
"growth_monthly",
|
|
591
|
+
"not_shown",
|
|
592
|
+
);
|
|
593
|
+
expect(postCalls()).toHaveLength(0);
|
|
594
|
+
},
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
it("refuses with no POST once a hung shown read passes 5 seconds", async () => {
|
|
598
|
+
shownAnswer = "hang";
|
|
599
|
+
const pending = buy("growth_monthly");
|
|
600
|
+
await jest.advanceTimersByTimeAsync(5_000);
|
|
601
|
+
await expectRefused(await pending, "growth_monthly", "not_shown");
|
|
602
|
+
expect(postCalls()).toHaveLength(0);
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it.each<[string, () => void]>([
|
|
606
|
+
["no commerce feature", () => licenceResolves({ features: [] })],
|
|
607
|
+
[
|
|
608
|
+
"a revoked licence",
|
|
609
|
+
() => licenceResolves({ features: ["commerce"], revoked: true }),
|
|
610
|
+
],
|
|
611
|
+
[
|
|
612
|
+
"a licence read that throws",
|
|
613
|
+
() => mockCheckLicense.mockRejectedValue(new Error("no licence")),
|
|
614
|
+
],
|
|
615
|
+
])("refuses with no fetch on %s", async (_label, arrange) => {
|
|
616
|
+
arrange();
|
|
617
|
+
await expectRefused(
|
|
618
|
+
await buy("growth_monthly"),
|
|
619
|
+
"growth_monthly",
|
|
620
|
+
"no_claim",
|
|
621
|
+
);
|
|
622
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it("refuses with no fetch in production with no API origin", async () => {
|
|
626
|
+
env.NODE_ENV = "production";
|
|
627
|
+
delete env.AILK_API_URL;
|
|
628
|
+
await expectRefused(
|
|
629
|
+
await buy("growth_monthly"),
|
|
630
|
+
"growth_monthly",
|
|
631
|
+
"unconnected",
|
|
632
|
+
);
|
|
633
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
it.each(["not a url", "https://example.com"])(
|
|
637
|
+
"refuses with no POST when NEXT_PUBLIC_BASE_URL is %j",
|
|
638
|
+
async (base) => {
|
|
639
|
+
env.NEXT_PUBLIC_BASE_URL = base;
|
|
640
|
+
await expectRefused(
|
|
641
|
+
await buy("growth_monthly"),
|
|
642
|
+
"growth_monthly",
|
|
643
|
+
"no_origin",
|
|
644
|
+
);
|
|
645
|
+
expect(postCalls()).toHaveLength(0);
|
|
646
|
+
},
|
|
647
|
+
);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
// ─── AC-5 ───────────────────────────────────────────────────────────────────
|
|
651
|
+
|
|
652
|
+
describe("AC-5 — only a buyer's page load starts anything", () => {
|
|
653
|
+
it.each<
|
|
654
|
+
[string, { method?: string; headers?: Record<string, string | null> }]
|
|
655
|
+
>([
|
|
656
|
+
["HEAD", { method: "HEAD" }],
|
|
657
|
+
[
|
|
658
|
+
"no fetch metadata (a crawler)",
|
|
659
|
+
{ headers: { "sec-fetch-mode": null, "sec-fetch-dest": null } },
|
|
660
|
+
],
|
|
661
|
+
[
|
|
662
|
+
"an <img> load",
|
|
663
|
+
{ headers: { "sec-fetch-mode": "no-cors", "sec-fetch-dest": "image" } },
|
|
664
|
+
],
|
|
665
|
+
[
|
|
666
|
+
"a fetch()",
|
|
667
|
+
{ headers: { "sec-fetch-mode": "cors", "sec-fetch-dest": "empty" } },
|
|
668
|
+
],
|
|
669
|
+
[
|
|
670
|
+
"a document load that is not a navigation",
|
|
671
|
+
{ headers: { "sec-fetch-mode": "cors" } },
|
|
672
|
+
],
|
|
673
|
+
["a cross-site load", { headers: { "sec-fetch-site": "cross-site" } }],
|
|
674
|
+
["sec-purpose: prefetch", { headers: { "sec-purpose": "prefetch" } }],
|
|
675
|
+
["purpose: prefetch", { headers: { purpose: "prefetch" } }],
|
|
676
|
+
["x-moz: prefetch", { headers: { "x-moz": "prefetch" } }],
|
|
677
|
+
["a Next router prefetch", { headers: { "next-router-prefetch": "1" } }],
|
|
678
|
+
["an RSC fetch", { headers: { rsc: "1" } }],
|
|
679
|
+
])("refuses %s with no fetch", async (_label, options) => {
|
|
680
|
+
const key = "growth_monthly";
|
|
681
|
+
await expectRefused(
|
|
682
|
+
await buy(key, buyRequest(key, options)),
|
|
683
|
+
key,
|
|
684
|
+
"unintended",
|
|
685
|
+
);
|
|
686
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it.each(["same-origin", "same-site", "none"])(
|
|
690
|
+
"starts the Checkout for a navigation with sec-fetch-site %s",
|
|
691
|
+
async (site) => {
|
|
692
|
+
const key = "growth_monthly";
|
|
693
|
+
await expectStarted(
|
|
694
|
+
await buy(
|
|
695
|
+
key,
|
|
696
|
+
buyRequest(key, { headers: { "sec-fetch-site": site } }),
|
|
697
|
+
),
|
|
698
|
+
);
|
|
699
|
+
},
|
|
700
|
+
);
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
// ─── AC-6 ───────────────────────────────────────────────────────────────────
|
|
704
|
+
|
|
705
|
+
describe("AC-6 — one shared read, a switched-off product stops within it, a per-visitor budget", () => {
|
|
706
|
+
it("shares one read across concurrent clicks and re-reads after 15 seconds", async () => {
|
|
707
|
+
const [first, second] = await Promise.all([
|
|
708
|
+
buy("growth_monthly"),
|
|
709
|
+
buy("growth_monthly"),
|
|
710
|
+
]);
|
|
711
|
+
await expectStarted(first!);
|
|
712
|
+
await expectStarted(second!);
|
|
713
|
+
expect(shownCalls()).toBe(1);
|
|
714
|
+
expect(postCalls()).toHaveLength(2);
|
|
715
|
+
|
|
716
|
+
shownAnswer = {
|
|
717
|
+
status: 200,
|
|
718
|
+
json: {
|
|
719
|
+
ok: true,
|
|
720
|
+
data: {
|
|
721
|
+
status: "shown",
|
|
722
|
+
shownSet: wireShownSet({ withGrowth: false }),
|
|
723
|
+
},
|
|
724
|
+
},
|
|
725
|
+
};
|
|
726
|
+
jest.setSystemTime(Date.now() + 16_000);
|
|
727
|
+
await expectRefused(
|
|
728
|
+
await buy("growth_monthly"),
|
|
729
|
+
"growth_monthly",
|
|
730
|
+
"not_shown",
|
|
731
|
+
);
|
|
732
|
+
expect(shownCalls()).toBe(2);
|
|
733
|
+
expect(postCalls()).toHaveLength(2);
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
it("starts at most 5 Checkouts per visitor per 10 minutes", async () => {
|
|
737
|
+
const from = (address: string) =>
|
|
738
|
+
buyRequest("growth_monthly", { headers: { "x-forwarded-for": address } });
|
|
739
|
+
|
|
740
|
+
for (let i = 0; i < 5; i += 1) {
|
|
741
|
+
await expectStarted(await buy("growth_monthly", from("192.0.2.50")));
|
|
742
|
+
}
|
|
743
|
+
expect(postCalls()).toHaveLength(5);
|
|
744
|
+
|
|
745
|
+
await expectRefused(
|
|
746
|
+
await buy("growth_monthly", from("192.0.2.50")),
|
|
747
|
+
"growth_monthly",
|
|
748
|
+
"rate_limited",
|
|
749
|
+
);
|
|
750
|
+
expect(postCalls()).toHaveLength(5);
|
|
751
|
+
|
|
752
|
+
await expectStarted(await buy("growth_monthly", from("192.0.2.51")));
|
|
753
|
+
expect(postCalls()).toHaveLength(6);
|
|
754
|
+
|
|
755
|
+
jest.setSystemTime(Date.now() + 10 * 60_000);
|
|
756
|
+
await expectStarted(await buy("growth_monthly", from("192.0.2.50")));
|
|
757
|
+
expect(postCalls()).toHaveLength(7);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it("keys the budget on the first 64 characters of an address", async () => {
|
|
761
|
+
const prefix = "f".repeat(64);
|
|
762
|
+
for (let i = 0; i < 5; i += 1) {
|
|
763
|
+
await expectStarted(
|
|
764
|
+
await buy(
|
|
765
|
+
"growth_monthly",
|
|
766
|
+
buyRequest("growth_monthly", {
|
|
767
|
+
headers: { "x-forwarded-for": `${prefix}${i}` },
|
|
768
|
+
}),
|
|
769
|
+
),
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
await expectRefused(
|
|
773
|
+
await buy(
|
|
774
|
+
"growth_monthly",
|
|
775
|
+
buyRequest("growth_monthly", {
|
|
776
|
+
headers: { "x-forwarded-for": `${prefix}x` },
|
|
777
|
+
}),
|
|
778
|
+
),
|
|
779
|
+
"growth_monthly",
|
|
780
|
+
"rate_limited",
|
|
781
|
+
);
|
|
782
|
+
expect(postCalls()).toHaveLength(5);
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it("does not count a request with no visitor address", async () => {
|
|
786
|
+
for (let i = 0; i < 7; i += 1) {
|
|
787
|
+
await expectStarted(
|
|
788
|
+
await buy(
|
|
789
|
+
"growth_monthly",
|
|
790
|
+
buyRequest("growth_monthly", {
|
|
791
|
+
headers: { "x-forwarded-for": null },
|
|
792
|
+
}),
|
|
793
|
+
),
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
expect(postCalls()).toHaveLength(7);
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
it("reaches neither Stripe nor the session cookie itself", () => {
|
|
800
|
+
for (const banned of [
|
|
801
|
+
"stripe-client",
|
|
802
|
+
"spoke-checkout",
|
|
803
|
+
"STRIPE_",
|
|
804
|
+
"cookies(",
|
|
805
|
+
"lib/checkout",
|
|
806
|
+
]) {
|
|
807
|
+
expect(ROUTE_SOURCE).not.toContain(banned);
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
});
|