@tokenoftrust/storefront-runner 6.11.9 → 6.11.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.
@@ -159,6 +159,8 @@ declare global {
159
159
  * the pinned render.
160
160
  */
161
161
  apiBasePath: string;
162
+ /** Captured-image prefix from tenant routing (`TenantRouting.imageBasePath`); absent when root `/_a/` reaches the tenant. */
163
+ imageBasePath?: string;
162
164
  /**
163
165
  * The origin the viewer addressed: `https://<viewer host>` for an
164
166
  * authenticated CDN forward (ADR 0013 Tier 3), else the request URL's own
@@ -28,6 +28,11 @@ export interface TenantRouting {
28
28
  basePath: string;
29
29
  /** Route to render with the tenant prefix stripped (leading slash, no query). */
30
30
  renderPath: string;
31
+ /**
32
+ * Prefix that keeps captured-image (`/_a/...`) requests on {@link tenant}, set only when the tenant
33
+ * came from an embedded path segment on a host that routes root paths to a different tenant.
34
+ */
35
+ imageBasePath?: string;
31
36
  }
32
37
 
33
38
  /** Keep preview navigation on its session host whenever that host can route the target. */
@@ -154,6 +159,7 @@ export async function resolveTenantRouting(
154
159
  tenant: byEmbedded,
155
160
  basePath: "",
156
161
  renderPath: normalizePath(pathname),
162
+ imageBasePath: `/${embedded}`,
157
163
  };
158
164
  }
159
165
  }
@@ -45,7 +45,7 @@ export function prefixPreviewPinnedImageUrls(html: string, basePath: string): st
45
45
  /** Choose asset routing from the resolved request tenant, never a second host-membership check. */
46
46
  export function previewPinnedImageBasePath(tenant: {
47
47
  tenant_id: string; appDomain?: string;
48
- }, routing: { tenantId: string | undefined; basePath: string }): string {
49
- if (routing.tenantId === tenant.tenant_id) return routing.basePath;
48
+ }, routing: { tenantId: string | undefined; basePath: string; imageBasePath?: string }): string {
49
+ if (routing.tenantId === tenant.tenant_id) return routing.imageBasePath ?? routing.basePath;
50
50
  return tenant.appDomain && /^[a-z0-9.-]+$/i.test(tenant.appDomain) ? `/${tenant.appDomain}` : "";
51
51
  }
@@ -91,9 +91,12 @@ export const EXCISE_SKU_OUTCOMES = [
91
91
  export type ExciseSkuOutcome = (typeof EXCISE_SKU_OUTCOMES)[number];
92
92
 
93
93
  /**
94
- * The three admin view states for a catalog SKU in the Excise tax section (`ac-1`).
94
+ * The admin view states for a catalog SKU in the Excise tax section (`ac-1`).
95
95
  */
96
- export type ExciseSkuState = "registered" | "missing" | "refused";
96
+ export type ExciseSkuState = "registered" | "missing" | "refused" | "unavailable";
97
+
98
+ export const EXCISE_UNAVAILABLE_MESSAGE =
99
+ "Registry status is unavailable right now; reload to try again.";
97
100
 
98
101
  export type ExciseProductType = "vape" | "nicotinePouch" | "hemp";
99
102
 
@@ -131,7 +134,7 @@ export interface ExciseCatalogSkuRow {
131
134
  state: ExciseSkuState;
132
135
  outcome: ExciseSkuOutcome | null;
133
136
  message: string;
134
- attributes: ExciseSkuAttributes;
137
+ attributes: Partial<ExciseSkuAttributes>;
135
138
  }
136
139
 
137
140
  export interface ExciseRegistrySkuSnapshot {
@@ -209,69 +212,42 @@ export interface CatalogProductLike {
209
212
  }>;
210
213
  }
211
214
 
212
- function positiveFinite(value: unknown, fallback: number): number {
213
- const num = typeof value === "number" ? value : Number(value);
214
- return Number.isFinite(num) && num >= 0 ? Number(num.toFixed(2)) : fallback;
215
- }
216
-
217
- function defaultAttributesForVariant(
218
- product: CatalogProductLike,
219
- variant: CatalogProductLike["variants"][number],
220
- ): ExciseSkuAttributes {
221
- const retail = positiveFinite(variant.price, 19.99);
222
- const msrp = positiveFinite(variant.compare_at_price ?? retail, retail);
223
- const wholesalePrice = positiveFinite(retail * 0.5, 10);
224
- const wholesaleCost = positiveFinite(retail * 0.4, 8);
225
- const volumeMeta = product.metafields?.find(
226
- (m) => m.key === "volume_ml" || m.key === "volumeInMl" || m.key === "volume",
227
- )?.value;
228
- const parsedVolume = volumeMeta ? Number.parseFloat(volumeMeta) : NaN;
229
- const volumeInMl = Number.isFinite(parsedVolume) && parsedVolume > 0 ? parsedVolume : 30;
230
- const systemMeta = product.metafields?.find(
231
- (m) => m.key === "vape_system_type" || m.key === "vapeSystemType",
232
- )?.value;
233
- const vapeSystemType: ExciseVapeSystemType =
234
- systemMeta === "closed" || systemMeta === "closedSingleUse" || systemMeta === "closedCartridge"
235
- ? systemMeta
236
- : "open";
237
- return {
238
- type: "vape",
239
- vapeSystemType,
240
- volumeInMl,
241
- wholesaleCost,
242
- wholesalePrice,
243
- msrp,
244
- retailPrice: retail,
245
- hasNicotine: true,
246
- packQuantity: 1,
247
- };
248
- }
249
-
250
215
  /**
251
216
  * Build the admin excise SKU rows from the store's catalog products and optional registry read-back.
252
217
  * Only variants with a valid bare SKU in the store's catalog are included.
218
+ * Regulated engine attributes are never guessed from catalog prices; only registry-returned
219
+ * attributes are populated. When a registry read fails (`registryUnavailable: true`), rows with no
220
+ * snapshot are marked `"unavailable"` rather than `"missing"`.
253
221
  */
254
222
  export function toExciseCatalogSkuRows(
255
223
  products: readonly CatalogProductLike[],
256
224
  registryBySku?: ReadonlyMap<string, ExciseRegistrySkuSnapshot>,
225
+ options?: { registryUnavailable?: boolean },
257
226
  ): ExciseCatalogSkuRow[] {
258
227
  const rows: ExciseCatalogSkuRow[] = [];
259
228
  const seen = new Set<string>();
229
+ const registryUnavailable = options?.registryUnavailable === true;
260
230
  const sortedProducts = [...products].sort((a, b) => a.title.localeCompare(b.title));
261
231
  for (const product of sortedProducts) {
262
232
  for (const variant of product.variants) {
263
233
  const sku = typeof variant.sku === "string" ? variant.sku.trim() : "";
264
234
  if (!isValidBareCatalogSku(sku) || seen.has(sku)) continue;
265
235
  seen.add(sku);
266
- const defaults = defaultAttributesForVariant(product, variant);
267
236
  const snapshot = registryBySku?.get(sku);
268
237
  const outcome = snapshot?.outcome ?? null;
269
- const state = mapExciseOutcomeToState(outcome, snapshot?.active);
270
- const message = exciseOutcomeMessage(outcome, snapshot?.active);
271
- const mergedAttrs: ExciseSkuAttributes = {
272
- ...defaults,
273
- ...(snapshot?.attributes ?? {}),
274
- };
238
+ const state: ExciseSkuState = snapshot
239
+ ? mapExciseOutcomeToState(outcome, snapshot.active)
240
+ : registryUnavailable
241
+ ? "unavailable"
242
+ : "missing";
243
+ const message = snapshot
244
+ ? exciseOutcomeMessage(outcome, snapshot.active)
245
+ : registryUnavailable
246
+ ? EXCISE_UNAVAILABLE_MESSAGE
247
+ : exciseOutcomeMessage(null);
248
+ const attributes: Partial<ExciseSkuAttributes> = snapshot?.attributes
249
+ ? { ...snapshot.attributes }
250
+ : {};
275
251
  rows.push({
276
252
  sku,
277
253
  productHandle: product.handle,
@@ -283,7 +259,7 @@ export function toExciseCatalogSkuRows(
283
259
  state,
284
260
  outcome,
285
261
  message,
286
- attributes: mergedAttrs,
262
+ attributes,
287
263
  });
288
264
  }
289
265
  }
@@ -38,16 +38,18 @@ export function mountCheckoutExciseForm(form: HTMLElement): void {
38
38
  });
39
39
  }
40
40
 
41
- const SKU_CHIP_CLASSES: Record<"registered" | "missing" | "refused", string> = {
41
+ const SKU_CHIP_CLASSES: Record<"registered" | "missing" | "refused" | "unavailable", string> = {
42
42
  registered: "green",
43
43
  missing: "amber",
44
44
  refused: "red",
45
+ unavailable: "amber",
45
46
  };
46
47
 
47
- const SKU_CHIP_LABELS: Record<"registered" | "missing" | "refused", string> = {
48
+ const SKU_CHIP_LABELS: Record<"registered" | "missing" | "refused" | "unavailable", string> = {
48
49
  registered: "Registered",
49
50
  missing: "Missing",
50
51
  refused: "Refused",
52
+ unavailable: "Unavailable",
51
53
  };
52
54
 
53
55
  function readRowProduct(row: Element, sku: string, action: string): Record<string, unknown> {
@@ -60,14 +62,14 @@ function readRowProduct(row: Element, sku: string, action: string): Record<strin
60
62
  };
61
63
  return {
62
64
  sku,
63
- type: getVal("type") || "vape",
64
- vapeSystemType: getVal("vapeSystemType") || "open",
65
- volumeInMl: Number(getVal("volumeInMl") || 0),
66
- wholesaleCost: Number(getVal("wholesaleCost") || 0),
67
- wholesalePrice: Number(getVal("wholesalePrice") || 0),
68
- msrp: Number(getVal("msrp") || 0),
69
- retailPrice: Number(getVal("retailPrice") || 0),
70
- packQuantity: Number.parseInt(String(getVal("packQuantity") || "1"), 10) || 1,
65
+ type: getVal("type"),
66
+ vapeSystemType: getVal("vapeSystemType"),
67
+ volumeInMl: getVal("volumeInMl"),
68
+ wholesaleCost: getVal("wholesaleCost"),
69
+ wholesalePrice: getVal("wholesalePrice"),
70
+ msrp: getVal("msrp"),
71
+ retailPrice: getVal("retailPrice"),
72
+ packQuantity: getVal("packQuantity"),
71
73
  hasNicotine: Boolean(getVal("hasNicotine")),
72
74
  };
73
75
  }
@@ -78,8 +80,12 @@ function applyRowResult(
78
80
  ): void {
79
81
  const badge = row.querySelector<HTMLElement>("[data-excise-sku-state]");
80
82
  const msg = row.querySelector<HTMLElement>("[data-excise-sku-message]");
81
- const state: "registered" | "missing" | "refused" =
82
- item && (item.state === "registered" || item.state === "missing" || item.state === "refused")
83
+ const state: "registered" | "missing" | "refused" | "unavailable" =
84
+ item &&
85
+ (item.state === "registered" ||
86
+ item.state === "missing" ||
87
+ item.state === "refused" ||
88
+ item.state === "unavailable")
83
89
  ? item.state
84
90
  : "refused";
85
91
  if (badge) {
@@ -191,7 +191,7 @@ async function serveRequest(
191
191
  // Host first; if the host owns no tenant, a leading /<domain>/ path segment
192
192
  // selects one (DNS-free tenant selection on localhost/preview). The resolver
193
193
  // is KV-backed in prod (many-tenant) and static in plain dev.
194
- const { tenant, basePath, renderPath } = await timing.time("tenant", async () => {
194
+ const { tenant, basePath, renderPath, imageBasePath } = await timing.time("tenant", async () => {
195
195
  const resolver = await getTenantResolver();
196
196
  return cdn
197
197
  ? await resolveCdnForwardRouting(cdn, url.pathname, resolver)
@@ -201,6 +201,7 @@ async function serveRequest(
201
201
  return new Response("Unknown host", { status: 404 });
202
202
  }
203
203
  seen.assetBasePath = basePath;
204
+ if (imageBasePath) context.locals.imageBasePath = imageBasePath;
204
205
 
205
206
  // ---- The one route classification -----------------------------------------
206
207
  // An EXPLICITLY unpaid store is never fully public: the ONLY way to reach its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.11.9",
3
+ "version": "6.11.11",
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",