create-ailk 0.34.1 → 0.36.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 (139) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +37 -4
  3. package/component-catalog.md +11 -9
  4. package/dist/add-module.js +7 -2
  5. package/dist/derive-architecture.js +2 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/env-catalog.js +8 -0
  9. package/dist/module-architecture.js +9 -0
  10. package/dist/programmatic.js +5 -2
  11. package/dist/site-listing-path.d.ts +8 -0
  12. package/dist/site-listing-path.js +8 -0
  13. package/dist/surfaces.d.ts +20 -0
  14. package/dist/surfaces.js +32 -3
  15. package/dist/template-record.js +2 -0
  16. package/dist/topology.d.ts +4 -4
  17. package/dist/topology.js +104 -60
  18. package/dist/update.js +11 -0
  19. package/package.json +3 -3
  20. package/templates/.env.example +21 -0
  21. package/templates/apps/api/.env.example +7 -0
  22. package/templates/apps/api/CLAUDE.md +14 -9
  23. package/templates/apps/mcp/CLAUDE.md +18 -7
  24. package/templates/apps/web/.env.example +16 -0
  25. package/templates/apps/web/CLAUDE.md +46 -5
  26. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  27. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  28. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  29. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  30. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  31. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  32. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  33. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  34. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
  37. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +43 -0
  38. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  39. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +6 -5
  40. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
  41. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
  42. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
  43. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  44. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  45. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  46. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  47. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
  48. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +6 -1
  51. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  53. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  54. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  55. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
  57. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
  58. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  59. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  60. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +43 -4
  61. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +23 -9
  62. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +15 -0
  63. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +74 -0
  64. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +34 -1
  65. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +257 -4
  66. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +72 -92
  67. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +2 -2
  68. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +164 -65
  69. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +100 -0
  70. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +99 -0
  71. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +415 -253
  72. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +113 -32
  73. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +16 -17
  74. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +284 -0
  75. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +52 -19
  76. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +402 -0
  77. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +100 -12
  78. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +153 -101
  79. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +36 -0
  80. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +121 -33
  81. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +27 -17
  82. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +91 -0
  83. package/templates/apps/web/app/[locale]/layout.tsx +42 -76
  84. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  85. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  86. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  87. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +189 -6
  88. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +101 -31
  89. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  90. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  91. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  92. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  93. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  94. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  95. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  96. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
  97. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  98. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  99. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  100. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  101. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  102. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  103. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  104. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +122 -0
  105. package/templates/apps/web/app/llms.txt/route.ts +14 -2
  106. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +98 -0
  107. package/templates/apps/web/app/sitemap.xml/route.ts +13 -2
  108. package/templates/apps/web/auth.ts +133 -6
  109. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  110. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  111. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  112. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  113. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  114. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  115. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  116. package/templates/apps/web/lib/account-config.ts +24 -9
  117. package/templates/apps/web/lib/auth-email.ts +62 -6
  118. package/templates/apps/web/lib/auth-env.ts +13 -0
  119. package/templates/apps/web/lib/auth-sms.ts +180 -0
  120. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  121. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  122. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  123. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  124. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  125. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  126. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  127. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  128. package/templates/apps/web/lib/site-header.ts +14 -1
  129. package/templates/apps/web/lib/site-listing.ts +7 -0
  130. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  131. package/templates/apps/web/lib/topology.generated.ts +39 -0
  132. package/templates/apps/web/messages/en.json +125 -21
  133. package/templates/apps/web/middleware.ts +34 -2
  134. package/templates/apps/web/security-headers.config.ts +21 -0
  135. package/versions.json +47 -47
  136. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  137. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  138. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  139. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -11,6 +11,9 @@
11
11
  *
12
12
  * - the contact details (`AccountContactDetails`, #8435 D13) — only on the
13
13
  * member path, seeded from `member.contact` and saved by `saveContact`;
14
+ * - the phone step (`PhoneVerification`, #11106 D9) — on a hub only: the
15
+ * person sets and verifies their own number, read from their Better Auth
16
+ * session; a build without the phone plugin shows the not-available line;
14
17
  * - any section a module contributes (`accountSettingsSections`);
15
18
  * - `BillingAnchor`, which forwards a `#billing` fragment to Billing.
16
19
  *
@@ -31,16 +34,19 @@ import {
31
34
  } from "@working-theory/templates/account";
32
35
  import { Separator, Text } from "@working-theory/ui/primitives";
33
36
  import type { Metadata } from "next";
37
+ import { headers } from "next/headers";
34
38
  import { getTranslations } from "next-intl/server";
35
39
  import type { ReactElement } from "react";
36
40
 
37
41
  import { accountSettingsSections } from "../../../../../lib/account-config";
42
+ import { readPhoneStep, TOPOLOGY } from "../../../../../lib/topology.generated";
38
43
  import { accountSession } from "../account-data";
39
44
  import { siteThemeModeCount } from "../settings/theme-modes";
40
45
  import { memberSettingsFrame, SettingsSection, type Translate } from "../settings-frame";
41
46
 
42
47
  import { BillingAnchor } from "./billing-anchor";
43
48
  import { saveContact } from "./contact-actions";
49
+ import { PhoneVerification, type PhoneVerificationLabels } from "./phone-verification";
44
50
  import { GeneralSettings } from "./profile-form";
45
51
  import { loadProfileSource } from "./profile-source";
46
52
 
@@ -77,6 +83,36 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
77
83
 
78
84
  const { ctx } = session;
79
85
  const source = await loadProfileSource(ctx);
86
+ // The phone step reads through the generated seam (#11138); a spoke's hub
87
+ // holds the person, so a spoke has none.
88
+ const phoneStep = TOPOLOGY === "spoke" ? null : await readPhoneStep(await headers());
89
+ const phoneLabels: PhoneVerificationLabels = {
90
+ title: t("profile.phoneTitle"),
91
+ lead: t("profile.phoneLead"),
92
+ number: t("profile.phoneNumber"),
93
+ numberHint: t("profile.phoneNumberHint"),
94
+ sendCode: t("profile.phoneSendCode"),
95
+ sending: t("profile.phoneSending"),
96
+ code: t("profile.phoneCode"),
97
+ codeHint: t("profile.phoneCodeHint"),
98
+ verify: t("profile.phoneVerify"),
99
+ verifying: t("profile.phoneVerifying"),
100
+ verified: t("profile.phoneVerified"),
101
+ remove: t("profile.phoneRemove"),
102
+ sent: t("profile.phoneSent"),
103
+ unavailable: t("profile.phoneUnavailable"),
104
+ unverifiedEmail: t("profile.phoneUnverifiedEmail"),
105
+ errors: {
106
+ invalid_number: t("profile.phoneErrors.invalid_number"),
107
+ invalid_code: t("profile.phoneErrors.invalid_code"),
108
+ taken: t("profile.phoneErrors.taken"),
109
+ too_many: t("profile.phoneErrors.too_many"),
110
+ unverified: t("profile.phoneErrors.unverified"),
111
+ signed_out: t("profile.phoneErrors.signed_out"),
112
+ unavailable: t("profile.phoneErrors.unavailable"),
113
+ failed: t("profile.phoneErrors.failed"),
114
+ },
115
+ };
80
116
 
81
117
  // #8435 D13 — the person's confirmed contact on this site. A failed read
82
118
  // renders the section's "unavailable" line, never the form: a form seeded
@@ -163,6 +199,17 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
163
199
  </div>
164
200
  </>
165
201
  ) : null}
202
+ {phoneStep ? (
203
+ <>
204
+ <Separator />
205
+ <PhoneVerification
206
+ available={phoneStep.available}
207
+ emailVerified={ctx.user.emailVerified}
208
+ phone={phoneStep.phone}
209
+ labels={phoneLabels}
210
+ />
211
+ </>
212
+ ) : null}
166
213
  {accountSettingsSections.map((section) => (
167
214
  <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
168
215
  {section.render(ctx)}
@@ -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,214 @@
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
+ <Heading level={3} visual={4} id="account-phone-title">
201
+ {labels.title}
202
+ </Heading>
203
+ <Text as="p" variant="body-sm" tone="muted">
204
+ {labels.lead}
205
+ </Text>
206
+ {body}
207
+ {error ? (
208
+ <InlineMessage variant="error" role="alert" data-testid="account-phone-error">
209
+ {error}
210
+ </InlineMessage>
211
+ ) : null}
212
+ </section>
213
+ );
214
+ }
@@ -9,6 +9,10 @@
9
9
  * `InboxItemFrame`; the area supplies the back link, the caption (the kind's
10
10
  * label) and the title, so every kind's detail reads as one frame.
11
11
  *
12
+ * #11007 — a conversation kind (`accountChatKinds`: a message) renders
13
+ * through the frame's chat layout — RecordHeader over the message as a
14
+ * start-side bubble; every other kind keeps the stacked head and fields.
15
+ *
12
16
  * An unknown kind, or an id the kind did not load, is a not-found — never an
13
17
  * empty frame. A failed read is not a not-found: it renders an error with
14
18
  * Retry (D12's posture).
@@ -21,7 +25,7 @@ import { notFound } from "next/navigation";
21
25
  import { getTranslations } from "next-intl/server";
22
26
  import type { ReactElement } from "react";
23
27
 
24
- import { accountInboxKinds } from "../../../../../../../lib/account-config";
28
+ import { accountChatKinds, accountInboxKinds } from "../../../../../../../lib/account-config";
25
29
  import { accountSession, logReadFailure } from "../../../account-data";
26
30
  import { ErrorRow } from "../../../error-row";
27
31
 
@@ -88,6 +92,7 @@ export default async function AccountInboxItemPage({ params }: Props): Promise<R
88
92
  status={detail.status}
89
93
  {...(detail.actions ? { actions: detail.actions } : {})}
90
94
  fields={detail.fields}
95
+ {...(accountChatKinds.has(kind.kind) ? { layout: "chat" as const } : {})}
91
96
  testIdPrefix="account-item"
92
97
  >
93
98
  {detail.body}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ // `isInvitationId` (#11141): the `invite_` + uuid check the invitation page
5
+ // and its actions run before any call. It lives in a plain module — a
6
+ // synchronous export of the "use server" actions file fails `next build`.
7
+
8
+ import { readFileSync } from "node:fs";
9
+ import { join } from "node:path";
10
+
11
+ import { isInvitationId } from "../invitation-id";
12
+
13
+ describe("isInvitationId", () => {
14
+ it("accepts `invite_` + a lowercase uuid", () => {
15
+ expect(isInvitationId("invite_01920000-0000-7000-8000-000000000001")).toBe(true);
16
+ });
17
+
18
+ it.each([
19
+ "",
20
+ "01920000-0000-7000-8000-000000000001",
21
+ "invite_01920000-0000-7000-8000-00000000000",
22
+ "invite_01920000-0000-7000-8000-0000000000011",
23
+ "invite_01920000-0000-7000-8000-00000000000G",
24
+ "INVITE_01920000-0000-7000-8000-000000000001",
25
+ "invite_01920000-0000-7000-8000-000000000001/accept",
26
+ "../invite_01920000-0000-7000-8000-000000000001",
27
+ ])("rejects %j", (value) => {
28
+ expect(isInvitationId(value)).toBe(false);
29
+ });
30
+
31
+ it('is not a "use server" module', () => {
32
+ const source = readFileSync(join(__dirname, "..", "invitation-id.ts"), "utf8");
33
+ expect(source).not.toMatch(/^\s*["']use server["']/m);
34
+ });
35
+ });