uvd-x402-sdk 2.42.0 → 2.43.1

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 (41) 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 +10 -1
  5. package/dist/backend/index.d.ts +10 -1
  6. package/dist/backend/index.js +8 -1
  7. package/dist/backend/index.js.map +1 -1
  8. package/dist/backend/index.mjs +8 -1
  9. package/dist/backend/index.mjs.map +1 -1
  10. package/dist/{index-BJrBRC2u.d.mts → index-Bw4S80Ph.d.mts} +2 -2
  11. package/dist/{index-m2PwYmcQ.d.ts → index-Dgus5K-7.d.ts} +2 -2
  12. package/dist/{index-DBCFd6mO.d.mts → index-NDRI_c7e.d.mts} +1 -1
  13. package/dist/{index-DBCFd6mO.d.ts → index-NDRI_c7e.d.ts} +1 -1
  14. package/dist/index.d.mts +148 -3
  15. package/dist/index.d.ts +148 -3
  16. package/dist/index.js +150 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +144 -2
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/providers/algorand/index.d.mts +1 -1
  21. package/dist/providers/algorand/index.d.ts +1 -1
  22. package/dist/providers/evm/index.d.mts +1 -1
  23. package/dist/providers/evm/index.d.ts +1 -1
  24. package/dist/providers/near/index.d.mts +1 -1
  25. package/dist/providers/near/index.d.ts +1 -1
  26. package/dist/providers/solana/index.d.mts +1 -1
  27. package/dist/providers/solana/index.d.ts +1 -1
  28. package/dist/providers/stellar/index.d.mts +1 -1
  29. package/dist/providers/stellar/index.d.ts +1 -1
  30. package/dist/providers/sui/index.d.mts +1 -1
  31. package/dist/providers/sui/index.d.ts +1 -1
  32. package/dist/providers/xrpl/index.d.mts +1 -1
  33. package/dist/providers/xrpl/index.d.ts +1 -1
  34. package/dist/react/index.d.mts +3 -3
  35. package/dist/react/index.d.ts +3 -3
  36. package/dist/utils/index.d.mts +1 -1
  37. package/dist/utils/index.d.ts +1 -1
  38. package/package.json +1 -1
  39. package/src/backend/index.ts +17 -1
  40. package/src/events.ts +301 -0
  41. 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
@@ -93,6 +93,15 @@ interface PaymentAcceptance {
93
93
  network: string;
94
94
  asset: string;
95
95
  amount: string;
96
+ /**
97
+ * Payment scheme. REQUIRED by the facilitator's v2 `PaymentRequirementsV2`.
98
+ *
99
+ * Optional here only so existing callers keep compiling — when it is absent,
100
+ * `buildRequirementFromAcceptance` defaults it to `'exact'`. Do not treat its
101
+ * optionality as "the facilitator does not need it": an accepts[] entry that
102
+ * reaches a v2 client without a scheme is unpayable.
103
+ */
104
+ scheme?: string;
96
105
  payTo?: string;
97
106
  facilitator?: string;
98
107
  resource?: string;
@@ -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
@@ -93,6 +93,15 @@ interface PaymentAcceptance {
93
93
  network: string;
94
94
  asset: string;
95
95
  amount: string;
96
+ /**
97
+ * Payment scheme. REQUIRED by the facilitator's v2 `PaymentRequirementsV2`.
98
+ *
99
+ * Optional here only so existing callers keep compiling — when it is absent,
100
+ * `buildRequirementFromAcceptance` defaults it to `'exact'`. Do not treat its
101
+ * optionality as "the facilitator does not need it": an accepts[] entry that
102
+ * reaches a v2 client without a scheme is unpayable.
103
+ */
104
+ scheme?: string;
96
105
  payTo?: string;
97
106
  facilitator?: string;
98
107
  resource?: string;
@@ -1425,7 +1425,9 @@ function buildRequirementFromAcceptance(accept, resource, version, defaults) {
1425
1425
  throw new Error("Payment accepts entries must include payTo");
1426
1426
  }
1427
1427
  return normalizeRequirementForVersion({
1428
- scheme: "exact",
1428
+ // Honour a caller-supplied scheme; 'exact' is the default, not an override.
1429
+ // Hardcoding it silently discarded 'escrow' / 'commerce' accepts.
1430
+ scheme: accept.scheme ?? "exact",
1429
1431
  network: accept.network,
1430
1432
  maxAmountRequired: accept.amount,
1431
1433
  resource: accept.resource ?? defaults?.resource ?? resource,
@@ -1443,6 +1445,11 @@ function toPaymentAcceptance(requirements, facilitator) {
1443
1445
  network: requirements.network,
1444
1446
  asset: requirements.asset,
1445
1447
  amount: requirements.maxAmountRequired,
1448
+ // scheme is REQUIRED by the facilitator's v2 PaymentRequirementsV2. Dropping it
1449
+ // here produced an accepts[] entry that no v2 client could pay: the spec makes
1450
+ // the client echo the accept verbatim, so the omission travelled downstream and
1451
+ // died in deserialization with an error naming no field.
1452
+ scheme: requirements.scheme,
1446
1453
  payTo: requirements.payTo,
1447
1454
  resource: requirements.resource,
1448
1455
  description: requirements.description,