create-ailk 0.39.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/component-catalog.json +1 -1
- package/component-catalog.md +1 -1
- package/dist/add-route.js +15 -0
- package/dist/body-heading.d.ts +2 -1
- package/dist/body-heading.js +31 -3
- package/dist/module-architecture.js +0 -3
- package/dist/remove-module.js +13 -4
- package/dist/routes.d.ts +7 -0
- package/dist/routes.js +1 -1
- package/dist/site-roster.js +7 -1
- package/dist/surfaces.d.ts +2 -0
- package/dist/surfaces.js +59 -172
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +19 -2
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
- package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
- package/templates/apps/web/app/[locale]/layout.tsx +42 -25
- package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
- package/templates/apps/web/app/api/revalidate/route.ts +45 -4
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +53 -0
- package/templates/apps/web/app/llms.txt/route.ts +5 -2
- package/templates/apps/web/i18n/request.ts +5 -1
- package/templates/apps/web/jest.config.cjs +6 -0
- package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +239 -0
- package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
- package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +115 -3
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
- package/templates/apps/web/lib/hub-site-config.ts +151 -0
- package/templates/apps/web/lib/in-page-magnet.ts +2 -2
- package/templates/apps/web/lib/pricing-page.ts +3 -3
- package/templates/apps/web/lib/profile-back-link.ts +49 -12
- package/templates/apps/web/lib/served-pages.ts +144 -39
- package/templates/apps/web/lib/site-brand.tsx +66 -0
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +25 -5
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +21 -5
- package/templates/apps/web/lib/site-header.ts +1 -1
- package/templates/apps/web/lib/site-identity.ts +38 -2
- package/templates/apps/web/messages/en.json +3 -119
- package/templates/apps/web/next.config.mjs +7 -0
- package/templates/apps/web/package.json +1 -0
- package/templates/apps/web/site-pages.config.tsx +85 -0
- package/templates/tools/body-heading.ts +30 -3
- package/versions.json +50 -49
- package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
- package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
- package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
- package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
- package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
- package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
- package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
- package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
- package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
- package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
- package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
- package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
- package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
- package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
- package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
- package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
- package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
- package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
- package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
- package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
- package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
- package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
- package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
- package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
- package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
- package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
- package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
- package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
- package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
- package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
- package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
- package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
- package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
- package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
- package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
- package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
- package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/page.tsx +0 -147
- package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
- package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
- package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
- package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
- package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
- package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
- package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
- package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
- package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
- package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
- package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
- package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
- package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
- package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
- package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
- package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
- package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
- package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
- package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
- package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
- package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
- package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
- package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
- package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
- package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
- package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
- package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
- package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
- package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
- package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
- package/templates/apps/web/lib/hub-children.tsx +0 -351
- package/templates/apps/web/lib/meet-placeholder.ts +0 -5
- package/templates/apps/web/lib/posting-title.ts +0 -39
- package/templates/apps/web/lib/route-family.ts +0 -69
- package/templates/apps/web/lib/service-listing.ts +0 -89
- package/templates/apps/web/lib/template-listing.ts +0 -169
- package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
- package/templates/apps/web/src/lib/lead-write.ts +0 -90
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the signed-in owner's lead inbox (#5678 Deliverable 2).
|
|
3
|
-
*
|
|
4
|
-
* Covers:
|
|
5
|
-
* 1. Renders one row per lead, with a `null` name shown as the
|
|
6
|
-
* "unavailable" sentinel rather than blank.
|
|
7
|
-
* 2. Renders the forward-only "next" link when `nextCursor` is present, and
|
|
8
|
-
* omits it when it is `null`.
|
|
9
|
-
* 3. Forwards `?cursor=` from `searchParams` to the api-client call.
|
|
10
|
-
* 4. Renders an EmptyState — not a headerless table — for an empty page.
|
|
11
|
-
* 5. Renders ForbiddenState on a 401/403; falls back to the first page
|
|
12
|
-
* when a supplied `?cursor=` 400s; rethrows every other error.
|
|
13
|
-
* 6. With no session, renders ForbiddenState and makes no apps/api request
|
|
14
|
-
* — the (authed) layout's gate renders concurrently, so the page must
|
|
15
|
-
* not spend (or fail) an API call on a visitor it will never serve
|
|
16
|
-
* (#6865).
|
|
17
|
-
*/
|
|
18
|
-
import { render, screen } from "@testing-library/react";
|
|
19
|
-
|
|
20
|
-
jest.mock("next-intl/server", () => ({
|
|
21
|
-
__esModule: true,
|
|
22
|
-
getTranslations: jest.fn().mockImplementation(async () => (key: string, values?: Record<string, unknown>) =>
|
|
23
|
-
values ? `copy:${key}:${JSON.stringify(values)}` : `copy:${key}`,
|
|
24
|
-
),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
jest.mock("next/headers", () => ({
|
|
28
|
-
__esModule: true,
|
|
29
|
-
headers: jest.fn().mockResolvedValue(new Headers()),
|
|
30
|
-
cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
const mockGetSession = jest.fn();
|
|
34
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test can mock without standing up Prisma.
|
|
35
|
-
jest.mock("../../../../../auth", () => ({
|
|
36
|
-
__esModule: true,
|
|
37
|
-
auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
const mockList = jest.fn();
|
|
41
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
42
|
-
__esModule: true,
|
|
43
|
-
leads: { list: (...args: unknown[]) => mockList(...args) },
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
import Page from "../page";
|
|
47
|
-
|
|
48
|
-
const FIXTURE_PAGE = {
|
|
49
|
-
items: [
|
|
50
|
-
{
|
|
51
|
-
id: "lead_1",
|
|
52
|
-
name: "Ada Lovelace",
|
|
53
|
-
email: "ada@example.com",
|
|
54
|
-
source: "web",
|
|
55
|
-
createdAt: "2026-09-01T10:00:00.000Z",
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: "lead_2",
|
|
59
|
-
name: null,
|
|
60
|
-
email: "anon@example.com",
|
|
61
|
-
source: "conversational-intake",
|
|
62
|
-
createdAt: "2026-08-31T09:00:00.000Z",
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
nextCursor: null as string | null,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
function renderPage(cursor?: string) {
|
|
69
|
-
return Page({
|
|
70
|
-
params: Promise.resolve({ locale: "en" }),
|
|
71
|
-
searchParams: Promise.resolve(cursor ? { cursor } : {}),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
describe("LeadsInboxPage", () => {
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
mockList.mockReset();
|
|
78
|
-
mockGetSession.mockReset();
|
|
79
|
-
mockGetSession.mockResolvedValue({ user: { id: "user_1" } });
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// #6865: the (authed) layout renders SignInGate to an anonymous visitor,
|
|
83
|
-
// but Next renders this page concurrently — it must not call apps/api.
|
|
84
|
-
it("makes no apps/api request and renders ForbiddenState with no session", async () => {
|
|
85
|
-
mockGetSession.mockResolvedValue(null);
|
|
86
|
-
render(await renderPage("lead_9"));
|
|
87
|
-
|
|
88
|
-
expect(mockList).not.toHaveBeenCalled();
|
|
89
|
-
expect(screen.getByTestId("waitlist-forbidden")).toBeInTheDocument();
|
|
90
|
-
expect(screen.queryByTestId("leads-inbox-page")).not.toBeInTheDocument();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("renders one row per lead, with email and source", async () => {
|
|
94
|
-
mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
|
|
95
|
-
render(await renderPage());
|
|
96
|
-
|
|
97
|
-
expect(screen.getByTestId("leads-inbox-page")).toBeInTheDocument();
|
|
98
|
-
const first = screen.getByTestId("leads-table-row-lead_1");
|
|
99
|
-
expect(first).toHaveTextContent("Ada Lovelace");
|
|
100
|
-
expect(first).toHaveTextContent("ada@example.com");
|
|
101
|
-
expect(first).toHaveTextContent("web");
|
|
102
|
-
expect(screen.getByTestId("leads-table-row-lead_2")).toHaveTextContent(
|
|
103
|
-
"conversational-intake",
|
|
104
|
-
);
|
|
105
|
-
expect(screen.getAllByTestId(/^leads-table-row-/)).toHaveLength(2);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("renders a null name as the unavailable sentinel", async () => {
|
|
109
|
-
mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
|
|
110
|
-
render(await renderPage());
|
|
111
|
-
|
|
112
|
-
expect(screen.getByTestId("leads-table-row-lead_2")).toHaveTextContent(
|
|
113
|
-
"copy:table.unavailable",
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("omits the next link when nextCursor is null", async () => {
|
|
118
|
-
mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
|
|
119
|
-
render(await renderPage());
|
|
120
|
-
|
|
121
|
-
expect(screen.queryByTestId("leads-table-next")).not.toBeInTheDocument();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("renders the next link pointing at the next cursor", async () => {
|
|
125
|
-
mockList.mockResolvedValue({
|
|
126
|
-
ok: true,
|
|
127
|
-
body: { ...FIXTURE_PAGE, nextCursor: "lead_2" },
|
|
128
|
-
});
|
|
129
|
-
render(await renderPage());
|
|
130
|
-
|
|
131
|
-
const next = screen.getByTestId("leads-table-next");
|
|
132
|
-
expect(next).toBeInTheDocument();
|
|
133
|
-
expect(next).toHaveAttribute("href", "/en/leads?cursor=lead_2");
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("forwards ?cursor= to the api-client call", async () => {
|
|
137
|
-
mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
|
|
138
|
-
render(await renderPage("lead_9"));
|
|
139
|
-
|
|
140
|
-
expect(mockList).toHaveBeenCalledWith(
|
|
141
|
-
{ cursor: "lead_9" },
|
|
142
|
-
expect.objectContaining({ headers: expect.objectContaining({ cookie: "session=abc" }) }),
|
|
143
|
-
);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("renders an EmptyState when the owner has no leads", async () => {
|
|
147
|
-
mockList.mockResolvedValue({ ok: true, body: { items: [], nextCursor: null } });
|
|
148
|
-
render(await renderPage());
|
|
149
|
-
|
|
150
|
-
expect(screen.getByTestId("leads-table-empty")).toBeInTheDocument();
|
|
151
|
-
expect(screen.queryByTestId("leads-table")).not.toBeInTheDocument();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("renders ForbiddenState on a 401 rather than throwing", async () => {
|
|
155
|
-
mockList.mockResolvedValue({
|
|
156
|
-
ok: false,
|
|
157
|
-
status: 401,
|
|
158
|
-
body: { error: { code: "unauthorized", message: "Unauthorized" } },
|
|
159
|
-
});
|
|
160
|
-
render(await renderPage());
|
|
161
|
-
|
|
162
|
-
expect(screen.getByTestId("waitlist-forbidden")).toBeInTheDocument();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("rethrows a non-401/403 error", async () => {
|
|
166
|
-
mockList.mockResolvedValue({
|
|
167
|
-
ok: false,
|
|
168
|
-
status: 500,
|
|
169
|
-
body: { error: { code: "internal_error", message: "Boom" } },
|
|
170
|
-
});
|
|
171
|
-
await expect(renderPage()).rejects.toThrow();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// PR #5705 security review, finding 3.
|
|
175
|
-
it("falls back to the first page when a supplied ?cursor= 400s", async () => {
|
|
176
|
-
mockList
|
|
177
|
-
.mockResolvedValueOnce({
|
|
178
|
-
ok: false,
|
|
179
|
-
status: 400,
|
|
180
|
-
body: {
|
|
181
|
-
error: {
|
|
182
|
-
code: "validation_failed",
|
|
183
|
-
message: "cursor does not resolve within this scope",
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
})
|
|
187
|
-
.mockResolvedValueOnce({ ok: true, body: FIXTURE_PAGE });
|
|
188
|
-
|
|
189
|
-
render(await renderPage("lead_gone"));
|
|
190
|
-
|
|
191
|
-
expect(screen.getByTestId("leads-table")).toBeInTheDocument();
|
|
192
|
-
expect(mockList).toHaveBeenNthCalledWith(1, { cursor: "lead_gone" }, expect.anything());
|
|
193
|
-
expect(mockList).toHaveBeenNthCalledWith(2, {}, expect.anything());
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("rethrows a 400 on the FIRST page — there is no cursor to blame", async () => {
|
|
197
|
-
mockList.mockResolvedValue({
|
|
198
|
-
ok: false,
|
|
199
|
-
status: 400,
|
|
200
|
-
body: { error: { code: "validation_failed", message: "Invalid query parameters" } },
|
|
201
|
-
});
|
|
202
|
-
await expect(renderPage()).rejects.toThrow();
|
|
203
|
-
expect(mockList).toHaveBeenCalledTimes(1);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LeadsTable — the lead inbox's paginated table (#5678 Deliverable 2).
|
|
3
|
-
*
|
|
4
|
-
* App-local composition: `Table` primitive + `EmptyState` when there are no
|
|
5
|
-
* rows + a single forward-only "next page" link. Every string is
|
|
6
|
-
* caller-supplied (translatable) and every value arrives pre-formatted — this
|
|
7
|
-
* component formats nothing itself (Rule 10: formatting happens in the page,
|
|
8
|
-
* via `../../waitlist/format.js`).
|
|
9
|
-
*
|
|
10
|
-
* Deliberately NOT an import of the structurally identical
|
|
11
|
-
* `../../waitlist/components/SignupsTable.tsx`, despite sharing its shape:
|
|
12
|
-
* that file is an `ownedFiles` entry of a PAID module slice
|
|
13
|
-
* (`packages/create-ailk/src/module-architecture.ts` — the
|
|
14
|
-
* `apps/web/app/[locale]/(authed)/waitlist/**` block, which belongs to the
|
|
15
|
-
* `multi-tenant` slice, not `signal-collectors` as the card's brief had it;
|
|
16
|
-
* verified at HEAD, the `SignupsTable.tsx` entry is on line 1035 inside
|
|
17
|
-
* `MODULE_SLICES["multi-tenant"].ownedFiles`). A scaffold built without that
|
|
18
|
-
* module has no such file. Lead capture — and therefore this inbox — ships at
|
|
19
|
-
* every level including Free, so importing it would make a base-tier page
|
|
20
|
-
* depend on a file the strip removes. The pattern is reused; the file is not.
|
|
21
|
-
*
|
|
22
|
-
* `EmptyState`-when-empty follows `ExperimentsTable`'s idiom rather than
|
|
23
|
-
* `SignupsTable`'s (which always renders a table): a headerless table is not
|
|
24
|
-
* an acceptable empty state for a page whose whole body is this one table.
|
|
25
|
-
*
|
|
26
|
-
* `ForbiddenState` and `format.ts`, by contrast, are safe to import: both are
|
|
27
|
-
* deliberately EXCLUDED from that same `ownedFiles` list (see the module
|
|
28
|
-
* file's own ESCALATION comment above the list — they are shared with the
|
|
29
|
-
* Free `(authed)/account` page, which already imports both), so both survive
|
|
30
|
-
* in a build without the paid slice.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import type { LeadInboxRow } from "@working-theory/api-client";
|
|
34
|
-
import {
|
|
35
|
-
EmptyState,
|
|
36
|
-
Link,
|
|
37
|
-
Table,
|
|
38
|
-
TableBody,
|
|
39
|
-
TableCaption,
|
|
40
|
-
TableCell,
|
|
41
|
-
TableHead,
|
|
42
|
-
TableHeader,
|
|
43
|
-
TableRow,
|
|
44
|
-
} from "@working-theory/ui/primitives";
|
|
45
|
-
import type { ReactElement } from "react";
|
|
46
|
-
|
|
47
|
-
export interface LeadsTableLabels {
|
|
48
|
-
caption: string;
|
|
49
|
-
columnName: string;
|
|
50
|
-
columnEmail: string;
|
|
51
|
-
columnSource: string;
|
|
52
|
-
columnCreated: string;
|
|
53
|
-
unavailable: string;
|
|
54
|
-
next: string;
|
|
55
|
-
emptyHeadline: string;
|
|
56
|
-
emptyDescription: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface LeadsTableProps {
|
|
60
|
-
locale: string;
|
|
61
|
-
/**
|
|
62
|
-
* `created` is pre-formatted by the caller (Rule 10 — this component never
|
|
63
|
-
* formats a value itself). `lead.name` is `null` when the capture form took
|
|
64
|
-
* no name; it renders `labels.unavailable`, the same sentinel handling the
|
|
65
|
-
* caller's own `format.ts` uses elsewhere on the authed surface.
|
|
66
|
-
*
|
|
67
|
-
* There is no page/URL column: the `Lead` record persists no page or
|
|
68
|
-
* referrer field, so `source` is the only capture-origin signal.
|
|
69
|
-
*/
|
|
70
|
-
rows: Array<{
|
|
71
|
-
lead: LeadInboxRow;
|
|
72
|
-
created: string;
|
|
73
|
-
}>;
|
|
74
|
-
nextCursor: string | null;
|
|
75
|
-
labels: LeadsTableLabels;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function buildNextHref(locale: string, nextCursor: string): string {
|
|
79
|
-
const params = new URLSearchParams();
|
|
80
|
-
params.set("cursor", nextCursor);
|
|
81
|
-
return `/${locale}/leads?${params.toString()}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function LeadsTable({
|
|
85
|
-
locale,
|
|
86
|
-
rows,
|
|
87
|
-
nextCursor,
|
|
88
|
-
labels,
|
|
89
|
-
}: LeadsTableProps): ReactElement {
|
|
90
|
-
if (rows.length === 0) {
|
|
91
|
-
return (
|
|
92
|
-
<div data-testid="leads-table-empty">
|
|
93
|
-
<EmptyState headline={labels.emptyHeadline} description={labels.emptyDescription} />
|
|
94
|
-
</div>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<div data-testid="leads-table-wrapper">
|
|
100
|
-
<Table data-testid="leads-table">
|
|
101
|
-
<TableCaption>{labels.caption}</TableCaption>
|
|
102
|
-
<TableHeader>
|
|
103
|
-
<TableRow>
|
|
104
|
-
<TableHead scope="col">{labels.columnName}</TableHead>
|
|
105
|
-
<TableHead scope="col">{labels.columnEmail}</TableHead>
|
|
106
|
-
<TableHead scope="col">{labels.columnSource}</TableHead>
|
|
107
|
-
<TableHead scope="col">{labels.columnCreated}</TableHead>
|
|
108
|
-
</TableRow>
|
|
109
|
-
</TableHeader>
|
|
110
|
-
<TableBody>
|
|
111
|
-
{rows.map(({ lead, created }) => (
|
|
112
|
-
<TableRow key={lead.id} data-testid={`leads-table-row-${lead.id}`}>
|
|
113
|
-
<TableCell>{lead.name ?? labels.unavailable}</TableCell>
|
|
114
|
-
<TableCell>{lead.email}</TableCell>
|
|
115
|
-
<TableCell>{lead.source}</TableCell>
|
|
116
|
-
<TableCell>{created}</TableCell>
|
|
117
|
-
</TableRow>
|
|
118
|
-
))}
|
|
119
|
-
</TableBody>
|
|
120
|
-
</Table>
|
|
121
|
-
{nextCursor !== null ? (
|
|
122
|
-
<div className="mt-3 flex justify-end">
|
|
123
|
-
<Link
|
|
124
|
-
href={buildNextHref(locale, nextCursor)}
|
|
125
|
-
data-testid="leads-table-next"
|
|
126
|
-
// 24px hit-area floor (Rule 14) — a bare inline link's
|
|
127
|
-
// line-height box falls short on its own (#4665, caught on the
|
|
128
|
-
// worker's own re-inspection of the render evidence).
|
|
129
|
-
className="inline-flex min-h-6 items-center px-2"
|
|
130
|
-
>
|
|
131
|
-
{labels.next}
|
|
132
|
-
</Link>
|
|
133
|
-
</div>
|
|
134
|
-
) : null}
|
|
135
|
-
</div>
|
|
136
|
-
);
|
|
137
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* /[locale]/leads — the signed-in site owner's lead inbox (#5678).
|
|
3
|
-
*
|
|
4
|
-
* RSC: reads `GET /v1/leads` through `@working-theory/api-client`'s `leads`
|
|
5
|
-
* namespace, forwarding the caller's cookie session
|
|
6
|
-
* (`../../../../lib/server-api`, #4665 D9) — never a hand-rolled `fetch`
|
|
7
|
-
* (`architecture.yaml`: `apps/web` may not reach `apps/api` directly). The
|
|
8
|
-
* route is owner-scoped server-side, so this page passes no site or workspace
|
|
9
|
-
* argument; the only query it owns is the forward-only `?cursor=`.
|
|
10
|
-
*
|
|
11
|
-
* A 401/403 renders `ForbiddenState` (no leak of why — the same shape the
|
|
12
|
-
* waitlist comparison page uses); every other error (a 400 on a malformed
|
|
13
|
-
* cursor, a 500) rethrows to the route's error boundary rather than being
|
|
14
|
-
* swallowed.
|
|
15
|
-
*
|
|
16
|
-
* The page reads the session itself before any API call (#6865): Next renders
|
|
17
|
-
* it concurrently with the (authed) layout, so for an anonymous visitor the
|
|
18
|
-
* layout's `SignInGate` wins but this page would still have called
|
|
19
|
-
* `leads.list()` — spending (or, with no API reachable, failing) a request
|
|
20
|
-
* for a result nobody sees. No session renders `ForbiddenState` with no
|
|
21
|
-
* apps/api request, the same guard `../account/page.tsx` carries.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { leads, type LeadInboxPage } from "@working-theory/api-client";
|
|
25
|
-
import { PageHeader } from "@working-theory/ui/blocks";
|
|
26
|
-
import { Container, Heading, Text } from "@working-theory/ui/primitives";
|
|
27
|
-
import type { Metadata } from "next";
|
|
28
|
-
import { headers } from "next/headers";
|
|
29
|
-
import { getTranslations } from "next-intl/server";
|
|
30
|
-
import type { ReactElement } from "react";
|
|
31
|
-
|
|
32
|
-
import { auth } from "../../../../auth";
|
|
33
|
-
import { ApiError, forwardedCookieInit, unwrapApiResult } from "../../../../lib/server-api";
|
|
34
|
-
import { ForbiddenState } from "../waitlist/components/ForbiddenState";
|
|
35
|
-
import { formatDateTime } from "../waitlist/format";
|
|
36
|
-
|
|
37
|
-
import { LeadsTable } from "./components/LeadsTable";
|
|
38
|
-
|
|
39
|
-
interface Props {
|
|
40
|
-
params: Promise<{ locale: string }>;
|
|
41
|
-
searchParams: Promise<{ cursor?: string }>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
45
|
-
const { locale } = await params;
|
|
46
|
-
const t = await getTranslations({ locale, namespace: "leadsInbox" });
|
|
47
|
-
return { title: t("title"), description: t("description") };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default async function LeadsInboxPage({
|
|
51
|
-
params,
|
|
52
|
-
searchParams,
|
|
53
|
-
}: Props): Promise<ReactElement> {
|
|
54
|
-
const { locale } = await params;
|
|
55
|
-
const { cursor } = await searchParams;
|
|
56
|
-
const t = await getTranslations({ locale, namespace: "leadsInbox" });
|
|
57
|
-
|
|
58
|
-
const forbidden = (
|
|
59
|
-
<ForbiddenState headline={t("forbiddenHeadline")} description={t("forbiddenDescription")} />
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const session = await auth.api.getSession({ headers: await headers() });
|
|
63
|
-
if (!session) return forbidden;
|
|
64
|
-
|
|
65
|
-
const init = await forwardedCookieInit();
|
|
66
|
-
|
|
67
|
-
let page: LeadInboxPage;
|
|
68
|
-
try {
|
|
69
|
-
page = await unwrapApiResult(leads.list(cursor ? { cursor } : {}, init));
|
|
70
|
-
} catch (err) {
|
|
71
|
-
if (err instanceof ApiError && (err.status === 401 || err.status === 403)) {
|
|
72
|
-
return forbidden;
|
|
73
|
-
}
|
|
74
|
-
// A 400 means the `?cursor=` in the URL did not resolve — it was typed,
|
|
75
|
-
// or it is a stale next-page link whose row has since gone. That is a bad
|
|
76
|
-
// address, not a broken page, so fall back to the first page rather than
|
|
77
|
-
// letting it reach the route's error boundary (PR #5705 security review,
|
|
78
|
-
// finding 3). A 400 from the FIRST-page read has no cursor to blame and
|
|
79
|
-
// would be a genuine contract break, so it is rethrown.
|
|
80
|
-
if (err instanceof ApiError && err.status === 400 && cursor) {
|
|
81
|
-
page = await unwrapApiResult(leads.list({}, init));
|
|
82
|
-
} else {
|
|
83
|
-
throw err;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const rows = page.items.map((lead) => ({
|
|
88
|
-
lead,
|
|
89
|
-
created: formatDateTime(lead.createdAt, locale),
|
|
90
|
-
}));
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<main className="min-h-screen bg-surface text-fg" data-testid="leads-inbox-page">
|
|
94
|
-
<PageHeader />
|
|
95
|
-
<Container className="flex flex-col gap-6 py-section">
|
|
96
|
-
<div>
|
|
97
|
-
<Heading level={1}>{t("title")}</Heading>
|
|
98
|
-
<Text as="p" variant="body-sm" tone="muted" className="mt-1">
|
|
99
|
-
{t("description")}
|
|
100
|
-
</Text>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<LeadsTable
|
|
104
|
-
locale={locale}
|
|
105
|
-
rows={rows}
|
|
106
|
-
nextCursor={page.nextCursor}
|
|
107
|
-
labels={{
|
|
108
|
-
caption: t("table.caption"),
|
|
109
|
-
columnName: t("table.columnName"),
|
|
110
|
-
columnEmail: t("table.columnEmail"),
|
|
111
|
-
columnSource: t("table.columnSource"),
|
|
112
|
-
columnCreated: t("table.columnCreated"),
|
|
113
|
-
unavailable: t("table.unavailable"),
|
|
114
|
-
next: t("table.next"),
|
|
115
|
-
emptyHeadline: t("table.emptyHeadline"),
|
|
116
|
-
emptyDescription: t("table.emptyDescription"),
|
|
117
|
-
}}
|
|
118
|
-
/>
|
|
119
|
-
</Container>
|
|
120
|
-
</main>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ForbiddenState — the dashboard's shared 401/403 rendering (#4665 D9, §2.2
|
|
3
|
-
* Security: "a 401/403 renders an EmptyState (no leak of why)").
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { EmptyState } from "@working-theory/ui/primitives";
|
|
7
|
-
import type { ReactElement } from "react";
|
|
8
|
-
|
|
9
|
-
export function ForbiddenState({
|
|
10
|
-
headline,
|
|
11
|
-
description,
|
|
12
|
-
}: {
|
|
13
|
-
headline: string;
|
|
14
|
-
description: string;
|
|
15
|
-
}): ReactElement {
|
|
16
|
-
return (
|
|
17
|
-
<div
|
|
18
|
-
className="flex min-h-[50vh] items-center justify-center py-section"
|
|
19
|
-
data-testid="waitlist-forbidden"
|
|
20
|
-
>
|
|
21
|
-
<EmptyState headline={headline} description={description} />
|
|
22
|
-
</div>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Display formatting for the waitlist operator dashboard (#4665 D4/D10, UI).
|
|
3
|
-
*
|
|
4
|
-
* The ONE place a number, rate, or date becomes a string for this surface
|
|
5
|
-
* (Rule 10 — formatting happens in `apps/web`, never inside a
|
|
6
|
-
* `packages/ui/src/blocks/*` component). Every formatter here is
|
|
7
|
-
* locale-aware; the caller supplies the active `[locale]` route segment.
|
|
8
|
-
*
|
|
9
|
-
* `null` is D4's "unavailable" sentinel (an unscored / non-qualifying
|
|
10
|
-
* experiment) — rendered as an em dash, never `0` or an empty string, so an
|
|
11
|
-
* unscored row is never misread as a zero row.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { formatNumber, formatPercent } from "@working-theory/web-i18n";
|
|
15
|
-
|
|
16
|
-
/** D4/D9's "no value" rendering — never `0`, never blank. */
|
|
17
|
-
export const UNAVAILABLE = "—";
|
|
18
|
-
|
|
19
|
-
/** Format a raw count (signups, tier counts, question `answered`). */
|
|
20
|
-
export function formatCount(value: number, locale: string): string {
|
|
21
|
-
return formatNumber(value, locale);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Format a rate/share (0–1) as a percentage, or the unavailable sentinel when
|
|
26
|
-
* `null` (D4 — `qualified`/`qualificationRate` are `null` for a
|
|
27
|
-
* `lead-capture` experiment; a distribution `share` is always a number).
|
|
28
|
-
*/
|
|
29
|
-
export function formatRate(value: number | null, locale: string): string {
|
|
30
|
-
if (value === null) return UNAVAILABLE;
|
|
31
|
-
return formatPercent(value, locale);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Format an ISO-8601 datetime for display (list/comparison/drill-down). */
|
|
35
|
-
export function formatDateTime(iso: string, locale: string): string {
|
|
36
|
-
return new Intl.DateTimeFormat(locale, {
|
|
37
|
-
dateStyle: "medium",
|
|
38
|
-
timeStyle: "short",
|
|
39
|
-
}).format(new Date(iso));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ─── FEAT-074 U4a (#4715) — the targeting-maturity Level display ────────────
|
|
43
|
-
//
|
|
44
|
-
// Presentation-only mapping (spec D5): `level_3` -> the integer `3`,
|
|
45
|
-
// `level_0` -> `0` (the Gate). Scoped to the ONE experiment this Level
|
|
46
|
-
// vocabulary applies to — every other experiment's tier renders unchanged
|
|
47
|
-
// (AC-5's "a non-targeting experiment renders exactly as before"). Pure
|
|
48
|
-
// parsing only, no i18n — the CALLER (the page, which already owns every
|
|
49
|
-
// `getTranslations` call on this surface) turns the returned number into
|
|
50
|
-
// the "Level N" / Gate string via its own `t()`.
|
|
51
|
-
|
|
52
|
-
/** The one experiment this Level vocabulary applies to. */
|
|
53
|
-
export const TARGETING_MATURITY_EXPERIMENT_KEY = "targeting-maturity";
|
|
54
|
-
|
|
55
|
-
const LEVEL_TIER_RE = /^level_(\d+)$/;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* The Level number for a `targeting-maturity` `level_N` tier — `0` for the
|
|
59
|
-
* Gate, `N` otherwise. `null` for any other experiment, a `null` tier, or an
|
|
60
|
-
* unrecognized tier shape — the caller falls back to the raw tier /
|
|
61
|
-
* `labels.unavailable` unchanged (D5).
|
|
62
|
-
*/
|
|
63
|
-
export function targetingMaturityLevel(
|
|
64
|
-
tier: string | null,
|
|
65
|
-
experimentKey: string,
|
|
66
|
-
): number | null {
|
|
67
|
-
if (experimentKey !== TARGETING_MATURITY_EXPERIMENT_KEY || tier === null) return null;
|
|
68
|
-
const match = LEVEL_TIER_RE.exec(tier);
|
|
69
|
-
return match ? Number(match[1]) : null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The `ref(<name>)` def names that DECIDED the matched tier, for the
|
|
74
|
-
* ScoreTrace drill-down's "deciding factors" section (AC-5) — every
|
|
75
|
-
* `kind: "predicate"` entry in a `RuleTraceEntry[]`-shaped `ruleTrace`
|
|
76
|
-
* whose `tier` equals the signup's own tier AND whose `result` is `true`,
|
|
77
|
-
* with every `ref(...)` segment in its `path` extracted (there is no
|
|
78
|
-
* separate `def` field — `evaluatePredicateNode`'s own path-building embeds
|
|
79
|
-
* each traversed def as `ref(<name>)`). Duck-typed against `unknown`
|
|
80
|
-
* (`ruleTrace` is `z.unknown()` at this boundary — `waitlist-dashboard.ts`'s
|
|
81
|
-
* schema comment), mirroring the identical extraction the backend's
|
|
82
|
-
* `playbook-compile.ts` uses for its Level-1 loop-back framing — this is
|
|
83
|
-
* the read-side counterpart, not a fork of it (no shared module: the two
|
|
84
|
-
* sides are in different apps, which may not cross-import — `architecture.yaml`).
|
|
85
|
-
* `[]` for any other experiment (AC-5's non-targeting byte-unchanged floor).
|
|
86
|
-
*/
|
|
87
|
-
export function decidingDefsFor(
|
|
88
|
-
tier: string | null,
|
|
89
|
-
ruleTrace: unknown,
|
|
90
|
-
experimentKey: string,
|
|
91
|
-
): string[] {
|
|
92
|
-
if (experimentKey !== TARGETING_MATURITY_EXPERIMENT_KEY || tier === null) return [];
|
|
93
|
-
if (!Array.isArray(ruleTrace)) return [];
|
|
94
|
-
const seen = new Set<string>();
|
|
95
|
-
const names: string[] = [];
|
|
96
|
-
for (const entry of ruleTrace) {
|
|
97
|
-
if (typeof entry !== "object" || entry === null) continue;
|
|
98
|
-
const e = entry as Record<string, unknown>;
|
|
99
|
-
if (e["kind"] !== "predicate" || e["tier"] !== tier || e["result"] !== true) continue;
|
|
100
|
-
const path = e["path"];
|
|
101
|
-
if (typeof path !== "string") continue;
|
|
102
|
-
for (const m of path.matchAll(/ref\(([^)]+)\)/g)) {
|
|
103
|
-
const name = m[1]!;
|
|
104
|
-
if (!seen.has(name)) {
|
|
105
|
-
seen.add(name);
|
|
106
|
-
names.push(name);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return names;
|
|
111
|
-
}
|