@tokenoftrust/cli 6.12.3 → 6.12.5

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.12.3",
3
+ "version": "6.12.5",
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",
@@ -140,7 +140,7 @@ export const CAPABILITIES = [
140
140
  'docs/private-apps/documentation-and-recipe-architecture.md',
141
141
  ],
142
142
  populatedBy: 'tot-app.json manifest (`tot app scaffold` / `tot app install`; recipe://storefront-private-apps-devbook)',
143
- verifiedBy: 'tot app validate, tot app test-webhooks, and POST /api/apps/admin/test-orders on preview',
143
+ verifiedBy: 'tot app dev validate, tot app dev emit, and POST /api/apps/admin/test-orders on preview',
144
144
  appliesTo: ['commerce'],
145
145
  },
146
146
 
@@ -248,8 +248,11 @@ export const MANIFEST_WEBHOOK_TOPICS = [
248
248
  "catalog.product.updated",
249
249
  "inventory.changed",
250
250
  "order.created",
251
+ "order.paid",
251
252
  "order.fulfilled",
252
253
  "order.partially_fulfilled",
254
+ "order.cancelled",
255
+ "order.updated",
253
256
  "customer.marketing_consent.updated",
254
257
  "attribution.finalized",
255
258
  "fulfillment.assignment.created",
@@ -264,7 +267,7 @@ export const MANIFEST_TELEMETRY_MODES = ["errors-only", "sampled", "full"];
264
267
 
265
268
  export const MANIFEST_PII_REDACTIONS = ["default", "strict"];
266
269
 
267
- export const INVENTORY_CHANGED_KEYS = ["sku", "locationId", "balance", "asOf"];
270
+ export const INVENTORY_CHANGED_KEYS = ["sku", "locationId", "balance", "available", "asOf"];
268
271
 
269
272
  const LOCATION_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
270
273
  const ISO_DATE_TIME_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
@@ -278,7 +281,12 @@ const HOSTNAME_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a
278
281
  const TOP_LEVEL_KEYS = [
279
282
  "contractVersion", "id", "name", "version", "owner", "description", "installMode",
280
283
  "scopes", "webhooks", "widgets", "adminLinks", "telemetryMode", "retention", "hosting",
284
+ "clientAuth",
281
285
  ];
286
+ const CLIENT_AUTH_KEYS = ["method", "jwks", "jwksUri"];
287
+ const CLIENT_JWK_KTYS = ["RSA", "EC"];
288
+ const CLIENT_JWK_ALGS = ["RS256", "ES256"];
289
+ const PRIVATE_JWK_MEMBERS = ["d", "p", "q", "dp", "dq", "qi", "oth", "k"];
282
290
  const OWNER_KEYS = ["name", "email", "url"];
283
291
  const WEBHOOKS_KEYS = ["endpoint", "topics", "signatureKeyId"];
284
292
  const WIDGET_KEYS = ["placement", "endpoint", "title"];
@@ -453,6 +461,58 @@ function validateHosting(hosting, errors) {
453
461
  }
454
462
  }
455
463
 
464
+ function validateClientAuth(clientAuth, errors) {
465
+ if (clientAuth === undefined) return;
466
+ if (!isPlainObject(clientAuth)) {
467
+ errors.push("clientAuth: must be an object");
468
+ return;
469
+ }
470
+ rejectUnknownKeys(clientAuth, CLIENT_AUTH_KEYS, "clientAuth", errors);
471
+ if (clientAuth.method !== "private_key_jwt") errors.push('clientAuth.method: must be "private_key_jwt"');
472
+ const hasJwks = clientAuth.jwks !== undefined;
473
+ const hasUri = clientAuth.jwksUri !== undefined;
474
+ if (hasJwks === hasUri) {
475
+ errors.push("clientAuth: give exactly one of jwks or jwksUri");
476
+ return;
477
+ }
478
+ if (hasUri) {
479
+ const uri = clientAuth.jwksUri;
480
+ checkPattern(uri, HTTPS_URI_PATTERN, "clientAuth.jwksUri", errors);
481
+ if (typeof uri === "string" && uri.length > 2048) errors.push("clientAuth.jwksUri: must be at most 2048 characters");
482
+ return;
483
+ }
484
+ const jwks = clientAuth.jwks;
485
+ if (!isPlainObject(jwks)) {
486
+ errors.push("clientAuth.jwks: must be an object");
487
+ return;
488
+ }
489
+ rejectUnknownKeys(jwks, ["keys"], "clientAuth.jwks", errors);
490
+ const keys = jwks.keys;
491
+ if (!Array.isArray(keys) || keys.length === 0 || keys.length > 10) {
492
+ errors.push("clientAuth.jwks.keys: must be an array of 1 to 10 keys");
493
+ return;
494
+ }
495
+ const kids = new Set();
496
+ keys.forEach((key, index) => {
497
+ const at = `clientAuth.jwks.keys[${index}]`;
498
+ if (!isPlainObject(key)) {
499
+ errors.push(`${at}: must be an object`);
500
+ return;
501
+ }
502
+ checkEnum(key.kty, CLIENT_JWK_KTYS, `${at}.kty`, errors);
503
+ const kid = requireString(key, "kid", at, errors);
504
+ if (kid !== undefined) {
505
+ if (kids.has(kid)) errors.push(`${at}.kid: duplicate kid`);
506
+ kids.add(kid);
507
+ }
508
+ if (key.alg !== undefined) checkEnum(key.alg, CLIENT_JWK_ALGS, `${at}.alg`, errors);
509
+ if (key.use !== undefined && key.use !== "sig") errors.push(`${at}.use: must be "sig"`);
510
+ for (const member of PRIVATE_JWK_MEMBERS) {
511
+ if (key[member] !== undefined) errors.push(`${at}: private member "${member}" is not allowed; publish public keys only`);
512
+ }
513
+ });
514
+ }
515
+
456
516
  /**
457
517
  * Validate a parsed `tot-app.json` manifest against the V1 contract. Returns
458
518
  * every violation found (not just the first).
@@ -495,6 +555,7 @@ export function validateManifest(input) {
495
555
  }
496
556
  validateRetention(input.retention, errors);
497
557
  validateHosting(input.hosting, errors);
558
+ validateClientAuth(input.clientAuth, errors);
498
559
 
499
560
  if (errors.length > 0) return { ok: false, errors };
500
561
  return { ok: true, manifest: input };
@@ -522,6 +583,10 @@ export function validateInventoryChangedData(input) {
522
583
  if (typeof balance !== "number" || !Number.isSafeInteger(balance)) {
523
584
  errors.push("data.balance: must be a safe integer");
524
585
  }
586
+ const available = input.available;
587
+ if (typeof available !== "number" || !Number.isSafeInteger(available)) {
588
+ errors.push("data.available: must be a safe integer");
589
+ }
525
590
  const asOf = requireString(input, "asOf", "data", errors);
526
591
  if (asOf !== undefined && (!ISO_DATE_TIME_PATTERN.test(asOf) || Number.isNaN(Date.parse(asOf)))) {
527
592
  errors.push("data.asOf: must be an ISO-8601 date-time string");
@@ -533,6 +598,7 @@ export function validateInventoryChangedData(input) {
533
598
  sku,
534
599
  locationId,
535
600
  balance,
601
+ available,
536
602
  asOf,
537
603
  },
538
604
  };
@@ -76,17 +76,14 @@ for runnable reference connectors against the v1.3 contract:
76
76
  Developers holding `preview-access` or `ship-on-behalf` on a store can verify an app end-to-end on
77
77
  the preview stage without waiting on the store owner:
78
78
 
79
- 1. **Seed preview catalog & stock:**
79
+ 1. **Seed preview catalog & stock (inside a cloned store checkout):**
80
80
  ```bash
81
- tot catalog seed --store <tenant> --preset general|regulated-vape|multi-warehouse
82
- # or inside a cloned store checkout:
83
81
  tot catalog seed --preset=general|regulated-vape|multi-warehouse
82
+ tot preview
84
83
  ```
85
84
  2. **Self-serve install in `env="test"`:**
86
85
  ```bash
87
- tot app install --store <tenant> --env test --manifest ./tot-app.json
88
- # or inside your app directory:
89
- tot app install --tenant <tenant> --env test
86
+ tot app install --tenant <tenant> --env test --app .
90
87
  ```
91
88
  Manage your test install at any time with `tot app update <installId>`,
92
89
  `tot app rotate <installId>`, `tot app list`, and `tot app replay <deliveryId>`.
@@ -103,10 +100,10 @@ the preview stage without waiting on the store owner:
103
100
  (see the Devkit's
104
101
  [`webhooks-and-api.md`](https://github.com/tokenoftrust/storefront-devkit/blob/main/apps/private/webhooks-and-api.md)).
105
102
  2. **Stage a `private_key_jwt` `production` candidate (`pending_approval`):**
106
- POST to `POST /api/apps/admin/candidates` with `tokenEndpointAuthMethod: "private_key_jwt"` and
107
- your app's `jwksUri` or pinned `publicKeyJwk`. This records a `status: "pending_approval"`
103
+ POST to `POST /api/apps/admin/candidates` with `clientAuth: { method: "private_key_jwt", jwksUri: "https://..." }`
104
+ (or inline `jwks: { keys: [ <publicKeyJwk> ] }`). This records a `status: "pending_approval"`
108
105
  production candidate with zero shared secrets to hand off.
109
106
  3. **1-click Store Owner approval:**
110
107
  The Store Owner reviews the requested scopes, webhook endpoint, and key metadata in
111
- `/admin#integrations` and approves in 1 click (`POST /api/apps/admin/candidates/{candidateId}/approve`),
112
- activating the `production` install immediately.
108
+ `/admin#integrations` and approves in 1 click (`POST /api/apps/admin/candidates/decide` with
109
+ `decision: "approve"`), activating the `production` install immediately.
@@ -14,11 +14,11 @@
14
14
  * `recipes/fulfillment-shipstation`, `recipes/dropship-split-duoplane`).
15
15
  *
16
16
  * Online preview & production flow (see README.md):
17
- * 1. `tot catalog seed --store <tenant> --preset general|regulated-vape|multi-warehouse`
18
- * 2. `tot app install --store <tenant> --env test --manifest ./tot-app.json`
17
+ * 1. `tot catalog seed --preset=general|regulated-vape|multi-warehouse` (then `tot preview`)
18
+ * 2. `tot app install --tenant <tenant> --env test --app .`
19
19
  * 3. `POST /api/apps/admin/test-orders` (synthetic preview orders bound to `test` install)
20
20
  * 4. `POST /api/apps/admin/candidates` (`private_key_jwt`, `pending_approval`) ->
21
- * 1-click Store Owner approval in `/admin#integrations`
21
+ * 1-click Store Owner approval in `/admin#integrations` (`POST /api/apps/admin/candidates/decide`)
22
22
  */
23
23
  import { createServer } from "node:http";
24
24
  import { existsSync, readFileSync } from "node:fs";