@tokenoftrust/storefront-runner 7.6.7 → 7.6.9

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.
@@ -13,6 +13,7 @@ export type { AgentRoleId };
13
13
  export const PREVIEW_VIEW_ROLE = "preview:view" as const satisfies AgentRoleId;
14
14
  export const ADMIN_READ_ROLE = "admin:read" as const satisfies AgentRoleId;
15
15
  export const ORDERS_FULFIL_BY_ID_ROLE = "orders:fulfil-by-id" as const satisfies AgentRoleId;
16
+ export const ORDERS_READ_HOLDS_ROLE = "orders:read-holds" as const satisfies AgentRoleId;
16
17
 
17
18
  /** True when the catalog permits the role and the grant names it exactly. */
18
19
  export function agentHoldsRole(roles: readonly string[] | null | undefined, role: CatalogCapabilityId): boolean {
@@ -14,7 +14,8 @@
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), the stock levels and movement history reads, and the supplier and purchase
17
+ * call), the hold-reasons read (`orders:read-holds`, rechecked by tot20 on every page),
18
+ * the stock levels and movement history reads, and the supplier and purchase
18
19
  * order reads (`admin:read`). Those handlers project an agent's view; the gate only
19
20
  * admits. No purchasing write is reachable: an agent never creates, sends or receives
20
21
  * a purchase order through a route.
@@ -28,7 +29,13 @@
28
29
  */
29
30
  import type { SessionRecord } from "./session.js";
30
31
  import { isAgentSession } from "./session.js";
31
- import { ADMIN_READ_ROLE, agentHoldsRole, ORDERS_FULFIL_BY_ID_ROLE, type AgentRoleId } from "./agentRoles.js";
32
+ import {
33
+ ADMIN_READ_ROLE,
34
+ agentHoldsRole,
35
+ ORDERS_FULFIL_BY_ID_ROLE,
36
+ ORDERS_READ_HOLDS_ROLE,
37
+ type AgentRoleId,
38
+ } from "./agentRoles.js";
32
39
 
33
40
  /** Exact non-content routes an agent session may reach, by method. */
34
41
  export const AGENT_ALLOWED_ROUTES: ReadonlyArray<{ method: string; path: string }> = [
@@ -53,6 +60,7 @@ export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; ro
53
60
  { method: "GET", path: "/api/admin/purchasing/orders", role: ADMIN_READ_ROLE },
54
61
  { method: "GET", path: "/api/admin/purchasing/orders/:id", role: ADMIN_READ_ROLE },
55
62
  { method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
63
+ { method: "GET", path: "/api/admin/hold-reasons", role: ORDERS_READ_HOLDS_ROLE },
56
64
  ];
57
65
 
58
66
  function routeMatches(pattern: string, path: string): boolean {
@@ -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:ad601b987e2dc989aeaae1315d451cbce5d9b824393eebba409aa36fee1e2089" 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,33 @@ 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-holds",
83
+ "orders:read-minimal",
84
+ "orders:read-recipient",
85
+ "orders:webhook",
76
86
  "preview:view",
87
+ "purchasing:read",
88
+ "purchasing:write",
89
+ "reports:read",
77
90
  "storefrontEntitlements:set",
78
91
  "use-path:/app/connections",
92
+ "widgets:launch",
79
93
  ] as const;
80
94
  export type CatalogCapabilityId = (typeof CATALOG_CAPABILITY_IDS)[number];
81
95
 
@@ -114,10 +128,50 @@ export type CatalogBundleName = (typeof CATALOG_BUNDLE_NAMES)[number];
114
128
  export const AGENT_ROLE_IDS = [
115
129
  "admin:read",
116
130
  "orders:fulfil-by-id",
131
+ "orders:read-holds",
117
132
  "preview:view",
118
133
  ] as const satisfies readonly CatalogCapabilityId[];
119
134
  export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
120
135
 
136
+ /** Capability rows whose audience is `app`. Includes rows that are not Private Apps scopes (no access); see PRIVATE_APP_SCOPE_IDS. */
137
+ export const APP_AUDIENCE_CAPABILITY_IDS = [
138
+ "attribution:write",
139
+ "catalog:read",
140
+ "customers:read-minimal",
141
+ "fulfillment:process",
142
+ "inventory:read",
143
+ "inventory:write",
144
+ "message:send-status",
145
+ "orders:read-holds",
146
+ "orders:read-minimal",
147
+ "orders:read-recipient",
148
+ "orders:webhook",
149
+ "purchasing:read",
150
+ "purchasing:write",
151
+ "reports:read",
152
+ "widgets:launch",
153
+ ] as const satisfies readonly CatalogCapabilityId[];
154
+ export type AppAudienceCapabilityId = (typeof APP_AUDIENCE_CAPABILITY_IDS)[number];
155
+
156
+ /** The Private Apps scopes: the app-audience rows that carry an access of read, write or launch. The registry accepts exactly these. */
157
+ export const PRIVATE_APP_SCOPE_IDS = [
158
+ "attribution:write",
159
+ "catalog:read",
160
+ "customers:read-minimal",
161
+ "fulfillment:process",
162
+ "inventory:read",
163
+ "inventory:write",
164
+ "orders:read-holds",
165
+ "orders:read-minimal",
166
+ "orders:read-recipient",
167
+ "orders:webhook",
168
+ "purchasing:read",
169
+ "purchasing:write",
170
+ "reports:read",
171
+ "widgets:launch",
172
+ ] as const satisfies readonly AppAudienceCapabilityId[];
173
+ export type PrivateAppScopeId = (typeof PRIVATE_APP_SCOPE_IDS)[number];
174
+
121
175
  export function isCatalogCapabilityId(value: unknown): value is CatalogCapabilityId {
122
176
  return typeof value === "string" && (CATALOG_CAPABILITY_IDS as readonly string[]).includes(value);
123
177
  }
@@ -126,6 +180,10 @@ export function isAgentRoleId(value: unknown): value is AgentRoleId {
126
180
  return typeof value === "string" && (AGENT_ROLE_IDS as readonly string[]).includes(value);
127
181
  }
128
182
 
183
+ export function isAppAudienceCapabilityId(value: unknown): value is AppAudienceCapabilityId {
184
+ return typeof value === "string" && (APP_AUDIENCE_CAPABILITY_IDS as readonly string[]).includes(value);
185
+ }
186
+
129
187
  /** The storefront tenant roles the catalog names (ids and labels; what a role may do stays in tot20). */
130
188
  export const CATALOG_TENANT_ROLES = [
131
189
  { "id": "owner", "label": "Owner" },
@@ -7,34 +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
- "purchasing:read",
30
- "purchasing:write",
31
- "reports:read",
32
- "attribution:write",
33
- "widgets:launch",
34
- "fulfillment:process",
35
- "orders:read:recipient",
36
- ] as const;
37
- 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;
38
29
 
39
30
  /**
40
31
  * Denylist proving the compliance floor is unreachable (`contract/forbidden-scopes.json`).
@@ -65,20 +56,35 @@ export type ScopeValidationResult =
65
56
  | { ok: true; scopes: V1Scope[] }
66
57
  | { ok: false; code: "scope_denied"; denials: ScopeDenial[] };
67
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
+
68
64
  /**
69
- * Validate a requested scope array against the V1 catalog + forbidden list.
70
- * Deny-by-default and all-or-nothing: ANY scope that is forbidden or simply
71
- * 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).
72
70
  */
73
- export function validateScopes(requested: readonly string[]): ScopeValidationResult {
71
+ export function validateScopesAgainst(
72
+ requested: readonly string[],
73
+ accepted: ReadonlySet<string>,
74
+ ): ScopeValidationResult {
74
75
  const denials: ScopeDenial[] = [];
75
76
  for (const scope of requested) {
76
77
  if (FORBIDDEN_SCOPE_SET.has(scope)) {
77
78
  denials.push({ scope, reason: "forbidden" });
78
- } else if (!V1_SCOPE_SET.has(scope)) {
79
+ } else if (!accepted.has(scope)) {
79
80
  denials.push({ scope, reason: "unknown" });
80
81
  }
81
82
  }
82
83
  if (denials.length) return { ok: false, code: "scope_denied", denials };
83
84
  return { ok: true, scopes: requested as V1Scope[] };
84
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.7",
3
+ "version": "7.6.9",
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",