@vorim/sdk 3.8.0 → 3.9.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 (77) 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.cjs +280 -0
  30. package/dist/integrations/hermes.cjs.map +1 -0
  31. package/dist/integrations/hermes.d.cts +60 -0
  32. package/dist/integrations/hermes.d.ts +60 -0
  33. package/dist/integrations/hermes.js +242 -0
  34. package/dist/integrations/hermes.js.map +1 -0
  35. package/dist/integrations/langchain.d.cts +1 -1
  36. package/dist/integrations/langchain.d.ts +1 -1
  37. package/dist/integrations/langgraph.d.cts +1 -1
  38. package/dist/integrations/langgraph.d.ts +1 -1
  39. package/dist/integrations/llamaindex.d.cts +1 -1
  40. package/dist/integrations/llamaindex.d.ts +1 -1
  41. package/dist/integrations/nekuda.cjs +165 -0
  42. package/dist/integrations/nekuda.cjs.map +1 -0
  43. package/dist/integrations/nekuda.d.cts +79 -0
  44. package/dist/integrations/nekuda.d.ts +79 -0
  45. package/dist/integrations/nekuda.js +139 -0
  46. package/dist/integrations/nekuda.js.map +1 -0
  47. package/dist/integrations/openai.d.cts +1 -1
  48. package/dist/integrations/openai.d.ts +1 -1
  49. package/dist/integrations/paypal-agent.cjs +215 -0
  50. package/dist/integrations/paypal-agent.cjs.map +1 -0
  51. package/dist/integrations/paypal-agent.d.cts +87 -0
  52. package/dist/integrations/paypal-agent.d.ts +87 -0
  53. package/dist/integrations/paypal-agent.js +189 -0
  54. package/dist/integrations/paypal-agent.js.map +1 -0
  55. package/dist/integrations/siem.d.cts +1 -1
  56. package/dist/integrations/siem.d.ts +1 -1
  57. package/dist/integrations/skyfire.cjs +166 -0
  58. package/dist/integrations/skyfire.cjs.map +1 -0
  59. package/dist/integrations/skyfire.d.cts +80 -0
  60. package/dist/integrations/skyfire.d.ts +80 -0
  61. package/dist/integrations/skyfire.js +140 -0
  62. package/dist/integrations/skyfire.js.map +1 -0
  63. package/dist/integrations/stripe-acp.d.cts +1 -1
  64. package/dist/integrations/stripe-acp.d.ts +1 -1
  65. package/dist/integrations/ucp.d.cts +1 -1
  66. package/dist/integrations/ucp.d.ts +1 -1
  67. package/dist/integrations/vercel-ai.d.cts +1 -1
  68. package/dist/integrations/vercel-ai.d.ts +1 -1
  69. package/dist/integrations/x402.cjs +211 -0
  70. package/dist/integrations/x402.cjs.map +1 -0
  71. package/dist/integrations/x402.d.cts +87 -0
  72. package/dist/integrations/x402.d.ts +87 -0
  73. package/dist/integrations/x402.js +185 -0
  74. package/dist/integrations/x402.js.map +1 -0
  75. package/dist/{types-Cb6V-boJ.d.cts → types-zzK9YOoa.d.cts} +86 -1
  76. package/dist/{types-Cb6V-boJ.d.ts → types-zzK9YOoa.d.ts} +86 -1
  77. package/package.json +83 -2
@@ -0,0 +1,79 @@
1
+ import { VorimSDK } from '../index.js';
2
+ import '../types-zzK9YOoa.js';
3
+
4
+ interface NekudaConfig {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ minTrustScore?: number;
8
+ requiredScope?: string;
9
+ }
10
+ interface NekudaMandateRequest {
11
+ /** The Vorim agent id creating the mandate. */
12
+ agentId: string;
13
+ /** The merchant the purchase is with. */
14
+ merchant?: string;
15
+ /** The product / item being purchased. */
16
+ product?: string;
17
+ /** Amount in the smallest currency unit. */
18
+ amount?: number;
19
+ /** Currency code. */
20
+ currency?: string;
21
+ /** Per-call override of the trust threshold. */
22
+ minTrustScore?: number;
23
+ }
24
+ interface NekudaAuthorization {
25
+ authorized: boolean;
26
+ agentId: string;
27
+ trustScore: number;
28
+ status: string;
29
+ reason?: string;
30
+ scopeVerified: boolean;
31
+ }
32
+ declare class VorimNekuda {
33
+ private sdk;
34
+ private minTrustScore;
35
+ private requiredScope;
36
+ private static _warnedNoAuth;
37
+ constructor(sdk: VorimSDK, config?: Partial<NekudaConfig>);
38
+ /**
39
+ * Verify an agent is authorized to create a Nekuda mandate. The mandate is
40
+ * the purchase-intent authorization step (before any card reveal), so it is
41
+ * the right chokepoint. Same gate: scope → active status → trust.
42
+ */
43
+ authorizeMandate(req: NekudaMandateRequest): Promise<NekudaAuthorization>;
44
+ /** Log that a Nekuda mandate was created. */
45
+ logMandateCreated(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
46
+ /** Log that a card-reveal token was requested against a mandate (card injected at checkout). */
47
+ logCardRevealed(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
48
+ /** Log that a Nekuda purchase/charge failed. */
49
+ logMandateFailed(agentId: string, mandateId: string, reason?: string, req?: Partial<NekudaMandateRequest>): Promise<void>;
50
+ /**
51
+ * Express/Connect middleware that gates a mandate-creation endpoint on agent
52
+ * authorization.
53
+ *
54
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
55
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
56
+ * one-time warning is logged.
57
+ */
58
+ middleware(options?: {
59
+ agentIdHeader?: string;
60
+ minTrustScore?: number;
61
+ authenticate?: (agentId: string, req: any) => boolean | Promise<boolean>;
62
+ }): (req: any, res: any, next: any) => Promise<void>;
63
+ private logEvent;
64
+ }
65
+ /**
66
+ * Create a VorimNekuda instance.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import createVorim from '@vorim/sdk';
71
+ * import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';
72
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
73
+ * const nekuda = createVorimNekuda(vorim, { minTrustScore: 70 });
74
+ * const auth = await nekuda.authorizeMandate({ agentId: 'agid_abc', merchant: 'shop', amount: 8999 });
75
+ * ```
76
+ */
77
+ declare function createVorimNekuda(sdk: VorimSDK, config?: Partial<NekudaConfig>): VorimNekuda;
78
+
79
+ export { type NekudaAuthorization, type NekudaConfig, type NekudaMandateRequest, VorimNekuda, createVorimNekuda };
@@ -0,0 +1,139 @@
1
+ // src/integrations/nekuda.ts
2
+ var VorimNekuda = class _VorimNekuda {
3
+ sdk;
4
+ minTrustScore;
5
+ requiredScope;
6
+ static _warnedNoAuth = false;
7
+ constructor(sdk, config) {
8
+ this.sdk = sdk;
9
+ this.minTrustScore = config?.minTrustScore ?? 50;
10
+ this.requiredScope = config?.requiredScope ?? "agent:transact";
11
+ }
12
+ /**
13
+ * Verify an agent is authorized to create a Nekuda mandate. The mandate is
14
+ * the purchase-intent authorization step (before any card reveal), so it is
15
+ * the right chokepoint. Same gate: scope → active status → trust.
16
+ */
17
+ async authorizeMandate(req) {
18
+ const threshold = req.minTrustScore ?? this.minTrustScore;
19
+ try {
20
+ const perm = await this.sdk.check(req.agentId, this.requiredScope);
21
+ if (!perm.allowed) {
22
+ await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Missing ${this.requiredScope}` });
23
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Agent does not have ${this.requiredScope} permission`, scopeVerified: false };
24
+ }
25
+ } catch (e) {
26
+ await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: e.message });
27
+ return { authorized: false, agentId: req.agentId, trustScore: 0, status: "unknown", reason: `Permission check failed: ${e.message}`, scopeVerified: false };
28
+ }
29
+ let score = 0;
30
+ let status = "unknown";
31
+ try {
32
+ const trust = await this.sdk.verify(req.agentId);
33
+ score = trust.trust_score ?? 0;
34
+ status = trust.status ?? "unknown";
35
+ } catch {
36
+ }
37
+ if (status !== "active") {
38
+ await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Status: ${status}` });
39
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Agent is ${status}, not active`, scopeVerified: true };
40
+ }
41
+ if (score < threshold) {
42
+ await this.logEvent(req.agentId, "nekuda.mandate.authorize", "denied", req, { reason: `Score ${score} < ${threshold}` });
43
+ return { authorized: false, agentId: req.agentId, trustScore: score, status, reason: `Trust score ${score} is below minimum ${threshold}`, scopeVerified: true };
44
+ }
45
+ await this.logEvent(req.agentId, "nekuda.mandate.authorize", "success", req, { trust_score: score });
46
+ return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };
47
+ }
48
+ /** Log that a Nekuda mandate was created. */
49
+ async logMandateCreated(agentId, mandateId, req) {
50
+ await this.logEvent(agentId, "nekuda.mandate.created", "success", req, { mandate_id: mandateId });
51
+ }
52
+ /** Log that a card-reveal token was requested against a mandate (card injected at checkout). */
53
+ async logCardRevealed(agentId, mandateId, req) {
54
+ await this.logEvent(agentId, "nekuda.card.revealed", "success", req, { mandate_id: mandateId });
55
+ }
56
+ /** Log that a Nekuda purchase/charge failed. */
57
+ async logMandateFailed(agentId, mandateId, reason, req) {
58
+ await this.logEvent(agentId, "nekuda.mandate.failed", "error", req, { mandate_id: mandateId, fail_reason: reason });
59
+ }
60
+ /**
61
+ * Express/Connect middleware that gates a mandate-creation endpoint on agent
62
+ * authorization.
63
+ *
64
+ * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass
65
+ * `authenticate` to verify the caller-to-agent binding. When omitted, a
66
+ * one-time warning is logged.
67
+ */
68
+ middleware(options) {
69
+ const header = options?.agentIdHeader ?? "x-vorim-agent-id";
70
+ const threshold = options?.minTrustScore ?? this.minTrustScore;
71
+ const authenticate = options?.authenticate;
72
+ if (!authenticate && !_VorimNekuda._warnedNoAuth) {
73
+ _VorimNekuda._warnedNoAuth = true;
74
+ console.warn(
75
+ "[vorim] VorimNekuda.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). Pass `authenticate`."
76
+ );
77
+ }
78
+ return async (req, res, next) => {
79
+ const agentId = req.headers?.[header] || req.headers?.[header.toLowerCase()] || "";
80
+ if (!agentId) {
81
+ res.status(401).json({ error: { code: "MISSING_AGENT_ID", message: `Agent ID required in ${header} header` } });
82
+ return;
83
+ }
84
+ if (authenticate) {
85
+ let bound = false;
86
+ try {
87
+ bound = await authenticate(agentId, req);
88
+ } catch {
89
+ bound = false;
90
+ }
91
+ if (!bound) {
92
+ res.status(401).json({ error: { code: "AGENT_BINDING_UNVERIFIED", message: "Caller is not authenticated as the named agent" } });
93
+ return;
94
+ }
95
+ }
96
+ const auth = await this.authorizeMandate({
97
+ agentId,
98
+ merchant: req.body?.merchant || "",
99
+ product: req.body?.product || "",
100
+ amount: req.body?.amount || 0,
101
+ currency: req.body?.currency || "usd",
102
+ minTrustScore: threshold
103
+ });
104
+ if (!auth.authorized) {
105
+ res.status(403).json({ error: { code: "UNAUTHORIZED_AGENT", message: auth.reason || "Agent not authorized to create a Nekuda mandate", trust_score: auth.trustScore, status: auth.status } });
106
+ return;
107
+ }
108
+ req.vorimAuthorization = auth;
109
+ next();
110
+ };
111
+ }
112
+ async logEvent(agentId, action, result, req, metadata) {
113
+ try {
114
+ await this.sdk.emit({
115
+ agent_id: agentId,
116
+ event_type: "api_request",
117
+ action,
118
+ result,
119
+ resource: req?.merchant || "",
120
+ metadata: {
121
+ merchant: req?.merchant || "",
122
+ product: req?.product || "",
123
+ amount: req?.amount || 0,
124
+ currency: req?.currency || "",
125
+ ...metadata
126
+ }
127
+ });
128
+ } catch {
129
+ }
130
+ }
131
+ };
132
+ function createVorimNekuda(sdk, config) {
133
+ return new VorimNekuda(sdk, config);
134
+ }
135
+ export {
136
+ VorimNekuda,
137
+ createVorimNekuda
138
+ };
139
+ //# sourceMappingURL=nekuda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/nekuda.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Nekuda Integration\n//\n// Nekuda gives an AI agent a secure wallet + payment SDK: a user delegates\n// payment credentials, and the agent creates a \"mandate\" (purchase intent:\n// product / price / currency / merchant) which is then used to request a\n// just-in-time card-reveal token at checkout.\n//\n// This integration adds Vorim's identity, permission, and audit layer IN FRONT\n// of a Nekuda mandate: before an agent creates a mandate or requests a card\n// reveal, it verifies the agent holds `transact`, is active, and clears a trust\n// threshold, then records the mandate + reveal + charge lifecycle on a signed,\n// tamper-evident audit trail. It does NOT create Nekuda mandates or handle card\n// data — Nekuda does the payment; Vorim authorizes and attests.\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const nekuda = createVorimNekuda(vorim, { minTrustScore: 60 });\n//\n// const auth = await nekuda.authorizeMandate({\n// agentId: 'agid_abc123',\n// merchant: 'acme-store',\n// product: 'running-shoes',\n// amount: 8999,\n// currency: 'usd',\n// });\n// if (auth.authorized) {\n// // ... create the Nekuda mandate, then:\n// await nekuda.logMandateCreated(auth.agentId, mandateId, { merchant, amount });\n// }\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\n\nexport interface NekudaConfig {\n apiKey: string;\n baseUrl?: string;\n minTrustScore?: number;\n requiredScope?: string;\n}\n\nexport interface NekudaMandateRequest {\n /** The Vorim agent id creating the mandate. */\n agentId: string;\n /** The merchant the purchase is with. */\n merchant?: string;\n /** The product / item being purchased. */\n product?: string;\n /** Amount in the smallest currency unit. */\n amount?: number;\n /** Currency code. */\n currency?: string;\n /** Per-call override of the trust threshold. */\n minTrustScore?: number;\n}\n\nexport interface NekudaAuthorization {\n authorized: boolean;\n agentId: string;\n trustScore: number;\n status: string;\n reason?: string;\n scopeVerified: boolean;\n}\n\nexport class VorimNekuda {\n private sdk: VorimSDK;\n private minTrustScore: number;\n private requiredScope: string;\n private static _warnedNoAuth = false;\n\n constructor(sdk: VorimSDK, config?: Partial<NekudaConfig>) {\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 Nekuda mandate. The mandate is\n * the purchase-intent authorization step (before any card reveal), so it is\n * the right chokepoint. Same gate: scope → active status → trust.\n */\n async authorizeMandate(req: NekudaMandateRequest): Promise<NekudaAuthorization> {\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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.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, 'nekuda.mandate.authorize', 'success', req, { trust_score: score });\n return { authorized: true, agentId: req.agentId, trustScore: score, status, scopeVerified: true };\n }\n\n /** Log that a Nekuda mandate was created. */\n async logMandateCreated(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.mandate.created', 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that a card-reveal token was requested against a mandate (card injected at checkout). */\n async logCardRevealed(agentId: string, mandateId: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.card.revealed', 'success', req, { mandate_id: mandateId });\n }\n\n /** Log that a Nekuda purchase/charge failed. */\n async logMandateFailed(agentId: string, mandateId: string, reason?: string, req?: Partial<NekudaMandateRequest>): Promise<void> {\n await this.logEvent(agentId, 'nekuda.mandate.failed', 'error', req, { mandate_id: mandateId, fail_reason: reason });\n }\n\n /**\n * Express/Connect middleware that gates a mandate-creation endpoint on agent\n * authorization.\n *\n * ⚠️ CONFUSED-DEPUTY WARNING. Evaluates the *named* agent only; pass\n * `authenticate` to verify the caller-to-agent binding. When omitted, a\n * 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 && !VorimNekuda._warnedNoAuth) {\n VorimNekuda._warnedNoAuth = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[vorim] VorimNekuda.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). 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.authorizeMandate({\n agentId,\n merchant: req.body?.merchant || '',\n product: req.body?.product || '',\n amount: req.body?.amount || 0,\n currency: req.body?.currency || 'usd',\n minTrustScore: threshold,\n });\n if (!auth.authorized) {\n res.status(403).json({ error: { code: 'UNAUTHORIZED_AGENT', message: auth.reason || 'Agent not authorized to create a Nekuda mandate', 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<NekudaMandateRequest>,\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 product: req?.product || '',\n amount: req?.amount || 0,\n currency: req?.currency || '',\n ...metadata,\n },\n });\n } catch { /* never block the payment flow */ }\n }\n}\n\n/**\n * Create a VorimNekuda instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimNekuda } from '@vorim/sdk/integrations/nekuda';\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const nekuda = createVorimNekuda(vorim, { minTrustScore: 70 });\n * const auth = await nekuda.authorizeMandate({ agentId: 'agid_abc', merchant: 'shop', amount: 8999 });\n * ```\n */\nexport function createVorimNekuda(sdk: VorimSDK, config?: Partial<NekudaConfig>): VorimNekuda {\n return new VorimNekuda(sdk, config);\n}\n"],"mappings":";AAoEO,IAAM,cAAN,MAAM,aAAY;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACR,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,iBAAiB,KAAyD;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,4BAA4B,EAAE,OAAO,IAAI,eAAe,MAAM;AAAA,IAC5J;AAEA,QAAI,QAAQ;AACZ,QAAI,SAAS;AACb,QAAI;AACF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K,OAAO,EAAE,CAAC;AAC5L;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,YAAY;AAAA,QAC3B,UAAU;AAAA,UACR,UAAU,KAAK,YAAY;AAAA,UAC3B,SAAS,KAAK,WAAW;AAAA,UACzB,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAAqC;AAAA,EAC/C;AACF;AAcO,SAAS,kBAAkB,KAAe,QAA6C;AAC5F,SAAO,IAAI,YAAY,KAAK,MAAM;AACpC;","names":[]}
@@ -1,4 +1,4 @@
1
- import { P as PermissionScope, A as AgentRegistrationResult } from '../types-Cb6V-boJ.cjs';
1
+ import { P as PermissionScope, A as AgentRegistrationResult } from '../types-zzK9YOoa.cjs';
2
2
  import { VorimSDK, ReplayInputs } from '../index.cjs';
3
3
  import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { P as PermissionScope, A as AgentRegistrationResult } from '../types-Cb6V-boJ.js';
1
+ import { P as PermissionScope, A as AgentRegistrationResult } from '../types-zzK9YOoa.js';
2
2
  import { VorimSDK, ReplayInputs } from '../index.js';
3
3
  import { E as EscalationPolicy, T as TransportFailurePolicy } from '../_runtime-gate-DOJUKJBu.js';
4
4
 
@@ -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;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,UAAU;AAAA,YACxB,aAAa,KAAK;AAAA,YAClB,QAAQ,KAAK;AAAA,UACf;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAEA,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,YAAY;AAAA,QAC3B,UAAU;AAAA,UACR,UAAU,KAAK,YAAY;AAAA,UAC3B,QAAQ,KAAK,UAAU;AAAA,UACvB,UAAU,KAAK,YAAY;AAAA,UAC3B,QAAQ,KAAK,UAAU;AAAA,UACvB,GAAG;AAAA,QACL;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAkBO,SAAS,kBAAkB,KAAe,QAA6C;AAC5F,SAAO,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 };