@tokenoftrust/cli 6.12.2 → 6.12.4
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
|
+
"version": "6.12.4",
|
|
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
|
|
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
|
|
|
@@ -278,7 +278,12 @@ const HOSTNAME_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a
|
|
|
278
278
|
const TOP_LEVEL_KEYS = [
|
|
279
279
|
"contractVersion", "id", "name", "version", "owner", "description", "installMode",
|
|
280
280
|
"scopes", "webhooks", "widgets", "adminLinks", "telemetryMode", "retention", "hosting",
|
|
281
|
+
"clientAuth",
|
|
281
282
|
];
|
|
283
|
+
const CLIENT_AUTH_KEYS = ["method", "jwks", "jwksUri"];
|
|
284
|
+
const CLIENT_JWK_KTYS = ["RSA", "EC"];
|
|
285
|
+
const CLIENT_JWK_ALGS = ["RS256", "ES256"];
|
|
286
|
+
const PRIVATE_JWK_MEMBERS = ["d", "p", "q", "dp", "dq", "qi", "oth", "k"];
|
|
282
287
|
const OWNER_KEYS = ["name", "email", "url"];
|
|
283
288
|
const WEBHOOKS_KEYS = ["endpoint", "topics", "signatureKeyId"];
|
|
284
289
|
const WIDGET_KEYS = ["placement", "endpoint", "title"];
|
|
@@ -453,6 +458,58 @@ function validateHosting(hosting, errors) {
|
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
460
|
|
|
461
|
+
function validateClientAuth(clientAuth, errors) {
|
|
462
|
+
if (clientAuth === undefined) return;
|
|
463
|
+
if (!isPlainObject(clientAuth)) {
|
|
464
|
+
errors.push("clientAuth: must be an object");
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
rejectUnknownKeys(clientAuth, CLIENT_AUTH_KEYS, "clientAuth", errors);
|
|
468
|
+
if (clientAuth.method !== "private_key_jwt") errors.push('clientAuth.method: must be "private_key_jwt"');
|
|
469
|
+
const hasJwks = clientAuth.jwks !== undefined;
|
|
470
|
+
const hasUri = clientAuth.jwksUri !== undefined;
|
|
471
|
+
if (hasJwks === hasUri) {
|
|
472
|
+
errors.push("clientAuth: give exactly one of jwks or jwksUri");
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (hasUri) {
|
|
476
|
+
const uri = clientAuth.jwksUri;
|
|
477
|
+
checkPattern(uri, HTTPS_URI_PATTERN, "clientAuth.jwksUri", errors);
|
|
478
|
+
if (typeof uri === "string" && uri.length > 2048) errors.push("clientAuth.jwksUri: must be at most 2048 characters");
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const jwks = clientAuth.jwks;
|
|
482
|
+
if (!isPlainObject(jwks)) {
|
|
483
|
+
errors.push("clientAuth.jwks: must be an object");
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
rejectUnknownKeys(jwks, ["keys"], "clientAuth.jwks", errors);
|
|
487
|
+
const keys = jwks.keys;
|
|
488
|
+
if (!Array.isArray(keys) || keys.length === 0 || keys.length > 10) {
|
|
489
|
+
errors.push("clientAuth.jwks.keys: must be an array of 1 to 10 keys");
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const kids = new Set();
|
|
493
|
+
keys.forEach((key, index) => {
|
|
494
|
+
const at = `clientAuth.jwks.keys[${index}]`;
|
|
495
|
+
if (!isPlainObject(key)) {
|
|
496
|
+
errors.push(`${at}: must be an object`);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
checkEnum(key.kty, CLIENT_JWK_KTYS, `${at}.kty`, errors);
|
|
500
|
+
const kid = requireString(key, "kid", at, errors);
|
|
501
|
+
if (kid !== undefined) {
|
|
502
|
+
if (kids.has(kid)) errors.push(`${at}.kid: duplicate kid`);
|
|
503
|
+
kids.add(kid);
|
|
504
|
+
}
|
|
505
|
+
if (key.alg !== undefined) checkEnum(key.alg, CLIENT_JWK_ALGS, `${at}.alg`, errors);
|
|
506
|
+
if (key.use !== undefined && key.use !== "sig") errors.push(`${at}.use: must be "sig"`);
|
|
507
|
+
for (const member of PRIVATE_JWK_MEMBERS) {
|
|
508
|
+
if (key[member] !== undefined) errors.push(`${at}: private member "${member}" is not allowed; publish public keys only`);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
456
513
|
/**
|
|
457
514
|
* Validate a parsed `tot-app.json` manifest against the V1 contract. Returns
|
|
458
515
|
* every violation found (not just the first).
|
|
@@ -495,6 +552,7 @@ export function validateManifest(input) {
|
|
|
495
552
|
}
|
|
496
553
|
validateRetention(input.retention, errors);
|
|
497
554
|
validateHosting(input.hosting, errors);
|
|
555
|
+
validateClientAuth(input.clientAuth, errors);
|
|
498
556
|
|
|
499
557
|
if (errors.length > 0) return { ok: false, errors };
|
|
500
558
|
return { ok: true, manifest: input };
|
|
@@ -45,11 +45,65 @@ tot app dev mint
|
|
|
45
45
|
offline — nothing here is a real ToT-issued credential. Run `tot app dev --help`
|
|
46
46
|
for the full command surface.
|
|
47
47
|
|
|
48
|
-
##
|
|
48
|
+
## Reference recipes & examples in the public Devkit
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
See [`https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private`](https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private)
|
|
51
|
+
for runnable reference connectors against the v1.3 contract:
|
|
52
|
+
|
|
53
|
+
- **`examples/hello-inventory`** — starter reference: locations (`GET`/`PUT /inventory/locations`),
|
|
54
|
+
mirror stock reads/writes (`GET /inventory`, `POST /inventory/movements`), and synthetic test
|
|
55
|
+
orders (`POST /api/apps/admin/test-orders`).
|
|
56
|
+
- **`recipes/inventory-sync-skuvault`** — multi-location WMS sync (SkuVault, Finale Inventory):
|
|
57
|
+
`GET`/`PUT /inventory/locations/{locationId}`, `PUT /inventory/levels` (`expectedVersion` CAS
|
|
58
|
+
reconciliation), batch `POST /inventory/movements` (`receive`, `pick`, `cycle_count`, `damage`,
|
|
59
|
+
`transfer_in`, `transfer_out`, `return_restock`), and `inventory.changed` webhooks (`low_stock`,
|
|
60
|
+
`out_of_stock`, `back_in_stock`).
|
|
61
|
+
- **`recipes/fulfillment-shipstation`** — shipping and label station (ShipStation, Shippo,
|
|
62
|
+
PirateShip): `fulfillment.assignment.created`/`updated`, `GET /fulfillment/assignments`,
|
|
63
|
+
`GET /fulfillment/orders/{orderId}/recipient`, `GET /fulfillment/carriers` (PACT Act &
|
|
64
|
+
`adultSignature` carrier profiles), 1:N split cartons
|
|
65
|
+
(`POST /fulfillment/assignments/{assignmentId}/shipments`), and whole-order `shipment-evidence`
|
|
66
|
+
(`label-purchased`, `label-voided`, `handed-off`).
|
|
67
|
+
- **`recipes/dropship-split-duoplane`** — 3PL and multi-vendor dropship routing (Duoplane, DSCO):
|
|
68
|
+
location-keyed processor coexistence per `(tenant, stage, location_id)` (Stone 1), assignments
|
|
69
|
+
with `locationId` and `lines[]` (`sku`, `quantity`, `fulfilledQuantity`, `cancelledQuantity`),
|
|
70
|
+
partial line shipments (`order.partially_fulfilled` -> `order.fulfilled`), and line exceptions
|
|
71
|
+
(`POST /fulfillment/assignments/{assignmentId}/exceptions`: `backordered`, `cannot_fulfill`,
|
|
72
|
+
`address_undeliverable`).
|
|
73
|
+
|
|
74
|
+
## Self-serve `env="test"` preview loop (v1.3)
|
|
75
|
+
|
|
76
|
+
Developers holding `preview-access` or `ship-on-behalf` on a store can verify an app end-to-end on
|
|
77
|
+
the preview stage without waiting on the store owner:
|
|
78
|
+
|
|
79
|
+
1. **Seed preview catalog & stock (inside a cloned store checkout):**
|
|
80
|
+
```bash
|
|
81
|
+
tot catalog seed --preset=general|regulated-vape|multi-warehouse
|
|
82
|
+
tot preview
|
|
83
|
+
```
|
|
84
|
+
2. **Self-serve install in `env="test"`:**
|
|
85
|
+
```bash
|
|
86
|
+
tot app install --tenant <tenant> --env test --app .
|
|
87
|
+
```
|
|
88
|
+
Manage your test install at any time with `tot app update <installId>`,
|
|
89
|
+
`tot app rotate <installId>`, `tot app list`, and `tot app replay <deliveryId>`.
|
|
90
|
+
3. **Trigger synthetic preview orders bound to the `test` install:**
|
|
91
|
+
Call `POST /api/apps/admin/test-orders` (`action: "bind" | "create" | "release"`) to bind your
|
|
92
|
+
`test` install as the preview fulfillment processor and emit synthetic preview orders with
|
|
93
|
+
RFC-reserved recipient fixtures. Preview tokens and webhooks are isolated by the stage wall
|
|
94
|
+
(`403 stage_mismatch` if used against live publication hosts).
|
|
95
|
+
|
|
96
|
+
## Going live (`private_key_jwt` candidate staging & 1-click Owner approval)
|
|
97
|
+
|
|
98
|
+
1. Point `webhooks.endpoint` at your real, publicly reachable HTTPS receiver and swap the dev-only
|
|
99
|
+
signature verification in `server.js` for the platform's published JWKS/signing-key metadata
|
|
100
|
+
(see the Devkit's
|
|
55
101
|
[`webhooks-and-api.md`](https://github.com/tokenoftrust/storefront-devkit/blob/main/apps/private/webhooks-and-api.md)).
|
|
102
|
+
2. **Stage a `private_key_jwt` `production` candidate (`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"`
|
|
105
|
+
production candidate with zero shared secrets to hand off.
|
|
106
|
+
3. **1-click Store Owner approval:**
|
|
107
|
+
The Store Owner reviews the requested scopes, webhook endpoint, and key metadata in
|
|
108
|
+
`/admin#integrations` and approves in 1 click (`POST /api/apps/admin/candidates/decide` with
|
|
109
|
+
`decision: "approve"`), activating the `production` install immediately.
|
|
@@ -8,8 +8,17 @@
|
|
|
8
8
|
* Trusts the public key `tot app dev` wrote to .tot/dev-keys.json (re-read on
|
|
9
9
|
* every request, so it always sees the harness's current key). That file is
|
|
10
10
|
* dev-only scaffolding: your real receiver checks against the platform's
|
|
11
|
-
* published JWKS/signing-key metadata instead — see the
|
|
12
|
-
*
|
|
11
|
+
* published JWKS/signing-key metadata instead — see the Devkit's
|
|
12
|
+
* https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private
|
|
13
|
+
* (`examples/hello-inventory`, `recipes/inventory-sync-skuvault`,
|
|
14
|
+
* `recipes/fulfillment-shipstation`, `recipes/dropship-split-duoplane`).
|
|
15
|
+
*
|
|
16
|
+
* Online preview & production flow (see README.md):
|
|
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
|
+
* 3. `POST /api/apps/admin/test-orders` (synthetic preview orders bound to `test` install)
|
|
20
|
+
* 4. `POST /api/apps/admin/candidates` (`private_key_jwt`, `pending_approval`) ->
|
|
21
|
+
* 1-click Store Owner approval in `/admin#integrations` (`POST /api/apps/admin/candidates/decide`)
|
|
13
22
|
*/
|
|
14
23
|
import { createServer } from "node:http";
|
|
15
24
|
import { existsSync, readFileSync } from "node:fs";
|