@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.
Files changed (85) hide show
  1. package/dist/index.cjs +208 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +133 -3
  4. package/dist/index.d.ts +133 -3
  5. package/dist/index.js +208 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/integrations/anthropic.d.cts +1 -1
  8. package/dist/integrations/anthropic.d.ts +1 -1
  9. package/dist/integrations/ap2.cjs +218 -0
  10. package/dist/integrations/ap2.cjs.map +1 -0
  11. package/dist/integrations/ap2.d.cts +95 -0
  12. package/dist/integrations/ap2.d.ts +95 -0
  13. package/dist/integrations/ap2.js +192 -0
  14. package/dist/integrations/ap2.js.map +1 -0
  15. package/dist/integrations/bank-rails.cjs +173 -0
  16. package/dist/integrations/bank-rails.cjs.map +1 -0
  17. package/dist/integrations/bank-rails.d.cts +87 -0
  18. package/dist/integrations/bank-rails.d.ts +87 -0
  19. package/dist/integrations/bank-rails.js +147 -0
  20. package/dist/integrations/bank-rails.js.map +1 -0
  21. package/dist/integrations/circle.cjs +159 -0
  22. package/dist/integrations/circle.cjs.map +1 -0
  23. package/dist/integrations/circle.d.cts +75 -0
  24. package/dist/integrations/circle.d.ts +75 -0
  25. package/dist/integrations/circle.js +133 -0
  26. package/dist/integrations/circle.js.map +1 -0
  27. package/dist/integrations/crewai.d.cts +1 -1
  28. package/dist/integrations/crewai.d.ts +1 -1
  29. package/dist/integrations/hermes.d.cts +1 -1
  30. package/dist/integrations/hermes.d.ts +1 -1
  31. package/dist/integrations/langchain.d.cts +1 -1
  32. package/dist/integrations/langchain.d.ts +1 -1
  33. package/dist/integrations/langgraph.d.cts +1 -1
  34. package/dist/integrations/langgraph.d.ts +1 -1
  35. package/dist/integrations/llamaindex.d.cts +1 -1
  36. package/dist/integrations/llamaindex.d.ts +1 -1
  37. package/dist/integrations/modern-treasury.cjs +178 -0
  38. package/dist/integrations/modern-treasury.cjs.map +1 -0
  39. package/dist/integrations/modern-treasury.d.cts +90 -0
  40. package/dist/integrations/modern-treasury.d.ts +90 -0
  41. package/dist/integrations/modern-treasury.js +152 -0
  42. package/dist/integrations/modern-treasury.js.map +1 -0
  43. package/dist/integrations/nekuda.cjs +165 -0
  44. package/dist/integrations/nekuda.cjs.map +1 -0
  45. package/dist/integrations/nekuda.d.cts +79 -0
  46. package/dist/integrations/nekuda.d.ts +79 -0
  47. package/dist/integrations/nekuda.js +139 -0
  48. package/dist/integrations/nekuda.js.map +1 -0
  49. package/dist/integrations/openai.d.cts +1 -1
  50. package/dist/integrations/openai.d.ts +1 -1
  51. package/dist/integrations/paypal-agent.cjs +215 -0
  52. package/dist/integrations/paypal-agent.cjs.map +1 -0
  53. package/dist/integrations/paypal-agent.d.cts +87 -0
  54. package/dist/integrations/paypal-agent.d.ts +87 -0
  55. package/dist/integrations/paypal-agent.js +189 -0
  56. package/dist/integrations/paypal-agent.js.map +1 -0
  57. package/dist/integrations/plaid.cjs +174 -0
  58. package/dist/integrations/plaid.cjs.map +1 -0
  59. package/dist/integrations/plaid.d.cts +86 -0
  60. package/dist/integrations/plaid.d.ts +86 -0
  61. package/dist/integrations/plaid.js +148 -0
  62. package/dist/integrations/plaid.js.map +1 -0
  63. package/dist/integrations/siem.d.cts +1 -1
  64. package/dist/integrations/siem.d.ts +1 -1
  65. package/dist/integrations/skyfire.cjs +166 -0
  66. package/dist/integrations/skyfire.cjs.map +1 -0
  67. package/dist/integrations/skyfire.d.cts +80 -0
  68. package/dist/integrations/skyfire.d.ts +80 -0
  69. package/dist/integrations/skyfire.js +140 -0
  70. package/dist/integrations/skyfire.js.map +1 -0
  71. package/dist/integrations/stripe-acp.d.cts +1 -1
  72. package/dist/integrations/stripe-acp.d.ts +1 -1
  73. package/dist/integrations/ucp.d.cts +1 -1
  74. package/dist/integrations/ucp.d.ts +1 -1
  75. package/dist/integrations/vercel-ai.d.cts +1 -1
  76. package/dist/integrations/vercel-ai.d.ts +1 -1
  77. package/dist/integrations/x402.cjs +211 -0
  78. package/dist/integrations/x402.cjs.map +1 -0
  79. package/dist/integrations/x402.d.cts +87 -0
  80. package/dist/integrations/x402.d.ts +87 -0
  81. package/dist/integrations/x402.js +185 -0
  82. package/dist/integrations/x402.js.map +1 -0
  83. package/dist/{types-Cb6V-boJ.d.cts → types-zzK9YOoa.d.cts} +86 -1
  84. package/dist/{types-Cb6V-boJ.d.ts → types-zzK9YOoa.d.ts} +86 -1
  85. package/package.json +91 -1
@@ -0,0 +1,174 @@
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/plaid.ts
21
+ var plaid_exports = {};
22
+ __export(plaid_exports, {
23
+ VorimPlaid: () => VorimPlaid,
24
+ createVorimPlaid: () => createVorimPlaid
25
+ });
26
+ module.exports = __toCommonJS(plaid_exports);
27
+ var VorimPlaid = class _VorimPlaid {
28
+ sdk;
29
+ minTrustScore;
30
+ requiredScope;
31
+ environment;
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
+ this.environment = config?.environment ?? "sandbox";
38
+ }
39
+ /**
40
+ * Verify an agent is authorized to initiate a Plaid transfer, to run before
41
+ * POST /transfer/authorization/create. Gate: transact scope → active status →
42
+ * trust threshold. Every outcome is audit-logged with the environment tag.
43
+ */
44
+ async authorizeTransfer(req) {
45
+ const threshold = req.minTrustScore ?? this.minTrustScore;
46
+ try {
47
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
48
+ if (!perm.allowed) {
49
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
50
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
51
+ }
52
+ } catch (e) {
53
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: e.message });
54
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
55
+ }
56
+ let score = 0;
57
+ let status = "unknown";
58
+ try {
59
+ const trust = await this.sdk.verify(req.agentId);
60
+ score = trust.trust_score ?? 0;
61
+ status = trust.status ?? "unknown";
62
+ } catch {
63
+ }
64
+ if (status !== "active") {
65
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: `Status: ${status}` });
66
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
67
+ }
68
+ if (score < threshold) {
69
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
70
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
71
+ }
72
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "success", req, { trust_score: score });
73
+ return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
74
+ }
75
+ /** Log Plaid's own authorization decision (approved / declined / user_action_required). */
76
+ async logAuthorizationDecision(agentId, authorizationId, decision, req) {
77
+ const result = decision === "approved" ? "success" : decision === "declined" ? "denied" : "success";
78
+ await this.logEvent(agentId, "plaid.transfer.decision", result, req, { authorization_id: authorizationId, decision });
79
+ }
80
+ /** Log that a Plaid transfer was created (after /transfer/create). */
81
+ async logTransferCreated(agentId, transferId, req) {
82
+ await this.logEvent(agentId, "plaid.transfer.created", "success", req, { transfer_id: transferId });
83
+ }
84
+ /** Log that a Plaid transfer settled. */
85
+ async logTransferSettled(agentId, transferId, req) {
86
+ await this.logEvent(agentId, "plaid.transfer.settled", "success", req, { transfer_id: transferId });
87
+ }
88
+ /** Log that a Plaid transfer was returned or failed. */
89
+ async logTransferFailed(agentId, transferId, reason, req) {
90
+ await this.logEvent(agentId, "plaid.transfer.failed", "error", req, { transfer_id: transferId, fail_reason: reason });
91
+ }
92
+ /**
93
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
94
+ * agent authorization.
95
+ *
96
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
97
+ * `authenticate` to verify the caller-to-agent binding. This gates real money
98
+ * movement in production — wiring `authenticate` is strongly recommended.
99
+ */
100
+ middleware(options) {
101
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
102
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
103
+ const authenticate = options?.authenticate;
104
+ if (!authenticate && !_VorimPlaid._warnedNoAuth) {
105
+ _VorimPlaid._warnedNoAuth = true;
106
+ console.warn(
107
+ "[vorim] VorimPlaid.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). This gates money movement \u2014 pass `authenticate`."
108
+ );
109
+ }
110
+ return async (req, res, next) => {
111
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
112
+ if (!agentId) {
113
+ res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
114
+ return;
115
+ }
116
+ if (authenticate) {
117
+ let bound = false;
118
+ try {
119
+ bound = await authenticate(agentId, req);
120
+ } catch {
121
+ bound = false;
122
+ }
123
+ if (!bound) {
124
+ res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
125
+ return;
126
+ }
127
+ }
128
+ const auth = await this.authorizeTransfer({
129
+ agentId,
130
+ amount: req.body?.amount || 0,
131
+ currency: req.body?.currency || "usd",
132
+ counterparty: req.body?.counterparty || "",
133
+ achClass: req.body?.achClass || "ppd",
134
+ minTrustScore: threshold
135
+ });
136
+ if (!auth.authorized) {
137
+ res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to move money", trust_score: auth.trustScore, status: auth.status } });
138
+ return;
139
+ }
140
+ req.vorimAuthorization = auth;
141
+ next();
142
+ };
143
+ }
144
+ async logEvent(agentId, action, result, req, metadata) {
145
+ try {
146
+ await this.sdk.emit({
147
+ agent_id: agentId,
148
+ event_type: "api_request",
149
+ action,
150
+ result,
151
+ resource: req?.counterparty || "",
152
+ metadata: {
153
+ provider: "plaid",
154
+ environment: this.environment,
155
+ amount: req?.amount || 0,
156
+ currency: req?.currency || "",
157
+ counterparty: req?.counterparty || "",
158
+ ach_class: req?.achClass || "",
159
+ ...metadata
160
+ }
161
+ });
162
+ } catch {
163
+ }
164
+ }
165
+ };
166
+ function createVorimPlaid(sdk, config) {
167
+ return new VorimPlaid(sdk, config);
168
+ }
169
+ // Annotate the CommonJS export names for ESM import in node:
170
+ 0 && (module.exports = {
171
+ VorimPlaid,
172
+ createVorimPlaid
173
+ });
174
+ //# sourceMappingURL=plaid.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/plaid.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Plaid Transfer Integration (SANDBOX-READY)\n//\n// ⚠️ SANDBOX / EVALUATION. Plaid's Transfer product moves real money over ACH,\n// but PRODUCTION access requires Plaid application review + KYC/underwriting\n// (control-person verification, EDD for restricted industries) — an agent\n// cannot self-onboard. This wrapper is fully usable against Plaid's self-serve\n// SANDBOX today, and drops straight onto production once your Plaid Transfer\n// application is approved. The `environment` field defaults to 'sandbox' and is\n// recorded on every audit event so sandbox and production activity never blur.\n//\n// Wrap point: Plaid's two-step transfer flow —\n// POST /transfer/authorization/create → returns a decision\n// POST /transfer/create → requires the authorization_id\n// This layer verifies the AGENT (transact scope, active, trust) before the\n// authorization step and signs the transfer lifecycle. It does NOT call Plaid,\n// hold Plaid credentials, or move money — it authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimPlaid } from '@vorim/sdk/integrations/plaid';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const plaid = createVorimPlaid(vorim, { environment: 'sandbox', minTrustScore: 70 });\n//\n// const auth = await plaid.authorizeTransfer({\n// agentId: 'agid_abc123',\n// amount: 25000, // smallest unit (cents)\n// currency: 'usd',\n// counterparty: 'legal name / account ref',\n// achClass: 'ppd',\n// });\n// if (auth.authorized) {\n// // ... POST /transfer/authorization/create then /transfer/create, then:\n// await plaid.logTransferCreated(auth.agentId, transferId, { amount: 25000 });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport type PlaidEnvironment = 'sandbox' | 'production';\nexport type PlaidAchClass = 'ppd' | 'ccd' | 'web' | 'tel';\n\nexport interface PlaidConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n /** 'sandbox' (default) or 'production'. Recorded on every audit event. */\n environment?: PlaidEnvironment;\n}\n\nexport interface PlaidTransferRequest {\n /** The Vorim agent id initiating the transfer. */\n agentId: string;\n /** Amount in the smallest currency unit (cents). */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** Destination account / counterparty reference (Plaid uses a legal name). */\n counterparty?: string;\n /** ACH class (ppd/ccd/web/tel). */\n achClass?: PlaidAchClass;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface PlaidAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimPlaid {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private environment: PlaidEnvironment;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<PlaidConfig>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n this.environment = config?.environment ?? 'sandbox';\n }\n\n /**\n * Verify an agent is authorized to initiate a Plaid transfer, to run before\n * POST /transfer/authorization/create. Gate: transact scope → active status →\n * trust threshold. Every outcome is audit-logged with the environment tag.\n */\n async authorizeTransfer(req: PlaidTransferRequest): Promise<PlaidAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n\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, 'plaid.transfer.authorize', 'denied', req, { reason: `Missing ${this.requiredScope}` });\n return { authorized: false, agentId: req.agentId, trustScore: 0, status: 'unknown', reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };\n }\n } catch (e: any) {\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'denied', req, { reason: e.message });\n return { authorized: false, agentId: req.agentId, trustScore: 0, status: 'unknown', reason: `Permission check failed: ${e.message}`, scopeVerified: false };\n }\n\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 { /* treated as not-active below */ }\n\n if (status !== 'active') {\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'denied', req, { reason: `Status: ${status}` });\n return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };\n }\n\n if (score < threshold) {\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'denied', req, { reason: `Score ${score} < ${threshold}` });\n return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };\n }\n\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log Plaid's own authorization decision (approved / declined / user_action_required). */\n async logAuthorizationDecision(agentId: string, authorizationId: string, decision: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n const result = decision === 'approved' ? 'success' : decision === 'declined' ? 'denied' : 'success';\n await this.logEvent(agentId, 'plaid.transfer.decision', result, req, { authorization_id: authorizationId, decision });\n }\n\n /** Log that a Plaid transfer was created (after /transfer/create). */\n async logTransferCreated(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'plaid.transfer.created', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a Plaid transfer settled. */\n async logTransferSettled(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'plaid.transfer.settled', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a Plaid transfer was returned or failed. */\n async logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'plaid.transfer.failed', 'error', req, { transfer_id: transferId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a transfer-initiation endpoint on\n * agent authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass\n * `authenticate` to verify the caller-to-agent binding. This gates real money\n * movement in production — wiring `authenticate` is strongly recommended.\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 && !VorimPlaid._warnedNoAuth) {\n VorimPlaid._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimPlaid.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). This gates money ' +\n 'movement — 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 if (!agentId) {\n res.status(401).json({ error: { code: 'MISSING_AGENT_ID', message: `Agent ID required in ${header} header` } });\n return;\n }\n if (authenticate) {\n let bound = false;\n try { bound = await authenticate(agentId, req); } catch { bound = false; }\n if (!bound) {\n res.status(401).json({ error: { code: 'AGENT_BINDING_UNVERIFIED', message: 'Caller is not authenticated as the named agent' } });\n return;\n }\n }\n const auth = await this.authorizeTransfer({\n agentId,\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n counterparty: req.body?.counterparty || '',\n achClass: req.body?.achClass || 'ppd',\n minTrustScore: threshold,\n });\n if (!auth.authorized) {\n res.status(403).json({ error: { code: 'UNAUTHORIZED_AGENT', message: auth.reason || 'Agent not authorized to move money', trust_score: auth.trustScore, status: auth.status } });\n return;\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<PlaidTransferRequest>,\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?.counterparty || '',\n metadata: {\n provider: 'plaid',\n environment: this.environment,\n amount: req?.amount || 0,\n currency: req?.currency || '',\n counterparty: req?.counterparty || '',\n ach_class: req?.achClass || '',\n ...metadata,\n },\n });\n } catch { /* never block the payment flow */ }\n }\n}\n\n/**\n * Create a VorimPlaid instance (sandbox by default).\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimPlaid } from '@vorim/sdk/integrations/plaid';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const plaid = createVorimPlaid(vorim, { environment: 'sandbox', minTrustScore: 70 });\n * const auth = await plaid.authorizeTransfer({ agentId: 'agid_abc', amount: 25000, counterparty: 'Jane Doe' });\n * ```\n */\nexport function createVorimPlaid(sdk: VorimSDK, config?: Partial<PlaidConfig>): VorimPlaid {\n return new VorimPlaid(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4EO,IAAM,aAAN,MAAM,YAAW;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACR,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAA+B;AACxD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,cAAc,QAAQ,eAAe;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,KAAwD;AAC9E,UAAM,YAAY,IAAI,iBAAiB,KAAK;AAE5C,QAAI;AACF,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,IAAI,SAAS,KAAK,aAAoB;AACxE,UAAI,CAAE,KAAa,SAAS;AAC1B,cAAM,KAAK,SAAS,IAAI,SAAS,4BAA4B,UAAU,KAAK,EAAE,QAAQ,WAAW,KAAK,aAAa,GAAG,CAAC;AACvH,eAAO,EAAE,YAAY,OAAO,SAAS,IAAI,SAAS,YAAY,GAAG,QAAQ,WAAW,QAAQ,uBAAuB,KAAK,aAAa,eAAe,eAAe,MAAM;AAAA,MAC3K;AAAA,IACF,SAAS,GAAQ;AACf,YAAM,KAAK,SAAS,IAAI,SAAS,4BAA4B,UAAU,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC;AACjG,aAAO,EAAE,YAAY,OAAO,SAAS,IAAI,SAAS,YAAY,GAAG,QAAQ,WAAW,QAAQ,4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AAI,MAAM,UAAU;AAAA,QAC5B,UAAU,IAAI,MAAM,YAAY;AAAA,QAChC,cAAc,IAAI,MAAM,gBAAgB;AAAA,QACxC,UAAU,IAAI,MAAM,YAAY;AAAA,QAChC,eAAe;AAAA,MACjB,CAAC;AACD,UAAI,CAAC,KAAK,YAAY;AACpB,YAAI,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,SAAS,KAAK,UAAU,sCAAsC,aAAa,KAAK,YAAY,QAAQ,KAAK,OAAO,EAAE,CAAC;AAC/K;AAAA,MACF;AACA,UAAI,qBAAqB;AACzB,WAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,MAAc,SACZ,SACA,QACA,QACA,KACA,UACe;AACf,QAAI;AACF,YAAM,KAAK,IAAI,KAAK;AAAA,QAClB,UAAU;AAAA,QACV,YAAY;AAAA,QACZ;AAAA,QACA;AAAA,QACA,UAAU,KAAK,gBAAgB;AAAA,QAC/B,UAAU;AAAA,UACR,UAAU;AAAA,UACV,aAAa,KAAK;AAAA,UAClB,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,cAAc,KAAK,gBAAgB;AAAA,UACnC,WAAW,KAAK,YAAY;AAAA,UAC5B,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAqC;AAAA,EAC/C;AACF;AAcO,SAAS,iBAAiB,KAAe,QAA2C;AACzF,SAAO,IAAI,WAAW,KAAK,MAAM;AACnC;","names":[]}
@@ -0,0 +1,86 @@
1
+ import { VorimSDK } from '../index.cjs';
2
+ import '../types-zzK9YOoa.cjs';
3
+
4
+ type PlaidEnvironment = 'sandbox' | 'production';
5
+ type PlaidAchClass = 'ppd' | 'ccd' | 'web' | 'tel';
6
+ interface PlaidConfig {
7
+ apiKey: string;
8
+ baseUrl?: string;
9
+ minTrustScore?: number;
10
+ requiredScope?: string;
11
+ /** 'sandbox' (default) or 'production'. Recorded on every audit event. */
12
+ environment?: PlaidEnvironment;
13
+ }
14
+ interface PlaidTransferRequest {
15
+ /** The Vorim agent id initiating the transfer. */
16
+ agentId: string;
17
+ /** Amount in the smallest currency unit (cents). */
18
+ amount?: number;
19
+ /** Currency code. */
20
+ currency?: string;
21
+ /** Destination account / counterparty reference (Plaid uses a legal name). */
22
+ counterparty?: string;
23
+ /** ACH class (ppd/ccd/web/tel). */
24
+ achClass?: PlaidAchClass;
25
+ /** Per-call override of the trust threshold. */
26
+ minTrustScore?: number;
27
+ }
28
+ interface PlaidAuthorization {
29
+ authorized: boolean;
30
+ agentId: string;
31
+ trustScore: number;
32
+ status: string;
33
+ reason?: string;
34
+ scopeVerified: boolean;
35
+ }
36
+ declare class VorimPlaid {
37
+ private sdk;
38
+ private minTrustScore;
39
+ private requiredScope;
40
+ private environment;
41
+ private static _warnedNoAuth;
42
+ constructor(sdk: VorimSDK, config?: Partial<PlaidConfig>);
43
+ /**
44
+ * Verify an agent is authorized to initiate a Plaid transfer, to run before
45
+ * POST /transfer/authorization/create. Gate: transact scope → active status →
46
+ * trust threshold. Every outcome is audit-logged with the environment tag.
47
+ */
48
+ authorizeTransfer(req: PlaidTransferRequest): Promise<PlaidAuthorization>;
49
+ /** Log Plaid's own authorization decision (approved / declined / user_action_required). */
50
+ logAuthorizationDecision(agentId: string, authorizationId: string, decision: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
51
+ /** Log that a Plaid transfer was created (after /transfer/create). */
52
+ logTransferCreated(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
53
+ /** Log that a Plaid transfer settled. */
54
+ logTransferSettled(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
55
+ /** Log that a Plaid transfer was returned or failed. */
56
+ logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
57
+ /**
58
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
59
+ * agent authorization.
60
+ *
61
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
62
+ * `authenticate` to verify the caller-to-agent binding. This gates real money
63
+ * movement in production — wiring `authenticate` is strongly recommended.
64
+ */
65
+ middleware(options?: {
66
+ agentIdHeader?: string;
67
+ minTrustScore?: number;
68
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
69
+ }): (req: any, res: any, next: any) => Promise<void>;
70
+ private logEvent;
71
+ }
72
+ /**
73
+ * Create a VorimPlaid instance (sandbox by default).
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * import createVorim from '@vorim/sdk';
78
+ * import { createVorimPlaid } from '@vorim/sdk/integrations/plaid';
79
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
80
+ * const plaid = createVorimPlaid(vorim, { environment: 'sandbox', minTrustScore: 70 });
81
+ * const auth = await plaid.authorizeTransfer({ agentId: 'agid_abc', amount: 25000, counterparty: 'Jane Doe' });
82
+ * ```
83
+ */
84
+ declare function createVorimPlaid(sdk: VorimSDK, config?: Partial<PlaidConfig>): VorimPlaid;
85
+
86
+ export { type PlaidAchClass, type PlaidAuthorization, type PlaidConfig, type PlaidEnvironment, type PlaidTransferRequest, VorimPlaid, createVorimPlaid };
@@ -0,0 +1,86 @@
1
+ import { VorimSDK } from '../index.js';
2
+ import '../types-zzK9YOoa.js';
3
+
4
+ type PlaidEnvironment = 'sandbox' | 'production';
5
+ type PlaidAchClass = 'ppd' | 'ccd' | 'web' | 'tel';
6
+ interface PlaidConfig {
7
+ apiKey: string;
8
+ baseUrl?: string;
9
+ minTrustScore?: number;
10
+ requiredScope?: string;
11
+ /** 'sandbox' (default) or 'production'. Recorded on every audit event. */
12
+ environment?: PlaidEnvironment;
13
+ }
14
+ interface PlaidTransferRequest {
15
+ /** The Vorim agent id initiating the transfer. */
16
+ agentId: string;
17
+ /** Amount in the smallest currency unit (cents). */
18
+ amount?: number;
19
+ /** Currency code. */
20
+ currency?: string;
21
+ /** Destination account / counterparty reference (Plaid uses a legal name). */
22
+ counterparty?: string;
23
+ /** ACH class (ppd/ccd/web/tel). */
24
+ achClass?: PlaidAchClass;
25
+ /** Per-call override of the trust threshold. */
26
+ minTrustScore?: number;
27
+ }
28
+ interface PlaidAuthorization {
29
+ authorized: boolean;
30
+ agentId: string;
31
+ trustScore: number;
32
+ status: string;
33
+ reason?: string;
34
+ scopeVerified: boolean;
35
+ }
36
+ declare class VorimPlaid {
37
+ private sdk;
38
+ private minTrustScore;
39
+ private requiredScope;
40
+ private environment;
41
+ private static _warnedNoAuth;
42
+ constructor(sdk: VorimSDK, config?: Partial<PlaidConfig>);
43
+ /**
44
+ * Verify an agent is authorized to initiate a Plaid transfer, to run before
45
+ * POST /transfer/authorization/create. Gate: transact scope → active status →
46
+ * trust threshold. Every outcome is audit-logged with the environment tag.
47
+ */
48
+ authorizeTransfer(req: PlaidTransferRequest): Promise<PlaidAuthorization>;
49
+ /** Log Plaid's own authorization decision (approved / declined / user_action_required). */
50
+ logAuthorizationDecision(agentId: string, authorizationId: string, decision: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
51
+ /** Log that a Plaid transfer was created (after /transfer/create). */
52
+ logTransferCreated(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
53
+ /** Log that a Plaid transfer settled. */
54
+ logTransferSettled(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
55
+ /** Log that a Plaid transfer was returned or failed. */
56
+ logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<PlaidTransferRequest>): Promise<void>;
57
+ /**
58
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
59
+ * agent authorization.
60
+ *
61
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
62
+ * `authenticate` to verify the caller-to-agent binding. This gates real money
63
+ * movement in production — wiring `authenticate` is strongly recommended.
64
+ */
65
+ middleware(options?: {
66
+ agentIdHeader?: string;
67
+ minTrustScore?: number;
68
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
69
+ }): (req: any, res: any, next: any) => Promise<void>;
70
+ private logEvent;
71
+ }
72
+ /**
73
+ * Create a VorimPlaid instance (sandbox by default).
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * import createVorim from '@vorim/sdk';
78
+ * import { createVorimPlaid } from '@vorim/sdk/integrations/plaid';
79
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
80
+ * const plaid = createVorimPlaid(vorim, { environment: 'sandbox', minTrustScore: 70 });
81
+ * const auth = await plaid.authorizeTransfer({ agentId: 'agid_abc', amount: 25000, counterparty: 'Jane Doe' });
82
+ * ```
83
+ */
84
+ declare function createVorimPlaid(sdk: VorimSDK, config?: Partial<PlaidConfig>): VorimPlaid;
85
+
86
+ export { type PlaidAchClass, type PlaidAuthorization, type PlaidConfig, type PlaidEnvironment, type PlaidTransferRequest, VorimPlaid, createVorimPlaid };
@@ -0,0 +1,148 @@
1
+ // src/integrations/plaid.ts
2
+ var VorimPlaid = class _VorimPlaid {
3
+ sdk;
4
+ minTrustScore;
5
+ requiredScope;
6
+ environment;
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
+ this.environment = config?.environment ?? "sandbox";
13
+ }
14
+ /**
15
+ * Verify an agent is authorized to initiate a Plaid transfer, to run before
16
+ * POST /transfer/authorization/create. Gate: transact scope → active status →
17
+ * trust threshold. Every outcome is audit-logged with the environment tag.
18
+ */
19
+ async authorizeTransfer(req) {
20
+ const threshold = req.minTrustScore ?? this.minTrustScore;
21
+ try {
22
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
23
+ if (!perm.allowed) {
24
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
25
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
26
+ }
27
+ } catch (e) {
28
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: e.message });
29
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
30
+ }
31
+ let score = 0;
32
+ let status = "unknown";
33
+ try {
34
+ const trust = await this.sdk.verify(req.agentId);
35
+ score = trust.trust_score ?? 0;
36
+ status = trust.status ?? "unknown";
37
+ } catch {
38
+ }
39
+ if (status !== "active") {
40
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: `Status: ${status}` });
41
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
42
+ }
43
+ if (score < threshold) {
44
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
45
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
46
+ }
47
+ await this.logEvent(req.agentId, "plaid.transfer.authorize", "success", req, { trust_score: score });
48
+ return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
49
+ }
50
+ /** Log Plaid's own authorization decision (approved / declined / user_action_required). */
51
+ async logAuthorizationDecision(agentId, authorizationId, decision, req) {
52
+ const result = decision === "approved" ? "success" : decision === "declined" ? "denied" : "success";
53
+ await this.logEvent(agentId, "plaid.transfer.decision", result, req, { authorization_id: authorizationId, decision });
54
+ }
55
+ /** Log that a Plaid transfer was created (after /transfer/create). */
56
+ async logTransferCreated(agentId, transferId, req) {
57
+ await this.logEvent(agentId, "plaid.transfer.created", "success", req, { transfer_id: transferId });
58
+ }
59
+ /** Log that a Plaid transfer settled. */
60
+ async logTransferSettled(agentId, transferId, req) {
61
+ await this.logEvent(agentId, "plaid.transfer.settled", "success", req, { transfer_id: transferId });
62
+ }
63
+ /** Log that a Plaid transfer was returned or failed. */
64
+ async logTransferFailed(agentId, transferId, reason, req) {
65
+ await this.logEvent(agentId, "plaid.transfer.failed", "error", req, { transfer_id: transferId, fail_reason: reason });
66
+ }
67
+ /**
68
+ * Express/Connect middleware that gates a transfer-initiation endpoint on
69
+ * agent authorization.
70
+ *
71
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
72
+ * `authenticate` to verify the caller-to-agent binding. This gates real money
73
+ * movement in production — wiring `authenticate` is strongly recommended.
74
+ */
75
+ middleware(options) {
76
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
77
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
78
+ const authenticate = options?.authenticate;
79
+ if (!authenticate && !_VorimPlaid._warnedNoAuth) {
80
+ _VorimPlaid._warnedNoAuth = true;
81
+ console.warn(
82
+ "[vorim] VorimPlaid.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). This gates money movement \u2014 pass `authenticate`."
83
+ );
84
+ }
85
+ return async (req, res, next) => {
86
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
87
+ if (!agentId) {
88
+ res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
89
+ return;
90
+ }
91
+ if (authenticate) {
92
+ let bound = false;
93
+ try {
94
+ bound = await authenticate(agentId, req);
95
+ } catch {
96
+ bound = false;
97
+ }
98
+ if (!bound) {
99
+ res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
100
+ return;
101
+ }
102
+ }
103
+ const auth = await this.authorizeTransfer({
104
+ agentId,
105
+ amount: req.body?.amount || 0,
106
+ currency: req.body?.currency || "usd",
107
+ counterparty: req.body?.counterparty || "",
108
+ achClass: req.body?.achClass || "ppd",
109
+ minTrustScore: threshold
110
+ });
111
+ if (!auth.authorized) {
112
+ res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to move money", trust_score: auth.trustScore, status: auth.status } });
113
+ return;
114
+ }
115
+ req.vorimAuthorization = auth;
116
+ next();
117
+ };
118
+ }
119
+ async logEvent(agentId, action, result, req, metadata) {
120
+ try {
121
+ await this.sdk.emit({
122
+ agent_id: agentId,
123
+ event_type: "api_request",
124
+ action,
125
+ result,
126
+ resource: req?.counterparty || "",
127
+ metadata: {
128
+ provider: "plaid",
129
+ environment: this.environment,
130
+ amount: req?.amount || 0,
131
+ currency: req?.currency || "",
132
+ counterparty: req?.counterparty || "",
133
+ ach_class: req?.achClass || "",
134
+ ...metadata
135
+ }
136
+ });
137
+ } catch {
138
+ }
139
+ }
140
+ };
141
+ function createVorimPlaid(sdk, config) {
142
+ return new VorimPlaid(sdk, config);
143
+ }
144
+ export {
145
+ VorimPlaid,
146
+ createVorimPlaid
147
+ };
148
+ //# sourceMappingURL=plaid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/plaid.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Plaid Transfer Integration (SANDBOX-READY)\n//\n// ⚠️ SANDBOX / EVALUATION. Plaid's Transfer product moves real money over ACH,\n// but PRODUCTION access requires Plaid application review + KYC/underwriting\n// (control-person verification, EDD for restricted industries) — an agent\n// cannot self-onboard. This wrapper is fully usable against Plaid's self-serve\n// SANDBOX today, and drops straight onto production once your Plaid Transfer\n// application is approved. The `environment` field defaults to 'sandbox' and is\n// recorded on every audit event so sandbox and production activity never blur.\n//\n// Wrap point: Plaid's two-step transfer flow —\n// POST /transfer/authorization/create → returns a decision\n// POST /transfer/create → requires the authorization_id\n// This layer verifies the AGENT (transact scope, active, trust) before the\n// authorization step and signs the transfer lifecycle. It does NOT call Plaid,\n// hold Plaid credentials, or move money — it authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimPlaid } from '@vorim/sdk/integrations/plaid';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const plaid = createVorimPlaid(vorim, { environment: 'sandbox', minTrustScore: 70 });\n//\n// const auth = await plaid.authorizeTransfer({\n// agentId: 'agid_abc123',\n// amount: 25000, // smallest unit (cents)\n// currency: 'usd',\n// counterparty: 'legal name / account ref',\n// achClass: 'ppd',\n// });\n// if (auth.authorized) {\n// // ... POST /transfer/authorization/create then /transfer/create, then:\n// await plaid.logTransferCreated(auth.agentId, transferId, { amount: 25000 });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport type PlaidEnvironment = 'sandbox' | 'production';\nexport type PlaidAchClass = 'ppd' | 'ccd' | 'web' | 'tel';\n\nexport interface PlaidConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n /** 'sandbox' (default) or 'production'. Recorded on every audit event. */\n environment?: PlaidEnvironment;\n}\n\nexport interface PlaidTransferRequest {\n /** The Vorim agent id initiating the transfer. */\n agentId: string;\n /** Amount in the smallest currency unit (cents). */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** Destination account / counterparty reference (Plaid uses a legal name). */\n counterparty?: string;\n /** ACH class (ppd/ccd/web/tel). */\n achClass?: PlaidAchClass;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface PlaidAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimPlaid {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private environment: PlaidEnvironment;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<PlaidConfig>) {\n this.sdk = sdk;\n this.minTrustScore = config?.minTrustScore ?? 50;\n this.requiredScope = config?.requiredScope ?? 'agent:transact';\n this.environment = config?.environment ?? 'sandbox';\n }\n\n /**\n * Verify an agent is authorized to initiate a Plaid transfer, to run before\n * POST /transfer/authorization/create. Gate: transact scope → active status →\n * trust threshold. Every outcome is audit-logged with the environment tag.\n */\n async authorizeTransfer(req: PlaidTransferRequest): Promise<PlaidAuthorization> {\n const threshold = req.minTrustScore ?? this.minTrustScore;\n\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, 'plaid.transfer.authorize', 'denied', req, { reason: `Missing ${this.requiredScope}` });\n return { authorized: false, agentId: req.agentId, trustScore: 0, status: 'unknown', reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };\n }\n } catch (e: any) {\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'denied', req, { reason: e.message });\n return { authorized: false, agentId: req.agentId, trustScore: 0, status: 'unknown', reason: `Permission check failed: ${e.message}`, scopeVerified: false };\n }\n\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 { /* treated as not-active below */ }\n\n if (status !== 'active') {\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'denied', req, { reason: `Status: ${status}` });\n return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };\n }\n\n if (score < threshold) {\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'denied', req, { reason: `Score ${score} < ${threshold}` });\n return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };\n }\n\n await this.logEvent(req.agentId, 'plaid.transfer.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log Plaid's own authorization decision (approved / declined / user_action_required). */\n async logAuthorizationDecision(agentId: string, authorizationId: string, decision: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n const result = decision === 'approved' ? 'success' : decision === 'declined' ? 'denied' : 'success';\n await this.logEvent(agentId, 'plaid.transfer.decision', result, req, { authorization_id: authorizationId, decision });\n }\n\n /** Log that a Plaid transfer was created (after /transfer/create). */\n async logTransferCreated(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'plaid.transfer.created', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a Plaid transfer settled. */\n async logTransferSettled(agentId: string, transferId: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'plaid.transfer.settled', 'success', req, { transfer_id: transferId });\n }\n\n /** Log that a Plaid transfer was returned or failed. */\n async logTransferFailed(agentId: string, transferId: string, reason?: string, req?: Partial<PlaidTransferRequest>): Promise<void> {\n await this.logEvent(agentId, 'plaid.transfer.failed', 'error', req, { transfer_id: transferId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a transfer-initiation endpoint on\n * agent authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass\n * `authenticate` to verify the caller-to-agent binding. This gates real money\n * movement in production — wiring `authenticate` is strongly recommended.\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 && !VorimPlaid._warnedNoAuth) {\n VorimPlaid._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimPlaid.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). This gates money ' +\n 'movement — 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 if (!agentId) {\n res.status(401).json({ error: { code: 'MISSING_AGENT_ID', message: `Agent ID required in ${header} header` } });\n return;\n }\n if (authenticate) {\n let bound = false;\n try { bound = await authenticate(agentId, req); } catch { bound = false; }\n if (!bound) {\n res.status(401).json({ error: { code: 'AGENT_BINDING_UNVERIFIED', message: 'Caller is not authenticated as the named agent' } });\n return;\n }\n }\n const auth = await this.authorizeTransfer({\n agentId,\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n counterparty: req.body?.counterparty || '',\n achClass: req.body?.achClass || 'ppd',\n minTrustScore: threshold,\n });\n if (!auth.authorized) {\n res.status(403).json({ error: { code: 'UNAUTHORIZED_AGENT', message: auth.reason || 'Agent not authorized to move money', trust_score: auth.trustScore, status: auth.status } });\n return;\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<PlaidTransferRequest>,\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?.counterparty || '',\n metadata: {\n provider: 'plaid',\n environment: this.environment,\n amount: req?.amount || 0,\n currency: req?.currency || '',\n counterparty: req?.counterparty || '',\n ach_class: req?.achClass || '',\n ...metadata,\n },\n });\n } catch { /* never block the payment flow */ }\n }\n}\n\n/**\n * Create a VorimPlaid instance (sandbox by default).\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimPlaid } from '@vorim/sdk/integrations/plaid';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const plaid = createVorimPlaid(vorim, { environment: 'sandbox', minTrustScore: 70 });\n * const auth = await plaid.authorizeTransfer({ agentId: 'agid_abc', amount: 25000, counterparty: 'Jane Doe' });\n * ```\n */\nexport function createVorimPlaid(sdk: VorimSDK, config?: Partial<PlaidConfig>): VorimPlaid {\n return new VorimPlaid(sdk, config);\n}\n"],"mappings":";AA4EO,IAAM,aAAN,MAAM,YAAW;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACR,OAAe,gBAAgB;AAAA,EAE/B,YAAY,KAAe,QAA+B;AACxD,SAAK,MAAM;AACX,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,gBAA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AAY;AAAA,QACZ;AAAA,QACA;AAAA,QACA,UAAU,KAAK,gBAAgB;AAAA,QAC/B,UAAU;AAAA,UACR,UAAU;AAAA,UACV,aAAa,KAAK;AAAA,UAClB,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,cAAc,KAAK,gBAAgB;AAAA,UACnC,WAAW,KAAK,YAAY;AAAA,UAC5B,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAqC;AAAA,EAC/C;AACF;AAcO,SAAS,iBAAiB,KAAe,QAA2C;AACzF,SAAO,IAAI,WAAW,KAAK,MAAM;AACnC;","names":[]}
@@ -1,4 +1,4 @@
1
- import { a as AuditEventInput } from '../types-Cb6V-boJ.cjs';
1
+ import { a as AuditEventInput } from '../types-zzK9YOoa.cjs';
2
2
 
3
3
  type SiemSink = 'otlp-http' | 'splunk-hec' | 'elasticsearch';
4
4
  interface SiemForwarderConfig {
@@ -1,4 +1,4 @@
1
- import { a as AuditEventInput } from '../types-Cb6V-boJ.js';
1
+ import { a as AuditEventInput } from '../types-zzK9YOoa.js';
2
2
 
3
3
  type SiemSink = 'otlp-http' | 'splunk-hec' | 'elasticsearch';
4
4
  interface SiemForwarderConfig {