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,486 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import { userRoutes } from '../user';
|
|
3
|
+
|
|
4
|
+
// Mock Prisma — lib/prisma.ts wraps the external DB boundary (PrismaClient
|
|
5
|
+
// requires a live connection). This call auto-resolves to the manual mock at
|
|
6
|
+
// src/lib/__mocks__/prisma.ts which covers user/userData/apiToken models.
|
|
7
|
+
// 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.
|
|
8
|
+
jest.mock('../../../lib/prisma.js');
|
|
9
|
+
|
|
10
|
+
import { prisma } from '../../../lib/prisma.js';
|
|
11
|
+
|
|
12
|
+
// Helper to create authenticated request
|
|
13
|
+
function createAuthenticatedRequest(userId: string) {
|
|
14
|
+
return {
|
|
15
|
+
userId,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('User Routes', () => {
|
|
20
|
+
let app: FastifyInstance;
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
const fastify = require('fastify')();
|
|
24
|
+
// Add userId decorator for testing
|
|
25
|
+
fastify.decorateRequest('userId', null);
|
|
26
|
+
await fastify.register(userRoutes);
|
|
27
|
+
app = fastify;
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(async () => {
|
|
32
|
+
await app.close();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('GET /v1/user/profile', () => {
|
|
36
|
+
it('should return 401 when user is not authenticated', async () => {
|
|
37
|
+
// ACT
|
|
38
|
+
const response = await app.inject({
|
|
39
|
+
method: 'GET',
|
|
40
|
+
url: '/v1/user/profile',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ASSERT
|
|
44
|
+
expect(response.statusCode).toBe(401);
|
|
45
|
+
const body = JSON.parse(response.body);
|
|
46
|
+
expect(body.success).toBe(false);
|
|
47
|
+
expect(body.error).toBe('Authentication required');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should return user profile when authenticated', async () => {
|
|
51
|
+
// ARRANGE
|
|
52
|
+
const mockUser = {
|
|
53
|
+
id: 'user_123',
|
|
54
|
+
email: 'test@example.com',
|
|
55
|
+
name: 'Test User',
|
|
56
|
+
image: null,
|
|
57
|
+
role: 'USER',
|
|
58
|
+
createdAt: new Date(),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
(prisma.user.findUnique as jest.Mock).mockResolvedValue(mockUser);
|
|
62
|
+
|
|
63
|
+
// Create a new app instance with userId set via hook
|
|
64
|
+
const fastify2 = require('fastify')();
|
|
65
|
+
fastify2.decorateRequest('userId', null);
|
|
66
|
+
|
|
67
|
+
// Add preHandler to set userId
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
69
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
70
|
+
request.userId = 'user_123';
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await fastify2.register(userRoutes);
|
|
74
|
+
|
|
75
|
+
// ACT
|
|
76
|
+
const response = await fastify2.inject({
|
|
77
|
+
method: 'GET',
|
|
78
|
+
url: '/v1/user/profile',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// ASSERT
|
|
82
|
+
expect(response.statusCode).toBe(200);
|
|
83
|
+
const body = JSON.parse(response.body);
|
|
84
|
+
expect(body.success).toBe(true);
|
|
85
|
+
expect(body.data.id).toBe('user_123');
|
|
86
|
+
|
|
87
|
+
await fastify2.close();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should return 404 when user is not found', async () => {
|
|
91
|
+
// ARRANGE
|
|
92
|
+
(prisma.user.findUnique as jest.Mock).mockResolvedValue(null);
|
|
93
|
+
|
|
94
|
+
const fastify2 = require('fastify')();
|
|
95
|
+
fastify2.decorateRequest('userId', null);
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
97
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
98
|
+
request.userId = 'user_123';
|
|
99
|
+
});
|
|
100
|
+
await fastify2.register(userRoutes);
|
|
101
|
+
|
|
102
|
+
// ACT
|
|
103
|
+
const response = await fastify2.inject({
|
|
104
|
+
method: 'GET',
|
|
105
|
+
url: '/v1/user/profile',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ASSERT
|
|
109
|
+
expect(response.statusCode).toBe(404);
|
|
110
|
+
const body = JSON.parse(response.body);
|
|
111
|
+
expect(body.success).toBe(false);
|
|
112
|
+
expect(body.error).toBe('User not found');
|
|
113
|
+
|
|
114
|
+
await fastify2.close();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should return 500 on database error', async () => {
|
|
118
|
+
// ARRANGE
|
|
119
|
+
(prisma.user.findUnique as jest.Mock).mockRejectedValue(
|
|
120
|
+
new Error('Database error')
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const fastify2 = require('fastify')();
|
|
124
|
+
fastify2.decorateRequest('userId', null);
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
126
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
127
|
+
request.userId = 'user_123';
|
|
128
|
+
});
|
|
129
|
+
await fastify2.register(userRoutes);
|
|
130
|
+
|
|
131
|
+
// ACT
|
|
132
|
+
const response = await fastify2.inject({
|
|
133
|
+
method: 'GET',
|
|
134
|
+
url: '/v1/user/profile',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// ASSERT
|
|
138
|
+
expect(response.statusCode).toBe(500);
|
|
139
|
+
|
|
140
|
+
await fastify2.close();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('PATCH /v1/user/profile', () => {
|
|
145
|
+
it('should return 401 when user is not authenticated', async () => {
|
|
146
|
+
const response = await app.inject({
|
|
147
|
+
method: 'PATCH',
|
|
148
|
+
url: '/v1/user/profile',
|
|
149
|
+
payload: { name: 'New Name' },
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(response.statusCode).toBe(401);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should update user profile with valid data', async () => {
|
|
156
|
+
// ARRANGE
|
|
157
|
+
const updatedUser = {
|
|
158
|
+
id: 'user_123',
|
|
159
|
+
email: 'test@example.com',
|
|
160
|
+
name: 'New Name',
|
|
161
|
+
image: 'https://example.com/avatar.jpg',
|
|
162
|
+
role: 'USER',
|
|
163
|
+
updatedAt: new Date(),
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
(prisma.user.update as jest.Mock).mockResolvedValue(updatedUser);
|
|
167
|
+
|
|
168
|
+
const fastify2 = require('fastify')();
|
|
169
|
+
fastify2.decorateRequest('userId', null);
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
171
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
172
|
+
request.userId = 'user_123';
|
|
173
|
+
});
|
|
174
|
+
await fastify2.register(userRoutes);
|
|
175
|
+
|
|
176
|
+
// ACT
|
|
177
|
+
const response = await fastify2.inject({
|
|
178
|
+
method: 'PATCH',
|
|
179
|
+
url: '/v1/user/profile',
|
|
180
|
+
payload: { name: 'New Name', image: 'https://example.com/avatar.jpg' },
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ASSERT
|
|
184
|
+
expect(response.statusCode).toBe(200);
|
|
185
|
+
expect(prisma.user.update).toHaveBeenCalledWith({
|
|
186
|
+
where: { id: 'user_123' },
|
|
187
|
+
data: { name: 'New Name', image: 'https://example.com/avatar.jpg' },
|
|
188
|
+
select: expect.any(Object),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await fastify2.close();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should return 400 on validation error', async () => {
|
|
195
|
+
const fastify2 = require('fastify')();
|
|
196
|
+
fastify2.decorateRequest('userId', null);
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
198
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
199
|
+
request.userId = 'user_123';
|
|
200
|
+
});
|
|
201
|
+
await fastify2.register(userRoutes);
|
|
202
|
+
|
|
203
|
+
const response = await fastify2.inject({
|
|
204
|
+
method: 'PATCH',
|
|
205
|
+
url: '/v1/user/profile',
|
|
206
|
+
payload: { image: 'not-a-url' }, // Invalid URL
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(response.statusCode).toBe(400);
|
|
210
|
+
|
|
211
|
+
await fastify2.close();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should return 500 on non-ZodError database error', async () => {
|
|
215
|
+
// ARRANGE — throw a plain Error (not ZodError) to hit the 500 branch
|
|
216
|
+
(prisma.user.update as jest.Mock).mockRejectedValue(
|
|
217
|
+
new Error('DB connection lost')
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const fastify2 = require('fastify')();
|
|
221
|
+
fastify2.decorateRequest('userId', null);
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
223
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
224
|
+
request.userId = 'user_123';
|
|
225
|
+
});
|
|
226
|
+
await fastify2.register(userRoutes);
|
|
227
|
+
|
|
228
|
+
// ACT
|
|
229
|
+
const response = await fastify2.inject({
|
|
230
|
+
method: 'PATCH',
|
|
231
|
+
url: '/v1/user/profile',
|
|
232
|
+
payload: { name: 'New Name' },
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// ASSERT
|
|
236
|
+
expect(response.statusCode).toBe(500);
|
|
237
|
+
const body = JSON.parse(response.body);
|
|
238
|
+
expect(body.success).toBe(false);
|
|
239
|
+
expect(body.error).toBe('Internal server error');
|
|
240
|
+
|
|
241
|
+
await fastify2.close();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe('GET /v1/user/data/:key', () => {
|
|
246
|
+
it('should return 401 when user is not authenticated', async () => {
|
|
247
|
+
const response = await app.inject({
|
|
248
|
+
method: 'GET',
|
|
249
|
+
url: '/v1/user/data/preferences',
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(response.statusCode).toBe(401);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should return user data when found', async () => {
|
|
256
|
+
// ARRANGE
|
|
257
|
+
const mockUserData = {
|
|
258
|
+
userId: 'user_123',
|
|
259
|
+
key: 'preferences',
|
|
260
|
+
value: { theme: 'dark' },
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
(prisma.userData.findUnique as jest.Mock).mockResolvedValue(mockUserData);
|
|
264
|
+
|
|
265
|
+
const fastify2 = require('fastify')();
|
|
266
|
+
fastify2.decorateRequest('userId', null);
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
268
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
269
|
+
request.userId = 'user_123';
|
|
270
|
+
});
|
|
271
|
+
await fastify2.register(userRoutes);
|
|
272
|
+
|
|
273
|
+
// ACT
|
|
274
|
+
const response = await fastify2.inject({
|
|
275
|
+
method: 'GET',
|
|
276
|
+
url: '/v1/user/data/preferences',
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// ASSERT
|
|
280
|
+
expect(response.statusCode).toBe(200);
|
|
281
|
+
const body = JSON.parse(response.body);
|
|
282
|
+
expect(body.success).toBe(true);
|
|
283
|
+
|
|
284
|
+
await fastify2.close();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('should return 404 when data is not found', async () => {
|
|
288
|
+
(prisma.userData.findUnique as jest.Mock).mockResolvedValue(null);
|
|
289
|
+
|
|
290
|
+
const fastify2 = require('fastify')();
|
|
291
|
+
fastify2.decorateRequest('userId', null);
|
|
292
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
293
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
294
|
+
request.userId = 'user_123';
|
|
295
|
+
});
|
|
296
|
+
await fastify2.register(userRoutes);
|
|
297
|
+
|
|
298
|
+
const response = await fastify2.inject({
|
|
299
|
+
method: 'GET',
|
|
300
|
+
url: '/v1/user/data/nonexistent',
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(response.statusCode).toBe(404);
|
|
304
|
+
|
|
305
|
+
await fastify2.close();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('PUT /v1/user/data/:key', () => {
|
|
310
|
+
it('should return 401 when user is not authenticated', async () => {
|
|
311
|
+
const response = await app.inject({
|
|
312
|
+
method: 'PUT',
|
|
313
|
+
url: '/v1/user/data/preferences',
|
|
314
|
+
payload: { theme: 'light' },
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(response.statusCode).toBe(401);
|
|
318
|
+
const body = JSON.parse(response.body);
|
|
319
|
+
expect(body.success).toBe(false);
|
|
320
|
+
expect(body.error).toBe('Authentication required');
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('should create or update user data', async () => {
|
|
324
|
+
// ARRANGE
|
|
325
|
+
const mockUserData = {
|
|
326
|
+
userId: 'user_123',
|
|
327
|
+
key: 'preferences',
|
|
328
|
+
value: { theme: 'light' },
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
(prisma.userData.upsert as jest.Mock).mockResolvedValue(mockUserData);
|
|
332
|
+
|
|
333
|
+
const fastify2 = require('fastify')();
|
|
334
|
+
fastify2.decorateRequest('userId', null);
|
|
335
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
336
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
337
|
+
request.userId = 'user_123';
|
|
338
|
+
});
|
|
339
|
+
await fastify2.register(userRoutes);
|
|
340
|
+
|
|
341
|
+
// ACT
|
|
342
|
+
const response = await fastify2.inject({
|
|
343
|
+
method: 'PUT',
|
|
344
|
+
url: '/v1/user/data/preferences',
|
|
345
|
+
payload: { theme: 'light' },
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// ASSERT
|
|
349
|
+
expect(response.statusCode).toBe(200);
|
|
350
|
+
expect(prisma.userData.upsert).toHaveBeenCalled();
|
|
351
|
+
|
|
352
|
+
await fastify2.close();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('should return 500 on database error', async () => {
|
|
356
|
+
// ARRANGE
|
|
357
|
+
(prisma.userData.upsert as jest.Mock).mockRejectedValue(
|
|
358
|
+
new Error('DB write failed')
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
const fastify2 = require('fastify')();
|
|
362
|
+
fastify2.decorateRequest('userId', null);
|
|
363
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
364
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
365
|
+
request.userId = 'user_123';
|
|
366
|
+
});
|
|
367
|
+
await fastify2.register(userRoutes);
|
|
368
|
+
|
|
369
|
+
// ACT
|
|
370
|
+
const response = await fastify2.inject({
|
|
371
|
+
method: 'PUT',
|
|
372
|
+
url: '/v1/user/data/preferences',
|
|
373
|
+
payload: { theme: 'light' },
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// ASSERT
|
|
377
|
+
expect(response.statusCode).toBe(500);
|
|
378
|
+
const body = JSON.parse(response.body);
|
|
379
|
+
expect(body.success).toBe(false);
|
|
380
|
+
expect(body.error).toBe('Internal server error');
|
|
381
|
+
|
|
382
|
+
await fastify2.close();
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe('DELETE /v1/user/data/:key', () => {
|
|
387
|
+
it('should return 401 when user is not authenticated', async () => {
|
|
388
|
+
const response = await app.inject({
|
|
389
|
+
method: 'DELETE',
|
|
390
|
+
url: '/v1/user/data/preferences',
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
expect(response.statusCode).toBe(401);
|
|
394
|
+
const body = JSON.parse(response.body);
|
|
395
|
+
expect(body.success).toBe(false);
|
|
396
|
+
expect(body.error).toBe('Authentication required');
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('should delete user data', async () => {
|
|
400
|
+
// ARRANGE
|
|
401
|
+
(prisma.userData.deleteMany as jest.Mock).mockResolvedValue({ count: 1 });
|
|
402
|
+
|
|
403
|
+
const fastify2 = require('fastify')();
|
|
404
|
+
fastify2.decorateRequest('userId', null);
|
|
405
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
406
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
407
|
+
request.userId = 'user_123';
|
|
408
|
+
});
|
|
409
|
+
await fastify2.register(userRoutes);
|
|
410
|
+
|
|
411
|
+
// ACT
|
|
412
|
+
const response = await fastify2.inject({
|
|
413
|
+
method: 'DELETE',
|
|
414
|
+
url: '/v1/user/data/preferences',
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// ASSERT
|
|
418
|
+
expect(response.statusCode).toBe(200);
|
|
419
|
+
expect(prisma.userData.deleteMany).toHaveBeenCalledWith({
|
|
420
|
+
where: { userId: 'user_123', key: 'preferences' },
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
await fastify2.close();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('should return 500 on database error', async () => {
|
|
427
|
+
// ARRANGE
|
|
428
|
+
(prisma.userData.deleteMany as jest.Mock).mockRejectedValue(
|
|
429
|
+
new Error('DB delete failed')
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
const fastify2 = require('fastify')();
|
|
433
|
+
fastify2.decorateRequest('userId', null);
|
|
434
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
435
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
436
|
+
request.userId = 'user_123';
|
|
437
|
+
});
|
|
438
|
+
await fastify2.register(userRoutes);
|
|
439
|
+
|
|
440
|
+
// ACT
|
|
441
|
+
const response = await fastify2.inject({
|
|
442
|
+
method: 'DELETE',
|
|
443
|
+
url: '/v1/user/data/preferences',
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// ASSERT
|
|
447
|
+
expect(response.statusCode).toBe(500);
|
|
448
|
+
const body = JSON.parse(response.body);
|
|
449
|
+
expect(body.success).toBe(false);
|
|
450
|
+
expect(body.error).toBe('Internal server error');
|
|
451
|
+
|
|
452
|
+
await fastify2.close();
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
describe('GET /v1/user/data/:key — error path', () => {
|
|
457
|
+
it('should return 500 on database error', async () => {
|
|
458
|
+
// ARRANGE
|
|
459
|
+
(prisma.userData.findUnique as jest.Mock).mockRejectedValue(
|
|
460
|
+
new Error('DB read failed')
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
const fastify2 = require('fastify')();
|
|
464
|
+
fastify2.decorateRequest('userId', null);
|
|
465
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- #506/#507: pre-existing test-hygiene violation
|
|
466
|
+
fastify2.addHook('preHandler', async (request: any) => {
|
|
467
|
+
request.userId = 'user_123';
|
|
468
|
+
});
|
|
469
|
+
await fastify2.register(userRoutes);
|
|
470
|
+
|
|
471
|
+
// ACT
|
|
472
|
+
const response = await fastify2.inject({
|
|
473
|
+
method: 'GET',
|
|
474
|
+
url: '/v1/user/data/preferences',
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// ASSERT
|
|
478
|
+
expect(response.statusCode).toBe(500);
|
|
479
|
+
const body = JSON.parse(response.body);
|
|
480
|
+
expect(body.success).toBe(false);
|
|
481
|
+
expect(body.error).toBe('Internal server error');
|
|
482
|
+
|
|
483
|
+
await fastify2.close();
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Token Management
|
|
3
|
+
*
|
|
4
|
+
* Handles creation and management of API tokens for mobile/external clients.
|
|
5
|
+
* These tokens are stored locally in the customer's database.
|
|
6
|
+
*/
|
|
7
|
+
import { randomBytes, createHash } from 'crypto';
|
|
8
|
+
|
|
9
|
+
import { getClock } from '@working-theory/common';
|
|
10
|
+
import { logger } from '@working-theory/observability';
|
|
11
|
+
import type { FastifyPluginAsync } from 'fastify';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
|
|
14
|
+
import { prisma } from '../../lib/prisma.js';
|
|
15
|
+
|
|
16
|
+
const createTokenSchema = z.object({
|
|
17
|
+
name: z.string().min(1, 'Name is required'),
|
|
18
|
+
clientType: z.enum(['mobile', 'api', 'cli']).default('api'),
|
|
19
|
+
deviceInfo: z.string().optional(),
|
|
20
|
+
scopes: z.array(z.string()).default([]),
|
|
21
|
+
expiresInDays: z.number().min(1).max(365).optional(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generate a secure API token
|
|
26
|
+
*/
|
|
27
|
+
function generateToken(): { token: string; hash: string; prefix: string } {
|
|
28
|
+
const token = `tok_${randomBytes(32).toString('hex')}`;
|
|
29
|
+
const hash = createHash('sha256').update(token).digest('hex');
|
|
30
|
+
const prefix = token.substring(0, 12);
|
|
31
|
+
return { token, hash, prefix };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const tokenRoutes: FastifyPluginAsync = async (fastify) => {
|
|
35
|
+
/**
|
|
36
|
+
* POST /v1/auth/tokens
|
|
37
|
+
* Create a new API token
|
|
38
|
+
* Requires authenticated user (session or existing token)
|
|
39
|
+
*/
|
|
40
|
+
fastify.post('/v1/auth/tokens', async (request, reply) => {
|
|
41
|
+
try {
|
|
42
|
+
// TODO: Get userId from session/auth middleware
|
|
43
|
+
const userId = (request as unknown as { userId?: string }).userId;
|
|
44
|
+
if (!userId) {
|
|
45
|
+
return reply.status(401).send({
|
|
46
|
+
success: false,
|
|
47
|
+
error: 'Authentication required',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const data = createTokenSchema.parse(request.body);
|
|
52
|
+
const { token, hash, prefix } = generateToken();
|
|
53
|
+
|
|
54
|
+
// Calculate expiration
|
|
55
|
+
const expiresAt = data.expiresInDays
|
|
56
|
+
? new Date(getClock().now() + data.expiresInDays * 24 * 60 * 60 * 1000)
|
|
57
|
+
: null;
|
|
58
|
+
|
|
59
|
+
// Create token in database
|
|
60
|
+
const apiToken = await prisma.apiToken.create({
|
|
61
|
+
data: {
|
|
62
|
+
userId,
|
|
63
|
+
name: data.name,
|
|
64
|
+
token: hash, // Store hash, not the actual token
|
|
65
|
+
tokenPrefix: prefix,
|
|
66
|
+
clientType: data.clientType,
|
|
67
|
+
...(data.deviceInfo !== undefined && { deviceInfo: data.deviceInfo }),
|
|
68
|
+
scopes: data.scopes,
|
|
69
|
+
expiresAt,
|
|
70
|
+
},
|
|
71
|
+
select: {
|
|
72
|
+
id: true,
|
|
73
|
+
name: true,
|
|
74
|
+
tokenPrefix: true,
|
|
75
|
+
clientType: true,
|
|
76
|
+
scopes: true,
|
|
77
|
+
expiresAt: true,
|
|
78
|
+
createdAt: true,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Return the actual token ONCE (user must save it)
|
|
83
|
+
return reply.status(201).send({
|
|
84
|
+
success: true,
|
|
85
|
+
token, // Only time we return the actual token
|
|
86
|
+
data: apiToken,
|
|
87
|
+
warning: 'Save this token now. You will not be able to see it again.',
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error instanceof z.ZodError) {
|
|
91
|
+
return reply.status(400).send({
|
|
92
|
+
success: false,
|
|
93
|
+
error: 'Validation failed',
|
|
94
|
+
details: error.issues,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
logger.error({ err: error }, '[Tokens] Error creating token');
|
|
99
|
+
return reply.status(500).send({
|
|
100
|
+
success: false,
|
|
101
|
+
error: 'Internal server error',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* GET /v1/auth/tokens
|
|
108
|
+
* List user's API tokens (without the actual token values)
|
|
109
|
+
*/
|
|
110
|
+
fastify.get('/v1/auth/tokens', async (request, reply) => {
|
|
111
|
+
try {
|
|
112
|
+
const userId = (request as unknown as { userId?: string }).userId;
|
|
113
|
+
if (!userId) {
|
|
114
|
+
return reply.status(401).send({
|
|
115
|
+
success: false,
|
|
116
|
+
error: 'Authentication required',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const tokens = await prisma.apiToken.findMany({
|
|
121
|
+
where: {
|
|
122
|
+
userId,
|
|
123
|
+
revokedAt: null,
|
|
124
|
+
},
|
|
125
|
+
select: {
|
|
126
|
+
id: true,
|
|
127
|
+
name: true,
|
|
128
|
+
tokenPrefix: true,
|
|
129
|
+
clientType: true,
|
|
130
|
+
deviceInfo: true,
|
|
131
|
+
scopes: true,
|
|
132
|
+
expiresAt: true,
|
|
133
|
+
lastUsedAt: true,
|
|
134
|
+
createdAt: true,
|
|
135
|
+
},
|
|
136
|
+
orderBy: { createdAt: 'desc' },
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return reply.send({
|
|
140
|
+
success: true,
|
|
141
|
+
data: tokens,
|
|
142
|
+
});
|
|
143
|
+
} catch (error) {
|
|
144
|
+
logger.error({ err: error }, '[Tokens] Error listing tokens');
|
|
145
|
+
return reply.status(500).send({
|
|
146
|
+
success: false,
|
|
147
|
+
error: 'Internal server error',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* DELETE /v1/auth/tokens/:id
|
|
154
|
+
* Revoke an API token
|
|
155
|
+
*/
|
|
156
|
+
fastify.delete<{ Params: { id: string } }>('/v1/auth/tokens/:id', async (request, reply) => {
|
|
157
|
+
try {
|
|
158
|
+
const userId = (request as unknown as { userId?: string }).userId;
|
|
159
|
+
if (!userId) {
|
|
160
|
+
return reply.status(401).send({
|
|
161
|
+
success: false,
|
|
162
|
+
error: 'Authentication required',
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { id } = request.params;
|
|
167
|
+
|
|
168
|
+
// Verify ownership and revoke
|
|
169
|
+
const token = await prisma.apiToken.updateMany({
|
|
170
|
+
where: {
|
|
171
|
+
id,
|
|
172
|
+
userId,
|
|
173
|
+
revokedAt: null,
|
|
174
|
+
},
|
|
175
|
+
data: {
|
|
176
|
+
revokedAt: new Date(),
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (token.count === 0) {
|
|
181
|
+
return reply.status(404).send({
|
|
182
|
+
success: false,
|
|
183
|
+
error: 'Token not found',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return reply.send({
|
|
188
|
+
success: true,
|
|
189
|
+
message: 'Token revoked',
|
|
190
|
+
});
|
|
191
|
+
} catch (error) {
|
|
192
|
+
logger.error({ err: error }, '[Tokens] Error revoking token');
|
|
193
|
+
return reply.status(500).send({
|
|
194
|
+
success: false,
|
|
195
|
+
error: 'Internal server error',
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
};
|