@tokenoftrust/cli 7.4.2 → 7.4.3
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/package.json +1 -1
- package/src/validate.mjs +121 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.3",
|
|
4
4
|
"description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Token of Trust",
|
package/src/validate.mjs
CHANGED
|
@@ -114,7 +114,120 @@ export function catalogSkuFindings(products) {
|
|
|
114
114
|
return out;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
const GENERIC_PRODUCT_TYPES = new Set(["physical", "digital", "gift_certificate"]);
|
|
118
|
+
const CATALOG_FLAVOR_FIELDS = new Set(["flavor", "flavour", "flavors", "flavours"]);
|
|
119
|
+
const CATALOG_CATEGORY_FIELDS = new Set(["compliance category", "product category", "product_category"]);
|
|
120
|
+
const CATALOG_NICOTINE_FORMAT_LABELS = new Set([
|
|
121
|
+
"nicotine salt", "nicotine salts", "salt nicotine", "salt nic", "nic salt", "nic salts", "salt", "salts",
|
|
122
|
+
"freebase", "free base", "freebase nicotine", "free base nicotine", "synthetic", "synthetic nicotine",
|
|
123
|
+
"tfn", "tobacco free nicotine", "tobacco-free nicotine",
|
|
124
|
+
]);
|
|
125
|
+
const CATALOG_NICOTINE_HINTS = [
|
|
126
|
+
"nicotine", "vape", "vapor", "vaping", "e-liquid", "eliquid", "e-juice", "ejuice",
|
|
127
|
+
"e liquid", "salt nic", "nic salt", "pod", "disposable", "ends", "cig",
|
|
128
|
+
];
|
|
129
|
+
const CATALOG_ACCESSORY_HINTS = ["battery", "coil", "charger", "case", "lanyard"];
|
|
130
|
+
|
|
131
|
+
function readCatalogMetafield(product, namespace, keys) {
|
|
132
|
+
const mfs = Array.isArray(product?.metafields) ? product.metafields : [];
|
|
133
|
+
const found = mfs.find((m) => m && m.namespace === namespace && typeof m.key === "string" && keys.has(m.key.trim().toLowerCase()));
|
|
134
|
+
return typeof found?.value === "string" && found.value.trim() ? found.value.trim() : undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function collectCatalogFlavorLabels(product, variant) {
|
|
138
|
+
const labels = new Set();
|
|
139
|
+
const add = (raw) => {
|
|
140
|
+
const v = String(raw ?? "").trim().toLowerCase();
|
|
141
|
+
if (v && !CATALOG_NICOTINE_FORMAT_LABELS.has(v)) labels.add(v);
|
|
142
|
+
};
|
|
143
|
+
const addList = (raw) => {
|
|
144
|
+
for (const part of String(raw ?? "").split(/[,;|]/)) add(part);
|
|
145
|
+
};
|
|
146
|
+
for (const tag of Array.isArray(product?.tags) ? product.tags : []) {
|
|
147
|
+
if (typeof tag === "string" && tag.startsWith("F: ")) add(tag.slice(3));
|
|
148
|
+
}
|
|
149
|
+
for (const mf of Array.isArray(product?.metafields) ? product.metafields : []) {
|
|
150
|
+
if (!mf || typeof mf.key !== "string") continue;
|
|
151
|
+
const key = mf.key.trim().toLowerCase();
|
|
152
|
+
if (mf.namespace === "compliance" && key === "flavor") addList(mf.value);
|
|
153
|
+
if (mf.namespace === "bigcommerce_custom" && CATALOG_FLAVOR_FIELDS.has(key)) addList(mf.value);
|
|
154
|
+
}
|
|
155
|
+
const opts = variant && typeof variant.option_values === "object" && variant.option_values ? variant.option_values : {};
|
|
156
|
+
for (const [name, value] of Object.entries(opts)) {
|
|
157
|
+
if (CATALOG_FLAVOR_FIELDS.has(name.trim().toLowerCase()) && value) add(value);
|
|
158
|
+
}
|
|
159
|
+
return [...labels];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function productClassificationGaps(product) {
|
|
163
|
+
if (!product || typeof product !== "object") return [];
|
|
164
|
+
const category =
|
|
165
|
+
readCatalogMetafield(product, "compliance", new Set(["product_category"])) ??
|
|
166
|
+
readCatalogMetafield(product, "bigcommerce_custom", CATALOG_CATEGORY_FIELDS);
|
|
167
|
+
const productType = typeof product.product_type === "string" ? product.product_type.trim().toLowerCase() : "";
|
|
168
|
+
const merchantType = GENERIC_PRODUCT_TYPES.has(productType) ? "" : productType;
|
|
169
|
+
const categoryClassified = Boolean(category) || merchantType.length > 0;
|
|
170
|
+
const haystack = [
|
|
171
|
+
merchantType,
|
|
172
|
+
(category ?? "").toLowerCase(),
|
|
173
|
+
typeof product.title === "string" ? product.title.toLowerCase() : "",
|
|
174
|
+
...(Array.isArray(product.tags) ? product.tags : []).map((t) => String(t ?? "").toLowerCase()),
|
|
175
|
+
].join(" ");
|
|
176
|
+
const isAccessory =
|
|
177
|
+
CATALOG_ACCESSORY_HINTS.some((n) => haystack.includes(n)) &&
|
|
178
|
+
!["e-liquid", "eliquid", "juice", "salt"].some((n) => haystack.includes(n));
|
|
179
|
+
const variants = Array.isArray(product.variants) && product.variants.length > 0 ? product.variants : [null];
|
|
180
|
+
const gaps = new Set();
|
|
181
|
+
if (!categoryClassified) gaps.add("category");
|
|
182
|
+
for (const variant of variants) {
|
|
183
|
+
const nicStrength = typeof variant?.option_values?.["Nicotine strength"] === "string"
|
|
184
|
+
? variant.option_values["Nicotine strength"].toLowerCase()
|
|
185
|
+
: undefined;
|
|
186
|
+
const nicOptionSaysZero = nicStrength !== undefined && /^0\s*mg\b/.test(nicStrength);
|
|
187
|
+
const nicOptionSaysNonZero = nicStrength !== undefined && /\d/.test(nicStrength) && !nicOptionSaysZero;
|
|
188
|
+
const containsNicotine =
|
|
189
|
+
!isAccessory &&
|
|
190
|
+
(nicOptionSaysNonZero || (!nicOptionSaysZero && CATALOG_NICOTINE_HINTS.some((n) => haystack.includes(n))));
|
|
191
|
+
const flavorClassified = collectCatalogFlavorLabels(product, variant).length > 0;
|
|
192
|
+
if ((containsNicotine || !categoryClassified) && !flavorClassified) gaps.add("flavor");
|
|
193
|
+
}
|
|
194
|
+
return ["category", "flavor"].filter((g) => gaps.has(g));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Per-tenant compliance classification audit for regulated stores: reports how many catalog
|
|
199
|
+
* products still lack a compliance category or flavour (which checkout refuses in flavour-ban states).
|
|
200
|
+
* @param {Array<{ file: string, record: any }>} products
|
|
201
|
+
* @param {Record<string, any> | null | undefined} config
|
|
202
|
+
* @returns {Finding[]}
|
|
203
|
+
*/
|
|
204
|
+
export function catalogComplianceFindings(products, config) {
|
|
205
|
+
if (!isRegulatedCompliance(config?.compliance) || !Array.isArray(products) || products.length === 0) return [];
|
|
206
|
+
const unclassified = [];
|
|
207
|
+
let missingCategory = 0;
|
|
208
|
+
let missingFlavor = 0;
|
|
209
|
+
for (const { file, record } of products) {
|
|
210
|
+
const gaps = productClassificationGaps(record);
|
|
211
|
+
if (gaps.length === 0) continue;
|
|
212
|
+
if (gaps.includes("category")) missingCategory += 1;
|
|
213
|
+
if (gaps.includes("flavor")) missingFlavor += 1;
|
|
214
|
+
const handle = typeof record?.handle === "string" && record.handle.trim() ? record.handle.trim() : file;
|
|
215
|
+
unclassified.push(handle);
|
|
216
|
+
}
|
|
217
|
+
if (unclassified.length === 0) return [];
|
|
218
|
+
const sample = unclassified.slice(0, 5).join(", ") + (unclassified.length > 5 ? ", ..." : "");
|
|
219
|
+
return [
|
|
220
|
+
mk(
|
|
221
|
+
WARN,
|
|
222
|
+
"catalog-compliance-unclassified",
|
|
223
|
+
"content/catalog/products",
|
|
224
|
+
`${unclassified.length} of ${products.length} catalog product(s) are not classified for compliance (${missingCategory} missing category, ${missingFlavor} missing flavour; e.g. ${sample}) — checkout refuses unclassified products in flavour-ban states`,
|
|
225
|
+
"classify at the source (BigCommerce \"Compliance Category\" and \"Flavor\" custom fields) or run `node agency-kit/tools/classify-catalog.mjs --store <checkout> --suggest <review.csv>`, review every row with the merchant, and apply with `--apply <review.csv> --write` (devbook://storefront-devbook-compliance-classification)",
|
|
226
|
+
),
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function validateCatalogSkus(contentDir, rel, config = null) {
|
|
118
231
|
const dir = join(contentDir, "catalog", "products");
|
|
119
232
|
if (!existsSync(dir)) return [];
|
|
120
233
|
/** @type {Finding[]} */
|
|
@@ -126,7 +239,7 @@ function validateCatalogSkus(contentDir, rel) {
|
|
|
126
239
|
if (error) parseErrors.push(mk(ERROR, "catalog-parse", rel(path), `invalid JSON: ${error}`));
|
|
127
240
|
else products.push({ file: rel(path), record: value });
|
|
128
241
|
}
|
|
129
|
-
return [...parseErrors, ...catalogSkuFindings(products)];
|
|
242
|
+
return [...parseErrors, ...catalogSkuFindings(products), ...catalogComplianceFindings(products, config)];
|
|
130
243
|
}
|
|
131
244
|
|
|
132
245
|
// --- canonical `.tot/config.json` shape (the #24/#25 regression guard) --------
|
|
@@ -995,6 +1108,11 @@ export const LOUD_ADVISORY_RULES = [
|
|
|
995
1108
|
"a previously-declared data-tot-el changed value",
|
|
996
1109
|
"The page still works, but everything already recorded under the old id is now orphaned — this identity is supposed to be permanent.",
|
|
997
1110
|
],
|
|
1111
|
+
[
|
|
1112
|
+
"catalog-compliance-unclassified",
|
|
1113
|
+
"regulated catalog products missing compliance category or flavour classification",
|
|
1114
|
+
"Checkout fails closed in flavour-ban states (CA, MA, NJ, NY, RI) and refuses every unclassified product — including tobacco and unflavoured items — until category and flavour are recorded (see agency-kit/tools/classify-catalog.mjs and devbook://storefront-devbook-compliance-classification).",
|
|
1115
|
+
],
|
|
998
1116
|
];
|
|
999
1117
|
|
|
1000
1118
|
/**
|
|
@@ -1399,7 +1517,7 @@ export function validateTenant(tenantDir, opts = {}) {
|
|
|
1399
1517
|
}
|
|
1400
1518
|
}
|
|
1401
1519
|
|
|
1402
|
-
findings.push(...validateCatalogSkus(contentDir, rel));
|
|
1520
|
+
findings.push(...validateCatalogSkus(contentDir, rel, config));
|
|
1403
1521
|
|
|
1404
1522
|
const capabilitiesPath = located("capabilities.json");
|
|
1405
1523
|
if (existsSync(capabilitiesPath)) {
|