create-ailk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-catalog.md +50 -53
- package/dist/lib/apply-module-patches.d.ts +47 -0
- package/dist/lib/apply-module-patches.js +370 -0
- package/dist/lib/extract-module-bundle.d.ts +12 -3
- package/dist/lib/extract-module-bundle.js +236 -24
- package/dist/lib/fetch-module.d.ts +3 -38
- package/dist/lib/fetch-module.js +26 -8
- package/dist/lib/module-license-gate.d.ts +2 -0
- package/dist/lib/module-license-gate.js +1 -0
- package/dist/lib/paid-paths.d.ts +16 -0
- package/dist/lib/paid-paths.js +90 -0
- package/dist/module-architecture.d.ts +139 -23
- package/dist/module-architecture.js +668 -25
- package/dist/parse-args.d.ts +2 -2
- package/dist/parse-args.js +3 -1
- package/dist/programmatic.d.ts +2 -1
- package/dist/programmatic.js +15 -4
- package/dist/surfaces.d.ts +12 -36
- package/dist/surfaces.js +35 -5
- package/dist/sync-routes.js +31 -1
- package/package.json +2 -2
- package/templates/.claude/agents/web.md +2 -3
- package/templates/.claude/rules/architecture.md +5 -5
- package/templates/.claude/skills/README.md +2 -1
- package/templates/.env.example +21 -9
- package/templates/CONVENTIONS.md +6 -7
- package/templates/apps/api/.env.example +9 -0
- package/templates/apps/api/CLAUDE.md +33 -5
- package/templates/apps/api/package.json +0 -1
- package/templates/apps/api/src/__tests__/cors.test.ts +195 -0
- package/templates/apps/api/src/__tests__/module-exclusion.test.ts +60 -2
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +159 -0
- package/templates/apps/api/src/config/__tests__/modules.test.ts +76 -0
- package/templates/apps/api/src/config/index.ts +19 -0
- package/templates/apps/api/src/config/modules.ts +12 -14
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +3 -0
- package/templates/apps/api/src/lib/__tests__/slice-load.test.ts +89 -0
- package/templates/apps/api/src/lib/slice-load.ts +90 -0
- package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +52 -32
- package/templates/apps/api/src/openapi/__tests__/spec-identity.test.ts +182 -0
- package/templates/apps/api/src/openapi/__tests__/surface-drift.test.ts +293 -0
- package/templates/apps/api/src/openapi/index.ts +9 -3
- package/templates/apps/api/src/openapi/spec.ts +505 -65
- package/templates/apps/api/src/openapi/surface-drift.ts +195 -0
- package/templates/apps/api/src/routes/content/__tests__/create.test.ts +14 -0
- package/templates/apps/api/src/routes/content/__tests__/delete.test.ts +14 -0
- package/templates/apps/api/src/routes/content/__tests__/update.test.ts +14 -0
- package/templates/apps/api/src/routes/content/index.ts +38 -11
- package/templates/apps/api/src/routes/project-listings/__tests__/configured-application.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/founder-identity.test.ts +796 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +38 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/resume-email.test.ts +814 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/site-key.test.ts +24 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/structured-address.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/index.ts +37 -10
- package/templates/apps/api/src/routes/project-listings/me.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/patch-draft.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/public.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/respond.ts +11 -0
- package/templates/apps/api/src/routes/project-listings/resume-token.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/start.ts +30 -0
- package/templates/apps/api/src/routes/project-listings/submit.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/verify-email.ts +150 -0
- package/templates/apps/api/src/server.ts +459 -135
- package/templates/apps/api/src/services/deliverable-fulfillment.ts +10 -0
- package/templates/apps/api/src/services/listing-config.ts +58 -0
- package/templates/apps/api/src/services/project-listing-resume-email.ts +326 -0
- package/templates/apps/api/src/services/project-listings.ts +229 -4
- package/templates/apps/api/src/vercel-handler.ts +60 -26
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +2 -2
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +21 -0
- package/templates/apps/mcp/__tests__/config/modules.test.ts +78 -0
- package/templates/apps/mcp/__tests__/module-exclusion.test.ts +1 -1
- package/templates/apps/mcp/src/config/modules.ts +14 -13
- package/templates/apps/mcp/src/server.ts +8 -4
- package/templates/apps/mcp/src/tools/index.ts +7 -22
- package/templates/apps/web/.env.example +15 -0
- package/templates/apps/web/app/[locale]/(authed)/{waitlist/__tests__ → __tests__}/gate.test.tsx +4 -4
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +1 -0
- package/templates/apps/web/app/llms.txt/route.ts +12 -9
- package/templates/apps/web/jest.config.cjs +14 -13
- package/templates/apps/web/next.config.mjs +1 -3
- package/templates/apps/web/package.json +0 -6
- package/templates/apps/web/public/android-chrome-192x192.png +0 -0
- package/templates/apps/web/public/android-chrome-512x512.png +0 -0
- package/templates/apps/web/public/apple-touch-icon.png +0 -0
- package/templates/apps/web/public/favicon-16x16.png +0 -0
- package/templates/apps/web/public/favicon-32x32.png +0 -0
- package/templates/apps/web/public/favicon.ico +0 -0
- package/templates/apps/web/public/favicon.svg +6 -3
- package/templates/apps/web/public/lockup-horizontal.svg +4 -0
- package/templates/apps/web/public/logomark.svg +4 -0
- package/templates/apps/web/public/site.webmanifest +2 -2
- package/templates/apps/web/public/wordmark.svg +4 -0
- package/templates/database/CHANGELOG.md +33 -0
- package/templates/database/inbox/schema.prisma +67 -0
- package/templates/database/migrations/20260914120000_listing_founder_identity/migration.sql +123 -0
- package/templates/database/package.json +1 -1
- package/templates/package.json +1 -1
- package/templates/.claude/skills/scaffold-commerce/SKILL.md +0 -807
- package/templates/.claude/skills/scaffold-commerce/references/lookup-keys-template.md +0 -71
- package/templates/.claude/skills/scaffold-commerce/references/marketplace-brand-pages.md +0 -83
- package/templates/.claude/skills/scaffold-commerce/templates/checkout-route.template.ts +0 -370
- package/templates/.claude/skills/scaffold-commerce/templates/invoice-route.template.ts +0 -376
- package/templates/.claude/skills/scaffold-commerce/templates/marketplace-cta-route.tsx.tmpl +0 -72
- package/templates/.claude/skills/scaffold-commerce/templates/payment-link-route.template.ts +0 -471
- package/templates/.claude/skills/scaffold-commerce/templates/portal-route.template.ts +0 -365
- package/templates/.claude/skills/scaffold-commerce/templates/stripe-config.template.ts +0 -60
- package/templates/.claude/skills/scaffold-commerce/templates/subscription-route.template.ts +0 -446
- package/templates/apps/api/src/__tests__/server.test.ts +0 -253
- package/templates/apps/api/src/bin/deliverable-resend.ts +0 -144
- package/templates/apps/api/src/bin/deliverable-upload.ts +0 -114
- package/templates/apps/api/src/bin/followup-sweep.ts +0 -44
- package/templates/apps/api/src/bin/listing-csv-sweep.ts +0 -46
- package/templates/apps/api/src/bin/seed-presets.ts +0 -58
- package/templates/apps/api/src/bin/seed-waitlist-experiments.ts +0 -104
- package/templates/apps/api/src/bin/session-retention-sweep.ts +0 -46
- package/templates/apps/api/src/lib/__tests__/stripe.test.ts +0 -74
- package/templates/apps/api/src/lib/stripe.ts +0 -52
- package/templates/apps/api/src/lib/tenant-db.ts +0 -225
- package/templates/apps/api/src/lib/ws-token.ts +0 -91
- package/templates/apps/api/src/middleware/tenant.ts +0 -99
- package/templates/apps/api/src/routes/billing/__tests__/portal.test.ts +0 -450
- package/templates/apps/api/src/routes/billing/__tests__/read.test.ts +0 -262
- package/templates/apps/api/src/routes/billing/__tests__/usage.test.ts +0 -436
- package/templates/apps/api/src/routes/billing/index.ts +0 -36
- package/templates/apps/api/src/routes/billing/portal.ts +0 -182
- package/templates/apps/api/src/routes/billing/read.ts +0 -75
- package/templates/apps/api/src/routes/billing/usage.ts +0 -153
- package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +0 -687
- package/templates/apps/api/src/routes/checkout/index.ts +0 -13
- package/templates/apps/api/src/routes/checkout/sessions.ts +0 -197
- package/templates/apps/api/src/routes/deliverables/__tests__/index.test.ts +0 -393
- package/templates/apps/api/src/routes/deliverables/index.ts +0 -200
- package/templates/apps/api/src/routes/flow-checkouts/__tests__/index.test.ts +0 -443
- package/templates/apps/api/src/routes/flow-checkouts/index.ts +0 -82
- package/templates/apps/api/src/routes/flows/README.md +0 -147
- package/templates/apps/api/src/routes/flows/__tests__/index.test.ts +0 -752
- package/templates/apps/api/src/routes/flows/__tests__/recommender.test.ts +0 -671
- package/templates/apps/api/src/routes/flows/index.ts +0 -202
- package/templates/apps/api/src/routes/flows/recommender.ts +0 -443
- package/templates/apps/api/src/routes/project-listings/__tests__/copy-edit.test.ts +0 -815
- package/templates/apps/api/src/routes/project-listings/__tests__/me-route-precedence.test.ts +0 -221
- package/templates/apps/api/src/routes/project-listings/__tests__/tenant-isolation.test.ts +0 -566
- package/templates/apps/api/src/routes/project-listings/get.ts +0 -70
- package/templates/apps/api/src/routes/project-listings/list.ts +0 -47
- package/templates/apps/api/src/routes/project-listings/patch.ts +0 -136
- package/templates/apps/api/src/routes/schedule/__tests__/index.test.ts +0 -490
- package/templates/apps/api/src/routes/schedule/index.ts +0 -249
- package/templates/apps/api/src/routes/slack/__tests__/actions.test.ts +0 -385
- package/templates/apps/api/src/routes/slack/actions.ts +0 -177
- package/templates/apps/api/src/routes/slack/index.ts +0 -38
- package/templates/apps/api/src/routes/waitlist-experiments/__tests__/tenant-isolation.test.ts +0 -577
- package/templates/apps/api/src/routes/waitlist-experiments/comparison.ts +0 -78
- package/templates/apps/api/src/routes/waitlist-experiments/index.ts +0 -41
- package/templates/apps/api/src/routes/waitlist-experiments/list.ts +0 -64
- package/templates/apps/api/src/routes/waitlist-experiments/respond.ts +0 -42
- package/templates/apps/api/src/routes/waitlist-experiments/signup.ts +0 -84
- package/templates/apps/api/src/routes/waitlist-experiments/signups.ts +0 -119
- package/templates/apps/api/src/routes/waitlist-signups/__tests__/index.test.ts +0 -238
- package/templates/apps/api/src/routes/waitlist-signups/index.ts +0 -101
- package/templates/apps/api/src/routes/webhooks/README.md +0 -80
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +0 -315
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +0 -247
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +0 -270
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +0 -198
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +0 -633
- package/templates/apps/api/src/routes/webhooks/index.ts +0 -41
- package/templates/apps/api/src/routes/webhooks/stripe.ts +0 -481
- package/templates/apps/api/src/routes/workspaces/__tests__/config-tenant-isolation.test.ts +0 -356
- package/templates/apps/api/src/routes/workspaces/__tests__/tenant-isolation.test.ts +0 -671
- package/templates/apps/api/src/routes/workspaces/config.ts +0 -125
- package/templates/apps/api/src/routes/workspaces/index.ts +0 -194
- package/templates/apps/api/src/routes/workspaces/sessions.ts +0 -218
- package/templates/apps/api/src/services/__tests__/flow-aggregate.test.ts +0 -425
- package/templates/apps/api/src/services/__tests__/flow-engine.test.ts +0 -2840
- package/templates/apps/api/src/services/__tests__/lead-promotion.test.ts +0 -393
- package/templates/apps/api/src/services/__tests__/listing-csv-sweep.test.ts +0 -560
- package/templates/apps/api/src/services/__tests__/listing-promotion.test.ts +0 -684
- package/templates/apps/api/src/services/__tests__/playbook-compile.test.ts +0 -406
- package/templates/apps/api/src/services/__tests__/playbook-render.test.ts +0 -290
- package/templates/apps/api/src/services/__tests__/project-listing-decision.test.ts +0 -736
- package/templates/apps/api/src/services/__tests__/project-listing-flow.test.ts +0 -475
- package/templates/apps/api/src/services/__tests__/project-listing-issue.test.ts +0 -340
- package/templates/apps/api/src/services/__tests__/recommender-capture.test.ts +0 -983
- package/templates/apps/api/src/services/__tests__/tenant-context-cascade.test.ts +0 -71
- package/templates/apps/api/src/services/__tests__/tenant-context.test.ts +0 -379
- package/templates/apps/api/src/services/__tests__/usage-metering.test.ts +0 -768
- package/templates/apps/api/src/services/__tests__/waitlist-dashboard.test.ts +0 -1314
- package/templates/apps/api/src/services/__tests__/waitlist-experiments.test.ts +0 -341
- package/templates/apps/api/src/services/__tests__/waitlist-followup.test.ts +0 -567
- package/templates/apps/api/src/services/__tests__/waitlist-scoring.test.ts +0 -474
- package/templates/apps/api/src/services/__tests__/waitlist-signups.test.ts +0 -354
- package/templates/apps/api/src/services/flow-aggregate.ts +0 -232
- package/templates/apps/api/src/services/flow-checkouts.ts +0 -123
- package/templates/apps/api/src/services/flow-engine.ts +0 -1296
- package/templates/apps/api/src/services/lead-promotion.ts +0 -176
- package/templates/apps/api/src/services/listing-csv-sweep.ts +0 -455
- package/templates/apps/api/src/services/listing-promotion.ts +0 -342
- package/templates/apps/api/src/services/playbook-compile.ts +0 -398
- package/templates/apps/api/src/services/playbook-render.ts +0 -263
- package/templates/apps/api/src/services/project-listing-decision.ts +0 -510
- package/templates/apps/api/src/services/project-listing-flow.ts +0 -426
- package/templates/apps/api/src/services/project-listing-issue.ts +0 -251
- package/templates/apps/api/src/services/recommender-capture.ts +0 -835
- package/templates/apps/api/src/services/scheduling/cal-provider.ts +0 -392
- package/templates/apps/api/src/services/scheduling/index.ts +0 -63
- package/templates/apps/api/src/services/scheduling/types.ts +0 -88
- package/templates/apps/api/src/services/tenant-context.ts +0 -451
- package/templates/apps/api/src/services/usage-metering.ts +0 -699
- package/templates/apps/api/src/services/waitlist-dashboard.ts +0 -947
- package/templates/apps/api/src/services/waitlist-experiments.ts +0 -213
- package/templates/apps/api/src/services/waitlist-followup.ts +0 -486
- package/templates/apps/api/src/services/waitlist-scoring.ts +0 -166
- package/templates/apps/api/src/services/waitlist-signups.ts +0 -165
- package/templates/apps/mcp/__tests__/schedule_tools.test.ts +0 -242
- package/templates/apps/mcp/src/tools/create_booking.ts +0 -58
- package/templates/apps/mcp/src/tools/get_event_meta.ts +0 -55
- package/templates/apps/mcp/src/tools/get_flow.ts +0 -61
- package/templates/apps/mcp/src/tools/list_availability.ts +0 -67
- package/templates/apps/mcp/src/tools/submit_flow_step.ts +0 -83
- package/templates/apps/web/app/[locale]/(authed)/waitlist/[experimentId]/page.tsx +0 -309
- package/templates/apps/web/app/[locale]/(authed)/waitlist/[experimentId]/signups/[leadId]/page.tsx +0 -149
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/comparison.test.tsx +0 -273
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/list.test.tsx +0 -171
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/signup.test.tsx +0 -179
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ExperimentsTable.tsx +0 -116
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/OfferFunnelTable.tsx +0 -66
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/RollupTicker.tsx +0 -61
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ScoreTrace.tsx +0 -114
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/SignupsTable.tsx +0 -139
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/WaitlistComparisonTabs.tsx +0 -85
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/status-badges.tsx +0 -67
- package/templates/apps/web/app/[locale]/(authed)/waitlist/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/blog/[[...slug]]/page.tsx +0 -178
- package/templates/apps/web/app/[locale]/dev/purchase/__tests__/actions.test.ts +0 -160
- package/templates/apps/web/app/[locale]/dev/purchase/error.tsx +0 -25
- package/templates/apps/web/app/[locale]/dev/purchase/page.tsx +0 -117
- package/templates/apps/web/app/[locale]/dev/purchase/purchase.actions.ts +0 -58
- package/templates/apps/web/app/[locale]/docs/[[...slug]]/page.tsx +0 -119
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/checkout.actions.test.ts +0 -287
- package/templates/apps/web/app/[locale]/flows/[slug]/checkout.actions.ts +0 -254
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -532
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -121
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.checkout.test.tsx +0 -457
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -396
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/projects/apply/ListingApplicationClient.tsx +0 -110
- package/templates/apps/web/app/[locale]/projects/apply/__tests__/ListingApplicationClient.test.tsx +0 -96
- package/templates/apps/web/app/[locale]/schedule/__tests__/page.test.tsx +0 -117
- package/templates/apps/web/app/[locale]/schedule/confirmed/__tests__/page.test.tsx +0 -96
- package/templates/apps/web/app/[locale]/schedule/confirmed/page.tsx +0 -92
- package/templates/apps/web/app/[locale]/schedule/page.tsx +0 -82
- package/templates/apps/web/content/en/blog/README.txt +0 -25
- package/templates/apps/web/content/en/docs/index.mdx +0 -28
- package/templates/apps/web/lib/__mocks__/source-server.js +0 -31
- package/templates/apps/web/lib/blog-list-data.ts +0 -95
- package/templates/apps/web/lib/blog-post-data.ts +0 -79
- package/templates/apps/web/lib/source.ts +0 -34
- package/templates/apps/web/public/logomark-dark.svg +0 -4
- package/templates/apps/web/public/logomark-light.svg +0 -4
- package/templates/apps/web/source.config.ts +0 -78
package/templates/apps/api/src/routes/project-listings/__tests__/me-route-precedence.test.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// oss: false
|
|
2
|
-
/**
|
|
3
|
-
* @file me-route-precedence.test.ts
|
|
4
|
-
*
|
|
5
|
-
* The regression net for the one structural risk in #5295: the static
|
|
6
|
-
* `/v1/project-listings/me` and the parametric `/v1/project-listings/:id` share
|
|
7
|
-
* a prefix and are registered in DIFFERENT scopes — `/me` in `server.ts`'s
|
|
8
|
-
* `authScope`, `/:id` inside the encapsulated `tenantScope` behind
|
|
9
|
-
* `tenantPreHandlerPlugin`.
|
|
10
|
-
*
|
|
11
|
-
* `me.test.ts` registers `/me` alone, so nothing there would catch a
|
|
12
|
-
* registration reorder that shadowed `/me` or weakened the tenant guard on
|
|
13
|
-
* `/:id`. The security review for this change verified the behaviour by hand and
|
|
14
|
-
* named the missing net; this file is that net.
|
|
15
|
-
*
|
|
16
|
-
* It asserts three things in ONE Fastify instance with the REAL preHandlers:
|
|
17
|
-
* 1. `/v1/project-listings/me` reaches the `/me` handler — static beats
|
|
18
|
-
* parametric — and runs auth ONLY, no tenant guard.
|
|
19
|
-
* 2. `/v1/project-listings/<id>` still reaches the tenant handler WITH the
|
|
20
|
-
* tenant guard: registering a static sibling in the outer scope does not
|
|
21
|
-
* weaken it. A member below the `owner|admin` floor is still refused.
|
|
22
|
-
* 3. Registering both raises no duplicate-route error.
|
|
23
|
-
*
|
|
24
|
-
* This file is `oss: false` because it imports the multi-tenant slice
|
|
25
|
-
* (`middleware/tenant.js`, `./get.js`), the same reason `tenant-isolation.test.ts`
|
|
26
|
-
* is.
|
|
27
|
-
*/
|
|
28
|
-
import Fastify from "fastify";
|
|
29
|
-
import type { FastifyInstance } from "fastify";
|
|
30
|
-
|
|
31
|
-
jest.mock("@working-theory/email", () => ({
|
|
32
|
-
sendLeadNotification: jest.fn().mockResolvedValue({ ok: true, messageId: "msg-test" }),
|
|
33
|
-
}));
|
|
34
|
-
jest.mock("@working-theory/license", () => ({
|
|
35
|
-
checkLicense: jest.fn().mockResolvedValue({
|
|
36
|
-
tier: "free",
|
|
37
|
-
plan: null,
|
|
38
|
-
features: [],
|
|
39
|
-
expiresAt: null,
|
|
40
|
-
revoked: false,
|
|
41
|
-
}),
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line no-restricted-syntax -- jest mock factory must be hoisted
|
|
45
|
-
jest.mock("../../../lib/prisma.js", () => ({
|
|
46
|
-
prisma: {
|
|
47
|
-
session: { findUnique: jest.fn() },
|
|
48
|
-
apiToken: {
|
|
49
|
-
findUnique: jest.fn(),
|
|
50
|
-
update: jest.fn().mockResolvedValue(undefined),
|
|
51
|
-
},
|
|
52
|
-
user: { findUnique: jest.fn() },
|
|
53
|
-
workspace: { findUnique: jest.fn(), count: jest.fn() },
|
|
54
|
-
membership: { findUnique: jest.fn() },
|
|
55
|
-
projectListing: { findMany: jest.fn(), findFirst: jest.fn() },
|
|
56
|
-
waitlistScore: { count: jest.fn() },
|
|
57
|
-
},
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
import { prisma } from "../../../lib/prisma.js";
|
|
61
|
-
import { authPreHandlerPlugin } from "../../../middleware/auth.js";
|
|
62
|
-
import { tenantPreHandlerPlugin } from "../../../middleware/tenant.js";
|
|
63
|
-
import { projectListingMeRoute, projectListingTenantRoutes } from "../index.js";
|
|
64
|
-
|
|
65
|
-
const FRONTEND = "https://app.example.com";
|
|
66
|
-
const FUTURE = new Date(Date.now() + 60 * 60 * 1000);
|
|
67
|
-
|
|
68
|
-
const ORG = "org_00000000-0000-7000-8000-000000000001";
|
|
69
|
-
const WS = "wksp_00000000-0000-7000-8000-000000000001";
|
|
70
|
-
const LISTING_ID = "prjl_00000000-0000-7000-8000-0000000000d1";
|
|
71
|
-
|
|
72
|
-
/** `owner` clears the floor; `member` does not. Both are real members of ORG. */
|
|
73
|
-
const SESSION_ROWS: Record<string, Record<string, unknown>> = {
|
|
74
|
-
cookie_owner: {
|
|
75
|
-
id: "sess_owner",
|
|
76
|
-
userId: "owner-user",
|
|
77
|
-
expiresAt: FUTURE,
|
|
78
|
-
activeOrganizationId: ORG,
|
|
79
|
-
activeWorkspaceId: WS,
|
|
80
|
-
},
|
|
81
|
-
cookie_member: {
|
|
82
|
-
id: "sess_member",
|
|
83
|
-
userId: "member-user",
|
|
84
|
-
expiresAt: FUTURE,
|
|
85
|
-
activeOrganizationId: ORG,
|
|
86
|
-
activeWorkspaceId: WS,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const MEMBERSHIPS: Record<string, string> = {
|
|
91
|
-
"owner-user": "owner",
|
|
92
|
-
"member-user": "member",
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
async function buildApp(): Promise<FastifyInstance> {
|
|
96
|
-
// The exact nesting server.ts uses: /me in the OUTER auth scope, the tenant
|
|
97
|
-
// routes in an INNER scope behind the tenant preHandler.
|
|
98
|
-
const app = Fastify();
|
|
99
|
-
await app.register(async (authScope) => {
|
|
100
|
-
await authScope.register(authPreHandlerPlugin, { frontendOrigin: FRONTEND });
|
|
101
|
-
await authScope.register(projectListingMeRoute);
|
|
102
|
-
await authScope.register(async (tenantScope) => {
|
|
103
|
-
await tenantScope.register(tenantPreHandlerPlugin);
|
|
104
|
-
await tenantScope.register(projectListingTenantRoutes);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
await app.ready();
|
|
108
|
-
return app;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const cookie = (token: string) => ({ cookie: `better-auth.session_token=${token}` });
|
|
112
|
-
|
|
113
|
-
let app: FastifyInstance;
|
|
114
|
-
|
|
115
|
-
beforeEach(async () => {
|
|
116
|
-
jest.clearAllMocks();
|
|
117
|
-
(prisma.session.findUnique as jest.Mock).mockImplementation(
|
|
118
|
-
({ where }: { where: { token?: string } }) =>
|
|
119
|
-
Promise.resolve(where.token ? (SESSION_ROWS[where.token] ?? null) : null),
|
|
120
|
-
);
|
|
121
|
-
(prisma.apiToken.findUnique as jest.Mock).mockResolvedValue(null);
|
|
122
|
-
(prisma.user.findUnique as jest.Mock).mockImplementation(({ where }: { where: { id: string } }) =>
|
|
123
|
-
Promise.resolve({ id: where.id, email: `${where.id}@example.com`, emailVerified: true }),
|
|
124
|
-
);
|
|
125
|
-
(prisma.workspace.findUnique as jest.Mock).mockResolvedValue({ id: WS, organizationId: ORG });
|
|
126
|
-
// The composite key is `organizationId_userId` — the order `tenant-context.ts`
|
|
127
|
-
// actually queries with.
|
|
128
|
-
(prisma.membership.findUnique as jest.Mock).mockImplementation(
|
|
129
|
-
({ where }: { where: { organizationId_userId?: { userId: string } } }) => {
|
|
130
|
-
const userId = where.organizationId_userId?.userId;
|
|
131
|
-
const role = userId ? MEMBERSHIPS[userId] : undefined;
|
|
132
|
-
return Promise.resolve(role ? { role } : null);
|
|
133
|
-
},
|
|
134
|
-
);
|
|
135
|
-
// The /me read returns nothing; this file is about routing, not payloads.
|
|
136
|
-
(prisma.projectListing.findMany as jest.Mock).mockResolvedValue([]);
|
|
137
|
-
(prisma.projectListing.findFirst as jest.Mock).mockResolvedValue(null);
|
|
138
|
-
app = await buildApp();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
afterEach(async () => {
|
|
142
|
-
await app.close();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("route precedence: static /me beside parametric /:id in one instance", () => {
|
|
146
|
-
it("registering both raises no duplicate-route error", async () => {
|
|
147
|
-
// buildApp() already awaited app.ready(); reaching here is the assertion.
|
|
148
|
-
const tree = app.printRoutes();
|
|
149
|
-
expect(tree).toContain("me");
|
|
150
|
-
expect(tree).toContain(":id");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("/v1/project-listings/me reaches the /me handler, not the parametric one", async () => {
|
|
154
|
-
const res = await app.inject({
|
|
155
|
-
method: "GET",
|
|
156
|
-
url: "/v1/project-listings/me",
|
|
157
|
-
headers: cookie("cookie_owner"),
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// The /me handler answers its own 200 + empty list. The parametric handler
|
|
161
|
-
// would have answered 400 `validation_failed` — "me" is not a listing id.
|
|
162
|
-
expect(res.statusCode).toBe(200);
|
|
163
|
-
expect(res.json()).toEqual({ ok: true, data: [] });
|
|
164
|
-
// And it read through the owner link, not by id.
|
|
165
|
-
expect(prisma.projectListing.findMany).toHaveBeenCalledWith(
|
|
166
|
-
expect.objectContaining({ where: { ownerUserId: "owner-user" } }),
|
|
167
|
-
);
|
|
168
|
-
expect(prisma.projectListing.findFirst).not.toHaveBeenCalled();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("/me runs auth ONLY — a caller BELOW the owner|admin floor still gets their own rows", async () => {
|
|
172
|
-
const res = await app.inject({
|
|
173
|
-
method: "GET",
|
|
174
|
-
url: "/v1/project-listings/me",
|
|
175
|
-
headers: cookie("cookie_member"),
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// A `member` is refused by the tenant routes and allowed here: /me is not
|
|
179
|
-
// behind the floor, and it does not need to be — the owner link is the gate.
|
|
180
|
-
expect(res.statusCode).toBe(200);
|
|
181
|
-
expect(res.json()).toEqual({ ok: true, data: [] });
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("the parametric /:id still runs the tenant guard — the static sibling does not weaken it", async () => {
|
|
185
|
-
const ownerRes = await app.inject({
|
|
186
|
-
method: "GET",
|
|
187
|
-
url: `/v1/project-listings/${LISTING_ID}`,
|
|
188
|
-
headers: cookie("cookie_owner"),
|
|
189
|
-
});
|
|
190
|
-
// Owner clears the floor and reaches the service, which finds no row.
|
|
191
|
-
expect(ownerRes.statusCode).toBe(404);
|
|
192
|
-
|
|
193
|
-
const memberRes = await app.inject({
|
|
194
|
-
method: "GET",
|
|
195
|
-
url: `/v1/project-listings/${LISTING_ID}`,
|
|
196
|
-
headers: cookie("cookie_member"),
|
|
197
|
-
});
|
|
198
|
-
// Member is still refused BEFORE any read — the floor is intact.
|
|
199
|
-
expect(memberRes.statusCode).toBe(403);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("the tenant LIST route is unaffected and still refuses a member", async () => {
|
|
203
|
-
const res = await app.inject({
|
|
204
|
-
method: "GET",
|
|
205
|
-
url: "/v1/project-listings",
|
|
206
|
-
headers: cookie("cookie_member"),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
expect(res.statusCode).toBe(403);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("an unauthenticated caller is refused on both paths", async () => {
|
|
213
|
-
const meRes = await app.inject({ method: "GET", url: "/v1/project-listings/me" });
|
|
214
|
-
const idRes = await app.inject({ method: "GET", url: `/v1/project-listings/${LISTING_ID}` });
|
|
215
|
-
|
|
216
|
-
expect(meRes.statusCode).toBe(401);
|
|
217
|
-
expect(idRes.statusCode).toBe(401);
|
|
218
|
-
expect(prisma.projectListing.findMany).not.toHaveBeenCalled();
|
|
219
|
-
expect(prisma.projectListing.findFirst).not.toHaveBeenCalled();
|
|
220
|
-
});
|
|
221
|
-
});
|