create-ailk 0.35.1 → 0.37.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 (169) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +51 -1
  3. package/component-catalog.md +8 -5
  4. package/dist/lib/env-catalog.js +8 -0
  5. package/dist/surfaces.js +66 -22
  6. package/dist/topology.d.ts +4 -4
  7. package/dist/topology.js +104 -60
  8. package/dist/update.d.ts +19 -1
  9. package/dist/update.js +293 -35
  10. package/package.json +3 -3
  11. package/templates/.env.example +38 -0
  12. package/templates/apps/api/.env.example +45 -0
  13. package/templates/apps/api/CLAUDE.md +12 -4
  14. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  15. package/templates/apps/mcp/CLAUDE.md +4 -2
  16. package/templates/apps/web/.env.example +16 -0
  17. package/templates/apps/web/CLAUDE.md +73 -5
  18. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  19. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  22. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  23. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  24. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  25. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  26. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  27. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  28. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  29. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +241 -66
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +377 -151
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  37. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  38. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  39. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  40. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  41. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  42. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  44. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  45. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  46. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +20 -4
  47. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  48. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  53. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  54. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  55. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  56. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  57. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  58. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  59. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  60. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +323 -73
  61. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +199 -43
  62. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  63. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  64. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  65. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  70. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +97 -53
  71. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  72. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +215 -0
  73. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  75. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  76. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  77. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  79. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  80. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  81. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  82. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  83. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  84. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  85. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  86. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +9 -6
  87. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  88. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  89. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  90. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  91. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  92. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  93. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  94. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  95. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  96. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +21 -22
  97. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  98. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  99. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  101. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  102. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  103. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  104. package/templates/apps/web/app/[locale]/layout.tsx +24 -75
  105. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  106. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  107. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  108. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
  109. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
  110. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  111. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  112. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  113. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  114. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  115. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  116. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  117. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  118. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  119. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  120. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  121. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +738 -7
  122. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  123. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  124. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  125. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  126. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  127. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  128. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  129. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  130. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  131. package/templates/apps/web/auth.ts +133 -6
  132. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  133. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  134. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  135. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  136. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  137. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  138. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  139. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  140. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  141. package/templates/apps/web/lib/account-config.ts +132 -8
  142. package/templates/apps/web/lib/auth-email.ts +62 -6
  143. package/templates/apps/web/lib/auth-env.ts +13 -0
  144. package/templates/apps/web/lib/auth-routes.ts +11 -6
  145. package/templates/apps/web/lib/auth-sms.ts +180 -0
  146. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  147. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  148. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  149. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  150. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  151. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  152. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  153. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  154. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  155. package/templates/apps/web/lib/site-header.ts +14 -1
  156. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  157. package/templates/apps/web/lib/topology.generated.ts +39 -0
  158. package/templates/apps/web/messages/en.json +264 -96
  159. package/templates/apps/web/middleware.ts +34 -2
  160. package/templates/apps/web/security-headers.config.ts +21 -0
  161. package/versions.json +48 -48
  162. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  163. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  164. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  165. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
  166. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  167. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  168. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  169. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -1,52 +1,75 @@
1
1
  /**
2
- * /[locale]/account/privacy — User settings › Privacy (#8438 D14, NEW).
2
+ * /[locale]/account/privacy — User settings › Privacy (#8438 D14; #11164 —
3
+ * Ploy's row-and-card shape, operator rulings 2026-11-08).
3
4
  *
4
5
  * RSC, outside the account layout's SignedInShell (#8430), in the member's
5
6
  * settings frame (D7) — standalone, the Admin's shape. In DOM order:
6
7
  *
7
- * 1. account-privacy-summary — one line with a link to the site's
8
- * privacy policy.
9
- * 2. account-privacy-cookies — the current cookie-banner choice, read
10
- * from the request's OWN `ailk-consent` cookie (never the ledger —
11
- * the cookie stays the operative switch, C3), and a Change link
12
- * (moved here from Notifications, #8438 D15) to
13
- * `/privacy#cookie-settings`.
14
- * 3. account-privacy-consents — one `ConsentSwitchList` row per
15
- * `area: "data"` purpose, or the "no other data-use consents" line.
16
- * 4. account-privacy-agreements — a read-only `AgreementList` of every
17
- * agreement (`service_terms`, `account_terms`, …), or "None yet"; each
18
- * statement's links resolve through `consentPoliciesFor(locale)`
19
- * (#8765 D11).
20
- * 5. account-deletion — moved unchanged from General (#8438 D16).
8
+ * 1. The title and the lead, with "Privacy Policy" linked to the site's
9
+ * privacy policy (`consentPoliciesFor(locale).privacy`, #8765 D9).
10
+ * 2. One card:
11
+ * - account-privacy-data-use — "How we use your data", collapsed, a
12
+ * disclosure button whose chevron expands it in place to the two
13
+ * bullets (`DataUseDisclosure`);
14
+ * - account-privacy-data-consent — one `ConsentSwitchList` row per
15
+ * `area: "data"` purpose, the shipped one being "Help improve our AI
16
+ * models" (`ai_training`, #11164 AC-2: a consent, off until ticked,
17
+ * written through `setConsentAction`), with its description and the
18
+ * given/withdrawn date line; a site that declares none shows the one
19
+ * line. A failed consents read shows the unavailable line in its place
20
+ * and everything else still renders.
21
+ * 3. One card: account-privacy-your-data — the "Your data" table
22
+ * (`AccountDataTable`): Export data, a download of the person's own
23
+ * records through this site's `./export` route; Delete stored sessions,
24
+ * which confirms first, then calls `deleteStoredSessionsAction` and
25
+ * reports the count. The same card on every surface, a spoke that
26
+ * signs in through its hub included (#11194): the two member routes
27
+ * the table calls are on `HUB_SESSION_ROUTES`, each answered for the
28
+ * spoke's own workspace from the hub session.
21
29
  *
22
- * Sections 3 and 4 read `GET /v1/member/consents`; a failed read shows one
23
- * line in their place and sections 1, 2 and 5 still render (D14).
30
+ * Gone (#11164 rulings 1, 2, 5, 6): the Cookies section (the choice cannot
31
+ * change without a new banner prompt), the summary row, the agreements list
32
+ * (the ledger keeps the record) and the account-deletion line and button. An
33
+ * account-deletion request now lives in the Delete row's confirmation, which
34
+ * points at Support — on every surface but a hub-mode spoke whose hub answers
35
+ * no member route (`via: "none"`), where Support must not take it
36
+ * (SEC-7894-11); `POST /v1/member/deletion-request` is unchanged.
37
+ *
38
+ * The registry purpose this app names itself: `ai_training` →
39
+ * `settings.privacy.purposes.ai_training` (title, description); a purpose a
40
+ * site adds is labelled by its statement and described by its description.
41
+ * The lead is one `t.rich` message whose `<policy>` tag is the link (the
42
+ * billing tab's `accessEnds` idiom); the metadata description is the same
43
+ * message through `t.markup` with the tag dropped.
24
44
  */
25
45
 
26
46
  import { member } from "@working-theory/api-client";
27
47
  import {
48
+ AccountDataTable,
28
49
  AccountSettingsFrame,
29
50
  AccountSettingsPane,
30
- AgreementList,
31
51
  ConsentSwitchList,
52
+ DataUseDisclosure,
53
+ type ConsentSwitchRow,
32
54
  } from "@working-theory/templates/account";
33
55
  import { localeHref } from "@working-theory/ui";
34
- import { Heading, Link, Text } from "@working-theory/ui/primitives";
56
+ import {
57
+ Link,
58
+ SERVER_TIME_ZONE,
59
+ Text,
60
+ formatLocalTime,
61
+ } from "@working-theory/ui/primitives";
62
+ import { AI_TRAINING_PURPOSE_ID } from "@working-theory/validation";
35
63
  import type { Metadata } from "next";
36
- import { cookies } from "next/headers";
37
64
  import { getTranslations } from "next-intl/server";
38
65
  import type { ReactElement } from "react";
39
66
 
40
67
  import { consentPoliciesFor } from "../../../../../lib/consent-policies";
41
68
  import { accountSession } from "../account-data";
42
- import { DeletionRequest } from "../general/deletion-request";
43
69
  import { loadProfileSource } from "../general/profile-source";
44
70
  import { memberSettingsFrame, type Translate } from "../settings-frame";
45
71
 
46
- import { setConsentAction } from "./actions";
47
-
48
- /** The cookie banner's own choice cookie (`layout.tsx`'s `CONSENT_COOKIE_NAME`, #5557). */
49
- const CONSENT_COOKIE_NAME = "ailk-consent";
72
+ import { deleteStoredSessionsAction, setConsentAction } from "./actions";
50
73
 
51
74
  interface Props {
52
75
  params: Promise<{ locale: string }>;
@@ -55,14 +78,34 @@ interface Props {
55
78
  export async function generateMetadata({ params }: Props): Promise<Metadata> {
56
79
  const { locale } = await params;
57
80
  const t = await getTranslations({ locale, namespace: "account" });
58
- return { title: t("settings.privacy.title"), description: t("settings.privacy.lead") };
81
+ return {
82
+ title: t("settings.privacy.title"),
83
+ description: t.markup("settings.privacy.lead", {
84
+ policy: (chunks) => chunks,
85
+ }),
86
+ };
59
87
  }
60
88
 
61
- export default async function AccountPrivacyPage({ params }: Props): Promise<ReactElement> {
89
+ export default async function AccountPrivacyPage({
90
+ params,
91
+ }: Props): Promise<ReactElement> {
62
92
  const { locale } = await params;
63
93
  const t = await getTranslations({ locale, namespace: "account" });
64
94
  const session = await accountSession(locale);
65
- const frame = memberSettingsFrame(locale, t as unknown as Translate, "privacy");
95
+ const frame = memberSettingsFrame(
96
+ locale,
97
+ t as unknown as Translate,
98
+ "privacy",
99
+ );
100
+ const policyHref =
101
+ consentPoliciesFor(locale)["privacy"] ?? localeHref(locale, "/privacy");
102
+ const lead = t.rich("settings.privacy.lead", {
103
+ policy: (chunks) => (
104
+ <Link href={policyHref} data-testid="account-privacy-policy">
105
+ {chunks}
106
+ </Link>
107
+ ),
108
+ });
66
109
 
67
110
  // Unreachable behind the (authed) gate; a session that expired between
68
111
  // the layout and the page renders the pane's title alone.
@@ -72,7 +115,7 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
72
115
  <AccountSettingsPane
73
116
  id="account-settings-privacy"
74
117
  title={t("settings.privacy.title")}
75
- lead={t("settings.privacy.lead")}
118
+ lead={lead}
76
119
  >
77
120
  {null}
78
121
  </AccountSettingsPane>
@@ -84,16 +127,7 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
84
127
  const name = ctx.user.name || ctx.user.email;
85
128
  const source = await loadProfileSource(ctx);
86
129
 
87
- let cookieChoice: "accepted" | "declined" | null;
88
- try {
89
- const value = (await cookies()).get(CONSENT_COOKIE_NAME)?.value;
90
- cookieChoice = value === "accepted" || value === "declined" ? value : null;
91
- } catch {
92
- cookieChoice = null;
93
- }
94
-
95
- let dataRows: { id: string; label: string; description?: string; granted: boolean; dateLine?: string }[] = [];
96
- let agreementRows: { id: string; statement: string; version: number; acceptedLine?: string }[] = [];
130
+ let dataRows: ConsentSwitchRow[] = [];
97
131
  let consentsAvailable = true;
98
132
  try {
99
133
  const res = await member.consents(ctx.init, { locale });
@@ -102,27 +136,32 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
102
136
  .filter((purpose) => purpose.area === "data")
103
137
  .map((purpose) => ({
104
138
  id: purpose.id,
105
- label: purpose.statement,
139
+ ...(purpose.id === AI_TRAINING_PURPOSE_ID
140
+ ? {
141
+ label: t("settings.privacy.purposes.ai_training.title"),
142
+ description: t(
143
+ "settings.privacy.purposes.ai_training.description",
144
+ ),
145
+ }
146
+ : {
147
+ label: purpose.statement,
148
+ ...(purpose.description
149
+ ? { description: purpose.description }
150
+ : {}),
151
+ }),
106
152
  granted: purpose.effective,
107
- ...(purpose.description ? { description: purpose.description } : {}),
108
153
  ...(purpose.state
109
154
  ? {
110
155
  dateLine: purpose.state.granted
111
- ? t("settings.privacy.given", { date: formatDate(purpose.state.at, locale) })
112
- : t("settings.privacy.withdrawn", { date: formatDate(purpose.state.at, locale) }),
156
+ ? t("settings.privacy.given", {
157
+ date: formatDate(purpose.state.at, locale),
158
+ })
159
+ : t("settings.privacy.withdrawn", {
160
+ date: formatDate(purpose.state.at, locale),
161
+ }),
113
162
  }
114
163
  : {}),
115
164
  }));
116
- agreementRows = res.body.purposes
117
- .filter((purpose) => purpose.kind === "agreement")
118
- .map((purpose) => ({
119
- id: purpose.id,
120
- statement: purpose.statement,
121
- version: purpose.policyVersion,
122
- ...(purpose.state?.granted
123
- ? { acceptedLine: t("settings.privacy.accepted", { date: formatDate(purpose.state.at, locale) }) }
124
- : {}),
125
- }));
126
165
  } else {
127
166
  consentsAvailable = false;
128
167
  }
@@ -135,96 +174,67 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
135
174
  <AccountSettingsPane
136
175
  id="account-settings-privacy"
137
176
  title={t("settings.privacy.title")}
138
- lead={t("settings.privacy.lead")}
177
+ lead={lead}
139
178
  >
140
- <div data-testid="account-privacy-summary" className="flex flex-wrap items-baseline gap-1">
141
- <Text as="span" variant="body-sm">
142
- {t("settings.privacy.summary")}
143
- </Text>
144
- <Link href={localeHref(locale, "/privacy")} data-testid="account-privacy-policy">
145
- {t("settings.privacy.policyLink")}
146
- </Link>
147
- </div>
148
-
149
- <div data-testid="account-privacy-cookies" className="flex flex-col gap-1">
150
- <Heading level={2} visual={4} className="!text-body-sm !font-medium">
151
- {t("settings.privacy.cookiesTitle")}
152
- </Heading>
153
- <div className="flex flex-wrap items-baseline gap-3">
154
- <Text as="span" variant="body-sm" tone="muted">
155
- {cookieChoice === "accepted"
156
- ? t("settings.privacy.cookiesAccepted")
157
- : cookieChoice === "declined"
158
- ? t("settings.privacy.cookiesDeclined")
159
- : t("settings.privacy.cookiesUnset")}
160
- </Text>
161
- <Link
162
- href={localeHref(locale, "/privacy#cookie-settings")}
163
- className="inline-flex min-h-6 items-center"
164
- data-testid="account-cookie-settings"
165
- >
166
- {t("settings.privacy.cookiesChange")}
167
- </Link>
168
- </div>
169
- </div>
170
-
171
- {consentsAvailable ? (
172
- <>
173
- <div data-testid="account-privacy-consents" className="flex flex-col gap-2">
174
- <Heading level={2} visual={4} className="!text-body-sm !font-medium">
175
- {t("settings.privacy.consentsTitle")}
176
- </Heading>
177
- <ConsentSwitchList
178
- rows={dataRows}
179
- onChange={setConsentAction}
180
- emptyLine={t("settings.privacy.consentsEmpty")}
181
- testIdPrefix="account-privacy-data-consent"
182
- />
183
- </div>
184
-
185
- <div data-testid="account-privacy-agreements" className="flex flex-col gap-2">
186
- <Heading level={2} visual={4} className="!text-body-sm !font-medium">
187
- {t("settings.privacy.agreementsTitle")}
188
- </Heading>
189
- <AgreementList
190
- rows={agreementRows}
191
- notAcceptedLine={t("settings.privacy.agreementsEmpty")}
192
- emptyLine={t("settings.privacy.agreementsEmpty")}
193
- testIdPrefix="account-privacy-agreement"
194
- policies={consentPoliciesFor(locale)}
195
- />
196
- </div>
197
- </>
198
- ) : (
199
- <span data-testid="account-privacy-unavailable">
200
- <Text as="p" variant="body-sm" tone="muted">
201
- {t("settings.privacy.unavailable")}
202
- </Text>
203
- </span>
204
- )}
205
-
206
- <div data-testid="account-deletion">
207
- <DeletionRequest
208
- via={source.via}
209
- supportHref={localeHref(locale, "/account/support")}
210
- labels={{
211
- lead: t("settings.privacy.deletionLead"),
212
- action: t("settings.privacy.deletion"),
213
- sentSite: t("settings.privacy.deletionSentSite"),
214
- sentHub: t("settings.privacy.deletionSentHub"),
215
- unverified: t("settings.privacy.deletionUnverified"),
216
- unavailable: t("settings.privacy.deletionUnavailable"),
217
- error: t("settings.privacy.deletionError"),
218
- viaSupport: t("settings.privacy.deletionViaSupport"),
219
- supportLink: t("settings.privacy.deletionSupportLink"),
220
- }}
179
+ <>
180
+ <DataUseDisclosure
181
+ title={t("settings.privacy.dataUse.title")}
182
+ bullets={[
183
+ t("settings.privacy.dataUse.bullet1"),
184
+ t("settings.privacy.dataUse.bullet2"),
185
+ ]}
186
+ testId="account-privacy-data-use"
221
187
  />
222
- </div>
188
+ {consentsAvailable ? (
189
+ <ConsentSwitchList
190
+ rows={dataRows}
191
+ onChange={setConsentAction}
192
+ emptyLine={t("settings.privacy.consentsEmpty")}
193
+ testIdPrefix="account-privacy-data-consent"
194
+ />
195
+ ) : (
196
+ <span data-testid="account-privacy-unavailable">
197
+ <Text as="p" variant="body-sm" tone="muted" className="pt-3">
198
+ {t("settings.privacy.unavailable")}
199
+ </Text>
200
+ </span>
201
+ )}
202
+ </>
203
+ <AccountDataTable
204
+ exportHref={localeHref(locale, "/account/privacy/export")}
205
+ onDeleteSessions={deleteStoredSessionsAction}
206
+ supportHref={
207
+ source.via === "none"
208
+ ? null
209
+ : localeHref(locale, "/account/support")
210
+ }
211
+ testIdPrefix="account-privacy-your-data"
212
+ labels={{
213
+ title: t("settings.privacy.yourData.title"),
214
+ exportLabel: t("settings.privacy.yourData.exportLabel"),
215
+ exportButton: t("settings.privacy.yourData.exportButton"),
216
+ deleteLabel: t("settings.privacy.yourData.deleteLabel"),
217
+ deleteDescription: t("settings.privacy.yourData.deleteDescription"),
218
+ deleteButton: t("settings.privacy.yourData.deleteButton"),
219
+ confirmTitle: t("settings.privacy.yourData.confirmTitle"),
220
+ confirmBody: t("settings.privacy.yourData.confirmBody"),
221
+ confirmCancel: t("settings.privacy.yourData.confirmCancel"),
222
+ confirmDelete: t("settings.privacy.yourData.confirmDelete"),
223
+ deleting: t("settings.privacy.yourData.deleting"),
224
+ deleteFailed: t("settings.privacy.yourData.deleteFailed"),
225
+ accountDeletion: t("settings.privacy.yourData.accountDeletion"),
226
+ accountDeletionLink: t(
227
+ "settings.privacy.yourData.accountDeletionLink",
228
+ ),
229
+ }}
230
+ />
223
231
  </AccountSettingsPane>
224
232
  </AccountSettingsFrame>
225
233
  );
226
234
  }
227
235
 
236
+ // #11159: a `t()` argument is a string, so this RSC reads the day in the
237
+ // server fallback zone — never the host's, which the unpinned form read.
228
238
  function formatDate(iso: string, locale: string): string {
229
- return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(new Date(iso));
239
+ return formatLocalTime(iso, "date", { timeZone: SERVER_TIME_ZONE, locale });
230
240
  }
@@ -0,0 +1,258 @@
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
+ });