@limrun/api 0.79.0 → 0.79.2
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/CHANGELOG.md +26 -0
- package/destination-tunnel-dialer.d.mts.map +1 -1
- package/destination-tunnel-dialer.d.ts.map +1 -1
- package/destination-tunnel-dialer.js +23 -14
- package/destination-tunnel-dialer.js.map +1 -1
- package/destination-tunnel-dialer.mjs +23 -14
- package/destination-tunnel-dialer.mjs.map +1 -1
- package/internal/app-log-events.d.mts +21 -0
- package/internal/app-log-events.d.mts.map +1 -0
- package/internal/app-log-events.d.ts +21 -0
- package/internal/app-log-events.d.ts.map +1 -0
- package/internal/app-log-events.js +73 -0
- package/internal/app-log-events.js.map +1 -0
- package/internal/app-log-events.mjs +69 -0
- package/internal/app-log-events.mjs.map +1 -0
- package/internal/signaling-transport.d.mts +79 -0
- package/internal/signaling-transport.d.mts.map +1 -0
- package/internal/signaling-transport.d.ts +79 -0
- package/internal/signaling-transport.d.ts.map +1 -0
- package/internal/signaling-transport.js +320 -0
- package/internal/signaling-transport.js.map +1 -0
- package/internal/signaling-transport.mjs +316 -0
- package/internal/signaling-transport.mjs.map +1 -0
- package/ios-client.d.mts +4 -9
- package/ios-client.d.mts.map +1 -1
- package/ios-client.d.ts +4 -9
- package/ios-client.d.ts.map +1 -1
- package/ios-client.js +172 -412
- package/ios-client.js.map +1 -1
- package/ios-client.mjs +173 -413
- package/ios-client.mjs.map +1 -1
- package/log-stream.d.mts +11 -4
- package/log-stream.d.mts.map +1 -1
- package/log-stream.d.ts +11 -4
- package/log-stream.d.ts.map +1 -1
- package/log-stream.js +45 -8
- package/log-stream.js.map +1 -1
- package/log-stream.mjs +45 -8
- package/log-stream.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/macos-instances-helpers.d.mts +12 -0
- package/resources/macos-instances-helpers.d.mts.map +1 -1
- package/resources/macos-instances-helpers.d.ts +12 -0
- package/resources/macos-instances-helpers.d.ts.map +1 -1
- package/resources/macos-instances-helpers.js +118 -141
- package/resources/macos-instances-helpers.js.map +1 -1
- package/resources/macos-instances-helpers.mjs +118 -141
- package/resources/macos-instances-helpers.mjs.map +1 -1
- package/src/destination-tunnel-dialer.ts +23 -14
- package/src/internal/app-log-events.ts +76 -0
- package/src/internal/signaling-transport.ts +454 -0
- package/src/ios-client.ts +193 -471
- package/src/log-stream.ts +54 -11
- package/src/resources/macos-instances-helpers.ts +153 -136
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { nodeProxyTransport } from "./proxy-transport.mjs";
|
|
2
|
+
import { directInstanceErrorReason } from "./direct-instance-errors.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* followAppLogEvents reads `GET <apiUrl>/app-logs/stream?bundleId=` and calls `onLine` per event.
|
|
5
|
+
* It resolves when the stream ends or `signal` aborts, and rejects on a non-2xx response or a
|
|
6
|
+
* broken connection. The instance sends no ids and replays nothing, so nothing resumes.
|
|
7
|
+
*/
|
|
8
|
+
export async function followAppLogEvents(source, onLine, signal) {
|
|
9
|
+
const url = `${source.apiUrl.replace(/\/+$/, '')}/app-logs/stream?${new URLSearchParams({
|
|
10
|
+
bundleId: source.bundleId,
|
|
11
|
+
})}`;
|
|
12
|
+
const response = await nodeProxyTransport.fetch(url, {
|
|
13
|
+
headers: { Authorization: `Bearer ${source.token}`, Accept: 'text/event-stream' },
|
|
14
|
+
signal,
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok || !response.body) {
|
|
17
|
+
const reason = directInstanceErrorReason(await response.text());
|
|
18
|
+
throw new Error(`GET /app-logs/stream failed: ${response.status} ${reason}`.trim());
|
|
19
|
+
}
|
|
20
|
+
for await (const event of readServerSentEvents(response.body))
|
|
21
|
+
onLine(event.data);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* readServerSentEvents yields the events of a server-sent event stream as they arrive. The data
|
|
25
|
+
* fields of one event are joined with newlines; comments such as keepalives are skipped.
|
|
26
|
+
*/
|
|
27
|
+
export async function* readServerSentEvents(body) {
|
|
28
|
+
const decoder = new TextDecoder();
|
|
29
|
+
let buffer = '';
|
|
30
|
+
let event = 'message';
|
|
31
|
+
let data = [];
|
|
32
|
+
let hasData = false;
|
|
33
|
+
const reader = body.getReader();
|
|
34
|
+
try {
|
|
35
|
+
while (true) {
|
|
36
|
+
const { value, done } = await reader.read();
|
|
37
|
+
if (done)
|
|
38
|
+
break;
|
|
39
|
+
buffer += decoder.decode(value, { stream: true });
|
|
40
|
+
let newline;
|
|
41
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
42
|
+
const line = buffer.slice(0, newline).replace(/\r$/, '');
|
|
43
|
+
buffer = buffer.slice(newline + 1);
|
|
44
|
+
if (line === '') {
|
|
45
|
+
if (hasData)
|
|
46
|
+
yield { event, data: data.join('\n') };
|
|
47
|
+
event = 'message';
|
|
48
|
+
data = [];
|
|
49
|
+
hasData = false;
|
|
50
|
+
}
|
|
51
|
+
else if (line.startsWith('event:')) {
|
|
52
|
+
event = line.slice(6).trim();
|
|
53
|
+
}
|
|
54
|
+
else if (line.startsWith('data:')) {
|
|
55
|
+
data.push(line.slice(5).replace(/^ /, ''));
|
|
56
|
+
hasData = true;
|
|
57
|
+
}
|
|
58
|
+
else if (line === 'data') {
|
|
59
|
+
data.push('');
|
|
60
|
+
hasData = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
reader.releaseLock();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=app-log-events.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-log-events.mjs","sourceRoot":"","sources":["../src/internal/app-log-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,8BAA0B;AACvD,OA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CAAC;qBAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;oBAC3B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACd,OAAO,GAAG,IAAI,CAAC;gBACjB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection state of an instance's signaling WebSocket.
|
|
3
|
+
*/
|
|
4
|
+
export type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
5
|
+
/**
|
|
6
|
+
* Callback function for connection state changes
|
|
7
|
+
*/
|
|
8
|
+
export type ConnectionStateCallback = (state: ConnectionState) => void;
|
|
9
|
+
/** A message the instance sends on the signaling socket. Replies carry the request's `id`. */
|
|
10
|
+
export type SignalingMessage = {
|
|
11
|
+
type: string;
|
|
12
|
+
id: string;
|
|
13
|
+
error?: string | null;
|
|
14
|
+
} & Record<string, any>;
|
|
15
|
+
export interface SignalingLogger {
|
|
16
|
+
debug: (...args: any[]) => void;
|
|
17
|
+
info: (...args: any[]) => void;
|
|
18
|
+
warn: (...args: any[]) => void;
|
|
19
|
+
error: (...args: any[]) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface SignalingTransportOptions {
|
|
22
|
+
/** The instance's API URL; the socket opens at its `/signaling` path. */
|
|
23
|
+
apiUrl: string;
|
|
24
|
+
token: string;
|
|
25
|
+
logger: SignalingLogger;
|
|
26
|
+
/** Reconnect attempts after the socket drops. Defaults to 6. */
|
|
27
|
+
maxReconnectAttempts?: number;
|
|
28
|
+
/** First reconnect delay in milliseconds, doubled per attempt. Defaults to 1000. */
|
|
29
|
+
reconnectDelay?: number;
|
|
30
|
+
/** Longest reconnect delay in milliseconds. Defaults to 30000. */
|
|
31
|
+
maxReconnectDelay?: number;
|
|
32
|
+
/** Turns a reply into a request's result, by reply type. Unknown types resolve with the message. */
|
|
33
|
+
responseHandlers?: Record<string, (message: SignalingMessage) => unknown>;
|
|
34
|
+
/** Turns a reply's `error` into the error its request rejects with. Defaults to an Error with that text. */
|
|
35
|
+
replyError?: (message: SignalingMessage) => Error;
|
|
36
|
+
/** Consumes messages that are not replies, such as notifications and streams. True when handled. */
|
|
37
|
+
handleMessage?: (message: SignalingMessage) => boolean;
|
|
38
|
+
/** Called when the socket closes, with the reason pending requests failed for. */
|
|
39
|
+
onConnectionLost?: (reason: string) => void;
|
|
40
|
+
/** Called once the client is closed for good: on disconnect, or when reconnecting gives up. */
|
|
41
|
+
onClosed?: () => void;
|
|
42
|
+
/** What a request looks like in debug logs, for requests that carry secrets. */
|
|
43
|
+
redactRequest?: (request: Record<string, unknown>) => Record<string, unknown>;
|
|
44
|
+
/** Runs on the first open before the transport resolves; a failure rejects it. */
|
|
45
|
+
onFirstOpen?: (transport: SignalingTransport) => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* SignalingTransport is an instance's signaling WebSocket: requests matched to replies by `id`,
|
|
49
|
+
* reconnects with exponential backoff, and keepAlive. The iOS and macOS clients share it.
|
|
50
|
+
*/
|
|
51
|
+
export interface SignalingTransport {
|
|
52
|
+
/** The signaling WebSocket URL, token included. */
|
|
53
|
+
readonly url: string;
|
|
54
|
+
/**
|
|
55
|
+
* Send `{type, id, ...params}` and resolve with the reply with the same `id`. A `timeoutMs` of
|
|
56
|
+
* zero waits until the reply or the connection ends. Pass `id` (from {@link nextId}) to match
|
|
57
|
+
* messages the instance sends before the reply, such as progress.
|
|
58
|
+
*/
|
|
59
|
+
request<T>(type: string, params?: Record<string, unknown>, transform?: (message: SignalingMessage) => T, timeoutMs?: number, id?: string): Promise<T>;
|
|
60
|
+
/** A new request ID. */
|
|
61
|
+
nextId(): string;
|
|
62
|
+
/** Send a message without waiting for a reply. False when the socket is not open. */
|
|
63
|
+
send(message: Record<string, unknown>, callback?: (err?: Error) => void): boolean;
|
|
64
|
+
isOpen(): boolean;
|
|
65
|
+
/** Send an application-level keepAlive message. */
|
|
66
|
+
keepAlive(): void;
|
|
67
|
+
/** Close the socket for good and fail pending requests. */
|
|
68
|
+
disconnect(): void;
|
|
69
|
+
getConnectionState(): ConnectionState;
|
|
70
|
+
onConnectionStateChange(callback: ConnectionStateCallback): () => void;
|
|
71
|
+
}
|
|
72
|
+
/** signalingUrl is the signaling WebSocket URL of an instance API URL. */
|
|
73
|
+
export declare function signalingUrl(apiUrl: string, token: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Open an instance's signaling WebSocket. Resolves once it is open and `onFirstOpen` finished.
|
|
76
|
+
* Only the opening handshake is retried before it resolves, once, when the failure is transient.
|
|
77
|
+
*/
|
|
78
|
+
export declare function openSignalingTransport(options: SignalingTransportOptions): Promise<SignalingTransport>;
|
|
79
|
+
//# sourceMappingURL=signaling-transport.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signaling-transport.d.mts","sourceRoot":"","sources":["../src/internal/signaling-transport.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;AAE3F;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;AAEvE,8FAA8F;AAC9F,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEzG,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;I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AAO,CAAC,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,CAAC,EAC5C,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,CAAC,EAAE,MAAM,GACV,OAAO,CAAC,CAAC,CAAC,CAAC;IACd,wBAAwB;IACxB,MAAM,IAAI,MAAM,CAAC;IACjB,qFAAqF;IACrF,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC;IAClF,MAAM,IAAI,OAAO,CAAC;IAClB,mDAAmD;IACnD,SAAS,IAAI,IAAI,CAAC;IAClB,2DAA2D;IAC3D,UAAU,IAAI,IAAI,CAAC;IACnB,kBAAkB,IAAI,eAAe,CAAC;IACtC,uBAAuB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI,CAAC;CACxE;AAYD,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8VtG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection state of an instance's signaling WebSocket.
|
|
3
|
+
*/
|
|
4
|
+
export type ConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
5
|
+
/**
|
|
6
|
+
* Callback function for connection state changes
|
|
7
|
+
*/
|
|
8
|
+
export type ConnectionStateCallback = (state: ConnectionState) => void;
|
|
9
|
+
/** A message the instance sends on the signaling socket. Replies carry the request's `id`. */
|
|
10
|
+
export type SignalingMessage = {
|
|
11
|
+
type: string;
|
|
12
|
+
id: string;
|
|
13
|
+
error?: string | null;
|
|
14
|
+
} & Record<string, any>;
|
|
15
|
+
export interface SignalingLogger {
|
|
16
|
+
debug: (...args: any[]) => void;
|
|
17
|
+
info: (...args: any[]) => void;
|
|
18
|
+
warn: (...args: any[]) => void;
|
|
19
|
+
error: (...args: any[]) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface SignalingTransportOptions {
|
|
22
|
+
/** The instance's API URL; the socket opens at its `/signaling` path. */
|
|
23
|
+
apiUrl: string;
|
|
24
|
+
token: string;
|
|
25
|
+
logger: SignalingLogger;
|
|
26
|
+
/** Reconnect attempts after the socket drops. Defaults to 6. */
|
|
27
|
+
maxReconnectAttempts?: number;
|
|
28
|
+
/** First reconnect delay in milliseconds, doubled per attempt. Defaults to 1000. */
|
|
29
|
+
reconnectDelay?: number;
|
|
30
|
+
/** Longest reconnect delay in milliseconds. Defaults to 30000. */
|
|
31
|
+
maxReconnectDelay?: number;
|
|
32
|
+
/** Turns a reply into a request's result, by reply type. Unknown types resolve with the message. */
|
|
33
|
+
responseHandlers?: Record<string, (message: SignalingMessage) => unknown>;
|
|
34
|
+
/** Turns a reply's `error` into the error its request rejects with. Defaults to an Error with that text. */
|
|
35
|
+
replyError?: (message: SignalingMessage) => Error;
|
|
36
|
+
/** Consumes messages that are not replies, such as notifications and streams. True when handled. */
|
|
37
|
+
handleMessage?: (message: SignalingMessage) => boolean;
|
|
38
|
+
/** Called when the socket closes, with the reason pending requests failed for. */
|
|
39
|
+
onConnectionLost?: (reason: string) => void;
|
|
40
|
+
/** Called once the client is closed for good: on disconnect, or when reconnecting gives up. */
|
|
41
|
+
onClosed?: () => void;
|
|
42
|
+
/** What a request looks like in debug logs, for requests that carry secrets. */
|
|
43
|
+
redactRequest?: (request: Record<string, unknown>) => Record<string, unknown>;
|
|
44
|
+
/** Runs on the first open before the transport resolves; a failure rejects it. */
|
|
45
|
+
onFirstOpen?: (transport: SignalingTransport) => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* SignalingTransport is an instance's signaling WebSocket: requests matched to replies by `id`,
|
|
49
|
+
* reconnects with exponential backoff, and keepAlive. The iOS and macOS clients share it.
|
|
50
|
+
*/
|
|
51
|
+
export interface SignalingTransport {
|
|
52
|
+
/** The signaling WebSocket URL, token included. */
|
|
53
|
+
readonly url: string;
|
|
54
|
+
/**
|
|
55
|
+
* Send `{type, id, ...params}` and resolve with the reply with the same `id`. A `timeoutMs` of
|
|
56
|
+
* zero waits until the reply or the connection ends. Pass `id` (from {@link nextId}) to match
|
|
57
|
+
* messages the instance sends before the reply, such as progress.
|
|
58
|
+
*/
|
|
59
|
+
request<T>(type: string, params?: Record<string, unknown>, transform?: (message: SignalingMessage) => T, timeoutMs?: number, id?: string): Promise<T>;
|
|
60
|
+
/** A new request ID. */
|
|
61
|
+
nextId(): string;
|
|
62
|
+
/** Send a message without waiting for a reply. False when the socket is not open. */
|
|
63
|
+
send(message: Record<string, unknown>, callback?: (err?: Error) => void): boolean;
|
|
64
|
+
isOpen(): boolean;
|
|
65
|
+
/** Send an application-level keepAlive message. */
|
|
66
|
+
keepAlive(): void;
|
|
67
|
+
/** Close the socket for good and fail pending requests. */
|
|
68
|
+
disconnect(): void;
|
|
69
|
+
getConnectionState(): ConnectionState;
|
|
70
|
+
onConnectionStateChange(callback: ConnectionStateCallback): () => void;
|
|
71
|
+
}
|
|
72
|
+
/** signalingUrl is the signaling WebSocket URL of an instance API URL. */
|
|
73
|
+
export declare function signalingUrl(apiUrl: string, token: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Open an instance's signaling WebSocket. Resolves once it is open and `onFirstOpen` finished.
|
|
76
|
+
* Only the opening handshake is retried before it resolves, once, when the failure is transient.
|
|
77
|
+
*/
|
|
78
|
+
export declare function openSignalingTransport(options: SignalingTransportOptions): Promise<SignalingTransport>;
|
|
79
|
+
//# sourceMappingURL=signaling-transport.d.ts.map
|
|
@@ -0,0 +1 @@
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I,CAAC;IACnB,kBAAkB,IAAI,eAAe,CAAC;IACtC,uBAAuB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI,CAAC;CACxE;AAYD,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8VtG"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signalingUrl = signalingUrl;
|
|
4
|
+
exports.openSignalingTransport = openSignalingTransport;
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const ws_1 = require("ws");
|
|
7
|
+
const proxy_transport_1 = require("./proxy-transport.js");
|
|
8
|
+
const tunnel_1 = require("../tunnel.js");
|
|
9
|
+
/** The WebSocket close code for a policy violation, as the instance closes a refused session. */
|
|
10
|
+
const POLICY_VIOLATION = 1008;
|
|
11
|
+
/** signalingUrl is the signaling WebSocket URL of an instance API URL. */
|
|
12
|
+
function signalingUrl(apiUrl, token) {
|
|
13
|
+
return `${apiUrl.replace('https://', 'wss://').replace('http://', 'ws://')}/signaling?token=${token}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Open an instance's signaling WebSocket. Resolves once it is open and `onFirstOpen` finished.
|
|
17
|
+
* Only the opening handshake is retried before it resolves, once, when the failure is transient.
|
|
18
|
+
*/
|
|
19
|
+
function openSignalingTransport(options) {
|
|
20
|
+
const url = signalingUrl(options.apiUrl, options.token);
|
|
21
|
+
const logger = options.logger;
|
|
22
|
+
const maxReconnectAttempts = options.maxReconnectAttempts ?? 6;
|
|
23
|
+
const reconnectDelay = options.reconnectDelay ?? 1000;
|
|
24
|
+
const maxReconnectDelay = options.maxReconnectDelay ?? 30000;
|
|
25
|
+
const responseHandlers = options.responseHandlers ?? {};
|
|
26
|
+
let ws = undefined;
|
|
27
|
+
let connectionState = 'connecting';
|
|
28
|
+
let reconnectAttempts = 0;
|
|
29
|
+
let reconnectTimeout;
|
|
30
|
+
let handshakeDeadline;
|
|
31
|
+
let pingInterval;
|
|
32
|
+
let intentionalDisconnect = false;
|
|
33
|
+
let lastError;
|
|
34
|
+
// What the instance said in an error frame before closing, such as a message above the grant.
|
|
35
|
+
let instanceError;
|
|
36
|
+
const pendingRequests = new Map();
|
|
37
|
+
const stateChangeCallbacks = new Set();
|
|
38
|
+
const keepAliveSessionId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
39
|
+
const updateConnectionState = (newState) => {
|
|
40
|
+
if (connectionState !== newState) {
|
|
41
|
+
connectionState = newState;
|
|
42
|
+
logger.debug(`Connection state changed to: ${newState}`);
|
|
43
|
+
stateChangeCallbacks.forEach((callback) => {
|
|
44
|
+
try {
|
|
45
|
+
callback(newState);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
logger.error('Error in connection state callback:', err);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const failPendingRequests = (reason) => {
|
|
54
|
+
pendingRequests.forEach((request) => {
|
|
55
|
+
clearTimeout(request.timeout);
|
|
56
|
+
request.reject(new Error(reason));
|
|
57
|
+
});
|
|
58
|
+
pendingRequests.clear();
|
|
59
|
+
options.onConnectionLost?.(reason);
|
|
60
|
+
};
|
|
61
|
+
const cleanupConnection = () => {
|
|
62
|
+
clearTimeout(handshakeDeadline);
|
|
63
|
+
if (reconnectTimeout) {
|
|
64
|
+
clearTimeout(reconnectTimeout);
|
|
65
|
+
reconnectTimeout = undefined;
|
|
66
|
+
}
|
|
67
|
+
if (pingInterval) {
|
|
68
|
+
clearInterval(pingInterval);
|
|
69
|
+
pingInterval = undefined;
|
|
70
|
+
}
|
|
71
|
+
if (ws) {
|
|
72
|
+
ws.removeAllListeners();
|
|
73
|
+
// A retired socket can emit an error when an unfinished handshake is cancelled.
|
|
74
|
+
ws.on('error', () => { });
|
|
75
|
+
if (ws.readyState === ws_1.WebSocket.OPEN || ws.readyState === ws_1.WebSocket.CONNECTING) {
|
|
76
|
+
ws.close();
|
|
77
|
+
}
|
|
78
|
+
ws = undefined;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const isOpen = () => !!ws && ws.readyState === ws_1.WebSocket.OPEN;
|
|
82
|
+
const generateId = () => `ts-client-${(0, crypto_1.randomUUID)()}`;
|
|
83
|
+
const request = (type, params = {}, transform, timeoutMs = 30000, id = generateId()) => {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
if (!ws || ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
86
|
+
reject(new Error('WebSocket is not connected or connection is not open.'));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const timeout = timeoutMs > 0 ?
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
pendingRequests.delete(id);
|
|
92
|
+
reject(new Error(`Request ${type} timed out`));
|
|
93
|
+
}, timeoutMs)
|
|
94
|
+
: undefined;
|
|
95
|
+
pendingRequests.set(id, transform ? { resolve, reject, timeout, transform } : { resolve, reject, timeout });
|
|
96
|
+
const message = { type, id, ...params };
|
|
97
|
+
logger.debug('Sending request:', options.redactRequest ? options.redactRequest(message) : message);
|
|
98
|
+
ws.send(JSON.stringify(message), (err) => {
|
|
99
|
+
if (err) {
|
|
100
|
+
clearTimeout(timeout);
|
|
101
|
+
pendingRequests.delete(id);
|
|
102
|
+
logger.error(`Failed to send ${type} request:`, err);
|
|
103
|
+
reject(err);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const send = (message, callback) => {
|
|
109
|
+
if (!ws || ws.readyState !== ws_1.WebSocket.OPEN)
|
|
110
|
+
return false;
|
|
111
|
+
ws.send(JSON.stringify(message), callback);
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
const keepAlive = () => {
|
|
115
|
+
send({ type: 'keepAlive', sessionId: keepAliveSessionId });
|
|
116
|
+
};
|
|
117
|
+
const disconnect = () => {
|
|
118
|
+
intentionalDisconnect = true;
|
|
119
|
+
cleanupConnection();
|
|
120
|
+
updateConnectionState('disconnected');
|
|
121
|
+
failPendingRequests('Intentional disconnect');
|
|
122
|
+
options.onClosed?.();
|
|
123
|
+
logger.debug('Intentionally disconnected from WebSocket.');
|
|
124
|
+
};
|
|
125
|
+
const transport = {
|
|
126
|
+
url,
|
|
127
|
+
request,
|
|
128
|
+
nextId: generateId,
|
|
129
|
+
send,
|
|
130
|
+
isOpen,
|
|
131
|
+
keepAlive,
|
|
132
|
+
disconnect,
|
|
133
|
+
getConnectionState: () => connectionState,
|
|
134
|
+
onConnectionStateChange: (callback) => {
|
|
135
|
+
stateChangeCallbacks.add(callback);
|
|
136
|
+
return () => {
|
|
137
|
+
stateChangeCallbacks.delete(callback);
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
return new Promise((resolveConnection, rejectConnection) => {
|
|
142
|
+
let hasResolved = false;
|
|
143
|
+
let retriedHandshake = false;
|
|
144
|
+
// Reconnection logic with exponential backoff
|
|
145
|
+
const scheduleReconnect = () => {
|
|
146
|
+
if (intentionalDisconnect) {
|
|
147
|
+
logger.debug('Skipping reconnection (intentional disconnect)');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if ((0, tunnel_1.isNonRetryableError)(lastError ?? '')) {
|
|
151
|
+
logger.error(`Skipping reconnection (non-retryable error): ${lastError}`);
|
|
152
|
+
updateConnectionState('disconnected');
|
|
153
|
+
options.onClosed?.();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (reconnectAttempts >= maxReconnectAttempts) {
|
|
157
|
+
logger.error(`Max reconnection attempts (${maxReconnectAttempts}) reached. Giving up.`);
|
|
158
|
+
updateConnectionState('disconnected');
|
|
159
|
+
options.onClosed?.();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const currentDelay = Math.min(reconnectDelay * Math.pow(2, reconnectAttempts), maxReconnectDelay);
|
|
163
|
+
reconnectAttempts++;
|
|
164
|
+
logger.debug(`Scheduling reconnection attempt ${reconnectAttempts} in ${currentDelay}ms...`);
|
|
165
|
+
updateConnectionState('reconnecting');
|
|
166
|
+
reconnectTimeout = setTimeout(() => {
|
|
167
|
+
logger.debug(`Attempting to reconnect (attempt ${reconnectAttempts})...`);
|
|
168
|
+
setupWebSocket();
|
|
169
|
+
}, currentDelay);
|
|
170
|
+
};
|
|
171
|
+
const setupWebSocket = () => {
|
|
172
|
+
cleanupConnection();
|
|
173
|
+
updateConnectionState('connecting');
|
|
174
|
+
const proxyAgent = proxy_transport_1.nodeProxyTransport.getWebSocketAgent(url);
|
|
175
|
+
let opened = false;
|
|
176
|
+
let handshakeError;
|
|
177
|
+
const socket = new ws_1.WebSocket(url, proxyAgent ? { agent: proxyAgent } : {});
|
|
178
|
+
ws = socket;
|
|
179
|
+
// A socket inactivity timeout allows a slow TLS peer to keep the first command waiting.
|
|
180
|
+
handshakeDeadline = setTimeout(() => {
|
|
181
|
+
handshakeError = Object.assign(new Error('Opening handshake has timed out'), { code: 'ETIMEDOUT' });
|
|
182
|
+
socket.terminate();
|
|
183
|
+
}, 5000);
|
|
184
|
+
socket.on('message', (data) => {
|
|
185
|
+
let message;
|
|
186
|
+
try {
|
|
187
|
+
message = JSON.parse(data.toString());
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
logger.error({ data, error: e }, 'Failed to parse JSON message');
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (options.handleMessage?.(message)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const pending = pendingRequests.get(message.id);
|
|
197
|
+
if (!pending) {
|
|
198
|
+
if (message.type === 'error' && message['message']) {
|
|
199
|
+
// The instance explains a policy close, such as a message above the token's grant.
|
|
200
|
+
instanceError = String(message['message']);
|
|
201
|
+
logger.error('Instance error:', instanceError);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
logger.debug(`Received response for unknown or already handled request: ${message.id}`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
clearTimeout(pending.timeout);
|
|
208
|
+
pendingRequests.delete(message.id);
|
|
209
|
+
if (message.error) {
|
|
210
|
+
logger.debug(`Server error for ${message.type}: ${message.error}`);
|
|
211
|
+
pending.reject(options.replyError ? options.replyError(message) : new Error(message.error));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Use handler to transform response, or resolve with raw message
|
|
215
|
+
const handler = pending.transform ?? responseHandlers[message.type];
|
|
216
|
+
if (handler) {
|
|
217
|
+
try {
|
|
218
|
+
pending.resolve(handler(message));
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
pending.reject(err);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
logger.warn('Received unexpected message type:', message.type);
|
|
226
|
+
pending.resolve(message);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
socket.on('error', (err) => {
|
|
230
|
+
lastError = err.message;
|
|
231
|
+
logger.error('WebSocket error:', err.message);
|
|
232
|
+
if (!opened)
|
|
233
|
+
handshakeError ?? (handshakeError = err);
|
|
234
|
+
});
|
|
235
|
+
socket.on('close', (code) => {
|
|
236
|
+
clearTimeout(handshakeDeadline);
|
|
237
|
+
if (pingInterval) {
|
|
238
|
+
clearInterval(pingInterval);
|
|
239
|
+
pingInterval = undefined;
|
|
240
|
+
}
|
|
241
|
+
// A policy close, or the instance's error frame before it, refuses the token for good,
|
|
242
|
+
// such as a command above its grant, so reconnecting cannot help.
|
|
243
|
+
const refusal = instanceError ?? (code === POLICY_VIOLATION ? 'the instance closed the session' : undefined);
|
|
244
|
+
instanceError = undefined;
|
|
245
|
+
const shouldReconnect = !intentionalDisconnect &&
|
|
246
|
+
!refusal &&
|
|
247
|
+
!(0, tunnel_1.isNonRetryableError)(lastError ?? '') &&
|
|
248
|
+
connectionState !== 'disconnected';
|
|
249
|
+
updateConnectionState('disconnected');
|
|
250
|
+
logger.debug('Disconnected from server.');
|
|
251
|
+
failPendingRequests(refusal ? `Connection closed: ${refusal}` : 'Connection closed');
|
|
252
|
+
if (!hasResolved) {
|
|
253
|
+
// Settle before onFirstOpen sees its request fail, with the instance's reason.
|
|
254
|
+
const err = refusal ?
|
|
255
|
+
new Error(refusal)
|
|
256
|
+
: handshakeError ?? new Error('Connection closed before the client was ready');
|
|
257
|
+
// Retry only the opening handshake. Once open, onFirstOpen owns its failure.
|
|
258
|
+
const code = err.code;
|
|
259
|
+
const transient = ['ETIMEDOUT', 'ECONNRESET', 'ECONNREFUSED', 'EHOSTUNREACH', 'ENETUNREACH', 'EAI_AGAIN'].includes(code ?? '') ||
|
|
260
|
+
/^(Opening handshake has timed out|socket hang up|Unexpected server response: 50[234])$/.test(err.message);
|
|
261
|
+
if (!refusal && !opened && !retriedHandshake && maxReconnectAttempts > 0 && transient) {
|
|
262
|
+
retriedHandshake = true;
|
|
263
|
+
updateConnectionState('reconnecting');
|
|
264
|
+
reconnectTimeout = setTimeout(setupWebSocket, 100 + Math.floor(Math.random() * 151));
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
cleanupConnection();
|
|
268
|
+
rejectConnection(err);
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (shouldReconnect) {
|
|
273
|
+
scheduleReconnect();
|
|
274
|
+
}
|
|
275
|
+
else if (refusal && !intentionalDisconnect) {
|
|
276
|
+
logger.error(`The instance closed the session: ${refusal}`);
|
|
277
|
+
cleanupConnection();
|
|
278
|
+
options.onClosed?.();
|
|
279
|
+
}
|
|
280
|
+
else if ((0, tunnel_1.isNonRetryableError)(lastError ?? '')) {
|
|
281
|
+
logger.error(`Closing connection due to non-retryable error: ${lastError}`);
|
|
282
|
+
cleanupConnection();
|
|
283
|
+
updateConnectionState('disconnected');
|
|
284
|
+
failPendingRequests('Non-retryable error');
|
|
285
|
+
options.onClosed?.();
|
|
286
|
+
logger.debug('Non-retryable error. Closing connection.');
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
socket.on('open', async () => {
|
|
290
|
+
clearTimeout(handshakeDeadline);
|
|
291
|
+
opened = true;
|
|
292
|
+
logger.debug('WebSocket connected');
|
|
293
|
+
reconnectAttempts = 0;
|
|
294
|
+
lastError = undefined;
|
|
295
|
+
updateConnectionState('connected');
|
|
296
|
+
pingInterval = setInterval(() => {
|
|
297
|
+
if (ws && ws.readyState === ws_1.WebSocket.OPEN) {
|
|
298
|
+
ws.ping();
|
|
299
|
+
}
|
|
300
|
+
}, 30000);
|
|
301
|
+
if (!hasResolved) {
|
|
302
|
+
try {
|
|
303
|
+
await options.onFirstOpen?.(transport);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
logger.error('Failed to prepare the client:', err);
|
|
307
|
+
cleanupConnection();
|
|
308
|
+
updateConnectionState('disconnected');
|
|
309
|
+
rejectConnection(err);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
hasResolved = true;
|
|
313
|
+
resolveConnection(transport);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
setupWebSocket();
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=signaling-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signaling-transport.js","sourceRoot":"","sources":["../src/internal/signaling-transport.ts"],"names":[],"mappings":";;AA+FA,oCAEC;AAMD,wDA8VC;AArcD,mCAAoC;AACpC,2BAAqC;AACrC,0DAAuD;AACvD,yCAAgD;AAwFhD,iGAAiG;AACjG,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,0EAA0E;AAC1E,SAAgB,YAAY,CAAC,MAAc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