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,122 @@
1
+ "use server";
2
+
3
+ /**
4
+ * general/phone-actions.ts — User settings › General's phone step (#11106,
5
+ * spec docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
6
+ *
7
+ * Three server actions over Better Auth's phone plugin, each a SERVER call
8
+ * with the request's own headers, so the plugin and its guard (`auth.ts`'s
9
+ * `phoneVerificationGuard`) see the person's session:
10
+ *
11
+ * - `sendPhoneCode` → `auth.api.sendPhoneNumberOTP` — texts a six-digit
12
+ * code through the apps/api relay;
13
+ * - `verifyPhoneCode` → `auth.api.verifyPhoneNumber({ updatePhoneNumber:
14
+ * true })` — the one writer of `phoneNumber` and `phoneNumberVerified`;
15
+ * - `removePhone` → `auth.api.updateUser({ phoneNumber: null })`, which
16
+ * the plugin turns into `phoneNumberVerified: false`.
17
+ *
18
+ * Each reaches the plugin through the generated seam's `loadPhoneApi`
19
+ * (`lib/topology.generated.ts`, #11138), never `auth.ts` directly, so a spoke
20
+ * that signs in through its hub keeps this file: there the seam answers null
21
+ * and every action answers `unavailable`.
22
+ *
23
+ * They take no identity argument: who comes from the session alone. Each
24
+ * answers `{ ok: true }` or a refusal `reason` the island maps to its own
25
+ * line. No log line, and no answer, carries the number or the code: a log
26
+ * line names the action and the plugin's error code only.
27
+ *
28
+ * Not a `*.actions.ts` file and no `*Action`-suffixed export: the phone step
29
+ * is a person's own act on the hub, with no MCP twin (apps/mcp's parity test
30
+ * reads that suffix).
31
+ */
32
+
33
+ import { headers } from "next/headers";
34
+
35
+ import { loadPhoneApi } from "../../../../../lib/topology.generated";
36
+
37
+ export type PhoneActionResult =
38
+ | { ok: true }
39
+ | {
40
+ ok: false;
41
+ reason:
42
+ | "invalid_number"
43
+ | "invalid_code"
44
+ | "taken"
45
+ | "too_many"
46
+ | "unverified"
47
+ | "signed_out"
48
+ | "unavailable"
49
+ | "failed";
50
+ };
51
+
52
+ /** The plugin's error code of a thrown `APIError`, when it has one. */
53
+ function errorCode(err: unknown): string | null {
54
+ const code = (err as { body?: { code?: unknown } } | null)?.body?.code;
55
+ return typeof code === "string" ? code : null;
56
+ }
57
+
58
+ const REASONS: Record<string, Exclude<PhoneActionResult, { ok: true }>["reason"]> = {
59
+ INVALID_PHONE_NUMBER: "invalid_number",
60
+ INVALID_OTP: "invalid_code",
61
+ OTP_EXPIRED: "invalid_code",
62
+ OTP_NOT_FOUND: "invalid_code",
63
+ TOO_MANY_ATTEMPTS: "too_many",
64
+ PHONE_NUMBER_EXIST: "taken",
65
+ EMAIL_NOT_VERIFIED: "unverified",
66
+ SESSION_REQUIRED: "signed_out",
67
+ };
68
+
69
+ function refused(action: string, err: unknown): PhoneActionResult {
70
+ const code = errorCode(err);
71
+ console.error(`[phone-actions] ${action} refused code=${code ?? "none"}`);
72
+ return { ok: false, reason: (code && REASONS[code]) || "failed" };
73
+ }
74
+
75
+ const isText = (value: unknown, max: number): value is string =>
76
+ typeof value === "string" && value.length > 0 && value.length <= max;
77
+
78
+ export async function sendPhoneCode(phoneNumber: unknown): Promise<PhoneActionResult> {
79
+ // Action input is untrusted: the plugin's validator is the real check.
80
+ if (!isText(phoneNumber, 16)) return { ok: false, reason: "invalid_number" };
81
+ // The generated seam: null on a spoke or a build without the step.
82
+ const api = await loadPhoneApi();
83
+ if (!api) return { ok: false, reason: "unavailable" };
84
+ try {
85
+ await api.sendPhoneNumberOTP({ body: { phoneNumber }, headers: await headers() });
86
+ return { ok: true };
87
+ } catch (err) {
88
+ return refused("sendPhoneCode", err);
89
+ }
90
+ }
91
+
92
+ export async function verifyPhoneCode(
93
+ phoneNumber: unknown,
94
+ code: unknown,
95
+ ): Promise<PhoneActionResult> {
96
+ if (!isText(phoneNumber, 16)) return { ok: false, reason: "invalid_number" };
97
+ if (!isText(code, 6)) return { ok: false, reason: "invalid_code" };
98
+ const api = await loadPhoneApi();
99
+ if (!api) return { ok: false, reason: "unavailable" };
100
+ try {
101
+ await api.verifyPhoneNumber({
102
+ body: { phoneNumber, code, updatePhoneNumber: true },
103
+ headers: await headers(),
104
+ });
105
+ return { ok: true };
106
+ } catch (err) {
107
+ return refused("verifyPhoneCode", err);
108
+ }
109
+ }
110
+
111
+ export async function removePhone(): Promise<PhoneActionResult> {
112
+ const api = await loadPhoneApi();
113
+ if (!api) return { ok: false, reason: "unavailable" };
114
+ try {
115
+ // The plugin's own clearing write (`phoneNumber: null` also sets
116
+ // `phoneNumberVerified: false`).
117
+ await api.updateUser({ body: { phoneNumber: null }, headers: await headers() });
118
+ return { ok: true };
119
+ } catch (err) {
120
+ return refused("removePhone", err);
121
+ }
122
+ }
@@ -0,0 +1,215 @@
1
+ "use client"; // owns the number and code fields and the three action calls
2
+
3
+ /**
4
+ * PhoneVerification — User settings › General's phone step (#11106, spec
5
+ * docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
6
+ *
7
+ * The one place a person sets their own phone. Two states:
8
+ *
9
+ * - no verified number: the number field and Send code; once a code is
10
+ * sent, the code field and Verify (`verifyPhoneCode`, which writes the
11
+ * number only after the code matches);
12
+ * - a verified number: the number with "Verified" and Remove.
13
+ *
14
+ * `available: false` (a build without the step) renders the not-available
15
+ * line, and an unverified email renders the confirm-email line, with no
16
+ * form. Every string arrives as a prop from the page's `account.profile.*`
17
+ * messages; the number and the code never leave this island except to the
18
+ * server actions, which log neither.
19
+ */
20
+
21
+ import {
22
+ Badge,
23
+ Button,
24
+ Field,
25
+ Heading,
26
+ InlineMessage,
27
+ Input,
28
+ Text,
29
+ } from "@working-theory/ui/primitives";
30
+ import { useRouter } from "next/navigation";
31
+ import { useState, useTransition, type FormEvent, type ReactElement } from "react";
32
+
33
+ import {
34
+ removePhone,
35
+ sendPhoneCode,
36
+ verifyPhoneCode,
37
+ type PhoneActionResult,
38
+ } from "./phone-actions";
39
+
40
+ export interface PhoneVerificationLabels {
41
+ title: string;
42
+ lead: string;
43
+ number: string;
44
+ numberHint: string;
45
+ sendCode: string;
46
+ sending: string;
47
+ code: string;
48
+ codeHint: string;
49
+ verify: string;
50
+ verifying: string;
51
+ verified: string;
52
+ remove: string;
53
+ sent: string;
54
+ unavailable: string;
55
+ unverifiedEmail: string;
56
+ errors: Record<Exclude<PhoneActionResult, { ok: true }>["reason"], string>;
57
+ }
58
+
59
+ export function PhoneVerification({
60
+ available,
61
+ emailVerified,
62
+ phone,
63
+ labels,
64
+ }: {
65
+ available: boolean;
66
+ emailVerified: boolean;
67
+ phone: { number: string; verified: boolean } | null;
68
+ labels: PhoneVerificationLabels;
69
+ }): ReactElement {
70
+ const router = useRouter();
71
+ const [number, setNumber] = useState("");
72
+ const [code, setCode] = useState("");
73
+ const [codeSent, setCodeSent] = useState(false);
74
+ const [error, setError] = useState<string | null>(null);
75
+ const [pending, startTransition] = useTransition();
76
+
77
+ const run = (action: () => Promise<PhoneActionResult>, onOk: () => void) => {
78
+ setError(null);
79
+ startTransition(async () => {
80
+ const result = await action();
81
+ if (result.ok) onOk();
82
+ else setError(labels.errors[result.reason]);
83
+ });
84
+ };
85
+
86
+ const onSend = (event: FormEvent<HTMLFormElement>) => {
87
+ event.preventDefault();
88
+ run(
89
+ () => sendPhoneCode(number.trim()),
90
+ () => setCodeSent(true),
91
+ );
92
+ };
93
+
94
+ const onVerify = (event: FormEvent<HTMLFormElement>) => {
95
+ event.preventDefault();
96
+ run(
97
+ () => verifyPhoneCode(number.trim(), code.trim()),
98
+ () => {
99
+ setCode("");
100
+ setCodeSent(false);
101
+ router.refresh();
102
+ },
103
+ );
104
+ };
105
+
106
+ const onRemove = () => run(removePhone, () => router.refresh());
107
+
108
+ let body: ReactElement;
109
+ if (!available) {
110
+ body = (
111
+ <Text as="p" variant="body-sm" tone="muted" data-testid="account-phone-unavailable">
112
+ {labels.unavailable}
113
+ </Text>
114
+ );
115
+ } else if (phone?.verified) {
116
+ body = (
117
+ <div className="flex flex-wrap items-center gap-3" data-testid="account-phone-verified">
118
+ <Text as="span" variant="body" data-testid="account-phone-number">
119
+ {phone.number}
120
+ </Text>
121
+ <Badge data-testid="account-phone-verified-badge">{labels.verified}</Badge>
122
+ <Button
123
+ type="button"
124
+ variant="ghost"
125
+ size="big"
126
+ disabled={pending}
127
+ onClick={onRemove}
128
+ data-testid="account-phone-remove"
129
+ >
130
+ {labels.remove}
131
+ </Button>
132
+ </div>
133
+ );
134
+ } else if (!emailVerified) {
135
+ body = (
136
+ <Text as="p" variant="body-sm" tone="muted" data-testid="account-phone-unverified-email">
137
+ {labels.unverifiedEmail}
138
+ </Text>
139
+ );
140
+ } else {
141
+ body = (
142
+ <div className="flex flex-col gap-4">
143
+ <form onSubmit={onSend} className="flex flex-col gap-3" data-testid="account-phone-send-form">
144
+ <Field label={labels.number} htmlFor="account-phone-number-input" helperText={labels.numberHint}>
145
+ <Input
146
+ type="tel"
147
+ size="big"
148
+ inputMode="tel"
149
+ autoComplete="tel"
150
+ value={number}
151
+ onChange={(e) => setNumber(e.target.value)}
152
+ required
153
+ data-testid="account-phone-number-input"
154
+ />
155
+ </Field>
156
+ <Button
157
+ type="submit"
158
+ variant="secondary"
159
+ size="big"
160
+ disabled={pending || number.trim() === ""}
161
+ data-testid="account-phone-send"
162
+ >
163
+ {pending && !codeSent ? labels.sending : labels.sendCode}
164
+ </Button>
165
+ </form>
166
+ {codeSent ? (
167
+ <form onSubmit={onVerify} className="flex flex-col gap-3" data-testid="account-phone-verify-form">
168
+ <InlineMessage variant="success" role="status" data-testid="account-phone-sent">
169
+ {labels.sent}
170
+ </InlineMessage>
171
+ <Field label={labels.code} htmlFor="account-phone-code-input" helperText={labels.codeHint}>
172
+ <Input
173
+ type="text"
174
+ size="big"
175
+ inputMode="numeric"
176
+ autoComplete="one-time-code"
177
+ maxLength={6}
178
+ value={code}
179
+ onChange={(e) => setCode(e.target.value)}
180
+ required
181
+ data-testid="account-phone-code-input"
182
+ />
183
+ </Field>
184
+ <Button
185
+ type="submit"
186
+ size="big"
187
+ disabled={pending || code.trim() === ""}
188
+ data-testid="account-phone-verify"
189
+ >
190
+ {pending ? labels.verifying : labels.verify}
191
+ </Button>
192
+ </form>
193
+ ) : null}
194
+ </div>
195
+ );
196
+ }
197
+
198
+ return (
199
+ <section className="flex flex-col gap-3" data-testid="account-phone-section" aria-labelledby="account-phone-title">
200
+ {/* A level-2 heading: one group of the pane, beside Contact details (#11167 ruling 11). */}
201
+ <Heading level={2} visual={4} id="account-phone-title">
202
+ {labels.title}
203
+ </Heading>
204
+ <Text as="p" variant="body-sm" tone="muted">
205
+ {labels.lead}
206
+ </Text>
207
+ {body}
208
+ {error ? (
209
+ <InlineMessage variant="error" role="alert" data-testid="account-phone-error">
210
+ {error}
211
+ </InlineMessage>
212
+ ) : null}
213
+ </section>
214
+ );
215
+ }
@@ -0,0 +1,73 @@
1
+ "use server";
2
+
3
+ /**
4
+ * general/photo-actions.ts — User settings › General's photo write on the
5
+ * member path (#11167 ruling 5).
6
+ *
7
+ * The member General renders no Name field: the account name follows the
8
+ * contact's first and last names (`contact-actions.ts`), so the profile form
9
+ * saves the photo alone — `member.updateProfile({ image })`, `PATCH
10
+ * /v1/member/profile` with no `name` key, so a person who has not set a name
11
+ * yet can still set their photo. `null` (or a blank link) clears it. The
12
+ * session is not re-sealed: a hub session carries no photo (`profile-source.ts`
13
+ * reads it from the member API instead).
14
+ *
15
+ * It sends `forwardedCookieInit()`'s init, as `profile-actions.ts`'s
16
+ * `saveProfile` does, and maps the same refusals: `photo` (`400
17
+ * link_not_https`), `unverified` (`403`), `unavailable` (`404`, `503`), else
18
+ * `failed`. Logs carry a status or `err.name` only — never a link.
19
+ *
20
+ * Not a `*.actions.ts` file and no `*Action`-suffixed export: the write has no
21
+ * MCP twin by decision (8170's header), and apps/mcp's parity test reads that
22
+ * suffix.
23
+ */
24
+
25
+ import { member } from "@working-theory/api-client";
26
+
27
+ import { forwardedCookieInit } from "../../../../../lib/server-api";
28
+
29
+ /** PII-safe error identity for logs (the `profile-actions.ts` idiom: `err.name` only). */
30
+ function errorName(err: unknown): string {
31
+ return err instanceof Error ? err.name : "unknown";
32
+ }
33
+
34
+ /** The `error.code` of a member write's refusal body, when it has one. */
35
+ function errorCode(body: unknown): string | null {
36
+ if (typeof body !== "object" || body === null) return null;
37
+ const error = (body as { error?: unknown }).error;
38
+ if (typeof error !== "object" || error === null) return null;
39
+ const code = (error as { code?: unknown }).code;
40
+ return typeof code === "string" ? code : null;
41
+ }
42
+
43
+ export type SavePhotoResult =
44
+ | { ok: true; image: string | null }
45
+ | { ok: false; reason: "photo" | "unverified" | "unavailable" | "failed" };
46
+
47
+ /** Saves the member's photo alone: `null` or a blank link clears it. */
48
+ export async function savePhoto(
49
+ image: string | null,
50
+ ): Promise<SavePhotoResult> {
51
+ // Action input is untrusted: anything but a string or null is refused,
52
+ // never read as "clear the photo".
53
+ if (image !== null && typeof image !== "string")
54
+ return { ok: false, reason: "photo" };
55
+ try {
56
+ const res = await member.updateProfile(
57
+ { image: image?.trim() || null },
58
+ await forwardedCookieInit(),
59
+ );
60
+ if (res.ok) return { ok: true, image: res.body.image };
61
+ console.error(`[photo-actions] savePhoto status=${res.status}`);
62
+ if (res.status === 400 && errorCode(res.body) === "link_not_https") {
63
+ return { ok: false, reason: "photo" };
64
+ }
65
+ if (res.status === 403) return { ok: false, reason: "unverified" };
66
+ if (res.status === 404 || res.status === 503)
67
+ return { ok: false, reason: "unavailable" };
68
+ return { ok: false, reason: "failed" };
69
+ } catch (err) {
70
+ console.error(`[photo-actions] savePhoto errName=${errorName(err)}`);
71
+ return { ok: false, reason: "failed" };
72
+ }
73
+ }
@@ -10,9 +10,10 @@
10
10
  * this file supplies `profile` and `onSave` from `via` (General's
11
11
  * `loadProfileSource`, D3):
12
12
  *
13
- * - `member` — `saveProfile` (`PATCH /v1/member/profile`, D6). `image` is
14
- * sent only when the photo field changed (an untouched field never
15
- * clears a photo, 8232 D4/D6); a refusal keeps both fields as typed.
13
+ * - `member` — no Name field (#11167 ruling 5: the account name follows
14
+ * the contact's first and last names, `contact-actions.ts`), so the form
15
+ * saves the photo alone through `savePhoto` (`PATCH /v1/member/profile`
16
+ * with `image` only); a refusal keeps the field as typed.
16
17
  * - `session` — a build with no member API: the name saves through
17
18
  * Better Auth's own `updateUser`, and no photo field shows
18
19
  * (`profile="name-only"`).
@@ -33,7 +34,7 @@ import { createAuthClient } from "better-auth/react";
33
34
  import { useRouter } from "next/navigation";
34
35
  import type { ReactElement, ReactNode } from "react";
35
36
 
36
- import { saveProfile } from "../profile-actions";
37
+ import { savePhoto } from "./photo-actions";
37
38
 
38
39
  const authClient = createAuthClient();
39
40
 
@@ -75,18 +76,19 @@ export function GeneralSettings({
75
76
  router.refresh();
76
77
  return { ok: true };
77
78
  }
78
- const res = await saveProfile(imageChanged ? { name, image } : { name });
79
+ // The member path saves the photo alone; `name` is the account's as it
80
+ // stands and never written here. Only a changed photo reaches here (Save
81
+ // is disabled otherwise), so the untouched-field rule (8232 D4/D6) holds.
82
+ if (!imageChanged) return { ok: true };
83
+ const res = await savePhoto(image);
79
84
  if (!res.ok) {
80
85
  if (res.reason === "photo") return { ok: false, field: "photo", message: labels.photoInvalid };
81
- if (res.reason === "required") return { ok: false, field: "name", message: labels.nameRequired };
82
86
  if (res.reason === "unverified") return { ok: false, message: labels.unverified };
83
87
  if (res.reason === "unavailable") return { ok: false, message: labels.unavailable };
84
88
  return { ok: false, message: labels.saveError };
85
89
  }
86
90
  router.refresh();
87
- // exactOptionalPropertyTypes: omit `name` entirely rather than set it to
88
- // `undefined` — AccountSaveResult's `name?: string` has no `undefined` value.
89
- return { ok: true, image: res.image, ...(res.name !== null ? { name: res.name } : {}) };
91
+ return { ok: true, image: res.image };
90
92
  }
91
93
 
92
94
  return (
@@ -96,6 +98,7 @@ export function GeneralSettings({
96
98
  labels={labels}
97
99
  colorMode={colorMode}
98
100
  profile={via === "member" ? "editable" : via === "session" ? "name-only" : "read-only"}
101
+ nameField={via !== "member"}
99
102
  {...(via === "none" ? {} : { onSave })}
100
103
  >
101
104
  {children}
@@ -23,9 +23,12 @@
23
23
  * A 404 is a module-presence test, as `read()` in `lib/account-config.ts`
24
24
  * already makes; this file names no topology constant itself.
25
25
  *
26
- * `image` — the session's photo, which Better Auth's session carries at run
27
- * time though the generated `SiteSession` type does not declare it. A hub
28
- * session carries none (C5), so on a spoke the form starts empty.
26
+ * `image` — on the `member` path, the photo the member API holds for the
27
+ * caller's own row (`GET /v1/member/profile`, #11167): a spoke's hub session
28
+ * carries no photo, and this is how the Admin's Google photo reaches the
29
+ * spoke's General. A failed or refused read falls back to the session's photo,
30
+ * which Better Auth's session carries at run time though the generated
31
+ * `SiteSession` type does not declare it (a hub session carries none, C5).
29
32
  */
30
33
 
31
34
  import { member } from "@working-theory/api-client";
@@ -59,6 +62,16 @@ async function memberApiAnswers(ctx: AccountContext): Promise<boolean> {
59
62
  }
60
63
  }
61
64
 
65
+ /** The caller's stored photo, or `null` when the read fails or holds none. */
66
+ async function memberImage(ctx: AccountContext): Promise<string | null> {
67
+ try {
68
+ const res = await member.profile(ctx.init);
69
+ return res.ok ? res.body.image?.trim() || null : null;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+
62
75
  export const loadProfileSource = cache(async (ctx: AccountContext): Promise<ProfileSource> => {
63
76
  // The photo is optional: a failed session read starts the field empty
64
77
  // rather than failing the page.
@@ -69,5 +82,6 @@ export const loadProfileSource = cache(async (ctx: AccountContext): Promise<Prof
69
82
  .catch(() => null),
70
83
  ]);
71
84
  const via = answers ? "member" : signInMethod().kind === "site" ? "session" : "none";
72
- return { via, image: sessionImage(session) };
85
+ const image = (via === "member" ? await memberImage(ctx) : null) ?? sessionImage(session);
86
+ return { via, image };
73
87
  });
@@ -12,6 +12,9 @@
12
12
  * #11007 — a conversation kind (`accountChatKinds`: a message) renders
13
13
  * through the frame's chat layout — RecordHeader over the message as a
14
14
  * start-side bubble; every other kind keeps the stacked head and fields.
15
+ * #11152 — such a kind's item also links to the member thread page
16
+ * (`../../thread`, Open conversation), first among its actions: the whole
17
+ * exchange, with the composer, is one step away from any one message.
15
18
  *
16
19
  * An unknown kind, or an id the kind did not load, is a not-found — never an
17
20
  * empty frame. A failed read is not a not-found: it renders an error with
@@ -82,6 +85,21 @@ export default async function AccountInboxItemPage({ params }: Props): Promise<R
82
85
  if (!item) notFound();
83
86
 
84
87
  const detail = kind.renderDetail(item, session.ctx);
88
+ const chat = accountChatKinds.has(kind.kind);
89
+ // #11152 — a conversation kind's item opens the thread; the kind's own actions follow.
90
+ const actions = [
91
+ ...(chat
92
+ ? [
93
+ {
94
+ key: "thread",
95
+ label: t("thread.open"),
96
+ variant: "outline" as const,
97
+ href: localeHref(locale, "/account/inbox/thread"),
98
+ },
99
+ ]
100
+ : []),
101
+ ...(detail.actions ?? []),
102
+ ];
85
103
 
86
104
  return (
87
105
  <InboxItemFrame
@@ -90,9 +108,9 @@ export default async function AccountInboxItemPage({ params }: Props): Promise<R
90
108
  title={item.title}
91
109
  lead={detail.lead}
92
110
  status={detail.status}
93
- {...(detail.actions ? { actions: detail.actions } : {})}
111
+ {...(actions.length > 0 ? { actions } : {})}
94
112
  fields={detail.fields}
95
- {...(accountChatKinds.has(kind.kind) ? { layout: "chat" as const } : {})}
113
+ {...(chat ? { layout: "chat" as const } : {})}
96
114
  testIdPrefix="account-item"
97
115
  >
98
116
  {detail.body}
@@ -0,0 +1,43 @@
1
+ "use client"; // binds the shared composer to the member write and the route refresh
2
+
3
+ /**
4
+ * MemberThreadComposer — the member thread page's composer (#11152): the
5
+ * shared `ThreadComposer` (`@working-theory/templates/account`, the control
6
+ * the Admin's inbox thread shares) bound to `postThreadMessage` and to the
7
+ * router. A sent message refreshes the route, so the page's Server
8
+ * Components read the thread again and the new bubble appears with no
9
+ * reload (the New menu's own idiom after a post); a refusal shows the plain
10
+ * line its code maps to, with the body kept. Only strings cross to the
11
+ * client: the labels and the refusal lines, never the session.
12
+ */
13
+
14
+ import { ThreadComposer, type ThreadComposerLabels } from "@working-theory/templates/account";
15
+ import { MESSAGE_BODY_MAX } from "@working-theory/validation";
16
+ import { useRouter } from "next/navigation";
17
+ import type { ReactElement } from "react";
18
+
19
+ import type { NewActionErrorCode } from "../../new-actions";
20
+
21
+ import { postThreadMessage } from "./thread-write";
22
+
23
+ export interface MemberThreadComposerProps {
24
+ labels: ThreadComposerLabels;
25
+ /** Each refusal code's plain line (`new.errors.*`). */
26
+ errors: Record<NewActionErrorCode, string>;
27
+ }
28
+
29
+ export function MemberThreadComposer({ labels, errors }: MemberThreadComposerProps): ReactElement {
30
+ const router = useRouter();
31
+ return (
32
+ <ThreadComposer
33
+ labels={labels}
34
+ maxLength={MESSAGE_BODY_MAX}
35
+ send={async (body) => {
36
+ const state = await postThreadMessage(body);
37
+ if (state.kind === "success") return { kind: "sent" };
38
+ return { kind: "refused", message: errors[state.kind === "error" ? state.code : "failed"] };
39
+ }}
40
+ onSent={() => router.refresh()}
41
+ />
42
+ );
43
+ }