create-ailk 0.34.1 → 0.35.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.
Files changed (54) hide show
  1. package/component-catalog.json +25 -3
  2. package/component-catalog.md +9 -8
  3. package/dist/add-module.js +7 -2
  4. package/dist/derive-architecture.js +2 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/module-architecture.js +9 -0
  8. package/dist/programmatic.js +5 -2
  9. package/dist/site-listing-path.d.ts +8 -0
  10. package/dist/site-listing-path.js +8 -0
  11. package/dist/surfaces.d.ts +20 -0
  12. package/dist/surfaces.js +26 -0
  13. package/dist/template-record.js +2 -0
  14. package/dist/update.js +11 -0
  15. package/package.json +3 -3
  16. package/templates/apps/api/CLAUDE.md +6 -6
  17. package/templates/apps/mcp/CLAUDE.md +16 -7
  18. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +43 -0
  19. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +6 -5
  20. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +6 -1
  21. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +43 -4
  22. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +23 -9
  23. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +15 -0
  24. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +74 -0
  25. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +34 -1
  26. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +257 -4
  27. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +72 -92
  28. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +2 -2
  29. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +164 -65
  30. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +100 -0
  31. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +99 -0
  32. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +415 -253
  33. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +113 -32
  34. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +16 -17
  35. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +284 -0
  36. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +52 -19
  37. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +402 -0
  38. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +100 -12
  39. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +153 -101
  40. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +36 -0
  41. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +121 -33
  42. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +27 -17
  43. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +91 -0
  44. package/templates/apps/web/app/[locale]/layout.tsx +18 -1
  45. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +24 -0
  46. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +5 -1
  47. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +122 -0
  48. package/templates/apps/web/app/llms.txt/route.ts +14 -2
  49. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +98 -0
  50. package/templates/apps/web/app/sitemap.xml/route.ts +13 -2
  51. package/templates/apps/web/lib/account-config.ts +24 -9
  52. package/templates/apps/web/lib/site-listing.ts +7 -0
  53. package/templates/apps/web/messages/en.json +13 -1
  54. package/versions.json +47 -47
@@ -1,18 +1,21 @@
1
1
  /**
2
- * Tests for "Email me this plan" — `saveRecommendationAction` (#4842 D7),
3
- * split out of `checkout.actions.ts` with its cases by #6786 so the save half
4
- * ships with the results page while checkout stays commerce's.
2
+ * Tests for Get your full report — `sendResultsEmailAction` (#11013 spec E,
3
+ * D-F), the results page's email moment, which replaced "Email me this plan"
4
+ * (`saveRecommendationAction`, #4842 D7 / #6786).
5
5
  *
6
- * AC-4 (the action half) — calls `flows.save` once with
7
- * `{ answers, email, locale }` and returns the lead id.
8
- * D7 — the shared status → kind map (`email-moment.ts`), never a throw;
9
- * an invalid body → `invalid_input` without calling the api-client.
6
+ * AC-4 (the action half) — refuses a bad slug or body as `invalid_input`
7
+ * without a call; `unavailable` on a refused bot check; on success calls
8
+ * `flows.resultsEmail` once with the body and the visitor's IP init and
9
+ * answers `{ ok: true }` — never an id. No `saveRecommendationAction`
10
+ * export remains.
11
+ * D7 — the shared status → kind map (`email-moment.ts`), never a throw.
10
12
  *
11
13
  * Mock shape: `checkout.actions.test.ts`'s (`@working-theory/api-client` +
12
14
  * `next/headers`).
13
15
  */
14
16
 
15
- import { saveRecommendationAction } from "../save.actions.js";
17
+ import * as actions from "../save.actions.js";
18
+ import { sendResultsEmailAction } from "../save.actions.js";
16
19
 
17
20
  // #9255 — the write bot check's verdict. `checkBotId` reads Vercel's
18
21
  // request context, which jest has none of, so every case decides it here.
@@ -23,6 +26,7 @@ jest.mock("botid/server", () => ({
23
26
 
24
27
  jest.mock("@working-theory/api-client", () => ({
25
28
  flows: {
29
+ resultsEmail: jest.fn(),
26
30
  save: jest.fn(),
27
31
  },
28
32
  }));
@@ -35,12 +39,13 @@ jest.mock("next/headers", () => ({
35
39
  import { flows } from "@working-theory/api-client";
36
40
  import { headers } from "next/headers";
37
41
 
42
+ const mockResultsEmail = flows.resultsEmail as jest.Mock;
38
43
  const mockSave = flows.save as jest.Mock;
39
44
  const mockHeaders = headers as jest.Mock;
40
45
 
41
46
  const SLUG = "ailk-recommender";
42
47
  const ANSWERS = { team_size: "agency", wants_seo: "yes" };
43
- const SAVE_BODY = { answers: ANSWERS, email: "jane@example.com", locale: "en" };
48
+ const BODY = { answers: ANSWERS, email: "jane@example.com", locale: "en" };
44
49
 
45
50
  beforeEach(() => {
46
51
  jest.spyOn(console, "error").mockImplementation(() => undefined);
@@ -52,77 +57,71 @@ afterEach(() => {
52
57
  mockHeaders.mockResolvedValue({ get: () => null });
53
58
  });
54
59
 
55
- describe("saveRecommendationAction — AC-4 (the action half)", () => {
56
- it("calls flows.save once with { answers, email, locale } and returns the leadId", async () => {
57
- mockSave.mockResolvedValueOnce({
58
- ok: true,
59
- body: { leadId: "lead_1", sessionId: "fs_1" },
60
- });
61
- await expect(saveRecommendationAction(SLUG, SAVE_BODY)).resolves.toEqual({
62
- ok: true,
63
- leadId: "lead_1",
64
- });
65
- expect(mockSave).toHaveBeenCalledTimes(1);
66
- expect(mockSave).toHaveBeenCalledWith(SLUG, SAVE_BODY);
60
+ describe("sendResultsEmailAction — AC-4 (the action half)", () => {
61
+ it("calls flows.resultsEmail once with the body and answers { ok: true } with no id", async () => {
62
+ mockResultsEmail.mockResolvedValueOnce({ ok: true, body: { sent: true } });
63
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({ ok: true });
64
+ expect(mockResultsEmail).toHaveBeenCalledTimes(1);
65
+ expect(mockResultsEmail).toHaveBeenCalledWith(SLUG, BODY);
66
+ expect(mockSave).not.toHaveBeenCalled();
67
67
  });
68
68
 
69
- it("maps failures exactly as checkout does and never throws", async () => {
70
- mockSave.mockResolvedValueOnce({
71
- ok: false,
72
- status: 429,
73
- body: { retryAfterSeconds: 9 },
74
- });
75
- await expect(saveRecommendationAction(SLUG, SAVE_BODY)).resolves.toEqual({
69
+ it("forwards the stored session id when the body carries one", async () => {
70
+ mockResultsEmail.mockResolvedValueOnce({ ok: true, body: { sent: true } });
71
+ await sendResultsEmailAction(SLUG, { ...BODY, sessionId: "fs_1" });
72
+ expect(mockResultsEmail).toHaveBeenCalledWith(SLUG, { ...BODY, sessionId: "fs_1" });
73
+ });
74
+
75
+ it("maps failures through the shared status → kind map and never throws", async () => {
76
+ mockResultsEmail.mockResolvedValueOnce({ ok: false, status: 429, body: { retryAfterSeconds: 9 } });
77
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({
76
78
  ok: false,
77
79
  kind: "rate_limited",
78
80
  retryAfterSeconds: 9,
79
81
  });
80
- mockSave.mockRejectedValueOnce(new Error("boom"));
81
- await expect(saveRecommendationAction(SLUG, SAVE_BODY)).resolves.toEqual({
82
+ mockResultsEmail.mockResolvedValueOnce({ ok: false, status: 409, body: null });
83
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({ ok: false, kind: "not_configured" });
84
+ mockResultsEmail.mockRejectedValueOnce(new Error("boom"));
85
+ await expect(sendResultsEmailAction(SLUG, BODY)).resolves.toEqual({ ok: false, kind: "network" });
86
+ expect(mockResultsEmail).toHaveBeenCalledTimes(3);
87
+ });
88
+
89
+ it.each([
90
+ ["a bad email", SLUG, { ...BODY, email: "nope" }],
91
+ ["an unknown body key", SLUG, { ...BODY, consents: { marketing: true } }],
92
+ ["a bad slug", "Not A Slug", BODY],
93
+ ])("%s is invalid_input with no call", async (_label, slug, body) => {
94
+ await expect(sendResultsEmailAction(slug, body as typeof BODY)).resolves.toEqual({
82
95
  ok: false,
83
- kind: "network",
96
+ kind: "invalid_input",
84
97
  });
85
- await expect(
86
- saveRecommendationAction(SLUG, { ...SAVE_BODY, email: "nope" }),
87
- ).resolves.toEqual({ ok: false, kind: "invalid_input" });
88
- expect(mockSave).toHaveBeenCalledTimes(2);
98
+ expect(mockResultsEmail).not.toHaveBeenCalled();
99
+ expect(checkBotIdMock).not.toHaveBeenCalled();
89
100
  });
90
101
 
91
102
  it("forwards the visitor's x-forwarded-for on the outbound call (#4730)", async () => {
92
103
  mockHeaders.mockResolvedValueOnce({
93
- get: (name: string) =>
94
- name === "x-forwarded-for" ? "203.0.113.7" : null,
104
+ get: (name: string) => (name === "x-forwarded-for" ? "203.0.113.7" : null),
95
105
  });
96
- mockSave.mockResolvedValueOnce({
97
- ok: true,
98
- body: { leadId: "lead_1", sessionId: "fs_1" },
99
- });
100
- await saveRecommendationAction(SLUG, SAVE_BODY);
101
- expect(mockSave).toHaveBeenCalledWith(SLUG, SAVE_BODY, {
106
+ mockResultsEmail.mockResolvedValueOnce({ ok: true, body: { sent: true } });
107
+ await sendResultsEmailAction(SLUG, BODY);
108
+ expect(mockResultsEmail).toHaveBeenCalledWith(SLUG, BODY, {
102
109
  headers: { "x-forwarded-for": "203.0.113.7" },
103
110
  });
104
111
  });
112
+
113
+ it("no saveRecommendationAction export remains", () => {
114
+ expect(Object.keys(actions)).not.toContain("saveRecommendationAction");
115
+ });
105
116
  });
106
117
 
107
118
  // #9255 D4 — the write bot check runs after the slug and body checks,
108
- // immediately before the write (spec
109
- // docs/specs/9255-an-edge-bot-challenge-in-spec.md §5.1 AC-2).
110
- describe("saveRecommendationAction — the write bot check (#9255)", () => {
111
- const BOT = {
112
- isHuman: false,
113
- isBot: true,
114
- isVerifiedBot: false,
115
- bypassed: false,
116
- };
119
+ // immediately before the write.
120
+ describe("sendResultsEmailAction — the write bot check (#9255)", () => {
121
+ const BOT = { isHuman: false, isBot: true, isVerifiedBot: false, bypassed: false };
117
122
  const HUMAN = { ...BOT, isHuman: true, isBot: false };
118
- const BOT_ENV_KEYS = [
119
- "VERCEL",
120
- "AILK_BOT_CHECK",
121
- "AILK_BOOKING_BOT_CHECK",
122
- ] as const;
123
- const priorBotEnv = new Map(
124
- BOT_ENV_KEYS.map((name) => [name, process.env[name]]),
125
- );
123
+ const BOT_ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK", "AILK_BOOKING_BOT_CHECK"] as const;
124
+ const priorBotEnv = new Map(BOT_ENV_KEYS.map((name) => [name, process.env[name]]));
126
125
 
127
126
  let botLogSpies: jest.SpyInstance[] = [];
128
127
 
@@ -146,48 +145,29 @@ describe("saveRecommendationAction — the write bot check (#9255)", () => {
146
145
 
147
146
  it.each([
148
147
  ["a bot", () => checkBotIdMock.mockResolvedValue(BOT)],
149
- [
150
- "a check that fails",
151
- () => checkBotIdMock.mockRejectedValue(new Error("boom")),
152
- ],
153
- ])(
154
- "%s gets kind unavailable, and nothing is sent",
155
- async (_label, decide) => {
156
- decide();
157
- expect(await saveRecommendationAction(SLUG, SAVE_BODY)).toStrictEqual({
158
- ok: false,
159
- kind: "unavailable",
160
- });
161
- expect(checkBotIdMock).toHaveBeenCalledTimes(1);
162
- expect(mockSave).not.toHaveBeenCalled();
163
- },
164
- );
148
+ ["a check that fails", () => checkBotIdMock.mockRejectedValue(new Error("boom"))],
149
+ ])("%s gets kind unavailable, and nothing is sent", async (_label, decide) => {
150
+ decide();
151
+ expect(await sendResultsEmailAction(SLUG, BODY)).toStrictEqual({ ok: false, kind: "unavailable" });
152
+ expect(checkBotIdMock).toHaveBeenCalledTimes(1);
153
+ expect(mockResultsEmail).not.toHaveBeenCalled();
154
+ });
165
155
 
166
156
  it("a human sends exactly what the check off sends", async () => {
167
157
  checkBotIdMock.mockResolvedValue(HUMAN);
168
- mockSave.mockResolvedValue({
169
- ok: true,
170
- status: 201,
171
- body: { leadId: "lead_1" },
172
- });
158
+ mockResultsEmail.mockResolvedValue({ ok: true, status: 200, body: { sent: true } });
173
159
  delete process.env.VERCEL;
174
- await saveRecommendationAction(SLUG, SAVE_BODY);
160
+ await sendResultsEmailAction(SLUG, BODY);
175
161
  process.env.VERCEL = "1";
176
- expect(await saveRecommendationAction(SLUG, SAVE_BODY)).toEqual({
177
- ok: true,
178
- leadId: "lead_1",
179
- });
162
+ expect(await sendResultsEmailAction(SLUG, BODY)).toEqual({ ok: true });
180
163
  expect(checkBotIdMock).toHaveBeenCalledTimes(1);
181
- expect(mockSave).toHaveBeenCalledTimes(2);
182
- expect(mockSave.mock.calls[1]).toEqual(mockSave.mock.calls[0]);
164
+ expect(mockResultsEmail).toHaveBeenCalledTimes(2);
165
+ expect(mockResultsEmail.mock.calls[1]).toEqual(mockResultsEmail.mock.calls[0]);
183
166
  });
184
167
 
185
168
  it("an invalid slug answers invalid_input with no check", async () => {
186
169
  checkBotIdMock.mockResolvedValue(BOT);
187
- expect(await saveRecommendationAction("Not A Slug", SAVE_BODY)).toEqual({
188
- ok: false,
189
- kind: "invalid_input",
190
- });
170
+ expect(await sendResultsEmailAction("Not A Slug", BODY)).toEqual({ ok: false, kind: "invalid_input" });
191
171
  expect(checkBotIdMock).not.toHaveBeenCalled();
192
172
  });
193
173
  });
@@ -1,8 +1,8 @@
1
1
  // oss: false
2
2
  /**
3
3
  * email-moment.ts — the helpers the recommender's two email-moment Server
4
- * Actions share (#4842 D7): `saveRecommendationAction` (`save.actions.ts`,
5
- * shipped with the results page) and `startCheckoutAction`
4
+ * Actions share (#4842 D7): `sendResultsEmailAction` (`save.actions.ts`,
5
+ * shipped with the results page; #11013 D-F) and `startCheckoutAction`
6
6
  * (`checkout.actions.ts`, commerce's). Split out of `checkout.actions.ts` by
7
7
  * #6786 so the save half ships without the checkout half; a `"use server"`
8
8
  * file may export only async functions, so the shared sync helpers live here.
@@ -3,13 +3,25 @@
3
3
  * magnet-page.tsx — the standard magnet page pair (#8840 D8).
4
4
  *
5
5
  * Every multi-step magnet is two pages, the canon's #5053 split moved to the
6
- * magnet's own path: an indexable LANDING (`/<magnet>`, inside the site's
7
- * chrome — a centred hero of the flow record's `landing` copy, a CTA to
8
- * `/<magnet>/start`, and the `Assessment` page type's single-layer
9
- * `WebApplication` JSON-LD) and a `noindex, follow` WALK (`/<magnet>/start`,
10
- * or the `startPath` a landing names, as `/trial` names `/trial/request` —
11
- * #9287 DD10; chrome-free by `lib/magnet-routes.ts`, the back arrow alone
12
- * above step 1).
6
+ * magnet's own path: an indexable LANDING (`/<magnet>`, the flow record's
7
+ * `landing` copy with a CTA to `/<magnet>/start` and the `Assessment` page
8
+ * type's single-layer `WebApplication` JSON-LD) and a `noindex, follow`
9
+ * WALK (`/<magnet>/start`, or the `startPath` a landing names, as `/trial`
10
+ * names `/trial/request` — #9287 DD10; chrome-free by `lib/magnet-routes.ts`).
11
+ *
12
+ * #11013 (spec E, D-A, D-B, D-D) — a multi-step magnet's landing is the
13
+ * TITLE PAGE: the same takeover window the walk lives in (`FlowFrame`, no
14
+ * bar, the site's logomark and wordmark on the left and one `Esc ×` exit to
15
+ * the site's home on the right, no header title), holding one `h1` (the
16
+ * landing title at `--flow-title-size`), the description, the button to the
17
+ * walk and a Time line — the record's `landing.meta`, else the counted
18
+ * steps ÷ 5 as "~ {n} min". The site chrome stays in the document under the
19
+ * overlay, so the page keeps its URL and its JSON-LD and stays indexable; a
20
+ * one-step flow keeps the centred hero inside the chrome. The walk hands
21
+ * `FlowStepperClient` the frame's brand (the marks and the landing title)
22
+ * and an exit to where the walk was entered from — the landing, or the
23
+ * posting — in place of the back arrow; the unavailable fallback keeps the
24
+ * arrow.
13
25
  * This module is the only code that renders either half: `/flows/<slug>`,
14
26
  * the careers apply pages and every pair `create-ailk add-route magnet`
15
27
  * writes are callers of the factories below.
@@ -19,9 +31,11 @@
19
31
  * burst of views make one hub read. A slug the schema refuses is `absent`
20
32
  * with no read and no cache entry, each insert first drops the stale
21
33
  * entries, and the map holds at most 256 slugs, so random URLs cannot grow
22
- * it (SEC-8840-G). A refused
23
- * connection or a 5xx is `unavailable`: both pages then show the site's
24
- * contact email instead of a 500, are `noindex`, and retry nothing. A site
34
+ * it (SEC-8840-G). The read itself is `served-flow.ts`'s `readServedFlow`
35
+ * (#10990 D1): anything but a served flow or a 404 — a refused connection, a
36
+ * 5xx, a 403 or 429, a 2xx that is not a flow, no answer within 5 s — is
37
+ * `unavailable`: both pages then show the site's contact email instead of a
38
+ * 500, are `noindex`, and retry nothing. A site
25
39
  * with no hub to ask — the read answers 503 `flows_not_configured`, or a
26
40
  * failed read with no API origin configured — is `not-configured` (#9219);
27
41
  * a pair renders it as `unavailable`, and `/reports/<slug>` uses it to 404
@@ -37,24 +51,37 @@
37
51
  * hand it over and an ungated deliverable never gets a form here. The
38
52
  * deliverable's own walk calls `renderMagnetStart` with `asDeliverable`.
39
53
  */
40
- import { flows } from "@working-theory/api-client";
41
54
  import { JsonLd } from "@working-theory/jsonld";
42
55
  import { flowRouteMetadata } from "@working-theory/metadata";
43
56
  import { buildJsonLd } from "@working-theory/schema";
44
- import { ContactFallback, Container, Heading, localeHref } from "@working-theory/ui";
57
+ import type { FlowFrameBrand, FlowFramePresentation } from "@working-theory/ui";
58
+ import {
59
+ Button,
60
+ ContactFallback,
61
+ Container,
62
+ FlowFrame,
63
+ Heading,
64
+ Icon,
65
+ Link,
66
+ localeHref,
67
+ Text,
68
+ } from "@working-theory/ui";
45
69
  import { NavBackLink } from "@working-theory/ui/chrome";
70
+ import { Image } from "@working-theory/ui/primitives";
46
71
  import { SectionRenderer } from "@working-theory/ui/sections";
47
72
  import type { FlowConfig, PageSection } from "@working-theory/validation";
48
73
  import { flowSlugSchema, resolveLocalizedString } from "@working-theory/validation";
74
+ import { ArrowRight } from "lucide-react";
49
75
  import type { Metadata } from "next";
50
76
  import { notFound, redirect } from "next/navigation";
51
77
  import { getTranslations } from "next-intl/server";
52
- import type { ReactElement } from "react";
78
+ import type { CSSProperties, ReactElement } from "react";
53
79
 
54
- import { browserApiOrigin } from "../../../../lib/api-origin.generated";
80
+ import { siteLogo, siteWordmarkAsset } from "../../../../lib/site-logo";
55
81
  import { readSiteContactEmail } from "../../contact/site-contact-email";
56
82
 
57
83
  import { FlowStepperClient } from "./FlowStepperClient";
84
+ import { type MagnetRead, readServedFlow } from "./served-flow";
58
85
 
59
86
  /** The marker every standard magnet page carries in its header comment (D13). */
60
87
  export const MAGNET_PAGE_MARKER = "Standard magnet page (#8840)";
@@ -65,52 +92,42 @@ const MAGNET_READ_TTL_MS = 15_000;
65
92
  /** At most this many slugs are held at once; past it a read is not shared. */
66
93
  const MAGNET_READ_MAX_ENTRIES = 256;
67
94
 
68
- export type MagnetRead =
69
- | { kind: "ok"; config: FlowConfig }
70
- | { kind: "absent" }
71
- | { kind: "unavailable" }
72
- | { kind: "not-configured" };
95
+ export type { MagnetRead } from "./served-flow";
73
96
 
74
- const magnetReads = new Map<string, { at: number; read: Promise<MagnetRead> }>();
97
+ // Mirrors `FlowStepperClient.tsx` (#4707) — a path the frame's exit follows
98
+ // is built only from an enabled locale, never the raw route segment.
99
+ const DEFAULT_LOCALE = "en";
100
+ const ENABLED_LOCALES = (process.env.NEXT_PUBLIC_ENABLED_LOCALES ?? DEFAULT_LOCALE).split(",");
75
101
 
76
- /**
77
- * Whether an API origin is configured: the three names `getApiBase()` in
78
- * packages/api-client/src/http.ts reads, in step with it on a hub. Without one
79
- * that function answers `localhost:3001`. The browser-facing origin comes from
80
- * the topology seam (#7874 D12), which a spoke renders with no env read, so a
81
- * spoke passes its own `env:check` (#9480). A spoke diverges on purpose: the
82
- * browser-facing name set on one at runtime counts as no origin here.
83
- */
84
- function apiOriginConfigured(): boolean {
85
- return Boolean(
86
- process.env.AILK_API_URL ||
87
- browserApiOrigin() ||
88
- process.env.NEXT_PUBLIC_API_URL,
89
- );
102
+ function resolveSafeLocale(candidate: string): string {
103
+ return ENABLED_LOCALES.includes(candidate) ? candidate : DEFAULT_LOCALE;
90
104
  }
91
105
 
92
- /** The flows route's own answer when its hub has no database (apps/api `flows_not_configured`). */
93
- function isFlowsNotConfigured(body: unknown): boolean {
94
- const error = (body as { error?: { code?: unknown } } | null)?.error;
95
- return error?.code === "flows_not_configured";
96
- }
106
+ // #11013 decision 21 / spec E D-B — the title's size, read from
107
+ // `--flow-title-size` with the heading-1 role as its fallback (heading-2
108
+ // below `md:`), declared under this page's own property names so a site's
109
+ // one-line `:root` declaration wins (the `FLOW_QUESTION_SIZE_STYLE` idiom).
110
+ const FLOW_TITLE_SIZE_STYLE = {
111
+ "--ailk-flow-title-size": "var(--flow-title-size, var(--text-heading-1))",
112
+ "--ailk-flow-title-size-sm": "var(--flow-title-size, var(--text-heading-2))",
113
+ } as CSSProperties;
114
+ const FLOW_TITLE_HEADING_CLASS =
115
+ "text-balance text-(length:--ailk-flow-title-size-sm) md:text-(length:--ailk-flow-title-size)";
97
116
 
98
- /** A read that failed: `not-configured` when there is no hub to ask, else `unavailable`. */
99
- function failedRead(): MagnetRead {
100
- return apiOriginConfigured() ? { kind: "unavailable" } : { kind: "not-configured" };
117
+ /** #11013 D-A — the frame's brand marks: the site's logomark and wordmark, built on the server. */
118
+ function brandMarks(): Pick<FlowFrameBrand, "logomark" | "wordmark"> {
119
+ return { logomark: siteLogo(), wordmark: <Image {...siteWordmarkAsset()} /> };
101
120
  }
102
121
 
103
- async function fetchMagnet(slug: string): Promise<MagnetRead> {
104
- try {
105
- const res = await flows.get(slug);
106
- if (res.ok) return { kind: "ok", config: res.body };
107
- if (res.status === 503 && isFlowsNotConfigured(res.body)) return { kind: "not-configured" };
108
- return res.status >= 500 ? failedRead() : { kind: "absent" };
109
- } catch {
110
- return failedRead();
111
- }
122
+ /** #11013 D-D — the Time line: the owner's words, else the counted steps ÷ 5. */
123
+ function landingTime(config: FlowConfig, meta: string | undefined, t: (key: "landingTime", values: { minutes: number }) => string): string {
124
+ if (meta !== undefined) return meta;
125
+ const counted = config.steps.filter((step) => step.type !== "message").length;
126
+ return t("landingTime", { minutes: Math.max(1, Math.round(counted / 5)) });
112
127
  }
113
128
 
129
+ const magnetReads = new Map<string, { at: number; read: Promise<MagnetRead> }>();
130
+
114
131
  /** The served flow config for `slug`, shared per instance for 15 seconds. */
115
132
  export function readMagnet(slug: string): Promise<MagnetRead> {
116
133
  if (!flowSlugSchema.safeParse(slug).success) {
@@ -122,7 +139,7 @@ export function readMagnet(slug: string): Promise<MagnetRead> {
122
139
  for (const [key, entry] of magnetReads) {
123
140
  if (now - entry.at >= MAGNET_READ_TTL_MS) magnetReads.delete(key);
124
141
  }
125
- const read = fetchMagnet(slug);
142
+ const read = readServedFlow(slug);
126
143
  if (magnetReads.size < MAGNET_READ_MAX_ENTRIES) magnetReads.set(slug, { at: now, read });
127
144
  return read;
128
145
  }
@@ -204,6 +221,88 @@ export async function renderMagnetLanding({
204
221
  if (read.config.deliverable !== undefined) redirect(localeHref(locale, `/reports/${slug}`));
205
222
 
206
223
  const copy = await landingCopy(read.config, locale);
224
+ const jsonLd = (
225
+ <JsonLd
226
+ schema={buildJsonLd({
227
+ type: "Assessment",
228
+ slug: read.config.slug,
229
+ title: copy.title,
230
+ description: copy.description,
231
+ locale,
232
+ })}
233
+ />
234
+ );
235
+
236
+ // #11013 D-B — a multi-step magnet's landing is the takeover title page.
237
+ if (read.config.steps.length > 1) {
238
+ const t = await getTranslations({ locale, namespace: "flow" });
239
+ return (
240
+ <>
241
+ {jsonLd}
242
+ <main>
243
+ <FlowFrame
244
+ takeover
245
+ barMode="none"
246
+ brand={brandMarks()}
247
+ exit={{ href: `/${resolveSafeLocale(locale)}`, label: t("exitLabel") }}
248
+ data-testid="flow-title-frame"
249
+ >
250
+ {/* On a phone the copy scrolls in its own column and the button row sits
251
+ below it (the board's dock), so the frame's middle region never
252
+ overflows and its bottom fade (decision 23) never dims the primary;
253
+ from `md:` the row follows the description in normal flow. */}
254
+ <div
255
+ data-testid="flow-title-page"
256
+ className="flex min-h-0 w-full flex-1 flex-col md:justify-center"
257
+ style={FLOW_TITLE_SIZE_STYLE}
258
+ >
259
+ <div
260
+ data-testid="flow-title-scroller"
261
+ className="min-h-0 flex-1 overflow-y-auto md:min-h-fit md:flex-none md:overflow-visible"
262
+ >
263
+ <div className="mx-auto w-full max-w-container-sm px-5 pt-3 md:px-6 md:pt-8">
264
+ <Heading level={1} className={FLOW_TITLE_HEADING_CLASS}>
265
+ {copy.title}
266
+ </Heading>
267
+ <Text
268
+ variant="lead"
269
+ tone="muted"
270
+ className="mt-block-tight max-w-prose text-pretty"
271
+ data-testid="flow-title-description"
272
+ >
273
+ {copy.description}
274
+ </Text>
275
+ </div>
276
+ </div>
277
+ {/* Decision 9 — the button under the description, with Time just below it;
278
+ on a phone full width and anchored to the screen bottom. */}
279
+ <div
280
+ className="mx-auto flex w-full max-w-container-sm shrink-0 flex-col gap-3 px-5 pt-6 pb-(--ailk-flow-safe-bottom) md:mt-block-loose md:items-start md:px-6 md:pb-10"
281
+ style={{ "--ailk-flow-safe-bottom": "max(env(safe-area-inset-bottom, 0px), 1.25rem)" } as CSSProperties}
282
+ >
283
+ <Button asChild size="big" className="min-h-11 w-full md:w-auto">
284
+ <Link href={localeHref(locale, startPath)} variant="bare" data-testid="flow-title-cta">
285
+ {copy.cta}
286
+ <Icon icon={ArrowRight} size="sm" decorative />
287
+ </Link>
288
+ </Button>
289
+ <Text
290
+ as="span"
291
+ variant="body-sm"
292
+ tone="muted"
293
+ className="text-center tabular-nums md:text-start"
294
+ data-testid="flow-title-time"
295
+ >
296
+ {landingTime(read.config, copy.meta, t)}
297
+ </Text>
298
+ </div>
299
+ </div>
300
+ </FlowFrame>
301
+ </main>
302
+ </>
303
+ );
304
+ }
305
+
207
306
  const sections: PageSection[] = [
208
307
  {
209
308
  id: "flow-landing-hero",
@@ -220,15 +319,7 @@ export async function renderMagnetLanding({
220
319
 
221
320
  return (
222
321
  <>
223
- <JsonLd
224
- schema={buildJsonLd({
225
- type: "Assessment",
226
- slug: read.config.slug,
227
- title: copy.title,
228
- description: copy.description,
229
- locale,
230
- })}
231
- />
322
+ {jsonLd}
232
323
  <main>
233
324
  <SectionRenderer sections={sections} locale={locale} />
234
325
  </main>
@@ -253,8 +344,10 @@ export async function renderMagnetLandingMetadata({
253
344
  export interface MagnetStartInput {
254
345
  slug: string;
255
346
  locale: string;
256
- /** Where the back arrow goes, unlocalized (the landing, or the posting). */
347
+ /** Where the frame's Esc goes, unlocalized (the landing, or the posting); the fallback's back arrow too. */
257
348
  backHref: string;
349
+ /** #11013 decision 2 — the frame's presentation; absent, the stepper's own default (a window). */
350
+ presentation?: FlowFramePresentation;
258
351
  /** Page-supplied `hidden` field values (a posting's slug as `job`). */
259
352
  hiddenValues?: Readonly<Record<string, string>>;
260
353
  /** Replaces step 1's title at every locale it holds (a posting's title). */
@@ -284,6 +377,7 @@ export async function renderMagnetStart({
284
377
  firstStepTitle,
285
378
  asDeliverable = false,
286
379
  title,
380
+ presentation,
287
381
  }: MagnetStartInput): Promise<ReactElement> {
288
382
  const read = await readMagnet(slug);
289
383
  if (read.kind === "absent" && title === undefined) notFound();
@@ -291,11 +385,12 @@ export async function renderMagnetStart({
291
385
  redirect(localeHref(locale, `/reports/${slug}/start`));
292
386
  }
293
387
  const t = await getTranslations({ locale, namespace: "flow" });
294
- const back = <NavBackLink href={localeHref(locale, backHref)} label={t("back")} />;
295
388
  if (read.kind !== "ok") {
296
389
  return (
297
390
  <>
298
- <div className="px-control-x pt-control-y">{back}</div>
391
+ <div className="px-control-x pt-control-y">
392
+ <NavBackLink href={localeHref(locale, backHref)} label={t("back")} />
393
+ </div>
299
394
  {await magnetUnavailable(locale, title)}
300
395
  </>
301
396
  );
@@ -303,12 +398,16 @@ export async function renderMagnetStart({
303
398
 
304
399
  const config =
305
400
  firstStepTitle !== undefined ? withFirstStepTitle(read.config, firstStepTitle) : read.config;
401
+ // #11013 D-A — the frame's brand header and the Esc exit replace the back arrow.
402
+ const brand: FlowFrameBrand = { ...brandMarks(), title: (await landingCopy(read.config, locale)).title };
306
403
  return (
307
404
  <FlowStepperClient
308
405
  config={config}
309
406
  locale={locale}
310
407
  slug={read.config.slug}
311
- header={back}
408
+ brand={brand}
409
+ exit={{ href: `/${resolveSafeLocale(locale)}${backHref}`, label: t("exitLabel") }}
410
+ {...(presentation !== undefined ? { presentation } : {})}
312
411
  {...(hiddenValues !== undefined ? { hiddenValues } : {})}
313
412
  />
314
413
  );