@tokenoftrust/storefront-runner 7.6.9 → 7.6.11
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.
- package/agency-kit/tools/lib/catalog-model/files.mjs +8 -2
- package/apps/storefront/src/lib/developer-experience/http/mcpServiceCall.ts +11 -1
- package/apps/storefront/src/lib/developer-experience/http/mcpServiceProof.ts +32 -0
- package/apps/storefront/src/pages/404.astro +1 -1
- package/apps/storefront/src/pages/[...slug].astro +11 -0
- package/package.json +1 -1
|
@@ -298,7 +298,7 @@ export function readCatalogFiles(entries, { tenantScope, inventoryProvider }) {
|
|
|
298
298
|
// LISTING_DESCRIPTION_CHARS) plus every collection whole, or, when any file fails validation, the
|
|
299
299
|
// failures. A product page reads its full file.
|
|
300
300
|
|
|
301
|
-
/** Version of the projection document;
|
|
301
|
+
/** Version of the projection document written by this build; readers accept version 1..CATALOG_LISTING_VERSION. */
|
|
302
302
|
export const CATALOG_LISTING_VERSION = 2;
|
|
303
303
|
/** Metafield namespaces a listing keeps: the compliance classification a listing's readiness and gates read. */
|
|
304
304
|
export const LISTING_METAFIELD_NAMESPACES = Object.freeze(["compliance", "bigcommerce_custom"]);
|
|
@@ -406,7 +406,13 @@ export function readCatalogListing(raw, { tenantScope, inventoryProvider }) {
|
|
|
406
406
|
} catch {
|
|
407
407
|
doc = null;
|
|
408
408
|
}
|
|
409
|
-
if (
|
|
409
|
+
if (
|
|
410
|
+
!isObject(doc) ||
|
|
411
|
+
typeof doc.version !== "number" ||
|
|
412
|
+
!Number.isInteger(doc.version) ||
|
|
413
|
+
doc.version < 1 ||
|
|
414
|
+
doc.version > CATALOG_LISTING_VERSION
|
|
415
|
+
) {
|
|
410
416
|
throw new CatalogFileError([
|
|
411
417
|
{ path: "catalog/", issues: ["the catalog listing projection is unreadable; reconcile the preview again"] },
|
|
412
418
|
]);
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* for the outcome.
|
|
27
27
|
*/
|
|
28
28
|
import { readEnv } from "@/lib/publication/shared/env";
|
|
29
|
+
import { mcpServiceProof, type McpServiceProofSpec } from "./mcpServiceProof";
|
|
29
30
|
|
|
30
31
|
export interface McpServiceResponse {
|
|
31
32
|
status: number;
|
|
@@ -52,6 +53,12 @@ export interface McpServiceRequest {
|
|
|
52
53
|
path: string;
|
|
53
54
|
query?: Record<string, string>;
|
|
54
55
|
body?: unknown;
|
|
56
|
+
/**
|
|
57
|
+
* A proof over a typed tuple, computed here from the service secret and merged into an object
|
|
58
|
+
* `body` under `proof.field`. The caller supplies labels and values and receives only the proof;
|
|
59
|
+
* the secret never leaves this module.
|
|
60
|
+
*/
|
|
61
|
+
proof?: McpServiceProofSpec;
|
|
55
62
|
/** `"grant"` selects `MCP_GRANT_AUTHORITY_URL`; omitted selects `MCP_APP_BINDING_URL`. */
|
|
56
63
|
authority?: "grant";
|
|
57
64
|
transport: McpServiceTransport;
|
|
@@ -147,12 +154,15 @@ export async function callMcpService(req: McpServiceRequest): Promise<McpService
|
|
|
147
154
|
const headers = { "x-mcp-service-secret": secret };
|
|
148
155
|
let res: McpServiceResponse;
|
|
149
156
|
try {
|
|
157
|
+
const body = req.proof
|
|
158
|
+
? { ...(req.body as Record<string, unknown>), [req.proof.field]: await mcpServiceProof(req.proof, secret) }
|
|
159
|
+
: req.body;
|
|
150
160
|
if (req.method === "GET") {
|
|
151
161
|
if (!req.transport.get) throw new Error("transport has no get()");
|
|
152
162
|
res = await req.transport.get(url, headers);
|
|
153
163
|
} else {
|
|
154
164
|
if (!req.transport.post) throw new Error("transport has no post()");
|
|
155
|
-
res = await req.transport.post(url, headers,
|
|
165
|
+
res = await req.transport.post(url, headers, body);
|
|
156
166
|
}
|
|
157
167
|
} catch (thrown) {
|
|
158
168
|
console.error(
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof that a request body was produced by a holder of the shared tot-mcp service key. The caller
|
|
3
|
+
* names a field, two labels and the tuple to sign; this module derives a key from the service
|
|
4
|
+
* secret and returns only the hex HMAC. The secret is used here and in `callMcpService`, and never
|
|
5
|
+
* handed to a caller.
|
|
6
|
+
*
|
|
7
|
+
* The proof shows possession of the shared service key over the tuple. It does not establish who
|
|
8
|
+
* the viewer is: the caller's own admin and tenant checks do that before a proof is requested.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface McpServiceProofSpec {
|
|
12
|
+
/** The body field that carries the proof. */
|
|
13
|
+
field: string;
|
|
14
|
+
/** Derives the signing key from the service secret. */
|
|
15
|
+
keyLabel: string;
|
|
16
|
+
/** Prefixes the signed tuple, so a proof for one purpose verifies for no other. */
|
|
17
|
+
proofLabel: string;
|
|
18
|
+
/** The signed values, in order. */
|
|
19
|
+
tuple: readonly (string | number)[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function hmac(key: BufferSource, message: string): Promise<ArrayBuffer> {
|
|
23
|
+
const imported = await crypto.subtle.importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
24
|
+
return crypto.subtle.sign("HMAC", imported, new TextEncoder().encode(message));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Lowercase hex HMAC-SHA256 of `[proofLabel, ...tuple]` under a key derived from the secret. */
|
|
28
|
+
export async function mcpServiceProof(spec: McpServiceProofSpec, secret: string): Promise<string> {
|
|
29
|
+
const key = await hmac(new TextEncoder().encode(secret), spec.keyLabel);
|
|
30
|
+
const proof = new Uint8Array(await hmac(key, JSON.stringify([spec.proofLabel, ...spec.tuple])));
|
|
31
|
+
return Array.from(proof, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
32
|
+
}
|
|
@@ -20,7 +20,7 @@ const { tenant, tot, basePath, features } = Astro.locals;
|
|
|
20
20
|
// A handful of collections to redirect lost visitors toward. Marketing tenants
|
|
21
21
|
// (features.catalog === false) have no /collections route at all — skip the
|
|
22
22
|
// fetch entirely rather than trust it to come back empty.
|
|
23
|
-
const collections = features.catalog ? (await tot.listCollections()).slice(0, 3) : [];
|
|
23
|
+
const collections = features.catalog ? (await tot.listCollections().catch(() => [])).slice(0, 3) : [];
|
|
24
24
|
---
|
|
25
25
|
|
|
26
26
|
<Layout
|
|
@@ -25,6 +25,17 @@ const { tenant, canonicalBase, content, basePath, apiBasePath, capabilities, fea
|
|
|
25
25
|
Astro.locals;
|
|
26
26
|
const slug = (Astro.params.slug ?? "").replace(/^\/+|\/+$/g, "");
|
|
27
27
|
|
|
28
|
+
// Astro's DefaultErrorHandler falls back to this catch-all when no 500 route exists,
|
|
29
|
+
// passing `{ error }` in Astro.props with status 500. Preserve the 500 instead of
|
|
30
|
+
// returning a body-less 404, which DefaultErrorHandler.mergeResponses would otherwise
|
|
31
|
+
// use to overwrite the 500 with an empty 404.
|
|
32
|
+
if ("error" in Astro.props || Astro.response.status === 500) {
|
|
33
|
+
return new Response("Internal Server Error", {
|
|
34
|
+
status: 500,
|
|
35
|
+
headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
// Defensive: never let the catch-all answer for first-class route namespaces.
|
|
29
40
|
// (Keeps the commerce boundary hard — a marketing subpage can never shadow a
|
|
30
41
|
// product/collection route.)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.11",
|
|
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",
|