@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,290 @@
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/lithic.ts
21
+ var lithic_exports = {};
22
+ __export(lithic_exports, {
23
+ VorimLithic: () => VorimLithic,
24
+ createVorimLithic: () => createVorimLithic
25
+ });
26
+ module.exports = __toCommonJS(lithic_exports);
27
+ var OPERATION_SCOPE = {
28
+ createCard: "agent:write",
29
+ updateCard: "agent:write",
30
+ authRule: "agent:write",
31
+ asaDecision: "agent:transact"
32
+ };
33
+ var VorimLithic = 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] Lithic 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 --------------------------------------------------------
59
+ async guardLifecycle(operation, meta, run) {
60
+ const scope = this.scopeFor(operation);
61
+ let authorized = true;
62
+ let reason;
63
+ try {
64
+ if (this.minTrustScore > 0) {
65
+ const trust = await this.sdk.verify(this.agentId);
66
+ if ((trust?.trust_score ?? 0) < this.minTrustScore) {
67
+ authorized = false;
68
+ reason = `trust score below ${this.minTrustScore}`;
69
+ }
70
+ }
71
+ if (authorized) {
72
+ const perm = await this.sdk.check(this.agentId, scope);
73
+ if (!perm.allowed) {
74
+ authorized = false;
75
+ reason = perm.reason ?? `missing scope ${scope}`;
76
+ }
77
+ }
78
+ } catch (e) {
79
+ authorized = this.onError === "open";
80
+ reason = authorized ? "vorim unreachable, failed open" : `vorim unreachable: ${e?.message ?? "error"}`;
81
+ }
82
+ if (!authorized) {
83
+ const recorded = await this.recordLifecycle(operation, meta, "denied", reason);
84
+ return { receipt: this.lifecycleReceipt(operation, meta, false, "denied", reason, recorded) };
85
+ }
86
+ try {
87
+ const value = await run();
88
+ const recorded = await this.recordLifecycle(operation, meta, "success");
89
+ return { receipt: this.lifecycleReceipt(operation, meta, true, "success", void 0, recorded), value };
90
+ } catch (e) {
91
+ const recorded = await this.recordLifecycle(operation, meta, "error", e?.message);
92
+ throw Object.assign(e ?? new Error("lithic operation failed"), {
93
+ vorimReceipt: this.lifecycleReceipt(operation, meta, true, "error", e?.message, recorded)
94
+ });
95
+ }
96
+ }
97
+ /** Guard creating a card (POST /v1/cards). Requires agent:write. Use
98
+ * cardType SINGLE_USE for one-shot spend or MERCHANT_LOCKED to pin a merchant. */
99
+ guardedCreateCard(meta, run) {
100
+ return this.guardLifecycle("createCard", meta, run);
101
+ }
102
+ /** Guard updating a card's spend limit or state (PATCH /v1/cards/{token}),
103
+ * e.g. state PAUSED. Requires agent:write. */
104
+ guardedUpdateSpendLimit(meta, run) {
105
+ return this.guardLifecycle("updateCard", meta, run);
106
+ }
107
+ /** Guard creating an auth rule (velocity/MCC/amount guardrail). agent:write. */
108
+ guardedCreateAuthRule(meta, run) {
109
+ return this.guardLifecycle("authRule", meta, run);
110
+ }
111
+ // --- Auth Stream Access decision (the signing checkpoint) ------------------
112
+ /**
113
+ * Decide a real-time Lithic authorization. Call from your ASA endpoint and
114
+ * return `{ result: decision.result, token }` to Lithic. Within the ceiling
115
+ * approves; above it declines (fail-closed) or escalates to a named approver.
116
+ * Every decision is signed.
117
+ */
118
+ async guardedAsaDecision(req) {
119
+ const overCeiling = this.maxAuthorizationAmount != null && typeof req.amount === "number" && req.amount > this.maxAuthorizationAmount;
120
+ let approve = false;
121
+ let outcome = "within";
122
+ let reason;
123
+ let approverId;
124
+ let decisionId;
125
+ try {
126
+ if (this.minTrustScore > 0) {
127
+ const trust = await this.sdk.verify(this.agentId);
128
+ if ((trust?.trust_score ?? 0) < this.minTrustScore) {
129
+ const rec = await this.recordAsa(req, "declined", {
130
+ reason: `trust score below ${this.minTrustScore}`,
131
+ authOutcome: overCeiling ? "over-ceiling-declined" : "within"
132
+ });
133
+ return this.asaDecision(req, false, `trust score below ${this.minTrustScore}`, overCeiling ? "over-ceiling-declined" : "within", void 0, void 0, rec);
134
+ }
135
+ }
136
+ if (overCeiling) {
137
+ if (this.escalateOverCeiling) {
138
+ const esc = await this.escalate(req);
139
+ approve = esc.approved;
140
+ outcome = esc.approved ? "escalated-approved" : "escalated-declined";
141
+ approverId = this.approverId;
142
+ decisionId = esc.decisionId;
143
+ reason = esc.approved ? void 0 : esc.reason ?? "named approver declined";
144
+ } else {
145
+ approve = false;
146
+ outcome = "over-ceiling-declined";
147
+ reason = `authorization ${req.amount} exceeds this agent's ceiling of ${this.maxAuthorizationAmount}`;
148
+ }
149
+ } else {
150
+ const perm = await this.sdk.check(this.agentId, "agent:transact");
151
+ approve = perm.allowed;
152
+ outcome = "within";
153
+ reason = perm.allowed ? void 0 : perm.reason ?? "missing scope agent:transact";
154
+ }
155
+ } catch (e) {
156
+ approve = this.onError === "open";
157
+ reason = approve ? "vorim unreachable, failed open" : `vorim unreachable: ${e?.message ?? "error"}`;
158
+ outcome = overCeiling ? "over-ceiling-declined" : "within";
159
+ }
160
+ const recorded = await this.recordAsa(req, approve ? "success" : "declined", { reason, authOutcome: outcome, approverId, decisionId });
161
+ return this.asaDecision(req, approve, reason, outcome, approverId, decisionId, recorded);
162
+ }
163
+ async escalate(req) {
164
+ const decision = await this.sdk.beforeAction(
165
+ {
166
+ agentId: this.agentId,
167
+ actionType: "api_request",
168
+ actionTarget: "lithic:asaDecision",
169
+ requiredScope: "agent:transact",
170
+ payload: { amount: req.amount, currency: req.currency, limit: this.maxAuthorizationAmount, card_token: req.cardToken, token: req.token },
171
+ context: { integration: "lithic", requires_named_approver: true, approver_hint: this.approverId, merchant: req.merchant }
172
+ },
173
+ { throwOnDeny: false }
174
+ );
175
+ if (decision.decision === "escalate") {
176
+ const resolved = await this.sdk.waitForDecisionResolution(decision.decisionId, { timeoutMs: this.escalationTimeoutMs });
177
+ const approved = resolved.decision === "allow" || resolved.escalationResolution === "approved";
178
+ return { approved, reason: approved ? void 0 : "named approver declined", decisionId: decision.decisionId };
179
+ }
180
+ if (decision.decision === "allow") return { approved: true, decisionId: decision.decisionId };
181
+ if (decision.decision === "fallback")
182
+ return { approved: this.onError === "open", reason: "runtime unreachable", decisionId: decision.decisionId };
183
+ return { approved: false, reason: decision.reason ?? "declined", decisionId: decision.decisionId };
184
+ }
185
+ // --- audit -----------------------------------------------------------------
186
+ async recordLifecycle(operation, meta, result, reason) {
187
+ try {
188
+ await this.sdk.emit(
189
+ {
190
+ agent_id: this.agentId,
191
+ event_type: "api_request",
192
+ action: `lithic:${operation}${meta.cardToken ? " " + meta.cardToken : ""}`,
193
+ resource: meta.cardToken || "lithic",
194
+ permission: this.scopeFor(operation),
195
+ result,
196
+ input_hash: meta.inputHash,
197
+ metadata: {
198
+ integration: "lithic",
199
+ operation,
200
+ acts_for_human: this.humanId,
201
+ ...meta.cardType ? { card_type: meta.cardType } : {},
202
+ ...meta.spendLimit != null ? { spend_limit: meta.spendLimit } : {},
203
+ ...reason ? { reason } : {}
204
+ }
205
+ },
206
+ { sign: true }
207
+ );
208
+ return true;
209
+ } catch {
210
+ return false;
211
+ }
212
+ }
213
+ async recordAsa(req, result, extra) {
214
+ try {
215
+ await this.sdk.emit(
216
+ {
217
+ agent_id: this.agentId,
218
+ event_type: "api_request",
219
+ action: `lithic:asaDecision${req.token ? " " + req.token : ""}`,
220
+ resource: req.cardToken || "lithic",
221
+ permission: "agent:transact",
222
+ // A card decline is a policy denial in audit terms; the receipt keeps
223
+ // the card-domain word 'declined', the signed event uses the enum.
224
+ result: result === "declined" ? "denied" : result,
225
+ metadata: {
226
+ integration: "lithic",
227
+ operation: "asaDecision",
228
+ acts_for_human: this.humanId,
229
+ amount: req.amount,
230
+ ...req.currency ? { currency: req.currency } : {},
231
+ ...req.merchant ? { merchant: req.merchant } : {},
232
+ ...extra.authOutcome ? { auth_outcome: extra.authOutcome } : {},
233
+ ...extra.approverId ? { approver_id: extra.approverId } : {},
234
+ ...extra.decisionId ? { decision_id: extra.decisionId } : {},
235
+ ...extra.reason ? { reason: extra.reason } : {}
236
+ }
237
+ },
238
+ { sign: true }
239
+ );
240
+ return true;
241
+ } catch {
242
+ return false;
243
+ }
244
+ }
245
+ lifecycleReceipt(operation, meta, authorized, result, reason, recorded) {
246
+ return {
247
+ authorized,
248
+ agentId: this.agentId,
249
+ humanId: this.humanId,
250
+ operation,
251
+ cardToken: meta.cardToken,
252
+ cardType: meta.cardType,
253
+ result,
254
+ scope: this.scopeFor(operation),
255
+ reason,
256
+ recorded
257
+ };
258
+ }
259
+ asaDecision(req, approve, reason, authOutcome, approverId, decisionId, recorded) {
260
+ return {
261
+ result: approve ? "APPROVED" : "DECLINED",
262
+ approve,
263
+ receipt: {
264
+ authorized: approve,
265
+ agentId: this.agentId,
266
+ humanId: this.humanId,
267
+ operation: "asaDecision",
268
+ cardToken: req.cardToken,
269
+ amount: req.amount,
270
+ currency: req.currency,
271
+ authOutcome,
272
+ approverId,
273
+ result: approve ? "success" : "declined",
274
+ scope: "agent:transact",
275
+ reason,
276
+ decisionId,
277
+ recorded
278
+ }
279
+ };
280
+ }
281
+ };
282
+ function createVorimLithic(sdk, config) {
283
+ return new VorimLithic(sdk, config);
284
+ }
285
+ // Annotate the CommonJS export names for ESM import in node:
286
+ 0 && (module.exports = {
287
+ VorimLithic,
288
+ createVorimLithic
289
+ });
290
+ //# sourceMappingURL=lithic.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integrations/lithic.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Lithic (card issuing with Auth Stream Access) Integration\n//\n// This guards an AI agent that spends on a Lithic-issued card. It gates and\n// signs card creation/updates and — the novel part — the real-time Auth Stream\n// Access (ASA) decision on every transaction. Lithic POSTs each authorization to\n// your ASA endpoint and you respond APPROVED or declined; this layer makes that\n// decision against the agent's delegated ceiling, escalates above it to a named\n// approver, and signs a tamper-evident record of the approve/decline.\n//\n// LITHIC'S AGENT-PERFECT PRIMITIVES\n// SINGLE_USE cards map to one-shot delegated spend; MERCHANT_LOCKED cards pin an\n// agent to one merchant. spend_limit + spend_limit_duration\n// (TRANSACTION/MONTHLY/ANNUALLY/FOREVER) are Lithic's own controls; Vorim\n// tightens below them per agent and signs every ASA decision.\n//\n// SCOPE MAPPING (uses Vorim's real scopes)\n// create / update / pause a card -> agent:write\n// ASA decision (a spend) -> agent:transact + amount ceiling\n// create an auth rule -> agent:write\n//\n// This layer never holds the Lithic api-key and never calls Lithic itself. For\n// card ops you pass the Lithic call as a closure; for the ASA decision you pass\n// the amount and this layer returns the signed APPROVED/decline you send back.\n//\n// COMPLIANCE FRAMING (honest)\n// PCI DSS Requirement 10 mandates tamper-evident audit logs, NOT cryptographic\n// signatures. A signed record of each ASA decision satisfies that intent. Say\n// \"tamper-evident, signed record of every authorization\", never \"required by\n// PCI\".\n//\n// Usage:\n// import createVorim from '@vorim/sdk';\n// import { createVorimLithic } from '@vorim/sdk/integrations/lithic';\n//\n// const vorim = createVorim({ apiKey: 'agid_sk_...' });\n// const lithic = createVorimLithic(vorim, {\n// agentId: 'agid_abc123',\n// maxAuthorizationAmount: 20000, // approve up to $200.00 (cents) per txn\n// escalateOverCeiling: true, approverId: 'finance_ops',\n// });\n//\n// // create a single-use card (you pass the Lithic call):\n// await lithic.guardedCreateCard(\n// { cardType: 'SINGLE_USE', spendLimit: 5000 },\n// () => lithicClient.cards.create({ type: 'SINGLE_USE', spend_limit: 5000 }),\n// );\n//\n// // ASA webhook decision:\n// const decision = await lithic.guardedAsaDecision({ token: 'txn_...', amount: 4999 });\n// // return { result: decision.result, token } to Lithic; decision.receipt is signed.\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\n/** Lithic card types. SINGLE_USE and MERCHANT_LOCKED are the agent-friendly\n * ones (one-shot / merchant-pinned delegated spend). */\nexport type LithicCardType = 'VIRTUAL' | 'SINGLE_USE' | 'MERCHANT_LOCKED';\n\nexport type LithicOperation = 'createCard' | 'updateCard' | 'asaDecision' | 'authRule';\n\nconst OPERATION_SCOPE: Record<string, PermissionScope> = {\n createCard: 'agent:write',\n updateCard: 'agent:write',\n authRule: 'agent:write',\n asaDecision: 'agent:transact',\n};\n\nexport interface LithicConfig {\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 a single ASA authorization, in minor units (cents). Omit\n * for no per-authorization ceiling. */\n maxAuthorizationAmount?: number;\n /** Over the ceiling, escalate to a named approver instead of declining.\n * Default false: over-ceiling is a signed decline (fail-closed spend). */\n escalateOverCeiling?: boolean;\n /** Named approver for an over-ceiling authorization. Defaults to humanId. */\n approverId?: string;\n /** Max wait for an escalation, ms. Default 1800 (Lithic's ASA budget is tight). */\n escalationTimeoutMs?: number;\n /** Minimum trust score before a card op. Default 0. */\n minTrustScore?: number;\n /** Fail closed (decline/deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface LithicCardMeta {\n cardToken?: string;\n cardType?: LithicCardType;\n /** The Lithic spend_limit set on the card, in cents. Recorded. */\n spendLimit?: number;\n inputHash?: string;\n}\n\nexport interface LithicAsaRequest {\n /** The Lithic transaction token. Echoed back in the ASA response. */\n token?: string;\n cardToken?: string;\n /** The pending amount, in minor units (cents). Checked against the ceiling. */\n amount: number;\n currency?: string;\n merchant?: string;\n}\n\nexport type AuthOutcome = 'within' | 'escalated-approved' | 'escalated-declined' | 'over-ceiling-declined';\n\nexport interface LithicReceipt {\n authorized: boolean;\n agentId: string;\n humanId?: string;\n operation: string;\n cardToken?: string;\n cardType?: LithicCardType;\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 ASA decision: the Lithic result string to return, plus the signed\n * receipt. Return `{ result: decision.result, token }` to Lithic. */\nexport interface AsaDecision {\n /** 'APPROVED' to approve; 'DECLINED' otherwise (any non-APPROVED declines). */\n result: 'APPROVED' | 'DECLINED';\n approve: boolean;\n receipt: LithicReceipt;\n}\n\nexport class VorimLithic {\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: LithicConfig) {\n if (!config?.agentId) throw new Error('[vorim] Lithic 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 --------------------------------------------------------\n\n private async guardLifecycle<T>(\n operation: string,\n meta: LithicCardMeta,\n run: () => Promise<T>,\n ): Promise<{ receipt: LithicReceipt; 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('lithic operation failed'), {\n vorimReceipt: this.lifecycleReceipt(operation, meta, true, 'error', e?.message, recorded),\n });\n }\n }\n\n /** Guard creating a card (POST /v1/cards). Requires agent:write. Use\n * cardType SINGLE_USE for one-shot spend or MERCHANT_LOCKED to pin a merchant. */\n guardedCreateCard<T>(meta: LithicCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('createCard', meta, run);\n }\n\n /** Guard updating a card's spend limit or state (PATCH /v1/cards/{token}),\n * e.g. state PAUSED. Requires agent:write. */\n guardedUpdateSpendLimit<T>(meta: LithicCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('updateCard', meta, run);\n }\n\n /** Guard creating an auth rule (velocity/MCC/amount guardrail). agent:write. */\n guardedCreateAuthRule<T>(meta: LithicCardMeta, run: () => Promise<T>) {\n return this.guardLifecycle('authRule', meta, run);\n }\n\n // --- Auth Stream Access decision (the signing checkpoint) ------------------\n\n /**\n * Decide a real-time Lithic authorization. Call from your ASA endpoint and\n * return `{ result: decision.result, token }` to Lithic. Within the ceiling\n * approves; above it declines (fail-closed) or escalates to a named approver.\n * Every decision is signed.\n */\n async guardedAsaDecision(req: LithicAsaRequest): Promise<AsaDecision> {\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 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.recordAsa(req, 'declined', {\n reason: `trust score below ${this.minTrustScore}`,\n authOutcome: overCeiling ? 'over-ceiling-declined' : 'within',\n });\n return this.asaDecision(req, false, `trust score below ${this.minTrustScore}`, overCeiling ? 'over-ceiling-declined' : 'within', undefined, undefined, rec);\n }\n }\n\n if (overCeiling) {\n if (this.escalateOverCeiling) {\n const esc = await this.escalate(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 approve = false;\n outcome = 'over-ceiling-declined';\n reason = `authorization ${req.amount} exceeds this agent's ceiling of ${this.maxAuthorizationAmount}`;\n }\n } else {\n const perm = await this.sdk.check(this.agentId, 'agent:transact');\n approve = perm.allowed;\n outcome = 'within';\n reason = perm.allowed ? undefined : (perm.reason ?? 'missing scope agent:transact');\n }\n } catch (e: any) {\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 recorded = await this.recordAsa(req, approve ? 'success' : 'declined', { reason, authOutcome: outcome, approverId, decisionId });\n return this.asaDecision(req, approve, reason, outcome, approverId, decisionId, recorded);\n }\n\n private async escalate(req: LithicAsaRequest): 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: 'lithic:asaDecision',\n requiredScope: 'agent:transact',\n payload: { amount: req.amount, currency: req.currency, limit: this.maxAuthorizationAmount, card_token: req.cardToken, token: req.token },\n context: { integration: 'lithic', requires_named_approver: true, approver_hint: this.approverId, merchant: req.merchant },\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 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: LithicCardMeta,\n result: 'success' | 'denied' | 'error',\n reason?: string,\n ): Promise<boolean> {\n try {\n await this.sdk.emit(\n {\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `lithic:${operation}${meta.cardToken ? ' ' + meta.cardToken : ''}`,\n resource: meta.cardToken || 'lithic',\n permission: this.scopeFor(operation),\n result,\n input_hash: meta.inputHash,\n metadata: {\n integration: 'lithic',\n operation,\n acts_for_human: this.humanId,\n ...(meta.cardType ? { card_type: meta.cardType } : {}),\n ...(meta.spendLimit != null ? { spend_limit: meta.spendLimit } : {}),\n ...(reason ? { reason } : {}),\n },\n },\n { sign: true },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n private async recordAsa(\n req: LithicAsaRequest,\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: `lithic:asaDecision${req.token ? ' ' + req.token : ''}`,\n resource: req.cardToken || 'lithic',\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: 'lithic',\n operation: 'asaDecision',\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 },\n );\n return true;\n } catch {\n return false;\n }\n }\n\n private lifecycleReceipt(\n operation: string,\n meta: LithicCardMeta,\n authorized: boolean,\n result: 'success' | 'denied' | 'error',\n reason: string | undefined,\n recorded: boolean,\n ): LithicReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n operation,\n cardToken: meta.cardToken,\n cardType: meta.cardType,\n result,\n scope: this.scopeFor(operation),\n reason,\n recorded,\n };\n }\n\n private asaDecision(\n req: LithicAsaRequest,\n approve: boolean,\n reason: string | undefined,\n authOutcome: AuthOutcome,\n approverId: string | undefined,\n decisionId: string | undefined,\n recorded: boolean,\n ): AsaDecision {\n return {\n result: approve ? 'APPROVED' : 'DECLINED',\n approve,\n receipt: {\n authorized: approve,\n agentId: this.agentId,\n humanId: this.humanId,\n operation: 'asaDecision',\n cardToken: req.cardToken,\n amount: req.amount,\n currency: req.currency,\n authOutcome,\n approverId,\n result: approve ? 'success' : 'declined',\n scope: 'agent:transact',\n reason,\n decisionId,\n recorded,\n },\n };\n }\n}\n\n/**\n * Create a VorimLithic guard around a Vorim SDK instance.\n *\n * @example\n * ```typescript\n * import createVorim from '@vorim/sdk';\n * import { createVorimLithic } from '@vorim/sdk/integrations/lithic';\n *\n * const vorim = createVorim({ apiKey: 'agid_sk_...' });\n * const lithic = createVorimLithic(vorim, { agentId: 'agid_abc123', maxAuthorizationAmount: 20000 });\n *\n * const decision = await lithic.guardedAsaDecision({ token: 'txn_1', amount: 4999 });\n * // return { result: decision.result, token: 'txn_1' } to Lithic; decision.receipt is signed.\n * ```\n */\nexport function createVorimLithic(sdk: VorimSDK, config: LithicConfig): VorimLithic {\n return new VorimLithic(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DA,IAAM,kBAAmD;AAAA,EACvD,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,aAAa;AACf;AAsEO,IAAM,cAAN,MAAkB;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAAsB;AAC/C,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,iDAAiD;AACvF,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,UAAU,OAAO;AACtB,SAAK,yBAAyB,OAAO;AACrC,SAAK,sBAAsB,OAAO,uBAAuB;AACzD,SAAK,aAAa,OAAO,cAAc,OAAO;AAC9C,SAAK,sBAAsB,OAAO,uBAAuB;AACzD,SAAK,gBAAgB,OAAO,iBAAiB;AAC7C,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA,EAEQ,SAAS,WAAoC;AACnD,WAAO,gBAAgB,SAAS,KAAK;AAAA,EACvC;AAAA;AAAA,EAIA,MAAc,eACZ,WACA,MACA,KACgD;AAChD,UAAM,QAAQ,KAAK,SAAS,SAAS;AACrC,QAAI,aAAa;AACjB,QAAI;AACJ,QAAI;AACF,UAAI,KAAK,gBAAgB,GAAG;AAC1B,cAAM,QAAQ,MAAM,KAAK,IAAI,OAAO,KAAK,OAAO;AAChD,aAAK,OAAO,eAAe,KAAK,KAAK,eAAe;AAClD,uBAAa;AACb,mBAAS,qBAAqB,KAAK,aAAa;AAAA,QAClD;AAAA,MACF;AACA,UAAI,YAAY;AACd,cAAM,OAAO,MAAM,KAAK,IAAI,MAAM,KAAK,SAAS,KAAK;AACrD,YAAI,CAAC,KAAK,SAAS;AACj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;AAAA,YAC5D,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;AAAA,UACjD;AAAA,QACF;AAAA,QACA,EAAE,MAAM,KAAK;AAAA,MACf;AACA,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,iBACN,WACA,MACA,YACA,QACA,QACA,UACe;AACf,WAAO;AAAA,MACL;AAAA,MACA,SAAS,KAAK;AAAA,MACd,SAAS,KAAK;AAAA,MACd;AAAA,MACA,WAAW,KAAK;AAAA,MAChB,UAAU,KAAK;AAAA,MACf;AAAA,MACA,OAAO,KAAK,SAAS,SAAS;AAAA,MAC9B;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,YACN,KACA,SACA,QACA,aACA,YACA,YACA,UACa;AACb,WAAO;AAAA,MACL,QAAQ,UAAU,aAAa;AAAA,MAC/B;AAAA,MACA,SAAS;AAAA,QACP,YAAY;AAAA,QACZ,SAAS,KAAK;AAAA,QACd,SAAS,KAAK;AAAA,QACd,WAAW;AAAA,QACX,WAAW,IAAI;AAAA,QACf,QAAQ,IAAI;AAAA,QACZ,UAAU,IAAI;AAAA,QACd;AAAA,QACA;AAAA,QACA,QAAQ,UAAU,YAAY;AAAA,QAC9B,OAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAiBO,SAAS,kBAAkB,KAAe,QAAmC;AAClF,SAAO,IAAI,YAAY,KAAK,MAAM;AACpC;","names":[]}
@@ -0,0 +1,130 @@
1
+ import { VorimSDK } from '../index.cjs';
2
+ import { P as PermissionScope } from '../types-zzK9YOoa.cjs';
3
+
4
+ /** Lithic card types. SINGLE_USE and MERCHANT_LOCKED are the agent-friendly
5
+ * ones (one-shot / merchant-pinned delegated spend). */
6
+ type LithicCardType = 'VIRTUAL' | 'SINGLE_USE' | 'MERCHANT_LOCKED';
7
+ type LithicOperation = 'createCard' | 'updateCard' | 'asaDecision' | 'authRule';
8
+ interface LithicConfig {
9
+ /** The acting agent's Vorim id (agid_...). */
10
+ agentId: string;
11
+ /** The person/team the agent acts for. Recorded and default escalation target. */
12
+ humanId?: string;
13
+ /** Attenuation: cap a single ASA authorization, in minor units (cents). Omit
14
+ * for no per-authorization ceiling. */
15
+ maxAuthorizationAmount?: number;
16
+ /** Over the ceiling, escalate to a named approver instead of declining.
17
+ * Default false: over-ceiling is a signed decline (fail-closed spend). */
18
+ escalateOverCeiling?: boolean;
19
+ /** Named approver for an over-ceiling authorization. Defaults to humanId. */
20
+ approverId?: string;
21
+ /** Max wait for an escalation, ms. Default 1800 (Lithic's ASA budget is tight). */
22
+ escalationTimeoutMs?: number;
23
+ /** Minimum trust score before a card op. Default 0. */
24
+ minTrustScore?: number;
25
+ /** Fail closed (decline/deny on any Vorim error) or fail open. Default 'closed'. */
26
+ onError?: 'closed' | 'open';
27
+ }
28
+ interface LithicCardMeta {
29
+ cardToken?: string;
30
+ cardType?: LithicCardType;
31
+ /** The Lithic spend_limit set on the card, in cents. Recorded. */
32
+ spendLimit?: number;
33
+ inputHash?: string;
34
+ }
35
+ interface LithicAsaRequest {
36
+ /** The Lithic transaction token. Echoed back in the ASA response. */
37
+ token?: string;
38
+ cardToken?: string;
39
+ /** The pending amount, in minor units (cents). Checked against the ceiling. */
40
+ amount: number;
41
+ currency?: string;
42
+ merchant?: string;
43
+ }
44
+ type AuthOutcome = 'within' | 'escalated-approved' | 'escalated-declined' | 'over-ceiling-declined';
45
+ interface LithicReceipt {
46
+ authorized: boolean;
47
+ agentId: string;
48
+ humanId?: string;
49
+ operation: string;
50
+ cardToken?: string;
51
+ cardType?: LithicCardType;
52
+ amount?: number;
53
+ currency?: string;
54
+ authOutcome?: AuthOutcome;
55
+ approverId?: string;
56
+ result: 'success' | 'denied' | 'declined' | 'error';
57
+ scope: PermissionScope;
58
+ reason?: string;
59
+ decisionId?: string;
60
+ recorded: boolean;
61
+ }
62
+ /** The ASA decision: the Lithic result string to return, plus the signed
63
+ * receipt. Return `{ result: decision.result, token }` to Lithic. */
64
+ interface AsaDecision {
65
+ /** 'APPROVED' to approve; 'DECLINED' otherwise (any non-APPROVED declines). */
66
+ result: 'APPROVED' | 'DECLINED';
67
+ approve: boolean;
68
+ receipt: LithicReceipt;
69
+ }
70
+ declare class VorimLithic {
71
+ private sdk;
72
+ private agentId;
73
+ private humanId?;
74
+ private maxAuthorizationAmount?;
75
+ private escalateOverCeiling;
76
+ private approverId?;
77
+ private escalationTimeoutMs;
78
+ private minTrustScore;
79
+ private onError;
80
+ constructor(sdk: VorimSDK, config: LithicConfig);
81
+ private scopeFor;
82
+ private guardLifecycle;
83
+ /** Guard creating a card (POST /v1/cards). Requires agent:write. Use
84
+ * cardType SINGLE_USE for one-shot spend or MERCHANT_LOCKED to pin a merchant. */
85
+ guardedCreateCard<T>(meta: LithicCardMeta, run: () => Promise<T>): Promise<{
86
+ receipt: LithicReceipt;
87
+ value?: T | undefined;
88
+ }>;
89
+ /** Guard updating a card's spend limit or state (PATCH /v1/cards/{token}),
90
+ * e.g. state PAUSED. Requires agent:write. */
91
+ guardedUpdateSpendLimit<T>(meta: LithicCardMeta, run: () => Promise<T>): Promise<{
92
+ receipt: LithicReceipt;
93
+ value?: T | undefined;
94
+ }>;
95
+ /** Guard creating an auth rule (velocity/MCC/amount guardrail). agent:write. */
96
+ guardedCreateAuthRule<T>(meta: LithicCardMeta, run: () => Promise<T>): Promise<{
97
+ receipt: LithicReceipt;
98
+ value?: T | undefined;
99
+ }>;
100
+ /**
101
+ * Decide a real-time Lithic authorization. Call from your ASA endpoint and
102
+ * return `{ result: decision.result, token }` to Lithic. Within the ceiling
103
+ * approves; above it declines (fail-closed) or escalates to a named approver.
104
+ * Every decision is signed.
105
+ */
106
+ guardedAsaDecision(req: LithicAsaRequest): Promise<AsaDecision>;
107
+ private escalate;
108
+ private recordLifecycle;
109
+ private recordAsa;
110
+ private lifecycleReceipt;
111
+ private asaDecision;
112
+ }
113
+ /**
114
+ * Create a VorimLithic guard around a Vorim SDK instance.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * import createVorim from '@vorim/sdk';
119
+ * import { createVorimLithic } from '@vorim/sdk/integrations/lithic';
120
+ *
121
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
122
+ * const lithic = createVorimLithic(vorim, { agentId: 'agid_abc123', maxAuthorizationAmount: 20000 });
123
+ *
124
+ * const decision = await lithic.guardedAsaDecision({ token: 'txn_1', amount: 4999 });
125
+ * // return { result: decision.result, token: 'txn_1' } to Lithic; decision.receipt is signed.
126
+ * ```
127
+ */
128
+ declare function createVorimLithic(sdk: VorimSDK, config: LithicConfig): VorimLithic;
129
+
130
+ export { type AsaDecision, type AuthOutcome, type LithicAsaRequest, type LithicCardMeta, type LithicCardType, type LithicConfig, type LithicOperation, type LithicReceipt, VorimLithic, createVorimLithic };
@@ -0,0 +1,130 @@
1
+ import { VorimSDK } from '../index.js';
2
+ import { P as PermissionScope } from '../types-zzK9YOoa.js';
3
+
4
+ /** Lithic card types. SINGLE_USE and MERCHANT_LOCKED are the agent-friendly
5
+ * ones (one-shot / merchant-pinned delegated spend). */
6
+ type LithicCardType = 'VIRTUAL' | 'SINGLE_USE' | 'MERCHANT_LOCKED';
7
+ type LithicOperation = 'createCard' | 'updateCard' | 'asaDecision' | 'authRule';
8
+ interface LithicConfig {
9
+ /** The acting agent's Vorim id (agid_...). */
10
+ agentId: string;
11
+ /** The person/team the agent acts for. Recorded and default escalation target. */
12
+ humanId?: string;
13
+ /** Attenuation: cap a single ASA authorization, in minor units (cents). Omit
14
+ * for no per-authorization ceiling. */
15
+ maxAuthorizationAmount?: number;
16
+ /** Over the ceiling, escalate to a named approver instead of declining.
17
+ * Default false: over-ceiling is a signed decline (fail-closed spend). */
18
+ escalateOverCeiling?: boolean;
19
+ /** Named approver for an over-ceiling authorization. Defaults to humanId. */
20
+ approverId?: string;
21
+ /** Max wait for an escalation, ms. Default 1800 (Lithic's ASA budget is tight). */
22
+ escalationTimeoutMs?: number;
23
+ /** Minimum trust score before a card op. Default 0. */
24
+ minTrustScore?: number;
25
+ /** Fail closed (decline/deny on any Vorim error) or fail open. Default 'closed'. */
26
+ onError?: 'closed' | 'open';
27
+ }
28
+ interface LithicCardMeta {
29
+ cardToken?: string;
30
+ cardType?: LithicCardType;
31
+ /** The Lithic spend_limit set on the card, in cents. Recorded. */
32
+ spendLimit?: number;
33
+ inputHash?: string;
34
+ }
35
+ interface LithicAsaRequest {
36
+ /** The Lithic transaction token. Echoed back in the ASA response. */
37
+ token?: string;
38
+ cardToken?: string;
39
+ /** The pending amount, in minor units (cents). Checked against the ceiling. */
40
+ amount: number;
41
+ currency?: string;
42
+ merchant?: string;
43
+ }
44
+ type AuthOutcome = 'within' | 'escalated-approved' | 'escalated-declined' | 'over-ceiling-declined';
45
+ interface LithicReceipt {
46
+ authorized: boolean;
47
+ agentId: string;
48
+ humanId?: string;
49
+ operation: string;
50
+ cardToken?: string;
51
+ cardType?: LithicCardType;
52
+ amount?: number;
53
+ currency?: string;
54
+ authOutcome?: AuthOutcome;
55
+ approverId?: string;
56
+ result: 'success' | 'denied' | 'declined' | 'error';
57
+ scope: PermissionScope;
58
+ reason?: string;
59
+ decisionId?: string;
60
+ recorded: boolean;
61
+ }
62
+ /** The ASA decision: the Lithic result string to return, plus the signed
63
+ * receipt. Return `{ result: decision.result, token }` to Lithic. */
64
+ interface AsaDecision {
65
+ /** 'APPROVED' to approve; 'DECLINED' otherwise (any non-APPROVED declines). */
66
+ result: 'APPROVED' | 'DECLINED';
67
+ approve: boolean;
68
+ receipt: LithicReceipt;
69
+ }
70
+ declare class VorimLithic {
71
+ private sdk;
72
+ private agentId;
73
+ private humanId?;
74
+ private maxAuthorizationAmount?;
75
+ private escalateOverCeiling;
76
+ private approverId?;
77
+ private escalationTimeoutMs;
78
+ private minTrustScore;
79
+ private onError;
80
+ constructor(sdk: VorimSDK, config: LithicConfig);
81
+ private scopeFor;
82
+ private guardLifecycle;
83
+ /** Guard creating a card (POST /v1/cards). Requires agent:write. Use
84
+ * cardType SINGLE_USE for one-shot spend or MERCHANT_LOCKED to pin a merchant. */
85
+ guardedCreateCard<T>(meta: LithicCardMeta, run: () => Promise<T>): Promise<{
86
+ receipt: LithicReceipt;
87
+ value?: T | undefined;
88
+ }>;
89
+ /** Guard updating a card's spend limit or state (PATCH /v1/cards/{token}),
90
+ * e.g. state PAUSED. Requires agent:write. */
91
+ guardedUpdateSpendLimit<T>(meta: LithicCardMeta, run: () => Promise<T>): Promise<{
92
+ receipt: LithicReceipt;
93
+ value?: T | undefined;
94
+ }>;
95
+ /** Guard creating an auth rule (velocity/MCC/amount guardrail). agent:write. */
96
+ guardedCreateAuthRule<T>(meta: LithicCardMeta, run: () => Promise<T>): Promise<{
97
+ receipt: LithicReceipt;
98
+ value?: T | undefined;
99
+ }>;
100
+ /**
101
+ * Decide a real-time Lithic authorization. Call from your ASA endpoint and
102
+ * return `{ result: decision.result, token }` to Lithic. Within the ceiling
103
+ * approves; above it declines (fail-closed) or escalates to a named approver.
104
+ * Every decision is signed.
105
+ */
106
+ guardedAsaDecision(req: LithicAsaRequest): Promise<AsaDecision>;
107
+ private escalate;
108
+ private recordLifecycle;
109
+ private recordAsa;
110
+ private lifecycleReceipt;
111
+ private asaDecision;
112
+ }
113
+ /**
114
+ * Create a VorimLithic guard around a Vorim SDK instance.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * import createVorim from '@vorim/sdk';
119
+ * import { createVorimLithic } from '@vorim/sdk/integrations/lithic';
120
+ *
121
+ * const vorim = createVorim({ apiKey: 'agid_sk_...' });
122
+ * const lithic = createVorimLithic(vorim, { agentId: 'agid_abc123', maxAuthorizationAmount: 20000 });
123
+ *
124
+ * const decision = await lithic.guardedAsaDecision({ token: 'txn_1', amount: 4999 });
125
+ * // return { result: decision.result, token: 'txn_1' } to Lithic; decision.receipt is signed.
126
+ * ```
127
+ */
128
+ declare function createVorimLithic(sdk: VorimSDK, config: LithicConfig): VorimLithic;
129
+
130
+ export { type AsaDecision, type AuthOutcome, type LithicAsaRequest, type LithicCardMeta, type LithicCardType, type LithicConfig, type LithicOperation, type LithicReceipt, VorimLithic, createVorimLithic };