@useagentpay/sdk 0.1.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.
@@ -0,0 +1,328 @@
1
+ interface BillingCredentials {
2
+ card: {
3
+ number: string;
4
+ expiry: string;
5
+ cvv: string;
6
+ };
7
+ name: string;
8
+ billingAddress: {
9
+ street: string;
10
+ city: string;
11
+ state: string;
12
+ zip: string;
13
+ country: string;
14
+ };
15
+ shippingAddress: {
16
+ street: string;
17
+ city: string;
18
+ state: string;
19
+ zip: string;
20
+ country: string;
21
+ };
22
+ email: string;
23
+ phone: string;
24
+ }
25
+ interface EncryptedVault {
26
+ ciphertext: string;
27
+ salt: string;
28
+ iv: string;
29
+ }
30
+
31
+ interface KeyPair {
32
+ publicKey: string;
33
+ privateKey: string;
34
+ }
35
+ interface PurchaseMandate {
36
+ txId: string;
37
+ txHash: string;
38
+ signature: string;
39
+ publicKey: string;
40
+ timestamp: string;
41
+ }
42
+ interface TransactionDetails {
43
+ txId: string;
44
+ merchant: string;
45
+ amount: number;
46
+ description: string;
47
+ timestamp: string;
48
+ }
49
+
50
+ interface Wallet {
51
+ budget: number;
52
+ balance: number;
53
+ limitPerTx: number;
54
+ spent: number;
55
+ }
56
+
57
+ type TransactionStatus = 'pending' | 'approved' | 'rejected' | 'executing' | 'completed' | 'failed';
58
+ interface Transaction {
59
+ id: string;
60
+ status: TransactionStatus;
61
+ merchant: string;
62
+ amount: number;
63
+ description: string;
64
+ url: string;
65
+ createdAt: string;
66
+ mandate?: PurchaseMandate;
67
+ receipt?: Receipt;
68
+ rejectionReason?: string;
69
+ error?: string;
70
+ }
71
+ interface Receipt {
72
+ id: string;
73
+ merchant: string;
74
+ amount: number;
75
+ confirmationId: string;
76
+ completedAt: string;
77
+ }
78
+ interface ProposeOptions {
79
+ merchant: string;
80
+ amount: number;
81
+ description: string;
82
+ url: string;
83
+ }
84
+
85
+ interface CheckoutResult {
86
+ success: boolean;
87
+ confirmationId?: string;
88
+ error?: string;
89
+ }
90
+ interface ExecutorConfig {
91
+ browserbaseApiKey?: string;
92
+ browserbaseProjectId?: string;
93
+ modelApiKey?: string;
94
+ }
95
+
96
+ declare class NotSetupError extends Error {
97
+ readonly code = "NOT_SETUP";
98
+ constructor(message?: string);
99
+ }
100
+ declare class DecryptError extends Error {
101
+ readonly code = "DECRYPT_FAILED";
102
+ constructor(message?: string);
103
+ }
104
+ declare class InsufficientBalanceError extends Error {
105
+ readonly code = "INSUFFICIENT_BALANCE";
106
+ constructor(amount?: number, balance?: number);
107
+ }
108
+ declare class ExceedsTxLimitError extends Error {
109
+ readonly code = "EXCEEDS_TX_LIMIT";
110
+ constructor(amount?: number, limit?: number);
111
+ }
112
+ declare class NotApprovedError extends Error {
113
+ readonly code = "NOT_APPROVED";
114
+ constructor(txId?: string);
115
+ }
116
+ declare class InvalidMandateError extends Error {
117
+ readonly code = "INVALID_MANDATE";
118
+ constructor(message?: string);
119
+ }
120
+ declare class AlreadyExecutedError extends Error {
121
+ readonly code = "ALREADY_EXECUTED";
122
+ constructor(txId?: string);
123
+ }
124
+ declare class CheckoutFailedError extends Error {
125
+ readonly code = "CHECKOUT_FAILED";
126
+ constructor(message?: string);
127
+ }
128
+ declare class TimeoutError extends Error {
129
+ readonly code = "TIMEOUT";
130
+ constructor(message?: string);
131
+ }
132
+
133
+ declare function generateTxId(): string;
134
+
135
+ declare function formatCurrency(amount: number): string;
136
+ declare function formatTimestamp(iso: string): string;
137
+ declare function formatTable(transactions: Transaction[]): string;
138
+ declare function formatStatus(data: {
139
+ balance: number;
140
+ budget: number;
141
+ limitPerTx: number;
142
+ pending: Transaction[];
143
+ recent: Transaction[];
144
+ }): string;
145
+
146
+ declare function getHomePath(): string;
147
+ declare function getCredentialsPath(): string;
148
+ declare function getKeysPath(): string;
149
+ declare function getWalletPath(): string;
150
+ declare function getTransactionsPath(): string;
151
+ declare function getAuditPath(): string;
152
+
153
+ declare function encrypt(credentials: BillingCredentials, passphrase: string): EncryptedVault;
154
+ declare function decrypt(vault: EncryptedVault, passphrase: string): BillingCredentials;
155
+ declare function saveVault(vault: EncryptedVault, path?: string): void;
156
+ declare function loadVault(path?: string): EncryptedVault;
157
+
158
+ declare function generateKeyPair(passphrase: string): KeyPair;
159
+ declare function saveKeyPair(keys: KeyPair, publicPath?: string, privatePath?: string): void;
160
+ declare function loadPublicKey(path?: string): string;
161
+ declare function loadPrivateKey(path?: string): string;
162
+
163
+ declare function createMandate(txDetails: TransactionDetails, privateKeyPem: string, passphrase: string): PurchaseMandate;
164
+ declare function verifyMandate(mandate: PurchaseMandate, txDetails: TransactionDetails): boolean;
165
+
166
+ declare class BudgetManager {
167
+ private walletPath;
168
+ constructor(walletPath?: string);
169
+ getWallet(): Wallet;
170
+ private saveWallet;
171
+ setBudget(amount: number): void;
172
+ setLimitPerTx(limit: number): void;
173
+ deductBalance(amount: number): void;
174
+ checkProposal(amount: number): void;
175
+ addFunds(amount: number): Wallet;
176
+ getBalance(): {
177
+ budget: number;
178
+ balance: number;
179
+ limitPerTx: number;
180
+ spent: number;
181
+ };
182
+ initWallet(budget: number, limitPerTx?: number): void;
183
+ }
184
+
185
+ declare class TransactionManager {
186
+ private txPath;
187
+ constructor(txPath?: string);
188
+ private loadAll;
189
+ private saveAll;
190
+ propose(options: ProposeOptions): Transaction;
191
+ get(txId: string): Transaction | undefined;
192
+ approve(txId: string, mandate: PurchaseMandate): void;
193
+ reject(txId: string, reason?: string): void;
194
+ markExecuting(txId: string): void;
195
+ markCompleted(txId: string, receipt: Receipt): void;
196
+ markFailed(txId: string, error: string): void;
197
+ list(): Transaction[];
198
+ getPending(): Transaction[];
199
+ getHistory(): Transaction[];
200
+ }
201
+
202
+ interface PollOptions {
203
+ pollInterval?: number;
204
+ timeout?: number;
205
+ }
206
+ declare function waitForApproval(txId: string, manager: TransactionManager, options?: PollOptions): Promise<{
207
+ status: 'approved' | 'rejected';
208
+ reason?: string;
209
+ }>;
210
+
211
+ declare class AuditLogger {
212
+ private logPath;
213
+ constructor(logPath?: string);
214
+ log(action: string, details: Record<string, unknown>): void;
215
+ getLog(): string[];
216
+ }
217
+
218
+ interface DiscoverResult {
219
+ price: number;
220
+ productName: string;
221
+ }
222
+ declare class PurchaseExecutor {
223
+ private config;
224
+ private stagehand;
225
+ constructor(config?: ExecutorConfig);
226
+ private createStagehand;
227
+ /**
228
+ * Phase 1: Open browser, navigate to URL, extract price and product info.
229
+ * Keeps the session alive for fillAndComplete().
230
+ */
231
+ openAndDiscover(url: string, instructions?: string): Promise<DiscoverResult>;
232
+ /**
233
+ * Phase 2: Proceed to checkout, fill forms, swap credentials, and submit.
234
+ * Must be called after openAndDiscover().
235
+ */
236
+ fillAndComplete(credentials: BillingCredentials): Promise<CheckoutResult>;
237
+ /**
238
+ * Convenience: single-shot execute (navigate + checkout in one call).
239
+ * Used by AgentPay facade when amount is already known.
240
+ */
241
+ execute(tx: Transaction, credentials: BillingCredentials): Promise<CheckoutResult>;
242
+ close(): Promise<void>;
243
+ }
244
+
245
+ declare const PLACEHOLDER_MAP: {
246
+ readonly card_number: "{{card_number}}";
247
+ readonly cardholder_name: "{{cardholder_name}}";
248
+ readonly card_expiry: "{{card_expiry}}";
249
+ readonly card_cvv: "{{card_cvv}}";
250
+ readonly billing_street: "{{billing_street}}";
251
+ readonly billing_city: "{{billing_city}}";
252
+ readonly billing_state: "{{billing_state}}";
253
+ readonly billing_zip: "{{billing_zip}}";
254
+ readonly billing_country: "{{billing_country}}";
255
+ readonly shipping_street: "{{shipping_street}}";
256
+ readonly shipping_city: "{{shipping_city}}";
257
+ readonly shipping_state: "{{shipping_state}}";
258
+ readonly shipping_zip: "{{shipping_zip}}";
259
+ readonly shipping_country: "{{shipping_country}}";
260
+ readonly email: "{{email}}";
261
+ readonly phone: "{{phone}}";
262
+ };
263
+ declare function getPlaceholderVariables(): Record<string, string>;
264
+ declare function credentialsToSwapMap(creds: BillingCredentials): Record<string, string>;
265
+
266
+ interface AgentPayOptions {
267
+ home?: string;
268
+ passphrase?: string;
269
+ executor?: ExecutorConfig;
270
+ }
271
+ declare class AgentPay {
272
+ readonly home: string;
273
+ private passphrase?;
274
+ private budgetManager;
275
+ private txManager;
276
+ private auditLogger;
277
+ private executor;
278
+ constructor(options?: AgentPayOptions);
279
+ get wallet(): {
280
+ getBalance: () => {
281
+ budget: number;
282
+ balance: number;
283
+ limitPerTx: number;
284
+ spent: number;
285
+ };
286
+ getHistory: () => Transaction[];
287
+ getLimits: () => {
288
+ budget: number;
289
+ limitPerTx: number;
290
+ remaining: number;
291
+ };
292
+ generateFundingQR: (options?: {
293
+ suggestedBudget?: number;
294
+ message?: string;
295
+ }) => Promise<{
296
+ url: string;
297
+ qrDataUrl: string;
298
+ }>;
299
+ };
300
+ get transactions(): {
301
+ propose: (options: ProposeOptions) => Transaction;
302
+ get: (txId: string) => Transaction | undefined;
303
+ waitForApproval: (txId: string, options?: {
304
+ pollInterval?: number;
305
+ timeout?: number;
306
+ }) => Promise<{
307
+ status: "approved" | "rejected";
308
+ reason?: string;
309
+ }>;
310
+ execute: (txId: string) => Promise<Receipt>;
311
+ getReceipt: (txId: string) => Receipt | undefined;
312
+ };
313
+ get audit(): {
314
+ getLog: () => string[];
315
+ };
316
+ status(): {
317
+ balance: number;
318
+ budget: number;
319
+ limitPerTx: number;
320
+ pending: Transaction[];
321
+ recent: Transaction[];
322
+ isSetup: boolean;
323
+ };
324
+ }
325
+
326
+ declare const VERSION = "0.1.0";
327
+
328
+ export { AgentPay, type AgentPayOptions, AlreadyExecutedError, AuditLogger, type BillingCredentials, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, NotApprovedError, NotSetupError, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadPrivateKey, loadPublicKey, loadVault, saveKeyPair, saveVault, verifyMandate, waitForApproval };