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,322 +0,0 @@
1
- "use client"; // owns the answers' state and posts them through useActionState
2
-
3
- /**
4
- * OnboardingForm — the client's onboarding questions (#8515, spec
5
- * docs/specs/8515-standard-client-onboarding-diagnostic-and-spec.md D12).
6
- *
7
- * Renders every served step in order — the server checks every answer and
8
- * evaluates no `showIf` (D9). A field step renders each field as `Input`
9
- * (text, email, tel, url), `Textarea` or `Select`; a segmentation step renders
10
- * each question as a `RadioGroup` (single choice) or one `Checkbox` per option
11
- * (`multi`), labelled by the step's title. Copy is the provider's
12
- * `LocalizedString`s, resolved for the form's `defaultLocale` (else its first
13
- * locale) and rendered as text, never markup.
14
- *
15
- * Every control is named `answer.<name>` — a multi question's checkboxes
16
- * repeat it. The form is controlled and posts what its state holds, so a
17
- * refusal keeps every answer: one `answer.<name>` entry per value, plus a
18
- * `multi` entry naming each multi question, so `submitOnboarding` sends a
19
- * multi answer as an array even when one box is checked. A link is sent as
20
- * typed (`inputMode="url"`, no browser URL check): the server's https rule
21
- * is the only one. On success a status line replaces the form.
22
- */
23
-
24
- import {
25
- Button,
26
- Checkbox,
27
- Heading,
28
- InlineMessage,
29
- Input,
30
- Label,
31
- RadioGroup,
32
- RadioGroupItem,
33
- Select,
34
- SelectContent,
35
- SelectItem,
36
- SelectTrigger,
37
- SelectValue,
38
- Text,
39
- Textarea,
40
- } from "@working-theory/ui/primitives";
41
- import { resolveLocalizedString, type MemberOnboardingStep } from "@working-theory/validation";
42
- import {
43
- startTransition,
44
- useActionState,
45
- useId,
46
- useState,
47
- type FormEvent,
48
- type ReactElement,
49
- } from "react";
50
-
51
- import {
52
- submitOnboarding,
53
- type OnboardingErrorCode,
54
- type OnboardingForm as OnboardingFormData,
55
- type OnboardingState,
56
- } from "./actions";
57
-
58
- type FieldStep = Extract<MemberOnboardingStep, { type: "field" }>;
59
- type SegmentationStep = Extract<MemberOnboardingStep, { type: "segmentation" }>;
60
- type FormField = FieldStep["fields"][number];
61
- type Question = SegmentationStep["questions"][number];
62
-
63
- export interface OnboardingFormLabels {
64
- optional: string;
65
- submit: string;
66
- submitting: string;
67
- sent: string;
68
- errors: Record<OnboardingErrorCode, string>;
69
- }
70
-
71
- export interface OnboardingFormProps {
72
- form: OnboardingFormData;
73
- labels: OnboardingFormLabels;
74
- }
75
-
76
- export function OnboardingForm({ form, labels }: OnboardingFormProps): ReactElement {
77
- const id = useId();
78
- const [answers, setAnswers] = useState<Record<string, string | string[]>>({});
79
- const [state, dispatch, pending] = useActionState<OnboardingState, FormData>(
80
- submitOnboarding,
81
- { kind: "idle" },
82
- );
83
-
84
- if (state.kind === "sent") {
85
- return (
86
- <InlineMessage
87
- variant="success"
88
- role="status"
89
- className="text-body-sm"
90
- data-testid="account-onboarding-sent"
91
- >
92
- {labels.sent}
93
- </InlineMessage>
94
- );
95
- }
96
-
97
- const text = (value: Record<string, string>): string =>
98
- resolveLocalizedString(value, form.defaultLocale, form.defaultLocale);
99
- const setAnswer = (name: string, value: string | string[]): void =>
100
- setAnswers((current) => ({ ...current, [name]: value }));
101
- const single = (name: string): string => {
102
- const value = answers[name];
103
- return typeof value === "string" ? value : "";
104
- };
105
- const picked = (name: string): string[] => {
106
- const value = answers[name];
107
- return Array.isArray(value) ? value : [];
108
- };
109
-
110
- const onSubmit = (event: FormEvent<HTMLFormElement>): void => {
111
- event.preventDefault();
112
- const formData = new FormData();
113
- for (const step of form.steps) {
114
- if (step.type !== "segmentation") continue;
115
- for (const question of step.questions) {
116
- if (question.multi) formData.append("multi", question.name);
117
- }
118
- }
119
- for (const [name, value] of Object.entries(answers)) {
120
- for (const one of Array.isArray(value) ? value : [value]) {
121
- formData.append(`answer.${name}`, one);
122
- }
123
- }
124
- startTransition(() => dispatch(formData));
125
- };
126
-
127
- const renderField = (field: FormField): ReactElement => {
128
- const controlId = `${id}-${field.name}`;
129
- const helpId = `${controlId}-help`;
130
- const help = field.copy.help ? text(field.copy.help) : null;
131
- const placeholder = field.copy.placeholder ? text(field.copy.placeholder) : undefined;
132
- const value = single(field.name);
133
- const common = {
134
- id: controlId,
135
- name: `answer.${field.name}`,
136
- required: field.required === true,
137
- ...(help ? { "aria-describedby": helpId } : {}),
138
- "data-testid": `account-onboarding-field-${field.name}`,
139
- };
140
- const onChange = (event: { target: { value: string } }): void =>
141
- setAnswer(field.name, event.target.value);
142
-
143
- let control: ReactElement;
144
- if (field.inputType === "textarea") {
145
- control = (
146
- <Textarea {...common} rows={4} value={value} placeholder={placeholder} onChange={onChange} />
147
- );
148
- } else if (field.inputType === "select") {
149
- control = (
150
- <Select
151
- name={common.name}
152
- required={common.required}
153
- value={value}
154
- onValueChange={(next) => setAnswer(field.name, next)}
155
- >
156
- <SelectTrigger
157
- id={controlId}
158
- {...(help ? { "aria-describedby": helpId } : {})}
159
- data-testid={common["data-testid"]}
160
- >
161
- <SelectValue {...(placeholder ? { placeholder } : {})} />
162
- </SelectTrigger>
163
- <SelectContent>
164
- {(field.options ?? []).map((option) => (
165
- <SelectItem key={option.value} value={option.value}>
166
- {text(option.label)}
167
- </SelectItem>
168
- ))}
169
- </SelectContent>
170
- </Select>
171
- );
172
- } else {
173
- control = (
174
- <Input
175
- {...common}
176
- // A url field takes text: no browser URL check, so the server's plain refusal is the rule.
177
- type={field.inputType === "url" ? "text" : field.inputType}
178
- {...(field.inputType === "url" ? { inputMode: "url" as const } : {})}
179
- value={value}
180
- placeholder={placeholder}
181
- onChange={onChange}
182
- />
183
- );
184
- }
185
-
186
- return (
187
- <div key={field.name} className="flex flex-col gap-2">
188
- <div className="flex items-baseline gap-2">
189
- <Label htmlFor={controlId}>{text(field.copy.label)}</Label>
190
- {field.required ? null : (
191
- <Text as="span" variant="caption">
192
- {labels.optional}
193
- </Text>
194
- )}
195
- </div>
196
- {control}
197
- {help ? (
198
- <Text as="p" id={helpId} variant="caption">
199
- {help}
200
- </Text>
201
- ) : null}
202
- </div>
203
- );
204
- };
205
-
206
- /** One question, labelled by its step's title (`titleId`). */
207
- const renderQuestion = (question: Question, titleId: string): ReactElement => {
208
- const groupId = `${id}-${question.name}`;
209
- const name = `answer.${question.name}`;
210
- const optionId = (index: number): string => `${groupId}-${index}`;
211
-
212
- if (!question.multi) {
213
- return (
214
- <RadioGroup
215
- key={question.name}
216
- aria-labelledby={titleId}
217
- name={name}
218
- required
219
- value={single(question.name)}
220
- onValueChange={(next) => setAnswer(question.name, next)}
221
- data-testid={`account-onboarding-field-${question.name}`}
222
- >
223
- {question.options.map((option, index) => (
224
- <div key={option.value} className="flex min-h-11 items-center gap-3">
225
- <RadioGroupItem id={optionId(index)} value={option.value} />
226
- <Label htmlFor={optionId(index)}>{text(option.label)}</Label>
227
- </div>
228
- ))}
229
- </RadioGroup>
230
- );
231
- }
232
-
233
- const exclusive = new Set(question.exclusiveValues ?? []);
234
- const values = picked(question.name);
235
- // A value in `exclusiveValues` stands alone (D9): checking it clears the
236
- // others, and checking another clears it. Kept in the options' order.
237
- const toggle = (value: string, checked: boolean): void => {
238
- const next = new Set(
239
- checked
240
- ? exclusive.has(value)
241
- ? [value]
242
- : [...values.filter((v) => !exclusive.has(v)), value]
243
- : values.filter((v) => v !== value),
244
- );
245
- setAnswer(
246
- question.name,
247
- question.options.map((o) => o.value).filter((v) => next.has(v)),
248
- );
249
- };
250
- return (
251
- <div
252
- key={question.name}
253
- role="group"
254
- aria-labelledby={titleId}
255
- className="flex flex-col"
256
- data-testid={`account-onboarding-field-${question.name}`}
257
- >
258
- {question.options.map((option, index) => (
259
- <div key={option.value} className="flex min-h-11 items-center gap-3">
260
- <Checkbox
261
- id={optionId(index)}
262
- name={name}
263
- value={option.value}
264
- checked={values.includes(option.value)}
265
- onCheckedChange={(checked) => toggle(option.value, checked === true)}
266
- />
267
- <Label htmlFor={optionId(index)}>{text(option.label)}</Label>
268
- </div>
269
- ))}
270
- </div>
271
- );
272
- };
273
-
274
- /** A segmentation step: its title once, then each question it asks. */
275
- const renderSegmentation = (step: SegmentationStep): ReactElement => {
276
- const titleId = `${id}-${step.key}-title`;
277
- return (
278
- <div key={step.key} className="flex flex-col gap-2">
279
- <Text as="p" id={titleId} variant="body-sm" className="font-semibold">
280
- {text(step.copy.title)}
281
- </Text>
282
- {step.questions.map((question) => renderQuestion(question, titleId))}
283
- </div>
284
- );
285
- };
286
-
287
- return (
288
- <form onSubmit={onSubmit} className="flex flex-col gap-6" data-testid="account-onboarding-form">
289
- {form.steps.map((step) =>
290
- step.type === "segmentation" ? (
291
- renderSegmentation(step)
292
- ) : (
293
- <div key={step.key} className="flex flex-col gap-4">
294
- {/* A one-field step's title is its field's label; a heading only when it groups several. */}
295
- {step.fields.length > 1 ? (
296
- <Heading level={2} visual={4}>
297
- {text(step.copy.title)}
298
- </Heading>
299
- ) : null}
300
- {step.fields.map(renderField)}
301
- </div>
302
- ),
303
- )}
304
- {state.kind === "error" ? (
305
- <InlineMessage variant="error" className="text-body-sm" data-testid="account-onboarding-error">
306
- {labels.errors[state.code]}
307
- </InlineMessage>
308
- ) : null}
309
- <div>
310
- <Button
311
- type="submit"
312
- disabled={pending}
313
- // 44px on a phone (a touch-first context); the 36px primary from md up.
314
- className="max-md:min-h-11"
315
- data-testid="account-onboarding-submit"
316
- >
317
- {pending ? labels.submitting : labels.submit}
318
- </Button>
319
- </div>
320
- </form>
321
- );
322
- }
@@ -1,173 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- /**
6
- * The person's data export, re-served (#11164 AC-3) —
7
- * `GET /[locale]/account/privacy/export`.
8
- *
9
- * The api-client's `member.exportData` is the one external boundary mocked;
10
- * `forwardedCookieInit()` and the route's decisions are real (the build's
11
- * own sign-in, a single site: the caller's session cookie). Covers:
12
- * - the read carries the caller's credential and the JSON comes back with
13
- * all five hub headers unchanged;
14
- * - a hub answer missing any of the five is refused 502, its stream
15
- * cancelled — never bytes on this origin without them;
16
- * - a cross-site navigation is refused 403 before any call;
17
- * - refusals map to a status with no body and `private, no-store`: a 4xx
18
- * keeps its status (the 429 when the person's hourly exports are spent),
19
- * a 5xx or a throw is 502, no credential is 401.
20
- */
21
-
22
- const mockExportData = jest.fn();
23
- jest.mock("@working-theory/api-client", () => ({
24
- __esModule: true,
25
- member: { exportData: (...args: unknown[]) => mockExportData(...args) },
26
- }));
27
-
28
- const mockHeaders = jest.fn();
29
- const mockCookies = jest.fn();
30
- jest.mock("next/headers", () => ({
31
- __esModule: true,
32
- headers: (...args: unknown[]) => mockHeaders(...args),
33
- cookies: (...args: unknown[]) => mockCookies(...args),
34
- }));
35
-
36
- import { GET as route } from "../export/route";
37
-
38
- /** A same-origin navigation to the route, unless `site` says otherwise. */
39
- const GET = (site: string | null = "same-origin") =>
40
- route(
41
- new Request("https://site.example.com/account/privacy/export", {
42
- headers: site === null ? {} : { "sec-fetch-site": site },
43
- }),
44
- );
45
-
46
- const FIVE = {
47
- contentType: "application/json; charset=utf-8",
48
- contentDisposition: 'attachment; filename="your-data.json"',
49
- contentTypeOptions: "nosniff",
50
- contentSecurityPolicy:
51
- "default-src 'none'; sandbox; frame-ancestors 'none'; form-action 'none'; base-uri 'none'",
52
- cacheControl: "private, no-store",
53
- };
54
-
55
- beforeEach(() => {
56
- mockExportData.mockReset();
57
- mockHeaders
58
- .mockReset()
59
- .mockResolvedValue(new Headers({ origin: "https://site.example.com" }));
60
- mockCookies.mockReset().mockResolvedValue({ toString: () => "session=abc" });
61
- });
62
-
63
- it("reads the export with the caller's own credential and re-serves it with all five headers unchanged", async () => {
64
- const stream = new ReadableStream<Uint8Array>();
65
- mockExportData.mockResolvedValue({
66
- ok: true,
67
- body: { stream, headers: FIVE },
68
- });
69
- const res = await GET();
70
- expect(mockExportData).toHaveBeenCalledWith({
71
- headers: { cookie: "session=abc", origin: "https://site.example.com" },
72
- });
73
- expect(res.status).toBe(200);
74
- expect(res.body).toBe(stream);
75
- expect(res.headers.get("Content-Type")).toBe(FIVE.contentType);
76
- expect(res.headers.get("Content-Disposition")).toBe(FIVE.contentDisposition);
77
- expect(res.headers.get("X-Content-Type-Options")).toBe("nosniff");
78
- expect(res.headers.get("Content-Security-Policy")).toBe(
79
- FIVE.contentSecurityPolicy,
80
- );
81
- expect(res.headers.get("Cache-Control")).toBe("private, no-store");
82
- });
83
-
84
- it.each(Object.keys(FIVE) as (keyof typeof FIVE)[])(
85
- "a hub answer missing %s is refused 502 with the stream cancelled",
86
- async (missing) => {
87
- const cancel = jest.fn().mockResolvedValue(undefined);
88
- mockExportData.mockResolvedValue({
89
- ok: true,
90
- body: { stream: { cancel }, headers: { ...FIVE, [missing]: null } },
91
- });
92
- const res = await GET();
93
- expect(res.status).toBe(502);
94
- expect(res.body).toBeNull();
95
- expect(res.headers.get("Cache-Control")).toBe("private, no-store");
96
- expect(cancel).toHaveBeenCalledTimes(1);
97
- },
98
- );
99
-
100
- const refusal = (status: number, code: string) => ({
101
- ok: false,
102
- status,
103
- body: { ok: false, error: { code, message: code } },
104
- });
105
-
106
- it.each([
107
- [
108
- "a 429 (the hourly budget spent) answers 429",
109
- refusal(429, "rate_limited"),
110
- 429,
111
- ],
112
- [
113
- "a 403 (email unverified) answers 403",
114
- refusal(403, "email_unverified"),
115
- 403,
116
- ],
117
- [
118
- "a 404 (an older hub with no export route) answers 404",
119
- refusal(404, "not_found"),
120
- 404,
121
- ],
122
- ["a 503 from the hub answers 502", refusal(503, "tenant_unresolved"), 502],
123
- ["no credential (signed out) answers 401", refusal(0, "unauthorized"), 401],
124
- [
125
- "a transport the api-client refuses answers 502",
126
- refusal(0, "insecure_transport"),
127
- 502,
128
- ],
129
- ])("%s with no body and private, no-store", async (_name, answer, status) => {
130
- mockExportData.mockResolvedValue(answer);
131
- const res = await GET();
132
- expect(res.status).toBe(status);
133
- expect(res.body).toBeNull();
134
- expect(res.headers.get("Cache-Control")).toBe("private, no-store");
135
- });
136
-
137
- it("a 429 keeps the hub's retry hint as Retry-After, rebuilt from the refusal's retryAfterSeconds", async () => {
138
- mockExportData.mockResolvedValue({
139
- ok: false,
140
- status: 429,
141
- body: { error: "rate_limited", retryAfterSeconds: 1800 },
142
- });
143
- const res = await GET();
144
- expect(res.status).toBe(429);
145
- expect(res.headers.get("Retry-After")).toBe("1800");
146
- expect(res.body).toBeNull();
147
- });
148
-
149
- it.each(["cross-site", "same-site"])(
150
- "a %s navigation is refused 403 before any call",
151
- async (site) => {
152
- const res = await GET(site);
153
- expect(res.status).toBe(403);
154
- expect(res.body).toBeNull();
155
- expect(mockExportData).not.toHaveBeenCalled();
156
- },
157
- );
158
-
159
- it("a navigation with no Sec-Fetch-Site (an older browser) and a `none` one (the address bar) are served", async () => {
160
- mockExportData.mockResolvedValue({
161
- ok: true,
162
- body: { stream: new ReadableStream<Uint8Array>(), headers: FIVE },
163
- });
164
- expect((await GET(null)).status).toBe(200);
165
- expect((await GET("none")).status).toBe(200);
166
- });
167
-
168
- it("a hub call that throws is a 502, never Next's own 500", async () => {
169
- mockExportData.mockRejectedValue(new Error("ECONNREFUSED"));
170
- const res = await GET();
171
- expect(res.status).toBe(502);
172
- expect(res.body).toBeNull();
173
- });
@@ -1,103 +0,0 @@
1
- "use server";
2
-
3
- /**
4
- * A/privacy/actions.ts — the member Privacy and Notifications tabs' one
5
- * consent write path (#8438 D14, D15, spec
6
- * docs/specs/8438-consent-registry-and-ledger-step-spec.md), and the Privacy
7
- * tab's stored-sessions deletion (#11164 AC-3).
8
- *
9
- * `setConsentAction` posts one answer through `POST /v1/member/consents`
10
- * (`member.setConsent`) and answers in `ConsentSwitchList`'s own shape, so
11
- * both tabs' switch lists can call it directly with no adapter. The
12
- * banner's visitor id (`ailk-vid`) rides along as `x-ailk-consent-visitor`
13
- * when present, linking its cookie choices to the client record this write
14
- * resolves or creates (D6, D11, D12) — never failing the write when it is
15
- * absent or invalid.
16
- *
17
- * `deleteStoredSessionsAction` posts `POST /v1/member/stored-sessions/delete`
18
- * (`member.deleteStoredSessions`) with the caller's own credential and
19
- * answers in `AccountDataTable`'s shape: the line to show — the count, or
20
- * that there was nothing to delete — or the failure message. The
21
- * confirmation is the table's; this runs only after it.
22
- */
23
-
24
- import { member } from "@working-theory/api-client";
25
- import type {
26
- AccountDataActionResult,
27
- ConsentSwitchChangeResult,
28
- } from "@working-theory/templates/account";
29
- import {
30
- formatLocalTime,
31
- SERVER_TIME_ZONE,
32
- } from "@working-theory/ui/primitives";
33
- import { cookies } from "next/headers";
34
- import { getLocale, getTranslations } from "next-intl/server";
35
-
36
- import {
37
- consentVisitorHeader,
38
- readConsentVisitor,
39
- } from "../../../../../lib/consent-visitor";
40
- import { forwardedCookieInit } from "../../../../../lib/server-api";
41
-
42
- // #11159: the server fallback zone, never the host's, which the unpinned
43
- // form read; the line is a `t()` string, so no node can carry the viewer's.
44
- function formatDate(iso: string, locale: string): string {
45
- return formatLocalTime(iso, "date", { timeZone: SERVER_TIME_ZONE, locale });
46
- }
47
-
48
- export async function setConsentAction(
49
- purposeId: string,
50
- granted: boolean,
51
- ): Promise<ConsentSwitchChangeResult> {
52
- const [t, locale] = await Promise.all([
53
- getTranslations("account"),
54
- getLocale(),
55
- ]);
56
-
57
- try {
58
- const base = await forwardedCookieInit();
59
- let visitorHeaders: Record<string, string> = {};
60
- try {
61
- const visitorId = readConsentVisitor(await cookies());
62
- if (visitorId) visitorHeaders = consentVisitorHeader(visitorId);
63
- } catch {
64
- // No request scope to read, or no visitor cookie — write with none.
65
- }
66
-
67
- const res = await member.setConsent(
68
- { purposeId, granted, locale },
69
- { headers: { ...base.headers, ...visitorHeaders } },
70
- );
71
- if (!res.ok) {
72
- return { ok: false, message: t("settings.privacy.unavailable") };
73
- }
74
-
75
- const state = res.body.purpose.state;
76
- const at = state?.at ?? new Date().toISOString();
77
- const dateLine = state?.granted
78
- ? t("settings.privacy.given", { date: formatDate(at, locale) })
79
- : t("settings.privacy.withdrawn", { date: formatDate(at, locale) });
80
- return { ok: true, dateLine };
81
- } catch {
82
- return { ok: false, message: t("settings.privacy.unavailable") };
83
- }
84
- }
85
-
86
- export async function deleteStoredSessionsAction(): Promise<AccountDataActionResult> {
87
- const t = await getTranslations("account");
88
- try {
89
- const res = await member.deleteStoredSessions(await forwardedCookieInit());
90
- if (!res.ok) {
91
- return {
92
- ok: false,
93
- message: t("settings.privacy.yourData.deleteFailed"),
94
- };
95
- }
96
- return {
97
- ok: true,
98
- line: t("settings.privacy.yourData.deleted", { count: res.body.deleted }),
99
- };
100
- } catch {
101
- return { ok: false, message: t("settings.privacy.yourData.deleteFailed") };
102
- }
103
- }