@tokenoftrust/cli 8.3.0 → 8.4.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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",
|
|
@@ -23,6 +23,13 @@ import { missingGrantsOf, refusalHint } from "../../admission-hint.mjs";
|
|
|
23
23
|
import { validateManifest } from "../../vendor/private-apps-devkit.mjs";
|
|
24
24
|
import { generateCandidateKeys } from "./candidate-keys.mjs";
|
|
25
25
|
|
|
26
|
+
/** @typedef {import("../../vendor/private-apps-v1.8/admin.js").AdminInstallRequest} AdminInstallRequest */
|
|
27
|
+
/** @typedef {import("../../vendor/private-apps-v1.8/admin.js").AdminUpdateRequest} AdminUpdateRequest */
|
|
28
|
+
/** @typedef {import("../../vendor/private-apps-v1.8/admin.js").AdminInstallList} AdminInstallList */
|
|
29
|
+
/** @typedef {import("../../vendor/private-apps-v1.8/admin.js").AdminAppCandidateStage} AdminAppCandidateStage */
|
|
30
|
+
/** @typedef {import("../../vendor/private-apps-v1.8/admin.js").AdminAppCandidateList["candidates"][number]} AdminAppCandidate */
|
|
31
|
+
/** @typedef {{ id: string, version: string, scopes: string[], webhooks?: { endpoint: string }, widgets?: object[], clientAuth?: object }} ValidatedManifest */
|
|
32
|
+
|
|
26
33
|
export const DEFAULT_APP_ENV = "test";
|
|
27
34
|
const OPTION_VERBS = new Set(["install", "update", "rotate", "list", "replay", "test-order", "candidate", "suspend", "resume", "uninstall", "validate"]);
|
|
28
35
|
const TEST_ORDER_TRANSITIONS = new Map([["release", "released"], ["hold", "held"], ["cancel", "canceled"]]);
|
|
@@ -253,11 +260,11 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
253
260
|
const webhookEndpoint = args.webhookEndpoint === undefined ? m.webhooks?.endpoint : args.webhookEndpoint;
|
|
254
261
|
request = {
|
|
255
262
|
method: "POST", path: "/api/apps/admin/install",
|
|
256
|
-
body: {
|
|
263
|
+
body: /** @satisfies {AdminInstallRequest} */ ({
|
|
257
264
|
appId: m.id, appVersion: m.version, env: appEnv, scopes: m.scopes || [], manifest: m,
|
|
258
265
|
...(webhookEndpoint ? { webhookEndpoint } : {}),
|
|
259
266
|
...(Array.isArray(m.widgets) && m.widgets.length ? { widgetPlacements: m.widgets } : {}),
|
|
260
|
-
},
|
|
267
|
+
}),
|
|
261
268
|
};
|
|
262
269
|
} else if (verb === "update") {
|
|
263
270
|
const installId = args.positional[0];
|
|
@@ -267,13 +274,13 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
267
274
|
const m = loaded.manifest;
|
|
268
275
|
request = {
|
|
269
276
|
method: "POST", path: "/api/apps/admin/update",
|
|
270
|
-
body: {
|
|
277
|
+
body: /** @satisfies {AdminUpdateRequest} */ ({
|
|
271
278
|
installId, appVersion: m.version, scopes: m.scopes || [], manifest: m,
|
|
272
279
|
...(args.webhookEndpoint === undefined
|
|
273
280
|
? (m.webhooks?.endpoint ? { webhookEndpoint: m.webhooks.endpoint } : {})
|
|
274
281
|
: { webhookEndpoint: args.webhookEndpoint }),
|
|
275
282
|
...(Array.isArray(m.widgets) ? { widgetPlacements: m.widgets } : {}),
|
|
276
|
-
},
|
|
283
|
+
}),
|
|
277
284
|
};
|
|
278
285
|
} else if (verb === "rotate") {
|
|
279
286
|
const installId = args.positional[0];
|
|
@@ -348,14 +355,14 @@ export async function runAdmin(argv, ctx, deps = {}) {
|
|
|
348
355
|
const webhookEndpoint = args.webhookEndpoint === undefined ? m.webhooks?.endpoint : args.webhookEndpoint;
|
|
349
356
|
request = {
|
|
350
357
|
method: "POST", path: "/api/apps/admin/candidates",
|
|
351
|
-
body: {
|
|
358
|
+
body: /** @satisfies {AdminAppCandidateStage} */ ({
|
|
352
359
|
appId: m.id, appVersion: m.version, scopes: m.scopes || [], manifest: m,
|
|
353
360
|
...(webhookEndpoint ? { webhookEndpoint } : {}),
|
|
354
361
|
...(Array.isArray(m.widgets) && m.widgets.length ? { widgetPlacements: m.widgets } : {}),
|
|
355
362
|
...(args.jwksUri ? { jwksUri: args.jwksUri } : {}),
|
|
356
363
|
...(jwks ? { jwks } : {}),
|
|
357
364
|
...(args.requestConsent ? { requestConsent: true } : {}),
|
|
358
|
-
},
|
|
365
|
+
}),
|
|
359
366
|
};
|
|
360
367
|
} else {
|
|
361
368
|
const deliveryId = args.positional[0];
|
|
@@ -491,6 +498,7 @@ function runValidateManifest(args, ctx, out, err) {
|
|
|
491
498
|
return 1;
|
|
492
499
|
}
|
|
493
500
|
|
|
501
|
+
/** @param {{ candidates?: Array<Partial<AdminAppCandidate> & { id?: string }> } | null} data */
|
|
494
502
|
function renderCandidates(data, json, out) {
|
|
495
503
|
const rows = (Array.isArray(data?.candidates) ? data.candidates : []).map((c) => ({
|
|
496
504
|
candidateId: c?.candidateId ?? c?.id, appId: c?.appId, appVersion: c?.appVersion, status: c?.status,
|
|
@@ -517,7 +525,7 @@ function parseJsonBody(text) {
|
|
|
517
525
|
|
|
518
526
|
/**
|
|
519
527
|
* @param {string|null} appDir @param {any} ctx
|
|
520
|
-
* @returns {{ ok: true, manifest:
|
|
528
|
+
* @returns {{ ok: true, manifest: ValidatedManifest, dir: string } | { ok: false, message: string, next: string }}
|
|
521
529
|
*/
|
|
522
530
|
function loadManifest(appDir, ctx) {
|
|
523
531
|
const dir = resolve(appDir || ctx?.cwd || process.cwd());
|
|
@@ -576,6 +584,7 @@ function renderTestOrder(data, args, out, err) {
|
|
|
576
584
|
return 0;
|
|
577
585
|
}
|
|
578
586
|
|
|
587
|
+
/** @param {Partial<AdminInstallList> | null} data */
|
|
579
588
|
function renderList(data, json, out) {
|
|
580
589
|
const installs = Array.isArray(data?.installs) ? data.installs : [];
|
|
581
590
|
if (json) {
|
|
@@ -596,7 +605,7 @@ function renderList(data, json, out) {
|
|
|
596
605
|
return 0;
|
|
597
606
|
}
|
|
598
607
|
|
|
599
|
-
/** Only these fields ever leave a list response
|
|
608
|
+
/** Only these fields ever leave a list response. @param {AdminInstallList["installs"][number]} i */
|
|
600
609
|
function installRow(i) {
|
|
601
610
|
return {
|
|
602
611
|
installId: i?.installId, appId: i?.appId, appVersion: i?.appVersion, env: i?.env, status: i?.status,
|
|
@@ -105,12 +105,39 @@ const STRING_FACTS = new Set([
|
|
|
105
105
|
const STRING_LIST_FACTS = new Set(["flavor_labels", "registry_listings"]);
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
108
|
+
* Reject foreign-owned catalog attributes (`catalog_link.facts` or `catalog_link.identifiers`)
|
|
109
|
+
* committed into tenant catalog files (ADR 0048). Merchant git stores pointer-only links;
|
|
110
|
+
* Storefront hydrates Layer 1 facts from `product-catalog` into derived projections.
|
|
111
111
|
* @param {Array<{ file: string, record: any }>} products
|
|
112
112
|
*/
|
|
113
113
|
export function catalogFactFindings(products) {
|
|
114
|
+
const out = [];
|
|
115
|
+
for (const { file, record } of products) {
|
|
116
|
+
const variants = Array.isArray(record?.variants) ? record.variants : [];
|
|
117
|
+
variants.forEach((variant, vi) => {
|
|
118
|
+
const link = variant?.catalog_link;
|
|
119
|
+
if (!isObject(link)) return;
|
|
120
|
+
if (link.facts !== undefined || link.identifiers !== undefined || link.facts_state !== undefined) {
|
|
121
|
+
out.push({
|
|
122
|
+
level: "error",
|
|
123
|
+
rule: "catalog-link-committed-facts",
|
|
124
|
+
file: `${file} variants[${vi}].catalog_link`,
|
|
125
|
+
message: "Tenant catalog files must not commit catalog_link.facts, catalog_link.identifiers, or catalog_link.facts_state (ADR 0048).",
|
|
126
|
+
fix: "Store only the catalog_link pointer (item_id, accepted_revision_id); Storefront hydrates facts from product-catalog during reconcile and publish.",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Validate hydrated regulatory fact arrays (`variants[].catalog_link.facts`, storefront-catalog
|
|
136
|
+
* v2.1.0): a known fact carries a value of its key's type, any other state carries none, and a
|
|
137
|
+
* key is declared once per variant.
|
|
138
|
+
* @param {Array<{ file: string, record: any }>} products
|
|
139
|
+
*/
|
|
140
|
+
export function catalogHydratedFactFindings(products) {
|
|
114
141
|
const out = [];
|
|
115
142
|
for (const { file, record } of products) {
|
|
116
143
|
const variants = Array.isArray(record?.variants) ? record.variants : [];
|
|
@@ -120,7 +147,7 @@ export function catalogFactFindings(products) {
|
|
|
120
147
|
const at = `variants[${vi}].catalog_link.facts`;
|
|
121
148
|
const err = (rule, i, message, fix) => out.push({ level: "error", rule, file: `${file} ${at}[${i}]`, message, fix });
|
|
122
149
|
if (!Array.isArray(facts)) {
|
|
123
|
-
out.push({ level: "error", rule: "catalog-fact-shape", file: `${file} ${at}`, message: "`catalog_link.facts` must be an array.", fix: "Re-
|
|
150
|
+
out.push({ level: "error", rule: "catalog-fact-shape", file: `${file} ${at}`, message: "`catalog_link.facts` must be an array.", fix: "Re-hydrate the catalog facts projection from product-catalog." });
|
|
124
151
|
return;
|
|
125
152
|
}
|
|
126
153
|
const seen = new Set();
|
package/src/validate.mjs
CHANGED
|
@@ -157,14 +157,26 @@ function collectCatalogFlavorLabels(product, variant) {
|
|
|
157
157
|
const catalogFactOf = (variant, key) =>
|
|
158
158
|
(Array.isArray(variant?.catalog_link?.facts) ? variant.catalog_link.facts : []).find((f) => f?.key === key);
|
|
159
159
|
|
|
160
|
+
/** True when a variant carries a valid pointer-only `catalog_link` pin (ADR 0048). */
|
|
161
|
+
const hasCatalogLinkPointer = (variant) =>
|
|
162
|
+
Boolean(
|
|
163
|
+
variant?.catalog_link &&
|
|
164
|
+
typeof variant.catalog_link === "object" &&
|
|
165
|
+
typeof variant.catalog_link.item_id === "string" &&
|
|
166
|
+
variant.catalog_link.item_id.trim().length > 0 &&
|
|
167
|
+
typeof variant.catalog_link.accepted_revision_id === "string" &&
|
|
168
|
+
variant.catalog_link.accepted_revision_id.trim().length > 0,
|
|
169
|
+
);
|
|
170
|
+
|
|
160
171
|
/** A catalog fact settles a field unless it is unknown; conflicting/invalid facts settle it restrictively. */
|
|
161
172
|
const factDecides = (fact) => fact !== undefined && fact.state !== "unknown";
|
|
162
173
|
|
|
163
174
|
/**
|
|
164
|
-
* The classification a product still lacks.
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
175
|
+
* The classification a product still lacks. A variant carrying a valid pointer-only `catalog_link`
|
|
176
|
+
* receives its Layer 1 facts via derived hydration (ADR 0048) and does not trigger an offline gap.
|
|
177
|
+
* For unlinked variants (or hydrated records), accepted catalog facts are the primary truth and
|
|
178
|
+
* merchant fields are the secondary declaration; nothing is inferred from a title, tag, or
|
|
179
|
+
* product type.
|
|
168
180
|
*/
|
|
169
181
|
function productClassificationGaps(product) {
|
|
170
182
|
if (!product || typeof product !== "object") return [];
|
|
@@ -174,6 +186,7 @@ function productClassificationGaps(product) {
|
|
|
174
186
|
const variants = Array.isArray(product.variants) && product.variants.length > 0 ? product.variants : [null];
|
|
175
187
|
const gaps = new Set();
|
|
176
188
|
for (const variant of variants) {
|
|
189
|
+
if (hasCatalogLinkPointer(variant) && !Array.isArray(variant.catalog_link.facts)) continue;
|
|
177
190
|
const categoryFact = catalogFactOf(variant, "compliance_category");
|
|
178
191
|
const category = categoryFact?.state === "known" && typeof categoryFact.value === "string" ? categoryFact.value : explicitCategory;
|
|
179
192
|
const categoryClassified = factDecides(categoryFact) || Boolean(category);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Storefront Devkit Private Apps OpenAPI 1.8.0, commit 86ebe41a9785b177fb6dedf7f387bd4fc3b20787.
|
|
2
|
+
// apps/private/contract/openapi.yaml, SHA-256 00cd2b2665c4fc3183f48cac1ea2c30a6fa3a1b024f02bf0fc2774f60ec54b3e.
|
|
3
|
+
|
|
4
|
+
export interface AdminInstallRequest {
|
|
5
|
+
appId: string;
|
|
6
|
+
appVersion: string;
|
|
7
|
+
env: string;
|
|
8
|
+
scopes: string[];
|
|
9
|
+
manifest: object;
|
|
10
|
+
webhookEndpoint?: string | null;
|
|
11
|
+
widgetPlacements?: object[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AdminUpdateRequest {
|
|
15
|
+
installId: string;
|
|
16
|
+
appVersion?: string;
|
|
17
|
+
scopes?: string[];
|
|
18
|
+
manifest?: object;
|
|
19
|
+
webhookEndpoint?: string | null;
|
|
20
|
+
widgetPlacements?: object[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AdminInstallList {
|
|
24
|
+
installs: AdminInstall[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AdminInstall {
|
|
28
|
+
installId: string;
|
|
29
|
+
appId: string;
|
|
30
|
+
appVersion: string;
|
|
31
|
+
tenantId: string;
|
|
32
|
+
env: string;
|
|
33
|
+
status: "active" | "suspended" | "uninstalled";
|
|
34
|
+
scopes: string[];
|
|
35
|
+
manifest?: object;
|
|
36
|
+
webhookEndpoint?: string | null;
|
|
37
|
+
widgetPlacements?: object[];
|
|
38
|
+
installActor?: string;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AdminErrorBody {
|
|
44
|
+
error: string;
|
|
45
|
+
code?: string;
|
|
46
|
+
denials?: string[];
|
|
47
|
+
reasons?: ("install-inactive" | "webhook-endpoint-missing" | "processor-scope-missing")[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface AdminAppCandidateList {
|
|
51
|
+
candidates: AdminAppCandidate[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AdminAppCandidateStage {
|
|
55
|
+
appId: string;
|
|
56
|
+
appVersion: string;
|
|
57
|
+
scopes: string[];
|
|
58
|
+
manifest: object;
|
|
59
|
+
webhookEndpoint?: string | null;
|
|
60
|
+
widgetPlacements?: object[];
|
|
61
|
+
jwks?: { keys: {
|
|
62
|
+
kty: "RSA" | "EC";
|
|
63
|
+
kid: string;
|
|
64
|
+
alg?: "RS256" | "ES256";
|
|
65
|
+
use?: "sig";
|
|
66
|
+
[parameter: string]: unknown;
|
|
67
|
+
}[] };
|
|
68
|
+
jwksUri?: string;
|
|
69
|
+
requestConsent?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface AdminAppCandidate {
|
|
73
|
+
candidateId: string;
|
|
74
|
+
appId: string;
|
|
75
|
+
appVersion: string;
|
|
76
|
+
env: "production";
|
|
77
|
+
scopes: string[];
|
|
78
|
+
clientId: string;
|
|
79
|
+
keys: { kid: string; alg: "RS256" | "ES256" }[];
|
|
80
|
+
jwksHost: string | null;
|
|
81
|
+
requestConsent: boolean;
|
|
82
|
+
snapshotDigest: string;
|
|
83
|
+
status: "pending_approval" | "approved" | "rejected";
|
|
84
|
+
stagedAt: string;
|
|
85
|
+
decidedAt: string | null;
|
|
86
|
+
installId: string | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface AdminAppCandidateDecision {
|
|
90
|
+
candidateId: string;
|
|
91
|
+
snapshotDigest: string;
|
|
92
|
+
decision: "approve" | "reject";
|
|
93
|
+
grantConsent?: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface AdminAppCandidateDecisionResult {
|
|
97
|
+
candidateId: string;
|
|
98
|
+
status: "approved" | "rejected";
|
|
99
|
+
installId: string | null;
|
|
100
|
+
appId: string;
|
|
101
|
+
appVersion: string;
|
|
102
|
+
consentGranted: boolean;
|
|
103
|
+
}
|