@tokenoftrust/storefront-runner 6.11.9 → 6.11.10
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.
|
@@ -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
|
|
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 =
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
|
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")
|
|
64
|
-
vapeSystemType: getVal("vapeSystemType")
|
|
65
|
-
volumeInMl:
|
|
66
|
-
wholesaleCost:
|
|
67
|
-
wholesalePrice:
|
|
68
|
-
msrp:
|
|
69
|
-
retailPrice:
|
|
70
|
-
packQuantity:
|
|
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 &&
|
|
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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "6.11.
|
|
3
|
+
"version": "6.11.10",
|
|
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",
|