@tokenoftrust/storefront-runner 7.6.3 → 7.6.5
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 +9 -9
- package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +4 -1
- package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +3 -4
- package/apps/storefront/src/lib/inventory/mirrorStock.ts +14 -3
- package/package.json +1 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* role through these constants, never as a string literal (`agentRoles.test.ts` scans
|
|
5
|
-
* the tree for one).
|
|
2
|
+
* Capability names used by the sponsored-agent routes and store entry. A grant can
|
|
3
|
+
* satisfy a role check only when the generated catalog marks that role as holdable.
|
|
6
4
|
*
|
|
7
5
|
* The roles an agent session carries (`actor.roles`) only NARROW what it may reach; they
|
|
8
6
|
* never unlock anything locally. Customer PII in particular stays projected away for an
|
|
9
7
|
* agent whatever its roles say, and `orders:fulfil-by-id` still asks tot20 per operation.
|
|
10
8
|
*/
|
|
11
|
-
import {
|
|
9
|
+
import { isAgentRoleId, type AgentRoleId, type CatalogCapabilityId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
|
|
12
10
|
|
|
13
11
|
export type { AgentRoleId };
|
|
14
12
|
|
|
15
|
-
export const
|
|
13
|
+
export const PREVIEW_VIEW_ROLE = "preview:view" as const satisfies AgentRoleId;
|
|
14
|
+
export const ADMIN_READ_ROLE = "admin:read" as const satisfies AgentRoleId;
|
|
15
|
+
export const ORDERS_FULFIL_BY_ID_ROLE = "orders:fulfil-by-id" as const satisfies AgentRoleId;
|
|
16
16
|
|
|
17
|
-
/** True when
|
|
18
|
-
export function agentHoldsRole(roles: readonly string[] | null | undefined, role:
|
|
19
|
-
return Array.isArray(roles) && roles.includes(role);
|
|
17
|
+
/** True when the catalog permits the role and the grant names it exactly. */
|
|
18
|
+
export function agentHoldsRole(roles: readonly string[] | null | undefined, role: CatalogCapabilityId): boolean {
|
|
19
|
+
return isAgentRoleId(role) && Array.isArray(roles) && roles.includes(role);
|
|
20
20
|
}
|
|
@@ -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)
|
|
17
|
+
* call), and the stock levels and movement history reads (`admin:read`). Those
|
|
18
|
+
* handlers project an agent's view; the gate only admits.
|
|
18
19
|
*
|
|
19
20
|
* Everything else — every other `/api` route (so no derived credential such as the
|
|
20
21
|
* CLI sign-in code or the activity-ingest token), `/admin`, `/cockpit`, `/dev`,
|
|
@@ -41,6 +42,8 @@ export const AGENT_ALLOWED_ROUTES: ReadonlyArray<{ method: string; path: string
|
|
|
41
42
|
export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; role: AgentRoleId }> = [
|
|
42
43
|
{ method: "GET", path: "/api/admin/orders", role: ADMIN_READ_ROLE },
|
|
43
44
|
{ method: "GET", path: "/api/admin/orders/:id", role: ADMIN_READ_ROLE },
|
|
45
|
+
{ method: "GET", path: "/api/admin/inventory/levels", role: ADMIN_READ_ROLE },
|
|
46
|
+
{ method: "GET", path: "/api/admin/inventory/history", role: ADMIN_READ_ROLE },
|
|
44
47
|
{ method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
|
|
45
48
|
];
|
|
46
49
|
|
|
@@ -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:0683a9f2312c22c53fd995e5b8f90929b8887251d5fc47300f82776801203a39" as const;
|
|
9
9
|
|
|
10
10
|
/** Every capability row id the catalog names. */
|
|
11
11
|
export const CATALOG_CAPABILITY_IDS = [
|
|
@@ -110,12 +110,11 @@ export const CATALOG_BUNDLE_NAMES = [
|
|
|
110
110
|
] as const;
|
|
111
111
|
export type CatalogBundleName = (typeof CATALOG_BUNDLE_NAMES)[number];
|
|
112
112
|
|
|
113
|
-
/**
|
|
113
|
+
/** Capability rows marked holdable by sponsored agents in the catalog. */
|
|
114
114
|
export const AGENT_ROLE_IDS = [
|
|
115
|
-
"preview:view",
|
|
116
115
|
"admin:read",
|
|
117
116
|
"orders:fulfil-by-id",
|
|
118
|
-
"
|
|
117
|
+
"preview:view",
|
|
119
118
|
] as const satisfies readonly CatalogCapabilityId[];
|
|
120
119
|
export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
|
|
121
120
|
|
|
@@ -1006,19 +1006,30 @@ export async function importSourceOnHand(
|
|
|
1006
1006
|
input: {
|
|
1007
1007
|
tenantId: string;
|
|
1008
1008
|
stage: CommerceStage;
|
|
1009
|
-
lines: readonly { sku: string; onHand: number }[];
|
|
1009
|
+
lines: readonly { sku: string; onHand: number; locationId?: string }[];
|
|
1010
1010
|
runId: string;
|
|
1011
1011
|
asOf: string;
|
|
1012
1012
|
},
|
|
1013
1013
|
): Promise<void> {
|
|
1014
1014
|
for (const line of input.lines) {
|
|
1015
|
+
const locationId = line.locationId ?? MIRROR_LOCATION_UNSPECIFIED;
|
|
1016
|
+
if (!(await mirrorLocationKnown(db, { tenantId: input.tenantId, stage: input.stage, locationId }))) {
|
|
1017
|
+
throw new InventoryMovementError("invalid-movement");
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
for (const line of input.lines) {
|
|
1021
|
+
const locationId = line.locationId ?? MIRROR_LOCATION_UNSPECIFIED;
|
|
1015
1022
|
await appendSourceOnHand(db, {
|
|
1016
1023
|
tenantId: input.tenantId,
|
|
1017
1024
|
stage: input.stage,
|
|
1018
1025
|
sku: line.sku,
|
|
1019
|
-
locationId
|
|
1026
|
+
locationId,
|
|
1020
1027
|
source: CATALOG_IMPORT_SOURCE,
|
|
1021
|
-
sourceEventId: await catalogImportEventId(
|
|
1028
|
+
sourceEventId: await catalogImportEventId(
|
|
1029
|
+
input.runId,
|
|
1030
|
+
locationId === MIRROR_LOCATION_UNSPECIFIED ? line.sku : `${line.sku}.${locationId}`,
|
|
1031
|
+
line.onHand,
|
|
1032
|
+
),
|
|
1022
1033
|
onHand: line.onHand,
|
|
1023
1034
|
asOf: input.asOf,
|
|
1024
1035
|
actorId: CATALOG_IMPORT_ACTOR_ID,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.5",
|
|
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",
|