create-ailk 0.37.1 → 0.38.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.
Files changed (230) hide show
  1. package/README.md +129 -0
  2. package/component-catalog.json +44 -6
  3. package/component-catalog.md +6 -5
  4. package/dist/add-module.js +16 -1
  5. package/dist/add-route.d.ts +2 -2
  6. package/dist/add-route.js +18 -11
  7. package/dist/cli.js +52 -0
  8. package/dist/declined-routes.d.ts +13 -0
  9. package/dist/declined-routes.js +74 -0
  10. package/dist/derive-architecture.d.ts +0 -6
  11. package/dist/derive-architecture.js +9 -15
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +3 -0
  14. package/dist/language-import.d.ts +93 -0
  15. package/dist/language-import.js +270 -43
  16. package/dist/lib/import-mdx.js +1 -1
  17. package/dist/lib/scaffold-render-sweep.d.ts +6 -3
  18. package/dist/lib/scaffold-render-sweep.js +8 -4
  19. package/dist/migrate-content.d.ts +6 -2
  20. package/dist/migrate-content.js +62 -5
  21. package/dist/module-architecture.js +139 -103
  22. package/dist/paid-sections.d.ts +13 -0
  23. package/dist/paid-sections.js +35 -5
  24. package/dist/programmatic.js +6 -16
  25. package/dist/remove-module.js +67 -0
  26. package/dist/routes.d.ts +103 -0
  27. package/dist/routes.js +708 -0
  28. package/dist/site-manifest.js +1 -1
  29. package/dist/site-roster.d.ts +2 -1
  30. package/dist/site-roster.js +30 -8
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +18 -0
  34. package/dist/surfaces.js +47 -282
  35. package/dist/sync-routes.d.ts +14 -1
  36. package/dist/sync-routes.js +86 -5
  37. package/dist/topology.d.ts +15 -1
  38. package/dist/topology.js +20 -4
  39. package/dist/update.d.ts +17 -2
  40. package/dist/update.js +480 -77
  41. package/package.json +3 -3
  42. package/templates/README.md +1 -1
  43. package/templates/apps/mcp/CLAUDE.md +5 -3
  44. package/templates/apps/web/CLAUDE.md +62 -20
  45. package/templates/apps/web/account.config.tsx +101 -0
  46. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
  47. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
  50. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
  52. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  53. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
  54. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
  55. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
  57. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
  58. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
  59. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
  60. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
  61. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
  62. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
  63. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
  64. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
  65. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
  66. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
  67. package/templates/apps/web/app/[locale]/layout.tsx +45 -28
  68. package/templates/apps/web/app/apple-icon.tsx +72 -0
  69. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  70. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  71. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  72. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  73. package/templates/apps/web/app/og/route.tsx +155 -72
  74. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  75. package/templates/apps/web/i18n/request.ts +44 -1
  76. package/templates/apps/web/jest.config.cjs +13 -1
  77. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  78. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
  79. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  80. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  81. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  82. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  83. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  84. package/templates/apps/web/lib/listings.tsx +2 -2
  85. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  86. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  87. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  88. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  89. package/templates/apps/web/lib/served-pages.ts +95 -0
  90. package/templates/apps/web/lib/site-brand.tsx +3 -5
  91. package/templates/apps/web/messages/en.json +8 -684
  92. package/templates/apps/web/middleware.ts +3 -1
  93. package/templates/apps/web/next.config.mjs +27 -0
  94. package/templates/apps/web/package.json +1 -0
  95. package/templates/customizations.yaml +9 -0
  96. package/templates/package.json +3 -1
  97. package/templates/tools/lint-architecture.ts +164 -11
  98. package/versions.json +48 -47
  99. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  100. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  101. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  102. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  103. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  104. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  105. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  106. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  107. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  119. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  120. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  121. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  122. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  123. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  125. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  126. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  127. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  128. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  134. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  135. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  136. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  137. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  138. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  139. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  140. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  141. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  142. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  143. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  144. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  145. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  146. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  147. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  148. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  149. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  150. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  151. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  152. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  153. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  154. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  155. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  156. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  157. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  158. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  159. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  160. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  161. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  162. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  163. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  164. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  165. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  166. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  167. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  168. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  169. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  170. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  171. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  172. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  173. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  174. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  175. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  176. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  177. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  178. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  179. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  180. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  181. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  182. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  183. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  184. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  185. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  186. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  187. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  188. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  189. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  190. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  191. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  192. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  193. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  194. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  195. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  196. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  197. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  198. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  199. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  200. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  201. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  202. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  203. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  204. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  205. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  206. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  207. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  208. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  209. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  210. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  211. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  212. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  213. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  214. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  215. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  216. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  217. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  218. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  219. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  220. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  221. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  222. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  223. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  224. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  225. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  226. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  227. package/templates/apps/web/lib/account-config.ts +0 -678
  228. package/templates/apps/web/lib/checkout-config.ts +0 -16
  229. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  230. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,177 +0,0 @@
1
- // oss: false
2
- "use server";
3
-
4
- /**
5
- * submitFlowStepAction — Server Action paired with ailkSubmitFlowStep MCP
6
- * tool (#3957 D8; #3956 D7).
7
- *
8
- * Validates `slug` + `submitFlowStepInputSchema` (shared schema per ADR 0013,
9
- * mirroring `contact.actions.ts` / `purchase.actions.ts`), calls
10
- * `flows.submitStep` via `@working-theory/api-client`, and returns the
11
- * discriminated `FlowStepSubmitResult` `FlowStepper` (`@working-theory/ui`)
12
- * expects — never throws to the client. Invoked IMPERATIVELY from the
13
- * client wrapper (React 19 direct Server Action calls; no `useFormState` —
14
- * the stepper needs the response payload on every call, per step).
15
- *
16
- * Canonical filename: flow.actions.ts (*.actions.ts per ADR 0013 / U0 spec
17
- * parity-test regex `ACTION_FILE_RE = /\.actions\.ts$/`).
18
- *
19
- * Visitor-IP forwarding (#4730): this Server Action runs on the WEB
20
- * FUNCTION'S own server — every visitor's step submission calls the API
21
- * from the same process, so `apps/api`'s rate limiter would otherwise see
22
- * one shared egress IP for every visitor of this site. `resolveVisitorIp`
23
- * reads THIS action's own incoming request headers (via Next's `headers()`)
24
- * for the real visitor IP and forwards it on the outbound `flows.submitStep`
25
- * call, so the API's per-scope rate limiter (apps/api/src/middleware/
26
- * rate-limit.ts) keys on the real visitor. A read failure (or no header
27
- * present, e.g. local dev with no reverse proxy) degrades to forwarding
28
- * nothing — the API then falls back to its own `req.ip`, exactly as before
29
- * this fix.
30
- */
31
-
32
- import { flows } from "@working-theory/api-client";
33
- import type { FlowStepSubmitResult } from "@working-theory/ui-signal-collectors";
34
- import {
35
- flowSlugSchema,
36
- submitFlowStepInputSchema,
37
- } from "@working-theory/validation";
38
- import { cookies, headers } from "next/headers";
39
-
40
- import { runBotCheck } from "../../../../lib/bot-check";
41
- import { consentVisitorHeader, readConsentVisitor } from "../../../../lib/consent-visitor";
42
-
43
- /**
44
- * Reads the visitor's real IP from THIS action's own incoming request —
45
- * never from the browser-supplied payload — preferring `x-forwarded-for`
46
- * (the standard multi-hop chain Fastify's `trustProxy` on `apps/api`
47
- * understands) and falling back to `x-real-ip`. Returns `undefined` (no
48
- * header to forward) rather than throwing on any failure, so an inability
49
- * to read headers never blocks a step submission.
50
- */
51
- async function resolveVisitorIpInit(): Promise<
52
- { headers: Record<string, string> } | undefined
53
- > {
54
- try {
55
- const incoming = await headers();
56
- const visitorIp =
57
- incoming.get("x-forwarded-for") ?? incoming.get("x-real-ip");
58
- return visitorIp
59
- ? { headers: { "x-forwarded-for": visitorIp } }
60
- : undefined;
61
- } catch {
62
- return undefined;
63
- }
64
- }
65
-
66
- /**
67
- * #8438 D12 — the banner's visitor id, so a magnet's step submit links its
68
- * cookie choices to the Person lead-routing resolves (D11). `undefined`
69
- * with no request scope, no cookie, or an invalid value.
70
- */
71
- async function resolveConsentVisitorHeader(): Promise<
72
- Record<string, string> | undefined
73
- > {
74
- try {
75
- const visitorId = readConsentVisitor(await cookies());
76
- return visitorId ? consentVisitorHeader(visitorId) : undefined;
77
- } catch {
78
- return undefined;
79
- }
80
- }
81
-
82
- export async function submitFlowStepAction(
83
- slug: string,
84
- payload: {
85
- sessionId?: string;
86
- stepKey: string;
87
- values: Record<string, unknown>;
88
- locale?: string;
89
- },
90
- ): Promise<FlowStepSubmitResult> {
91
- const parsedSlug = flowSlugSchema.safeParse(slug);
92
- if (!parsedSlug.success) {
93
- return {
94
- ok: false,
95
- kind: "invalid_input",
96
- message: parsedSlug.error.issues[0]?.message ?? "Invalid flow slug.",
97
- };
98
- }
99
-
100
- const parsedPayload = submitFlowStepInputSchema.safeParse(payload);
101
- if (!parsedPayload.success) {
102
- return {
103
- ok: false,
104
- kind: "invalid_input",
105
- message:
106
- parsedPayload.error.issues[0]?.message ?? "Invalid step submission.",
107
- };
108
- }
109
-
110
- // #9255 D4 — the spoke edge's bot check, after the input checks and before
111
- // the write. A refusal is the walk's existing "try again" variant.
112
- const botCheck = await runBotCheck({
113
- source: "bot-check",
114
- target: "submitFlowStepAction",
115
- scope: "write",
116
- });
117
- if (botCheck !== "pass") return { ok: false, kind: "network" };
118
-
119
- try {
120
- // exactOptionalPropertyTypes-safe: submitFlowStepInputSchema's Zod-inferred
121
- // optional fields type as `T | undefined`, which does not structurally
122
- // match api-client's `sessionId?: string` (no explicit `| undefined`) —
123
- // rebuild the payload, omitting an absent optional key rather than
124
- // passing an explicit `undefined` value for it.
125
- const { sessionId, stepKey, values, locale } = parsedPayload.data;
126
- const stepPayload = {
127
- ...(sessionId !== undefined ? { sessionId } : {}),
128
- stepKey,
129
- values,
130
- ...(locale !== undefined ? { locale } : {}),
131
- };
132
- const visitorIpInit = await resolveVisitorIpInit();
133
- const consentVisitor = await resolveConsentVisitorHeader();
134
- const mergedHeaders = { ...(visitorIpInit?.headers ?? {}), ...(consentVisitor ?? {}) };
135
- const stepInit =
136
- Object.keys(mergedHeaders).length > 0 ? { headers: mergedHeaders } : undefined;
137
- // Two call shapes, not one call + a conditional spread: this keeps the
138
- // call at EXACTLY 2 args when there's no header to forward (never an
139
- // explicit `undefined` 3rd arg) — collapsing it into a spread-args form
140
- // would silently change call arity for every existing caller/test.
141
- const res = stepInit
142
- ? await flows.submitStep(parsedSlug.data, stepPayload, stepInit)
143
- : await flows.submitStep(parsedSlug.data, stepPayload);
144
- if (!res.ok) {
145
- if (res.status === 400) {
146
- return { ok: false, kind: "invalid_input" };
147
- }
148
- if (res.status === 409) {
149
- return { ok: false, kind: "step_conflict" };
150
- }
151
- if (res.status === 429) {
152
- const body = res.body as { retryAfterSeconds?: number } | null;
153
- return {
154
- ok: false,
155
- kind: "rate_limited",
156
- ...(typeof body?.retryAfterSeconds === "number"
157
- ? { retryAfterSeconds: body.retryAfterSeconds }
158
- : {}),
159
- };
160
- }
161
- return { ok: false, kind: "network" };
162
- }
163
-
164
- return { ok: true, response: res.body };
165
- } catch (err) {
166
- // Log server-side for observability — narrowly, no submitted `values`
167
- // (PII care, #3989): the api-client's `post()` never attaches the
168
- // request payload to a thrown error (packages/api-client/src/http.ts),
169
- // so logging `err` itself is safe, but slug/stepKey are the only
170
- // request-identifying fields included on purpose.
171
- console.error(
172
- `[submitFlowStepAction] slug=${parsedSlug.data} stepKey=${parsedPayload.data.stepKey}`,
173
- err,
174
- );
175
- return { ok: false, kind: "network" };
176
- }
177
- }
@@ -1,472 +0,0 @@
1
- // oss: false
2
- /**
3
- * magnet-page.tsx — the standard magnet page pair (#8840 D8).
4
- *
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>`, 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.
25
- * This module is the only code that renders either half: `/flows/<slug>`,
26
- * the careers apply pages and every pair `create-ailk add-route magnet`
27
- * writes are callers of the factories below.
28
- *
29
- * The read: one `flows.get(slug)` shared per server instance for 15 seconds
30
- * per slug (the /contact idiom, #8731), so a page's metadata, its body and a
31
- * burst of views make one hub read. A slug the schema refuses is `absent`
32
- * with no read and no cache entry, each insert first drops the stale
33
- * entries, and the map holds at most 256 slugs, so random URLs cannot grow
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
39
- * with no hub to ask — the read answers 503 `flows_not_configured`, or a
40
- * failed read with no API origin configured — is `not-configured` (#9219);
41
- * a pair renders it as `unavailable`, and `/reports/<slug>` uses it to 404
42
- * an unknown slug where a hub outage shows the contact email; a landing that
43
- * passes `notFoundWhenNotConfigured` (`/trial`, #9423) 404s on it too. A walk
44
- * that exists apart from its flow (`/careers/apply`) passes a `title`: its
45
- * fallback then carries that page heading, and an absent flow renders the
46
- * same fallback rather than a 404 (#9219).
47
- *
48
- * A flow whose served config carries a `deliverable` (#8848 D7) has one
49
- * route, `/reports/<slug>`: both halves redirect there (307) before
50
- * rendering anything, so `/flows/<slug>` and every `add-route magnet` pair
51
- * hand it over and an ungated deliverable never gets a form here. The
52
- * deliverable's own walk calls `renderMagnetStart` with `asDeliverable`.
53
- */
54
- import { JsonLd } from "@working-theory/jsonld";
55
- import { flowRouteMetadata } from "@working-theory/metadata";
56
- import { buildJsonLd } from "@working-theory/schema";
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";
69
- import { NavBackLink } from "@working-theory/ui/chrome";
70
- import { Image } from "@working-theory/ui/primitives";
71
- import { SectionRenderer } from "@working-theory/ui/sections";
72
- import type { FlowConfig, PageSection } from "@working-theory/validation";
73
- import { flowSlugSchema, resolveLocalizedString } from "@working-theory/validation";
74
- import { ArrowRight } from "lucide-react";
75
- import type { Metadata } from "next";
76
- import { notFound, redirect } from "next/navigation";
77
- import { getTranslations } from "next-intl/server";
78
- import type { CSSProperties, ReactElement } from "react";
79
-
80
- import { siteLogo, siteWordmarkAsset } from "../../../../lib/site-logo";
81
- import { readSiteContactEmail } from "../../contact/site-contact-email";
82
-
83
- import { FlowStepperClient } from "./FlowStepperClient";
84
- import { type MagnetRead, readServedFlow } from "./served-flow";
85
-
86
- /** The marker every standard magnet page carries in its header comment (D13). */
87
- export const MAGNET_PAGE_MARKER = "Standard magnet page (#8840)";
88
-
89
- /** How long one slug's read is shared across requests (/contact's #8731 value). */
90
- const MAGNET_READ_TTL_MS = 15_000;
91
-
92
- /** At most this many slugs are held at once; past it a read is not shared. */
93
- const MAGNET_READ_MAX_ENTRIES = 256;
94
-
95
- export type { MagnetRead } from "./served-flow";
96
-
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(",");
101
-
102
- function resolveSafeLocale(candidate: string): string {
103
- return ENABLED_LOCALES.includes(candidate) ? candidate : DEFAULT_LOCALE;
104
- }
105
-
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)";
116
-
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()} /> };
120
- }
121
-
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)) });
127
- }
128
-
129
- const magnetReads = new Map<string, { at: number; read: Promise<MagnetRead> }>();
130
-
131
- /** The served flow config for `slug`, shared per instance for 15 seconds. */
132
- export function readMagnet(slug: string): Promise<MagnetRead> {
133
- if (!flowSlugSchema.safeParse(slug).success) {
134
- return Promise.resolve({ kind: "absent" });
135
- }
136
- const now = Date.now();
137
- const hit = magnetReads.get(slug);
138
- if (hit && now - hit.at < MAGNET_READ_TTL_MS) return hit.read;
139
- for (const [key, entry] of magnetReads) {
140
- if (now - entry.at >= MAGNET_READ_TTL_MS) magnetReads.delete(key);
141
- }
142
- const read = readServedFlow(slug);
143
- if (magnetReads.size < MAGNET_READ_MAX_ENTRIES) magnetReads.set(slug, { at: now, read });
144
- return read;
145
- }
146
-
147
- /** The landing's title and line: the record's `landing` copy, else today's. */
148
- async function landingCopy(
149
- config: FlowConfig,
150
- locale: string,
151
- ): Promise<{ title: string; description: string; meta?: string; cta: string }> {
152
- const t = await getTranslations({ locale, namespace: "flow" });
153
- const pick = (value: Record<string, string> | undefined): string | undefined =>
154
- value === undefined ? undefined : resolveLocalizedString(value, locale, config.defaultLocale);
155
- const { landing } = config;
156
- const meta = pick(landing?.meta);
157
- return {
158
- title: pick(landing?.title) ?? pick(config.steps[0]!.copy.title)!,
159
- description: pick(landing?.description) ?? t("landingIntro"),
160
- ...(meta !== undefined ? { meta } : {}),
161
- cta: pick(landing?.cta) ?? t("getStarted"),
162
- };
163
- }
164
-
165
- /**
166
- * The site's contact email in place of a magnet the hub cannot serve (D8).
167
- * With a `title`, the page's own `<h1>` sits above it (#9219).
168
- */
169
- export async function magnetUnavailable(locale: string, title?: string): Promise<ReactElement> {
170
- const t = await getTranslations({ locale, namespace: "flow" });
171
- return (
172
- <Container className="py-section">
173
- <div className="mx-auto max-w-container-sm">
174
- {title !== undefined ? (
175
- <Heading level={1} className="mb-block-tight">
176
- {title}
177
- </Heading>
178
- ) : null}
179
- <ContactFallback
180
- email={readSiteContactEmail()}
181
- text={{
182
- heading: t("unavailableHeading"),
183
- body: t("unavailableBody"),
184
- noEmail: t("unavailableNoEmail"),
185
- }}
186
- />
187
- </div>
188
- </Container>
189
- );
190
- }
191
-
192
- export interface MagnetLandingInput {
193
- slug: string;
194
- /** The landing's own path, e.g. `/diagnostic`; the CTA goes to `<path>/start`. */
195
- path: string;
196
- locale: string;
197
- /** #9287 DD10 — the walk's path when it is not `<path>/start` (`/trial/request`). */
198
- startPath?: string;
199
- /**
200
- * #9423 — a landing that exists only to sell its hub's flow (`/trial`) is a
201
- * 404 on a site with no hub to ask (`not-configured`), as `/reports/<slug>`
202
- * is (#9219). A configured hub that cannot answer still shows the contact
203
- * email.
204
- */
205
- notFoundWhenNotConfigured?: boolean;
206
- }
207
-
208
- /** The indexable landing of a magnet pair (D8). */
209
- export async function renderMagnetLanding({
210
- slug,
211
- path,
212
- locale,
213
- startPath = `${path}/start`,
214
- notFoundWhenNotConfigured = false,
215
- }: MagnetLandingInput): Promise<ReactElement> {
216
- const read = await readMagnet(slug);
217
- if (read.kind === "absent") notFound();
218
- if (read.kind === "not-configured" && notFoundWhenNotConfigured) notFound();
219
- if (read.kind !== "ok") return magnetUnavailable(locale);
220
- // #8848 D7 — a deliverable's one route.
221
- if (read.config.deliverable !== undefined) redirect(localeHref(locale, `/reports/${slug}`));
222
-
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
-
306
- const sections: PageSection[] = [
307
- {
308
- id: "flow-landing-hero",
309
- type: "hero",
310
- data: {
311
- variant: "centered",
312
- headline: copy.title,
313
- subheadline: copy.description,
314
- ...(copy.meta !== undefined ? { body: copy.meta } : {}),
315
- primaryCta: { label: copy.cta, href: localeHref(locale, startPath) },
316
- },
317
- },
318
- ];
319
-
320
- return (
321
- <>
322
- {jsonLd}
323
- <main>
324
- <SectionRenderer sections={sections} locale={locale} />
325
- </main>
326
- </>
327
- );
328
- }
329
-
330
- /** The landing's metadata: indexable under the site's own rule; a fallback never is. */
331
- export async function renderMagnetLandingMetadata({
332
- slug,
333
- locale,
334
- notFoundWhenNotConfigured = false,
335
- }: Pick<MagnetLandingInput, "slug" | "locale" | "notFoundWhenNotConfigured">): Promise<Metadata> {
336
- const read = await readMagnet(slug);
337
- if (read.kind === "absent") return {};
338
- if (read.kind === "not-configured" && notFoundWhenNotConfigured) return {};
339
- if (read.kind !== "ok") return flowRouteMetadata();
340
- const copy = await landingCopy(read.config, locale);
341
- return { title: copy.title, description: copy.description };
342
- }
343
-
344
- export interface MagnetStartInput {
345
- slug: string;
346
- locale: string;
347
- /** Where the frame's Esc goes, unlocalized (the landing, or the posting); the fallback's back arrow too. */
348
- backHref: string;
349
- /** #11013 decision 2 — the frame's presentation; absent, the stepper's own default (a window). */
350
- presentation?: FlowFramePresentation;
351
- /** Page-supplied `hidden` field values (a posting's slug as `job`). */
352
- hiddenValues?: Readonly<Record<string, string>>;
353
- /** Replaces step 1's title at every locale it holds (a posting's title). */
354
- firstStepTitle?: string;
355
- /** #8848 D7 — the deliverable's own walk (`/reports/<slug>/start`): no redirect. */
356
- asDeliverable?: boolean;
357
- /**
358
- * #9219 — a walk that exists apart from its flow (`/careers/apply`): the
359
- * `<h1>` of its fallback, which an absent flow renders too, never a 404.
360
- */
361
- title?: string;
362
- }
363
-
364
- function withFirstStepTitle(config: FlowConfig, title: string): FlowConfig {
365
- const [first, ...rest] = config.steps;
366
- if (!first) return config;
367
- const titled = Object.fromEntries(Object.keys(first.copy.title).map((key) => [key, title]));
368
- return { ...config, steps: [{ ...first, copy: { ...first.copy, title: titled } }, ...rest] };
369
- }
370
-
371
- /** The chrome-free, noindex walk of a magnet pair (D8). */
372
- export async function renderMagnetStart({
373
- slug,
374
- locale,
375
- backHref,
376
- hiddenValues,
377
- firstStepTitle,
378
- asDeliverable = false,
379
- title,
380
- presentation,
381
- }: MagnetStartInput): Promise<ReactElement> {
382
- const read = await readMagnet(slug);
383
- if (read.kind === "absent" && title === undefined) notFound();
384
- if (read.kind === "ok" && read.config.deliverable !== undefined && !asDeliverable) {
385
- redirect(localeHref(locale, `/reports/${slug}/start`));
386
- }
387
- const t = await getTranslations({ locale, namespace: "flow" });
388
- if (read.kind !== "ok") {
389
- return (
390
- <>
391
- <div className="px-control-x pt-control-y">
392
- <NavBackLink href={localeHref(locale, backHref)} label={t("back")} />
393
- </div>
394
- {await magnetUnavailable(locale, title)}
395
- </>
396
- );
397
- }
398
-
399
- const config =
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 };
403
- return (
404
- <FlowStepperClient
405
- config={config}
406
- locale={locale}
407
- slug={read.config.slug}
408
- brand={brand}
409
- exit={{ href: `/${resolveSafeLocale(locale)}${backHref}`, label: t("exitLabel") }}
410
- {...(presentation !== undefined ? { presentation } : {})}
411
- {...(hiddenValues !== undefined ? { hiddenValues } : {})}
412
- />
413
- );
414
- }
415
-
416
- /** The walk's metadata: always `noindex, follow` (`flowRouteMetadata`). */
417
- export async function renderMagnetStartMetadata({
418
- slug,
419
- locale,
420
- firstStepTitle,
421
- title,
422
- }: Pick<MagnetStartInput, "slug" | "locale" | "firstStepTitle" | "title">): Promise<Metadata> {
423
- const read = await readMagnet(slug);
424
- if (read.kind !== "ok") return flowRouteMetadata(title !== undefined ? { title } : {});
425
- const firstStep = read.config.steps[0];
426
- if (!firstStep) return flowRouteMetadata();
427
- return flowRouteMetadata({
428
- title:
429
- firstStepTitle ??
430
- resolveLocalizedString(firstStep.copy.title, locale, read.config.defaultLocale),
431
- });
432
- }
433
-
434
- // ─── Factories for a pair at a path (D8, D12) ──────────────────────────────
435
-
436
- /** A magnet pair: the flow it walks, and the landing's own path. */
437
- export interface MagnetRef {
438
- slug: string;
439
- path: string;
440
- }
441
-
442
- interface MagnetPageProps {
443
- params: Promise<{ locale: string }>;
444
- }
445
-
446
- export function magnetLanding(ref: MagnetRef) {
447
- return async function MagnetLandingPage({ params }: MagnetPageProps): Promise<ReactElement> {
448
- const { locale } = await params;
449
- return renderMagnetLanding({ slug: ref.slug, path: ref.path, locale });
450
- };
451
- }
452
-
453
- export function magnetLandingMetadata(ref: MagnetRef) {
454
- return async function generateMetadata({ params }: MagnetPageProps): Promise<Metadata> {
455
- const { locale } = await params;
456
- return renderMagnetLandingMetadata({ slug: ref.slug, locale });
457
- };
458
- }
459
-
460
- export function magnetStart(ref: MagnetRef) {
461
- return async function MagnetStartPage({ params }: MagnetPageProps): Promise<ReactElement> {
462
- const { locale } = await params;
463
- return renderMagnetStart({ slug: ref.slug, locale, backHref: ref.path });
464
- };
465
- }
466
-
467
- export function magnetStartMetadata(ref: MagnetRef) {
468
- return async function generateMetadata({ params }: MagnetPageProps): Promise<Metadata> {
469
- const { locale } = await params;
470
- return renderMagnetStartMetadata({ slug: ref.slug, locale });
471
- };
472
- }