@tokenoftrust/cli 6.12.8 → 6.13.1
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/bin/tot.mjs
CHANGED
|
@@ -81,6 +81,8 @@ const COMMANDS = [
|
|
|
81
81
|
{ invocation: "app rotate <installId>", blurb: "issue a new client secret for an install (printed once)" },
|
|
82
82
|
{ invocation: "app list", blurb: "your store's app installs — id, app, version, env, status, scopes" },
|
|
83
83
|
{ invocation: "app replay <deliveryId>", blurb: "re-send a webhook delivery to its install" },
|
|
84
|
+
{ invocation: "app test-order bind <installId> | create | release <orderId>", blurb: "synthetic preview orders bound to your test install (preview host)" },
|
|
85
|
+
{ invocation: "app candidate", blurb: "stage a production candidate (pending_approval) for owner approval" },
|
|
84
86
|
{ invocation: "catalog seed --preset=<name>", blurb: "seed your store checkout with synthetic products (general, regulated-vape, multi-warehouse)" },
|
|
85
87
|
{ invocation: "help", blurb: "show this help" },
|
|
86
88
|
{ invocation: "--version", blurb: "print the CLI version" },
|
|
@@ -366,7 +368,7 @@ async function dispatch(cmd, rest, ctx) {
|
|
|
366
368
|
function safeSubcommand(cmd, rest) {
|
|
367
369
|
if (cmd === "app") {
|
|
368
370
|
const sub = rest.find((t) => t && !t.startsWith("-"));
|
|
369
|
-
if (sub === "scaffold" || sub === "dev" || sub === "install" || sub === "update" || sub === "rotate" || sub === "list" || sub === "replay") return sub;
|
|
371
|
+
if (sub === "scaffold" || sub === "dev" || sub === "install" || sub === "update" || sub === "rotate" || sub === "list" || sub === "replay" || sub === "test-order" || sub === "candidate") return sub;
|
|
370
372
|
}
|
|
371
373
|
if (cmd === "catalog") {
|
|
372
374
|
const sub = rest.find((t) => t && !t.startsWith("-"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.13.1",
|
|
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",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `tot app install | update | rotate | list | replay` — the ONLINE Private App commands.
|
|
2
|
+
* `tot app install | update | rotate | list | replay | test-order | candidate` — the ONLINE Private App commands.
|
|
3
3
|
*
|
|
4
4
|
* They call the store's own `/api/apps/admin/*` routes with your `tot login` identity
|
|
5
5
|
* (`resolveViewerTransport`: a viewer session minted from your MCP token). The server's
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* tot app rotate POST /api/apps/admin/credentials/rotate
|
|
11
11
|
* tot app list GET /api/apps/admin/list
|
|
12
12
|
* tot app replay POST /api/apps/admin/webhooks/deliveries/<deliveryId>/replay
|
|
13
|
+
* tot app test-order POST /api/apps/admin/test-orders
|
|
14
|
+
* tot app candidate POST /api/apps/admin/candidates
|
|
13
15
|
*
|
|
14
16
|
* A client secret is printed once, by `install` or `rotate`, and nowhere else: `list` never
|
|
15
17
|
* carries one and nothing here writes it to a file or the activity log.
|
|
@@ -21,7 +23,7 @@ import { missingGrantsOf, refusalHint } from "../../admission-hint.mjs";
|
|
|
21
23
|
import { validateManifest } from "../../vendor/private-apps-devkit.mjs";
|
|
22
24
|
|
|
23
25
|
export const DEFAULT_APP_ENV = "test";
|
|
24
|
-
const OPTION_VERBS = new Set(["install", "update", "rotate", "list", "replay"]);
|
|
26
|
+
const OPTION_VERBS = new Set(["install", "update", "rotate", "list", "replay", "test-order", "candidate"]);
|
|
25
27
|
|
|
26
28
|
export const ADMIN_USAGE = `tot app — manage Private App installs on your store
|
|
27
29
|
|
|
@@ -32,6 +34,14 @@ export const ADMIN_USAGE = `tot app — manage Private App installs on your stor
|
|
|
32
34
|
tot app rotate <installId> issue a new client secret (printed ONCE); the old one stops working
|
|
33
35
|
tot app list your store's installs: id, app, version, env, status, scopes (never secrets)
|
|
34
36
|
tot app replay <deliveryId> re-send a webhook delivery to its install
|
|
37
|
+
tot app test-order bind <installId>
|
|
38
|
+
bind your test install as the preview processor (preview host only)
|
|
39
|
+
tot app test-order create write one synthetic preview order
|
|
40
|
+
tot app test-order release <orderId>
|
|
41
|
+
claim and release one synthetic preview order
|
|
42
|
+
tot app candidate [--app <dir>] [--jwks-uri <url> | --jwks <file>] [--request-consent] [--webhook-endpoint <url>]
|
|
43
|
+
stage a production candidate (pending_approval) for owner approval;
|
|
44
|
+
keys come from --jwks-uri, --jwks, or the manifest's clientAuth
|
|
35
45
|
|
|
36
46
|
Options (all online commands):
|
|
37
47
|
--tenant <appDomain> the store (default: the current checkout's store)
|
|
@@ -46,9 +56,9 @@ Options (all online commands):
|
|
|
46
56
|
/** Parse the online `tot app` argv. Pure — unit-tested. @param {string[]} argv */
|
|
47
57
|
export function parseAdminArgs(argv) {
|
|
48
58
|
/** @type {{ verb: string|null, positional: string[], app: string|null, env: string|null, tenant: string|null,
|
|
49
|
-
* url: string|null, webhookEndpoint: string|null|undefined, json: boolean, help: boolean, unknown: string[] }} */
|
|
59
|
+
* url: string|null, webhookEndpoint: string|null|undefined, jwksUri: string|null, jwks: string|null, requestConsent: boolean, json: boolean, help: boolean, unknown: string[] }} */
|
|
50
60
|
const a = { verb: null, positional: [], app: null, env: null, tenant: null, url: null,
|
|
51
|
-
webhookEndpoint: undefined, json: false, help: false, unknown: [] };
|
|
61
|
+
webhookEndpoint: undefined, jwksUri: null, jwks: null, requestConsent: false, json: false, help: false, unknown: [] };
|
|
52
62
|
const valueOf = (i, t) => {
|
|
53
63
|
const eq = t.indexOf("=");
|
|
54
64
|
return eq >= 0 ? { value: t.slice(eq + 1), next: i } : { value: argv[i + 1], next: i + 1 };
|
|
@@ -57,8 +67,10 @@ export function parseAdminArgs(argv) {
|
|
|
57
67
|
const t = argv[i];
|
|
58
68
|
const flag = t.startsWith("--") ? t.slice(0, t.includes("=") ? t.indexOf("=") : undefined) : null;
|
|
59
69
|
if (t === "--json") a.json = true;
|
|
70
|
+
else if (t === "--request-consent") a.requestConsent = true;
|
|
60
71
|
else if (t === "--help" || t === "-h") a.help = true;
|
|
61
|
-
else if (flag === "--app" || flag === "--env" || flag === "--tenant" || flag === "--url" || flag === "--webhook-endpoint"
|
|
72
|
+
else if (flag === "--app" || flag === "--env" || flag === "--tenant" || flag === "--url" || flag === "--webhook-endpoint"
|
|
73
|
+
|| flag === "--jwks-uri" || flag === "--jwks") {
|
|
62
74
|
const { value, next } = valueOf(i, t);
|
|
63
75
|
i = next;
|
|
64
76
|
const v = value === undefined || value.startsWith("--") ? "" : value;
|
|
@@ -66,6 +78,8 @@ export function parseAdminArgs(argv) {
|
|
|
66
78
|
else if (flag === "--env") a.env = v;
|
|
67
79
|
else if (flag === "--tenant") a.tenant = v;
|
|
68
80
|
else if (flag === "--url") a.url = v;
|
|
81
|
+
else if (flag === "--jwks-uri") a.jwksUri = v;
|
|
82
|
+
else if (flag === "--jwks") a.jwks = v;
|
|
69
83
|
else a.webhookEndpoint = v === "none" ? null : v;
|
|
70
84
|
} else if (t.startsWith("--")) a.unknown.push(t);
|
|
71
85
|
else if (a.verb === null) a.verb = t;
|
|
@@ -84,6 +98,8 @@ function nextForRefusal(status, body) {
|
|
|
84
98
|
if (code === "scope_denied") return "remove the refused scopes from tot-app.json, then re-run";
|
|
85
99
|
if (code === "already_installed") return "run `tot app list` for its installId, then `tot app update <installId>`";
|
|
86
100
|
if (code === "not_found") return "run `tot app list` to see this store's installs";
|
|
101
|
+
if (code === "preview_stage_required") return "point --url at the store's preview host, then re-run";
|
|
102
|
+
if (code === "test_install_required") return "bind an install with env test: `tot app list`, then `tot app test-order bind <installId>`";
|
|
87
103
|
if (code === "invalid_state") return "run `tot app list` to check the install's status";
|
|
88
104
|
if (status === 403) return refusalHint(status, missingGrantsOf(body));
|
|
89
105
|
if (status === 429) return "wait a minute, then re-run";
|
|
@@ -150,6 +166,40 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
150
166
|
request = { method: "POST", path: "/api/apps/admin/credentials/rotate", body: { installId } };
|
|
151
167
|
} else if (verb === "list") {
|
|
152
168
|
request = { method: "GET", path: "/api/apps/admin/list" };
|
|
169
|
+
} else if (verb === "test-order") {
|
|
170
|
+
const action = args.positional[0];
|
|
171
|
+
const id = args.positional[1];
|
|
172
|
+
if (action !== "bind" && action !== "create" && action !== "release") {
|
|
173
|
+
return fail("test-order needs an action: bind, create or release", "tot app test-order bind <installId> | create | release <orderId>");
|
|
174
|
+
}
|
|
175
|
+
if (action === "bind" && !id) return fail("no install to bind", "tot app test-order bind <installId> (find it with `tot app list`)");
|
|
176
|
+
if (action === "release" && !id) return fail("no order to release", "tot app test-order release <orderId>");
|
|
177
|
+
request = {
|
|
178
|
+
method: "POST", path: "/api/apps/admin/test-orders",
|
|
179
|
+
body: action === "bind" ? { action, installId: id } : action === "release" ? { action, orderId: id } : { action },
|
|
180
|
+
};
|
|
181
|
+
} else if (verb === "candidate") {
|
|
182
|
+
const loaded = loadManifest(args.app, ctx);
|
|
183
|
+
if (!loaded.ok) return fail(loaded.message, loaded.next);
|
|
184
|
+
const m = loaded.manifest;
|
|
185
|
+
if (args.jwksUri && args.jwks) return fail("pass only one of --jwks-uri and --jwks", "re-run with one key source");
|
|
186
|
+
let jwks;
|
|
187
|
+
if (args.jwks) {
|
|
188
|
+
try { jwks = JSON.parse(readFileSync(resolve(ctx?.cwd || process.cwd(), args.jwks), "utf8")); }
|
|
189
|
+
catch (e) { return fail(`--jwks ${args.jwks} is not readable JSON: ${e.message}`, "pass a JWKS file, or use --jwks-uri <url>"); }
|
|
190
|
+
}
|
|
191
|
+
const webhookEndpoint = args.webhookEndpoint === undefined ? m.webhooks?.endpoint : args.webhookEndpoint;
|
|
192
|
+
request = {
|
|
193
|
+
method: "POST", path: "/api/apps/admin/candidates",
|
|
194
|
+
body: {
|
|
195
|
+
appId: m.id, appVersion: m.version, scopes: m.scopes || [], manifest: m,
|
|
196
|
+
...(webhookEndpoint ? { webhookEndpoint } : {}),
|
|
197
|
+
...(Array.isArray(m.widgets) && m.widgets.length ? { widgetPlacements: m.widgets } : {}),
|
|
198
|
+
...(args.jwksUri ? { jwksUri: args.jwksUri } : {}),
|
|
199
|
+
...(jwks ? { jwks } : {}),
|
|
200
|
+
...(args.requestConsent ? { requestConsent: true } : {}),
|
|
201
|
+
},
|
|
202
|
+
};
|
|
153
203
|
} else {
|
|
154
204
|
const deliveryId = args.positional[0];
|
|
155
205
|
if (!deliveryId) return fail("no delivery to replay", "tot app replay <deliveryId>");
|
|
@@ -197,6 +247,15 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
197
247
|
else out(`✓ updated ${data?.install?.installId ?? "the install"} (${data?.install?.appId ?? "app"} ${data?.install?.appVersion ?? ""}, ${data?.install?.env ?? ""})`.replace(/ ,/g, ","));
|
|
198
248
|
return 0;
|
|
199
249
|
}
|
|
250
|
+
if (verb === "test-order") return renderTestOrder(data, args, out);
|
|
251
|
+
if (verb === "candidate") {
|
|
252
|
+
if (args.json) out(JSON.stringify(data));
|
|
253
|
+
else {
|
|
254
|
+
const c = data?.candidate ?? data;
|
|
255
|
+
out(`✓ staged ${c?.appId ?? "the app"} ${c?.appVersion ?? ""} as candidate ${c?.candidateId ?? c?.id ?? ""} (${c?.status ?? "pending_approval"}); the store owner approves it in /admin#integrations`.replace(/ {2,}/g, " "));
|
|
256
|
+
}
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
200
259
|
if (args.json) out(JSON.stringify(data));
|
|
201
260
|
else out(`✓ replay queued for delivery ${data?.delivery?.deliveryId ?? args.positional[0]}`);
|
|
202
261
|
return 0;
|
|
@@ -250,6 +309,20 @@ function renderCredential(verb, data, json, out, err) {
|
|
|
250
309
|
return 0;
|
|
251
310
|
}
|
|
252
311
|
|
|
312
|
+
function renderTestOrder(data, args, out) {
|
|
313
|
+
if (args.json) { out(JSON.stringify(data)); return 0; }
|
|
314
|
+
const action = args.positional[0];
|
|
315
|
+
if (action === "bind") {
|
|
316
|
+
const p = data?.processor;
|
|
317
|
+
out(`✓ bound ${p?.installId ?? args.positional[1]} as the preview processor (notifiable: ${p?.notifiable}, consent granted: ${p?.consentGranted})`);
|
|
318
|
+
} else if (action === "create") {
|
|
319
|
+
out(`✓ created synthetic order ${data?.order?.orderId ?? ""} (${data?.order?.stage ?? "preview"})`);
|
|
320
|
+
} else {
|
|
321
|
+
out(`✓ released ${data?.order?.orderId ?? args.positional[1]} (${data?.order?.fulfillment ?? ""}, assigned to ${data?.order?.assignedInstallId ?? "no install"})`);
|
|
322
|
+
}
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
253
326
|
function renderList(data, json, out) {
|
|
254
327
|
const installs = Array.isArray(data?.installs) ? data.installs : [];
|
|
255
328
|
if (json) {
|
|
@@ -18,6 +18,8 @@ const USAGE = `tot app — build and install a Storefront Private App
|
|
|
18
18
|
tot app rotate <installId> issue a new client secret (printed once)
|
|
19
19
|
tot app list your store's installs (never secrets)
|
|
20
20
|
tot app replay <deliveryId> re-send a webhook delivery
|
|
21
|
+
tot app test-order bind <installId> | create | release <orderId> synthetic preview orders for your test install
|
|
22
|
+
tot app candidate stage a production candidate (pending_approval) for owner approval
|
|
21
23
|
|
|
22
24
|
Run \`tot app <command> --help\` for options. Online commands use your \`tot login\` session.`;
|
|
23
25
|
|
|
@@ -37,7 +39,7 @@ export async function run(argv, ctx) {
|
|
|
37
39
|
const { run: runDev } = await import("./dev.mjs");
|
|
38
40
|
return /** @type {any} */ (runDev)(rest, ctx);
|
|
39
41
|
}
|
|
40
|
-
if (sub === "install" || sub === "update" || sub === "rotate" || sub === "list" || sub === "replay") {
|
|
42
|
+
if (sub === "install" || sub === "update" || sub === "rotate" || sub === "list" || sub === "replay" || sub === "test-order" || sub === "candidate") {
|
|
41
43
|
const { runAdmin } = await import("./admin.mjs");
|
|
42
44
|
return runAdmin(argv, ctx);
|
|
43
45
|
}
|
|
@@ -119,11 +119,27 @@ the preview stage without waiting on the store owner:
|
|
|
119
119
|
Manage your test install at any time with `tot app update <installId>`,
|
|
120
120
|
`tot app rotate <installId>`, `tot app list`, and `tot app replay <deliveryId>`.
|
|
121
121
|
3. **Trigger synthetic preview orders bound to the `test` install:**
|
|
122
|
-
|
|
122
|
+
Run `tot app test-order bind <installId>`, `tot app test-order create` and
|
|
123
|
+
`tot app test-order release <orderId>` (`POST /api/apps/admin/test-orders`) to bind your
|
|
123
124
|
`test` install as the preview fulfillment processor and emit synthetic preview orders with
|
|
124
125
|
RFC-reserved recipient fixtures. Preview tokens and webhooks are isolated by the stage wall
|
|
125
126
|
(`403 stage_mismatch` if used against live publication hosts).
|
|
126
127
|
|
|
128
|
+
### Calling the API in test
|
|
129
|
+
|
|
130
|
+
A `test` install calls its store's preview stage at `https://storefront.tokenoftrust.store/<tenant>`.
|
|
131
|
+
No preview token is needed: your app's own credential selects the test stage, and it acts only on
|
|
132
|
+
preview data. No `Origin` header is needed; server-to-server is fine. Production installs call the
|
|
133
|
+
store's own live domain, never the shared host. A request with no credential gets 401
|
|
134
|
+
`store-not-public`.
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
curl -s -X POST https://storefront.tokenoftrust.store/<tenant>/api/apps/oauth/token \
|
|
138
|
+
-d grant_type=client_credentials -d client_id=<clientId> -d client_secret=<clientSecret>
|
|
139
|
+
curl -s https://storefront.tokenoftrust.store/<tenant>/api/apps/v1/<path> \
|
|
140
|
+
-H "Authorization: Bearer <access_token>"
|
|
141
|
+
```
|
|
142
|
+
|
|
127
143
|
## Going live (`private_key_jwt` candidate staging & 1-click Owner approval)
|
|
128
144
|
|
|
129
145
|
1. Point `webhooks.endpoint` at your real, publicly reachable HTTPS receiver and swap the dev-only
|
|
@@ -131,8 +147,9 @@ the preview stage without waiting on the store owner:
|
|
|
131
147
|
(see the Devkit's
|
|
132
148
|
[`webhooks-and-api.md`](https://github.com/tokenoftrust/storefront-devkit/blob/main/apps/private/webhooks-and-api.md)).
|
|
133
149
|
2. **Stage a `private_key_jwt` `production` candidate (`pending_approval`):**
|
|
134
|
-
|
|
135
|
-
|
|
150
|
+
Run `tot app candidate --jwks-uri https://...` (or `--jwks <file>` with `{ keys: [ <publicKeyJwk> ] }`;
|
|
151
|
+
without either flag the manifest's `clientAuth: { method: "private_key_jwt", jwksUri }` is used),
|
|
152
|
+
which calls `POST /api/apps/admin/candidates`. This records a `status: "pending_approval"`
|
|
136
153
|
production candidate with zero shared secrets to hand off.
|
|
137
154
|
3. **1-click Store Owner approval:**
|
|
138
155
|
The Store Owner reviews the requested scopes, webhook endpoint, and key metadata in
|