@tokenoftrust/cli 7.5.3 → 7.5.5

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/src/validate.mjs CHANGED
@@ -28,6 +28,7 @@ import { createRedirectShadowCollector, shadowedRedirectMessage } from "./redire
28
28
  import { pageSlugFindings } from "./page-slugs.mjs";
29
29
  import { ANALYTICS_DECLARATION_FILE, analyticsDeclarationFindings } from "./analytics-declaration.mjs";
30
30
  import { parseSku, skuCollisions, skuFindings } from "./sku.mjs";
31
+ import { resolveKnownProductCompliance } from "./known-product-catalog.mjs";
31
32
 
32
33
  export {
33
34
  TOT_CONFIG_KEYS,
@@ -161,25 +162,32 @@ function collectCatalogFlavorLabels(product, variant) {
161
162
 
162
163
  function productClassificationGaps(product) {
163
164
  if (!product || typeof product !== "object") return [];
164
- const category =
165
+ const explicitCategory =
165
166
  readCatalogMetafield(product, "compliance", new Set(["product_category"])) ??
166
167
  readCatalogMetafield(product, "bigcommerce_custom", CATALOG_CATEGORY_FIELDS);
167
168
  const productType = typeof product.product_type === "string" ? product.product_type.trim().toLowerCase() : "";
168
169
  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
170
  const variants = Array.isArray(product.variants) && product.variants.length > 0 ? product.variants : [null];
180
171
  const gaps = new Set();
181
- if (!categoryClassified) gaps.add("category");
182
172
  for (const variant of variants) {
173
+ const explicitFlavors = collectCatalogFlavorLabels(product, variant);
174
+ const known =
175
+ (!explicitCategory && merchantType.length === 0) || explicitFlavors.length === 0
176
+ ? resolveKnownProductCompliance(product, variant)
177
+ : undefined;
178
+ const category = explicitCategory ?? (merchantType.length === 0 ? known?.category : undefined);
179
+ const categoryClassified = Boolean(category) || merchantType.length > 0;
180
+ if (!categoryClassified) gaps.add("category");
181
+ const haystack = [
182
+ merchantType,
183
+ (category ?? "").toLowerCase(),
184
+ typeof product.title === "string" ? product.title.toLowerCase() : "",
185
+ ...(Array.isArray(product.tags) ? product.tags : []).map((t) => String(t ?? "").toLowerCase()),
186
+ ].join(" ");
187
+ const isAccessory =
188
+ ((category ?? "").trim().toLowerCase() === "accessory" ||
189
+ CATALOG_ACCESSORY_HINTS.some((n) => haystack.includes(n))) &&
190
+ !["e-liquid", "eliquid", "juice", "salt"].some((n) => haystack.includes(n));
183
191
  const nicStrength = typeof variant?.option_values?.["Nicotine strength"] === "string"
184
192
  ? variant.option_values["Nicotine strength"].toLowerCase()
185
193
  : undefined;
@@ -188,7 +196,10 @@ function productClassificationGaps(product) {
188
196
  const containsNicotine =
189
197
  !isAccessory &&
190
198
  (nicOptionSaysNonZero || (!nicOptionSaysZero && CATALOG_NICOTINE_HINTS.some((n) => haystack.includes(n))));
191
- const flavorClassified = collectCatalogFlavorLabels(product, variant).length > 0;
199
+ const knownFlavors = (known?.flavors ?? [])
200
+ .map((f) => String(f ?? "").trim().toLowerCase())
201
+ .filter((f) => Boolean(f) && !CATALOG_NICOTINE_FORMAT_LABELS.has(f));
202
+ const flavorClassified = explicitFlavors.length > 0 || knownFlavors.length > 0;
192
203
  if ((containsNicotine || !categoryClassified) && !flavorClassified) gaps.add("flavor");
193
204
  }
194
205
  return ["category", "flavor"].filter((g) => gaps.has(g));