@tokenoftrust/cli 8.1.0 → 8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "8.1.0",
3
+ "version": "8.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",
@@ -31,6 +31,9 @@ export const MAX_SHIPPING_AMOUNT: number;
31
31
  export const MAX_SHIPPING_TIERS: number;
32
32
  export const MAX_SHIPPING_LABEL_LENGTH: number;
33
33
  export function shippingDeclarationProblems(shipping: unknown): string[];
34
+ export const COMMERCE_KEYS: readonly string[];
35
+ export const ORDER_NUMBERING_KEYS: readonly string[];
36
+ export function commerceDeclarationProblems(commerce: unknown): string[];
34
37
  export const COMPLIANCE_NOTICES: Record<string, string>;
35
38
  export const MANDATED_NOTICE_KEYS: string[];
36
39
  export function nearestKey(key: string, known: readonly string[]): string | null;
@@ -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", "catalog", "accessPolicy", "verification",
22
+ "displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog", "commerce", "accessPolicy", "verification",
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" };
@@ -324,6 +324,67 @@ function catalogProblemMessage(problems) {
324
324
  "Owned catalog images stay refused until it is fixed.";
325
325
  }
326
326
 
327
+ /** Every `commerce` key a tenant may declare in `.tot/config.json`. Platform checkout/program fields stay outside. */
328
+ export const COMMERCE_KEYS = Object.freeze(["orderNumbering"]);
329
+
330
+ /** Every `commerce.orderNumbering` key (mirrors packages/public-runtime/src/declared-tenant-config.mjs). */
331
+ export const ORDER_NUMBERING_KEYS = Object.freeze(["startAt", "prefix", "padWidth"]);
332
+
333
+ const ORDER_NUMBER_PREFIX_RE = /^[A-Za-z0-9-]*$/;
334
+ const ORDER_NUMBER_MAX_PREFIX_LENGTH = 32;
335
+ const ORDER_NUMBER_MAX_PAD_WIDTH = 16;
336
+
337
+ /**
338
+ * What is wrong with a declared `commerce` value, one sentence per problem; `[]` when it is valid.
339
+ * @param {unknown} commerce
340
+ * @returns {string[]}
341
+ */
342
+ export function commerceDeclarationProblems(commerce) {
343
+ if (!isObject(commerce)) return ["`commerce` must be an object"];
344
+ const source = /** @type {Record<string, unknown>} */ (commerce);
345
+ const problems = [];
346
+ for (const key of Object.keys(source)) {
347
+ if (!COMMERCE_KEYS.includes(key)) {
348
+ problems.push(`\`commerce.${key}\` is not a commerce key (${COMMERCE_KEYS.join(", ")})`);
349
+ }
350
+ }
351
+ const on = source.orderNumbering;
352
+ if (on !== undefined) {
353
+ if (!isObject(on)) {
354
+ problems.push("`commerce.orderNumbering` must be an object");
355
+ } else {
356
+ const rec = /** @type {Record<string, unknown>} */ (on);
357
+ for (const key of Object.keys(rec)) {
358
+ if (!ORDER_NUMBERING_KEYS.includes(key)) {
359
+ problems.push(`\`commerce.orderNumbering.${key}\` is not an orderNumbering key (${ORDER_NUMBERING_KEYS.join(", ")})`);
360
+ }
361
+ }
362
+ if (typeof rec.startAt !== "number" || !Number.isSafeInteger(rec.startAt) || rec.startAt < 1) {
363
+ problems.push("`commerce.orderNumbering.startAt` must be a positive safe integer");
364
+ }
365
+ if (
366
+ rec.prefix !== undefined &&
367
+ (typeof rec.prefix !== "string" || rec.prefix.length > ORDER_NUMBER_MAX_PREFIX_LENGTH || !ORDER_NUMBER_PREFIX_RE.test(rec.prefix))
368
+ ) {
369
+ problems.push(`\`commerce.orderNumbering.prefix\` must be empty or match /^[A-Za-z0-9-]+$/ (max ${ORDER_NUMBER_MAX_PREFIX_LENGTH} chars)`);
370
+ }
371
+ if (
372
+ rec.padWidth !== undefined &&
373
+ (typeof rec.padWidth !== "number" || !Number.isSafeInteger(rec.padWidth) || rec.padWidth < 0 || rec.padWidth > ORDER_NUMBER_MAX_PAD_WIDTH)
374
+ ) {
375
+ problems.push(`\`commerce.orderNumbering.padWidth\` must be an integer between 0 and ${ORDER_NUMBER_MAX_PAD_WIDTH}`);
376
+ }
377
+ }
378
+ }
379
+ return problems;
380
+ }
381
+
382
+ /** The owner-facing sentence for an invalid `commerce` declaration. */
383
+ function commerceProblemMessage(problems) {
384
+ return `\`commerce\` is not a valid commerce declaration (${problems.join("; ")}). ` +
385
+ "Order numbering uses the default sequence until it is fixed.";
386
+ }
387
+
327
388
  /** Every `shipping` key (mirrors packages/public-runtime/src/declared-tenant-config.mjs). */
328
389
  export const SHIPPING_KEYS = Object.freeze(["tiers"]);
329
390
 
@@ -805,6 +866,8 @@ export function declarationFindings(current, previous) {
805
866
  if (shipping.length > 0) out.push(`CONFIG: ${shippingProblemMessage(shipping)}`);
806
867
  const catalog = current.catalog === undefined ? [] : catalogDeclarationProblems(current.catalog);
807
868
  if (catalog.length > 0) out.push(`CONFIG: ${catalogProblemMessage(catalog)}`);
869
+ const commerce = current.commerce === undefined ? [] : commerceDeclarationProblems(current.commerce);
870
+ if (commerce.length > 0) out.push(`CONFIG: ${commerceProblemMessage(commerce)}`);
808
871
  }
809
872
  for (const { key, notice } of droppedMandatedNotices(previous, current)) {
810
873
  out.push(
@@ -922,6 +985,13 @@ export function validateDeclaredConfig(config, file = ".tot/config.json") {
922
985
  'declare `"catalog": { "cdnSegment": "shop" }` as one lowercase DNS label, or remove `catalog`'));
923
986
  }
924
987
  }
988
+ if (config.commerce !== undefined) {
989
+ const problems = commerceDeclarationProblems(config.commerce);
990
+ if (problems.length > 0) {
991
+ out.push(mk(ERROR, "config-commerce", `${file} commerce`, commerceProblemMessage(problems),
992
+ 'declare `"commerce": { "orderNumbering": { "startAt": 270101 } }`, or remove `commerce`'));
993
+ }
994
+ }
925
995
  return out;
926
996
  }
927
997