recker 1.0.71 → 1.0.72

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.
@@ -1,5 +1,4 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { WebSocket, type RawData } from 'ws';
3
2
  export interface MockWebSocketServerOptions {
4
3
  port?: number;
5
4
  host?: string;
@@ -13,15 +12,15 @@ export interface MockWebSocketServerOptions {
13
12
  }
14
13
  export interface MockWebSocketClient {
15
14
  id: string;
16
- socket: WebSocket;
15
+ socket: import('ws').WebSocket;
17
16
  connectedAt: number;
18
17
  messageCount: number;
19
- lastMessage?: RawData;
18
+ lastMessage?: import('ws').RawData;
20
19
  metadata: Record<string, any>;
21
20
  }
22
21
  export interface MockWebSocketMessage {
23
22
  clientId: string;
24
- data: RawData;
23
+ data: import('ws').RawData;
25
24
  timestamp: number;
26
25
  isBinary: boolean;
27
26
  }
@@ -1,6 +1,23 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { WebSocketServer, WebSocket } from 'ws';
3
2
  import { createServer } from 'node:http';
3
+ let wsModule = null;
4
+ let WebSocketServer;
5
+ const WS_OPEN = 1;
6
+ async function loadWsModule() {
7
+ if (wsModule)
8
+ return wsModule;
9
+ try {
10
+ wsModule = await import('ws');
11
+ WebSocketServer = wsModule.WebSocketServer;
12
+ return wsModule;
13
+ }
14
+ catch {
15
+ throw new Error('MockWebSocketServer requires the "ws" package. Install it with:\n\n' +
16
+ ' pnpm add ws\n' +
17
+ ' # or\n' +
18
+ ' npm install ws\n');
19
+ }
20
+ }
4
21
  export class MockWebSocketServer extends EventEmitter {
5
22
  options;
6
23
  httpServer = null;
@@ -58,6 +75,7 @@ export class MockWebSocketServer extends EventEmitter {
58
75
  if (this._started) {
59
76
  throw new Error('Server already started');
60
77
  }
78
+ await loadWsModule();
61
79
  return new Promise((resolve, reject) => {
62
80
  this.httpServer = createServer();
63
81
  this.wss = new WebSocketServer({
@@ -152,7 +170,7 @@ export class MockWebSocketServer extends EventEmitter {
152
170
  }
153
171
  send(clientId, data) {
154
172
  const client = this.clients.get(clientId);
155
- if (!client || client.socket.readyState !== WebSocket.OPEN) {
173
+ if (!client || client.socket.readyState !== WS_OPEN) {
156
174
  return false;
157
175
  }
158
176
  const message = typeof data === 'object' && !Buffer.isBuffer(data)
@@ -236,7 +254,7 @@ export class MockWebSocketServer extends EventEmitter {
236
254
  this.emit('connection', client);
237
255
  if (this.options.autoCloseAfter > 0) {
238
256
  setTimeout(() => {
239
- if (socket.readyState === WebSocket.OPEN) {
257
+ if (socket.readyState === WS_OPEN) {
240
258
  socket.close(1000, 'Auto-close timeout');
241
259
  }
242
260
  }, this.options.autoCloseAfter);
@@ -277,7 +295,7 @@ export class MockWebSocketServer extends EventEmitter {
277
295
  await new Promise((resolve) => setTimeout(resolve, this.options.delay));
278
296
  }
279
297
  const response = this.getResponse(data.toString(), client);
280
- if (response !== null && client.socket.readyState === WebSocket.OPEN) {
298
+ if (response !== null && client.socket.readyState === WS_OPEN) {
281
299
  client.socket.send(response);
282
300
  this.stats.totalBytesSent += Buffer.byteLength(response);
283
301
  }
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
- const VERSION = '1.0.71';
1
+ const VERSION = '1.0.72';
2
2
  let _version = null;
3
3
  export async function getVersion() {
4
4
  if (_version)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recker",
3
- "version": "1.0.71",
3
+ "version": "1.0.72",
4
4
  "description": "Multi-Protocol SDK for the AI Era - HTTP, WebSocket, DNS, FTP, SFTP, Telnet, HLS unified with AI providers and MCP tools",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -231,7 +231,8 @@
231
231
  "peerDependencies": {
232
232
  "cardinal": "^2.1.0",
233
233
  "ioredis": "^5.0.0",
234
- "ssh2-sftp-client": "^11.0.0"
234
+ "ssh2-sftp-client": "^11.0.0",
235
+ "ws": "^8.0.0"
235
236
  },
236
237
  "peerDependenciesMeta": {
237
238
  "cardinal": {
@@ -242,6 +243,9 @@
242
243
  },
243
244
  "ssh2-sftp-client": {
244
245
  "optional": true
246
+ },
247
+ "ws": {
248
+ "optional": true
245
249
  }
246
250
  },
247
251
  "devDependencies": {