@tokenoftrust/storefront-runner 3.9.0 → 3.9.1

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.
@@ -113,7 +113,30 @@ function fullCartProduct(value: unknown, handle: string, scope: string): value i
113
113
  Object.values(variant.option_values).every(option => typeof option === "string") &&
114
114
  variant.inventory && typeof variant.inventory === "object" && !Array.isArray(variant.inventory) && typeof variant.inventory.available === "boolean");
115
115
  }
116
+ /** The caller's per-request id (its token's `jti`), echoed so the caller's decision log joins this one. */
117
+ const CORRELATION_ID = /^cart-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
118
+ /**
119
+ * One `commerce-final-cart-decision` line per request: the caller's correlation id, the finding, the
120
+ * HTTP status and the elapsed time. Closed values only — never cart, tenant-config or shopper data.
121
+ * A throw answers JSON `authority-error` so the caller maps it to a shopper sentence.
122
+ */
116
123
  export async function POST(context: APIContext): Promise<Response> {
124
+ const started = Date.now();
125
+ const header = context.request.headers.get("x-commerce-correlation-id") ?? "";
126
+ const correlationId = CORRELATION_ID.test(header) ? header : "absent";
127
+ let response: Response;
128
+ let threw = false;
129
+ try { response = await authorize(context); } catch { threw = true; response = deny("authority-error", 500); }
130
+ let finding = "approved";
131
+ if (response.status !== 200 || threw) {
132
+ try { finding = String((await response.clone().json() as { finding?: unknown }).finding ?? "unreadable").slice(0, 80); } catch { finding = "unreadable"; }
133
+ }
134
+ try {
135
+ console.info("commerce-final-cart-decision", JSON.stringify({ correlationId, ok: response.status === 200, finding, status: response.status, threw, ms: Date.now() - started }));
136
+ } catch { /* Diagnostic delivery cannot alter the decision. */ }
137
+ return response;
138
+ }
139
+ async function authorize(context: APIContext): Promise<Response> {
117
140
  if (Number(context.request.headers.get("content-length") ?? 0) > 65536) return deny("malformed-request");
118
141
  const raw = await context.request.text();
119
142
  if (raw.length > 65536) return deny("malformed-request");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
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",