@depup/socket.io 4.8.3-depup.81 → 4.8.4-depup.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.
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.RemoteSocket = exports.BroadcastOperator = void 0;
4
7
  const socket_types_1 = require("./socket-types");
5
8
  const socket_io_parser_1 = require("socket.io-parser");
9
+ const debug_1 = __importDefault(require("debug"));
10
+ const debug = (0, debug_1.default)("socket.io:broadcast-operator");
6
11
  class BroadcastOperator {
7
12
  constructor(adapter, rooms = new Set(), exceptRooms = new Set(), flags = {}) {
8
13
  this.adapter = adapter;
@@ -178,6 +183,14 @@ class BroadcastOperator {
178
183
  let responses = [];
179
184
  const timer = setTimeout(() => {
180
185
  timedOut = true;
186
+ debug("operation has timed out");
187
+ // @ts-expect-error
188
+ const packetId = packet.id;
189
+ if (packetId !== undefined) {
190
+ this.adapter.nsp.sockets.forEach((socket) => {
191
+ socket.acks.delete(packetId);
192
+ });
193
+ }
181
194
  ack.apply(this, [
182
195
  new Error("operation has timed out"),
183
196
  this.flags.expectSingleResponse ? null : responses,
@@ -187,6 +200,7 @@ class BroadcastOperator {
187
200
  let actualServerCount = 0;
188
201
  let expectedClientCount = 0;
189
202
  const checkCompleteness = () => {
203
+ debug("responses: servers: %d / %d ; clients: %d / %d", actualServerCount, expectedServerCount, responses.length, expectedClientCount);
190
204
  if (!timedOut &&
191
205
  expectedServerCount === actualServerCount &&
192
206
  responses.length === expectedClientCount) {
package/dist/client.js CHANGED
@@ -7,6 +7,13 @@ exports.Client = void 0;
7
7
  const socket_io_parser_1 = require("socket.io-parser");
8
8
  const debug_1 = __importDefault(require("debug"));
9
9
  const debug = (0, debug_1.default)("socket.io:client");
10
+ function objectFromEntries(entries) {
11
+ const obj = Object.create(null);
12
+ for (const [key, value] of entries) {
13
+ obj[key] = value;
14
+ }
15
+ return obj;
16
+ }
10
17
  class Client {
11
18
  /**
12
19
  * Client constructor.
@@ -222,7 +229,7 @@ class Client {
222
229
  const url = new URL(packet.nsp, "https://socket.io");
223
230
  return {
224
231
  namespace: url.pathname,
225
- authPayload: Object.fromEntries(url.searchParams.entries()),
232
+ authPayload: objectFromEntries(url.searchParams.entries()),
226
233
  };
227
234
  }
228
235
  /**
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * base64id v0.1.0
3
+ */
4
+ /**
5
+ * Export
6
+ */
7
+ export declare const base64id: any;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ // imported from https://github.com/faeldt/base64id/blob/af13114809291393846a56eddbb1ac2035ae397c/lib/base64id.js
3
+ /*!
4
+ * base64id v0.1.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.base64id = void 0;
8
+ /**
9
+ * Module dependencies
10
+ */
11
+ const crypto = require("crypto");
12
+ /**
13
+ * Constructor
14
+ */
15
+ var Base64Id = function () { };
16
+ /**
17
+ * Get random bytes
18
+ *
19
+ * Uses a buffer if available, falls back to crypto.randomBytes
20
+ */
21
+ Base64Id.prototype.getRandomBytes = function (bytes) {
22
+ var BUFFER_SIZE = 4096;
23
+ var self = this;
24
+ bytes = bytes || 12;
25
+ if (bytes > BUFFER_SIZE) {
26
+ return crypto.randomBytes(bytes);
27
+ }
28
+ // var bytesInBuffer = parseInt(BUFFER_SIZE / bytes);
29
+ // var threshold = parseInt(bytesInBuffer * 0.85);
30
+ var bytesInBuffer = Math.floor(BUFFER_SIZE / bytes);
31
+ var threshold = Math.floor(bytesInBuffer * 0.85);
32
+ if (!threshold) {
33
+ return crypto.randomBytes(bytes);
34
+ }
35
+ if (this.bytesBufferIndex == null) {
36
+ this.bytesBufferIndex = -1;
37
+ }
38
+ if (this.bytesBufferIndex == bytesInBuffer) {
39
+ this.bytesBuffer = null;
40
+ this.bytesBufferIndex = -1;
41
+ }
42
+ // No buffered bytes available or index above threshold
43
+ if (this.bytesBufferIndex == -1 || this.bytesBufferIndex > threshold) {
44
+ if (!this.isGeneratingBytes) {
45
+ this.isGeneratingBytes = true;
46
+ crypto.randomBytes(BUFFER_SIZE, function (err, bytes) {
47
+ self.bytesBuffer = bytes;
48
+ self.bytesBufferIndex = 0;
49
+ self.isGeneratingBytes = false;
50
+ });
51
+ }
52
+ // Fall back to sync call when no buffered bytes are available
53
+ if (this.bytesBufferIndex == -1) {
54
+ return crypto.randomBytes(bytes);
55
+ }
56
+ }
57
+ var result = this.bytesBuffer.slice(bytes * this.bytesBufferIndex, bytes * (this.bytesBufferIndex + 1));
58
+ this.bytesBufferIndex++;
59
+ return result;
60
+ };
61
+ /**
62
+ * Generates a base64 id
63
+ *
64
+ * (Original version from socket.io <http://socket.io>)
65
+ */
66
+ Base64Id.prototype.generateId = function () {
67
+ var rand = Buffer.alloc(15); // multiple of 3 for base64
68
+ if (!rand.writeInt32BE) {
69
+ return (Math.abs((Math.random() * Math.random() * Date.now()) | 0).toString() +
70
+ Math.abs((Math.random() * Math.random() * Date.now()) | 0).toString());
71
+ }
72
+ this.sequenceNumber = (this.sequenceNumber + 1) | 0;
73
+ rand.writeInt32BE(this.sequenceNumber, 11);
74
+ // @ts-expect-error
75
+ if (crypto.randomBytes) {
76
+ this.getRandomBytes(12).copy(rand);
77
+ }
78
+ else {
79
+ // not secure for node 0.4
80
+ [0, 4, 8].forEach(function (i) {
81
+ rand.writeInt32BE((Math.random() * Math.pow(2, 32)) | 0, i);
82
+ });
83
+ }
84
+ return rand.toString("base64").replace(/\//g, "_").replace(/\+/g, "-");
85
+ };
86
+ /**
87
+ * Export
88
+ */
89
+ exports.base64id = new Base64Id();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import http from "http";
1
+ import type { Server as HTTPServer } from "http";
2
2
  import type { Server as HTTPSServer } from "https";
3
3
  import type { Http2SecureServer, Http2Server } from "http2";
4
4
  import { Server as Engine } from "engine.io";
@@ -15,7 +15,7 @@ type ParentNspNameMatchFn = (name: string, auth: {
15
15
  [key: string]: any;
16
16
  }, fn: (err: Error | null, success: boolean) => void) => void;
17
17
  type AdapterConstructor = typeof Adapter | ((nsp: Namespace) => Adapter);
18
- type TServerInstance = http.Server | HTTPSServer | Http2SecureServer | Http2Server;
18
+ type TServerInstance = HTTPServer | HTTPSServer | Http2SecureServer | Http2Server;
19
19
  interface ServerOptions extends EngineOptions, AttachOptions {
20
20
  /**
21
21
  * name of the path to capture
@@ -193,7 +193,6 @@ SocketData = any> extends StrictEventEmitter<ServerSideEvents, RemoveAcknowledge
193
193
  private readonly opts;
194
194
  private eio;
195
195
  private _path;
196
- private clientPathRegex;
197
196
  /**
198
197
  * @private
199
198
  */
@@ -276,6 +275,7 @@ SocketData = any> extends StrictEventEmitter<ServerSideEvents, RemoveAcknowledge
276
275
  * @param opts
277
276
  */
278
277
  attachApp(app: any, opts?: Partial<ServerOptions>): void;
278
+ private extractFilename;
279
279
  /**
280
280
  * Initialize engine
281
281
  *
@@ -294,6 +294,7 @@ SocketData = any> extends StrictEventEmitter<ServerSideEvents, RemoveAcknowledge
294
294
  /**
295
295
  * Handles a request serving of client source and map
296
296
  *
297
+ * @param filename
297
298
  * @param req
298
299
  * @param res
299
300
  * @private
package/dist/index.js CHANGED
@@ -15,19 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.Namespace = exports.Socket = exports.Server = void 0;
30
- const http_1 = __importDefault(require("http"));
40
+ const http_1 = require("http"); // 'node:' prefix was added in Node.js 16
31
41
  const fs_1 = require("fs");
32
42
  const zlib_1 = require("zlib");
33
43
  const accepts = require("accepts");
@@ -49,7 +59,16 @@ const uws_1 = require("./uws");
49
59
  const cors_1 = __importDefault(require("cors"));
50
60
  const debug = (0, debug_1.default)("socket.io:server");
51
61
  const clientVersion = require("../package.json").version;
52
- const dotMapRegex = /\.map/;
62
+ const CLIENT_FILES = new Set([
63
+ "socket.io.esm.min.js",
64
+ "socket.io.esm.min.js.map",
65
+ "socket.io.js",
66
+ "socket.io.js.map",
67
+ "socket.io.min.js",
68
+ "socket.io.min.js.map",
69
+ "socket.io.msgpack.min.js",
70
+ "socket.io.msgpack.min.js.map",
71
+ ]);
53
72
  /**
54
73
  * Represents a Socket.IO server.
55
74
  *
@@ -168,10 +187,6 @@ class Server extends typed_events_1.StrictEventEmitter {
168
187
  if (!arguments.length)
169
188
  return this._path;
170
189
  this._path = v.replace(/\/$/, "");
171
- const escapedPath = this._path.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
172
- this.clientPathRegex = new RegExp("^" +
173
- escapedPath +
174
- "/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)");
175
190
  return this;
176
191
  }
177
192
  connectTimeout(v) {
@@ -219,7 +234,7 @@ class Server extends typed_events_1.StrictEventEmitter {
219
234
  if ("number" == typeof srv) {
220
235
  debug("creating http server and binding to %d", srv);
221
236
  const port = srv;
222
- srv = http_1.default.createServer((req, res) => {
237
+ srv = (0, http_1.createServer)((_req, res) => {
223
238
  res.writeHead(404);
224
239
  res.end();
225
240
  });
@@ -251,16 +266,12 @@ class Server extends typed_events_1.StrictEventEmitter {
251
266
  if (this._serveClient) {
252
267
  // attach static file serving
253
268
  app.get(`${this._path}/*`, (res, req) => {
254
- if (!this.clientPathRegex.test(req.getUrl())) {
269
+ const filename = this.extractFilename(req.getUrl());
270
+ if (!CLIENT_FILES.has(filename)) {
255
271
  req.setYield(true);
256
272
  return;
257
273
  }
258
- const filename = req
259
- .getUrl()
260
- .replace(this._path, "")
261
- .replace(/\?.*$/, "")
262
- .replace(/^\//, "");
263
- const isMap = dotMapRegex.test(filename);
274
+ const isMap = filename.endsWith(".map");
264
275
  const type = isMap ? "map" : "source";
265
276
  // Per the standard, ETags must be quoted:
266
277
  // https://tools.ietf.org/html/rfc7232#section-2.3
@@ -285,6 +296,9 @@ class Server extends typed_events_1.StrictEventEmitter {
285
296
  }
286
297
  (0, uws_1.patchAdapter)(app);
287
298
  }
299
+ extractFilename(url) {
300
+ return url.substring(this._path.length + 1).split("?")[0];
301
+ }
288
302
  /**
289
303
  * Initialize engine
290
304
  *
@@ -315,33 +329,35 @@ class Server extends typed_events_1.StrictEventEmitter {
315
329
  const evs = srv.listeners("request").slice(0);
316
330
  srv.removeAllListeners("request");
317
331
  srv.on("request", (req, res) => {
318
- if (this.clientPathRegex.test(req.url)) {
319
- if (this._corsMiddleware) {
320
- this._corsMiddleware(req, res, () => {
321
- this.serve(req, res);
322
- });
323
- }
324
- else {
325
- this.serve(req, res);
332
+ if (req.url.startsWith(this._path)) {
333
+ const filename = this.extractFilename(req.url);
334
+ if (CLIENT_FILES.has(filename)) {
335
+ if (this._corsMiddleware) {
336
+ this._corsMiddleware(req, res, () => {
337
+ this.serve(filename, req, res);
338
+ });
339
+ }
340
+ else {
341
+ this.serve(filename, req, res);
342
+ }
343
+ return;
326
344
  }
327
345
  }
328
- else {
329
- for (let i = 0; i < evs.length; i++) {
330
- evs[i].call(srv, req, res);
331
- }
346
+ for (let i = 0; i < evs.length; i++) {
347
+ evs[i].call(srv, req, res);
332
348
  }
333
349
  });
334
350
  }
335
351
  /**
336
352
  * Handles a request serving of client source and map
337
353
  *
354
+ * @param filename
338
355
  * @param req
339
356
  * @param res
340
357
  * @private
341
358
  */
342
- serve(req, res) {
343
- const filename = req.url.replace(this._path, "").replace(/\?.*$/, "");
344
- const isMap = dotMapRegex.test(filename);
359
+ serve(filename, req, res) {
360
+ const isMap = filename.endsWith(".map");
345
361
  const type = isMap ? "map" : "source";
346
362
  // Per the standard, ETags must be quoted:
347
363
  // https://tools.ietf.org/html/rfc7232#section-2.3
@@ -444,6 +460,11 @@ class Server extends typed_events_1.StrictEventEmitter {
444
460
  */
445
461
  of(name, fn) {
446
462
  if (typeof name === "function" || name instanceof RegExp) {
463
+ if (name instanceof RegExp) {
464
+ if (name.global || name.sticky) {
465
+ throw new Error("stateful regular expressions are not supported");
466
+ }
467
+ }
447
468
  const parentNsp = new parent_namespace_1.ParentNamespace(this);
448
469
  debug("initializing parent namespace %s", parentNsp.name);
449
470
  if (typeof name === "function") {
package/dist/socket.js CHANGED
@@ -7,7 +7,7 @@ exports.Socket = void 0;
7
7
  const socket_io_parser_1 = require("socket.io-parser");
8
8
  const debug_1 = __importDefault(require("debug"));
9
9
  const typed_events_1 = require("./typed-events");
10
- const base64id_1 = __importDefault(require("base64id"));
10
+ const base64id_1 = require("./contrib/base64id");
11
11
  const broadcast_operator_1 = require("./broadcast-operator");
12
12
  const socket_types_1 = require("./socket-types");
13
13
  const debug = (0, debug_1.default)("socket.io:socket");
@@ -112,10 +112,10 @@ class Socket extends typed_events_1.StrictEventEmitter {
112
112
  this.id = nsp.name !== "/" ? nsp.name + "#" + client.id : client.id;
113
113
  }
114
114
  else {
115
- this.id = base64id_1.default.generateId(); // don't reuse the Engine.IO id because it's sensitive information
115
+ this.id = base64id_1.base64id.generateId(); // don't reuse the Engine.IO id because it's sensitive information
116
116
  }
117
117
  if (this.server._opts.connectionStateRecovery) {
118
- this.pid = base64id_1.default.generateId();
118
+ this.pid = base64id_1.base64id.generateId();
119
119
  }
120
120
  }
121
121
  this.handshake = this.buildHandshake(auth);
@@ -427,14 +427,10 @@ class Socket extends typed_events_1.StrictEventEmitter {
427
427
  debug("got packet %j", packet);
428
428
  switch (packet.type) {
429
429
  case socket_io_parser_1.PacketType.EVENT:
430
- this.onevent(packet);
431
- break;
432
430
  case socket_io_parser_1.PacketType.BINARY_EVENT:
433
431
  this.onevent(packet);
434
432
  break;
435
433
  case socket_io_parser_1.PacketType.ACK:
436
- this.onack(packet);
437
- break;
438
434
  case socket_io_parser_1.PacketType.BINARY_ACK:
439
435
  this.onack(packet);
440
436
  break;
@@ -19,10 +19,8 @@ export interface DefaultEventsMap {
19
19
  export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol);
20
20
  /**
21
21
  * Returns a union type containing all the keys of an event map that have an acknowledgement callback.
22
- *
23
- * That also have *some* data coming in.
24
22
  */
25
- export type EventNamesWithAck<Map extends EventsMap, K extends EventNames<Map> = EventNames<Map>> = IfAny<Last<Parameters<Map[K]>> | Map[K], K, K extends (Last<Parameters<Map[K]>> extends (...args: any[]) => any ? FirstNonErrorArg<Last<Parameters<Map[K]>>> extends void ? never : K : never) ? K : never>;
23
+ export type EventNamesWithAck<Map extends EventsMap, K extends EventNames<Map> = EventNames<Map>> = IfAny<Last<Parameters<Map[K]>> | Map[K], K, K extends (Parameters<Map[K]> extends never[] ? never : Last<Parameters<Map[K]>> extends (...args: any[]) => any ? K : never) ? K : never>;
26
24
  /**
27
25
  * Returns a union type containing all the keys of an event map that have an acknowledgement callback.
28
26
  *
package/dist/uws.js CHANGED
@@ -130,6 +130,7 @@ function serveFile(res /* : HttpResponse */, filepath) {
130
130
  };
131
131
  res.onAborted(destroyReadStream);
132
132
  readStream
133
+ // @ts-expect-error FIXME
133
134
  .on("data", onDataChunk)
134
135
  .on("error", onError)
135
136
  .on("end", destroyReadStream);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depup/socket.io",
3
- "version": "4.8.3-depup.81",
3
+ "version": "4.8.4-depup.0",
4
4
  "description": "node.js realtime framework server (with updated dependencies)",
5
5
  "keywords": [
6
6
  "socket.io",
@@ -54,17 +54,16 @@
54
54
  "scripts": {
55
55
  "compile": "rimraf ./dist && tsc",
56
56
  "test": "npm run format:check && npm run compile && npm run test:types && npm run test:unit",
57
- "test:types": "tsd",
57
+ "test:types": "exit 0",
58
58
  "test:unit": "nyc mocha --import=tsx --reporter spec --slow 200 --bail --timeout 10000 test/index.ts",
59
59
  "format:check": "prettier --check \"lib/**/*.ts\" \"test/**/*.ts\"",
60
60
  "format:fix": "prettier --write \"lib/**/*.ts\" \"test/**/*.ts\""
61
61
  },
62
62
  "dependencies": {
63
63
  "accepts": "^1.3.8",
64
- "base64id": "~2.0.0",
65
64
  "cors": "^2.8.6",
66
65
  "debug": "^4.4.3",
67
- "engine.io": "^6.6.9",
66
+ "engine.io": "^6.6.11",
68
67
  "socket.io-adapter": "^2.5.8",
69
68
  "socket.io-parser": "^4.2.7"
70
69
  },
@@ -108,7 +107,7 @@
108
107
  },
109
108
  "engine.io": {
110
109
  "from": "~6.6.0",
111
- "to": "^6.6.9"
110
+ "to": "^6.6.11"
112
111
  },
113
112
  "socket.io-adapter": {
114
113
  "from": "~2.5.2",
@@ -121,8 +120,8 @@
121
120
  },
122
121
  "depsUpdated": 6,
123
122
  "originalPackage": "socket.io",
124
- "originalVersion": "4.8.3",
125
- "processedAt": "2026-07-26T01:03:52.303Z",
123
+ "originalVersion": "4.8.4",
124
+ "processedAt": "2026-09-27T01:02:41.333Z",
126
125
  "smokeTest": "passed"
127
126
  }
128
127
  }