@tokenoftrust/storefront-runner 7.6.8 → 7.6.10
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/apps/storefront/src/lib/access/auth/agentRoles.ts +1 -0
- package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +10 -2
- package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +5 -1
- 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/package.json +1 -1
|
@@ -13,6 +13,7 @@ export type { AgentRoleId };
|
|
|
13
13
|
export const PREVIEW_VIEW_ROLE = "preview:view" as const satisfies AgentRoleId;
|
|
14
14
|
export const ADMIN_READ_ROLE = "admin:read" as const satisfies AgentRoleId;
|
|
15
15
|
export const ORDERS_FULFIL_BY_ID_ROLE = "orders:fulfil-by-id" as const satisfies AgentRoleId;
|
|
16
|
+
export const ORDERS_READ_HOLDS_ROLE = "orders:read-holds" as const satisfies AgentRoleId;
|
|
16
17
|
|
|
17
18
|
/** True when the catalog permits the role and the grant names it exactly. */
|
|
18
19
|
export function agentHoldsRole(roles: readonly string[] | null | undefined, role: CatalogCapabilityId): boolean {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* - the ROLE-GATED routes in {@link AGENT_ROLE_ROUTES}, each only while the agent's
|
|
15
15
|
* grant roles name that route's role: the PII-blind order reads (`admin:read`) and
|
|
16
16
|
* the fulfil-by-id operation (`orders:fulfil-by-id`, which tot20 still decides per
|
|
17
|
-
* call), the
|
|
17
|
+
* call), the hold-reasons read (`orders:read-holds`, rechecked by tot20 on every page),
|
|
18
|
+
* the stock levels and movement history reads, and the supplier and purchase
|
|
18
19
|
* order reads (`admin:read`). Those handlers project an agent's view; the gate only
|
|
19
20
|
* admits. No purchasing write is reachable: an agent never creates, sends or receives
|
|
20
21
|
* a purchase order through a route.
|
|
@@ -28,7 +29,13 @@
|
|
|
28
29
|
*/
|
|
29
30
|
import type { SessionRecord } from "./session.js";
|
|
30
31
|
import { isAgentSession } from "./session.js";
|
|
31
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
ADMIN_READ_ROLE,
|
|
34
|
+
agentHoldsRole,
|
|
35
|
+
ORDERS_FULFIL_BY_ID_ROLE,
|
|
36
|
+
ORDERS_READ_HOLDS_ROLE,
|
|
37
|
+
type AgentRoleId,
|
|
38
|
+
} from "./agentRoles.js";
|
|
32
39
|
|
|
33
40
|
/** Exact non-content routes an agent session may reach, by method. */
|
|
34
41
|
export const AGENT_ALLOWED_ROUTES: ReadonlyArray<{ method: string; path: string }> = [
|
|
@@ -53,6 +60,7 @@ export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; ro
|
|
|
53
60
|
{ method: "GET", path: "/api/admin/purchasing/orders", role: ADMIN_READ_ROLE },
|
|
54
61
|
{ method: "GET", path: "/api/admin/purchasing/orders/:id", role: ADMIN_READ_ROLE },
|
|
55
62
|
{ method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
|
|
63
|
+
{ method: "GET", path: "/api/admin/hold-reasons", role: ORDERS_READ_HOLDS_ROLE },
|
|
56
64
|
];
|
|
57
65
|
|
|
58
66
|
function routeMatches(pattern: string, path: string): boolean {
|
|
@@ -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:
|
|
8
|
+
export const CAPABILITY_CATALOG_DIGEST = "sha256:ad601b987e2dc989aeaae1315d451cbce5d9b824393eebba409aa36fee1e2089" as const;
|
|
9
9
|
|
|
10
10
|
/** Every capability row id the catalog names. */
|
|
11
11
|
export const CATALOG_CAPABILITY_IDS = [
|
|
@@ -79,6 +79,7 @@ export const CATALOG_CAPABILITY_IDS = [
|
|
|
79
79
|
"message:send-status",
|
|
80
80
|
"orders:fulfil-by-id",
|
|
81
81
|
"orders:read-customer",
|
|
82
|
+
"orders:read-holds",
|
|
82
83
|
"orders:read-minimal",
|
|
83
84
|
"orders:read-recipient",
|
|
84
85
|
"orders:webhook",
|
|
@@ -127,6 +128,7 @@ export type CatalogBundleName = (typeof CATALOG_BUNDLE_NAMES)[number];
|
|
|
127
128
|
export const AGENT_ROLE_IDS = [
|
|
128
129
|
"admin:read",
|
|
129
130
|
"orders:fulfil-by-id",
|
|
131
|
+
"orders:read-holds",
|
|
130
132
|
"preview:view",
|
|
131
133
|
] as const satisfies readonly CatalogCapabilityId[];
|
|
132
134
|
export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
|
|
@@ -140,6 +142,7 @@ export const APP_AUDIENCE_CAPABILITY_IDS = [
|
|
|
140
142
|
"inventory:read",
|
|
141
143
|
"inventory:write",
|
|
142
144
|
"message:send-status",
|
|
145
|
+
"orders:read-holds",
|
|
143
146
|
"orders:read-minimal",
|
|
144
147
|
"orders:read-recipient",
|
|
145
148
|
"orders:webhook",
|
|
@@ -158,6 +161,7 @@ export const PRIVATE_APP_SCOPE_IDS = [
|
|
|
158
161
|
"fulfillment:process",
|
|
159
162
|
"inventory:read",
|
|
160
163
|
"inventory:write",
|
|
164
|
+
"orders:read-holds",
|
|
161
165
|
"orders:read-minimal",
|
|
162
166
|
"orders:read-recipient",
|
|
163
167
|
"orders:webhook",
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.10",
|
|
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",
|