@tokenoftrust/cli 6.11.0 → 6.11.2
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/validate.mjs +62 -1
- package/src/vendor/private-apps-devkit.mjs +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "6.11.
|
|
3
|
+
"version": "6.11.2",
|
|
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/validate.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
|
|
19
19
|
import { join, relative } from "node:path";
|
|
20
|
-
import { declaredObligations, isRegulatedCompliance, validateDeclaredConfig } from "./declared-config.mjs";
|
|
20
|
+
import { contrastRatio, declaredObligations, isRegulatedCompliance, validateDeclaredConfig } from "./declared-config.mjs";
|
|
21
21
|
import {
|
|
22
22
|
foreignTenantSegments,
|
|
23
23
|
parseMappingTarget,
|
|
@@ -432,6 +432,66 @@ function validateThemeHeadings(theme, file) {
|
|
|
432
432
|
return out;
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
+
const THEME_HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
436
|
+
const REFERENCE_THEME_COLORS = Object.freeze({
|
|
437
|
+
bg: "#F4F1EA",
|
|
438
|
+
surface: "#FCFAF5",
|
|
439
|
+
text: "#1C2624",
|
|
440
|
+
muted: "#5C6663",
|
|
441
|
+
primary: "#1F3A34",
|
|
442
|
+
"primary-contrast": "#F4F1EA",
|
|
443
|
+
});
|
|
444
|
+
const WCAG_AA_CONTRAST = 4.5;
|
|
445
|
+
|
|
446
|
+
function hexContrastRatio(a, b) {
|
|
447
|
+
if (typeof a !== "string" || typeof b !== "string") return null;
|
|
448
|
+
const ca = a.trim();
|
|
449
|
+
const cb = b.trim();
|
|
450
|
+
if (!THEME_HEX_RE.test(ca) || !THEME_HEX_RE.test(cb)) return null;
|
|
451
|
+
return contrastRatio(ca, cb);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* theme.json WCAG AA contrast: resolved foreground/background pairs (including the
|
|
456
|
+
* bold hero headline's `--color-primary-contrast` on `--color-primary` when
|
|
457
|
+
* `brand.heroVariant` is `"bold"` or omitted) must meet 4.5:1.
|
|
458
|
+
*/
|
|
459
|
+
export function validateThemeContrast(theme, file) {
|
|
460
|
+
const out = [];
|
|
461
|
+
if (theme == null || typeof theme !== "object" || Array.isArray(theme)) return out;
|
|
462
|
+
const rawColor = theme.color && typeof theme.color === "object" && !Array.isArray(theme.color) ? theme.color : {};
|
|
463
|
+
const color = { ...REFERENCE_THEME_COLORS, ...rawColor };
|
|
464
|
+
const heroVariant = theme?.brand?.heroVariant ?? "bold";
|
|
465
|
+
const pairs = [
|
|
466
|
+
{ fg: "text", bg: "bg", label: "body text (color.text on color.bg)", level: ERROR },
|
|
467
|
+
{ fg: "text", bg: "surface", label: "surface text (color.text on color.surface)", level: ERROR },
|
|
468
|
+
heroVariant === "light"
|
|
469
|
+
? { fg: "primary", bg: "bg", label: "light hero headline (color.primary on color.bg)", level: ERROR }
|
|
470
|
+
: {
|
|
471
|
+
fg: "primary-contrast",
|
|
472
|
+
bg: "primary",
|
|
473
|
+
label: "bold hero headline (color.primary-contrast on color.primary)",
|
|
474
|
+
level: ERROR,
|
|
475
|
+
},
|
|
476
|
+
{ fg: "muted", bg: "bg", label: "secondary text (color.muted on color.bg)", level: WARN },
|
|
477
|
+
];
|
|
478
|
+
for (const pair of pairs) {
|
|
479
|
+
const ratio = hexContrastRatio(color[pair.fg], color[pair.bg]);
|
|
480
|
+
if (ratio !== null && ratio < WCAG_AA_CONTRAST) {
|
|
481
|
+
out.push(
|
|
482
|
+
mk(
|
|
483
|
+
pair.level,
|
|
484
|
+
"theme-contrast",
|
|
485
|
+
file,
|
|
486
|
+
`${pair.label} contrast (${color[pair.fg]} on ${color[pair.bg]}) is ${ratio.toFixed(2)}:1 — below WCAG AA ${WCAG_AA_CONTRAST}:1`,
|
|
487
|
+
`adjust color.${pair.fg} or color.${pair.bg} in ${file} to achieve at least ${WCAG_AA_CONTRAST}:1 contrast`,
|
|
488
|
+
),
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return out;
|
|
493
|
+
}
|
|
494
|
+
|
|
435
495
|
// Standalone published-CLI mirror. packages/cli/test/validate.test.mjs pins it
|
|
436
496
|
// to extension-contract-values.mjs, the repository/runtime authority.
|
|
437
497
|
export const BLOCK_PALETTE_SUPPORTED_CONTRACTS = Object.freeze([
|
|
@@ -1317,6 +1377,7 @@ export function validateTenant(tenantDir, opts = {}) {
|
|
|
1317
1377
|
);
|
|
1318
1378
|
} else {
|
|
1319
1379
|
findings.push(...validateThemeHeadings(theme, rel(themePath)));
|
|
1380
|
+
findings.push(...validateThemeContrast(theme, rel(themePath)));
|
|
1320
1381
|
}
|
|
1321
1382
|
}
|
|
1322
1383
|
|
|
@@ -263,6 +263,11 @@ export const MANIFEST_TELEMETRY_MODES = ["errors-only", "sampled", "full"];
|
|
|
263
263
|
|
|
264
264
|
export const MANIFEST_PII_REDACTIONS = ["default", "strict"];
|
|
265
265
|
|
|
266
|
+
export const INVENTORY_CHANGED_KEYS = ["sku", "locationId", "balance", "asOf"];
|
|
267
|
+
|
|
268
|
+
const LOCATION_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
269
|
+
const ISO_DATE_TIME_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
270
|
+
|
|
266
271
|
const ID_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/;
|
|
267
272
|
const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
268
273
|
const HTTPS_URI_PATTERN = /^https:\/\/\S+$/;
|
|
@@ -493,3 +498,41 @@ export function validateManifest(input) {
|
|
|
493
498
|
if (errors.length > 0) return { ok: false, errors };
|
|
494
499
|
return { ok: true, manifest: input };
|
|
495
500
|
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Validate a parsed `inventory.changed` CloudEvents `data` payload against
|
|
504
|
+
* `docs/private-apps/contract/asyncapi.yaml` (`InventoryChangedData`).
|
|
505
|
+
*/
|
|
506
|
+
export function validateInventoryChangedData(input) {
|
|
507
|
+
const errors = [];
|
|
508
|
+
if (!isPlainObject(input)) {
|
|
509
|
+
return { ok: false, errors: ["inventory.changed data must be a JSON object"] };
|
|
510
|
+
}
|
|
511
|
+
rejectUnknownKeys(input, INVENTORY_CHANGED_KEYS, "data", errors);
|
|
512
|
+
const sku = requireString(input, "sku", "data", errors);
|
|
513
|
+
if (sku !== undefined && sku.trim().length === 0) {
|
|
514
|
+
errors.push("data.sku: must not be blank");
|
|
515
|
+
}
|
|
516
|
+
const locationId = requireString(input, "locationId", "data", errors);
|
|
517
|
+
if (locationId !== undefined) {
|
|
518
|
+
checkPattern(locationId, LOCATION_ID_PATTERN, "data.locationId", errors);
|
|
519
|
+
}
|
|
520
|
+
const balance = input.balance;
|
|
521
|
+
if (typeof balance !== "number" || !Number.isSafeInteger(balance)) {
|
|
522
|
+
errors.push("data.balance: must be a safe integer");
|
|
523
|
+
}
|
|
524
|
+
const asOf = requireString(input, "asOf", "data", errors);
|
|
525
|
+
if (asOf !== undefined && (!ISO_DATE_TIME_PATTERN.test(asOf) || Number.isNaN(Date.parse(asOf)))) {
|
|
526
|
+
errors.push("data.asOf: must be an ISO-8601 date-time string");
|
|
527
|
+
}
|
|
528
|
+
if (errors.length > 0) return { ok: false, errors };
|
|
529
|
+
return {
|
|
530
|
+
ok: true,
|
|
531
|
+
data: {
|
|
532
|
+
sku,
|
|
533
|
+
locationId,
|
|
534
|
+
balance,
|
|
535
|
+
asOf,
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
}
|