@haven_ai/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/README.md +46 -9
- package/dist/index.cjs +345 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -3
- package/dist/index.d.ts +49 -3
- package/dist/index.js +345 -63
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -113,6 +113,43 @@ interface X402Receipt {
|
|
|
113
113
|
merchantTo?: string | null;
|
|
114
114
|
payer?: string;
|
|
115
115
|
chainId?: number;
|
|
116
|
+
haven?: {
|
|
117
|
+
paymentId: string;
|
|
118
|
+
fundingTxHash: string;
|
|
119
|
+
fundingExplorerUrl: string;
|
|
120
|
+
};
|
|
121
|
+
merchant?: {
|
|
122
|
+
payTo: string | null;
|
|
123
|
+
settlementTxHash?: string | null;
|
|
124
|
+
settlementExplorerUrl?: string | null;
|
|
125
|
+
};
|
|
126
|
+
x402?: {
|
|
127
|
+
amount: string;
|
|
128
|
+
token: string;
|
|
129
|
+
network: string;
|
|
130
|
+
asset: string;
|
|
131
|
+
resource: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
interface X402AuthorizationOptions {
|
|
135
|
+
/** Stable caller-supplied key for this user intent. Prevents duplicate approvals across fresh 402 quotes. */
|
|
136
|
+
idempotencyKey?: string;
|
|
137
|
+
}
|
|
138
|
+
interface ResumeAuthorizedX402Input extends X402AuthorizationOptions {
|
|
139
|
+
/** Payment or approval request ID returned by authorizeX402 / haven.fetch. */
|
|
140
|
+
paymentId: string;
|
|
141
|
+
/** Original or freshly parsed x402 requirements for the merchant retry. */
|
|
142
|
+
paymentRequired: X402PaymentRequired;
|
|
143
|
+
}
|
|
144
|
+
interface ResumeX402PaymentInput extends X402AuthorizationOptions {
|
|
145
|
+
/** Payment or approval request ID returned by authorizeX402 / haven.fetch. */
|
|
146
|
+
paymentId: string;
|
|
147
|
+
/** Original paid URL. If paymentRequired is omitted, Haven will call it once to re-read the 402 challenge. */
|
|
148
|
+
url: string;
|
|
149
|
+
/** Original fetch options. Reused for the 402 probe and final merchant retry. */
|
|
150
|
+
init?: RequestInit;
|
|
151
|
+
/** Original or freshly parsed x402 requirements. Supplying this avoids an extra merchant 402 probe. */
|
|
152
|
+
paymentRequired?: X402PaymentRequired;
|
|
116
153
|
}
|
|
117
154
|
type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
|
|
118
155
|
interface MachinePaymentChallenge {
|
|
@@ -273,8 +310,10 @@ declare class HavenClient {
|
|
|
273
310
|
*
|
|
274
311
|
* Requires `delegateKey` to be set in the client config.
|
|
275
312
|
*/
|
|
276
|
-
authorizeX402(paymentRequired: X402PaymentRequired): Promise<X402Receipt>;
|
|
313
|
+
authorizeX402(paymentRequired: X402PaymentRequired, options?: X402AuthorizationOptions): Promise<X402Receipt>;
|
|
277
314
|
private authorizeStandardX402;
|
|
315
|
+
resumeAuthorizedX402(input: ResumeAuthorizedX402Input): Promise<X402Receipt>;
|
|
316
|
+
resumeX402Payment(input: ResumeX402PaymentInput): Promise<Response>;
|
|
278
317
|
/**
|
|
279
318
|
* Fetch wrapper that automatically handles HTTP 402 responses.
|
|
280
319
|
*
|
|
@@ -288,10 +327,15 @@ declare class HavenClient {
|
|
|
288
327
|
*
|
|
289
328
|
* Requires `delegateKey` to be set in the client config.
|
|
290
329
|
*/
|
|
291
|
-
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
330
|
+
fetch(url: string, init?: RequestInit, options?: X402AuthorizationOptions): Promise<Response>;
|
|
331
|
+
private retryX402Request;
|
|
292
332
|
authorizeMachinePayment(challenge: MachinePaymentChallenge): Promise<MachinePaymentReceipt>;
|
|
293
333
|
private authorizeMppDemoPayment;
|
|
294
334
|
private fetchWithMachinePayment;
|
|
335
|
+
private assertCanResumeX402;
|
|
336
|
+
private mapX402ReceiptFromAuthorization;
|
|
337
|
+
private mapX402ReceiptFromStatus;
|
|
338
|
+
private buildX402Receipt;
|
|
295
339
|
private createStandardX402Header;
|
|
296
340
|
private cacheX402Receipt;
|
|
297
341
|
private mapMachinePaymentReceipt;
|
|
@@ -315,6 +359,8 @@ declare class HavenClient {
|
|
|
315
359
|
* ```
|
|
316
360
|
*/
|
|
317
361
|
executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
362
|
+
private toolX402PaymentRequired;
|
|
363
|
+
private x402ToolReceipt;
|
|
318
364
|
private toolError;
|
|
319
365
|
private post;
|
|
320
366
|
private get;
|
|
@@ -450,4 +496,4 @@ declare function parseMachinePaymentChallengeResponse(response: Response): Promi
|
|
|
450
496
|
declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
|
|
451
497
|
declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
|
|
452
498
|
|
|
453
|
-
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|
|
499
|
+
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedX402Input, type ResumeX402PaymentInput, type SignData, type X402AuthorizationOptions, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,43 @@ interface X402Receipt {
|
|
|
113
113
|
merchantTo?: string | null;
|
|
114
114
|
payer?: string;
|
|
115
115
|
chainId?: number;
|
|
116
|
+
haven?: {
|
|
117
|
+
paymentId: string;
|
|
118
|
+
fundingTxHash: string;
|
|
119
|
+
fundingExplorerUrl: string;
|
|
120
|
+
};
|
|
121
|
+
merchant?: {
|
|
122
|
+
payTo: string | null;
|
|
123
|
+
settlementTxHash?: string | null;
|
|
124
|
+
settlementExplorerUrl?: string | null;
|
|
125
|
+
};
|
|
126
|
+
x402?: {
|
|
127
|
+
amount: string;
|
|
128
|
+
token: string;
|
|
129
|
+
network: string;
|
|
130
|
+
asset: string;
|
|
131
|
+
resource: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
interface X402AuthorizationOptions {
|
|
135
|
+
/** Stable caller-supplied key for this user intent. Prevents duplicate approvals across fresh 402 quotes. */
|
|
136
|
+
idempotencyKey?: string;
|
|
137
|
+
}
|
|
138
|
+
interface ResumeAuthorizedX402Input extends X402AuthorizationOptions {
|
|
139
|
+
/** Payment or approval request ID returned by authorizeX402 / haven.fetch. */
|
|
140
|
+
paymentId: string;
|
|
141
|
+
/** Original or freshly parsed x402 requirements for the merchant retry. */
|
|
142
|
+
paymentRequired: X402PaymentRequired;
|
|
143
|
+
}
|
|
144
|
+
interface ResumeX402PaymentInput extends X402AuthorizationOptions {
|
|
145
|
+
/** Payment or approval request ID returned by authorizeX402 / haven.fetch. */
|
|
146
|
+
paymentId: string;
|
|
147
|
+
/** Original paid URL. If paymentRequired is omitted, Haven will call it once to re-read the 402 challenge. */
|
|
148
|
+
url: string;
|
|
149
|
+
/** Original fetch options. Reused for the 402 probe and final merchant retry. */
|
|
150
|
+
init?: RequestInit;
|
|
151
|
+
/** Original or freshly parsed x402 requirements. Supplying this avoids an extra merchant 402 probe. */
|
|
152
|
+
paymentRequired?: X402PaymentRequired;
|
|
116
153
|
}
|
|
117
154
|
type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
|
|
118
155
|
interface MachinePaymentChallenge {
|
|
@@ -273,8 +310,10 @@ declare class HavenClient {
|
|
|
273
310
|
*
|
|
274
311
|
* Requires `delegateKey` to be set in the client config.
|
|
275
312
|
*/
|
|
276
|
-
authorizeX402(paymentRequired: X402PaymentRequired): Promise<X402Receipt>;
|
|
313
|
+
authorizeX402(paymentRequired: X402PaymentRequired, options?: X402AuthorizationOptions): Promise<X402Receipt>;
|
|
277
314
|
private authorizeStandardX402;
|
|
315
|
+
resumeAuthorizedX402(input: ResumeAuthorizedX402Input): Promise<X402Receipt>;
|
|
316
|
+
resumeX402Payment(input: ResumeX402PaymentInput): Promise<Response>;
|
|
278
317
|
/**
|
|
279
318
|
* Fetch wrapper that automatically handles HTTP 402 responses.
|
|
280
319
|
*
|
|
@@ -288,10 +327,15 @@ declare class HavenClient {
|
|
|
288
327
|
*
|
|
289
328
|
* Requires `delegateKey` to be set in the client config.
|
|
290
329
|
*/
|
|
291
|
-
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
330
|
+
fetch(url: string, init?: RequestInit, options?: X402AuthorizationOptions): Promise<Response>;
|
|
331
|
+
private retryX402Request;
|
|
292
332
|
authorizeMachinePayment(challenge: MachinePaymentChallenge): Promise<MachinePaymentReceipt>;
|
|
293
333
|
private authorizeMppDemoPayment;
|
|
294
334
|
private fetchWithMachinePayment;
|
|
335
|
+
private assertCanResumeX402;
|
|
336
|
+
private mapX402ReceiptFromAuthorization;
|
|
337
|
+
private mapX402ReceiptFromStatus;
|
|
338
|
+
private buildX402Receipt;
|
|
295
339
|
private createStandardX402Header;
|
|
296
340
|
private cacheX402Receipt;
|
|
297
341
|
private mapMachinePaymentReceipt;
|
|
@@ -315,6 +359,8 @@ declare class HavenClient {
|
|
|
315
359
|
* ```
|
|
316
360
|
*/
|
|
317
361
|
executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
362
|
+
private toolX402PaymentRequired;
|
|
363
|
+
private x402ToolReceipt;
|
|
318
364
|
private toolError;
|
|
319
365
|
private post;
|
|
320
366
|
private get;
|
|
@@ -450,4 +496,4 @@ declare function parseMachinePaymentChallengeResponse(response: Response): Promi
|
|
|
450
496
|
declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
|
|
451
497
|
declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
|
|
452
498
|
|
|
453
|
-
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|
|
499
|
+
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedX402Input, type ResumeX402PaymentInput, type SignData, type X402AuthorizationOptions, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|