@tokenoftrust/cli 6.17.0 → 7.0.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/package.json +1 -1
- package/src/commands/app/admin.mjs +33 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.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",
|
|
@@ -40,6 +40,7 @@ export const ADMIN_USAGE = `tot app — manage Private App installs on your stor
|
|
|
40
40
|
tot app replay <deliveryId> re-send a webhook delivery to its install
|
|
41
41
|
tot app test-order bind <installId>
|
|
42
42
|
bind your test install as the store's preview processor
|
|
43
|
+
(it must be active, with a webhook endpoint and fulfillment:process)
|
|
43
44
|
tot app test-order create write one synthetic preview order
|
|
44
45
|
tot app test-order release <orderId>
|
|
45
46
|
claim and release one synthetic preview order
|
|
@@ -95,10 +96,31 @@ export function parseAdminArgs(argv) {
|
|
|
95
96
|
return a;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
/**
|
|
99
|
-
|
|
99
|
+
/** What `install_not_processor` reasons mean, and what fixes each. */
|
|
100
|
+
const PROCESSOR_REASONS = {
|
|
101
|
+
"install-inactive": { says: "the install is not active", fix: "`tot app resume <installId>` (or reinstall an uninstalled app)" },
|
|
102
|
+
"webhook-endpoint-missing": { says: "the install has no webhook endpoint", fix: "`tot app update <installId> --webhook-endpoint <https url>` (a tunnel works for local dev)" },
|
|
103
|
+
"processor-scope-missing": { says: "the install lacks the fulfillment:process scope", fix: "add \"fulfillment:process\" to tot-app.json scopes, then `tot app update <installId>`" },
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
function processorReasonsOf(body) {
|
|
107
|
+
return (Array.isArray(body?.reasons) ? body.reasons : []).filter((r) => typeof r === "string");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Verbs whose request addresses one install by id, so a bare 404 `not_found` means that install. */
|
|
111
|
+
const INSTALL_VERBS = new Set(["update", "rotate", "suspend", "resume", "uninstall"]);
|
|
112
|
+
|
|
113
|
+
/** Plain wording for the not-found, processor and entitlement refusals; null when none applies. */
|
|
114
|
+
function plainRefusal(status, body, verb) {
|
|
100
115
|
const code = typeof body?.code === "string" ? body.code : "";
|
|
101
|
-
if (
|
|
116
|
+
if (status === 404 && (code === "install_not_found" || (code === "not_found" && INSTALL_VERBS.has(verb)))) {
|
|
117
|
+
return "install_not_found: this store has no install with that id";
|
|
118
|
+
}
|
|
119
|
+
if (status === 404 && code === "order_not_found") return "order_not_found: this store has no synthetic preview order with that id";
|
|
120
|
+
if (code === "install_not_processor") {
|
|
121
|
+
const says = processorReasonsOf(body).map((r) => PROCESSOR_REASONS[r]?.says ?? r);
|
|
122
|
+
return `install_not_processor: that install cannot be the preview processor${says.length ? ` — ${says.join("; ")}` : ""}`;
|
|
123
|
+
}
|
|
102
124
|
if (code === "owner_required_for_production_app" || (status === 403 && missingGrantsOf(body).length)) {
|
|
103
125
|
return "not_entitled: your sign-in is not allowed to do this on this store";
|
|
104
126
|
}
|
|
@@ -117,7 +139,12 @@ function nextForRefusal(status, body, target) {
|
|
|
117
139
|
if (status === 401) return "run `tot login`, then re-run";
|
|
118
140
|
if (code === "scope_denied") return "remove the refused scopes from tot-app.json, then re-run";
|
|
119
141
|
if (code === "already_installed") return "run `tot app list` for its installId, then `tot app update <installId>`";
|
|
120
|
-
if (code === "not_found") return "run `tot app list` to see this store's installs";
|
|
142
|
+
if (code === "not_found" || code === "install_not_found") return "run `tot app list` to see this store's installs";
|
|
143
|
+
if (code === "order_not_found") return "create one with `tot app test-order create`, then release the orderId it prints";
|
|
144
|
+
if (code === "install_not_processor") {
|
|
145
|
+
const fixes = processorReasonsOf(body).map((r) => PROCESSOR_REASONS[r]?.fix).filter(Boolean);
|
|
146
|
+
return `${fixes.length ? fixes.join("; then ") : "run `tot app list` to check the install"}; then re-run \`tot app test-order bind <installId>\``;
|
|
147
|
+
}
|
|
121
148
|
if (code === "preview_stage_required") {
|
|
122
149
|
const preview = `${DEFAULT_STOREFRONT_ORIGIN}/${target.tenant}`;
|
|
123
150
|
return target.urlOverridden
|
|
@@ -271,7 +298,8 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
271
298
|
? `\n refused scopes: ${data.denials.map((d) => d?.scope ?? d?.id ?? JSON.stringify(d)).join(", ")}` : "";
|
|
272
299
|
const storefrontUrl = String(args.url || env.TOT_STOREFRONT_URL || "").trim().replace(/\/+$/, "");
|
|
273
300
|
const urlOverridden = storefrontUrl !== "" && storefrontUrl !== DEFAULT_STOREFRONT_ORIGIN;
|
|
274
|
-
|
|
301
|
+
const plain = plainRefusal(res.status, data, verb);
|
|
302
|
+
err(`✗ tot app ${verb}: ${plain ? `${plain} (${reason})` : reason}${denials}\n\n → next: ${nextForRefusal(res.status, data, { tenant, urlOverridden })}`);
|
|
275
303
|
return res.status === 401 || res.status === 403 ? 1 : (res.status >= 500 ? 1 : 2);
|
|
276
304
|
}
|
|
277
305
|
|