@routedock/routedock 0.1.1 → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +281 -19
- package/dist/MppSessionHandler-B4TyD7Xg.d.cts +121 -0
- package/dist/MppSessionHandler-CLB5SzgN.d.ts +121 -0
- package/dist/ProviderRegistry-BJ9oJLVz.d.cts +142 -0
- package/dist/ProviderRegistry-C50nyhaF.d.ts +142 -0
- package/dist/RouteDockClient-B1roCa8h.d.cts +455 -0
- package/dist/RouteDockClient-BbkqjhMG.d.ts +455 -0
- package/dist/SessionReconciler-Dscw43F3.d.ts +125 -0
- package/dist/SessionReconciler-bi0z2qtN.d.cts +125 -0
- package/dist/SessionStore-BpK8vv0L.d.cts +111 -0
- package/dist/SessionStore-DvkZv8-E.d.ts +111 -0
- package/dist/client.cjs +2419 -202
- package/dist/client.d.cts +50 -81
- package/dist/client.d.ts +50 -81
- package/dist/client.js +2373 -203
- package/dist/index.cjs +3080 -298
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +3026 -298
- package/dist/provider/fastify.cjs +882 -0
- package/dist/provider/fastify.d.cts +35 -0
- package/dist/provider/fastify.d.ts +35 -0
- package/dist/provider/fastify.js +880 -0
- package/dist/provider/hono.cjs +948 -0
- package/dist/provider/hono.d.cts +99 -0
- package/dist/provider/hono.d.ts +99 -0
- package/dist/provider/hono.js +938 -0
- package/dist/provider.cjs +827 -97
- package/dist/provider.d.cts +32 -25
- package/dist/provider.d.ts +32 -25
- package/dist/provider.js +810 -99
- package/dist/react.cjs +2641 -0
- package/dist/react.d.cts +107 -0
- package/dist/react.d.ts +107 -0
- package/dist/react.js +2634 -0
- package/dist/routedockMiddleware-BlDsHuPl.d.ts +59 -0
- package/dist/routedockMiddleware-D97A5ptQ.d.cts +59 -0
- package/dist/schema.cjs +364 -0
- package/dist/schema.d.cts +3 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +359 -0
- package/dist/sign-CUf3rhTx.d.cts +53 -0
- package/dist/sign-Dpj2Mp7k.d.ts +53 -0
- package/dist/testing.cjs +57 -0
- package/dist/testing.d.cts +95 -0
- package/dist/testing.d.ts +95 -0
- package/dist/testing.js +54 -0
- package/dist/types-DmhmfLzP.d.cts +410 -0
- package/dist/types-DmhmfLzP.d.ts +410 -0
- package/package.json +143 -23
- package/PUBLISH_CHECKLIST.md +0 -70
- package/dist/SessionStore-CCVO0PHM.d.cts +0 -152
- package/dist/SessionStore-CCVO0PHM.d.ts +0 -152
- package/dist/routedockMiddleware-B7WTB3LT.d.cts +0 -53
- package/dist/routedockMiddleware-DRgdrycG.d.ts +0 -53
- package/src/client/ModeRouter.ts +0 -104
- package/src/client/MppChargeClient.ts +0 -44
- package/src/client/MppSessionClient.ts +0 -144
- package/src/client/RouteDockClient.ts +0 -124
- package/src/client/index.ts +0 -8
- package/src/client/x402Client.ts +0 -84
- package/src/index.ts +0 -9
- package/src/provider/MppChargeHandler.ts +0 -90
- package/src/provider/MppSessionHandler.ts +0 -157
- package/src/provider/index.ts +0 -7
- package/src/provider/routedockMiddleware.ts +0 -154
- package/src/provider/x402Handler.ts +0 -164
- package/src/schemas/routedock.schema.json +0 -159
- package/src/store/SessionStore.ts +0 -90
- package/src/tests/smoke.test.ts +0 -228
- package/src/types.ts +0 -165
- package/tsconfig.json +0 -14
- package/tsup.config.ts +0 -15
package/dist/client.d.cts
CHANGED
|
@@ -1,83 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as
|
|
1
|
+
import { R as RouteDockManifest, k as SessionOptions, j as SessionHandle } from './types-DmhmfLzP.cjs';
|
|
2
|
+
export { D as DEFAULT_MAX_SESSION_DURATION_MS, a as DisputeStatus, E as EndpointDescriptor, b as EstimateCostResult, P as PaymentMode, c as PaymentResult, d as PreflightResult, e as PricingConfig, S as SLAConfig, f as SessionCloseFailedPayload, g as SessionCloseResult, h as SessionEvent, i as SessionEventPayloadMap, l as SessionPricingConfig, m as SessionState, n as SessionStats, o as SessionTimeoutPayload, p as StreamOptions, V as VaultMode } from './types-DmhmfLzP.cjs';
|
|
3
|
+
export { R as RouteDockChannelStateError, a as RouteDockClientVersionError, b as RouteDockDisputeError, c as RouteDockError, d as RouteDockErrorCode, e as RouteDockErrorOptions, f as RouteDockFacilitatorError, g as RouteDockManifestError, h as RouteDockManifestSunsetError, i as RouteDockManifestTimeoutError, j as RouteDockNetworkError, k as RouteDockNoSupportedModeError, l as RouteDockPolicyRejectError, m as RouteDockPolicyRejectedError, n as RouteDockRefundWindowError, o as RouteDockSessionError, p as RouteDockSignatureError, q as RouteDockTrustlineError, r as RouteDockVoucherMonotonicityError, S as SessionStore, s as SupabaseSessionStore, t as httpStatusToError, u as parseRetryAfterMs, w as wrapFetchError } from './SessionStore-BpK8vv0L.cjs';
|
|
4
|
+
import { R as RetryPolicy } from './RouteDockClient-B1roCa8h.cjs';
|
|
5
|
+
export { D as DEFAULT_RETRY_POLICY, a as DailySpend, I as InMemorySpendStore, b as InMemorySpendStoreOptions, M as ModeSelectOptions, N as NulthAuthSignature, c as NulthClientConfig, d as NulthPolicyError, e as NulthPolicyState, f as NulthProof, g as NulthSignerConfig, h as NulthStellarSigner, i as NulthVaultConfig, P as PaymentAuthContext, j as RouteDockClient, k as RouteDockClientConfig, l as RouteDockLogger, S as SpendCap, m as SpendStore, V as VaultConfig, n as assertEndpointActive, o as assertManifestValid, p as assertNulthVaultManifest, q as backoffDelayMs, r as configureManifestCache, s as createNulthSigner, t as createPolicyState, u as decodeAuthSignature, v as fetchLedgerSequence, w as fetchManifest, x as invalidateManifest, y as paymentContextFromManifest, z as prepareNulthSigner, A as rankProvidersByLatency, B as selectMode, C as setNulthPaymentContext, E as usdcToMicros, F as withRetry } from './RouteDockClient-B1roCa8h.cjs';
|
|
6
|
+
export { F as FileSpendStore, M as MppChargeClient, O as OnChainProviderInfo, a as OnChainRegistry, P as ProviderRecord, b as ProviderRegistry, c as ProviderRegistryConfig, X as X402Client, u as usdcToUnits } from './ProviderRegistry-BJ9oJLVz.cjs';
|
|
3
7
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
8
|
+
export { USDC_DECIMALS, usdcToStroops } from '@routedock/nulth-sdk';
|
|
9
|
+
import 'mppx';
|
|
4
10
|
import '@supabase/supabase-js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** Force mpp-session if the provider supports it */
|
|
8
|
-
sustained?: boolean;
|
|
9
|
-
session?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Override mode selection and use this specific mode.
|
|
12
|
-
* Throws RouteDockNoSupportedModeError if the provider does not support it.
|
|
13
|
-
*/
|
|
14
|
-
forceMode?: PaymentMode;
|
|
15
|
-
}
|
|
16
|
-
/** Fetch, validate, and cache a RouteDock manifest from `baseUrl`. */
|
|
17
|
-
declare function fetchManifest(baseUrl: string): Promise<RouteDockManifest>;
|
|
18
|
-
/**
|
|
19
|
-
* Deterministic mode selection per Section 6.3 of ROUTEDOCK_MASTER.md:
|
|
20
|
-
* 1. If { sustained | session } AND manifest supports mpp-session → mpp-session
|
|
21
|
-
* 2. Else if manifest supports mpp-charge AND network is Stellar → mpp-charge
|
|
22
|
-
* 3. Else if manifest supports x402 → x402
|
|
23
|
-
* 4. Else throw RouteDockNoSupportedModeError
|
|
24
|
-
*/
|
|
25
|
-
declare function selectMode(manifest: RouteDockManifest, options?: ModeSelectOptions): PaymentMode;
|
|
26
|
-
|
|
27
|
-
interface SpendCap {
|
|
28
|
-
/** Maximum total USDC spend per day (decimal string, e.g. "1.00") */
|
|
29
|
-
daily: string;
|
|
30
|
-
asset: 'USDC';
|
|
31
|
-
}
|
|
32
|
-
interface RouteDockClientConfig {
|
|
33
|
-
/** Stellar keypair or raw secret key (S...) */
|
|
34
|
-
wallet: Keypair | string;
|
|
35
|
-
network: 'testnet' | 'mainnet';
|
|
36
|
-
/** Optional local daily spend cap — checked before every payment */
|
|
37
|
-
spendCap?: SpendCap;
|
|
38
|
-
/** Ed25519 secret key (S...) for signing channel commitments. Required for mpp-session. */
|
|
39
|
-
commitmentSecret?: string | undefined;
|
|
40
|
-
}
|
|
41
|
-
declare class RouteDockClient {
|
|
42
|
-
private readonly keypair;
|
|
43
|
-
private readonly network;
|
|
44
|
-
private readonly spendCap;
|
|
45
|
-
private readonly commitmentSecret;
|
|
46
|
-
/** Local daily accumulator keyed by YYYY-MM-DD */
|
|
47
|
-
private dailySpend;
|
|
48
|
-
private readonly x402;
|
|
49
|
-
private readonly charge;
|
|
50
|
-
private readonly session;
|
|
51
|
-
constructor(config: RouteDockClientConfig);
|
|
52
|
-
/**
|
|
53
|
-
* Pay for one request at `url`. Fetches manifest, selects payment mode,
|
|
54
|
-
* checks local spend cap, executes payment, returns result.
|
|
55
|
-
*/
|
|
56
|
-
pay(url: string, options?: ModeSelectOptions): Promise<PaymentResult>;
|
|
57
|
-
/**
|
|
58
|
-
* Open a sustained MPP session at `url`. Verifies mpp-session is supported
|
|
59
|
-
* before opening a channel. Returns a SessionHandle for streaming + closing.
|
|
60
|
-
*/
|
|
61
|
-
openSession(url: string): Promise<SessionHandle>;
|
|
62
|
-
/** Check local daily cap and record the spend. Throws if cap exceeded. */
|
|
63
|
-
private _checkAndRecordSpend;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type Network = 'testnet' | 'mainnet';
|
|
67
|
-
declare class X402Client {
|
|
68
|
-
private readonly secretKey;
|
|
69
|
-
private readonly network;
|
|
70
|
-
private readonly httpClient;
|
|
71
|
-
constructor(secretKey: string, network: Network);
|
|
72
|
-
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declare class MppChargeClient {
|
|
76
|
-
private readonly keypair;
|
|
77
|
-
private readonly network;
|
|
78
|
-
constructor(keypair: Keypair, network: 'testnet' | 'mainnet');
|
|
79
|
-
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
80
|
-
}
|
|
11
|
+
import '@x402/stellar';
|
|
12
|
+
import '@stellar/stellar-sdk/contract';
|
|
81
13
|
|
|
82
14
|
/**
|
|
83
15
|
* MppSessionClient — uses @stellar/mpp channel/client for off-chain
|
|
@@ -88,11 +20,48 @@ declare class MppChargeClient {
|
|
|
88
20
|
* @stellar/mpp library handles the 402 challenge-response cycle.
|
|
89
21
|
*/
|
|
90
22
|
|
|
23
|
+
/** A WebSocket socket as consumed by the mpp-session-ws stream. */
|
|
24
|
+
interface WebSocketLike {
|
|
25
|
+
readyState: number;
|
|
26
|
+
close(code?: number, reason?: string): void;
|
|
27
|
+
}
|
|
28
|
+
/** Callbacks a WebSocket factory must wire to the underlying socket. */
|
|
29
|
+
interface WebSocketHandlers {
|
|
30
|
+
onOpen(): void;
|
|
31
|
+
onMessage(data: string): void;
|
|
32
|
+
onClose(code: number, reason: string): void;
|
|
33
|
+
onError(): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a WebSocket connection with the given handshake headers.
|
|
37
|
+
* Injected for testability; defaults to the runtime WebSocket global
|
|
38
|
+
* (undici in Node ≥ 22 supports handshake headers via its options object).
|
|
39
|
+
*/
|
|
40
|
+
type WebSocketFactory = (url: string, init: {
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
}, handlers: WebSocketHandlers) => WebSocketLike;
|
|
91
43
|
declare class MppSessionClient {
|
|
92
44
|
private readonly keypair;
|
|
93
45
|
private readonly network;
|
|
94
|
-
|
|
95
|
-
|
|
46
|
+
private readonly retryPolicy?;
|
|
47
|
+
private readonly webSocketFactory;
|
|
48
|
+
constructor(keypair: Keypair, network: 'testnet' | 'mainnet', retryPolicy?: RetryPolicy | undefined, webSocketFactory?: WebSocketFactory);
|
|
49
|
+
openSession(url: string, manifest: RouteDockManifest, commitmentSecret: string, options?: SessionOptions, onSpend?: (amount: string) => Promise<void>): Promise<SessionHandle>;
|
|
50
|
+
/**
|
|
51
|
+
* mpp-session-ws streaming transport.
|
|
52
|
+
*
|
|
53
|
+
* Mirrors the issue's three-step sequence:
|
|
54
|
+
* 1. open the channel — probe the provider URL over HTTP;
|
|
55
|
+
* 2. negotiate the voucher — sign the mppx 402 challenge into a credential;
|
|
56
|
+
* 3. upgrade the HTTP connection to WebSocket — hand the signed voucher to
|
|
57
|
+
* the provider as the Authorization header of the WebSocket handshake.
|
|
58
|
+
*
|
|
59
|
+
* Each server frame is yielded (JSON frames parsed; raw strings yielded
|
|
60
|
+
* as-is). The stream ends when the server closes the socket with a normal
|
|
61
|
+
* close code (1000/1001); abnormal closes and connection failures surface as
|
|
62
|
+
* RouteDockChannelStateError.
|
|
63
|
+
*/
|
|
64
|
+
private streamWebSocket;
|
|
96
65
|
}
|
|
97
66
|
|
|
98
|
-
export {
|
|
67
|
+
export { MppSessionClient, RetryPolicy, RouteDockManifest, SessionHandle, SessionOptions, type WebSocketFactory, type WebSocketHandlers, type WebSocketLike };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,83 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as
|
|
1
|
+
import { R as RouteDockManifest, k as SessionOptions, j as SessionHandle } from './types-DmhmfLzP.js';
|
|
2
|
+
export { D as DEFAULT_MAX_SESSION_DURATION_MS, a as DisputeStatus, E as EndpointDescriptor, b as EstimateCostResult, P as PaymentMode, c as PaymentResult, d as PreflightResult, e as PricingConfig, S as SLAConfig, f as SessionCloseFailedPayload, g as SessionCloseResult, h as SessionEvent, i as SessionEventPayloadMap, l as SessionPricingConfig, m as SessionState, n as SessionStats, o as SessionTimeoutPayload, p as StreamOptions, V as VaultMode } from './types-DmhmfLzP.js';
|
|
3
|
+
export { R as RouteDockChannelStateError, a as RouteDockClientVersionError, b as RouteDockDisputeError, c as RouteDockError, d as RouteDockErrorCode, e as RouteDockErrorOptions, f as RouteDockFacilitatorError, g as RouteDockManifestError, h as RouteDockManifestSunsetError, i as RouteDockManifestTimeoutError, j as RouteDockNetworkError, k as RouteDockNoSupportedModeError, l as RouteDockPolicyRejectError, m as RouteDockPolicyRejectedError, n as RouteDockRefundWindowError, o as RouteDockSessionError, p as RouteDockSignatureError, q as RouteDockTrustlineError, r as RouteDockVoucherMonotonicityError, S as SessionStore, s as SupabaseSessionStore, t as httpStatusToError, u as parseRetryAfterMs, w as wrapFetchError } from './SessionStore-DvkZv8-E.js';
|
|
4
|
+
import { R as RetryPolicy } from './RouteDockClient-BbkqjhMG.js';
|
|
5
|
+
export { D as DEFAULT_RETRY_POLICY, a as DailySpend, I as InMemorySpendStore, b as InMemorySpendStoreOptions, M as ModeSelectOptions, N as NulthAuthSignature, c as NulthClientConfig, d as NulthPolicyError, e as NulthPolicyState, f as NulthProof, g as NulthSignerConfig, h as NulthStellarSigner, i as NulthVaultConfig, P as PaymentAuthContext, j as RouteDockClient, k as RouteDockClientConfig, l as RouteDockLogger, S as SpendCap, m as SpendStore, V as VaultConfig, n as assertEndpointActive, o as assertManifestValid, p as assertNulthVaultManifest, q as backoffDelayMs, r as configureManifestCache, s as createNulthSigner, t as createPolicyState, u as decodeAuthSignature, v as fetchLedgerSequence, w as fetchManifest, x as invalidateManifest, y as paymentContextFromManifest, z as prepareNulthSigner, A as rankProvidersByLatency, B as selectMode, C as setNulthPaymentContext, E as usdcToMicros, F as withRetry } from './RouteDockClient-BbkqjhMG.js';
|
|
6
|
+
export { F as FileSpendStore, M as MppChargeClient, O as OnChainProviderInfo, a as OnChainRegistry, P as ProviderRecord, b as ProviderRegistry, c as ProviderRegistryConfig, X as X402Client, u as usdcToUnits } from './ProviderRegistry-C50nyhaF.js';
|
|
3
7
|
import { Keypair } from '@stellar/stellar-sdk';
|
|
8
|
+
export { USDC_DECIMALS, usdcToStroops } from '@routedock/nulth-sdk';
|
|
9
|
+
import 'mppx';
|
|
4
10
|
import '@supabase/supabase-js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** Force mpp-session if the provider supports it */
|
|
8
|
-
sustained?: boolean;
|
|
9
|
-
session?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Override mode selection and use this specific mode.
|
|
12
|
-
* Throws RouteDockNoSupportedModeError if the provider does not support it.
|
|
13
|
-
*/
|
|
14
|
-
forceMode?: PaymentMode;
|
|
15
|
-
}
|
|
16
|
-
/** Fetch, validate, and cache a RouteDock manifest from `baseUrl`. */
|
|
17
|
-
declare function fetchManifest(baseUrl: string): Promise<RouteDockManifest>;
|
|
18
|
-
/**
|
|
19
|
-
* Deterministic mode selection per Section 6.3 of ROUTEDOCK_MASTER.md:
|
|
20
|
-
* 1. If { sustained | session } AND manifest supports mpp-session → mpp-session
|
|
21
|
-
* 2. Else if manifest supports mpp-charge AND network is Stellar → mpp-charge
|
|
22
|
-
* 3. Else if manifest supports x402 → x402
|
|
23
|
-
* 4. Else throw RouteDockNoSupportedModeError
|
|
24
|
-
*/
|
|
25
|
-
declare function selectMode(manifest: RouteDockManifest, options?: ModeSelectOptions): PaymentMode;
|
|
26
|
-
|
|
27
|
-
interface SpendCap {
|
|
28
|
-
/** Maximum total USDC spend per day (decimal string, e.g. "1.00") */
|
|
29
|
-
daily: string;
|
|
30
|
-
asset: 'USDC';
|
|
31
|
-
}
|
|
32
|
-
interface RouteDockClientConfig {
|
|
33
|
-
/** Stellar keypair or raw secret key (S...) */
|
|
34
|
-
wallet: Keypair | string;
|
|
35
|
-
network: 'testnet' | 'mainnet';
|
|
36
|
-
/** Optional local daily spend cap — checked before every payment */
|
|
37
|
-
spendCap?: SpendCap;
|
|
38
|
-
/** Ed25519 secret key (S...) for signing channel commitments. Required for mpp-session. */
|
|
39
|
-
commitmentSecret?: string | undefined;
|
|
40
|
-
}
|
|
41
|
-
declare class RouteDockClient {
|
|
42
|
-
private readonly keypair;
|
|
43
|
-
private readonly network;
|
|
44
|
-
private readonly spendCap;
|
|
45
|
-
private readonly commitmentSecret;
|
|
46
|
-
/** Local daily accumulator keyed by YYYY-MM-DD */
|
|
47
|
-
private dailySpend;
|
|
48
|
-
private readonly x402;
|
|
49
|
-
private readonly charge;
|
|
50
|
-
private readonly session;
|
|
51
|
-
constructor(config: RouteDockClientConfig);
|
|
52
|
-
/**
|
|
53
|
-
* Pay for one request at `url`. Fetches manifest, selects payment mode,
|
|
54
|
-
* checks local spend cap, executes payment, returns result.
|
|
55
|
-
*/
|
|
56
|
-
pay(url: string, options?: ModeSelectOptions): Promise<PaymentResult>;
|
|
57
|
-
/**
|
|
58
|
-
* Open a sustained MPP session at `url`. Verifies mpp-session is supported
|
|
59
|
-
* before opening a channel. Returns a SessionHandle for streaming + closing.
|
|
60
|
-
*/
|
|
61
|
-
openSession(url: string): Promise<SessionHandle>;
|
|
62
|
-
/** Check local daily cap and record the spend. Throws if cap exceeded. */
|
|
63
|
-
private _checkAndRecordSpend;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type Network = 'testnet' | 'mainnet';
|
|
67
|
-
declare class X402Client {
|
|
68
|
-
private readonly secretKey;
|
|
69
|
-
private readonly network;
|
|
70
|
-
private readonly httpClient;
|
|
71
|
-
constructor(secretKey: string, network: Network);
|
|
72
|
-
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declare class MppChargeClient {
|
|
76
|
-
private readonly keypair;
|
|
77
|
-
private readonly network;
|
|
78
|
-
constructor(keypair: Keypair, network: 'testnet' | 'mainnet');
|
|
79
|
-
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
80
|
-
}
|
|
11
|
+
import '@x402/stellar';
|
|
12
|
+
import '@stellar/stellar-sdk/contract';
|
|
81
13
|
|
|
82
14
|
/**
|
|
83
15
|
* MppSessionClient — uses @stellar/mpp channel/client for off-chain
|
|
@@ -88,11 +20,48 @@ declare class MppChargeClient {
|
|
|
88
20
|
* @stellar/mpp library handles the 402 challenge-response cycle.
|
|
89
21
|
*/
|
|
90
22
|
|
|
23
|
+
/** A WebSocket socket as consumed by the mpp-session-ws stream. */
|
|
24
|
+
interface WebSocketLike {
|
|
25
|
+
readyState: number;
|
|
26
|
+
close(code?: number, reason?: string): void;
|
|
27
|
+
}
|
|
28
|
+
/** Callbacks a WebSocket factory must wire to the underlying socket. */
|
|
29
|
+
interface WebSocketHandlers {
|
|
30
|
+
onOpen(): void;
|
|
31
|
+
onMessage(data: string): void;
|
|
32
|
+
onClose(code: number, reason: string): void;
|
|
33
|
+
onError(): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a WebSocket connection with the given handshake headers.
|
|
37
|
+
* Injected for testability; defaults to the runtime WebSocket global
|
|
38
|
+
* (undici in Node ≥ 22 supports handshake headers via its options object).
|
|
39
|
+
*/
|
|
40
|
+
type WebSocketFactory = (url: string, init: {
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
}, handlers: WebSocketHandlers) => WebSocketLike;
|
|
91
43
|
declare class MppSessionClient {
|
|
92
44
|
private readonly keypair;
|
|
93
45
|
private readonly network;
|
|
94
|
-
|
|
95
|
-
|
|
46
|
+
private readonly retryPolicy?;
|
|
47
|
+
private readonly webSocketFactory;
|
|
48
|
+
constructor(keypair: Keypair, network: 'testnet' | 'mainnet', retryPolicy?: RetryPolicy | undefined, webSocketFactory?: WebSocketFactory);
|
|
49
|
+
openSession(url: string, manifest: RouteDockManifest, commitmentSecret: string, options?: SessionOptions, onSpend?: (amount: string) => Promise<void>): Promise<SessionHandle>;
|
|
50
|
+
/**
|
|
51
|
+
* mpp-session-ws streaming transport.
|
|
52
|
+
*
|
|
53
|
+
* Mirrors the issue's three-step sequence:
|
|
54
|
+
* 1. open the channel — probe the provider URL over HTTP;
|
|
55
|
+
* 2. negotiate the voucher — sign the mppx 402 challenge into a credential;
|
|
56
|
+
* 3. upgrade the HTTP connection to WebSocket — hand the signed voucher to
|
|
57
|
+
* the provider as the Authorization header of the WebSocket handshake.
|
|
58
|
+
*
|
|
59
|
+
* Each server frame is yielded (JSON frames parsed; raw strings yielded
|
|
60
|
+
* as-is). The stream ends when the server closes the socket with a normal
|
|
61
|
+
* close code (1000/1001); abnormal closes and connection failures surface as
|
|
62
|
+
* RouteDockChannelStateError.
|
|
63
|
+
*/
|
|
64
|
+
private streamWebSocket;
|
|
96
65
|
}
|
|
97
66
|
|
|
98
|
-
export {
|
|
67
|
+
export { MppSessionClient, RetryPolicy, RouteDockManifest, SessionHandle, SessionOptions, type WebSocketFactory, type WebSocketHandlers, type WebSocketLike };
|