@routedock/routedock 0.3.1 → 0.4.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 (58) hide show
  1. package/README.md +113 -12
  2. package/dist/{MppSessionHandler-1EL8QBAn.d.cts → MppSessionHandler-3QfCHI5x.d.ts} +40 -2
  3. package/dist/{MppSessionHandler-Bq4S-JTE.d.ts → MppSessionHandler-xu4Kxu6N.d.cts} +40 -2
  4. package/dist/{ProviderRegistry-w4_hkI_1.d.ts → ProviderRegistry-D9KqyuH-.d.cts} +16 -36
  5. package/dist/{ProviderRegistry-CyZ5eryO.d.cts → ProviderRegistry-DVi2uzgk.d.ts} +16 -36
  6. package/dist/{RouteDockClient-CjM2VyOd.d.ts → RouteDockClient-6rmgkbYb.d.cts} +124 -144
  7. package/dist/{RouteDockClient-CXvWXix5.d.cts → RouteDockClient-CnAkxwrW.d.ts} +124 -144
  8. package/dist/{SessionReconciler-Bw-PoBVl.d.ts → SessionReconciler-Cce9MXO1.d.ts} +10 -3
  9. package/dist/{SessionReconciler-Cz2nuOlJ.d.cts → SessionReconciler-Dpe9qXdD.d.cts} +10 -3
  10. package/dist/{SessionStore-BaYiegP0.d.ts → SessionStore-DkLBxFQu.d.cts} +28 -3
  11. package/dist/{SessionStore-B4-Hi4H8.d.cts → SessionStore-_ZkoBzFY.d.ts} +28 -3
  12. package/dist/SpendStore-BUclV02i.d.ts +73 -0
  13. package/dist/SpendStore-s_dfcemj.d.cts +73 -0
  14. package/dist/client.cjs +767 -482
  15. package/dist/client.d.cts +80 -10
  16. package/dist/client.d.ts +80 -10
  17. package/dist/client.js +733 -463
  18. package/dist/index.cjs +1295 -585
  19. package/dist/index.d.cts +13 -10
  20. package/dist/index.d.ts +13 -10
  21. package/dist/index.js +1247 -554
  22. package/dist/logger-DVa7VT4c.d.cts +41 -0
  23. package/dist/logger-DVa7VT4c.d.ts +41 -0
  24. package/dist/network.cjs +57 -0
  25. package/dist/network.d.cts +72 -0
  26. package/dist/network.d.ts +72 -0
  27. package/dist/network.js +49 -0
  28. package/dist/node.cjs +166 -0
  29. package/dist/node.d.cts +77 -0
  30. package/dist/node.d.ts +77 -0
  31. package/dist/node.js +159 -0
  32. package/dist/provider/fastify.cjs +847 -62
  33. package/dist/provider/fastify.d.cts +10 -3
  34. package/dist/provider/fastify.d.ts +10 -3
  35. package/dist/provider/fastify.js +848 -63
  36. package/dist/provider/hono.cjs +936 -60
  37. package/dist/provider/hono.d.cts +23 -8
  38. package/dist/provider/hono.d.ts +23 -8
  39. package/dist/provider/hono.js +937 -61
  40. package/dist/provider.cjs +894 -70
  41. package/dist/provider.d.cts +9 -8
  42. package/dist/provider.d.ts +9 -8
  43. package/dist/provider.js +895 -72
  44. package/dist/react.cjs +736 -431
  45. package/dist/react.d.cts +7 -5
  46. package/dist/react.d.ts +7 -5
  47. package/dist/react.js +725 -420
  48. package/dist/{routedockMiddleware-57gUaEMf.d.ts → routedockMiddleware-Cq9HOJEa.d.ts} +9 -2
  49. package/dist/{routedockMiddleware-DlyLrxp7.d.cts → routedockMiddleware-CxsWkSKa.d.cts} +9 -2
  50. package/dist/schema.cjs +7 -0
  51. package/dist/schema.js +7 -0
  52. package/dist/{sign-AKH67sft.d.cts → sign-Bq08SeFq.d.ts} +2 -2
  53. package/dist/{sign-BEq-OsSq.d.ts → sign-DqGE0Plv.d.cts} +2 -2
  54. package/dist/testing.d.cts +4 -3
  55. package/dist/testing.d.ts +4 -3
  56. package/dist/{logger-D8_Q2ytp.d.cts → types-DXaS5Wip.d.cts} +85 -47
  57. package/dist/{logger-D8_Q2ytp.d.ts → types-DXaS5Wip.d.ts} +85 -47
  58. package/package.json +50 -4
@@ -1,6 +1,7 @@
1
1
  import { RequestHandler } from 'express';
2
- import { P as PaymentMode, h as RouteDockManifest, g as RouteDockLogger } from './logger-D8_Q2ytp.js';
3
- import { O as OrphanedSessionInfo, S as SeenTxStore } from './MppSessionHandler-Bq4S-JTE.js';
2
+ import { P as PaymentMode, R as RouteDockManifest } from './types-DXaS5Wip.js';
3
+ import { O as OrphanedSessionInfo, S as SeenTxStore, V as VaultSettlementConfig } from './MppSessionHandler-3QfCHI5x.js';
4
+ import { b as RouteDockLogger } from './logger-DVa7VT4c.js';
4
5
 
5
6
  interface RouteDockMiddlewareOptions {
6
7
  modes: PaymentMode[];
@@ -58,6 +59,12 @@ interface RouteDockMiddlewareOptions {
58
59
  * callback failures, orphaned sessions). Defaults to a console-backed logger.
59
60
  */
60
61
  logger?: RouteDockLogger;
62
+ /**
63
+ * Record `session_settled` on the agent vault after each clean mpp-session
64
+ * close. Falls back to the deprecated `AGENT_VAULT_CONTRACT`/
65
+ * `AGENT_VAULT_CONTRACT_ID` env vars when unset.
66
+ */
67
+ vaultSettlement?: VaultSettlementConfig;
61
68
  }
62
69
  declare function routedock(opts: RouteDockMiddlewareOptions): RequestHandler;
63
70
 
@@ -1,6 +1,7 @@
1
1
  import { RequestHandler } from 'express';
2
- import { P as PaymentMode, h as RouteDockManifest, g as RouteDockLogger } from './logger-D8_Q2ytp.cjs';
3
- import { O as OrphanedSessionInfo, S as SeenTxStore } from './MppSessionHandler-1EL8QBAn.cjs';
2
+ import { P as PaymentMode, R as RouteDockManifest } from './types-DXaS5Wip.cjs';
3
+ import { O as OrphanedSessionInfo, S as SeenTxStore, V as VaultSettlementConfig } from './MppSessionHandler-xu4Kxu6N.cjs';
4
+ import { b as RouteDockLogger } from './logger-DVa7VT4c.cjs';
4
5
 
5
6
  interface RouteDockMiddlewareOptions {
6
7
  modes: PaymentMode[];
@@ -58,6 +59,12 @@ interface RouteDockMiddlewareOptions {
58
59
  * callback failures, orphaned sessions). Defaults to a console-backed logger.
59
60
  */
60
61
  logger?: RouteDockLogger;
62
+ /**
63
+ * Record `session_settled` on the agent vault after each clean mpp-session
64
+ * close. Falls back to the deprecated `AGENT_VAULT_CONTRACT`/
65
+ * `AGENT_VAULT_CONTRACT_ID` env vars when unset.
66
+ */
67
+ vaultSettlement?: VaultSettlementConfig;
61
68
  }
62
69
  declare function routedock(opts: RouteDockMiddlewareOptions): RequestHandler;
63
70
 
package/dist/schema.cjs CHANGED
@@ -79,6 +79,7 @@ var routedock_schema_default = {
79
79
  },
80
80
  asset_contract: {
81
81
  type: "string",
82
+ pattern: "^C[A-Z2-7]{55}$",
82
83
  description: "Stellar Asset Contract (SAC) address for the payment asset"
83
84
  },
84
85
  assets: {
@@ -91,6 +92,7 @@ var routedock_schema_default = {
91
92
  },
92
93
  payee: {
93
94
  type: "string",
95
+ pattern: "^G[A-Z2-7]{55}$",
94
96
  description: "Stellar address (G...) that receives payments"
95
97
  },
96
98
  pricing: {
@@ -261,6 +263,7 @@ var routedock_schema_default = {
261
263
  properties: {
262
264
  amount: {
263
265
  type: "string",
266
+ pattern: "^[0-9]+(\\.[0-9]{1,7})?$",
264
267
  description: "Cost per request in the payment asset (decimal string, e.g. '0.001')"
265
268
  },
266
269
  per: {
@@ -274,6 +277,7 @@ var routedock_schema_default = {
274
277
  },
275
278
  payee: {
276
279
  type: "string",
280
+ pattern: "^G[A-Z2-7]{55}$",
277
281
  description: "Optional per-mode payee override (Stellar G... address). Directs settlements for this mode to a separate account for treasury separation. Falls back to the top-level 'payee' when omitted."
278
282
  }
279
283
  }
@@ -286,6 +290,7 @@ var routedock_schema_default = {
286
290
  properties: {
287
291
  rate: {
288
292
  type: "string",
293
+ pattern: "^[0-9]+(\\.[0-9]{1,7})?$",
289
294
  description: "Cost per voucher in the payment asset (decimal string, e.g. '0.0001')"
290
295
  },
291
296
  per: {
@@ -295,10 +300,12 @@ var routedock_schema_default = {
295
300
  },
296
301
  channel_factory: {
297
302
  type: "string",
303
+ pattern: "^C[A-Z2-7]{55}$",
298
304
  description: "Stable Soroban factory address (C...) used to deploy a per-session channel"
299
305
  },
300
306
  min_deposit: {
301
307
  type: "string",
308
+ pattern: "^[0-9]+(\\.[0-9]{1,7})?$",
302
309
  description: "Minimum initial deposit to open a channel (decimal string)"
303
310
  },
304
311
  refund_waiting_period_ledgers: {
package/dist/schema.js CHANGED
@@ -75,6 +75,7 @@ var routedock_schema_default = {
75
75
  },
76
76
  asset_contract: {
77
77
  type: "string",
78
+ pattern: "^C[A-Z2-7]{55}$",
78
79
  description: "Stellar Asset Contract (SAC) address for the payment asset"
79
80
  },
80
81
  assets: {
@@ -87,6 +88,7 @@ var routedock_schema_default = {
87
88
  },
88
89
  payee: {
89
90
  type: "string",
91
+ pattern: "^G[A-Z2-7]{55}$",
90
92
  description: "Stellar address (G...) that receives payments"
91
93
  },
92
94
  pricing: {
@@ -257,6 +259,7 @@ var routedock_schema_default = {
257
259
  properties: {
258
260
  amount: {
259
261
  type: "string",
262
+ pattern: "^[0-9]+(\\.[0-9]{1,7})?$",
260
263
  description: "Cost per request in the payment asset (decimal string, e.g. '0.001')"
261
264
  },
262
265
  per: {
@@ -270,6 +273,7 @@ var routedock_schema_default = {
270
273
  },
271
274
  payee: {
272
275
  type: "string",
276
+ pattern: "^G[A-Z2-7]{55}$",
273
277
  description: "Optional per-mode payee override (Stellar G... address). Directs settlements for this mode to a separate account for treasury separation. Falls back to the top-level 'payee' when omitted."
274
278
  }
275
279
  }
@@ -282,6 +286,7 @@ var routedock_schema_default = {
282
286
  properties: {
283
287
  rate: {
284
288
  type: "string",
289
+ pattern: "^[0-9]+(\\.[0-9]{1,7})?$",
285
290
  description: "Cost per voucher in the payment asset (decimal string, e.g. '0.0001')"
286
291
  },
287
292
  per: {
@@ -291,10 +296,12 @@ var routedock_schema_default = {
291
296
  },
292
297
  channel_factory: {
293
298
  type: "string",
299
+ pattern: "^C[A-Z2-7]{55}$",
294
300
  description: "Stable Soroban factory address (C...) used to deploy a per-session channel"
295
301
  },
296
302
  min_deposit: {
297
303
  type: "string",
304
+ pattern: "^[0-9]+(\\.[0-9]{1,7})?$",
298
305
  description: "Minimum initial deposit to open a channel (decimal string)"
299
306
  },
300
307
  refund_waiting_period_ledgers: {
@@ -1,4 +1,4 @@
1
- import { h as RouteDockManifest } from './logger-D8_Q2ytp.cjs';
1
+ import { R as RouteDockManifest } from './types-DXaS5Wip.js';
2
2
 
3
3
  /**
4
4
  * Ed25519 manifest signing and verification.
@@ -25,7 +25,7 @@ import { h as RouteDockManifest } from './logger-D8_Q2ytp.cjs';
25
25
 
26
26
  declare const MANIFEST_SIGNATURE_VERSION: "2";
27
27
  /** Produce the canonical SHA-256 digest of the manifest (signature field excluded). */
28
- declare function manifestDigest(manifest: RouteDockManifest): Buffer;
28
+ declare function manifestDigest(manifest: RouteDockManifest): Uint8Array;
29
29
  /**
30
30
  * Sign a manifest with the payee's Stellar secret key.
31
31
  * Returns a new manifest object with the `signature` field populated.
@@ -1,4 +1,4 @@
1
- import { h as RouteDockManifest } from './logger-D8_Q2ytp.js';
1
+ import { R as RouteDockManifest } from './types-DXaS5Wip.cjs';
2
2
 
3
3
  /**
4
4
  * Ed25519 manifest signing and verification.
@@ -25,7 +25,7 @@ import { h as RouteDockManifest } from './logger-D8_Q2ytp.js';
25
25
 
26
26
  declare const MANIFEST_SIGNATURE_VERSION: "2";
27
27
  /** Produce the canonical SHA-256 digest of the manifest (signature field excluded). */
28
- declare function manifestDigest(manifest: RouteDockManifest): Buffer;
28
+ declare function manifestDigest(manifest: RouteDockManifest): Uint8Array;
29
29
  /**
30
30
  * Sign a manifest with the payee's Stellar secret key.
31
31
  * Returns a new manifest object with the `signature` field populated.
@@ -1,8 +1,9 @@
1
1
  import { RequestHandler } from 'express';
2
- import { P as PaymentMode } from './logger-D8_Q2ytp.cjs';
3
- import { R as RouteDockMiddlewareOptions } from './routedockMiddleware-DlyLrxp7.cjs';
2
+ import { P as PaymentMode } from './types-DXaS5Wip.cjs';
3
+ import { R as RouteDockMiddlewareOptions } from './routedockMiddleware-CxsWkSKa.cjs';
4
4
  import 'mppx';
5
- import './MppSessionHandler-1EL8QBAn.cjs';
5
+ import './MppSessionHandler-xu4Kxu6N.cjs';
6
+ import './logger-DVa7VT4c.cjs';
6
7
 
7
8
  /**
8
9
  * Loosen a production callback's return type so a plain sync test spy works,
package/dist/testing.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { RequestHandler } from 'express';
2
- import { P as PaymentMode } from './logger-D8_Q2ytp.js';
3
- import { R as RouteDockMiddlewareOptions } from './routedockMiddleware-57gUaEMf.js';
2
+ import { P as PaymentMode } from './types-DXaS5Wip.js';
3
+ import { R as RouteDockMiddlewareOptions } from './routedockMiddleware-Cq9HOJEa.js';
4
4
  import 'mppx';
5
- import './MppSessionHandler-Bq4S-JTE.js';
5
+ import './MppSessionHandler-3QfCHI5x.js';
6
+ import './logger-DVa7VT4c.js';
6
7
 
7
8
  /**
8
9
  * Loosen a production callback's return type so a plain sync test spy works,
@@ -90,7 +90,12 @@ interface EndpointDescriptor {
90
90
  }
91
91
  /** Full RouteDock discovery manifest — served at /.well-known/routedock.json */
92
92
  interface RouteDockManifest {
93
- /** Manifest schema version (major.minor), e.g. "1.0", "1.1", "2.0" */
93
+ /**
94
+ * Manifest schema version (major.minor), e.g. "1.0", "1.1", "2.0".
95
+ * Clients reject a manifest whose major version is higher than the highest
96
+ * one they support (`RouteDockClientVersionError`); any minor of a supported
97
+ * major is accepted, since minor bumps are additive.
98
+ */
94
99
  routedock: string;
95
100
  /**
96
101
  * Minimum SDK client version (major.minor) required to use this manifest.
@@ -224,6 +229,39 @@ interface PreflightResult {
224
229
  /** Optional protocol features supported by this provider */
225
230
  capabilities?: RouteDockManifest['capabilities'];
226
231
  }
232
+ /** Estimated cost of one payment mode, as declared by the provider manifest */
233
+ interface PreflightModeCost {
234
+ /** Payment mode this cost applies to */
235
+ mode: PaymentMode;
236
+ /** Charge per unit in the payment asset (decimal string): per request, or per voucher for session modes */
237
+ amount: string;
238
+ /** Billing unit for `amount` */
239
+ per: 'request' | 'voucher';
240
+ /** Payment asset ticker that would be used for this mode, e.g. "USDC" */
241
+ asset: string;
242
+ /** Minimum channel deposit (decimal string) — session modes only */
243
+ min_deposit?: string;
244
+ }
245
+ /** Deprecation / sunset signals surfaced by client.preflight(url) */
246
+ interface PreflightComplianceFlags {
247
+ /** Modes still listed for backwards compatibility but deprecated */
248
+ deprecated_modes: PaymentMode[];
249
+ /** Manifest-level sunset timestamp (ISO 8601), when the provider declares one */
250
+ sunset_at?: string;
251
+ /** Whether an endpoint matching the URL path is marked deprecated */
252
+ endpoint_deprecated: boolean;
253
+ /** Sunset timestamp (ISO 8601) of the endpoint matching the URL path, when declared */
254
+ endpoint_sunset_at?: string;
255
+ }
256
+ /** Result returned by client.preflight(url) — manifest compatibility check with no money movement */
257
+ interface UrlPreflightResult {
258
+ /** Payment modes supported by this provider */
259
+ modes: PaymentMode[];
260
+ /** Estimated cost for each supported mode */
261
+ costs: PreflightModeCost[];
262
+ /** Deprecation / sunset flags */
263
+ compliance: PreflightComplianceFlags;
264
+ }
227
265
  /** Result returned by client.estimateCost() — the expected charge without submitting any transaction */
228
266
  interface EstimateCostResult {
229
267
  /** Expected charge in the payment asset (decimal string, e.g. "0.001") */
@@ -336,6 +374,28 @@ interface SessionEventPayloadMap {
336
374
  'session:timeout': SessionTimeoutPayload;
337
375
  'session:close-failed': SessionCloseFailedPayload;
338
376
  }
377
+ /**
378
+ * HTTP request fields RouteDock replays to the provider on the caller's behalf.
379
+ *
380
+ * A payment is more than one round-trip — an unpaid probe that elicits the 402
381
+ * challenge, the paid retry, and retries of either — so the body is buffered
382
+ * once (when it is not already replayable) and reused for every attempt. The
383
+ * supported bodies are strings, ArrayBuffers/typed arrays, `Blob`, `FormData`
384
+ * and `URLSearchParams`; a `ReadableStream` is drained up front, which makes it
385
+ * unsuitable for a streaming upload.
386
+ *
387
+ * Payment headers the SDK sets itself (`PAYMENT-SIGNATURE` / `X-PAYMENT` for
388
+ * x402, `Authorization` for MPP) always win over a caller header with the same
389
+ * name.
390
+ */
391
+ interface PaymentRequest {
392
+ /** HTTP method, e.g. `'POST'`. Defaults to `'GET'`. */
393
+ method?: string;
394
+ /** Additional request headers. SDK payment headers take precedence. */
395
+ headers?: HeadersInit;
396
+ /** Request body, replayed on every attempt. */
397
+ body?: BodyInit;
398
+ }
339
399
  /**
340
400
  * Options for SessionHandle.stream().
341
401
  */
@@ -347,6 +407,12 @@ interface StreamOptions {
347
407
  * vouchers; out-of-order sequence numbers will cause payment failures otherwise.
348
408
  */
349
409
  concurrency?: number;
410
+ /**
411
+ * HTTP request replayed for every voucher request. Use this when the streamed
412
+ * endpoint expects a POST body. For `mpp-session-ws` only the HTTP voucher
413
+ * probe uses it — the WebSocket upgrade is always a GET handshake.
414
+ */
415
+ request?: PaymentRequest;
350
416
  }
351
417
  /** Handle for a live MPP session returned by client.openSession() */
352
418
  interface SessionHandle {
@@ -388,10 +454,22 @@ interface SessionHandle {
388
454
  stats(): SessionStats;
389
455
  /** Close the channel on-chain with the highest signed voucher */
390
456
  close(): Promise<SessionCloseResult>;
391
- /** Request refund from the channel contract (initiates dispute) */
392
- requestRefund(): Promise<string>;
393
- /** Server-side counter-mechanism to settle with latest voucher before refund window expires */
394
- settleWithLatestVoucher(): Promise<string>;
457
+ /**
458
+ * Request refund from the channel contract (initiates dispute).
459
+ * Returns the transaction hash only after on-chain confirmation (SUCCESS).
460
+ */
461
+ requestRefund(options?: {
462
+ timeoutMs?: number;
463
+ intervalMs?: number;
464
+ }): Promise<string>;
465
+ /**
466
+ * Server-side counter-mechanism to settle with latest voucher before refund window expires.
467
+ * Returns the transaction hash only after on-chain confirmation (SUCCESS).
468
+ */
469
+ settleWithLatestVoucher(options?: {
470
+ timeoutMs?: number;
471
+ intervalMs?: number;
472
+ }): Promise<string>;
395
473
  /** Get the current dispute status of the channel */
396
474
  getDisputeStatus(): Promise<DisputeStatus>;
397
475
  /**
@@ -415,7 +493,7 @@ interface SessionState {
415
493
  /** Monotonically increasing cumulative amount — stored as string to preserve precision */
416
494
  cumulative_amount: string;
417
495
  last_signature: string;
418
- status: 'open' | 'closing' | 'closed';
496
+ status: 'open' | 'closing' | 'closed' | 'failed';
419
497
  opened_at: string;
420
498
  updated_at: string;
421
499
  settlement_tx_hash: string | null;
@@ -424,44 +502,4 @@ interface SessionState {
424
502
  /** Dispute status of a channel */
425
503
  type DisputeStatus = 'open' | 'in-refund-window' | 'refundable' | 'settled';
426
504
 
427
- /**
428
- * Structured logging hook shared by the client and provider adapters.
429
- *
430
- * The SDK used to write straight to `console` in a couple of dozen error
431
- * paths, which is unusable on structured-logging runtimes (Cloudflare Workers,
432
- * Datadog, …) and untestable without spying on `console`. Every internal
433
- * diagnostic now goes through a {@link RouteDockLogger}, so a consumer can
434
- * silence it, redirect it, or attach correlation fields.
435
- *
436
- * The default implementation is console-backed, so behaviour is unchanged when
437
- * no logger is supplied.
438
- */
439
- /** Severity of a log line. */
440
- type RouteDockLogLevel = 'debug' | 'info' | 'warn' | 'error';
441
- /**
442
- * Structured context attached to a log line, typically `{ error: err }`. Sinks
443
- * receive the values unresolved, so a serialising sink must project non-JSON
444
- * values such as `Error` itself.
445
- */
446
- type RouteDockLogFields = Record<string, unknown>;
447
- /**
448
- * Consumer-supplied log sink.
449
- *
450
- * `fields` carries the structured payload (the error, the channel id, …) that
451
- * a bare string would drop at the boundary.
452
- */
453
- type RouteDockLogger = (level: RouteDockLogLevel, message: string, fields?: RouteDockLogFields) => void;
454
- /**
455
- * Default logger that forwards to the console at the matching level. Field
456
- * values are spread as additional console arguments so `console.error(msg, err)`
457
- * spies (and existing log shippers) keep seeing the raw error object.
458
- */
459
- declare function createConsoleLogger(): RouteDockLogger;
460
- /** Shared console-backed logger — the default when none is configured. */
461
- declare const consoleLogger: RouteDockLogger;
462
- /** Logger that discards every line. */
463
- declare const noopLogger: RouteDockLogger;
464
- /** Resolve an optional logger to a concrete sink, defaulting to `fallback`. */
465
- declare function resolveLogger(logger: RouteDockLogger | undefined, fallback?: RouteDockLogger): RouteDockLogger;
466
-
467
- export { type AssetConfig as A, DEFAULT_MAX_SESSION_DURATION_MS as D, type EndpointDescriptor as E, type PaymentMode as P, type RouteDockLogFields as R, type SLAConfig as S, type VaultMode as V, type DisputeStatus as a, type EstimateCostResult as b, type PaymentResult as c, type PreflightResult as d, type PricingConfig as e, type RouteDockLogLevel as f, type RouteDockLogger as g, type RouteDockManifest as h, type SessionCloseFailedPayload as i, type SessionCloseResult as j, type SessionEvent as k, type SessionEventPayloadMap as l, type SessionHandle as m, type SessionOptions as n, type SessionPricingConfig as o, type SessionState as p, type SessionStats as q, type SessionTimeoutPayload as r, type StreamOptions as s, consoleLogger as t, createConsoleLogger as u, noopLogger as v, resolveLogger as w };
505
+ export { type AssetConfig as A, DEFAULT_MAX_SESSION_DURATION_MS as D, type EndpointDescriptor as E, type PaymentMode as P, type RouteDockManifest as R, type SLAConfig as S, type UrlPreflightResult as U, type VaultMode as V, type DisputeStatus as a, type EstimateCostResult as b, type PaymentRequest as c, type PaymentResult as d, type PreflightComplianceFlags as e, type PreflightModeCost as f, type PreflightResult as g, type PricingConfig as h, type SessionCloseFailedPayload as i, type SessionCloseResult as j, type SessionEvent as k, type SessionEventPayloadMap as l, type SessionHandle as m, type SessionOptions as n, type SessionPricingConfig as o, type SessionState as p, type SessionStats as q, type SessionTimeoutPayload as r, type StreamOptions as s };
@@ -90,7 +90,12 @@ interface EndpointDescriptor {
90
90
  }
91
91
  /** Full RouteDock discovery manifest — served at /.well-known/routedock.json */
92
92
  interface RouteDockManifest {
93
- /** Manifest schema version (major.minor), e.g. "1.0", "1.1", "2.0" */
93
+ /**
94
+ * Manifest schema version (major.minor), e.g. "1.0", "1.1", "2.0".
95
+ * Clients reject a manifest whose major version is higher than the highest
96
+ * one they support (`RouteDockClientVersionError`); any minor of a supported
97
+ * major is accepted, since minor bumps are additive.
98
+ */
94
99
  routedock: string;
95
100
  /**
96
101
  * Minimum SDK client version (major.minor) required to use this manifest.
@@ -224,6 +229,39 @@ interface PreflightResult {
224
229
  /** Optional protocol features supported by this provider */
225
230
  capabilities?: RouteDockManifest['capabilities'];
226
231
  }
232
+ /** Estimated cost of one payment mode, as declared by the provider manifest */
233
+ interface PreflightModeCost {
234
+ /** Payment mode this cost applies to */
235
+ mode: PaymentMode;
236
+ /** Charge per unit in the payment asset (decimal string): per request, or per voucher for session modes */
237
+ amount: string;
238
+ /** Billing unit for `amount` */
239
+ per: 'request' | 'voucher';
240
+ /** Payment asset ticker that would be used for this mode, e.g. "USDC" */
241
+ asset: string;
242
+ /** Minimum channel deposit (decimal string) — session modes only */
243
+ min_deposit?: string;
244
+ }
245
+ /** Deprecation / sunset signals surfaced by client.preflight(url) */
246
+ interface PreflightComplianceFlags {
247
+ /** Modes still listed for backwards compatibility but deprecated */
248
+ deprecated_modes: PaymentMode[];
249
+ /** Manifest-level sunset timestamp (ISO 8601), when the provider declares one */
250
+ sunset_at?: string;
251
+ /** Whether an endpoint matching the URL path is marked deprecated */
252
+ endpoint_deprecated: boolean;
253
+ /** Sunset timestamp (ISO 8601) of the endpoint matching the URL path, when declared */
254
+ endpoint_sunset_at?: string;
255
+ }
256
+ /** Result returned by client.preflight(url) — manifest compatibility check with no money movement */
257
+ interface UrlPreflightResult {
258
+ /** Payment modes supported by this provider */
259
+ modes: PaymentMode[];
260
+ /** Estimated cost for each supported mode */
261
+ costs: PreflightModeCost[];
262
+ /** Deprecation / sunset flags */
263
+ compliance: PreflightComplianceFlags;
264
+ }
227
265
  /** Result returned by client.estimateCost() — the expected charge without submitting any transaction */
228
266
  interface EstimateCostResult {
229
267
  /** Expected charge in the payment asset (decimal string, e.g. "0.001") */
@@ -336,6 +374,28 @@ interface SessionEventPayloadMap {
336
374
  'session:timeout': SessionTimeoutPayload;
337
375
  'session:close-failed': SessionCloseFailedPayload;
338
376
  }
377
+ /**
378
+ * HTTP request fields RouteDock replays to the provider on the caller's behalf.
379
+ *
380
+ * A payment is more than one round-trip — an unpaid probe that elicits the 402
381
+ * challenge, the paid retry, and retries of either — so the body is buffered
382
+ * once (when it is not already replayable) and reused for every attempt. The
383
+ * supported bodies are strings, ArrayBuffers/typed arrays, `Blob`, `FormData`
384
+ * and `URLSearchParams`; a `ReadableStream` is drained up front, which makes it
385
+ * unsuitable for a streaming upload.
386
+ *
387
+ * Payment headers the SDK sets itself (`PAYMENT-SIGNATURE` / `X-PAYMENT` for
388
+ * x402, `Authorization` for MPP) always win over a caller header with the same
389
+ * name.
390
+ */
391
+ interface PaymentRequest {
392
+ /** HTTP method, e.g. `'POST'`. Defaults to `'GET'`. */
393
+ method?: string;
394
+ /** Additional request headers. SDK payment headers take precedence. */
395
+ headers?: HeadersInit;
396
+ /** Request body, replayed on every attempt. */
397
+ body?: BodyInit;
398
+ }
339
399
  /**
340
400
  * Options for SessionHandle.stream().
341
401
  */
@@ -347,6 +407,12 @@ interface StreamOptions {
347
407
  * vouchers; out-of-order sequence numbers will cause payment failures otherwise.
348
408
  */
349
409
  concurrency?: number;
410
+ /**
411
+ * HTTP request replayed for every voucher request. Use this when the streamed
412
+ * endpoint expects a POST body. For `mpp-session-ws` only the HTTP voucher
413
+ * probe uses it — the WebSocket upgrade is always a GET handshake.
414
+ */
415
+ request?: PaymentRequest;
350
416
  }
351
417
  /** Handle for a live MPP session returned by client.openSession() */
352
418
  interface SessionHandle {
@@ -388,10 +454,22 @@ interface SessionHandle {
388
454
  stats(): SessionStats;
389
455
  /** Close the channel on-chain with the highest signed voucher */
390
456
  close(): Promise<SessionCloseResult>;
391
- /** Request refund from the channel contract (initiates dispute) */
392
- requestRefund(): Promise<string>;
393
- /** Server-side counter-mechanism to settle with latest voucher before refund window expires */
394
- settleWithLatestVoucher(): Promise<string>;
457
+ /**
458
+ * Request refund from the channel contract (initiates dispute).
459
+ * Returns the transaction hash only after on-chain confirmation (SUCCESS).
460
+ */
461
+ requestRefund(options?: {
462
+ timeoutMs?: number;
463
+ intervalMs?: number;
464
+ }): Promise<string>;
465
+ /**
466
+ * Server-side counter-mechanism to settle with latest voucher before refund window expires.
467
+ * Returns the transaction hash only after on-chain confirmation (SUCCESS).
468
+ */
469
+ settleWithLatestVoucher(options?: {
470
+ timeoutMs?: number;
471
+ intervalMs?: number;
472
+ }): Promise<string>;
395
473
  /** Get the current dispute status of the channel */
396
474
  getDisputeStatus(): Promise<DisputeStatus>;
397
475
  /**
@@ -415,7 +493,7 @@ interface SessionState {
415
493
  /** Monotonically increasing cumulative amount — stored as string to preserve precision */
416
494
  cumulative_amount: string;
417
495
  last_signature: string;
418
- status: 'open' | 'closing' | 'closed';
496
+ status: 'open' | 'closing' | 'closed' | 'failed';
419
497
  opened_at: string;
420
498
  updated_at: string;
421
499
  settlement_tx_hash: string | null;
@@ -424,44 +502,4 @@ interface SessionState {
424
502
  /** Dispute status of a channel */
425
503
  type DisputeStatus = 'open' | 'in-refund-window' | 'refundable' | 'settled';
426
504
 
427
- /**
428
- * Structured logging hook shared by the client and provider adapters.
429
- *
430
- * The SDK used to write straight to `console` in a couple of dozen error
431
- * paths, which is unusable on structured-logging runtimes (Cloudflare Workers,
432
- * Datadog, …) and untestable without spying on `console`. Every internal
433
- * diagnostic now goes through a {@link RouteDockLogger}, so a consumer can
434
- * silence it, redirect it, or attach correlation fields.
435
- *
436
- * The default implementation is console-backed, so behaviour is unchanged when
437
- * no logger is supplied.
438
- */
439
- /** Severity of a log line. */
440
- type RouteDockLogLevel = 'debug' | 'info' | 'warn' | 'error';
441
- /**
442
- * Structured context attached to a log line, typically `{ error: err }`. Sinks
443
- * receive the values unresolved, so a serialising sink must project non-JSON
444
- * values such as `Error` itself.
445
- */
446
- type RouteDockLogFields = Record<string, unknown>;
447
- /**
448
- * Consumer-supplied log sink.
449
- *
450
- * `fields` carries the structured payload (the error, the channel id, …) that
451
- * a bare string would drop at the boundary.
452
- */
453
- type RouteDockLogger = (level: RouteDockLogLevel, message: string, fields?: RouteDockLogFields) => void;
454
- /**
455
- * Default logger that forwards to the console at the matching level. Field
456
- * values are spread as additional console arguments so `console.error(msg, err)`
457
- * spies (and existing log shippers) keep seeing the raw error object.
458
- */
459
- declare function createConsoleLogger(): RouteDockLogger;
460
- /** Shared console-backed logger — the default when none is configured. */
461
- declare const consoleLogger: RouteDockLogger;
462
- /** Logger that discards every line. */
463
- declare const noopLogger: RouteDockLogger;
464
- /** Resolve an optional logger to a concrete sink, defaulting to `fallback`. */
465
- declare function resolveLogger(logger: RouteDockLogger | undefined, fallback?: RouteDockLogger): RouteDockLogger;
466
-
467
- export { type AssetConfig as A, DEFAULT_MAX_SESSION_DURATION_MS as D, type EndpointDescriptor as E, type PaymentMode as P, type RouteDockLogFields as R, type SLAConfig as S, type VaultMode as V, type DisputeStatus as a, type EstimateCostResult as b, type PaymentResult as c, type PreflightResult as d, type PricingConfig as e, type RouteDockLogLevel as f, type RouteDockLogger as g, type RouteDockManifest as h, type SessionCloseFailedPayload as i, type SessionCloseResult as j, type SessionEvent as k, type SessionEventPayloadMap as l, type SessionHandle as m, type SessionOptions as n, type SessionPricingConfig as o, type SessionState as p, type SessionStats as q, type SessionTimeoutPayload as r, type StreamOptions as s, consoleLogger as t, createConsoleLogger as u, noopLogger as v, resolveLogger as w };
505
+ export { type AssetConfig as A, DEFAULT_MAX_SESSION_DURATION_MS as D, type EndpointDescriptor as E, type PaymentMode as P, type RouteDockManifest as R, type SLAConfig as S, type UrlPreflightResult as U, type VaultMode as V, type DisputeStatus as a, type EstimateCostResult as b, type PaymentRequest as c, type PaymentResult as d, type PreflightComplianceFlags as e, type PreflightModeCost as f, type PreflightResult as g, type PricingConfig as h, type SessionCloseFailedPayload as i, type SessionCloseResult as j, type SessionEvent as k, type SessionEventPayloadMap as l, type SessionHandle as m, type SessionOptions as n, type SessionPricingConfig as o, type SessionState as p, type SessionStats as q, type SessionTimeoutPayload as r, type StreamOptions as s };