@tokenoftrust/storefront-runner 7.15.0 → 8.0.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.
@@ -15,6 +15,7 @@
15
15
  * Pure + edge-safe.
16
16
  */
17
17
  import type { ComplianceRuleset } from "./ruleset.js";
18
+ import { validateRulePack } from "./ruleset.js";
18
19
 
19
20
  export interface EnforcementEvidenceSignals {
20
21
  /** A data-driven ruleset resolved for this (regulated) tenant. */
@@ -87,9 +88,10 @@ export function enforcementSignals(
87
88
  !ruleset.pactAct.enabled ||
88
89
  !ruleset.pactAct.reportingRequired ||
89
90
  input.reportingCaptureWired;
91
+ const packValid = validateRulePack(ruleset.rulePack).ok;
90
92
  return {
91
93
  rulesetPresent: true,
92
- jurisdictionRulesPresent: ruleset.states.length > 0,
94
+ jurisdictionRulesPresent: packValid && ruleset.rulePack.rules.length > 0,
93
95
  verificationWired,
94
96
  exciseWired,
95
97
  reportingWired,
@@ -9,23 +9,24 @@
9
9
  * authoritative, data-driven per-product source; it is NOT a hardcoded list.
10
10
  * `docs/devkit-staging/books/storefront-devbook-compliance-classification.md`
11
11
  * is how a store records it.
12
- * 2. `product_type` / `tags` — merchant taxonomy (nicotine/vape/e-liquid, the
13
- * `F: <flavor>` tag convention the PDP already reads).
14
- * 3. BigCommerce custom fields (`bigcommerce_custom/Compliance Category`,
15
- * `bigcommerce_custom/Flavor`), which the BigCommerce catalog extract
16
- * carries as metafields.
17
- * 4. the chosen variant's `option_values` (Flavor, Nicotine strength).
18
- * 5. accepted catalog facts (`variant.catalog_link`), authoritative wherever
19
- * they speak.
12
+ * 2. the `F: <flavor>` tag convention the PDP already reads, BigCommerce custom
13
+ * fields (`bigcommerce_custom/Compliance Category`, `bigcommerce_custom/Flavor`)
14
+ * and the chosen variant's Flavor option: explicit merchant DECLARATIONS read
15
+ * by exact vocabulary, never inferred from titles or free text.
16
+ * 3. accepted catalog facts (`variant.catalog_link.facts`): the PRIMARY truth,
17
+ * authoritative wherever they speak; a merchant declaration may only tighten.
20
18
  *
21
- * A product with no classification from any source is reported as such
22
- * (`categoryClassified` / `flavorClassified`) so enforcement can fail closed
23
- * instead of reading "no flavour label" as "unflavoured".
19
+ * Nothing is inferred from substrings of a title, tag or product type. A product
20
+ * with no classification from any source is reported as such
21
+ * (`categoryClassified` / `flavorStatus: "unknown"`) so enforcement can fail closed
22
+ * instead of reading silence as "unflavoured". A missing, unknown, conflicting or
23
+ * invalid catalog fact never resolves to a permissive value.
24
24
  *
25
25
  * Pure + edge-safe (no node, no I/O). The storefront resolves a product's profile
26
26
  * once and feeds it to `evaluateCartCompliance`.
27
27
  */
28
28
  import type { CatalogFact, CatalogLink, CatalogProduct, CatalogVariant, Metafield } from "../product.js";
29
+ import { REGISTRY_JURISDICTIONS, REGISTRY_LISTING_STATUSES } from "./state-directory.js";
29
30
 
30
31
  /** Coarse regulated category. `none` ⇒ not an age/nicotine-restricted product. */
31
32
  export type RegulatedCategory =
@@ -35,14 +36,56 @@ export type RegulatedCategory =
35
36
  | "accessory" // batteries, coils — regulated-adjacent, no nicotine of its own
36
37
  | "none";
37
38
 
39
+ /** Whether a product carries a characterizing flavor; `unknown` is never read as plain. */
40
+ export type FlavorStatus = "characterizing" | "plain" | "unknown";
41
+
42
+ /** How one catalog fact resolves for a product; only `known` carries a value. */
43
+ export type CatalogReading<T> =
44
+ | { state: "known"; value: T }
45
+ | { state: "unknown" | "conflict" | "invalid" | "not_applicable" };
46
+
47
+ export type RegistryListingStatus = (typeof REGISTRY_LISTING_STATUSES)[number];
48
+ export type RegistryJurisdictionCode = (typeof REGISTRY_JURISDICTIONS)[number];
49
+ /** Per-jurisdiction listing status; a jurisdiction absent from the map is `unknown`. */
50
+ export type RegistryListingMap = Partial<Record<RegistryJurisdictionCode, RegistryListingStatus>>;
51
+
52
+ /** The regulatory catalog facts a profile carries, each resolved fail-closed. */
53
+ export interface ProfileCatalogFacts {
54
+ registryListings: CatalogReading<RegistryListingMap>;
55
+ fdaAuthorization: CatalogReading<string>;
56
+ nicotineOrigin: CatalogReading<string>;
57
+ containsLithiumBattery: CatalogReading<boolean>;
58
+ unitWeightGrams: CatalogReading<number>;
59
+ childResistantPackaging: CatalogReading<boolean>;
60
+ manufacturerLegalName: CatalogReading<string>;
61
+ liquidVolumeMl: CatalogReading<number>;
62
+ systemType: CatalogReading<string>;
63
+ }
64
+
65
+ const UNKNOWN_READING = { state: "unknown" } as const;
66
+
67
+ /** Every catalog fact unknown: what a product with no accepted catalog link carries. */
68
+ export const UNKNOWN_CATALOG_FACTS: ProfileCatalogFacts = Object.freeze({
69
+ registryListings: UNKNOWN_READING,
70
+ fdaAuthorization: UNKNOWN_READING,
71
+ nicotineOrigin: UNKNOWN_READING,
72
+ containsLithiumBattery: UNKNOWN_READING,
73
+ unitWeightGrams: UNKNOWN_READING,
74
+ childResistantPackaging: UNKNOWN_READING,
75
+ manufacturerLegalName: UNKNOWN_READING,
76
+ liquidVolumeMl: UNKNOWN_READING,
77
+ systemType: UNKNOWN_READING,
78
+ });
79
+
38
80
  export interface ProductComplianceProfile {
39
81
  /** Carries nicotine / is an ENDS product (the age-gate + excise axis). */
40
82
  containsNicotine: boolean;
41
83
  /**
42
- * Has a characterizing flavor (anything but plain tobacco or unflavoured;
43
- * menthol IS characterizing) — the axis several states ban for ENDS.
84
+ * Characterizing-flavor status (anything but plain tobacco or unflavoured;
85
+ * menthol IS characterizing) — the axis several states ban for ENDS. `unknown`
86
+ * means no source classified it.
44
87
  */
45
- isFlavored: boolean;
88
+ flavorStatus: FlavorStatus;
46
89
  /**
47
90
  * Flavor labels found (lowercased), e.g. ["mango", "ice"]. Nicotine-format
48
91
  * labels filed under `F:` ("nicotine salt", "freebase") are not flavors and
@@ -51,7 +94,7 @@ export interface ProductComplianceProfile {
51
94
  flavorLabels: string[];
52
95
  /**
53
96
  * The subset of `flavorLabels` that is characterizing — the labels that make
54
- * `isFlavored` true, so a flavored-ENDS block can name its trigger.
97
+ * `flavorStatus` characterizing, so a flavored-ENDS block can name its trigger.
55
98
  */
56
99
  characterizingFlavors: string[];
57
100
  /** Derived regulated category. */
@@ -78,15 +121,32 @@ export interface ProductComplianceProfile {
78
121
  * platform-generic type (BigCommerce `physical` / `digital`) is not one.
79
122
  */
80
123
  categoryClassified: boolean;
81
- /** At least one flavour label is recorded (`F:` tag, flavour metafield/custom field, or variant option). */
124
+ /** The flavor is classified: `flavorStatus` is not `unknown`. */
82
125
  flavorClassified: boolean;
83
126
  /**
84
127
  * Contains a synthetic cooling agent: `false` only when the catalog fact or the merchant
85
128
  * records it absent, `true` when either records it present (or the catalog fact is
86
- * conflicting or invalid), `null` when nothing records it. A ban on cooling agents clears
87
- * only `false`.
129
+ * conflicting or invalid, or the flavor classification is menthol-cooling), `null` when
130
+ * nothing records it. A ban on cooling agents clears only `false`.
88
131
  */
89
132
  coolingAgent: boolean | null;
133
+ /** Regulatory catalog facts resolved from `variant.catalog_link.facts`. */
134
+ catalogFacts: ProfileCatalogFacts;
135
+ /**
136
+ * Optional explicit product class identifier for non-ENDS or multi-class rule packs
137
+ * (e.g. `"botanical"`, `"battery"`, `"alcohol"`).
138
+ */
139
+ productClass?: string;
140
+ /**
141
+ * Optional domain fact map keyed by fact name for declarative rule predicates (`facts.<key>`).
142
+ * Raw primitive values resolve as known; `CatalogReading` values preserve `unknown`/`conflict`/`invalid`.
143
+ */
144
+ facts?: Record<string, CatalogReading<string | number | boolean | readonly string[]> | string | number | boolean | readonly string[]>;
145
+ }
146
+
147
+ /** A flavored nicotine product: the profile a flavored-ENDS ban applies to. */
148
+ export function isFlavoredNicotine(p: Pick<ProductComplianceProfile, "containsNicotine" | "flavorStatus">): boolean {
149
+ return p.containsNicotine && p.flavorStatus === "characterizing";
90
150
  }
91
151
 
92
152
  /** A classification the merchant still has to record before the product can be sold everywhere. */
@@ -167,35 +227,12 @@ function isCharacterizingFlavor(label: string): boolean {
167
227
  return !UNFLAVORED.has(label) && !isTobaccoFlavorLabel(label);
168
228
  }
169
229
 
170
- /** Platform-default product types that say nothing about what the product is. */
171
- const GENERIC_PRODUCT_TYPES = new Set(["physical", "digital", "gift_certificate"]);
172
-
173
230
  /** Flavour field names a source catalog uses (variant options, BigCommerce custom fields). */
174
231
  const FLAVOR_FIELD_NAMES = new Set(["flavor", "flavour", "flavors", "flavours"]);
175
232
 
176
233
  /** BigCommerce custom-field names that carry the compliance category. */
177
234
  const CATEGORY_FIELD_NAMES = new Set(["compliance category", "product category", "product_category"]);
178
235
 
179
- const NICOTINE_HINTS = [
180
- "nicotine",
181
- "vape",
182
- "vapor",
183
- "vaping",
184
- "e-liquid",
185
- "eliquid",
186
- "e-juice",
187
- "ejuice",
188
- "e liquid",
189
- "salt nic",
190
- "nic salt",
191
- "pod",
192
- "disposable",
193
- "ends",
194
- "cig",
195
- ];
196
-
197
- const ACCESSORY_HINTS = ["battery", "coil", "charger", "case", "lanyard"];
198
-
199
236
  function readMetafield(
200
237
  product: Pick<CatalogProduct, "metafields">,
201
238
  namespace: string,
@@ -311,10 +348,6 @@ function collectFlavors(
311
348
  return [...labels];
312
349
  }
313
350
 
314
- function containsAny(haystack: string, needles: string[]): boolean {
315
- return needles.some((n) => haystack.includes(n));
316
- }
317
-
318
351
  /** How restrictive a regulated category is; a merchant signal may only move a category up. */
319
352
  const CATEGORY_RANK: Record<RegulatedCategory, number> = {
320
353
  none: 0,
@@ -423,6 +456,76 @@ function readCatalogSignals(links: ReadonlyArray<Pick<CatalogLink, "facts">>): C
423
456
  };
424
457
  }
425
458
 
459
+ /** One link's fact as a reading: a missing fact, an unreadable value or an unknown state never reads as known. */
460
+ function readingOf<T>(
461
+ fact: CatalogFact | undefined,
462
+ parse: (value: CatalogFact["value"]) => T | undefined,
463
+ ): CatalogReading<T> {
464
+ if (!fact) return { state: "unknown" };
465
+ if (fact.state === "known") {
466
+ const value = parse(fact.value);
467
+ return value === undefined ? { state: "invalid" } : { state: "known", value };
468
+ }
469
+ return { state: fact.state };
470
+ }
471
+
472
+ /**
473
+ * Fold the per-link readings of one fact into one reading. Any conflict, then any invalid, then
474
+ * any unknown wins over a known value; known values that differ are a conflict.
475
+ */
476
+ function mergeReadings<T>(readings: ReadonlyArray<CatalogReading<T>>): CatalogReading<T> {
477
+ if (readings.length === 0) return { state: "unknown" };
478
+ for (const state of ["conflict", "invalid", "unknown"] as const) {
479
+ if (readings.some((r) => r.state === state)) return { state };
480
+ }
481
+ if (readings.every((r) => r.state === "not_applicable")) return { state: "not_applicable" };
482
+ const known = readings.filter((r): r is Extract<CatalogReading<T>, { state: "known" }> => r.state === "known");
483
+ if (known.length !== readings.length) return { state: "conflict" };
484
+ const first = JSON.stringify(known[0]!.value);
485
+ return known.every((r) => JSON.stringify(r.value) === first) ? known[0]! : { state: "conflict" };
486
+ }
487
+
488
+ const asString = (v: CatalogFact["value"]) => (typeof v === "string" && v.length > 0 ? v : undefined);
489
+ const asBoolean = (v: CatalogFact["value"]) => (typeof v === "boolean" ? v : undefined);
490
+ const asNumber = (v: CatalogFact["value"]) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
491
+
492
+ const JURISDICTION_SET: ReadonlySet<string> = new Set(REGISTRY_JURISDICTIONS);
493
+ const LISTING_STATUS_SET: ReadonlySet<string> = new Set(REGISTRY_LISTING_STATUSES);
494
+
495
+ /**
496
+ * `registry_listings` carries one `<JURISDICTION>:<status>` string per jurisdiction. An entry that
497
+ * names no known jurisdiction or status, or a jurisdiction named twice, makes the whole fact invalid.
498
+ */
499
+ function asRegistryListings(v: CatalogFact["value"]): RegistryListingMap | undefined {
500
+ if (!Array.isArray(v) || v.length === 0) return undefined;
501
+ const out: RegistryListingMap = {};
502
+ for (const entry of v) {
503
+ if (typeof entry !== "string") return undefined;
504
+ const [jurisdiction, status, ...rest] = entry.split(":");
505
+ if (rest.length > 0 || !jurisdiction || !status) return undefined;
506
+ if (!JURISDICTION_SET.has(jurisdiction) || !LISTING_STATUS_SET.has(status)) return undefined;
507
+ if (jurisdiction in out) return undefined;
508
+ out[jurisdiction as RegistryJurisdictionCode] = status as RegistryListingStatus;
509
+ }
510
+ return out;
511
+ }
512
+
513
+ function readCatalogFacts(links: ReadonlyArray<Pick<CatalogLink, "facts">>): ProfileCatalogFacts {
514
+ const read = <T>(key: string, parse: (value: CatalogFact["value"]) => T | undefined) =>
515
+ mergeReadings(links.map((link) => readingOf(factOf(link, key), parse)));
516
+ return {
517
+ registryListings: read("registry_listings", asRegistryListings),
518
+ fdaAuthorization: read("fda_authorization", asString),
519
+ nicotineOrigin: read("nicotine_origin", asString),
520
+ containsLithiumBattery: read("contains_lithium_battery", asBoolean),
521
+ unitWeightGrams: read("unit_weight_grams", asNumber),
522
+ childResistantPackaging: read("child_resistant_packaging", asBoolean),
523
+ manufacturerLegalName: read("manufacturer_legal_name", asString),
524
+ liquidVolumeMl: read("liquid_volume_ml", asNumber),
525
+ systemType: read("system_type", asString),
526
+ };
527
+ }
528
+
426
529
  /** A merchant-declared yes/no; anything else is no declaration. */
427
530
  function parseYesNo(raw: string | undefined): boolean | null {
428
531
  const v = (raw ?? "").trim().toLowerCase();
@@ -437,50 +540,6 @@ function tightenCooling(catalog: boolean | null, merchant: boolean | null): bool
437
540
  return catalog ?? merchant;
438
541
  }
439
542
 
440
- /**
441
- * Cooling signals matched per word token, by stem, so "iced", "frozen", "peppermint", "minty" and
442
- * "koolada" read as cooling while "juice", "slice" and "spice" (whole tokens that merely end in
443
- * "ice") do not. Over-matching only blocks, never clears.
444
- */
445
- const COOLING_TOKEN =
446
- /^(?:ice[dsy]?|icee|icey|freez\w*|froze\w*|frost\w*|chill\w*|cool\w*|kool\w*|menthol\w*|\w*mint\w*|wintergreen|arctic|polar|glacier)$/;
447
- const COOLING_COMPOUND = /ws[\s-]?(?:23|3)(?![0-9])|winter\s+green/;
448
-
449
- function hasCoolingSignal(text: string): boolean {
450
- const t = text.toLowerCase();
451
- return COOLING_COMPOUND.test(t) || t.split(/[^a-z0-9]+/).some((w) => COOLING_TOKEN.test(w));
452
- }
453
-
454
- /**
455
- * Cooling status when no metafield or catalog fact declares it. A classified product (category and
456
- * flavor recorded) with no cooling signal in its flavor labels, title or tags has none (`false`);
457
- * a signal reads `true`; an unclassified product stays `null` (fail closed).
458
- */
459
- function inferCoolingAgent(input: {
460
- classified: boolean;
461
- flavorLabels: string[];
462
- title: string;
463
- tags: string[];
464
- optionValues: string[];
465
- }): boolean | null {
466
- if (!input.classified) return null;
467
- return [...input.flavorLabels, input.title, ...input.tags, ...input.optionValues].some(hasCoolingSignal);
468
- }
469
-
470
- /** Variant option values (chosen variant, else every variant), minus the nicotine-strength axis. */
471
- function optionValuesOf(
472
- product: { variants?: ReadonlyArray<{ option_values?: Record<string, string> }> },
473
- variant: { option_values?: Record<string, string> } | null | undefined,
474
- ): string[] {
475
- const variants = variant ? [variant] : (product.variants ?? []);
476
- return variants.flatMap((v) =>
477
- Object.entries(v.option_values ?? {})
478
- .filter(([name]) => name.trim().toLowerCase() !== "nicotine strength")
479
- .map(([, value]) => value)
480
- .filter(Boolean),
481
- );
482
- }
483
-
484
543
  /** The accepted catalog links a profile reads: the chosen variant's, else every variant's. */
485
544
  function catalogLinksOf(
486
545
  product: { variants?: ReadonlyArray<{ catalog_link?: CatalogVariant["catalog_link"] }> },
@@ -490,20 +549,21 @@ function catalogLinksOf(
490
549
  return (product.variants ?? []).flatMap((v) => (v.catalog_link ? [v.catalog_link] : []));
491
550
  }
492
551
 
493
- /** The category an explicit merchant category string names; text that names nothing regulated is `none`. */
552
+ /**
553
+ * The category a merchant's explicit category declaration names, by exact vocabulary
554
+ * (the catalog categories plus `ends`). A declaration outside that vocabulary reads as
555
+ * `other-nicotine`: it names something, and unrecognized is never unregulated.
556
+ */
494
557
  function categoryOfExplicitText(text: string): RegulatedCategory {
495
- const t = text.toLowerCase();
496
- if (t.trim() === "accessory" || containsAny(t, ACCESSORY_HINTS)) return "accessory";
497
- if (containsAny(t, ["e-liquid", "eliquid", "juice", "salt"])) return "e-liquid";
498
- if (containsAny(t, ["pod", "device", "kit", "disposable", "vape", "ends"])) return "ends";
499
- if (containsAny(t, NICOTINE_HINTS)) return "other-nicotine";
500
- return "none";
558
+ const t = text.trim().toLowerCase().replace(/[_\s]+/g, "-");
559
+ if (t === "ends") return "ends";
560
+ return CATALOG_CATEGORY[t] ?? "other-nicotine";
501
561
  }
502
562
 
503
563
  /**
504
- * Derive a product's compliance profile. Optionally pass the chosen `variant` to
505
- * refine flavor/nicotine from the selected option values (e.g. a "0mg" variant is
506
- * not treated as nicotine-bearing on the nicotine-strength axis).
564
+ * Derive a product's compliance profile from its accepted catalog facts (the chosen `variant`'s
565
+ * link, else every variant's), tightened but never loosened by the merchant's explicit
566
+ * declarations. Nothing is inferred from a title, tag or product type.
507
567
  */
508
568
  export function deriveProductProfile(
509
569
  product: Pick<
@@ -530,17 +590,7 @@ export function deriveProductProfile(
530
590
  const explicitCategory =
531
591
  readMetafield(product, "compliance", "product_category") ??
532
592
  readCustomField(product, CATEGORY_FIELD_NAMES);
533
- const productType = product.product_type?.trim().toLowerCase() ?? "";
534
- const merchantType = GENERIC_PRODUCT_TYPES.has(productType) ? "" : productType;
535
593
  const explicitFlavors = collectFlavors(product, variant);
536
- const category = explicitCategory;
537
- const categoryClassified = Boolean(category) || merchantType.length > 0;
538
- const haystack = [
539
- merchantType,
540
- (category ?? "").toLowerCase(),
541
- (product.title ?? "").toLowerCase(),
542
- ...(product.tags ?? []).map((t) => t.toLowerCase()),
543
- ].join(" ");
544
594
 
545
595
  const restrictedRegions = parseRestrictedRegions(
546
596
  readMetafield(product, "compliance", "restricted_states"),
@@ -549,84 +599,51 @@ export function deriveProductProfile(
549
599
  readMetafield(product, "compliance", "allowed_states"),
550
600
  );
551
601
 
552
- const isAccessory =
553
- ((category ?? "").trim().toLowerCase() === "accessory" ||
554
- containsAny(haystack, ACCESSORY_HINTS)) &&
555
- !containsAny(haystack, ["e-liquid", "eliquid", "juice", "salt"]);
556
-
557
- // Nicotine strength option: a stated non-zero strength is a strong signal; an
558
- // explicit "0mg"/"0 mg" variant is NOT treated as nicotine on that axis.
559
- const nicStrength = variant?.option_values?.["Nicotine strength"]?.toLowerCase();
560
- const nicOptionSaysZero = nicStrength != null && /^0\s*mg\b/.test(nicStrength);
561
- const nicOptionSaysNonZero =
562
- nicStrength != null && /\d/.test(nicStrength) && !nicOptionSaysZero;
563
-
564
- const heuristicNicotine =
565
- !isAccessory &&
566
- (nicOptionSaysNonZero ||
567
- (!nicOptionSaysZero && containsAny(haystack, NICOTINE_HINTS)));
568
-
569
- const heuristicLabels = explicitFlavors;
570
-
571
- let heuristicCat: RegulatedCategory = "none";
572
- if (isAccessory) heuristicCat = "accessory";
573
- else if (containsAny(haystack, ["e-liquid", "eliquid", "juice", "salt"]))
574
- heuristicCat = "e-liquid";
575
- else if (heuristicNicotine && containsAny(haystack, ["pod", "device", "kit", "disposable", "vape", "ends"]))
576
- heuristicCat = "ends";
577
- else if (heuristicNicotine) heuristicCat = "other-nicotine";
578
-
579
- // Accepted catalog facts are authoritative where they speak: heuristics never apply to a
580
- // dimension a fact decides. A merchant's explicit declaration may only TIGHTEN a known fact.
581
- const signals = readCatalogSignals(catalogLinksOf(product, variant));
602
+ const links = catalogLinksOf(product, variant);
603
+ const signals = readCatalogSignals(links);
582
604
  const merchantCategory = explicitCategory ? categoryOfExplicitText(explicitCategory) : undefined;
583
- const merchantNicotine = merchantCategory !== undefined && CATEGORY_RANK[merchantCategory] >= 2;
584
-
585
- let containsNicotine = signals?.containsNicotine === undefined
586
- ? heuristicNicotine
587
- : signals.containsNicotine || merchantNicotine;
588
605
 
589
606
  let cat: RegulatedCategory;
590
- if (signals?.category === undefined) cat = heuristicCat;
607
+ if (signals?.category === undefined) cat = merchantCategory ?? "none";
591
608
  else if (merchantCategory !== undefined && CATEGORY_RANK[merchantCategory] > CATEGORY_RANK[signals.category]) cat = merchantCategory;
592
609
  else cat = signals.category;
610
+ const categoryClassified = signals?.category !== undefined || merchantCategory !== undefined;
611
+
612
+ // A known `has_nicotine` fact decides; without one, a regulated category is nicotine-bearing
613
+ // until the catalog says otherwise (an unclassified product is caught by the classification gap).
614
+ const merchantNicotine = merchantCategory !== undefined && CATEGORY_RANK[merchantCategory] >= 2;
615
+ const containsNicotine = signals?.containsNicotine === undefined
616
+ ? CATEGORY_RANK[cat] >= 2
617
+ : signals.containsNicotine || merchantNicotine;
593
618
  if (containsNicotine && (cat === "none" || cat === "accessory")) cat = "other-nicotine";
594
619
 
595
- const labels = new Set(signals?.characterizing === undefined ? heuristicLabels : []);
596
- if (signals) {
597
- for (const l of explicitFlavors) labels.add(l);
598
- for (const l of signals.flavorLabels) labels.add(l);
599
- if (signals.characterizing === true && !signals.flavorLabels.some(isCharacterizingFlavor)) labels.add(signals.characterizingLabel);
600
- }
620
+ const labels = new Set<string>(explicitFlavors);
621
+ for (const l of signals?.flavorLabels ?? []) labels.add(l);
622
+ if (signals?.characterizing === true && !signals.flavorLabels.some(isCharacterizingFlavor)) labels.add(signals.characterizingLabel);
601
623
  const flavorLabels = [...labels];
602
624
  const characterizingFlavors = flavorLabels.filter(isCharacterizingFlavor);
603
- const isFlavored = containsNicotine && (signals?.characterizing === true || characterizingFlavors.length > 0);
625
+ let flavorStatus: FlavorStatus;
626
+ if (signals?.characterizing === true || characterizingFlavors.length > 0) flavorStatus = "characterizing";
627
+ else if (signals?.characterizing === false || signals?.flavorClassified === true || flavorLabels.length > 0) flavorStatus = "plain";
628
+ else flavorStatus = "unknown";
604
629
 
605
630
  const merchantCooling = parseYesNo(readMetafield(product, "compliance", "cooling_agent"));
606
631
  const declaredCooling = tightenCooling(signals?.coolingAgent ?? null, merchantCooling);
607
- const coolingAgent =
608
- declaredCooling !== null
609
- ? declaredCooling
610
- : inferCoolingAgent({
611
- classified: (categoryClassified || signals?.category !== undefined) && (flavorLabels.length > 0 || signals?.flavorClassified === true),
612
- flavorLabels: signals?.mentholCooling ? [...flavorLabels, "menthol"] : flavorLabels,
613
- title: product.title ?? "",
614
- tags: product.tags ?? [],
615
- optionValues: optionValuesOf(product, variant),
616
- });
632
+ const coolingAgent = declaredCooling ?? (signals?.mentholCooling ? true : null);
617
633
 
618
634
  return {
619
635
  containsNicotine,
620
- isFlavored,
636
+ flavorStatus,
621
637
  flavorLabels,
622
638
  characterizingFlavors,
623
639
  category: cat,
624
640
  restrictedRegions,
625
641
  allowedRegions: allowed.regions,
626
642
  ...(allowed.rejected.length > 0 ? { allowedRegionsRejected: allowed.rejected } : {}),
627
- categoryClassified: categoryClassified || signals?.category !== undefined,
628
- flavorClassified: flavorLabels.length > 0 || signals?.flavorClassified === true,
643
+ categoryClassified,
644
+ flavorClassified: flavorStatus !== "unknown",
629
645
  coolingAgent,
646
+ catalogFacts: links.length === 0 ? UNKNOWN_CATALOG_FACTS : readCatalogFacts(links),
630
647
  };
631
648
  }
632
649
 
@@ -651,6 +668,7 @@ export function isRegulatedProfile(p: ProductComplianceProfile): boolean {
651
668
  p.containsNicotine ||
652
669
  p.category !== "none" ||
653
670
  p.restrictedRegions.length > 0 ||
654
- p.allowedRegions != null
671
+ p.allowedRegions != null ||
672
+ (p.productClass !== undefined && p.productClass !== "none")
655
673
  );
656
674
  }