@snowcone-app/mockup-resolver 1.0.11 → 1.0.12
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.
- package/CHANGELOG.md +7 -0
- package/package.json +4 -4
- package/src/index.ts +18 -12
- package/src/loadtest-exempt.ts +1 -1
- package/src/resolve.ts +46 -2
- package/test/render-limits.test.ts +3 -3
- package/test/resolve.test.ts +62 -0
- package/wrangler.jsonc +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @snowcone-app/mockup-resolver
|
|
2
2
|
|
|
3
|
+
## 1.0.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`126e84a`](https://github.com/snowcone-app/snowcone-monorepo/commit/126e84a5ab7e7e5d5cd60e37311bd8c3daca07d8)]:
|
|
8
|
+
- @snowcone-app/mockup-url@0.6.1
|
|
9
|
+
|
|
3
10
|
## 1.0.11
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowcone-app/mockup-resolver",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "URL signing and verification Cloudflare Worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@snowcone-app/mockup-url": "0.6.
|
|
9
|
+
"@snowcone-app/mockup-url": "0.6.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@cloudflare/workers-types": "^4.20250303.0",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"node-fetch": "^3.3.2",
|
|
17
17
|
"tsx": "^4.19.3",
|
|
18
18
|
"typescript": "^5.6.2",
|
|
19
|
-
"vite": "^5.
|
|
20
|
-
"vitest": "^2.
|
|
19
|
+
"vite": "^5.4.21",
|
|
20
|
+
"vitest": "^2.1.9",
|
|
21
21
|
"wrangler": "^3.37.0"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -48,7 +48,7 @@ interface RateLimiterStub extends DurableObjectStub {
|
|
|
48
48
|
// Interface for environment bindings
|
|
49
49
|
interface Env {
|
|
50
50
|
URL_SIGNING_SECRET: string;
|
|
51
|
-
/** Comma-separated client IPs exempt from the per-IP public caps (
|
|
51
|
+
/** Comma-separated client IPs exempt from the per-IP public caps (relay-lax-1 running the load generator). Exact match only; change via PR. */
|
|
52
52
|
LOADTEST_EXEMPT_IPS?: string;
|
|
53
53
|
/**
|
|
54
54
|
* rc#262 — Ed25519 seal signing key (PKCS#8 DER, base64). When SET, every
|
|
@@ -1748,6 +1748,7 @@ async function handlePublicResolve(
|
|
|
1748
1748
|
// 2026-09-06). Named, with the valid values, like unknown placement keys.
|
|
1749
1749
|
let vr: VariantResolution;
|
|
1750
1750
|
let scene: ResolveDefaults;
|
|
1751
|
+
let previewVariantHeader: string | undefined;
|
|
1751
1752
|
if (bundleScene) {
|
|
1752
1753
|
vr = { variantId: bundleScene.variantToken, optionSelections: bundleScene.optionSelections };
|
|
1753
1754
|
scene = {
|
|
@@ -1778,16 +1779,18 @@ async function handlePublicResolve(
|
|
|
1778
1779
|
if (!resolvedVariant) {
|
|
1779
1780
|
return errResp(422, `Product ${productCode} has no renderable combination`);
|
|
1780
1781
|
}
|
|
1781
|
-
vr = resolvedVariant;
|
|
1782
1782
|
const resolvedScene = resolveDefaults(product, {
|
|
1783
|
-
variant:
|
|
1783
|
+
variant: resolvedVariant.variantId,
|
|
1784
1784
|
mockupId: mockupOverride,
|
|
1785
1785
|
placement: placementOverride,
|
|
1786
|
+
variantIsDefault: !variantOverride && Object.keys(optionPicks).length === 0,
|
|
1786
1787
|
});
|
|
1787
1788
|
if (!resolvedScene) {
|
|
1788
1789
|
return errResp(422, `Product ${productCode} has no renderable combination`);
|
|
1789
1790
|
}
|
|
1791
|
+
vr = { ...resolvedVariant, variantId: resolvedScene.variantId };
|
|
1790
1792
|
scene = resolvedScene;
|
|
1793
|
+
if (resolvedScene.previewFor) previewVariantHeader = `${resolvedScene.variantId}; for=${resolvedScene.previewFor}`;
|
|
1791
1794
|
// page=N selects which album page feeds the scene: the resolved default
|
|
1792
1795
|
// placement becomes the repeating page placement's geometry.
|
|
1793
1796
|
if (pagePlacement) scene.placement = pagePlacement;
|
|
@@ -1834,14 +1837,15 @@ async function handlePublicResolve(
|
|
|
1834
1837
|
});
|
|
1835
1838
|
}
|
|
1836
1839
|
} else if (catalogDesign.asset) {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
}
|
|
1840
|
+
// One flattened design and no per-placement map: the design names no placement, so it is the SPREAD — seeded
|
|
1841
|
+
// on every placement exactly as a bare `asset=` is (assembleArtwork). Labelling it with the scene's default
|
|
1842
|
+
// placement alone made it look chosen, and a chosen label prints there only (the placement rule, 2026-11-10):
|
|
1843
|
+
// a hardcover would show its back cover alone.
|
|
1844
|
+
const assembled = assembleArtwork(renderProduct, { asset: catalogDesign.asset, design: {}, house, findPlacement });
|
|
1845
|
+
if (!assembled.ok) {
|
|
1846
|
+
return errResp(assembled.status, assembled.message, assembled.code);
|
|
1847
|
+
}
|
|
1848
|
+
designElements.push(...assembled.elements);
|
|
1845
1849
|
}
|
|
1846
1850
|
} else {
|
|
1847
1851
|
// ADR-0089 base+override: the scalar `asset=` SEEDS every placement (each
|
|
@@ -1990,6 +1994,8 @@ async function handlePublicResolve(
|
|
|
1990
1994
|
const edgeTotalMs = Number((/(?:^|[ ,])edge_total;dur=([0-9.]+)/.exec(edgeRes.headers.get("Server-Timing") || "") || [])[1] ?? NaN);
|
|
1991
1995
|
const hopMs = Number.isFinite(edgeTotalMs) ? Math.max(0, Math.round(edgeWallMs - edgeTotalMs)) : edgeWallMs;
|
|
1992
1996
|
const headers = new Headers(edgeRes.headers);
|
|
1997
|
+
// a chosen size with no scene rendered its listed size sibling: said, machine-readable (never a silent swap)
|
|
1998
|
+
if (previewVariantHeader) headers.set("X-Preview-Variant", previewVariantHeader);
|
|
1993
1999
|
// Revalidation (ADR-0096 amendment, 2026-09-04): the edge stamps the render
|
|
1994
2000
|
// key as a strong ETag and answers If-None-Match with a 304 — the browser's
|
|
1995
2001
|
// header rides through on `request.headers` above. A 304 is a SUCCESS here:
|
|
@@ -2011,7 +2017,7 @@ async function handlePublicResolve(
|
|
|
2011
2017
|
// encoder choice off cross-origin responses.
|
|
2012
2018
|
headers.set(
|
|
2013
2019
|
"Access-Control-Expose-Headers",
|
|
2014
|
-
"ETag, Server-Timing, X-Render-Box, X-Render-Pinned, X-Render-Overflow, X-Encoder"
|
|
2020
|
+
"ETag, Server-Timing, X-Render-Box, X-Render-Pinned, X-Render-Overflow, X-Encoder, X-Preview-Variant"
|
|
2015
2021
|
);
|
|
2016
2022
|
headers.append(
|
|
2017
2023
|
"Server-Timing",
|
package/src/loadtest-exempt.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Per-IP public rate-limit exemption for our own load
|
|
1
|
+
/** Per-IP public rate-limit exemption for our own load generator (relay-lax-1).
|
|
2
2
|
* Exact-IP match only: no CIDR, no wildcards. The list is a plain wrangler var. */
|
|
3
3
|
export function isLoadtestExempt(clientIp: string, list: string | undefined): boolean {
|
|
4
4
|
if (!list || !clientIp || clientIp === "unknown-ip") return false;
|
package/src/resolve.ts
CHANGED
|
@@ -200,6 +200,36 @@ export interface ResolveDefaults {
|
|
|
200
200
|
variantId: string;
|
|
201
201
|
mockupId: string;
|
|
202
202
|
placement: ResolvedPlacement;
|
|
203
|
+
/** Set when the render uses a different variant than the one asked for (a size the mockup lists no scene for
|
|
204
|
+
* previews its listed size sibling): the asked variant. The response says so in X-Preview-Variant. */
|
|
205
|
+
previewFor?: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const SIZE_ATTRIBUTE = /^size$/i;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The variant this mockup lists that differs from `variantId` ONLY by size (the SDK's resolvePreviewVariantId rule,
|
|
212
|
+
* #4074, applied where a public URL resolves). Scenes exist only for the variants a mockup lists and a size doesn't
|
|
213
|
+
* change the picture, so `opt.size=M` on a mockup built for S renders S, never a 503 E_SCENE_NOT_COMPILED. Anything
|
|
214
|
+
* else about the row must match, so a colour (a combination attribute) is never swapped. null: no such sibling.
|
|
215
|
+
*/
|
|
216
|
+
export function listedSizeSibling(product: Pick<ResolvedProduct, "combinations">, mockup: { gvids: string[] }, variantId: string): string | null {
|
|
217
|
+
const rows = product.combinations ?? [];
|
|
218
|
+
const asked = rows.find((r) => r.variantId === variantId);
|
|
219
|
+
if (!asked) return null;
|
|
220
|
+
const sizeKey = Object.keys(asked.options).find((k) => SIZE_ATTRIBUTE.test(k));
|
|
221
|
+
if (!sizeKey) return null;
|
|
222
|
+
const others = (o: Record<string, string>) => Object.keys(o).filter((k) => k !== sizeKey).sort();
|
|
223
|
+
const sameExceptSize = (r: { options: Record<string, string> }) => {
|
|
224
|
+
const a = others(asked.options), b = others(r.options);
|
|
225
|
+
return a.length === b.length && a.every((k, i) => k === b[i] && r.options[k] === asked.options[k]);
|
|
226
|
+
};
|
|
227
|
+
// the mockup's own order: its first listed gvid is the one it was built for
|
|
228
|
+
for (const g of mockup.gvids) {
|
|
229
|
+
const r = rows.find((x) => x.variantId === g);
|
|
230
|
+
if (r && sameExceptSize(r)) return g;
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
203
233
|
}
|
|
204
234
|
|
|
205
235
|
export interface VariantResolution {
|
|
@@ -577,7 +607,13 @@ function toResolvedProduct(raw: RawProduct, version: string, renderVersion: stri
|
|
|
577
607
|
*/
|
|
578
608
|
export function resolveDefaults(
|
|
579
609
|
product: ResolvedProduct,
|
|
580
|
-
overrides: {
|
|
610
|
+
overrides: {
|
|
611
|
+
variant?: string;
|
|
612
|
+
mockupId?: string;
|
|
613
|
+
placement?: string;
|
|
614
|
+
/** Nobody chose this variant (no `variant=`, no option picks): it may follow the mockup to one with a scene. */
|
|
615
|
+
variantIsDefault?: boolean;
|
|
616
|
+
}
|
|
581
617
|
): ResolveDefaults | null {
|
|
582
618
|
const variantId =
|
|
583
619
|
overrides.variant ?? product.defaultGvid ?? product.variants[0]?.gvid;
|
|
@@ -590,6 +626,14 @@ export function resolveDefaults(
|
|
|
590
626
|
product.mockups.find((m) => m.gvids.includes(variantId)) ??
|
|
591
627
|
product.mockups[0];
|
|
592
628
|
if (!mockup) return null;
|
|
629
|
+
// Scenes exist only for the variants a mockup lists. A default that isn't listed is a broken image nobody asked for
|
|
630
|
+
// (XTNA6J's home card, 2026-11); a variant someone chose is theirs, and may be a colour, so it is never swapped.
|
|
631
|
+
// A chosen SIZE with no scene previews the listed size sibling (declared in X-Preview-Variant), never a 503.
|
|
632
|
+
const listed = mockup.gvids.length === 0 || mockup.gvids.includes(variantId);
|
|
633
|
+
const sibling = listed ? null : listedSizeSibling(product, mockup, variantId);
|
|
634
|
+
const renderVariantId = listed
|
|
635
|
+
? variantId
|
|
636
|
+
: sibling ?? (overrides.variantIsDefault ? mockup.gvids[0] : variantId);
|
|
593
637
|
|
|
594
638
|
const placement =
|
|
595
639
|
(overrides.placement
|
|
@@ -597,7 +641,7 @@ export function resolveDefaults(
|
|
|
597
641
|
: undefined) ?? product.placements[0];
|
|
598
642
|
if (!placement) return null;
|
|
599
643
|
|
|
600
|
-
return { variantId, mockupId: mockup.id, placement };
|
|
644
|
+
return { variantId: renderVariantId, mockupId: mockup.id, placement, ...(renderVariantId !== variantId ? { previewFor: variantId } : {}) };
|
|
601
645
|
}
|
|
602
646
|
|
|
603
647
|
export interface UnknownOptionPick {
|
|
@@ -20,15 +20,15 @@ import {
|
|
|
20
20
|
* stated here so nobody reads a green run as "cross-checked".
|
|
21
21
|
*/
|
|
22
22
|
describe('MAX_DESIGN_ELEMENTS drift pin (resolver ↔ buy ↔ render box)', () => {
|
|
23
|
-
it('pins the literal the render box enforces (rendercenter shared CACHE_LIMITS.MAX_ELEMENTS =
|
|
24
|
-
expect(MAX_DESIGN_ELEMENTS).toBe(
|
|
23
|
+
it('pins the literal the render box enforces (rendercenter shared CACHE_LIMITS.MAX_ELEMENTS = 24)', () => {
|
|
24
|
+
expect(MAX_DESIGN_ELEMENTS).toBe(24)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it('matches the submodule copy when services/rendercenter is checked out (literal-only in CI)', () => {
|
|
28
28
|
const typesTs = resolve(__dirname, '../../../services/rendercenter/shared/src/types.ts')
|
|
29
29
|
if (!existsSync(typesTs)) {
|
|
30
30
|
// Submodule absent (CI): the literal pin above is the assertion.
|
|
31
|
-
expect(MAX_DESIGN_ELEMENTS).toBe(
|
|
31
|
+
expect(MAX_DESIGN_ELEMENTS).toBe(24)
|
|
32
32
|
return
|
|
33
33
|
}
|
|
34
34
|
const m = /MAX_ELEMENTS:\s*(\d+)/.exec(readFileSync(typesTs, 'utf8'))
|
package/test/resolve.test.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type ResolvedPlacement,
|
|
11
11
|
type ResolvedProduct,
|
|
12
12
|
fetchProduct,
|
|
13
|
+
resolveDefaults,
|
|
13
14
|
} from "../src/resolve";
|
|
14
15
|
|
|
15
16
|
// A size×color-style product WITH combinations (picks select the SKU).
|
|
@@ -703,3 +704,64 @@ describe("expandIngestHandles", () => {
|
|
|
703
704
|
expect(r.ok && r.expanded.size).toBe(0);
|
|
704
705
|
});
|
|
705
706
|
});
|
|
707
|
+
|
|
708
|
+
describe("resolveDefaults: a variant nobody chose follows the mockup to one with a scene", () => {
|
|
709
|
+
const product = {
|
|
710
|
+
defaultGvid: "stale",
|
|
711
|
+
variants: [{ gvid: "stale" }],
|
|
712
|
+
mockups: [{ id: "M1", gvids: ["built"] }, { id: "M2", gvids: [] }],
|
|
713
|
+
placements: [{ label: "Front" }],
|
|
714
|
+
} as unknown as Parameters<typeof resolveDefaults>[0];
|
|
715
|
+
|
|
716
|
+
it("default not listed: uses the mockup's listed variant (XTNA6J's stale defaultGvid)", () => {
|
|
717
|
+
expect(resolveDefaults(product, { variant: "stale", variantIsDefault: true })?.variantId).toBe("built");
|
|
718
|
+
});
|
|
719
|
+
it("a chosen variant is never swapped: it may be a colour", () => {
|
|
720
|
+
expect(resolveDefaults(product, { variant: "chosen" })?.variantId).toBe("chosen");
|
|
721
|
+
expect(resolveDefaults(product, { variant: "chosen", mockupId: "M1" })?.variantId).toBe("chosen");
|
|
722
|
+
});
|
|
723
|
+
it("default already listed stays", () => {
|
|
724
|
+
expect(resolveDefaults(product, { variant: "built", variantIsDefault: true })?.variantId).toBe("built");
|
|
725
|
+
});
|
|
726
|
+
it("a mockup listing nothing keeps the default", () => {
|
|
727
|
+
expect(resolveDefaults(product, { variant: "stale", mockupId: "M2", variantIsDefault: true })?.variantId).toBe("stale");
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
describe("a chosen SIZE no mockup lists renders the listed size sibling, said in previewFor (#4342/#4388)", async () => {
|
|
732
|
+
const { listedSizeSibling, resolveVariant: rv } = await import("../src/resolve");
|
|
733
|
+
// XTNA6J, 2026-11-11: sizes are combination rows, colour is an option (affectsCombinations false); every live mockup
|
|
734
|
+
// lists only S (47448b) and the default is XL (296448).
|
|
735
|
+
const sizes: Array<[string, string]> = [["S", "47448b"], ["M", "731fb0"], ["L", "l00000"], ["XL", "296448"], ["2XL", "c9f1ea"]];
|
|
736
|
+
const hoodie = {
|
|
737
|
+
defaultGvid: "296448",
|
|
738
|
+
variants: sizes.map(([, g]) => ({ gvid: g })),
|
|
739
|
+
attributes: { Size: { affectsCombinations: true, choices: sizes.map(([s]) => s) }, Color: { affectsCombinations: false, choices: ["Black", "White"] } },
|
|
740
|
+
combinations: sizes.map(([s, g]) => ({ variantId: g, options: { Size: s } })),
|
|
741
|
+
mockups: [{ id: "3VPV6M", gvids: ["47448b"] }, { id: "9XC4GD", gvids: ["47448b"] }],
|
|
742
|
+
placements: [{ label: "Front left" }],
|
|
743
|
+
} as unknown as Parameters<typeof resolveDefaults>[0];
|
|
744
|
+
const resolveUrl = (picks: Record<string, string>, variantOverride?: string) => {
|
|
745
|
+
const v = rv(hoodie as any, picks, variantOverride)!;
|
|
746
|
+
return resolveDefaults(hoodie, { variant: v.variantId, variantIsDefault: !variantOverride && Object.keys(picks).length === 0 });
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
it("the lead's six URLs: plain, size S/M/XL/2XL, XL+White, White or Black alone: all render 47448b; a swap names the asked size", () => {
|
|
750
|
+
expect(resolveUrl({})).toMatchObject({ variantId: "47448b", previewFor: "296448" });
|
|
751
|
+
expect(resolveUrl({ size: "S" })).toEqual(expect.objectContaining({ variantId: "47448b" }));
|
|
752
|
+
expect(resolveUrl({ size: "S" })?.previewFor).toBeUndefined();
|
|
753
|
+
for (const [s, g] of [["M", "731fb0"], ["XL", "296448"], ["2XL", "c9f1ea"]]) expect(resolveUrl({ size: s })).toMatchObject({ variantId: "47448b", previewFor: g });
|
|
754
|
+
expect(resolveUrl({ size: "XL", color: "White" })).toMatchObject({ variantId: "47448b", previewFor: "296448" });
|
|
755
|
+
for (const c of ["White", "Black"]) expect(resolveUrl({ color: c })).toMatchObject({ variantId: "47448b", previewFor: "296448" });
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
it("never swaps a colour that is a combination attribute (a tee whose mockups list only Black)", () => {
|
|
759
|
+
const tee = { combinations: [{ variantId: "bk-m", options: { Color: "Black", Size: "M" } }, { variantId: "wh-m", options: { Color: "White", Size: "M" } }, { variantId: "bk-s", options: { Color: "Black", Size: "S" } }] };
|
|
760
|
+
expect(listedSizeSibling(tee as any, { gvids: ["bk-s"] }, "bk-m")).toBe("bk-s");
|
|
761
|
+
expect(listedSizeSibling(tee as any, { gvids: ["bk-s"] }, "wh-m")).toBeNull();
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it("a variant= the caller named with no size sibling is theirs (the box's typed refusal stands)", () => {
|
|
765
|
+
expect(resolveDefaults(hoodie, { variant: "nope" })?.variantId).toBe("nope");
|
|
766
|
+
});
|
|
767
|
+
});
|
package/wrangler.jsonc
CHANGED
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
// to override these prod defaults. For standalone `pnpm dev`, copy
|
|
31
31
|
// .dev.vars.example -> .dev.vars.
|
|
32
32
|
"vars": {
|
|
33
|
-
//
|
|
34
|
-
|
|
33
|
+
// relay-lax-1, our one remaining relay: the production-shape load generator. Exact IPs; change via PR.
|
|
34
|
+
// (The eight other metro relays were deleted 2026-10-20 — their IPs return to Linode's pool, so they must never stay listed.)
|
|
35
|
+
"LOADTEST_EXEMPT_IPS": "172.236.245.89",
|
|
35
36
|
"TTL_DEFAULT": "86400",
|
|
36
37
|
"LOG_LEVEL": "info",
|
|
37
38
|
// MEILISEARCH_API_KEY is the public read-only search key (same as apps/www);
|