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,116 +0,0 @@
1
- "use server";
2
-
3
- /**
4
- * account/profile-actions.ts — User settings › General's two member writes
5
- * (#8232, spec docs/specs/8232-member-settings-account-general-and-spec.md
6
- * D6; the writes are #8170's).
7
- *
8
- * - `saveProfile` — the member's name and photo, `member.updateProfile`
9
- * (`PATCH /v1/member/profile`). On a spoke the hub-session cookie is then
10
- * re-sealed from the hub's `/me` (`resealHubSession`, D11), so the new
11
- * name shows on the next render.
12
- * - `requestAccountDeletion` — `member.requestDeletion`
13
- * (`POST /v1/member/deletion-request`). The API files it with the
14
- * deployment that holds the account (8170 D9) and answers which operator
15
- * it went to, so nothing here tests the topology.
16
- *
17
- * Both send `forwardedCookieInit()`'s init: on a single site the session
18
- * cookie plus the request's `Origin`, which `apps/api`'s cookie CSRF check
19
- * needs; on a hub-mode spoke the hub credential. Neither takes an identity
20
- * argument — who comes from the forwarded credential alone (8170 D1).
21
- *
22
- * Not a `*.actions.ts` file and no `*Action`-suffixed export: these writes
23
- * have no MCP twin by decision (8170's header), and apps/mcp's parity test
24
- * reads that suffix. `resealHubSession` is imported by its own path, never
25
- * through `lib/hub-session/index.ts`: `sync-routes` never overwrites a
26
- * scaffold's existing `index.ts`, so an import through it would not compile
27
- * there (D13). Logs carry a status or `err.name` only — never a name, a
28
- * link, an email or a credential.
29
- */
30
-
31
- import { member } from "@working-theory/api-client";
32
-
33
- import { resealHubSession } from "../../../../lib/hub-session/reseal";
34
- import { forwardedCookieInit } from "../../../../lib/server-api";
35
-
36
- /** PII-safe error identity for logs (the `checkout.actions.ts` idiom: `err.name` only). */
37
- function errorName(err: unknown): string {
38
- return err instanceof Error ? err.name : "unknown";
39
- }
40
-
41
- /** The `error.code` of a member write's refusal body, when it has one. */
42
- function errorCode(body: unknown): string | null {
43
- if (typeof body !== "object" || body === null) return null;
44
- const error = (body as { error?: unknown }).error;
45
- if (typeof error !== "object" || error === null) return null;
46
- const code = (error as { code?: unknown }).code;
47
- return typeof code === "string" ? code : null;
48
- }
49
-
50
- export type SaveProfileResult =
51
- | { ok: true; name: string | null; image: string | null }
52
- | { ok: false; reason: "required" | "photo" | "unverified" | "unavailable" | "failed" };
53
-
54
- /**
55
- * Saves the member's name, and their photo when `image` is present:
56
- * `null` (or a blank link) clears it, and an absent key leaves it as it is.
57
- */
58
- export async function saveProfile(input: {
59
- name: string;
60
- image?: string | null;
61
- }): Promise<SaveProfileResult> {
62
- // Action input is untrusted: a hand-built call may send anything.
63
- const { name: rawName, image } = (typeof input === "object" && input !== null ? input : {}) as {
64
- name?: unknown;
65
- image?: unknown;
66
- };
67
- const name = typeof rawName === "string" ? rawName.trim() : "";
68
- if (!name) return { ok: false, reason: "required" };
69
- // Anything but a string or null is refused, never read as "clear the photo".
70
- if (image !== undefined && image !== null && typeof image !== "string") {
71
- return { ok: false, reason: "photo" };
72
- }
73
- const body = image === undefined ? { name } : { name, image: image?.trim() || null };
74
-
75
- try {
76
- const res = await member.updateProfile(body, await forwardedCookieInit());
77
- if (res.ok) {
78
- if ((await resealHubSession()) === "failed") {
79
- console.error("[profile-actions] saveProfile reseal=failed");
80
- }
81
- return { ok: true, name: res.body.name, image: res.body.image };
82
- }
83
- console.error(`[profile-actions] saveProfile status=${res.status}`);
84
- if (res.status === 400 && errorCode(res.body) === "link_not_https") {
85
- return { ok: false, reason: "photo" };
86
- }
87
- if (res.status === 403) return { ok: false, reason: "unverified" };
88
- if (res.status === 404 || res.status === 503) return { ok: false, reason: "unavailable" };
89
- return { ok: false, reason: "failed" };
90
- } catch (err) {
91
- console.error(`[profile-actions] saveProfile errName=${errorName(err)}`);
92
- return { ok: false, reason: "failed" };
93
- }
94
- }
95
-
96
- export type AccountDeletionResult =
97
- | { ok: true; sentTo: "site-operator" | "hub-operator" }
98
- | { ok: false; reason: "unverified" | "unavailable" | "failed" };
99
-
100
- /**
101
- * Asks the operator who holds the account to delete it. The body is empty,
102
- * so the API's own subject and message go to the operator.
103
- */
104
- export async function requestAccountDeletion(): Promise<AccountDeletionResult> {
105
- try {
106
- const res = await member.requestDeletion({}, await forwardedCookieInit());
107
- if (res.ok) return { ok: true, sentTo: res.body.sentTo };
108
- console.error(`[profile-actions] requestAccountDeletion status=${res.status}`);
109
- if (res.status === 403) return { ok: false, reason: "unverified" };
110
- if (res.status === 404 || res.status === 503) return { ok: false, reason: "unavailable" };
111
- return { ok: false, reason: "failed" };
112
- } catch (err) {
113
- console.error(`[profile-actions] requestAccountDeletion errName=${errorName(err)}`);
114
- return { ok: false, reason: "failed" };
115
- }
116
- }
@@ -1,27 +0,0 @@
1
- "use client"; // Retry re-runs the page's server reads through the router
2
-
3
- /**
4
- * RetryButton — the Inbox error row's Retry control (#7430, spec 7423 D12).
5
- *
6
- * `router.refresh()` re-renders the route's Server Components, so every
7
- * account read runs again without a full page load.
8
- */
9
-
10
- import { Button } from "@working-theory/ui/primitives";
11
- import { useRouter } from "next/navigation";
12
- import type { ReactElement } from "react";
13
-
14
- export function RetryButton({ label }: { label: string }): ReactElement {
15
- const router = useRouter();
16
- return (
17
- <Button
18
- variant="secondary"
19
- // 44px on a phone (a touch-first context), the 36px default from md up.
20
- className="max-md:min-h-11"
21
- onClick={() => router.refresh()}
22
- data-testid="inbox-retry"
23
- >
24
- {label}
25
- </Button>
26
- );
27
- }
@@ -1,258 +0,0 @@
1
- /**
2
- * Security on a spoke that signs in through its hub (#11162 AC-1, AC-3).
3
- *
4
- * The generated web seam is mocked to its `signIn: "hub"` render, as
5
- * `account/__tests__/hub-mode.test.tsx` mocks it; this suite sits beside the
6
- * route so it copies with it. Covers:
7
- *
8
- * - AC-1: the tab renders the Sign-in methods panel — the Password row
9
- * with Set / Not set read from the hub's `me` for the signed-in person
10
- * (the Bearer credential, never a cookie), the secure-link line naming
11
- * the person's email, Set password or Change password — and Log out; no
12
- * "managed at <host>" sentence and no link to the hub's Security page,
13
- * and the seam's accounts reader is never asked.
14
- * - AC-2 (the spoke's half): Set / Change password POSTs `{ locale }` to
15
- * the spoke's own `/api/hub-session/password`, same-origin, and asks
16
- * Better Auth for nothing; a 202 is "Link sent", anything else the
17
- * failure line.
18
- * - AC-3: a hub that answers no state — no `hasPassword`, a refusal, a
19
- * failed read — renders the panel's unavailable line, never a form.
20
- */
21
- import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
22
- import { tmpdir } from "node:os";
23
- import { join } from "node:path";
24
-
25
- import { act, fireEvent, render, screen } from "@testing-library/react";
26
-
27
- jest.mock("next-intl/server", () => {
28
- const msgs: unknown = require("../../../../../../messages/en.json");
29
- const dig = (obj: unknown, path: string): unknown =>
30
- path.split(".").reduce<unknown>(
31
- (acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
32
- obj,
33
- );
34
- return {
35
- __esModule: true,
36
- getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
37
- const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
38
- const messages = dig(msgs, ns);
39
- return (key: string, values?: Record<string, unknown>): string => {
40
- const value = dig(messages, key);
41
- if (typeof value !== "string") return `${ns}.${key}`;
42
- return value.replace(/\{(\w+)\}/g, (m, name: string) =>
43
- values && name in values ? String(values[name]) : m,
44
- );
45
- };
46
- },
47
- };
48
- });
49
-
50
- const mockHeaders = jest.fn();
51
- jest.mock("next/headers", () => ({
52
- __esModule: true,
53
- headers: (...args: unknown[]) => mockHeaders(...args),
54
- cookies: jest.fn().mockImplementation(async () => ({ toString: () => "", set: jest.fn() })),
55
- }));
56
-
57
- const mockReadSession = jest.fn();
58
- const mockReadOwnAccounts = jest.fn();
59
- // eslint-disable-next-line no-restricted-syntax -- #507: the seam is generated per build (#7894 D8); its `signIn: "hub"` render is the boundary under test, and no env or HTTP surface selects it.
60
- jest.mock("../../../../../../lib/topology.generated", () => ({
61
- __esModule: true,
62
- TOPOLOGY: "spoke",
63
- SIGN_IN_ENABLED: true,
64
- SIGN_IN_PROVIDER: "hub",
65
- SIGN_IN_PATH: "/account",
66
- SIGN_UP_PATH: null,
67
- SIGN_OUT_ENDPOINT: "/api/hub-session/sign-out",
68
- readSession: (...args: unknown[]) => mockReadSession(...args),
69
- registerSiteStores: () => Promise.resolve(),
70
- loadSpokeBilling: () => Promise.resolve(null),
71
- readOwnAccounts: (...args: unknown[]) => mockReadOwnAccounts(...args),
72
- }));
73
-
74
- const mockHubMe = jest.fn();
75
- jest.mock("@working-theory/api-client", () => ({
76
- __esModule: true,
77
- visitorForwardHeaders: () => null,
78
- hubSignIn: { me: (...args: unknown[]) => mockHubMe(...args) },
79
- }));
80
-
81
- const mockRequestPasswordReset = jest.fn();
82
- const mockSignOut = jest.fn();
83
- jest.mock("better-auth/react", () => ({
84
- __esModule: true,
85
- createAuthClient: () => ({
86
- requestPasswordReset: (...args: unknown[]) => mockRequestPasswordReset(...args),
87
- signOut: (...args: unknown[]) => mockSignOut(...args),
88
- }),
89
- }));
90
-
91
- const mockPush = jest.fn();
92
- jest.mock("next/navigation", () => ({
93
- __esModule: true,
94
- useRouter: () => ({ push: mockPush, refresh: jest.fn(), replace: jest.fn() }),
95
- usePathname: () => "/account/security",
96
- redirect: jest.fn(),
97
- }));
98
-
99
- import { seal } from "../../../../../../lib/hub-session/seal";
100
- import SecurityPage from "../page";
101
-
102
- const HUB = "https://hub.example.com";
103
- const SESSION_SECRET = "s".repeat(43);
104
- const CREDENTIAL = `ailk_hst_${"t".repeat(43)}`;
105
- const BEARER = { headers: { authorization: `Bearer ${CREDENTIAL}` } };
106
- const USER = {
107
- name: "Ada Lovelace",
108
- email: "ada@example.com",
109
- emailVerified: true,
110
- createdAt: "2026-09-01T00:00:00.000Z",
111
- };
112
- const WIRE_USER = { id: "user_1", ...USER };
113
-
114
- const ENV = process.env;
115
- let contentRoot: string;
116
- const realFetch = Object.getOwnPropertyDescriptor(globalThis, "fetch");
117
- const mockFetch = jest.fn();
118
-
119
- beforeEach(() => {
120
- contentRoot = mkdtempSync(join(tmpdir(), "ailk-security-hub-"));
121
- writeFileSync(join(contentRoot, "_site.mdx"), '---\nsiteName: "Test"\n---\n');
122
- process.env = {
123
- ...ENV,
124
- AILK_CONTENT_ROOT: contentRoot,
125
- AILK_HUB_SIGN_IN_URL: HUB,
126
- AILK_HUB_CLIENT_ID: "spoke_0001",
127
- AILK_HUB_CLIENT_SECRET: `ailk_hcs_${"c".repeat(43)}`,
128
- AILK_HUB_SESSION_SECRET: SESSION_SECRET,
129
- NEXT_PUBLIC_BASE_URL: "https://spoke.example.com",
130
- };
131
- const sealed = seal(
132
- { v: 1, accessToken: CREDENTIAL, expiresAt: Date.now() + 60_000, user: USER },
133
- SESSION_SECRET,
134
- "session",
135
- "__Host-ailk-hub-session",
136
- );
137
- mockHeaders.mockReset().mockResolvedValue(new Headers({ cookie: `__Host-ailk-hub-session=${sealed}` }));
138
- mockReadSession.mockReset().mockResolvedValue({ user: USER });
139
- mockReadOwnAccounts.mockReset().mockResolvedValue(null);
140
- mockHubMe.mockReset();
141
- mockRequestPasswordReset.mockReset();
142
- mockSignOut.mockReset();
143
- mockPush.mockReset();
144
- mockFetch.mockReset();
145
- Object.defineProperty(globalThis, "fetch", { value: mockFetch, writable: true, configurable: true });
146
- });
147
-
148
- afterEach(() => {
149
- rmSync(contentRoot, { recursive: true, force: true });
150
- process.env = ENV;
151
- if (realFetch) Object.defineProperty(globalThis, "fetch", realFetch);
152
- else Reflect.deleteProperty(globalThis, "fetch");
153
- });
154
-
155
- function hubAnswers(body: Record<string, unknown>): void {
156
- mockHubMe.mockResolvedValue({ ok: true, status: 200, body: { user: WIRE_USER, billingCustomerId: null, ...body } });
157
- }
158
-
159
- async function renderSecurity(): Promise<void> {
160
- render(await SecurityPage({ params: Promise.resolve({ locale: "en" }) }));
161
- }
162
-
163
- /** The panel's shape every hub render shares: Log out, and none of the retired pointer. */
164
- function expectNoPointer(): void {
165
- expect(screen.getByTestId("account-security-log-out")).toBeInTheDocument();
166
- expect(screen.queryByTestId("account-security-hub")).not.toBeInTheDocument();
167
- expect(screen.queryByTestId("account-security-hub-link")).not.toBeInTheDocument();
168
- expect(screen.queryByTestId("account-security-sentence")).not.toBeInTheDocument();
169
- expect(screen.queryByText(/managed at/i)).toBeNull();
170
- expect(screen.queryByText(/main site/i)).toBeNull();
171
- expect(mockReadOwnAccounts).not.toHaveBeenCalled();
172
- }
173
-
174
- describe("AC-1 — the Sign-in methods panel on a hub-mode spoke", () => {
175
- it("renders the Password row as Set, the change line naming the email, and Change password, read from the hub with the credential", async () => {
176
- hubAnswers({ hasPassword: true });
177
- await renderSecurity();
178
-
179
- expect(mockHubMe).toHaveBeenCalledTimes(1);
180
- expect(mockHubMe).toHaveBeenCalledWith(BEARER);
181
- expect(screen.getByText("Sign-in methods")).toBeInTheDocument();
182
- expect(screen.getByTestId("account-security-password")).toBeInTheDocument();
183
- expect(screen.getByTestId("account-security-password-status")).toHaveTextContent("Set");
184
- expect(screen.getByTestId("account-security-password-note")).toHaveTextContent(
185
- "We'll email ada@example.com a secure link to change your password.",
186
- );
187
- expect(screen.getByTestId("account-security-password-request")).toHaveTextContent("Change password");
188
- expectNoPointer();
189
- });
190
-
191
- it("renders the Password row as Not set, the set line naming the email, and Set password", async () => {
192
- hubAnswers({ hasPassword: false });
193
- await renderSecurity();
194
-
195
- expect(screen.getByTestId("account-security-password-status")).toHaveTextContent("Not set");
196
- expect(screen.getByTestId("account-security-password-note")).toHaveTextContent(
197
- "We'll email ada@example.com a secure link to create your password.",
198
- );
199
- expect(screen.getByTestId("account-security-password-request")).toHaveTextContent("Set password");
200
- expectNoPointer();
201
- });
202
- });
203
-
204
- describe("AC-2 — Set / Change password asks the spoke's own route", () => {
205
- it("POSTs { locale } to /api/hub-session/password same-origin, asks Better Auth nothing, and a 202 is Link sent", async () => {
206
- hubAnswers({ hasPassword: false });
207
- mockFetch.mockResolvedValue({ ok: true, status: 202 });
208
- await renderSecurity();
209
-
210
- await act(async () => {
211
- fireEvent.click(screen.getByTestId("account-security-password-request"));
212
- });
213
-
214
- expect(mockFetch).toHaveBeenCalledTimes(1);
215
- expect(mockFetch).toHaveBeenCalledWith("/api/hub-session/password", {
216
- method: "POST",
217
- credentials: "same-origin",
218
- headers: { "content-type": "application/json" },
219
- body: JSON.stringify({ locale: "en" }),
220
- });
221
- expect(mockRequestPasswordReset).not.toHaveBeenCalled();
222
- expect(await screen.findByTestId("account-security-password-sent")).toBeInTheDocument();
223
- expect(screen.queryByTestId("account-security-password-error")).not.toBeInTheDocument();
224
- });
225
-
226
- it("anything but a 202 is the failure line, and nothing navigates", async () => {
227
- hubAnswers({ hasPassword: true });
228
- mockFetch.mockResolvedValue({ ok: false, status: 503 });
229
- await renderSecurity();
230
-
231
- await act(async () => {
232
- fireEvent.click(screen.getByTestId("account-security-password-request"));
233
- });
234
-
235
- expect(await screen.findByTestId("account-security-password-error")).toBeInTheDocument();
236
- expect(screen.queryByTestId("account-security-password-sent")).not.toBeInTheDocument();
237
- expect(mockPush).not.toHaveBeenCalled();
238
- expect(mockRequestPasswordReset).not.toHaveBeenCalled();
239
- });
240
- });
241
-
242
- describe("AC-3 — a hub that answers no state renders the unavailable line, never a form", () => {
243
- it.each([
244
- ["a hub older than #11162 (no hasPassword)", () => hubAnswers({})],
245
- ["a refused credential", () => mockHubMe.mockResolvedValue({ ok: false, status: 401, body: { ok: false } })],
246
- ["a failed read", () => mockHubMe.mockRejectedValue(new Error("network"))],
247
- ])("%s", async (_label, arrange) => {
248
- jest.spyOn(console, "error").mockImplementation(() => undefined);
249
- arrange();
250
- await renderSecurity();
251
-
252
- expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't check your password settings.");
253
- expect(screen.queryByTestId("account-security-password")).not.toBeInTheDocument();
254
- expect(screen.queryByTestId("account-security-password-request")).not.toBeInTheDocument();
255
- expect(screen.queryByText(/Sign-in methods/)).toBeNull();
256
- expectNoPointer();
257
- });
258
- });
@@ -1,130 +0,0 @@
1
- "use client"; // Better Auth's client calls (requestPasswordReset, signOut) and router navigation need the browser
2
-
3
- /**
4
- * SecurityPanel — the member's adapter over `SecuritySettings` (#8431 D3;
5
- * #11162).
6
- *
7
- * The page (RSC) resolves the variant, the strings, the person's own address,
8
- * the reset link's absolute `redirectTo` and where Log out lands; this island
9
- * supplies the two actions:
10
- *
11
- * - the Password row's request: on a spoke that signs in through its hub,
12
- * one same-origin POST of `{ locale }` to the spoke's password route,
13
- * which asks the hub to mail the signed-in person's own address (#11162);
14
- * elsewhere Better Auth's `requestPasswordReset` for the person's OWN
15
- * address, with the server-built `redirectTo` (never one derived from
16
- * `window.location` — `forgot-password-card.tsx`'s rule). No address and
17
- * no password ever leaves this island;
18
- * - Log out: the spoke's same-origin sign-out endpoint when the page passes
19
- * one, else Better Auth's `signOut`. Only a log-out that succeeded
20
- * navigates (the `SignOutTrigger` rule).
21
- *
22
- * Its `authClient` is its own module-scope `createAuthClient()`, the
23
- * `account-frame.tsx` idiom — never imported from `(auth)/`, a tree a spoke
24
- * drops.
25
- */
26
-
27
- import {
28
- SecuritySettings,
29
- type SecuritySettingsLabels,
30
- type SecuritySignIn,
31
- } from "@working-theory/templates/account";
32
- import { createAuthClient } from "better-auth/react";
33
- import { useRouter } from "next/navigation";
34
- import type { ReactElement, ReactNode } from "react";
35
-
36
- const authClient = createAuthClient();
37
-
38
- /** The variant as the page resolved it — serializable, no functions. */
39
- export type SecurityPanelVariant =
40
- | { kind: "password"; hasPassword: boolean }
41
- | { kind: "sentence"; text: string };
42
-
43
- export interface SecurityPanelProps {
44
- /** `null`: the accounts read failed; `failed` renders in its place. */
45
- variant: SecurityPanelVariant | null;
46
- failed?: ReactNode;
47
- /** The session's own address — the only one a link is ever requested for. */
48
- email: string;
49
- /** The absolute reset page the emailed link returns to. */
50
- resetUrl: string;
51
- /**
52
- * A spoke's same-origin password route (#11162), which asks the hub to mail
53
- * the link; `null` asks Better Auth here.
54
- */
55
- passwordEndpoint: string | null;
56
- /** The locale the hub's set-password page renders in. */
57
- locale: string;
58
- /** A spoke's same-origin sign-out route; `null` signs out through Better Auth. */
59
- signOutEndpoint: string | null;
60
- /** The site's sign-in page, where Log out lands. */
61
- signInHref: string;
62
- labels: SecuritySettingsLabels;
63
- }
64
-
65
- export function SecurityPanel({
66
- variant,
67
- failed,
68
- email,
69
- resetUrl,
70
- passwordEndpoint,
71
- locale,
72
- signOutEndpoint,
73
- signInHref,
74
- labels,
75
- }: SecurityPanelProps): ReactElement {
76
- const router = useRouter();
77
-
78
- async function requestLink(): Promise<boolean> {
79
- if (passwordEndpoint !== null) {
80
- // The person is the sealed session's, never a body field; only the
81
- // route's 202 is a sent link.
82
- try {
83
- const res = await fetch(passwordEndpoint, {
84
- method: "POST",
85
- credentials: "same-origin",
86
- headers: { "content-type": "application/json" },
87
- body: JSON.stringify({ locale }),
88
- });
89
- return res.status === 202;
90
- } catch {
91
- return false;
92
- }
93
- }
94
- // A refusal (the rate limit, the method off) resolves with `{ error }`; a
95
- // network failure rejects. Both read as not sent.
96
- return authClient.requestPasswordReset({ email, redirectTo: resetUrl }).then(
97
- (res) => !res?.error,
98
- () => false,
99
- );
100
- }
101
-
102
- async function logOut(): Promise<boolean> {
103
- let ok: boolean;
104
- try {
105
- if (signOutEndpoint !== null) {
106
- const res = await fetch(signOutEndpoint, { method: "POST", credentials: "same-origin" });
107
- ok = res.ok;
108
- } else {
109
- const res = await authClient.signOut();
110
- ok = !res?.error;
111
- }
112
- } catch {
113
- ok = false;
114
- }
115
- // A failed log-out leaves the person signed in: navigate nowhere.
116
- if (!ok) return false;
117
- router.push(signInHref);
118
- router.refresh();
119
- return true;
120
- }
121
-
122
- const signIn: SecuritySignIn | null =
123
- variant === null
124
- ? null
125
- : variant.kind === "password"
126
- ? { kind: "password", hasPassword: variant.hasPassword, onRequestLink: requestLink }
127
- : variant;
128
-
129
- return <SecuritySettings signIn={signIn} failed={failed} onLogOut={logOut} labels={labels} />;
130
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * account/security/security-source.ts (server code) — which sign-in variant
3
- * the member's Security tab shows (#8431 D2, spec
4
- * docs/specs/8431-account-security-tab-human-sign-spec.md; #11162).
5
- *
6
- * - hub — a spoke that signs in through its hub: whether this person
7
- * has a password, read live from the hub's
8
- * `GET /v1/hub-sign-in/me` with the session's own credential
9
- * (#11162). `null` when the hub answers no state — a hub
10
- * older than #11162, a refusal, a failed read — and the tab
11
- * shows its unavailable line, never a form.
12
- * - password — a site or hub that can email a password link
13
- * (`resetSendConfigured()`, C1): whether this person has a
14
- * password, from the session's own accounts.
15
- * - sentence — any other site: the deployment's configured methods.
16
- *
17
- * It tests no topology constant and imports nothing that loads `auth.ts`:
18
- * `sign-in-method.ts` and the generated seam stay the account tree's seams
19
- * (a hub-sign-in spoke drops `auth.ts`, and `spokeExclusions` refuses any
20
- * surviving account file that reaches it).
21
- *
22
- * The seam is read as a namespace, never by a named import: a site whose
23
- * seam was rendered before #8431 lacks the accounts reader (D2a), and a
24
- * Security route `sync-routes` copies into it must still compile. There it
25
- * shows the sentence — a retry cannot fix a stale seam (D2b).
26
- */
27
-
28
- import { hubSignIn } from "@working-theory/api-client";
29
-
30
- import { resetSendConfigured } from "../../../../../lib/auth-env";
31
- import * as seam from "../../../../../lib/topology.generated";
32
- import { logReadFailure } from "../account-data";
33
- import { signInMethod, type SignInMethodId } from "../sign-in-method";
34
-
35
- export type SecuritySource =
36
- /** `hasPassword: null` — the accounts read failed. */
37
- | { kind: "password"; hasPassword: boolean | null }
38
- | { kind: "sentence"; methods: SignInMethodId[] }
39
- /** `hasPassword: null` — the hub answered no state (#11162). */
40
- | { kind: "hub"; hasPassword: boolean | null };
41
-
42
- type OwnAccountsReader = (headers: Headers) => Promise<ReadonlyArray<{ providerId: string }> | null>;
43
-
44
- /** The account area's request init — on a hub-mode spoke, the credential as a Bearer header. */
45
- type HubReadInit = Parameters<typeof hubSignIn.me>[0];
46
-
47
- /** The seam's accounts reader (D2a), or `null` on a seam rendered before it existed. */
48
- function ownAccountsReader(): OwnAccountsReader | null {
49
- const reader: unknown = Reflect.get(seam, "readOwnAccounts");
50
- return typeof reader === "function" ? (reader as OwnAccountsReader) : null;
51
- }
52
-
53
- /**
54
- * Whether the hub's person has a password (#11162): `hasPassword` from the
55
- * hub's `me` read with the session's credential. `null` when there is no
56
- * credential to ask with, when the hub refuses it, when it answers without
57
- * the field (a hub older than #11162), or when the read fails.
58
- */
59
- async function hubPasswordState(init: HubReadInit | undefined): Promise<boolean | null> {
60
- if (init === undefined) return null;
61
- try {
62
- const res = await hubSignIn.me(init);
63
- if (!res.ok) return null;
64
- return typeof res.body.hasPassword === "boolean" ? res.body.hasPassword : null;
65
- } catch (err) {
66
- logReadFailure("security-hub", err);
67
- return null;
68
- }
69
- }
70
-
71
- export async function securitySource(
72
- headers: Headers,
73
- init: HubReadInit | undefined,
74
- ): Promise<SecuritySource> {
75
- const signIn = signInMethod();
76
- if (signIn.kind === "hub") {
77
- return { kind: "hub", hasPassword: await hubPasswordState(init) };
78
- }
79
- if (!resetSendConfigured()) return { kind: "sentence", methods: signIn.methods };
80
-
81
- const read = ownAccountsReader();
82
- if (read === null) return { kind: "sentence", methods: signIn.methods };
83
- try {
84
- const accounts = await read(headers);
85
- // `null` is a topology with no local accounts, which never reaches here.
86
- if (accounts === null) return { kind: "password", hasPassword: null };
87
- return { kind: "password", hasPassword: accounts.some((a) => a.providerId === "credential") };
88
- } catch (err) {
89
- logReadFailure("security-password", err);
90
- return { kind: "password", hasPassword: null };
91
- }
92
- }