@bian-womp/spark-remote 0.2.82 → 0.2.83

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.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * WebSocket event handlers for connection lifecycle events.
3
+ */
4
+ export interface WebSocketHandlers {
5
+ onopen?: (ev: Event) => void;
6
+ onmessage?: (ev: MessageEvent) => void;
7
+ onerror?: (ev: Event) => void;
8
+ onclose?: (ev: CloseEvent) => void;
9
+ }
10
+ /**
11
+ * Parameters for establishing a WebSocket connection.
12
+ */
13
+ export interface WebSocketConnectParams {
14
+ /**
15
+ * WebSocket URL (ws:// or wss://)
16
+ */
17
+ url: string;
18
+ /**
19
+ * Query parameters to append to the URL.
20
+ * Values are converted to strings; undefined/null values are filtered out.
21
+ */
22
+ params?: Record<string, string | number | boolean | null | undefined>;
23
+ /**
24
+ * If true, skip authentication (don't append token to URL).
25
+ */
26
+ noAuth?: boolean;
27
+ }
28
+ /**
29
+ * Generic WebSocket type that can be either browser WebSocket or Node.js WebSocket.
30
+ * This allows the connector to work in both environments.
31
+ */
32
+ export type GenericWebSocket = WebSocket | {
33
+ readyState: number;
34
+ send(data: string | ArrayBuffer | Blob): void;
35
+ close(code?: number, reason?: string): void;
36
+ onopen: ((ev: Event) => void) | null;
37
+ onmessage: ((ev: MessageEvent) => void) | null;
38
+ onerror: ((ev: Event) => void) | null;
39
+ onclose: ((ev: CloseEvent) => void) | null;
40
+ on?(event: string, handler: () => void): void;
41
+ off?(event: string, handler: () => void): void;
42
+ ping?(): void;
43
+ terminate?(): void;
44
+ };
45
+ /**
46
+ * Interface for establishing WebSocket connections with optional authentication handling.
47
+ *
48
+ * This allows transports to delegate connection establishment to external systems
49
+ * that handle authentication, token refresh, and retry logic (e.g., runSocket in swan-frontend).
50
+ *
51
+ * The connector should:
52
+ * 1. Build the final URL with query parameters
53
+ * 2. Establish the WebSocket connection
54
+ * 3. Set up the provided event handlers
55
+ * 4. Return the WebSocket instance once connected
56
+ * 5. Handle authentication errors (e.g., 4401) and retry with refreshed tokens
57
+ *
58
+ * @param params Connection parameters (URL, query params, auth flag)
59
+ * @param handlers Event handlers to attach to the WebSocket
60
+ * @returns Promise resolving to the connected WebSocket instance
61
+ */
62
+ export type WebSocketConnector = (params: WebSocketConnectParams, handlers: WebSocketHandlers) => Promise<GenericWebSocket>;
63
+ //# sourceMappingURL=WebSocketConnector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebSocketConnector.d.ts","sourceRoot":"","sources":["../../../../src/transport/WebSocketConnector.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC;IAC7B,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,UAAU,KAAK,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACtE;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT;IACE,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,IAAI,CAAC;IAC9C,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC/C,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3C,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC9C,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC/C,IAAI,CAAC,IAAI,IAAI,CAAC;IACd,SAAS,CAAC,IAAI,IAAI,CAAC;CACpB,CAAC;AAEN;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,QAAQ,EAAE,iBAAiB,KACxB,OAAO,CAAC,gBAAgB,CAAC,CAAC"}
@@ -1,5 +1,19 @@
1
1
  import type { Envelope } from "@bian-womp/spark-protocol";
2
2
  import type { Transport, TransportConnectOptions } from "./Transport";
3
+ import type { WebSocketConnector } from "./WebSocketConnector";
4
+ /**
5
+ * WebSocket transport connection options.
6
+ * Allows extensions to pass domain-specific parameters (e.g., flowId).
7
+ */
8
+ export interface WebSocketTransportConnectOptions extends TransportConnectOptions {
9
+ /**
10
+ * Optional WebSocket connector for WebSocketTransport.
11
+ * If provided, WebSocketTransport will use this connector instead of
12
+ * creating WebSocket connections directly. This allows external systems
13
+ * to handle authentication, token refresh, and retry logic.
14
+ */
15
+ connector?: WebSocketConnector;
16
+ }
3
17
  export declare class WebSocketTransport implements Transport {
4
18
  private ws?;
5
19
  private listeners;
@@ -12,10 +26,14 @@ export declare class WebSocketTransport implements Transport {
12
26
  private readonly PONG_TIMEOUT_MS;
13
27
  private onConnectionLost?;
14
28
  private pongHandler?;
29
+ private connector?;
15
30
  constructor(url: string, options?: {
16
31
  onConnectionLost?: () => void;
32
+ connector?: WebSocketConnector;
17
33
  });
18
- connect(options?: TransportConnectOptions): Promise<void>;
34
+ connect(options?: WebSocketTransportConnectOptions): Promise<void>;
35
+ private connectWithConnector;
36
+ private connectDirect;
19
37
  private startHeartbeat;
20
38
  private stopHeartbeat;
21
39
  request<TReq = unknown, TRes = unknown>(msg: Envelope<TReq>): Promise<Envelope<TRes>>;
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketTransport.d.ts","sourceRoot":"","sources":["../../../../src/transport/WebSocketTransport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAQtE,qBAAa,kBAAmB,YAAW,SAAS;IAClD,OAAO,CAAC,EAAE,CAAC,CAAY;IACvB,OAAO,CAAC,SAAS,CAA6C;IAC9D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,GAAG,CAAsB;IAEjC,OAAO,CAAC,YAAY,CAAC,CAAiB;IACtC,OAAO,CAAC,WAAW,CAAC,CAAiB;IACrC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,gBAAgB,CAAC,CAAa;IACtC,OAAO,CAAC,WAAW,CAAC,CAAa;gBAErB,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE;IAK9D,OAAO,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8C/D,OAAO,CAAC,cA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AO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,SAAS,CAAC,CAAqB;gBAGrC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QACR,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;QAC9B,SAAS,CAAC,EAAE,kBAAkB,CAAC;KAChC;IAOG,OAAO,CAAC,OAAO,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC,IAAI,CAAC;YAa1D,oBAAoB;YAkEpB,aAAa;IA+C3B,OAAO,CAAC,cAAc;IAmDtB,OAAO,CAAC,aAAa;IAgBf,OAAO,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO,EAC1C,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,GAClB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAe1B,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI;IAK/C,SAAS,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAKnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAc7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bian-womp/spark-remote",
3
- "version": "0.2.82",
3
+ "version": "0.2.83",
4
4
  "description": "Spark Remote - Remote execution engine for distributed graph processing",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,8 +48,8 @@
48
48
  "typescript": "5.6.3"
49
49
  },
50
50
  "dependencies": {
51
- "@bian-womp/spark-graph": "^0.2.82",
52
- "@bian-womp/spark-protocol": "^0.2.82",
51
+ "@bian-womp/spark-graph": "^0.2.83",
52
+ "@bian-womp/spark-protocol": "^0.2.83",
53
53
  "ws": "^8.18.3"
54
54
  }
55
55
  }