@snowcone-app/mockup-resolver 1.0.10 → 1.0.11

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @snowcone-app/mockup-resolver
2
2
 
3
+ ## 1.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`0088c4a`](https://github.com/snowcone-app/snowcone-monorepo/commit/0088c4a11e30ca0322a15d38c7be577ed0b0616b)]:
8
+ - @snowcone-app/mockup-url@0.6.0
9
+
3
10
  ## 1.0.10
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.10",
3
+ "version": "1.0.11",
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.5.0"
9
+ "@snowcone-app/mockup-url": "0.6.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@cloudflare/workers-types": "^4.20250303.0",
package/src/index.ts CHANGED
@@ -1006,6 +1006,8 @@ import {
1006
1006
  renderUrlLengthError,
1007
1007
  E_RENDER_URL_TOO_LONG,
1008
1008
  MAX_DESIGN_ELEMENTS,
1009
+ expandIngestHandle,
1010
+ isIngestHandle,
1009
1011
  PARAMS,
1010
1012
  type DesignElement,
1011
1013
  } from "@snowcone-app/mockup-url";
@@ -1013,6 +1015,7 @@ import {
1013
1015
  assembleArtwork,
1014
1016
  fetchProduct,
1015
1017
  looksLikeResolveRequest,
1018
+ expandIngestHandles,
1016
1019
  resolveAlbumPagePlacement,
1017
1020
  resolveBundleScene,
1018
1021
  resolveDefaults,
@@ -1357,8 +1360,18 @@ async function handlePublicResolve(
1357
1360
  // design map (`asset.<key>`/`color.<key>`/`tile.<key>`/`align.<key>`) + variant
1358
1361
  // option picks (`opt.<attr>`).
1359
1362
  const parsed = parsePublicUrl(reqUrl);
1360
- const asset = q.get(PARAMS.asset);
1361
- const design = parsed.design ?? {};
1363
+ // First-party asset handles (ADR-0099 D3): `ingest:<sha256>` expands to the
1364
+ // ingested artwork's first-party URL before anything else reads the asset
1365
+ // values; the expanded URLs skip the origin allowlist (platform provenance).
1366
+ const handles = expandIngestHandles(
1367
+ q.get(PARAMS.asset),
1368
+ parsed.design ?? {},
1369
+ expandIngestHandle,
1370
+ isIngestHandle
1371
+ );
1372
+ if (!handles.ok) return errResp(handles.status, handles.message, handles.code);
1373
+ const asset = handles.asset;
1374
+ const design = handles.design;
1362
1375
  const optionPicks = parsed.options ?? {};
1363
1376
  const designKeys = Object.keys(design);
1364
1377
  // Catalog design reference (ADR-0086): `design=<pairingId|slug>` renders a
@@ -1459,10 +1472,10 @@ async function handlePublicResolve(
1459
1472
  // per-placement srcs). Reserved `default` tokens are EXCLUDED — they are
1460
1473
  // platform-injected (resolved to `house`), so they bypass L2 by provenance.
1461
1474
  const imageUrls: string[] = [];
1462
- if (asset && !isDefaultToken(asset)) imageUrls.push(asset);
1475
+ if (asset && !isDefaultToken(asset) && !handles.expanded.has(asset)) imageUrls.push(asset);
1463
1476
  for (const k of designKeys) {
1464
1477
  const src = design[k].src;
1465
- if (src && !isDefaultToken(src)) imageUrls.push(src);
1478
+ if (src && !isDefaultToken(src) && !handles.expanded.has(src)) imageUrls.push(src);
1466
1479
  }
1467
1480
 
1468
1481
  // 2b. L2 — asset-source allowlist (checked for EVERY image URL's hostname).
package/src/resolve.ts CHANGED
@@ -701,6 +701,53 @@ export function resolveVariant(
701
701
  return { variantId, optionSelections };
702
702
  }
703
703
 
704
+ // ─── First-party asset handles (ADR-0099 D3 / ADR-0095) ────────────────────
705
+
706
+ export type ExpandHandlesResult =
707
+ | { ok: true; asset: string | null; design: Record<string, ParsedFill>; expanded: Set<string> }
708
+ | { ok: false; status: number; code: string; message: string };
709
+
710
+ /**
711
+ * Replace every `ingest:<sha256>` asset value (bare `asset=` and per-key
712
+ * `asset.<key>=` sources) with its first-party URL. Returns the set of URLs
713
+ * that came from handles so the caller can skip the origin allowlist for
714
+ * them (platform provenance, like the `default` token). A malformed handle
715
+ * fails loudly — never falls back to fetching the literal string.
716
+ */
717
+ export function expandIngestHandles(
718
+ asset: string | null,
719
+ design: Record<string, ParsedFill>,
720
+ expand: (value: string) => string | null,
721
+ isHandle: (value: unknown) => boolean
722
+ ): ExpandHandlesResult {
723
+ const expanded = new Set<string>();
724
+ const bad = (where: string, value: string): ExpandHandlesResult => ({
725
+ ok: false,
726
+ status: 400,
727
+ code: "E_INGEST_HANDLE_INVALID",
728
+ message: `${where} is not a valid asset handle: "${value}". Expected ingest:<64 lowercase hex sha256> (the sha256 of the ingested source URL).`,
729
+ });
730
+ let outAsset = asset;
731
+ if (asset !== null && isHandle(asset)) {
732
+ const url = expand(asset);
733
+ if (!url) return bad("asset", asset);
734
+ outAsset = url;
735
+ expanded.add(url);
736
+ }
737
+ const outDesign: Record<string, ParsedFill> = {};
738
+ for (const [key, fill] of Object.entries(design)) {
739
+ if (fill.src && isHandle(fill.src)) {
740
+ const url = expand(fill.src);
741
+ if (!url) return bad(`asset.${key}`, fill.src);
742
+ outDesign[key] = { ...fill, src: url };
743
+ expanded.add(url);
744
+ } else {
745
+ outDesign[key] = fill;
746
+ }
747
+ }
748
+ return { ok: true, asset: outAsset, design: outDesign, expanded };
749
+ }
750
+
704
751
  // ─── Bundles (ADR-0099): picks, per-role variants, the mockup, the placements ──
705
752
 
706
753
  export interface BundleSceneInput {
@@ -672,3 +672,34 @@ function ok2(r: ReturnType<typeof resolveBundleScene>) {
672
672
  if (!r.ok) throw new Error(`${r.code}: ${r.message}`);
673
673
  return r.scene;
674
674
  }
675
+
676
+ // ─── First-party asset handles (ADR-0099 D3) ─────────────────────────────────
677
+ import { expandIngestHandles } from "../src/resolve";
678
+ import { expandIngestHandle, isIngestHandle } from "@snowcone-app/mockup-url";
679
+
680
+ describe("expandIngestHandles", () => {
681
+ const sha = "a".repeat(64);
682
+ it("expands bare and per-key handles to the first-party URL and reports them as platform-provenance", () => {
683
+ const r = expandIngestHandles(`ingest:${sha}`, { back: { src: `ingest:${sha}` }, left: { src: "https://x/y.png" } }, expandIngestHandle, isIngestHandle);
684
+ expect(r.ok).toBe(true);
685
+ if (r.ok) {
686
+ expect(r.asset).toBe(`https://raws.snowcone.app/art-ingest/${sha}`);
687
+ expect(r.design.back.src).toBe(`https://raws.snowcone.app/art-ingest/${sha}`);
688
+ expect(r.design.left.src).toBe("https://x/y.png");
689
+ expect([...r.expanded]).toEqual([`https://raws.snowcone.app/art-ingest/${sha}`]);
690
+ }
691
+ });
692
+ it("a malformed handle is a typed 400, never fetched literally", () => {
693
+ const r = expandIngestHandles("ingest:nope", {}, expandIngestHandle, isIngestHandle);
694
+ expect(r.ok).toBe(false);
695
+ if (!r.ok) expect([r.status, r.code]).toEqual([400, "E_INGEST_HANDLE_INVALID"]);
696
+ const r2 = expandIngestHandles(null, { front: { src: "ingest:ABC" } }, expandIngestHandle, isIngestHandle);
697
+ expect(r2.ok).toBe(false);
698
+ if (!r2.ok) expect(r2.message).toMatch(/asset\.front/);
699
+ });
700
+ it("leaves non-handle values untouched", () => {
701
+ const r = expandIngestHandles("https://a/b.png", { front: { color: "ff0000" } }, expandIngestHandle, isIngestHandle);
702
+ expect(r.ok && r.asset).toBe("https://a/b.png");
703
+ expect(r.ok && r.expanded.size).toBe(0);
704
+ });
705
+ });