@tokenoftrust/cli 6.11.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "6.11.1",
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",
@@ -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
+ }