version.id)}
+ rows={project.versions.map((version) => [
+ version.version,
+ <>{version.filename} · {new Date(version.createdAt).toLocaleString()}
+ Version identifiers
ID {version.id}
SHA-256 {version.sha256}
>,
+ version.decision ? <>{version.decision.outcome} · {version.decision.note}
+ Reviewed {new Date(version.decision.createdAt).toLocaleString()} by {version.decision.reviewerId}
> : "Pending",
+ (reviewer || version.uploadedById === userId || version.decision?.outcome === "APPROVED") &&
+ ,
+ ])} />
+ {pending && reviewer && (latest.uploadedById === userId ?
+ A different staff member must review this version. :
+ )}
+ {can("b2b.artwork.manage") && <>
+ {uncertain &&
+ The server may have saved the file. Check the version history before attempting another upload.
+
+ }
+ {pending ? The latest version needs a review decision before another file can be uploaded.
:
+ project.versions.length >= 20 ? This project has reached the 20-version limit.
:
+ !uncertain && prepareArtworkUpload(data.get("file"))}
+ submit={async (body) => {
+ try {
+ await request(`${path}/versions`, artworkVersion, { method: "POST", body });
+ } catch (error) {
+ if (isUnknownOutcome(error)) setUncertain(true);
+ throw error;
+ } finally {
+ await query.refetch();
+ }
+ }}>
+
+
+ Choose a PDF, PNG, or JPEG up to 2 MiB with a simple filename.
+ }
+ >}
+
+ ;
+ }};
+}
+
+function ReviewArtwork({ version, refresh }: { version: Version; refresh: () => Promise }) {
+ const { request } = usePlatform();
+ return artworkDecision.parse({
+ outcome: readText(data, "outcome"), note: readText(data, "note"),
+ })} submit={async (body) => {
+ try {
+ await request(`/b2b/artwork-versions/${version.id}/decision`, artworkVersion, { method: "POST", body });
+ } finally {
+ await refresh();
+ }
+ }}>
+ Review version {version.version}. The decision is permanent and applies to this file.
+
+
+ ;
+}
+
+function DownloadArtwork({ version }: { version: Version }) {
+ const { downloadArtwork } = usePlatform();
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState(null);
+ return <>
+
+
+ >;
+}
+
+export default function ArtworkPage({ id, accountId, create = false }: { id?: string; accountId?: string; create?: boolean }) {
+ const project = uuid.safeParse(id);
+ const account = uuid.safeParse(accountId);
+ return
+ {(id || accountId || create) && All artwork projects}
+ {(id && !project.success) || (accountId && !account.success) ? Invalid project or business account ID. :
+ create ? :
+ project.success ? :
+ }
+ ;
+}
diff --git a/src/pages/BusinessAccountsPage.tsx b/src/pages/BusinessAccountsPage.tsx
index 7f6e04b..ef594ad 100644
--- a/src/pages/BusinessAccountsPage.tsx
+++ b/src/pages/BusinessAccountsPage.tsx
@@ -129,6 +129,9 @@ function Details({ id, refreshDirectory }: { id: string; refreshDirectory: () =>
{can("b2b.sample.read") && Business sample requests
}
{account.status === "VERIFIED" && can("b2b.sample.read") && can("b2b.sample.request") &&
Request samples for this business
}
+ {can("b2b.artwork.read") && Business artwork projects
}
+ {account.status === "VERIFIED" && can("b2b.artwork.read") && can("b2b.artwork.manage") &&
+ Create artwork project for this business
}
diff --git a/test/api.test.ts b/test/api.test.ts
index 8ce6ded..8edc3e4 100644
--- a/test/api.test.ts
+++ b/test/api.test.ts
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
import {
apiRequest,
apiPdf,
+ apiArtwork,
listProducts,
getProduct,
login,
@@ -57,6 +58,50 @@ test("private PDF downloads preserve API denial and require the expected PDF med
globalThis.fetch = async () => Response.json({ code: "DOCUMENT_PENDING_REVIEW" }, { status: 403 });
await assert.rejects(apiPdf(path, content.length, "opaque", controller.signal), { code: "DOCUMENT_PENDING_REVIEW", status: 403 });
});
+test("private artwork downloads authenticate and enforce the declared file type and size", async () => {
+ const controller = new AbortController();
+ const content = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
+ const mimeType = "image/png";
+ globalThis.fetch = async (url, options) => {
+ assert.equal(url, `/api/v1/b2b/artwork-versions/${org}/download`);
+ const headers = new Headers(options?.headers);
+ assert.equal(headers.get("authorization"), "Bearer opaque");
+ assert.equal(headers.get("accept"), mimeType);
+ assert.equal(options?.cache, "no-store");
+ assert.equal(options?.redirect, "error");
+ assert.equal(options?.signal?.aborted, false);
+ return new Response(content, { headers: { "Content-Type": mimeType } });
+ };
+ const file = await apiArtwork(org, content.length, mimeType, "opaque", controller.signal);
+ assert.deepEqual(new Uint8Array(await file.arrayBuffer()), content);
+ await assert.rejects(apiArtwork(org, 1, mimeType, "opaque", controller.signal), { code: "INVALID_RESPONSE" });
+
+ globalThis.fetch = async () =>
+ new Response(content, { headers: { "Content-Type": "image/jpeg" } });
+ await assert.rejects(apiArtwork(org, content.length, mimeType, "opaque", controller.signal), { code: "INVALID_RESPONSE" });
+ globalThis.fetch = async () => Response.json({ code: "B2B_ARTWORK_DOWNLOAD_DENIED" }, { status: 403 });
+ await assert.rejects(apiArtwork(org, content.length, mimeType, "opaque", controller.signal), {
+ code: "B2B_ARTWORK_DOWNLOAD_DENIED", status: 403,
+ });
+});
+
+test("artwork download validates metadata before fetch and propagates aborts", async () => {
+ const controller = new AbortController();
+ globalThis.fetch = async () => {
+ assert.fail("Invalid artwork metadata must not send a request");
+ };
+ await assert.rejects(apiArtwork("../auth/me", 1, "application/pdf", "opaque", controller.signal), { name: "ZodError" });
+ await assert.rejects(apiArtwork(org, 1, "text/html", "opaque", controller.signal), { name: "ZodError" });
+ await assert.rejects(apiArtwork(org, 2 * 1024 * 1024 + 1, "image/jpeg", "opaque", controller.signal), { name: "ZodError" });
+ globalThis.fetch = async (_url, options) => {
+ const signal = options?.signal;
+ assert.ok(signal);
+ controller.abort(new Error("Test abort"));
+ assert.equal(signal.aborted, true);
+ throw new DOMException("Request cancelled", "AbortError");
+ };
+ await assert.rejects(apiArtwork(org, 1, "image/jpeg", "opaque", controller.signal), { name: "AbortError" });
+});
test("invalid organization cannot trigger catalog requests", async () => {
globalThis.fetch = async () => {
assert.fail("Must not send a request");
diff --git a/test/artwork.test.ts b/test/artwork.test.ts
new file mode 100644
index 0000000..c7e5b05
--- /dev/null
+++ b/test/artwork.test.ts
@@ -0,0 +1,57 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import {
+ artworkDecision,
+ artworkDetails,
+ artworkInput,
+ artworkProject,
+ artworkVersion,
+ maxArtworkBytes,
+ prepareArtworkUpload,
+} from "../src/lib/artwork.ts";
+
+const id = "d66c798a-f764-4b88-8d13-ace328ff1010";
+const date = "2026-11-16T00:00:00.000Z";
+const input = { accountId: id, name: "Brand refresh", placement: "LABEL", brief: "Use the supplied customer logo." };
+const version = {
+ id, artworkId: id, uploadedById: id, version: 1, filename: "brand-proof.jpeg",
+ mimeType: "image/jpeg", sha256: "a".repeat(64), size: 10, createdAt: date, decision: null,
+};
+
+test("artwork creation and decisions enforce placement and trimmed plain-text notes", () => {
+ assert.deepEqual(artworkInput.parse({ ...input, name: " Brand refresh " }), input);
+ assert.equal(artworkInput.safeParse({ ...input, placement: "BANNER" }).success, false);
+ assert.equal(artworkInput.safeParse({ ...input, brief: " " }).success, false);
+ assert.equal(artworkInput.safeParse({ ...input, brief: "" }).success, false);
+ assert.deepEqual(artworkDecision.parse({ outcome: "APPROVED", note: " Looks good " }), { outcome: "APPROVED", note: "Looks good" });
+ assert.equal(artworkDecision.safeParse({ outcome: "REJECTED", note: "" }).success, false);
+});
+
+test("project and version reads retain safe metadata and strip payload bytes", () => {
+ const project = { ...input, id, createdAt: date };
+ assert.deepEqual(artworkProject.parse({ ...project, organizationId: id }), project);
+ assert.deepEqual(artworkDetails.parse({ ...project, versions: [{ ...version, content: [1, 2, 3] }] }),
+ { ...project, versions: [version] });
+ const decision = { outcome: "APPROVED", note: "Reviewed the final logo", reviewerId: id, createdAt: date };
+ assert.equal(artworkVersion.parse({ ...version, decision }).decision?.reviewerId, id);
+ assert.equal(artworkVersion.safeParse({ ...version, mimeType: "image/svg+xml" }).success, false);
+ assert.equal(artworkVersion.safeParse({ ...version, mimeType: "application/pdf" }).success, false);
+ assert.equal(artworkVersion.safeParse({ ...version, size: maxArtworkBytes + 1 }).success, false);
+});
+
+test("artwork uploads use a single multipart file with the permitted media type", () => {
+ for (const [filename, type] of [["proof.pdf", "application/pdf"], ["proof.png", "image/png"], ["proof.jpg", "image/jpeg"], ["proof.jpeg", "image/jpeg"]]) {
+ const form = prepareArtworkUpload(new File(["bytes"], filename, { type }));
+ const selected = form.get("file");
+ assert.ok(selected instanceof File);
+ assert.equal(selected.name, filename);
+ assert.equal(selected.type, type);
+ assert.deepEqual([...form.keys()], ["file"]);
+ }
+ assert.equal((prepareArtworkUpload(new File(["bytes"], "proof.png")).get("file") as File).type, "image/png");
+ assert.throws(() => prepareArtworkUpload(null));
+ assert.throws(() => prepareArtworkUpload(new File(["bytes"], "public.svg", { type: "image/svg+xml" })));
+ assert.throws(() => prepareArtworkUpload(new File(["bytes"], "unsafe name.png", { type: "image/png" })));
+ assert.throws(() => prepareArtworkUpload(new File(["bytes"], "wrong.png", { type: "image/jpeg" })));
+ assert.throws(() => prepareArtworkUpload(new File([new Uint8Array(maxArtworkBytes + 1)], "large.pdf", { type: "application/pdf" })));
+});
diff --git a/test/artwork.ui.test.tsx b/test/artwork.ui.test.tsx
new file mode 100644
index 0000000..5943023
--- /dev/null
+++ b/test/artwork.ui.test.tsx
@@ -0,0 +1,182 @@
+import { type ReactNode } from "react";
+import { fireEvent, render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { ThemeProvider } from "@mui/material/styles";
+import { afterEach, expect, test, vi } from "vitest";
+import { Route, Switch } from "wouter";
+import { PlatformProvider, usePlatform } from "../src/lib/platform";
+import ArtworkPage from "../src/pages/ArtworkPage";
+import theme from "../src/theme";
+
+const accountId = "d66c798a-f764-4b88-8d13-ace328ff1010";
+const artworkId = "d66c798a-f764-4b88-8d13-ace328ff1011";
+const firstVersionId = "d66c798a-f764-4b88-8d13-ace328ff1012";
+const secondVersionId = "d66c798a-f764-4b88-8d13-ace328ff1013";
+const uploaderId = "d66c798a-f764-4b88-8d13-ace328ff1014";
+const reviewerId = "d66c798a-f764-4b88-8d13-ace328ff1015";
+const createdAt = "2026-11-16T08:00:00.000Z";
+const api = "/b2b/artworks";
+const path = `${api}/${artworkId}`;
+const route = "/admin/b2b-artwork";
+const project = {
+ id: artworkId, accountId, name: "Seasonal gift branding", placement: "PACKAGING",
+ brief: "Use the supplied mark on a matte kraft box", createdAt,
+};
+const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
+const first = {
+ id: firstVersionId, artworkId, uploadedById: uploaderId, version: 1, filename: "artwork-v1.png",
+ mimeType: "image/png", size: png.length, sha256: "a".repeat(64), createdAt,
+};
+const pendingVersion = { ...first, version: 2, id: secondVersionId, filename: "artwork-v2.png", decision: null };
+const previousVersion = {
+ ...first,
+ decision: { outcome: "APPROVED", note: "Original file approved", reviewerId, createdAt },
+};
+const json = (body: unknown) => new Response(JSON.stringify(body));
+
+function staffSession(url: string, userId: string, permissions: string[]) {
+ if (url.endsWith("/auth/login")) {
+ return json({
+ accessToken: "test-opaque", tokenType: "Bearer",
+ expiresAt: new Date(Date.now() + 3_600_000).toISOString(),
+ });
+ }
+ if (url.endsWith("/auth/me")) return json({ userId, organizationId: accountId, sessionId: accountId, permissions });
+}
+
+function Login() {
+ const { signIn } = usePlatform();
+ return ;
+}
+
+function showArtwork(children: ReactNode) {
+ localStorage.setItem("mani.organization", accountId);
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ render(
+
+ {children}
+
+ );
+}
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+ history.replaceState(null, "", "/");
+});
+
+test("artwork readers can download approved versions but cannot download pending versions", async () => {
+ const fetch = vi.fn(async (url: string) => {
+ const auth = staffSession(url, reviewerId, ["b2b.artwork.read"]);
+ if (auth) return auth;
+ if (url.endsWith(path)) return json({ ...project, versions: [pendingVersion, previousVersion] });
+ throw new Error(`Unexpected request ${url}`);
+ });
+ vi.stubGlobal("fetch", fetch);
+ showArtwork();
+ expect(fetch).not.toHaveBeenCalled();
+
+ const user = userEvent.setup();
+ await user.click(screen.getByRole("button", { name: "Test login" }));
+ await screen.findByRole("button", { name: "Download artwork version 1" });
+ expect(screen.getByText(/^artwork-v2\.png /)).toBeTruthy();
+ expect(screen.queryByRole("button", { name: "Download artwork version 2" })).toBeNull();
+ expect(screen.queryByRole("button", { name: "Record artwork decision" })).toBeNull();
+ expect(screen.queryByRole("button", { name: "Upload artwork version" })).toBeNull();
+});
+
+test("the uploader can download their pending file and must wait for independent review", async () => {
+ vi.stubGlobal("fetch", vi.fn(async (url: string) => {
+ const auth = staffSession(url, uploaderId, ["b2b.artwork.read", "b2b.artwork.manage", "b2b.artwork.review"]);
+ if (auth) return auth;
+ if (url.endsWith(path)) return json({ ...project, versions: [pendingVersion, previousVersion] });
+ throw new Error(`Unexpected request ${url}`);
+ }));
+ showArtwork();
+ const user = userEvent.setup();
+ await user.click(screen.getByRole("button", { name: "Test login" }));
+ await screen.findByText("A different staff member must review this version.");
+ expect(screen.getByRole("button", { name: "Download artwork version 2" })).toBeTruthy();
+ expect(screen.queryByRole("button", { name: "Record artwork decision" })).toBeNull();
+ expect(screen.queryByRole("button", { name: "Upload artwork version" })).toBeNull();
+});
+
+test("an independent reviewer can approve the latest artwork version", async () => {
+ const note = "Brand mark is legible";
+ let submitted: unknown;
+ let current: typeof pendingVersion | typeof previousVersion = pendingVersion;
+ vi.stubGlobal("fetch", vi.fn(async (url: string, options?: RequestInit) => {
+ const auth = staffSession(url, reviewerId, ["b2b.artwork.read", "b2b.artwork.review"]);
+ if (auth) return auth;
+ if (url.endsWith(path)) return json({ ...project, versions: [current, previousVersion] });
+ if (url.endsWith(`/b2b/artwork-versions/${secondVersionId}/decision`) && options?.method === "POST") {
+ submitted = JSON.parse(String(options.body));
+ current = { ...pendingVersion, decision: { outcome: "APPROVED", note, reviewerId, createdAt } };
+ return json(current);
+ }
+ throw new Error(`Unexpected request ${url}`);
+ }));
+ showArtwork();
+ const user = userEvent.setup();
+ await user.click(screen.getByRole("button", { name: "Test login" }));
+ await user.selectOptions(await screen.findByRole("combobox", { name: /Review decision/ }), "APPROVED");
+ await user.type(screen.getByRole("textbox", { name: /Review note/ }), note);
+ await user.click(screen.getByRole("button", { name: "Record artwork decision" }));
+ await screen.findByText(new RegExp(note));
+ expect(submitted).toEqual({ outcome: "APPROVED", note });
+ expect(screen.getByText(/Original file approved/)).toBeTruthy();
+ expect(screen.queryByRole("button", { name: "Record artwork decision" })).toBeNull();
+});
+
+test("a staff member can create a project and upload its first private PNG version", async () => {
+ const version = { ...first, decision: null };
+ let projectBody: unknown;
+ let uploadBody: FormData | undefined;
+ // jsdom reads its internal file list when constructing FormData, while user-event exposes the selected file on the input.
+ vi.stubGlobal("FormData", class extends FormData {
+ constructor(form?: HTMLFormElement) {
+ super(form);
+ const file = form?.querySelector("input[type=file]")?.files?.[0];
+ if (file) this.set("file", file);
+ }
+ });
+ vi.stubGlobal("fetch", vi.fn(async (url: string, options?: RequestInit) => {
+ const auth = staffSession(url, uploaderId, ["b2b.artwork.read", "b2b.artwork.manage"]);
+ if (auth) return auth;
+ if (url.endsWith(api) && options?.method === "POST") {
+ projectBody = JSON.parse(String(options.body));
+ return json(project);
+ }
+ if (url.endsWith(path)) return json({ ...project, versions: uploadBody ? [version] : [] });
+ if (url.endsWith(`${path}/versions`) && options?.method === "POST" && options.body instanceof FormData) {
+ uploadBody = options.body;
+ return json(version);
+ }
+ throw new Error(`Unexpected request ${url}`);
+ }));
+ history.replaceState(null, "", `${route}/new/${accountId}`);
+ showArtwork(
+
+ {(params) => }
+
+ {(params) => }
+ );
+
+ const user = userEvent.setup();
+ await user.click(screen.getByRole("button", { name: "Test login" }));
+ await user.type(await screen.findByRole("textbox", { name: /Project name/ }), project.name);
+ await user.selectOptions(screen.getByRole("combobox", { name: /Artwork placement/ }), project.placement);
+ await user.type(screen.getByRole("textbox", { name: /Artwork brief/ }), project.brief);
+ await user.click(screen.getByRole("button", { name: "Create artwork project" }));
+ const input = await screen.findByLabelText(/Artwork file/);
+ const file = new File([png], first.filename, { type: first.mimeType });
+ await user.upload(input, file);
+ expect(input.files?.[0]).toBe(file);
+ // The native required check also reads jsdom's internal list, so start at the submit event.
+ fireEvent.submit(screen.getByRole("form", { name: "Upload artwork version" }));
+ await screen.findByRole("button", { name: "Download artwork version 1" });
+ expect(location.pathname).toBe(`${route}/${artworkId}`);
+ expect(projectBody).toEqual({ accountId, name: project.name, placement: project.placement, brief: project.brief });
+ expect(uploadBody?.get("file")).toMatchObject({ name: first.filename, type: first.mimeType, size: png.length });
+ expect(screen.queryByRole("button", { name: "Upload artwork version" })).toBeNull();
+});