uvd-x402-sdk 2.42.0 → 2.43.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.
Files changed (36) hide show
  1. package/README.md +58 -0
  2. package/dist/adapters/index.d.mts +1 -1
  3. package/dist/adapters/index.d.ts +1 -1
  4. package/dist/backend/index.d.mts +1 -1
  5. package/dist/backend/index.d.ts +1 -1
  6. package/dist/{index-BJrBRC2u.d.mts → index-Bw4S80Ph.d.mts} +2 -2
  7. package/dist/{index-m2PwYmcQ.d.ts → index-Dgus5K-7.d.ts} +2 -2
  8. package/dist/{index-DBCFd6mO.d.mts → index-NDRI_c7e.d.mts} +1 -1
  9. package/dist/{index-DBCFd6mO.d.ts → index-NDRI_c7e.d.ts} +1 -1
  10. package/dist/index.d.mts +148 -3
  11. package/dist/index.d.ts +148 -3
  12. package/dist/index.js +142 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +136 -1
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/providers/algorand/index.d.mts +1 -1
  17. package/dist/providers/algorand/index.d.ts +1 -1
  18. package/dist/providers/evm/index.d.mts +1 -1
  19. package/dist/providers/evm/index.d.ts +1 -1
  20. package/dist/providers/near/index.d.mts +1 -1
  21. package/dist/providers/near/index.d.ts +1 -1
  22. package/dist/providers/solana/index.d.mts +1 -1
  23. package/dist/providers/solana/index.d.ts +1 -1
  24. package/dist/providers/stellar/index.d.mts +1 -1
  25. package/dist/providers/stellar/index.d.ts +1 -1
  26. package/dist/providers/sui/index.d.mts +1 -1
  27. package/dist/providers/sui/index.d.ts +1 -1
  28. package/dist/providers/xrpl/index.d.mts +1 -1
  29. package/dist/providers/xrpl/index.d.ts +1 -1
  30. package/dist/react/index.d.mts +3 -3
  31. package/dist/react/index.d.ts +3 -3
  32. package/dist/utils/index.d.mts +1 -1
  33. package/dist/utils/index.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/src/events.ts +301 -0
  36. package/src/index.ts +17 -0
package/README.md CHANGED
@@ -19,6 +19,7 @@ Users sign a message or transaction, and the Ultravioleta facilitator handles on
19
19
  - **Commerce Scheme**: `'commerce'` scheme alias for marketplace integrations (identical to `'escrow'` on-chain)
20
20
  - **`/accepts` Negotiation**: Discover facilitator capabilities before constructing payments
21
21
  - **Bazaar Discovery**: Register and discover paid resources across the x402 network
22
+ - **Live Traffic Stream**: Subscribe to `GET /events` (SSE) for settlements as they happen — lossy live hint, not a ledger
22
23
  - **Facilitator Info**: Query version, supported networks, blacklist, and health
23
24
 
24
25
  ## Installation
@@ -1066,6 +1067,63 @@ console.log(stats.total, stats.visible, stats.byHealth.alive);
1066
1067
 
1067
1068
  Timestamps (`firstSeen`, `lastSeen`, `lastUpdated`, `health.lastChecked`) are Unix epoch **seconds**. Use `epochToDate()` to get a `Date`.
1068
1069
 
1070
+ ## Live Traffic Stream (`GET /events`)
1071
+
1072
+ The facilitator emits one Server-Sent Event per operation it handles, so you can
1073
+ render or react to live traffic without polling. Works in Node 18+ and browsers —
1074
+ it uses `fetch` and the response body stream rather than `EventSource`, so custom
1075
+ headers work too.
1076
+
1077
+ ```typescript
1078
+ import { streamTrafficEvents } from 'uvd-x402-sdk';
1079
+
1080
+ for await (const event of streamTrafficEvents()) {
1081
+ console.log(event.kind, event.network, event.ok, event.tx);
1082
+ }
1083
+
1084
+ // Only settlements on the chains you care about. The facilitator has NO
1085
+ // server-side filter by network, so this runs client-side.
1086
+ const controller = new AbortController();
1087
+ const stream = streamTrafficEvents({
1088
+ networks: ['base', 'polygon'],
1089
+ kinds: ['settle'],
1090
+ signal: controller.signal,
1091
+ });
1092
+ for await (const event of stream) console.log(event.tx, new Date(event.ts));
1093
+ ```
1094
+
1095
+ Three properties decide how you should use this:
1096
+
1097
+ **It is lossy by design.** The facilitator will never slow down or fail a payment
1098
+ to keep an observer in sync, so an event you were not connected for is gone.
1099
+ Treat it as a live hint and use the chain as the source of truth — and note that
1100
+ *absence of events is not evidence that nothing happened*. On a quiet rail the
1101
+ only thing on the wire for minutes is a keepalive.
1102
+
1103
+ **Failed operations are not published.** Only operations that resolved emit an
1104
+ event, so `ok: false` means "resolved and came back negative", never "blew up". A
1105
+ stream that looks healthy is not proof that the rail is.
1106
+
1107
+ **Admission is bounded.** `/events` is public and unauthenticated, so it sheds
1108
+ with HTTP 503 + `Retry-After` at subscriber capacity, and returns 404 when the
1109
+ operator disabled it. Both throw `TrafficStreamError`, which carries `status` and
1110
+ `retryAfter`. Iteration does **not** reconnect on its own: reconnect policy
1111
+ belongs to you, because only you know whether a gap matters.
1112
+
1113
+ > **Match the canonical network slug.** `network` is the name `/supported` uses,
1114
+ > which is not always the alias you may *send*. `skale` is accepted inbound, but
1115
+ > events always say `skale-base`. Keying on the alias silently drops every event
1116
+ > for that chain.
1117
+
1118
+ | Field | Notes |
1119
+ |-------|-------|
1120
+ | `ts` | Unix epoch **milliseconds** (not seconds) |
1121
+ | `kind` | `'verify'` or `'settle'` |
1122
+ | `network` | Canonical slug, same as `/supported` |
1123
+ | `ok` | Resolved successfully? |
1124
+ | `payer` / `amount` / `asset` | Omitted in `minimal` detail mode |
1125
+ | `tx` | Present on `settle`, absent on `verify` — nothing settled yet |
1126
+
1069
1127
  ## Facilitator Info
1070
1128
 
1071
1129
  Query the facilitator for version, supported networks, and compliance data.
@@ -1,4 +1,4 @@
1
- import { O as X402Version, k as PaymentResult } from '../index-DBCFd6mO.mjs';
1
+ import { X as X402Version, b as PaymentResult } from '../index-NDRI_c7e.mjs';
2
2
  export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-CYIVd4xO.mjs';
3
3
  import '../wallet-0cX9Pw2F.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { O as X402Version, k as PaymentResult } from '../index-DBCFd6mO.js';
1
+ import { X as X402Version, b as PaymentResult } from '../index-NDRI_c7e.js';
2
2
  export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-DTDixPzO.js';
3
3
  import '../wallet-0cX9Pw2F.js';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.mjs';
2
- import { w as X402Header, O as X402Version } from '../index-DBCFd6mO.mjs';
2
+ import { e as X402Header, X as X402Version } from '../index-NDRI_c7e.mjs';
3
3
 
4
4
  /**
5
5
  * Payment requirements sent to the facilitator
@@ -1,5 +1,5 @@
1
1
  import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.js';
2
- import { w as X402Header, O as X402Version } from '../index-DBCFd6mO.js';
2
+ import { e as X402Header, X as X402Version } from '../index-NDRI_c7e.js';
3
3
 
4
4
  /**
5
5
  * Payment requirements sent to the facilitator
@@ -1,4 +1,4 @@
1
- import { p as X402ClientConfig, h as PaymentInfo, k as PaymentResult, o as WalletState, b as ChainConfig, t as X402Event, v as X402EventHandler, g as NetworkType, n as TokenType, T as TokenConfig } from './index-DBCFd6mO.mjs';
1
+ import { a as X402ClientConfig, P as PaymentInfo, b as PaymentResult, d as WalletState, C as ChainConfig, v as X402Event, x as X402EventHandler, c as NetworkType, T as TokenType, q as TokenConfig } from './index-NDRI_c7e.mjs';
2
2
 
3
3
  /**
4
4
  * uvd-x402-sdk - Main Client
@@ -258,4 +258,4 @@ declare function isTokenSupported(chainName: string, tokenType: TokenType): bool
258
258
  */
259
259
  declare function getChainsByToken(tokenType: TokenType): ChainConfig[];
260
260
 
261
- export { DEFAULT_CHAIN as D, SUPPORTED_CHAINS as S, X402Client as X, DEFAULT_FACILITATOR_URL as a, getChainById as b, getChainByName as c, getChainsByNetworkType as d, getChainsByToken as e, getEVMChainIds as f, getAlgorandChains as g, getEnabledChains as h, getExplorerAddressUrl as i, getExplorerTxUrl as j, getNetworkType as k, getSVMChains as l, getSuiChains as m, getSupportedTokens as n, getTokenConfig as o, getXRPLChains as p, isAlgorandChain as q, isChainSupported as r, isSVMChain as s, isSuiChain as t, isTokenSupported as u, isXRPLChain as v };
261
+ export { DEFAULT_CHAIN as D, SUPPORTED_CHAINS as S, X402Client as X, DEFAULT_FACILITATOR_URL as a, getAlgorandChains as b, getChainById as c, getChainsByNetworkType as d, getChainsByToken as e, getEVMChainIds as f, getChainByName as g, getEnabledChains as h, getExplorerAddressUrl as i, getExplorerTxUrl as j, getNetworkType as k, getSVMChains as l, getSuiChains as m, getSupportedTokens as n, getTokenConfig as o, getXRPLChains as p, isAlgorandChain as q, isChainSupported as r, isSVMChain as s, isSuiChain as t, isTokenSupported as u, isXRPLChain as v };
@@ -1,4 +1,4 @@
1
- import { p as X402ClientConfig, h as PaymentInfo, k as PaymentResult, o as WalletState, b as ChainConfig, t as X402Event, v as X402EventHandler, g as NetworkType, n as TokenType, T as TokenConfig } from './index-DBCFd6mO.js';
1
+ import { a as X402ClientConfig, P as PaymentInfo, b as PaymentResult, d as WalletState, C as ChainConfig, v as X402Event, x as X402EventHandler, c as NetworkType, T as TokenType, q as TokenConfig } from './index-NDRI_c7e.js';
2
2
 
3
3
  /**
4
4
  * uvd-x402-sdk - Main Client
@@ -258,4 +258,4 @@ declare function isTokenSupported(chainName: string, tokenType: TokenType): bool
258
258
  */
259
259
  declare function getChainsByToken(tokenType: TokenType): ChainConfig[];
260
260
 
261
- export { DEFAULT_CHAIN as D, SUPPORTED_CHAINS as S, X402Client as X, DEFAULT_FACILITATOR_URL as a, getChainById as b, getChainByName as c, getChainsByNetworkType as d, getChainsByToken as e, getEVMChainIds as f, getAlgorandChains as g, getEnabledChains as h, getExplorerAddressUrl as i, getExplorerTxUrl as j, getNetworkType as k, getSVMChains as l, getSuiChains as m, getSupportedTokens as n, getTokenConfig as o, getXRPLChains as p, isAlgorandChain as q, isChainSupported as r, isSVMChain as s, isSuiChain as t, isTokenSupported as u, isXRPLChain as v };
261
+ export { DEFAULT_CHAIN as D, SUPPORTED_CHAINS as S, X402Client as X, DEFAULT_FACILITATOR_URL as a, getAlgorandChains as b, getChainById as c, getChainsByNetworkType as d, getChainsByToken as e, getEVMChainIds as f, getChainByName as g, getEnabledChains as h, getExplorerAddressUrl as i, getExplorerTxUrl as j, getNetworkType as k, getSVMChains as l, getSuiChains as m, getSupportedTokens as n, getTokenConfig as o, getXRPLChains as p, isAlgorandChain as q, isChainSupported as r, isSVMChain as s, isSuiChain as t, isTokenSupported as u, isXRPLChain as v };
@@ -648,4 +648,4 @@ declare class X402Error extends Error {
648
648
  constructor(message: string, code: X402ErrorCode, details?: unknown);
649
649
  }
650
650
 
651
- export { type AlgorandPaymentPayload as A, type X402NEARPayload as B, CAIP2_IDENTIFIERS as C, DEFAULT_CONFIG as D, type EIP712Domain as E, type X402PayloadData as F, type X402PaymentOption as G, type X402Scheme as H, type X402SettlementAccountPayload as I, type X402SolanaPayload as J, type X402StellarPayload as K, type X402SuiPayload as L, type MultiPaymentConfig as M, type NEARPaymentPayload as N, type X402Version as O, type PaymentHeaders as P, type X402XRPLPayload as Q, type XRPLPaymentPayload as R, type SolanaPaymentPayload as S, type TokenConfig as T, type USDCConfig as U, type WalletAdapter as W, type X402AlgorandPayload as X, CAIP2_TO_CHAIN as a, type ChainConfig as b, type EIP712Types as c, type EVMPaymentPayload as d, type NativeCurrency as e, type NetworkBalance as f, type NetworkType as g, type PaymentInfo as h, type PaymentPayload as i, type PaymentRequest as j, type PaymentResult as k, type StellarPaymentPayload as l, type SuiPaymentPayload as m, type TokenType as n, type WalletState as o, type X402ClientConfig as p, type X402EVMPayload as q, X402Error as r, type X402ErrorCode as s, type X402Event as t, type X402EventData as u, type X402EventHandler as v, type X402Header as w, type X402HeaderName as x, type X402HeaderV1 as y, type X402HeaderV2 as z };
651
+ export { type AlgorandPaymentPayload as A, type X402HeaderV2 as B, type ChainConfig as C, DEFAULT_CONFIG as D, type EIP712Domain as E, type X402NEARPayload as F, type X402PayloadData as G, type X402PaymentOption as H, type X402Scheme as I, type X402SettlementAccountPayload as J, type X402SolanaPayload as K, type X402StellarPayload as L, type MultiPaymentConfig as M, type NetworkBalance as N, type X402SuiPayload as O, type PaymentInfo as P, type X402XRPLPayload as Q, type XRPLPaymentPayload as R, type SolanaPaymentPayload as S, type TokenType as T, type USDCConfig as U, type WalletAdapter as W, type X402Version as X, type X402ClientConfig as a, type PaymentResult as b, type NetworkType as c, type WalletState as d, type X402Header as e, CAIP2_IDENTIFIERS as f, CAIP2_TO_CHAIN as g, type EIP712Types as h, type EVMPaymentPayload as i, type NEARPaymentPayload as j, type NativeCurrency as k, type PaymentHeaders as l, type PaymentPayload as m, type PaymentRequest as n, type StellarPaymentPayload as o, type SuiPaymentPayload as p, type TokenConfig as q, type X402AlgorandPayload as r, type X402EVMPayload as s, X402Error as t, type X402ErrorCode as u, type X402Event as v, type X402EventData as w, type X402EventHandler as x, type X402HeaderName as y, type X402HeaderV1 as z };
@@ -648,4 +648,4 @@ declare class X402Error extends Error {
648
648
  constructor(message: string, code: X402ErrorCode, details?: unknown);
649
649
  }
650
650
 
651
- export { type AlgorandPaymentPayload as A, type X402NEARPayload as B, CAIP2_IDENTIFIERS as C, DEFAULT_CONFIG as D, type EIP712Domain as E, type X402PayloadData as F, type X402PaymentOption as G, type X402Scheme as H, type X402SettlementAccountPayload as I, type X402SolanaPayload as J, type X402StellarPayload as K, type X402SuiPayload as L, type MultiPaymentConfig as M, type NEARPaymentPayload as N, type X402Version as O, type PaymentHeaders as P, type X402XRPLPayload as Q, type XRPLPaymentPayload as R, type SolanaPaymentPayload as S, type TokenConfig as T, type USDCConfig as U, type WalletAdapter as W, type X402AlgorandPayload as X, CAIP2_TO_CHAIN as a, type ChainConfig as b, type EIP712Types as c, type EVMPaymentPayload as d, type NativeCurrency as e, type NetworkBalance as f, type NetworkType as g, type PaymentInfo as h, type PaymentPayload as i, type PaymentRequest as j, type PaymentResult as k, type StellarPaymentPayload as l, type SuiPaymentPayload as m, type TokenType as n, type WalletState as o, type X402ClientConfig as p, type X402EVMPayload as q, X402Error as r, type X402ErrorCode as s, type X402Event as t, type X402EventData as u, type X402EventHandler as v, type X402Header as w, type X402HeaderName as x, type X402HeaderV1 as y, type X402HeaderV2 as z };
651
+ export { type AlgorandPaymentPayload as A, type X402HeaderV2 as B, type ChainConfig as C, DEFAULT_CONFIG as D, type EIP712Domain as E, type X402NEARPayload as F, type X402PayloadData as G, type X402PaymentOption as H, type X402Scheme as I, type X402SettlementAccountPayload as J, type X402SolanaPayload as K, type X402StellarPayload as L, type MultiPaymentConfig as M, type NetworkBalance as N, type X402SuiPayload as O, type PaymentInfo as P, type X402XRPLPayload as Q, type XRPLPaymentPayload as R, type SolanaPaymentPayload as S, type TokenType as T, type USDCConfig as U, type WalletAdapter as W, type X402Version as X, type X402ClientConfig as a, type PaymentResult as b, type NetworkType as c, type WalletState as d, type X402Header as e, CAIP2_IDENTIFIERS as f, CAIP2_TO_CHAIN as g, type EIP712Types as h, type EVMPaymentPayload as i, type NEARPaymentPayload as j, type NativeCurrency as k, type PaymentHeaders as l, type PaymentPayload as m, type PaymentRequest as n, type StellarPaymentPayload as o, type SuiPaymentPayload as p, type TokenConfig as q, type X402AlgorandPayload as r, type X402EVMPayload as s, X402Error as t, type X402ErrorCode as u, type X402Event as v, type X402EventData as w, type X402EventHandler as x, type X402HeaderName as y, type X402HeaderV1 as z };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- export { D as DEFAULT_CHAIN, a as DEFAULT_FACILITATOR_URL, S as SUPPORTED_CHAINS, X as X402Client, g as getAlgorandChains, b as getChainById, c as getChainByName, d as getChainsByNetworkType, e as getChainsByToken, f as getEVMChainIds, h as getEnabledChains, i as getExplorerAddressUrl, j as getExplorerTxUrl, k as getNetworkType, l as getSVMChains, m as getSuiChains, n as getSupportedTokens, o as getTokenConfig, p as getXRPLChains, q as isAlgorandChain, r as isChainSupported, s as isSVMChain, t as isSuiChain, u as isTokenSupported, v as isXRPLChain } from './index-BJrBRC2u.mjs';
1
+ export { D as DEFAULT_CHAIN, a as DEFAULT_FACILITATOR_URL, S as SUPPORTED_CHAINS, X as X402Client, b as getAlgorandChains, c as getChainById, g as getChainByName, d as getChainsByNetworkType, e as getChainsByToken, f as getEVMChainIds, h as getEnabledChains, i as getExplorerAddressUrl, j as getExplorerTxUrl, k as getNetworkType, l as getSVMChains, m as getSuiChains, n as getSupportedTokens, o as getTokenConfig, p as getXRPLChains, q as isAlgorandChain, r as isChainSupported, s as isSVMChain, t as isSuiChain, u as isTokenSupported, v as isXRPLChain } from './index-Bw4S80Ph.mjs';
2
2
  export { DEFAULT_PAYMENT_HEADER, PAYMENT_HEADER_NAMES, caip2ToChain, chainToCAIP2, convertX402Header, createPaymentHeaders, createX402Header, createX402V1Header, createX402V2Header, decodeX402Header, detectX402Version, encodeX402Header, generatePaymentOptions, getPaymentHeader, isCAIP2Format, parseNetworkIdentifier, validateAmount, validateRecipient } from './utils/index.mjs';
3
- export { A as AlgorandPaymentPayload, C as CAIP2_IDENTIFIERS, a as CAIP2_TO_CHAIN, b as ChainConfig, D as DEFAULT_CONFIG, E as EIP712Domain, c as EIP712Types, d as EVMPaymentPayload, M as MultiPaymentConfig, N as NEARPaymentPayload, e as NativeCurrency, f as NetworkBalance, g as NetworkType, P as PaymentHeaders, h as PaymentInfo, i as PaymentPayload, j as PaymentRequest, k as PaymentResult, S as SolanaPaymentPayload, l as StellarPaymentPayload, m as SuiPaymentPayload, T as TokenConfig, n as TokenType, U as USDCConfig, W as WalletAdapter, o as WalletState, X as X402AlgorandPayload, p as X402ClientConfig, q as X402EVMPayload, r as X402Error, s as X402ErrorCode, t as X402Event, u as X402EventData, v as X402EventHandler, w as X402Header, x as X402HeaderName, y as X402HeaderV1, z as X402HeaderV2, B as X402NEARPayload, F as X402PayloadData, G as X402PaymentOption, H as X402Scheme, I as X402SettlementAccountPayload, J as X402SolanaPayload, K as X402StellarPayload, L as X402SuiPayload, O as X402Version, Q as X402XRPLPayload, R as XRPLPaymentPayload } from './index-DBCFd6mO.mjs';
3
+ export { A as AlgorandPaymentPayload, f as CAIP2_IDENTIFIERS, g as CAIP2_TO_CHAIN, C as ChainConfig, D as DEFAULT_CONFIG, E as EIP712Domain, h as EIP712Types, i as EVMPaymentPayload, M as MultiPaymentConfig, j as NEARPaymentPayload, k as NativeCurrency, N as NetworkBalance, c as NetworkType, l as PaymentHeaders, P as PaymentInfo, m as PaymentPayload, n as PaymentRequest, b as PaymentResult, S as SolanaPaymentPayload, o as StellarPaymentPayload, p as SuiPaymentPayload, q as TokenConfig, T as TokenType, U as USDCConfig, W as WalletAdapter, d as WalletState, r as X402AlgorandPayload, a as X402ClientConfig, s as X402EVMPayload, t as X402Error, u as X402ErrorCode, v as X402Event, w as X402EventData, x as X402EventHandler, e as X402Header, y as X402HeaderName, z as X402HeaderV1, B as X402HeaderV2, F as X402NEARPayload, G as X402PayloadData, H as X402PaymentOption, I as X402Scheme, J as X402SettlementAccountPayload, K as X402SolanaPayload, L as X402StellarPayload, O as X402SuiPayload, X as X402Version, Q as X402XRPLPayload, R as XRPLPaymentPayload } from './index-NDRI_c7e.mjs';
4
4
  export { E as EIP3009Authorization, a as EIP3009Params, S as SigningWalletAdapter } from './wallet-0cX9Pw2F.mjs';
5
5
  export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-CYIVd4xO.mjs';
6
6
  export { FacilitatorClient, FacilitatorClientOptions, HonoMiddlewareOptions, PaymentAcceptance, PaymentMiddlewareOptions, VerifiedPaymentState, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, getCorsHeaders } from './backend/index.mjs';
@@ -99,4 +99,149 @@ declare function getFacilitatorAddress(chainName: string, networkType?: string):
99
99
  */
100
100
  type FacilitatorAddresses = typeof FACILITATOR_ADDRESSES;
101
101
 
102
- export { FACILITATOR_ADDRESSES, type FacilitatorAddresses, getFacilitatorAddress };
102
+ /**
103
+ * Live traffic stream client (`GET /events`, Server-Sent Events).
104
+ *
105
+ * The facilitator emits one event per operation it handles, so you can render or
106
+ * react to live traffic without polling and without scraping logs.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * import { streamTrafficEvents } from '@ultravioletadao/x402-sdk';
111
+ *
112
+ * for await (const event of streamTrafficEvents()) {
113
+ * console.log(event.kind, event.network, event.ok, event.tx);
114
+ * }
115
+ * ```
116
+ *
117
+ * @example Only settlements on the chains you care about. The facilitator has NO
118
+ * server-side filter by network, so this is applied client-side.
119
+ * ```ts
120
+ * const stream = streamTrafficEvents({
121
+ * networks: ['base', 'polygon'],
122
+ * kinds: ['settle'],
123
+ * });
124
+ * for await (const event of stream) console.log(event.tx);
125
+ * ```
126
+ *
127
+ * Three properties of this stream decide how you should use it:
128
+ *
129
+ * **It is lossy by design.** The facilitator will never slow down or fail a
130
+ * payment to keep an observer in sync, so an event you were not connected for is
131
+ * simply gone. Treat it as a live hint and use the chain as the source of truth.
132
+ * Absence of events is NOT evidence that nothing happened.
133
+ *
134
+ * **Failed operations are not published.** Only operations that resolved emit an
135
+ * event, so `ok: false` means "resolved and came back negative", never "blew up".
136
+ * A stream that looks healthy is not proof that the rail is.
137
+ *
138
+ * **Admission is bounded.** The endpoint is public and unauthenticated, so it
139
+ * sheds with HTTP 503 + `Retry-After` once too many subscribers are connected,
140
+ * and returns 404 when the operator disabled it.
141
+ */
142
+ /** Operations the facilitator publishes. */
143
+ type TrafficEventKind = 'verify' | 'settle';
144
+ /** Operations the facilitator publishes, as a value. */
145
+ declare const EVENT_KINDS: readonly TrafficEventKind[];
146
+ /**
147
+ * The stream sends a `:keepalive` comment on this cadence, so any read timeout
148
+ * you add must comfortably exceed it or you will kill healthy connections on an
149
+ * idle rail.
150
+ */
151
+ declare const KEEPALIVE_INTERVAL_MS = 15000;
152
+ /**
153
+ * One facilitator operation, as seen by an observer.
154
+ *
155
+ * Optional fields are *omitted* by the facilitator rather than sent as null, and
156
+ * they are all absent when the operator runs the stream in `minimal` detail
157
+ * mode. Never assume `payer` or `amount` is present.
158
+ */
159
+ interface TrafficEvent {
160
+ /** Unix epoch **milliseconds**, UTC. Note: milliseconds, not seconds. */
161
+ ts: number;
162
+ kind: TrafficEventKind | string;
163
+ /**
164
+ * The facilitator's canonical network slug, the same one `/supported` uses.
165
+ *
166
+ * Beware: this is the *canonical* name, which is not always the alias you are
167
+ * allowed to send. `skale` is accepted on the way in, but this field always
168
+ * says `skale-base`. Match on the canonical form or you will silently drop
169
+ * every event for that chain.
170
+ */
171
+ network: string;
172
+ /** Resolved successfully? False means resolved-negative, not errored. */
173
+ ok: boolean;
174
+ payer?: string;
175
+ /** Present on `settle`, absent on `verify` — nothing settled yet. */
176
+ tx?: string;
177
+ amount?: string;
178
+ asset?: string;
179
+ }
180
+ /** Raised when the stream cannot be opened. Carries the HTTP status. */
181
+ declare class TrafficStreamError extends Error {
182
+ readonly status: number;
183
+ /** Seconds to wait before retrying, when the server said so (503). */
184
+ readonly retryAfter?: number;
185
+ constructor(message: string, status: number, retryAfter?: number);
186
+ }
187
+ interface StreamTrafficEventsOptions {
188
+ /** Facilitator to subscribe to. Defaults to the Ultravioleta DAO facilitator. */
189
+ facilitatorUrl?: string;
190
+ /**
191
+ * Only yield events for these networks. Applied client-side — the facilitator
192
+ * has no per-network filter, so every event still crosses the wire. Match the
193
+ * canonical slug (`skale-base`, not `skale`).
194
+ */
195
+ networks?: string[];
196
+ /** Only yield these operations. */
197
+ kinds?: TrafficEventKind[];
198
+ /** Abort the stream. Without one, iteration ends only when the server closes. */
199
+ signal?: AbortSignal;
200
+ /** Extra headers, for a deployment that gates the stream behind authorization. */
201
+ headers?: Record<string, string>;
202
+ }
203
+ /** One decoded SSE frame: the event name and its raw data payload. */
204
+ interface SSEFrame {
205
+ event: string;
206
+ data: string;
207
+ }
208
+ /**
209
+ * Incremental Server-Sent Events parser.
210
+ *
211
+ * Kept separate from the network layer so the framing can be tested without a
212
+ * socket — which matters, because the case that breaks in production is an idle
213
+ * rail sending nothing but keepalive comments for minutes.
214
+ */
215
+ declare class SSEParser {
216
+ private buffer;
217
+ private eventName;
218
+ private dataLines;
219
+ /** Feed a chunk of the response body; get back whatever frames completed. */
220
+ push(chunk: string): SSEFrame[];
221
+ }
222
+ /**
223
+ * Decode one SSE frame into a {@link TrafficEvent}.
224
+ *
225
+ * Returns null for anything malformed: a single bad message must never tear down
226
+ * a long-lived stream — the connection is worth more than the message.
227
+ */
228
+ declare function parseTrafficEvent(frame: SSEFrame): TrafficEvent | null;
229
+ /** Does this event pass the caller's client-side filters? */
230
+ declare function matchesFilters(event: TrafficEvent, options: Pick<StreamTrafficEventsOptions, 'networks' | 'kinds'>): boolean;
231
+ /**
232
+ * Subscribe to the facilitator's live traffic stream.
233
+ *
234
+ * Works in Node 18+ and in browsers: it uses `fetch` and the response body
235
+ * stream rather than `EventSource`, so it also works where custom headers are
236
+ * needed (`EventSource` cannot send them).
237
+ *
238
+ * Iteration ends when the server closes the connection or the `signal` aborts.
239
+ * It does NOT reconnect on its own — reconnect policy belongs to the caller, who
240
+ * is the only one who knows whether a gap matters.
241
+ *
242
+ * @throws {TrafficStreamError} 404 when the operator disabled the stream, 503
243
+ * with `retryAfter` when it is at subscriber capacity.
244
+ */
245
+ declare function streamTrafficEvents(options?: StreamTrafficEventsOptions): AsyncGenerator<TrafficEvent, void, undefined>;
246
+
247
+ export { EVENT_KINDS, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, type SSEFrame, SSEParser, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, getFacilitatorAddress, matchesFilters, parseTrafficEvent, streamTrafficEvents };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { D as DEFAULT_CHAIN, a as DEFAULT_FACILITATOR_URL, S as SUPPORTED_CHAINS, X as X402Client, g as getAlgorandChains, b as getChainById, c as getChainByName, d as getChainsByNetworkType, e as getChainsByToken, f as getEVMChainIds, h as getEnabledChains, i as getExplorerAddressUrl, j as getExplorerTxUrl, k as getNetworkType, l as getSVMChains, m as getSuiChains, n as getSupportedTokens, o as getTokenConfig, p as getXRPLChains, q as isAlgorandChain, r as isChainSupported, s as isSVMChain, t as isSuiChain, u as isTokenSupported, v as isXRPLChain } from './index-m2PwYmcQ.js';
1
+ export { D as DEFAULT_CHAIN, a as DEFAULT_FACILITATOR_URL, S as SUPPORTED_CHAINS, X as X402Client, b as getAlgorandChains, c as getChainById, g as getChainByName, d as getChainsByNetworkType, e as getChainsByToken, f as getEVMChainIds, h as getEnabledChains, i as getExplorerAddressUrl, j as getExplorerTxUrl, k as getNetworkType, l as getSVMChains, m as getSuiChains, n as getSupportedTokens, o as getTokenConfig, p as getXRPLChains, q as isAlgorandChain, r as isChainSupported, s as isSVMChain, t as isSuiChain, u as isTokenSupported, v as isXRPLChain } from './index-Dgus5K-7.js';
2
2
  export { DEFAULT_PAYMENT_HEADER, PAYMENT_HEADER_NAMES, caip2ToChain, chainToCAIP2, convertX402Header, createPaymentHeaders, createX402Header, createX402V1Header, createX402V2Header, decodeX402Header, detectX402Version, encodeX402Header, generatePaymentOptions, getPaymentHeader, isCAIP2Format, parseNetworkIdentifier, validateAmount, validateRecipient } from './utils/index.js';
3
- export { A as AlgorandPaymentPayload, C as CAIP2_IDENTIFIERS, a as CAIP2_TO_CHAIN, b as ChainConfig, D as DEFAULT_CONFIG, E as EIP712Domain, c as EIP712Types, d as EVMPaymentPayload, M as MultiPaymentConfig, N as NEARPaymentPayload, e as NativeCurrency, f as NetworkBalance, g as NetworkType, P as PaymentHeaders, h as PaymentInfo, i as PaymentPayload, j as PaymentRequest, k as PaymentResult, S as SolanaPaymentPayload, l as StellarPaymentPayload, m as SuiPaymentPayload, T as TokenConfig, n as TokenType, U as USDCConfig, W as WalletAdapter, o as WalletState, X as X402AlgorandPayload, p as X402ClientConfig, q as X402EVMPayload, r as X402Error, s as X402ErrorCode, t as X402Event, u as X402EventData, v as X402EventHandler, w as X402Header, x as X402HeaderName, y as X402HeaderV1, z as X402HeaderV2, B as X402NEARPayload, F as X402PayloadData, G as X402PaymentOption, H as X402Scheme, I as X402SettlementAccountPayload, J as X402SolanaPayload, K as X402StellarPayload, L as X402SuiPayload, O as X402Version, Q as X402XRPLPayload, R as XRPLPaymentPayload } from './index-DBCFd6mO.js';
3
+ export { A as AlgorandPaymentPayload, f as CAIP2_IDENTIFIERS, g as CAIP2_TO_CHAIN, C as ChainConfig, D as DEFAULT_CONFIG, E as EIP712Domain, h as EIP712Types, i as EVMPaymentPayload, M as MultiPaymentConfig, j as NEARPaymentPayload, k as NativeCurrency, N as NetworkBalance, c as NetworkType, l as PaymentHeaders, P as PaymentInfo, m as PaymentPayload, n as PaymentRequest, b as PaymentResult, S as SolanaPaymentPayload, o as StellarPaymentPayload, p as SuiPaymentPayload, q as TokenConfig, T as TokenType, U as USDCConfig, W as WalletAdapter, d as WalletState, r as X402AlgorandPayload, a as X402ClientConfig, s as X402EVMPayload, t as X402Error, u as X402ErrorCode, v as X402Event, w as X402EventData, x as X402EventHandler, e as X402Header, y as X402HeaderName, z as X402HeaderV1, B as X402HeaderV2, F as X402NEARPayload, G as X402PayloadData, H as X402PaymentOption, I as X402Scheme, J as X402SettlementAccountPayload, K as X402SolanaPayload, L as X402StellarPayload, O as X402SuiPayload, X as X402Version, Q as X402XRPLPayload, R as XRPLPaymentPayload } from './index-NDRI_c7e.js';
4
4
  export { E as EIP3009Authorization, a as EIP3009Params, S as SigningWalletAdapter } from './wallet-0cX9Pw2F.js';
5
5
  export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from './ows-DTDixPzO.js';
6
6
  export { FacilitatorClient, FacilitatorClientOptions, HonoMiddlewareOptions, PaymentAcceptance, PaymentMiddlewareOptions, VerifiedPaymentState, X402_CORS_HEADERS, X402_HEADER_NAMES, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, create402Response, createHonoMiddleware, createPaymentMiddleware, extractPaymentFromHeaders, getCorsHeaders } from './backend/index.js';
@@ -99,4 +99,149 @@ declare function getFacilitatorAddress(chainName: string, networkType?: string):
99
99
  */
100
100
  type FacilitatorAddresses = typeof FACILITATOR_ADDRESSES;
101
101
 
102
- export { FACILITATOR_ADDRESSES, type FacilitatorAddresses, getFacilitatorAddress };
102
+ /**
103
+ * Live traffic stream client (`GET /events`, Server-Sent Events).
104
+ *
105
+ * The facilitator emits one event per operation it handles, so you can render or
106
+ * react to live traffic without polling and without scraping logs.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * import { streamTrafficEvents } from '@ultravioletadao/x402-sdk';
111
+ *
112
+ * for await (const event of streamTrafficEvents()) {
113
+ * console.log(event.kind, event.network, event.ok, event.tx);
114
+ * }
115
+ * ```
116
+ *
117
+ * @example Only settlements on the chains you care about. The facilitator has NO
118
+ * server-side filter by network, so this is applied client-side.
119
+ * ```ts
120
+ * const stream = streamTrafficEvents({
121
+ * networks: ['base', 'polygon'],
122
+ * kinds: ['settle'],
123
+ * });
124
+ * for await (const event of stream) console.log(event.tx);
125
+ * ```
126
+ *
127
+ * Three properties of this stream decide how you should use it:
128
+ *
129
+ * **It is lossy by design.** The facilitator will never slow down or fail a
130
+ * payment to keep an observer in sync, so an event you were not connected for is
131
+ * simply gone. Treat it as a live hint and use the chain as the source of truth.
132
+ * Absence of events is NOT evidence that nothing happened.
133
+ *
134
+ * **Failed operations are not published.** Only operations that resolved emit an
135
+ * event, so `ok: false` means "resolved and came back negative", never "blew up".
136
+ * A stream that looks healthy is not proof that the rail is.
137
+ *
138
+ * **Admission is bounded.** The endpoint is public and unauthenticated, so it
139
+ * sheds with HTTP 503 + `Retry-After` once too many subscribers are connected,
140
+ * and returns 404 when the operator disabled it.
141
+ */
142
+ /** Operations the facilitator publishes. */
143
+ type TrafficEventKind = 'verify' | 'settle';
144
+ /** Operations the facilitator publishes, as a value. */
145
+ declare const EVENT_KINDS: readonly TrafficEventKind[];
146
+ /**
147
+ * The stream sends a `:keepalive` comment on this cadence, so any read timeout
148
+ * you add must comfortably exceed it or you will kill healthy connections on an
149
+ * idle rail.
150
+ */
151
+ declare const KEEPALIVE_INTERVAL_MS = 15000;
152
+ /**
153
+ * One facilitator operation, as seen by an observer.
154
+ *
155
+ * Optional fields are *omitted* by the facilitator rather than sent as null, and
156
+ * they are all absent when the operator runs the stream in `minimal` detail
157
+ * mode. Never assume `payer` or `amount` is present.
158
+ */
159
+ interface TrafficEvent {
160
+ /** Unix epoch **milliseconds**, UTC. Note: milliseconds, not seconds. */
161
+ ts: number;
162
+ kind: TrafficEventKind | string;
163
+ /**
164
+ * The facilitator's canonical network slug, the same one `/supported` uses.
165
+ *
166
+ * Beware: this is the *canonical* name, which is not always the alias you are
167
+ * allowed to send. `skale` is accepted on the way in, but this field always
168
+ * says `skale-base`. Match on the canonical form or you will silently drop
169
+ * every event for that chain.
170
+ */
171
+ network: string;
172
+ /** Resolved successfully? False means resolved-negative, not errored. */
173
+ ok: boolean;
174
+ payer?: string;
175
+ /** Present on `settle`, absent on `verify` — nothing settled yet. */
176
+ tx?: string;
177
+ amount?: string;
178
+ asset?: string;
179
+ }
180
+ /** Raised when the stream cannot be opened. Carries the HTTP status. */
181
+ declare class TrafficStreamError extends Error {
182
+ readonly status: number;
183
+ /** Seconds to wait before retrying, when the server said so (503). */
184
+ readonly retryAfter?: number;
185
+ constructor(message: string, status: number, retryAfter?: number);
186
+ }
187
+ interface StreamTrafficEventsOptions {
188
+ /** Facilitator to subscribe to. Defaults to the Ultravioleta DAO facilitator. */
189
+ facilitatorUrl?: string;
190
+ /**
191
+ * Only yield events for these networks. Applied client-side — the facilitator
192
+ * has no per-network filter, so every event still crosses the wire. Match the
193
+ * canonical slug (`skale-base`, not `skale`).
194
+ */
195
+ networks?: string[];
196
+ /** Only yield these operations. */
197
+ kinds?: TrafficEventKind[];
198
+ /** Abort the stream. Without one, iteration ends only when the server closes. */
199
+ signal?: AbortSignal;
200
+ /** Extra headers, for a deployment that gates the stream behind authorization. */
201
+ headers?: Record<string, string>;
202
+ }
203
+ /** One decoded SSE frame: the event name and its raw data payload. */
204
+ interface SSEFrame {
205
+ event: string;
206
+ data: string;
207
+ }
208
+ /**
209
+ * Incremental Server-Sent Events parser.
210
+ *
211
+ * Kept separate from the network layer so the framing can be tested without a
212
+ * socket — which matters, because the case that breaks in production is an idle
213
+ * rail sending nothing but keepalive comments for minutes.
214
+ */
215
+ declare class SSEParser {
216
+ private buffer;
217
+ private eventName;
218
+ private dataLines;
219
+ /** Feed a chunk of the response body; get back whatever frames completed. */
220
+ push(chunk: string): SSEFrame[];
221
+ }
222
+ /**
223
+ * Decode one SSE frame into a {@link TrafficEvent}.
224
+ *
225
+ * Returns null for anything malformed: a single bad message must never tear down
226
+ * a long-lived stream — the connection is worth more than the message.
227
+ */
228
+ declare function parseTrafficEvent(frame: SSEFrame): TrafficEvent | null;
229
+ /** Does this event pass the caller's client-side filters? */
230
+ declare function matchesFilters(event: TrafficEvent, options: Pick<StreamTrafficEventsOptions, 'networks' | 'kinds'>): boolean;
231
+ /**
232
+ * Subscribe to the facilitator's live traffic stream.
233
+ *
234
+ * Works in Node 18+ and in browsers: it uses `fetch` and the response body
235
+ * stream rather than `EventSource`, so it also works where custom headers are
236
+ * needed (`EventSource` cannot send them).
237
+ *
238
+ * Iteration ends when the server closes the connection or the `signal` aborts.
239
+ * It does NOT reconnect on its own — reconnect policy belongs to the caller, who
240
+ * is the only one who knows whether a gap matters.
241
+ *
242
+ * @throws {TrafficStreamError} 404 when the operator disabled the stream, 503
243
+ * with `retryAfter` when it is at subscriber capacity.
244
+ */
245
+ declare function streamTrafficEvents(options?: StreamTrafficEventsOptions): AsyncGenerator<TrafficEvent, void, undefined>;
246
+
247
+ export { EVENT_KINDS, FACILITATOR_ADDRESSES, type FacilitatorAddresses, KEEPALIVE_INTERVAL_MS, type SSEFrame, SSEParser, type StreamTrafficEventsOptions, type TrafficEvent, type TrafficEventKind, TrafficStreamError, getFacilitatorAddress, matchesFilters, parseTrafficEvent, streamTrafficEvents };