@toon-protocol/client 5.1.0 → 5.1.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.
- package/dist/{chunk-BHGJXLS7.js → chunk-GNPJRJ6U.js} +60 -16
- package/dist/chunk-GNPJRJ6U.js.map +1 -0
- package/dist/cli/main.js +13 -4
- package/dist/cli/main.js.map +1 -1
- package/dist/{client-DF3LZVLC.js → client-RO3VITXU.js} +4 -2
- package/dist/index.d.ts +38 -10
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BHGJXLS7.js.map +0 -1
- /package/dist/{client-DF3LZVLC.js.map → client-RO3VITXU.js.map} +0 -0
|
@@ -23,11 +23,17 @@ var ToonClientError = class extends Error {
|
|
|
23
23
|
code;
|
|
24
24
|
};
|
|
25
25
|
var NetworkError = class extends ToonClientError {
|
|
26
|
-
|
|
26
|
+
/** The URL that could not be reached, when the failure was reaching one. */
|
|
27
|
+
endpoint;
|
|
28
|
+
constructor(message, cause, endpoint) {
|
|
27
29
|
super(message, "NETWORK_ERROR", cause);
|
|
28
30
|
this.name = "NetworkError";
|
|
31
|
+
if (endpoint !== void 0) this.endpoint = endpoint;
|
|
29
32
|
}
|
|
30
33
|
};
|
|
34
|
+
function describeEndpoint(url, source) {
|
|
35
|
+
return source === "published" ? `${url} (the endpoint the connector published in its self-description)` : url;
|
|
36
|
+
}
|
|
31
37
|
var ConnectorError = class extends ToonClientError {
|
|
32
38
|
constructor(message, cause) {
|
|
33
39
|
super(message, "CONNECTOR_ERROR", cause);
|
|
@@ -1725,6 +1731,7 @@ function headerReader(headers) {
|
|
|
1725
1731
|
}
|
|
1726
1732
|
var HttpIlpClient = class {
|
|
1727
1733
|
httpEndpoint;
|
|
1734
|
+
endpointSource;
|
|
1728
1735
|
peerId;
|
|
1729
1736
|
authToken;
|
|
1730
1737
|
timeout;
|
|
@@ -1733,6 +1740,7 @@ var HttpIlpClient = class {
|
|
|
1733
1740
|
createWebSocket;
|
|
1734
1741
|
constructor(config) {
|
|
1735
1742
|
this.httpEndpoint = config.httpEndpoint;
|
|
1743
|
+
this.endpointSource = config.endpointSource;
|
|
1736
1744
|
this.peerId = config.peerId;
|
|
1737
1745
|
this.authToken = config.authToken;
|
|
1738
1746
|
this.timeout = config.timeout ?? 3e4;
|
|
@@ -1961,14 +1969,16 @@ var HttpIlpClient = class {
|
|
|
1961
1969
|
}
|
|
1962
1970
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1963
1971
|
return new NetworkError(
|
|
1964
|
-
`Request timeout after ${requestTimeout}ms`,
|
|
1965
|
-
error
|
|
1972
|
+
`Request timeout after ${requestTimeout}ms reaching ${describeEndpoint(this.httpEndpoint, this.endpointSource)}`,
|
|
1973
|
+
error,
|
|
1974
|
+
this.httpEndpoint
|
|
1966
1975
|
);
|
|
1967
1976
|
}
|
|
1968
1977
|
if (error instanceof TypeError && (error.message.includes("fetch failed") || error.message.includes("ECONNREFUSED") || error.message.includes("ECONNRESET") || error.message.includes("ETIMEDOUT") || error.message.includes("network"))) {
|
|
1969
1978
|
return new NetworkError(
|
|
1970
|
-
`Network connection failed: ${error.message}`,
|
|
1971
|
-
error
|
|
1979
|
+
`Network connection failed reaching ${describeEndpoint(this.httpEndpoint, this.endpointSource)}: ${error.message}`,
|
|
1980
|
+
error,
|
|
1981
|
+
this.httpEndpoint
|
|
1972
1982
|
);
|
|
1973
1983
|
}
|
|
1974
1984
|
return new ConnectorError(
|
|
@@ -2384,7 +2394,8 @@ var ConnectorEdgeClient = class {
|
|
|
2384
2394
|
} catch (error) {
|
|
2385
2395
|
throw new NetworkError(
|
|
2386
2396
|
`could not reach the connector client edge at ${url}`,
|
|
2387
|
-
error instanceof Error ? error : void 0
|
|
2397
|
+
error instanceof Error ? error : void 0,
|
|
2398
|
+
url
|
|
2388
2399
|
);
|
|
2389
2400
|
} finally {
|
|
2390
2401
|
clearTimeout(timer);
|
|
@@ -2420,8 +2431,8 @@ var ConnectorEdgeClient = class {
|
|
|
2420
2431
|
* a transport failure throws {@link NetworkError} instead, so a caller can
|
|
2421
2432
|
* always tell "not mine" from "could not ask".
|
|
2422
2433
|
*
|
|
2423
|
-
* Fetched once per (endpoint, destination) and reused. ADR 0020
|
|
2424
|
-
*
|
|
2434
|
+
* Fetched once per (endpoint, destination) and reused. ADR 0020 gives a
|
|
2435
|
+
* handler one set of terms, which do not vary with the packet — a route
|
|
2425
2436
|
* being repriced is an operator event, and {@link invalidateRoutePrice} is
|
|
2426
2437
|
* how a caller reacts to one.
|
|
2427
2438
|
*
|
|
@@ -2489,7 +2500,8 @@ var ConnectorEdgeClient = class {
|
|
|
2489
2500
|
} catch (error) {
|
|
2490
2501
|
throw new NetworkError(
|
|
2491
2502
|
`could not reach the connector client edge at ${base}/ilp`,
|
|
2492
|
-
error instanceof Error ? error : void 0
|
|
2503
|
+
error instanceof Error ? error : void 0,
|
|
2504
|
+
`${base}/ilp`
|
|
2493
2505
|
);
|
|
2494
2506
|
} finally {
|
|
2495
2507
|
clearTimeout(timer);
|
|
@@ -2543,7 +2555,8 @@ var ConnectorEdgeClient = class {
|
|
|
2543
2555
|
} catch (error) {
|
|
2544
2556
|
throw new NetworkError(
|
|
2545
2557
|
`could not reach the connector client edge at ${url}`,
|
|
2546
|
-
error instanceof Error ? error : void 0
|
|
2558
|
+
error instanceof Error ? error : void 0,
|
|
2559
|
+
url
|
|
2547
2560
|
);
|
|
2548
2561
|
} finally {
|
|
2549
2562
|
clearTimeout(timer);
|
|
@@ -2657,7 +2670,8 @@ var ConnectorEdgeClient = class {
|
|
|
2657
2670
|
} catch (error) {
|
|
2658
2671
|
throw new NetworkError(
|
|
2659
2672
|
`could not reach the connector client edge at ${url}`,
|
|
2660
|
-
error instanceof Error ? error : void 0
|
|
2673
|
+
error instanceof Error ? error : void 0,
|
|
2674
|
+
url
|
|
2661
2675
|
);
|
|
2662
2676
|
} finally {
|
|
2663
2677
|
clearTimeout(timer);
|
|
@@ -2744,6 +2758,8 @@ function sleep(ms) {
|
|
|
2744
2758
|
var BtpPaidWriteTransport = class {
|
|
2745
2759
|
session;
|
|
2746
2760
|
fallback;
|
|
2761
|
+
url;
|
|
2762
|
+
endpointSource;
|
|
2747
2763
|
maxReconnectAttempts;
|
|
2748
2764
|
reconnectDelay;
|
|
2749
2765
|
/**
|
|
@@ -2756,6 +2772,8 @@ var BtpPaidWriteTransport = class {
|
|
|
2756
2772
|
constructor(config) {
|
|
2757
2773
|
this.session = config.session;
|
|
2758
2774
|
this.fallback = config.fallback;
|
|
2775
|
+
this.url = config.url;
|
|
2776
|
+
this.endpointSource = config.endpointSource;
|
|
2759
2777
|
this.maxReconnectAttempts = config.maxReconnectAttempts ?? 1;
|
|
2760
2778
|
this.reconnectDelay = config.reconnectDelay ?? 250;
|
|
2761
2779
|
}
|
|
@@ -2802,8 +2820,26 @@ var BtpPaidWriteTransport = class {
|
|
|
2802
2820
|
}
|
|
2803
2821
|
/** Connect if need be, then send once. No claim, so nothing to re-spend. */
|
|
2804
2822
|
async dispatchUnpaid(params) {
|
|
2805
|
-
|
|
2806
|
-
|
|
2823
|
+
try {
|
|
2824
|
+
if (!this.session.isConnected) await this.session.connect();
|
|
2825
|
+
return await this.session.sendIlpPacket(params);
|
|
2826
|
+
} catch (error) {
|
|
2827
|
+
throw this.nameEndpoint(error);
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* A connection-level failure becomes a {@link NetworkError} naming the BTP
|
|
2832
|
+
* URL, with the original kept as `cause`. Anything else passes through.
|
|
2833
|
+
*/
|
|
2834
|
+
nameEndpoint(error) {
|
|
2835
|
+
if (this.url === void 0 || error instanceof NetworkError) return error;
|
|
2836
|
+
if (!isConnectionError2(error)) return error;
|
|
2837
|
+
const cause = error instanceof Error ? error : void 0;
|
|
2838
|
+
return new NetworkError(
|
|
2839
|
+
`BTP connection failed reaching ${describeEndpoint(this.url, this.endpointSource)}: ${cause?.message ?? String(error)}`,
|
|
2840
|
+
cause,
|
|
2841
|
+
this.url
|
|
2842
|
+
);
|
|
2807
2843
|
}
|
|
2808
2844
|
/**
|
|
2809
2845
|
* One write's worth of connect/send/reconnect/fallback policy. Runs
|
|
@@ -2837,8 +2873,12 @@ var BtpPaidWriteTransport = class {
|
|
|
2837
2873
|
if (this.fallback) {
|
|
2838
2874
|
return this.fallback.sendIlpPacketWithClaim(params, claim);
|
|
2839
2875
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2876
|
+
const named = this.nameEndpoint(lastError);
|
|
2877
|
+
if (named instanceof Error) throw named;
|
|
2878
|
+
throw new NetworkError(
|
|
2879
|
+
`BTP paid-write transport exhausted its reconnect budget${this.url !== void 0 ? ` reaching ${describeEndpoint(this.url, this.endpointSource)}` : ""} and no HTTP fallback is configured`,
|
|
2880
|
+
void 0,
|
|
2881
|
+
this.url
|
|
2842
2882
|
);
|
|
2843
2883
|
}
|
|
2844
2884
|
};
|
|
@@ -8396,6 +8436,7 @@ var ToonClient = class _ToonClient {
|
|
|
8396
8436
|
this.assertEndpointReachable(httpEndpoint);
|
|
8397
8437
|
const http2 = new HttpIlpClient({
|
|
8398
8438
|
httpEndpoint,
|
|
8439
|
+
...description.httpEndpoint !== void 0 ? { endpointSource: "published" } : {},
|
|
8399
8440
|
timeout: this.config.timeoutMs,
|
|
8400
8441
|
httpClient: this.config.fetch,
|
|
8401
8442
|
...this.config.createWebSocket ? { createWebSocket: this.config.createWebSocket } : {}
|
|
@@ -8422,6 +8463,8 @@ var ToonClient = class _ToonClient {
|
|
|
8422
8463
|
kind: "btp",
|
|
8423
8464
|
transport: new BtpPaidWriteTransport({
|
|
8424
8465
|
session,
|
|
8466
|
+
url: choice.url,
|
|
8467
|
+
endpointSource: "published",
|
|
8425
8468
|
// HTTP fallback only where the node did not REQUIRE btp *for this
|
|
8426
8469
|
// destination*: falling back onto a carriage the route refuses would
|
|
8427
8470
|
// turn a recoverable socket outage into a `402` per request. Read
|
|
@@ -8536,6 +8579,7 @@ function lazyEvmReader(config) {
|
|
|
8536
8579
|
export {
|
|
8537
8580
|
ToonClientError,
|
|
8538
8581
|
NetworkError,
|
|
8582
|
+
describeEndpoint,
|
|
8539
8583
|
ConnectorError,
|
|
8540
8584
|
ValidationError,
|
|
8541
8585
|
ConfigError,
|
|
@@ -8748,4 +8792,4 @@ export {
|
|
|
8748
8792
|
toEnvelopeRequest,
|
|
8749
8793
|
ToonClient
|
|
8750
8794
|
};
|
|
8751
|
-
//# sourceMappingURL=chunk-
|
|
8795
|
+
//# sourceMappingURL=chunk-GNPJRJ6U.js.map
|