@dexterai/x402 3.8.0 → 3.9.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.
@@ -1,9 +1,83 @@
1
- import { C as ChainAdapter, W as WalletSet, A as AccessPassClientConfig, P as PaymentAccept } from './types-htvWHuW3.cjs';
2
1
  import { SponsoredRecommendation, SponsoredAccessSettlementInfo } from '@dexterai/x402-ads-types';
2
+ import { C as ChainAdapter, W as WalletSet, A as AccessPassClientConfig, P as PaymentAccept, S as SettlementProbe } from './types-RxdlGPaG.js';
3
+
4
+ /**
5
+ * Sponsored Access (Ads for Agents) — Client Helpers
6
+ *
7
+ * Extract sponsored recommendations from x402 payment receipts and
8
+ * fire impression beacons to confirm delivery to the ad network.
9
+ *
10
+ * Recommendations are injected by the facilitator after settlement
11
+ * via the `extensions["sponsored-access"]` field. Publishers who enable
12
+ * `sponsoredAccess: true` in their middleware also inject them into
13
+ * the JSON response body as `_x402_sponsored`.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { wrapFetch, getSponsoredRecommendations, fireImpressionBeacon } from '@dexterai/x402/client';
18
+ *
19
+ * const x402Fetch = wrapFetch(fetch, { walletPrivateKey: key });
20
+ * const response = await x402Fetch('https://api.example.com/data');
21
+ *
22
+ * const recs = getSponsoredRecommendations(response);
23
+ * if (recs) {
24
+ * console.log('Sponsored:', recs.map(r => `${r.sponsor}: ${r.description}`));
25
+ * await fireImpressionBeacon(response); // Confirm delivery to ad network
26
+ * }
27
+ * ```
28
+ */
29
+
30
+ /**
31
+ * Extract the full sponsored-access extension data from a payment receipt.
32
+ * Returns undefined if no sponsored-access extension is present.
33
+ */
34
+ declare function getSponsoredAccessInfo(response: Response): SponsoredAccessSettlementInfo | undefined;
35
+ /**
36
+ * Extract sponsored recommendations from an x402 payment response.
37
+ * Returns the recommendations array, or undefined if none present.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const recs = getSponsoredRecommendations(response);
42
+ * if (recs) {
43
+ * for (const rec of recs) {
44
+ * console.log(`${rec.sponsor}: ${rec.description} — ${rec.resourceUrl}`);
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ declare function getSponsoredRecommendations(response: Response): SponsoredRecommendation[] | undefined;
50
+ /**
51
+ * Fire the impression beacon to confirm recommendation delivery to the ad network.
52
+ * This is a fire-and-forget GET request — failures are silently ignored.
53
+ *
54
+ * Call this after you've read the recommendations to help the ad network
55
+ * track delivery rates and verify impressions.
56
+ *
57
+ * @returns true if the beacon was fired (regardless of response), false if no beacon URL
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const recs = getSponsoredRecommendations(response);
62
+ * if (recs) {
63
+ * // Process recommendations...
64
+ * await fireImpressionBeacon(response);
65
+ * }
66
+ * ```
67
+ */
68
+ declare function fireImpressionBeacon(response: Response): Promise<boolean>;
3
69
 
4
70
  /**
5
71
  * x402 v2 Client
6
72
  *
73
+ * `createX402Client`, `X402Client`, and `X402ClientConfig` are
74
+ * @deprecated — slated for removal in `@dexterai/x402` 5.0 (~6 months out;
75
+ * longer cycle than the 4.0 batch because there are real consumers). Use
76
+ * `payAndFetch` from `@dexterai/x402/client` instead — it's the version-
77
+ * agnostic 2026+ client with a discriminated-union return type. The
78
+ * `getPaymentReceipt` helper and `PaymentReceipt` type in this file are NOT
79
+ * deprecated; they continue to support receipt-reading on any paid response.
80
+ *
7
81
  * Chain-agnostic client for x402 v2 payments.
8
82
  * Automatically detects 402 responses, finds a matching payment option,
9
83
  * builds the transaction with the appropriate chain adapter, and retries.
@@ -58,6 +132,9 @@ interface PaymentReceipt {
58
132
  declare function getPaymentReceipt(response: Response): PaymentReceipt | undefined;
59
133
  /**
60
134
  * Client configuration
135
+ *
136
+ * @deprecated Slated for removal in `@dexterai/x402` 5.0 alongside
137
+ * `createX402Client` and `X402Client`. Use `PayAndFetchOptions` instead.
61
138
  */
62
139
  interface X402ClientConfig {
63
140
  /**
@@ -121,6 +198,24 @@ interface X402ClientConfig {
121
198
  * ```
122
199
  */
123
200
  onPaymentRequired?: (requirements: PaymentAccept) => boolean | Promise<boolean>;
201
+ /**
202
+ * Called the instant the signed payment authorization is sent to the
203
+ * merchant — after `buildTransaction`, immediately before the paid retry
204
+ * fetch. This is the point past which a timeout can no longer be treated
205
+ * as "no money moved": the facilitator may settle at any time once the
206
+ * authorization is in its hands.
207
+ *
208
+ * The callback receives the `accept` it is paying against (network, asset,
209
+ * amount, payTo) and the `settlementProbe` the adapter produced (or
210
+ * `undefined` for schemes with no on-chain confirmation). `payAndFetch`
211
+ * uses this to mark a payment as dispatched — so a post-payment abort is
212
+ * not misreported as a plain timeout — and keeps the probe so it can
213
+ * confirm settlement on-chain if the merchant never responds.
214
+ *
215
+ * Fire-and-forget — the return value is ignored, and a throw is swallowed
216
+ * (the payment proceeds regardless). Do not do slow work here.
217
+ */
218
+ onPaymentDispatched?: (accept: PaymentAccept, settlementProbe?: SettlementProbe) => void;
124
219
  /**
125
220
  * Maximum retry attempts for transient failures (network errors, 502/503).
126
221
  * Does not cause double payments — EIP-3009 nonces prevent replay.
@@ -135,6 +230,9 @@ interface X402ClientConfig {
135
230
  }
136
231
  /**
137
232
  * x402 Client interface
233
+ *
234
+ * @deprecated Slated for removal in `@dexterai/x402` 5.0. Use `payAndFetch`
235
+ * directly instead of constructing a client object.
138
236
  */
139
237
  interface X402Client {
140
238
  /**
@@ -145,73 +243,26 @@ interface X402Client {
145
243
  }
146
244
  /**
147
245
  * Create an x402 v2 client
148
- */
149
- declare function createX402Client(config: X402ClientConfig): X402Client;
150
-
151
- /**
152
- * Sponsored Access (Ads for Agents) — Client Helpers
153
- *
154
- * Extract sponsored recommendations from x402 payment receipts and
155
- * fire impression beacons to confirm delivery to the ad network.
156
246
  *
157
- * Recommendations are injected by the facilitator after settlement
158
- * via the `extensions["sponsored-access"]` field. Publishers who enable
159
- * `sponsoredAccess: true` in their middleware also inject them into
160
- * the JSON response body as `_x402_sponsored`.
247
+ * @deprecated Slated for removal in `@dexterai/x402` 5.0 (~6 months out — long
248
+ * cycle because of real production consumers). Use `payAndFetch` from
249
+ * `@dexterai/x402/client` instead it's version-agnostic across x402 v1 and
250
+ * v2 and returns a discriminated union for cleaner error handling.
161
251
  *
162
- * @example
252
+ * Migration:
163
253
  * ```typescript
164
- * import { wrapFetch, getSponsoredRecommendations, fireImpressionBeacon } from '@dexterai/x402/client';
165
- *
166
- * const x402Fetch = wrapFetch(fetch, { walletPrivateKey: key });
167
- * const response = await x402Fetch('https://api.example.com/data');
254
+ * // Before
255
+ * const client = createX402Client({ wallets });
256
+ * const res = await client.fetch(url);
168
257
  *
169
- * const recs = getSponsoredRecommendations(response);
170
- * if (recs) {
171
- * console.log('Sponsored:', recs.map(r => `${r.sponsor}: ${r.description}`));
172
- * await fireImpressionBeacon(response); // Confirm delivery to ad network
258
+ * // After
259
+ * import { payAndFetch } from '@dexterai/x402/client';
260
+ * const result = await payAndFetch(url, undefined, wallets);
261
+ * if (result.ok) {
262
+ * const res = result.response;
173
263
  * }
174
264
  * ```
175
265
  */
266
+ declare function createX402Client(config: X402ClientConfig): X402Client;
176
267
 
177
- /**
178
- * Extract the full sponsored-access extension data from a payment receipt.
179
- * Returns undefined if no sponsored-access extension is present.
180
- */
181
- declare function getSponsoredAccessInfo(response: Response): SponsoredAccessSettlementInfo | undefined;
182
- /**
183
- * Extract sponsored recommendations from an x402 payment response.
184
- * Returns the recommendations array, or undefined if none present.
185
- *
186
- * @example
187
- * ```typescript
188
- * const recs = getSponsoredRecommendations(response);
189
- * if (recs) {
190
- * for (const rec of recs) {
191
- * console.log(`${rec.sponsor}: ${rec.description} — ${rec.resourceUrl}`);
192
- * }
193
- * }
194
- * ```
195
- */
196
- declare function getSponsoredRecommendations(response: Response): SponsoredRecommendation[] | undefined;
197
- /**
198
- * Fire the impression beacon to confirm recommendation delivery to the ad network.
199
- * This is a fire-and-forget GET request — failures are silently ignored.
200
- *
201
- * Call this after you've read the recommendations to help the ad network
202
- * track delivery rates and verify impressions.
203
- *
204
- * @returns true if the beacon was fired (regardless of response), false if no beacon URL
205
- *
206
- * @example
207
- * ```typescript
208
- * const recs = getSponsoredRecommendations(response);
209
- * if (recs) {
210
- * // Process recommendations...
211
- * await fireImpressionBeacon(response);
212
- * }
213
- * ```
214
- */
215
- declare function fireImpressionBeacon(response: Response): Promise<boolean>;
216
-
217
- export { type PaymentReceipt as P, type X402ClientConfig as X, type X402Client as a, getSponsoredRecommendations as b, createX402Client as c, getSponsoredAccessInfo as d, fireImpressionBeacon as f, getPaymentReceipt as g };
268
+ export { type PaymentReceipt as P, type X402ClientConfig as X, getSponsoredAccessInfo as a, getPaymentReceipt as b, createX402Client as c, type X402Client as d, fireImpressionBeacon as f, getSponsoredRecommendations as g };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexterai/x402",
3
- "version": "3.8.0",
3
+ "version": "3.9.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",