@tokenoftrust/cli 7.4.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "7.4.1",
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",
@@ -0,0 +1,261 @@
1
+ // @ts-check
2
+ /**
3
+ * Precedence between the routes a release GENERATES and the redirects its content DECLARES: a route
4
+ * the release generates wins over a declared redirect whose exact source is that route. The redirect
5
+ * is dropped from what the release publishes and reported as a non-blocking warning; it is never a
6
+ * reason to refuse a publish.
7
+ *
8
+ * A redirect declared for a URL that did not exist yet goes stale the day the content grows into it:
9
+ * a leftover `"blog/page/9": "blog"` does nothing while the blog has 8 pages, and would send the 9th
10
+ * page away the day one more post is written. Only EXACT sources yield; a `<dir>/*` rule is a
11
+ * deliberate statement about a whole family of URLs and keeps answering.
12
+ *
13
+ * Pure: callers pass the declaration files they read (`{path, json}`, the shape
14
+ * `declaredRedirectsFromContent` takes) and the route set they know, so the publish, the preview
15
+ * reconcile, the kit and `tot validate` apply one rule.
16
+ * `packages/cli/src/redirect-shadows.mjs` is a byte-identical copy (a test pins it).
17
+ */
18
+
19
+ /** The finding prefix the publish pipeline classifies as non-blocking (`finding-severity`). */
20
+ export const SHADOWED_REDIRECT_PREFIX = "REDIRECT";
21
+
22
+ /** The tenant-wide declaration, and a content collection's slug-rename map. */
23
+ const SITE_REDIRECTS_PATH = "content/redirects.json";
24
+ const COLLECTION_REDIRECTS_PATH = /^content\/([A-Za-z0-9][A-Za-z0-9_-]*)\/redirects\.json$/;
25
+
26
+ /** Posts per collection index page when a collection declares no valid `pageSize`. */
27
+ const DEFAULT_PAGE_SIZE = 12;
28
+
29
+ /**
30
+ * The form a route and a redirect source are compared in: root-absolute, no query or fragment, a
31
+ * trailing slash unless the last segment names a file. Null when `raw` is not a same-origin path.
32
+ * The same normalization the redirect contract applies to a declared source.
33
+ * @param {unknown} raw
34
+ * @returns {string | null}
35
+ */
36
+ export function routeKey(raw) {
37
+ if (typeof raw !== "string") return null;
38
+ const trimmed = raw.trim();
39
+ if (!trimmed.startsWith("/") || trimmed.startsWith("//") || trimmed.includes("*")) return null;
40
+ const path = trimmed.replace(/[?#].*$/, "");
41
+ if (path.includes("..") || path.includes("\\")) return null;
42
+ const collapsed = path.replace(/\/{2,}/g, "/");
43
+ if (collapsed === "/") return "/";
44
+ const segments = collapsed.split("/").filter(Boolean);
45
+ if ((segments[segments.length - 1] ?? "").includes(".")) return collapsed.replace(/\/$/, "");
46
+ return collapsed.endsWith("/") ? collapsed : `${collapsed}/`;
47
+ }
48
+
49
+ /**
50
+ * A matcher over a list of generated route paths, in any slash form.
51
+ * @param {Iterable<string>} paths
52
+ * @returns {(source: string) => boolean}
53
+ */
54
+ export function routeMatcher(paths) {
55
+ const keys = new Set();
56
+ for (const path of paths) {
57
+ const key = routeKey(path);
58
+ if (key) keys.add(key);
59
+ }
60
+ return (source) => keys.has(source);
61
+ }
62
+
63
+ /**
64
+ * @typedef {{file: string, key: string, value: unknown, source: string}} ShadowedRedirect
65
+ * `file` the declaration it came from, `key`/`value` the entry exactly as written, `source` the
66
+ * generated route it would have redirected.
67
+ */
68
+
69
+ /**
70
+ * Split declaration files into the entries that still apply and the ones a generated route shadows.
71
+ * The files come back with the shadowed entries removed and every other entry untouched, so the
72
+ * caller hands them to the redirect contract exactly as it would have handed the originals; a file
73
+ * that is not a key/value object passes through unchanged for the contract to refuse.
74
+ * @template {{path: string, json: unknown}} T
75
+ * @param {readonly T[]} declarations
76
+ * @param {(source: string) => boolean} isRoute called with a source in `routeKey` form
77
+ * @returns {{declarations: T[], shadowed: ShadowedRedirect[]}}
78
+ */
79
+ export function redirectsYieldingToRoutes(declarations, isRoute) {
80
+ /** @type {T[]} */
81
+ const kept = [];
82
+ /** @type {ShadowedRedirect[]} */
83
+ const shadowed = [];
84
+ for (const declaration of declarations ?? []) {
85
+ const collection = COLLECTION_REDIRECTS_PATH.exec(declaration?.path ?? "")?.[1];
86
+ const json = declaration?.json;
87
+ if ((declaration?.path !== SITE_REDIRECTS_PATH && !collection) ||
88
+ !json || typeof json !== "object" || Array.isArray(json)) {
89
+ kept.push(declaration);
90
+ continue;
91
+ }
92
+ /** @type {Record<string, unknown>} */
93
+ const rows = {};
94
+ for (const [key, value] of Object.entries(json)) {
95
+ const source = collection
96
+ ? (key ? routeKey(`/${collection}/${key}/`) : null)
97
+ : (key && !key.startsWith("/") ? routeKey(`/${key}`) : null);
98
+ if (source !== null && isRoute(source)) shadowed.push({ file: declaration.path, key, value, source });
99
+ else rows[key] = value;
100
+ }
101
+ kept.push({ ...declaration, json: rows });
102
+ }
103
+ return { declarations: kept, shadowed };
104
+ }
105
+
106
+ /** @param {number} n */
107
+ function ordinal(n) {
108
+ const tens = n % 100;
109
+ const suffix = tens >= 11 && tens <= 13 ? "th" : ({ 1: "st", 2: "nd", 3: "rd" })[n % 10] ?? "th";
110
+ return `${n}${suffix}`;
111
+ }
112
+
113
+ /** @param {string} collection */
114
+ function collectionName(collection) {
115
+ return collection === "blog" ? "The blog" : `The ${collection} collection`;
116
+ }
117
+
118
+ /**
119
+ * Why the content now generates `source`, as the start of a sentence.
120
+ * @param {string} source a route in `routeKey` form
121
+ */
122
+ export function generatedRouteReason(source) {
123
+ const parts = source.split("/").filter(Boolean);
124
+ const [collection, kind, value] = parts;
125
+ if (collection === "blog" || collection === "the-build") {
126
+ if (parts.length === 3 && kind === "page" && /^[1-9][0-9]*$/.test(value ?? "")) {
127
+ return `${collectionName(collection)} now has a ${ordinal(Number(value))} page`;
128
+ }
129
+ if (parts.length === 3 && (kind === "tag" || kind === "category" || kind === "author")) {
130
+ return `${collectionName(collection)} now has a page for the ${kind} "${value}"`;
131
+ }
132
+ if (parts.length === 2) {
133
+ return `${collection === "blog" ? "A blog post" : `A post in the ${collection} collection`} now lives at ${source}`;
134
+ }
135
+ }
136
+ return `A page now lives at ${source}`;
137
+ }
138
+
139
+ /**
140
+ * The plain-language warning for one shadowed redirect: the file, the exact entry, what now
141
+ * generates that page and why, and what to do.
142
+ * @param {ShadowedRedirect} entry
143
+ */
144
+ export function shadowedRedirectMessage(entry) {
145
+ return `Your ${entry.file} has an old redirect, ${JSON.stringify(entry.key)}: ${JSON.stringify(entry.value)}. ` +
146
+ `${generatedRouteReason(entry.source)}, and that redirect would send it away. ` +
147
+ "The page is served; delete the redirect entry to clear this warning.";
148
+ }
149
+
150
+ /** The warning as a publish finding: `REDIRECT: <message>`. @param {ShadowedRedirect} entry */
151
+ export function shadowedRedirectFinding(entry) {
152
+ return `${SHADOWED_REDIRECT_PREFIX}: ${shadowedRedirectMessage(entry)}`;
153
+ }
154
+
155
+ /**
156
+ * Is a post listed on the live site's index pages? A missing status is published; a scheduled post
157
+ * counts once its time has come.
158
+ * @param {any} post @param {number} now
159
+ */
160
+ function listable(post, now) {
161
+ const status = post?.status ?? "published";
162
+ if (status === "published") return true;
163
+ return status === "scheduled" && typeof post?.scheduledAt === "string" && Date.parse(post.scheduledAt) <= now;
164
+ }
165
+
166
+ /** @param {any} post @param {number} now */
167
+ function visible(post, now) {
168
+ return (post?.status ?? "published") === "unlisted" || listable(post, now);
169
+ }
170
+
171
+ /** @param {unknown} value */
172
+ function taxonomySlug(value) {
173
+ return typeof value === "string" ? value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") : "";
174
+ }
175
+
176
+ /**
177
+ * The routes a store's content generates at the default collection bases: each editorial page at
178
+ * its slug, each visible post, each tag and category archive of a listed post, and every index page
179
+ * of a collection. The publish judges against the routes it actually rendered; this is the same
180
+ * question asked of the content, so authoring tools can warn before a publish.
181
+ * @param {{pages?: {slug?: unknown}[], collections?: Record<string, {posts?: {slug: string, post: any}[], settings?: any}>, now?: number}} content
182
+ * @returns {Set<string>} routes in `routeKey` form
183
+ */
184
+ export function contentGeneratedRoutes({ pages = [], collections = {}, now = Date.now() }) {
185
+ const routes = new Set();
186
+ const add = (/** @type {string} */ path) => {
187
+ const key = routeKey(path);
188
+ if (key) routes.add(key);
189
+ };
190
+ for (const page of pages) if (typeof page?.slug === "string" && page.slug) add(`/${page.slug}`);
191
+ for (const [collection, { posts = [], settings } = {}] of Object.entries(collections)) {
192
+ const pageSize = Number.isInteger(settings?.pageSize) && settings.pageSize > 0 ? settings.pageSize : DEFAULT_PAGE_SIZE;
193
+ let listed = 0;
194
+ for (const { slug, post } of posts) {
195
+ if (visible(post, now)) add(`/${collection}/${slug}`);
196
+ if (!listable(post, now)) continue;
197
+ listed++;
198
+ for (const kind of /** @type {const} */ (["tags", "categories"])) {
199
+ for (const value of Array.isArray(post?.[kind]) ? post[kind] : []) {
200
+ const term = taxonomySlug(value);
201
+ if (term) add(`/${collection}/${kind === "tags" ? "tag" : "category"}/${term}`);
202
+ }
203
+ }
204
+ }
205
+ if (listed > 0) add(`/${collection}`);
206
+ for (let page = 2; page <= Math.ceil(listed / pageSize); page++) add(`/${collection}/page/${page}`);
207
+ }
208
+ return routes;
209
+ }
210
+
211
+ /** The collections whose posts the platform renders at their default base. */
212
+ const POST_COLLECTIONS = /^(blog|the-build)\/(?:posts\/([^/]+)\.json|settings\.json)$/;
213
+
214
+ /**
215
+ * Collects, file by file, what the shadowed-redirect check needs from a store's `content/` tree,
216
+ * keeping only the few fields it reads (a slug, a post's status and taxonomy, a page size), so a
217
+ * caller streaming a large tree never holds it. A file that does not parse is skipped: the content
218
+ * validators own that finding.
219
+ */
220
+ export function createRedirectShadowCollector() {
221
+ /** @type {{slug?: unknown}[]} */
222
+ const pages = [];
223
+ /** @type {Record<string, {posts: {slug: string, post: any}[], settings?: any}>} */
224
+ const collections = {};
225
+ /** @type {{path: string, json: unknown}[]} */
226
+ const declarations = [];
227
+ const collection = (/** @type {string} */ name) => (collections[name] ??= { posts: [] });
228
+ return {
229
+ /**
230
+ * @param {string} rel path under `content/`, e.g. `blog/posts/hello.json`
231
+ * @param {string} text
232
+ */
233
+ add(rel, text) {
234
+ const declaration = rel === "redirects.json" || COLLECTION_REDIRECTS_PATH.test(`content/${rel}`);
235
+ const html = /^pages-html\/(.+)\.html$/.exec(rel);
236
+ const post = POST_COLLECTIONS.exec(rel);
237
+ if (html) {
238
+ pages.push({ slug: html[1] });
239
+ return;
240
+ }
241
+ if (!declaration && !post && !/^pages\/[^/]+\.json$/.test(rel)) return;
242
+ let json;
243
+ try {
244
+ json = JSON.parse(text);
245
+ } catch {
246
+ return;
247
+ }
248
+ if (declaration) declarations.push({ path: `content/${rel}`, json });
249
+ else if (!post) pages.push({ slug: json?.slug });
250
+ else if (post[2] === undefined) collection(post[1] ?? "").settings = { pageSize: json?.pageSize };
251
+ else collection(post[1] ?? "").posts.push({ slug: post[2], post: {
252
+ status: json?.status, scheduledAt: json?.scheduledAt, tags: json?.tags, categories: json?.categories,
253
+ } });
254
+ },
255
+ /** The declared redirects the collected content shadows. @param {number} [now] */
256
+ shadowed(now = Date.now()) {
257
+ const routes = contentGeneratedRoutes({ pages, collections, now });
258
+ return redirectsYieldingToRoutes(declarations, (source) => routes.has(source)).shadowed;
259
+ },
260
+ };
261
+ }
package/src/validate.mjs CHANGED
@@ -16,7 +16,7 @@
16
16
  * point; `validateConfigShape` is exported for focused testing.
17
17
  */
18
18
  import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
19
- import { join, relative } from "node:path";
19
+ import { join, relative, sep } from "node:path";
20
20
  import { contrastRatio, declaredObligations, isRegulatedCompliance, validateDeclaredConfig } from "./declared-config.mjs";
21
21
  import {
22
22
  foreignTenantSegments,
@@ -24,6 +24,7 @@ import {
24
24
  workspacePathForTenantRelative,
25
25
  } from "./tot-repo-mappings.mjs";
26
26
  import { isForbiddenPublicPath, publicBinaryFindings } from "./public-binaries.mjs";
27
+ import { createRedirectShadowCollector, shadowedRedirectMessage } from "./redirect-shadows.mjs";
27
28
  import { pageSlugFindings } from "./page-slugs.mjs";
28
29
  import { ANALYTICS_DECLARATION_FILE, analyticsDeclarationFindings } from "./analytics-declaration.mjs";
29
30
  import { parseSku, skuCollisions, skuFindings } from "./sku.mjs";
@@ -113,7 +114,120 @@ export function catalogSkuFindings(products) {
113
114
  return out;
114
115
  }
115
116
 
116
- function validateCatalogSkus(contentDir, rel) {
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) {
117
231
  const dir = join(contentDir, "catalog", "products");
118
232
  if (!existsSync(dir)) return [];
119
233
  /** @type {Finding[]} */
@@ -125,7 +239,7 @@ function validateCatalogSkus(contentDir, rel) {
125
239
  if (error) parseErrors.push(mk(ERROR, "catalog-parse", rel(path), `invalid JSON: ${error}`));
126
240
  else products.push({ file: rel(path), record: value });
127
241
  }
128
- return [...parseErrors, ...catalogSkuFindings(products)];
242
+ return [...parseErrors, ...catalogSkuFindings(products), ...catalogComplianceFindings(products, config)];
129
243
  }
130
244
 
131
245
  // --- canonical `.tot/config.json` shape (the #24/#25 regression guard) --------
@@ -994,6 +1108,11 @@ export const LOUD_ADVISORY_RULES = [
994
1108
  "a previously-declared data-tot-el changed value",
995
1109
  "The page still works, but everything already recorded under the old id is now orphaned — this identity is supposed to be permanent.",
996
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
+ ],
997
1116
  ];
998
1117
 
999
1118
  /**
@@ -1206,6 +1325,23 @@ function readJsonSafe(path) {
1206
1325
  return { value: null, error: /** @type {Error} */ (e).message };
1207
1326
  }
1208
1327
  }
1328
+ /**
1329
+ * Declared redirects a generated page shadows (the same rule the publish and the preview reconcile
1330
+ * apply), as warnings naming the file, the entry, why, and what to do.
1331
+ * @param {string} contentDir @param {(p: string) => string} rel
1332
+ */
1333
+ function shadowedRedirectFindings(contentDir, rel) {
1334
+ const collector = createRedirectShadowCollector();
1335
+ for (const p of walk(contentDir, (x) => x.endsWith(".json") || x.endsWith(".html"))) {
1336
+ const path = relative(contentDir, p).split(sep).join("/");
1337
+ if (!/^(redirects\.json|[^/]+\/redirects\.json|pages-html\/.+\.html|pages\/[^/]+\.json|(blog|the-build)\/(settings\.json|posts\/[^/]+\.json))$/.test(path)) continue;
1338
+ collector.add(path, readFileSync(p, "utf8"));
1339
+ }
1340
+ return collector.shadowed().map((entry) => mk(WARN, "redirect-shadowed",
1341
+ rel(join(contentDir, entry.file.slice("content/".length))), shadowedRedirectMessage(entry),
1342
+ `delete ${JSON.stringify(entry.key)} from ${entry.file}`));
1343
+ }
1344
+
1209
1345
  function walk(dir, pred) {
1210
1346
  const out = [];
1211
1347
  if (!existsSync(dir)) return out;
@@ -1381,7 +1517,7 @@ export function validateTenant(tenantDir, opts = {}) {
1381
1517
  }
1382
1518
  }
1383
1519
 
1384
- findings.push(...validateCatalogSkus(contentDir, rel));
1520
+ findings.push(...validateCatalogSkus(contentDir, rel, config));
1385
1521
 
1386
1522
  const capabilitiesPath = located("capabilities.json");
1387
1523
  if (existsSync(capabilitiesPath)) {
@@ -1441,6 +1577,10 @@ export function validateTenant(tenantDir, opts = {}) {
1441
1577
  // 3b. editorial page slugs — every page must be reachable at its slug on the hosted router.
1442
1578
  findings.push(...editorialSlugFindings(contentDir, pagesDir, rel));
1443
1579
 
1580
+ // 3c. a declared redirect whose source the content now generates a page for: the page is served
1581
+ // and the redirect yields, so this warns rather than refuses.
1582
+ findings.push(...shadowedRedirectFindings(contentDir, rel));
1583
+
1444
1584
  // 4. raw HTML documents — validate + portability + resolution
1445
1585
  const hasChrome = providesChrome(contentDir);
1446
1586
  const htmlFiles = walk(contentDir, (p) => p.endsWith(".html"));