@tokenoftrust/storefront-runner 7.9.0 → 7.9.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.
@@ -116,6 +116,8 @@ declare global {
116
116
  interface Locals {
117
117
  /** Tenant resolved from the request Host by src/middleware. */
118
118
  tenant: TenantConfig;
119
+ /** Set on the exact, tenant-routed Bearer readiness GET. */
120
+ couponDoorReadinessRouted?: { hasQuery: boolean };
119
121
  /**
120
122
  * THE route-tier answer for this request (ADR 0013), resolved once by the
121
123
  * middleware from the TENANT-RELATIVE path and used to pick which branch
@@ -50,6 +50,8 @@ import {
50
50
  type AgentRoleId,
51
51
  } from "./agentRoles.js";
52
52
 
53
+ export const COUPON_DOOR_READINESS_PATH = "/api/admin/coupon-operations-readiness";
54
+
53
55
  /** Exact non-content routes an agent session may reach, by method. */
54
56
  export const AGENT_ALLOWED_ROUTES: ReadonlyArray<{ method: string; path: string }> = [
55
57
  { method: "GET", path: "/api/dev/cli-session" },
@@ -333,7 +333,7 @@ export async function evaluateFinalCart(input: FinalCartRequest): Promise<FinalC
333
333
  /** The allocation quantities and balance checks shared by both final-cart entry points. */
334
334
  export function finalCartStockHolds(
335
335
  lines: readonly { sku: string; quantity: number }[],
336
- stockTracked: boolean,
336
+ stockTracked: boolean | undefined = true,
337
337
  authorities: readonly unknown[],
338
338
  catalogAvailable: boolean,
339
339
  ): { ok: true; holds: ReserveHold[] } | { ok: false; finding: string } {
@@ -344,7 +344,7 @@ export function finalCartStockHolds(
344
344
  const holds: ReserveHold[] = [];
345
345
  for (const sku of [...quantities.keys()].sort()) {
346
346
  const quantity = quantities.get(sku)!;
347
- if (!stockTracked) {
347
+ if (stockTracked === false) {
348
348
  holds.push({ sku, locationId: "unspecified", quantity, onHand: 0 });
349
349
  continue;
350
350
  }
@@ -53,6 +53,8 @@ export interface McpServiceRequest {
53
53
  path: string;
54
54
  query?: Record<string, string>;
55
55
  body?: unknown;
56
+ /** A credential-bearing body requires fixed transport diagnostics. */
57
+ sensitiveBody?: true;
56
58
  /**
57
59
  * A proof over a typed tuple, computed here from the service secret and merged into an object
58
60
  * `body` under `proof.field`. The caller supplies labels and values and receives only the proof;
@@ -165,8 +167,9 @@ export async function callMcpService(req: McpServiceRequest): Promise<McpService
165
167
  res = await req.transport.post(url, headers, body);
166
168
  }
167
169
  } catch (thrown) {
170
+ const detail = req.sensitiveBody ? "" : transportErrorDetail(thrown, secret);
168
171
  console.error(
169
- `[mcp-service-seam] ${req.method} ${req.path} transport-error: ${transportErrorClass(thrown)} (${urlEnv})${transportErrorDetail(thrown, secret)}`,
172
+ `[mcp-service-seam] ${req.method} ${req.path} transport-error: ${transportErrorClass(thrown)} (${urlEnv})${detail}`,
170
173
  );
171
174
  return { kind: "transport-error", message: MCP_SERVICE_TRANSPORT_FAILURE };
172
175
  }
@@ -44,7 +44,9 @@ import { ServerTiming, withServerTiming } from "@/lib/observability/shared/serve
44
44
  import { observeDeployVersion } from "@/lib/activity/deployVersion";
45
45
  import { primeActivityKillSwitch } from "@/lib/activity/killSwitch";
46
46
  import {
47
+ isAstroErrorRouteV1,
47
48
  isPlatformPublicDiscoveryPath,
49
+ middlewareRewriteTargetV1,
48
50
  platformStaticRootLocationV1,
49
51
  publicationRedirectLocationV1,
50
52
  resolveMiddlewareBranchV1,
@@ -59,7 +61,7 @@ import {
59
61
  import { mirrorBalanceKey, parseMirrorBalances, publicMirrorStage } from "@/lib/inventory/mirrorBalanceProjection";
60
62
  import { serveControlPlane } from "./controlPlane.js";
61
63
  import { KvSessionStore, readSession, SESSION_COOKIE } from "@/lib/access/auth/session";
62
- import { agentMayReach, agentSessionGateRefusal, holdReadMixedCredentialsRefusal } from "@/lib/access/auth/agentSessionGate";
64
+ import { agentMayReach, agentSessionGateRefusal, COUPON_DOOR_READINESS_PATH, holdReadMixedCredentialsRefusal } from "@/lib/access/auth/agentSessionGate";
63
65
  import { mintOpaqueBrokerAssertion } from "@/lib/access/auth/brokerAssertion";
64
66
  import { withDeclaredTenantConfig } from "@/config/declaredTenantConfig";
65
67
  import { closedCatalogPath, resolveShopperAccessPolicy } from "@tot/public-runtime/declared-tenant-config";
@@ -96,6 +98,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
96
98
  context.locals.serverTiming = timing;
97
99
  const seen: RequestDelivery = { cdnForwarded: false };
98
100
  const served = await serveRequest(context, next, seen, timing);
101
+ if (seen.couponDoorReadiness) return outer ? withServerTiming(served, timing) : served;
99
102
  // Registered responsive renditions on a rendered page, by the same addresses and markup the static
100
103
  // bundle carries. The materialize render is left to the bundle build, which owns its renditions.
101
104
  const { withRegisteredRenditions } = await import("@/lib/assets/registeredRenditions");
@@ -120,6 +123,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
120
123
 
121
124
  interface RequestDelivery {
122
125
  cdnForwarded: boolean;
126
+ couponDoorReadiness?: boolean;
123
127
  assetBasePath?: string;
124
128
  privateCatalog?: boolean;
125
129
  }
@@ -264,6 +268,20 @@ async function serveRequest(
264
268
  seen.assetBasePath = basePath;
265
269
  if (imageBasePath) context.locals.imageBasePath = imageBasePath;
266
270
 
271
+ // The Bearer-only readiness route owns its admission and needs only the routed tenant.
272
+ if (request.method === "GET" && renderPath === COUPON_DOOR_READINESS_PATH &&
273
+ url.pathname === `${basePath}${renderPath}` && (!routedByFallback || basePath !== "") &&
274
+ !isAstroErrorRouteV1(context.routePattern)) {
275
+ seen.couponDoorReadiness = true;
276
+ locals.tenant = tenant;
277
+ locals.basePath = basePath;
278
+ locals.couponDoorReadinessRouted = { hasQuery: request.url.includes("?") };
279
+ const rewrite = middlewareRewriteTargetV1({ requestPath: url.pathname, basePath, renderPath, search: "" });
280
+ const response = await (rewrite === undefined ? next() : next(rewrite));
281
+ applySecurityHeaders(response.headers);
282
+ return response;
283
+ }
284
+
267
285
  // ---- The one route classification -----------------------------------------
268
286
  // An EXPLICITLY unpaid store is never fully public: the ONLY way to reach its
269
287
  // hosted URL is to sign in, regardless of the demo-gate host list or mode —
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.9.0",
3
+ "version": "7.9.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",