@tokenoftrust/storefront-runner 7.7.1 → 7.7.2

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.
@@ -16,13 +16,8 @@ export const ORDERS_FULFIL_BY_ID_ROLE = "orders:fulfil-by-id" as const satisfies
16
16
  export const PROPOSALS_WRITE_ROLE = "proposals:write" as const satisfies AgentRoleId;
17
17
  export const ORDERS_READ_HOLDS_ROLE = "orders:read-holds" as const satisfies AgentRoleId;
18
18
 
19
- /** The role under which an agent files a `coupon.create` proposal; not yet in the vendored catalog. */
20
- export const COUPONS_PROPOSE_ROLE = "coupons:propose";
21
-
22
- /** True when `role` is in the vendored catalog and the grant names it exactly. */
23
- export function agentHoldsVendoredRole(roles: readonly string[] | null | undefined, role: string): boolean {
24
- return isAgentRoleId(role) && Array.isArray(roles) && roles.includes(role);
25
- }
19
+ /** The role under which an agent files a `coupon.create` proposal. */
20
+ export const COUPONS_PROPOSE_ROLE = "coupons:propose" as const satisfies AgentRoleId;
26
21
 
27
22
  /** True when the catalog permits the role and the grant names it exactly. */
28
23
  export function agentHoldsRole(roles: readonly string[] | null | undefined, role: CatalogCapabilityId): boolean {
@@ -40,11 +40,9 @@
40
40
  import { COMMERCE_STAGES } from "@tot/public-runtime";
41
41
  import type { SessionRecord } from "./session.js";
42
42
  import { isAgentSession } from "./session.js";
43
- import { isAgentRoleId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
44
43
  import {
45
44
  ADMIN_READ_ROLE,
46
45
  agentHoldsRole,
47
- agentHoldsVendoredRole,
48
46
  COUPONS_PROPOSE_ROLE,
49
47
  ORDERS_FULFIL_BY_ID_ROLE,
50
48
  ORDERS_READ_HOLDS_ROLE,
@@ -77,25 +75,9 @@ export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; ro
77
75
  { method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
78
76
  { method: "POST", path: "/api/admin/proposals", role: PROPOSALS_WRITE_ROLE },
79
77
  { method: "GET", path: "/api/admin/hold-reasons", role: ORDERS_READ_HOLDS_ROLE },
80
- ];
81
-
82
- /**
83
- * Exact filing doors under a role the platform has not vendored yet. The role is not a catalog id, so
84
- * no grant can hold it: until it is vendored the gate answers the door 501 `not_configured` itself, and
85
- * no handler is reached. Once the catalog carries the role, a grant naming it is admitted to the handler,
86
- * which verifies the grant.
87
- */
88
- export const AGENT_FILING_ROUTES: ReadonlyArray<{ method: string; path: string; role: string }> = [
89
78
  { method: "POST", path: "/api/admin/coupon-operations", role: COUPONS_PROPOSE_ROLE },
90
79
  ];
91
80
 
92
- /** True when `method renderPath` is a filing door whose role is not in the vendored catalog. */
93
- export function agentFilingDoorUnvendored(method: string, renderPath: string): boolean {
94
- const verb = (method || "GET").toUpperCase();
95
- const path = gatePath(renderPath);
96
- return path !== null && AGENT_FILING_ROUTES.some((r) => r.method === verb && r.path === path && !isAgentRoleId(r.role));
97
- }
98
-
99
81
  function routeMatches(pattern: string, path: string): boolean {
100
82
  if (!pattern.endsWith("/:id")) return pattern === path;
101
83
  const base = pattern.slice(0, -"/:id".length);
@@ -173,7 +155,6 @@ export function agentMayReach(method: string, renderPath: string, roles: readonl
173
155
  if (path === null) return false;
174
156
  if (AGENT_ALLOWED_ROUTES.some((r) => r.method === verb && r.path === path)) return true;
175
157
  if (AGENT_ROLE_ROUTES.some((r) => r.method === verb && routeMatches(r.path, path) && agentHoldsRole(roles, r.role))) return true;
176
- if (AGENT_FILING_ROUTES.some((r) => r.method === verb && r.path === path && agentHoldsVendoredRole(roles, r.role))) return true;
177
158
  if (verb !== "GET" && verb !== "HEAD") return false;
178
159
  // `/__capabilities` and any other `/__*` console is a control surface.
179
160
  if (path.startsWith("/__")) return false;
@@ -249,12 +230,6 @@ export function agentSessionGateRefusal(
249
230
  );
250
231
  }
251
232
  if (agentMayReach(method, renderPath, session.actor.roles)) return null;
252
- if (agentFilingDoorUnvendored(method, renderPath)) {
253
- return new Response(JSON.stringify({ error: "not_configured" }), {
254
- status: 501,
255
- headers: { "content-type": "application/json", "cache-control": "no-store" },
256
- });
257
- }
258
233
  return new Response(
259
234
  JSON.stringify({ error: "agent_route_not_allowed", reason: "agentDenied" }),
260
235
  { status: 403, headers: { "content-type": "application/json", "cache-control": "no-store" } },
@@ -471,6 +471,20 @@ export function isHoldReadBearerRequest(input: HoldReadBearerRequest): boolean {
471
471
  && /^Bearer\s+\S/i.test(input.authorization?.trim() ?? "");
472
472
  }
473
473
 
474
+ const COUPON_FILING_PATH = "/api/admin/coupon-operations";
475
+
476
+ /**
477
+ * A `POST` of the coupon filing door carrying a `Bearer` credential: the only coupon-operation API that
478
+ * reaches its handler with no session. Presence only: the handler authorizes the credential live and
479
+ * refuses everything else. `renderPath` is the tenant-relative publication path, so a neighbor path,
480
+ * another method, a suffix or a trailing slash matches nothing.
481
+ */
482
+ export function isCouponFilingBearerRequest(input: HoldReadBearerRequest): boolean {
483
+ return input.method === "POST"
484
+ && input.renderPath === COUPON_FILING_PATH
485
+ && /^Bearer\s+\S/i.test(input.authorization?.trim() ?? "");
486
+ }
487
+
474
488
  /** The render path is the app token endpoint, whose form body {@link isAppCredentialRequest} reads. */
475
489
  export function isAppTokenPath(renderPath: string | undefined): boolean {
476
490
  return renderPath === APP_TOKEN_PATH;
@@ -534,6 +548,11 @@ export interface LoginGateInput {
534
548
  * its handler, which authorizes the credential live for this tenant and stage.
535
549
  */
536
550
  holdReadBearer?: boolean;
551
+ /**
552
+ * True when the request is an {@link isCouponFilingBearerRequest} on a preview surface. It reaches
553
+ * its handler, which authorizes the credential live for this tenant and stage.
554
+ */
555
+ couponFilingBearer?: boolean;
537
556
  }
538
557
 
539
558
  /**
@@ -578,6 +597,8 @@ export function evaluateLoginGate(input: LoginGateInput): LoginGateDecision {
578
597
  if (input.appCredential) return { action: "pass" };
579
598
  // The hold-reasons read's own bearer reaches its handler, the authority for the credential.
580
599
  if (input.holdReadBearer) return { action: "pass" };
600
+ // The coupon filing door's own bearer reaches its handler, the authority for the credential.
601
+ if (input.couponFilingBearer) return { action: "pass" };
581
602
  if (input.hasValidSession) return { action: "pass" };
582
603
  return { action: "redirect", location: loginRedirectLocation(input.pathname) };
583
604
  }
@@ -5,7 +5,7 @@
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:0325d1d04b03c03895d741463c587354c9bf99e992b526bc52cb68132f5429b6" as const;
8
+ export const CAPABILITY_CATALOG_DIGEST = "sha256:d919aef43b1e2db030a87bebdf87946a29c18f24c0feb89494ea55a65b4bc943" as const;
9
9
 
10
10
  /** Every capability row id the catalog names. */
11
11
  export const CATALOG_CAPABILITY_IDS = [
@@ -63,6 +63,7 @@ export const CATALOG_CAPABILITY_IDS = [
63
63
  "core:view-verification-health",
64
64
  "core:view-verificationSummary",
65
65
  "core:view-wordpressIntegration",
66
+ "coupons:propose",
66
67
  "customers:read-minimal",
67
68
  "feedbackRecord:delete",
68
69
  "feedbackRecord:read",
@@ -84,6 +85,7 @@ export const CATALOG_CAPABILITY_IDS = [
84
85
  "orders:read-recipient",
85
86
  "orders:webhook",
86
87
  "preview:view",
88
+ "preview:view-owner",
87
89
  "proposal-events:read",
88
90
  "proposals:write",
89
91
  "purchasing:read",
@@ -129,9 +131,11 @@ export type CatalogBundleName = (typeof CATALOG_BUNDLE_NAMES)[number];
129
131
  /** Capability rows marked holdable by sponsored agents in the catalog. */
130
132
  export const AGENT_ROLE_IDS = [
131
133
  "admin:read",
134
+ "coupons:propose",
132
135
  "orders:fulfil-by-id",
133
136
  "orders:read-holds",
134
137
  "preview:view",
138
+ "preview:view-owner",
135
139
  "proposals:write",
136
140
  ] as const satisfies readonly CatalogCapabilityId[];
137
141
  export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
@@ -140,6 +144,7 @@ export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
140
144
  export const APP_AUDIENCE_CAPABILITY_IDS = [
141
145
  "attribution:write",
142
146
  "catalog:read",
147
+ "coupons:propose",
143
148
  "customers:read-minimal",
144
149
  "fulfillment:process",
145
150
  "inventory:read",
@@ -34,6 +34,7 @@ import {
34
34
  evaluateLoginGate,
35
35
  isApiPath,
36
36
  isAppCredentialRequest,
37
+ isCouponFilingBearerRequest,
37
38
  isHoldReadBearerRequest,
38
39
  isAppTokenPath,
39
40
  isAuthPath,
@@ -126,6 +127,7 @@ async function serveControlPlaneInScope(input: ControlPlaneInput): Promise<Respo
126
127
  // grant `resource` is the tenant's appDomain — never input.
127
128
  let appTestStage = false;
128
129
  let holdReadBearer = false;
130
+ let couponFilingBearer = false;
129
131
  if (input.hostLoginGated && !input.internalContentGrant) {
130
132
  // From the platform registry by id, NOT off `tenant` — that object resolves
131
133
  // from TENANT_CACHE KV first, so a record written before this field existed
@@ -194,6 +196,11 @@ async function serveControlPlaneInScope(input: ControlPlaneInput): Promise<Respo
194
196
  renderPath,
195
197
  authorization: request.headers.get("authorization"),
196
198
  });
199
+ couponFilingBearer = isCouponFilingBearerRequest({
200
+ method: request.method,
201
+ renderPath,
202
+ authorization: request.headers.get("authorization"),
203
+ });
197
204
  }
198
205
 
199
206
  // Canonical admin tenant landing: an AUTHENTICATED viewer who is not a
@@ -242,6 +249,7 @@ async function serveControlPlaneInScope(input: ControlPlaneInput): Promise<Respo
242
249
  renderPath,
243
250
  appCredential: appTestStage,
244
251
  holdReadBearer,
252
+ couponFilingBearer,
245
253
  });
246
254
  if (decision.action === "redirect") {
247
255
  // Admin and the cockpit hard-redirect to sign-in rather than rendering the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.7.1",
3
+ "version": "7.7.2",
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",