create-ailk 0.36.0 → 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 (94) hide show
  1. package/component-catalog.json +40 -1
  2. package/component-catalog.md +7 -5
  3. package/dist/surfaces.js +60 -19
  4. package/dist/update.d.ts +19 -1
  5. package/dist/update.js +293 -35
  6. package/package.json +3 -3
  7. package/templates/.env.example +17 -0
  8. package/templates/apps/api/.env.example +38 -0
  9. package/templates/apps/api/CLAUDE.md +3 -0
  10. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  11. package/templates/apps/mcp/CLAUDE.md +1 -1
  12. package/templates/apps/web/CLAUDE.md +28 -1
  13. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  14. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  15. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  16. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  17. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  18. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  19. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  20. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  21. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  22. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  30. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  31. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  32. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  33. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  34. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  36. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  38. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  39. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  40. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  41. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  42. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  43. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  45. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  46. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  47. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  48. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  50. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  52. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  53. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  54. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  59. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  60. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  62. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  63. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  64. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  65. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  66. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  68. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  69. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  70. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  71. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  72. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  73. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  74. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  75. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  76. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  77. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  78. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  79. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  80. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  81. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  82. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  83. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  84. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  85. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  86. package/templates/apps/web/lib/account-config.ts +132 -8
  87. package/templates/apps/web/lib/auth-routes.ts +11 -6
  88. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  89. package/templates/apps/web/messages/en.json +156 -80
  90. package/versions.json +48 -48
  91. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  92. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  93. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  94. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -365,9 +365,6 @@ describe("AC-3 — a site that cannot email a password link shows one sentence",
365
365
  magicLink: "a link sent to {email}",
366
366
  password: "your email and password",
367
367
  },
368
- managedAt: "Your sign-in is managed at {hub}.",
369
- managedUnnamed: "Your sign-in is managed by our main site.",
370
- manageOnHub: "Manage sign-in on {hub}",
371
368
  passwordUnavailable: "We couldn't check your password settings.",
372
369
  });
373
370
  });
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Tests for /[locale]/account/inbox/thread — the member's one conversation
3
+ * with the workspace (#11152).
4
+ *
5
+ * Covers:
6
+ * 1. The page lists every message between the signed-in person and the
7
+ * workspace — the provider's messages (`member.messages`, start side)
8
+ * and the person's own sent requests and messages (`member.requests`,
9
+ * end side) — oldest first, under a RecordHeader titled Messages whose
10
+ * back link returns to the Inbox's Messages tab, with the composer at
11
+ * the foot of the conversation.
12
+ * 2. An empty thread reads the empty line; a failed read shows the error
13
+ * row with Retry above what did load (D12's posture); signed out is a
14
+ * not-found.
15
+ * 3. A message's own actions (a file's Download) render under its bubble.
16
+ * 4. Posting from the composer runs the existing member message write
17
+ * (`sendMessage` → `member.sendMessage`) with the body as typed and a
18
+ * subject cut from its first line; a success clears the field and
19
+ * refreshes the route, whose next render lists the sent message — no
20
+ * reload; a refusal shows its plain message and keeps the body.
21
+ * 5. `threadSubject` — the first non-blank line, whitespace collapsed,
22
+ * clipped to the subject's cap.
23
+ */
24
+ import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
25
+
26
+ jest.mock("next-intl/server", () => {
27
+ const msgs: unknown = require("../../../../../messages/en.json");
28
+ const dig = (obj: unknown, path: string): unknown =>
29
+ path.split(".").reduce<unknown>(
30
+ (acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
31
+ obj,
32
+ );
33
+ return {
34
+ __esModule: true,
35
+ getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
36
+ const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
37
+ const messages = dig(msgs, ns);
38
+ return (key: string, values?: Record<string, unknown>): string => {
39
+ const value = dig(messages, key);
40
+ if (typeof value !== "string") return `${ns}.${key}`;
41
+ return value.replace(/\{(\w+)\}/g, (m, name: string) =>
42
+ values && name in values ? String(values[name]) : m,
43
+ );
44
+ };
45
+ },
46
+ };
47
+ });
48
+
49
+ jest.mock("next/headers", () => ({
50
+ __esModule: true,
51
+ headers: jest.fn().mockResolvedValue(new Headers()),
52
+ cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
53
+ }));
54
+
55
+ const mockGetSession = jest.fn();
56
+ // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test of the session fields can mock without standing up Prisma.
57
+ jest.mock("../../../../../auth", () => ({
58
+ __esModule: true,
59
+ auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
60
+ }));
61
+
62
+ const mockMemberMessages = jest.fn();
63
+ const mockMemberRequests = jest.fn();
64
+ const mockMemberSendMessage = jest.fn();
65
+ jest.mock("@working-theory/api-client", () => ({
66
+ __esModule: true,
67
+ waitlistSignups: { me: jest.fn() },
68
+ subscription: { me: jest.fn() },
69
+ member: {
70
+ messages: (...args: unknown[]) => mockMemberMessages(...args),
71
+ requests: (...args: unknown[]) => mockMemberRequests(...args),
72
+ sendMessage: (...args: unknown[]) => mockMemberSendMessage(...args),
73
+ },
74
+ }));
75
+
76
+ const mockNotFound = jest.fn(() => {
77
+ throw new Error("NEXT_NOT_FOUND");
78
+ });
79
+ const mockRefresh = jest.fn();
80
+ jest.mock("next/navigation", () => ({
81
+ __esModule: true,
82
+ notFound: () => mockNotFound(),
83
+ useRouter: () => ({ push: jest.fn(), refresh: mockRefresh }),
84
+ usePathname: () => "/account/inbox/thread",
85
+ }));
86
+
87
+ import { MESSAGE_SUBJECT_MAX } from "@working-theory/validation";
88
+
89
+ import Page from "../inbox/thread/page";
90
+ import { threadSubject } from "../inbox/thread/thread-data";
91
+
92
+ const SESSION = {
93
+ user: { id: "user_1", name: "Ada", email: "ada@example.com", emailVerified: true },
94
+ };
95
+
96
+ /** The cookie a single site forwards (`forwardedCookieInit()`). */
97
+ const INIT = { headers: { cookie: "session=abc" } };
98
+
99
+ const ok = <T,>(body: T) => ({ ok: true, body });
100
+ const refusal = (status: number, code: string) => ({
101
+ ok: false,
102
+ status,
103
+ body: { ok: false, error: { code, message: "x" } },
104
+ });
105
+
106
+ /** The provider's messages to the member, newest first as the read serves them. */
107
+ const MESSAGES = [
108
+ {
109
+ id: "int_file",
110
+ subject: "Your plan",
111
+ body: "The plan is attached.",
112
+ file: { filename: "plan.pdf", contentType: "application/pdf" },
113
+ action: null,
114
+ createdAt: "2026-10-12T09:00:00.000Z",
115
+ readAt: null,
116
+ },
117
+ {
118
+ id: "int_1",
119
+ subject: "Welcome",
120
+ body: "Thanks for reaching out.",
121
+ file: null,
122
+ action: null,
123
+ createdAt: "2026-10-10T09:00:00.000Z",
124
+ readAt: null,
125
+ },
126
+ ];
127
+
128
+ /** The member's own sent rows, newest first as the read serves them. */
129
+ const REQUESTS = [
130
+ {
131
+ id: "intx_a",
132
+ kind: "message" as const,
133
+ subject: "Hello",
134
+ body: "Hi there",
135
+ createdAt: "2026-10-11T10:00:00.000Z",
136
+ },
137
+ {
138
+ id: "intx_q",
139
+ kind: "quote" as const,
140
+ subject: "Request quote",
141
+ body: "",
142
+ createdAt: "2026-10-09T10:00:00.000Z",
143
+ },
144
+ ];
145
+
146
+ const RECEIPT = ok({ id: "intx_new", createdAt: "2026-10-13T10:00:00.000Z" });
147
+
148
+ beforeEach(() => {
149
+ mockGetSession.mockReset().mockResolvedValue(SESSION);
150
+ mockMemberMessages.mockReset().mockResolvedValue(ok({ items: MESSAGES }));
151
+ mockMemberRequests.mockReset().mockResolvedValue(ok({ items: REQUESTS }));
152
+ mockMemberSendMessage.mockReset().mockResolvedValue(RECEIPT);
153
+ mockNotFound.mockClear();
154
+ mockRefresh.mockReset();
155
+ });
156
+
157
+ async function renderThread(locale = "en"): Promise<ReturnType<typeof render>> {
158
+ const element = await Page({ params: Promise.resolve({ locale }) });
159
+ return render(element);
160
+ }
161
+
162
+ function entries(): HTMLElement[] {
163
+ return screen.getAllByTestId("account-thread-entry");
164
+ }
165
+
166
+ describe("the member thread page lists the whole conversation (AC-2)", () => {
167
+ it("renders both sides oldest first under a Messages header, the composer at the foot", async () => {
168
+ await renderThread();
169
+ const frame = screen.getByTestId("account-thread");
170
+ const header = within(frame).getByTestId("account-thread-header");
171
+ expect(within(header).getByRole("heading", { level: 1 })).toHaveTextContent("Messages");
172
+ const back = within(header).getByTestId("account-thread-back");
173
+ expect(back).toHaveAttribute("href", "/account?tab=messages");
174
+ expect(back).toHaveAccessibleName("Inbox");
175
+
176
+ expect(mockMemberMessages).toHaveBeenCalledWith(INIT);
177
+ expect(mockMemberRequests).toHaveBeenCalledWith(INIT);
178
+
179
+ // Oldest first: the quote request, Welcome, Hello, Your plan.
180
+ const rows = entries();
181
+ expect(rows.map((row) => row.getAttribute("data-kind"))).toEqual([
182
+ "request",
183
+ "message",
184
+ "request",
185
+ "message",
186
+ ]);
187
+ expect(rows[0]).toHaveTextContent("Your quote request was sent.");
188
+ expect(rows[1]).toHaveTextContent("Thanks for reaching out.");
189
+ expect(rows[2]).toHaveTextContent("Hi there");
190
+ expect(rows[3]).toHaveTextContent("The plan is attached.");
191
+ // The provider's messages sit on the start side, the member's own on the end.
192
+ expect(within(rows[1]!).getByTestId("account-item-message")).toHaveAttribute("data-side", "start");
193
+ expect(within(rows[2]!).getByTestId("account-item-request")).toHaveAttribute("data-side", "end");
194
+
195
+ // The composer is pinned after the conversation.
196
+ const conversation = within(frame).getByTestId("account-thread-conversation");
197
+ const composer = within(frame).getByTestId("account-thread-composer");
198
+ expect(
199
+ conversation.compareDocumentPosition(composer) & Node.DOCUMENT_POSITION_FOLLOWING,
200
+ ).toBeTruthy();
201
+ expect(within(composer).getByRole("form", { name: "Send a message" })).toBeInTheDocument();
202
+ expect(screen.queryByTestId("account-thread-empty")).not.toBeInTheDocument();
203
+ });
204
+
205
+ it("a message's own actions render under its bubble — the file's Download", async () => {
206
+ await renderThread();
207
+ const row = entries()[3]!;
208
+ const download = within(row).getByRole("link", { name: "Download plan.pdf" });
209
+ expect(download).toHaveAttribute("href", "/account/inbox/message/int_file/file");
210
+ // The provider's plain message carries none.
211
+ expect(within(entries()[1]!).queryByRole("link")).not.toBeInTheDocument();
212
+ });
213
+
214
+ it("a non-default locale's back link returns to that locale's Inbox", async () => {
215
+ await renderThread("fr");
216
+ expect(screen.getByTestId("account-thread-back")).toHaveAttribute("href", "/fr/account?tab=messages");
217
+ });
218
+
219
+ it("an empty thread reads the empty line and still offers the composer", async () => {
220
+ mockMemberMessages.mockResolvedValue(ok({ items: [] }));
221
+ mockMemberRequests.mockResolvedValue(ok({ items: [] }));
222
+ await renderThread();
223
+ expect(screen.getByTestId("account-thread-empty")).toHaveTextContent("No messages yet.");
224
+ expect(screen.queryAllByTestId("account-thread-entry")).toEqual([]);
225
+ expect(screen.getByTestId("thread-composer")).toBeInTheDocument();
226
+ });
227
+
228
+ it("a 404 from a read is nothing for this caller, not an error", async () => {
229
+ mockMemberRequests.mockResolvedValue({ ok: false, status: 404, body: {} });
230
+ await renderThread();
231
+ expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
232
+ expect(entries().map((row) => row.getAttribute("data-kind"))).toEqual(["message", "message"]);
233
+ });
234
+
235
+ it("a failed read shows the error row with Retry above what did load (D12)", async () => {
236
+ mockMemberMessages.mockResolvedValue({ ok: false, status: 500, body: {} });
237
+ await renderThread();
238
+ expect(mockNotFound).not.toHaveBeenCalled();
239
+ const error = screen.getByTestId("inbox-error");
240
+ expect(error).toHaveTextContent("We couldn't load this conversation.");
241
+ expect(entries().map((row) => row.getAttribute("data-kind"))).toEqual(["request", "request"]);
242
+ expect(screen.queryByTestId("account-thread-empty")).not.toBeInTheDocument();
243
+ fireEvent.click(screen.getByTestId("inbox-retry"));
244
+ expect(mockRefresh).toHaveBeenCalledTimes(1);
245
+ });
246
+
247
+ it("signed out is a not-found and reads nothing", async () => {
248
+ mockGetSession.mockResolvedValue(null);
249
+ await expect(renderThread()).rejects.toThrow("NEXT_NOT_FOUND");
250
+ expect(mockMemberMessages).not.toHaveBeenCalled();
251
+ });
252
+ });
253
+
254
+ describe("posting from the composer uses the existing member message write (AC-3)", () => {
255
+ function type(value: string): HTMLTextAreaElement {
256
+ const field = screen.getByLabelText("Message") as HTMLTextAreaElement;
257
+ fireEvent.change(field, { target: { value } });
258
+ return field;
259
+ }
260
+
261
+ it("posts the body as typed with its first line as the subject, clears the field and refreshes the route", async () => {
262
+ await renderThread();
263
+ const field = type("Can we move the call?\nThursday works.");
264
+ fireEvent.click(screen.getByTestId("thread-composer-send"));
265
+ await waitFor(() => expect(mockMemberSendMessage).toHaveBeenCalledTimes(1));
266
+ expect(mockMemberSendMessage).toHaveBeenCalledWith(
267
+ { subject: "Can we move the call?", body: "Can we move the call?\nThursday works." },
268
+ INIT,
269
+ );
270
+ await waitFor(() => expect(field).toHaveValue(""));
271
+ expect(screen.getByTestId("thread-composer-notice")).toHaveTextContent("Sent.");
272
+ expect(mockRefresh).toHaveBeenCalledTimes(1);
273
+ });
274
+
275
+ it("the refreshed render lists the sent message as the member's own newest bubble — no reload", async () => {
276
+ const { unmount } = await renderThread();
277
+ type("Can we move the call?");
278
+ fireEvent.click(screen.getByTestId("thread-composer-send"));
279
+ await waitFor(() => expect(mockRefresh).toHaveBeenCalledTimes(1));
280
+ unmount();
281
+ // `router.refresh()` re-renders the route's Server Components: the
282
+ // requests read now serves the row the write created.
283
+ mockMemberRequests.mockResolvedValue(
284
+ ok({
285
+ items: [
286
+ {
287
+ id: "intx_new",
288
+ kind: "message" as const,
289
+ subject: "Can we move the call?",
290
+ body: "Can we move the call?",
291
+ createdAt: "2026-10-13T10:00:00.000Z",
292
+ },
293
+ ...REQUESTS,
294
+ ],
295
+ }),
296
+ );
297
+ await renderThread();
298
+ const rows = entries();
299
+ const last = rows[rows.length - 1]!;
300
+ expect(last).toHaveAttribute("data-kind", "request");
301
+ expect(last).toHaveTextContent("Can we move the call?");
302
+ expect(within(last).getByTestId("account-item-request")).toHaveAttribute("data-side", "end");
303
+ });
304
+
305
+ it("a refusal shows its plain message, keeps the body and refreshes nothing", async () => {
306
+ mockMemberSendMessage.mockResolvedValue(refusal(429, "too_many_requests"));
307
+ await renderThread();
308
+ const field = type("Hello again");
309
+ fireEvent.click(screen.getByTestId("thread-composer-send"));
310
+ const notice = await screen.findByTestId("thread-composer-notice");
311
+ expect(notice).toHaveTextContent("Too many requests. Try again later.");
312
+ expect(field).toHaveValue("Hello again");
313
+ expect(mockRefresh).not.toHaveBeenCalled();
314
+ });
315
+
316
+ it("an unlisted refusal code reads the generic line", async () => {
317
+ mockMemberSendMessage.mockResolvedValue(refusal(503, "tenant_unresolved"));
318
+ await renderThread();
319
+ type("Hello again");
320
+ fireEvent.click(screen.getByTestId("thread-composer-send"));
321
+ expect(await screen.findByText("This could not be sent. Try again.")).toBeInTheDocument();
322
+ });
323
+ });
324
+
325
+ describe("threadSubject — the subject cut from the body", () => {
326
+ it("is the first non-blank line, its whitespace collapsed", () => {
327
+ expect(threadSubject(" \n Can we move the call? \nThursday works.")).toBe(
328
+ "Can we move the call?",
329
+ );
330
+ });
331
+
332
+ it("is clipped to the subject's cap", () => {
333
+ const long = "x".repeat(MESSAGE_SUBJECT_MAX + 20);
334
+ expect(threadSubject(long)).toHaveLength(MESSAGE_SUBJECT_MAX);
335
+ });
336
+
337
+ it("is empty for a blank body — the server's own rule refuses it", () => {
338
+ expect(threadSubject(" \n ")).toBe("");
339
+ });
340
+ });
@@ -14,7 +14,8 @@
14
14
  * an error row with Retry, never a silently partial or empty list).
15
15
  * - `loadForYou(locale)` — every For-you source's items plus the area's own
16
16
  * "Add your name" item (an accepted applicant arrives with no name,
17
- * #7418), with the same `failed` flag.
17
+ * #7418) — unless the `onboarding-steps` source already asks for the
18
+ * name (#11150) — with the same `failed` flag.
18
19
  *
19
20
  * `cache()` dedupes the reads within one request: the layout's aside and the
20
21
  * Inbox's phone For you tab render the same items from one set of API calls.
@@ -168,11 +169,12 @@ export const loadForYou = cache(
168
169
  settled.forEach((r, i) => {
169
170
  if (r.status === "rejected") logReadFailure(`foryou:${accountForYouSources[i]!.id}`, r.reason);
170
171
  });
172
+ const items = settled.flatMap((r) => (r.status === "fulfilled" ? r.value : []));
173
+ // #11150 — a welcomed member's `name` onboarding step says the same thing
174
+ // and cannot be dismissed; the area's own item yields to it.
175
+ const nameStep = items.some((item) => item.id === "onboarding:name");
171
176
  return {
172
- items: [
173
- ...addNameItem(session, now),
174
- ...settled.flatMap((r) => (r.status === "fulfilled" ? r.value : [])),
175
- ],
177
+ items: [...(nameStep ? [] : addNameItem(session, now)), ...items],
176
178
  failed: settled.some((r) => r.status === "rejected"),
177
179
  now,
178
180
  };
@@ -25,7 +25,7 @@
25
25
  * agreements interstitial's Sign out ends the session the same way (#8765 D7).
26
26
  *
27
27
  * #8231 D1, as amended by #8334 — the rail reads Inbox, a Library group
28
- * holding Artifacts, and the footer's ?. Settings is not a rail row: it lives
28
+ * holding Artifacts and Appointments (#11154), and the footer's ?. Settings is not a rail row: it lives
29
29
  * in the avatar menu, as on the Admin (the operator's 2026-10-11 Phase 6
30
30
  * read), so no row is selected on a Settings page. A row is selected on its
31
31
  * own path and the paths under it; the Inbox also on an item's page
@@ -75,7 +75,7 @@ import {
75
75
  import { localeHref } from "@working-theory/ui";
76
76
  import { InlineMessage, Link } from "@working-theory/ui/primitives";
77
77
  import { createAuthClient } from "better-auth/react";
78
- import { Inbox, Layers, Settings, Sparkles } from "lucide-react";
78
+ import { CalendarClock, Inbox, Layers, Settings, Sparkles } from "lucide-react";
79
79
  import { usePathname, useRouter, useSearchParams } from "next/navigation";
80
80
  import { useState, type ReactElement, type ReactNode } from "react";
81
81
 
@@ -98,6 +98,8 @@ export interface AccountFrameLabels extends SignedInShellLabels {
98
98
  /** The rail's Library group heading (#8231 D1). */
99
99
  library: string;
100
100
  artifacts: string;
101
+ /** The Library group's Appointments row (#11154). */
102
+ appointments: string;
101
103
  /** Shown when a hub sign-out is refused or fails (#8465). */
102
104
  signOutFailed: string;
103
105
  }
@@ -206,6 +208,7 @@ export function AccountFrame({
206
208
  const homeHref = localeHref(locale, "/");
207
209
  const inboxHref = localeHref(locale, "/account");
208
210
  const artifactsHref = localeHref(locale, "/account/artifacts");
211
+ const appointmentsHref = localeHref(locale, "/account/appointments");
209
212
  const settingsHref = localeHref(locale, "/account/general");
210
213
  const within = (href: string): boolean => pathname === href || pathname.startsWith(`${href}/`);
211
214
 
@@ -220,7 +223,13 @@ export function AccountFrame({
220
223
 
221
224
  // The Inbox row stays selected on an item's own page (/account/inbox/…).
222
225
  const onInbox = pathname === inboxHref || pathname.startsWith(`${inboxHref}/inbox/`);
223
- const activePath = onInbox ? inboxHref : within(artifactsHref) ? artifactsHref : undefined;
226
+ const activePath = onInbox
227
+ ? inboxHref
228
+ : within(artifactsHref)
229
+ ? artifactsHref
230
+ : within(appointmentsHref)
231
+ ? appointmentsHref
232
+ : undefined;
224
233
  // #7469 — the phone tab: For you only on the Inbox route itself.
225
234
  const phoneTab =
226
235
  pathname === inboxHref && searchParams?.get("tab") === FOR_YOU_TAB ? FOR_YOU_TAB : "inbox";
@@ -234,6 +243,7 @@ export function AccountFrame({
234
243
  settings,
235
244
  library,
236
245
  artifacts,
246
+ appointments,
237
247
  signOutFailed: signOutFailedLabel,
238
248
  ...shellLabels
239
249
  } = labels;
@@ -266,6 +276,12 @@ export function AccountFrame({
266
276
  heading: library,
267
277
  items: [
268
278
  { labelKey: "artifacts", label: artifacts, path: "/account/artifacts", icon: Layers },
279
+ {
280
+ labelKey: "appointments",
281
+ label: appointments,
282
+ path: "/account/appointments",
283
+ icon: CalendarClock,
284
+ },
269
285
  ],
270
286
  },
271
287
  ]}
@@ -22,10 +22,14 @@
22
22
  * `authPreHandler` checks against its trusted origins on this
23
23
  * cookie-authenticated mutating request; the route accepts only a cookie
24
24
  * session, never a bearer (D3.1/D5).
25
- * - A spoke that signs in through its hub and carries commerce: the spoke's
26
- * own Stripe key, for the customer its hub vouches for — read server-side
27
- * by the rendered billing action, never from this action's input.
28
- * - A spoke without that action: no portal, so nothing to redirect to.
25
+ * - A spoke that signs in through its hub: the hub's
26
+ * `POST /v1/member/billing/portal-session` (#11165), minted through the
27
+ * workspace's Organization's Stripe connection for the customer the hub
28
+ * vouches for, returning to this page on the spoke's registered origin;
29
+ * where the hub has no portal to open (an older hub, no connection), the
30
+ * spoke's own Stripe key through the rendered billing action (spec 8217),
31
+ * never from this action's input.
32
+ * - A spoke with neither: no portal, so nothing to redirect to.
29
33
  *
30
34
  * It takes no argument, so nothing a browser sends can name a customer.
31
35
  * Next's Server Action origin check applies as before.
@@ -0,0 +1,161 @@
1
+ /**
2
+ * /[locale]/account/appointments/[slug] — one type's booking page for the
3
+ * signed-in member (#11154).
4
+ *
5
+ * RSC, inside the account layout's SignedInShell. Built the way
6
+ * `/meet/[slug]` is: one centred H1 ("Schedule a <title> meeting"), Cal.com's
7
+ * inline booker (the `scheduler-embed` section, provider `cal`, month view,
8
+ * the tight gap) and "← All appointments" under it — but for the member: the
9
+ * verified email and the name from the session ride into the booker as the
10
+ * section's `prefill` (`CalSchedulerEmbed`'s prefill prop, which Cal.com's
11
+ * booking form opens with already filled), so the member retypes neither,
12
+ * and the booking lands on the member's Person by that email — the Inbox's
13
+ * Scheduled tab and the Admin's Bookings.
14
+ *
15
+ * Who may book what is the member read's call (`loadMeetingTypes`): a slug
16
+ * it does not serve — a type switched Off, taken off the clients list, or
17
+ * never offered — answers "This appointment type is no longer offered.",
18
+ * never a public booking and never a redirect to `/meet`. The member read's
19
+ * `calLink` is the type's Cal.com link (#11154); a type without one says
20
+ * the page could not load, with Retry.
21
+ *
22
+ * A segment outside the slug grammar, or carrying a `.`, is `notFound()`
23
+ * before any read (`isTypePath`). No session is a not-found, as the artifact
24
+ * page's is. The embed's own strings are Cal.com's; every other string is an
25
+ * `account.appointments` message.
26
+ */
27
+
28
+ import { localeHref } from "@working-theory/ui";
29
+ import { Container, Heading, Link, Text } from "@working-theory/ui/primitives";
30
+ import { SectionRenderer } from "@working-theory/ui/sections";
31
+ import type {
32
+ MemberMeetingType,
33
+ PageSection,
34
+ } from "@working-theory/validation";
35
+ import type { Metadata } from "next";
36
+ import { notFound } from "next/navigation";
37
+ import { getTranslations } from "next-intl/server";
38
+ import type { ReactElement, ReactNode } from "react";
39
+
40
+ import { accountSession, logReadFailure } from "../../account-data";
41
+ import { ErrorRow } from "../../error-row";
42
+ import {
43
+ isTypePath,
44
+ loadMeetingTypes,
45
+ } from "../appointments-data";
46
+
47
+ interface Props {
48
+ params: Promise<{ locale: string; slug: string }>;
49
+ }
50
+
51
+ /**
52
+ * The booker, pre-bound to the member: the type's Cal.com link with the
53
+ * session's verified email and name as the section's `prefill`. The section
54
+ * shape is `lib/meetings.tsx`'s `meetingPageSections` (provider `cal`, month
55
+ * view, the tight gap), which this base file does not import (the module's own).
56
+ */
57
+ export function memberBookerSection(
58
+ slug: string,
59
+ calLink: string,
60
+ user: { name: string | null; email: string },
61
+ ): PageSection {
62
+ return {
63
+ id: `appointment-${slug}`,
64
+ type: "scheduler-embed",
65
+ data: {
66
+ provider: "cal",
67
+ calLink,
68
+ prefill: { email: user.email, ...(user.name ? { name: user.name } : {}) },
69
+ layout: "month_view",
70
+ gapAbove: "tight",
71
+ },
72
+ };
73
+ }
74
+
75
+ export async function generateMetadata({ params }: Props): Promise<Metadata> {
76
+ const { locale } = await params;
77
+ const t = await getTranslations({ locale, namespace: "account" });
78
+ return { title: t("appointments.title") };
79
+ }
80
+
81
+ export default async function AccountAppointmentPage({
82
+ params,
83
+ }: Props): Promise<ReactElement> {
84
+ const { locale, slug } = await params;
85
+ if (!isTypePath(slug)) notFound();
86
+ const t = await getTranslations({ locale, namespace: "account" });
87
+ const session = await accountSession(locale);
88
+ if (!session) notFound();
89
+
90
+ const frame = (heading: string, body: ReactNode): ReactElement => (
91
+ <div className="py-8" data-testid="appointment">
92
+ <Container className="text-center">
93
+ <Heading level={1} visual={2}>
94
+ {heading}
95
+ </Heading>
96
+ </Container>
97
+ {body}
98
+ <Container className="pb-section pt-block-tight text-center">
99
+ <Link
100
+ href={localeHref(locale, "/account/appointments")}
101
+ variant="nav"
102
+ data-testid="appointment-back"
103
+ >
104
+ {t("appointments.back")}
105
+ </Link>
106
+ </Container>
107
+ </div>
108
+ );
109
+
110
+ let types: MemberMeetingType[];
111
+ try {
112
+ types = await loadMeetingTypes(session.ctx);
113
+ } catch (err) {
114
+ logReadFailure("appointments", err);
115
+ return frame(
116
+ t("appointments.title"),
117
+ <Container size="sm" className="mt-block-loose">
118
+ <ErrorRow
119
+ message={t("appointments.typeError")}
120
+ retryLabel={t("appointments.retry")}
121
+ />
122
+ </Container>,
123
+ );
124
+ }
125
+
126
+ const type = types.find((candidate) => candidate.slug === slug);
127
+ if (!type) {
128
+ return frame(
129
+ t("appointments.title"),
130
+ <Container size="sm" className="mt-block-tight text-center">
131
+ <Text as="p" data-testid="appointment-not-offered">
132
+ {t("appointments.notOffered")}
133
+ </Text>
134
+ </Container>,
135
+ );
136
+ }
137
+
138
+ const heading = t("appointments.bookHeading", {
139
+ title: type.title.toLocaleLowerCase(locale),
140
+ });
141
+ const calLink = type.calLink ?? null;
142
+ if (calLink === null) {
143
+ return frame(
144
+ heading,
145
+ <Container size="sm" className="mt-block-loose">
146
+ <ErrorRow
147
+ message={t("appointments.typeError")}
148
+ retryLabel={t("appointments.retry")}
149
+ />
150
+ </Container>,
151
+ );
152
+ }
153
+
154
+ return frame(
155
+ heading,
156
+ <SectionRenderer
157
+ sections={[memberBookerSection(slug, calLink, session.ctx.user)]}
158
+ locale={locale}
159
+ />,
160
+ );
161
+ }