create-ailk 0.38.0 → 0.39.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 (135) hide show
  1. package/dist/add-route.js +1 -1
  2. package/dist/derive-architecture.js +3 -1
  3. package/dist/remove-module.js +18 -14
  4. package/dist/routes.d.ts +29 -2
  5. package/dist/routes.js +269 -23
  6. package/dist/site-manifest.js +6 -4
  7. package/dist/site-roster.d.ts +11 -3
  8. package/dist/site-roster.js +42 -22
  9. package/dist/surfaces.d.ts +11 -3
  10. package/dist/surfaces.js +69 -22
  11. package/dist/sync-routes.js +22 -5
  12. package/dist/template-record.js +3 -1
  13. package/dist/topology.d.ts +11 -0
  14. package/dist/topology.js +253 -3
  15. package/package.json +3 -3
  16. package/templates/apps/web/CLAUDE.md +26 -4
  17. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
  18. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
  19. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  20. package/templates/apps/web/account.config.tsx +2 -3
  21. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  22. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  23. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  24. package/templates/apps/web/app/[locale]/layout.tsx +1 -1
  25. package/templates/apps/web/auth.config.tsx +107 -0
  26. package/templates/apps/web/auth.ts +2 -1
  27. package/templates/apps/web/i18n/request.ts +9 -2
  28. package/templates/apps/web/jest.config.cjs +4 -0
  29. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
  30. package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
  31. package/templates/apps/web/lib/server-api.ts +1 -1
  32. package/templates/apps/web/lib/topology.generated.ts +5 -0
  33. package/templates/apps/web/messages/en.json +0 -152
  34. package/templates/apps/web/middleware.ts +12 -25
  35. package/templates/apps/web/next.config.mjs +8 -0
  36. package/templates/apps/web/package.json +1 -0
  37. package/templates/apps/web/types/messages.d.ts +6 -1
  38. package/versions.json +49 -48
  39. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  40. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  41. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  42. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  43. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  44. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  45. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  46. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  47. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  48. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  49. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  50. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  51. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  52. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  53. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  54. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  55. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  56. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  57. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  58. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  59. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  60. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  61. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  62. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  63. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  64. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  65. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  66. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  67. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  68. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  69. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  70. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
  71. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
  72. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
  73. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
  74. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
  75. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
  76. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
  77. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
  78. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
  79. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
  80. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
  81. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
  82. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
  83. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
  84. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
  85. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
  86. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
  87. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
  88. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  89. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
  90. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  91. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  92. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  93. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  94. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  95. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  96. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  97. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  98. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  99. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  100. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  101. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  102. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  103. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  104. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  105. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  106. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  107. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  108. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  109. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  110. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  111. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  112. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  113. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  114. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  115. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  116. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  117. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  118. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  119. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  120. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  121. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  122. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  123. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  124. package/templates/apps/web/lib/auth-routes.ts +0 -125
  125. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  126. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  127. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  128. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  129. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  130. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  131. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  132. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  133. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  134. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  135. package/templates/apps/web/lib/next-path.ts +0 -35
@@ -1,277 +0,0 @@
1
- /**
2
- * SpokeSignIn — the signed-out account page of a spoke that signs in through
3
- * its hub (#11096 D1, D9, D10; spec docs/specs/11096-the-spoke-hosts-the-sign-spec.md).
4
- *
5
- * A Server Component, rendered by the `(authed)` layout through the generated
6
- * gate seam (`signed-out-gate.generated.tsx`, its `signIn: "hub"` render) for
7
- * every signed-out account path. The person never sees the hub's brand here:
8
- *
9
- * - **The form.** One email field, the hub's sign-up agreements under a
10
- * "New here?" line (unticked; ticking them makes the request a sign-up),
11
- * and Continue with Google. It is a native `<form method="post">` to this
12
- * site's `/api/hub-session/email`, inside `AuthCard`'s `body` (#9662), so
13
- * it works without JavaScript. No password field, ever (D5), and no link
14
- * to a hub page: Google goes to this site's own sign-in route with
15
- * `provider=google`, which the hub's authorize step turns into Google.
16
- * The agreements' policy links are the hub's (D3).
17
- * - **Its states**, read from the middleware's `x-search` (a layout gets no
18
- * `searchParams`): `?sent=1` (check your email), `?error=agreements |
19
- * unavailable | exists | claim`.
20
- * - **The purchase link** (`?claim=`, D9): "Open your account", the
21
- * agreements' statements and one "Open my account" button whose form
22
- * POSTs the claim to `/api/hub-session/open`. No checkbox: the click is the
23
- * acceptance. Rendering it changes nothing (SEC-11096-3).
24
- * - **One Tap** (D10): the `OneTap` island, only when the spoke sets
25
- * `AILK_HUB_ONE_TAP=on` and its hub reports a client id.
26
- *
27
- * Not configured (`hubSessionConfig()` is `null`), it says sign-in isn't
28
- * available yet and links back to the site. Nothing here logs a claim or
29
- * anything `x-search` carries.
30
- */
31
- import { localeHref } from "@working-theory/ui";
32
- import { AuthCard, ConsentStatement } from "@working-theory/ui/blocks";
33
- import { NavBackLink } from "@working-theory/ui/chrome";
34
- import {
35
- Button,
36
- Checkbox,
37
- Field,
38
- InlineMessage,
39
- Input,
40
- Link,
41
- Text,
42
- } from "@working-theory/ui/primitives";
43
- import { type HubSignUpAgreement, hubPurchaseClaimSchema } from "@working-theory/validation";
44
- import { getTranslations } from "next-intl/server";
45
- import type { ReactElement, ReactNode } from "react";
46
-
47
- import { SITE_NAME } from "../site-brand";
48
- import { siteLogo } from "../site-logo";
49
-
50
- import { hubSessionConfig } from "./config";
51
- import { readHubSignUp, readOneTapClientId } from "./entry";
52
- import { OneTap } from "./one-tap";
53
- import { HUB_SESSION_FALLBACK_PATH, hubNextPath } from "./session";
54
-
55
- /** The spoke's own routes the page posts or links to. */
56
- const EMAIL_ROUTE = "/api/hub-session/email";
57
- const OPEN_ROUTE = "/api/hub-session/open";
58
- const SIGN_IN_ROUTE = "/api/hub-session/sign-in";
59
-
60
- export interface SpokeSignInProps {
61
- locale: string;
62
- /** The incoming request's headers: `x-pathname` and `x-search` (middleware). */
63
- requestHeaders: Headers;
64
- }
65
-
66
- type Translate = Awaited<ReturnType<typeof getTranslations>>;
67
-
68
- /** The one value of `name` in `search`, or `null` (absent or repeated). */
69
- function single(search: URLSearchParams, name: string): string | null {
70
- const values = search.getAll(name);
71
- return values.length === 1 ? (values[0] ?? null) : null;
72
- }
73
-
74
- /** The page's frame: the back arrow, then the card (the account gate's own shape, #8790). */
75
- function Frame({
76
- locale,
77
- backLabel,
78
- card,
79
- }: {
80
- locale: string;
81
- backLabel: string;
82
- card: ReactNode;
83
- }): ReactElement {
84
- return (
85
- <div className="flex min-h-screen flex-col" data-testid="account-sign-in-gate">
86
- <header className="flex h-16 items-center px-5 md:px-8" data-testid="account-sign-in-gate-header">
87
- <NavBackLink href={localeHref(locale, "/")} label={backLabel} />
88
- </header>
89
- <div className="flex flex-1 flex-col items-center md:justify-center md:py-section">
90
- {/* AuthShell's 400px column: the cap sits on the wrapper, never on the card. */}
91
- <div className="w-full max-w-100">{card}</div>
92
- </div>
93
- </div>
94
- );
95
- }
96
-
97
- /** One agreement's checkbox and statement; posts its purpose id under `agreements`. */
98
- function AgreementRow({ agreement }: { agreement: HubSignUpAgreement }): ReactElement {
99
- const id = `spoke-sign-in-agreement-${agreement.purposeId}`;
100
- return (
101
- <div className="flex items-start gap-3">
102
- <Checkbox
103
- id={id}
104
- name="agreements"
105
- value={agreement.purposeId}
106
- aria-labelledby={`${id}-statement`}
107
- className="mt-0.5"
108
- data-testid={id}
109
- />
110
- <ConsentStatement id={`${id}-statement`} statement={agreement.statement} policies={agreement.policies} />
111
- </div>
112
- );
113
- }
114
-
115
- /** The line a `?error=` state puts above the form, or `null`. */
116
- function errorLine(error: string | null, t: Translate): ReactNode {
117
- const lines: Record<string, [string, string]> = {
118
- unavailable: ["spoke-sign-in-unavailable", t("unavailable")],
119
- exists: ["spoke-sign-in-exists", t("exists")],
120
- claim: ["spoke-sign-in-claim-error", t("claimInvalid")],
121
- };
122
- const line = error === null ? undefined : lines[error];
123
- if (line === undefined) return null;
124
- return (
125
- <InlineMessage variant={error === "exists" ? "default" : "error"} role="alert" data-testid={line[0]}>
126
- {line[1]}
127
- </InlineMessage>
128
- );
129
- }
130
-
131
- export async function SpokeSignIn({ locale, requestHeaders }: SpokeSignInProps): Promise<ReactElement> {
132
- const t = await getTranslations({ locale, namespace: "account.spokeSignIn" });
133
- const gate = await getTranslations({ locale, namespace: "account.gate" });
134
- const config = hubSessionConfig();
135
-
136
- if (config === null) {
137
- return (
138
- <Frame
139
- locale={locale}
140
- backLabel={gate("homeLink")}
141
- card={
142
- <AuthCard
143
- intent="sign-in"
144
- footer="none"
145
- headingLevel={1}
146
- logo={siteLogo()}
147
- labels={{ signInHeading: gate("emptyHeadline") }}
148
- subhead={gate("emptyDescription")}
149
- body={
150
- <Button asChild variant="secondary" size="big" className="w-full">
151
- <Link href={localeHref(locale, "/")} variant="bare" data-testid="account-sign-in-gate-home">
152
- {gate("homeLink")}
153
- </Link>
154
- </Button>
155
- }
156
- />
157
- }
158
- />
159
- );
160
- }
161
-
162
- const search = new URLSearchParams(requestHeaders.get("x-search") ?? "");
163
- const next = hubNextPath(
164
- requestHeaders.get("x-pathname") ?? localeHref(locale, HUB_SESSION_FALLBACK_PATH),
165
- );
166
- const info = await readHubSignUp(config, locale);
167
- const agreements = info?.signUpOpen ? info.agreements : [];
168
- const error = single(search, "error");
169
- const rawClaim = single(search, "claim");
170
- const claim = rawClaim !== null && hubPurchaseClaimSchema.safeParse(rawClaim).success ? rawClaim : null;
171
- const card = (heading: string, subhead: string, body: ReactNode): ReactElement => (
172
- <Frame
173
- locale={locale}
174
- backLabel={gate("homeLink")}
175
- card={
176
- <AuthCard
177
- intent="sign-in"
178
- footer="none"
179
- headingLevel={1}
180
- logo={siteLogo()}
181
- labels={{ signInHeading: heading }}
182
- subhead={subhead}
183
- body={body}
184
- />
185
- }
186
- />
187
- );
188
-
189
- // D9 — the purchase link. Without the hub's agreements to show, there is
190
- // nothing to accept, so no button: the form takes over.
191
- if (claim !== null && agreements.length > 0) {
192
- return card(
193
- t("openHeading"),
194
- t("openLead"),
195
- <form method="post" action={OPEN_ROUTE} className="flex flex-col gap-4" data-testid="spoke-sign-in-open-form">
196
- <Input type="hidden" name="claim" value={claim} />
197
- <div className="flex flex-col gap-2" data-testid="spoke-sign-in-open-terms">
198
- {agreements.map((agreement) => (
199
- <ConsentStatement
200
- key={agreement.purposeId}
201
- statement={agreement.statement}
202
- policies={agreement.policies}
203
- />
204
- ))}
205
- </div>
206
- <Button type="submit" size="big" className="w-full" data-testid="spoke-sign-in-open">
207
- {t("open")}
208
- </Button>
209
- </form>,
210
- );
211
- }
212
-
213
- if (single(search, "sent") === "1") {
214
- return card(
215
- t("sent"),
216
- t("sentBody"),
217
- <div className="flex flex-col gap-4" data-testid="spoke-sign-in-sent">
218
- <Button asChild variant="secondary" size="big" className="w-full">
219
- <Link href={next} variant="bare" data-testid="spoke-sign-in-back">
220
- {t("back")}
221
- </Link>
222
- </Button>
223
- </div>,
224
- );
225
- }
226
-
227
- const oneTapClientId = config.oneTap ? await readOneTapClientId(config) : null;
228
- const googleHref = `${SIGN_IN_ROUTE}?${new URLSearchParams({ next, provider: "google" }).toString()}`;
229
- return card(
230
- t("heading", { site: SITE_NAME }),
231
- t("subhead"),
232
- <div className="flex flex-col gap-4">
233
- {errorLine(claim !== null ? "unavailable" : error, t)}
234
- <form method="post" action={EMAIL_ROUTE} className="flex flex-col gap-4" data-testid="spoke-sign-in-form">
235
- <Input type="hidden" name="next" value={next} />
236
- <Field label={t("emailLabel")} htmlFor="spoke-sign-in-email">
237
- <Input
238
- type="email"
239
- name="email"
240
- required
241
- autoComplete="email"
242
- size="big"
243
- data-testid="auth-email"
244
- />
245
- </Field>
246
- {agreements.length > 0 ? (
247
- <fieldset className="flex flex-col gap-3" data-testid="spoke-sign-in-agreements">
248
- <legend className="mb-2">
249
- <Text as="span" variant="body-sm" tone="muted">
250
- {t("newHere")}
251
- </Text>
252
- </legend>
253
- {error === "agreements" ? (
254
- <InlineMessage variant="error" role="alert" data-testid="spoke-sign-in-agreements-error">
255
- {t("agreementsError")}
256
- </InlineMessage>
257
- ) : null}
258
- {agreements.map((agreement) => (
259
- <AgreementRow key={agreement.purposeId} agreement={agreement} />
260
- ))}
261
- </fieldset>
262
- ) : null}
263
- <Button type="submit" size="big" className="w-full" data-testid="spoke-sign-in-submit">
264
- {t("submit")}
265
- </Button>
266
- </form>
267
- {info?.google ? (
268
- <Button asChild variant="secondary" size="big" className="w-full">
269
- <Link href={googleHref} variant="bare" data-testid="spoke-sign-in-google">
270
- {t("google")}
271
- </Link>
272
- </Button>
273
- ) : null}
274
- {oneTapClientId !== null ? <OneTap clientId={oneTapClientId} next={next} /> : null}
275
- </div>,
276
- );
277
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * `?next=` sanitizer for the /sign-in page (#4984) and the hub-session
3
- * callback (#7894 D7 — moved here from `app/[locale]/(auth)/sign-in/`, which
4
- * re-exports it, so a spoke that drops the `(auth)` group keeps it).
5
- *
6
- * The post-sign-in `callbackURL` handed to Better Auth is caller-controlled
7
- * via the `next` search param, so it must be a SAME-ORIGIN, SAME-APP path —
8
- * never a foreign origin (open redirect), a protocol-relative URL, a
9
- * backslash trick browsers normalise to `//`, or a control character that
10
- * could split a header. Anything that fails falls back to `fallback`.
11
- */
12
-
13
- // U+0000–U+001F and U+007F — the header-splitting / URL-mangling range.
14
- // eslint-disable-next-line no-control-regex -- the control range is the thing being rejected
15
- const CONTROL_CHARS = /[\x00-\x1f\x7f]/;
16
-
17
- /**
18
- * Returns `raw` when it is a safe in-app path, else `fallback`.
19
- *
20
- * Accepts: a string starting with a single "/" (e.g. `/account`,
21
- * `/en/account?tab=x`, `/waitlist#a`).
22
- * Rejects: non-strings (incl. Next's `string[]` for a repeated param), "",
23
- * `//host` (protocol-relative), `/\host` (backslash normalised to `//`),
24
- * any backslash anywhere, whitespace, control characters, and anything not
25
- * starting with "/" (`https://…`, `host.tld`).
26
- */
27
- export function resolveNextPath(raw: unknown, fallback: string): string {
28
- if (typeof raw !== "string") return fallback;
29
- if (!raw.startsWith("/")) return fallback;
30
- if (raw.startsWith("//")) return fallback;
31
- if (raw.includes("\\")) return fallback;
32
- if (/\s/.test(raw)) return fallback;
33
- if (CONTROL_CHARS.test(raw)) return fallback;
34
- return raw;
35
- }