create-ailk 0.35.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 (96) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +12 -1
  3. package/component-catalog.md +6 -5
  4. package/dist/lib/env-catalog.js +8 -0
  5. package/dist/surfaces.js +6 -3
  6. package/dist/topology.d.ts +4 -4
  7. package/dist/topology.js +104 -60
  8. package/package.json +3 -3
  9. package/templates/.env.example +21 -0
  10. package/templates/apps/api/.env.example +7 -0
  11. package/templates/apps/api/CLAUDE.md +9 -4
  12. package/templates/apps/mcp/CLAUDE.md +4 -2
  13. package/templates/apps/web/.env.example +16 -0
  14. package/templates/apps/web/CLAUDE.md +46 -5
  15. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  16. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  17. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  18. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  19. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  20. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  21. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  22. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  23. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  27. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
  28. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
  29. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
  30. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  31. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  32. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  33. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  34. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  36. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  38. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  39. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  40. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
  43. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
  44. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  45. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  46. package/templates/apps/web/app/[locale]/layout.tsx +24 -75
  47. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  48. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  49. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  50. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
  51. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
  52. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  53. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  54. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  55. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  56. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  57. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  58. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  59. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
  60. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  61. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  62. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  63. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  64. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  65. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  66. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  67. package/templates/apps/web/auth.ts +133 -6
  68. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  69. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  70. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  71. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  72. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  73. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  74. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  75. package/templates/apps/web/lib/auth-email.ts +62 -6
  76. package/templates/apps/web/lib/auth-env.ts +13 -0
  77. package/templates/apps/web/lib/auth-sms.ts +180 -0
  78. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  79. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  80. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  81. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  82. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  83. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  84. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  85. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  86. package/templates/apps/web/lib/site-header.ts +14 -1
  87. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  88. package/templates/apps/web/lib/topology.generated.ts +39 -0
  89. package/templates/apps/web/messages/en.json +112 -20
  90. package/templates/apps/web/middleware.ts +34 -2
  91. package/templates/apps/web/security-headers.config.ts +21 -0
  92. package/versions.json +47 -47
  93. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  94. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  95. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  96. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -33,6 +33,7 @@
33
33
  * change it reports.
34
34
  */
35
35
 
36
+ import { AsyncLocalStorage } from "node:async_hooks";
36
37
  import { createHmac } from "node:crypto";
37
38
 
38
39
  import { authEmail } from "@working-theory/api-client";
@@ -46,15 +47,17 @@ import {
46
47
  } from "./sign-up-agreements";
47
48
 
48
49
  /**
49
- * The five fixed kinds the relay will send. A caller picks no copy: a sign-up
50
+ * The six fixed kinds the relay will send. A caller picks no copy: a sign-up
50
51
  * link sends agreement ids and a locale, which the API names itself (#9720).
52
+ * `account-open` is a paid buyer's "Open your account" link (#11096 D9).
51
53
  */
52
54
  export type AuthEmailKind =
53
55
  | "password-reset"
54
56
  | "email-verification"
55
57
  | "password-changed"
56
58
  | "magic-link"
57
- | "magic-link-sign-up";
59
+ | "magic-link-sign-up"
60
+ | "account-open";
58
61
 
59
62
  export interface AuthEmailPayload {
60
63
  kind: AuthEmailKind;
@@ -164,7 +167,7 @@ interface DispatchDeps {
164
167
  async function dispatch(
165
168
  payload: AuthEmailPayload,
166
169
  { send, log }: { send: AuthEmailTransport; log: AuthEmailLog },
167
- ): Promise<void> {
170
+ ): Promise<boolean> {
168
171
  const secret = process.env.AUTH_EMAIL_WEBHOOK_SECRET;
169
172
  const base = { userId: payload.userId, kind: payload.kind };
170
173
 
@@ -172,7 +175,7 @@ async function dispatch(
172
175
  // Never sign with an empty key: the relay would reject every delivery and
173
176
  // the deployment would have no local signal at all.
174
177
  log.warn({ ...base, reason: "not_configured" });
175
- return;
178
+ return false;
176
179
  }
177
180
 
178
181
  /**
@@ -196,7 +199,7 @@ async function dispatch(
196
199
  } catch {
197
200
  // The KIND only — see this file's PII boundary note.
198
201
  log.warn({ ...base, reason: "send_failed", errorKind: "signing_failed" });
199
- return;
202
+ return false;
200
203
  }
201
204
 
202
205
  try {
@@ -207,12 +210,14 @@ async function dispatch(
207
210
  // The STATUS, never the response body — the relay's own error text is
208
211
  // not guaranteed free of the address it was given.
209
212
  log.warn({ ...base, reason: "send_failed", errorKind: "relay_rejected" });
210
- return;
213
+ return false;
211
214
  }
212
215
  log.info({ ...base, reason: "sent" });
216
+ return true;
213
217
  } catch {
214
218
  // The error's NAME would be safe; its message is not guaranteed to be.
215
219
  log.warn({ ...base, reason: "send_failed", errorKind: "transport_error" });
220
+ return false;
216
221
  }
217
222
  }
218
223
 
@@ -449,6 +454,48 @@ export function makeSendPasswordChangedNotice(deps: DispatchDeps) {
449
454
  };
450
455
  }
451
456
 
457
+ /**
458
+ * The paid buyer's "Open your account" email (#11096 D9): one link to the
459
+ * spoke's `/account?claim=…`. It carries no agreement copy and signs no one
460
+ * in; the relay only logs `userId`, so it is the fixed sentinel `"purchase"`.
461
+ * Never throws.
462
+ */
463
+ export function makeSendAccountOpen(deps: DispatchDeps) {
464
+ const { send } = deps;
465
+ const log = deps.log ?? defaultLog;
466
+ /** Whether the relay accepted the mail. */
467
+ return async function sendAccountOpen(input: {
468
+ to: string;
469
+ url: string;
470
+ }): Promise<boolean> {
471
+ return dispatch(
472
+ {
473
+ kind: "account-open",
474
+ userId: "purchase",
475
+ to: input.to,
476
+ url: input.url,
477
+ },
478
+ { send, log },
479
+ );
480
+ };
481
+ }
482
+
483
+ /** What one purchase spend gets back from `sendMagicLink` (#11096 D9). */
484
+ export interface PurchaseCaptureStore {
485
+ token: string | null;
486
+ }
487
+
488
+ /**
489
+ * The purchase route's capture (#11096 D9). A `sendMagicLink` call inside
490
+ * `purchaseCapture.run(store, …)` binds a sign-up request's agreements as
491
+ * any sign-up request does, then hands the token to `store` instead of
492
+ * mailing it — so the route can return the hub's own verify URL to the spoke
493
+ * that spent the claim. It captures only a new address with a written
494
+ * binding: an existing account, or a failed binding, leaves `token` null.
495
+ * Outside a capture nothing changes.
496
+ */
497
+ export const purchaseCapture = new AsyncLocalStorage<PurchaseCaptureStore>();
498
+
452
499
  /**
453
500
  * Magic-link token lifetime (#7435 § D2). Five minutes — the library default,
454
501
  * and the number `packages/email`'s magic-link template already promises ("This
@@ -554,6 +601,15 @@ function makeSendMagicLink(deps: MagicLinkDeps) {
554
601
  }
555
602
  }
556
603
 
604
+ // #11096 D9 — inside a purchase capture nothing is mailed: the token of
605
+ // a new address's bound sign-up request goes to the capture.
606
+ const capture = purchaseCapture.getStore();
607
+ if (capture) {
608
+ if (!found && binding) capture.token = data.token;
609
+ log.info({ kind: "magic-link", reason: "captured" });
610
+ return;
611
+ }
612
+
557
613
  // A new address has no user yet; the relay only logs `userId`, so a
558
614
  // sign-up link carries the fixed sentinel and the binding's ids, never
559
615
  // the request's (#9720 D6).
@@ -181,3 +181,16 @@ export function resetSendConfigured(): boolean {
181
181
  if (!process.env.BETTER_AUTH_URL) return false;
182
182
  return Boolean(process.env.BETTER_AUTH_SECRET);
183
183
  }
184
+
185
+ /**
186
+ * True when this deployment can verify a person's phone (#11106 D9): the
187
+ * signed relay's secret (`AUTH_EMAIL_WEBHOOK_SECRET`, which the apps/api SMS
188
+ * relay checks too) and `BETTER_AUTH_URL` (the pinned origin every auth
189
+ * callback rides on). `auth.ts` installs the phone plugin only under this
190
+ * predicate and never on a spoke, and the Account page offers the step only
191
+ * when the plugin is installed. Whether apps/api holds a text provider is
192
+ * apps/api's to say: its relay answers 503 without one.
193
+ */
194
+ export function phoneVerificationConfigured(): boolean {
195
+ return Boolean(process.env.AUTH_EMAIL_WEBHOOK_SECRET && process.env.BETTER_AUTH_URL);
196
+ }
@@ -0,0 +1,180 @@
1
+ /**
2
+ * The phone plugin's outbound text (#11106, spec
3
+ * docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
4
+ *
5
+ * Better Auth's phone plugin generates a verification code and calls
6
+ * `sendOTP`. `apps/web` sends no text itself: like `lib/auth-email.ts`, this
7
+ * file serializes one body, signs it, and POSTs it to `apps/api`'s
8
+ * `/v1/auth/transactional-sms`, which sends one fixed text. The signed bytes
9
+ * and the sent bytes are one string (`buildAuthSmsRequest`).
10
+ *
11
+ * The base string is domain-separated (`transactional-sms.<ts>.<rawBody>`),
12
+ * so a body signed here never verifies at the email relay or the confirm hop,
13
+ * nor the reverse. The secret is the email relay's.
14
+ *
15
+ * The transport is a bare `fetch` to the API origin `@working-theory/api-client`
16
+ * resolves (`getApiBase()`), the `app/openapi.json/route.ts` precedent: the
17
+ * client package carries no SMS namespace, and this unit adds none.
18
+ *
19
+ * PII BOUNDARY: a log line carries `userId`, `kind` and `reason` — never the
20
+ * number and never the code. NOTHING HERE THROWS: a failed send is a log line,
21
+ * and the person asks for another code.
22
+ */
23
+
24
+ import { createHmac } from "node:crypto";
25
+
26
+ import { getApiBase } from "@working-theory/api-client";
27
+
28
+ /** The relay's base-string domain (`packages/api/src/routes/auth/transactional-sms.ts`). */
29
+ export const SMS_SIGNATURE_DOMAIN = "transactional-sms.";
30
+
31
+ /** Bounds the call so a hung apps/api cannot pin an apps/web worker. */
32
+ const SEND_TIMEOUT_MS = 10_000;
33
+
34
+ /** E.164: a plus, a non-zero first digit, eight to fifteen digits in all. */
35
+ export const E164_PATTERN = /^\+[1-9]\d{7,14}$/;
36
+
37
+ /**
38
+ * `AILK_SMS_COUNTRY_CODES`: the calling codes a code may be texted to,
39
+ * comma-separated, default `1`. The relay re-checks the same list.
40
+ */
41
+ export function smsCountryCodes(raw = process.env.AILK_SMS_COUNTRY_CODES): string[] {
42
+ const codes = (raw ?? "")
43
+ .split(",")
44
+ .map((code) => code.trim().replace(/^\+/, ""))
45
+ .filter((code) => /^[1-9]\d{0,2}$/.test(code));
46
+ return codes.length > 0 ? codes : ["1"];
47
+ }
48
+
49
+ /**
50
+ * The plugin's `phoneNumberValidator` (SEC-11106-2): E.164 only, and only a
51
+ * calling code on the list, so a premium-rate destination elsewhere is
52
+ * refused before any code is generated or sent. Calling codes are
53
+ * prefix-free, so a prefix match names one country code.
54
+ */
55
+ export function isAllowedPhoneNumber(phone: string): boolean {
56
+ if (!E164_PATTERN.test(phone)) return false;
57
+ return smsCountryCodes().some((code) => phone.startsWith(`+${code}`));
58
+ }
59
+
60
+ export interface AuthSmsPayload {
61
+ kind: "phone-verification";
62
+ userId: string;
63
+ to: string;
64
+ code: string;
65
+ }
66
+
67
+ export interface AuthSmsRequest {
68
+ rawBody: string;
69
+ headers: Record<string, string>;
70
+ }
71
+
72
+ /** Sign one body; its `ts` is the signed timestamp, so neither moves alone. */
73
+ export function buildAuthSmsRequest(
74
+ payload: AuthSmsPayload,
75
+ secret: string,
76
+ nowSeconds = Math.floor(Date.now() / 1000),
77
+ ): AuthSmsRequest {
78
+ const rawBody = JSON.stringify({
79
+ kind: payload.kind,
80
+ userId: payload.userId,
81
+ to: payload.to,
82
+ code: payload.code,
83
+ ts: nowSeconds,
84
+ });
85
+ const timestamp = String(nowSeconds);
86
+ const signature = `sha256=${createHmac("sha256", secret)
87
+ .update(`${SMS_SIGNATURE_DOMAIN}${timestamp}.${rawBody}`, "utf8")
88
+ .digest("hex")}`;
89
+ return {
90
+ rawBody,
91
+ headers: {
92
+ "x-ailk-auth-sms-signature": signature,
93
+ "x-ailk-auth-sms-timestamp": timestamp,
94
+ },
95
+ };
96
+ }
97
+
98
+ /** The transport seam; resolves the relay's HTTP status, 0 for no answer. */
99
+ export type AuthSmsTransport = (
100
+ rawBody: string,
101
+ headers: Record<string, string>,
102
+ ) => Promise<{ status: number }>;
103
+
104
+ export interface AuthSmsLog {
105
+ warn: (fields: Record<string, unknown>) => void;
106
+ info: (fields: Record<string, unknown>) => void;
107
+ }
108
+
109
+ const defaultLog: AuthSmsLog = {
110
+ warn: (fields) => console.warn(`[auth-sms] ${JSON.stringify(fields)}`),
111
+ info: (fields) => console.info(`[auth-sms] ${JSON.stringify(fields)}`),
112
+ };
113
+
114
+ /** The production transport: one POST of the exact signed bytes. */
115
+ export const authSmsTransport: AuthSmsTransport = async (rawBody, headers) => {
116
+ try {
117
+ const res = await fetch(`${getApiBase()}/v1/auth/transactional-sms`, {
118
+ method: "POST",
119
+ headers: { "Content-Type": "application/json", ...headers },
120
+ body: rawBody,
121
+ signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
122
+ });
123
+ await res.body?.cancel().catch(() => undefined);
124
+ return { status: res.status };
125
+ } catch {
126
+ return { status: 0 };
127
+ }
128
+ };
129
+
130
+ export interface SendPhoneOtpDeps {
131
+ send?: AuthSmsTransport;
132
+ log?: AuthSmsLog;
133
+ /** The signed-in person the code is for — the plugin's verify step binds it. */
134
+ sessionUserId: (ctx: unknown) => Promise<string | null>;
135
+ }
136
+
137
+ /**
138
+ * The plugin's `sendOTP`. The phone before-hook in `auth.ts` has already
139
+ * refused a caller without a verified-email session, so a missing session
140
+ * here is logged and sends nothing.
141
+ */
142
+ export function makeSendPhoneOtp(deps: SendPhoneOtpDeps) {
143
+ const send = deps.send ?? authSmsTransport;
144
+ const log = deps.log ?? defaultLog;
145
+ return async (
146
+ { phoneNumber, code }: { phoneNumber: string; code: string },
147
+ ctx?: unknown,
148
+ ): Promise<void> => {
149
+ const base = { kind: "phone-verification" };
150
+ const secret = process.env.AUTH_EMAIL_WEBHOOK_SECRET;
151
+ if (!secret) {
152
+ log.warn({ ...base, reason: "not_configured" });
153
+ return;
154
+ }
155
+ let userId: string | null;
156
+ try {
157
+ userId = await deps.sessionUserId(ctx);
158
+ } catch {
159
+ userId = null;
160
+ }
161
+ if (userId === null) {
162
+ log.warn({ ...base, reason: "no_session" });
163
+ return;
164
+ }
165
+ let request: AuthSmsRequest;
166
+ try {
167
+ request = buildAuthSmsRequest({ kind: "phone-verification", userId, to: phoneNumber, code }, secret);
168
+ } catch {
169
+ log.warn({ ...base, userId, reason: "send_failed", errorKind: "signing_failed" });
170
+ return;
171
+ }
172
+ const { status } = await send(request.rawBody, request.headers);
173
+ if (status >= 200 && status < 300) {
174
+ log.info({ ...base, userId, reason: "sent" });
175
+ } else {
176
+ // The status only — the relay's body is never read.
177
+ log.warn({ ...base, userId, reason: "send_failed", status });
178
+ }
179
+ };
180
+ }
@@ -158,9 +158,21 @@ describe("hubSessionConfig", () => {
158
158
  siteOrigin: "http://127.0.0.1:3100",
159
159
  redirectUri: "http://127.0.0.1:3100/api/hub-session/callback",
160
160
  secure: false,
161
+ oneTap: false,
161
162
  });
162
163
  });
163
164
 
165
+ // #11096 D10 — One Tap is on only for exactly `on`.
166
+ it.each([
167
+ ["on", true],
168
+ ["ON", false],
169
+ ["1", false],
170
+ ["", false],
171
+ ])("AILK_HUB_ONE_TAP=%p reads oneTap %p", (value, expected) => {
172
+ configure({ AILK_HUB_ONE_TAP: value });
173
+ expect(hubSessionConfig()?.oneTap).toBe(expected);
174
+ });
175
+
164
176
  it("is secure on an https site", () => {
165
177
  configure({ NEXT_PUBLIC_BASE_URL: "https://spoke.example.com/" });
166
178
  expect(hubSessionConfig()).toMatchObject({
@@ -403,3 +415,19 @@ describe("#8232 AC-5 — resealHubSession", () => {
403
415
  await expect(resealHubSession()).resolves.toBe("failed");
404
416
  });
405
417
  });
418
+
419
+ describe("readBodyText (#11096) — the spoke's body read caps BYTES, not characters", () => {
420
+ const post = (body: string): Request =>
421
+ new Request("https://spoke.example/api/hub-session/email", { method: "POST", body });
422
+
423
+ it("reads a body within 8 KB", async () => {
424
+ const { readBodyText } = await import("../entry");
425
+ await expect(readBodyText(post("a".repeat(8_192)))).resolves.toBe("a".repeat(8_192));
426
+ });
427
+
428
+ it("refuses a body under 8 K characters but over 8 KB of UTF-8", async () => {
429
+ const { readBodyText } = await import("../entry");
430
+ // 3 000 three-byte characters: 3 000 characters, 9 000 bytes.
431
+ await expect(readBodyText(post("€".repeat(3_000)))).resolves.toBeNull();
432
+ });
433
+ });