@tokenoftrust/cli 8.3.0 → 8.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
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",
@@ -105,12 +105,39 @@ const STRING_FACTS = new Set([
105
105
  const STRING_LIST_FACTS = new Set(["flavor_labels", "registry_listings"]);
106
106
 
107
107
  /**
108
- * Regulatory fact declarations on catalog products (`variants[].catalog_link.facts`, storefront-catalog
109
- * v2.1.0): a known fact carries a value of its key's type, any other state carries none, and a key is
110
- * declared once per variant. Errors, because checkout reads these as the primary eligibility truth.
108
+ * Reject foreign-owned catalog attributes (`catalog_link.facts` or `catalog_link.identifiers`)
109
+ * committed into tenant catalog files (ADR 0048). Merchant git stores pointer-only links;
110
+ * Storefront hydrates Layer 1 facts from `product-catalog` into derived projections.
111
111
  * @param {Array<{ file: string, record: any }>} products
112
112
  */
113
113
  export function catalogFactFindings(products) {
114
+ const out = [];
115
+ for (const { file, record } of products) {
116
+ const variants = Array.isArray(record?.variants) ? record.variants : [];
117
+ variants.forEach((variant, vi) => {
118
+ const link = variant?.catalog_link;
119
+ if (!isObject(link)) return;
120
+ if (link.facts !== undefined || link.identifiers !== undefined || link.facts_state !== undefined) {
121
+ out.push({
122
+ level: "error",
123
+ rule: "catalog-link-committed-facts",
124
+ file: `${file} variants[${vi}].catalog_link`,
125
+ message: "Tenant catalog files must not commit catalog_link.facts, catalog_link.identifiers, or catalog_link.facts_state (ADR 0048).",
126
+ fix: "Store only the catalog_link pointer (item_id, accepted_revision_id); Storefront hydrates facts from product-catalog during reconcile and publish.",
127
+ });
128
+ }
129
+ });
130
+ }
131
+ return out;
132
+ }
133
+
134
+ /**
135
+ * Validate hydrated regulatory fact arrays (`variants[].catalog_link.facts`, storefront-catalog
136
+ * v2.1.0): a known fact carries a value of its key's type, any other state carries none, and a
137
+ * key is declared once per variant.
138
+ * @param {Array<{ file: string, record: any }>} products
139
+ */
140
+ export function catalogHydratedFactFindings(products) {
114
141
  const out = [];
115
142
  for (const { file, record } of products) {
116
143
  const variants = Array.isArray(record?.variants) ? record.variants : [];
@@ -120,7 +147,7 @@ export function catalogFactFindings(products) {
120
147
  const at = `variants[${vi}].catalog_link.facts`;
121
148
  const err = (rule, i, message, fix) => out.push({ level: "error", rule, file: `${file} ${at}[${i}]`, message, fix });
122
149
  if (!Array.isArray(facts)) {
123
- out.push({ level: "error", rule: "catalog-fact-shape", file: `${file} ${at}`, message: "`catalog_link.facts` must be an array.", fix: "Re-accept the catalog item to rewrite its facts." });
150
+ out.push({ level: "error", rule: "catalog-fact-shape", file: `${file} ${at}`, message: "`catalog_link.facts` must be an array.", fix: "Re-hydrate the catalog facts projection from product-catalog." });
124
151
  return;
125
152
  }
126
153
  const seen = new Set();
package/src/validate.mjs CHANGED
@@ -157,14 +157,26 @@ function collectCatalogFlavorLabels(product, variant) {
157
157
  const catalogFactOf = (variant, key) =>
158
158
  (Array.isArray(variant?.catalog_link?.facts) ? variant.catalog_link.facts : []).find((f) => f?.key === key);
159
159
 
160
+ /** True when a variant carries a valid pointer-only `catalog_link` pin (ADR 0048). */
161
+ const hasCatalogLinkPointer = (variant) =>
162
+ Boolean(
163
+ variant?.catalog_link &&
164
+ typeof variant.catalog_link === "object" &&
165
+ typeof variant.catalog_link.item_id === "string" &&
166
+ variant.catalog_link.item_id.trim().length > 0 &&
167
+ typeof variant.catalog_link.accepted_revision_id === "string" &&
168
+ variant.catalog_link.accepted_revision_id.trim().length > 0,
169
+ );
170
+
160
171
  /** A catalog fact settles a field unless it is unknown; conflicting/invalid facts settle it restrictively. */
161
172
  const factDecides = (fact) => fact !== undefined && fact.state !== "unknown";
162
173
 
163
174
  /**
164
- * The classification a product still lacks. The accepted catalog facts
165
- * (`variants[].catalog_link.facts`) are the primary truth; merchant fields are the secondary
166
- * declaration. Nothing is inferred from a title, tag or product type: a product whose category is
167
- * not recorded is unclassified, and a nicotine-bearing one needs a flavour reading.
175
+ * The classification a product still lacks. A variant carrying a valid pointer-only `catalog_link`
176
+ * receives its Layer 1 facts via derived hydration (ADR 0048) and does not trigger an offline gap.
177
+ * For unlinked variants (or hydrated records), accepted catalog facts are the primary truth and
178
+ * merchant fields are the secondary declaration; nothing is inferred from a title, tag, or
179
+ * product type.
168
180
  */
169
181
  function productClassificationGaps(product) {
170
182
  if (!product || typeof product !== "object") return [];
@@ -174,6 +186,7 @@ function productClassificationGaps(product) {
174
186
  const variants = Array.isArray(product.variants) && product.variants.length > 0 ? product.variants : [null];
175
187
  const gaps = new Set();
176
188
  for (const variant of variants) {
189
+ if (hasCatalogLinkPointer(variant) && !Array.isArray(variant.catalog_link.facts)) continue;
177
190
  const categoryFact = catalogFactOf(variant, "compliance_category");
178
191
  const category = categoryFact?.state === "known" && typeof categoryFact.value === "string" ? categoryFact.value : explicitCategory;
179
192
  const categoryClassified = factDecides(categoryFact) || Boolean(category);