@tokenoftrust/storefront-runner 7.0.0 → 7.2.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.
@@ -5,8 +5,12 @@
5
5
  * an entitlement tot20 reports enabled.
6
6
  */
7
7
  import { IMAGE_TIERS, LARGE_IMAGES_ADDON_NAME } from "@tot/public-runtime/image-limits";
8
+ import {
9
+ CATALOG_SCALE_LARGE,
10
+ LARGE_CATALOG_ADDON_NAME,
11
+ } from "@tot/public-runtime/catalog-scale";
8
12
 
9
- export const ADDON_IDS = ["largeImages"] as const;
13
+ export const ADDON_IDS = ["largeImages", "largeCatalog"] as const;
10
14
  export type AddOnId = (typeof ADDON_IDS)[number];
11
15
 
12
16
  export interface AddOnDefinition {
@@ -29,6 +33,14 @@ export const ADDONS: readonly AddOnDefinition[] = Object.freeze([
29
33
  `Raises this store's image limit from the standard ${limits(IMAGE_TIERS.standard)} ` +
30
34
  `to ${limits(IMAGE_TIERS.large)}. Takes effect on the next capture or upload.`,
31
35
  },
36
+ {
37
+ id: "largeCatalog",
38
+ name: LARGE_CATALOG_ADDON_NAME,
39
+ description:
40
+ `For catalogs past ${CATALOG_SCALE_LARGE.products.toLocaleString("en-US")} products or ` +
41
+ `${CATALOG_SCALE_LARGE.bytes / 1_000_000} MB of catalog files, whose static publication takes ` +
42
+ `over ten minutes. Publishing is not blocked without it today.`,
43
+ },
32
44
  ]);
33
45
 
34
46
  /** What `/admin/addons` shows for one add-on. `unavailable` means tot20 could not be read. */
@@ -25,6 +25,7 @@ import { readEnv } from "@/lib/publication/shared/env";
25
25
  /** The add-on set as this storefront reads it. Unknown add-ons and fields are dropped. */
26
26
  export interface StoreEntitlementSet {
27
27
  largeImages?: { enabled: boolean; updatedAt?: string };
28
+ largeCatalog?: { enabled: boolean; updatedAt?: string };
28
29
  }
29
30
 
30
31
  export type EntitlementFallbackReason =
@@ -105,19 +106,21 @@ function isRecord(value: unknown): value is Record<string, unknown> {
105
106
  /** Project the wire add-on set to the fields this module knows; `undefined` when malformed. */
106
107
  function projectSet(raw: unknown): StoreEntitlementSet | undefined {
107
108
  if (!isRecord(raw)) return undefined;
108
- const large = raw.largeImages;
109
- if (large === undefined) return {};
110
- if (!isRecord(large) || typeof large.enabled !== "boolean") return undefined;
111
- return {
112
- largeImages: {
113
- enabled: large.enabled,
114
- ...(typeof large.updatedAt === "string" ? { updatedAt: large.updatedAt } : {}),
115
- },
116
- };
109
+ const out: StoreEntitlementSet = {};
110
+ for (const key of ["largeImages", "largeCatalog"] as const) {
111
+ const value = raw[key];
112
+ if (value === undefined) continue;
113
+ if (!isRecord(value) || typeof value.enabled !== "boolean") return undefined;
114
+ out[key] = {
115
+ enabled: value.enabled,
116
+ ...(typeof value.updatedAt === "string" ? { updatedAt: value.updatedAt } : {}),
117
+ };
118
+ }
119
+ return out;
117
120
  }
118
121
 
119
122
  function classify(entitlements: StoreEntitlementSet): StoreEntitlements {
120
- return entitlements.largeImages?.enabled === true
123
+ return entitlements.largeImages?.enabled === true || entitlements.largeCatalog?.enabled === true
121
124
  ? { status: "ok", entitlements }
122
125
  : { status: "not-entitled", entitlements };
123
126
  }
@@ -365,7 +365,10 @@ export async function sampleCartGet(
365
365
  if (!signing.enabled) return sampleResponse('{"error":"sample_unavailable"}', 503);
366
366
  const payload = await buildVariantCartPayload(product, variant, {
367
367
  mode: "signed", secret: signing.secret, tenantId: commerceTenantId(tenant), currency: tenant.currency,
368
- publicOrigin: tenantPublicOrigin(tenant),
368
+ publicOrigin: tenantPublicOrigin(tenant, {
369
+ requestOrigin: url.origin,
370
+ basePath: context.locals.basePath,
371
+ }),
369
372
  });
370
373
  const result = await enforceCartSubmission({
371
374
  entries: [...payload.hidden.map((f): [string, string] => [f.name, f.value]), [payload.quantityName, quantity]],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.0.0",
3
+ "version": "7.2.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",
@@ -3,9 +3,12 @@ export interface CatalogSize {
3
3
  readonly bytes: number;
4
4
  }
5
5
  export type CatalogScaleLevel = "ok" | "warn" | "large";
6
+ export type CatalogTier = "standard" | "large";
6
7
 
7
8
  export declare const CATALOG_SCALE_WARN: Readonly<CatalogSize>;
8
9
  export declare const CATALOG_SCALE_LARGE: Readonly<CatalogSize>;
10
+ export declare const LARGE_CATALOG_ADDON_NAME: string;
11
+ export declare function resolveCatalogTier(entitlements: unknown): CatalogTier;
9
12
  export declare function catalogScaleLevel(size: CatalogSize): CatalogScaleLevel;
10
13
  export declare function catalogScaleFinding(
11
14
  size: CatalogSize,
@@ -41,6 +41,21 @@ export function catalogScaleLevel({ products, bytes }) {
41
41
  return "ok";
42
42
  }
43
43
 
44
+ export const LARGE_CATALOG_ADDON_NAME = "Large Catalog";
45
+
46
+ /**
47
+ * The catalog tier a store's add-on entitlements grant. `entitlements` is untrusted input; only
48
+ * `largeCatalog.enabled === true` exactly grants `large`, everything else is `standard`.
49
+ * @param {unknown} entitlements
50
+ * @returns {"standard" | "large"}
51
+ */
52
+ export function resolveCatalogTier(entitlements) {
53
+ if (!entitlements || typeof entitlements !== "object" || Array.isArray(entitlements)) return "standard";
54
+ const addOn = /** @type {Record<string, unknown>} */ (entitlements).largeCatalog;
55
+ if (!addOn || typeof addOn !== "object" || Array.isArray(addOn)) return "standard";
56
+ return /** @type {Record<string, unknown>} */ (addOn).enabled === true ? "large" : "standard";
57
+ }
58
+
44
59
  const mb = (bytes) => `${(bytes / 1_000_000).toFixed(1)} MB`;
45
60
 
46
61
  /**
@@ -71,6 +86,8 @@ export function catalogScaleFinding(size) {
71
86
  message:
72
87
  `catalog is ${have}, past the ${CATALOG_SCALE_LARGE.products}-product / ` +
73
88
  `${mb(CATALOG_SCALE_LARGE.bytes)} line. Static publication took 11 minutes at 5,000 products ` +
74
- `and 21 minutes at 7,000 in measurement, growing faster than the catalog. ${cdns}`,
89
+ `and 21 minutes at 7,000 in measurement, growing faster than the catalog. ` +
90
+ `Catalogs past this line belong on the ${LARGE_CATALOG_ADDON_NAME} add-on; publishing is not ` +
91
+ `blocked today. ${cdns}`,
75
92
  };
76
93
  }