@agent-score/commerce 1.0.1 → 1.0.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.
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/identity/express.js +1 -1
- package/dist/identity/express.mjs +1 -1
- package/dist/identity/fastify.js +1 -1
- package/dist/identity/fastify.mjs +1 -1
- package/dist/identity/hono.js +1 -1
- package/dist/identity/hono.mjs +1 -1
- package/dist/identity/nextjs.js +1 -1
- package/dist/identity/nextjs.mjs +1 -1
- package/dist/identity/policy.d.mts +1 -2
- package/dist/identity/policy.d.ts +1 -2
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.js +1 -1
- package/dist/identity/web.mjs +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/stripe-multichain/index.d.mts +3 -3
- package/dist/stripe-multichain/index.d.ts +3 -3
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/core.js
CHANGED
|
@@ -164,7 +164,7 @@ function createAgentScoreCore(options) {
|
|
|
164
164
|
} = options;
|
|
165
165
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
166
166
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
167
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
167
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
168
168
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
169
169
|
const API_TIMEOUT_MS = 1e4;
|
|
170
170
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/core.mjs
CHANGED
|
@@ -137,7 +137,7 @@ function createAgentScoreCore(options) {
|
|
|
137
137
|
} = options;
|
|
138
138
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
139
139
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
140
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
140
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
141
141
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
142
142
|
const API_TIMEOUT_MS = 1e4;
|
|
143
143
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/express.js
CHANGED
|
@@ -344,7 +344,7 @@ function createAgentScoreCore(options) {
|
|
|
344
344
|
} = options;
|
|
345
345
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
346
346
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
347
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
347
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
348
348
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
349
349
|
const API_TIMEOUT_MS = 1e4;
|
|
350
350
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
|
@@ -306,7 +306,7 @@ function createAgentScoreCore(options) {
|
|
|
306
306
|
} = options;
|
|
307
307
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
308
308
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
309
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
309
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
310
310
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
311
311
|
const API_TIMEOUT_MS = 1e4;
|
|
312
312
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/fastify.js
CHANGED
|
@@ -345,7 +345,7 @@ function createAgentScoreCore(options) {
|
|
|
345
345
|
} = options;
|
|
346
346
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
347
347
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
348
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
348
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
349
349
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
350
350
|
const API_TIMEOUT_MS = 1e4;
|
|
351
351
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
|
@@ -306,7 +306,7 @@ function createAgentScoreCore(options) {
|
|
|
306
306
|
} = options;
|
|
307
307
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
308
308
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
309
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
309
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
310
310
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
311
311
|
const API_TIMEOUT_MS = 1e4;
|
|
312
312
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/hono.js
CHANGED
|
@@ -344,7 +344,7 @@ function createAgentScoreCore(options) {
|
|
|
344
344
|
} = options;
|
|
345
345
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
346
346
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
347
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
347
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
348
348
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
349
349
|
const API_TIMEOUT_MS = 1e4;
|
|
350
350
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/hono.mjs
CHANGED
|
@@ -306,7 +306,7 @@ function createAgentScoreCore(options) {
|
|
|
306
306
|
} = options;
|
|
307
307
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
308
308
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
309
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
309
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
310
310
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
311
311
|
const API_TIMEOUT_MS = 1e4;
|
|
312
312
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/nextjs.js
CHANGED
|
@@ -342,7 +342,7 @@ function createAgentScoreCore(options) {
|
|
|
342
342
|
} = options;
|
|
343
343
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
344
344
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
345
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
345
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
346
346
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
347
347
|
const API_TIMEOUT_MS = 1e4;
|
|
348
348
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/nextjs.mjs
CHANGED
|
@@ -306,7 +306,7 @@ function createAgentScoreCore(options) {
|
|
|
306
306
|
} = options;
|
|
307
307
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
308
308
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
309
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
309
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
310
310
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
311
311
|
const API_TIMEOUT_MS = 1e4;
|
|
312
312
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
|
@@ -27,8 +27,7 @@ import { DenialReason, AgentScoreCoreOptions } from '../core.mjs';
|
|
|
27
27
|
* {@link GateResult} so the vendor decides how to surface it.
|
|
28
28
|
*
|
|
29
29
|
* All three are additive — vendors using `agentscoreGate(...)` directly are
|
|
30
|
-
* unaffected.
|
|
31
|
-
* `store/routes/purchase.py` (Python sibling) for the full per-request flow.
|
|
30
|
+
* unaffected.
|
|
32
31
|
*/
|
|
33
32
|
|
|
34
33
|
/** Hard = 403 propagates; soft = swallowed + identity_status="unverified". */
|
|
@@ -27,8 +27,7 @@ import { DenialReason, AgentScoreCoreOptions } from '../core.js';
|
|
|
27
27
|
* {@link GateResult} so the vendor decides how to surface it.
|
|
28
28
|
*
|
|
29
29
|
* All three are additive — vendors using `agentscoreGate(...)` directly are
|
|
30
|
-
* unaffected.
|
|
31
|
-
* `store/routes/purchase.py` (Python sibling) for the full per-request flow.
|
|
30
|
+
* unaffected.
|
|
32
31
|
*/
|
|
33
32
|
|
|
34
33
|
/** Hard = 403 propagates; soft = swallowed + identity_status="unverified". */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/identity/policy.ts"],"sourcesContent":["/**\n * Per-product / per-tier compliance policy helpers.\n *\n * A *policy* is a small bag of fields describing what identity the merchant wants\n * verified for a given resource:\n *\n * - `enforcement`: `\"hard\"` (today's wine path — 403 on miss) or `\"soft\"` (gate\n * denial is swallowed; the order completes with a degraded `identity_status`).\n * `null` / absent = no gate at all.\n * - `requireKyc` / `requireSanctionsClear` / `minAge`: passed through to the\n * per-framework `agentscoreGate(...)` factory.\n * - `allowedJurisdictions`: buyer-verified country list (`[\"US\", \"CA\", ...]`).\n * - `allowedShippingCountries` / `allowedShippingStates`: optional shipping\n * allowlists. State list is only enforced for US shipments.\n *\n * This module ships three primitives:\n *\n * 1. {@link PolicyBlock} — the typed shape.\n * 2. {@link policyToGateOptions} — translate a block into the options object the\n * per-framework `agentscoreGate(...)` accepts. Returns `null` when the policy\n * has no enforcement (treat as \"no gate; anonymous OK\").\n * 3. {@link runGateWithEnforcement} — wrap a per-framework middleware in the\n * hard/soft enforcement runner. The middleware is given an `onDenied` shim\n * that captures the denial body and status; the runner returns a structured\n * {@link GateResult} so the vendor decides how to surface it.\n *\n * All three are additive — vendors using `agentscoreGate(...)` directly are\n * unaffected
|
|
1
|
+
{"version":3,"sources":["../../src/identity/policy.ts"],"sourcesContent":["/**\n * Per-product / per-tier compliance policy helpers.\n *\n * A *policy* is a small bag of fields describing what identity the merchant wants\n * verified for a given resource:\n *\n * - `enforcement`: `\"hard\"` (today's wine path — 403 on miss) or `\"soft\"` (gate\n * denial is swallowed; the order completes with a degraded `identity_status`).\n * `null` / absent = no gate at all.\n * - `requireKyc` / `requireSanctionsClear` / `minAge`: passed through to the\n * per-framework `agentscoreGate(...)` factory.\n * - `allowedJurisdictions`: buyer-verified country list (`[\"US\", \"CA\", ...]`).\n * - `allowedShippingCountries` / `allowedShippingStates`: optional shipping\n * allowlists. State list is only enforced for US shipments.\n *\n * This module ships three primitives:\n *\n * 1. {@link PolicyBlock} — the typed shape.\n * 2. {@link policyToGateOptions} — translate a block into the options object the\n * per-framework `agentscoreGate(...)` accepts. Returns `null` when the policy\n * has no enforcement (treat as \"no gate; anonymous OK\").\n * 3. {@link runGateWithEnforcement} — wrap a per-framework middleware in the\n * hard/soft enforcement runner. The middleware is given an `onDenied` shim\n * that captures the denial body and status; the runner returns a structured\n * {@link GateResult} so the vendor decides how to surface it.\n *\n * All three are additive — vendors using `agentscoreGate(...)` directly are\n * unaffected.\n */\n\nimport type { AgentScoreCoreOptions, DenialReason } from '../core.js';\n\n/** Hard = 403 propagates; soft = swallowed + identity_status=\"unverified\". */\nexport type EnforcementMode = 'hard' | 'soft';\n\n/** Per-order trust level captured at settle time. */\nexport type IdentityStatus = 'verified' | 'unverified' | 'anonymous' | 'denied';\n\n/** Compliance fields a merchant attaches per product / per tier. All optional. */\nexport interface PolicyBlock {\n enforcement?: EnforcementMode;\n requireKyc?: boolean;\n requireSanctionsClear?: boolean;\n minAge?: number;\n allowedJurisdictions?: readonly string[];\n allowedShippingCountries?: readonly string[];\n allowedShippingStates?: readonly string[];\n}\n\n/**\n * Outcome of running a gate under an enforcement mode.\n *\n * - `verified`: gate accepted; identity is fully verified for the policy.\n * - `unverified`: soft mode swallowed a gate denial; the agent had *some*\n * identity but didn't meet the policy. Stamp this on the order so\n * ops/analytics can tell apart soft passes from hard passes.\n * - `anonymous`: no gate ran (policy was null / no enforcement).\n * - `denied`: hard mode rejected; the caller must propagate the 403. The\n * `denialBody` and `denialStatus` carry the original gate response so the\n * caller can return it as-is.\n */\nexport interface GateResult {\n status: IdentityStatus;\n denialStatus?: number;\n denialBody?: Record<string, unknown>;\n denialReason?: DenialReason;\n}\n\n/**\n * Translate a {@link PolicyBlock} into the options the per-framework\n * `agentscoreGate(...)` expects. Returns `null` when the block has no\n * `enforcement` set — the caller should treat that as \"no gate; anonymous OK\".\n *\n * Use a fresh gate per request rather than constructing once at module scope\n * when the policy varies per resource (e.g. per product). Each adapter's gate\n * is cheap to instantiate.\n */\nexport function policyToGateOptions(\n policy: PolicyBlock | null | undefined,\n base: { apiKey: string; baseUrl?: string },\n): AgentScoreCoreOptions | null {\n if (!policy || !policy.enforcement) return null;\n return {\n apiKey: base.apiKey,\n ...(base.baseUrl !== undefined && { baseUrl: base.baseUrl }),\n ...(policy.requireKyc !== undefined && { requireKyc: policy.requireKyc }),\n ...(policy.requireSanctionsClear !== undefined && {\n requireSanctionsClear: policy.requireSanctionsClear,\n }),\n ...(policy.minAge !== undefined && { minAge: policy.minAge }),\n ...(policy.allowedJurisdictions !== undefined && {\n allowedJurisdictions: [...policy.allowedJurisdictions],\n }),\n };\n}\n\n/**\n * Run a per-framework gate middleware respecting the enforcement mode.\n *\n * The vendor passes:\n * - `gate`: their framework's middleware (Hono `MiddlewareHandler`, Express\n * `(req, res, next) => void`, etc.) — anything that resolves on accept and\n * throws or returns a `Response` on deny.\n * - `runGate`: a thin adapter that calls the middleware with the framework\n * context and returns either `{ ok: true }` (gate accepted) or\n * `{ ok: false, status, body, reason? }` (gate denied with details).\n *\n * `runGateWithEnforcement` wraps that in the hard/soft split:\n *\n * - `gate=null` or `enforcement=null`: no gate fires; status=\"anonymous\".\n * - `enforcement=\"hard\"` + denied: status=\"denied\"; caller propagates denialStatus + denialBody.\n * - `enforcement=\"soft\"` + denied: swallow; status=\"unverified\".\n * - accepted: status=\"verified\".\n */\nexport async function runGateWithEnforcement(\n enforcement: EnforcementMode | undefined,\n runGate: (() => Promise<{ ok: true } | { ok: false; status: number; body: Record<string, unknown>; reason?: DenialReason }>) | null,\n): Promise<GateResult> {\n if (!runGate || !enforcement) return { status: 'anonymous' };\n\n const outcome = await runGate();\n if (outcome.ok) return { status: 'verified' };\n\n if (enforcement === 'hard') {\n return {\n status: 'denied',\n denialStatus: outcome.status,\n denialBody: outcome.body,\n ...(outcome.reason !== undefined && { denialReason: outcome.reason }),\n };\n }\n return {\n status: 'unverified',\n denialStatus: outcome.status,\n denialBody: outcome.body,\n ...(outcome.reason !== undefined && { denialReason: outcome.reason }),\n };\n}\n\n/** NULL policy / NULL allowlist → ship anywhere. Otherwise country must be in the list. */\nexport function shippingCountryAllowed(country: string, policy: PolicyBlock | null | undefined): boolean {\n if (!policy?.allowedShippingCountries || policy.allowedShippingCountries.length === 0) return true;\n const allowed = new Set(policy.allowedShippingCountries.map((c) => c.toUpperCase()));\n return allowed.has(country.toUpperCase());\n}\n\n/**\n * US-state allowlist (e.g. wine).\n *\n * Only enforced for US shipments — non-US shipments are governed by\n * {@link shippingCountryAllowed} independently.\n */\nexport function shippingStateAllowed(\n state: string,\n country: string,\n policy: PolicyBlock | null | undefined,\n): boolean {\n if (!policy?.allowedShippingStates || policy.allowedShippingStates.length === 0) return true;\n if (country.toUpperCase() !== 'US') return true;\n const allowed = new Set(policy.allowedShippingStates.map((s) => s.toUpperCase()));\n return allowed.has(state.toUpperCase());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EO,SAAS,oBACd,QACA,MAC8B;AAC9B,MAAI,CAAC,UAAU,CAAC,OAAO,YAAa,QAAO;AAC3C,SAAO;AAAA,IACL,QAAQ,KAAK;AAAA,IACb,GAAI,KAAK,YAAY,UAAa,EAAE,SAAS,KAAK,QAAQ;AAAA,IAC1D,GAAI,OAAO,eAAe,UAAa,EAAE,YAAY,OAAO,WAAW;AAAA,IACvE,GAAI,OAAO,0BAA0B,UAAa;AAAA,MAChD,uBAAuB,OAAO;AAAA,IAChC;AAAA,IACA,GAAI,OAAO,WAAW,UAAa,EAAE,QAAQ,OAAO,OAAO;AAAA,IAC3D,GAAI,OAAO,yBAAyB,UAAa;AAAA,MAC/C,sBAAsB,CAAC,GAAG,OAAO,oBAAoB;AAAA,IACvD;AAAA,EACF;AACF;AAoBA,eAAsB,uBACpB,aACA,SACqB;AACrB,MAAI,CAAC,WAAW,CAAC,YAAa,QAAO,EAAE,QAAQ,YAAY;AAE3D,QAAM,UAAU,MAAM,QAAQ;AAC9B,MAAI,QAAQ,GAAI,QAAO,EAAE,QAAQ,WAAW;AAE5C,MAAI,gBAAgB,QAAQ;AAC1B,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,cAAc,QAAQ;AAAA,MACtB,YAAY,QAAQ;AAAA,MACpB,GAAI,QAAQ,WAAW,UAAa,EAAE,cAAc,QAAQ,OAAO;AAAA,IACrE;AAAA,EACF;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,cAAc,QAAQ;AAAA,IACtB,YAAY,QAAQ;AAAA,IACpB,GAAI,QAAQ,WAAW,UAAa,EAAE,cAAc,QAAQ,OAAO;AAAA,EACrE;AACF;AAGO,SAAS,uBAAuB,SAAiB,QAAiD;AACvG,MAAI,CAAC,QAAQ,4BAA4B,OAAO,yBAAyB,WAAW,EAAG,QAAO;AAC9F,QAAM,UAAU,IAAI,IAAI,OAAO,yBAAyB,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AACnF,SAAO,QAAQ,IAAI,QAAQ,YAAY,CAAC;AAC1C;AAQO,SAAS,qBACd,OACA,SACA,QACS;AACT,MAAI,CAAC,QAAQ,yBAAyB,OAAO,sBAAsB,WAAW,EAAG,QAAO;AACxF,MAAI,QAAQ,YAAY,MAAM,KAAM,QAAO;AAC3C,QAAM,UAAU,IAAI,IAAI,OAAO,sBAAsB,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAChF,SAAO,QAAQ,IAAI,MAAM,YAAY,CAAC;AACxC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/identity/policy.ts"],"sourcesContent":["/**\n * Per-product / per-tier compliance policy helpers.\n *\n * A *policy* is a small bag of fields describing what identity the merchant wants\n * verified for a given resource:\n *\n * - `enforcement`: `\"hard\"` (today's wine path — 403 on miss) or `\"soft\"` (gate\n * denial is swallowed; the order completes with a degraded `identity_status`).\n * `null` / absent = no gate at all.\n * - `requireKyc` / `requireSanctionsClear` / `minAge`: passed through to the\n * per-framework `agentscoreGate(...)` factory.\n * - `allowedJurisdictions`: buyer-verified country list (`[\"US\", \"CA\", ...]`).\n * - `allowedShippingCountries` / `allowedShippingStates`: optional shipping\n * allowlists. State list is only enforced for US shipments.\n *\n * This module ships three primitives:\n *\n * 1. {@link PolicyBlock} — the typed shape.\n * 2. {@link policyToGateOptions} — translate a block into the options object the\n * per-framework `agentscoreGate(...)` accepts. Returns `null` when the policy\n * has no enforcement (treat as \"no gate; anonymous OK\").\n * 3. {@link runGateWithEnforcement} — wrap a per-framework middleware in the\n * hard/soft enforcement runner. The middleware is given an `onDenied` shim\n * that captures the denial body and status; the runner returns a structured\n * {@link GateResult} so the vendor decides how to surface it.\n *\n * All three are additive — vendors using `agentscoreGate(...)` directly are\n * unaffected
|
|
1
|
+
{"version":3,"sources":["../../src/identity/policy.ts"],"sourcesContent":["/**\n * Per-product / per-tier compliance policy helpers.\n *\n * A *policy* is a small bag of fields describing what identity the merchant wants\n * verified for a given resource:\n *\n * - `enforcement`: `\"hard\"` (today's wine path — 403 on miss) or `\"soft\"` (gate\n * denial is swallowed; the order completes with a degraded `identity_status`).\n * `null` / absent = no gate at all.\n * - `requireKyc` / `requireSanctionsClear` / `minAge`: passed through to the\n * per-framework `agentscoreGate(...)` factory.\n * - `allowedJurisdictions`: buyer-verified country list (`[\"US\", \"CA\", ...]`).\n * - `allowedShippingCountries` / `allowedShippingStates`: optional shipping\n * allowlists. State list is only enforced for US shipments.\n *\n * This module ships three primitives:\n *\n * 1. {@link PolicyBlock} — the typed shape.\n * 2. {@link policyToGateOptions} — translate a block into the options object the\n * per-framework `agentscoreGate(...)` accepts. Returns `null` when the policy\n * has no enforcement (treat as \"no gate; anonymous OK\").\n * 3. {@link runGateWithEnforcement} — wrap a per-framework middleware in the\n * hard/soft enforcement runner. The middleware is given an `onDenied` shim\n * that captures the denial body and status; the runner returns a structured\n * {@link GateResult} so the vendor decides how to surface it.\n *\n * All three are additive — vendors using `agentscoreGate(...)` directly are\n * unaffected.\n */\n\nimport type { AgentScoreCoreOptions, DenialReason } from '../core.js';\n\n/** Hard = 403 propagates; soft = swallowed + identity_status=\"unverified\". */\nexport type EnforcementMode = 'hard' | 'soft';\n\n/** Per-order trust level captured at settle time. */\nexport type IdentityStatus = 'verified' | 'unverified' | 'anonymous' | 'denied';\n\n/** Compliance fields a merchant attaches per product / per tier. All optional. */\nexport interface PolicyBlock {\n enforcement?: EnforcementMode;\n requireKyc?: boolean;\n requireSanctionsClear?: boolean;\n minAge?: number;\n allowedJurisdictions?: readonly string[];\n allowedShippingCountries?: readonly string[];\n allowedShippingStates?: readonly string[];\n}\n\n/**\n * Outcome of running a gate under an enforcement mode.\n *\n * - `verified`: gate accepted; identity is fully verified for the policy.\n * - `unverified`: soft mode swallowed a gate denial; the agent had *some*\n * identity but didn't meet the policy. Stamp this on the order so\n * ops/analytics can tell apart soft passes from hard passes.\n * - `anonymous`: no gate ran (policy was null / no enforcement).\n * - `denied`: hard mode rejected; the caller must propagate the 403. The\n * `denialBody` and `denialStatus` carry the original gate response so the\n * caller can return it as-is.\n */\nexport interface GateResult {\n status: IdentityStatus;\n denialStatus?: number;\n denialBody?: Record<string, unknown>;\n denialReason?: DenialReason;\n}\n\n/**\n * Translate a {@link PolicyBlock} into the options the per-framework\n * `agentscoreGate(...)` expects. Returns `null` when the block has no\n * `enforcement` set — the caller should treat that as \"no gate; anonymous OK\".\n *\n * Use a fresh gate per request rather than constructing once at module scope\n * when the policy varies per resource (e.g. per product). Each adapter's gate\n * is cheap to instantiate.\n */\nexport function policyToGateOptions(\n policy: PolicyBlock | null | undefined,\n base: { apiKey: string; baseUrl?: string },\n): AgentScoreCoreOptions | null {\n if (!policy || !policy.enforcement) return null;\n return {\n apiKey: base.apiKey,\n ...(base.baseUrl !== undefined && { baseUrl: base.baseUrl }),\n ...(policy.requireKyc !== undefined && { requireKyc: policy.requireKyc }),\n ...(policy.requireSanctionsClear !== undefined && {\n requireSanctionsClear: policy.requireSanctionsClear,\n }),\n ...(policy.minAge !== undefined && { minAge: policy.minAge }),\n ...(policy.allowedJurisdictions !== undefined && {\n allowedJurisdictions: [...policy.allowedJurisdictions],\n }),\n };\n}\n\n/**\n * Run a per-framework gate middleware respecting the enforcement mode.\n *\n * The vendor passes:\n * - `gate`: their framework's middleware (Hono `MiddlewareHandler`, Express\n * `(req, res, next) => void`, etc.) — anything that resolves on accept and\n * throws or returns a `Response` on deny.\n * - `runGate`: a thin adapter that calls the middleware with the framework\n * context and returns either `{ ok: true }` (gate accepted) or\n * `{ ok: false, status, body, reason? }` (gate denied with details).\n *\n * `runGateWithEnforcement` wraps that in the hard/soft split:\n *\n * - `gate=null` or `enforcement=null`: no gate fires; status=\"anonymous\".\n * - `enforcement=\"hard\"` + denied: status=\"denied\"; caller propagates denialStatus + denialBody.\n * - `enforcement=\"soft\"` + denied: swallow; status=\"unverified\".\n * - accepted: status=\"verified\".\n */\nexport async function runGateWithEnforcement(\n enforcement: EnforcementMode | undefined,\n runGate: (() => Promise<{ ok: true } | { ok: false; status: number; body: Record<string, unknown>; reason?: DenialReason }>) | null,\n): Promise<GateResult> {\n if (!runGate || !enforcement) return { status: 'anonymous' };\n\n const outcome = await runGate();\n if (outcome.ok) return { status: 'verified' };\n\n if (enforcement === 'hard') {\n return {\n status: 'denied',\n denialStatus: outcome.status,\n denialBody: outcome.body,\n ...(outcome.reason !== undefined && { denialReason: outcome.reason }),\n };\n }\n return {\n status: 'unverified',\n denialStatus: outcome.status,\n denialBody: outcome.body,\n ...(outcome.reason !== undefined && { denialReason: outcome.reason }),\n };\n}\n\n/** NULL policy / NULL allowlist → ship anywhere. Otherwise country must be in the list. */\nexport function shippingCountryAllowed(country: string, policy: PolicyBlock | null | undefined): boolean {\n if (!policy?.allowedShippingCountries || policy.allowedShippingCountries.length === 0) return true;\n const allowed = new Set(policy.allowedShippingCountries.map((c) => c.toUpperCase()));\n return allowed.has(country.toUpperCase());\n}\n\n/**\n * US-state allowlist (e.g. wine).\n *\n * Only enforced for US shipments — non-US shipments are governed by\n * {@link shippingCountryAllowed} independently.\n */\nexport function shippingStateAllowed(\n state: string,\n country: string,\n policy: PolicyBlock | null | undefined,\n): boolean {\n if (!policy?.allowedShippingStates || policy.allowedShippingStates.length === 0) return true;\n if (country.toUpperCase() !== 'US') return true;\n const allowed = new Set(policy.allowedShippingStates.map((s) => s.toUpperCase()));\n return allowed.has(state.toUpperCase());\n}\n"],"mappings":";AA6EO,SAAS,oBACd,QACA,MAC8B;AAC9B,MAAI,CAAC,UAAU,CAAC,OAAO,YAAa,QAAO;AAC3C,SAAO;AAAA,IACL,QAAQ,KAAK;AAAA,IACb,GAAI,KAAK,YAAY,UAAa,EAAE,SAAS,KAAK,QAAQ;AAAA,IAC1D,GAAI,OAAO,eAAe,UAAa,EAAE,YAAY,OAAO,WAAW;AAAA,IACvE,GAAI,OAAO,0BAA0B,UAAa;AAAA,MAChD,uBAAuB,OAAO;AAAA,IAChC;AAAA,IACA,GAAI,OAAO,WAAW,UAAa,EAAE,QAAQ,OAAO,OAAO;AAAA,IAC3D,GAAI,OAAO,yBAAyB,UAAa;AAAA,MAC/C,sBAAsB,CAAC,GAAG,OAAO,oBAAoB;AAAA,IACvD;AAAA,EACF;AACF;AAoBA,eAAsB,uBACpB,aACA,SACqB;AACrB,MAAI,CAAC,WAAW,CAAC,YAAa,QAAO,EAAE,QAAQ,YAAY;AAE3D,QAAM,UAAU,MAAM,QAAQ;AAC9B,MAAI,QAAQ,GAAI,QAAO,EAAE,QAAQ,WAAW;AAE5C,MAAI,gBAAgB,QAAQ;AAC1B,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,cAAc,QAAQ;AAAA,MACtB,YAAY,QAAQ;AAAA,MACpB,GAAI,QAAQ,WAAW,UAAa,EAAE,cAAc,QAAQ,OAAO;AAAA,IACrE;AAAA,EACF;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,cAAc,QAAQ;AAAA,IACtB,YAAY,QAAQ;AAAA,IACpB,GAAI,QAAQ,WAAW,UAAa,EAAE,cAAc,QAAQ,OAAO;AAAA,EACrE;AACF;AAGO,SAAS,uBAAuB,SAAiB,QAAiD;AACvG,MAAI,CAAC,QAAQ,4BAA4B,OAAO,yBAAyB,WAAW,EAAG,QAAO;AAC9F,QAAM,UAAU,IAAI,IAAI,OAAO,yBAAyB,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AACnF,SAAO,QAAQ,IAAI,QAAQ,YAAY,CAAC;AAC1C;AAQO,SAAS,qBACd,OACA,SACA,QACS;AACT,MAAI,CAAC,QAAQ,yBAAyB,OAAO,sBAAsB,WAAW,EAAG,QAAO;AACxF,MAAI,QAAQ,YAAY,MAAM,KAAM,QAAO;AAC3C,QAAM,UAAU,IAAI,IAAI,OAAO,sBAAsB,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAChF,SAAO,QAAQ,IAAI,MAAM,YAAY,CAAC;AACxC;","names":[]}
|
package/dist/identity/web.js
CHANGED
|
@@ -342,7 +342,7 @@ function createAgentScoreCore(options) {
|
|
|
342
342
|
} = options;
|
|
343
343
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
344
344
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
345
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
345
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
346
346
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
347
347
|
const API_TIMEOUT_MS = 1e4;
|
|
348
348
|
const cache = new TTLCache(cacheSeconds * 1e3);
|
package/dist/identity/web.mjs
CHANGED
|
@@ -306,7 +306,7 @@ function createAgentScoreCore(options) {
|
|
|
306
306
|
} = options;
|
|
307
307
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
308
308
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
309
|
-
const defaultUa = `@agent-score/commerce@${"1.0.
|
|
309
|
+
const defaultUa = `@agent-score/commerce@${"1.0.2"}`;
|
|
310
310
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
311
311
|
const API_TIMEOUT_MS = 1e4;
|
|
312
312
|
const cache = new TTLCache(cacheSeconds * 1e3);
|