@tokenoftrust/cli 6.2.0 → 6.3.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 +1 -1
- package/src/declared-config.mjs +41 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.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",
|
package/src/declared-config.mjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
export const TOT_CONFIG_KEYS = [
|
|
21
21
|
"$schema", "tenant", "scope", "mappings", "hostPlatform", "sample", "seed",
|
|
22
|
-
"displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping",
|
|
22
|
+
"displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog",
|
|
23
23
|
];
|
|
24
24
|
// Keys other tooling has written that the platform does NOT read, with the key it does.
|
|
25
25
|
const RENAMED_CONFIG_KEYS = { appDomain: "scope", tenantId: "tenant" };
|
|
@@ -232,6 +232,37 @@ export function seoDeclarationProblems(seo) {
|
|
|
232
232
|
return problems;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
/** Every `catalog` key a tenant may declare. `serving` stays a platform field. */
|
|
236
|
+
export const CATALOG_KEYS = Object.freeze(["cdnSegment"]);
|
|
237
|
+
|
|
238
|
+
/** One DNS label. Anything else is not a catalog object-key segment. */
|
|
239
|
+
const CATALOG_SEGMENT = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* What is wrong with a declared `catalog` value, one sentence per problem; `[]` when it is valid.
|
|
243
|
+
* A tenant cannot set `catalog.serving` here: that field belongs to the platform record.
|
|
244
|
+
* @param {unknown} catalog
|
|
245
|
+
* @returns {string[]}
|
|
246
|
+
*/
|
|
247
|
+
export function catalogDeclarationProblems(catalog) {
|
|
248
|
+
if (!isObject(catalog)) return ["`catalog` must be an object"];
|
|
249
|
+
const source = /** @type {Record<string, unknown>} */ (catalog);
|
|
250
|
+
const problems = [];
|
|
251
|
+
for (const key of Object.keys(source)) {
|
|
252
|
+
if (!CATALOG_KEYS.includes(key)) problems.push(`\`catalog.${key}\` is not a catalog key (${CATALOG_KEYS.join(", ")})`);
|
|
253
|
+
}
|
|
254
|
+
if (source.cdnSegment !== undefined && (typeof source.cdnSegment !== "string" || !CATALOG_SEGMENT.test(source.cdnSegment))) {
|
|
255
|
+
problems.push("`catalog.cdnSegment` must be one lowercase DNS label");
|
|
256
|
+
}
|
|
257
|
+
return problems;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** The owner-facing sentence for an invalid `catalog` declaration. */
|
|
261
|
+
function catalogProblemMessage(problems) {
|
|
262
|
+
return `\`catalog\` is not a valid catalog declaration (${problems.join("; ")}). ` +
|
|
263
|
+
"Owned catalog images stay refused until it is fixed.";
|
|
264
|
+
}
|
|
265
|
+
|
|
235
266
|
/** Every `shipping` key (mirrors packages/public-runtime/src/declared-tenant-config.mjs). */
|
|
236
267
|
export const SHIPPING_KEYS = Object.freeze(["tiers"]);
|
|
237
268
|
|
|
@@ -690,6 +721,8 @@ export function declarationFindings(current, previous) {
|
|
|
690
721
|
}
|
|
691
722
|
const shipping = current.shipping === undefined ? [] : shippingDeclarationProblems(current.shipping);
|
|
692
723
|
if (shipping.length > 0) out.push(`CONFIG: ${shippingProblemMessage(shipping)}`);
|
|
724
|
+
const catalog = current.catalog === undefined ? [] : catalogDeclarationProblems(current.catalog);
|
|
725
|
+
if (catalog.length > 0) out.push(`CONFIG: ${catalogProblemMessage(catalog)}`);
|
|
693
726
|
}
|
|
694
727
|
for (const { key, notice } of droppedMandatedNotices(previous, current)) {
|
|
695
728
|
out.push(
|
|
@@ -790,6 +823,13 @@ export function validateDeclaredConfig(config, file = ".tot/config.json") {
|
|
|
790
823
|
'declare e.g. `"shipping": { "tiers": [ { "rate": 5.99 }, { "atOrAbove": 100, "rate": 0, "label": "Free shipping" } ] }`, or remove `shipping` to charge none'));
|
|
791
824
|
}
|
|
792
825
|
}
|
|
826
|
+
if (config.catalog !== undefined) {
|
|
827
|
+
const problems = catalogDeclarationProblems(config.catalog);
|
|
828
|
+
if (problems.length > 0) {
|
|
829
|
+
out.push(mk(ERROR, "config-catalog", `${file} catalog`, catalogProblemMessage(problems),
|
|
830
|
+
'declare `"catalog": { "cdnSegment": "shop" }` as one lowercase DNS label, or remove `catalog`'));
|
|
831
|
+
}
|
|
832
|
+
}
|
|
793
833
|
return out;
|
|
794
834
|
}
|
|
795
835
|
|