@tokenoftrust/cli 6.14.6 → 6.15.0
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 +5 -0
- package/package.json +1 -1
- package/src/commands/app/admin.mjs +69 -2
- package/src/commands/app/index.mjs +4 -1
package/bin/tot.mjs
CHANGED
|
@@ -85,6 +85,11 @@ const COMMANDS = [
|
|
|
85
85
|
{ invocation: "app replay <deliveryId>", blurb: "re-send a webhook delivery to its install" },
|
|
86
86
|
{ invocation: "app test-order bind <installId> | create | release <orderId>", blurb: "synthetic preview orders bound to your test install (preview host)" },
|
|
87
87
|
{ invocation: "app candidate", blurb: "stage a production candidate (pending_approval) for owner approval" },
|
|
88
|
+
{ invocation: "app candidate status", blurb: "your store's candidates and their status" },
|
|
89
|
+
{ invocation: "app suspend <installId>", blurb: "disable an install's tokens, webhooks and widgets (reversible)" },
|
|
90
|
+
{ invocation: "app resume <installId>", blurb: "bring a suspended install back to active" },
|
|
91
|
+
{ invocation: "app uninstall <installId>", blurb: "revoke an install's credentials and clear its placements" },
|
|
92
|
+
{ invocation: "app validate [<manifest>]", blurb: "lint tot-app.json offline (invalid_manifest on refusal)" },
|
|
88
93
|
{ invocation: "catalog seed --preset=<name>", blurb: "seed your store checkout with synthetic products (general, regulated-vape, multi-warehouse)" },
|
|
89
94
|
{ invocation: "help", blurb: "show this help" },
|
|
90
95
|
{ invocation: "--version", blurb: "print the CLI version" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.0",
|
|
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",
|
|
@@ -23,7 +23,7 @@ import { missingGrantsOf, refusalHint } from "../../admission-hint.mjs";
|
|
|
23
23
|
import { validateManifest } from "../../vendor/private-apps-devkit.mjs";
|
|
24
24
|
|
|
25
25
|
export const DEFAULT_APP_ENV = "test";
|
|
26
|
-
const OPTION_VERBS = new Set(["install", "update", "rotate", "list", "replay", "test-order", "candidate"]);
|
|
26
|
+
const OPTION_VERBS = new Set(["install", "update", "rotate", "list", "replay", "test-order", "candidate", "suspend", "resume", "uninstall", "validate"]);
|
|
27
27
|
|
|
28
28
|
export const ADMIN_USAGE = `tot app — manage Private App installs on your store
|
|
29
29
|
|
|
@@ -31,6 +31,10 @@ export const ADMIN_USAGE = `tot app — manage Private App installs on your stor
|
|
|
31
31
|
install the app in <dir> (reads its tot-app.json); prints the client secret ONCE
|
|
32
32
|
tot app update <installId> [--app <dir>] [--webhook-endpoint <url|none>]
|
|
33
33
|
push the app's current version, scopes, manifest and widgets to an install
|
|
34
|
+
tot app suspend <installId> disable an install's tokens, webhooks and widgets (reversible)
|
|
35
|
+
tot app resume <installId> bring a suspended install back to active
|
|
36
|
+
tot app uninstall <installId> revoke an install's credentials and clear its placements (the audit trail stays)
|
|
37
|
+
tot app validate [<manifest>] lint tot-app.json offline; a refused manifest is reported as invalid_manifest
|
|
34
38
|
tot app rotate <installId> issue a new client secret (printed ONCE); the old one stops working
|
|
35
39
|
tot app list your store's installs: id, app, version, env, status, scopes (never secrets)
|
|
36
40
|
tot app replay <deliveryId> re-send a webhook delivery to its install
|
|
@@ -41,6 +45,7 @@ export const ADMIN_USAGE = `tot app — manage Private App installs on your stor
|
|
|
41
45
|
claim and release one synthetic preview order
|
|
42
46
|
(test orders always act on the store's preview stage, at
|
|
43
47
|
${DEFAULT_STOREFRONT_ORIGIN}/<tenant>; no --url needed)
|
|
48
|
+
tot app candidate status this store's candidates: id, app, version, status
|
|
44
49
|
tot app candidate [--app <dir>] [--jwks-uri <url> | --jwks <file>] [--request-consent] [--webhook-endpoint <url>]
|
|
45
50
|
stage a production candidate (pending_approval) for owner approval;
|
|
46
51
|
keys come from --jwks-uri, --jwks, or the manifest's clientAuth
|
|
@@ -90,6 +95,16 @@ export function parseAdminArgs(argv) {
|
|
|
90
95
|
return a;
|
|
91
96
|
}
|
|
92
97
|
|
|
98
|
+
/** Plain wording for the ownership and entitlement refusals; null when neither applies. */
|
|
99
|
+
function plainRefusal(status, body) {
|
|
100
|
+
const code = typeof body?.code === "string" ? body.code : "";
|
|
101
|
+
if (code === "not_found" && status === 404) return "not_owner: that install is not on this store";
|
|
102
|
+
if (code === "owner_required_for_production_app" || (status === 403 && missingGrantsOf(body).length)) {
|
|
103
|
+
return "not_entitled: your sign-in is not allowed to do this on this store";
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
93
108
|
/**
|
|
94
109
|
* The next step for a refused call: the server's `code` first, then the generic admission hint.
|
|
95
110
|
* @param {number} status @param {any} body @param {{ tenant: string, urlOverridden: boolean }} target
|
|
@@ -134,6 +149,8 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
134
149
|
if (args.unknown.length) return fail(`unknown option ${args.unknown[0]}`, "tot app --help");
|
|
135
150
|
const verb = args.verb;
|
|
136
151
|
|
|
152
|
+
if (verb === "validate") return runValidateManifest(args, ctx, out, err);
|
|
153
|
+
|
|
137
154
|
// ── build the request from local files and arguments, before any network call ──
|
|
138
155
|
/** @type {{ method: string, path: string, body?: unknown }} */
|
|
139
156
|
let request;
|
|
@@ -188,6 +205,12 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
188
205
|
method: "POST", path: "/api/apps/admin/test-orders",
|
|
189
206
|
body: action === "bind" ? { action, installId: id } : action === "release" ? { action, orderId: id } : { action },
|
|
190
207
|
};
|
|
208
|
+
} else if (verb === "suspend" || verb === "resume" || verb === "uninstall") {
|
|
209
|
+
const installId = args.positional[0];
|
|
210
|
+
if (!installId) return fail(`no install to ${verb}`, `tot app ${verb} <installId> (find it with \`tot app list\`)`);
|
|
211
|
+
request = { method: "POST", path: `/api/apps/admin/${verb}`, body: { installId } };
|
|
212
|
+
} else if (verb === "candidate" && args.positional[0] === "status") {
|
|
213
|
+
request = { method: "GET", path: "/api/apps/admin/candidates" };
|
|
191
214
|
} else if (verb === "candidate") {
|
|
192
215
|
const loaded = loadManifest(args.app, ctx);
|
|
193
216
|
if (!loaded.ok) return fail(loaded.message, loaded.next);
|
|
@@ -248,7 +271,7 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
248
271
|
? `\n refused scopes: ${data.denials.map((d) => d?.scope ?? d?.id ?? JSON.stringify(d)).join(", ")}` : "";
|
|
249
272
|
const storefrontUrl = String(args.url || env.TOT_STOREFRONT_URL || "").trim().replace(/\/+$/, "");
|
|
250
273
|
const urlOverridden = storefrontUrl !== "" && storefrontUrl !== DEFAULT_STOREFRONT_ORIGIN;
|
|
251
|
-
err(`✗ tot app ${verb}: ${reason}${denials}\n\n → next: ${nextForRefusal(res.status, data, { tenant, urlOverridden })}`);
|
|
274
|
+
err(`✗ tot app ${verb}: ${plainRefusal(res.status, data) ? `${plainRefusal(res.status, data)} (${reason})` : reason}${denials}\n\n → next: ${nextForRefusal(res.status, data, { tenant, urlOverridden })}`);
|
|
252
275
|
return res.status === 401 || res.status === 403 ? 1 : (res.status >= 500 ? 1 : 2);
|
|
253
276
|
}
|
|
254
277
|
|
|
@@ -260,6 +283,16 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
260
283
|
return 0;
|
|
261
284
|
}
|
|
262
285
|
if (verb === "test-order") return renderTestOrder(data, args, out);
|
|
286
|
+
if (verb === "suspend" || verb === "resume" || verb === "uninstall") {
|
|
287
|
+
if (args.json) out(JSON.stringify(data));
|
|
288
|
+
else {
|
|
289
|
+
const i = data?.install;
|
|
290
|
+
const done = verb === "uninstall" ? "uninstalled" : verb === "suspend" ? "suspended" : "resumed";
|
|
291
|
+
out(`✓ ${done} ${i?.installId ?? args.positional[0]} (${i?.appId ?? "app"}, status ${i?.status ?? ""})`);
|
|
292
|
+
}
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
if (verb === "candidate" && args.positional[0] === "status") return renderCandidates(data, args.json, out);
|
|
263
296
|
if (verb === "candidate") {
|
|
264
297
|
if (args.json) out(JSON.stringify(data));
|
|
265
298
|
else {
|
|
@@ -273,6 +306,40 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
273
306
|
return 0;
|
|
274
307
|
}
|
|
275
308
|
|
|
309
|
+
/** `tot app validate`: offline manifest lint; a refused manifest is `invalid_manifest`, exit 1. */
|
|
310
|
+
function runValidateManifest(args, ctx, out, err) {
|
|
311
|
+
const path = args.positional[0]
|
|
312
|
+
? resolve(ctx?.cwd || process.cwd(), args.positional[0])
|
|
313
|
+
: join(resolve(args.app || ctx?.cwd || process.cwd()), "tot-app.json");
|
|
314
|
+
if (!existsSync(path)) {
|
|
315
|
+
err(`✗ no manifest at ${path}\n\n → next: pass a path, or \`tot app scaffold <name>\``);
|
|
316
|
+
return 2;
|
|
317
|
+
}
|
|
318
|
+
let parsed;
|
|
319
|
+
try { parsed = JSON.parse(readFileSync(path, "utf8")); }
|
|
320
|
+
catch (e) { err(`✗ invalid_manifest: ${path} is not valid JSON: ${e.message}`); return 1; }
|
|
321
|
+
const result = validateManifest(parsed);
|
|
322
|
+
if (result.ok) {
|
|
323
|
+
if (args.json) out(JSON.stringify({ ok: true }));
|
|
324
|
+
else out(`✓ ${path} is a valid tot-app.json`);
|
|
325
|
+
return 0;
|
|
326
|
+
}
|
|
327
|
+
const errors = result.errors || [];
|
|
328
|
+
if (args.json) out(JSON.stringify({ ok: false, code: "invalid_manifest", errors }));
|
|
329
|
+
else err(`✗ invalid_manifest: ${path}\n${errors.map((e) => ` - ${e}`).join("\n")}\n\n → next: fix the manifest, then re-run \`tot app validate\``);
|
|
330
|
+
return 1;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function renderCandidates(data, json, out) {
|
|
334
|
+
const rows = (Array.isArray(data?.candidates) ? data.candidates : []).map((c) => ({
|
|
335
|
+
candidateId: c?.candidateId ?? c?.id, appId: c?.appId, appVersion: c?.appVersion, status: c?.status,
|
|
336
|
+
}));
|
|
337
|
+
if (json) { out(JSON.stringify(rows)); return 0; }
|
|
338
|
+
if (!rows.length) { out("No candidates on this store. Stage one with `tot app candidate`."); return 0; }
|
|
339
|
+
for (const r of rows) out(`${r.candidateId ?? ""} ${r.appId ?? ""} ${r.appVersion ?? ""} ${r.status ?? ""}`.trimEnd());
|
|
340
|
+
return 0;
|
|
341
|
+
}
|
|
342
|
+
|
|
276
343
|
/**
|
|
277
344
|
* A response body as JSON, or null when the store answered with something that is not JSON (an
|
|
278
345
|
* HTML error page from a proxy, an empty 204). Only a parse failure maps to null.
|
|
@@ -19,6 +19,9 @@ const USAGE = `tot app — build and install a Storefront Private App
|
|
|
19
19
|
tot app list your store's installs (never secrets)
|
|
20
20
|
tot app replay <deliveryId> re-send a webhook delivery
|
|
21
21
|
tot app test-order bind <installId> | create | release <orderId> synthetic preview orders for your test install
|
|
22
|
+
tot app suspend|resume|uninstall <installId> lifecycle of an install on your store
|
|
23
|
+
tot app validate [<manifest>] lint tot-app.json offline (invalid_manifest on refusal)
|
|
24
|
+
tot app candidate status your store's candidates and their status
|
|
22
25
|
tot app candidate stage a production candidate (pending_approval) for owner approval
|
|
23
26
|
|
|
24
27
|
Run \`tot app <command> --help\` for options. Online commands use your \`tot login\` session.`;
|
|
@@ -39,7 +42,7 @@ export async function run(argv, ctx) {
|
|
|
39
42
|
const { run: runDev } = await import("./dev.mjs");
|
|
40
43
|
return /** @type {any} */ (runDev)(rest, ctx);
|
|
41
44
|
}
|
|
42
|
-
if (sub === "install" || sub === "update" || sub === "rotate" || sub === "list" || sub === "replay" || sub === "test-order" || sub === "candidate") {
|
|
45
|
+
if (sub === "install" || sub === "update" || sub === "rotate" || sub === "list" || sub === "replay" || sub === "test-order" || sub === "candidate" || sub === "suspend" || sub === "resume" || sub === "uninstall" || sub === "validate") {
|
|
43
46
|
const { runAdmin } = await import("./admin.mjs");
|
|
44
47
|
return runAdmin(argv, ctx);
|
|
45
48
|
}
|