uvd-x402-sdk 2.41.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 (41) hide show
  1. package/README.md +98 -16
  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 +246 -231
  5. package/dist/backend/index.d.ts +246 -231
  6. package/dist/backend/index.js +128 -331
  7. package/dist/backend/index.js.map +1 -1
  8. package/dist/backend/index.mjs +124 -332
  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 +142 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +136 -1
  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 +361 -562
  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
@@ -1014,34 +1015,115 @@ The facilitator's `/supported` endpoint advertises both `'escrow'` and `'commerc
1014
1015
 
1015
1016
  Register and discover paid x402 resources across the network.
1016
1017
 
1018
+ The Bazaar is served by the facilitator itself under `/discovery/*`. No API key, no separate host.
1019
+
1017
1020
  ```typescript
1018
- import { BazaarClient } from 'uvd-x402-sdk/backend';
1021
+ import { BazaarClient, isAlive } from 'uvd-x402-sdk/backend';
1019
1022
 
1020
- const bazaar = new BazaarClient({ apiKey: 'your-api-key' });
1023
+ const bazaar = new BazaarClient();
1021
1024
 
1022
- // Discover resources
1023
- const results = await bazaar.discover({
1024
- category: 'ai',
1025
- network: 'base',
1026
- maxPrice: '0.10',
1025
+ // List resources. Every filter is applied server-side over the whole catalog,
1026
+ // so `pagination.total` is the real number of matches -- filtering one page
1027
+ // locally is not the same thing and will under-report.
1028
+ const page = await bazaar.listResources({
1029
+ network: 'eip155:8453',
1030
+ health: 'alive', // only endpoints a probe actually reached
1031
+ tier: 'vip', // first_party | vip | verified | listed
1032
+ limit: 20,
1027
1033
  });
1028
1034
 
1029
- for (const resource of results.resources) {
1030
- console.log(`${resource.name}: ${resource.url}`);
1035
+ for (const r of page.items) {
1036
+ console.log(r.url, r.health?.status, `${r.health?.latencyMs}ms`, r.curation?.label);
1037
+ }
1038
+ console.log(`${page.items.length} of ${page.pagination.total}`);
1039
+
1040
+ // Free-text search. The parameter is `q`; anything else is rejected with a 400.
1041
+ const hits = await bazaar.listResources({ q: 'logs' });
1042
+
1043
+ // Walk the whole filtered catalog, one page at a time
1044
+ for await (const r of bazaar.iterateResources({ health: 'alive' })) {
1045
+ if (isAlive(r)) console.log(r.url);
1031
1046
  }
1032
1047
 
1033
- // Register a resource
1034
- const resource = await bazaar.register({
1048
+ // Register a resource. Registration is open and rate limited.
1049
+ await bazaar.registerResource({
1035
1050
  url: 'https://api.example.com/v1/generate',
1036
- name: 'Image Generator API',
1037
1051
  description: 'Generate images with AI',
1038
- category: 'ai',
1039
- networks: ['base', 'ethereum'],
1040
- price: '0.05',
1041
- payTo: '0x1234...',
1052
+ accepts: [{
1053
+ scheme: 'exact',
1054
+ network: 'eip155:8453',
1055
+ asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
1056
+ amount: '50000',
1057
+ payTo: '0x1234...',
1058
+ maxTimeoutSeconds: 60,
1059
+ }],
1060
+ metadata: { category: 'ai', tags: ['image'] },
1042
1061
  });
1062
+
1063
+ // Aggregate catalog metrics
1064
+ const stats = await bazaar.getStats();
1065
+ console.log(stats.total, stats.visible, stats.byHealth.alive);
1043
1066
  ```
1044
1067
 
1068
+ Timestamps (`firstSeen`, `lastSeen`, `lastUpdated`, `health.lastChecked`) are Unix epoch **seconds**. Use `epochToDate()` to get a `Date`.
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
+
1045
1127
  ## Facilitator Info
1046
1128
 
1047
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