create-ailk 0.24.0 → 0.26.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/README.md +53 -22
- package/component-catalog.json +3 -3
- package/component-catalog.md +3 -3
- package/dist/add-module.js +4 -2
- package/dist/add-route.d.ts +12 -1
- package/dist/add-route.js +31 -3
- package/dist/cli.js +12 -7
- package/dist/derive-architecture.d.ts +3 -4
- package/dist/derive-architecture.js +65 -29
- package/dist/lib/design-checks.d.ts +9 -4
- package/dist/lib/design-checks.js +13 -7
- package/dist/lib/extract-module-bundle.js +29 -2
- package/dist/lib/fetch-template-snapshot.d.ts +2 -1
- package/dist/lib/fetch-template-snapshot.js +8 -3
- package/dist/lib/import-graph.d.ts +1 -1
- package/dist/lib/import-graph.js +4 -4
- package/dist/lib/module-license-gate.d.ts +12 -1
- package/dist/lib/module-license-gate.js +36 -15
- package/dist/lib/module-tier.d.ts +2 -8
- package/dist/lib/module-tier.js +13 -12
- package/dist/module-architecture.d.ts +20 -3
- package/dist/module-architecture.js +129 -552
- package/dist/paid-sections.d.ts +25 -1
- package/dist/paid-sections.js +88 -3
- package/dist/starter-grid.d.ts +6 -6
- package/dist/starter-grid.js +12 -5
- package/dist/surfaces.js +39 -2
- package/dist/template-record.d.ts +21 -3
- package/dist/template-record.js +38 -7
- package/dist/topology.d.ts +16 -3
- package/dist/topology.js +54 -23
- package/dist/update.d.ts +10 -1
- package/dist/update.js +715 -21
- package/package.json +3 -3
- package/release-scope.json +2 -2
- package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +8 -2
- package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +2 -2
- package/site-templates/marketing-site/ailk-template.json +7 -1
- package/site-templates/marketing-site/provenance.json +7 -1
- package/site-templates/saas-product/ailk-template.json +2 -1
- package/site-templates/saas-product/provenance.json +1 -0
- package/templates/.claude/cloudparity-repo-hooks.json +5 -0
- package/templates/.claude/hooks/template-guard.sh +137 -0
- package/templates/.claude/rules/extending.md +106 -0
- package/templates/.claude/rules/loop-contract.md +2 -2
- package/templates/.claude/settings.json +11 -0
- package/templates/.env.example +20 -5
- package/templates/.github/workflows/ci.yml +7 -4
- package/templates/CLAUDE.md +11 -1
- package/templates/CONVENTIONS.md +8 -10
- package/templates/README.md +14 -13
- package/templates/apps/api/.env.example +23 -2
- package/templates/apps/api/CLAUDE.md +119 -83
- package/templates/apps/api/jest.config.cjs +15 -5
- package/templates/apps/api/package.json +16 -20
- package/templates/apps/api/src/__tests__/trusted-origins.server.test.ts +2 -2
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +4 -4
- package/templates/apps/api/src/index.ts +1 -1
- package/templates/apps/api/src/lib/__mocks__/prisma-client.js +16 -0
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +3 -3
- package/templates/apps/api/src/modules/commerce.ts +10 -0
- package/templates/apps/api/src/modules/content-write.ts +10 -0
- package/templates/apps/api/src/modules/multi-tenant.ts +10 -0
- package/templates/apps/api/src/modules/scheduling.ts +10 -0
- package/templates/apps/api/src/modules/signal-collectors.ts +10 -0
- package/templates/apps/api/src/modules/workspace.ts +10 -0
- package/templates/apps/api/src/server.ts +117 -1882
- package/templates/apps/api/vercel.json +2 -2
- package/templates/apps/mcp/CLAUDE.md +90 -26
- package/templates/apps/mcp/__tests__/app-entry.test.ts +4 -254
- package/templates/apps/mcp/__tests__/boot-file.test.ts +92 -0
- package/templates/apps/mcp/jest.config.cjs +6 -1
- package/templates/apps/mcp/package.json +5 -13
- package/templates/apps/mcp/src/app.ts +8 -7
- package/templates/apps/mcp/src/index.ts +6 -34
- package/templates/apps/mcp/src/lib/paid-tools.generated.ts +10 -0
- package/templates/apps/mcp/src/lib/topology.generated.ts +2 -2
- package/templates/apps/mcp/src/site.ts +12 -0
- package/templates/apps/web/.env.example +1 -1
- package/templates/apps/web/CLAUDE.md +31 -3
- package/templates/apps/web/app/.well-known/mcp.json/route.ts +9 -3
- package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +43 -4
- package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +35 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +117 -8
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +14 -37
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +6 -6
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +20 -35
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +108 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +111 -5
- package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +78 -16
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +132 -12
- package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +53 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +38 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +4 -2
- package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +47 -24
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +23 -4
- package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +1 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +22 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +7 -3
- package/templates/apps/web/app/[locale]/layout.tsx +33 -13
- package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +128 -0
- package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +126 -0
- package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +43 -0
- package/templates/apps/web/app/[locale]/pricing/page.tsx +7 -3
- package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/__tests__/route.test.ts +222 -0
- package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/route.ts +10 -3
- package/templates/apps/web/app/api/revalidate/route.ts +3 -3
- package/templates/apps/web/auth.ts +10 -6
- package/templates/apps/web/i18n/request.ts +49 -1
- package/templates/apps/web/jest.config.cjs +1 -0
- package/templates/apps/web/lib/__tests__/account-config.test.ts +7 -0
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +276 -0
- package/templates/apps/web/lib/auth-email.ts +103 -21
- package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +72 -23
- package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +94 -70
- package/templates/apps/web/lib/prisma-for-auth.ts +5 -2
- package/templates/apps/web/lib/relay.ts +2 -2
- package/templates/apps/web/lib/release-scope.ts +47 -0
- package/templates/apps/web/lib/server-api.ts +1 -1
- package/templates/apps/web/lib/sign-up-agreements.ts +291 -28
- package/templates/apps/web/lib/site-contributions.ts +18 -0
- package/templates/apps/web/messages/en.json +186 -20
- package/templates/apps/web/messages/site/en.json +1 -0
- package/templates/apps/web/src/lib/commerce-claim.ts +1 -1
- package/templates/customizations.yaml +37 -0
- package/templates/database/prisma.config.ts +10 -14
- package/templates/database/seed-test.ts +2 -2
- package/templates/database/seed.ts +5 -5
- package/templates/package.json +12 -6
- package/templates/pnpm-workspace.yaml +0 -1
- package/templates/project.yaml +16 -8
- package/templates/tools/jest/reporters.cjs +65 -0
- package/templates/tools/lint-architecture.ts +553 -7
- package/templates/tsconfig.json +1 -2
- package/versions.json +49 -36
- package/templates/apps/api/src/__tests__/commerce-claim-registration.test.ts +0 -409
- package/templates/apps/api/src/__tests__/factories/agent-caller.ts +0 -102
- package/templates/apps/api/src/__tests__/factories/content-fixture.ts +0 -138
- package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +0 -441
- package/templates/apps/api/src/__tests__/factories/index.ts +0 -70
- package/templates/apps/api/src/__tests__/factories/lead-fixture.ts +0 -82
- package/templates/apps/api/src/__tests__/leads-forwarded-rate-limit.test.ts +0 -135
- package/templates/apps/api/src/__tests__/services/enrichment-shim.test.ts +0 -126
- package/templates/apps/api/src/__tests__/stripe-boot.test.ts +0 -132
- package/templates/apps/api/src/__tests__/support/hub-sign-in-fake-db.ts +0 -362
- package/templates/apps/api/src/bin/__tests__/rate-limit-probe.test.ts +0 -184
- package/templates/apps/api/src/bin/abandon-sweep.ts +0 -42
- package/templates/apps/api/src/bin/rate-limit-probe.ts +0 -53
- package/templates/apps/api/src/bin/spokes.ts +0 -198
- package/templates/apps/api/src/bin/stripe-connections-rekey.ts +0 -45
- package/templates/apps/api/src/config/__tests__/hub-require-spoke-key.test.ts +0 -196
- package/templates/apps/api/src/config/__tests__/index.test.ts +0 -233
- package/templates/apps/api/src/config/__tests__/modules.test.ts +0 -76
- package/templates/apps/api/src/config/__tests__/stripe-connection-key.test.ts +0 -185
- package/templates/apps/api/src/config/__tests__/trusted-origins.test.ts +0 -238
- package/templates/apps/api/src/config/index.ts +0 -596
- package/templates/apps/api/src/config/modules.ts +0 -83
- package/templates/apps/api/src/lib/__tests__/agent-store.test.ts +0 -581
- package/templates/apps/api/src/lib/__tests__/auth-email-budget.test.ts +0 -143
- package/templates/apps/api/src/lib/__tests__/consent-ledger-double.ts +0 -237
- package/templates/apps/api/src/lib/__tests__/consent-store.test.ts +0 -353
- package/templates/apps/api/src/lib/__tests__/content-adapter.test.ts +0 -201
- package/templates/apps/api/src/lib/__tests__/deliverable-asset-store.test.ts +0 -224
- package/templates/apps/api/src/lib/__tests__/error-serializer.test.ts +0 -120
- package/templates/apps/api/src/lib/__tests__/errors.test.ts +0 -94
- package/templates/apps/api/src/lib/__tests__/file-fallback.test.ts +0 -144
- package/templates/apps/api/src/lib/__tests__/fixtures/HomePage/home.mdx +0 -8
- package/templates/apps/api/src/lib/__tests__/flow-completion-store.test.ts +0 -149
- package/templates/apps/api/src/lib/__tests__/flow-rename-race.db.test.ts +0 -116
- package/templates/apps/api/src/lib/__tests__/hub-sign-in-store.test.ts +0 -209
- package/templates/apps/api/src/lib/__tests__/lead-capture-store.test.ts +0 -257
- package/templates/apps/api/src/lib/__tests__/lead-delivery.test.ts +0 -96
- package/templates/apps/api/src/lib/__tests__/outbound-http.test.ts +0 -125
- package/templates/apps/api/src/lib/__tests__/prisma.test.ts +0 -165
- package/templates/apps/api/src/lib/__tests__/require-commerce-claim.test.ts +0 -317
- package/templates/apps/api/src/lib/__tests__/require-paid-tier.test.ts +0 -129
- package/templates/apps/api/src/lib/__tests__/site.test.ts +0 -308
- package/templates/apps/api/src/lib/__tests__/slice-load.test.ts +0 -89
- package/templates/apps/api/src/lib/__tests__/spoke-store.test.ts +0 -202
- package/templates/apps/api/src/lib/__tests__/stripe-admission.test.ts +0 -217
- package/templates/apps/api/src/lib/__tests__/stripe.test.ts +0 -82
- package/templates/apps/api/src/lib/agent-store.ts +0 -613
- package/templates/apps/api/src/lib/auth-email-budget.ts +0 -161
- package/templates/apps/api/src/lib/consent-store.ts +0 -363
- package/templates/apps/api/src/lib/content-adapter.ts +0 -112
- package/templates/apps/api/src/lib/deliverable-asset-store.ts +0 -96
- package/templates/apps/api/src/lib/error-serializer.ts +0 -164
- package/templates/apps/api/src/lib/errors.ts +0 -95
- package/templates/apps/api/src/lib/file-fallback.ts +0 -87
- package/templates/apps/api/src/lib/flow-completion-store.ts +0 -136
- package/templates/apps/api/src/lib/hub-sign-in-store.ts +0 -455
- package/templates/apps/api/src/lib/lead-capture-store.ts +0 -122
- package/templates/apps/api/src/lib/lead-delivery.ts +0 -52
- package/templates/apps/api/src/lib/license-key-store.ts +0 -45
- package/templates/apps/api/src/lib/locales.ts +0 -201
- package/templates/apps/api/src/lib/outbound-http.ts +0 -127
- package/templates/apps/api/src/lib/prisma.ts +0 -21
- package/templates/apps/api/src/lib/proposal-paid-store.ts +0 -66
- package/templates/apps/api/src/lib/rate-limit-probe.ts +0 -165
- package/templates/apps/api/src/lib/rate-limit-store.ts +0 -142
- package/templates/apps/api/src/lib/require-commerce-claim.ts +0 -250
- package/templates/apps/api/src/lib/require-paid-tier.ts +0 -53
- package/templates/apps/api/src/lib/site.ts +0 -257
- package/templates/apps/api/src/lib/slice-load.ts +0 -90
- package/templates/apps/api/src/lib/spoke-store.ts +0 -180
- package/templates/apps/api/src/lib/stripe.ts +0 -321
- package/templates/apps/api/src/lib/webhook-idempotency.ts +0 -156
- package/templates/apps/api/src/middleware/__tests__/adversarial/bearer-token-format.test.ts +0 -111
- package/templates/apps/api/src/middleware/__tests__/adversarial/cookie-or-bearer-precedence.test.ts +0 -172
- package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-bearer-skip.test.ts +0 -119
- package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-cookie-path.test.ts +0 -138
- package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-trusted-origins.test.ts +0 -142
- package/templates/apps/api/src/middleware/__tests__/adversarial/session-fixation.test.ts +0 -155
- package/templates/apps/api/src/middleware/__tests__/adversarial/session-timeout.test.ts +0 -139
- package/templates/apps/api/src/middleware/__tests__/auth.bearer-path.test.ts +0 -562
- package/templates/apps/api/src/middleware/__tests__/auth.both-present-precedence.test.ts +0 -76
- package/templates/apps/api/src/middleware/__tests__/auth.cookie-path.test.ts +0 -220
- package/templates/apps/api/src/middleware/__tests__/auth.database-not-configured.test.ts +0 -97
- package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +0 -557
- package/templates/apps/api/src/middleware/__tests__/auth.neither-present.test.ts +0 -72
- package/templates/apps/api/src/middleware/__tests__/auth.optional-cookie.test.ts +0 -140
- package/templates/apps/api/src/middleware/__tests__/default-tenant.test.ts +0 -721
- package/templates/apps/api/src/middleware/__tests__/rate-limit-cross-isolate.db.test.ts +0 -220
- package/templates/apps/api/src/middleware/__tests__/rate-limit-store.test.ts +0 -430
- package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +0 -1409
- package/templates/apps/api/src/middleware/__tests__/write-budget.test.ts +0 -174
- package/templates/apps/api/src/middleware/auth.ts +0 -864
- package/templates/apps/api/src/middleware/default-tenant.ts +0 -166
- package/templates/apps/api/src/middleware/rate-limit.ts +0 -983
- package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +0 -391
- package/templates/apps/api/src/openapi/__tests__/spec-identity.test.ts +0 -182
- package/templates/apps/api/src/openapi/index.ts +0 -18
- package/templates/apps/api/src/openapi/spec.ts +0 -2148
- package/templates/apps/api/src/openapi/surface-drift.ts +0 -195
- package/templates/apps/api/src/routes/aeo/__tests__/index.test.ts +0 -175
- package/templates/apps/api/src/routes/aeo/index.ts +0 -107
- package/templates/apps/api/src/routes/auth/__tests__/auth-tokens.functional.test.ts +0 -196
- package/templates/apps/api/src/routes/auth/__tests__/auth-user.functional.test.ts +0 -249
- package/templates/apps/api/src/routes/auth/__tests__/hub-sign-in.test.ts +0 -532
- package/templates/apps/api/src/routes/auth/__tests__/tokens.test.ts +0 -313
- package/templates/apps/api/src/routes/auth/__tests__/transactional-email.test.ts +0 -413
- package/templates/apps/api/src/routes/auth/__tests__/user.test.ts +0 -609
- package/templates/apps/api/src/routes/auth/hub-sign-in.ts +0 -242
- package/templates/apps/api/src/routes/auth/tokens.ts +0 -211
- package/templates/apps/api/src/routes/auth/transactional-email.ts +0 -301
- package/templates/apps/api/src/routes/auth/user.ts +0 -305
- package/templates/apps/api/src/routes/billing/plan-checkout.ts +0 -332
- package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +0 -178
- package/templates/apps/api/src/routes/checkout/__tests__/offerings-authorization.test.ts +0 -1426
- package/templates/apps/api/src/routes/checkout/__tests__/session.test.ts +0 -448
- package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +0 -1742
- package/templates/apps/api/src/routes/checkout/index.ts +0 -34
- package/templates/apps/api/src/routes/checkout/session.ts +0 -171
- package/templates/apps/api/src/routes/checkout/sessions.ts +0 -540
- package/templates/apps/api/src/routes/consent/__tests__/account.test.ts +0 -386
- package/templates/apps/api/src/routes/consent/__tests__/sign-up-rate-limit.test.ts +0 -160
- package/templates/apps/api/src/routes/consent/account.ts +0 -268
- package/templates/apps/api/src/routes/consent/cookie.ts +0 -90
- package/templates/apps/api/src/routes/consent/index.ts +0 -26
- package/templates/apps/api/src/routes/consent/unsubscribe.ts +0 -127
- package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +0 -853
- package/templates/apps/api/src/routes/content/__tests__/list-pages.test.ts +0 -230
- package/templates/apps/api/src/routes/content/__tests__/list-types.test.ts +0 -44
- package/templates/apps/api/src/routes/content/__tests__/locale.test.ts +0 -118
- package/templates/apps/api/src/routes/content/__tests__/offerings.test.ts +0 -731
- package/templates/apps/api/src/routes/content/__tests__/pricing.test.ts +0 -753
- package/templates/apps/api/src/routes/content/__tests__/rate-limit.test.ts +0 -51
- package/templates/apps/api/src/routes/content/__tests__/search.test.ts +0 -450
- package/templates/apps/api/src/routes/content/__tests__/shown-offerings.test.ts +0 -762
- package/templates/apps/api/src/routes/content/get-page.ts +0 -183
- package/templates/apps/api/src/routes/content/index.ts +0 -49
- package/templates/apps/api/src/routes/content/list-pages.ts +0 -74
- package/templates/apps/api/src/routes/content/list-types.ts +0 -19
- package/templates/apps/api/src/routes/content/offerings.ts +0 -184
- package/templates/apps/api/src/routes/content/pricing.ts +0 -176
- package/templates/apps/api/src/routes/content/rate-limit.ts +0 -22
- package/templates/apps/api/src/routes/content/search.ts +0 -100
- package/templates/apps/api/src/routes/content/shown-offerings.ts +0 -229
- package/templates/apps/api/src/routes/leads/__tests__/capture.test.ts +0 -88
- package/templates/apps/api/src/routes/leads/__tests__/list.test.ts +0 -171
- package/templates/apps/api/src/routes/leads/__tests__/magnet-completion.test.ts +0 -515
- package/templates/apps/api/src/routes/leads/__tests__/spoke.test.ts +0 -392
- package/templates/apps/api/src/routes/leads/__tests__/track.test.ts +0 -165
- package/templates/apps/api/src/routes/leads/index.ts +0 -639
- package/templates/apps/api/src/routes/leads/list.ts +0 -104
- package/templates/apps/api/src/routes/project-listings/__tests__/configured-application.test.ts +0 -626
- package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +0 -1268
- package/templates/apps/api/src/routes/project-listings/__tests__/founder-identity.test.ts +0 -847
- package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +0 -491
- package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +0 -476
- package/templates/apps/api/src/routes/project-listings/__tests__/resume-email.test.ts +0 -872
- package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +0 -1022
- package/templates/apps/api/src/routes/project-listings/__tests__/site-key.test.ts +0 -484
- package/templates/apps/api/src/routes/project-listings/__tests__/structured-address.test.ts +0 -535
- package/templates/apps/api/src/routes/project-listings/index.ts +0 -164
- package/templates/apps/api/src/routes/project-listings/me.ts +0 -87
- package/templates/apps/api/src/routes/project-listings/patch-copy.ts +0 -224
- package/templates/apps/api/src/routes/project-listings/patch-draft.ts +0 -102
- package/templates/apps/api/src/routes/project-listings/public.ts +0 -98
- package/templates/apps/api/src/routes/project-listings/respond.ts +0 -48
- package/templates/apps/api/src/routes/project-listings/resume-token.ts +0 -27
- package/templates/apps/api/src/routes/project-listings/start.ts +0 -140
- package/templates/apps/api/src/routes/project-listings/submit.ts +0 -130
- package/templates/apps/api/src/routes/project-listings/verify-email.ts +0 -150
- package/templates/apps/api/src/routes/requests/__tests__/confirm.test.ts +0 -686
- package/templates/apps/api/src/routes/requests/confirm.ts +0 -601
- package/templates/apps/api/src/routes/requests/index.ts +0 -54
- package/templates/apps/api/src/routes/test/auth/__tests__/session.test.ts +0 -306
- package/templates/apps/api/src/routes/test/auth/session.ts +0 -143
- package/templates/apps/api/src/routes/webhooks/README.md +0 -398
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-checkout-consent.test.ts +0 -649
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-dunning.test.ts +0 -749
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +0 -449
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +0 -264
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode-live.test.ts +0 -159
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode.test.ts +0 -158
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-offerings.test.ts +0 -814
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +0 -301
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-proposal-paid.test.ts +0 -369
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +0 -215
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-request-paid.test.ts +0 -301
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +0 -809
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +0 -1155
- package/templates/apps/api/src/routes/webhooks/index.ts +0 -141
- package/templates/apps/api/src/routes/webhooks/stripe-offerings.ts +0 -384
- package/templates/apps/api/src/routes/webhooks/stripe.ts +0 -2028
- package/templates/apps/api/src/services/__tests__/abandon-email.test.ts +0 -645
- package/templates/apps/api/src/services/__tests__/answer-distributions.test.ts +0 -132
- package/templates/apps/api/src/services/__tests__/audit-log.test.ts +0 -1028
- package/templates/apps/api/src/services/__tests__/checkout-plan.test.ts +0 -313
- package/templates/apps/api/src/services/__tests__/consent-ledger.test.ts +0 -503
- package/templates/apps/api/src/services/__tests__/consent-migration.test.ts +0 -65
- package/templates/apps/api/src/services/__tests__/consent.test.ts +0 -299
- package/templates/apps/api/src/services/__tests__/default-tenant.test.ts +0 -147
- package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +0 -877
- package/templates/apps/api/src/services/__tests__/deliverable-resend.test.ts +0 -379
- package/templates/apps/api/src/services/__tests__/dunning-policy.test.ts +0 -368
- package/templates/apps/api/src/services/__tests__/entitlements.test.ts +0 -142
- package/templates/apps/api/src/services/__tests__/hub-sign-in.test.ts +0 -854
- package/templates/apps/api/src/services/__tests__/keyless-workspace-predicate.test.ts +0 -234
- package/templates/apps/api/src/services/__tests__/lead-accept-user.test.ts +0 -251
- package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +0 -2660
- package/templates/apps/api/src/services/__tests__/listing-config.test.ts +0 -166
- package/templates/apps/api/src/services/__tests__/magnet-completion.test.ts +0 -389
- package/templates/apps/api/src/services/__tests__/person.test.ts +0 -1204
- package/templates/apps/api/src/services/__tests__/plan-offerings.test.ts +0 -450
- package/templates/apps/api/src/services/__tests__/project-listings.counts.test.ts +0 -202
- package/templates/apps/api/src/services/__tests__/project-listings.fence.test.ts +0 -151
- package/templates/apps/api/src/services/__tests__/public-site-resolver.test.ts +0 -137
- package/templates/apps/api/src/services/__tests__/request-confirm.test.ts +0 -531
- package/templates/apps/api/src/services/__tests__/revalidation.test.ts +0 -372
- package/templates/apps/api/src/services/__tests__/slack-notify.test.ts +0 -348
- package/templates/apps/api/src/services/__tests__/spoke-resolution.test.ts +0 -660
- package/templates/apps/api/src/services/__tests__/usage-aggregation.test.ts +0 -941
- package/templates/apps/api/src/services/__tests__/usage-credits.test.ts +0 -588
- package/templates/apps/api/src/services/__tests__/verified-email.test.ts +0 -78
- package/templates/apps/api/src/services/abandon-email.ts +0 -336
- package/templates/apps/api/src/services/aeo-score.ts +0 -325
- package/templates/apps/api/src/services/answer-distributions.ts +0 -138
- package/templates/apps/api/src/services/audit-log.ts +0 -961
- package/templates/apps/api/src/services/checkout-buyer.ts +0 -168
- package/templates/apps/api/src/services/consent.ts +0 -834
- package/templates/apps/api/src/services/default-tenant.ts +0 -416
- package/templates/apps/api/src/services/deliverable-fulfillment.ts +0 -750
- package/templates/apps/api/src/services/dunning-policy.ts +0 -294
- package/templates/apps/api/src/services/enrichment-shim.ts +0 -53
- package/templates/apps/api/src/services/entitlements.ts +0 -338
- package/templates/apps/api/src/services/hub-sign-in.ts +0 -472
- package/templates/apps/api/src/services/lead-accept-user.ts +0 -126
- package/templates/apps/api/src/services/lead-promotion.ts +0 -160
- package/templates/apps/api/src/services/lead-routing.ts +0 -1372
- package/templates/apps/api/src/services/leads-inbox.ts +0 -312
- package/templates/apps/api/src/services/listing-config.ts +0 -178
- package/templates/apps/api/src/services/magnet-completion.ts +0 -242
- package/templates/apps/api/src/services/offerings/__tests__/catalog.test.ts +0 -348
- package/templates/apps/api/src/services/offerings/__tests__/checkout-session-record.test.ts +0 -268
- package/templates/apps/api/src/services/offerings/__tests__/connection.test.ts +0 -975
- package/templates/apps/api/src/services/offerings/__tests__/fixtures.ts +0 -416
- package/templates/apps/api/src/services/offerings/__tests__/org-products.test.ts +0 -400
- package/templates/apps/api/src/services/offerings/__tests__/readers.test.ts +0 -685
- package/templates/apps/api/src/services/offerings/__tests__/source.test.ts +0 -231
- package/templates/apps/api/src/services/offerings/catalog.ts +0 -318
- package/templates/apps/api/src/services/offerings/checkout-authorization.ts +0 -403
- package/templates/apps/api/src/services/offerings/checkout-session-record.ts +0 -192
- package/templates/apps/api/src/services/offerings/connection.ts +0 -1083
- package/templates/apps/api/src/services/offerings/index.ts +0 -614
- package/templates/apps/api/src/services/offerings/source.ts +0 -140
- package/templates/apps/api/src/services/offerings/store.ts +0 -150
- package/templates/apps/api/src/services/owner-workspaces.ts +0 -132
- package/templates/apps/api/src/services/person.ts +0 -1211
- package/templates/apps/api/src/services/plan-offerings.ts +0 -125
- package/templates/apps/api/src/services/project-listing-resume-email.ts +0 -326
- package/templates/apps/api/src/services/project-listings.ts +0 -2085
- package/templates/apps/api/src/services/public-site-resolver.ts +0 -396
- package/templates/apps/api/src/services/request-confirm.ts +0 -698
- package/templates/apps/api/src/services/revalidation.ts +0 -235
- package/templates/apps/api/src/services/slack-notify.ts +0 -291
- package/templates/apps/api/src/services/usage-aggregation.ts +0 -516
- package/templates/apps/api/src/services/usage-credits.ts +0 -340
- package/templates/apps/api/src/services/verified-email.ts +0 -71
- package/templates/apps/mcp/__tests__/abuse/daily-cap.test.ts +0 -52
- package/templates/apps/mcp/__tests__/abuse/email-validator.test.ts +0 -46
- package/templates/apps/mcp/__tests__/abuse/guard.test.ts +0 -198
- package/templates/apps/mcp/__tests__/abuse/honeypot.test.ts +0 -36
- package/templates/apps/mcp/__tests__/abuse/user-agent-deny.test.ts +0 -54
- package/templates/apps/mcp/__tests__/aeo-cli-parity.test.ts +0 -116
- package/templates/apps/mcp/__tests__/audit-single-page.test.ts +0 -299
- package/templates/apps/mcp/__tests__/boot.test.ts +0 -280
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +0 -359
- package/templates/apps/mcp/__tests__/config/modules.test.ts +0 -78
- package/templates/apps/mcp/__tests__/get_business_hours.test.ts +0 -82
- package/templates/apps/mcp/__tests__/get_faq.test.ts +0 -80
- package/templates/apps/mcp/__tests__/get_locations.test.ts +0 -65
- package/templates/apps/mcp/__tests__/get_offerings.test.ts +0 -557
- package/templates/apps/mcp/__tests__/get_pricing.test.ts +0 -524
- package/templates/apps/mcp/__tests__/get_site_info.test.ts +0 -81
- package/templates/apps/mcp/__tests__/http-transport.test.ts +0 -1232
- package/templates/apps/mcp/__tests__/index.test.ts +0 -195
- package/templates/apps/mcp/__tests__/lib/audit-single-page-readiness-scan.test.ts +0 -191
- package/templates/apps/mcp/__tests__/lib/commerce-claim.test.ts +0 -531
- package/templates/apps/mcp/__tests__/lib/content-adapter-parity.test.ts +0 -70
- package/templates/apps/mcp/__tests__/lib/content-adapter.test.ts +0 -162
- package/templates/apps/mcp/__tests__/lib/content-root.test.ts +0 -93
- package/templates/apps/mcp/__tests__/lib/errors.test.ts +0 -75
- package/templates/apps/mcp/__tests__/lib/fail-closed-tools.test.ts +0 -180
- package/templates/apps/mcp/__tests__/lib/public-workspace.test.ts +0 -124
- package/templates/apps/mcp/__tests__/list_pages.test.ts +0 -268
- package/templates/apps/mcp/__tests__/locale.test.ts +0 -120
- package/templates/apps/mcp/__tests__/module-exclusion.test.ts +0 -175
- package/templates/apps/mcp/__tests__/purchase-disabled.test.ts +0 -101
- package/templates/apps/mcp/__tests__/rate-limit-write.test.ts +0 -189
- package/templates/apps/mcp/__tests__/read_content.test.ts +0 -511
- package/templates/apps/mcp/__tests__/request_callback.test.ts +0 -160
- package/templates/apps/mcp/__tests__/search_content.test.ts +0 -271
- package/templates/apps/mcp/__tests__/server.test.ts +0 -388
- package/templates/apps/mcp/__tests__/start_purchase.test.ts +0 -448
- package/templates/apps/mcp/__tests__/submit_lead.test.ts +0 -222
- package/templates/apps/mcp/__tests__/subscribe_newsletter.test.ts +0 -152
- package/templates/apps/mcp/__tests__/tools/create_project.test.ts +0 -243
- package/templates/apps/mcp/__tests__/tools/purchase.test.ts +0 -451
- package/templates/apps/mcp/src/abuse/daily-cap.ts +0 -47
- package/templates/apps/mcp/src/abuse/email-validator.ts +0 -25
- package/templates/apps/mcp/src/abuse/honeypot.ts +0 -21
- package/templates/apps/mcp/src/abuse/index.ts +0 -349
- package/templates/apps/mcp/src/abuse/user-agent-deny.ts +0 -58
- package/templates/apps/mcp/src/boot.ts +0 -167
- package/templates/apps/mcp/src/config/modules.ts +0 -43
- package/templates/apps/mcp/src/http-transport.ts +0 -564
- package/templates/apps/mcp/src/lib/audit-single-page.ts +0 -308
- package/templates/apps/mcp/src/lib/commerce-claim.ts +0 -263
- package/templates/apps/mcp/src/lib/content-adapter.ts +0 -116
- package/templates/apps/mcp/src/lib/empty-content-adapter.ts +0 -140
- package/templates/apps/mcp/src/lib/errors.ts +0 -61
- package/templates/apps/mcp/src/lib/license-key-store.ts +0 -45
- package/templates/apps/mcp/src/lib/locales.ts +0 -171
- package/templates/apps/mcp/src/lib/prisma.ts +0 -39
- package/templates/apps/mcp/src/lib/public-workspace.ts +0 -133
- package/templates/apps/mcp/src/lib/resolve-locale.ts +0 -30
- package/templates/apps/mcp/src/lib/shown-offerings.ts +0 -105
- package/templates/apps/mcp/src/lib/site-config.ts +0 -53
- package/templates/apps/mcp/src/lib/stripe-tax-signal.ts +0 -59
- package/templates/apps/mcp/src/request-context.ts +0 -52
- package/templates/apps/mcp/src/server.ts +0 -343
- package/templates/apps/mcp/src/serverless-app.ts +0 -88
- package/templates/apps/mcp/src/tools/audit.ts +0 -127
- package/templates/apps/mcp/src/tools/capture_lead.ts +0 -66
- package/templates/apps/mcp/src/tools/create_project.ts +0 -134
- package/templates/apps/mcp/src/tools/get_business_hours.ts +0 -68
- package/templates/apps/mcp/src/tools/get_faq.ts +0 -71
- package/templates/apps/mcp/src/tools/get_locations.ts +0 -88
- package/templates/apps/mcp/src/tools/get_offerings.ts +0 -96
- package/templates/apps/mcp/src/tools/get_pricing.ts +0 -94
- package/templates/apps/mcp/src/tools/get_site_info.ts +0 -86
- package/templates/apps/mcp/src/tools/index.ts +0 -138
- package/templates/apps/mcp/src/tools/list_pages.ts +0 -68
- package/templates/apps/mcp/src/tools/person_notes.ts +0 -25
- package/templates/apps/mcp/src/tools/proposals.ts +0 -27
- package/templates/apps/mcp/src/tools/purchase.ts +0 -205
- package/templates/apps/mcp/src/tools/read_content.ts +0 -81
- package/templates/apps/mcp/src/tools/request_callback.ts +0 -52
- package/templates/apps/mcp/src/tools/search_content.ts +0 -63
- package/templates/apps/mcp/src/tools/subscribe_newsletter.ts +0 -54
- package/templates/apps/mcp/src/workspace-server.ts +0 -224
- package/templates/database/CHANGELOG.md +0 -981
- package/templates/database/LICENSE +0 -202
- package/templates/database/NOTICE +0 -2
- package/templates/database/README.md +0 -243
- package/templates/database/__tests__/agents.db.test.ts +0 -320
- package/templates/database/__tests__/appointment.db.test.ts +0 -106
- package/templates/database/__tests__/artifact-content-store.db.test.ts +0 -316
- package/templates/database/__tests__/composite-fence.db.test.ts +0 -206
- package/templates/database/__tests__/consent-ledger.db.test.ts +0 -345
- package/templates/database/__tests__/consent-source-checkout-migration.test.ts +0 -79
- package/templates/database/__tests__/fence-fan-out.db.test.ts +0 -715
- package/templates/database/__tests__/fixtures/appointment-create-probe.ts +0 -79
- package/templates/database/__tests__/fixtures/person-backfill.json +0 -264
- package/templates/database/__tests__/fixtures/person-contact-backfill.json +0 -182
- package/templates/database/__tests__/fixtures/project-listing-consent-probe.ts +0 -100
- package/templates/database/__tests__/flow-completion-migration.test.ts +0 -115
- package/templates/database/__tests__/flow-completion.db.test.ts +0 -136
- package/templates/database/__tests__/flow-workspace-key.db.test.ts +0 -263
- package/templates/database/__tests__/flows-listing-diagnostic.test.ts +0 -392
- package/templates/database/__tests__/flows-presets.test.ts +0 -173
- package/templates/database/__tests__/in-page-magnets-migration.test.ts +0 -161
- package/templates/database/__tests__/lead-idempotency-key.db.test.ts +0 -92
- package/templates/database/__tests__/member-area.db.test.ts +0 -257
- package/templates/database/__tests__/member-contract-migration.test.ts +0 -85
- package/templates/database/__tests__/member-contract.db.test.ts +0 -413
- package/templates/database/__tests__/offerings-checkout-session.db.test.ts +0 -270
- package/templates/database/__tests__/offerings-migration.test.ts +0 -197
- package/templates/database/__tests__/offerings-shown-price-ids-migration.test.ts +0 -86
- package/templates/database/__tests__/offerings.db.test.ts +0 -303
- package/templates/database/__tests__/outbound-message-action.db.test.ts +0 -80
- package/templates/database/__tests__/person-contact.db.test.ts +0 -563
- package/templates/database/__tests__/person-notes.db.test.ts +0 -249
- package/templates/database/__tests__/person.db.test.ts +0 -586
- package/templates/database/__tests__/piece-kind-migration.test.ts +0 -67
- package/templates/database/__tests__/piece-kind.db.test.ts +0 -208
- package/templates/database/__tests__/prefixed-ids.db.test.ts +0 -222
- package/templates/database/__tests__/project-listing-consent-at.db.test.ts +0 -111
- package/templates/database/__tests__/seed.test.ts +0 -272
- package/templates/database/__tests__/spoke-registry.db.test.ts +0 -191
- package/templates/database/__tests__/tenancy.test.ts +0 -141
- package/templates/database/__tests__/trial-magnet-migration.test.ts +0 -186
- package/templates/database/__tests__/user-cascade.test.ts +0 -140
- package/templates/database/_gitignore +0 -8
- package/templates/database/auth/.gitkeep +0 -0
- package/templates/database/auth/schema.prisma +0 -641
- package/templates/database/config/.gitkeep +0 -0
- package/templates/database/config/schema.prisma +0 -441
- package/templates/database/content/.gitkeep +0 -0
- package/templates/database/content/schema.prisma +0 -339
- package/templates/database/eslint.config.mjs +0 -69
- package/templates/database/flows/listing-diagnostic.ts +0 -182
- package/templates/database/flows/presets.ts +0 -315
- package/templates/database/inbox/.gitkeep +0 -0
- package/templates/database/inbox/README.md +0 -3
- package/templates/database/inbox/__tests__/schema.test.ts +0 -44
- package/templates/database/inbox/schema.prisma +0 -1447
- package/templates/database/jest.config.cjs +0 -36
- package/templates/database/migrations/20260508000000_add_inbox_namespace/migration.sql +0 -328
- package/templates/database/migrations/20260513000000_better_auth_migration/migration.sql +0 -100
- package/templates/database/migrations/20260515000000_add_user_billing_fields/migration.sql +0 -28
- package/templates/database/migrations/20260516000000_add_user_tier_care_plan_seat/migration.sql +0 -25
- package/templates/database/migrations/20260518000000_add_telemetry_records/migration.sql +0 -42
- package/templates/database/migrations/20260525000000_theme_wiring/migration.sql +0 -67
- package/templates/database/migrations/20260710000000_retire_commercial_tier/migration.sql +0 -21
- package/templates/database/migrations/20260712215647_add_multi_tenant_tenancy/migration.sql +0 -201
- package/templates/database/migrations/20260713143320_reanchor_site_config_to_workspace/migration.sql +0 -67
- package/templates/database/migrations/20260713174000_add_audit_logs/migration.sql +0 -46
- package/templates/database/migrations/20260713190000_drop_telemetry_records/migration.sql +0 -25
- package/templates/database/migrations/20260713192000_add_uuidv7_function/migration.sql +0 -49
- package/templates/database/migrations/20260713192429_prefixed_uuid_entity_ids/migration.sql +0 -197
- package/templates/database/migrations/20260713200000_add_org_billing/migration.sql +0 -32
- package/templates/database/migrations/20260714000000_add_lead_promotion_fields/migration.sql +0 -22
- package/templates/database/migrations/20260714010000_add_usage_billing_content_models/migration.sql +0 -151
- package/templates/database/migrations/20260714020000_add_usage_billing_auth_config_models/migration.sql +0 -223
- package/templates/database/migrations/20260714030000_credit_balance_non_negative/migration.sql +0 -22
- package/templates/database/migrations/20260714030000_widen_usage_billing_report_aggregates/migration.sql +0 -32
- package/templates/database/migrations/20260810233516_add_flow_engine_models/migration.sql +0 -40
- package/templates/database/migrations/20260811020000_add_flow_session_abandon_email_columns/migration.sql +0 -4
- package/templates/database/migrations/20260811030000_add_flow_session_abandon_email_index/migration.sql +0 -2
- package/templates/database/migrations/20260811040000_add_flow_session_segment/migration.sql +0 -2
- package/templates/database/migrations/20260811050000_add_deliverable_models/migration.sql +0 -29
- package/templates/database/migrations/20260812000000_add_deliverable_grant_send_columns/migration.sql +0 -6
- package/templates/database/migrations/20260902222948_add_waitlist_experiment_models/migration.sql +0 -39
- package/templates/database/migrations/20260902224500_add_waitlist_id_format_checks/migration.sql +0 -24
- package/templates/database/migrations/20260903004112_add_flow_session_flags_aeo_score/migration.sql +0 -3
- package/templates/database/migrations/20260903010000_add_playbook_instance/migration.sql +0 -33
- package/templates/database/migrations/20260904000000_add_waitlist_followup_send/migration.sql +0 -30
- package/templates/database/migrations/20260905230000_add_flow_checkout/migration.sql +0 -47
- package/templates/database/migrations/20260906000000_add_flow_checkout_idempotency/migration.sql +0 -16
- package/templates/database/migrations/20260907120000_add_project_listing/migration.sql +0 -47
- package/templates/database/migrations/20260907130000_add_project_listing_slack_columns/migration.sql +0 -10
- package/templates/database/migrations/20260907180000_add_listing_csv_send/migration.sql +0 -26
- package/templates/database/migrations/20260909120000_project_listings_platform/migration.sql +0 -90
- package/templates/database/migrations/20260909180000_listing_draft_and_fields/migration.sql +0 -174
- package/templates/database/migrations/20260910120000_listing_public_site_key/migration.sql +0 -14
- package/templates/database/migrations/20260911120000_listing_copy_edit_audit/migration.sql +0 -25
- package/templates/database/migrations/20260911140000_listing_structured_address/migration.sql +0 -32
- package/templates/database/migrations/20260911180000_consent_grants/migration.sql +0 -71
- package/templates/database/migrations/20260911200000_listing_site_answers/migration.sql +0 -30
- package/templates/database/migrations/20260912120000_listing_owner_link/migration.sql +0 -49
- package/templates/database/migrations/20260914120000_listing_founder_identity/migration.sql +0 -123
- package/templates/database/migrations/20260915120000_project_listing_solution/migration.sql +0 -15
- package/templates/database/migrations/20260916120000_artifact_content_store/migration.sql +0 -158
- package/templates/database/migrations/20260917120000_callback_request_confirm/migration.sql +0 -40
- package/templates/database/migrations/20260918120000_add_appointment/migration.sql +0 -67
- package/templates/database/migrations/20260918120000_asset_metadata_columns/migration.sql +0 -70
- package/templates/database/migrations/20260919120000_flow_workspace_key/migration.sql +0 -181
- package/templates/database/migrations/20260919130000_flow_definition_admin_columns/migration.sql +0 -172
- package/templates/database/migrations/20260919130000_workspace_meetings/migration.sql +0 -41
- package/templates/database/migrations/20260919140000_inbox_workspace_key/migration.sql +0 -185
- package/templates/database/migrations/20260920120000_lead_handled_at/migration.sql +0 -70
- package/templates/database/migrations/20260920130000_lead_workspace_source_index/migration.sql +0 -57
- package/templates/database/migrations/20260921120000_deliverable_grant_workspace_key/migration.sql +0 -68
- package/templates/database/migrations/20260922120000_tenancy_fence/migration.sql +0 -1067
- package/templates/database/migrations/20260923120000_listing_capturing_magnet/migration.sql +0 -210
- package/templates/database/migrations/20261003120000_spoke_registry/migration.sql +0 -80
- package/templates/database/migrations/20261003130000_scheduling_connection/migration.sql +0 -49
- package/templates/database/migrations/20261005120000_agents/migration.sql +0 -84
- package/templates/database/migrations/20261008120000_user_last_workspace/migration.sql +0 -35
- package/templates/database/migrations/20261008130000_lead_idempotency_key/migration.sql +0 -20
- package/templates/database/migrations/20261009120000_agent_grants/migration.sql +0 -33
- package/templates/database/migrations/20261010120000_person/migration.sql +0 -106
- package/templates/database/migrations/20261010121000_person_backfill/migration.sql +0 -132
- package/templates/database/migrations/20261010130000_agent_grants_people_read/migration.sql +0 -20
- package/templates/database/migrations/20261011120000_member_area/migration.sql +0 -158
- package/templates/database/migrations/20261011130000_agent_grants_member_pieces_manage/migration.sql +0 -21
- package/templates/database/migrations/20261012120000_member_contract/migration.sql +0 -192
- package/templates/database/migrations/20261013120000_lead_spoke_checkout/migration.sql +0 -20
- package/templates/database/migrations/20261014120000_consent_ledger/migration.sql +0 -122
- package/templates/database/migrations/20261014120000_person_contact/migration.sql +0 -231
- package/templates/database/migrations/20261015120000_person_notes/migration.sql +0 -77
- package/templates/database/migrations/20261015120000_rate_limit_counters/migration.sql +0 -43
- package/templates/database/migrations/20261016120000_piece_kind/migration.sql +0 -95
- package/templates/database/migrations/20261017120000_outbound_message_action/migration.sql +0 -30
- package/templates/database/migrations/20261018120000_flow_completion/migration.sql +0 -52
- package/templates/database/migrations/20261019120000_consent_source_checkout/migration.sql +0 -27
- package/templates/database/migrations/20261020120000_offerings_data_model/migration.sql +0 -146
- package/templates/database/migrations/20261021120000_offerings_checkout_session/migration.sql +0 -77
- package/templates/database/migrations/20261022120000_in_page_magnets/migration.sql +0 -45
- package/templates/database/migrations/20261023120000_offerings_shown_price_ids/migration.sql +0 -47
- package/templates/database/migrations/20261024120000_organization_plan_checkout_session/migration.sql +0 -16
- package/templates/database/migrations/20261025120000_trial_magnet/migration.sql +0 -28
- package/templates/database/migrations/20261026120000_trial_magnet_proof_line/migration.sql +0 -23
- package/templates/database/migrations/migration_lock.toml +0 -3
- package/templates/database/ops/.gitkeep +0 -0
- package/templates/database/ops/schema.prisma +0 -43
- package/templates/database/package.json +0 -89
- package/templates/database/schema.prisma +0 -71
- package/templates/database/scripts/db-generate-locked.sh +0 -80
- package/templates/database/scripts/person-backfill.sql +0 -132
- package/templates/database/tenancy.ts +0 -183
- package/templates/database/tsconfig.build.json +0 -16
- package/templates/database/tsconfig.flows.json +0 -15
- package/templates/database/tsconfig.json +0 -16
- package/templates/database/tsconfig.tenancy.json +0 -14
|
@@ -1,1232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for the MCP HTTP transport.
|
|
3
|
-
*
|
|
4
|
-
* Starts a real Fastify server on an ephemeral port (port 0) per test suite
|
|
5
|
-
* and uses Node's global fetch to send requests. Real TCP sockets avoid the
|
|
6
|
-
* `socket.destroySoon is not a function` crash that occurs when the MCP SDK's
|
|
7
|
-
* StreamableHTTPServerTransport receives the mock socket from app.inject().
|
|
8
|
-
*
|
|
9
|
-
* Uses stateless transport mode: each request is independent, responses are
|
|
10
|
-
* plain JSON (no SSE). This is the simplest deployment model and the easiest
|
|
11
|
-
* to test. Stateful session behaviour is exercised by the SDK's own test suite.
|
|
12
|
-
*
|
|
13
|
-
* Acceptance criteria verified here (Layer 2):
|
|
14
|
-
* - tools/list returns all OSS tools (count matches listRegisteredTools())
|
|
15
|
-
* - Read-tool call succeeds over HTTP
|
|
16
|
-
* - Write-tool call from a disallowed origin returns 403
|
|
17
|
-
* - Rate-limit triggers at configured threshold
|
|
18
|
-
* - Abuse rules reject invalid email on capture_lead
|
|
19
|
-
* - Honeypot field rejection on capture_lead
|
|
20
|
-
* - Blocked UA returns 403
|
|
21
|
-
* - #5971: a start_purchase burst past the per-IP daily cap is refused with
|
|
22
|
-
* the rate-limit error, and no Checkout Session is created
|
|
23
|
-
* - #8071: create_booking and submit_flow_step take the same write branch —
|
|
24
|
-
* the origin allow-list, each tool's own daily cap (no hub call for a
|
|
25
|
-
* refused one), one cap unit per batched call, and for create_booking an
|
|
26
|
-
* attendee.email format check
|
|
27
|
-
* - #8073: a capture_lead call forwards the socket address the transport
|
|
28
|
-
* trusted (never a caller-forged X-Forwarded-For) plus
|
|
29
|
-
* AILK_VISITOR_FORWARD_KEY as the two visitor-forwarding headers, and sends
|
|
30
|
-
* neither when the key is unset
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import type { AddressInfo } from "node:net";
|
|
34
|
-
|
|
35
|
-
import type { FastifyInstance, FastifyRequest } from "fastify";
|
|
36
|
-
import { apiClient, checkout } from "@working-theory/api-client";
|
|
37
|
-
|
|
38
|
-
import {
|
|
39
|
-
__setMcpCommerceClaimForTest,
|
|
40
|
-
resetMcpCommerceClaim,
|
|
41
|
-
} from "../src/lib/commerce-claim.js";
|
|
42
|
-
import { AbuseGuard, AbuseReasonCode } from "../src/abuse/index.js";
|
|
43
|
-
import {
|
|
44
|
-
ABUSE_REFUSAL_STATUS,
|
|
45
|
-
buildHttpTransportApp,
|
|
46
|
-
WRITE_TOOLS,
|
|
47
|
-
} from "../src/http-transport.js";
|
|
48
|
-
import { listRegisteredTools } from "../src/server.js";
|
|
49
|
-
|
|
50
|
-
jest.mock("@working-theory/api-client", () => {
|
|
51
|
-
const actual = jest.requireActual("@working-theory/api-client");
|
|
52
|
-
// The hub stubs for the two #8071 write tools: every other surface stays
|
|
53
|
-
// real, so a tool these tests do not name behaves exactly as before.
|
|
54
|
-
return {
|
|
55
|
-
...actual,
|
|
56
|
-
checkout: { createSession: jest.fn() },
|
|
57
|
-
apiClient: {
|
|
58
|
-
...actual.apiClient,
|
|
59
|
-
schedule: { ...actual.apiClient.schedule, book: jest.fn() },
|
|
60
|
-
flows: { ...actual.apiClient.flows, submitStep: jest.fn() },
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
/** Permissive JSON-RPC 2.0 envelope type for response body assertions. */
|
|
66
|
-
type JsonRpcResponse = {
|
|
67
|
-
jsonrpc?: string;
|
|
68
|
-
id?: number | string | null;
|
|
69
|
-
result?: { tools?: unknown[]; [k: string]: unknown };
|
|
70
|
-
error?: { code: number; message: string };
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const TOOLS_LIST_PAYLOAD = {
|
|
74
|
-
jsonrpc: "2.0",
|
|
75
|
-
id: 1,
|
|
76
|
-
method: "tools/list",
|
|
77
|
-
params: {},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/** Default config used by most test suites. */
|
|
81
|
-
const DEFAULT_CONFIG = {
|
|
82
|
-
path: "/mcp",
|
|
83
|
-
stateless: true,
|
|
84
|
-
rateLimits: { readPerMin: 60, writePerMin: 10 },
|
|
85
|
-
cors: { writeAllowedOrigins: [] as string[] },
|
|
86
|
-
abuse: {
|
|
87
|
-
captureLeadDailyCapPerIp: 50,
|
|
88
|
-
blockedUserAgents: "",
|
|
89
|
-
},
|
|
90
|
-
} as const;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Post a JSON-RPC payload to the server at the given port and return the
|
|
94
|
-
* fetch Response. Includes the Accept header required by the MCP Streamable
|
|
95
|
-
* HTTP spec.
|
|
96
|
-
*/
|
|
97
|
-
async function mcpPost(
|
|
98
|
-
port: number,
|
|
99
|
-
payload: object,
|
|
100
|
-
headers: Record<string, string> = {},
|
|
101
|
-
): Promise<Response> {
|
|
102
|
-
return fetch(`http://127.0.0.1:${port}/mcp`, {
|
|
103
|
-
method: "POST",
|
|
104
|
-
body: JSON.stringify(payload),
|
|
105
|
-
headers: {
|
|
106
|
-
"content-type": "application/json",
|
|
107
|
-
accept: "application/json, text/event-stream",
|
|
108
|
-
...headers,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
describe("buildHttpTransportApp", () => {
|
|
114
|
-
let app: FastifyInstance;
|
|
115
|
-
let port: number;
|
|
116
|
-
|
|
117
|
-
beforeEach(async () => {
|
|
118
|
-
app = await buildHttpTransportApp(DEFAULT_CONFIG);
|
|
119
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
120
|
-
port = (app.server.address() as AddressInfo).port;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
afterEach(async () => {
|
|
124
|
-
await app.close();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("starts listening on an ephemeral port without throwing", () => {
|
|
128
|
-
expect(app.server.listening).toBe(true);
|
|
129
|
-
expect(port).toBeGreaterThan(0);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe("tools/list over HTTP (stateless)", () => {
|
|
134
|
-
let app: FastifyInstance;
|
|
135
|
-
let port: number;
|
|
136
|
-
|
|
137
|
-
beforeEach(async () => {
|
|
138
|
-
app = await buildHttpTransportApp(DEFAULT_CONFIG);
|
|
139
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
140
|
-
port = (app.server.address() as AddressInfo).port;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
afterEach(async () => {
|
|
144
|
-
await app.close();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("returns 200 for a tools/list request", async () => {
|
|
148
|
-
const res = await mcpPost(port, TOOLS_LIST_PAYLOAD);
|
|
149
|
-
expect(res.status).toBe(200);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("tools/list response includes all OSS tools", async () => {
|
|
153
|
-
const res = await mcpPost(port, TOOLS_LIST_PAYLOAD);
|
|
154
|
-
expect(res.status).toBe(200);
|
|
155
|
-
|
|
156
|
-
const body = (await res.json()) as JsonRpcResponse;
|
|
157
|
-
expect(body.result).toBeDefined();
|
|
158
|
-
// body.result is confirmed defined above; non-null assertion is safe
|
|
159
|
-
expect(Array.isArray(body.result!.tools)).toBe(true);
|
|
160
|
-
|
|
161
|
-
const expectedCount = listRegisteredTools().length;
|
|
162
|
-
expect(body.result!.tools).toHaveLength(expectedCount);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe("CORS enforcement on write tools", () => {
|
|
167
|
-
let app: FastifyInstance;
|
|
168
|
-
let port: number;
|
|
169
|
-
|
|
170
|
-
beforeEach(async () => {
|
|
171
|
-
app = await buildHttpTransportApp(DEFAULT_CONFIG);
|
|
172
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
173
|
-
port = (app.server.address() as AddressInfo).port;
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
afterEach(async () => {
|
|
177
|
-
await app.close();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("blocks a tools/call write from a non-allowlisted origin", async () => {
|
|
181
|
-
const payload = {
|
|
182
|
-
jsonrpc: "2.0",
|
|
183
|
-
id: 3,
|
|
184
|
-
method: "tools/call",
|
|
185
|
-
params: {
|
|
186
|
-
name: "capture_lead",
|
|
187
|
-
arguments: {
|
|
188
|
-
source: "mcp",
|
|
189
|
-
email: "bot@evil.com",
|
|
190
|
-
payload: { name: "Bot" },
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const res = await mcpPost(port, payload, {
|
|
196
|
-
origin: "https://evil.example.com",
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
expect(res.status).toBe(403);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("allows a tools/call write from an allowlisted origin", async () => {
|
|
203
|
-
const allowedApp = await buildHttpTransportApp({
|
|
204
|
-
...DEFAULT_CONFIG,
|
|
205
|
-
cors: { writeAllowedOrigins: ["https://allowed.example.com"] },
|
|
206
|
-
});
|
|
207
|
-
await allowedApp.listen({ host: "127.0.0.1", port: 0 });
|
|
208
|
-
const allowedPort = (allowedApp.server.address() as AddressInfo).port;
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
const payload = {
|
|
212
|
-
jsonrpc: "2.0",
|
|
213
|
-
id: 3,
|
|
214
|
-
method: "tools/call",
|
|
215
|
-
params: {
|
|
216
|
-
name: "capture_lead",
|
|
217
|
-
arguments: {
|
|
218
|
-
source: "mcp",
|
|
219
|
-
email: "jane@example.com",
|
|
220
|
-
payload: { name: "Jane" },
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const res = await mcpPost(allowedPort, payload, {
|
|
226
|
-
origin: "https://allowed.example.com",
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// Should NOT be 403 (may be 200 or a tool-level error, but not CORS blocked)
|
|
230
|
-
expect(res.status).not.toBe(403);
|
|
231
|
-
} finally {
|
|
232
|
-
await allowedApp.close();
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
describe("Rate limiting", () => {
|
|
238
|
-
// Use a very low limit to test without hammering
|
|
239
|
-
const LOW_RATE_CONFIG = {
|
|
240
|
-
...DEFAULT_CONFIG,
|
|
241
|
-
rateLimits: { readPerMin: 3, writePerMin: 2 },
|
|
242
|
-
} as const;
|
|
243
|
-
|
|
244
|
-
let app: FastifyInstance;
|
|
245
|
-
let port: number;
|
|
246
|
-
|
|
247
|
-
beforeEach(async () => {
|
|
248
|
-
app = await buildHttpTransportApp(LOW_RATE_CONFIG);
|
|
249
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
250
|
-
port = (app.server.address() as AddressInfo).port;
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
afterEach(async () => {
|
|
254
|
-
await app.close();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("returns 429 after exceeding the read rate limit", async () => {
|
|
258
|
-
const payload = {
|
|
259
|
-
jsonrpc: "2.0",
|
|
260
|
-
id: 10,
|
|
261
|
-
method: "tools/list",
|
|
262
|
-
params: {},
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
let lastStatus = 200;
|
|
266
|
-
for (let i = 0; i < 5; i++) {
|
|
267
|
-
const res = await mcpPost(port, payload);
|
|
268
|
-
lastStatus = res.status;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
expect(lastStatus).toBe(429);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
describe("Abuse rules", () => {
|
|
276
|
-
const OPEN_CORS_CONFIG = {
|
|
277
|
-
...DEFAULT_CONFIG,
|
|
278
|
-
cors: { writeAllowedOrigins: ["*"] as string[] },
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
let app: FastifyInstance;
|
|
282
|
-
let port: number;
|
|
283
|
-
|
|
284
|
-
beforeEach(async () => {
|
|
285
|
-
app = await buildHttpTransportApp(OPEN_CORS_CONFIG);
|
|
286
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
287
|
-
port = (app.server.address() as AddressInfo).port;
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
afterEach(async () => {
|
|
291
|
-
await app.close();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("rejects capture_lead with malformed email", async () => {
|
|
295
|
-
const payload = {
|
|
296
|
-
jsonrpc: "2.0",
|
|
297
|
-
id: 20,
|
|
298
|
-
method: "tools/call",
|
|
299
|
-
params: {
|
|
300
|
-
name: "capture_lead",
|
|
301
|
-
arguments: {
|
|
302
|
-
source: "mcp",
|
|
303
|
-
email: "not-an-email",
|
|
304
|
-
payload: { name: "Spammer" },
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const res = await mcpPost(port, payload);
|
|
310
|
-
expect(res.status).toBe(422);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
// #7171 — `email` is optional at the top level of the route body (the
|
|
314
|
-
// site's own envelope carries it inside `payload`, and the route lifts it
|
|
315
|
-
// from there), so the guard reads `payload.email` when the top level has
|
|
316
|
-
// none: a malformed address cannot be nested past the check.
|
|
317
|
-
it("rejects capture_lead with a malformed payload.email and no top-level email", async () => {
|
|
318
|
-
const payload = {
|
|
319
|
-
jsonrpc: "2.0",
|
|
320
|
-
id: 23,
|
|
321
|
-
method: "tools/call",
|
|
322
|
-
params: {
|
|
323
|
-
name: "capture_lead",
|
|
324
|
-
arguments: {
|
|
325
|
-
source: "mcp",
|
|
326
|
-
payload: { name: "Spammer", email: "not-an-email" },
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
const res = await mcpPost(port, payload);
|
|
332
|
-
expect(res.status).toBe(422);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("rejects capture_lead with honeypot field filled", async () => {
|
|
336
|
-
const payload = {
|
|
337
|
-
jsonrpc: "2.0",
|
|
338
|
-
id: 21,
|
|
339
|
-
method: "tools/call",
|
|
340
|
-
params: {
|
|
341
|
-
name: "capture_lead",
|
|
342
|
-
arguments: {
|
|
343
|
-
source: "mcp",
|
|
344
|
-
email: "bot@example.com",
|
|
345
|
-
honeypot: "i-am-a-bot",
|
|
346
|
-
payload: { name: "Bot" },
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
const res = await mcpPost(port, payload);
|
|
352
|
-
expect(res.status).toBe(422);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it("blocks requests from blocked user agents", async () => {
|
|
356
|
-
const blockedApp = await buildHttpTransportApp({
|
|
357
|
-
...OPEN_CORS_CONFIG,
|
|
358
|
-
abuse: {
|
|
359
|
-
captureLeadDailyCapPerIp: 50,
|
|
360
|
-
blockedUserAgents: "EvilBot",
|
|
361
|
-
},
|
|
362
|
-
});
|
|
363
|
-
await blockedApp.listen({ host: "127.0.0.1", port: 0 });
|
|
364
|
-
const blockedPort = (blockedApp.server.address() as AddressInfo).port;
|
|
365
|
-
|
|
366
|
-
try {
|
|
367
|
-
const res = await mcpPost(
|
|
368
|
-
blockedPort,
|
|
369
|
-
{
|
|
370
|
-
jsonrpc: "2.0",
|
|
371
|
-
id: 22,
|
|
372
|
-
method: "tools/call",
|
|
373
|
-
params: {
|
|
374
|
-
name: "capture_lead",
|
|
375
|
-
arguments: {
|
|
376
|
-
source: "mcp",
|
|
377
|
-
email: "bot@example.com",
|
|
378
|
-
payload: { name: "Bot" },
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
{ "user-agent": "EvilBot/1.0" },
|
|
383
|
-
);
|
|
384
|
-
expect(res.status).toBe(403);
|
|
385
|
-
} finally {
|
|
386
|
-
await blockedApp.close();
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* #8073 — the lead-write tools forward the address the transport TRUSTED
|
|
393
|
-
* (`request.ip`), not a caller-supplied `X-Forwarded-For` value. The
|
|
394
|
-
* long-running entry (`buildHttpTransportApp`, used throughout this file)
|
|
395
|
-
* sets no `trustProxy`, so `request.ip` is always the real socket address —
|
|
396
|
-
* 127.0.0.1 here — exactly the D5 guarantee a forged header cannot move.
|
|
397
|
-
*/
|
|
398
|
-
describe("capture_lead forwards the trusted caller address (#8073)", () => {
|
|
399
|
-
let app: FastifyInstance;
|
|
400
|
-
let port: number;
|
|
401
|
-
let submitSpy: jest.SpiedFunction<typeof apiClient.leads.submit>;
|
|
402
|
-
|
|
403
|
-
beforeEach(async () => {
|
|
404
|
-
submitSpy = jest
|
|
405
|
-
.spyOn(apiClient.leads, "submit")
|
|
406
|
-
.mockResolvedValue({
|
|
407
|
-
ok: true,
|
|
408
|
-
body: {
|
|
409
|
-
id: "lead_1",
|
|
410
|
-
persisted: "db",
|
|
411
|
-
email: { ok: true, messageId: "msg_1" },
|
|
412
|
-
},
|
|
413
|
-
});
|
|
414
|
-
app = await buildHttpTransportApp(DEFAULT_CONFIG);
|
|
415
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
416
|
-
port = (app.server.address() as AddressInfo).port;
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
afterEach(async () => {
|
|
420
|
-
await app.close();
|
|
421
|
-
submitSpy.mockRestore();
|
|
422
|
-
delete process.env.AILK_VISITOR_FORWARD_KEY;
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
function capturePayload(id: number, email: string) {
|
|
426
|
-
return {
|
|
427
|
-
jsonrpc: "2.0",
|
|
428
|
-
id,
|
|
429
|
-
method: "tools/call",
|
|
430
|
-
params: {
|
|
431
|
-
name: "capture_lead",
|
|
432
|
-
arguments: { source: "mcp", email, payload: { name: "Jane" } },
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
it("sends the socket address and the forward key as the two visitor headers", async () => {
|
|
438
|
-
process.env.AILK_VISITOR_FORWARD_KEY = "spoke-key";
|
|
439
|
-
|
|
440
|
-
const res = await mcpPost(port, capturePayload(40, "jane@example.com"), {
|
|
441
|
-
// A caller-forged hop: D5 says this must not move the key.
|
|
442
|
-
"x-forwarded-for": "203.0.113.7",
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
expect(res.status).toBe(200);
|
|
446
|
-
expect(submitSpy).toHaveBeenCalledTimes(1);
|
|
447
|
-
const init = submitSpy.mock.calls[0]?.[1];
|
|
448
|
-
expect(init?.headers).toEqual({
|
|
449
|
-
"x-ailk-visitor-ip": "127.0.0.1",
|
|
450
|
-
"x-ailk-visitor-forward-key": "spoke-key",
|
|
451
|
-
});
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
// #7171 AC-11, AC-14 — the body reaches the hub as the agent sent it; an
|
|
455
|
-
// agent's `siteId` is STRIPPED by the SDK's parse against the registered
|
|
456
|
-
// shape (never refused, as the route strips it), so none is ever posted.
|
|
457
|
-
it("posts the route body as sent, and strips an agent's siteId rather than refusing it", async () => {
|
|
458
|
-
delete process.env.AILK_LEAD_SITE;
|
|
459
|
-
|
|
460
|
-
const res = await mcpPost(port, {
|
|
461
|
-
jsonrpc: "2.0",
|
|
462
|
-
id: 42,
|
|
463
|
-
method: "tools/call",
|
|
464
|
-
params: {
|
|
465
|
-
name: "capture_lead",
|
|
466
|
-
arguments: {
|
|
467
|
-
source: "mcp",
|
|
468
|
-
email: "jane3@example.com",
|
|
469
|
-
payload: { name: "Jane" },
|
|
470
|
-
siteId: "evil",
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
expect(res.status).toBe(200);
|
|
476
|
-
expect(submitSpy).toHaveBeenCalledTimes(1);
|
|
477
|
-
expect(submitSpy.mock.calls[0]?.[0]).toEqual({
|
|
478
|
-
source: "mcp",
|
|
479
|
-
email: "jane3@example.com",
|
|
480
|
-
payload: { name: "Jane" },
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
it("sends no visitor headers (and no second argument) when the key is unset", async () => {
|
|
485
|
-
delete process.env.AILK_VISITOR_FORWARD_KEY;
|
|
486
|
-
|
|
487
|
-
const res = await mcpPost(port, capturePayload(41, "jane2@example.com"));
|
|
488
|
-
|
|
489
|
-
expect(res.status).toBe(200);
|
|
490
|
-
expect(submitSpy).toHaveBeenCalledTimes(1);
|
|
491
|
-
expect(submitSpy.mock.calls[0]).toHaveLength(1);
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* AC-3 — a `start_purchase` burst beyond the AbuseGuard per-IP cap is refused
|
|
497
|
-
* with the rate-limit error and creates no Checkout Session (#5971 D6).
|
|
498
|
-
*
|
|
499
|
-
* The refusal happens in the POST preHandler, BEFORE the MCP handler runs, so
|
|
500
|
-
* `checkout.createSession` is the thing to count: it is called once per call
|
|
501
|
-
* that got through and never for the one that was refused.
|
|
502
|
-
*
|
|
503
|
-
* `start_purchase` takes the write branch only because #5971 added it to
|
|
504
|
-
* `WRITE_TOOLS`; on the read branch the AbuseGuard checks the UA deny list
|
|
505
|
-
* alone and the cap would never be consulted.
|
|
506
|
-
*/
|
|
507
|
-
describe("start_purchase — per-IP daily cap (#5971)", () => {
|
|
508
|
-
const CAP = 2;
|
|
509
|
-
const CAPPED_CONFIG = {
|
|
510
|
-
...DEFAULT_CONFIG,
|
|
511
|
-
cors: { writeAllowedOrigins: ["*"] as string[] },
|
|
512
|
-
abuse: {
|
|
513
|
-
captureLeadDailyCapPerIp: 50,
|
|
514
|
-
startPurchaseDailyCapPerIp: CAP,
|
|
515
|
-
blockedUserAgents: "",
|
|
516
|
-
},
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
const createSession = checkout.createSession as jest.MockedFunction<
|
|
520
|
-
typeof checkout.createSession
|
|
521
|
-
>;
|
|
522
|
-
|
|
523
|
-
let app: FastifyInstance;
|
|
524
|
-
let port: number;
|
|
525
|
-
|
|
526
|
-
function purchasePayload(id: number) {
|
|
527
|
-
return {
|
|
528
|
-
jsonrpc: "2.0",
|
|
529
|
-
id,
|
|
530
|
-
method: "tools/call",
|
|
531
|
-
params: {
|
|
532
|
-
name: "start_purchase",
|
|
533
|
-
arguments: { productCode: "growth_monthly" },
|
|
534
|
-
},
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
beforeEach(async () => {
|
|
539
|
-
__setMcpCommerceClaimForTest("claimed");
|
|
540
|
-
createSession.mockResolvedValue({
|
|
541
|
-
ok: true,
|
|
542
|
-
body: {
|
|
543
|
-
sessionId: "cs_test_burst",
|
|
544
|
-
url: "https://checkout.stripe.com/c/pay/cs_test_burst",
|
|
545
|
-
},
|
|
546
|
-
});
|
|
547
|
-
app = await buildHttpTransportApp(CAPPED_CONFIG);
|
|
548
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
549
|
-
port = (app.server.address() as AddressInfo).port;
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
afterEach(async () => {
|
|
553
|
-
await app.close();
|
|
554
|
-
jest.clearAllMocks();
|
|
555
|
-
resetMcpCommerceClaim();
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
it("refuses the call past the cap with 403 and a 'daily cap' reason", async () => {
|
|
559
|
-
const first = await mcpPost(port, purchasePayload(30));
|
|
560
|
-
const second = await mcpPost(port, purchasePayload(31));
|
|
561
|
-
const third = await mcpPost(port, purchasePayload(32));
|
|
562
|
-
|
|
563
|
-
expect(first.status).toBe(200);
|
|
564
|
-
expect(second.status).toBe(200);
|
|
565
|
-
expect(third.status).toBe(403);
|
|
566
|
-
|
|
567
|
-
const body = (await third.json()) as { error?: string };
|
|
568
|
-
expect(body.error).toContain("daily");
|
|
569
|
-
expect(body.error).toContain("cap");
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it("creates no Checkout Session for the refused call", async () => {
|
|
573
|
-
await mcpPost(port, purchasePayload(33));
|
|
574
|
-
await mcpPost(port, purchasePayload(34));
|
|
575
|
-
await mcpPost(port, purchasePayload(35));
|
|
576
|
-
|
|
577
|
-
expect(createSession).toHaveBeenCalledTimes(CAP);
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
it("start_purchase takes the write branch, so the guard sees it at all", async () => {
|
|
581
|
-
const res = await mcpPost(port, purchasePayload(36), {
|
|
582
|
-
"user-agent": "curl/8.0",
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
// A built-in blocked UA is refused on the write branch; a read-branch
|
|
586
|
-
// tool would be too, but only the write branch consults the cap above.
|
|
587
|
-
expect(res.status).toBe(403);
|
|
588
|
-
});
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
/**
|
|
592
|
-
* JSON-RPC BATCH envelope — the write branch must survive it (#5971 security
|
|
593
|
-
* review, High).
|
|
594
|
-
*
|
|
595
|
-
* JSON-RPC 2.0 allows an ARRAY of messages in one POST, and the pinned MCP SDK
|
|
596
|
-
* dispatches every one of them. The write-tool guard used to read
|
|
597
|
-
* `body.method` on a body that may be an array: an array has no `.method`, so
|
|
598
|
-
* the whole batch was classified as a READ, skipping the write-origin
|
|
599
|
-
* allow-list and every AbuseGuard rule — including the per-IP daily cap. N
|
|
600
|
-
* batched `start_purchase` calls then executed on zero cap units, each one
|
|
601
|
-
* creating a real Stripe Checkout Session on the seller's account.
|
|
602
|
-
*
|
|
603
|
-
* These tests pin the envelope, not the tool: any future WRITE_TOOLS addition
|
|
604
|
-
* inherits them. The gap predated `start_purchase` and covered the three other
|
|
605
|
-
* write tools too, which is why the last case here is `capture_lead`.
|
|
606
|
-
*/
|
|
607
|
-
describe("JSON-RPC batch bodies take the write branch (#5971)", () => {
|
|
608
|
-
const CAP = 2;
|
|
609
|
-
const BATCH_CONFIG = {
|
|
610
|
-
...DEFAULT_CONFIG,
|
|
611
|
-
cors: { writeAllowedOrigins: ["*"] as string[] },
|
|
612
|
-
abuse: {
|
|
613
|
-
captureLeadDailyCapPerIp: CAP,
|
|
614
|
-
startPurchaseDailyCapPerIp: CAP,
|
|
615
|
-
blockedUserAgents: "",
|
|
616
|
-
},
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
const createSession = checkout.createSession as jest.MockedFunction<
|
|
620
|
-
typeof checkout.createSession
|
|
621
|
-
>;
|
|
622
|
-
|
|
623
|
-
let app: FastifyInstance;
|
|
624
|
-
let port: number;
|
|
625
|
-
|
|
626
|
-
function purchaseMessage(id: number) {
|
|
627
|
-
return {
|
|
628
|
-
jsonrpc: "2.0",
|
|
629
|
-
id,
|
|
630
|
-
method: "tools/call",
|
|
631
|
-
params: {
|
|
632
|
-
name: "start_purchase",
|
|
633
|
-
arguments: { productCode: "growth_monthly" },
|
|
634
|
-
},
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
beforeEach(async () => {
|
|
639
|
-
__setMcpCommerceClaimForTest("claimed");
|
|
640
|
-
createSession.mockResolvedValue({
|
|
641
|
-
ok: true,
|
|
642
|
-
body: {
|
|
643
|
-
sessionId: "cs_test_batch",
|
|
644
|
-
url: "https://checkout.stripe.com/c/pay/cs_test_batch",
|
|
645
|
-
},
|
|
646
|
-
});
|
|
647
|
-
app = await buildHttpTransportApp(BATCH_CONFIG);
|
|
648
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
649
|
-
port = (app.server.address() as AddressInfo).port;
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
afterEach(async () => {
|
|
653
|
-
await app.close();
|
|
654
|
-
jest.clearAllMocks();
|
|
655
|
-
resetMcpCommerceClaim();
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
it("a batch of N write calls consumes N cap units, not one", async () => {
|
|
659
|
-
// One POST carrying CAP + 1 messages. Under the old per-request check this
|
|
660
|
-
// returned 200 and executed every one; the cap must refuse it outright.
|
|
661
|
-
const res = await mcpPost(port, [
|
|
662
|
-
purchaseMessage(40),
|
|
663
|
-
purchaseMessage(41),
|
|
664
|
-
purchaseMessage(42),
|
|
665
|
-
]);
|
|
666
|
-
|
|
667
|
-
expect(res.status).toBe(403);
|
|
668
|
-
const body = (await res.json()) as { error?: string };
|
|
669
|
-
expect(body.error).toContain("daily cap");
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
it("refuses the batch before the SDK dispatches any of its messages", async () => {
|
|
673
|
-
await mcpPost(port, [
|
|
674
|
-
purchaseMessage(43),
|
|
675
|
-
purchaseMessage(44),
|
|
676
|
-
purchaseMessage(45),
|
|
677
|
-
]);
|
|
678
|
-
|
|
679
|
-
// Refused in the preHandler ⇒ no Checkout Session for ANY message.
|
|
680
|
-
expect(createSession).not.toHaveBeenCalled();
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
it("a batch within the cap still works, and charges one unit per message", async () => {
|
|
684
|
-
const res = await mcpPost(port, [purchaseMessage(46), purchaseMessage(47)]);
|
|
685
|
-
expect(res.status).toBe(200);
|
|
686
|
-
|
|
687
|
-
// Both units are now spent, so a single further call is refused.
|
|
688
|
-
const third = await mcpPost(port, purchaseMessage(48));
|
|
689
|
-
expect(third.status).toBe(403);
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
it("a batch is subject to the write-origin allow-list", async () => {
|
|
693
|
-
const strictApp = await buildHttpTransportApp({
|
|
694
|
-
...BATCH_CONFIG,
|
|
695
|
-
cors: { writeAllowedOrigins: [] as string[] },
|
|
696
|
-
});
|
|
697
|
-
await strictApp.listen({ host: "127.0.0.1", port: 0 });
|
|
698
|
-
const strictPort = (strictApp.server.address() as AddressInfo).port;
|
|
699
|
-
|
|
700
|
-
try {
|
|
701
|
-
const res = await mcpPost(strictPort, [purchaseMessage(49)], {
|
|
702
|
-
origin: "https://evil.example",
|
|
703
|
-
});
|
|
704
|
-
expect(res.status).toBe(403);
|
|
705
|
-
const body = (await res.json()) as { error?: string };
|
|
706
|
-
expect(body.error).toContain("CORS");
|
|
707
|
-
} finally {
|
|
708
|
-
await strictApp.close();
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
it("the same protection covers the pre-existing write tools (capture_lead)", async () => {
|
|
713
|
-
const leadMessage = (id: number) => ({
|
|
714
|
-
jsonrpc: "2.0",
|
|
715
|
-
id,
|
|
716
|
-
method: "tools/call",
|
|
717
|
-
params: {
|
|
718
|
-
name: "capture_lead",
|
|
719
|
-
arguments: { source: "mcp", email: "a@example.com", payload: { name: "A" } },
|
|
720
|
-
},
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
const res = await mcpPost(port, [
|
|
724
|
-
leadMessage(50),
|
|
725
|
-
leadMessage(51),
|
|
726
|
-
leadMessage(52),
|
|
727
|
-
]);
|
|
728
|
-
|
|
729
|
-
expect(res.status).toBe(403);
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
it("a batch of READ messages is unaffected", async () => {
|
|
733
|
-
const res = await mcpPost(port, [TOOLS_LIST_PAYLOAD]);
|
|
734
|
-
expect(res.status).toBe(200);
|
|
735
|
-
});
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* Guardrail — batch coverage is driven from WRITE_TOOLS itself (#5971 security
|
|
740
|
-
* review round 2), not from hand-picked names.
|
|
741
|
-
*
|
|
742
|
-
* The round-1 defect was invisible because every existing test used the
|
|
743
|
-
* single-message envelope. A comment on WRITE_TOOLS saying "enforce this
|
|
744
|
-
* batch-aware" is the weakest available remedy for a defect whose whole
|
|
745
|
-
* character was that nobody thought to send an array — so the inheritance is
|
|
746
|
-
* mechanical here: a tool added to WRITE_TOOLS without batch enforcement fails
|
|
747
|
-
* this suite on its first run.
|
|
748
|
-
*
|
|
749
|
-
* The assertion is the write-branch ORIGIN check rather than the cap, because
|
|
750
|
-
* it needs no per-tool arguments and no per-tool budget — only two of the four
|
|
751
|
-
* write tools carry a daily cap (see DAILY_CAPPED_TOOLS).
|
|
752
|
-
*/
|
|
753
|
-
describe.each([...WRITE_TOOLS])(
|
|
754
|
-
"a batch naming %s takes the write branch (#5971)",
|
|
755
|
-
(toolName) => {
|
|
756
|
-
let app: FastifyInstance;
|
|
757
|
-
let port: number;
|
|
758
|
-
|
|
759
|
-
beforeEach(async () => {
|
|
760
|
-
// Empty allow-list ⇒ a cross-origin write must be refused. On the read
|
|
761
|
-
// branch the origin is never consulted, so a 200 here means the batch
|
|
762
|
-
// was misclassified.
|
|
763
|
-
app = await buildHttpTransportApp({
|
|
764
|
-
...DEFAULT_CONFIG,
|
|
765
|
-
cors: { writeAllowedOrigins: [] as string[] },
|
|
766
|
-
});
|
|
767
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
768
|
-
port = (app.server.address() as AddressInfo).port;
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
afterEach(async () => {
|
|
772
|
-
await app.close();
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
it("is refused by the write-origin allow-list inside an array body", async () => {
|
|
776
|
-
const res = await mcpPost(
|
|
777
|
-
port,
|
|
778
|
-
[
|
|
779
|
-
{
|
|
780
|
-
jsonrpc: "2.0",
|
|
781
|
-
id: 60,
|
|
782
|
-
method: "tools/call",
|
|
783
|
-
params: { name: toolName, arguments: {} },
|
|
784
|
-
},
|
|
785
|
-
],
|
|
786
|
-
{ origin: "https://evil.example" },
|
|
787
|
-
);
|
|
788
|
-
|
|
789
|
-
expect(res.status).toBe(403);
|
|
790
|
-
});
|
|
791
|
-
},
|
|
792
|
-
);
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
* Guardrail — a blank or malformed cap must not silently disable enforcement
|
|
796
|
-
* (#5971 security review round 2, Medium).
|
|
797
|
-
*
|
|
798
|
-
* `parseInt("")` is NaN, NaN survives every `??` guard, and `count >= NaN` is
|
|
799
|
-
* always false — so the cap stops refusing anything, with no log and no
|
|
800
|
-
* startup warning. A misconfigured deployment looks identical to a correct one
|
|
801
|
-
* at rest, which is why this is pinned rather than left to convention.
|
|
802
|
-
*/
|
|
803
|
-
describe("a non-finite daily cap falls back to the default, never to unlimited (#5971)", () => {
|
|
804
|
-
let app: FastifyInstance;
|
|
805
|
-
let port: number;
|
|
806
|
-
|
|
807
|
-
afterEach(async () => {
|
|
808
|
-
if (app) await app.close();
|
|
809
|
-
jest.clearAllMocks();
|
|
810
|
-
resetMcpCommerceClaim();
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
async function startWithCap(cap: number): Promise<void> {
|
|
814
|
-
__setMcpCommerceClaimForTest("claimed");
|
|
815
|
-
(
|
|
816
|
-
checkout.createSession as jest.MockedFunction<
|
|
817
|
-
typeof checkout.createSession
|
|
818
|
-
>
|
|
819
|
-
).mockResolvedValue({
|
|
820
|
-
ok: true,
|
|
821
|
-
body: { sessionId: "cs_nan", url: "https://checkout.stripe.com/c/nan" },
|
|
822
|
-
});
|
|
823
|
-
app = await buildHttpTransportApp({
|
|
824
|
-
...DEFAULT_CONFIG,
|
|
825
|
-
// 21 writes in one minute: lift the per-minute write bucket (#9251) so
|
|
826
|
-
// the DAILY cap is the limit this test exercises.
|
|
827
|
-
rateLimits: { readPerMin: 60, writePerMin: 1000 },
|
|
828
|
-
cors: { writeAllowedOrigins: ["*"] as string[] },
|
|
829
|
-
abuse: {
|
|
830
|
-
captureLeadDailyCapPerIp: 50,
|
|
831
|
-
startPurchaseDailyCapPerIp: cap,
|
|
832
|
-
blockedUserAgents: "",
|
|
833
|
-
},
|
|
834
|
-
});
|
|
835
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
836
|
-
port = (app.server.address() as AddressInfo).port;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
it("NaN does not disable the start_purchase cap", async () => {
|
|
840
|
-
// What `parseInt("")` on a blank MCP_ABUSE_START_PURCHASE_DAILY_CAP yields.
|
|
841
|
-
await startWithCap(Number.NaN);
|
|
842
|
-
|
|
843
|
-
// The default (20) must still bite. 21 calls ⇒ the last one is refused.
|
|
844
|
-
let lastStatus = 0;
|
|
845
|
-
for (let i = 0; i < 21; i += 1) {
|
|
846
|
-
const res = await mcpPost(port, {
|
|
847
|
-
jsonrpc: "2.0",
|
|
848
|
-
id: 70 + i,
|
|
849
|
-
method: "tools/call",
|
|
850
|
-
params: {
|
|
851
|
-
name: "start_purchase",
|
|
852
|
-
arguments: { productCode: "growth_monthly" },
|
|
853
|
-
},
|
|
854
|
-
});
|
|
855
|
-
lastStatus = res.status;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
expect(lastStatus).toBe(403);
|
|
859
|
-
});
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* #5994 — the 403-vs-422 split is keyed on a TYPED reason code, never on the
|
|
864
|
-
* wording of the refusal reason.
|
|
865
|
-
*
|
|
866
|
-
* The guard refuses for two different kinds of reason and the transport owes
|
|
867
|
-
* them different statuses: a refusal of the CALLER (blocked UA, per-IP daily
|
|
868
|
-
* cap) is 403, a refusal of the INPUT (honeypot, malformed email) is 422.
|
|
869
|
-
* Before this change the transport told them apart with
|
|
870
|
-
* `reason.includes("daily cap")`, so a reworded reason silently turned a
|
|
871
|
-
* rate-limit refusal into a 422 — and `capture_lead`'s wording carried the
|
|
872
|
-
* substring only by accident ("daily capture_lead cap" contains "daily cap"
|
|
873
|
-
* because the tool name starts with "cap").
|
|
874
|
-
*
|
|
875
|
-
* These tests pin the mapping from the code, and assert the two daily-capped
|
|
876
|
-
* tools — whose reason wordings differ — both reach 403 through it.
|
|
877
|
-
*/
|
|
878
|
-
describe("abuse refusal status is keyed on the typed reason code (#5994)", () => {
|
|
879
|
-
const CODE_KEYED_CONFIG = {
|
|
880
|
-
...DEFAULT_CONFIG,
|
|
881
|
-
cors: { writeAllowedOrigins: ["*"] as string[] },
|
|
882
|
-
abuse: {
|
|
883
|
-
captureLeadDailyCapPerIp: 1,
|
|
884
|
-
startPurchaseDailyCapPerIp: 1,
|
|
885
|
-
blockedUserAgents: "",
|
|
886
|
-
},
|
|
887
|
-
};
|
|
888
|
-
|
|
889
|
-
const createSession = checkout.createSession as jest.MockedFunction<
|
|
890
|
-
typeof checkout.createSession
|
|
891
|
-
>;
|
|
892
|
-
|
|
893
|
-
let app: FastifyInstance;
|
|
894
|
-
let port: number;
|
|
895
|
-
|
|
896
|
-
beforeEach(async () => {
|
|
897
|
-
__setMcpCommerceClaimForTest("claimed");
|
|
898
|
-
createSession.mockResolvedValue({
|
|
899
|
-
ok: true,
|
|
900
|
-
body: {
|
|
901
|
-
sessionId: "cs_test_5994",
|
|
902
|
-
url: "https://checkout.stripe.com/c/pay/cs_test_5994",
|
|
903
|
-
},
|
|
904
|
-
});
|
|
905
|
-
app = await buildHttpTransportApp(CODE_KEYED_CONFIG);
|
|
906
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
907
|
-
port = (app.server.address() as AddressInfo).port;
|
|
908
|
-
});
|
|
909
|
-
|
|
910
|
-
afterEach(async () => {
|
|
911
|
-
await app.close();
|
|
912
|
-
jest.clearAllMocks();
|
|
913
|
-
resetMcpCommerceClaim();
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
function captureLeadPayload(id: number, args: Record<string, unknown>) {
|
|
917
|
-
return {
|
|
918
|
-
jsonrpc: "2.0",
|
|
919
|
-
id,
|
|
920
|
-
method: "tools/call",
|
|
921
|
-
params: { name: "capture_lead", arguments: args },
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
it("maps a capture_lead daily-cap refusal to 403", async () => {
|
|
926
|
-
// The first call spends the IP's single cap unit. Whatever the handler
|
|
927
|
-
// then makes of it is irrelevant here — only the SECOND call, refused in
|
|
928
|
-
// the preHandler, is under test.
|
|
929
|
-
await mcpPost(
|
|
930
|
-
port,
|
|
931
|
-
captureLeadPayload(40, {
|
|
932
|
-
source: "mcp",
|
|
933
|
-
email: "first@example.com",
|
|
934
|
-
payload: { name: "First" },
|
|
935
|
-
}),
|
|
936
|
-
);
|
|
937
|
-
|
|
938
|
-
const capped = await mcpPost(
|
|
939
|
-
port,
|
|
940
|
-
captureLeadPayload(41, {
|
|
941
|
-
source: "mcp",
|
|
942
|
-
email: "second@example.com",
|
|
943
|
-
payload: { name: "Second" },
|
|
944
|
-
}),
|
|
945
|
-
);
|
|
946
|
-
|
|
947
|
-
expect(capped.status).toBe(403);
|
|
948
|
-
});
|
|
949
|
-
|
|
950
|
-
it("maps a start_purchase daily-cap refusal to 403", async () => {
|
|
951
|
-
const purchase = (id: number) => ({
|
|
952
|
-
jsonrpc: "2.0",
|
|
953
|
-
id,
|
|
954
|
-
method: "tools/call",
|
|
955
|
-
params: { name: "start_purchase", arguments: { productCode: "growth_monthly" } },
|
|
956
|
-
});
|
|
957
|
-
|
|
958
|
-
const first = await mcpPost(port, purchase(42));
|
|
959
|
-
const capped = await mcpPost(port, purchase(43));
|
|
960
|
-
|
|
961
|
-
expect(first.status).toBe(200);
|
|
962
|
-
expect(capped.status).toBe(403);
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
it("maps a validation refusal to 422", async () => {
|
|
966
|
-
const res = await mcpPost(
|
|
967
|
-
port,
|
|
968
|
-
captureLeadPayload(44, { name: "Spammer", email: "not-an-email" }),
|
|
969
|
-
);
|
|
970
|
-
|
|
971
|
-
expect(res.status).toBe(422);
|
|
972
|
-
});
|
|
973
|
-
|
|
974
|
-
/**
|
|
975
|
-
* The AbuseGuard reads exactly two things off the request — the
|
|
976
|
-
* `user-agent` header and `ip`. The UA here is one the built-in deny list
|
|
977
|
-
* lets through, so Rule 4 (the cap) is what refuses these calls rather than
|
|
978
|
-
* Rule 1.
|
|
979
|
-
*/
|
|
980
|
-
function makeGuardRequest(): FastifyRequest {
|
|
981
|
-
// @ts-expect-error: a stub carrying only the two members the guard reads;
|
|
982
|
-
// a full FastifyRequest cannot be constructed without a live server.
|
|
983
|
-
return {
|
|
984
|
-
headers: { "user-agent": "Mozilla/5.0 (compatible; TestAgent/1.0)" },
|
|
985
|
-
ip: "203.0.113.7",
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
it("derives the status from the code alone — the two daily-capped tools word their reasons differently yet both map to 403", () => {
|
|
990
|
-
const guard = new AbuseGuard({
|
|
991
|
-
captureLeadDailyCapPerIp: 1,
|
|
992
|
-
startPurchaseDailyCapPerIp: 1,
|
|
993
|
-
blockedUserAgents: "",
|
|
994
|
-
});
|
|
995
|
-
const request = makeGuardRequest();
|
|
996
|
-
|
|
997
|
-
// Spend each tool's single cap unit, then collect the refusal.
|
|
998
|
-
guard.validate("capture_lead", {}, request);
|
|
999
|
-
guard.validate("start_purchase", {}, request);
|
|
1000
|
-
const lead = guard.validate("capture_lead", {}, request);
|
|
1001
|
-
const purchase = guard.validate("start_purchase", {}, request);
|
|
1002
|
-
|
|
1003
|
-
expect(lead.allowed).toBe(false);
|
|
1004
|
-
expect(purchase.allowed).toBe(false);
|
|
1005
|
-
if (lead.allowed || purchase.allowed) return;
|
|
1006
|
-
|
|
1007
|
-
// Same code, different wording — the wording is prose for the caller, the
|
|
1008
|
-
// code is what the transport reads.
|
|
1009
|
-
expect(lead.code).toBe(AbuseReasonCode.DAILY_CAP_REACHED);
|
|
1010
|
-
expect(purchase.code).toBe(AbuseReasonCode.DAILY_CAP_REACHED);
|
|
1011
|
-
expect(lead.reason).not.toBe(purchase.reason);
|
|
1012
|
-
|
|
1013
|
-
expect(ABUSE_REFUSAL_STATUS[lead.code]).toBe(403);
|
|
1014
|
-
expect(ABUSE_REFUSAL_STATUS[purchase.code]).toBe(403);
|
|
1015
|
-
});
|
|
1016
|
-
|
|
1017
|
-
it("declares a status for every reason code the guard can return", () => {
|
|
1018
|
-
expect(Object.keys(ABUSE_REFUSAL_STATUS).sort()).toEqual(
|
|
1019
|
-
Object.values(AbuseReasonCode).sort(),
|
|
1020
|
-
);
|
|
1021
|
-
expect(ABUSE_REFUSAL_STATUS[AbuseReasonCode.BLOCKED_USER_AGENT]).toBe(403);
|
|
1022
|
-
expect(ABUSE_REFUSAL_STATUS[AbuseReasonCode.HONEYPOT_FILLED]).toBe(422);
|
|
1023
|
-
expect(ABUSE_REFUSAL_STATUS[AbuseReasonCode.INVALID_EMAIL]).toBe(422);
|
|
1024
|
-
});
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
/**
|
|
1028
|
-
* #8071 — `create_booking` and `submit_flow_step` send caller-chosen data to
|
|
1029
|
-
* the hub, so they take the same write branch as `capture_lead`: the
|
|
1030
|
-
* write-origin allow-list, then the AbuseGuard once per call — each on its OWN
|
|
1031
|
-
* daily-cap tracker.
|
|
1032
|
-
*
|
|
1033
|
-
* Every assertion here is a refusal the preHandler makes, so the suite holds
|
|
1034
|
-
* in a scaffold that does not register the tool (no `scheduling` or
|
|
1035
|
-
* `signal-collectors` module): the hub stub is checked for "no request for the
|
|
1036
|
-
* refused call", never for a count the handler would have to produce.
|
|
1037
|
-
*/
|
|
1038
|
-
const HUB_WRITE_TOOLS = [
|
|
1039
|
-
{
|
|
1040
|
-
toolName: "create_booking",
|
|
1041
|
-
capField: "createBookingDailyCapPerIp",
|
|
1042
|
-
hubStub: () => apiClient.schedule.book as jest.Mock,
|
|
1043
|
-
args: () => ({
|
|
1044
|
-
calLink: "acme/intro",
|
|
1045
|
-
start: "2030-01-07T15:00:00.000Z",
|
|
1046
|
-
attendee: { name: "Ada", email: "ada@example.com" },
|
|
1047
|
-
}),
|
|
1048
|
-
},
|
|
1049
|
-
{
|
|
1050
|
-
toolName: "submit_flow_step",
|
|
1051
|
-
capField: "submitFlowStepDailyCapPerIp",
|
|
1052
|
-
hubStub: () => apiClient.flows.submitStep as jest.Mock,
|
|
1053
|
-
args: () => ({
|
|
1054
|
-
slug: "intake",
|
|
1055
|
-
stepKey: "contact",
|
|
1056
|
-
values: { company: "Acme" },
|
|
1057
|
-
}),
|
|
1058
|
-
},
|
|
1059
|
-
] as const;
|
|
1060
|
-
|
|
1061
|
-
describe.each(HUB_WRITE_TOOLS)(
|
|
1062
|
-
"$toolName takes the write branch of the HTTP guard (#8071)",
|
|
1063
|
-
({ toolName, capField, hubStub, args }) => {
|
|
1064
|
-
const CAP = 2;
|
|
1065
|
-
const config = {
|
|
1066
|
-
...DEFAULT_CONFIG,
|
|
1067
|
-
cors: { writeAllowedOrigins: ["https://allowed.example"] as string[] },
|
|
1068
|
-
abuse: {
|
|
1069
|
-
captureLeadDailyCapPerIp: 50,
|
|
1070
|
-
startPurchaseDailyCapPerIp: 20,
|
|
1071
|
-
[capField]: CAP,
|
|
1072
|
-
blockedUserAgents: "",
|
|
1073
|
-
},
|
|
1074
|
-
};
|
|
1075
|
-
|
|
1076
|
-
let app: FastifyInstance;
|
|
1077
|
-
let port: number;
|
|
1078
|
-
|
|
1079
|
-
function call(id: number, callArgs: object = args()) {
|
|
1080
|
-
return {
|
|
1081
|
-
jsonrpc: "2.0",
|
|
1082
|
-
id,
|
|
1083
|
-
method: "tools/call",
|
|
1084
|
-
params: { name: toolName, arguments: callArgs },
|
|
1085
|
-
};
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
beforeEach(async () => {
|
|
1089
|
-
hubStub().mockResolvedValue({ ok: false, status: 503, body: {} });
|
|
1090
|
-
app = await buildHttpTransportApp(config);
|
|
1091
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
1092
|
-
port = (app.server.address() as AddressInfo).port;
|
|
1093
|
-
});
|
|
1094
|
-
|
|
1095
|
-
afterEach(async () => {
|
|
1096
|
-
await app.close();
|
|
1097
|
-
jest.clearAllMocks();
|
|
1098
|
-
});
|
|
1099
|
-
|
|
1100
|
-
it("is a member of WRITE_TOOLS", () => {
|
|
1101
|
-
expect(WRITE_TOOLS.has(toolName)).toBe(true);
|
|
1102
|
-
});
|
|
1103
|
-
|
|
1104
|
-
it("refuses a call from an origin not on writeAllowedOrigins with 403", async () => {
|
|
1105
|
-
const res = await mcpPost(port, call(80), {
|
|
1106
|
-
origin: "https://evil.example",
|
|
1107
|
-
});
|
|
1108
|
-
|
|
1109
|
-
expect(res.status).toBe(403);
|
|
1110
|
-
const body = (await res.json()) as { error?: string };
|
|
1111
|
-
expect(body.error).toContain("CORS");
|
|
1112
|
-
expect(hubStub()).not.toHaveBeenCalled();
|
|
1113
|
-
});
|
|
1114
|
-
|
|
1115
|
-
it("refuses the call past its daily cap with 403, and the hub gets no request for it", async () => {
|
|
1116
|
-
for (let i = 0; i < CAP; i += 1) {
|
|
1117
|
-
const res = await mcpPost(port, call(81 + i));
|
|
1118
|
-
expect(res.status).toBe(200);
|
|
1119
|
-
}
|
|
1120
|
-
const hubCallsBefore = hubStub().mock.calls.length;
|
|
1121
|
-
|
|
1122
|
-
const capped = await mcpPost(port, call(90));
|
|
1123
|
-
|
|
1124
|
-
expect(capped.status).toBe(403);
|
|
1125
|
-
const body = (await capped.json()) as { error?: string };
|
|
1126
|
-
expect(body.error).toContain(toolName);
|
|
1127
|
-
expect(hubStub().mock.calls.length).toBe(hubCallsBefore);
|
|
1128
|
-
});
|
|
1129
|
-
|
|
1130
|
-
it("a batch of N calls charges N cap units", async () => {
|
|
1131
|
-
const res = await mcpPost(port, [call(91), call(92), call(93)]);
|
|
1132
|
-
|
|
1133
|
-
expect(res.status).toBe(403);
|
|
1134
|
-
expect(hubStub()).not.toHaveBeenCalled();
|
|
1135
|
-
});
|
|
1136
|
-
|
|
1137
|
-
it("its cap is its own — spending it leaves capture_lead callable", async () => {
|
|
1138
|
-
for (let i = 0; i < CAP; i += 1) await mcpPost(port, call(94 + i));
|
|
1139
|
-
expect((await mcpPost(port, call(97))).status).toBe(403);
|
|
1140
|
-
|
|
1141
|
-
const lead = await mcpPost(port, {
|
|
1142
|
-
jsonrpc: "2.0",
|
|
1143
|
-
id: 98,
|
|
1144
|
-
method: "tools/call",
|
|
1145
|
-
params: {
|
|
1146
|
-
name: "capture_lead",
|
|
1147
|
-
arguments: { name: "Ada", email: "ada@example.com" },
|
|
1148
|
-
},
|
|
1149
|
-
});
|
|
1150
|
-
expect(lead.status).not.toBe(403);
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
it("a refusal maps through the typed code: past the cap is DAILY_CAP_REACHED", () => {
|
|
1154
|
-
const guard = new AbuseGuard({
|
|
1155
|
-
captureLeadDailyCapPerIp: 50,
|
|
1156
|
-
[capField]: 1,
|
|
1157
|
-
blockedUserAgents: "",
|
|
1158
|
-
});
|
|
1159
|
-
// @ts-expect-error: a stub carrying only the two members the guard reads.
|
|
1160
|
-
const request: FastifyRequest = {
|
|
1161
|
-
headers: { "user-agent": "Mozilla/5.0 (compatible; TestAgent/1.0)" },
|
|
1162
|
-
ip: "203.0.113.9",
|
|
1163
|
-
};
|
|
1164
|
-
|
|
1165
|
-
expect(guard.validate(toolName, args(), request).allowed).toBe(true);
|
|
1166
|
-
const refused = guard.validate(toolName, args(), request);
|
|
1167
|
-
|
|
1168
|
-
expect(refused.allowed).toBe(false);
|
|
1169
|
-
if (refused.allowed) return;
|
|
1170
|
-
expect(refused.code).toBe(AbuseReasonCode.DAILY_CAP_REACHED);
|
|
1171
|
-
expect(ABUSE_REFUSAL_STATUS[refused.code]).toBe(403);
|
|
1172
|
-
});
|
|
1173
|
-
},
|
|
1174
|
-
);
|
|
1175
|
-
|
|
1176
|
-
describe("create_booking — attendee.email is format-checked before the hub (#8071)", () => {
|
|
1177
|
-
let app: FastifyInstance;
|
|
1178
|
-
let port: number;
|
|
1179
|
-
|
|
1180
|
-
const book = () => apiClient.schedule.book as jest.Mock;
|
|
1181
|
-
|
|
1182
|
-
function booking(id: number, attendee: unknown) {
|
|
1183
|
-
return {
|
|
1184
|
-
jsonrpc: "2.0",
|
|
1185
|
-
id,
|
|
1186
|
-
method: "tools/call",
|
|
1187
|
-
params: {
|
|
1188
|
-
name: "create_booking",
|
|
1189
|
-
arguments: {
|
|
1190
|
-
calLink: "acme/intro",
|
|
1191
|
-
start: "2030-01-07T15:00:00.000Z",
|
|
1192
|
-
attendee,
|
|
1193
|
-
},
|
|
1194
|
-
},
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
beforeEach(async () => {
|
|
1199
|
-
book().mockResolvedValue({ ok: false, status: 503, body: {} });
|
|
1200
|
-
app = await buildHttpTransportApp(DEFAULT_CONFIG);
|
|
1201
|
-
await app.listen({ host: "127.0.0.1", port: 0 });
|
|
1202
|
-
port = (app.server.address() as AddressInfo).port;
|
|
1203
|
-
});
|
|
1204
|
-
|
|
1205
|
-
afterEach(async () => {
|
|
1206
|
-
await app.close();
|
|
1207
|
-
jest.clearAllMocks();
|
|
1208
|
-
});
|
|
1209
|
-
|
|
1210
|
-
it("refuses a malformed attendee.email with 422 and leaves the hub stub untouched", async () => {
|
|
1211
|
-
const res = await mcpPost(
|
|
1212
|
-
port,
|
|
1213
|
-
booking(100, { name: "Spammer", email: "not-an-email" }),
|
|
1214
|
-
);
|
|
1215
|
-
|
|
1216
|
-
expect(res.status).toBe(422);
|
|
1217
|
-
const body = (await res.json()) as { error?: string };
|
|
1218
|
-
expect(body.error).toContain("email");
|
|
1219
|
-
expect(book()).not.toHaveBeenCalled();
|
|
1220
|
-
});
|
|
1221
|
-
|
|
1222
|
-
it.each([null, "ada@example.com", ["ada@example.com"], 42])(
|
|
1223
|
-
"a non-object attendee (%p) is not a guard refusal and never a 500",
|
|
1224
|
-
async (attendee) => {
|
|
1225
|
-
const res = await mcpPost(port, booking(101, attendee));
|
|
1226
|
-
|
|
1227
|
-
// The handler's own Zod schema is the authority on the shape.
|
|
1228
|
-
expect(res.status).toBe(200);
|
|
1229
|
-
expect(book()).not.toHaveBeenCalled();
|
|
1230
|
-
},
|
|
1231
|
-
);
|
|
1232
|
-
});
|