@useagentpay/sdk 0.1.2 → 0.1.3
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.
- package/dist/index.cjs +306 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.js +296 -32
- package/dist/index.js.map +1 -1
- package/package.json +27 -2
package/dist/index.d.cts
CHANGED
|
@@ -197,6 +197,19 @@ declare class BudgetManager {
|
|
|
197
197
|
initWallet(budget: number, limitPerTx?: number): void;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
interface AgentPayConfig {
|
|
201
|
+
/** When true, approval links are tunneled via Cloudflare for mobile access */
|
|
202
|
+
mobileMode: boolean;
|
|
203
|
+
/** Shell command to send notification. {{url}} is replaced with the approval URL. */
|
|
204
|
+
notifyCommand?: string;
|
|
205
|
+
/** Webhook URL to POST approval payload to */
|
|
206
|
+
notifyWebhook?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
declare function loadConfig(home?: string): AgentPayConfig;
|
|
210
|
+
declare function saveConfig(config: AgentPayConfig, home?: string): void;
|
|
211
|
+
declare function setMobileMode(enabled: boolean, home?: string): AgentPayConfig;
|
|
212
|
+
|
|
200
213
|
declare class TransactionManager {
|
|
201
214
|
private txPath;
|
|
202
215
|
constructor(txPath?: string);
|
|
@@ -294,6 +307,75 @@ interface ApprovalResult {
|
|
|
294
307
|
*/
|
|
295
308
|
declare function requestBrowserApproval(tx: Transaction, tm: TransactionManager, audit: AuditLogger, home?: string): Promise<ApprovalResult>;
|
|
296
309
|
|
|
310
|
+
interface NotifyOptions {
|
|
311
|
+
/** Shell command to run. `{{url}}` is replaced with the approval URL. */
|
|
312
|
+
command?: string;
|
|
313
|
+
/** Webhook URL to POST `{ url, txId, merchant, amount }` to. */
|
|
314
|
+
webhookUrl?: string;
|
|
315
|
+
}
|
|
316
|
+
interface NotifyPayload {
|
|
317
|
+
url: string;
|
|
318
|
+
txId: string;
|
|
319
|
+
merchant: string;
|
|
320
|
+
amount: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Send a notification about a pending mobile approval.
|
|
324
|
+
*
|
|
325
|
+
* Supports two delivery methods (both can be used simultaneously):
|
|
326
|
+
* - `command`: Shell command with `{{url}}` placeholder (e.g. send via iMessage, Telegram, etc.)
|
|
327
|
+
* - `webhookUrl`: HTTP POST endpoint that receives JSON payload
|
|
328
|
+
*
|
|
329
|
+
* Returns an array of results (one per delivery method attempted).
|
|
330
|
+
*/
|
|
331
|
+
declare function sendNotification(payload: NotifyPayload, options: NotifyOptions): Promise<{
|
|
332
|
+
method: string;
|
|
333
|
+
success: boolean;
|
|
334
|
+
error?: string;
|
|
335
|
+
}[]>;
|
|
336
|
+
|
|
337
|
+
interface MobileApprovalOptions {
|
|
338
|
+
/** Notification delivery options */
|
|
339
|
+
notify: NotifyOptions;
|
|
340
|
+
/** AgentPay home directory */
|
|
341
|
+
home?: string;
|
|
342
|
+
}
|
|
343
|
+
interface MobileApprovalResult extends ApprovalResult {
|
|
344
|
+
/** Public URL that was sent to the user */
|
|
345
|
+
approvalUrl: string;
|
|
346
|
+
/** Notification delivery results */
|
|
347
|
+
notifyResults: {
|
|
348
|
+
method: string;
|
|
349
|
+
success: boolean;
|
|
350
|
+
error?: string;
|
|
351
|
+
}[];
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Request approval via a publicly accessible URL.
|
|
355
|
+
*
|
|
356
|
+
* Flow:
|
|
357
|
+
* 1. Start the local approval server (no browser opened)
|
|
358
|
+
* 2. Open a tunnel to expose it publicly
|
|
359
|
+
* 3. Send the tunnel URL to the user via configured notification method
|
|
360
|
+
* 4. Wait for the user to approve/reject (same as browser flow)
|
|
361
|
+
* 5. Clean up tunnel when done
|
|
362
|
+
*/
|
|
363
|
+
declare function requestMobileApproval(tx: Transaction, tm: TransactionManager, audit: AuditLogger, options: MobileApprovalOptions): Promise<MobileApprovalResult>;
|
|
364
|
+
|
|
365
|
+
interface TunnelHandle {
|
|
366
|
+
url: string;
|
|
367
|
+
close: () => void;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Expose a local port via a public HTTPS tunnel using Cloudflare Quick Tunnels.
|
|
371
|
+
*
|
|
372
|
+
* Requires `cloudflared` to be installed on the system. No Cloudflare account
|
|
373
|
+
* needed — quick tunnels generate a random `*.trycloudflare.com` URL.
|
|
374
|
+
*
|
|
375
|
+
* The tunnel process is spawned as a child process and killed when `close()` is called.
|
|
376
|
+
*/
|
|
377
|
+
declare function openTunnel(port: number): Promise<TunnelHandle>;
|
|
378
|
+
|
|
297
379
|
interface SetupResult {
|
|
298
380
|
completed: boolean;
|
|
299
381
|
}
|
|
@@ -354,6 +436,11 @@ declare class AgentPay {
|
|
|
354
436
|
remaining: number;
|
|
355
437
|
};
|
|
356
438
|
};
|
|
439
|
+
get config(): {
|
|
440
|
+
get: () => AgentPayConfig;
|
|
441
|
+
setMobileMode: (enabled: boolean) => AgentPayConfig;
|
|
442
|
+
save: (config: AgentPayConfig) => void;
|
|
443
|
+
};
|
|
357
444
|
get transactions(): {
|
|
358
445
|
propose: (options: ProposeOptions) => Transaction;
|
|
359
446
|
get: (txId: string) => Transaction | undefined;
|
|
@@ -369,6 +456,7 @@ declare class AgentPay {
|
|
|
369
456
|
passphrase?: string;
|
|
370
457
|
reason?: string;
|
|
371
458
|
}>;
|
|
459
|
+
requestMobileApproval: (txId: string, notify: NotifyOptions) => Promise<MobileApprovalResult>;
|
|
372
460
|
execute: (txId: string) => Promise<Receipt>;
|
|
373
461
|
getReceipt: (txId: string) => Receipt | undefined;
|
|
374
462
|
};
|
|
@@ -382,9 +470,10 @@ declare class AgentPay {
|
|
|
382
470
|
pending: Transaction[];
|
|
383
471
|
recent: Transaction[];
|
|
384
472
|
isSetup: boolean;
|
|
473
|
+
mobileMode: boolean;
|
|
385
474
|
};
|
|
386
475
|
}
|
|
387
476
|
|
|
388
477
|
declare const VERSION: string;
|
|
389
478
|
|
|
390
|
-
export { AgentPay, type AgentPayOptions, AlreadyExecutedError, type ApprovalResult, AuditLogger, type BillingCredentials, type BrowserProvider, 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, type SetupResult, 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, openBrowser, promptConfirm, promptInput, promptPassphrase, promptPassphraseSafe, requestBrowserApproval, requestBrowserSetup, saveKeyPair, saveVault, startServer as startDashboardServer, verifyMandate, waitForApproval };
|
|
479
|
+
export { AgentPay, type AgentPayConfig, type AgentPayOptions, AlreadyExecutedError, type ApprovalResult, AuditLogger, type BillingCredentials, type BrowserProvider, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, type MobileApprovalOptions, type MobileApprovalResult, NotApprovedError, NotSetupError, type NotifyOptions, type NotifyPayload, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, type SetupResult, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, type TunnelHandle, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadConfig, loadPrivateKey, loadPublicKey, loadVault, openBrowser, openTunnel, promptConfirm, promptInput, promptPassphrase, promptPassphraseSafe, requestBrowserApproval, requestBrowserSetup, requestMobileApproval, saveConfig, saveKeyPair, saveVault, sendNotification, setMobileMode, startServer as startDashboardServer, verifyMandate, waitForApproval };
|
package/dist/index.d.ts
CHANGED
|
@@ -197,6 +197,19 @@ declare class BudgetManager {
|
|
|
197
197
|
initWallet(budget: number, limitPerTx?: number): void;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
interface AgentPayConfig {
|
|
201
|
+
/** When true, approval links are tunneled via Cloudflare for mobile access */
|
|
202
|
+
mobileMode: boolean;
|
|
203
|
+
/** Shell command to send notification. {{url}} is replaced with the approval URL. */
|
|
204
|
+
notifyCommand?: string;
|
|
205
|
+
/** Webhook URL to POST approval payload to */
|
|
206
|
+
notifyWebhook?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
declare function loadConfig(home?: string): AgentPayConfig;
|
|
210
|
+
declare function saveConfig(config: AgentPayConfig, home?: string): void;
|
|
211
|
+
declare function setMobileMode(enabled: boolean, home?: string): AgentPayConfig;
|
|
212
|
+
|
|
200
213
|
declare class TransactionManager {
|
|
201
214
|
private txPath;
|
|
202
215
|
constructor(txPath?: string);
|
|
@@ -294,6 +307,75 @@ interface ApprovalResult {
|
|
|
294
307
|
*/
|
|
295
308
|
declare function requestBrowserApproval(tx: Transaction, tm: TransactionManager, audit: AuditLogger, home?: string): Promise<ApprovalResult>;
|
|
296
309
|
|
|
310
|
+
interface NotifyOptions {
|
|
311
|
+
/** Shell command to run. `{{url}}` is replaced with the approval URL. */
|
|
312
|
+
command?: string;
|
|
313
|
+
/** Webhook URL to POST `{ url, txId, merchant, amount }` to. */
|
|
314
|
+
webhookUrl?: string;
|
|
315
|
+
}
|
|
316
|
+
interface NotifyPayload {
|
|
317
|
+
url: string;
|
|
318
|
+
txId: string;
|
|
319
|
+
merchant: string;
|
|
320
|
+
amount: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Send a notification about a pending mobile approval.
|
|
324
|
+
*
|
|
325
|
+
* Supports two delivery methods (both can be used simultaneously):
|
|
326
|
+
* - `command`: Shell command with `{{url}}` placeholder (e.g. send via iMessage, Telegram, etc.)
|
|
327
|
+
* - `webhookUrl`: HTTP POST endpoint that receives JSON payload
|
|
328
|
+
*
|
|
329
|
+
* Returns an array of results (one per delivery method attempted).
|
|
330
|
+
*/
|
|
331
|
+
declare function sendNotification(payload: NotifyPayload, options: NotifyOptions): Promise<{
|
|
332
|
+
method: string;
|
|
333
|
+
success: boolean;
|
|
334
|
+
error?: string;
|
|
335
|
+
}[]>;
|
|
336
|
+
|
|
337
|
+
interface MobileApprovalOptions {
|
|
338
|
+
/** Notification delivery options */
|
|
339
|
+
notify: NotifyOptions;
|
|
340
|
+
/** AgentPay home directory */
|
|
341
|
+
home?: string;
|
|
342
|
+
}
|
|
343
|
+
interface MobileApprovalResult extends ApprovalResult {
|
|
344
|
+
/** Public URL that was sent to the user */
|
|
345
|
+
approvalUrl: string;
|
|
346
|
+
/** Notification delivery results */
|
|
347
|
+
notifyResults: {
|
|
348
|
+
method: string;
|
|
349
|
+
success: boolean;
|
|
350
|
+
error?: string;
|
|
351
|
+
}[];
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Request approval via a publicly accessible URL.
|
|
355
|
+
*
|
|
356
|
+
* Flow:
|
|
357
|
+
* 1. Start the local approval server (no browser opened)
|
|
358
|
+
* 2. Open a tunnel to expose it publicly
|
|
359
|
+
* 3. Send the tunnel URL to the user via configured notification method
|
|
360
|
+
* 4. Wait for the user to approve/reject (same as browser flow)
|
|
361
|
+
* 5. Clean up tunnel when done
|
|
362
|
+
*/
|
|
363
|
+
declare function requestMobileApproval(tx: Transaction, tm: TransactionManager, audit: AuditLogger, options: MobileApprovalOptions): Promise<MobileApprovalResult>;
|
|
364
|
+
|
|
365
|
+
interface TunnelHandle {
|
|
366
|
+
url: string;
|
|
367
|
+
close: () => void;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Expose a local port via a public HTTPS tunnel using Cloudflare Quick Tunnels.
|
|
371
|
+
*
|
|
372
|
+
* Requires `cloudflared` to be installed on the system. No Cloudflare account
|
|
373
|
+
* needed — quick tunnels generate a random `*.trycloudflare.com` URL.
|
|
374
|
+
*
|
|
375
|
+
* The tunnel process is spawned as a child process and killed when `close()` is called.
|
|
376
|
+
*/
|
|
377
|
+
declare function openTunnel(port: number): Promise<TunnelHandle>;
|
|
378
|
+
|
|
297
379
|
interface SetupResult {
|
|
298
380
|
completed: boolean;
|
|
299
381
|
}
|
|
@@ -354,6 +436,11 @@ declare class AgentPay {
|
|
|
354
436
|
remaining: number;
|
|
355
437
|
};
|
|
356
438
|
};
|
|
439
|
+
get config(): {
|
|
440
|
+
get: () => AgentPayConfig;
|
|
441
|
+
setMobileMode: (enabled: boolean) => AgentPayConfig;
|
|
442
|
+
save: (config: AgentPayConfig) => void;
|
|
443
|
+
};
|
|
357
444
|
get transactions(): {
|
|
358
445
|
propose: (options: ProposeOptions) => Transaction;
|
|
359
446
|
get: (txId: string) => Transaction | undefined;
|
|
@@ -369,6 +456,7 @@ declare class AgentPay {
|
|
|
369
456
|
passphrase?: string;
|
|
370
457
|
reason?: string;
|
|
371
458
|
}>;
|
|
459
|
+
requestMobileApproval: (txId: string, notify: NotifyOptions) => Promise<MobileApprovalResult>;
|
|
372
460
|
execute: (txId: string) => Promise<Receipt>;
|
|
373
461
|
getReceipt: (txId: string) => Receipt | undefined;
|
|
374
462
|
};
|
|
@@ -382,9 +470,10 @@ declare class AgentPay {
|
|
|
382
470
|
pending: Transaction[];
|
|
383
471
|
recent: Transaction[];
|
|
384
472
|
isSetup: boolean;
|
|
473
|
+
mobileMode: boolean;
|
|
385
474
|
};
|
|
386
475
|
}
|
|
387
476
|
|
|
388
477
|
declare const VERSION: string;
|
|
389
478
|
|
|
390
|
-
export { AgentPay, type AgentPayOptions, AlreadyExecutedError, type ApprovalResult, AuditLogger, type BillingCredentials, type BrowserProvider, 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, type SetupResult, 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, openBrowser, promptConfirm, promptInput, promptPassphrase, promptPassphraseSafe, requestBrowserApproval, requestBrowserSetup, saveKeyPair, saveVault, startServer as startDashboardServer, verifyMandate, waitForApproval };
|
|
479
|
+
export { AgentPay, type AgentPayConfig, type AgentPayOptions, AlreadyExecutedError, type ApprovalResult, AuditLogger, type BillingCredentials, type BrowserProvider, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, type MobileApprovalOptions, type MobileApprovalResult, NotApprovedError, NotSetupError, type NotifyOptions, type NotifyPayload, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, type SetupResult, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, type TunnelHandle, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadConfig, loadPrivateKey, loadPublicKey, loadVault, openBrowser, openTunnel, promptConfirm, promptInput, promptPassphrase, promptPassphraseSafe, requestBrowserApproval, requestBrowserSetup, requestMobileApproval, saveConfig, saveKeyPair, saveVault, sendNotification, setMobileMode, startServer as startDashboardServer, verifyMandate, waitForApproval };
|