@tokenoftrust/storefront-runner 7.6.6 → 7.6.8

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.
@@ -14,8 +14,10 @@
14
14
  * - the ROLE-GATED routes in {@link AGENT_ROLE_ROUTES}, each only while the agent's
15
15
  * grant roles name that route's role: the PII-blind order reads (`admin:read`) and
16
16
  * the fulfil-by-id operation (`orders:fulfil-by-id`, which tot20 still decides per
17
- * call), and the stock levels and movement history reads (`admin:read`). Those
18
- * handlers project an agent's view; the gate only admits.
17
+ * call), the stock levels and movement history reads, and the supplier and purchase
18
+ * order reads (`admin:read`). Those handlers project an agent's view; the gate only
19
+ * admits. No purchasing write is reachable: an agent never creates, sends or receives
20
+ * a purchase order through a route.
19
21
  *
20
22
  * Everything else — every other `/api` route (so no derived credential such as the
21
23
  * CLI sign-in code or the activity-ingest token), `/admin`, `/cockpit`, `/dev`,
@@ -46,6 +48,10 @@ export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; ro
46
48
  { method: "GET", path: "/api/admin/inventory/history", role: ADMIN_READ_ROLE },
47
49
  { method: "GET", path: "/api/admin/inventory/stocktakes", role: ADMIN_READ_ROLE },
48
50
  { method: "GET", path: "/api/admin/inventory/stocktakes/:id", role: ADMIN_READ_ROLE },
51
+ { method: "GET", path: "/api/admin/purchasing/suppliers", role: ADMIN_READ_ROLE },
52
+ { method: "GET", path: "/api/admin/purchasing/suppliers/:id", role: ADMIN_READ_ROLE },
53
+ { method: "GET", path: "/api/admin/purchasing/orders", role: ADMIN_READ_ROLE },
54
+ { method: "GET", path: "/api/admin/purchasing/orders/:id", role: ADMIN_READ_ROLE },
49
55
  { method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
50
56
  ];
51
57
 
@@ -5,11 +5,13 @@
5
5
 
6
6
  /** The vendored artifact's schema and the digest tot20 stamped on it. */
7
7
  export const CAPABILITY_CATALOG_SCHEMA = "tot.capability-catalog/v1" as const;
8
- export const CAPABILITY_CATALOG_DIGEST = "sha256:0683a9f2312c22c53fd995e5b8f90929b8887251d5fc47300f82776801203a39" as const;
8
+ export const CAPABILITY_CATALOG_DIGEST = "sha256:575fa5e1da430973a51979967d3602314f987c6ca9cab3b2793adfa2c686e250" as const;
9
9
 
10
10
  /** Every capability row id the catalog names. */
11
11
  export const CATALOG_CAPABILITY_IDS = [
12
12
  "admin:read",
13
+ "attribution:write",
14
+ "catalog:read",
13
15
  "clientConfig:crossTenant",
14
16
  "clientConfig:get",
15
17
  "clientConfig:list",
@@ -61,21 +63,32 @@ export const CATALOG_CAPABILITY_IDS = [
61
63
  "core:view-verification-health",
62
64
  "core:view-verificationSummary",
63
65
  "core:view-wordpressIntegration",
66
+ "customers:read-minimal",
64
67
  "feedbackRecord:delete",
65
68
  "feedbackRecord:read",
66
69
  "forge:content-read-any",
67
70
  "forge:grant-any-tenant",
68
71
  "forge:provision-any-app",
72
+ "fulfillment:process",
69
73
  "grant:confirm",
70
74
  "grant:issue",
71
75
  "grant:list",
72
76
  "grant:revoke",
77
+ "inventory:read",
78
+ "inventory:write",
73
79
  "message:send-status",
74
80
  "orders:fulfil-by-id",
75
81
  "orders:read-customer",
82
+ "orders:read-minimal",
83
+ "orders:read-recipient",
84
+ "orders:webhook",
76
85
  "preview:view",
86
+ "purchasing:read",
87
+ "purchasing:write",
88
+ "reports:read",
77
89
  "storefrontEntitlements:set",
78
90
  "use-path:/app/connections",
91
+ "widgets:launch",
79
92
  ] as const;
80
93
  export type CatalogCapabilityId = (typeof CATALOG_CAPABILITY_IDS)[number];
81
94
 
@@ -118,6 +131,43 @@ export const AGENT_ROLE_IDS = [
118
131
  ] as const satisfies readonly CatalogCapabilityId[];
119
132
  export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
120
133
 
134
+ /** Capability rows whose audience is `app`. Includes rows that are not Private Apps scopes (no access); see PRIVATE_APP_SCOPE_IDS. */
135
+ export const APP_AUDIENCE_CAPABILITY_IDS = [
136
+ "attribution:write",
137
+ "catalog:read",
138
+ "customers:read-minimal",
139
+ "fulfillment:process",
140
+ "inventory:read",
141
+ "inventory:write",
142
+ "message:send-status",
143
+ "orders:read-minimal",
144
+ "orders:read-recipient",
145
+ "orders:webhook",
146
+ "purchasing:read",
147
+ "purchasing:write",
148
+ "reports:read",
149
+ "widgets:launch",
150
+ ] as const satisfies readonly CatalogCapabilityId[];
151
+ export type AppAudienceCapabilityId = (typeof APP_AUDIENCE_CAPABILITY_IDS)[number];
152
+
153
+ /** The Private Apps scopes: the app-audience rows that carry an access of read, write or launch. The registry accepts exactly these. */
154
+ export const PRIVATE_APP_SCOPE_IDS = [
155
+ "attribution:write",
156
+ "catalog:read",
157
+ "customers:read-minimal",
158
+ "fulfillment:process",
159
+ "inventory:read",
160
+ "inventory:write",
161
+ "orders:read-minimal",
162
+ "orders:read-recipient",
163
+ "orders:webhook",
164
+ "purchasing:read",
165
+ "purchasing:write",
166
+ "reports:read",
167
+ "widgets:launch",
168
+ ] as const satisfies readonly AppAudienceCapabilityId[];
169
+ export type PrivateAppScopeId = (typeof PRIVATE_APP_SCOPE_IDS)[number];
170
+
121
171
  export function isCatalogCapabilityId(value: unknown): value is CatalogCapabilityId {
122
172
  return typeof value === "string" && (CATALOG_CAPABILITY_IDS as readonly string[]).includes(value);
123
173
  }
@@ -126,6 +176,10 @@ export function isAgentRoleId(value: unknown): value is AgentRoleId {
126
176
  return typeof value === "string" && (AGENT_ROLE_IDS as readonly string[]).includes(value);
127
177
  }
128
178
 
179
+ export function isAppAudienceCapabilityId(value: unknown): value is AppAudienceCapabilityId {
180
+ return typeof value === "string" && (APP_AUDIENCE_CAPABILITY_IDS as readonly string[]).includes(value);
181
+ }
182
+
129
183
  /** The storefront tenant roles the catalog names (ids and labels; what a role may do stays in tot20). */
130
184
  export const CATALOG_TENANT_ROLES = [
131
185
  { "id": "owner", "label": "Owner" },
@@ -7,32 +7,25 @@
7
7
  * to floor clauses (`checkout:mutate`, `tax:mutate`, …) and must NEVER be
8
8
  * grantable.
9
9
  *
10
- * The catalog is hand-kept here (Workers can't read `docs/` off disk at
11
- * runtime) rather than imported at build time; `scopes.test.ts` asserts
12
- * structural equivalence against the actual contract JSON files, the same
13
- * discipline `schema.test.ts` uses for the D1 migrations vs. their read-model
14
- * consts — so this list and the contract can't silently drift.
10
+ * The accepted list is generated from the vendored capability catalog
11
+ * (`PRIVATE_APP_SCOPE_IDS`: the app-audience rows that carry an access of
12
+ * read, write or launch), never kept by hand. Workers can't read `docs/` off
13
+ * disk at runtime; `scopes.test.ts` asserts structural equivalence against the
14
+ * actual contract JSON files, so the list and the contract can't silently
15
+ * drift. An app-audience row with no access (message:send-status) is not a
16
+ * Private Apps scope and is unknown here.
15
17
  *
16
18
  * `validateScopes` is the ONE gate `AppRegistryService.install`/`update` call
17
- * before writing a row: any requested scope outside the V1 catalog, or any
18
- * scope in the forbidden list, denies the whole request (no partial grant).
19
+ * before writing a row: any scope in the forbidden list (checked first, by
20
+ * name) or outside the accepted list denies the whole request (no partial
21
+ * grant). Token issuance and verification keep only accepted scopes.
19
22
  */
20
23
 
21
- /** The V1 scope catalog (`contract/scopes.json`). Least-privilege, mostly READ. */
22
- export const V1_SCOPES = [
23
- "catalog:read",
24
- "orders:read:minimal",
25
- "orders:webhook",
26
- "customers:read:minimal",
27
- "inventory:read",
28
- "inventory:write",
29
- "reports:read",
30
- "attribution:write",
31
- "widgets:launch",
32
- "fulfillment:process",
33
- "orders:read:recipient",
34
- ] as const;
35
- export type V1Scope = (typeof V1_SCOPES)[number];
24
+ import { PRIVATE_APP_SCOPE_IDS, type PrivateAppScopeId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
25
+
26
+ /** The V1 scope catalog (`contract/scopes.json`), generated from the vendored capability catalog. Least-privilege, mostly READ. */
27
+ export const V1_SCOPES = PRIVATE_APP_SCOPE_IDS;
28
+ export type V1Scope = PrivateAppScopeId;
36
29
 
37
30
  /**
38
31
  * Denylist proving the compliance floor is unreachable (`contract/forbidden-scopes.json`).
@@ -63,20 +56,35 @@ export type ScopeValidationResult =
63
56
  | { ok: true; scopes: V1Scope[] }
64
57
  | { ok: false; code: "scope_denied"; denials: ScopeDenial[] };
65
58
 
59
+ /** Whether a value is a scope the registry accepts. Anything else, however it got here, is unknown. */
60
+ export function isAcceptedScope(value: unknown): value is V1Scope {
61
+ return typeof value === "string" && V1_SCOPE_SET.has(value);
62
+ }
63
+
66
64
  /**
67
- * Validate a requested scope array against the V1 catalog + forbidden list.
68
- * Deny-by-default and all-or-nothing: ANY scope that is forbidden or simply
69
- * not in the V1 catalog denies the entire request (never a partial grant).
65
+ * Validate a requested scope array against an accepted set + the forbidden list.
66
+ * The forbidden list is checked FIRST, by name, so no accepted set can make a
67
+ * forbidden id grantable. Deny-by-default and all-or-nothing: ANY scope that is
68
+ * forbidden or not in the accepted set denies the entire request (never a
69
+ * partial grant).
70
70
  */
71
- export function validateScopes(requested: readonly string[]): ScopeValidationResult {
71
+ export function validateScopesAgainst(
72
+ requested: readonly string[],
73
+ accepted: ReadonlySet<string>,
74
+ ): ScopeValidationResult {
72
75
  const denials: ScopeDenial[] = [];
73
76
  for (const scope of requested) {
74
77
  if (FORBIDDEN_SCOPE_SET.has(scope)) {
75
78
  denials.push({ scope, reason: "forbidden" });
76
- } else if (!V1_SCOPE_SET.has(scope)) {
79
+ } else if (!accepted.has(scope)) {
77
80
  denials.push({ scope, reason: "unknown" });
78
81
  }
79
82
  }
80
83
  if (denials.length) return { ok: false, code: "scope_denied", denials };
81
84
  return { ok: true, scopes: requested as V1Scope[] };
82
85
  }
86
+
87
+ /** Validate a requested scope array against the V1 catalog + forbidden list. */
88
+ export function validateScopes(requested: readonly string[]): ScopeValidationResult {
89
+ return validateScopesAgainst(requested, V1_SCOPE_SET);
90
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.6",
3
+ "version": "7.6.8",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",