Branchwell

Lumen & Gesso / website · lumengesso.com / app / lib / prodigi-skus.ts

1// Map our internal (productId, sizeId, frameId) tuples to Prodigi v4
2// catalogue SKUs + the per-variant attributes Prodigi expects in the
3// order item payload.
4//
5// Prodigi encodes the *size* in the SKU suffix (e.g. `-40X50`) but
6// keeps the frame finish + mount colour (and, for canvas, the wrap
7// behaviour) as a separate `attributes` object on the order item — so a
8// single SKU like `FRA-BOX-EMA-MOUNT1-ACRY-40X50` covers every colour /
9// mount-colour variant Prodigi offers for that size.
10//
11// SKUs verified live against `GET /v4.0/products/<sku>` for every size
12// listed in pricing.ts (May 2026). The webhook will still fail loudly
13// if a SKU gets rejected — we'd rather catch a mismatch than ship the
14// wrong frame.
15
16import { PRODUCTS, type ProductId } from './pricing';
17import { WRAPS, normalizeWrapId } from '../data/frames';
18
19type Tuple = { productId: ProductId; sizeId: string; frameId: string; matteId?: string; wrapId?: string };
20type ProdigiItem = { sku: string; attributes: Record<string, string> };
21
22// Our six in-app frame finishes mapped to Prodigi's catalogue colours.
23// The matted box frame (FRA-BOX) offers black / brown / natural / white;
24// FRA-CAN canvas offers those plus gold / silver. The mapping below
25// resolves to values that exist on the relevant product — and the
26// Builder only exposes each product's `availableFrames`, so we never
27// send a colour the chosen product can't fulfil.
28const FRAME_TO_PRODIGI_COLOR: Record<string, string> = {
29 black: 'black',
30 white: 'white',
31 walnut: 'brown',
32 oak: 'natural',
33 gold: 'gold',
34 silver: 'silver',
35 // Classic-frame-only finishes.
36 darkgrey: 'dark grey',
37 lightgrey: 'light grey',
38};
39
40// FRA-BOX (box-frame matted) mount: Prodigi verified 2026-05 to fulfil
41// THREE mountColor values — "Snow white", "Off-white", "Black". We map
42// our internal matteId → the exact catalogue string here. (The earlier
43// CFPM product only ever shipped Snow white regardless of the picker,
44// which is why the picker was pulled; the move to FRA-BOX restores a
45// real, fulfillable choice.)
46//
47// Attribute key is `mountColor` (American spelling) — Prodigi's catalog
48// schema. A prior version sent the British `mountColour`, which
49// Prodigi silently ignored.
50const MATTE_TO_PRODIGI_MOUNT: Record<string, string> = {
51 snowwhite: 'Snow white',
52 offwhite: 'Off-white',
53 black: 'Black',
54 // Legacy ids that may live on older orders/drafts:
55 warmwhite: 'Off-white',
56 cream: 'Off-white',
57 hayseed: 'Off-white',
58 none: 'Snow white',
59};
60
61// "No matte" ships on the box-frame line's No-Mount sibling:
62// FRA-BOX-EMA-NM-ACRY (same Box moulding, EMA paper, Perspex glaze as
63// the mounted FRA-BOX-EMA-MOUNT1-ACRY — just NM/no mat instead of a
64// 1.4mm mount). Same SKU family, same METRIC size codes (40X50, 60X60…)
65// as the mounted product, so it reuses size.prodigiSize verbatim — just
66// swap the prefix. It fulfils the same four finishes (black / brown /
67// natural / white = our black / walnut / oak / white) via
68// attributes.color, with NO mountColor. Verified live against
69// GET /products/<sku> for every matted size (Jun 2026).
70const NO_MAT_PRODIGI_SKU_PREFIX = 'FRA-BOX-EMA-NM-ACRY';
71
72export function prodigiItem(t: Tuple): ProdigiItem {
73 const product = PRODUCTS[t.productId];
74 const sizes = product.sizes as Record<string, { prodigiSize: string }>;
75 const size = sizes[t.sizeId];
76 if (!size) throw new Error(`Unknown size ${t.sizeId} for product ${t.productId}`);
77
78 // Stretched canvas is frameless: no frame colour, no mat. The only
79 // variant attribute is the edge `wrap` (Image / Mirror / White / Black).
80 if (t.productId === 'stretched') {
81 const wrap = WRAPS[normalizeWrapId(t.wrapId)].prodigi;
82 return { sku: `${product.prodigiSkuPrefix}-${size.prodigiSize}`, attributes: { wrap } };
83 }
84
85 const color = FRAME_TO_PRODIGI_COLOR[t.frameId] ?? 'black';
86
87 // No-matte box frame → the No-Mount box-frame SKU (same metric size
88 // code as the mounted product). No mountColor; the print fills the
89 // frame edge to edge.
90 if (t.productId === 'matted' && t.matteId === 'nomat') {
91 return { sku: `${NO_MAT_PRODIGI_SKU_PREFIX}-${size.prodigiSize}`, attributes: { color } };
92 }
93
94 // Classic Frame: INCH-coded line. No-mat fulfils on GLOBAL-CFP (no
95 // mountColor); mounted fulfils on GLOBAL-CFPM, which only ships a Snow
96 // white mat — so we always send 'Snow white' for the mounted variant
97 // regardless of the picker (the Builder only ever offers Snow white +
98 // No matte for this product).
99 if (t.productId === 'classic') {
100 if (t.matteId === 'nomat') {
101 return { sku: `GLOBAL-CFP-${size.prodigiSize}`, attributes: { color } };
102 }
103 return { sku: `GLOBAL-CFPM-${size.prodigiSize}`, attributes: { color, mountColor: 'Snow white' } };
104 }
105
106 const sku = `${product.prodigiSkuPrefix}-${size.prodigiSize}`;
107
108 // Canvas needs an explicit `wrap` attribute. ImageWrap mirrors the
109 // composition onto the four sides of the stretcher — the standard
110 // premium look that customers expect from a "float-framed canvas."
111 if (t.productId === 'canvas') {
112 return { sku, attributes: { color, wrap: 'ImageWrap' } };
113 }
114
115 // Matted box frame: send the customer's chosen mount colour, mapped to
116 // Prodigi's exact catalogue string. Unknown/missing ids fall back to
117 // Snow white (the safe default the product always offers).
118 const mountColor = MATTE_TO_PRODIGI_MOUNT[t.matteId ?? ''] ?? 'Snow white';
119 return { sku, attributes: { color, mountColor } };
120}