@dexterai/x402 3.15.0 → 3.17.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,154 @@
1
+ import { W as WalletSet } from './types-xQu1U4xk.cjs';
2
+ import { T as Tab } from './types-DEnVPFxF.cjs';
3
+
4
+ /**
5
+ * Shared contract for the x402 version seam. Both the v1 and v2 strategy
6
+ * modules implement PaymentStrategy. Callers depend ONLY on this file —
7
+ * never on a specific version module.
8
+ */
9
+
10
+ /** A network reference, kept in BOTH forms so neither version loses info. */
11
+ interface NetworkRef {
12
+ /** CAIP-2 form, e.g. "eip155:8453", "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp". */
13
+ caip2: string;
14
+ /** Bare form, e.g. "base", "solana". */
15
+ bare: string;
16
+ /** "evm" | "svm" — which signer family. */
17
+ family: 'evm' | 'svm';
18
+ }
19
+ /** One payment option parsed from a 402 challenge, version-normalised. */
20
+ interface ChallengeOption {
21
+ scheme: string;
22
+ network: NetworkRef;
23
+ /** Atomic amount as a string (e.g. "2000"). */
24
+ amount: string;
25
+ asset: string;
26
+ payTo: string;
27
+ /** Optional — v1 challenges may omit it; a strategy supplies a default when absent. */
28
+ maxTimeoutSeconds?: number;
29
+ /** Scheme-specific extras, passed through verbatim from the merchant. */
30
+ extra?: Record<string, unknown>;
31
+ }
32
+ /** A 402 challenge, normalised across v1 and v2. */
33
+ interface PaymentChallenge {
34
+ x402Version: 1 | 2;
35
+ options: ChallengeOption[];
36
+ resourceUrl?: string;
37
+ }
38
+ /**
39
+ * Result of a paid fetch. Never throws for an expected failure.
40
+ *
41
+ * The `ok: true` branch is further discriminated by `paid`:
42
+ * - `paid: true` — the endpoint demanded payment and we paid; `amountPaid`
43
+ * and `network` are present, `txSignature` optional.
44
+ * `response` is usually the merchant's response, but is
45
+ * `undefined` when the payment settled and the merchant
46
+ * never delivered a response before the deadline (a
47
+ * confirmed-but-unanswered payment — see `payment_unconfirmed`
48
+ * below for the unconfirmed counterpart).
49
+ * - `paid: false` — the endpoint returned a non-402 directly; no payment
50
+ * was attempted. Only `response` is present, because no
51
+ * payment-related fields are meaningful in that case.
52
+ *
53
+ * Callers should narrow on `paid` before reading payment fields. Previously
54
+ * (3.8.x and earlier) the dispatcher returned a phantom `network` placeholder
55
+ * on the unpaid branch; the discriminator forces a correct read.
56
+ */
57
+ type PayResult = {
58
+ ok: true;
59
+ paid: true;
60
+ /**
61
+ * The merchant's response. `undefined` when the payment was confirmed
62
+ * settled but the merchant did not respond before the deadline — you
63
+ * paid, the merchant never answered. Always check before use.
64
+ */
65
+ response: Response | undefined;
66
+ /** Atomic amount actually paid. */
67
+ amountPaid: string;
68
+ network: NetworkRef;
69
+ txSignature?: string;
70
+ } | {
71
+ ok: true;
72
+ paid: false;
73
+ response: Response;
74
+ } | {
75
+ ok: false;
76
+ reason: 'unsupported_network' | 'insufficient_funds'
77
+ /** The merchant rejected the payment itself — bad/declined payload,
78
+ * failed verification. Our side: check the payment. */
79
+ | 'merchant_rejected'
80
+ /** The merchant ACCEPTED the payment shape but their own settlement
81
+ * failed (their facilitator errored). Not our payload — a
82
+ * merchant-side defect. `detail` carries their verbatim error. */
83
+ | 'settlement_failed' | 'no_payment_options'
84
+ /** No payment was sent before the deadline — the unpaid probe (or
85
+ * build/sign) ran past the pre-payment timeout. No money moved;
86
+ * safe to retry. */
87
+ | 'timeout'
88
+ /** The payment authorization WAS sent to the merchant, the merchant
89
+ * did not respond before the deadline, and settlement could not be
90
+ * confirmed. The payment MAY have settled on-chain. DO NOT
91
+ * blind-retry — a retry signs a fresh authorization and can pay
92
+ * again. `detail` explains the state. */
93
+ | 'payment_unconfirmed' | 'budget_exceeded' | 'error';
94
+ detail?: string;
95
+ };
96
+
97
+ /** Options for a paid fetch. */
98
+ interface PayAndFetchOptions {
99
+ /** Max total atomic spend for this call. */
100
+ maxAmountAtomic?: string;
101
+ /**
102
+ * Pre-payment timeout in ms — the deadline for the unpaid probe and the
103
+ * build/sign step, i.e. everything BEFORE the payment authorization is
104
+ * sent. Exceeding it yields `reason: 'timeout'` (no money moved, safe to
105
+ * retry). Default 15000.
106
+ *
107
+ * This does NOT bound the wait for the merchant's response once payment
108
+ * has been dispatched — see `responseTimeoutMs`. The two phases have
109
+ * separate deadlines on purpose: once the payment is out the door,
110
+ * aborting the wait does not un-spend the money.
111
+ */
112
+ timeoutMs?: number;
113
+ /**
114
+ * Post-payment timeout in ms — the deadline for the merchant's response
115
+ * AFTER the payment authorization has been sent. Exceeding it does not
116
+ * yield `'timeout'`; it yields `'payment_unconfirmed'` (or, once on-chain
117
+ * confirmation lands, a confirmed `paid: true`). Default 120000.
118
+ *
119
+ * Generous by design: research / scout / agent endpoints routinely take
120
+ * tens of seconds, and the money is already committed once this phase
121
+ * begins — there is no benefit to a tight deadline here.
122
+ */
123
+ responseTimeoutMs?: number;
124
+ /**
125
+ * Solana RPC endpoint for v1 SVM payment signing. v1 Solana `exact`
126
+ * signing builds a real transaction and needs RPC access (mint lookup,
127
+ * recent blockhash). Ignored for EVM-only flows. Defaults to the public
128
+ * Solana RPC when omitted — callers should pass their own for
129
+ * reliability.
130
+ */
131
+ solanaRpcUrl?: string;
132
+ /**
133
+ * An open spend-tab to pay `tab`-scheme accepts entries with. Used only
134
+ * when the 402 offers scheme "tab" AND the option's payTo matches the
135
+ * counterparty this tab was opened against — otherwise ignored and the
136
+ * normal exact/batch path runs.
137
+ */
138
+ tab?: Tab;
139
+ }
140
+ /**
141
+ * The contract each version module implements.
142
+ *
143
+ * parseChallenge: given a raw 402 Response, extract the challenge — or
144
+ * null if this strategy does not recognise it as its version.
145
+ * pay: given a parsed challenge, sign + send the paid request, return
146
+ * the merchant's response.
147
+ */
148
+ interface PaymentStrategy {
149
+ readonly version: 1 | 2;
150
+ parseChallenge(res: Response): Promise<PaymentChallenge | null>;
151
+ pay(url: string, requestInit: RequestInit, challenge: PaymentChallenge, wallets: WalletSet, opts: PayAndFetchOptions): Promise<PayResult>;
152
+ }
153
+
154
+ export type { ChallengeOption as C, NetworkRef as N, PayAndFetchOptions as P, PayResult as a, PaymentStrategy as b, PaymentChallenge as c };
@@ -0,0 +1,154 @@
1
+ import { W as WalletSet } from './types-xQu1U4xk.js';
2
+ import { T as Tab } from './types-DEnVPFxF.js';
3
+
4
+ /**
5
+ * Shared contract for the x402 version seam. Both the v1 and v2 strategy
6
+ * modules implement PaymentStrategy. Callers depend ONLY on this file —
7
+ * never on a specific version module.
8
+ */
9
+
10
+ /** A network reference, kept in BOTH forms so neither version loses info. */
11
+ interface NetworkRef {
12
+ /** CAIP-2 form, e.g. "eip155:8453", "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp". */
13
+ caip2: string;
14
+ /** Bare form, e.g. "base", "solana". */
15
+ bare: string;
16
+ /** "evm" | "svm" — which signer family. */
17
+ family: 'evm' | 'svm';
18
+ }
19
+ /** One payment option parsed from a 402 challenge, version-normalised. */
20
+ interface ChallengeOption {
21
+ scheme: string;
22
+ network: NetworkRef;
23
+ /** Atomic amount as a string (e.g. "2000"). */
24
+ amount: string;
25
+ asset: string;
26
+ payTo: string;
27
+ /** Optional — v1 challenges may omit it; a strategy supplies a default when absent. */
28
+ maxTimeoutSeconds?: number;
29
+ /** Scheme-specific extras, passed through verbatim from the merchant. */
30
+ extra?: Record<string, unknown>;
31
+ }
32
+ /** A 402 challenge, normalised across v1 and v2. */
33
+ interface PaymentChallenge {
34
+ x402Version: 1 | 2;
35
+ options: ChallengeOption[];
36
+ resourceUrl?: string;
37
+ }
38
+ /**
39
+ * Result of a paid fetch. Never throws for an expected failure.
40
+ *
41
+ * The `ok: true` branch is further discriminated by `paid`:
42
+ * - `paid: true` — the endpoint demanded payment and we paid; `amountPaid`
43
+ * and `network` are present, `txSignature` optional.
44
+ * `response` is usually the merchant's response, but is
45
+ * `undefined` when the payment settled and the merchant
46
+ * never delivered a response before the deadline (a
47
+ * confirmed-but-unanswered payment — see `payment_unconfirmed`
48
+ * below for the unconfirmed counterpart).
49
+ * - `paid: false` — the endpoint returned a non-402 directly; no payment
50
+ * was attempted. Only `response` is present, because no
51
+ * payment-related fields are meaningful in that case.
52
+ *
53
+ * Callers should narrow on `paid` before reading payment fields. Previously
54
+ * (3.8.x and earlier) the dispatcher returned a phantom `network` placeholder
55
+ * on the unpaid branch; the discriminator forces a correct read.
56
+ */
57
+ type PayResult = {
58
+ ok: true;
59
+ paid: true;
60
+ /**
61
+ * The merchant's response. `undefined` when the payment was confirmed
62
+ * settled but the merchant did not respond before the deadline — you
63
+ * paid, the merchant never answered. Always check before use.
64
+ */
65
+ response: Response | undefined;
66
+ /** Atomic amount actually paid. */
67
+ amountPaid: string;
68
+ network: NetworkRef;
69
+ txSignature?: string;
70
+ } | {
71
+ ok: true;
72
+ paid: false;
73
+ response: Response;
74
+ } | {
75
+ ok: false;
76
+ reason: 'unsupported_network' | 'insufficient_funds'
77
+ /** The merchant rejected the payment itself — bad/declined payload,
78
+ * failed verification. Our side: check the payment. */
79
+ | 'merchant_rejected'
80
+ /** The merchant ACCEPTED the payment shape but their own settlement
81
+ * failed (their facilitator errored). Not our payload — a
82
+ * merchant-side defect. `detail` carries their verbatim error. */
83
+ | 'settlement_failed' | 'no_payment_options'
84
+ /** No payment was sent before the deadline — the unpaid probe (or
85
+ * build/sign) ran past the pre-payment timeout. No money moved;
86
+ * safe to retry. */
87
+ | 'timeout'
88
+ /** The payment authorization WAS sent to the merchant, the merchant
89
+ * did not respond before the deadline, and settlement could not be
90
+ * confirmed. The payment MAY have settled on-chain. DO NOT
91
+ * blind-retry — a retry signs a fresh authorization and can pay
92
+ * again. `detail` explains the state. */
93
+ | 'payment_unconfirmed' | 'budget_exceeded' | 'error';
94
+ detail?: string;
95
+ };
96
+
97
+ /** Options for a paid fetch. */
98
+ interface PayAndFetchOptions {
99
+ /** Max total atomic spend for this call. */
100
+ maxAmountAtomic?: string;
101
+ /**
102
+ * Pre-payment timeout in ms — the deadline for the unpaid probe and the
103
+ * build/sign step, i.e. everything BEFORE the payment authorization is
104
+ * sent. Exceeding it yields `reason: 'timeout'` (no money moved, safe to
105
+ * retry). Default 15000.
106
+ *
107
+ * This does NOT bound the wait for the merchant's response once payment
108
+ * has been dispatched — see `responseTimeoutMs`. The two phases have
109
+ * separate deadlines on purpose: once the payment is out the door,
110
+ * aborting the wait does not un-spend the money.
111
+ */
112
+ timeoutMs?: number;
113
+ /**
114
+ * Post-payment timeout in ms — the deadline for the merchant's response
115
+ * AFTER the payment authorization has been sent. Exceeding it does not
116
+ * yield `'timeout'`; it yields `'payment_unconfirmed'` (or, once on-chain
117
+ * confirmation lands, a confirmed `paid: true`). Default 120000.
118
+ *
119
+ * Generous by design: research / scout / agent endpoints routinely take
120
+ * tens of seconds, and the money is already committed once this phase
121
+ * begins — there is no benefit to a tight deadline here.
122
+ */
123
+ responseTimeoutMs?: number;
124
+ /**
125
+ * Solana RPC endpoint for v1 SVM payment signing. v1 Solana `exact`
126
+ * signing builds a real transaction and needs RPC access (mint lookup,
127
+ * recent blockhash). Ignored for EVM-only flows. Defaults to the public
128
+ * Solana RPC when omitted — callers should pass their own for
129
+ * reliability.
130
+ */
131
+ solanaRpcUrl?: string;
132
+ /**
133
+ * An open spend-tab to pay `tab`-scheme accepts entries with. Used only
134
+ * when the 402 offers scheme "tab" AND the option's payTo matches the
135
+ * counterparty this tab was opened against — otherwise ignored and the
136
+ * normal exact/batch path runs.
137
+ */
138
+ tab?: Tab;
139
+ }
140
+ /**
141
+ * The contract each version module implements.
142
+ *
143
+ * parseChallenge: given a raw 402 Response, extract the challenge — or
144
+ * null if this strategy does not recognise it as its version.
145
+ * pay: given a parsed challenge, sign + send the paid request, return
146
+ * the merchant's response.
147
+ */
148
+ interface PaymentStrategy {
149
+ readonly version: 1 | 2;
150
+ parseChallenge(res: Response): Promise<PaymentChallenge | null>;
151
+ pay(url: string, requestInit: RequestInit, challenge: PaymentChallenge, wallets: WalletSet, opts: PayAndFetchOptions): Promise<PayResult>;
152
+ }
153
+
154
+ export type { ChallengeOption as C, NetworkRef as N, PayAndFetchOptions as P, PayResult as a, PaymentStrategy as b, PaymentChallenge as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexterai/x402",
3
- "version": "3.15.0",
3
+ "version": "3.17.0",
4
4
  "description": "Full-stack x402 SDK - add paid API monetization to any endpoint. Express middleware, React hooks, Access Pass, dynamic pricing. Solana, Base, Polygon, Arbitrum, Optimism, Avalanche, SKALE.",
5
5
  "author": "Dexter",
6
6
  "license": "MIT",