@vorim/sdk 3.12.0 → 3.15.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 (57) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/integrations/coinbase-cdp.cjs +230 -0
  4. package/dist/integrations/coinbase-cdp.cjs.map +1 -0
  5. package/dist/integrations/coinbase-cdp.d.cts +169 -0
  6. package/dist/integrations/coinbase-cdp.d.ts +169 -0
  7. package/dist/integrations/coinbase-cdp.js +204 -0
  8. package/dist/integrations/coinbase-cdp.js.map +1 -0
  9. package/dist/integrations/fhir.cjs +304 -0
  10. package/dist/integrations/fhir.cjs.map +1 -0
  11. package/dist/integrations/fhir.d.cts +185 -0
  12. package/dist/integrations/fhir.d.ts +185 -0
  13. package/dist/integrations/fhir.js +278 -0
  14. package/dist/integrations/fhir.js.map +1 -0
  15. package/dist/integrations/guidewire.cjs +363 -0
  16. package/dist/integrations/guidewire.cjs.map +1 -0
  17. package/dist/integrations/guidewire.d.cts +258 -0
  18. package/dist/integrations/guidewire.d.ts +258 -0
  19. package/dist/integrations/guidewire.js +337 -0
  20. package/dist/integrations/guidewire.js.map +1 -0
  21. package/dist/integrations/legal.cjs +339 -0
  22. package/dist/integrations/legal.cjs.map +1 -0
  23. package/dist/integrations/legal.d.cts +225 -0
  24. package/dist/integrations/legal.d.ts +225 -0
  25. package/dist/integrations/legal.js +313 -0
  26. package/dist/integrations/legal.js.map +1 -0
  27. package/dist/integrations/life-sciences.cjs +335 -0
  28. package/dist/integrations/life-sciences.cjs.map +1 -0
  29. package/dist/integrations/life-sciences.d.cts +214 -0
  30. package/dist/integrations/life-sciences.d.ts +214 -0
  31. package/dist/integrations/life-sciences.js +309 -0
  32. package/dist/integrations/life-sciences.js.map +1 -0
  33. package/dist/integrations/lithic.cjs +290 -0
  34. package/dist/integrations/lithic.cjs.map +1 -0
  35. package/dist/integrations/lithic.d.cts +130 -0
  36. package/dist/integrations/lithic.d.ts +130 -0
  37. package/dist/integrations/lithic.js +264 -0
  38. package/dist/integrations/lithic.js.map +1 -0
  39. package/dist/integrations/marqeta.cjs +285 -0
  40. package/dist/integrations/marqeta.cjs.map +1 -0
  41. package/dist/integrations/marqeta.d.cts +121 -0
  42. package/dist/integrations/marqeta.d.ts +121 -0
  43. package/dist/integrations/marqeta.js +259 -0
  44. package/dist/integrations/marqeta.js.map +1 -0
  45. package/dist/integrations/ramp.cjs +206 -0
  46. package/dist/integrations/ramp.cjs.map +1 -0
  47. package/dist/integrations/ramp.d.cts +139 -0
  48. package/dist/integrations/ramp.d.ts +139 -0
  49. package/dist/integrations/ramp.js +180 -0
  50. package/dist/integrations/ramp.js.map +1 -0
  51. package/dist/integrations/stripe-issuing.cjs +316 -0
  52. package/dist/integrations/stripe-issuing.cjs.map +1 -0
  53. package/dist/integrations/stripe-issuing.d.cts +154 -0
  54. package/dist/integrations/stripe-issuing.d.ts +154 -0
  55. package/dist/integrations/stripe-issuing.js +290 -0
  56. package/dist/integrations/stripe-issuing.js.map +1 -0
  57. package/package.json +91 -1
@@ -0,0 +1,180 @@
1
+ // src/integrations/ramp.ts
2
+ var OPERATION_SCOPE = {
3
+ createLimit: "agent:write",
4
+ updateRestriction: "agent:write",
5
+ terminateCard: "agent:write"
6
+ };
7
+ var VorimRamp = class {
8
+ sdk;
9
+ agentId;
10
+ humanId;
11
+ maxLimitAmount;
12
+ escalateOverCeiling;
13
+ approverId;
14
+ escalationTimeoutMs;
15
+ minTrustScore;
16
+ onError;
17
+ constructor(sdk, config) {
18
+ if (!config?.agentId) throw new Error("[vorim] Ramp integration requires an agentId.");
19
+ this.sdk = sdk;
20
+ this.agentId = config.agentId;
21
+ this.humanId = config.humanId;
22
+ this.maxLimitAmount = config.maxLimitAmount;
23
+ this.escalateOverCeiling = config.escalateOverCeiling ?? false;
24
+ this.approverId = config.approverId ?? config.humanId;
25
+ this.escalationTimeoutMs = config.escalationTimeoutMs ?? 3e5;
26
+ this.minTrustScore = config.minTrustScore ?? 0;
27
+ this.onError = config.onError ?? "closed";
28
+ }
29
+ scopeFor(operation) {
30
+ return OPERATION_SCOPE[operation] ?? "agent:write";
31
+ }
32
+ /** Only createLimit / updateRestriction carry a limit amount to cap. */
33
+ hasLimitAmount(operation) {
34
+ return operation === "createLimit" || operation === "updateRestriction";
35
+ }
36
+ async authorize(action) {
37
+ const scope = this.scopeFor(action.operation);
38
+ const overCeiling = this.hasLimitAmount(action.operation) && this.maxLimitAmount != null && typeof action.amount === "number" && action.amount > this.maxLimitAmount;
39
+ try {
40
+ if (this.minTrustScore > 0) {
41
+ const trust = await this.sdk.verify(this.agentId);
42
+ if ((trust?.trust_score ?? 0) < this.minTrustScore) {
43
+ return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: overCeiling ? "over-ceiling" : "within" };
44
+ }
45
+ }
46
+ if (overCeiling) {
47
+ if (!this.escalateOverCeiling) {
48
+ return {
49
+ authorized: false,
50
+ reason: `limit ${action.amount} exceeds this agent's ceiling of ${this.maxLimitAmount}`,
51
+ outcome: "over-ceiling"
52
+ };
53
+ }
54
+ const esc = await this.escalate(action, scope);
55
+ return {
56
+ authorized: esc.approved,
57
+ reason: esc.approved ? void 0 : esc.reason ?? "named approver denied",
58
+ outcome: esc.approved ? "escalated-approved" : "escalated-denied",
59
+ approverId: this.approverId,
60
+ decisionId: esc.decisionId
61
+ };
62
+ }
63
+ const perm = await this.sdk.check(this.agentId, scope);
64
+ return perm.allowed ? { authorized: true, outcome: "within" } : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: "within" };
65
+ } catch (e) {
66
+ return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open", outcome: overCeiling ? "over-ceiling" : "within" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}`, outcome: overCeiling ? "over-ceiling" : "within" };
67
+ }
68
+ }
69
+ async escalate(action, scope) {
70
+ const decision = await this.sdk.beforeAction(
71
+ {
72
+ agentId: this.agentId,
73
+ actionType: "api_request",
74
+ actionTarget: `ramp:${action.operation}`,
75
+ requiredScope: scope,
76
+ payload: { amount: action.amount, interval: action.interval, limit: this.maxLimitAmount, card_id: action.cardId },
77
+ context: { integration: "ramp", requires_named_approver: true, approver_hint: this.approverId }
78
+ },
79
+ { throwOnDeny: false }
80
+ );
81
+ if (decision.decision === "escalate") {
82
+ const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });
83
+ const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
84
+ return { approved, reason: approved ? void 0 : "named approver denied", decisionId: decision.decisionId };
85
+ }
86
+ if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
87
+ if (decision.decision === "fallback")
88
+ return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
89
+ return { approved: false, reason: decision.reason ?? "denied", decisionId: decision.decisionId };
90
+ }
91
+ async record(action, result, extra = {}) {
92
+ const scope = this.scopeFor(action.operation);
93
+ try {
94
+ await this.sdk.emit(
95
+ {
96
+ agent_id: this.agentId,
97
+ event_type: "api_request",
98
+ action: `ramp:${action.operation}${action.cardId ? " " + action.cardId : ""}`,
99
+ resource: action.cardId || "ramp",
100
+ permission: scope,
101
+ result,
102
+ input_hash: action.inputHash,
103
+ metadata: {
104
+ integration: "ramp",
105
+ operation: action.operation,
106
+ acts_for_human: this.humanId,
107
+ ...action.amount != null ? { amount: action.amount } : {},
108
+ ...action.interval ? { interval: action.interval } : {},
109
+ ...extra.outcome ? { limit_outcome: extra.outcome } : {},
110
+ ...extra.approverId ? { approver_id: extra.approverId } : {},
111
+ ...extra.decisionId ? { decision_id: extra.decisionId } : {},
112
+ ...extra.reason ? { reason: extra.reason } : {}
113
+ }
114
+ },
115
+ { sign: true }
116
+ );
117
+ return true;
118
+ } catch {
119
+ return false;
120
+ }
121
+ }
122
+ async guard(action, run) {
123
+ const auth = await this.authorize(action);
124
+ if (!auth.authorized) {
125
+ const recorded = await this.record(action, "denied", { reason: auth.reason, outcome: auth.outcome, approverId: auth.approverId, decisionId: auth.decisionId });
126
+ return { receipt: this.receipt(action, false, "denied", auth, recorded) };
127
+ }
128
+ try {
129
+ const value = await run();
130
+ const recorded = await this.record(action, "success", { outcome: auth.outcome, approverId: auth.approverId, decisionId: auth.decisionId });
131
+ return { receipt: this.receipt(action, true, "success", auth, recorded), value };
132
+ } catch (e) {
133
+ const recorded = await this.record(action, "error", { reason: e?.message, outcome: auth.outcome, approverId: auth.approverId, decisionId: auth.decisionId });
134
+ throw Object.assign(e ?? new Error("ramp operation failed"), {
135
+ vorimReceipt: this.receipt(action, true, "error", { ...auth, reason: e?.message }, recorded)
136
+ });
137
+ }
138
+ }
139
+ // --- Named helpers ---------------------------------------------------------
140
+ /** Guard creating a limit / virtual card. Requires agent:write; the limit
141
+ * amount is checked against maxLimitAmount. */
142
+ guardedCreateLimit(meta, run) {
143
+ return this.guard({ operation: "createLimit", ...meta }, run);
144
+ }
145
+ /** Guard updating a card restriction (amount/interval/category/vendors).
146
+ * Requires agent:write; a raised amount is checked against the ceiling. */
147
+ guardedUpdateRestriction(meta, run) {
148
+ return this.guard({ operation: "updateRestriction", ...meta }, run);
149
+ }
150
+ /** Guard suspending / terminating a card. Requires agent:write. */
151
+ guardedTerminateCard(meta, run) {
152
+ return this.guard({ operation: "terminateCard", ...meta }, run);
153
+ }
154
+ receipt(action, authorized, result, auth, recorded) {
155
+ return {
156
+ authorized,
157
+ agentId: this.agentId,
158
+ humanId: this.humanId,
159
+ operation: action.operation,
160
+ cardId: action.cardId,
161
+ amount: action.amount,
162
+ interval: action.interval,
163
+ limitOutcome: auth.outcome,
164
+ approverId: auth.approverId,
165
+ result,
166
+ scope: this.scopeFor(action.operation),
167
+ reason: auth.reason,
168
+ decisionId: auth.decisionId,
169
+ recorded
170
+ };
171
+ }
172
+ };
173
+ function createVorimRamp(sdk, config) {
174
+ return new VorimRamp(sdk, config);
175
+ }
176
+ export {
177
+ VorimRamp,
178
+ createVorimRamp
179
+ };
180
+ //# sourceMappingURL=ramp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/ramp.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Ramp (B2B agent spend cards) Integration\n//\n// This guards an AI agent that provisions and manages Ramp virtual spend cards\n// through the Limits API. Before each op runs it verifies the agent's identity\n// and scoped permission, caps the limit amount an agent may create/raise, and\n// signs a tamper-evident record of the provisioning action.\n//\n// HONEST SCOPE: PROVISIONING, NOT PER-AUTHORIZATION\n// Ramp is a spend-management layer on top of Visa, not a raw issuer. There is no\n// real-time authorization webhook to sit in front of (unlike Stripe Issuing,\n// Lithic ASA, or Marqeta JIT). So Vorim signs each card-issue and limit-change,\n// and enforces a ceiling on the LIMIT the agent may provision, rather than\n// deciding each transaction. Use the card-issuing connectors when you need a\n// signed record of every authorization; use Ramp for governed B2B provisioning.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// create a limit / virtual card -> agent:write (+ limit-amount ceiling)\n// update a restriction -> agent:write\n// suspend / terminate a card -> agent:write\n//\n// This layer never holds Ramp OAuth credentials and never calls Ramp itself. You\n// pass the Ramp API call as a closure; it authorizes, runs it, signs the receipt.\n//\n// COMPLIANCE FRAMING (honest)\n// PCI DSS Requirement 10 mandates tamper-evident audit logs, NOT cryptographic\n// signatures. A signed record of each provisioning action satisfies that intent.\n// Say \"tamper-evident, signed record of every card-provisioning action\", never\n// \"required by PCI\".\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimRamp } from '@vorim/sdk/integrations/ramp';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const ramp = createVorimRamp(vorim, {\n// agentId: 'agid_abc123',\n// maxLimitAmount: 500000, // an agent can provision limits up to $5,000.00\n// });\n//\n// const { receipt, value } = await ramp.guardedCreateLimit(\n// { amount: 250000, interval: 'MONTHLY' },\n// () => rampClient.limits.create({ ... }),\n// );\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\nexport type RampOperation = 'createLimit' | 'updateRestriction' | 'terminateCard';\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n createLimit: 'agent:write',\n updateRestriction: 'agent:write',\n terminateCard: 'agent:write',\n};\n\nexport interface RampConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The person/team the agent acts for. Recorded and default escalation target. */\n humanId?: string;\n /** Attenuation: cap the limit amount an agent may create or raise, in minor\n * units (cents). A createLimit / updateRestriction above this is denied or\n * escalated. Omit for no ceiling. */\n maxLimitAmount?: number;\n /** Over the limit-amount ceiling, escalate to a named approver instead of\n * denying. Default false. */\n escalateOverCeiling?: boolean;\n /** Named approver for an over-ceiling provisioning op. Defaults to humanId. */\n approverId?: string;\n /** Max wait for an escalation, ms. Default 300000 (a human sign-off). */\n escalationTimeoutMs?: number;\n /** Minimum trust score before an op. Default 0. */\n minTrustScore?: number;\n /** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface RampAction {\n /** The Ramp operation, e.g. 'createLimit'. Drives the scope. */\n operation: RampOperation | string;\n /** The card / limit the op targets, when known. */\n cardId?: string;\n /** For createLimit / updateRestriction: the limit amount in minor units.\n * Checked against maxLimitAmount. */\n amount?: number;\n /** The limit interval, e.g. 'MONTHLY'. Recorded. */\n interval?: string;\n /** Optional hash of the request body. */\n inputHash?: string;\n}\n\nexport type LimitOutcome = 'within' | 'escalated-approved' | 'escalated-denied' | 'over-ceiling';\n\nexport interface RampReceipt {\n authorized: boolean;\n agentId: string;\n humanId?: string;\n operation: string;\n cardId?: string;\n amount?: number;\n interval?: string;\n limitOutcome?: LimitOutcome;\n approverId?: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\nexport class VorimRamp {\n private sdk: VorimSDK;\n private agentId: string;\n private humanId?: string;\n private maxLimitAmount?: number;\n private escalateOverCeiling: boolean;\n private approverId?: string;\n private escalationTimeoutMs: number;\n private minTrustScore: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: RampConfig) {\n if (!config?.agentId) throw new Error('[vorim] Ramp integration requires an agentId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.humanId = config.humanId;\n this.maxLimitAmount = config.maxLimitAmount;\n this.escalateOverCeiling = config.escalateOverCeiling ?? false;\n this.approverId = config.approverId ?? config.humanId;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 300_000;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.onError = config.onError ?? 'closed';\n }\n\n private scopeFor(operation: string): PermissionScope {\n return OPERATION_SCOPE[operation] ?? 'agent:write';\n }\n\n /** Only createLimit / updateRestriction carry a limit amount to cap. */\n private hasLimitAmount(operation: string): boolean {\n return operation === 'createLimit' || operation === 'updateRestriction';\n }\n\n async authorize(\n action: RampAction,\n ): Promise<{ authorized: boolean; reason?: string; outcome: LimitOutcome; approverId?: string; decisionId?: string }> {\n const scope = this.scopeFor(action.operation);\n const overCeiling =\n this.hasLimitAmount(action.operation) &&\n this.maxLimitAmount != null &&\n typeof action.amount === 'number' &&\n action.amount > this.maxLimitAmount;\n\n try {\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}`, outcome: overCeiling ? 'over-ceiling' : 'within' };\n }\n }\n\n if (overCeiling) {\n if (!this.escalateOverCeiling) {\n return {\n authorized: false,\n reason: `limit ${action.amount} exceeds this agent's ceiling of ${this.maxLimitAmount}`,\n outcome: 'over-ceiling',\n };\n }\n const esc = await this.escalate(action, scope);\n return {\n authorized: esc.approved,\n reason: esc.approved ? undefined : (esc.reason ?? 'named approver denied'),\n outcome: esc.approved ? 'escalated-approved' : 'escalated-denied',\n approverId: this.approverId,\n decisionId: esc.decisionId,\n };\n }\n\n const perm = await this.sdk.check(this.agentId, scope);\n return perm.allowed\n ? { authorized: true, outcome: 'within' }\n : { authorized: false, reason: perm.reason ?? `missing scope ${scope}`, outcome: 'within' };\n } catch (e: any) {\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open', outcome: overCeiling ? 'over-ceiling' : 'within' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}`, outcome: overCeiling ? 'over-ceiling' : 'within' };\n }\n }\n\n private async escalate(action: RampAction, scope: PermissionScope): Promise<{ approved: boolean; reason?: string; decisionId?: string }> {\n const decision = await this.sdk.beforeAction(\n {\n agentId: this.agentId,\n actionType: 'api_request',\n actionTarget: `ramp:${action.operation}`,\n requiredScope: scope,\n payload: { amount: action.amount, interval: action.interval, limit: this.maxLimitAmount, card_id: action.cardId },\n context: { integration: 'ramp', requires_named_approver: true, approver_hint: this.approverId },\n },\n { throwOnDeny: false },\n );\n if (decision.decision === 'escalate') {\n const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });\n const approved = resolved.decision === 'allow' || resolved.escalationResolution === 'approved';\n return { approved, reason: approved ? undefined : 'named approver denied', decisionId: decision.decisionId };\n }\n if (decision.decision === 'allow') return { approved: true, decisionId: decision.decisionId };\n if (decision.decision === 'fallback')\n return { approved: this.onError === 'open', reason: 'runtime unreachable', decisionId: decision.decisionId };\n return { approved: false, reason: decision.reason ?? 'denied', decisionId: decision.decisionId };\n }\n\n async record(\n action: RampAction,\n result: 'success' | 'denied' | 'error',\n extra: { reason?: string; outcome?: LimitOutcome; approverId?: string; decisionId?: string } = {},\n ): Promise<boolean> {\n const scope = this.scopeFor(action.operation);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `ramp:${action.operation}${action.cardId ? ' ' + action.cardId : ''}`,\n resource: action.cardId || 'ramp',\n permission: scope,\n result,\n input_hash: action.inputHash,\n metadata: {\n integration: 'ramp',\n operation: action.operation,\n acts_for_human: this.humanId,\n ...(action.amount != null ? { amount: action.amount } : {}),\n ...(action.interval ? { interval: action.interval } : {}),\n ...(extra.outcome ? { limit_outcome: extra.outcome } : {}),\n ...(extra.approverId ? { approver_id: extra.approverId } : {}),\n ...(extra.decisionId ? { decision_id: extra.decisionId } : {}),\n ...(extra.reason ? { reason: extra.reason } : {}),\n },\n },\n { sign: true },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n async guard<T>(action: RampAction, run: () => Promise<T>): Promise<{ receipt: RampReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', { reason: auth.reason, outcome: auth.outcome, approverId: auth.approverId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, false, 'denied', auth, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success', { outcome: auth.outcome, approverId: auth.approverId, decisionId: auth.decisionId });\n return { receipt: this.receipt(action, true, 'success', auth, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', { reason: e?.message, outcome: auth.outcome, approverId: auth.approverId, decisionId: auth.decisionId });\n throw Object.assign(e ?? new Error('ramp operation failed'), {\n vorimReceipt: this.receipt(action, true, 'error', { ...auth, reason: e?.message }, recorded),\n });\n }\n }\n\n // --- Named helpers ---------------------------------------------------------\n\n /** Guard creating a limit / virtual card. Requires agent:write; the limit\n * amount is checked against maxLimitAmount. */\n guardedCreateLimit<T>(meta: { amount?: number; interval?: string; cardId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'createLimit', ...meta }, run);\n }\n\n /** Guard updating a card restriction (amount/interval/category/vendors).\n * Requires agent:write; a raised amount is checked against the ceiling. */\n guardedUpdateRestriction<T>(meta: { cardId?: string; amount?: number; interval?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'updateRestriction', ...meta }, run);\n }\n\n /** Guard suspending / terminating a card. Requires agent:write. */\n guardedTerminateCard<T>(meta: { cardId?: string; inputHash?: string }, run: () => Promise<T>) {\n return this.guard({ operation: 'terminateCard', ...meta }, run);\n }\n\n private receipt(\n action: RampAction,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n auth: { reason?: string; outcome?: LimitOutcome; approverId?: string; decisionId?: string },\n recorded: boolean,\n ): RampReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n operation: action.operation,\n cardId: action.cardId,\n amount: action.amount,\n interval: action.interval,\n limitOutcome: auth.outcome,\n approverId: auth.approverId,\n result,\n scope: this.scopeFor(action.operation),\n reason: auth.reason,\n decisionId: auth.decisionId,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimRamp guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimRamp } from '@vorim/sdk/integrations/ramp';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const ramp = createVorimRamp(vorim, { agentId: 'agid_abc123', maxLimitAmount: 500000 });\n *\n * const { receipt, value } = await ramp.guardedCreateLimit(\n * { amount: 250000, interval: 'MONTHLY' },\n * () => rampClient.limits.create({ ... }),\n * );\n * ```\n */\nexport function createVorimRamp(sdk: VorimSDK, config: RampConfig): VorimRamp {\n return new VorimRamp(sdk, config);\n}\n"],"mappings":";AAmDA,IAAM,kBAAmD;AAAA,EACvD,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,eAAe;AACjB;AAyDO,IAAM,YAAN,MAAgB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAAoB;AAC7C,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,+CAA+C;AACrF,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,UAAU,OAAO;AACtB,SAAK,iBAAiB,OAAO;AAC7B,SAAK,sBAAsB,OAAO,uBAAuB;AACzD,SAAK,aAAa,OAAO,cAAc,OAA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OAAO;AAAA,MACf,UAAU,OAAO;AAAA,MACjB,cAAc,KAAK;AAAA,MACnB,YAAY,KAAK;AAAA,MACjB;AAAA,MACA,OAAO,KAAK,SAAS,OAAO,SAAS;AAAA,MACrC,QAAQ,KAAK;AAAA,MACb,YAAY,KAAK;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;AAmBO,SAAS,gBAAgB,KAAe,QAA+B;AAC5E,SAAO,IAAI,UAAU,KAAK,MAAM;AAClC;","names":[]}
@@ -0,0 +1,316 @@
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/stripe-issuing.ts
21
+ var stripe_issuing_exports = {};
22
+ __export(stripe_issuing_exports, {
23
+ VorimStripeIssuing: () => VorimStripeIssuing,
24
+ createVorimStripeIssuing: () => createVorimStripeIssuing
25
+ });
26
+ module.exports = __toCommonJS(stripe_issuing_exports);
27
+ var OPERATION_SCOPE = {
28
+ issueCard: "agent:write",
29
+ updateCard: "agent:write",
30
+ dispute: "agent:write",
31
+ authorize: "agent:transact"
32
+ };
33
+ var VorimStripeIssuing = class {
34
+ sdk;
35
+ agentId;
36
+ humanId;
37
+ maxAuthorizationAmount;
38
+ escalateOverCeiling;
39
+ approverId;
40
+ escalationTimeoutMs;
41
+ minTrustScore;
42
+ onError;
43
+ constructor(sdk, config) {
44
+ if (!config?.agentId) throw new Error("[vorim] Stripe Issuing integration requires an agentId.");
45
+ this.sdk = sdk;
46
+ this.agentId = config.agentId;
47
+ this.humanId = config.humanId;
48
+ this.maxAuthorizationAmount = config.maxAuthorizationAmount;
49
+ this.escalateOverCeiling = config.escalateOverCeiling ?? false;
50
+ this.approverId = config.approverId ?? config.humanId;
51
+ this.escalationTimeoutMs = config.escalationTimeoutMs ?? 1800;
52
+ this.minTrustScore = config.minTrustScore ?? 0;
53
+ this.onError = config.onError ?? "closed";
54
+ }
55
+ scopeFor(operation) {
56
+ return OPERATION_SCOPE[operation] ?? "agent:write";
57
+ }
58
+ // --- card lifecycle (issue / update / dispute) -----------------------------
59
+ /** Guard a card lifecycle op (issue / update / dispute). Verifies identity +
60
+ * scope, runs the Stripe call, signs a receipt. */
61
+ async guardLifecycle(operation, meta, run) {
62
+ const scope = this.scopeFor(operation);
63
+ let authorized = true;
64
+ let reason;
65
+ try {
66
+ if (this.minTrustScore > 0) {
67
+ const trust = await this.sdk.verify(this.agentId);
68
+ if ((trust?.trust_score ?? 0) < this.minTrustScore) {
69
+ authorized = false;
70
+ reason = `trust score below ${this.minTrustScore}`;
71
+ }
72
+ }
73
+ if (authorized) {
74
+ const perm = await this.sdk.check(this.agentId, scope);
75
+ if (!perm.allowed) {
76
+ authorized = false;
77
+ reason = perm.reason ?? `missing scope ${scope}`;
78
+ }
79
+ }
80
+ } catch (e) {
81
+ authorized = this.onError === "open";
82
+ reason = authorized ? "vorim unreachable, failed open" : `vorim unreachable: ${e?.message ?? "error"}`;
83
+ }
84
+ if (!authorized) {
85
+ const recorded = await this.recordLifecycle(operation, meta, "denied", reason);
86
+ return { receipt: this.lifecycleReceipt(operation, meta, false, "denied", reason, recorded) };
87
+ }
88
+ try {
89
+ const value = await run();
90
+ const recorded = await this.recordLifecycle(operation, meta, "success");
91
+ return { receipt: this.lifecycleReceipt(operation, meta, true, "success", void 0, recorded), value };
92
+ } catch (e) {
93
+ const recorded = await this.recordLifecycle(operation, meta, "error", e?.message);
94
+ throw Object.assign(e ?? new Error("stripe issuing operation failed"), {
95
+ vorimReceipt: this.lifecycleReceipt(operation, meta, true, "error", e?.message, recorded)
96
+ });
97
+ }
98
+ }
99
+ /** Guard issuing a virtual card (POST /v1/issuing/cards). Requires
100
+ * agent:write. Pass the Stripe cards.create call as `run`. */
101
+ guardedIssueCard(meta, run) {
102
+ return this.guardLifecycle("issueCard", meta, run);
103
+ }
104
+ /** Guard updating a card's spend limit or status (POST /v1/issuing/cards/{id}),
105
+ * e.g. `status: 'inactive'` to freeze. Requires agent:write. */
106
+ guardedUpdateSpend(meta, run) {
107
+ return this.guardLifecycle("updateCard", meta, run);
108
+ }
109
+ /** Guard freezing a card (updateCard with status inactive). Convenience alias. */
110
+ guardedFreezeCard(meta, run) {
111
+ return this.guardLifecycle("updateCard", meta, run);
112
+ }
113
+ /** Guard filing a dispute (POST /v1/issuing/disputes). Requires agent:write. */
114
+ guardedDispute(meta, run) {
115
+ return this.guardLifecycle("dispute", meta, run);
116
+ }
117
+ // --- real-time authorization (the signing checkpoint) ----------------------
118
+ /**
119
+ * Decide a real-time card authorization. Call this from your
120
+ * `issuing_authorization.request` webhook handler within Stripe's 2-second
121
+ * budget, then return `{ approved: decision.approve }` to Stripe. The
122
+ * authorization amount is checked against the agent's delegated ceiling: within
123
+ * it approves; above it either declines (fail-closed spend) or escalates to a
124
+ * named approver when escalateOverCeiling is on. Every decision is signed.
125
+ */
126
+ async guardedAuthorize(req) {
127
+ const scope = "agent:transact";
128
+ const overCeiling = this.maxAuthorizationAmount != null && typeof req.amount === "number" && req.amount > this.maxAuthorizationAmount;
129
+ let approve = false;
130
+ let outcome = "within";
131
+ let reason;
132
+ let approverId;
133
+ let decisionId;
134
+ try {
135
+ if (this.minTrustScore > 0) {
136
+ const trust = await this.sdk.verify(this.agentId);
137
+ if ((trust?.trust_score ?? 0) < this.minTrustScore) {
138
+ const rec = await this.recordAuthorization(req, "declined", {
139
+ reason: `trust score below ${this.minTrustScore}`,
140
+ authOutcome: overCeiling ? "over-ceiling-declined" : "within"
141
+ });
142
+ return {
143
+ approve: false,
144
+ receipt: this.authReceipt(req, false, "declined", `trust score below ${this.minTrustScore}`, overCeiling ? "over-ceiling-declined" : "within", void 0, void 0, rec)
145
+ };
146
+ }
147
+ }
148
+ if (overCeiling) {
149
+ if (this.escalateOverCeiling) {
150
+ const esc = await this.escalateAuthorization(req);
151
+ approve = esc.approved;
152
+ outcome = esc.approved ? "escalated-approved" : "escalated-declined";
153
+ approverId = this.approverId;
154
+ decisionId = esc.decisionId;
155
+ reason = esc.approved ? void 0 : esc.reason ?? "named approver declined";
156
+ } else {
157
+ approve = false;
158
+ outcome = "over-ceiling-declined";
159
+ reason = `authorization ${req.amount} exceeds this agent's ceiling of ${this.maxAuthorizationAmount}`;
160
+ }
161
+ } else {
162
+ const perm = await this.sdk.check(this.agentId, scope);
163
+ approve = perm.allowed;
164
+ outcome = "within";
165
+ reason = perm.allowed ? void 0 : perm.reason ?? `missing scope ${scope}`;
166
+ }
167
+ } catch (e) {
168
+ approve = this.onError === "open";
169
+ reason = approve ? "vorim unreachable, failed open" : `vorim unreachable: ${e?.message ?? "error"}`;
170
+ outcome = overCeiling ? "over-ceiling-declined" : "within";
171
+ }
172
+ const result = approve ? "success" : "declined";
173
+ const recorded = await this.recordAuthorization(req, result, { reason, authOutcome: outcome, approverId, decisionId });
174
+ return {
175
+ approve,
176
+ receipt: this.authReceipt(req, approve, result, reason, outcome, approverId, decisionId, recorded)
177
+ };
178
+ }
179
+ async escalateAuthorization(req) {
180
+ const decision = await this.sdk.beforeAction(
181
+ {
182
+ agentId: this.agentId,
183
+ actionType: "api_request",
184
+ actionTarget: "stripe-issuing:authorize",
185
+ requiredScope: "agent:transact",
186
+ payload: {
187
+ amount: req.amount,
188
+ currency: req.currency,
189
+ limit: this.maxAuthorizationAmount,
190
+ card_id: req.cardId,
191
+ authorization_id: req.authorizationId
192
+ },
193
+ context: {
194
+ integration: "stripe-issuing",
195
+ requires_named_approver: true,
196
+ approver_hint: this.approverId,
197
+ merchant: req.merchant
198
+ }
199
+ },
200
+ { throwOnDeny: false }
201
+ );
202
+ if (decision.decision === "escalate") {
203
+ const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {
204
+ timeoutMs: this.escalationTimeoutMs
205
+ });
206
+ const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
207
+ return { approved, reason: approved ? void 0 : "named approver declined", decisionId: decision.decisionId };
208
+ }
209
+ if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
210
+ if (decision.decision === "fallback")
211
+ return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
212
+ return { approved: false, reason: decision.reason ?? "declined", decisionId: decision.decisionId };
213
+ }
214
+ // --- audit -----------------------------------------------------------------
215
+ async recordLifecycle(operation, meta, result, reason) {
216
+ const scope = this.scopeFor(operation);
217
+ try {
218
+ await this.sdk.emit(
219
+ {
220
+ agent_id: this.agentId,
221
+ event_type: "api_request",
222
+ action: `stripe-issuing:${operation}${meta.cardId ? " " + meta.cardId : ""}`,
223
+ resource: meta.cardId || meta.cardholderId || "stripe-issuing",
224
+ permission: scope,
225
+ result,
226
+ input_hash: meta.inputHash,
227
+ metadata: {
228
+ integration: "stripe-issuing",
229
+ operation,
230
+ acts_for_human: this.humanId,
231
+ ...meta.currency ? { currency: meta.currency } : {},
232
+ ...reason ? { reason } : {}
233
+ }
234
+ },
235
+ { sign: true }
236
+ );
237
+ return true;
238
+ } catch {
239
+ return false;
240
+ }
241
+ }
242
+ async recordAuthorization(req, result, extra) {
243
+ try {
244
+ await this.sdk.emit(
245
+ {
246
+ agent_id: this.agentId,
247
+ event_type: "api_request",
248
+ action: `stripe-issuing:authorize${req.authorizationId ? " " + req.authorizationId : ""}`,
249
+ resource: req.cardId || "stripe-issuing",
250
+ permission: "agent:transact",
251
+ // A card decline is a policy denial in audit terms; the receipt keeps
252
+ // the card-domain word 'declined', the signed event uses the enum.
253
+ result: result === "declined" ? "denied" : result,
254
+ metadata: {
255
+ integration: "stripe-issuing",
256
+ operation: "authorize",
257
+ acts_for_human: this.humanId,
258
+ amount: req.amount,
259
+ ...req.currency ? { currency: req.currency } : {},
260
+ ...req.merchant ? { merchant: req.merchant } : {},
261
+ ...extra.authOutcome ? { auth_outcome: extra.authOutcome } : {},
262
+ ...extra.approverId ? { approver_id: extra.approverId } : {},
263
+ ...extra.decisionId ? { decision_id: extra.decisionId } : {},
264
+ ...extra.reason ? { reason: extra.reason } : {}
265
+ }
266
+ },
267
+ { sign: true }
268
+ // every approve/decline is a signed, tamper-evident record
269
+ );
270
+ return true;
271
+ } catch {
272
+ return false;
273
+ }
274
+ }
275
+ lifecycleReceipt(operation, meta, authorized, result, reason, recorded) {
276
+ return {
277
+ authorized,
278
+ agentId: this.agentId,
279
+ humanId: this.humanId,
280
+ operation,
281
+ cardId: meta.cardId,
282
+ currency: meta.currency,
283
+ result,
284
+ scope: this.scopeFor(operation),
285
+ reason,
286
+ recorded
287
+ };
288
+ }
289
+ authReceipt(req, authorized, result, reason, authOutcome, approverId, decisionId, recorded) {
290
+ return {
291
+ authorized,
292
+ agentId: this.agentId,
293
+ humanId: this.humanId,
294
+ operation: "authorize",
295
+ cardId: req.cardId,
296
+ amount: req.amount,
297
+ currency: req.currency,
298
+ authOutcome,
299
+ approverId,
300
+ result,
301
+ scope: "agent:transact",
302
+ reason,
303
+ decisionId,
304
+ recorded
305
+ };
306
+ }
307
+ };
308
+ function createVorimStripeIssuing(sdk, config) {
309
+ return new VorimStripeIssuing(sdk, config);
310
+ }
311
+ // Annotate the CommonJS export names for ESM import in node:
312
+ 0 && (module.exports = {
313
+ VorimStripeIssuing,
314
+ createVorimStripeIssuing
315
+ });
316
+ //# sourceMappingURL=stripe-issuing.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/stripe-issuing.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Stripe Issuing (virtual cards for agents) Integration\n//\n// This guards an AI agent that spends on a Stripe-issued virtual card. It gates\n// and signs the two moments that matter: issuing/updating a card (with spend\n// controls), and — the novel part — the REAL-TIME AUTHORIZATION on every\n// transaction. Stripe fires an `issuing_authorization.request` webhook (2-second\n// budget) for each purchase; this layer decides approve/decline against the\n// agent's delegated ceiling, escalates above it to a named approver, and signs a\n// tamper-evident record of the decision. No card rail produces a signed record\n// of every authorization; that is the story.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// issue / update / freeze a card -> agent:write\n// authorize a transaction (spend) -> agent:transact + amount ceiling\n// file a dispute -> agent:write\n//\n// This layer never holds the Stripe secret key and never calls Stripe itself.\n// For card lifecycle ops you pass the Stripe SDK call as a closure; for the\n// authorization webhook you pass the amount and this layer returns the signed\n// approve/decline you send back to Stripe.\n//\n// ATTENUATION (the wedge)\n// Stripe's own spending_controls cap the card. Vorim can TIGHTEN below them per\n// agent, add a per-authorization ceiling, and add segregation of duties: an\n// authorization above the agent's delegated limit is escalated to a named\n// approver instead of auto-approved. Every approve/decline is signed.\n//\n// COMPLIANCE FRAMING (honest)\n// PCI DSS Requirement 10 mandates tamper-evident audit logs, NOT cryptographic\n// signatures. A signed record of each authorization satisfies that intent and is\n// a stronger primitive than file-integrity monitoring. Say \"tamper-evident,\n// signed record of every authorization decision\", never \"required by PCI\".\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimStripeIssuing } from '@vorim/sdk/integrations/stripe-issuing';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const issuing = createVorimStripeIssuing(vorim, {\n// agentId: 'agid_abc123',\n// maxAuthorizationAmount: 20000, // approve up to $200.00 (cents) per txn\n// escalateOverCeiling: true, // above that -> named-approver decision\n// approverId: 'finance_ops',\n// });\n//\n// // 1) issue a card (you pass the Stripe call):\n// const { receipt, value } = await issuing.guardedIssueCard(\n// { cardholderId: 'ich_...', currency: 'usd' },\n// () => stripe.issuing.cards.create({ cardholder, currency, type: 'virtual' }),\n// );\n//\n// // 2) real-time authorization webhook:\n// const decision = await issuing.guardedAuthorize({\n// authorizationId: 'iauth_...', amount: 4999, currency: 'usd', merchant: 'MCC 5812',\n// });\n// // decision.approve is what you return to Stripe within 2s; decision.receipt is signed.\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** The Stripe Issuing operations this guard classifies. */\nexport type StripeIssuingOperation =\n | 'issueCard' // POST /v1/issuing/cards\n | 'updateCard' // POST /v1/issuing/cards/{id} (spend limit / freeze)\n | 'authorize' // issuing_authorization.request webhook — the spend decision\n | 'dispute'; // POST /v1/issuing/disputes\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n issueCard: 'agent:write',\n updateCard: 'agent:write',\n dispute: 'agent:write',\n authorize: 'agent:transact',\n};\n\nexport interface StripeIssuingConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The person / team the agent acts for. Recorded on every receipt and used as\n * the default escalation target. */\n humanId?: string;\n /** Attenuation: cap a single authorization (one card transaction), in the\n * currency's minor unit (cents). Omit for no per-authorization ceiling. */\n maxAuthorizationAmount?: number;\n /** When an authorization exceeds the ceiling, escalate to a named approver and\n * wait instead of declining outright. Requires the runtime decision plane.\n * Default false: over-ceiling is a signed DECLINE (fail-closed spend). */\n escalateOverCeiling?: boolean;\n /** The named approver for an over-ceiling authorization (segregation of\n * duties). Defaults to humanId. */\n approverId?: string;\n /** Max time to wait for an escalation decision, ms. Default 1800 (well inside\n * Stripe's 2s authorization budget — an escalation that cannot resolve in\n * time declines, and the human can pre-approve out of band). */\n escalationTimeoutMs?: number;\n /** Minimum trust score the agent must hold before a card op. Default 0. */\n minTrustScore?: number;\n /** Fail closed (deny/decline on any Vorim error) or fail open. Default\n * 'closed' — for a spend decision, a check we cannot complete declines. */\n onError?: 'closed' | 'open';\n}\n\nexport interface StripeIssuingCardMeta {\n /** The card the op targets, when known. */\n cardId?: string;\n /** The Stripe cardholder id, for issueCard. */\n cardholderId?: string;\n currency?: string;\n /** Optional hash of the request body. */\n inputHash?: string;\n}\n\nexport interface StripeAuthorizationRequest {\n /** The Stripe authorization id (iauth_...). */\n authorizationId?: string;\n /** The card the authorization is against. */\n cardId?: string;\n /** The pending amount, in the currency's minor unit (cents). Checked against\n * maxAuthorizationAmount. */\n amount: number;\n currency?: string;\n /** The merchant / MCC, recorded for the audit. */\n merchant?: string;\n}\n\n/** How an authorization amount resolved. */\nexport type AuthOutcome = 'within' | 'escalated-approved' | 'escalated-declined' | 'over-ceiling-declined';\n\n/** An offline-verifiable receipt for a Stripe Issuing op or authorization. */\nexport interface StripeIssuingReceipt {\n authorized: boolean;\n agentId: string;\n humanId?: string;\n operation: string;\n cardId?: string;\n amount?: number;\n currency?: string;\n authOutcome?: AuthOutcome;\n approverId?: string;\n result: 'success' | 'denied' | 'declined' | 'error';\n scope: PermissionScope;\n reason?: string;\n decisionId?: string;\n recorded: boolean;\n}\n\n/** The result of a real-time authorization decision: what to return to Stripe,\n * plus the signed receipt. */\nexport interface AuthorizationDecision {\n /** True = return `{ approved: true }` to Stripe; false = decline. */\n approve: boolean;\n receipt: StripeIssuingReceipt;\n}\n\nexport class VorimStripeIssuing {\n private sdk: VorimSDK;\n private agentId: string;\n private humanId?: string;\n private maxAuthorizationAmount?: number;\n private escalateOverCeiling: boolean;\n private approverId?: string;\n private escalationTimeoutMs: number;\n private minTrustScore: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: StripeIssuingConfig) {\n if (!config?.agentId) throw new Error('[vorim] Stripe Issuing integration requires an agentId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.humanId = config.humanId;\n this.maxAuthorizationAmount = config.maxAuthorizationAmount;\n this.escalateOverCeiling = config.escalateOverCeiling ?? false;\n this.approverId = config.approverId ?? config.humanId;\n this.escalationTimeoutMs = config.escalationTimeoutMs ?? 1800;\n this.minTrustScore = config.minTrustScore ?? 0;\n this.onError = config.onError ?? 'closed';\n }\n\n private scopeFor(operation: string): PermissionScope {\n return OPERATION_SCOPE[operation] ?? 'agent:write';\n }\n\n // --- card lifecycle (issue / update / dispute) -----------------------------\n\n /** Guard a card lifecycle op (issue / update / dispute). Verifies identity +\n * scope, runs the Stripe call, signs a receipt. */\n private async guardLifecycle<T>(\n operation: string,\n meta: StripeIssuingCardMeta,\n run: () => Promise<T>,\n ): Promise<{ receipt: StripeIssuingReceipt; value?: T }> {\n const scope = this.scopeFor(operation);\n let authorized = true;\n let reason: string | undefined;\n try {\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n authorized = false;\n reason = `trust score below ${this.minTrustScore}`;\n }\n }\n if (authorized) {\n const perm = await this.sdk.check(this.agentId, scope);\n if (!perm.allowed) {\n authorized = false;\n reason = perm.reason ?? `missing scope ${scope}`;\n }\n }\n } catch (e: any) {\n authorized = this.onError === 'open';\n reason = authorized ? 'vorim unreachable, failed open' : `vorim unreachable: ${e?.message ?? 'error'}`;\n }\n\n if (!authorized) {\n const recorded = await this.recordLifecycle(operation, meta, 'denied', reason);\n return { receipt: this.lifecycleReceipt(operation, meta, false, 'denied', reason, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.recordLifecycle(operation, meta, 'success');\n return { receipt: this.lifecycleReceipt(operation, meta, true, 'success', undefined, recorded), value };\n } catch (e: any) {\n const recorded = await this.recordLifecycle(operation, meta, 'error', e?.message);\n throw Object.assign(e ?? new Error('stripe issuing operation failed'), {\n vorimReceipt: this.lifecycleReceipt(operation, meta, true, 'error', e?.message, recorded),\n });\n }\n }\n\n /** Guard issuing a virtual card (POST /v1/issuing/cards). Requires\n * agent:write. Pass the Stripe cards.create call as `run`. */\n guardedIssueCard<T>(meta: StripeIssuingCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('issueCard', meta, run);\n }\n\n /** Guard updating a card's spend limit or status (POST /v1/issuing/cards/{id}),\n * e.g. `status: 'inactive'` to freeze. Requires agent:write. */\n guardedUpdateSpend<T>(meta: StripeIssuingCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('updateCard', meta, run);\n }\n\n /** Guard freezing a card (updateCard with status inactive). Convenience alias. */\n guardedFreezeCard<T>(meta: StripeIssuingCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('updateCard', meta, run);\n }\n\n /** Guard filing a dispute (POST /v1/issuing/disputes). Requires agent:write. */\n guardedDispute<T>(meta: StripeIssuingCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('dispute', meta, run);\n }\n\n // --- real-time authorization (the signing checkpoint) ----------------------\n\n /**\n * Decide a real-time card authorization. Call this from your\n * `issuing_authorization.request` webhook handler within Stripe's 2-second\n * budget, then return `{ approved: decision.approve }` to Stripe. The\n * authorization amount is checked against the agent's delegated ceiling: within\n * it approves; above it either declines (fail-closed spend) or escalates to a\n * named approver when escalateOverCeiling is on. Every decision is signed.\n */\n async guardedAuthorize(req: StripeAuthorizationRequest): Promise<AuthorizationDecision> {\n const scope: PermissionScope = 'agent:transact';\n const overCeiling =\n this.maxAuthorizationAmount != null && typeof req.amount === 'number' && req.amount > this.maxAuthorizationAmount;\n\n let approve = false;\n let outcome: AuthOutcome = 'within';\n let reason: string | undefined;\n let approverId: string | undefined;\n let decisionId: string | undefined;\n\n try {\n // Trust floor first.\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n const rec = await this.recordAuthorization(req, 'declined', {\n reason: `trust score below ${this.minTrustScore}`,\n authOutcome: overCeiling ? 'over-ceiling-declined' : 'within',\n });\n return {\n approve: false,\n receipt: this.authReceipt(req, false, 'declined', `trust score below ${this.minTrustScore}`, overCeiling ? 'over-ceiling-declined' : 'within', undefined, undefined, rec),\n };\n }\n }\n\n if (overCeiling) {\n if (this.escalateOverCeiling) {\n const esc = await this.escalateAuthorization(req);\n approve = esc.approved;\n outcome = esc.approved ? 'escalated-approved' : 'escalated-declined';\n approverId = this.approverId;\n decisionId = esc.decisionId;\n reason = esc.approved ? undefined : (esc.reason ?? 'named approver declined');\n } else {\n // Fail-closed spend: over the ceiling with no escalation is a decline.\n approve = false;\n outcome = 'over-ceiling-declined';\n reason = `authorization ${req.amount} exceeds this agent's ceiling of ${this.maxAuthorizationAmount}`;\n }\n } else {\n // Within ceiling: a permission check on the transact scope.\n const perm = await this.sdk.check(this.agentId, scope);\n approve = perm.allowed;\n outcome = 'within';\n reason = perm.allowed ? undefined : (perm.reason ?? `missing scope ${scope}`);\n }\n } catch (e: any) {\n // Fail closed by default: a check we cannot complete DECLINES the spend.\n approve = this.onError === 'open';\n reason = approve ? 'vorim unreachable, failed open' : `vorim unreachable: ${e?.message ?? 'error'}`;\n outcome = overCeiling ? 'over-ceiling-declined' : 'within';\n }\n\n const result: StripeIssuingReceipt['result'] = approve ? 'success' : 'declined';\n const recorded = await this.recordAuthorization(req, result, { reason, authOutcome: outcome, approverId, decisionId });\n return {\n approve,\n receipt: this.authReceipt(req, approve, result, reason, outcome, approverId, decisionId, recorded),\n };\n }\n\n private async escalateAuthorization(\n req: StripeAuthorizationRequest,\n ): Promise<{ approved: boolean; reason?: string; decisionId?: string }> {\n const decision = await this.sdk.beforeAction(\n {\n agentId: this.agentId,\n actionType: 'api_request',\n actionTarget: 'stripe-issuing:authorize',\n requiredScope: 'agent:transact',\n payload: {\n amount: req.amount,\n currency: req.currency,\n limit: this.maxAuthorizationAmount,\n card_id: req.cardId,\n authorization_id: req.authorizationId,\n },\n context: {\n integration: 'stripe-issuing',\n requires_named_approver: true,\n approver_hint: this.approverId,\n merchant: req.merchant,\n },\n },\n { throwOnDeny: false },\n );\n\n if (decision.decision === 'escalate') {\n const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, {\n timeoutMs: this.escalationTimeoutMs,\n });\n const approved = resolved.decision === 'allow' || resolved.escalationResolution === 'approved';\n return { approved, reason: approved ? undefined : 'named approver declined', decisionId: decision.decisionId };\n }\n if (decision.decision === 'allow') return { approved: true, decisionId: decision.decisionId };\n if (decision.decision === 'fallback')\n return { approved: this.onError === 'open', reason: 'runtime unreachable', decisionId: decision.decisionId };\n return { approved: false, reason: decision.reason ?? 'declined', decisionId: decision.decisionId };\n }\n\n // --- audit -----------------------------------------------------------------\n\n private async recordLifecycle(\n operation: string,\n meta: StripeIssuingCardMeta,\n result: 'success' | 'denied' | 'error',\n reason?: string,\n ): Promise<boolean> {\n const scope = this.scopeFor(operation);\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `stripe-issuing:${operation}${meta.cardId ? ' ' + meta.cardId : ''}`,\n resource: meta.cardId || meta.cardholderId || 'stripe-issuing',\n permission: scope,\n result,\n input_hash: meta.inputHash,\n metadata: {\n integration: 'stripe-issuing',\n operation,\n acts_for_human: this.humanId,\n ...(meta.currency ? { currency: meta.currency } : {}),\n ...(reason ? { reason } : {}),\n },\n },\n { sign: true },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n private async recordAuthorization(\n req: StripeAuthorizationRequest,\n result: 'success' | 'declined',\n extra: { reason?: string; authOutcome?: AuthOutcome; approverId?: string; decisionId?: string },\n ): Promise<boolean> {\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `stripe-issuing:authorize${req.authorizationId ? ' ' + req.authorizationId : ''}`,\n resource: req.cardId || 'stripe-issuing',\n permission: 'agent:transact',\n // A card decline is a policy denial in audit terms; the receipt keeps\n // the card-domain word 'declined', the signed event uses the enum.\n result: result === 'declined' ? 'denied' : result,\n metadata: {\n integration: 'stripe-issuing',\n operation: 'authorize',\n acts_for_human: this.humanId,\n amount: req.amount,\n ...(req.currency ? { currency: req.currency } : {}),\n ...(req.merchant ? { merchant: req.merchant } : {}),\n ...(extra.authOutcome ? { auth_outcome: extra.authOutcome } : {}),\n ...(extra.approverId ? { approver_id: extra.approverId } : {}),\n ...(extra.decisionId ? { decision_id: extra.decisionId } : {}),\n ...(extra.reason ? { reason: extra.reason } : {}),\n },\n },\n { sign: true }, // every approve/decline is a signed, tamper-evident record\n );\n return true;\n } catch {\n return false;\n }\n }\n\n private lifecycleReceipt(\n operation: string,\n meta: StripeIssuingCardMeta,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n reason: string | undefined,\n recorded: boolean,\n ): StripeIssuingReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n operation,\n cardId: meta.cardId,\n currency: meta.currency,\n result,\n scope: this.scopeFor(operation),\n reason,\n recorded,\n };\n }\n\n private authReceipt(\n req: StripeAuthorizationRequest,\n authorized: boolean,\n result: 'success' | 'declined',\n reason: string | undefined,\n authOutcome: AuthOutcome,\n approverId: string | undefined,\n decisionId: string | undefined,\n recorded: boolean,\n ): StripeIssuingReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n operation: 'authorize',\n cardId: req.cardId,\n amount: req.amount,\n currency: req.currency,\n authOutcome,\n approverId,\n result,\n scope: 'agent:transact',\n reason,\n decisionId,\n recorded,\n };\n }\n}\n\n/**\n * Create a VorimStripeIssuing guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimStripeIssuing } from '@vorim/sdk/integrations/stripe-issuing';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const issuing = createVorimStripeIssuing(vorim, {\n * agentId: 'agid_abc123',\n * maxAuthorizationAmount: 20000, // $200.00 per transaction\n * escalateOverCeiling: true,\n * approverId: 'finance_ops',\n * });\n *\n * // real-time authorization webhook:\n * const decision = await issuing.guardedAuthorize({ authorizationId: 'iauth_1', amount: 4999, currency: 'usd' });\n * // return { approved: decision.approve } to Stripe; decision.receipt is signed.\n * ```\n */\nexport function createVorimStripeIssuing(sdk: VorimSDK, config: StripeIssuingConfig): VorimStripeIssuing {\n return new VorimStripeIssuing(sdk, config);\n}\n"],"mappings":";;;;;;;;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