@vorim/sdk 3.6.3 → 3.7.0
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/CHANGELOG.md +21 -0
- package/dist/index.cjs +7 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/siem.cjs +1 -1
- package/dist/integrations/siem.cjs.map +1 -1
- package/dist/integrations/siem.js +1 -1
- package/dist/integrations/siem.js.map +1 -1
- package/dist/integrations/ucp.cjs +224 -0
- package/dist/integrations/ucp.cjs.map +1 -0
- package/dist/integrations/ucp.d.cts +102 -0
- package/dist/integrations/ucp.d.ts +102 -0
- package/dist/integrations/ucp.js +198 -0
- package/dist/integrations/ucp.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/ucp.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Universal Commerce Protocol (UCP) Integration\n//\n// UCP is Google's open agentic-commerce protocol (announced Jan 2026, NRF). It\n// standardises how an AI agent transacts with a merchant across the shopping\n// journey — discovery, checkout, payment (via AP2), and order management — over\n// REST / JSON-RPC, with A2A and MCP bindings.\n//\n// What UCP does NOT answer is the question Vorim exists to answer: *which* agent\n// is this, is it *allowed* to spend on this merchant for this amount, and can you\n// produce a tamper-evident record of what it bought that a counterparty can\n// verify independently. This integration adds exactly that layer around the UCP\n// commerce lifecycle.\n//\n// Design note: this wrapper is deliberately agnostic about UCP's internal wire\n// payloads. It operates on the commerce facts Vorim needs — agent id, merchant,\n// amount, currency, and an opaque UCP order/checkout reference — so it stays\n// correct as the UCP schema evolves. It does not invent UCP field names; the\n// caller passes the UCP order id it already holds. Where it does touch\n// UCP-specific vocabulary (the checkout-session status values and the\n// `ap2_mandate` extension's `checkout_mandate`), it matches the UCP spec,\n// version 2026-04-08. Spec: https://ucp.dev/latest/specification/overview/\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimUCP } from '@vorim/sdk/integrations/ucp';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const ucp = createVorimUCP(vorim, { minTrustScore: 60 });\n//\n// // Before an agent initiates a UCP checkout:\n// const auth = await ucp.authorizePurchase({\n// agentId: 'agid_abc123',\n// merchant: 'acme-store',\n// amount: 4999,\n// currency: 'usd',\n// });\n// if (!auth.authorized) throw new Error(auth.reason);\n//\n// // ...run the UCP checkout, then record the signed audit trail:\n// await ucp.logOrderPlaced('agid_abc123', ucpOrderId, 'acme-store', 4999);\n// await ucp.logOrderFulfilled('agid_abc123', ucpOrderId);\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface UCPConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface PurchaseAuthorizationRequest {\n agentId: string;\n /** UCP merchant / seller identifier the agent is transacting with. */\n merchant?: string;\n /** Amount in the smallest currency unit (e.g. cents), as UCP/AP2 uses. */\n amount?: number;\n currency?: string;\n minTrustScore?: number;\n}\n\nexport interface PurchaseAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimUCP {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n\n constructor(sdk: VorimSDK, config?: Partial<UCPConfig>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n }\n\n /**\n * Verify an agent is authorized to initiate a UCP purchase: it holds the\n * transact scope, is active, and meets the trust-score threshold. Every\n * decision (allow or deny) is recorded as a signed audit event.\n */\n async authorizePurchase(req: PurchaseAuthorizationRequest): Promise<PurchaseAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n\n // 1. Permission: agent must hold the transact scope.\n try {\n const perm = await this.sdk.check(req.agentId, this.requiredScope as any);\n if (!(perm as any).allowed) {\n await this.logEvent(req.agentId, 'ucp.purchase.authorize', 'denied', req, { reason: `Missing ${this.requiredScope}` });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: 0,\n status: 'unknown',\n reason: `Agent does not have ${this.requiredScope} permission`,\n scopeVerified: false,\n };\n }\n } catch (e: any) {\n await this.logEvent(req.agentId, 'ucp.purchase.authorize', 'denied', req, { reason: e.message });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: 0,\n status: 'unknown',\n reason: `Permission check failed: ${e.message}`,\n scopeVerified: false,\n };\n }\n\n // 2. Trust: agent must be active and above the score threshold.\n let score = 0;\n let status = 'unknown';\n try {\n const trust = await this.sdk.verify(req.agentId);\n score = (trust as any).trust_score ?? 0;\n status = (trust as any).status ?? 'unknown';\n } catch {\n // Trust verification failed; treated as not-active below.\n }\n\n if (status !== 'active') {\n await this.logEvent(req.agentId, 'ucp.purchase.authorize', 'denied', req, { reason: `Status: ${status}` });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: score,\n status,\n reason: `Agent is ${status}, not active`,\n scopeVerified: true,\n };\n }\n\n if (score < threshold) {\n await this.logEvent(req.agentId, 'ucp.purchase.authorize', 'denied', req, { reason: `Score ${score} < ${threshold}` });\n return {\n authorized: false,\n agentId: req.agentId,\n trustScore: score,\n status,\n reason: `Trust score ${score} is below minimum ${threshold}`,\n scopeVerified: true,\n };\n }\n\n await this.logEvent(req.agentId, 'ucp.purchase.authorize', 'success', req, { trust_score: score });\n\n return {\n authorized: true,\n agentId: req.agentId,\n trustScore: score,\n status,\n scopeVerified: true,\n };\n }\n\n /**\n * Record the UCP commerce lifecycle as signed, offline-verifiable audit\n * events. The id passed is the UCP checkout-session / order reference the\n * caller already holds (UCP spec 2026-04-08) — Vorim does not parse UCP\n * payloads, it attests to them.\n */\n async logCartCreated(agentId: string, ucpOrderId: string, merchant?: string): Promise<void> {\n await this.logEvent(agentId, 'ucp.cart.created', 'success', { agentId, merchant }, { ucp_order_id: ucpOrderId });\n }\n\n async logOrderPlaced(agentId: string, ucpOrderId: string, merchant?: string, amount?: number): Promise<void> {\n await this.logEvent(agentId, 'ucp.order.placed', 'success', { agentId, merchant, amount }, { ucp_order_id: ucpOrderId });\n }\n\n async logOrderFulfilled(agentId: string, ucpOrderId: string, merchant?: string): Promise<void> {\n await this.logEvent(agentId, 'ucp.order.fulfilled', 'success', { agentId, merchant }, { ucp_order_id: ucpOrderId });\n }\n\n async logOrderCanceled(agentId: string, ucpOrderId: string, reason?: string): Promise<void> {\n await this.logEvent(agentId, 'ucp.order.canceled', 'success', { agentId }, { ucp_order_id: ucpOrderId, cancel_reason: reason });\n }\n\n /**\n * Record the outcome of a UCP checkout-session completion, keyed to the real\n * UCP status vocabulary. The spec's `complete` response carries a status of\n * `completed` | `incomplete` | `requires_escalation` | `error`; this maps it\n * to the audit `result` so an outside party can verify the agent's purchase\n * outcome. `requires_escalation` is recorded as a denial pending human\n * approval — the natural hand-off point for Vorim runtime control.\n */\n async logCheckoutSession(\n agentId: string,\n sessionId: string,\n status: 'completed' | 'incomplete' | 'requires_escalation' | 'error',\n opts?: { merchant?: string; amount?: number },\n ): Promise<void> {\n const result: 'success' | 'denied' | 'error' =\n status === 'completed' ? 'success' : status === 'error' ? 'error' : 'denied';\n await this.logEvent(\n agentId,\n 'ucp.checkout_session.complete',\n result,\n { agentId, merchant: opts?.merchant, amount: opts?.amount },\n { ucp_order_id: sessionId, ucp_status: status },\n );\n }\n\n /**\n * Record the AP2 payment mandate (UCP's `dev.ucp.shopping.ap2_mandate`\n * extension) for an autonomous purchase. The `checkout_mandate` is a signed\n * JWT proof that the agent was authorised to pay; capturing it in the Vorim\n * audit links UCP's own cryptographic payment proof to Vorim's signed,\n * independently-verifiable record of the action.\n */\n async logAp2Mandate(\n agentId: string,\n sessionId: string,\n checkoutMandate: string,\n opts?: { merchant?: string; amount?: number },\n ): Promise<void> {\n await this.logEvent(\n agentId,\n 'ucp.ap2.mandate',\n 'success',\n { agentId, merchant: opts?.merchant, amount: opts?.amount },\n { ucp_order_id: sessionId, ap2_checkout_mandate: checkoutMandate },\n );\n }\n\n /**\n * Express/Connect middleware that gates a UCP checkout endpoint on agent\n * authorization. Expects the agent id in the `x-vorim-agent-id` header\n * (configurable) and the merchant/amount in the request body.\n */\n middleware(options?: { agentIdHeader?: string; minTrustScore?: number }) {\n const header = options?.agentIdHeader ?? 'x-vorim-agent-id';\n const threshold = options?.minTrustScore ?? this.minTrustScore;\n\n return async (req: any, res: any, next: any) => {\n const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || '';\n\n if (!agentId) {\n res.status(401).json({\n error: { code: 'MISSING_AGENT_ID', message: `Agent ID required in ${header} header` },\n });\n return;\n }\n\n const auth = await this.authorizePurchase({\n agentId,\n merchant: req.body?.merchant || req.body?.seller || '',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n minTrustScore: threshold,\n });\n\n if (!auth.authorized) {\n res.status(403).json({\n error: {\n code: 'UNAUTHORIZED_AGENT',\n message: auth.reason || 'Agent not authorized for UCP transactions',\n trust_score: auth.trustScore,\n status: auth.status,\n },\n });\n return;\n }\n\n req.vorimAuthorization = auth;\n next();\n };\n }\n\n private async logEvent(\n agentId: string,\n action: string,\n result: 'success' | 'denied' | 'error',\n req?: any,\n metadata?: Record<string, any>,\n ): Promise<void> {\n try {\n // Canonical audit contract: event_type from the AuditEventType enum\n // ('api_request' for a commerce action) and `result` (not `outcome`)\n // from the AuditResult enum.\n await this.sdk.emit({\n agent_id: agentId,\n event_type: 'api_request',\n action,\n result,\n resource: req?.merchant || '',\n metadata: {\n protocol: 'ucp',\n merchant: req?.merchant || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n ...metadata,\n },\n });\n } catch {\n // Never block the commerce flow on an audit failure.\n }\n }\n}\n\n/**\n * Create a VorimUCP instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimUCP } from '@vorim/sdk/integrations/ucp';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const ucp = createVorimUCP(vorim, { minTrustScore: 70 });\n *\n * // Verify before a UCP checkout\n * const auth = await ucp.authorizePurchase({ agentId: 'agid_abc123', merchant: 'shop', amount: 4999 });\n *\n * // Express middleware on your UCP checkout route\n * app.post('/ucp/checkout', ucp.middleware(), createCheckoutHandler);\n * ```\n */\nexport function createVorimUCP(sdk: VorimSDK, config?: Partial<UCPConfig>): VorimUCP {\n return new VorimUCP(sdk, config);\n}\n"],"mappings":";AAwEO,IAAM,WAAN,MAAe;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAA6B;AACtD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,KAAmE;AACzF,UAAM,YAAY,IAAI,iBAAiB,KAAK;AAG5C,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,IAAI,SAAS,KAAK,aAAoB;AACxE,UAAI,CAAE,KAAa,SAAS;AAC1B,cAAM,KAAK,SAAS,IAAI,SAAS,0BAA0B,UAAU,KAAK,EAAE,QAAQ,WAAW,KAAK,aAAa,GAAG,CAAC;AACrH,eAAO;AAAA,UACL,YAAY;AAAA,UACZ,SAAS,IAAI;AAAA,UACb,YAAY;AAAA,UACZ,QAAQ;AAAA,UACR,QAAQ,uBAAuB,KAAK,aAAa;AAAA,UACjD,eAAe;AAAA,QACjB;AAAA,MACF;AAAA,IACF,SAAS,GAAQ;AACf,YAAM,KAAK,SAAS,IAAI,SAAS,0BAA0B,UAAU,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAC/F,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,SAAS,IAAI;AAAA,QACb,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,QAAQ,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|
{
|
|
2
2
|
"name": "@vorim/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Official TypeScript SDK for Vorim AI — AI Agent Identity, Permissions & Audit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -97,6 +97,16 @@
|
|
|
97
97
|
"default": "./dist/integrations/stripe-acp.cjs"
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
+
"./integrations/ucp": {
|
|
101
|
+
"import": {
|
|
102
|
+
"types": "./dist/integrations/ucp.d.ts",
|
|
103
|
+
"default": "./dist/integrations/ucp.js"
|
|
104
|
+
},
|
|
105
|
+
"require": {
|
|
106
|
+
"types": "./dist/integrations/ucp.d.cts",
|
|
107
|
+
"default": "./dist/integrations/ucp.cjs"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
100
110
|
"./integrations/siem": {
|
|
101
111
|
"import": {
|
|
102
112
|
"types": "./dist/integrations/siem.d.ts",
|