create-ailk 0.1.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/LICENSE +201 -0
- package/README.md +39 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +80 -0
- package/dist/copy.d.ts +8 -0
- package/dist/copy.js +109 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/lib/pro-callout.d.ts +12 -0
- package/dist/lib/pro-callout.js +20 -0
- package/dist/parse-args.d.ts +13 -0
- package/dist/parse-args.js +81 -0
- package/dist/programmatic.d.ts +49 -0
- package/dist/programmatic.js +89 -0
- package/dist/substitute.d.ts +31 -0
- package/dist/substitute.js +45 -0
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +70 -0
- package/package.json +47 -0
- package/templates/.claude/.gitkeep +0 -0
- package/templates/.claude/agents/web.md +80 -0
- package/templates/.claude/rules/architecture.md +62 -0
- package/templates/.claude/rules/preserve-existing-style.md +51 -0
- package/templates/.claude/skills/README.md +43 -0
- package/templates/.claude/skills/add-schema/SKILL.md +270 -0
- package/templates/.claude/skills/add-schema/references/conflict-handling.md +200 -0
- package/templates/.claude/skills/add-schema/references/file-finding.md +123 -0
- package/templates/.claude/skills/add-schema/references/schema-types.md +131 -0
- package/templates/.claude/skills/audit-site/SKILL.md +213 -0
- package/templates/.claude/skills/audit-site/references/common-errors.md +113 -0
- package/templates/.claude/skills/audit-site/references/findings-glossary.md +138 -0
- package/templates/.claude/skills/audit-site/references/severity-levels.md +114 -0
- package/templates/.claude/skills/provision-config/SKILL.md +243 -0
- package/templates/.claude/skills/provision-config/references/env-vars-template.md +184 -0
- package/templates/.claude/skills/provision-config/references/runbook-template.md +248 -0
- package/templates/.claude/skills/provision-config/references/vercel-json-template.md +98 -0
- package/templates/.claude/skills/scaffold-auth/SKILL.md +261 -0
- package/templates/.claude/skills/scaffold-auth/references/env-vars.md +91 -0
- package/templates/.claude/skills/scaffold-auth/references/oauth-app-setup.md +171 -0
- package/templates/.claude/skills/scaffold-commerce/SKILL.md +310 -0
- package/templates/.claude/skills/scaffold-commerce/references/lookup-keys-template.md +71 -0
- package/templates/.claude/skills/scaffold-commerce/references/marketplace-brand-pages.md +83 -0
- package/templates/.claude/skills/scaffold-commerce/templates/marketplace-cta-route.tsx.tmpl +72 -0
- package/templates/.claude/skills/scaffold-page/SKILL.md +243 -0
- package/templates/.claude/skills/scaffold-page/references/page-types.md +169 -0
- package/templates/.claude/skills/scaffold-page/templates/content.mdx.tmpl +28 -0
- package/templates/.claude/skills/scaffold-page/templates/route.tsx.tmpl +28 -0
- package/templates/.claude/skills/suggest-site-pages/SKILL.md +242 -0
- package/templates/.claude/skills/suggest-site-pages/references/categories.md +287 -0
- package/templates/.env.example +205 -0
- package/templates/.gitkeep +2 -0
- package/templates/CLAUDE.md +142 -0
- package/templates/CONVENTIONS.md +222 -0
- package/templates/README.md +110 -0
- package/templates/apps/api/.env.example +40 -0
- package/templates/apps/api/CLAUDE.md +63 -0
- package/templates/apps/api/api/index.ts +144 -0
- package/templates/apps/api/jest.config.cjs +74 -0
- package/templates/apps/api/package.json +54 -0
- package/templates/apps/api/src/__tests__/factories/content-fixture.ts +138 -0
- package/templates/apps/api/src/__tests__/factories/index.ts +70 -0
- package/templates/apps/api/src/__tests__/factories/lead-fixture.ts +82 -0
- package/templates/apps/api/src/__tests__/index.test.ts +118 -0
- package/templates/apps/api/src/__tests__/server.test.ts +207 -0
- package/templates/apps/api/src/__tests__/services/enrichment-shim.test.ts +126 -0
- package/templates/apps/api/src/__tests__/setup.ts +24 -0
- package/templates/apps/api/src/cli.ts +30 -0
- package/templates/apps/api/src/config/__tests__/index.test.ts +97 -0
- package/templates/apps/api/src/config/index.ts +56 -0
- package/templates/apps/api/src/index.ts +32 -0
- package/templates/apps/api/src/lib/__mocks__/prisma-client.js +15 -0
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +45 -0
- package/templates/apps/api/src/lib/__tests__/content-adapter.test.ts +178 -0
- package/templates/apps/api/src/lib/__tests__/error-serializer.test.ts +100 -0
- package/templates/apps/api/src/lib/__tests__/errors.test.ts +94 -0
- package/templates/apps/api/src/lib/__tests__/file-fallback.test.ts +144 -0
- package/templates/apps/api/src/lib/__tests__/fixtures/HomePage/home.mdx +8 -0
- package/templates/apps/api/src/lib/__tests__/lead-capture-store.test.ts +227 -0
- package/templates/apps/api/src/lib/__tests__/outbound-http.test.ts +125 -0
- package/templates/apps/api/src/lib/__tests__/prisma.test.ts +165 -0
- package/templates/apps/api/src/lib/__tests__/require-paid-tier.test.ts +129 -0
- package/templates/apps/api/src/lib/__tests__/stripe.test.ts +74 -0
- package/templates/apps/api/src/lib/content-adapter.ts +86 -0
- package/templates/apps/api/src/lib/error-serializer.ts +77 -0
- package/templates/apps/api/src/lib/errors.ts +95 -0
- package/templates/apps/api/src/lib/file-fallback.ts +87 -0
- package/templates/apps/api/src/lib/lead-capture-store.ts +110 -0
- package/templates/apps/api/src/lib/locales.ts +201 -0
- package/templates/apps/api/src/lib/outbound-http.ts +122 -0
- package/templates/apps/api/src/lib/prisma.ts +21 -0
- package/templates/apps/api/src/lib/require-paid-tier.ts +53 -0
- package/templates/apps/api/src/lib/stripe.ts +30 -0
- package/templates/apps/api/src/lib/webhook-idempotency.ts +92 -0
- package/templates/apps/api/src/middleware/__tests__/adversarial/bearer-token-format.test.ts +111 -0
- package/templates/apps/api/src/middleware/__tests__/adversarial/cookie-or-bearer-precedence.test.ts +172 -0
- package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-bearer-skip.test.ts +119 -0
- package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-cookie-path.test.ts +138 -0
- package/templates/apps/api/src/middleware/__tests__/adversarial/session-fixation.test.ts +149 -0
- package/templates/apps/api/src/middleware/__tests__/adversarial/session-timeout.test.ts +139 -0
- package/templates/apps/api/src/middleware/__tests__/auth.bearer-path.test.ts +175 -0
- package/templates/apps/api/src/middleware/__tests__/auth.both-present-precedence.test.ts +76 -0
- package/templates/apps/api/src/middleware/__tests__/auth.cookie-path.test.ts +153 -0
- package/templates/apps/api/src/middleware/__tests__/auth.neither-present.test.ts +72 -0
- package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +292 -0
- package/templates/apps/api/src/middleware/auth.ts +246 -0
- package/templates/apps/api/src/middleware/rate-limit.ts +132 -0
- package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +129 -0
- package/templates/apps/api/src/openapi/index.ts +12 -0
- package/templates/apps/api/src/openapi/spec.ts +408 -0
- package/templates/apps/api/src/routes/auth/__tests__/auth-tokens.functional.test.ts +193 -0
- package/templates/apps/api/src/routes/auth/__tests__/auth-user.functional.test.ts +201 -0
- package/templates/apps/api/src/routes/auth/__tests__/tokens.test.ts +294 -0
- package/templates/apps/api/src/routes/auth/__tests__/user.test.ts +486 -0
- package/templates/apps/api/src/routes/auth/tokens.ts +199 -0
- package/templates/apps/api/src/routes/auth/user.ts +244 -0
- package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +588 -0
- package/templates/apps/api/src/routes/checkout/index.ts +13 -0
- package/templates/apps/api/src/routes/checkout/sessions.ts +185 -0
- package/templates/apps/api/src/routes/content/__tests__/create.test.ts +239 -0
- package/templates/apps/api/src/routes/content/__tests__/delete.test.ts +201 -0
- package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +141 -0
- package/templates/apps/api/src/routes/content/__tests__/list-pages.test.ts +122 -0
- package/templates/apps/api/src/routes/content/__tests__/list-types.test.ts +44 -0
- package/templates/apps/api/src/routes/content/__tests__/locale.test.ts +118 -0
- package/templates/apps/api/src/routes/content/__tests__/rate-limit.test.ts +51 -0
- package/templates/apps/api/src/routes/content/__tests__/update.test.ts +252 -0
- package/templates/apps/api/src/routes/content/create.ts +114 -0
- package/templates/apps/api/src/routes/content/delete.ts +81 -0
- package/templates/apps/api/src/routes/content/get-page.ts +98 -0
- package/templates/apps/api/src/routes/content/index.ts +32 -0
- package/templates/apps/api/src/routes/content/list-pages.ts +83 -0
- package/templates/apps/api/src/routes/content/list-types.ts +19 -0
- package/templates/apps/api/src/routes/content/rate-limit.ts +13 -0
- package/templates/apps/api/src/routes/content/slug.ts +9 -0
- package/templates/apps/api/src/routes/content/update.ts +111 -0
- package/templates/apps/api/src/routes/leads/__tests__/index.test.ts +415 -0
- package/templates/apps/api/src/routes/leads/__tests__/track.test.ts +165 -0
- package/templates/apps/api/src/routes/leads/index.ts +130 -0
- package/templates/apps/api/src/routes/test/auth/__tests__/session.test.ts +296 -0
- package/templates/apps/api/src/routes/test/auth/session.ts +141 -0
- package/templates/apps/api/src/routes/webhooks/README.md +57 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +247 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +198 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +633 -0
- package/templates/apps/api/src/routes/webhooks/index.ts +41 -0
- package/templates/apps/api/src/routes/webhooks/stripe.ts +253 -0
- package/templates/apps/api/src/server.ts +157 -0
- package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +395 -0
- package/templates/apps/api/src/services/enrichment-shim.ts +53 -0
- package/templates/apps/api/src/services/lead-routing.ts +338 -0
- package/templates/apps/api/tsconfig.json +34 -0
- package/templates/apps/api/vercel.json +17 -0
- package/templates/apps/mcp/.env.example +52 -0
- package/templates/apps/mcp/CLAUDE.md +84 -0
- package/templates/apps/mcp/__tests__/abuse/daily-cap.test.ts +52 -0
- package/templates/apps/mcp/__tests__/abuse/email-validator.test.ts +46 -0
- package/templates/apps/mcp/__tests__/abuse/honeypot.test.ts +36 -0
- package/templates/apps/mcp/__tests__/abuse/user-agent-deny.test.ts +54 -0
- package/templates/apps/mcp/__tests__/aeo-cli-parity.test.ts +110 -0
- package/templates/apps/mcp/__tests__/audit-single-page.test.ts +213 -0
- package/templates/apps/mcp/__tests__/audit.test.ts +217 -0
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +52 -0
- package/templates/apps/mcp/__tests__/create_page.test.ts +201 -0
- package/templates/apps/mcp/__tests__/delete_page.test.ts +176 -0
- package/templates/apps/mcp/__tests__/get_business_hours.test.ts +82 -0
- package/templates/apps/mcp/__tests__/get_faq.test.ts +80 -0
- package/templates/apps/mcp/__tests__/get_locations.test.ts +65 -0
- package/templates/apps/mcp/__tests__/get_offerings.test.ts +90 -0
- package/templates/apps/mcp/__tests__/get_pricing.test.ts +80 -0
- package/templates/apps/mcp/__tests__/get_site_info.test.ts +81 -0
- package/templates/apps/mcp/__tests__/http-transport.test.ts +323 -0
- package/templates/apps/mcp/__tests__/lib/errors.test.ts +75 -0
- package/templates/apps/mcp/__tests__/lib/require-paid-tier.test.ts +75 -0
- package/templates/apps/mcp/__tests__/list_pages.test.ts +112 -0
- package/templates/apps/mcp/__tests__/locale.test.ts +135 -0
- package/templates/apps/mcp/__tests__/parity.test.ts +205 -0
- package/templates/apps/mcp/__tests__/purchase-disabled.test.ts +34 -0
- package/templates/apps/mcp/__tests__/read_content.test.ts +153 -0
- package/templates/apps/mcp/__tests__/request_callback.test.ts +163 -0
- package/templates/apps/mcp/__tests__/search_content.test.ts +153 -0
- package/templates/apps/mcp/__tests__/server.test.ts +115 -0
- package/templates/apps/mcp/__tests__/submit_lead.test.ts +165 -0
- package/templates/apps/mcp/__tests__/subscribe_newsletter.test.ts +161 -0
- package/templates/apps/mcp/__tests__/tools/purchase.test.ts +227 -0
- package/templates/apps/mcp/__tests__/tools/scaffold.test.ts +237 -0
- package/templates/apps/mcp/__tests__/update_page.test.ts +195 -0
- package/templates/apps/mcp/jest.config.cjs +82 -0
- package/templates/apps/mcp/package.json +37 -0
- package/templates/apps/mcp/src/abuse/daily-cap.ts +47 -0
- package/templates/apps/mcp/src/abuse/email-validator.ts +25 -0
- package/templates/apps/mcp/src/abuse/honeypot.ts +21 -0
- package/templates/apps/mcp/src/abuse/index.ts +111 -0
- package/templates/apps/mcp/src/abuse/user-agent-deny.ts +58 -0
- package/templates/apps/mcp/src/http-transport.ts +303 -0
- package/templates/apps/mcp/src/index.ts +67 -0
- package/templates/apps/mcp/src/lib/audit-single-page.ts +194 -0
- package/templates/apps/mcp/src/lib/errors.ts +61 -0
- package/templates/apps/mcp/src/lib/locales.ts +171 -0
- package/templates/apps/mcp/src/lib/require-paid-tier.ts +44 -0
- package/templates/apps/mcp/src/lib/resolve-locale.ts +30 -0
- package/templates/apps/mcp/src/server.ts +139 -0
- package/templates/apps/mcp/src/tools/audit.ts +103 -0
- package/templates/apps/mcp/src/tools/capture_lead.ts +52 -0
- package/templates/apps/mcp/src/tools/create_page.ts +95 -0
- package/templates/apps/mcp/src/tools/delete_page.ts +73 -0
- package/templates/apps/mcp/src/tools/get_business_hours.ts +66 -0
- package/templates/apps/mcp/src/tools/get_faq.ts +69 -0
- package/templates/apps/mcp/src/tools/get_locations.ts +85 -0
- package/templates/apps/mcp/src/tools/get_offerings.ts +66 -0
- package/templates/apps/mcp/src/tools/get_pricing.ts +74 -0
- package/templates/apps/mcp/src/tools/get_site_info.ts +84 -0
- package/templates/apps/mcp/src/tools/index.ts +125 -0
- package/templates/apps/mcp/src/tools/list_pages.ts +72 -0
- package/templates/apps/mcp/src/tools/purchase.ts +89 -0
- package/templates/apps/mcp/src/tools/read_content.ts +61 -0
- package/templates/apps/mcp/src/tools/request_callback.ts +51 -0
- package/templates/apps/mcp/src/tools/scaffold.ts +119 -0
- package/templates/apps/mcp/src/tools/search_content.ts +59 -0
- package/templates/apps/mcp/src/tools/subscribe_newsletter.ts +47 -0
- package/templates/apps/mcp/src/tools/update_page.ts +91 -0
- package/templates/apps/mcp/tsconfig.json +19 -0
- package/templates/apps/web/.env.example +47 -0
- package/templates/apps/web/CLAUDE.md +81 -0
- package/templates/apps/web/__tests__/auth/adversarial/cookie-attributes.test.ts +94 -0
- package/templates/apps/web/__tests__/auth/adversarial/oauth-state-parameter.test.ts +75 -0
- package/templates/apps/web/__tests__/auth/adversarial/redirect-uri-allowlist.test.ts +82 -0
- package/templates/apps/web/__tests__/auth/env-helpers.test.ts +168 -0
- package/templates/apps/web/__tests__/authority-list-routes.test.tsx +208 -0
- package/templates/apps/web/__tests__/better-stack.test.ts +66 -0
- package/templates/apps/web/__tests__/blog-dir-resolution.test.ts +87 -0
- package/templates/apps/web/__tests__/blog-source-populated.test.ts +130 -0
- package/templates/apps/web/__tests__/data-testid-coverage.test.tsx +60 -0
- package/templates/apps/web/__tests__/google-analytics.test.tsx +104 -0
- package/templates/apps/web/__tests__/i18n/middleware.test.ts +119 -0
- package/templates/apps/web/__tests__/i18n/routing.test.ts +114 -0
- package/templates/apps/web/__tests__/i18n/translations.test.ts +191 -0
- package/templates/apps/web/__tests__/json-ld.test.ts +98 -0
- package/templates/apps/web/__tests__/knowledge-events-routes.test.tsx +580 -0
- package/templates/apps/web/__tests__/layout-stealth.test.ts +39 -0
- package/templates/apps/web/__tests__/lighthouse-fixtures/improvement-image-shrink.tsx +103 -0
- package/templates/apps/web/__tests__/lighthouse-fixtures/override-fixture.md +114 -0
- package/templates/apps/web/__tests__/lighthouse-fixtures/regression-bloat.tsx +94 -0
- package/templates/apps/web/__tests__/page.test.tsx +230 -0
- package/templates/apps/web/__tests__/products-services-phase1.test.tsx +321 -0
- package/templates/apps/web/__tests__/projects-routes.test.tsx +392 -0
- package/templates/apps/web/__tests__/resources-downloads-integrations-phase2.test.tsx +475 -0
- package/templates/apps/web/__tests__/routes/ai-plugin-json.test.ts +53 -0
- package/templates/apps/web/__tests__/routes/blog-route.test.tsx +191 -0
- package/templates/apps/web/__tests__/routes/llms-txt.test.ts +123 -0
- package/templates/apps/web/__tests__/routes/robots-txt.test.ts +52 -0
- package/templates/apps/web/__tests__/routes/sitemap-xml.test.ts +78 -0
- package/templates/apps/web/__tests__/routes/well-known-mcp.test.ts +203 -0
- package/templates/apps/web/__tests__/section-routes.test.tsx +693 -0
- package/templates/apps/web/__tests__/security-headers.test.ts +201 -0
- package/templates/apps/web/__tests__/sentry-config.test.ts +116 -0
- package/templates/apps/web/__tests__/setup.ts +82 -0
- package/templates/apps/web/__tests__/sitemap-locales.test.ts +415 -0
- package/templates/apps/web/__tests__/standalone-informational-routes.test.tsx +844 -0
- package/templates/apps/web/app/.well-known/ai-plugin.json/route.ts +81 -0
- package/templates/apps/web/app/.well-known/mcp.json/build-manifest.ts +110 -0
- package/templates/apps/web/app/.well-known/mcp.json/route.ts +58 -0
- package/templates/apps/web/app/[locale]/__tests__/layout.test.tsx +120 -0
- package/templates/apps/web/app/[locale]/__tests__/page-renderer-migration.test.tsx +202 -0
- package/templates/apps/web/app/[locale]/about/page.tsx +31 -0
- package/templates/apps/web/app/[locale]/blog/[[...slug]]/page.tsx +173 -0
- package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +45 -0
- package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +117 -0
- package/templates/apps/web/app/[locale]/careers/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +44 -0
- package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +113 -0
- package/templates/apps/web/app/[locale]/case-studies/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +63 -0
- package/templates/apps/web/app/[locale]/clients/page.tsx +27 -0
- package/templates/apps/web/app/[locale]/contact/ContactForm.tsx +130 -0
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +152 -0
- package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +92 -0
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +79 -0
- package/templates/apps/web/app/[locale]/contact/error.tsx +24 -0
- package/templates/apps/web/app/[locale]/contact/page.tsx +38 -0
- package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +34 -0
- package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +119 -0
- package/templates/apps/web/app/[locale]/courses/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/dev/purchase/__tests__/actions.test.ts +160 -0
- package/templates/apps/web/app/[locale]/dev/purchase/error.tsx +25 -0
- package/templates/apps/web/app/[locale]/dev/purchase/page.tsx +117 -0
- package/templates/apps/web/app/[locale]/dev/purchase/purchase.actions.ts +58 -0
- package/templates/apps/web/app/[locale]/docs/[[...slug]]/page.tsx +118 -0
- package/templates/apps/web/app/[locale]/downloads/__tests__/page-renderer-migration.test.tsx +72 -0
- package/templates/apps/web/app/[locale]/downloads/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +47 -0
- package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +130 -0
- package/templates/apps/web/app/[locale]/events/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/faq/page.tsx +36 -0
- package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +34 -0
- package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +78 -0
- package/templates/apps/web/app/[locale]/how-to/page.tsx +40 -0
- package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +43 -0
- package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +129 -0
- package/templates/apps/web/app/[locale]/integrations/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/launch-service/page.tsx +31 -0
- package/templates/apps/web/app/[locale]/layout.tsx +241 -0
- package/templates/apps/web/app/[locale]/page.tsx +41 -0
- package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +44 -0
- package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +113 -0
- package/templates/apps/web/app/[locale]/partners/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +43 -0
- package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +129 -0
- package/templates/apps/web/app/[locale]/products/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +39 -0
- package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +138 -0
- package/templates/apps/web/app/[locale]/projects/page.tsx +30 -0
- package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +51 -0
- package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +117 -0
- package/templates/apps/web/app/[locale]/resources/page.tsx +27 -0
- package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +43 -0
- package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +129 -0
- package/templates/apps/web/app/[locale]/services/page.tsx +25 -0
- package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +34 -0
- package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +81 -0
- package/templates/apps/web/app/[locale]/software/page.tsx +39 -0
- package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +34 -0
- package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +82 -0
- package/templates/apps/web/app/[locale]/tech-articles/page.tsx +39 -0
- package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +63 -0
- package/templates/apps/web/app/[locale]/testimonials/page.tsx +27 -0
- package/templates/apps/web/app/[locale]/use-cases/__tests__/page-renderer-migration.test.tsx +63 -0
- package/templates/apps/web/app/[locale]/use-cases/page.tsx +27 -0
- package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +34 -0
- package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +82 -0
- package/templates/apps/web/app/[locale]/whitepapers/page.tsx +39 -0
- package/templates/apps/web/app/__tests__/error-boundaries.test.tsx +152 -0
- package/templates/apps/web/app/api/auth/[...all]/route.ts +16 -0
- package/templates/apps/web/app/error-fallback.tsx +75 -0
- package/templates/apps/web/app/error.tsx +23 -0
- package/templates/apps/web/app/layout.tsx +18 -0
- package/templates/apps/web/app/llms.txt/route.ts +101 -0
- package/templates/apps/web/app/not-found.tsx +48 -0
- package/templates/apps/web/app/og/__tests__/route.test.ts +164 -0
- package/templates/apps/web/app/og/route.tsx +135 -0
- package/templates/apps/web/app/robots.txt/route.ts +36 -0
- package/templates/apps/web/app/sitemap.xml/route.ts +146 -0
- package/templates/apps/web/auth.ts +141 -0
- package/templates/apps/web/components/ThemeToggle.tsx +60 -0
- package/templates/apps/web/components/google-analytics.tsx +34 -0
- package/templates/apps/web/content/en/blog/index.mdx +15 -0
- package/templates/apps/web/content/en/blog/launching-ailk.mdx +20 -0
- package/templates/apps/web/content/en/docs/getting-started.mdx +30 -0
- package/templates/apps/web/i18n/request.ts +36 -0
- package/templates/apps/web/jest.config.cjs +100 -0
- package/templates/apps/web/lib/__mocks__/next-mdx-remote-rsc.js +12 -0
- package/templates/apps/web/lib/__mocks__/source-server.js +31 -0
- package/templates/apps/web/lib/__tests__/og.test.ts +65 -0
- package/templates/apps/web/lib/auth-env.ts +66 -0
- package/templates/apps/web/lib/blog-list-data.ts +95 -0
- package/templates/apps/web/lib/blog-post-data.ts +79 -0
- package/templates/apps/web/lib/nav-config.ts +13 -0
- package/templates/apps/web/lib/observability/better-stack.ts +27 -0
- package/templates/apps/web/lib/og.ts +23 -0
- package/templates/apps/web/lib/prisma-for-auth.ts +34 -0
- package/templates/apps/web/lib/source.ts +34 -0
- package/templates/apps/web/messages/en.json +131 -0
- package/templates/apps/web/middleware.ts +80 -0
- package/templates/apps/web/next.config.mjs +167 -0
- package/templates/apps/web/package.json +62 -0
- package/templates/apps/web/public/.well-known/security.txt +17 -0
- package/templates/apps/web/public/android-chrome-192x192.png +0 -0
- package/templates/apps/web/public/android-chrome-512x512.png +0 -0
- package/templates/apps/web/public/apple-touch-icon.png +0 -0
- package/templates/apps/web/public/favicon-16x16.png +0 -0
- package/templates/apps/web/public/favicon-32x32.png +0 -0
- package/templates/apps/web/public/favicon.ico +0 -0
- package/templates/apps/web/public/favicon.svg +4 -0
- package/templates/apps/web/public/logo-dark.svg +21 -0
- package/templates/apps/web/public/logo-light.svg +21 -0
- package/templates/apps/web/public/logomark-dark.svg +4 -0
- package/templates/apps/web/public/logomark-light.svg +4 -0
- package/templates/apps/web/public/og-default.png +0 -0
- package/templates/apps/web/public/site.webmanifest +19 -0
- package/templates/apps/web/scripts/assert-content-bundled.ts +55 -0
- package/templates/apps/web/security-headers.config.ts +132 -0
- package/templates/apps/web/sentry.client.config.ts +27 -0
- package/templates/apps/web/sentry.edge.config.ts +15 -0
- package/templates/apps/web/sentry.server.config.ts +20 -0
- package/templates/apps/web/source.config.ts +78 -0
- package/templates/apps/web/src/components/SiteNav.tsx +21 -0
- package/templates/apps/web/src/lib/routes.ts +37 -0
- package/templates/apps/web/tsconfig.json +35 -0
- package/templates/apps/web/types/messages.d.ts +19 -0
- package/templates/content/.gitkeep +0 -0
- package/templates/content/CLAUDE.md +85 -0
- package/templates/content/_site.mdx +38 -0
- package/templates/content/ar/HomePage/home.mdx +123 -0
- package/templates/content/ar/_site.mdx +35 -0
- package/templates/content/de/_site.mdx +29 -0
- package/templates/content/en/.gitkeep +0 -0
- package/templates/content/en/AboutPage/about.mdx +19 -0
- package/templates/content/en/AboutPage/about.schema.json +82 -0
- package/templates/content/en/BookCall/book-call.mdx +19 -0
- package/templates/content/en/BookCall/book-call.schema.json +121 -0
- package/templates/content/en/BreadcrumbList/site-breadcrumbs.mdx +20 -0
- package/templates/content/en/CareersList/careers.mdx +24 -0
- package/templates/content/en/CaseStudiesList/case-studies.mdx +22 -0
- package/templates/content/en/CaseStudiesList/showcase.mdx +8 -0
- package/templates/content/en/CaseStudy/ailk-aeo-rollout.mdx +32 -0
- package/templates/content/en/CaseStudy/schema-builder-migration.mdx +41 -0
- package/templates/content/en/ClientsList/clients.mdx +38 -0
- package/templates/content/en/ContactPage/contact.mdx +19 -0
- package/templates/content/en/ContactPage/contact.schema.json +100 -0
- package/templates/content/en/ContactPoint/primary.mdx +14 -0
- package/templates/content/en/Course/aeo-fundamentals.mdx +37 -0
- package/templates/content/en/Course/schema-builder-workshop.mdx +62 -0
- package/templates/content/en/CoursesList/courses.mdx +22 -0
- package/templates/content/en/DownloadsList/downloads.mdx +22 -0
- package/templates/content/en/Event/aeo-office-hours-may-2026.mdx +39 -0
- package/templates/content/en/Event/ailk-launch-day-2026.mdx +35 -0
- package/templates/content/en/EventsList/events.mdx +26 -0
- package/templates/content/en/FAQPage/faq.mdx +420 -0
- package/templates/content/en/FAQPage/faq.schema.json +231 -0
- package/templates/content/en/GlossaryList/glossary.mdx +19 -0
- package/templates/content/en/GlossaryList/glossary.schema.json +300 -0
- package/templates/content/en/HomePage/home.mdx +312 -0
- package/templates/content/en/HomePage/home.schema.json +88 -0
- package/templates/content/en/HomePage/launch-service.mdx +475 -0
- package/templates/content/en/HomePage/launch-service.schema.json +138 -0
- package/templates/content/en/HowTo/add-mdx-content.mdx +38 -0
- package/templates/content/en/HowTo/configure-aeo-scoring.mdx +35 -0
- package/templates/content/en/HowTo/set-up-json-ld.mdx +36 -0
- package/templates/content/en/Integration/github-actions.mdx +31 -0
- package/templates/content/en/Integration/openai-api.mdx +26 -0
- package/templates/content/en/Integration/vercel.mdx +32 -0
- package/templates/content/en/IntegrationsList/integrations.mdx +22 -0
- package/templates/content/en/JobPosting/content-strategist.mdx +46 -0
- package/templates/content/en/JobPosting/developer-advocate.mdx +47 -0
- package/templates/content/en/JobPosting/senior-fullstack-engineer.mdx +57 -0
- package/templates/content/en/LandingPage/aeo-audit.mdx +19 -0
- package/templates/content/en/LandingPage/aeo-audit.schema.json +92 -0
- package/templates/content/en/LandingPage/agency-waitlist.mdx +340 -0
- package/templates/content/en/LandingPage/agency-waitlist.schema.json +152 -0
- package/templates/content/en/LandingPage/developers.mdx +19 -0
- package/templates/content/en/LandingPage/developers.schema.json +109 -0
- package/templates/content/en/LandingPage/for-agencies.mdx +390 -0
- package/templates/content/en/LandingPage/for-agencies.schema.json +107 -0
- package/templates/content/en/LandingPage/for-ai-search-agencies.mdx +417 -0
- package/templates/content/en/LandingPage/for-ai-search-agencies.schema.json +105 -0
- package/templates/content/en/LandingPage/for-businesses.mdx +19 -0
- package/templates/content/en/LandingPage/for-businesses.schema.json +96 -0
- package/templates/content/en/LandingPage/platform.mdx +369 -0
- package/templates/content/en/LandingPage/platform.schema.json +166 -0
- package/templates/content/en/LandingPage/vs-ai-website-builders.mdx +19 -0
- package/templates/content/en/LandingPage/vs-ai-website-builders.schema.json +102 -0
- package/templates/content/en/LandingPage/vs-wordpress.mdx +19 -0
- package/templates/content/en/LandingPage/vs-wordpress.schema.json +53 -0
- package/templates/content/en/NewsletterSignup/newsletter.mdx +236 -0
- package/templates/content/en/NewsletterSignup/newsletter.schema.json +91 -0
- package/templates/content/en/Organization/site-owner.mdx +16 -0
- package/templates/content/en/Partner/prisma.mdx +31 -0
- package/templates/content/en/Partner/supabase.mdx +30 -0
- package/templates/content/en/Partner/vercel.mdx +28 -0
- package/templates/content/en/PartnersList/partners.mdx +22 -0
- package/templates/content/en/Person/founder.mdx +18 -0
- package/templates/content/en/Pricing/pricing.mdx +538 -0
- package/templates/content/en/Pricing/pricing.schema.json +209 -0
- package/templates/content/en/PrivacyPage/privacy.mdx +165 -0
- package/templates/content/en/PrivacyPage/privacy.schema.json +64 -0
- package/templates/content/en/Product/ailk.mdx +19 -0
- package/templates/content/en/Product/ailk.schema.json +94 -0
- package/templates/content/en/Product/api-launch-kit.mdx +26 -0
- package/templates/content/en/Product/launch-kit.mdx +28 -0
- package/templates/content/en/ProductsList/products.mdx +26 -0
- package/templates/content/en/Project/ailk-phase-2.mdx +54 -0
- package/templates/content/en/ProjectsList/projects.mdx +25 -0
- package/templates/content/en/ResourceDetail/aeo-scoring-guide.mdx +27 -0
- package/templates/content/en/ResourceDetail/content-model-whitepaper.mdx +28 -0
- package/templates/content/en/ResourceDetail/schema-org-quick-reference.mdx +39 -0
- package/templates/content/en/ResourcesHub/resources.mdx +22 -0
- package/templates/content/en/Service/consulting.mdx +22 -0
- package/templates/content/en/Service/implementation.mdx +30 -0
- package/templates/content/en/Service/launch-service.mdx +232 -0
- package/templates/content/en/Service/launch.mdx +228 -0
- package/templates/content/en/ServicesList/services.mdx +84 -0
- package/templates/content/en/SoftwareProduct/ailk-aeo.mdx +44 -0
- package/templates/content/en/SoftwareProduct/ailk-content-adapters.mdx +47 -0
- package/templates/content/en/SoftwareProduct/ailk-schema.mdx +49 -0
- package/templates/content/en/TeamList/team.mdx +63 -0
- package/templates/content/en/TeamMember/founder.mdx +72 -0
- package/templates/content/en/TermsPage/terms.mdx +19 -0
- package/templates/content/en/TermsPage/terms.schema.json +99 -0
- package/templates/content/en/TestimonialsList/testimonials.mdx +44 -0
- package/templates/content/en/UseCasesList/use-cases.mdx +30 -0
- package/templates/content/en/Whitepaper/ax-first-product-development.mdx +27 -0
- package/templates/content/en/Whitepaper/open-core-commercial-strategy.mdx +27 -0
- package/templates/content/en/Whitepaper/structured-data-for-answer-engines.mdx +31 -0
- package/templates/content/en-XA/AboutPage/about.mdx +8 -0
- package/templates/content/en-XA/FAQPage/faq.mdx +8 -0
- package/templates/content/en-XA/HomePage/home.mdx +8 -0
- package/templates/content/es/_site.mdx +30 -0
- package/templates/content/fr/_site.mdx +30 -0
- package/templates/content/ja/_site.mdx +30 -0
- package/templates/content/pt-BR/AboutPage/about.mdx +8 -0
- package/templates/content/pt-BR/FAQPage/faq.mdx +8 -0
- package/templates/content/pt-BR/HomePage/home.mdx +23 -0
- package/templates/database/CHANGELOG.md +5 -0
- package/templates/database/README.md +234 -0
- package/templates/database/__tests__/user-cascade.test.ts +125 -0
- package/templates/database/auth/.gitkeep +0 -0
- package/templates/database/config/.gitkeep +0 -0
- package/templates/database/content/.gitkeep +0 -0
- package/templates/database/inbox/.gitkeep +0 -0
- package/templates/database/inbox/README.md +3 -0
- package/templates/database/inbox/__tests__/schema.test.ts +40 -0
- package/templates/database/inbox/schema.prisma +52 -0
- package/templates/database/jest.config.cjs +29 -0
- package/templates/database/migrations/20260508000000_add_inbox_namespace/migration.sql +328 -0
- package/templates/database/migrations/20260513000000_better_auth_migration/migration.sql +100 -0
- package/templates/database/migrations/20260515000000_add_user_billing_fields/migration.sql +28 -0
- package/templates/database/migrations/20260516000000_add_user_tier_care_plan_seat/migration.sql +25 -0
- package/templates/database/migrations/20260518000000_add_telemetry_records/migration.sql +42 -0
- package/templates/database/migrations/20260525000000_theme_wiring/migration.sql +67 -0
- package/templates/database/migrations/20260710000000_retire_commercial_tier/migration.sql +21 -0
- package/templates/database/migrations/migration_lock.toml +3 -0
- package/templates/database/ops/.gitkeep +0 -0
- package/templates/database/package.json +45 -0
- package/templates/database/prisma.config.ts +20 -0
- package/templates/database/schema.prisma +487 -0
- package/templates/database/scripts/db-generate-locked.sh +80 -0
- package/templates/database/seed-test.ts +85 -0
- package/templates/database/tsconfig.build.json +16 -0
- package/templates/database/tsconfig.json +9 -0
- package/templates/package.json +125 -0
- package/templates/pnpm-workspace.yaml +6 -0
- package/templates/project.yaml +59 -0
- package/templates/tsconfig.base.json +18 -0
- package/templates/tsconfig.json +45 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lead-routing.test.ts
|
|
3
|
+
* @description Unit tests for the lead-routing service (ADR 0009 D3 service-layer pattern).
|
|
4
|
+
*
|
|
5
|
+
* External dependency boundaries mocked:
|
|
6
|
+
* - @working-theory/database (via moduleNameMapper → prisma-client.js mock; prisma singleton via __mocks__/prisma.ts)
|
|
7
|
+
* - @working-theory/email sendLeadNotification
|
|
8
|
+
*
|
|
9
|
+
* Internal modules run real:
|
|
10
|
+
* - apps/api/src/services/enrichment-shim — real; @working-theory/license catches + returns lead unchanged
|
|
11
|
+
* - apps/api/src/lib/file-fallback — real; uses AILK_INBOX_FALLBACK_DIR temp dir set per test
|
|
12
|
+
* - apps/api/src/lib/prisma — uses __mocks__/prisma.ts (manual mock via jest.mock without factory)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { RouteLeadResult } from "../lead-routing";
|
|
16
|
+
|
|
17
|
+
// ─── Mock: Prisma ─────────────────────────────────────────────────────────────
|
|
18
|
+
// lib/prisma.ts is a thin wrapper that instantiates PrismaClient (external DB
|
|
19
|
+
// boundary). The manual mock at src/lib/__mocks__/prisma.ts provides a full
|
|
20
|
+
// in-memory stub — this call auto-resolves to that file.
|
|
21
|
+
// eslint-disable-next-line no-restricted-syntax -- lib/prisma.ts wraps the external DB boundary (PrismaClient requires a live connection); __mocks__/prisma.ts is the repo-standard test double for this boundary.
|
|
22
|
+
jest.mock("../../lib/prisma.js");
|
|
23
|
+
|
|
24
|
+
// ─── Mock: email (external boundary) ─────────────────────────────────────────
|
|
25
|
+
const mockSendLeadNotification = jest.fn();
|
|
26
|
+
jest.mock("@working-theory/email", () => ({
|
|
27
|
+
sendLeadNotification: (...args: unknown[]) =>
|
|
28
|
+
mockSendLeadNotification(...args),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
// ─── Import after mocks ───────────────────────────────────────────────────────
|
|
32
|
+
import * as fs from "fs/promises";
|
|
33
|
+
import * as os from "os";
|
|
34
|
+
import * as path from "path";
|
|
35
|
+
|
|
36
|
+
import { prisma } from "../../lib/prisma.js";
|
|
37
|
+
import { routeLead } from "../lead-routing";
|
|
38
|
+
|
|
39
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
40
|
+
const sourceMeta = {
|
|
41
|
+
ip: "127.0.0.1",
|
|
42
|
+
userAgent: "jest",
|
|
43
|
+
receivedAt: new Date().toISOString(),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const leadInput = {
|
|
47
|
+
kind: "lead" as const,
|
|
48
|
+
siteId: "site-abc",
|
|
49
|
+
source: "contact",
|
|
50
|
+
email: "test@example.com",
|
|
51
|
+
payload: { message: "hello" },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const subscribeInput = {
|
|
55
|
+
kind: "subscribe" as const,
|
|
56
|
+
siteId: "site-abc",
|
|
57
|
+
email: "subscriber@example.com",
|
|
58
|
+
source: "footer",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const callbackInput = {
|
|
62
|
+
kind: "callback" as const,
|
|
63
|
+
siteId: "site-abc",
|
|
64
|
+
name: "Alice",
|
|
65
|
+
phone: "+15551234567",
|
|
66
|
+
payload: { notes: "urgent" },
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// ─── Tests ────────────────────────────────────────────────────────────────────
|
|
70
|
+
describe("routeLead", () => {
|
|
71
|
+
let tmpDir: string;
|
|
72
|
+
|
|
73
|
+
beforeAll(async () => {
|
|
74
|
+
// Real file-fallback module uses AILK_INBOX_FALLBACK_DIR for writes.
|
|
75
|
+
// Point it at a temp dir so tests remain hermetic.
|
|
76
|
+
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "ailk-lead-test-"));
|
|
77
|
+
process.env.AILK_INBOX_FALLBACK_DIR = tmpDir;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterAll(async () => {
|
|
81
|
+
delete process.env.AILK_INBOX_FALLBACK_DIR;
|
|
82
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
beforeEach(() => {
|
|
86
|
+
jest.clearAllMocks();
|
|
87
|
+
// Default: DB up, email up
|
|
88
|
+
(prisma.lead.create as jest.Mock).mockResolvedValue({
|
|
89
|
+
id: "cuid-lead-1",
|
|
90
|
+
siteId: "site-abc",
|
|
91
|
+
source: "contact",
|
|
92
|
+
email: "test@example.com",
|
|
93
|
+
payload: {},
|
|
94
|
+
createdAt: new Date(),
|
|
95
|
+
});
|
|
96
|
+
(prisma.subscriber.create as jest.Mock).mockResolvedValue({
|
|
97
|
+
id: "cuid-sub-1",
|
|
98
|
+
siteId: "site-abc",
|
|
99
|
+
email: "subscriber@example.com",
|
|
100
|
+
source: "footer",
|
|
101
|
+
createdAt: new Date(),
|
|
102
|
+
});
|
|
103
|
+
(prisma.callback.create as jest.Mock).mockResolvedValue({
|
|
104
|
+
id: "cuid-cb-1",
|
|
105
|
+
siteId: "site-abc",
|
|
106
|
+
name: "Alice",
|
|
107
|
+
phone: "+15551234567",
|
|
108
|
+
payload: {},
|
|
109
|
+
createdAt: new Date(),
|
|
110
|
+
});
|
|
111
|
+
mockSendLeadNotification.mockResolvedValue({
|
|
112
|
+
ok: true,
|
|
113
|
+
messageId: "msg-123",
|
|
114
|
+
});
|
|
115
|
+
// Set required env
|
|
116
|
+
process.env.AILK_LEAD_NOTIFICATION_TO = "owner@example.com";
|
|
117
|
+
process.env.AILK_LEAD_NOTIFICATION_FROM = "noreply@example.com";
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
afterEach(() => {
|
|
121
|
+
delete process.env.AILK_LEAD_NOTIFICATION_TO;
|
|
122
|
+
delete process.env.AILK_LEAD_NOTIFICATION_FROM;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// ── 1. Happy path lead — DB up, email up ──────────────────────────────────
|
|
126
|
+
it("happy path lead — returns ok:true with persisted:db and email:ok", async () => {
|
|
127
|
+
const result = await routeLead(leadInput, sourceMeta);
|
|
128
|
+
|
|
129
|
+
expect(result).toMatchObject({
|
|
130
|
+
ok: true,
|
|
131
|
+
id: "cuid-lead-1",
|
|
132
|
+
persisted: "db",
|
|
133
|
+
email: { ok: true, messageId: "msg-123" },
|
|
134
|
+
});
|
|
135
|
+
expect(prisma.lead.create).toHaveBeenCalledTimes(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// ── 2. DB down → fallback engages → persisted:file ───────────────────────
|
|
139
|
+
it("DB down → file fallback → persisted:file", async () => {
|
|
140
|
+
(prisma.lead.create as jest.Mock).mockRejectedValue(new Error("connection refused"));
|
|
141
|
+
|
|
142
|
+
const result = (await routeLead(leadInput, sourceMeta)) as Extract<
|
|
143
|
+
RouteLeadResult,
|
|
144
|
+
{ ok: true }
|
|
145
|
+
>;
|
|
146
|
+
|
|
147
|
+
expect(result.ok).toBe(true);
|
|
148
|
+
expect(result.persisted).toBe("file");
|
|
149
|
+
// Verify a file was actually written to the temp dir
|
|
150
|
+
const files = await fs.readdir(tmpDir);
|
|
151
|
+
expect(files.length).toBeGreaterThan(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ── 3. DB down + fallback fails → persist_failed ─────────────────────────
|
|
155
|
+
it("DB down + fallback fails → ok:false persist_failed", async () => {
|
|
156
|
+
(prisma.lead.create as jest.Mock).mockRejectedValue(new Error("db error"));
|
|
157
|
+
// Point fallback at a nonexistent dir so mkdir fails
|
|
158
|
+
process.env.AILK_INBOX_FALLBACK_DIR = "/nonexistent-ailk-test-dir/inbox";
|
|
159
|
+
|
|
160
|
+
const result = (await routeLead(leadInput, sourceMeta)) as Extract<
|
|
161
|
+
RouteLeadResult,
|
|
162
|
+
{ ok: false }
|
|
163
|
+
>;
|
|
164
|
+
|
|
165
|
+
// Restore good temp dir for other tests
|
|
166
|
+
process.env.AILK_INBOX_FALLBACK_DIR = tmpDir;
|
|
167
|
+
|
|
168
|
+
expect(result.ok).toBe(false);
|
|
169
|
+
expect(result.error.kind).toBe("persist_failed");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// ── 4. Email down → persist succeeds, email error returned ───────────────
|
|
173
|
+
it("email failure does NOT roll back DB write — returns ok:true with email error", async () => {
|
|
174
|
+
mockSendLeadNotification.mockResolvedValue({
|
|
175
|
+
ok: false,
|
|
176
|
+
error: { kind: "send_failed", message: "timeout" },
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const result = (await routeLead(leadInput, sourceMeta)) as Extract<
|
|
180
|
+
RouteLeadResult,
|
|
181
|
+
{ ok: true }
|
|
182
|
+
>;
|
|
183
|
+
|
|
184
|
+
expect(result.ok).toBe(true);
|
|
185
|
+
expect(result.persisted).toBe("db");
|
|
186
|
+
expect(result.email).toMatchObject({
|
|
187
|
+
ok: false,
|
|
188
|
+
error: "send_failed: timeout",
|
|
189
|
+
});
|
|
190
|
+
expect(prisma.lead.create).toHaveBeenCalledTimes(1); // DB write happened
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// ── 5. Resend env unset → email skipped ──────────────────────────────────
|
|
194
|
+
it("AILK_LEAD_NOTIFICATION_TO unset → email skipped with reason env_unset", async () => {
|
|
195
|
+
delete process.env.AILK_LEAD_NOTIFICATION_TO;
|
|
196
|
+
|
|
197
|
+
const result = (await routeLead(leadInput, sourceMeta)) as Extract<
|
|
198
|
+
RouteLeadResult,
|
|
199
|
+
{ ok: true }
|
|
200
|
+
>;
|
|
201
|
+
|
|
202
|
+
expect(result.ok).toBe(true);
|
|
203
|
+
expect(result.email).toMatchObject({ skipped: true, reason: "env_unset" });
|
|
204
|
+
expect(mockSendLeadNotification).not.toHaveBeenCalled();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("config_missing from Resend → email coerced to skipped:resend_key_unset", async () => {
|
|
208
|
+
mockSendLeadNotification.mockResolvedValue({
|
|
209
|
+
ok: false,
|
|
210
|
+
error: { kind: "config_missing", message: "RESEND_API_KEY not set" },
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const result = (await routeLead(leadInput, sourceMeta)) as Extract<
|
|
214
|
+
RouteLeadResult,
|
|
215
|
+
{ ok: true }
|
|
216
|
+
>;
|
|
217
|
+
|
|
218
|
+
expect(result.ok).toBe(true);
|
|
219
|
+
expect(result.email).toMatchObject({
|
|
220
|
+
skipped: true,
|
|
221
|
+
reason: "resend_key_unset",
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ── 6. Subscribe duplicate (P2002) → sentinel id, email skipped:duplicate ─
|
|
226
|
+
it("subscribe duplicate P2002 → ok:true with email.skipped.reason duplicate", async () => {
|
|
227
|
+
const p2002 = Object.assign(new Error("Unique constraint"), {
|
|
228
|
+
code: "P2002",
|
|
229
|
+
});
|
|
230
|
+
(prisma.subscriber.create as jest.Mock).mockRejectedValue(p2002);
|
|
231
|
+
(prisma.subscriber.findUnique as jest.Mock).mockResolvedValue({
|
|
232
|
+
id: "existing-sub-id",
|
|
233
|
+
siteId: "site-abc",
|
|
234
|
+
email: "subscriber@example.com",
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const result = (await routeLead(subscribeInput, sourceMeta)) as Extract<
|
|
238
|
+
RouteLeadResult,
|
|
239
|
+
{ ok: true }
|
|
240
|
+
>;
|
|
241
|
+
|
|
242
|
+
expect(result.ok).toBe(true);
|
|
243
|
+
expect(result.id).toBe("existing-sub-id");
|
|
244
|
+
expect(result.persisted).toBe("db");
|
|
245
|
+
expect(result.email).toMatchObject({ skipped: true, reason: "duplicate" });
|
|
246
|
+
expect(mockSendLeadNotification).not.toHaveBeenCalled();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("subscribe duplicate P2002 with lookup miss → sentinel id duplicate-no-id", async () => {
|
|
250
|
+
const p2002 = Object.assign(new Error("Unique constraint"), {
|
|
251
|
+
code: "P2002",
|
|
252
|
+
});
|
|
253
|
+
(prisma.subscriber.create as jest.Mock).mockRejectedValue(p2002);
|
|
254
|
+
(prisma.subscriber.findUnique as jest.Mock).mockResolvedValue(null);
|
|
255
|
+
|
|
256
|
+
const result = (await routeLead(subscribeInput, sourceMeta)) as Extract<
|
|
257
|
+
RouteLeadResult,
|
|
258
|
+
{ ok: true }
|
|
259
|
+
>;
|
|
260
|
+
|
|
261
|
+
expect(result.ok).toBe(true);
|
|
262
|
+
expect(result.id).toBe("duplicate-no-id");
|
|
263
|
+
expect(result.email).toMatchObject({ skipped: true, reason: "duplicate" });
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// ── 7. Validation failure → invalid_input ────────────────────────────────
|
|
267
|
+
it("malformed input (missing email) → ok:false invalid_input", async () => {
|
|
268
|
+
const bad = {
|
|
269
|
+
kind: "lead" as const,
|
|
270
|
+
siteId: "site",
|
|
271
|
+
source: "contact",
|
|
272
|
+
email: "not-an-email",
|
|
273
|
+
payload: {},
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const result = (await routeLead(bad, sourceMeta)) as Extract<
|
|
277
|
+
RouteLeadResult,
|
|
278
|
+
{ ok: false }
|
|
279
|
+
>;
|
|
280
|
+
|
|
281
|
+
expect(result.ok).toBe(false);
|
|
282
|
+
expect(result.error.kind).toBe("invalid_input");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// ── 8. PII non-leak — log spy never sees email/phone/name/payload ─────────
|
|
286
|
+
it("PII non-leak — log output never contains email, phone, name, or payload values", async () => {
|
|
287
|
+
const logLines: string[] = [];
|
|
288
|
+
const infoSpy = jest
|
|
289
|
+
.spyOn(console, "info")
|
|
290
|
+
.mockImplementation((...args) => {
|
|
291
|
+
logLines.push(args.map(String).join(" "));
|
|
292
|
+
});
|
|
293
|
+
const warnSpy = jest
|
|
294
|
+
.spyOn(console, "warn")
|
|
295
|
+
.mockImplementation((...args) => {
|
|
296
|
+
logLines.push(args.map(String).join(" "));
|
|
297
|
+
});
|
|
298
|
+
const logSpy = jest.spyOn(console, "log").mockImplementation((...args) => {
|
|
299
|
+
logLines.push(args.map(String).join(" "));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
await routeLead(leadInput, sourceMeta);
|
|
303
|
+
await routeLead(callbackInput, sourceMeta);
|
|
304
|
+
|
|
305
|
+
const combined = logLines.join("\n");
|
|
306
|
+
|
|
307
|
+
// PII values must not appear in any log output
|
|
308
|
+
expect(combined).not.toContain("test@example.com");
|
|
309
|
+
expect(combined).not.toContain("+15551234567");
|
|
310
|
+
expect(combined).not.toContain("Alice");
|
|
311
|
+
// payload values must not appear
|
|
312
|
+
expect(combined).not.toContain("hello");
|
|
313
|
+
expect(combined).not.toContain("urgent");
|
|
314
|
+
|
|
315
|
+
infoSpy.mockRestore();
|
|
316
|
+
warnSpy.mockRestore();
|
|
317
|
+
logSpy.mockRestore();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// ── Callback happy path ───────────────────────────────────────────────────
|
|
321
|
+
it("callback happy path → persisted:db", async () => {
|
|
322
|
+
const result = (await routeLead(callbackInput, sourceMeta)) as Extract<
|
|
323
|
+
RouteLeadResult,
|
|
324
|
+
{ ok: true }
|
|
325
|
+
>;
|
|
326
|
+
|
|
327
|
+
expect(result.ok).toBe(true);
|
|
328
|
+
expect(result.id).toBe("cuid-cb-1");
|
|
329
|
+
expect(result.persisted).toBe("db");
|
|
330
|
+
expect(prisma.callback.create).toHaveBeenCalledTimes(1);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// ── routeLead never throws ────────────────────────────────────────────────
|
|
334
|
+
it("routeLead never throws even when all dependencies fail", async () => {
|
|
335
|
+
(prisma.lead.create as jest.Mock).mockRejectedValue(new Error("db down"));
|
|
336
|
+
// Point fallback at a bad dir so file write also fails
|
|
337
|
+
process.env.AILK_INBOX_FALLBACK_DIR = "/nonexistent-ailk-test-dir-2/inbox";
|
|
338
|
+
|
|
339
|
+
// Should not throw — returns ok:false instead
|
|
340
|
+
await expect(routeLead(leadInput, sourceMeta)).resolves.toBeDefined();
|
|
341
|
+
|
|
342
|
+
// Restore
|
|
343
|
+
process.env.AILK_INBOX_FALLBACK_DIR = tmpDir;
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// ── Regression: HIGH-1 — extra field in input must not be passed through ──
|
|
347
|
+
// The route handler must NOT spread unknown fields from the request body into
|
|
348
|
+
// the service call. The service's Zod validation via .strict() must reject
|
|
349
|
+
// unknown keys; the id field is controlled server-side only.
|
|
350
|
+
it("regression HIGH-1: input with extra 'id' field is rejected by strict schema validation", async () => {
|
|
351
|
+
const inputWithExtraId = {
|
|
352
|
+
kind: "lead" as const,
|
|
353
|
+
siteId: "site-abc",
|
|
354
|
+
source: "contact",
|
|
355
|
+
email: "test@example.com",
|
|
356
|
+
payload: { message: "hello" },
|
|
357
|
+
id: "attacker-supplied-id", // extra field — must be rejected by .strict()
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// .strict() on leadSubmitSchema rejects unknown keys → invalid_input
|
|
361
|
+
// Omit the extra `id` field from the type so only one cast is needed.
|
|
362
|
+
const { id: _id, ...inputWithoutId } = inputWithExtraId;
|
|
363
|
+
const inputForService = {
|
|
364
|
+
...inputWithoutId,
|
|
365
|
+
// Re-attach as a plain unknown property so Zod's strict() can reject it.
|
|
366
|
+
...({"id": inputWithExtraId.id} as Record<string, unknown>),
|
|
367
|
+
} as Parameters<typeof routeLead>[0];
|
|
368
|
+
const result = (await routeLead(inputForService, sourceMeta)) as Extract<RouteLeadResult, { ok: false }>;
|
|
369
|
+
|
|
370
|
+
expect(result.ok).toBe(false);
|
|
371
|
+
expect(result.error.kind).toBe("invalid_input");
|
|
372
|
+
// The DB must not have been called with an attacker-supplied id
|
|
373
|
+
expect(prisma.lead.create).not.toHaveBeenCalled();
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// ── Regression: MEDIUM-4 — CRLF injection in siteId must be rejected ─────
|
|
377
|
+
// siteId is constrained to /^[a-zA-Z0-9._-]+$/ which excludes \r\n.
|
|
378
|
+
it("regression MEDIUM-4: CRLF injection in siteId returns invalid_input", async () => {
|
|
379
|
+
const inputWithCrlf = {
|
|
380
|
+
kind: "subscribe" as const,
|
|
381
|
+
siteId: "x\r\nBcc: attacker@x.com", // header injection attempt
|
|
382
|
+
email: "victim@example.com",
|
|
383
|
+
source: "footer",
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const result = (await routeLead(inputWithCrlf, sourceMeta)) as Extract<
|
|
387
|
+
RouteLeadResult,
|
|
388
|
+
{ ok: false }
|
|
389
|
+
>;
|
|
390
|
+
|
|
391
|
+
expect(result.ok).toBe(false);
|
|
392
|
+
expect(result.error.kind).toBe("invalid_input");
|
|
393
|
+
expect(prisma.subscriber.create).not.toHaveBeenCalled();
|
|
394
|
+
});
|
|
395
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file enrichment-shim.ts
|
|
3
|
+
* @description License-gated lead enrichment stub.
|
|
4
|
+
*
|
|
5
|
+
* Today: checkLicense()-gated branch — log a deduped sentinel for pro tier, return
|
|
6
|
+
* lead unchanged. Phase 3: real enrichment replaces this file; the call site
|
|
7
|
+
* (B6 lead-routing pipeline) stays stable.
|
|
8
|
+
*
|
|
9
|
+
* ADR 0008: license key is never logged raw — only the SHA-256 hash prefix
|
|
10
|
+
* (first 8 chars) appears in log output.
|
|
11
|
+
* ADR 0009 §D3: service-layer placement at apps/api/src/services/.
|
|
12
|
+
* ADR 0014: license is a JWT verified locally; tier read via `result.tier`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createHash } from "crypto";
|
|
16
|
+
|
|
17
|
+
import { checkLicense } from "@working-theory/license";
|
|
18
|
+
import { logger } from "@working-theory/observability";
|
|
19
|
+
// TODO(#214): swap to canonical Lead from @working-theory/validation when B1 lands.
|
|
20
|
+
import type { CreateLead as Lead } from "@working-theory/validation";
|
|
21
|
+
|
|
22
|
+
// Routes the once-per-process Pro sentinel through @working-theory/observability so it
|
|
23
|
+
// shares the redact + entropy pipeline (S17). The signature stays unchanged.
|
|
24
|
+
|
|
25
|
+
type EnrichedLead = Lead & { _enrichedAt?: string }; // type union shape; today equals Lead
|
|
26
|
+
|
|
27
|
+
// Module-scoped sentinel flag — one log per process lifecycle. Process restart re-arms it.
|
|
28
|
+
let proSentinelLogged = false;
|
|
29
|
+
|
|
30
|
+
function hashPrefix(key: string): string {
|
|
31
|
+
return createHash("sha256").update(key).digest("hex").substring(0, 8);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function enrichLead(lead: Lead): Promise<EnrichedLead | Lead> {
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = await checkLicense();
|
|
38
|
+
} catch {
|
|
39
|
+
return lead;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (result.tier === "pro" && !proSentinelLogged) {
|
|
43
|
+
const key = process.env["AILK_LICENSE_KEY"];
|
|
44
|
+
const prefix = key ? hashPrefix(key) : "no-key";
|
|
45
|
+
logger.info(
|
|
46
|
+
{ licensePrefix: prefix },
|
|
47
|
+
"[enrichment-shim] Pro server processing not yet operational — falling back to OSS path",
|
|
48
|
+
);
|
|
49
|
+
proSentinelLogged = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return lead;
|
|
53
|
+
}
|