create-ailk 0.36.0 → 0.37.1

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 (101) hide show
  1. package/README.md +20 -2
  2. package/component-catalog.json +40 -1
  3. package/component-catalog.md +7 -5
  4. package/dist/add-route.d.ts +5 -0
  5. package/dist/add-route.js +10 -2
  6. package/dist/surfaces.js +60 -19
  7. package/dist/sync-routes.d.ts +15 -1
  8. package/dist/sync-routes.js +58 -6
  9. package/dist/template-record.d.ts +11 -0
  10. package/dist/template-record.js +18 -0
  11. package/dist/update.d.ts +33 -1
  12. package/dist/update.js +439 -56
  13. package/package.json +3 -3
  14. package/templates/.env.example +17 -0
  15. package/templates/apps/api/.env.example +38 -0
  16. package/templates/apps/api/CLAUDE.md +3 -0
  17. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  18. package/templates/apps/mcp/CLAUDE.md +1 -1
  19. package/templates/apps/web/CLAUDE.md +28 -1
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  22. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  38. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  39. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  40. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  45. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  46. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  47. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  50. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  54. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  59. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  60. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  62. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  63. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  64. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  65. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  70. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  71. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  72. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  73. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  75. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  76. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  77. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  79. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  80. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  81. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  82. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  83. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  84. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  85. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  86. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  87. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  88. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  89. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  90. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  91. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  92. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  93. package/templates/apps/web/lib/account-config.ts +132 -8
  94. package/templates/apps/web/lib/auth-routes.ts +11 -6
  95. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  96. package/templates/apps/web/messages/en.json +156 -80
  97. package/versions.json +48 -48
  98. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  99. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  101. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -3,14 +3,23 @@
3
3
  * docs/specs/8234-member-artifacts-account-artifacts-and-spec.md D4).
4
4
  *
5
5
  * RSC, inside the account layout's SignedInShell, through the shared
6
- * `InboxItemFrame`: back to Artifacts, the title, the review state, and —
6
+ * `InboxItemFrame`: back to Artifacts, the title, the piece's stage as its
7
+ * status (#11161 — the provider's own pipeline, read as on the list), the
8
+ * review of the latest version as a tag beside it when there is one, and —
7
9
  * once approved — "Approved <date>". The body lists every served version in
8
10
  * the read's order, newest first: its number, its delivery date, its note,
9
- * the member's own review when there is one, and one action — Download for a
10
- * file (re-served by `versions/[version]/file/route.ts`, never shown inline
11
- * on this origin) or View for an https link, opened in a new tab. A link
12
- * that is not https renders no action. The read serves no deliverer (8169
13
- * D6), so none is shown.
11
+ * the member's own review when there is one (a tag and the dated line), and
12
+ * its action — Download for a file (re-served by
13
+ * `versions/[version]/file/route.ts`) or View for an https link, opened in a
14
+ * new tab. A link that is not https renders no action. The read serves no
15
+ * deliverer (8169 D6), so none is shown.
16
+ *
17
+ * #11161 — an image or a PDF version renders INLINE above its Download
18
+ * (`ArtifactVersionPreview`: the AssetLightbox for an image, the
19
+ * document-viewer section for a PDF), from the same route asked to answer
20
+ * inline (`?inline=1`), which it does for those two types only, under the
21
+ * hub's sandbox CSP and `nosniff` (docs/security/member-artifact-preview.md).
22
+ * Every other file keeps Download alone.
14
23
  *
15
24
  * Inside the latest version only: the review form while it is reviewable
16
25
  * (not approved, no review yet — `isReviewable`), else the waiting line once
@@ -34,9 +43,21 @@
34
43
  * no `kind`, renders exactly as before.
35
44
  */
36
45
 
37
- import { InboxItemFrame } from "@working-theory/templates/account";
46
+ import {
47
+ ArtifactVersionPreview,
48
+ InboxItemFrame,
49
+ previewKind,
50
+ type ArtifactVersionPreviewLabels,
51
+ } from "@working-theory/templates/account";
38
52
  import { localeHref } from "@working-theory/ui";
39
- import { Button, Heading, Link, Text } from "@working-theory/ui/primitives";
53
+ import {
54
+ Badge,
55
+ Button,
56
+ Heading,
57
+ Link,
58
+ LocalTime,
59
+ Text,
60
+ } from "@working-theory/ui/primitives";
40
61
  import {
41
62
  isHttpsLink,
42
63
  type MemberArtifact,
@@ -50,6 +71,7 @@ import type { ReactElement } from "react";
50
71
  import { accountSession, logReadFailure } from "../../account-data";
51
72
  import { ErrorRow } from "../../error-row";
52
73
  import {
74
+ artifactStageLabel,
53
75
  artifactState,
54
76
  isProposal,
55
77
  isReviewable,
@@ -57,6 +79,8 @@ import {
57
79
  paymentDue,
58
80
  STATE_KEYS,
59
81
  versionFileHref,
82
+ versionPreviewHref,
83
+ versionTypeKey,
60
84
  } from "../artifact-data";
61
85
 
62
86
  import { PayForm, type PayFormLabels } from "./pay-form";
@@ -115,7 +139,7 @@ export default async function AccountArtifactPage({
115
139
 
116
140
  let artifacts: MemberArtifact[];
117
141
  try {
118
- artifacts = await loadArtifacts(session.ctx);
142
+ artifacts = (await loadArtifacts(session.ctx)).items;
119
143
  } catch (err) {
120
144
  logReadFailure("artifacts", err);
121
145
  return (
@@ -134,12 +158,14 @@ export default async function AccountArtifactPage({
134
158
  );
135
159
  if (!artifact) notFound();
136
160
 
137
- const date = (iso: string): string =>
138
- new Intl.DateTimeFormat(locale, {
139
- dateStyle: "medium",
140
- timeZone: "UTC",
141
- }).format(new Date(iso));
161
+ // #11175: every dated message carries a `<date>` tag, rendered through
162
+ // `t.rich` as a `LocalTime` node — the server fallback zone in this RSC's
163
+ // render, the viewer's own once the page hydrates.
164
+ const dateTag = (iso: string): { date: () => ReactElement } => ({
165
+ date: () => <LocalTime at={iso} preset="date" locale={locale} />,
166
+ });
142
167
  const state = artifactState(artifact);
168
+ const reviewTag = state === "ready" ? null : t(STATE_KEYS[state]);
143
169
  const reviewable = isReviewable(artifact);
144
170
  const latest = artifact.versions[0]!.version;
145
171
  const proposal = isProposal(artifact);
@@ -180,6 +206,33 @@ export default async function AccountArtifactPage({
180
206
  },
181
207
  };
182
208
 
209
+ const previewLabels = (filename: string): ArtifactVersionPreviewLabels => ({
210
+ open: t("artifacts.preview.open", { filename }),
211
+ details: t("artifacts.preview.details"),
212
+ filename: t("artifacts.preview.filename"),
213
+ type: t("artifacts.preview.type"),
214
+ zoomIn: t("artifacts.preview.zoomIn"),
215
+ zoomOut: t("artifacts.preview.zoomOut"),
216
+ copyLink: t("artifacts.preview.copyLink"),
217
+ });
218
+
219
+ // An image or a PDF version, inline (#11161); any other file has none.
220
+ const versionPreview = (v: MemberPieceVersion): ReactElement | null => {
221
+ if (v.file === null) return null;
222
+ const kind = previewKind(v.file.contentType);
223
+ if (kind === null) return null;
224
+ return (
225
+ <ArtifactVersionPreview
226
+ kind={kind}
227
+ src={versionPreviewHref(locale, artifact.id, v.version)}
228
+ filename={v.file.filename}
229
+ typeLabel={t(versionTypeKey(v))}
230
+ labels={previewLabels(v.file.filename)}
231
+ testIdPrefix={`artifact-version-${v.version}-preview`}
232
+ />
233
+ );
234
+ };
235
+
183
236
  // The one action of a version: Download a file, View an https link, else none.
184
237
  const versionAction = (v: MemberPieceVersion): ReactElement | null => {
185
238
  if (v.file !== null) {
@@ -222,10 +275,12 @@ export default async function AccountArtifactPage({
222
275
  proposal ? t("artifacts.proposal.caption") : t("artifacts.caption")
223
276
  }
224
277
  title={artifact.title}
225
- status={t(STATE_KEYS[state])}
278
+ // An older hub serves no stage; the review tag alone then.
279
+ status={artifactStageLabel(artifact) ?? undefined}
280
+ tags={reviewTag === null ? [] : [reviewTag]}
226
281
  lead={
227
282
  artifact.approvedAt !== null
228
- ? t("artifacts.approvedOn", { date: date(artifact.approvedAt) })
283
+ ? t.rich("artifacts.approvedOn", dateTag(artifact.approvedAt))
229
284
  : null
230
285
  }
231
286
  testIdPrefix="artifact"
@@ -244,6 +299,7 @@ export default async function AccountArtifactPage({
244
299
  <div className="mt-block-tight flex flex-col gap-4">
245
300
  {artifact.versions.map((v) => {
246
301
  const action = versionAction(v);
302
+ const preview = versionPreview(v);
247
303
  return (
248
304
  <div
249
305
  key={v.version}
@@ -254,7 +310,7 @@ export default async function AccountArtifactPage({
254
310
  {t("artifacts.version", { version: v.version })}
255
311
  </Text>
256
312
  <Text as="p" variant="body-sm" tone="muted">
257
- {t("artifacts.deliveredOn", { date: date(v.deliveredAt) })}
313
+ {t.rich("artifacts.deliveredOn", dateTag(v.deliveredAt))}
258
314
  </Text>
259
315
  {v.note !== null ? (
260
316
  <Text
@@ -267,14 +323,23 @@ export default async function AccountArtifactPage({
267
323
  ) : null}
268
324
  {v.review !== null && v.reviewedAt !== null ? (
269
325
  <div className="mt-2">
326
+ <Badge
327
+ variant="outline"
328
+ size="sm"
329
+ className="mb-1"
330
+ data-testid={`artifact-version-${v.version}-review`}
331
+ >
332
+ {v.review === "approved"
333
+ ? t("artifacts.states.approved")
334
+ : t("artifacts.states.changesRequested")}
335
+ </Badge>
270
336
  <Text as="p" variant="body-sm" tone="muted">
271
337
  {v.review === "approved"
272
- ? t("artifacts.reviewApproved", {
273
- date: date(v.reviewedAt),
274
- })
275
- : t("artifacts.reviewChangesRequested", {
276
- date: date(v.reviewedAt),
277
- })}
338
+ ? t.rich("artifacts.reviewApproved", dateTag(v.reviewedAt))
339
+ : t.rich(
340
+ "artifacts.reviewChangesRequested",
341
+ dateTag(v.reviewedAt),
342
+ )}
278
343
  </Text>
279
344
  {v.reviewComment !== null ? (
280
345
  <Text
@@ -287,6 +352,9 @@ export default async function AccountArtifactPage({
287
352
  ) : null}
288
353
  </div>
289
354
  ) : null}
355
+ {preview !== null ? (
356
+ <div className="mt-block-tight">{preview}</div>
357
+ ) : null}
290
358
  {action !== null ? (
291
359
  <div className="mt-block-tight">{action}</div>
292
360
  ) : null}
@@ -314,7 +382,7 @@ export default async function AccountArtifactPage({
314
382
  {v.version === latest && paidAt !== null ? (
315
383
  <div className="mt-block-tight" data-testid="artifact-paid">
316
384
  <Text as="p" variant="body-sm">
317
- {t("artifacts.proposal.paid", { date: date(paidAt) })}
385
+ {t.rich("artifacts.proposal.paid", dateTag(paidAt))}
318
386
  </Text>
319
387
  </div>
320
388
  ) : null}
@@ -20,6 +20,17 @@
20
20
  * without it — and so is one whose safety headers carry the wrong value
21
21
  * (#8320, #9965 D8): presence alone is not the hub's promise.
22
22
  *
23
+ * #11161 — the preview mode, the one amendment to that obligation (recorded
24
+ * in `docs/security/member-artifact-preview.md`): `?inline=1` asks for the
25
+ * bytes as a document the artifact page can render in place. The route
26
+ * answers `Content-Disposition: inline` ONLY when the hub's `Content-Type`
27
+ * is `image/*` (never SVG) or `application/pdf`, with the download name the
28
+ * hub pinned and the other four headers still unchanged — so the document
29
+ * renders inside the sandbox CSP's opaque origin (no script, no cookie, no
30
+ * same-origin access) and `nosniff` holds the type. Any other type, and
31
+ * every request without the flag, is `attachment` exactly as the hub sent
32
+ * it. The hub itself never answers inline.
33
+ *
23
34
  * The params are shape-checked before any call (a malformed piece id or a
24
35
  * version that is not a whole number from 1 is a 404 with no call). A
25
36
  * refusal has no body: no credential (signed out) is a 401, a hub 4xx keeps
@@ -52,6 +63,16 @@ const FILE_HEADER_NAMES: Record<keyof MemberFileHeaders, string> = {
52
63
  const HTTP_VALUE = /^[\t\x20-\x7e]*$/;
53
64
  const httpTrim = (value: string) => value.replace(/^[ \t]+|[ \t]+$/g, "");
54
65
 
66
+ /**
67
+ * #11161 — the two type families a preview may render inline: raster images
68
+ * and PDF. SVG is refused by name (it is not attachable either, SEC-7877-D),
69
+ * so a hub that ever stored one still serves it as an attachment.
70
+ */
71
+ export function isInlinePreviewType(contentType: string): boolean {
72
+ const type = httpTrim(contentType.split(";")[0] ?? "").toLowerCase();
73
+ return type === "application/pdf" || (type.startsWith("image/") && type !== "image/svg+xml");
74
+ }
75
+
55
76
  /**
56
77
  * The CSP's directives by name, or `null` for two policies joined or a
57
78
  * directive named twice — a browser enforces the first copy, so a check that
@@ -115,11 +136,12 @@ function refusalStatus(status: number, body: unknown): number {
115
136
 
116
137
  // platform-decisions-waiver: api-versioning — a page-scoped download link on the site's own account area, not an API contract; it re-serves the versioned hub route /v1/member/artifacts/:pieceId/versions/:version/file
117
138
  export async function GET(
118
- _request: Request,
139
+ request: Request,
119
140
  { params }: Context,
120
141
  ): Promise<Response> {
121
142
  // Exactly the two segments the strict schema takes — `params` also carries `locale`.
122
143
  const { pieceId, version } = await params;
144
+ const inline = new URL(request.url).searchParams.get("inline") === "1";
123
145
  const parsed = memberArtifactFileParamsSchema.safeParse({ pieceId, version });
124
146
  if (!parsed.success) return refusal(404);
125
147
 
@@ -155,5 +177,14 @@ export async function GET(
155
177
  }
156
178
  out.set(name, value);
157
179
  }
180
+ // #11161 — the preview mode: inline for an image or a PDF, the hub's
181
+ // attachment disposition (already checked above) rewritten in place with
182
+ // the same pinned filename; everything else stays an attachment.
183
+ if (inline && headers.contentType !== null && isInlinePreviewType(headers.contentType)) {
184
+ out.set(
185
+ "Content-Disposition",
186
+ (out.get("Content-Disposition") ?? "").replace(/^[ \t]*attachment/i, "inline"),
187
+ );
188
+ }
158
189
  return new Response(stream, { status: 200, headers: out });
159
190
  }
@@ -19,6 +19,9 @@
19
19
  * - malformed params are a 404 with no call — and `locale`, which Next
20
20
  * always passes, never makes a real request fail;
21
21
  * - refusals map to a status with no body and `private, no-store`;
22
+ * - the preview mode (#11161 AC-4): `?inline=1` answers `inline` for an
23
+ * image or a PDF only — the other four headers unchanged — and
24
+ * `attachment` for every other type, and without the flag always;
22
25
  * - the route reads no topology constant.
23
26
  */
24
27
 
@@ -39,7 +42,9 @@ jest.mock("next/headers", () => ({
39
42
  cookies: (...args: unknown[]) => mockCookies(...args),
40
43
  }));
41
44
 
42
- import { GET } from "../[pieceId]/versions/[version]/file/route";
45
+ import { previewKind } from "@working-theory/templates/account";
46
+
47
+ import { GET, isInlinePreviewType } from "../[pieceId]/versions/[version]/file/route";
43
48
 
44
49
  const SITE = "https://site.example.com";
45
50
  const PIECE = "piece_01920000-0000-7000-8000-000000000001";
@@ -73,10 +78,10 @@ function fileResult(
73
78
  };
74
79
  }
75
80
 
76
- function get(pieceId = PIECE, version = "2"): Promise<Response> {
81
+ function get(pieceId = PIECE, version = "2", query = ""): Promise<Response> {
77
82
  return GET(
78
83
  new Request(
79
- `${SITE}/account/artifacts/${pieceId}/versions/${version}/file`,
84
+ `${SITE}/account/artifacts/${pieceId}/versions/${version}/file${query}`,
80
85
  ),
81
86
  {
82
87
  params: Promise.resolve({ locale: "en", pieceId, version }),
@@ -252,6 +257,74 @@ describe("the version file read", () => {
252
257
  await expectBodylessRefusal(await get(), 502);
253
258
  });
254
259
 
260
+ describe("the preview mode (#11161 AC-4)", () => {
261
+ it.each([
262
+ ["a PDF", "application/pdf"],
263
+ ["a PNG", "image/png"],
264
+ ["a JPEG with a parameter", "image/jpeg; charset=binary"],
265
+ ])("?inline=1 answers %s inline, the pinned filename and the other four headers unchanged", async (_case, contentType) => {
266
+ mockArtifactFile.mockResolvedValue(fileResult({ contentType }));
267
+ const res = await get(PIECE, "2", "?inline=1");
268
+ expect(res.status).toBe(200);
269
+ expect(res.headers.get("content-type")).toBe(contentType);
270
+ expect(res.headers.get("content-disposition")).toBe('inline; filename="brief-v2.pdf"');
271
+ expect(res.headers.get("x-content-type-options")).toBe("nosniff");
272
+ expect(res.headers.get("content-security-policy")).toBe(FILE_HEADERS.contentSecurityPolicy);
273
+ expect(res.headers.get("cache-control")).toBe("private, no-store");
274
+ await expect(res.text()).resolves.toBe("%PDF-1.7 bytes");
275
+ });
276
+
277
+ it.each([
278
+ ["SVG", "image/svg+xml"],
279
+ ["HTML", "text/html"],
280
+ ["a zip", "application/zip"],
281
+ ["an octet stream", "application/octet-stream"],
282
+ ])("?inline=1 keeps %s an attachment", async (_case, contentType) => {
283
+ mockArtifactFile.mockResolvedValue(fileResult({ contentType }));
284
+ const res = await get(PIECE, "2", "?inline=1");
285
+ expect(res.status).toBe(200);
286
+ expect(res.headers.get("content-disposition")).toBe(FILE_HEADERS.contentDisposition);
287
+ });
288
+
289
+ it("without the flag, a PDF stays an attachment; another value of the flag is no flag", async () => {
290
+ expect((await get()).headers.get("content-disposition")).toBe(FILE_HEADERS.contentDisposition);
291
+ expect((await get(PIECE, "2", "?inline=true")).headers.get("content-disposition")).toBe(
292
+ FILE_HEADERS.contentDisposition,
293
+ );
294
+ });
295
+
296
+ it("the preview mode still refuses a hub answer that is not an attachment — it rewrites the checked value, never trusts an inline one", async () => {
297
+ const result = fileResult({ contentDisposition: "inline; filename=a.pdf" });
298
+ mockArtifactFile.mockResolvedValue(result);
299
+ await expectBodylessRefusal(await get(PIECE, "2", "?inline=1"), 502);
300
+ });
301
+
302
+ it.each([
303
+ "application/pdf",
304
+ "Application/PDF",
305
+ " image/png ",
306
+ "image/jpeg; charset=binary",
307
+ "image/webp",
308
+ "image/svg+xml",
309
+ "image/svg+xml;charset=utf-8",
310
+ "text/html",
311
+ "application/pdfx",
312
+ "application/zip",
313
+ "",
314
+ ])("the page's previewKind agrees with the route's inline predicate on %j", (contentType) => {
315
+ expect(previewKind(contentType) !== null).toBe(isInlinePreviewType(contentType));
316
+ });
317
+
318
+ it("isInlinePreviewType admits image/* but SVG and application/pdf, case-insensitively, and nothing else", () => {
319
+ expect(isInlinePreviewType("application/pdf")).toBe(true);
320
+ expect(isInlinePreviewType("Application/PDF")).toBe(true);
321
+ expect(isInlinePreviewType("image/webp")).toBe(true);
322
+ expect(isInlinePreviewType("image/svg+xml")).toBe(false);
323
+ expect(isInlinePreviewType("text/html")).toBe(false);
324
+ expect(isInlinePreviewType("application/pdfx")).toBe(false);
325
+ });
326
+ });
327
+
255
328
  it("reads no topology constant", () => {
256
329
  expect(readFileSync(ROUTE_FILE, "utf8")).not.toContain(
257
330
  "topology.generated",