// Map our internal (productId, sizeId, frameId) tuples to Prodigi v4 // catalogue SKUs + the per-variant attributes Prodigi expects in the // order item payload. // // Prodigi encodes the *size* in the SKU suffix (e.g. `-40X50`) but // keeps the frame finish + mount colour (and, for canvas, the wrap // behaviour) as a separate `attributes` object on the order item — so a // single SKU like `FRA-BOX-EMA-MOUNT1-ACRY-40X50` covers every colour / // mount-colour variant Prodigi offers for that size. // // SKUs verified live against `GET /v4.0/products/` for every size // listed in pricing.ts (May 2026). The webhook will still fail loudly // if a SKU gets rejected — we'd rather catch a mismatch than ship the // wrong frame. import { PRODUCTS, type ProductId } from './pricing'; import { WRAPS, normalizeWrapId } from '../data/frames'; type Tuple = { productId: ProductId; sizeId: string; frameId: string; matteId?: string; wrapId?: string }; type ProdigiItem = { sku: string; attributes: Record }; // Our six in-app frame finishes mapped to Prodigi's catalogue colours. // The matted box frame (FRA-BOX) offers black / brown / natural / white; // FRA-CAN canvas offers those plus gold / silver. The mapping below // resolves to values that exist on the relevant product — and the // Builder only exposes each product's `availableFrames`, so we never // send a colour the chosen product can't fulfil. const FRAME_TO_PRODIGI_COLOR: Record = { black: 'black', white: 'white', walnut: 'brown', oak: 'natural', gold: 'gold', silver: 'silver', // Classic-frame-only finishes. darkgrey: 'dark grey', lightgrey: 'light grey', }; // FRA-BOX (box-frame matted) mount: Prodigi verified 2026-05 to fulfil // THREE mountColor values — "Snow white", "Off-white", "Black". We map // our internal matteId → the exact catalogue string here. (The earlier // CFPM product only ever shipped Snow white regardless of the picker, // which is why the picker was pulled; the move to FRA-BOX restores a // real, fulfillable choice.) // // Attribute key is `mountColor` (American spelling) — Prodigi's catalog // schema. A prior version sent the British `mountColour`, which // Prodigi silently ignored. const MATTE_TO_PRODIGI_MOUNT: Record = { snowwhite: 'Snow white', offwhite: 'Off-white', black: 'Black', // Legacy ids that may live on older orders/drafts: warmwhite: 'Off-white', cream: 'Off-white', hayseed: 'Off-white', none: 'Snow white', }; // "No matte" ships on the box-frame line's No-Mount sibling: // FRA-BOX-EMA-NM-ACRY (same Box moulding, EMA paper, Perspex glaze as // the mounted FRA-BOX-EMA-MOUNT1-ACRY — just NM/no mat instead of a // 1.4mm mount). Same SKU family, same METRIC size codes (40X50, 60X60…) // as the mounted product, so it reuses size.prodigiSize verbatim — just // swap the prefix. It fulfils the same four finishes (black / brown / // natural / white = our black / walnut / oak / white) via // attributes.color, with NO mountColor. Verified live against // GET /products/ for every matted size (Jun 2026). const NO_MAT_PRODIGI_SKU_PREFIX = 'FRA-BOX-EMA-NM-ACRY'; export function prodigiItem(t: Tuple): ProdigiItem { const product = PRODUCTS[t.productId]; const sizes = product.sizes as Record; const size = sizes[t.sizeId]; if (!size) throw new Error(`Unknown size ${t.sizeId} for product ${t.productId}`); // Stretched canvas is frameless: no frame colour, no mat. The only // variant attribute is the edge `wrap` (Image / Mirror / White / Black). if (t.productId === 'stretched') { const wrap = WRAPS[normalizeWrapId(t.wrapId)].prodigi; return { sku: `${product.prodigiSkuPrefix}-${size.prodigiSize}`, attributes: { wrap } }; } const color = FRAME_TO_PRODIGI_COLOR[t.frameId] ?? 'black'; // No-matte box frame → the No-Mount box-frame SKU (same metric size // code as the mounted product). No mountColor; the print fills the // frame edge to edge. if (t.productId === 'matted' && t.matteId === 'nomat') { return { sku: `${NO_MAT_PRODIGI_SKU_PREFIX}-${size.prodigiSize}`, attributes: { color } }; } // Classic Frame: INCH-coded line. No-mat fulfils on GLOBAL-CFP (no // mountColor); mounted fulfils on GLOBAL-CFPM, which only ships a Snow // white mat — so we always send 'Snow white' for the mounted variant // regardless of the picker (the Builder only ever offers Snow white + // No matte for this product). if (t.productId === 'classic') { if (t.matteId === 'nomat') { return { sku: `GLOBAL-CFP-${size.prodigiSize}`, attributes: { color } }; } return { sku: `GLOBAL-CFPM-${size.prodigiSize}`, attributes: { color, mountColor: 'Snow white' } }; } const sku = `${product.prodigiSkuPrefix}-${size.prodigiSize}`; // Canvas needs an explicit `wrap` attribute. ImageWrap mirrors the // composition onto the four sides of the stretcher — the standard // premium look that customers expect from a "float-framed canvas." if (t.productId === 'canvas') { return { sku, attributes: { color, wrap: 'ImageWrap' } }; } // Matted box frame: send the customer's chosen mount colour, mapped to // Prodigi's exact catalogue string. Unknown/missing ids fall back to // Snow white (the safe default the product always offers). const mountColor = MATTE_TO_PRODIGI_MOUNT[t.matteId ?? ''] ?? 'Snow white'; return { sku, attributes: { color, mountColor } }; }