@vorim/sdk 3.8.1 → 3.10.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/dist/index.cjs +208 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -3
- package/dist/index.d.ts +133 -3
- package/dist/index.js +208 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/anthropic.d.cts +1 -1
- package/dist/integrations/anthropic.d.ts +1 -1
- package/dist/integrations/ap2.cjs +218 -0
- package/dist/integrations/ap2.cjs.map +1 -0
- package/dist/integrations/ap2.d.cts +95 -0
- package/dist/integrations/ap2.d.ts +95 -0
- package/dist/integrations/ap2.js +192 -0
- package/dist/integrations/ap2.js.map +1 -0
- package/dist/integrations/bank-rails.cjs +173 -0
- package/dist/integrations/bank-rails.cjs.map +1 -0
- package/dist/integrations/bank-rails.d.cts +87 -0
- package/dist/integrations/bank-rails.d.ts +87 -0
- package/dist/integrations/bank-rails.js +147 -0
- package/dist/integrations/bank-rails.js.map +1 -0
- package/dist/integrations/circle.cjs +159 -0
- package/dist/integrations/circle.cjs.map +1 -0
- package/dist/integrations/circle.d.cts +75 -0
- package/dist/integrations/circle.d.ts +75 -0
- package/dist/integrations/circle.js +133 -0
- package/dist/integrations/circle.js.map +1 -0
- package/dist/integrations/crewai.d.cts +1 -1
- package/dist/integrations/crewai.d.ts +1 -1
- package/dist/integrations/hermes.d.cts +1 -1
- package/dist/integrations/hermes.d.ts +1 -1
- package/dist/integrations/langchain.d.cts +1 -1
- package/dist/integrations/langchain.d.ts +1 -1
- package/dist/integrations/langgraph.d.cts +1 -1
- package/dist/integrations/langgraph.d.ts +1 -1
- package/dist/integrations/llamaindex.d.cts +1 -1
- package/dist/integrations/llamaindex.d.ts +1 -1
- package/dist/integrations/modern-treasury.cjs +178 -0
- package/dist/integrations/modern-treasury.cjs.map +1 -0
- package/dist/integrations/modern-treasury.d.cts +90 -0
- package/dist/integrations/modern-treasury.d.ts +90 -0
- package/dist/integrations/modern-treasury.js +152 -0
- package/dist/integrations/modern-treasury.js.map +1 -0
- package/dist/integrations/nekuda.cjs +165 -0
- package/dist/integrations/nekuda.cjs.map +1 -0
- package/dist/integrations/nekuda.d.cts +79 -0
- package/dist/integrations/nekuda.d.ts +79 -0
- package/dist/integrations/nekuda.js +139 -0
- package/dist/integrations/nekuda.js.map +1 -0
- package/dist/integrations/openai.d.cts +1 -1
- package/dist/integrations/openai.d.ts +1 -1
- package/dist/integrations/paypal-agent.cjs +215 -0
- package/dist/integrations/paypal-agent.cjs.map +1 -0
- package/dist/integrations/paypal-agent.d.cts +87 -0
- package/dist/integrations/paypal-agent.d.ts +87 -0
- package/dist/integrations/paypal-agent.js +189 -0
- package/dist/integrations/paypal-agent.js.map +1 -0
- package/dist/integrations/plaid.cjs +174 -0
- package/dist/integrations/plaid.cjs.map +1 -0
- package/dist/integrations/plaid.d.cts +86 -0
- package/dist/integrations/plaid.d.ts +86 -0
- package/dist/integrations/plaid.js +148 -0
- package/dist/integrations/plaid.js.map +1 -0
- package/dist/integrations/siem.d.cts +1 -1
- package/dist/integrations/siem.d.ts +1 -1
- package/dist/integrations/skyfire.cjs +166 -0
- package/dist/integrations/skyfire.cjs.map +1 -0
- package/dist/integrations/skyfire.d.cts +80 -0
- package/dist/integrations/skyfire.d.ts +80 -0
- package/dist/integrations/skyfire.js +140 -0
- package/dist/integrations/skyfire.js.map +1 -0
- package/dist/integrations/stripe-acp.d.cts +1 -1
- package/dist/integrations/stripe-acp.d.ts +1 -1
- package/dist/integrations/ucp.d.cts +1 -1
- package/dist/integrations/ucp.d.ts +1 -1
- package/dist/integrations/vercel-ai.d.cts +1 -1
- package/dist/integrations/vercel-ai.d.ts +1 -1
- package/dist/integrations/x402.cjs +211 -0
- package/dist/integrations/x402.cjs.map +1 -0
- package/dist/integrations/x402.d.cts +87 -0
- package/dist/integrations/x402.d.ts +87 -0
- package/dist/integrations/x402.js +185 -0
- package/dist/integrations/x402.js.map +1 -0
- package/dist/{types-Cb6V-boJ.d.cts → types-zzK9YOoa.d.cts} +86 -1
- package/dist/{types-Cb6V-boJ.d.ts → types-zzK9YOoa.d.ts} +86 -1
- package/package.json +91 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/integrations/paypal-agent.ts
|
|
21
|
+
var paypal_agent_exports = {};
|
|
22
|
+
__export(paypal_agent_exports, {
|
|
23
|
+
VorimPayPal: () => VorimPayPal,
|
|
24
|
+
createVorimPayPal: () => createVorimPayPal
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(paypal_agent_exports);
|
|
27
|
+
var VorimPayPal = class _VorimPayPal {
|
|
28
|
+
sdk;
|
|
29
|
+
minTrustScore;
|
|
30
|
+
requiredScope;
|
|
31
|
+
/** One-time guard so the no-auth confused-deputy warning logs at most once. */
|
|
32
|
+
static _warnedNoAuth = false;
|
|
33
|
+
constructor(sdk, config) {
|
|
34
|
+
this.sdk = sdk;
|
|
35
|
+
this.minTrustScore = config?.minTrustScore ?? 50;
|
|
36
|
+
this.requiredScope = config?.requiredScope ?? "agent:transact";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Verify an agent is authorized to create a PayPal order / capture a payment.
|
|
40
|
+
* Same gate as the other payment integrations: transact scope → active
|
|
41
|
+
* status → trust threshold. Every outcome (allow or deny) is audit-logged.
|
|
42
|
+
*/
|
|
43
|
+
async authorizeOrder(req) {
|
|
44
|
+
const threshold = req.minTrustScore ?? this.minTrustScore;
|
|
45
|
+
try {
|
|
46
|
+
const perm = await this.sdk.check(req.agentId, this.requiredScope);
|
|
47
|
+
if (!perm.allowed) {
|
|
48
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
|
|
49
|
+
return {
|
|
50
|
+
authorized: false,
|
|
51
|
+
agentId: req.agentId,
|
|
52
|
+
trustScore: 0,
|
|
53
|
+
status: "unknown",
|
|
54
|
+
reason: `Agent does not have ${this.requiredScope} permission`,
|
|
55
|
+
scopeVerified: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: e.message });
|
|
60
|
+
return {
|
|
61
|
+
authorized: false,
|
|
62
|
+
agentId: req.agentId,
|
|
63
|
+
trustScore: 0,
|
|
64
|
+
status: "unknown",
|
|
65
|
+
reason: `Permission check failed: ${e.message}`,
|
|
66
|
+
scopeVerified: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
let score = 0;
|
|
70
|
+
let status = "unknown";
|
|
71
|
+
try {
|
|
72
|
+
const trust = await this.sdk.verify(req.agentId);
|
|
73
|
+
score = trust.trust_score ?? 0;
|
|
74
|
+
status = trust.status ?? "unknown";
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
if (status !== "active") {
|
|
78
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: `Status: ${status}` });
|
|
79
|
+
return {
|
|
80
|
+
authorized: false,
|
|
81
|
+
agentId: req.agentId,
|
|
82
|
+
trustScore: score,
|
|
83
|
+
status,
|
|
84
|
+
reason: `Agent is ${status}, not active`,
|
|
85
|
+
scopeVerified: true
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (score < threshold) {
|
|
89
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
|
|
90
|
+
return {
|
|
91
|
+
authorized: false,
|
|
92
|
+
agentId: req.agentId,
|
|
93
|
+
trustScore: score,
|
|
94
|
+
status,
|
|
95
|
+
reason: `Trust score ${score} is below minimum ${threshold}`,
|
|
96
|
+
scopeVerified: true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "success", req, { trust_score: score });
|
|
100
|
+
return {
|
|
101
|
+
authorized: true,
|
|
102
|
+
agentId: req.agentId,
|
|
103
|
+
trustScore: score,
|
|
104
|
+
status,
|
|
105
|
+
scopeVerified: true
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Log that a PayPal order was created. */
|
|
109
|
+
async logOrderCreated(agentId, orderId, req) {
|
|
110
|
+
await this.logEvent(agentId, "paypal.order.created", "success", req, { order_id: orderId });
|
|
111
|
+
}
|
|
112
|
+
/** Log that a PayPal payment was captured (money moved). */
|
|
113
|
+
async logPaymentCaptured(agentId, orderId, captureId, req) {
|
|
114
|
+
await this.logEvent(agentId, "paypal.payment.captured", "success", req, { order_id: orderId, capture_id: captureId });
|
|
115
|
+
}
|
|
116
|
+
/** Log that a refund was issued against an order/capture. */
|
|
117
|
+
async logRefundIssued(agentId, captureId, refundId, req) {
|
|
118
|
+
await this.logEvent(agentId, "paypal.refund.issued", "success", req, { capture_id: captureId, refund_id: refundId });
|
|
119
|
+
}
|
|
120
|
+
/** Log that a PayPal order/payment failed or was declined. */
|
|
121
|
+
async logOrderFailed(agentId, orderId, reason, req) {
|
|
122
|
+
await this.logEvent(agentId, "paypal.order.failed", "error", req, { order_id: orderId, fail_reason: reason });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Express/Connect middleware that gates a PayPal order-creation endpoint on
|
|
126
|
+
* agent authorization.
|
|
127
|
+
*
|
|
128
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing
|
|
129
|
+
* only; it does NOT prove the HTTP caller controls that agent. Authenticate
|
|
130
|
+
* the caller-to-agent binding upstream, or pass `authenticate`. When omitted,
|
|
131
|
+
* a one-time warning is logged.
|
|
132
|
+
*/
|
|
133
|
+
middleware(options) {
|
|
134
|
+
const header = options?.agentIdHeader ?? "x-vorim-agent-id";
|
|
135
|
+
const threshold = options?.minTrustScore ?? this.minTrustScore;
|
|
136
|
+
const authenticate = options?.authenticate;
|
|
137
|
+
if (!authenticate && !_VorimPayPal._warnedNoAuth) {
|
|
138
|
+
_VorimPayPal._warnedNoAuth = true;
|
|
139
|
+
console.warn(
|
|
140
|
+
"[vorim] VorimPayPal.middleware() called without an `authenticate` hook: it authorizes the agent NAMED in the header but does not verify the caller controls that agent (confused-deputy risk). Authenticate the caller-to-agent binding upstream or pass `authenticate`."
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return async (req, res, next) => {
|
|
144
|
+
const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
|
|
145
|
+
if (!agentId) {
|
|
146
|
+
res.status(401).json({
|
|
147
|
+
error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` }
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (authenticate) {
|
|
152
|
+
let bound = false;
|
|
153
|
+
try {
|
|
154
|
+
bound = await authenticate(agentId, req);
|
|
155
|
+
} catch {
|
|
156
|
+
bound = false;
|
|
157
|
+
}
|
|
158
|
+
if (!bound) {
|
|
159
|
+
res.status(401).json({
|
|
160
|
+
error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" }
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const auth = await this.authorizeOrder({
|
|
166
|
+
agentId,
|
|
167
|
+
merchant: req.body?.merchant || "",
|
|
168
|
+
amount: req.body?.amount || 0,
|
|
169
|
+
currency: req.body?.currency || "USD",
|
|
170
|
+
minTrustScore: threshold
|
|
171
|
+
});
|
|
172
|
+
if (!auth.authorized) {
|
|
173
|
+
res.status(403).json({
|
|
174
|
+
error: {
|
|
175
|
+
code: "UNAUTHORIZED_AGENT",
|
|
176
|
+
message: auth.reason || "Agent not authorized for PayPal transactions",
|
|
177
|
+
trust_score: auth.trustScore,
|
|
178
|
+
status: auth.status
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
req.vorimAuthorization = auth;
|
|
184
|
+
next();
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async logEvent(agentId, action, result, req, metadata) {
|
|
188
|
+
try {
|
|
189
|
+
await this.sdk.emit({
|
|
190
|
+
agent_id: agentId,
|
|
191
|
+
event_type: "api_request",
|
|
192
|
+
action,
|
|
193
|
+
result,
|
|
194
|
+
resource: req?.merchant || "",
|
|
195
|
+
metadata: {
|
|
196
|
+
merchant: req?.merchant || "",
|
|
197
|
+
amount: req?.amount || 0,
|
|
198
|
+
currency: req?.currency || "",
|
|
199
|
+
intent: req?.intent || "",
|
|
200
|
+
...metadata
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
function createVorimPayPal(sdk, config) {
|
|
208
|
+
return new VorimPayPal(sdk, config);
|
|
209
|
+
}
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
VorimPayPal,
|
|
213
|
+
createVorimPayPal
|
|
214
|
+
});
|
|
215
|
+
//# sourceMappingURL=paypal-agent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/paypal-agent.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — PayPal Agent Toolkit Integration\n//\n// PayPal ships an open Agent Toolkit (npm @paypal/agent-toolkit, PyPI\n// paypal-agent-toolkit) and MCP server that let AI agents drive PayPal's\n// Orders v2 lifecycle: create an order, capture (or authorize) payment, and\n// issue refunds. The tools are exposed as discrete, named calls.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of those calls: before an agent creates an order or captures a payment, it\n// verifies the agent holds `transact`, is active, and clears a trust\n// threshold, and it records the order → capture → refund lifecycle on a signed,\n// tamper-evident audit trail. It does NOT move money or hold PayPal\n// credentials — the PayPal toolkit does the payment; Vorim authorizes and\n// attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimPayPal } from '@vorim/sdk/integrations/paypal-agent';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const pp = createVorimPayPal(vorim, { minTrustScore: 60 });\n//\n// // Before an agent creates a PayPal order:\n// const auth = await pp.authorizeOrder({\n// agentId: 'agid_abc123',\n// merchant: 'acme-store',\n// amount: 4999,\n// currency: 'USD',\n// });\n// if (auth.authorized) {\n// const order = await paypalToolkit.createOrder(...); // your PayPal call\n// await pp.logOrderCreated(auth.agentId, order.id, { merchant, amount });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface PayPalConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface PayPalOrderRequest {\n /** The Vorim agent id creating the order / capturing the payment. */\n agentId: string;\n /** The merchant / seller the order is with. */\n merchant?: string;\n /** Amount in the smallest currency unit (e.g. cents). */\n amount?: number;\n /** Currency code (e.g. 'USD'). */\n currency?: string;\n /** Optional PayPal intent hint ('CAPTURE' | 'AUTHORIZE'). Informational. */\n intent?: 'CAPTURE' | 'AUTHORIZE';\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface PayPalAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimPayPal {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n /** One-time guard so the no-auth confused-deputy warning logs at most once. */\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<PayPalConfig>) {\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 create a PayPal order / capture a payment.\n * Same gate as the other payment integrations: transact scope → active\n * status → trust threshold. Every outcome (allow or deny) is audit-logged.\n */\n async authorizeOrder(req: PayPalOrderRequest): Promise<PayPalAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n\n // 1. Permission: the 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, 'paypal.order.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, 'paypal.order.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: verify the agent's public standing.\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, 'paypal.order.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, 'paypal.order.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, 'paypal.order.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 /** Log that a PayPal order was created. */\n async logOrderCreated(agentId: string, orderId: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.order.created', 'success', req, { order_id: orderId });\n }\n\n /** Log that a PayPal payment was captured (money moved). */\n async logPaymentCaptured(agentId: string, orderId: string, captureId?: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.payment.captured', 'success', req, { order_id: orderId, capture_id: captureId });\n }\n\n /** Log that a refund was issued against an order/capture. */\n async logRefundIssued(agentId: string, captureId: string, refundId?: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.refund.issued', 'success', req, { capture_id: captureId, refund_id: refundId });\n }\n\n /** Log that a PayPal order/payment failed or was declined. */\n async logOrderFailed(agentId: string, orderId: string, reason?: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.order.failed', 'error', req, { order_id: orderId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a PayPal order-creation endpoint on\n * agent authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing\n * only; it does NOT prove the HTTP caller controls that agent. Authenticate\n * the caller-to-agent binding upstream, or pass `authenticate`. When omitted,\n * a one-time warning is logged.\n */\n middleware(options?: {\n agentIdHeader?: string;\n minTrustScore?: number;\n authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;\n }) {\n const header = options?.agentIdHeader ?? 'x-vorim-agent-id';\n const threshold = options?.minTrustScore ?? this.minTrustScore;\n const authenticate = options?.authenticate;\n\n if (!authenticate && !VorimPayPal._warnedNoAuth) {\n VorimPayPal._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimPayPal.middleware() called without an `authenticate` hook: ' +\n 'it authorizes the agent NAMED in the header but does not verify the ' +\n 'caller controls that agent (confused-deputy risk). Authenticate the ' +\n 'caller-to-agent binding upstream or pass `authenticate`.'\n );\n }\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 if (authenticate) {\n let bound = false;\n try {\n bound = await authenticate(agentId, req);\n } catch {\n bound = false;\n }\n if (!bound) {\n res.status(401).json({\n error: { code: 'AGENT_BINDING_UNVERIFIED', message: 'Caller is not authenticated as the named agent' },\n });\n return;\n }\n }\n\n const auth = await this.authorizeOrder({\n agentId,\n merchant: req.body?.merchant || '',\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 PayPal 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?: Partial<PayPalOrderRequest>,\n metadata?: Record<string, any>,\n ): Promise<void> {\n try {\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 merchant: req?.merchant || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n intent: req?.intent || '',\n ...metadata,\n },\n });\n } catch {\n // Never block the payment flow on an audit hiccup.\n }\n }\n}\n\n/**\n * Create a VorimPayPal instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimPayPal } from '@vorim/sdk/integrations/paypal-agent';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const pp = createVorimPayPal(vorim, { minTrustScore: 70 });\n *\n * const auth = await pp.authorizeOrder({ agentId: 'agid_abc123', merchant: 'shop', amount: 4999, currency: 'USD' });\n *\n * app.post('/paypal/orders', pp.middleware(), createOrderHandler);\n * ```\n */\nexport function createVorimPayPal(sdk: VorimSDK, config?: Partial<PayPalConfig>): VorimPayPal {\n return new VorimPayPal(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqEO,IAAM,cAAN,MAAM,aAAY;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAER,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAAgC;AACzD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,eAAe,KAAuD;AAC1E,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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AAO,IAAI,YAAY,KAAK,MAAM;AACpC;","names":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.cjs';
|
|
2
|
+
import '../types-zzK9YOoa.cjs';
|
|
3
|
+
|
|
4
|
+
interface PayPalConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
minTrustScore?: number;
|
|
8
|
+
requiredScope?: string;
|
|
9
|
+
}
|
|
10
|
+
interface PayPalOrderRequest {
|
|
11
|
+
/** The Vorim agent id creating the order / capturing the payment. */
|
|
12
|
+
agentId: string;
|
|
13
|
+
/** The merchant / seller the order is with. */
|
|
14
|
+
merchant?: string;
|
|
15
|
+
/** Amount in the smallest currency unit (e.g. cents). */
|
|
16
|
+
amount?: number;
|
|
17
|
+
/** Currency code (e.g. 'USD'). */
|
|
18
|
+
currency?: string;
|
|
19
|
+
/** Optional PayPal intent hint ('CAPTURE' | 'AUTHORIZE'). Informational. */
|
|
20
|
+
intent?: 'CAPTURE' | 'AUTHORIZE';
|
|
21
|
+
/** Per-call override of the trust threshold. */
|
|
22
|
+
minTrustScore?: number;
|
|
23
|
+
}
|
|
24
|
+
interface PayPalAuthorization {
|
|
25
|
+
authorized: boolean;
|
|
26
|
+
agentId: string;
|
|
27
|
+
trustScore: number;
|
|
28
|
+
status: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
scopeVerified: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare class VorimPayPal {
|
|
33
|
+
private sdk;
|
|
34
|
+
private minTrustScore;
|
|
35
|
+
private requiredScope;
|
|
36
|
+
/** One-time guard so the no-auth confused-deputy warning logs at most once. */
|
|
37
|
+
private static _warnedNoAuth;
|
|
38
|
+
constructor(sdk: VorimSDK, config?: Partial<PayPalConfig>);
|
|
39
|
+
/**
|
|
40
|
+
* Verify an agent is authorized to create a PayPal order / capture a payment.
|
|
41
|
+
* Same gate as the other payment integrations: transact scope → active
|
|
42
|
+
* status → trust threshold. Every outcome (allow or deny) is audit-logged.
|
|
43
|
+
*/
|
|
44
|
+
authorizeOrder(req: PayPalOrderRequest): Promise<PayPalAuthorization>;
|
|
45
|
+
/** Log that a PayPal order was created. */
|
|
46
|
+
logOrderCreated(agentId: string, orderId: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
47
|
+
/** Log that a PayPal payment was captured (money moved). */
|
|
48
|
+
logPaymentCaptured(agentId: string, orderId: string, captureId?: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
49
|
+
/** Log that a refund was issued against an order/capture. */
|
|
50
|
+
logRefundIssued(agentId: string, captureId: string, refundId?: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
51
|
+
/** Log that a PayPal order/payment failed or was declined. */
|
|
52
|
+
logOrderFailed(agentId: string, orderId: string, reason?: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Express/Connect middleware that gates a PayPal order-creation endpoint on
|
|
55
|
+
* agent authorization.
|
|
56
|
+
*
|
|
57
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing
|
|
58
|
+
* only; it does NOT prove the HTTP caller controls that agent. Authenticate
|
|
59
|
+
* the caller-to-agent binding upstream, or pass `authenticate`. When omitted,
|
|
60
|
+
* a one-time warning is logged.
|
|
61
|
+
*/
|
|
62
|
+
middleware(options?: {
|
|
63
|
+
agentIdHeader?: string;
|
|
64
|
+
minTrustScore?: number;
|
|
65
|
+
authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
|
|
66
|
+
}): (req: any, res: any, next: any) => Promise<void>;
|
|
67
|
+
private logEvent;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a VorimPayPal instance.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import createVorim from '@vorim/sdk';
|
|
75
|
+
* import { createVorimPayPal } from '@vorim/sdk/integrations/paypal-agent';
|
|
76
|
+
*
|
|
77
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
78
|
+
* const pp = createVorimPayPal(vorim, { minTrustScore: 70 });
|
|
79
|
+
*
|
|
80
|
+
* const auth = await pp.authorizeOrder({ agentId: 'agid_abc123', merchant: 'shop', amount: 4999, currency: 'USD' });
|
|
81
|
+
*
|
|
82
|
+
* app.post('/paypal/orders', pp.middleware(), createOrderHandler);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function createVorimPayPal(sdk: VorimSDK, config?: Partial<PayPalConfig>): VorimPayPal;
|
|
86
|
+
|
|
87
|
+
export { type PayPalAuthorization, type PayPalConfig, type PayPalOrderRequest, VorimPayPal, createVorimPayPal };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.js';
|
|
2
|
+
import '../types-zzK9YOoa.js';
|
|
3
|
+
|
|
4
|
+
interface PayPalConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
minTrustScore?: number;
|
|
8
|
+
requiredScope?: string;
|
|
9
|
+
}
|
|
10
|
+
interface PayPalOrderRequest {
|
|
11
|
+
/** The Vorim agent id creating the order / capturing the payment. */
|
|
12
|
+
agentId: string;
|
|
13
|
+
/** The merchant / seller the order is with. */
|
|
14
|
+
merchant?: string;
|
|
15
|
+
/** Amount in the smallest currency unit (e.g. cents). */
|
|
16
|
+
amount?: number;
|
|
17
|
+
/** Currency code (e.g. 'USD'). */
|
|
18
|
+
currency?: string;
|
|
19
|
+
/** Optional PayPal intent hint ('CAPTURE' | 'AUTHORIZE'). Informational. */
|
|
20
|
+
intent?: 'CAPTURE' | 'AUTHORIZE';
|
|
21
|
+
/** Per-call override of the trust threshold. */
|
|
22
|
+
minTrustScore?: number;
|
|
23
|
+
}
|
|
24
|
+
interface PayPalAuthorization {
|
|
25
|
+
authorized: boolean;
|
|
26
|
+
agentId: string;
|
|
27
|
+
trustScore: number;
|
|
28
|
+
status: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
scopeVerified: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare class VorimPayPal {
|
|
33
|
+
private sdk;
|
|
34
|
+
private minTrustScore;
|
|
35
|
+
private requiredScope;
|
|
36
|
+
/** One-time guard so the no-auth confused-deputy warning logs at most once. */
|
|
37
|
+
private static _warnedNoAuth;
|
|
38
|
+
constructor(sdk: VorimSDK, config?: Partial<PayPalConfig>);
|
|
39
|
+
/**
|
|
40
|
+
* Verify an agent is authorized to create a PayPal order / capture a payment.
|
|
41
|
+
* Same gate as the other payment integrations: transact scope → active
|
|
42
|
+
* status → trust threshold. Every outcome (allow or deny) is audit-logged.
|
|
43
|
+
*/
|
|
44
|
+
authorizeOrder(req: PayPalOrderRequest): Promise<PayPalAuthorization>;
|
|
45
|
+
/** Log that a PayPal order was created. */
|
|
46
|
+
logOrderCreated(agentId: string, orderId: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
47
|
+
/** Log that a PayPal payment was captured (money moved). */
|
|
48
|
+
logPaymentCaptured(agentId: string, orderId: string, captureId?: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
49
|
+
/** Log that a refund was issued against an order/capture. */
|
|
50
|
+
logRefundIssued(agentId: string, captureId: string, refundId?: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
51
|
+
/** Log that a PayPal order/payment failed or was declined. */
|
|
52
|
+
logOrderFailed(agentId: string, orderId: string, reason?: string, req?: Partial<PayPalOrderRequest>): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Express/Connect middleware that gates a PayPal order-creation endpoint on
|
|
55
|
+
* agent authorization.
|
|
56
|
+
*
|
|
57
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing
|
|
58
|
+
* only; it does NOT prove the HTTP caller controls that agent. Authenticate
|
|
59
|
+
* the caller-to-agent binding upstream, or pass `authenticate`. When omitted,
|
|
60
|
+
* a one-time warning is logged.
|
|
61
|
+
*/
|
|
62
|
+
middleware(options?: {
|
|
63
|
+
agentIdHeader?: string;
|
|
64
|
+
minTrustScore?: number;
|
|
65
|
+
authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
|
|
66
|
+
}): (req: any, res: any, next: any) => Promise<void>;
|
|
67
|
+
private logEvent;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a VorimPayPal instance.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import createVorim from '@vorim/sdk';
|
|
75
|
+
* import { createVorimPayPal } from '@vorim/sdk/integrations/paypal-agent';
|
|
76
|
+
*
|
|
77
|
+
* const vorim = createVorim({ apiKey: 'agid_sk_...' });
|
|
78
|
+
* const pp = createVorimPayPal(vorim, { minTrustScore: 70 });
|
|
79
|
+
*
|
|
80
|
+
* const auth = await pp.authorizeOrder({ agentId: 'agid_abc123', merchant: 'shop', amount: 4999, currency: 'USD' });
|
|
81
|
+
*
|
|
82
|
+
* app.post('/paypal/orders', pp.middleware(), createOrderHandler);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function createVorimPayPal(sdk: VorimSDK, config?: Partial<PayPalConfig>): VorimPayPal;
|
|
86
|
+
|
|
87
|
+
export { type PayPalAuthorization, type PayPalConfig, type PayPalOrderRequest, VorimPayPal, createVorimPayPal };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// src/integrations/paypal-agent.ts
|
|
2
|
+
var VorimPayPal = class _VorimPayPal {
|
|
3
|
+
sdk;
|
|
4
|
+
minTrustScore;
|
|
5
|
+
requiredScope;
|
|
6
|
+
/** One-time guard so the no-auth confused-deputy warning logs at most once. */
|
|
7
|
+
static _warnedNoAuth = false;
|
|
8
|
+
constructor(sdk, config) {
|
|
9
|
+
this.sdk = sdk;
|
|
10
|
+
this.minTrustScore = config?.minTrustScore ?? 50;
|
|
11
|
+
this.requiredScope = config?.requiredScope ?? "agent:transact";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Verify an agent is authorized to create a PayPal order / capture a payment.
|
|
15
|
+
* Same gate as the other payment integrations: transact scope → active
|
|
16
|
+
* status → trust threshold. Every outcome (allow or deny) is audit-logged.
|
|
17
|
+
*/
|
|
18
|
+
async authorizeOrder(req) {
|
|
19
|
+
const threshold = req.minTrustScore ?? this.minTrustScore;
|
|
20
|
+
try {
|
|
21
|
+
const perm = await this.sdk.check(req.agentId, this.requiredScope);
|
|
22
|
+
if (!perm.allowed) {
|
|
23
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
|
|
24
|
+
return {
|
|
25
|
+
authorized: false,
|
|
26
|
+
agentId: req.agentId,
|
|
27
|
+
trustScore: 0,
|
|
28
|
+
status: "unknown",
|
|
29
|
+
reason: `Agent does not have ${this.requiredScope} permission`,
|
|
30
|
+
scopeVerified: false
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: e.message });
|
|
35
|
+
return {
|
|
36
|
+
authorized: false,
|
|
37
|
+
agentId: req.agentId,
|
|
38
|
+
trustScore: 0,
|
|
39
|
+
status: "unknown",
|
|
40
|
+
reason: `Permission check failed: ${e.message}`,
|
|
41
|
+
scopeVerified: false
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
let score = 0;
|
|
45
|
+
let status = "unknown";
|
|
46
|
+
try {
|
|
47
|
+
const trust = await this.sdk.verify(req.agentId);
|
|
48
|
+
score = trust.trust_score ?? 0;
|
|
49
|
+
status = trust.status ?? "unknown";
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
if (status !== "active") {
|
|
53
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: `Status: ${status}` });
|
|
54
|
+
return {
|
|
55
|
+
authorized: false,
|
|
56
|
+
agentId: req.agentId,
|
|
57
|
+
trustScore: score,
|
|
58
|
+
status,
|
|
59
|
+
reason: `Agent is ${status}, not active`,
|
|
60
|
+
scopeVerified: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (score < threshold) {
|
|
64
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
|
|
65
|
+
return {
|
|
66
|
+
authorized: false,
|
|
67
|
+
agentId: req.agentId,
|
|
68
|
+
trustScore: score,
|
|
69
|
+
status,
|
|
70
|
+
reason: `Trust score ${score} is below minimum ${threshold}`,
|
|
71
|
+
scopeVerified: true
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
await this.logEvent(req.agentId, "paypal.order.authorize", "success", req, { trust_score: score });
|
|
75
|
+
return {
|
|
76
|
+
authorized: true,
|
|
77
|
+
agentId: req.agentId,
|
|
78
|
+
trustScore: score,
|
|
79
|
+
status,
|
|
80
|
+
scopeVerified: true
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Log that a PayPal order was created. */
|
|
84
|
+
async logOrderCreated(agentId, orderId, req) {
|
|
85
|
+
await this.logEvent(agentId, "paypal.order.created", "success", req, { order_id: orderId });
|
|
86
|
+
}
|
|
87
|
+
/** Log that a PayPal payment was captured (money moved). */
|
|
88
|
+
async logPaymentCaptured(agentId, orderId, captureId, req) {
|
|
89
|
+
await this.logEvent(agentId, "paypal.payment.captured", "success", req, { order_id: orderId, capture_id: captureId });
|
|
90
|
+
}
|
|
91
|
+
/** Log that a refund was issued against an order/capture. */
|
|
92
|
+
async logRefundIssued(agentId, captureId, refundId, req) {
|
|
93
|
+
await this.logEvent(agentId, "paypal.refund.issued", "success", req, { capture_id: captureId, refund_id: refundId });
|
|
94
|
+
}
|
|
95
|
+
/** Log that a PayPal order/payment failed or was declined. */
|
|
96
|
+
async logOrderFailed(agentId, orderId, reason, req) {
|
|
97
|
+
await this.logEvent(agentId, "paypal.order.failed", "error", req, { order_id: orderId, fail_reason: reason });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Express/Connect middleware that gates a PayPal order-creation endpoint on
|
|
101
|
+
* agent authorization.
|
|
102
|
+
*
|
|
103
|
+
* ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing
|
|
104
|
+
* only; it does NOT prove the HTTP caller controls that agent. Authenticate
|
|
105
|
+
* the caller-to-agent binding upstream, or pass `authenticate`. When omitted,
|
|
106
|
+
* a one-time warning is logged.
|
|
107
|
+
*/
|
|
108
|
+
middleware(options) {
|
|
109
|
+
const header = options?.agentIdHeader ?? "x-vorim-agent-id";
|
|
110
|
+
const threshold = options?.minTrustScore ?? this.minTrustScore;
|
|
111
|
+
const authenticate = options?.authenticate;
|
|
112
|
+
if (!authenticate && !_VorimPayPal._warnedNoAuth) {
|
|
113
|
+
_VorimPayPal._warnedNoAuth = true;
|
|
114
|
+
console.warn(
|
|
115
|
+
"[vorim] VorimPayPal.middleware() called without an `authenticate` hook: it authorizes the agent NAMED in the header but does not verify the caller controls that agent (confused-deputy risk). Authenticate the caller-to-agent binding upstream or pass `authenticate`."
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return async (req, res, next) => {
|
|
119
|
+
const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
|
|
120
|
+
if (!agentId) {
|
|
121
|
+
res.status(401).json({
|
|
122
|
+
error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` }
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (authenticate) {
|
|
127
|
+
let bound = false;
|
|
128
|
+
try {
|
|
129
|
+
bound = await authenticate(agentId, req);
|
|
130
|
+
} catch {
|
|
131
|
+
bound = false;
|
|
132
|
+
}
|
|
133
|
+
if (!bound) {
|
|
134
|
+
res.status(401).json({
|
|
135
|
+
error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" }
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const auth = await this.authorizeOrder({
|
|
141
|
+
agentId,
|
|
142
|
+
merchant: req.body?.merchant || "",
|
|
143
|
+
amount: req.body?.amount || 0,
|
|
144
|
+
currency: req.body?.currency || "USD",
|
|
145
|
+
minTrustScore: threshold
|
|
146
|
+
});
|
|
147
|
+
if (!auth.authorized) {
|
|
148
|
+
res.status(403).json({
|
|
149
|
+
error: {
|
|
150
|
+
code: "UNAUTHORIZED_AGENT",
|
|
151
|
+
message: auth.reason || "Agent not authorized for PayPal transactions",
|
|
152
|
+
trust_score: auth.trustScore,
|
|
153
|
+
status: auth.status
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
req.vorimAuthorization = auth;
|
|
159
|
+
next();
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async logEvent(agentId, action, result, req, metadata) {
|
|
163
|
+
try {
|
|
164
|
+
await this.sdk.emit({
|
|
165
|
+
agent_id: agentId,
|
|
166
|
+
event_type: "api_request",
|
|
167
|
+
action,
|
|
168
|
+
result,
|
|
169
|
+
resource: req?.merchant || "",
|
|
170
|
+
metadata: {
|
|
171
|
+
merchant: req?.merchant || "",
|
|
172
|
+
amount: req?.amount || 0,
|
|
173
|
+
currency: req?.currency || "",
|
|
174
|
+
intent: req?.intent || "",
|
|
175
|
+
...metadata
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function createVorimPayPal(sdk, config) {
|
|
183
|
+
return new VorimPayPal(sdk, config);
|
|
184
|
+
}
|
|
185
|
+
export {
|
|
186
|
+
VorimPayPal,
|
|
187
|
+
createVorimPayPal
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=paypal-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/paypal-agent.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — PayPal Agent Toolkit Integration\n//\n// PayPal ships an open Agent Toolkit (npm @paypal/agent-toolkit, PyPI\n// paypal-agent-toolkit) and MCP server that let AI agents drive PayPal's\n// Orders v2 lifecycle: create an order, capture (or authorize) payment, and\n// issue refunds. The tools are exposed as discrete, named calls.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of those calls: before an agent creates an order or captures a payment, it\n// verifies the agent holds `transact`, is active, and clears a trust\n// threshold, and it records the order → capture → refund lifecycle on a signed,\n// tamper-evident audit trail. It does NOT move money or hold PayPal\n// credentials — the PayPal toolkit does the payment; Vorim authorizes and\n// attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimPayPal } from '@vorim/sdk/integrations/paypal-agent';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const pp = createVorimPayPal(vorim, { minTrustScore: 60 });\n//\n// // Before an agent creates a PayPal order:\n// const auth = await pp.authorizeOrder({\n// agentId: 'agid_abc123',\n// merchant: 'acme-store',\n// amount: 4999,\n// currency: 'USD',\n// });\n// if (auth.authorized) {\n// const order = await paypalToolkit.createOrder(...); // your PayPal call\n// await pp.logOrderCreated(auth.agentId, order.id, { merchant, amount });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface PayPalConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface PayPalOrderRequest {\n /** The Vorim agent id creating the order / capturing the payment. */\n agentId: string;\n /** The merchant / seller the order is with. */\n merchant?: string;\n /** Amount in the smallest currency unit (e.g. cents). */\n amount?: number;\n /** Currency code (e.g. 'USD'). */\n currency?: string;\n /** Optional PayPal intent hint ('CAPTURE' | 'AUTHORIZE'). Informational. */\n intent?: 'CAPTURE' | 'AUTHORIZE';\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface PayPalAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimPayPal {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n /** One-time guard so the no-auth confused-deputy warning logs at most once. */\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<PayPalConfig>) {\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 create a PayPal order / capture a payment.\n * Same gate as the other payment integrations: transact scope → active\n * status → trust threshold. Every outcome (allow or deny) is audit-logged.\n */\n async authorizeOrder(req: PayPalOrderRequest): Promise<PayPalAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n\n // 1. Permission: the 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, 'paypal.order.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, 'paypal.order.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: verify the agent's public standing.\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, 'paypal.order.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, 'paypal.order.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, 'paypal.order.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 /** Log that a PayPal order was created. */\n async logOrderCreated(agentId: string, orderId: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.order.created', 'success', req, { order_id: orderId });\n }\n\n /** Log that a PayPal payment was captured (money moved). */\n async logPaymentCaptured(agentId: string, orderId: string, captureId?: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.payment.captured', 'success', req, { order_id: orderId, capture_id: captureId });\n }\n\n /** Log that a refund was issued against an order/capture. */\n async logRefundIssued(agentId: string, captureId: string, refundId?: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.refund.issued', 'success', req, { capture_id: captureId, refund_id: refundId });\n }\n\n /** Log that a PayPal order/payment failed or was declined. */\n async logOrderFailed(agentId: string, orderId: string, reason?: string, req?: Partial<PayPalOrderRequest>): Promise<void> {\n await this.logEvent(agentId, 'paypal.order.failed', 'error', req, { order_id: orderId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a PayPal order-creation endpoint on\n * agent authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. This evaluates the *named* agent's standing\n * only; it does NOT prove the HTTP caller controls that agent. Authenticate\n * the caller-to-agent binding upstream, or pass `authenticate`. When omitted,\n * a one-time warning is logged.\n */\n middleware(options?: {\n agentIdHeader?: string;\n minTrustScore?: number;\n authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;\n }) {\n const header = options?.agentIdHeader ?? 'x-vorim-agent-id';\n const threshold = options?.minTrustScore ?? this.minTrustScore;\n const authenticate = options?.authenticate;\n\n if (!authenticate && !VorimPayPal._warnedNoAuth) {\n VorimPayPal._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimPayPal.middleware() called without an `authenticate` hook: ' +\n 'it authorizes the agent NAMED in the header but does not verify the ' +\n 'caller controls that agent (confused-deputy risk). Authenticate the ' +\n 'caller-to-agent binding upstream or pass `authenticate`.'\n );\n }\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 if (authenticate) {\n let bound = false;\n try {\n bound = await authenticate(agentId, req);\n } catch {\n bound = false;\n }\n if (!bound) {\n res.status(401).json({\n error: { code: 'AGENT_BINDING_UNVERIFIED', message: 'Caller is not authenticated as the named agent' },\n });\n return;\n }\n }\n\n const auth = await this.authorizeOrder({\n agentId,\n merchant: req.body?.merchant || '',\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 PayPal 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?: Partial<PayPalOrderRequest>,\n metadata?: Record<string, any>,\n ): Promise<void> {\n try {\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 merchant: req?.merchant || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n intent: req?.intent || '',\n ...metadata,\n },\n });\n } catch {\n // Never block the payment flow on an audit hiccup.\n }\n }\n}\n\n/**\n * Create a VorimPayPal instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimPayPal } from '@vorim/sdk/integrations/paypal-agent';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const pp = createVorimPayPal(vorim, { minTrustScore: 70 });\n *\n * const auth = await pp.authorizeOrder({ agentId: 'agid_abc123', merchant: 'shop', amount: 4999, currency: 'USD' });\n *\n * app.post('/paypal/orders', pp.middleware(), createOrderHandler);\n * ```\n */\nexport function createVorimPayPal(sdk: VorimSDK, config?: Partial<PayPalConfig>): VorimPayPal {\n return new VorimPayPal(sdk, config);\n}\n"],"mappings":";AAqEO,IAAM,cAAN,MAAM,aAAY;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAER,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAAgC;AACzD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,eAAe,KAAuD;AAC1E,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;AAA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