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
@@ -0,0 +1,215 @@
1
+ /**
2
+ * The Account page's phone step (#11106, spec
3
+ * docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9; AC-6's
4
+ * "a user sets and verifies a phone in the hub's Account settings").
5
+ *
6
+ * - the island: send a code, then verify it; a verified number shows with
7
+ * "Verified" and Remove; a refusal shows its line; a build without the
8
+ * step, or an unverified email, shows its line and no form;
9
+ * - the server actions: each is a SERVER call on the plugin with the
10
+ * request's headers, `verifyPhoneCode` always with `updatePhoneNumber:
11
+ * true`, Remove writes `phoneNumber: null`, a refusal maps to its reason,
12
+ * a build without the step answers `unavailable` with no call, and no log
13
+ * line carries the number or the code.
14
+ */
15
+ import { act, fireEvent, render, screen } from "@testing-library/react";
16
+
17
+ const mockSendOtp = jest.fn();
18
+ const mockVerify = jest.fn();
19
+ const mockUpdateUser = jest.fn();
20
+ const mockPhoneStepActive = jest.fn();
21
+ // eslint-disable-next-line no-restricted-syntax -- #507: auth.ts is Better Auth's server singleton (a DB/HTTP boundary); its phone endpoints are the actions' one dependency.
22
+ jest.mock("../../../../../../auth", () => ({
23
+ __esModule: true,
24
+ phoneStepActive: () => mockPhoneStepActive(),
25
+ auth: {
26
+ api: {
27
+ sendPhoneNumberOTP: (...args: unknown[]) => mockSendOtp(...args),
28
+ verifyPhoneNumber: (...args: unknown[]) => mockVerify(...args),
29
+ updateUser: (...args: unknown[]) => mockUpdateUser(...args),
30
+ },
31
+ },
32
+ }));
33
+
34
+ const REQUEST_HEADERS = new Headers({ cookie: "better-auth.session_token=abc" });
35
+ jest.mock("next/headers", () => ({
36
+ __esModule: true,
37
+ headers: jest.fn(async () => REQUEST_HEADERS),
38
+ }));
39
+
40
+ const mockRefresh = jest.fn();
41
+ jest.mock("next/navigation", () => ({
42
+ __esModule: true,
43
+ useRouter: () => ({ refresh: mockRefresh }),
44
+ }));
45
+
46
+ import { removePhone, sendPhoneCode, verifyPhoneCode } from "../phone-actions";
47
+ import { PhoneVerification, type PhoneVerificationLabels } from "../phone-verification";
48
+
49
+ const NUMBER = "+15555550123";
50
+ const CODE = "482913";
51
+
52
+ const LABELS: PhoneVerificationLabels = {
53
+ title: "Phone",
54
+ lead: "Only you can set it.",
55
+ number: "Mobile number",
56
+ numberHint: "Include the country code.",
57
+ sendCode: "Send code",
58
+ sending: "Sending…",
59
+ code: "Code",
60
+ codeHint: "Six digits.",
61
+ verify: "Verify",
62
+ verifying: "Verifying…",
63
+ verified: "Verified",
64
+ remove: "Remove",
65
+ sent: "We texted you a code.",
66
+ unavailable: "Phone verification isn't available on this site.",
67
+ unverifiedEmail: "Confirm your email address first.",
68
+ errors: {
69
+ invalid_number: "Bad number.",
70
+ invalid_code: "Bad code.",
71
+ taken: "Taken.",
72
+ too_many: "Too many.",
73
+ unverified: "Unverified.",
74
+ signed_out: "Signed out.",
75
+ unavailable: "Unavailable.",
76
+ failed: "Failed.",
77
+ },
78
+ };
79
+
80
+ const apiError = (code: string) => Object.assign(new Error(code), { body: { code } });
81
+
82
+ let logLines: string[] = [];
83
+ beforeEach(() => {
84
+ jest.clearAllMocks();
85
+ mockPhoneStepActive.mockReturnValue(true);
86
+ mockSendOtp.mockResolvedValue({ message: "code sent" });
87
+ mockVerify.mockResolvedValue({ status: true });
88
+ mockUpdateUser.mockResolvedValue({ status: true });
89
+ logLines = [];
90
+ jest.spyOn(console, "error").mockImplementation((...args: unknown[]) => {
91
+ logLines.push(args.map(String).join(" "));
92
+ });
93
+ });
94
+
95
+ afterEach(() => {
96
+ jest.restoreAllMocks();
97
+ });
98
+
99
+ describe("the island", () => {
100
+ it("sends a code, then verifies it, and refreshes the page", async () => {
101
+ render(<PhoneVerification available emailVerified phone={null} labels={LABELS} />);
102
+ fireEvent.change(screen.getByTestId("account-phone-number-input"), { target: { value: NUMBER } });
103
+ await act(async () => {
104
+ fireEvent.click(screen.getByTestId("account-phone-send"));
105
+ });
106
+ expect(mockSendOtp).toHaveBeenCalledWith({ body: { phoneNumber: NUMBER }, headers: REQUEST_HEADERS });
107
+ expect(screen.getByTestId("account-phone-sent")).toHaveTextContent(LABELS.sent);
108
+
109
+ fireEvent.change(screen.getByTestId("account-phone-code-input"), { target: { value: CODE } });
110
+ await act(async () => {
111
+ fireEvent.click(screen.getByTestId("account-phone-verify"));
112
+ });
113
+ expect(mockVerify).toHaveBeenCalledWith({
114
+ body: { phoneNumber: NUMBER, code: CODE, updatePhoneNumber: true },
115
+ headers: REQUEST_HEADERS,
116
+ });
117
+ expect(mockRefresh).toHaveBeenCalledTimes(1);
118
+ });
119
+
120
+ it("a refused code shows its line and refreshes nothing", async () => {
121
+ mockVerify.mockRejectedValue(apiError("INVALID_OTP"));
122
+ render(<PhoneVerification available emailVerified phone={null} labels={LABELS} />);
123
+ fireEvent.change(screen.getByTestId("account-phone-number-input"), { target: { value: NUMBER } });
124
+ await act(async () => {
125
+ fireEvent.click(screen.getByTestId("account-phone-send"));
126
+ });
127
+ fireEvent.change(screen.getByTestId("account-phone-code-input"), { target: { value: CODE } });
128
+ await act(async () => {
129
+ fireEvent.click(screen.getByTestId("account-phone-verify"));
130
+ });
131
+ expect(screen.getByTestId("account-phone-error")).toHaveTextContent(LABELS.errors.invalid_code);
132
+ expect(mockRefresh).not.toHaveBeenCalled();
133
+ });
134
+
135
+ it("a verified number shows with Verified and Remove, which clears it", async () => {
136
+ render(
137
+ <PhoneVerification available emailVerified phone={{ number: NUMBER, verified: true }} labels={LABELS} />,
138
+ );
139
+ expect(screen.getByTestId("account-phone-number")).toHaveTextContent(NUMBER);
140
+ expect(screen.getByTestId("account-phone-verified")).toHaveTextContent(LABELS.verified);
141
+ expect(screen.queryByTestId("account-phone-number-input")).toBeNull();
142
+ await act(async () => {
143
+ fireEvent.click(screen.getByTestId("account-phone-remove"));
144
+ });
145
+ expect(mockUpdateUser).toHaveBeenCalledWith({ body: { phoneNumber: null }, headers: REQUEST_HEADERS });
146
+ expect(mockRefresh).toHaveBeenCalledTimes(1);
147
+ });
148
+
149
+ it("a build without the step shows the not-available line and no form", () => {
150
+ render(<PhoneVerification available={false} emailVerified phone={null} labels={LABELS} />);
151
+ expect(screen.getByTestId("account-phone-unavailable")).toHaveTextContent(LABELS.unavailable);
152
+ expect(screen.queryByTestId("account-phone-send-form")).toBeNull();
153
+ });
154
+
155
+ it("an unverified email shows the confirm-email line and no form", () => {
156
+ render(<PhoneVerification available emailVerified={false} phone={null} labels={LABELS} />);
157
+ expect(screen.getByTestId("account-phone-unverified-email")).toHaveTextContent(LABELS.unverifiedEmail);
158
+ expect(screen.queryByTestId("account-phone-send-form")).toBeNull();
159
+ });
160
+ });
161
+
162
+ describe("the server actions", () => {
163
+ it.each([
164
+ ["INVALID_PHONE_NUMBER", "invalid_number"],
165
+ ["EMAIL_NOT_VERIFIED", "unverified"],
166
+ ["SESSION_REQUIRED", "signed_out"],
167
+ ["SOMETHING_ELSE", "failed"],
168
+ ])("sendPhoneCode maps %s to %s", async (code, reason) => {
169
+ mockSendOtp.mockRejectedValue(apiError(code));
170
+ expect(await sendPhoneCode(NUMBER)).toEqual({ ok: false, reason });
171
+ });
172
+
173
+ it.each([
174
+ ["INVALID_OTP", "invalid_code"],
175
+ ["TOO_MANY_ATTEMPTS", "too_many"],
176
+ ["PHONE_NUMBER_EXIST", "taken"],
177
+ ])("verifyPhoneCode maps %s to %s", async (code, reason) => {
178
+ mockVerify.mockRejectedValue(apiError(code));
179
+ expect(await verifyPhoneCode(NUMBER, CODE)).toEqual({ ok: false, reason });
180
+ });
181
+
182
+ it("verifyPhoneCode always asks for updatePhoneNumber, never a sign-in", async () => {
183
+ expect(await verifyPhoneCode(NUMBER, CODE)).toEqual({ ok: true });
184
+ expect(mockVerify.mock.calls[0]![0].body.updatePhoneNumber).toBe(true);
185
+ });
186
+
187
+ it("refuses untrusted input before any call", async () => {
188
+ expect(await sendPhoneCode({ phoneNumber: NUMBER })).toEqual({ ok: false, reason: "invalid_number" });
189
+ expect(await verifyPhoneCode(NUMBER, "1234567")).toEqual({ ok: false, reason: "invalid_code" });
190
+ expect(mockSendOtp).not.toHaveBeenCalled();
191
+ expect(mockVerify).not.toHaveBeenCalled();
192
+ });
193
+
194
+ it("a build without the step answers unavailable with no call", async () => {
195
+ mockPhoneStepActive.mockReturnValue(false);
196
+ expect(await sendPhoneCode(NUMBER)).toEqual({ ok: false, reason: "unavailable" });
197
+ expect(await verifyPhoneCode(NUMBER, CODE)).toEqual({ ok: false, reason: "unavailable" });
198
+ expect(await removePhone()).toEqual({ ok: false, reason: "unavailable" });
199
+ expect(mockSendOtp).not.toHaveBeenCalled();
200
+ expect(mockVerify).not.toHaveBeenCalled();
201
+ expect(mockUpdateUser).not.toHaveBeenCalled();
202
+ });
203
+
204
+ it("no log line carries the number or the code", async () => {
205
+ mockSendOtp.mockRejectedValue(apiError("INVALID_PHONE_NUMBER"));
206
+ mockVerify.mockRejectedValue(apiError("INVALID_OTP"));
207
+ await sendPhoneCode(NUMBER);
208
+ await verifyPhoneCode(NUMBER, CODE);
209
+ expect(logLines.length).toBe(2);
210
+ for (const line of logLines) {
211
+ expect(line).not.toContain(NUMBER.slice(1));
212
+ expect(line).not.toContain(CODE);
213
+ }
214
+ });
215
+ });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @jest-environment node
3
+ *
4
+ * User settings › General reaches sign-in only through the generated seam
5
+ * (#11138). A spoke that signs in through its hub keeps this page, but not
6
+ * `auth.ts` or any other sign-in or database file, so a direct import here
7
+ * would make create-ailk's spoke closure drop the page with them and refuse.
8
+ * Every non-test source file under `account/general` is read, and none may
9
+ * name one of those files, statically or by `import()`/`require`; the phone
10
+ * step goes through `loadPhoneApi` in `lib/topology.generated.ts` instead.
11
+ */
12
+ import { readdirSync, readFileSync } from "node:fs";
13
+ import { dirname, join, relative, resolve } from "node:path";
14
+
15
+ const GENERAL = resolve(__dirname, "..");
16
+ const WEB = resolve(GENERAL, "../../../../..");
17
+
18
+ /** The sign-in and database files a spoke does not carry, relative to apps/web. */
19
+ const SIGN_IN_FILES = [
20
+ "auth",
21
+ "lib/prisma-for-auth",
22
+ "lib/mcp-oauth",
23
+ "lib/license-key-store",
24
+ "app/api/auth",
25
+ "app/[locale]/(auth)",
26
+ ];
27
+
28
+ const sources = readdirSync(GENERAL).filter((name) => /\.tsx?$/.test(name));
29
+
30
+ function specifiers(text: string): string[] {
31
+ return [
32
+ ...text.matchAll(/(?:\bfrom\s+|\bimport\s*\(\s*|\brequire\s*\(\s*)["'`]([^"'`]+)["'`]/g),
33
+ ].map((m) => m[1] as string);
34
+ }
35
+
36
+ describe("account/general imports sign-in only through the seam (#11138)", () => {
37
+ it("reads every source file", () => {
38
+ expect(sources).toEqual(expect.arrayContaining(["page.tsx", "phone-actions.ts"]));
39
+ });
40
+
41
+ it.each(sources)("%s names no sign-in or database file", (name) => {
42
+ const file = join(GENERAL, name);
43
+ const reached = specifiers(readFileSync(file, "utf8"))
44
+ .filter((spec) => spec.startsWith("."))
45
+ .map((spec) =>
46
+ relative(WEB, resolve(dirname(file), spec))
47
+ .split("\\")
48
+ .join("/")
49
+ .replace(/\.tsx?$/, ""),
50
+ );
51
+ expect(
52
+ reached.filter((target) =>
53
+ SIGN_IN_FILES.some((seed) => target === seed || target.startsWith(`${seed}/`)),
54
+ ),
55
+ ).toEqual([]);
56
+ });
57
+
58
+ it("the phone step reads the seam", () => {
59
+ for (const name of ["page.tsx", "phone-actions.ts"]) {
60
+ expect(readFileSync(join(GENERAL, name), "utf8")).toMatch(
61
+ /from "\.\.\/\.\.\/\.\.\/\.\.\/\.\.\/lib\/topology\.generated"/,
62
+ );
63
+ }
64
+ });
65
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The account name the contact derives (#11167 ruling 5): "First Last" from
3
+ * the contact's given and family names, and the rule for when the account
4
+ * name may follow it — while it is empty, or equals what the PREVIOUS contact
5
+ * derived, so a name the person set by hand is never overwritten.
6
+ *
7
+ * Not in `contact-actions.ts`: Next.js makes every runtime export of a
8
+ * "use server" file a Server Action and fails the build on a synchronous one
9
+ * (the `invitation-id.ts` rule, #11141).
10
+ */
11
+
12
+ import { PROFILE_NAME_MAX } from "@working-theory/validation";
13
+
14
+ export type ContactNames = { givenName: string | null; familyName: string | null } | null;
15
+
16
+ /** "First Last", trimmed and cut to the profile name's width; `""` with neither name. */
17
+ export function derivedAccountName(contact: ContactNames): string {
18
+ return [contact?.givenName, contact?.familyName]
19
+ .map((part) => part?.trim() ?? "")
20
+ .filter((part) => part !== "")
21
+ .join(" ")
22
+ .slice(0, PROFILE_NAME_MAX)
23
+ .trim();
24
+ }
25
+
26
+ /**
27
+ * Whether the account name may follow the contact: it is empty, or it is
28
+ * exactly what the previous contact derived (so it was never set by hand).
29
+ */
30
+ export function accountNameFollowsContact(
31
+ current: string | null | undefined,
32
+ previous: ContactNames,
33
+ ): boolean {
34
+ const name = current?.trim() ?? "";
35
+ return name === "" || name === derivedAccountName(previous);
36
+ }
@@ -20,6 +20,20 @@
20
20
  * another account), else `failed`. Logs carry a status or `err.name` only —
21
21
  * never a name, a number, an address or an email.
22
22
  *
23
+ * #11167 ruling 5 — the account name follows the contact. The member General
24
+ * renders no Name field; after a save that succeeded, `followContactName`
25
+ * derives "First Last" from the saved contact's given and family names and
26
+ * writes it as the account name (`member.updateProfile({ name })`, then the
27
+ * hub-session re-seal) ONLY while the account name is empty or equals the
28
+ * value the PREVIOUS contact derived — a name the person set by hand (on the
29
+ * Admin, or before this ruling) is never overwritten. The rule itself is
30
+ * `account-name.ts`. The account name is the stored one (`member.profile`,
31
+ * never the session's copy, which a spoke's cookie holds from its last
32
+ * re-seal), and the previous contact is `member.contact`, both read before
33
+ * the save; an unreadable name follows nothing, an unreadable contact counts
34
+ * as none, so only an empty name is then followed. A failed follow is logged
35
+ * and the save still answers `{ ok: true }`: the contact IS saved.
36
+ *
23
37
  * Not a `*.actions.ts` file and no `*Action`-suffixed export: the write has no
24
38
  * MCP twin by decision (8435 D12), and apps/mcp's parity test reads that
25
39
  * suffix.
@@ -27,8 +41,11 @@
27
41
 
28
42
  import { member } from "@working-theory/api-client";
29
43
 
44
+ import { resealHubSession } from "../../../../../lib/hub-session/reseal";
30
45
  import { forwardedCookieInit } from "../../../../../lib/server-api";
31
46
 
47
+ import { accountNameFollowsContact, type ContactNames, derivedAccountName } from "./account-name";
48
+
32
49
  /** PII-safe error identity for logs (the `profile-actions.ts` idiom: `err.name` only). */
33
50
  function errorName(err: unknown): string {
34
51
  return err instanceof Error ? err.name : "unknown";
@@ -50,6 +67,52 @@ export type SaveContactResult =
50
67
  reason: "telephone" | "invalid" | "unverified" | "unavailable" | "failed";
51
68
  };
52
69
 
70
+ type Init = Awaited<ReturnType<typeof forwardedCookieInit>>;
71
+
72
+ /** The person's confirmed contact before the save, or `null` when unread. */
73
+ async function previousContact(init: Init): Promise<ContactNames> {
74
+ try {
75
+ const res = await member.contact(init);
76
+ return res.ok ? res.body.contact : null;
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
81
+
82
+ /** The stored account name (`""` when none), or `undefined` when it cannot be read. */
83
+ async function currentAccountName(init: Init): Promise<string | undefined> {
84
+ try {
85
+ const res = await member.profile(init);
86
+ return res.ok ? (res.body.name ?? "") : undefined;
87
+ } catch {
88
+ return undefined;
89
+ }
90
+ }
91
+
92
+ /** Writes the derived name as the account name when the rule allows; never throws. */
93
+ async function followContactName(
94
+ current: string | undefined,
95
+ previous: ContactNames,
96
+ next: ContactNames,
97
+ init: Init,
98
+ ): Promise<void> {
99
+ const derived = derivedAccountName(next);
100
+ if (derived === "" || current === undefined) return;
101
+ if (!accountNameFollowsContact(current, previous) || current.trim() === derived) return;
102
+ try {
103
+ const res = await member.updateProfile({ name: derived }, init);
104
+ if (!res.ok) {
105
+ console.error(`[contact-actions] followContactName status=${res.status}`);
106
+ return;
107
+ }
108
+ if ((await resealHubSession()) === "failed") {
109
+ console.error("[contact-actions] followContactName reseal=failed");
110
+ }
111
+ } catch (err) {
112
+ console.error(`[contact-actions] followContactName errName=${errorName(err)}`);
113
+ }
114
+ }
115
+
53
116
  export async function saveContact(
54
117
  input: Parameters<typeof member.updateContact>[0],
55
118
  ): Promise<SaveContactResult> {
@@ -59,8 +122,13 @@ export async function saveContact(
59
122
  return { ok: false, reason: "invalid" };
60
123
 
61
124
  try {
62
- const res = await member.updateContact(input, await forwardedCookieInit());
63
- if (res.ok) return { ok: true };
125
+ const init = await forwardedCookieInit();
126
+ const [previous, current] = await Promise.all([previousContact(init), currentAccountName(init)]);
127
+ const res = await member.updateContact(input, init);
128
+ if (res.ok) {
129
+ await followContactName(current, previous, res.body.contact, init);
130
+ return { ok: true };
131
+ }
64
132
  console.error(`[contact-actions] saveContact status=${res.status}`);
65
133
  if (res.status === 400) {
66
134
  return {
@@ -0,0 +1,42 @@
1
+ "use client"; // owns the router.refresh() that follows a contact save
2
+
3
+ /**
4
+ * ContactDetails — User settings › General's contact section on the member
5
+ * path (#8435 D13; #11167 ruling 5): the shared `AccountContactDetails` over
6
+ * `saveContact`, plus one thing the server action cannot do — after a save
7
+ * that succeeded it refreshes the route, so the rail's name shows the
8
+ * "First Last" the save may have derived for the account.
9
+ */
10
+
11
+ import {
12
+ AccountContactDetails,
13
+ type AccountContact,
14
+ type AccountContactLabels,
15
+ type AccountContactSaveResult,
16
+ } from "@working-theory/templates/account";
17
+ import { useRouter } from "next/navigation";
18
+ import type { ReactElement } from "react";
19
+
20
+ import { saveContact } from "./contact-actions";
21
+
22
+ export function ContactDetails({
23
+ contact,
24
+ labels,
25
+ }: {
26
+ contact: AccountContact | null;
27
+ labels: AccountContactLabels;
28
+ }): ReactElement {
29
+ const router = useRouter();
30
+
31
+ async function onSave(
32
+ next: AccountContact,
33
+ ): Promise<AccountContactSaveResult> {
34
+ const result = await saveContact(next);
35
+ if (result.ok) router.refresh();
36
+ return result;
37
+ }
38
+
39
+ return (
40
+ <AccountContactDetails contact={contact} labels={labels} onSave={onSave} />
41
+ );
42
+ }
@@ -7,12 +7,25 @@
7
7
  * shape. Renders the shared
8
8
  * `AccountSettings` composition (@working-theory/templates/account, spec
9
9
  * 8339 D4) — the same General form the Admin renders — through the client
10
- * adapter `GeneralSettings` (`profile-form.tsx`). Below the form:
10
+ * adapter `GeneralSettings` (`profile-form.tsx`). Below the form, each a
11
+ * card of the pane (#11167 — the pane draws every direct child as one):
11
12
  *
12
- * - the contact details (`AccountContactDetails`, #8435 D13) — only on the
13
- * member path, seeded from `member.contact` and saved by `saveContact`;
13
+ * - the contact details (`ContactDetails` over `AccountContactDetails`,
14
+ * #8435 D13) — only on the member path, seeded from `member.contact` and
15
+ * saved by `saveContact`, which also derives the account name from the
16
+ * first and last names (#11167 ruling 5 — the member General renders no
17
+ * Name field);
18
+ * - the phone step (`PhoneVerification`, #11106 D9) — on a hub only: the
19
+ * person sets and verifies their own number, read from their Better Auth
20
+ * session; a build without the phone plugin shows the not-available line;
14
21
  * - any section a module contributes (`accountSettingsSections`);
15
- * - `BillingAnchor`, which forwards a `#billing` fragment to Billing.
22
+ * - `BillingAnchor`, which forwards a `#billing` fragment to Billing — it
23
+ * renders nothing, so it sits beside the composition, not in a card.
24
+ *
25
+ * Color mode renders on every site (#11167 ruling 3, as on the Admin); the
26
+ * one-palette gate of #7430 is gone. The Photo and the person's name come
27
+ * from `loadProfileSource` (D3) — on the member path the photo is the hub's
28
+ * (#11167 ruling 4).
16
29
  *
17
30
  * Sign-in moved to Security, cookie settings moved to Notifications then to
18
31
  * Privacy (#8339 C6), and Request account deletion moved to Privacy (#8438
@@ -24,23 +37,24 @@
24
37
 
25
38
  import { member } from "@working-theory/api-client";
26
39
  import {
27
- AccountContactDetails,
28
40
  AccountSettingsFrame,
29
41
  AccountSettingsPane,
30
42
  type AccountContact,
31
43
  } from "@working-theory/templates/account";
32
- import { Separator, Text } from "@working-theory/ui/primitives";
44
+ import { Text } from "@working-theory/ui/primitives";
33
45
  import type { Metadata } from "next";
46
+ import { headers } from "next/headers";
34
47
  import { getTranslations } from "next-intl/server";
35
48
  import type { ReactElement } from "react";
36
49
 
37
50
  import { accountSettingsSections } from "../../../../../lib/account-config";
51
+ import { readPhoneStep, TOPOLOGY } from "../../../../../lib/topology.generated";
38
52
  import { accountSession } from "../account-data";
39
- import { siteThemeModeCount } from "../settings/theme-modes";
40
53
  import { memberSettingsFrame, SettingsSection, type Translate } from "../settings-frame";
41
54
 
42
55
  import { BillingAnchor } from "./billing-anchor";
43
- import { saveContact } from "./contact-actions";
56
+ import { ContactDetails } from "./contact-details";
57
+ import { PhoneVerification, type PhoneVerificationLabels } from "./phone-verification";
44
58
  import { GeneralSettings } from "./profile-form";
45
59
  import { loadProfileSource } from "./profile-source";
46
60
 
@@ -77,6 +91,36 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
77
91
 
78
92
  const { ctx } = session;
79
93
  const source = await loadProfileSource(ctx);
94
+ // The phone step reads through the generated seam (#11138); a spoke's hub
95
+ // holds the person, so a spoke has none.
96
+ const phoneStep = TOPOLOGY === "spoke" ? null : await readPhoneStep(await headers());
97
+ const phoneLabels: PhoneVerificationLabels = {
98
+ title: t("profile.phoneTitle"),
99
+ lead: t("profile.phoneLead"),
100
+ number: t("profile.phoneNumber"),
101
+ numberHint: t("profile.phoneNumberHint"),
102
+ sendCode: t("profile.phoneSendCode"),
103
+ sending: t("profile.phoneSending"),
104
+ code: t("profile.phoneCode"),
105
+ codeHint: t("profile.phoneCodeHint"),
106
+ verify: t("profile.phoneVerify"),
107
+ verifying: t("profile.phoneVerifying"),
108
+ verified: t("profile.phoneVerified"),
109
+ remove: t("profile.phoneRemove"),
110
+ sent: t("profile.phoneSent"),
111
+ unavailable: t("profile.phoneUnavailable"),
112
+ unverifiedEmail: t("profile.phoneUnverifiedEmail"),
113
+ errors: {
114
+ invalid_number: t("profile.phoneErrors.invalid_number"),
115
+ invalid_code: t("profile.phoneErrors.invalid_code"),
116
+ taken: t("profile.phoneErrors.taken"),
117
+ too_many: t("profile.phoneErrors.too_many"),
118
+ unverified: t("profile.phoneErrors.unverified"),
119
+ signed_out: t("profile.phoneErrors.signed_out"),
120
+ unavailable: t("profile.phoneErrors.unavailable"),
121
+ failed: t("profile.phoneErrors.failed"),
122
+ },
123
+ };
80
124
 
81
125
  // #8435 D13 — the person's confirmed contact on this site. A failed read
82
126
  // renders the section's "unavailable" line, never the form: a form seeded
@@ -92,48 +136,40 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
92
136
  }
93
137
 
94
138
  return (
95
- <GeneralSettings
96
- frame={memberSettingsFrame(locale, t as unknown as Translate, "general")}
97
- user={{ name: ctx.user.name ?? "", email: ctx.user.email, image: source.image }}
98
- labels={{
99
- title: t("settings.general.title"),
100
- lead: t("settings.general.lead"),
101
- colorMode: t("settings.general.colorMode"),
102
- light: t("settings.general.light"),
103
- auto: t("settings.general.auto"),
104
- dark: t("settings.general.dark"),
105
- emailLabel: t("settings.general.email"),
106
- nameLabel: t("settings.general.name"),
107
- photoLabel: t("settings.general.photo"),
108
- photoHint: t("settings.general.photoHint"),
109
- photoPlaceholder: t("settings.general.photoPlaceholder"),
110
- saveButton: t("settings.general.save"),
111
- saving: t("settings.general.saving"),
112
- saved: t("settings.general.saved"),
113
- saveError: t("settings.general.saveError"),
114
- nameRequired: t("settings.general.nameRequired"),
115
- photoInvalid: t("settings.general.photoInvalid"),
116
- unverified: t("settings.general.unverified"),
117
- unavailable: t("settings.general.unavailable"),
118
- }}
119
- colorMode={
120
- siteThemeModeCount() > 1
121
- ? { cookieName: process.env.NEXT_PUBLIC_THEME_COOKIE_NAME ?? "ailk-theme" }
122
- : null
123
- }
124
- via={source.via}
125
- >
126
- {contactRead ? (
127
- <>
128
- <Separator />
139
+ <>
140
+ <GeneralSettings
141
+ frame={memberSettingsFrame(locale, t as unknown as Translate, "general")}
142
+ user={{ name: ctx.user.name ?? "", email: ctx.user.email, image: source.image }}
143
+ labels={{
144
+ title: t("settings.general.title"),
145
+ lead: t("settings.general.lead"),
146
+ colorMode: t("settings.general.colorMode"),
147
+ light: t("settings.general.light"),
148
+ auto: t("settings.general.auto"),
149
+ dark: t("settings.general.dark"),
150
+ emailLabel: t("settings.general.email"),
151
+ nameLabel: t("settings.general.name"),
152
+ photoLabel: t("settings.general.photo"),
153
+ photoPlaceholder: t("settings.general.photoPlaceholder"),
154
+ saveButton: t("settings.general.save"),
155
+ saving: t("settings.general.saving"),
156
+ saved: t("settings.general.saved"),
157
+ saveError: t("settings.general.saveError"),
158
+ nameRequired: t("settings.general.nameRequired"),
159
+ photoInvalid: t("settings.general.photoInvalid"),
160
+ unverified: t("settings.general.unverified"),
161
+ unavailable: t("settings.general.unavailable"),
162
+ }}
163
+ colorMode={{ cookieName: process.env.NEXT_PUBLIC_THEME_COOKIE_NAME ?? "ailk-theme" }}
164
+ via={source.via}
165
+ >
166
+ {contactRead ? (
129
167
  <div data-testid="account-contact-section">
130
168
  {contactRead.ok ? (
131
- <AccountContactDetails
169
+ <ContactDetails
132
170
  contact={contactRead.contact}
133
- onSave={saveContact}
134
171
  labels={{
135
172
  title: t("settings.general.contact.title"),
136
- lead: t("settings.general.contact.lead"),
137
173
  givenName: t("settings.general.contact.givenName"),
138
174
  familyName: t("settings.general.contact.familyName"),
139
175
  telephone: t("settings.general.contact.telephone"),
@@ -161,14 +197,22 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
161
197
  </span>
162
198
  )}
163
199
  </div>
164
- </>
165
- ) : null}
166
- {accountSettingsSections.map((section) => (
167
- <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
168
- {section.render(ctx)}
169
- </SettingsSection>
170
- ))}
200
+ ) : null}
201
+ {phoneStep ? (
202
+ <PhoneVerification
203
+ available={phoneStep.available}
204
+ emailVerified={ctx.user.emailVerified}
205
+ phone={phoneStep.phone}
206
+ labels={phoneLabels}
207
+ />
208
+ ) : null}
209
+ {accountSettingsSections.map((section) => (
210
+ <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
211
+ {section.render(ctx)}
212
+ </SettingsSection>
213
+ ))}
214
+ </GeneralSettings>
171
215
  <BillingAnchor locale={locale} />
172
- </GeneralSettings>
216
+ </>
173
217
  );
174
218
  }