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
@@ -26,6 +26,10 @@
26
26
  * `provider` hint (AC-3), the purchase link's "Open my account" (AC-4) and
27
27
  * One Tap's nonce and credential exchange (AC-5, AC-6). The hub web is
28
28
  * reached with `fetch` (mocked); the hub API through the api-client.
29
+ *
30
+ * #11162 (AC-2): the Security tab's password link — a same-origin JSON POST
31
+ * for the sealed session's person, asked of the hub web as the spoke's
32
+ * client; no address and no password ever crosses this route.
29
33
  */
30
34
 
31
35
  import { createHash } from "node:crypto";
@@ -33,12 +37,14 @@ import { createHash } from "node:crypto";
33
37
  const mockExchange = jest.fn();
34
38
  const mockRevoke = jest.fn();
35
39
  const mockGoogle = jest.fn();
40
+ const mockMe = jest.fn();
36
41
  jest.mock("@working-theory/api-client", () => ({
37
42
  __esModule: true,
38
43
  hubSignIn: {
39
44
  exchange: (...args: unknown[]) => mockExchange(...args),
40
45
  revoke: (...args: unknown[]) => mockRevoke(...args),
41
46
  google: (...args: unknown[]) => mockGoogle(...args),
47
+ me: (...args: unknown[]) => mockMe(...args),
42
48
  },
43
49
  }));
44
50
 
@@ -65,6 +71,8 @@ import { POST as email } from "../email/route";
65
71
  import { POST as oneTapNonce } from "../one-tap/nonce/route";
66
72
  import { POST as oneTap } from "../one-tap/route";
67
73
  import { POST as open } from "../open/route";
74
+ import { GET as passwordReturn } from "../password/return/route";
75
+ import { POST as password } from "../password/route";
68
76
  import { GET as signIn } from "../sign-in/route";
69
77
  import { POST as signOut } from "../sign-out/route";
70
78
 
@@ -136,6 +144,7 @@ beforeEach(() => {
136
144
  mockProvider.value = "hub";
137
145
  mockExchange.mockReset();
138
146
  mockGoogle.mockReset();
147
+ mockMe.mockReset();
139
148
  mockCheckBotId.mockReset().mockResolvedValue({ isBot: false });
140
149
  mockFetch.mockReset();
141
150
  // eslint-disable-next-line no-restricted-syntax -- a jest.fn stands in for the global fetch, the hub web's HTTP boundary; its call signature is not fetch's own.
@@ -901,3 +910,257 @@ describe("POST /api/hub-session/one-tap and its nonce (#11096 D10, AC-5)", () =>
901
910
  ).toBe(404);
902
911
  });
903
912
  });
913
+
914
+ describe("POST /api/hub-session/password — the Security tab's password link (#11162 AC-2)", () => {
915
+ const SAME_ORIGIN = { "sec-fetch-site": "same-origin", origin: SITE };
916
+ const SESSION_COOKIE = "ailk-hub-session";
917
+
918
+ function sessionCookie(secret: string = SESSION_SECRET): string {
919
+ const sealed = seal(
920
+ { v: 1, accessToken: CREDENTIAL, expiresAt: Date.now() + 60_000, user: USER },
921
+ secret,
922
+ "session",
923
+ SESSION_COOKIE,
924
+ );
925
+ return `${SESSION_COOKIE}=${sealed}`;
926
+ }
927
+
928
+ function post(
929
+ body: unknown,
930
+ headers: Record<string, string> = { ...SAME_ORIGIN, cookie: sessionCookie() },
931
+ ): Request {
932
+ return new Request(`${SITE}/api/hub-session/password`, {
933
+ method: "POST",
934
+ headers: { "content-type": "application/json", ...headers },
935
+ body: typeof body === "string" ? body : JSON.stringify(body),
936
+ });
937
+ }
938
+
939
+ beforeEach(() => {
940
+ process.env.AILK_SPOKE_KEY = SPOKE_KEY;
941
+ });
942
+
943
+ it("asks the hub web as the spoke's client for the sealed session's person, never a body address; 202 { sent: true }", async () => {
944
+ mockFetch.mockResolvedValue(hubAnswer(202, { sent: true }));
945
+ const res = await password(post({ locale: "en" }));
946
+
947
+ expect(res.status).toBe(202);
948
+ expect(await res.json()).toEqual({ sent: true });
949
+ expect(res.headers.get("cache-control")).toBe("no-store");
950
+ expect(setCookies(res)).toEqual([]);
951
+
952
+ const call = hubCall();
953
+ expect(call.url).toBe(`${HUB}/api/auth/hub/password`);
954
+ expect(call.headers.get("authorization")).toBe(
955
+ `Basic ${Buffer.from(`${CLIENT.clientId}:${CLIENT.clientSecret}`).toString("base64")}`,
956
+ );
957
+ expect(call.headers.get("x-ailk-spoke-key")).toBe(SPOKE_KEY);
958
+ expect(call.body).toEqual({
959
+ client_id: CLIENT.clientId,
960
+ redirect_uri: `${SITE}/api/hub-session/callback`,
961
+ access_token: CREDENTIAL,
962
+ locale: "en",
963
+ return_path: "/account/security",
964
+ });
965
+ });
966
+
967
+ it("returns the person to the locale's own Security tab", async () => {
968
+ configure({ NEXT_PUBLIC_ENABLED_LOCALES: "en,fr" });
969
+ mockFetch.mockResolvedValue(hubAnswer(202, { sent: true }));
970
+ await password(post({ locale: "fr" }));
971
+ expect(hubCall().body).toMatchObject({ locale: "fr", return_path: "/fr/account/security" });
972
+ });
973
+
974
+ it("a locale this site does not enable reads as the default", async () => {
975
+ mockFetch.mockResolvedValue(hubAnswer(202, { sent: true }));
976
+ await password(post({ locale: "de" }));
977
+ expect(hubCall().body).toMatchObject({ locale: "en", return_path: "/account/security" });
978
+ });
979
+
980
+ it.each([
981
+ ["a password field (the spoke never accepts one)", { locale: "en", password: "hunter22" }],
982
+ ["an email field (the person is the session's)", { locale: "en", email: "eve@example.com" }],
983
+ ["no locale", {}],
984
+ ["a malformed locale", { locale: "english" }],
985
+ ["a body that is not JSON", "locale=en"],
986
+ ] as Array<[string, unknown]>)("%s → 400, no hub call", async (_label, body) => {
987
+ const res = await password(post(body));
988
+ expect(res.status).toBe(400);
989
+ expect(await res.json()).toEqual({ error: "invalid_request" });
990
+ expect(mockFetch).not.toHaveBeenCalled();
991
+ });
992
+
993
+ it("without a session cookie → 401, no hub call", async () => {
994
+ const res = await password(post({ locale: "en" }, SAME_ORIGIN));
995
+ expect(res.status).toBe(401);
996
+ expect(await res.json()).toEqual({ error: "no_session" });
997
+ expect(mockFetch).not.toHaveBeenCalled();
998
+ });
999
+
1000
+ it("a session sealed under another key → 401, no hub call", async () => {
1001
+ const res = await password(
1002
+ post({ locale: "en" }, { ...SAME_ORIGIN, cookie: sessionCookie("x".repeat(43)) }),
1003
+ );
1004
+ expect(res.status).toBe(401);
1005
+ expect(mockFetch).not.toHaveBeenCalled();
1006
+ });
1007
+
1008
+ it.each([
1009
+ ["cross-site", { "sec-fetch-site": "cross-site", origin: SITE }],
1010
+ ["a foreign Origin", { "sec-fetch-site": "same-origin", origin: "https://evil.example.com" }],
1011
+ ["neither header", {}],
1012
+ ] as Array<[string, Record<string, string>]>)("refuses %s with 403, calling nothing", async (_label, headers) => {
1013
+ const res = await password(post({ locale: "en" }, { ...headers, cookie: sessionCookie() }));
1014
+ expect(res.status).toBe(403);
1015
+ expect(mockFetch).not.toHaveBeenCalled();
1016
+ });
1017
+
1018
+ it("the hub's invalid_grant — a credential it no longer honours — → 401", async () => {
1019
+ mockFetch.mockResolvedValue(hubAnswer(400, { error: "invalid_grant" }));
1020
+ const res = await password(post({ locale: "en" }));
1021
+ expect(res.status).toBe(401);
1022
+ expect(await res.json()).toEqual({ error: "invalid_session" });
1023
+ });
1024
+
1025
+ it.each([
1026
+ ["a 401", () => mockFetch.mockResolvedValue(hubAnswer(401, { error: "invalid_client" }))],
1027
+ ["a 429", () => mockFetch.mockResolvedValue(hubAnswer(429, { error: "rate_limited" }))],
1028
+ ["a 503", () => mockFetch.mockResolvedValue(hubAnswer(503, { error: "temporarily_unavailable" }))],
1029
+ ["a throw", () => mockFetch.mockRejectedValue(new Error("network"))],
1030
+ ])("%s → 503 temporarily_unavailable", async (_label, arrange) => {
1031
+ arrange();
1032
+ const res = await password(post({ locale: "en" }));
1033
+ expect(res.status).toBe(503);
1034
+ expect(await res.json()).toEqual({ error: "temporarily_unavailable" });
1035
+ });
1036
+
1037
+ it("a visitor over the limit gets 429 and no hub call", async () => {
1038
+ configure({ VERCEL: "1", AILK_BOT_CHECK: "off" });
1039
+ mockFetch.mockResolvedValue(hubAnswer(202, { sent: true }));
1040
+ const visitor = { ...SAME_ORIGIN, cookie: sessionCookie(), "x-vercel-forwarded-for": "203.0.113.79" };
1041
+ for (let i = 0; i < 10; i++) {
1042
+ expect((await password(post({ locale: "en" }, visitor))).status).toBe(202);
1043
+ }
1044
+ mockFetch.mockClear();
1045
+ const limited = await password(post({ locale: "en" }, visitor));
1046
+ expect(limited.status).toBe(429);
1047
+ expect(mockFetch).not.toHaveBeenCalled();
1048
+ });
1049
+
1050
+ it("a bot gets 503 and no hub call", async () => {
1051
+ configure({ VERCEL: "1" });
1052
+ mockCheckBotId.mockResolvedValue({ isBot: true, classificationReason: "test" });
1053
+ const res = await password(
1054
+ post({ locale: "en" }, { ...SAME_ORIGIN, cookie: sessionCookie(), "x-vercel-forwarded-for": "203.0.113.80" }),
1055
+ );
1056
+ expect(res.status).toBe(503);
1057
+ expect(mockFetch).not.toHaveBeenCalled();
1058
+ });
1059
+
1060
+ it("with no configuration → 503, no hub call", async () => {
1061
+ configure({ AILK_HUB_CLIENT_SECRET: undefined });
1062
+ const res = await password(post({ locale: "en" }));
1063
+ expect(res.status).toBe(503);
1064
+ expect(mockFetch).not.toHaveBeenCalled();
1065
+ });
1066
+
1067
+ it("is 404 unless the provider is hub", async () => {
1068
+ mockProvider.value = "site";
1069
+ const res = await password(post({ locale: "en" }));
1070
+ expect(res.status).toBe(404);
1071
+ });
1072
+
1073
+ it("never logs the credential or the address", async () => {
1074
+ const warn = jest.spyOn(console, "warn");
1075
+ const error = jest.spyOn(console, "error");
1076
+ mockFetch.mockRejectedValue(new Error("network"));
1077
+ await password(post({ locale: "en" }));
1078
+ const logged = [...warn.mock.calls, ...error.mock.calls].flat().join(" ");
1079
+ expect(logged).not.toContain(CREDENTIAL);
1080
+ expect(logged).not.toContain(USER.email);
1081
+ });
1082
+ });
1083
+
1084
+ describe("GET /api/hub-session/password/return — where the hub's set-password page lands the person (#11162 AC-2)", () => {
1085
+ const SESSION_COOKIE = "ailk-hub-session";
1086
+ const CLEARED = /^ailk-hub-session=; Path=\/; HttpOnly; SameSite=Lax; Max-Age=0$/;
1087
+
1088
+ function sessionCookie(): string {
1089
+ const sealed = seal(
1090
+ { v: 1, accessToken: CREDENTIAL, expiresAt: Date.now() + 60_000, user: USER },
1091
+ SESSION_SECRET,
1092
+ "session",
1093
+ SESSION_COOKIE,
1094
+ );
1095
+ return `${SESSION_COOKIE}=${sealed}`;
1096
+ }
1097
+
1098
+ /** `cookie: null` is a request with no session cookie. */
1099
+ function get(next: string | null, cookie: string | null = sessionCookie()): Promise<Response> {
1100
+ const url = new URL("/api/hub-session/password/return", SITE);
1101
+ if (next !== null) url.searchParams.set("next", next);
1102
+ return passwordReturn(new Request(url.toString(), { headers: cookie === null ? {} : { cookie } }));
1103
+ }
1104
+
1105
+ it("a credential the hub no longer honours (the reset revoked it): the session cookie is cleared and the person lands on the tab, whose gate signs them back in", async () => {
1106
+ mockMe.mockResolvedValue({ ok: false, status: 401, body: { ok: false } });
1107
+ const res = await get("/account/security");
1108
+ expect(res.status).toBe(303);
1109
+ expect(res.headers.get("location")).toBe("/account/security");
1110
+ expect(res.headers.get("cache-control")).toBe("no-store");
1111
+ expect(setCookies(res)).toHaveLength(1);
1112
+ expect(setCookies(res)[0]).toMatch(CLEARED);
1113
+ expect(mockMe).toHaveBeenCalledWith({ headers: { authorization: `Bearer ${CREDENTIAL}` } });
1114
+ });
1115
+
1116
+ it("a credential the hub still honours keeps its cookie", async () => {
1117
+ mockMe.mockResolvedValue({ ok: true, status: 200, body: { user: USER, billingCustomerId: null, hasPassword: true } });
1118
+ const res = await get("/fr/account/security");
1119
+ expect(res.headers.get("location")).toBe("/fr/account/security");
1120
+ expect(setCookies(res)).toEqual([]);
1121
+ });
1122
+
1123
+ it.each([
1124
+ ["cannot be reached", () => mockMe.mockRejectedValue(new Error("network"))],
1125
+ ["answers a limit (429)", () => mockMe.mockResolvedValue({ ok: false, status: 429, body: { ok: false } })],
1126
+ ["answers an outage (503)", () => mockMe.mockResolvedValue({ ok: false, status: 503, body: { ok: false } })],
1127
+ ["refuses the spoke, not the credential (403)", () => mockMe.mockResolvedValue({ ok: false, status: 403, body: { ok: false } })],
1128
+ ])("a hub that %s clears nothing — only its 401 does", async (_label, arrange) => {
1129
+ arrange();
1130
+ const res = await get("/account/security");
1131
+ expect(res.headers.get("location")).toBe("/account/security");
1132
+ expect(setCookies(res)).toEqual([]);
1133
+ });
1134
+
1135
+ it("with no session cookie it only lands, asking the hub nothing", async () => {
1136
+ const res = await get("/account/security", null);
1137
+ expect(res.status).toBe(303);
1138
+ expect(res.headers.get("location")).toBe("/account/security");
1139
+ expect(setCookies(res)).toEqual([]);
1140
+ expect(mockMe).not.toHaveBeenCalled();
1141
+ });
1142
+
1143
+ it.each([
1144
+ ["an absolute URL", "https://evil.example.com/account/security"],
1145
+ ["a protocol-relative path", "//evil.example.com/account/security"],
1146
+ ["a route-handler path", "/api/hub-session/sign-out"],
1147
+ ["no next", null],
1148
+ ])("%s as next lands on /account", async (_label, next) => {
1149
+ mockMe.mockResolvedValue({ ok: true, status: 200, body: {} });
1150
+ const res = await get(next);
1151
+ expect(res.headers.get("location")).toBe("/account");
1152
+ });
1153
+
1154
+ it("with no configuration lands home", async () => {
1155
+ configure({ AILK_HUB_CLIENT_SECRET: undefined });
1156
+ const res = await get("/account/security");
1157
+ expect(res.headers.get("location")).toBe("/");
1158
+ expect(mockMe).not.toHaveBeenCalled();
1159
+ });
1160
+
1161
+ it("is 404 unless the provider is hub", async () => {
1162
+ mockProvider.value = "site";
1163
+ const res = await get("/account/security");
1164
+ expect(res.status).toBe(404);
1165
+ });
1166
+ });
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Where the hub's set-password page returns a spoke's person (#11162) —
3
+ * `GET /api/hub-session/password/return?next=<path>`.
4
+ *
5
+ * Saving a password on the hub ends every session and every spoke
6
+ * credential the person held (`onPasswordReset`, SEC-7894-5) — the Security
7
+ * tab's own copy says so. The sealed cookie this spoke keeps therefore
8
+ * names a credential the hub no longer honours, and a page that read it as
9
+ * signed in would fail closed on the hub's refusal instead of showing the
10
+ * tab. So the hub's page lands here first:
11
+ *
12
+ * 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 303 home.
13
+ * 2. `next` is the sanitized same-origin page path (`hubNextPath`), else
14
+ * `/account`.
15
+ * 3. With a session cookie, the hub is asked once whether the credential
16
+ * still stands (`GET /v1/hub-sign-in/me`). A 401 — the one status the
17
+ * hub answers a credential it no longer honours — clears the cookie, so
18
+ * the gate on `next` shows this spoke's own sign-in form and the person
19
+ * comes back to the tab with a fresh credential; a credential the hub
20
+ * still honours, no cookie, or a hub that cannot answer (a limit, an
21
+ * outage, a thrown read) leaves the cookie as it is.
22
+ * 4. 303 to `next`, always.
23
+ *
24
+ * A GET, reachable cross-site: it changes nothing an attacker could not
25
+ * already cause — the one write is to drop a cookie the hub has ALREADY
26
+ * refused, and no credential is revoked here. Nothing is logged but a
27
+ * status; the credential never is.
28
+ */
29
+ import { hubSignIn } from "@working-theory/api-client";
30
+
31
+ import { hubSessionConfig } from "../../../../../lib/hub-session/config";
32
+ import {
33
+ cookieHeader,
34
+ HUB_SESSION_HOME_PATH,
35
+ hubNextPath,
36
+ readHubSessionPayload,
37
+ seeOther,
38
+ sessionCookieName,
39
+ } from "../../../../../lib/hub-session/session";
40
+ import { SIGN_IN_PROVIDER } from "../../../../../lib/topology.generated";
41
+
42
+ /**
43
+ * Whether the hub still honours the credential: `false` only on its 401,
44
+ * `null` when it could not answer — any other status, or a thrown read.
45
+ */
46
+ async function credentialStands(accessToken: string): Promise<boolean | null> {
47
+ try {
48
+ const res = await hubSignIn.me({ headers: { authorization: `Bearer ${accessToken}` } });
49
+ if (res.ok) return true;
50
+ return res.status === 401 ? false : null;
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+
56
+ // platform-decisions-waiver: api-versioning — a sign-in step of the spoke's own form, not a versioned API contract (spec 11096 §6)
57
+ export async function GET(request: Request): Promise<Response> {
58
+ if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
59
+ const config = hubSessionConfig();
60
+ if (config === null) return seeOther(HUB_SESSION_HOME_PATH);
61
+
62
+ const next = hubNextPath(new URL(request.url).searchParams.get("next"));
63
+ const session = readHubSessionPayload(request.headers);
64
+ if (session === null) return seeOther(next);
65
+
66
+ const stands = await credentialStands(session.accessToken);
67
+ if (stands !== false) return seeOther(next);
68
+ return seeOther(next, [cookieHeader(sessionCookieName(config), "", 0, config)]);
69
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The spoke's Security tab asks for a password link (#11162) —
3
+ * `POST /api/hub-session/password`.
4
+ *
5
+ * On a spoke that signs in through its hub, the Security tab renders the
6
+ * Password row itself; its Set / Change password button posts here. This
7
+ * route asks the hub web, server to server as the spoke's client, to mail the
8
+ * SIGNED-IN person the hub's own set-password link — the person comes from
9
+ * the sealed session cookie, never from the body, so a spoke cannot ask for
10
+ * anyone it did not sign in. The link lands on the hub's set-password page,
11
+ * which returns the person to this site's `/account/security`.
12
+ *
13
+ * 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 503.
14
+ * 2. Same-origin only (`Sec-Fetch-Site`, `Origin`), else 403.
15
+ * 3. No session cookie, or one that does not open → 401.
16
+ * 4. 10 posts per visitor per 10 minutes (429), then the bot check (503).
17
+ * 5. The body is `spokePasswordBodySchema`: `{ locale }` and nothing else —
18
+ * a `password` key, or any other, is 400. The spoke never holds or
19
+ * accepts a password.
20
+ * 6. The hub web's `POST /api/auth/hub/password` gets the client, its
21
+ * callback, the session's credential, the locale and the return path
22
+ * (`/account/security` under that locale); the hub API checks the
23
+ * client and the credential before anything is mailed.
24
+ * 7. 202 `{ sent: true }`; the hub's `invalid_grant` (a credential it no
25
+ * longer honours) → 401; anything else → 503.
26
+ *
27
+ * Nothing here logs the credential, the cookie or an address. Every answer
28
+ * is `Cache-Control: no-store`.
29
+ */
30
+ import { spokePasswordBodySchema } from "@working-theory/validation";
31
+
32
+ import { runBotCheck } from "../../../../lib/bot-check";
33
+ import { hubSessionConfig } from "../../../../lib/hub-session/config";
34
+ import { hubError, localeOfPath, postToHub, readBodyText } from "../../../../lib/hub-session/entry";
35
+ import { isSameOrigin, readHubSessionPayload } from "../../../../lib/hub-session/session";
36
+ import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
37
+ import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
38
+
39
+ /** The hub web's password route. */
40
+ const HUB_PASSWORD_PATH = "/api/auth/hub/password";
41
+
42
+ /** The per-visitor budget for this route. */
43
+ const VISITOR_LIMIT = 10;
44
+ const VISITOR_WINDOW_MS = 10 * 60_000;
45
+
46
+ const DEFAULT_LOCALE = "en";
47
+
48
+ function json(status: number, body: Record<string, unknown>): Response {
49
+ return new Response(JSON.stringify(body), {
50
+ status,
51
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" },
52
+ });
53
+ }
54
+
55
+ const refuse = (status: number, error: string): Response => json(status, { error });
56
+
57
+ /** The parsed JSON body, or `undefined` when it is too large or does not parse. */
58
+ async function readJson(request: Request): Promise<unknown> {
59
+ const text = await readBodyText(request);
60
+ if (text === null) return undefined;
61
+ try {
62
+ return JSON.parse(text) as unknown;
63
+ } catch {
64
+ return undefined;
65
+ }
66
+ }
67
+
68
+ // platform-decisions-waiver: api-versioning — a sign-in step of the spoke's own form, not a versioned API contract (spec 11096 §6)
69
+ export async function POST(request: Request): Promise<Response> {
70
+ if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
71
+ const config = hubSessionConfig();
72
+ if (config === null) return refuse(503, "temporarily_unavailable");
73
+ if (!isSameOrigin(request, config.siteOrigin)) return refuse(403, "forbidden");
74
+
75
+ const session = readHubSessionPayload(request.headers);
76
+ if (session === null) return refuse(401, "no_session");
77
+
78
+ if (!takeVisitorLimit("hub-session-password", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
79
+ return refuse(429, "rate_limited");
80
+ }
81
+ const bot = await runBotCheck({ source: "hub-session", target: "password", scope: "write" });
82
+ if (bot !== "pass") return refuse(503, "temporarily_unavailable");
83
+
84
+ const parsed = spokePasswordBodySchema.safeParse(await readJson(request));
85
+ if (!parsed.success) return refuse(400, "invalid_request");
86
+ // An enabled locale, else the default — the one the Security tab is under.
87
+ const locale = localeOfPath(`/${parsed.data.locale}`);
88
+
89
+ const answer = await postToHub(config, HUB_PASSWORD_PATH, {
90
+ client_id: config.clientId,
91
+ redirect_uri: config.redirectUri,
92
+ access_token: session.accessToken,
93
+ locale,
94
+ return_path: `${locale === DEFAULT_LOCALE ? "" : `/${locale}`}/account/security`,
95
+ });
96
+
97
+ if (answer?.status === 202) return json(202, { sent: true });
98
+ if (answer?.status === 400 && hubError(answer) === "invalid_grant") {
99
+ return refuse(401, "invalid_session");
100
+ }
101
+ // The hub's error code is a closed enum, never an address.
102
+ console.warn(
103
+ `[hub-session] password link not sent status=${answer === null ? "unreachable" : answer.status} error=${hubError(answer) ?? "none"}`,
104
+ );
105
+ return refuse(503, "temporarily_unavailable");
106
+ }
@@ -35,11 +35,13 @@ const mockCheckoutsMe = jest.fn();
35
35
  const mockSubscriptionMe = jest.fn();
36
36
  const mockMemberPieces = jest.fn();
37
37
  const mockMemberMessages = jest.fn();
38
+ const mockMemberRequests = jest.fn();
38
39
  const mockMemberPurchases = jest.fn();
39
40
  const mockMemberResults = jest.fn();
40
41
  const mockMemberAppointments = jest.fn();
41
42
  const mockMemberMeetingTypes = jest.fn();
42
43
  const mockMemberRequestForm = jest.fn();
44
+ const mockMemberWelcome = jest.fn();
43
45
  jest.mock("@working-theory/api-client", () => ({
44
46
  __esModule: true,
45
47
  waitlistSignups: { me: (...args: unknown[]) => mockSignupMe(...args) },
@@ -48,11 +50,13 @@ jest.mock("@working-theory/api-client", () => ({
48
50
  member: {
49
51
  pieces: (...args: unknown[]) => mockMemberPieces(...args),
50
52
  messages: (...args: unknown[]) => mockMemberMessages(...args),
53
+ requests: (...args: unknown[]) => mockMemberRequests(...args),
51
54
  purchases: (...args: unknown[]) => mockMemberPurchases(...args),
52
55
  results: (...args: unknown[]) => mockMemberResults(...args),
53
56
  appointments: (...args: unknown[]) => mockMemberAppointments(...args),
54
57
  meetingTypes: (...args: unknown[]) => mockMemberMeetingTypes(...args),
55
58
  requestForm: (...args: unknown[]) => mockMemberRequestForm(...args),
59
+ welcome: (...args: unknown[]) => mockMemberWelcome(...args),
56
60
  },
57
61
  }));
58
62
 
@@ -147,6 +151,15 @@ const MESSAGE = {
147
151
  readAt: null,
148
152
  };
149
153
 
154
+ /** #11157 — a quote request the member sent; a quote's body is empty. */
155
+ const SENT_REQUEST = {
156
+ id: "intx_2",
157
+ kind: "quote" as const,
158
+ subject: "Request quote",
159
+ body: "",
160
+ createdAt: "2026-09-05T10:00:00.000Z",
161
+ };
162
+
150
163
  const ok = <T>(body: T) => ({ ok: true as const, body });
151
164
  const fail = (status: number) => ({ ok: false as const, status, body: null });
152
165
 
@@ -186,17 +199,19 @@ describe("account-config exports (AC-6)", () => {
186
199
  ["purchase", "purchases"],
187
200
  ["piece", "updates"],
188
201
  ["message", "updates"],
202
+ ["request", "updates"],
189
203
  ["appointment", "upcoming"],
190
204
  ]);
191
205
  // No Inbox row asks for a decision — that is the For-you panel's job.
192
206
  expect(accountInboxKinds.some((k) => k.section === "needs-you")).toBe(false);
193
207
  });
194
208
 
195
- it("ships email-unverified, payment-due and piece-needs-client (#7920) as For-you sources, not Inbox kinds (D9 as amended)", () => {
209
+ it("ships email-unverified, payment-due, piece-needs-client (#7920) and onboarding-steps (#11150) as For-you sources, not Inbox kinds (D9 as amended)", () => {
196
210
  expect(accountForYouSources.map((s) => s.id)).toEqual([
197
211
  "email-unverified",
198
212
  "payment-due",
199
213
  "piece-needs-client",
214
+ "onboarding-steps",
200
215
  ]);
201
216
  const kinds = accountInboxKinds.map((k) => k.kind);
202
217
  expect(kinds).not.toContain("email-unverified");
@@ -458,9 +473,35 @@ describe("member kinds on a cookie-session site — no gate (#8231 D7)", () => {
458
473
  expect(items.map((i) => i.id)).toEqual(["piece:piece_1"]);
459
474
  });
460
475
 
476
+ it("request reads member.requests with the cookie init and returns the sent rows, titled by subject (#11157)", async () => {
477
+ mockMemberRequests.mockResolvedValue(ok({ items: [SENT_REQUEST] }));
478
+ const items = await kind("request").load(ctx());
479
+ expect(mockMemberRequests).toHaveBeenCalledWith(INIT);
480
+ expect(items.map((i) => [i.id, i.title, i.at])).toEqual([
481
+ ["intx_2", "Request quote", "2026-09-05T10:00:00.000Z"],
482
+ ]);
483
+ });
484
+
485
+ it("request is a conversation kind: its detail is the member's own bubble, the sent line for a quote's empty body (#11157)", () => {
486
+ const item = { id: "intx_2", title: "Request quote", at: SENT_REQUEST.createdAt, data: SENT_REQUEST };
487
+ const detail = kind("request").renderDetail(item, ctx());
488
+ expect(detail.actions).toBeUndefined();
489
+ expect(detail.fields).toBeUndefined();
490
+ const bubble = detail.body as { props: { side: string; caption: string; children: { props: { children: string } } } };
491
+ expect(bubble.props.side).toBe("end");
492
+ expect(bubble.props.caption).toContain("t:requests.sentAt · ");
493
+ expect(bubble.props.children.props.children).toBe("t:requests.quoteSent");
494
+ const withBody = kind("request").renderDetail(
495
+ { ...item, data: { ...SENT_REQUEST, kind: "message" as const, body: "Hello\nthere" } },
496
+ ctx(),
497
+ ).body as { props: { children: { props: { children: string } } } };
498
+ expect(withBody.props.children.props.children).toBe("Hello\nthere");
499
+ });
500
+
461
501
  it.each([
462
502
  ["piece", mockMemberPieces],
463
503
  ["message", mockMemberMessages],
504
+ ["request", mockMemberRequests],
464
505
  ] as const)("%s loads [] on a 404 and rejects on a 500", async (id, mock) => {
465
506
  mock.mockResolvedValue(fail(404));
466
507
  await expect(kind(id).load(ctx())).resolves.toEqual([]);
@@ -507,6 +548,87 @@ describe("payment-due — a For-you item from subscription.me's actionRequired",
507
548
  });
508
549
  });
509
550
 
551
+ // ── #11150 — the onboarding steps ────────────────────────────────────────────
552
+
553
+ describe("onboarding-steps — a welcomed member's steps left, from member.welcome (#11150 AC-3)", () => {
554
+ const WELCOMED_AT = "2026-11-08T09:00:00.000Z";
555
+ const WELCOME = {
556
+ welcomedAt: WELCOMED_AT,
557
+ steps: [
558
+ { id: "name", done: false },
559
+ { id: "onboarding", done: false },
560
+ { id: "email", done: true },
561
+ { id: "booking", done: false },
562
+ ],
563
+ };
564
+
565
+ it("is one item per step not done, each linking to its page, none dismissible, timed at the welcome", async () => {
566
+ mockMemberWelcome.mockResolvedValue(ok(WELCOME));
567
+ const items = await source("onboarding-steps").load(ctx());
568
+ expect(mockMemberWelcome).toHaveBeenCalledWith(INIT);
569
+ expect(items.map((item) => item.id)).toEqual([
570
+ "onboarding:name",
571
+ "onboarding:onboarding",
572
+ "onboarding:booking",
573
+ ]);
574
+ expect(items[0]).toEqual({
575
+ id: "onboarding:name",
576
+ type: { id: "onboarding", label: "t:forYou.types.onboarding", tone: "neutral" },
577
+ // The area's own "Add your name" string — the item it replaces (account-data.ts).
578
+ title: "t:forYou.addName",
579
+ time: { kind: "at", at: WELCOMED_AT },
580
+ action: { kind: "open", href: "/account/general" },
581
+ dismissible: false,
582
+ });
583
+ expect(items.map((item) => (item.action as { href: string }).href)).toEqual([
584
+ "/account/general",
585
+ "/account/onboarding",
586
+ "/account/appointments",
587
+ ]);
588
+ expect(items.every((item) => item.dismissible === false)).toBe(true);
589
+ });
590
+
591
+ it("links the email step to General and the booking step to Appointments", async () => {
592
+ mockMemberWelcome.mockResolvedValue(
593
+ ok({
594
+ welcomedAt: WELCOMED_AT,
595
+ steps: [
596
+ { id: "email", done: false },
597
+ { id: "booking", done: false },
598
+ ],
599
+ }),
600
+ );
601
+ const items = await source("onboarding-steps").load(ctx({ emailVerified: false }));
602
+ expect(items.map((item) => [item.title, (item.action as { href: string }).href])).toEqual([
603
+ ["t:forYou.onboarding.email", "/account/general"],
604
+ ["t:forYou.onboarding.booking", "/account/appointments"],
605
+ ]);
606
+ });
607
+
608
+ it("is empty once every step is done, so the panel's empty-hides rule holds", async () => {
609
+ mockMemberWelcome.mockResolvedValue(
610
+ ok({ welcomedAt: WELCOMED_AT, steps: WELCOME.steps.map((step) => ({ ...step, done: true })) }),
611
+ );
612
+ await expect(source("onboarding-steps").load(ctx())).resolves.toEqual([]);
613
+ });
614
+
615
+ it("is empty with no marker (no Person could be made), on a 404, and on an unverified 401/403", async () => {
616
+ mockMemberWelcome.mockResolvedValueOnce(ok({ welcomedAt: null, steps: [] }));
617
+ await expect(source("onboarding-steps").load(ctx())).resolves.toEqual([]);
618
+ mockMemberWelcome.mockResolvedValueOnce(fail(404));
619
+ await expect(source("onboarding-steps").load(ctx())).resolves.toEqual([]);
620
+ mockMemberWelcome.mockResolvedValueOnce(fail(403));
621
+ await expect(source("onboarding-steps").load(ctx({ emailVerified: false }))).resolves.toEqual([]);
622
+ });
623
+
624
+ it("rejects on a failed read, a 403 for a verified email included (D12)", async () => {
625
+ mockMemberWelcome.mockResolvedValueOnce(fail(500));
626
+ await expect(source("onboarding-steps").load(ctx())).rejects.toThrow();
627
+ mockMemberWelcome.mockResolvedValueOnce(fail(403));
628
+ await expect(source("onboarding-steps").load(ctx())).rejects.toThrow();
629
+ });
630
+ });
631
+
510
632
  // ── #8233 — the New actions ──────────────────────────────────────────────────
511
633
 
512
634
  describe("New actions — offered while their member read answers (#8233 D1, D2)", () => {
@@ -550,6 +672,12 @@ describe("New actions — offered while their member read answers (#8233 D1, D2)
550
672
  expect(mockMemberRequestForm).toHaveBeenCalledWith(INIT);
551
673
  });
552
674
 
675
+ it("send-message is a link row to the member thread page (#11152)", () => {
676
+ expect(action("send-message").href).toBe("/account/inbox/thread");
677
+ expect(action("schedule-service").href).toBe("/account/appointments");
678
+ expect(action("request-quote").href).toBeUndefined();
679
+ });
680
+
553
681
  it("send-message: a messages 200 → true, read with ctx.init", async () => {
554
682
  mockMemberMessages.mockResolvedValue(ok({ items: [] }));
555
683
  await expect(action("send-message").available(ctx())).resolves.toBe(true);