@tokenoftrust/storefront-runner 4.2.4 → 4.3.0

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.
@@ -2,7 +2,7 @@
2
2
  import type { APIContext } from "astro";
3
3
  import { createLocalJWKSet, decodeProtectedHeader, jwtVerify, type JSONWebKeySet } from "jose";
4
4
  import {
5
- commerceTenantId, totalsMatch, canonicalJson, shippingMinorFor, isContentVersionId, providerCartDigestMaterial,
5
+ commerceTenantId, totalsMatch, shippingMinorFor, isContentVersionId, catalogPinDigestFinding,
6
6
  type CallerToken, type CatalogProduct, type CommerceEvidence, type CommerceEvidenceProvenance,
7
7
  type CommerceProviderCartSnapshot, type FinalCartBinding, type TenantConfig,
8
8
  } from "@tot/public-runtime";
@@ -183,7 +183,8 @@ async function authorize(context: APIContext): Promise<Response> {
183
183
  : createContentProvider(tenant, { get: kvGet, env: contentEnv });
184
184
  const tot = await createToTClient(tenant, await readD1("CATALOG_DB"), content);
185
185
  const authorityContext = { ...context, locals: { ...context.locals, tenant, tot, content } } as APIContext;
186
- if (snapshot.providerCartDigest !== await digest(canonicalJson(providerCartDigestMaterial(snapshot)))) return deny("provider-cart-digest");
186
+ const catalogPin = await catalogPinDigestFinding(snapshot);
187
+ if (catalogPin) return deny(catalogPin);
187
188
  let listing: CatalogProduct[];
188
189
  try { listing = await tot.getAllActiveProducts(); } catch { return deny("catalog-unavailable", 503); }
189
190
  if (!Array.isArray(listing)) return deny("catalog-unavailable", 503);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "4.2.4",
3
+ "version": "4.3.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",
@@ -401,6 +401,29 @@ export function providerCartDigestMaterial(snapshot: {
401
401
  return snapshot.contentVersionId === undefined ? material : { ...material, contentVersionId: snapshot.contentVersionId };
402
402
  }
403
403
 
404
+ /** Finding when the provider-cart digest was not computed over the rendered content pin. */
405
+ export const PROVIDER_CART_DIGEST_FINDING = "provider-cart-digest";
406
+
407
+ /**
408
+ * The provider-cart digest check the final-cart authority applies. Returns
409
+ * `provider-cart-digest` when `providerCartDigest` is not the digest of
410
+ * `providerCartDigestMaterial` (the content pin is inside that material when
411
+ * the snapshot names one). Returns null when the digest matches.
412
+ */
413
+ export async function catalogPinDigestFinding(snapshot: {
414
+ providerCartDigest: string;
415
+ tenantId: string;
416
+ stage: string;
417
+ currency: string;
418
+ lines: readonly FinalCartLine[];
419
+ totals: MinorTotals;
420
+ destinationDigest: string;
421
+ contentVersionId?: string;
422
+ }): Promise<typeof PROVIDER_CART_DIGEST_FINDING | null> {
423
+ const expected = await sha256Hex(canonicalJson(providerCartDigestMaterial(snapshot)));
424
+ return snapshot.providerCartDigest === expected ? null : PROVIDER_CART_DIGEST_FINDING;
425
+ }
426
+
404
427
  /** Safe source references explaining each server-owned authority decision. */
405
428
  export interface CommerceAuthoritySource {
406
429
  requirement: "required" | "not-required";