create-ailk 0.37.0 → 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 (232) hide show
  1. package/README.md +149 -2
  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 +7 -2
  6. package/dist/add-route.js +28 -13
  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 +28 -1
  36. package/dist/sync-routes.js +144 -11
  37. package/dist/template-record.d.ts +11 -0
  38. package/dist/template-record.js +18 -0
  39. package/dist/topology.d.ts +15 -1
  40. package/dist/topology.js +20 -4
  41. package/dist/update.d.ts +31 -2
  42. package/dist/update.js +627 -99
  43. package/package.json +3 -3
  44. package/templates/README.md +1 -1
  45. package/templates/apps/mcp/CLAUDE.md +5 -3
  46. package/templates/apps/web/CLAUDE.md +62 -20
  47. package/templates/apps/web/account.config.tsx +101 -0
  48. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
  49. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
  50. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
  51. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
  52. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
  54. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
  57. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
  58. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
  59. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
  60. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
  61. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
  62. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
  63. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
  64. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
  65. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
  66. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
  67. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
  68. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
  69. package/templates/apps/web/app/[locale]/layout.tsx +45 -28
  70. package/templates/apps/web/app/apple-icon.tsx +72 -0
  71. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  72. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  73. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  74. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  75. package/templates/apps/web/app/og/route.tsx +155 -72
  76. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  77. package/templates/apps/web/i18n/request.ts +44 -1
  78. package/templates/apps/web/jest.config.cjs +13 -1
  79. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  80. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
  81. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  82. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  83. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  84. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  85. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  86. package/templates/apps/web/lib/listings.tsx +2 -2
  87. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  88. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  89. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  90. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  91. package/templates/apps/web/lib/served-pages.ts +95 -0
  92. package/templates/apps/web/lib/site-brand.tsx +3 -5
  93. package/templates/apps/web/messages/en.json +8 -684
  94. package/templates/apps/web/middleware.ts +3 -1
  95. package/templates/apps/web/next.config.mjs +27 -0
  96. package/templates/apps/web/package.json +1 -0
  97. package/templates/customizations.yaml +9 -0
  98. package/templates/package.json +3 -1
  99. package/templates/tools/lint-architecture.ts +164 -11
  100. package/versions.json +48 -47
  101. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  102. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  103. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  104. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  105. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  106. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  107. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  119. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  120. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  121. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  122. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  123. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  125. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  126. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  127. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  128. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  134. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  135. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  136. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  137. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  138. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  139. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  140. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  141. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  142. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  143. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  144. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  145. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  146. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  147. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  148. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  149. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  150. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  151. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  152. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  153. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  154. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  155. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  156. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  157. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  158. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  159. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  160. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  161. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  162. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  163. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  164. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  165. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  166. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  167. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  168. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  169. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  170. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  171. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  172. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  173. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  174. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  175. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  176. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  177. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  178. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  179. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  180. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  181. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  182. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  183. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  184. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  185. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  186. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  187. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  188. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  189. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  190. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  191. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  192. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  193. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  194. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  195. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  196. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  197. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  198. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  199. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  200. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  201. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  202. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  203. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  204. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  205. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  206. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  207. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  208. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  209. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  210. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  211. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  212. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  213. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  214. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  215. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  216. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  217. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  218. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  219. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  220. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  221. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  222. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  223. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  224. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  225. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  226. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  227. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  228. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  229. package/templates/apps/web/lib/account-config.ts +0 -678
  230. package/templates/apps/web/lib/checkout-config.ts +0 -16
  231. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  232. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,122 +0,0 @@
1
- "use server";
2
-
3
- /**
4
- * general/phone-actions.ts — User settings › General's phone step (#11106,
5
- * spec docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
6
- *
7
- * Three server actions over Better Auth's phone plugin, each a SERVER call
8
- * with the request's own headers, so the plugin and its guard (`auth.ts`'s
9
- * `phoneVerificationGuard`) see the person's session:
10
- *
11
- * - `sendPhoneCode` → `auth.api.sendPhoneNumberOTP` — texts a six-digit
12
- * code through the apps/api relay;
13
- * - `verifyPhoneCode` → `auth.api.verifyPhoneNumber({ updatePhoneNumber:
14
- * true })` — the one writer of `phoneNumber` and `phoneNumberVerified`;
15
- * - `removePhone` → `auth.api.updateUser({ phoneNumber: null })`, which
16
- * the plugin turns into `phoneNumberVerified: false`.
17
- *
18
- * Each reaches the plugin through the generated seam's `loadPhoneApi`
19
- * (`lib/topology.generated.ts`, #11138), never `auth.ts` directly, so a spoke
20
- * that signs in through its hub keeps this file: there the seam answers null
21
- * and every action answers `unavailable`.
22
- *
23
- * They take no identity argument: who comes from the session alone. Each
24
- * answers `{ ok: true }` or a refusal `reason` the island maps to its own
25
- * line. No log line, and no answer, carries the number or the code: a log
26
- * line names the action and the plugin's error code only.
27
- *
28
- * Not a `*.actions.ts` file and no `*Action`-suffixed export: the phone step
29
- * is a person's own act on the hub, with no MCP twin (apps/mcp's parity test
30
- * reads that suffix).
31
- */
32
-
33
- import { headers } from "next/headers";
34
-
35
- import { loadPhoneApi } from "../../../../../lib/topology.generated";
36
-
37
- export type PhoneActionResult =
38
- | { ok: true }
39
- | {
40
- ok: false;
41
- reason:
42
- | "invalid_number"
43
- | "invalid_code"
44
- | "taken"
45
- | "too_many"
46
- | "unverified"
47
- | "signed_out"
48
- | "unavailable"
49
- | "failed";
50
- };
51
-
52
- /** The plugin's error code of a thrown `APIError`, when it has one. */
53
- function errorCode(err: unknown): string | null {
54
- const code = (err as { body?: { code?: unknown } } | null)?.body?.code;
55
- return typeof code === "string" ? code : null;
56
- }
57
-
58
- const REASONS: Record<string, Exclude<PhoneActionResult, { ok: true }>["reason"]> = {
59
- INVALID_PHONE_NUMBER: "invalid_number",
60
- INVALID_OTP: "invalid_code",
61
- OTP_EXPIRED: "invalid_code",
62
- OTP_NOT_FOUND: "invalid_code",
63
- TOO_MANY_ATTEMPTS: "too_many",
64
- PHONE_NUMBER_EXIST: "taken",
65
- EMAIL_NOT_VERIFIED: "unverified",
66
- SESSION_REQUIRED: "signed_out",
67
- };
68
-
69
- function refused(action: string, err: unknown): PhoneActionResult {
70
- const code = errorCode(err);
71
- console.error(`[phone-actions] ${action} refused code=${code ?? "none"}`);
72
- return { ok: false, reason: (code && REASONS[code]) || "failed" };
73
- }
74
-
75
- const isText = (value: unknown, max: number): value is string =>
76
- typeof value === "string" && value.length > 0 && value.length <= max;
77
-
78
- export async function sendPhoneCode(phoneNumber: unknown): Promise<PhoneActionResult> {
79
- // Action input is untrusted: the plugin's validator is the real check.
80
- if (!isText(phoneNumber, 16)) return { ok: false, reason: "invalid_number" };
81
- // The generated seam: null on a spoke or a build without the step.
82
- const api = await loadPhoneApi();
83
- if (!api) return { ok: false, reason: "unavailable" };
84
- try {
85
- await api.sendPhoneNumberOTP({ body: { phoneNumber }, headers: await headers() });
86
- return { ok: true };
87
- } catch (err) {
88
- return refused("sendPhoneCode", err);
89
- }
90
- }
91
-
92
- export async function verifyPhoneCode(
93
- phoneNumber: unknown,
94
- code: unknown,
95
- ): Promise<PhoneActionResult> {
96
- if (!isText(phoneNumber, 16)) return { ok: false, reason: "invalid_number" };
97
- if (!isText(code, 6)) return { ok: false, reason: "invalid_code" };
98
- const api = await loadPhoneApi();
99
- if (!api) return { ok: false, reason: "unavailable" };
100
- try {
101
- await api.verifyPhoneNumber({
102
- body: { phoneNumber, code, updatePhoneNumber: true },
103
- headers: await headers(),
104
- });
105
- return { ok: true };
106
- } catch (err) {
107
- return refused("verifyPhoneCode", err);
108
- }
109
- }
110
-
111
- export async function removePhone(): Promise<PhoneActionResult> {
112
- const api = await loadPhoneApi();
113
- if (!api) return { ok: false, reason: "unavailable" };
114
- try {
115
- // The plugin's own clearing write (`phoneNumber: null` also sets
116
- // `phoneNumberVerified: false`).
117
- await api.updateUser({ body: { phoneNumber: null }, headers: await headers() });
118
- return { ok: true };
119
- } catch (err) {
120
- return refused("removePhone", err);
121
- }
122
- }
@@ -1,215 +0,0 @@
1
- "use client"; // owns the number and code fields and the three action calls
2
-
3
- /**
4
- * PhoneVerification — User settings › General's phone step (#11106, spec
5
- * docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
6
- *
7
- * The one place a person sets their own phone. Two states:
8
- *
9
- * - no verified number: the number field and Send code; once a code is
10
- * sent, the code field and Verify (`verifyPhoneCode`, which writes the
11
- * number only after the code matches);
12
- * - a verified number: the number with "Verified" and Remove.
13
- *
14
- * `available: false` (a build without the step) renders the not-available
15
- * line, and an unverified email renders the confirm-email line, with no
16
- * form. Every string arrives as a prop from the page's `account.profile.*`
17
- * messages; the number and the code never leave this island except to the
18
- * server actions, which log neither.
19
- */
20
-
21
- import {
22
- Badge,
23
- Button,
24
- Field,
25
- Heading,
26
- InlineMessage,
27
- Input,
28
- Text,
29
- } from "@working-theory/ui/primitives";
30
- import { useRouter } from "next/navigation";
31
- import { useState, useTransition, type FormEvent, type ReactElement } from "react";
32
-
33
- import {
34
- removePhone,
35
- sendPhoneCode,
36
- verifyPhoneCode,
37
- type PhoneActionResult,
38
- } from "./phone-actions";
39
-
40
- export interface PhoneVerificationLabels {
41
- title: string;
42
- lead: string;
43
- number: string;
44
- numberHint: string;
45
- sendCode: string;
46
- sending: string;
47
- code: string;
48
- codeHint: string;
49
- verify: string;
50
- verifying: string;
51
- verified: string;
52
- remove: string;
53
- sent: string;
54
- unavailable: string;
55
- unverifiedEmail: string;
56
- errors: Record<Exclude<PhoneActionResult, { ok: true }>["reason"], string>;
57
- }
58
-
59
- export function PhoneVerification({
60
- available,
61
- emailVerified,
62
- phone,
63
- labels,
64
- }: {
65
- available: boolean;
66
- emailVerified: boolean;
67
- phone: { number: string; verified: boolean } | null;
68
- labels: PhoneVerificationLabels;
69
- }): ReactElement {
70
- const router = useRouter();
71
- const [number, setNumber] = useState("");
72
- const [code, setCode] = useState("");
73
- const [codeSent, setCodeSent] = useState(false);
74
- const [error, setError] = useState<string | null>(null);
75
- const [pending, startTransition] = useTransition();
76
-
77
- const run = (action: () => Promise<PhoneActionResult>, onOk: () => void) => {
78
- setError(null);
79
- startTransition(async () => {
80
- const result = await action();
81
- if (result.ok) onOk();
82
- else setError(labels.errors[result.reason]);
83
- });
84
- };
85
-
86
- const onSend = (event: FormEvent<HTMLFormElement>) => {
87
- event.preventDefault();
88
- run(
89
- () => sendPhoneCode(number.trim()),
90
- () => setCodeSent(true),
91
- );
92
- };
93
-
94
- const onVerify = (event: FormEvent<HTMLFormElement>) => {
95
- event.preventDefault();
96
- run(
97
- () => verifyPhoneCode(number.trim(), code.trim()),
98
- () => {
99
- setCode("");
100
- setCodeSent(false);
101
- router.refresh();
102
- },
103
- );
104
- };
105
-
106
- const onRemove = () => run(removePhone, () => router.refresh());
107
-
108
- let body: ReactElement;
109
- if (!available) {
110
- body = (
111
- <Text as="p" variant="body-sm" tone="muted" data-testid="account-phone-unavailable">
112
- {labels.unavailable}
113
- </Text>
114
- );
115
- } else if (phone?.verified) {
116
- body = (
117
- <div className="flex flex-wrap items-center gap-3" data-testid="account-phone-verified">
118
- <Text as="span" variant="body" data-testid="account-phone-number">
119
- {phone.number}
120
- </Text>
121
- <Badge data-testid="account-phone-verified-badge">{labels.verified}</Badge>
122
- <Button
123
- type="button"
124
- variant="ghost"
125
- size="big"
126
- disabled={pending}
127
- onClick={onRemove}
128
- data-testid="account-phone-remove"
129
- >
130
- {labels.remove}
131
- </Button>
132
- </div>
133
- );
134
- } else if (!emailVerified) {
135
- body = (
136
- <Text as="p" variant="body-sm" tone="muted" data-testid="account-phone-unverified-email">
137
- {labels.unverifiedEmail}
138
- </Text>
139
- );
140
- } else {
141
- body = (
142
- <div className="flex flex-col gap-4">
143
- <form onSubmit={onSend} className="flex flex-col gap-3" data-testid="account-phone-send-form">
144
- <Field label={labels.number} htmlFor="account-phone-number-input" helperText={labels.numberHint}>
145
- <Input
146
- type="tel"
147
- size="big"
148
- inputMode="tel"
149
- autoComplete="tel"
150
- value={number}
151
- onChange={(e) => setNumber(e.target.value)}
152
- required
153
- data-testid="account-phone-number-input"
154
- />
155
- </Field>
156
- <Button
157
- type="submit"
158
- variant="secondary"
159
- size="big"
160
- disabled={pending || number.trim() === ""}
161
- data-testid="account-phone-send"
162
- >
163
- {pending && !codeSent ? labels.sending : labels.sendCode}
164
- </Button>
165
- </form>
166
- {codeSent ? (
167
- <form onSubmit={onVerify} className="flex flex-col gap-3" data-testid="account-phone-verify-form">
168
- <InlineMessage variant="success" role="status" data-testid="account-phone-sent">
169
- {labels.sent}
170
- </InlineMessage>
171
- <Field label={labels.code} htmlFor="account-phone-code-input" helperText={labels.codeHint}>
172
- <Input
173
- type="text"
174
- size="big"
175
- inputMode="numeric"
176
- autoComplete="one-time-code"
177
- maxLength={6}
178
- value={code}
179
- onChange={(e) => setCode(e.target.value)}
180
- required
181
- data-testid="account-phone-code-input"
182
- />
183
- </Field>
184
- <Button
185
- type="submit"
186
- size="big"
187
- disabled={pending || code.trim() === ""}
188
- data-testid="account-phone-verify"
189
- >
190
- {pending ? labels.verifying : labels.verify}
191
- </Button>
192
- </form>
193
- ) : null}
194
- </div>
195
- );
196
- }
197
-
198
- return (
199
- <section className="flex flex-col gap-3" data-testid="account-phone-section" aria-labelledby="account-phone-title">
200
- {/* A level-2 heading: one group of the pane, beside Contact details (#11167 ruling 11). */}
201
- <Heading level={2} visual={4} id="account-phone-title">
202
- {labels.title}
203
- </Heading>
204
- <Text as="p" variant="body-sm" tone="muted">
205
- {labels.lead}
206
- </Text>
207
- {body}
208
- {error ? (
209
- <InlineMessage variant="error" role="alert" data-testid="account-phone-error">
210
- {error}
211
- </InlineMessage>
212
- ) : null}
213
- </section>
214
- );
215
- }
@@ -1,73 +0,0 @@
1
- "use server";
2
-
3
- /**
4
- * general/photo-actions.ts — User settings › General's photo write on the
5
- * member path (#11167 ruling 5).
6
- *
7
- * The member General renders no Name field: the account name follows the
8
- * contact's first and last names (`contact-actions.ts`), so the profile form
9
- * saves the photo alone — `member.updateProfile({ image })`, `PATCH
10
- * /v1/member/profile` with no `name` key, so a person who has not set a name
11
- * yet can still set their photo. `null` (or a blank link) clears it. The
12
- * session is not re-sealed: a hub session carries no photo (`profile-source.ts`
13
- * reads it from the member API instead).
14
- *
15
- * It sends `forwardedCookieInit()`'s init, as `profile-actions.ts`'s
16
- * `saveProfile` does, and maps the same refusals: `photo` (`400
17
- * link_not_https`), `unverified` (`403`), `unavailable` (`404`, `503`), else
18
- * `failed`. Logs carry a status or `err.name` only — never a link.
19
- *
20
- * Not a `*.actions.ts` file and no `*Action`-suffixed export: the write has no
21
- * MCP twin by decision (8170's header), and apps/mcp's parity test reads that
22
- * suffix.
23
- */
24
-
25
- import { member } from "@working-theory/api-client";
26
-
27
- import { forwardedCookieInit } from "../../../../../lib/server-api";
28
-
29
- /** PII-safe error identity for logs (the `profile-actions.ts` idiom: `err.name` only). */
30
- function errorName(err: unknown): string {
31
- return err instanceof Error ? err.name : "unknown";
32
- }
33
-
34
- /** The `error.code` of a member write's refusal body, when it has one. */
35
- function errorCode(body: unknown): string | null {
36
- if (typeof body !== "object" || body === null) return null;
37
- const error = (body as { error?: unknown }).error;
38
- if (typeof error !== "object" || error === null) return null;
39
- const code = (error as { code?: unknown }).code;
40
- return typeof code === "string" ? code : null;
41
- }
42
-
43
- export type SavePhotoResult =
44
- | { ok: true; image: string | null }
45
- | { ok: false; reason: "photo" | "unverified" | "unavailable" | "failed" };
46
-
47
- /** Saves the member's photo alone: `null` or a blank link clears it. */
48
- export async function savePhoto(
49
- image: string | null,
50
- ): Promise<SavePhotoResult> {
51
- // Action input is untrusted: anything but a string or null is refused,
52
- // never read as "clear the photo".
53
- if (image !== null && typeof image !== "string")
54
- return { ok: false, reason: "photo" };
55
- try {
56
- const res = await member.updateProfile(
57
- { image: image?.trim() || null },
58
- await forwardedCookieInit(),
59
- );
60
- if (res.ok) return { ok: true, image: res.body.image };
61
- console.error(`[photo-actions] savePhoto status=${res.status}`);
62
- if (res.status === 400 && errorCode(res.body) === "link_not_https") {
63
- return { ok: false, reason: "photo" };
64
- }
65
- if (res.status === 403) return { ok: false, reason: "unverified" };
66
- if (res.status === 404 || res.status === 503)
67
- return { ok: false, reason: "unavailable" };
68
- return { ok: false, reason: "failed" };
69
- } catch (err) {
70
- console.error(`[photo-actions] savePhoto errName=${errorName(err)}`);
71
- return { ok: false, reason: "failed" };
72
- }
73
- }
@@ -1,107 +0,0 @@
1
- "use client"; // owns the save call and the router.refresh() that follows it
2
-
3
- /**
4
- * GeneralSettings — User settings › General's adapter over the shared
5
- * `AccountSettings` composition (#8339 D8; builds on #8232 D3, D4).
6
- *
7
- * Rewritten in place from `ProfileForm` (#7430 → #8232), which rendered its
8
- * own form. The form, the color logic and the markup now live in
9
- * `@working-theory/templates/account`'s `AccountSettings` (spec 8339 D4);
10
- * this file supplies `profile` and `onSave` from `via` (General's
11
- * `loadProfileSource`, D3):
12
- *
13
- * - `member` — no Name field (#11167 ruling 5: the account name follows
14
- * the contact's first and last names, `contact-actions.ts`), so the form
15
- * saves the photo alone through `savePhoto` (`PATCH /v1/member/profile`
16
- * with `image` only); a refusal keeps the field as typed.
17
- * - `session` — a build with no member API: the name saves through
18
- * Better Auth's own `updateUser`, and no photo field shows
19
- * (`profile="name-only"`).
20
- * - `none` — a hub-mode spoke whose hub answers no member route: no form,
21
- * the name as read-only text (`profile="read-only"`).
22
- *
23
- * On success, both paths call `router.refresh()` so the rail's name follows
24
- * the save.
25
- */
26
-
27
- import {
28
- AccountSettings,
29
- type AccountGeneralLabels,
30
- type AccountSaveResult,
31
- type AccountSettingsFrameProps,
32
- } from "@working-theory/templates/account";
33
- import { createAuthClient } from "better-auth/react";
34
- import { useRouter } from "next/navigation";
35
- import type { ReactElement, ReactNode } from "react";
36
-
37
- import { savePhoto } from "./photo-actions";
38
-
39
- const authClient = createAuthClient();
40
-
41
- export interface GeneralSettingsLabels extends AccountGeneralLabels {
42
- /** The `saveProfile` refusal lines not already in `AccountGeneralLabels`. */
43
- unverified: string;
44
- unavailable: string;
45
- }
46
-
47
- export function GeneralSettings({
48
- frame,
49
- user,
50
- labels,
51
- colorMode,
52
- via,
53
- children,
54
- }: {
55
- frame: Omit<AccountSettingsFrameProps, "name" | "children">;
56
- user: { name: string; email: string; image: string | null };
57
- labels: GeneralSettingsLabels;
58
- colorMode: { cookieName: string } | null;
59
- via: "member" | "session" | "none";
60
- children?: ReactNode;
61
- }): ReactElement {
62
- const router = useRouter();
63
-
64
- async function onSave({
65
- name,
66
- image,
67
- imageChanged,
68
- }: {
69
- name: string;
70
- image: string | null;
71
- imageChanged: boolean;
72
- }): Promise<AccountSaveResult> {
73
- if (via === "session") {
74
- const { error } = await authClient.updateUser({ name });
75
- if (error) return { ok: false, message: labels.saveError };
76
- router.refresh();
77
- return { ok: true };
78
- }
79
- // The member path saves the photo alone; `name` is the account's as it
80
- // stands and never written here. Only a changed photo reaches here (Save
81
- // is disabled otherwise), so the untouched-field rule (8232 D4/D6) holds.
82
- if (!imageChanged) return { ok: true };
83
- const res = await savePhoto(image);
84
- if (!res.ok) {
85
- if (res.reason === "photo") return { ok: false, field: "photo", message: labels.photoInvalid };
86
- if (res.reason === "unverified") return { ok: false, message: labels.unverified };
87
- if (res.reason === "unavailable") return { ok: false, message: labels.unavailable };
88
- return { ok: false, message: labels.saveError };
89
- }
90
- router.refresh();
91
- return { ok: true, image: res.image };
92
- }
93
-
94
- return (
95
- <AccountSettings
96
- frame={frame}
97
- user={user}
98
- labels={labels}
99
- colorMode={colorMode}
100
- profile={via === "member" ? "editable" : via === "session" ? "name-only" : "read-only"}
101
- nameField={via !== "member"}
102
- {...(via === "none" ? {} : { onSave })}
103
- >
104
- {children}
105
- </AccountSettings>
106
- );
107
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * general/profile-source.ts (server code) — who saves User settings ›
3
- * General's profile and takes its deletion request, and the photo the
4
- * profile form starts with (#8232, spec
5
- * docs/specs/8232-member-settings-account-general-and-spec.md D3, C2, C5).
6
- *
7
- * `via` — whether the member API answers, read once per request from
8
- * `member.pieces`, the cheapest member read:
9
- *
10
- * - `member` — any answer but a 404: a 2xx, any other refusal, a preflight
11
- * refusal (status 0) or a throw. A refusal of another kind belongs to the
12
- * write, which reports it honestly. A `503 tenant_unresolved` is
13
- * `member` too: the writes answer the same 503, shown as unavailable.
14
- * - on a 404, the sign-in seam (`signInMethod()`, D7) says who holds the
15
- * account. A `site` sign-in gives `session`: this site's own sign-in
16
- * holds it, and the 404 is a build with no tenancy module — every member
17
- * read and write registers in one module block — so the name saves
18
- * through Better Auth as before and deletion points at Support. A `hub`
19
- * sign-in gives `none`: the hub holds the account and answers no member
20
- * route for this spoke, and the spoke has no `/api/auth` of its own, so
21
- * no write can reach the account from here.
22
- *
23
- * A 404 is a module-presence test, as `read()` in `lib/account-config.ts`
24
- * already makes; this file names no topology constant itself.
25
- *
26
- * `image` — on the `member` path, the photo the member API holds for the
27
- * caller's own row (`GET /v1/member/profile`, #11167): a spoke's hub session
28
- * carries no photo, and this is how the Admin's Google photo reaches the
29
- * spoke's General. A failed or refused read falls back to the session's photo,
30
- * which Better Auth's session carries at run time though the generated
31
- * `SiteSession` type does not declare it (a hub session carries none, C5).
32
- */
33
-
34
- import { member } from "@working-theory/api-client";
35
- import type { AccountContext } from "@working-theory/templates/account";
36
- import { headers } from "next/headers";
37
- import { cache } from "react";
38
-
39
- import { readSession } from "../../../../../lib/topology.generated";
40
- import { signInMethod } from "../sign-in-method";
41
-
42
- export interface ProfileSource {
43
- via: "member" | "session" | "none";
44
- image: string | null;
45
- }
46
-
47
- /** `user.image` as a trimmed non-blank string, else `null`. */
48
- function sessionImage(session: unknown): string | null {
49
- if (typeof session !== "object" || session === null) return null;
50
- const user = (session as { user?: unknown }).user;
51
- if (typeof user !== "object" || user === null) return null;
52
- const image = (user as { image?: unknown }).image;
53
- return typeof image === "string" && image.trim() !== "" ? image.trim() : null;
54
- }
55
-
56
- async function memberApiAnswers(ctx: AccountContext): Promise<boolean> {
57
- try {
58
- const res = await member.pieces(ctx.init);
59
- return res.ok || res.status !== 404;
60
- } catch {
61
- return true;
62
- }
63
- }
64
-
65
- /** The caller's stored photo, or `null` when the read fails or holds none. */
66
- async function memberImage(ctx: AccountContext): Promise<string | null> {
67
- try {
68
- const res = await member.profile(ctx.init);
69
- return res.ok ? res.body.image?.trim() || null : null;
70
- } catch {
71
- return null;
72
- }
73
- }
74
-
75
- export const loadProfileSource = cache(async (ctx: AccountContext): Promise<ProfileSource> => {
76
- // The photo is optional: a failed session read starts the field empty
77
- // rather than failing the page.
78
- const [answers, session] = await Promise.all([
79
- memberApiAnswers(ctx),
80
- headers()
81
- .then((h) => readSession(h))
82
- .catch(() => null),
83
- ]);
84
- const via = answers ? "member" : signInMethod().kind === "site" ? "session" : "none";
85
- const image = (via === "member" ? await memberImage(ctx) : null) ?? sessionImage(session);
86
- return { via, image };
87
- });