@tokenoftrust/storefront-runner 7.7.0 → 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,6 +16,9 @@ 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. */
20
+ export const COUPONS_PROPOSE_ROLE = "coupons:propose" as const satisfies AgentRoleId;
21
+
19
22
  /** True when the catalog permits the role and the grant names it exactly. */
20
23
  export function agentHoldsRole(roles: readonly string[] | null | undefined, role: CatalogCapabilityId): boolean {
21
24
  return isAgentRoleId(role) && Array.isArray(roles) && roles.includes(role);
@@ -43,6 +43,7 @@ import { isAgentSession } from "./session.js";
43
43
  import {
44
44
  ADMIN_READ_ROLE,
45
45
  agentHoldsRole,
46
+ COUPONS_PROPOSE_ROLE,
46
47
  ORDERS_FULFIL_BY_ID_ROLE,
47
48
  ORDERS_READ_HOLDS_ROLE,
48
49
  PROPOSALS_WRITE_ROLE,
@@ -74,6 +75,7 @@ export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; ro
74
75
  { method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
75
76
  { method: "POST", path: "/api/admin/proposals", role: PROPOSALS_WRITE_ROLE },
76
77
  { method: "GET", path: "/api/admin/hold-reasons", role: ORDERS_READ_HOLDS_ROLE },
78
+ { method: "POST", path: "/api/admin/coupon-operations", role: COUPONS_PROPOSE_ROLE },
77
79
  ];
78
80
 
79
81
  function routeMatches(pattern: string, path: string): boolean {
@@ -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",
@@ -249,13 +249,15 @@ export function movementEventStatements(input: {
249
249
  source: string;
250
250
  sourceEventId: string;
251
251
  now: string;
252
+ eventPrefix?: string;
252
253
  }): SqlStatement[] {
253
254
  const { tenantId, stage } = input;
255
+ const tag = input.eventPrefix ?? "inv.";
254
256
  const prefix = `${input.sourceEventId}.`;
255
257
  return [
256
258
  {
257
259
  sql: `INSERT INTO webhook_events (id, tenant_id, topic, dataschema_version, payload, created_at)
258
- SELECT 'inv.' || m.source_event_id, m.tenant_id, '${INVENTORY_CHANGED_TOPIC}', '${INVENTORY_DATASCHEMA_VERSION}',
260
+ SELECT ? || m.source_event_id, m.tenant_id, '${INVENTORY_CHANGED_TOPIC}', '${INVENTORY_DATASCHEMA_VERSION}',
259
261
  json_object('sku', m.sku, 'locationId', m.location_id,
260
262
  'balance', ${locationBalanceSql("m.sku", "m.location_id")},
261
263
  'available', ${availableSql("m.sku")}, 'asOf', m.as_of), m.as_of
@@ -263,17 +265,19 @@ export function movementEventStatements(input: {
263
265
  WHERE m.tenant_id = ? AND m.stage = ? AND m.source = ?
264
266
  AND ${idMatchSql("m.source_event_id")}
265
267
  AND m.quantity_delta != 0
266
- AND NOT EXISTS (SELECT 1 FROM webhook_events WHERE id = 'inv.' || m.source_event_id)`,
268
+ AND NOT EXISTS (SELECT 1 FROM webhook_events WHERE id = ? || m.source_event_id)`,
267
269
  params: [
270
+ tag,
268
271
  ...twice(tenantId, stage),
269
272
  ...twice(tenantId, stage),
270
273
  tenantId,
271
274
  stage,
272
275
  input.source,
273
276
  ...idMatchParams(input.sourceEventId, prefix),
277
+ tag,
274
278
  ],
275
279
  },
276
- deliveryStatement({ tenantId, stage, now: input.now, idEquals: `inv.${input.sourceEventId}`, idPrefix: `inv.${prefix}` }),
280
+ deliveryStatement({ tenantId, stage, now: input.now, idEquals: `${tag}${input.sourceEventId}`, idPrefix: `${tag}${prefix}` }),
277
281
  ];
278
282
  }
279
283
 
@@ -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.0",
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",