@shopify/create-app 3.65.2 → 3.66.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.
Files changed (86) hide show
  1. package/dist/chunk-2RSJVBMF.js +5625 -0
  2. package/dist/{chunk-Z65QJ5D7.js → chunk-4DRC2PSU.js} +17 -30
  3. package/dist/chunk-4OD45DDO.js +31508 -0
  4. package/dist/chunk-522OB3EU.js +45 -0
  5. package/dist/{chunk-JTKTLA7L.js → chunk-5U24TEX5.js} +5434 -10324
  6. package/dist/{chunk-GJPZCXGT.js → chunk-6A7MXLVB.js} +159 -405
  7. package/dist/{chunk-ZYKRTO5P.js → chunk-7ZCQLP5Y.js} +3 -3
  8. package/dist/{chunk-5LBEKXRW.js → chunk-FIJKOZJF.js} +19 -55
  9. package/dist/{chunk-QSKQTKTB.js → chunk-FT6PCF6E.js} +2441 -5551
  10. package/dist/chunk-GIUM5DCQ.js +2144 -0
  11. package/dist/chunk-HIAKHDLR.js +54 -0
  12. package/dist/chunk-LLSRDN3T.js +15352 -0
  13. package/dist/chunk-LTDD2GRL.js +111 -0
  14. package/dist/{chunk-63QVG2CD.js → chunk-NGBYQF44.js} +9 -9
  15. package/dist/chunk-NLC7NBUB.js +80 -0
  16. package/dist/{chunk-FMKVOTQK.js → chunk-O5K4AU7Q.js} +18 -34
  17. package/dist/chunk-OMDEA7TV.js +10615 -0
  18. package/dist/chunk-PNN7RS7Y.js +105 -0
  19. package/dist/{chunk-ZPL24Y2D.js → chunk-POZ5MGPT.js} +13 -18
  20. package/dist/chunk-T7T35H4F.js +108 -0
  21. package/dist/chunk-UBB7JKND.js +55 -0
  22. package/dist/chunk-VSLR7ET4.js +3034 -0
  23. package/dist/{chunk-SAO7C4LP.js → chunk-VZVGAREJ.js} +46821 -101962
  24. package/dist/{chunk-KDNBKIH4.js → chunk-WBQF4CSV.js} +12 -22
  25. package/dist/chunk-XVNW332R.js +524 -0
  26. package/dist/{chunk-YB6D4XQ7.js → chunk-Y4ECGRAF.js} +13 -23
  27. package/dist/chunk-ZAUZQLNO.js +3774 -0
  28. package/dist/chunk-ZULFH3SL.js +1847 -0
  29. package/dist/commands/init.d.ts +0 -1
  30. package/dist/commands/init.js +27 -27
  31. package/dist/commands/init.test.js +51 -70
  32. package/dist/{constants-24TFXZKQ.js → constants-WG7I7G3O.js} +5 -5
  33. package/dist/custom-oclif-loader-JKRJZ56E.js +47 -0
  34. package/dist/del-NW5KFKFP.js +1820 -0
  35. package/dist/devtools-UBOREV57.js +2572 -0
  36. package/dist/error-handler-26SLAJTC.js +35 -0
  37. package/dist/hooks/postrun.js +35 -42
  38. package/dist/hooks/prerun.js +58 -36
  39. package/dist/index.js +7 -7
  40. package/dist/lib-3K5QYF3J.js +9 -0
  41. package/dist/{local-3VUKCW4R.js → local-H6TW5MNX.js} +13 -13
  42. package/dist/magic-string.es-3RXPUXZF.js +843 -0
  43. package/dist/multipart-parser-QKUAJJP5.js +193 -0
  44. package/dist/{node-package-manager-HYZRZNU6.js → node-package-manager-QAUN6HGS.js} +16 -14
  45. package/dist/open-MZGVNFZO.js +197 -0
  46. package/dist/out-KDGAD475.js +6 -0
  47. package/dist/{path-CFPIDSWV.js → path-L375JOQ2.js} +4 -4
  48. package/dist/prompts/init.js +13 -13
  49. package/dist/prompts/init.test.js +42 -59
  50. package/dist/services/init.js +20 -20
  51. package/dist/services/init.test.js +5 -5
  52. package/dist/system-ZI2HKAKO.js +26 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/dist/{ui-7NEDEALP.js → ui-727JEZUX.js} +13 -13
  55. package/dist/utils/template/cleanup.js +13 -13
  56. package/dist/utils/template/cleanup.test.js +18 -30
  57. package/dist/utils/template/npm.js +15 -15
  58. package/dist/utils/template/npm.test.js +48 -87
  59. package/oclif.manifest.json +1 -1
  60. package/package.json +3 -4
  61. package/dist/chunk-3US34ZNP.js +0 -145
  62. package/dist/chunk-3XYIOBQ2.js +0 -22131
  63. package/dist/chunk-6IZMEXPW.js +0 -105
  64. package/dist/chunk-7DRS5WXI.js +0 -7843
  65. package/dist/chunk-DL3MKXVR.js +0 -4754
  66. package/dist/chunk-HDVJ5FPK.js +0 -63
  67. package/dist/chunk-IKO7JBOJ.js +0 -14788
  68. package/dist/chunk-LSCXQWNO.js +0 -822
  69. package/dist/chunk-M2VKB6RG.js +0 -146
  70. package/dist/chunk-MCED27CG.js +0 -5626
  71. package/dist/chunk-SWNRLCC6.js +0 -61
  72. package/dist/chunk-T5LLJYYS.js +0 -195
  73. package/dist/chunk-U5LTJVWL.js +0 -3185
  74. package/dist/chunk-WR7YKB6H.js +0 -44962
  75. package/dist/chunk-YC4FLMDD.js +0 -74
  76. package/dist/chunk-ZRUHMMSQ.js +0 -2477
  77. package/dist/custom-oclif-loader-5KBN3RSN.js +0 -83
  78. package/dist/del-ZCPTGWOA.js +0 -2847
  79. package/dist/devtools-5N4JAP3R.js +0 -3588
  80. package/dist/error-handler-GTW2KSRC.js +0 -35
  81. package/dist/lib-CTSCLPNV.js +0 -9
  82. package/dist/magic-string.es-ATGURXGQ.js +0 -1353
  83. package/dist/multipart-parser-KYOHF24X.js +0 -360
  84. package/dist/open-JRS7RW22.js +0 -291
  85. package/dist/out-OKI3G7I5.js +0 -6
  86. package/dist/system-4S4YXUXZ.js +0 -26
@@ -1,3588 +0,0 @@
1
- import {
2
- __commonJS,
3
- __require,
4
- __toESM,
5
- init_cjs_shims
6
- } from "./chunk-ZPL24Y2D.js";
7
-
8
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/stream.js
9
- var require_stream = __commonJS({
10
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/stream.js"(exports, module) {
11
- "use strict";
12
- init_cjs_shims();
13
- var { Duplex } = __require("stream");
14
- function emitClose(stream) {
15
- stream.emit("close");
16
- }
17
- function duplexOnEnd() {
18
- if (!this.destroyed && this._writableState.finished) {
19
- this.destroy();
20
- }
21
- }
22
- function duplexOnError(err) {
23
- this.removeListener("error", duplexOnError);
24
- this.destroy();
25
- if (this.listenerCount("error") === 0) {
26
- this.emit("error", err);
27
- }
28
- }
29
- function createWebSocketStream2(ws, options) {
30
- let terminateOnDestroy = true;
31
- const duplex = new Duplex({
32
- ...options,
33
- autoDestroy: false,
34
- emitClose: false,
35
- objectMode: false,
36
- writableObjectMode: false
37
- });
38
- ws.on("message", function message(msg, isBinary) {
39
- const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
40
- if (!duplex.push(data))
41
- ws.pause();
42
- });
43
- ws.once("error", function error(err) {
44
- if (duplex.destroyed)
45
- return;
46
- terminateOnDestroy = false;
47
- duplex.destroy(err);
48
- });
49
- ws.once("close", function close() {
50
- if (duplex.destroyed)
51
- return;
52
- duplex.push(null);
53
- });
54
- duplex._destroy = function(err, callback) {
55
- if (ws.readyState === ws.CLOSED) {
56
- callback(err);
57
- process.nextTick(emitClose, duplex);
58
- return;
59
- }
60
- let called = false;
61
- ws.once("error", function error(err2) {
62
- called = true;
63
- callback(err2);
64
- });
65
- ws.once("close", function close() {
66
- if (!called)
67
- callback(err);
68
- process.nextTick(emitClose, duplex);
69
- });
70
- if (terminateOnDestroy)
71
- ws.terminate();
72
- };
73
- duplex._final = function(callback) {
74
- if (ws.readyState === ws.CONNECTING) {
75
- ws.once("open", function open() {
76
- duplex._final(callback);
77
- });
78
- return;
79
- }
80
- if (ws._socket === null)
81
- return;
82
- if (ws._socket._writableState.finished) {
83
- callback();
84
- if (duplex._readableState.endEmitted)
85
- duplex.destroy();
86
- } else {
87
- ws._socket.once("finish", function finish() {
88
- callback();
89
- });
90
- ws.close();
91
- }
92
- };
93
- duplex._read = function() {
94
- if (ws.isPaused)
95
- ws.resume();
96
- };
97
- duplex._write = function(chunk, encoding, callback) {
98
- if (ws.readyState === ws.CONNECTING) {
99
- ws.once("open", function open() {
100
- duplex._write(chunk, encoding, callback);
101
- });
102
- return;
103
- }
104
- ws.send(chunk, callback);
105
- };
106
- duplex.on("end", duplexOnEnd);
107
- duplex.on("error", duplexOnError);
108
- return duplex;
109
- }
110
- module.exports = createWebSocketStream2;
111
- }
112
- });
113
-
114
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/constants.js
115
- var require_constants = __commonJS({
116
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/constants.js"(exports, module) {
117
- "use strict";
118
- init_cjs_shims();
119
- module.exports = {
120
- BINARY_TYPES: ["nodebuffer", "arraybuffer", "fragments"],
121
- EMPTY_BUFFER: Buffer.alloc(0),
122
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
123
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
124
- kListener: Symbol("kListener"),
125
- kStatusCode: Symbol("status-code"),
126
- kWebSocket: Symbol("websocket"),
127
- NOOP: () => {
128
- }
129
- };
130
- }
131
- });
132
-
133
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js
134
- var require_buffer_util = __commonJS({
135
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js"(exports, module) {
136
- "use strict";
137
- init_cjs_shims();
138
- var { EMPTY_BUFFER } = require_constants();
139
- var FastBuffer = Buffer[Symbol.species];
140
- function concat(list, totalLength) {
141
- if (list.length === 0)
142
- return EMPTY_BUFFER;
143
- if (list.length === 1)
144
- return list[0];
145
- const target = Buffer.allocUnsafe(totalLength);
146
- let offset = 0;
147
- for (let i = 0; i < list.length; i++) {
148
- const buf = list[i];
149
- target.set(buf, offset);
150
- offset += buf.length;
151
- }
152
- if (offset < totalLength) {
153
- return new FastBuffer(target.buffer, target.byteOffset, offset);
154
- }
155
- return target;
156
- }
157
- function _mask(source, mask, output, offset, length) {
158
- for (let i = 0; i < length; i++) {
159
- output[offset + i] = source[i] ^ mask[i & 3];
160
- }
161
- }
162
- function _unmask(buffer, mask) {
163
- for (let i = 0; i < buffer.length; i++) {
164
- buffer[i] ^= mask[i & 3];
165
- }
166
- }
167
- function toArrayBuffer(buf) {
168
- if (buf.length === buf.buffer.byteLength) {
169
- return buf.buffer;
170
- }
171
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
172
- }
173
- function toBuffer(data) {
174
- toBuffer.readOnly = true;
175
- if (Buffer.isBuffer(data))
176
- return data;
177
- let buf;
178
- if (data instanceof ArrayBuffer) {
179
- buf = new FastBuffer(data);
180
- } else if (ArrayBuffer.isView(data)) {
181
- buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
182
- } else {
183
- buf = Buffer.from(data);
184
- toBuffer.readOnly = false;
185
- }
186
- return buf;
187
- }
188
- module.exports = {
189
- concat,
190
- mask: _mask,
191
- toArrayBuffer,
192
- toBuffer,
193
- unmask: _unmask
194
- };
195
- if (!process.env.WS_NO_BUFFER_UTIL) {
196
- try {
197
- const bufferUtil = __require("bufferutil");
198
- module.exports.mask = function(source, mask, output, offset, length) {
199
- if (length < 48)
200
- _mask(source, mask, output, offset, length);
201
- else
202
- bufferUtil.mask(source, mask, output, offset, length);
203
- };
204
- module.exports.unmask = function(buffer, mask) {
205
- if (buffer.length < 32)
206
- _unmask(buffer, mask);
207
- else
208
- bufferUtil.unmask(buffer, mask);
209
- };
210
- } catch (e) {
211
- }
212
- }
213
- }
214
- });
215
-
216
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/limiter.js
217
- var require_limiter = __commonJS({
218
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/limiter.js"(exports, module) {
219
- "use strict";
220
- init_cjs_shims();
221
- var kDone = Symbol("kDone");
222
- var kRun = Symbol("kRun");
223
- var Limiter = class {
224
- /**
225
- * Creates a new `Limiter`.
226
- *
227
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
228
- * to run concurrently
229
- */
230
- constructor(concurrency) {
231
- this[kDone] = () => {
232
- this.pending--;
233
- this[kRun]();
234
- };
235
- this.concurrency = concurrency || Infinity;
236
- this.jobs = [];
237
- this.pending = 0;
238
- }
239
- /**
240
- * Adds a job to the queue.
241
- *
242
- * @param {Function} job The job to run
243
- * @public
244
- */
245
- add(job) {
246
- this.jobs.push(job);
247
- this[kRun]();
248
- }
249
- /**
250
- * Removes a job from the queue and runs it if possible.
251
- *
252
- * @private
253
- */
254
- [kRun]() {
255
- if (this.pending === this.concurrency)
256
- return;
257
- if (this.jobs.length) {
258
- const job = this.jobs.shift();
259
- this.pending++;
260
- job(this[kDone]);
261
- }
262
- }
263
- };
264
- module.exports = Limiter;
265
- }
266
- });
267
-
268
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/permessage-deflate.js
269
- var require_permessage_deflate = __commonJS({
270
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
271
- "use strict";
272
- init_cjs_shims();
273
- var zlib = __require("zlib");
274
- var bufferUtil = require_buffer_util();
275
- var Limiter = require_limiter();
276
- var { kStatusCode } = require_constants();
277
- var FastBuffer = Buffer[Symbol.species];
278
- var TRAILER = Buffer.from([0, 0, 255, 255]);
279
- var kPerMessageDeflate = Symbol("permessage-deflate");
280
- var kTotalLength = Symbol("total-length");
281
- var kCallback = Symbol("callback");
282
- var kBuffers = Symbol("buffers");
283
- var kError = Symbol("error");
284
- var zlibLimiter;
285
- var PerMessageDeflate = class {
286
- /**
287
- * Creates a PerMessageDeflate instance.
288
- *
289
- * @param {Object} [options] Configuration options
290
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
291
- * for, or request, a custom client window size
292
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
293
- * acknowledge disabling of client context takeover
294
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
295
- * calls to zlib
296
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
297
- * use of a custom server window size
298
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
299
- * disabling of server context takeover
300
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
301
- * messages should not be compressed if context takeover is disabled
302
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
303
- * deflate
304
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
305
- * inflate
306
- * @param {Boolean} [isServer=false] Create the instance in either server or
307
- * client mode
308
- * @param {Number} [maxPayload=0] The maximum allowed message length
309
- */
310
- constructor(options, isServer, maxPayload) {
311
- this._maxPayload = maxPayload | 0;
312
- this._options = options || {};
313
- this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
314
- this._isServer = !!isServer;
315
- this._deflate = null;
316
- this._inflate = null;
317
- this.params = null;
318
- if (!zlibLimiter) {
319
- const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
320
- zlibLimiter = new Limiter(concurrency);
321
- }
322
- }
323
- /**
324
- * @type {String}
325
- */
326
- static get extensionName() {
327
- return "permessage-deflate";
328
- }
329
- /**
330
- * Create an extension negotiation offer.
331
- *
332
- * @return {Object} Extension parameters
333
- * @public
334
- */
335
- offer() {
336
- const params = {};
337
- if (this._options.serverNoContextTakeover) {
338
- params.server_no_context_takeover = true;
339
- }
340
- if (this._options.clientNoContextTakeover) {
341
- params.client_no_context_takeover = true;
342
- }
343
- if (this._options.serverMaxWindowBits) {
344
- params.server_max_window_bits = this._options.serverMaxWindowBits;
345
- }
346
- if (this._options.clientMaxWindowBits) {
347
- params.client_max_window_bits = this._options.clientMaxWindowBits;
348
- } else if (this._options.clientMaxWindowBits == null) {
349
- params.client_max_window_bits = true;
350
- }
351
- return params;
352
- }
353
- /**
354
- * Accept an extension negotiation offer/response.
355
- *
356
- * @param {Array} configurations The extension negotiation offers/reponse
357
- * @return {Object} Accepted configuration
358
- * @public
359
- */
360
- accept(configurations) {
361
- configurations = this.normalizeParams(configurations);
362
- this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
363
- return this.params;
364
- }
365
- /**
366
- * Releases all resources used by the extension.
367
- *
368
- * @public
369
- */
370
- cleanup() {
371
- if (this._inflate) {
372
- this._inflate.close();
373
- this._inflate = null;
374
- }
375
- if (this._deflate) {
376
- const callback = this._deflate[kCallback];
377
- this._deflate.close();
378
- this._deflate = null;
379
- if (callback) {
380
- callback(
381
- new Error(
382
- "The deflate stream was closed while data was being processed"
383
- )
384
- );
385
- }
386
- }
387
- }
388
- /**
389
- * Accept an extension negotiation offer.
390
- *
391
- * @param {Array} offers The extension negotiation offers
392
- * @return {Object} Accepted configuration
393
- * @private
394
- */
395
- acceptAsServer(offers) {
396
- const opts = this._options;
397
- const accepted = offers.find((params) => {
398
- if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
399
- return false;
400
- }
401
- return true;
402
- });
403
- if (!accepted) {
404
- throw new Error("None of the extension offers can be accepted");
405
- }
406
- if (opts.serverNoContextTakeover) {
407
- accepted.server_no_context_takeover = true;
408
- }
409
- if (opts.clientNoContextTakeover) {
410
- accepted.client_no_context_takeover = true;
411
- }
412
- if (typeof opts.serverMaxWindowBits === "number") {
413
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
414
- }
415
- if (typeof opts.clientMaxWindowBits === "number") {
416
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
417
- } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
418
- delete accepted.client_max_window_bits;
419
- }
420
- return accepted;
421
- }
422
- /**
423
- * Accept the extension negotiation response.
424
- *
425
- * @param {Array} response The extension negotiation response
426
- * @return {Object} Accepted configuration
427
- * @private
428
- */
429
- acceptAsClient(response) {
430
- const params = response[0];
431
- if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
432
- throw new Error('Unexpected parameter "client_no_context_takeover"');
433
- }
434
- if (!params.client_max_window_bits) {
435
- if (typeof this._options.clientMaxWindowBits === "number") {
436
- params.client_max_window_bits = this._options.clientMaxWindowBits;
437
- }
438
- } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
439
- throw new Error(
440
- 'Unexpected or invalid parameter "client_max_window_bits"'
441
- );
442
- }
443
- return params;
444
- }
445
- /**
446
- * Normalize parameters.
447
- *
448
- * @param {Array} configurations The extension negotiation offers/reponse
449
- * @return {Array} The offers/response with normalized parameters
450
- * @private
451
- */
452
- normalizeParams(configurations) {
453
- configurations.forEach((params) => {
454
- Object.keys(params).forEach((key) => {
455
- let value = params[key];
456
- if (value.length > 1) {
457
- throw new Error(`Parameter "${key}" must have only a single value`);
458
- }
459
- value = value[0];
460
- if (key === "client_max_window_bits") {
461
- if (value !== true) {
462
- const num = +value;
463
- if (!Number.isInteger(num) || num < 8 || num > 15) {
464
- throw new TypeError(
465
- `Invalid value for parameter "${key}": ${value}`
466
- );
467
- }
468
- value = num;
469
- } else if (!this._isServer) {
470
- throw new TypeError(
471
- `Invalid value for parameter "${key}": ${value}`
472
- );
473
- }
474
- } else if (key === "server_max_window_bits") {
475
- const num = +value;
476
- if (!Number.isInteger(num) || num < 8 || num > 15) {
477
- throw new TypeError(
478
- `Invalid value for parameter "${key}": ${value}`
479
- );
480
- }
481
- value = num;
482
- } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
483
- if (value !== true) {
484
- throw new TypeError(
485
- `Invalid value for parameter "${key}": ${value}`
486
- );
487
- }
488
- } else {
489
- throw new Error(`Unknown parameter "${key}"`);
490
- }
491
- params[key] = value;
492
- });
493
- });
494
- return configurations;
495
- }
496
- /**
497
- * Decompress data. Concurrency limited.
498
- *
499
- * @param {Buffer} data Compressed data
500
- * @param {Boolean} fin Specifies whether or not this is the last fragment
501
- * @param {Function} callback Callback
502
- * @public
503
- */
504
- decompress(data, fin, callback) {
505
- zlibLimiter.add((done) => {
506
- this._decompress(data, fin, (err, result) => {
507
- done();
508
- callback(err, result);
509
- });
510
- });
511
- }
512
- /**
513
- * Compress data. Concurrency limited.
514
- *
515
- * @param {(Buffer|String)} data Data to compress
516
- * @param {Boolean} fin Specifies whether or not this is the last fragment
517
- * @param {Function} callback Callback
518
- * @public
519
- */
520
- compress(data, fin, callback) {
521
- zlibLimiter.add((done) => {
522
- this._compress(data, fin, (err, result) => {
523
- done();
524
- callback(err, result);
525
- });
526
- });
527
- }
528
- /**
529
- * Decompress data.
530
- *
531
- * @param {Buffer} data Compressed data
532
- * @param {Boolean} fin Specifies whether or not this is the last fragment
533
- * @param {Function} callback Callback
534
- * @private
535
- */
536
- _decompress(data, fin, callback) {
537
- const endpoint = this._isServer ? "client" : "server";
538
- if (!this._inflate) {
539
- const key = `${endpoint}_max_window_bits`;
540
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
541
- this._inflate = zlib.createInflateRaw({
542
- ...this._options.zlibInflateOptions,
543
- windowBits
544
- });
545
- this._inflate[kPerMessageDeflate] = this;
546
- this._inflate[kTotalLength] = 0;
547
- this._inflate[kBuffers] = [];
548
- this._inflate.on("error", inflateOnError);
549
- this._inflate.on("data", inflateOnData);
550
- }
551
- this._inflate[kCallback] = callback;
552
- this._inflate.write(data);
553
- if (fin)
554
- this._inflate.write(TRAILER);
555
- this._inflate.flush(() => {
556
- const err = this._inflate[kError];
557
- if (err) {
558
- this._inflate.close();
559
- this._inflate = null;
560
- callback(err);
561
- return;
562
- }
563
- const data2 = bufferUtil.concat(
564
- this._inflate[kBuffers],
565
- this._inflate[kTotalLength]
566
- );
567
- if (this._inflate._readableState.endEmitted) {
568
- this._inflate.close();
569
- this._inflate = null;
570
- } else {
571
- this._inflate[kTotalLength] = 0;
572
- this._inflate[kBuffers] = [];
573
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
574
- this._inflate.reset();
575
- }
576
- }
577
- callback(null, data2);
578
- });
579
- }
580
- /**
581
- * Compress data.
582
- *
583
- * @param {(Buffer|String)} data Data to compress
584
- * @param {Boolean} fin Specifies whether or not this is the last fragment
585
- * @param {Function} callback Callback
586
- * @private
587
- */
588
- _compress(data, fin, callback) {
589
- const endpoint = this._isServer ? "server" : "client";
590
- if (!this._deflate) {
591
- const key = `${endpoint}_max_window_bits`;
592
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
593
- this._deflate = zlib.createDeflateRaw({
594
- ...this._options.zlibDeflateOptions,
595
- windowBits
596
- });
597
- this._deflate[kTotalLength] = 0;
598
- this._deflate[kBuffers] = [];
599
- this._deflate.on("data", deflateOnData);
600
- }
601
- this._deflate[kCallback] = callback;
602
- this._deflate.write(data);
603
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
604
- if (!this._deflate) {
605
- return;
606
- }
607
- let data2 = bufferUtil.concat(
608
- this._deflate[kBuffers],
609
- this._deflate[kTotalLength]
610
- );
611
- if (fin) {
612
- data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
613
- }
614
- this._deflate[kCallback] = null;
615
- this._deflate[kTotalLength] = 0;
616
- this._deflate[kBuffers] = [];
617
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
618
- this._deflate.reset();
619
- }
620
- callback(null, data2);
621
- });
622
- }
623
- };
624
- module.exports = PerMessageDeflate;
625
- function deflateOnData(chunk) {
626
- this[kBuffers].push(chunk);
627
- this[kTotalLength] += chunk.length;
628
- }
629
- function inflateOnData(chunk) {
630
- this[kTotalLength] += chunk.length;
631
- if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
632
- this[kBuffers].push(chunk);
633
- return;
634
- }
635
- this[kError] = new RangeError("Max payload size exceeded");
636
- this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
637
- this[kError][kStatusCode] = 1009;
638
- this.removeListener("data", inflateOnData);
639
- this.reset();
640
- }
641
- function inflateOnError(err) {
642
- this[kPerMessageDeflate]._inflate = null;
643
- err[kStatusCode] = 1007;
644
- this[kCallback](err);
645
- }
646
- }
647
- });
648
-
649
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js
650
- var require_validation = __commonJS({
651
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js"(exports, module) {
652
- "use strict";
653
- init_cjs_shims();
654
- var { isUtf8 } = __require("buffer");
655
- var tokenChars = [
656
- 0,
657
- 0,
658
- 0,
659
- 0,
660
- 0,
661
- 0,
662
- 0,
663
- 0,
664
- 0,
665
- 0,
666
- 0,
667
- 0,
668
- 0,
669
- 0,
670
- 0,
671
- 0,
672
- // 0 - 15
673
- 0,
674
- 0,
675
- 0,
676
- 0,
677
- 0,
678
- 0,
679
- 0,
680
- 0,
681
- 0,
682
- 0,
683
- 0,
684
- 0,
685
- 0,
686
- 0,
687
- 0,
688
- 0,
689
- // 16 - 31
690
- 0,
691
- 1,
692
- 0,
693
- 1,
694
- 1,
695
- 1,
696
- 1,
697
- 1,
698
- 0,
699
- 0,
700
- 1,
701
- 1,
702
- 0,
703
- 1,
704
- 1,
705
- 0,
706
- // 32 - 47
707
- 1,
708
- 1,
709
- 1,
710
- 1,
711
- 1,
712
- 1,
713
- 1,
714
- 1,
715
- 1,
716
- 1,
717
- 0,
718
- 0,
719
- 0,
720
- 0,
721
- 0,
722
- 0,
723
- // 48 - 63
724
- 0,
725
- 1,
726
- 1,
727
- 1,
728
- 1,
729
- 1,
730
- 1,
731
- 1,
732
- 1,
733
- 1,
734
- 1,
735
- 1,
736
- 1,
737
- 1,
738
- 1,
739
- 1,
740
- // 64 - 79
741
- 1,
742
- 1,
743
- 1,
744
- 1,
745
- 1,
746
- 1,
747
- 1,
748
- 1,
749
- 1,
750
- 1,
751
- 1,
752
- 0,
753
- 0,
754
- 0,
755
- 1,
756
- 1,
757
- // 80 - 95
758
- 1,
759
- 1,
760
- 1,
761
- 1,
762
- 1,
763
- 1,
764
- 1,
765
- 1,
766
- 1,
767
- 1,
768
- 1,
769
- 1,
770
- 1,
771
- 1,
772
- 1,
773
- 1,
774
- // 96 - 111
775
- 1,
776
- 1,
777
- 1,
778
- 1,
779
- 1,
780
- 1,
781
- 1,
782
- 1,
783
- 1,
784
- 1,
785
- 1,
786
- 0,
787
- 1,
788
- 0,
789
- 1,
790
- 0
791
- // 112 - 127
792
- ];
793
- function isValidStatusCode(code) {
794
- return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
795
- }
796
- function _isValidUTF8(buf) {
797
- const len = buf.length;
798
- let i = 0;
799
- while (i < len) {
800
- if ((buf[i] & 128) === 0) {
801
- i++;
802
- } else if ((buf[i] & 224) === 192) {
803
- if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
804
- return false;
805
- }
806
- i += 2;
807
- } else if ((buf[i] & 240) === 224) {
808
- if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
809
- buf[i] === 237 && (buf[i + 1] & 224) === 160) {
810
- return false;
811
- }
812
- i += 3;
813
- } else if ((buf[i] & 248) === 240) {
814
- if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
815
- buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
816
- return false;
817
- }
818
- i += 4;
819
- } else {
820
- return false;
821
- }
822
- }
823
- return true;
824
- }
825
- module.exports = {
826
- isValidStatusCode,
827
- isValidUTF8: _isValidUTF8,
828
- tokenChars
829
- };
830
- if (isUtf8) {
831
- module.exports.isValidUTF8 = function(buf) {
832
- return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
833
- };
834
- } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
835
- try {
836
- const isValidUTF8 = __require("utf-8-validate");
837
- module.exports.isValidUTF8 = function(buf) {
838
- return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
839
- };
840
- } catch (e) {
841
- }
842
- }
843
- }
844
- });
845
-
846
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js
847
- var require_receiver = __commonJS({
848
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js"(exports, module) {
849
- "use strict";
850
- init_cjs_shims();
851
- var { Writable } = __require("stream");
852
- var PerMessageDeflate = require_permessage_deflate();
853
- var {
854
- BINARY_TYPES,
855
- EMPTY_BUFFER,
856
- kStatusCode,
857
- kWebSocket
858
- } = require_constants();
859
- var { concat, toArrayBuffer, unmask } = require_buffer_util();
860
- var { isValidStatusCode, isValidUTF8 } = require_validation();
861
- var FastBuffer = Buffer[Symbol.species];
862
- var GET_INFO = 0;
863
- var GET_PAYLOAD_LENGTH_16 = 1;
864
- var GET_PAYLOAD_LENGTH_64 = 2;
865
- var GET_MASK = 3;
866
- var GET_DATA = 4;
867
- var INFLATING = 5;
868
- var Receiver2 = class extends Writable {
869
- /**
870
- * Creates a Receiver instance.
871
- *
872
- * @param {Object} [options] Options object
873
- * @param {String} [options.binaryType=nodebuffer] The type for binary data
874
- * @param {Object} [options.extensions] An object containing the negotiated
875
- * extensions
876
- * @param {Boolean} [options.isServer=false] Specifies whether to operate in
877
- * client or server mode
878
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
879
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
880
- * not to skip UTF-8 validation for text and close messages
881
- */
882
- constructor(options = {}) {
883
- super();
884
- this._binaryType = options.binaryType || BINARY_TYPES[0];
885
- this._extensions = options.extensions || {};
886
- this._isServer = !!options.isServer;
887
- this._maxPayload = options.maxPayload | 0;
888
- this._skipUTF8Validation = !!options.skipUTF8Validation;
889
- this[kWebSocket] = void 0;
890
- this._bufferedBytes = 0;
891
- this._buffers = [];
892
- this._compressed = false;
893
- this._payloadLength = 0;
894
- this._mask = void 0;
895
- this._fragmented = 0;
896
- this._masked = false;
897
- this._fin = false;
898
- this._opcode = 0;
899
- this._totalPayloadLength = 0;
900
- this._messageLength = 0;
901
- this._fragments = [];
902
- this._state = GET_INFO;
903
- this._loop = false;
904
- }
905
- /**
906
- * Implements `Writable.prototype._write()`.
907
- *
908
- * @param {Buffer} chunk The chunk of data to write
909
- * @param {String} encoding The character encoding of `chunk`
910
- * @param {Function} cb Callback
911
- * @private
912
- */
913
- _write(chunk, encoding, cb) {
914
- if (this._opcode === 8 && this._state == GET_INFO)
915
- return cb();
916
- this._bufferedBytes += chunk.length;
917
- this._buffers.push(chunk);
918
- this.startLoop(cb);
919
- }
920
- /**
921
- * Consumes `n` bytes from the buffered data.
922
- *
923
- * @param {Number} n The number of bytes to consume
924
- * @return {Buffer} The consumed bytes
925
- * @private
926
- */
927
- consume(n) {
928
- this._bufferedBytes -= n;
929
- if (n === this._buffers[0].length)
930
- return this._buffers.shift();
931
- if (n < this._buffers[0].length) {
932
- const buf = this._buffers[0];
933
- this._buffers[0] = new FastBuffer(
934
- buf.buffer,
935
- buf.byteOffset + n,
936
- buf.length - n
937
- );
938
- return new FastBuffer(buf.buffer, buf.byteOffset, n);
939
- }
940
- const dst = Buffer.allocUnsafe(n);
941
- do {
942
- const buf = this._buffers[0];
943
- const offset = dst.length - n;
944
- if (n >= buf.length) {
945
- dst.set(this._buffers.shift(), offset);
946
- } else {
947
- dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
948
- this._buffers[0] = new FastBuffer(
949
- buf.buffer,
950
- buf.byteOffset + n,
951
- buf.length - n
952
- );
953
- }
954
- n -= buf.length;
955
- } while (n > 0);
956
- return dst;
957
- }
958
- /**
959
- * Starts the parsing loop.
960
- *
961
- * @param {Function} cb Callback
962
- * @private
963
- */
964
- startLoop(cb) {
965
- let err;
966
- this._loop = true;
967
- do {
968
- switch (this._state) {
969
- case GET_INFO:
970
- err = this.getInfo();
971
- break;
972
- case GET_PAYLOAD_LENGTH_16:
973
- err = this.getPayloadLength16();
974
- break;
975
- case GET_PAYLOAD_LENGTH_64:
976
- err = this.getPayloadLength64();
977
- break;
978
- case GET_MASK:
979
- this.getMask();
980
- break;
981
- case GET_DATA:
982
- err = this.getData(cb);
983
- break;
984
- default:
985
- this._loop = false;
986
- return;
987
- }
988
- } while (this._loop);
989
- cb(err);
990
- }
991
- /**
992
- * Reads the first two bytes of a frame.
993
- *
994
- * @return {(RangeError|undefined)} A possible error
995
- * @private
996
- */
997
- getInfo() {
998
- if (this._bufferedBytes < 2) {
999
- this._loop = false;
1000
- return;
1001
- }
1002
- const buf = this.consume(2);
1003
- if ((buf[0] & 48) !== 0) {
1004
- this._loop = false;
1005
- return error(
1006
- RangeError,
1007
- "RSV2 and RSV3 must be clear",
1008
- true,
1009
- 1002,
1010
- "WS_ERR_UNEXPECTED_RSV_2_3"
1011
- );
1012
- }
1013
- const compressed = (buf[0] & 64) === 64;
1014
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1015
- this._loop = false;
1016
- return error(
1017
- RangeError,
1018
- "RSV1 must be clear",
1019
- true,
1020
- 1002,
1021
- "WS_ERR_UNEXPECTED_RSV_1"
1022
- );
1023
- }
1024
- this._fin = (buf[0] & 128) === 128;
1025
- this._opcode = buf[0] & 15;
1026
- this._payloadLength = buf[1] & 127;
1027
- if (this._opcode === 0) {
1028
- if (compressed) {
1029
- this._loop = false;
1030
- return error(
1031
- RangeError,
1032
- "RSV1 must be clear",
1033
- true,
1034
- 1002,
1035
- "WS_ERR_UNEXPECTED_RSV_1"
1036
- );
1037
- }
1038
- if (!this._fragmented) {
1039
- this._loop = false;
1040
- return error(
1041
- RangeError,
1042
- "invalid opcode 0",
1043
- true,
1044
- 1002,
1045
- "WS_ERR_INVALID_OPCODE"
1046
- );
1047
- }
1048
- this._opcode = this._fragmented;
1049
- } else if (this._opcode === 1 || this._opcode === 2) {
1050
- if (this._fragmented) {
1051
- this._loop = false;
1052
- return error(
1053
- RangeError,
1054
- `invalid opcode ${this._opcode}`,
1055
- true,
1056
- 1002,
1057
- "WS_ERR_INVALID_OPCODE"
1058
- );
1059
- }
1060
- this._compressed = compressed;
1061
- } else if (this._opcode > 7 && this._opcode < 11) {
1062
- if (!this._fin) {
1063
- this._loop = false;
1064
- return error(
1065
- RangeError,
1066
- "FIN must be set",
1067
- true,
1068
- 1002,
1069
- "WS_ERR_EXPECTED_FIN"
1070
- );
1071
- }
1072
- if (compressed) {
1073
- this._loop = false;
1074
- return error(
1075
- RangeError,
1076
- "RSV1 must be clear",
1077
- true,
1078
- 1002,
1079
- "WS_ERR_UNEXPECTED_RSV_1"
1080
- );
1081
- }
1082
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1083
- this._loop = false;
1084
- return error(
1085
- RangeError,
1086
- `invalid payload length ${this._payloadLength}`,
1087
- true,
1088
- 1002,
1089
- "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
1090
- );
1091
- }
1092
- } else {
1093
- this._loop = false;
1094
- return error(
1095
- RangeError,
1096
- `invalid opcode ${this._opcode}`,
1097
- true,
1098
- 1002,
1099
- "WS_ERR_INVALID_OPCODE"
1100
- );
1101
- }
1102
- if (!this._fin && !this._fragmented)
1103
- this._fragmented = this._opcode;
1104
- this._masked = (buf[1] & 128) === 128;
1105
- if (this._isServer) {
1106
- if (!this._masked) {
1107
- this._loop = false;
1108
- return error(
1109
- RangeError,
1110
- "MASK must be set",
1111
- true,
1112
- 1002,
1113
- "WS_ERR_EXPECTED_MASK"
1114
- );
1115
- }
1116
- } else if (this._masked) {
1117
- this._loop = false;
1118
- return error(
1119
- RangeError,
1120
- "MASK must be clear",
1121
- true,
1122
- 1002,
1123
- "WS_ERR_UNEXPECTED_MASK"
1124
- );
1125
- }
1126
- if (this._payloadLength === 126)
1127
- this._state = GET_PAYLOAD_LENGTH_16;
1128
- else if (this._payloadLength === 127)
1129
- this._state = GET_PAYLOAD_LENGTH_64;
1130
- else
1131
- return this.haveLength();
1132
- }
1133
- /**
1134
- * Gets extended payload length (7+16).
1135
- *
1136
- * @return {(RangeError|undefined)} A possible error
1137
- * @private
1138
- */
1139
- getPayloadLength16() {
1140
- if (this._bufferedBytes < 2) {
1141
- this._loop = false;
1142
- return;
1143
- }
1144
- this._payloadLength = this.consume(2).readUInt16BE(0);
1145
- return this.haveLength();
1146
- }
1147
- /**
1148
- * Gets extended payload length (7+64).
1149
- *
1150
- * @return {(RangeError|undefined)} A possible error
1151
- * @private
1152
- */
1153
- getPayloadLength64() {
1154
- if (this._bufferedBytes < 8) {
1155
- this._loop = false;
1156
- return;
1157
- }
1158
- const buf = this.consume(8);
1159
- const num = buf.readUInt32BE(0);
1160
- if (num > Math.pow(2, 53 - 32) - 1) {
1161
- this._loop = false;
1162
- return error(
1163
- RangeError,
1164
- "Unsupported WebSocket frame: payload length > 2^53 - 1",
1165
- false,
1166
- 1009,
1167
- "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1168
- );
1169
- }
1170
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1171
- return this.haveLength();
1172
- }
1173
- /**
1174
- * Payload length has been read.
1175
- *
1176
- * @return {(RangeError|undefined)} A possible error
1177
- * @private
1178
- */
1179
- haveLength() {
1180
- if (this._payloadLength && this._opcode < 8) {
1181
- this._totalPayloadLength += this._payloadLength;
1182
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1183
- this._loop = false;
1184
- return error(
1185
- RangeError,
1186
- "Max payload size exceeded",
1187
- false,
1188
- 1009,
1189
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1190
- );
1191
- }
1192
- }
1193
- if (this._masked)
1194
- this._state = GET_MASK;
1195
- else
1196
- this._state = GET_DATA;
1197
- }
1198
- /**
1199
- * Reads mask bytes.
1200
- *
1201
- * @private
1202
- */
1203
- getMask() {
1204
- if (this._bufferedBytes < 4) {
1205
- this._loop = false;
1206
- return;
1207
- }
1208
- this._mask = this.consume(4);
1209
- this._state = GET_DATA;
1210
- }
1211
- /**
1212
- * Reads data bytes.
1213
- *
1214
- * @param {Function} cb Callback
1215
- * @return {(Error|RangeError|undefined)} A possible error
1216
- * @private
1217
- */
1218
- getData(cb) {
1219
- let data = EMPTY_BUFFER;
1220
- if (this._payloadLength) {
1221
- if (this._bufferedBytes < this._payloadLength) {
1222
- this._loop = false;
1223
- return;
1224
- }
1225
- data = this.consume(this._payloadLength);
1226
- if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1227
- unmask(data, this._mask);
1228
- }
1229
- }
1230
- if (this._opcode > 7)
1231
- return this.controlMessage(data);
1232
- if (this._compressed) {
1233
- this._state = INFLATING;
1234
- this.decompress(data, cb);
1235
- return;
1236
- }
1237
- if (data.length) {
1238
- this._messageLength = this._totalPayloadLength;
1239
- this._fragments.push(data);
1240
- }
1241
- return this.dataMessage();
1242
- }
1243
- /**
1244
- * Decompresses data.
1245
- *
1246
- * @param {Buffer} data Compressed data
1247
- * @param {Function} cb Callback
1248
- * @private
1249
- */
1250
- decompress(data, cb) {
1251
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1252
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1253
- if (err)
1254
- return cb(err);
1255
- if (buf.length) {
1256
- this._messageLength += buf.length;
1257
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1258
- return cb(
1259
- error(
1260
- RangeError,
1261
- "Max payload size exceeded",
1262
- false,
1263
- 1009,
1264
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1265
- )
1266
- );
1267
- }
1268
- this._fragments.push(buf);
1269
- }
1270
- const er = this.dataMessage();
1271
- if (er)
1272
- return cb(er);
1273
- this.startLoop(cb);
1274
- });
1275
- }
1276
- /**
1277
- * Handles a data message.
1278
- *
1279
- * @return {(Error|undefined)} A possible error
1280
- * @private
1281
- */
1282
- dataMessage() {
1283
- if (this._fin) {
1284
- const messageLength = this._messageLength;
1285
- const fragments = this._fragments;
1286
- this._totalPayloadLength = 0;
1287
- this._messageLength = 0;
1288
- this._fragmented = 0;
1289
- this._fragments = [];
1290
- if (this._opcode === 2) {
1291
- let data;
1292
- if (this._binaryType === "nodebuffer") {
1293
- data = concat(fragments, messageLength);
1294
- } else if (this._binaryType === "arraybuffer") {
1295
- data = toArrayBuffer(concat(fragments, messageLength));
1296
- } else {
1297
- data = fragments;
1298
- }
1299
- this.emit("message", data, true);
1300
- } else {
1301
- const buf = concat(fragments, messageLength);
1302
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1303
- this._loop = false;
1304
- return error(
1305
- Error,
1306
- "invalid UTF-8 sequence",
1307
- true,
1308
- 1007,
1309
- "WS_ERR_INVALID_UTF8"
1310
- );
1311
- }
1312
- this.emit("message", buf, false);
1313
- }
1314
- }
1315
- this._state = GET_INFO;
1316
- }
1317
- /**
1318
- * Handles a control message.
1319
- *
1320
- * @param {Buffer} data Data to handle
1321
- * @return {(Error|RangeError|undefined)} A possible error
1322
- * @private
1323
- */
1324
- controlMessage(data) {
1325
- if (this._opcode === 8) {
1326
- this._loop = false;
1327
- if (data.length === 0) {
1328
- this.emit("conclude", 1005, EMPTY_BUFFER);
1329
- this.end();
1330
- } else {
1331
- const code = data.readUInt16BE(0);
1332
- if (!isValidStatusCode(code)) {
1333
- return error(
1334
- RangeError,
1335
- `invalid status code ${code}`,
1336
- true,
1337
- 1002,
1338
- "WS_ERR_INVALID_CLOSE_CODE"
1339
- );
1340
- }
1341
- const buf = new FastBuffer(
1342
- data.buffer,
1343
- data.byteOffset + 2,
1344
- data.length - 2
1345
- );
1346
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1347
- return error(
1348
- Error,
1349
- "invalid UTF-8 sequence",
1350
- true,
1351
- 1007,
1352
- "WS_ERR_INVALID_UTF8"
1353
- );
1354
- }
1355
- this.emit("conclude", code, buf);
1356
- this.end();
1357
- }
1358
- } else if (this._opcode === 9) {
1359
- this.emit("ping", data);
1360
- } else {
1361
- this.emit("pong", data);
1362
- }
1363
- this._state = GET_INFO;
1364
- }
1365
- };
1366
- module.exports = Receiver2;
1367
- function error(ErrorCtor, message, prefix, statusCode, errorCode) {
1368
- const err = new ErrorCtor(
1369
- prefix ? `Invalid WebSocket frame: ${message}` : message
1370
- );
1371
- Error.captureStackTrace(err, error);
1372
- err.code = errorCode;
1373
- err[kStatusCode] = statusCode;
1374
- return err;
1375
- }
1376
- }
1377
- });
1378
-
1379
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/sender.js
1380
- var require_sender = __commonJS({
1381
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/sender.js"(exports, module) {
1382
- "use strict";
1383
- init_cjs_shims();
1384
- var net = __require("net");
1385
- var tls = __require("tls");
1386
- var { randomFillSync } = __require("crypto");
1387
- var PerMessageDeflate = require_permessage_deflate();
1388
- var { EMPTY_BUFFER } = require_constants();
1389
- var { isValidStatusCode } = require_validation();
1390
- var { mask: applyMask, toBuffer } = require_buffer_util();
1391
- var kByteLength = Symbol("kByteLength");
1392
- var maskBuffer = Buffer.alloc(4);
1393
- var Sender2 = class _Sender {
1394
- /**
1395
- * Creates a Sender instance.
1396
- *
1397
- * @param {(net.Socket|tls.Socket)} socket The connection socket
1398
- * @param {Object} [extensions] An object containing the negotiated extensions
1399
- * @param {Function} [generateMask] The function used to generate the masking
1400
- * key
1401
- */
1402
- constructor(socket, extensions, generateMask) {
1403
- this._extensions = extensions || {};
1404
- if (generateMask) {
1405
- this._generateMask = generateMask;
1406
- this._maskBuffer = Buffer.alloc(4);
1407
- }
1408
- this._socket = socket;
1409
- this._firstFragment = true;
1410
- this._compress = false;
1411
- this._bufferedBytes = 0;
1412
- this._deflating = false;
1413
- this._queue = [];
1414
- }
1415
- /**
1416
- * Frames a piece of data according to the HyBi WebSocket protocol.
1417
- *
1418
- * @param {(Buffer|String)} data The data to frame
1419
- * @param {Object} options Options object
1420
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1421
- * FIN bit
1422
- * @param {Function} [options.generateMask] The function used to generate the
1423
- * masking key
1424
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1425
- * `data`
1426
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1427
- * key
1428
- * @param {Number} options.opcode The opcode
1429
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1430
- * modified
1431
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1432
- * RSV1 bit
1433
- * @return {(Buffer|String)[]} The framed data
1434
- * @public
1435
- */
1436
- static frame(data, options) {
1437
- let mask;
1438
- let merge = false;
1439
- let offset = 2;
1440
- let skipMasking = false;
1441
- if (options.mask) {
1442
- mask = options.maskBuffer || maskBuffer;
1443
- if (options.generateMask) {
1444
- options.generateMask(mask);
1445
- } else {
1446
- randomFillSync(mask, 0, 4);
1447
- }
1448
- skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1449
- offset = 6;
1450
- }
1451
- let dataLength;
1452
- if (typeof data === "string") {
1453
- if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1454
- dataLength = options[kByteLength];
1455
- } else {
1456
- data = Buffer.from(data);
1457
- dataLength = data.length;
1458
- }
1459
- } else {
1460
- dataLength = data.length;
1461
- merge = options.mask && options.readOnly && !skipMasking;
1462
- }
1463
- let payloadLength = dataLength;
1464
- if (dataLength >= 65536) {
1465
- offset += 8;
1466
- payloadLength = 127;
1467
- } else if (dataLength > 125) {
1468
- offset += 2;
1469
- payloadLength = 126;
1470
- }
1471
- const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1472
- target[0] = options.fin ? options.opcode | 128 : options.opcode;
1473
- if (options.rsv1)
1474
- target[0] |= 64;
1475
- target[1] = payloadLength;
1476
- if (payloadLength === 126) {
1477
- target.writeUInt16BE(dataLength, 2);
1478
- } else if (payloadLength === 127) {
1479
- target[2] = target[3] = 0;
1480
- target.writeUIntBE(dataLength, 4, 6);
1481
- }
1482
- if (!options.mask)
1483
- return [target, data];
1484
- target[1] |= 128;
1485
- target[offset - 4] = mask[0];
1486
- target[offset - 3] = mask[1];
1487
- target[offset - 2] = mask[2];
1488
- target[offset - 1] = mask[3];
1489
- if (skipMasking)
1490
- return [target, data];
1491
- if (merge) {
1492
- applyMask(data, mask, target, offset, dataLength);
1493
- return [target];
1494
- }
1495
- applyMask(data, mask, data, 0, dataLength);
1496
- return [target, data];
1497
- }
1498
- /**
1499
- * Sends a close message to the other peer.
1500
- *
1501
- * @param {Number} [code] The status code component of the body
1502
- * @param {(String|Buffer)} [data] The message component of the body
1503
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1504
- * @param {Function} [cb] Callback
1505
- * @public
1506
- */
1507
- close(code, data, mask, cb) {
1508
- let buf;
1509
- if (code === void 0) {
1510
- buf = EMPTY_BUFFER;
1511
- } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1512
- throw new TypeError("First argument must be a valid error code number");
1513
- } else if (data === void 0 || !data.length) {
1514
- buf = Buffer.allocUnsafe(2);
1515
- buf.writeUInt16BE(code, 0);
1516
- } else {
1517
- const length = Buffer.byteLength(data);
1518
- if (length > 123) {
1519
- throw new RangeError("The message must not be greater than 123 bytes");
1520
- }
1521
- buf = Buffer.allocUnsafe(2 + length);
1522
- buf.writeUInt16BE(code, 0);
1523
- if (typeof data === "string") {
1524
- buf.write(data, 2);
1525
- } else {
1526
- buf.set(data, 2);
1527
- }
1528
- }
1529
- const options = {
1530
- [kByteLength]: buf.length,
1531
- fin: true,
1532
- generateMask: this._generateMask,
1533
- mask,
1534
- maskBuffer: this._maskBuffer,
1535
- opcode: 8,
1536
- readOnly: false,
1537
- rsv1: false
1538
- };
1539
- if (this._deflating) {
1540
- this.enqueue([this.dispatch, buf, false, options, cb]);
1541
- } else {
1542
- this.sendFrame(_Sender.frame(buf, options), cb);
1543
- }
1544
- }
1545
- /**
1546
- * Sends a ping message to the other peer.
1547
- *
1548
- * @param {*} data The message to send
1549
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1550
- * @param {Function} [cb] Callback
1551
- * @public
1552
- */
1553
- ping(data, mask, cb) {
1554
- let byteLength;
1555
- let readOnly;
1556
- if (typeof data === "string") {
1557
- byteLength = Buffer.byteLength(data);
1558
- readOnly = false;
1559
- } else {
1560
- data = toBuffer(data);
1561
- byteLength = data.length;
1562
- readOnly = toBuffer.readOnly;
1563
- }
1564
- if (byteLength > 125) {
1565
- throw new RangeError("The data size must not be greater than 125 bytes");
1566
- }
1567
- const options = {
1568
- [kByteLength]: byteLength,
1569
- fin: true,
1570
- generateMask: this._generateMask,
1571
- mask,
1572
- maskBuffer: this._maskBuffer,
1573
- opcode: 9,
1574
- readOnly,
1575
- rsv1: false
1576
- };
1577
- if (this._deflating) {
1578
- this.enqueue([this.dispatch, data, false, options, cb]);
1579
- } else {
1580
- this.sendFrame(_Sender.frame(data, options), cb);
1581
- }
1582
- }
1583
- /**
1584
- * Sends a pong message to the other peer.
1585
- *
1586
- * @param {*} data The message to send
1587
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1588
- * @param {Function} [cb] Callback
1589
- * @public
1590
- */
1591
- pong(data, mask, cb) {
1592
- let byteLength;
1593
- let readOnly;
1594
- if (typeof data === "string") {
1595
- byteLength = Buffer.byteLength(data);
1596
- readOnly = false;
1597
- } else {
1598
- data = toBuffer(data);
1599
- byteLength = data.length;
1600
- readOnly = toBuffer.readOnly;
1601
- }
1602
- if (byteLength > 125) {
1603
- throw new RangeError("The data size must not be greater than 125 bytes");
1604
- }
1605
- const options = {
1606
- [kByteLength]: byteLength,
1607
- fin: true,
1608
- generateMask: this._generateMask,
1609
- mask,
1610
- maskBuffer: this._maskBuffer,
1611
- opcode: 10,
1612
- readOnly,
1613
- rsv1: false
1614
- };
1615
- if (this._deflating) {
1616
- this.enqueue([this.dispatch, data, false, options, cb]);
1617
- } else {
1618
- this.sendFrame(_Sender.frame(data, options), cb);
1619
- }
1620
- }
1621
- /**
1622
- * Sends a data message to the other peer.
1623
- *
1624
- * @param {*} data The message to send
1625
- * @param {Object} options Options object
1626
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1627
- * or text
1628
- * @param {Boolean} [options.compress=false] Specifies whether or not to
1629
- * compress `data`
1630
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1631
- * last one
1632
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1633
- * `data`
1634
- * @param {Function} [cb] Callback
1635
- * @public
1636
- */
1637
- send(data, options, cb) {
1638
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1639
- let opcode = options.binary ? 2 : 1;
1640
- let rsv1 = options.compress;
1641
- let byteLength;
1642
- let readOnly;
1643
- if (typeof data === "string") {
1644
- byteLength = Buffer.byteLength(data);
1645
- readOnly = false;
1646
- } else {
1647
- data = toBuffer(data);
1648
- byteLength = data.length;
1649
- readOnly = toBuffer.readOnly;
1650
- }
1651
- if (this._firstFragment) {
1652
- this._firstFragment = false;
1653
- if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1654
- rsv1 = byteLength >= perMessageDeflate._threshold;
1655
- }
1656
- this._compress = rsv1;
1657
- } else {
1658
- rsv1 = false;
1659
- opcode = 0;
1660
- }
1661
- if (options.fin)
1662
- this._firstFragment = true;
1663
- if (perMessageDeflate) {
1664
- const opts = {
1665
- [kByteLength]: byteLength,
1666
- fin: options.fin,
1667
- generateMask: this._generateMask,
1668
- mask: options.mask,
1669
- maskBuffer: this._maskBuffer,
1670
- opcode,
1671
- readOnly,
1672
- rsv1
1673
- };
1674
- if (this._deflating) {
1675
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1676
- } else {
1677
- this.dispatch(data, this._compress, opts, cb);
1678
- }
1679
- } else {
1680
- this.sendFrame(
1681
- _Sender.frame(data, {
1682
- [kByteLength]: byteLength,
1683
- fin: options.fin,
1684
- generateMask: this._generateMask,
1685
- mask: options.mask,
1686
- maskBuffer: this._maskBuffer,
1687
- opcode,
1688
- readOnly,
1689
- rsv1: false
1690
- }),
1691
- cb
1692
- );
1693
- }
1694
- }
1695
- /**
1696
- * Dispatches a message.
1697
- *
1698
- * @param {(Buffer|String)} data The message to send
1699
- * @param {Boolean} [compress=false] Specifies whether or not to compress
1700
- * `data`
1701
- * @param {Object} options Options object
1702
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1703
- * FIN bit
1704
- * @param {Function} [options.generateMask] The function used to generate the
1705
- * masking key
1706
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1707
- * `data`
1708
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1709
- * key
1710
- * @param {Number} options.opcode The opcode
1711
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1712
- * modified
1713
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1714
- * RSV1 bit
1715
- * @param {Function} [cb] Callback
1716
- * @private
1717
- */
1718
- dispatch(data, compress, options, cb) {
1719
- if (!compress) {
1720
- this.sendFrame(_Sender.frame(data, options), cb);
1721
- return;
1722
- }
1723
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1724
- this._bufferedBytes += options[kByteLength];
1725
- this._deflating = true;
1726
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
1727
- if (this._socket.destroyed) {
1728
- const err = new Error(
1729
- "The socket was closed while data was being compressed"
1730
- );
1731
- if (typeof cb === "function")
1732
- cb(err);
1733
- for (let i = 0; i < this._queue.length; i++) {
1734
- const params = this._queue[i];
1735
- const callback = params[params.length - 1];
1736
- if (typeof callback === "function")
1737
- callback(err);
1738
- }
1739
- return;
1740
- }
1741
- this._bufferedBytes -= options[kByteLength];
1742
- this._deflating = false;
1743
- options.readOnly = false;
1744
- this.sendFrame(_Sender.frame(buf, options), cb);
1745
- this.dequeue();
1746
- });
1747
- }
1748
- /**
1749
- * Executes queued send operations.
1750
- *
1751
- * @private
1752
- */
1753
- dequeue() {
1754
- while (!this._deflating && this._queue.length) {
1755
- const params = this._queue.shift();
1756
- this._bufferedBytes -= params[3][kByteLength];
1757
- Reflect.apply(params[0], this, params.slice(1));
1758
- }
1759
- }
1760
- /**
1761
- * Enqueues a send operation.
1762
- *
1763
- * @param {Array} params Send operation parameters.
1764
- * @private
1765
- */
1766
- enqueue(params) {
1767
- this._bufferedBytes += params[3][kByteLength];
1768
- this._queue.push(params);
1769
- }
1770
- /**
1771
- * Sends a frame.
1772
- *
1773
- * @param {Buffer[]} list The frame to send
1774
- * @param {Function} [cb] Callback
1775
- * @private
1776
- */
1777
- sendFrame(list, cb) {
1778
- if (list.length === 2) {
1779
- this._socket.cork();
1780
- this._socket.write(list[0]);
1781
- this._socket.write(list[1], cb);
1782
- this._socket.uncork();
1783
- } else {
1784
- this._socket.write(list[0], cb);
1785
- }
1786
- }
1787
- };
1788
- module.exports = Sender2;
1789
- }
1790
- });
1791
-
1792
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/event-target.js
1793
- var require_event_target = __commonJS({
1794
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/event-target.js"(exports, module) {
1795
- "use strict";
1796
- init_cjs_shims();
1797
- var { kForOnEventAttribute, kListener } = require_constants();
1798
- var kCode = Symbol("kCode");
1799
- var kData = Symbol("kData");
1800
- var kError = Symbol("kError");
1801
- var kMessage = Symbol("kMessage");
1802
- var kReason = Symbol("kReason");
1803
- var kTarget = Symbol("kTarget");
1804
- var kType = Symbol("kType");
1805
- var kWasClean = Symbol("kWasClean");
1806
- var Event = class {
1807
- /**
1808
- * Create a new `Event`.
1809
- *
1810
- * @param {String} type The name of the event
1811
- * @throws {TypeError} If the `type` argument is not specified
1812
- */
1813
- constructor(type) {
1814
- this[kTarget] = null;
1815
- this[kType] = type;
1816
- }
1817
- /**
1818
- * @type {*}
1819
- */
1820
- get target() {
1821
- return this[kTarget];
1822
- }
1823
- /**
1824
- * @type {String}
1825
- */
1826
- get type() {
1827
- return this[kType];
1828
- }
1829
- };
1830
- Object.defineProperty(Event.prototype, "target", { enumerable: true });
1831
- Object.defineProperty(Event.prototype, "type", { enumerable: true });
1832
- var CloseEvent = class extends Event {
1833
- /**
1834
- * Create a new `CloseEvent`.
1835
- *
1836
- * @param {String} type The name of the event
1837
- * @param {Object} [options] A dictionary object that allows for setting
1838
- * attributes via object members of the same name
1839
- * @param {Number} [options.code=0] The status code explaining why the
1840
- * connection was closed
1841
- * @param {String} [options.reason=''] A human-readable string explaining why
1842
- * the connection was closed
1843
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1844
- * connection was cleanly closed
1845
- */
1846
- constructor(type, options = {}) {
1847
- super(type);
1848
- this[kCode] = options.code === void 0 ? 0 : options.code;
1849
- this[kReason] = options.reason === void 0 ? "" : options.reason;
1850
- this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
1851
- }
1852
- /**
1853
- * @type {Number}
1854
- */
1855
- get code() {
1856
- return this[kCode];
1857
- }
1858
- /**
1859
- * @type {String}
1860
- */
1861
- get reason() {
1862
- return this[kReason];
1863
- }
1864
- /**
1865
- * @type {Boolean}
1866
- */
1867
- get wasClean() {
1868
- return this[kWasClean];
1869
- }
1870
- };
1871
- Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1872
- Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1873
- Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1874
- var ErrorEvent = class extends Event {
1875
- /**
1876
- * Create a new `ErrorEvent`.
1877
- *
1878
- * @param {String} type The name of the event
1879
- * @param {Object} [options] A dictionary object that allows for setting
1880
- * attributes via object members of the same name
1881
- * @param {*} [options.error=null] The error that generated this event
1882
- * @param {String} [options.message=''] The error message
1883
- */
1884
- constructor(type, options = {}) {
1885
- super(type);
1886
- this[kError] = options.error === void 0 ? null : options.error;
1887
- this[kMessage] = options.message === void 0 ? "" : options.message;
1888
- }
1889
- /**
1890
- * @type {*}
1891
- */
1892
- get error() {
1893
- return this[kError];
1894
- }
1895
- /**
1896
- * @type {String}
1897
- */
1898
- get message() {
1899
- return this[kMessage];
1900
- }
1901
- };
1902
- Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1903
- Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1904
- var MessageEvent = class extends Event {
1905
- /**
1906
- * Create a new `MessageEvent`.
1907
- *
1908
- * @param {String} type The name of the event
1909
- * @param {Object} [options] A dictionary object that allows for setting
1910
- * attributes via object members of the same name
1911
- * @param {*} [options.data=null] The message content
1912
- */
1913
- constructor(type, options = {}) {
1914
- super(type);
1915
- this[kData] = options.data === void 0 ? null : options.data;
1916
- }
1917
- /**
1918
- * @type {*}
1919
- */
1920
- get data() {
1921
- return this[kData];
1922
- }
1923
- };
1924
- Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1925
- var EventTarget = {
1926
- /**
1927
- * Register an event listener.
1928
- *
1929
- * @param {String} type A string representing the event type to listen for
1930
- * @param {(Function|Object)} handler The listener to add
1931
- * @param {Object} [options] An options object specifies characteristics about
1932
- * the event listener
1933
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1934
- * listener should be invoked at most once after being added. If `true`,
1935
- * the listener would be automatically removed when invoked.
1936
- * @public
1937
- */
1938
- addEventListener(type, handler, options = {}) {
1939
- for (const listener of this.listeners(type)) {
1940
- if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1941
- return;
1942
- }
1943
- }
1944
- let wrapper;
1945
- if (type === "message") {
1946
- wrapper = function onMessage(data, isBinary) {
1947
- const event = new MessageEvent("message", {
1948
- data: isBinary ? data : data.toString()
1949
- });
1950
- event[kTarget] = this;
1951
- callListener(handler, this, event);
1952
- };
1953
- } else if (type === "close") {
1954
- wrapper = function onClose(code, message) {
1955
- const event = new CloseEvent("close", {
1956
- code,
1957
- reason: message.toString(),
1958
- wasClean: this._closeFrameReceived && this._closeFrameSent
1959
- });
1960
- event[kTarget] = this;
1961
- callListener(handler, this, event);
1962
- };
1963
- } else if (type === "error") {
1964
- wrapper = function onError(error) {
1965
- const event = new ErrorEvent("error", {
1966
- error,
1967
- message: error.message
1968
- });
1969
- event[kTarget] = this;
1970
- callListener(handler, this, event);
1971
- };
1972
- } else if (type === "open") {
1973
- wrapper = function onOpen() {
1974
- const event = new Event("open");
1975
- event[kTarget] = this;
1976
- callListener(handler, this, event);
1977
- };
1978
- } else {
1979
- return;
1980
- }
1981
- wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
1982
- wrapper[kListener] = handler;
1983
- if (options.once) {
1984
- this.once(type, wrapper);
1985
- } else {
1986
- this.on(type, wrapper);
1987
- }
1988
- },
1989
- /**
1990
- * Remove an event listener.
1991
- *
1992
- * @param {String} type A string representing the event type to remove
1993
- * @param {(Function|Object)} handler The listener to remove
1994
- * @public
1995
- */
1996
- removeEventListener(type, handler) {
1997
- for (const listener of this.listeners(type)) {
1998
- if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1999
- this.removeListener(type, listener);
2000
- break;
2001
- }
2002
- }
2003
- }
2004
- };
2005
- module.exports = {
2006
- CloseEvent,
2007
- ErrorEvent,
2008
- Event,
2009
- EventTarget,
2010
- MessageEvent
2011
- };
2012
- function callListener(listener, thisArg, event) {
2013
- if (typeof listener === "object" && listener.handleEvent) {
2014
- listener.handleEvent.call(listener, event);
2015
- } else {
2016
- listener.call(thisArg, event);
2017
- }
2018
- }
2019
- }
2020
- });
2021
-
2022
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/extension.js
2023
- var require_extension = __commonJS({
2024
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/extension.js"(exports, module) {
2025
- "use strict";
2026
- init_cjs_shims();
2027
- var { tokenChars } = require_validation();
2028
- function push(dest, name, elem) {
2029
- if (dest[name] === void 0)
2030
- dest[name] = [elem];
2031
- else
2032
- dest[name].push(elem);
2033
- }
2034
- function parse(header) {
2035
- const offers = /* @__PURE__ */ Object.create(null);
2036
- let params = /* @__PURE__ */ Object.create(null);
2037
- let mustUnescape = false;
2038
- let isEscaping = false;
2039
- let inQuotes = false;
2040
- let extensionName;
2041
- let paramName;
2042
- let start = -1;
2043
- let code = -1;
2044
- let end = -1;
2045
- let i = 0;
2046
- for (; i < header.length; i++) {
2047
- code = header.charCodeAt(i);
2048
- if (extensionName === void 0) {
2049
- if (end === -1 && tokenChars[code] === 1) {
2050
- if (start === -1)
2051
- start = i;
2052
- } else if (i !== 0 && (code === 32 || code === 9)) {
2053
- if (end === -1 && start !== -1)
2054
- end = i;
2055
- } else if (code === 59 || code === 44) {
2056
- if (start === -1) {
2057
- throw new SyntaxError(`Unexpected character at index ${i}`);
2058
- }
2059
- if (end === -1)
2060
- end = i;
2061
- const name = header.slice(start, end);
2062
- if (code === 44) {
2063
- push(offers, name, params);
2064
- params = /* @__PURE__ */ Object.create(null);
2065
- } else {
2066
- extensionName = name;
2067
- }
2068
- start = end = -1;
2069
- } else {
2070
- throw new SyntaxError(`Unexpected character at index ${i}`);
2071
- }
2072
- } else if (paramName === void 0) {
2073
- if (end === -1 && tokenChars[code] === 1) {
2074
- if (start === -1)
2075
- start = i;
2076
- } else if (code === 32 || code === 9) {
2077
- if (end === -1 && start !== -1)
2078
- end = i;
2079
- } else if (code === 59 || code === 44) {
2080
- if (start === -1) {
2081
- throw new SyntaxError(`Unexpected character at index ${i}`);
2082
- }
2083
- if (end === -1)
2084
- end = i;
2085
- push(params, header.slice(start, end), true);
2086
- if (code === 44) {
2087
- push(offers, extensionName, params);
2088
- params = /* @__PURE__ */ Object.create(null);
2089
- extensionName = void 0;
2090
- }
2091
- start = end = -1;
2092
- } else if (code === 61 && start !== -1 && end === -1) {
2093
- paramName = header.slice(start, i);
2094
- start = end = -1;
2095
- } else {
2096
- throw new SyntaxError(`Unexpected character at index ${i}`);
2097
- }
2098
- } else {
2099
- if (isEscaping) {
2100
- if (tokenChars[code] !== 1) {
2101
- throw new SyntaxError(`Unexpected character at index ${i}`);
2102
- }
2103
- if (start === -1)
2104
- start = i;
2105
- else if (!mustUnescape)
2106
- mustUnescape = true;
2107
- isEscaping = false;
2108
- } else if (inQuotes) {
2109
- if (tokenChars[code] === 1) {
2110
- if (start === -1)
2111
- start = i;
2112
- } else if (code === 34 && start !== -1) {
2113
- inQuotes = false;
2114
- end = i;
2115
- } else if (code === 92) {
2116
- isEscaping = true;
2117
- } else {
2118
- throw new SyntaxError(`Unexpected character at index ${i}`);
2119
- }
2120
- } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2121
- inQuotes = true;
2122
- } else if (end === -1 && tokenChars[code] === 1) {
2123
- if (start === -1)
2124
- start = i;
2125
- } else if (start !== -1 && (code === 32 || code === 9)) {
2126
- if (end === -1)
2127
- end = i;
2128
- } else if (code === 59 || code === 44) {
2129
- if (start === -1) {
2130
- throw new SyntaxError(`Unexpected character at index ${i}`);
2131
- }
2132
- if (end === -1)
2133
- end = i;
2134
- let value = header.slice(start, end);
2135
- if (mustUnescape) {
2136
- value = value.replace(/\\/g, "");
2137
- mustUnescape = false;
2138
- }
2139
- push(params, paramName, value);
2140
- if (code === 44) {
2141
- push(offers, extensionName, params);
2142
- params = /* @__PURE__ */ Object.create(null);
2143
- extensionName = void 0;
2144
- }
2145
- paramName = void 0;
2146
- start = end = -1;
2147
- } else {
2148
- throw new SyntaxError(`Unexpected character at index ${i}`);
2149
- }
2150
- }
2151
- }
2152
- if (start === -1 || inQuotes || code === 32 || code === 9) {
2153
- throw new SyntaxError("Unexpected end of input");
2154
- }
2155
- if (end === -1)
2156
- end = i;
2157
- const token = header.slice(start, end);
2158
- if (extensionName === void 0) {
2159
- push(offers, token, params);
2160
- } else {
2161
- if (paramName === void 0) {
2162
- push(params, token, true);
2163
- } else if (mustUnescape) {
2164
- push(params, paramName, token.replace(/\\/g, ""));
2165
- } else {
2166
- push(params, paramName, token);
2167
- }
2168
- push(offers, extensionName, params);
2169
- }
2170
- return offers;
2171
- }
2172
- function format(extensions) {
2173
- return Object.keys(extensions).map((extension) => {
2174
- let configurations = extensions[extension];
2175
- if (!Array.isArray(configurations))
2176
- configurations = [configurations];
2177
- return configurations.map((params) => {
2178
- return [extension].concat(
2179
- Object.keys(params).map((k) => {
2180
- let values = params[k];
2181
- if (!Array.isArray(values))
2182
- values = [values];
2183
- return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2184
- })
2185
- ).join("; ");
2186
- }).join(", ");
2187
- }).join(", ");
2188
- }
2189
- module.exports = { format, parse };
2190
- }
2191
- });
2192
-
2193
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/websocket.js
2194
- var require_websocket = __commonJS({
2195
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/websocket.js"(exports, module) {
2196
- "use strict";
2197
- init_cjs_shims();
2198
- var EventEmitter = __require("events");
2199
- var https = __require("https");
2200
- var http = __require("http");
2201
- var net = __require("net");
2202
- var tls = __require("tls");
2203
- var { randomBytes, createHash } = __require("crypto");
2204
- var { Readable } = __require("stream");
2205
- var { URL } = __require("url");
2206
- var PerMessageDeflate = require_permessage_deflate();
2207
- var Receiver2 = require_receiver();
2208
- var Sender2 = require_sender();
2209
- var {
2210
- BINARY_TYPES,
2211
- EMPTY_BUFFER,
2212
- GUID,
2213
- kForOnEventAttribute,
2214
- kListener,
2215
- kStatusCode,
2216
- kWebSocket,
2217
- NOOP
2218
- } = require_constants();
2219
- var {
2220
- EventTarget: { addEventListener, removeEventListener }
2221
- } = require_event_target();
2222
- var { format, parse } = require_extension();
2223
- var { toBuffer } = require_buffer_util();
2224
- var closeTimeout = 30 * 1e3;
2225
- var kAborted = Symbol("kAborted");
2226
- var protocolVersions = [8, 13];
2227
- var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2228
- var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2229
- var WebSocket2 = class _WebSocket extends EventEmitter {
2230
- /**
2231
- * Create a new `WebSocket`.
2232
- *
2233
- * @param {(String|URL)} address The URL to which to connect
2234
- * @param {(String|String[])} [protocols] The subprotocols
2235
- * @param {Object} [options] Connection options
2236
- */
2237
- constructor(address, protocols, options) {
2238
- super();
2239
- this._binaryType = BINARY_TYPES[0];
2240
- this._closeCode = 1006;
2241
- this._closeFrameReceived = false;
2242
- this._closeFrameSent = false;
2243
- this._closeMessage = EMPTY_BUFFER;
2244
- this._closeTimer = null;
2245
- this._extensions = {};
2246
- this._paused = false;
2247
- this._protocol = "";
2248
- this._readyState = _WebSocket.CONNECTING;
2249
- this._receiver = null;
2250
- this._sender = null;
2251
- this._socket = null;
2252
- if (address !== null) {
2253
- this._bufferedAmount = 0;
2254
- this._isServer = false;
2255
- this._redirects = 0;
2256
- if (protocols === void 0) {
2257
- protocols = [];
2258
- } else if (!Array.isArray(protocols)) {
2259
- if (typeof protocols === "object" && protocols !== null) {
2260
- options = protocols;
2261
- protocols = [];
2262
- } else {
2263
- protocols = [protocols];
2264
- }
2265
- }
2266
- initAsClient(this, address, protocols, options);
2267
- } else {
2268
- this._isServer = true;
2269
- }
2270
- }
2271
- /**
2272
- * This deviates from the WHATWG interface since ws doesn't support the
2273
- * required default "blob" type (instead we define a custom "nodebuffer"
2274
- * type).
2275
- *
2276
- * @type {String}
2277
- */
2278
- get binaryType() {
2279
- return this._binaryType;
2280
- }
2281
- set binaryType(type) {
2282
- if (!BINARY_TYPES.includes(type))
2283
- return;
2284
- this._binaryType = type;
2285
- if (this._receiver)
2286
- this._receiver._binaryType = type;
2287
- }
2288
- /**
2289
- * @type {Number}
2290
- */
2291
- get bufferedAmount() {
2292
- if (!this._socket)
2293
- return this._bufferedAmount;
2294
- return this._socket._writableState.length + this._sender._bufferedBytes;
2295
- }
2296
- /**
2297
- * @type {String}
2298
- */
2299
- get extensions() {
2300
- return Object.keys(this._extensions).join();
2301
- }
2302
- /**
2303
- * @type {Boolean}
2304
- */
2305
- get isPaused() {
2306
- return this._paused;
2307
- }
2308
- /**
2309
- * @type {Function}
2310
- */
2311
- /* istanbul ignore next */
2312
- get onclose() {
2313
- return null;
2314
- }
2315
- /**
2316
- * @type {Function}
2317
- */
2318
- /* istanbul ignore next */
2319
- get onerror() {
2320
- return null;
2321
- }
2322
- /**
2323
- * @type {Function}
2324
- */
2325
- /* istanbul ignore next */
2326
- get onopen() {
2327
- return null;
2328
- }
2329
- /**
2330
- * @type {Function}
2331
- */
2332
- /* istanbul ignore next */
2333
- get onmessage() {
2334
- return null;
2335
- }
2336
- /**
2337
- * @type {String}
2338
- */
2339
- get protocol() {
2340
- return this._protocol;
2341
- }
2342
- /**
2343
- * @type {Number}
2344
- */
2345
- get readyState() {
2346
- return this._readyState;
2347
- }
2348
- /**
2349
- * @type {String}
2350
- */
2351
- get url() {
2352
- return this._url;
2353
- }
2354
- /**
2355
- * Set up the socket and the internal resources.
2356
- *
2357
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2358
- * server and client
2359
- * @param {Buffer} head The first packet of the upgraded stream
2360
- * @param {Object} options Options object
2361
- * @param {Function} [options.generateMask] The function used to generate the
2362
- * masking key
2363
- * @param {Number} [options.maxPayload=0] The maximum allowed message size
2364
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2365
- * not to skip UTF-8 validation for text and close messages
2366
- * @private
2367
- */
2368
- setSocket(socket, head, options) {
2369
- const receiver = new Receiver2({
2370
- binaryType: this.binaryType,
2371
- extensions: this._extensions,
2372
- isServer: this._isServer,
2373
- maxPayload: options.maxPayload,
2374
- skipUTF8Validation: options.skipUTF8Validation
2375
- });
2376
- this._sender = new Sender2(socket, this._extensions, options.generateMask);
2377
- this._receiver = receiver;
2378
- this._socket = socket;
2379
- receiver[kWebSocket] = this;
2380
- socket[kWebSocket] = this;
2381
- receiver.on("conclude", receiverOnConclude);
2382
- receiver.on("drain", receiverOnDrain);
2383
- receiver.on("error", receiverOnError);
2384
- receiver.on("message", receiverOnMessage);
2385
- receiver.on("ping", receiverOnPing);
2386
- receiver.on("pong", receiverOnPong);
2387
- socket.setTimeout(0);
2388
- socket.setNoDelay();
2389
- if (head.length > 0)
2390
- socket.unshift(head);
2391
- socket.on("close", socketOnClose);
2392
- socket.on("data", socketOnData);
2393
- socket.on("end", socketOnEnd);
2394
- socket.on("error", socketOnError);
2395
- this._readyState = _WebSocket.OPEN;
2396
- this.emit("open");
2397
- }
2398
- /**
2399
- * Emit the `'close'` event.
2400
- *
2401
- * @private
2402
- */
2403
- emitClose() {
2404
- if (!this._socket) {
2405
- this._readyState = _WebSocket.CLOSED;
2406
- this.emit("close", this._closeCode, this._closeMessage);
2407
- return;
2408
- }
2409
- if (this._extensions[PerMessageDeflate.extensionName]) {
2410
- this._extensions[PerMessageDeflate.extensionName].cleanup();
2411
- }
2412
- this._receiver.removeAllListeners();
2413
- this._readyState = _WebSocket.CLOSED;
2414
- this.emit("close", this._closeCode, this._closeMessage);
2415
- }
2416
- /**
2417
- * Start a closing handshake.
2418
- *
2419
- * +----------+ +-----------+ +----------+
2420
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2421
- * | +----------+ +-----------+ +----------+ |
2422
- * +----------+ +-----------+ |
2423
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2424
- * +----------+ +-----------+ |
2425
- * | | | +---+ |
2426
- * +------------------------+-->|fin| - - - -
2427
- * | +---+ | +---+
2428
- * - - - - -|fin|<---------------------+
2429
- * +---+
2430
- *
2431
- * @param {Number} [code] Status code explaining why the connection is closing
2432
- * @param {(String|Buffer)} [data] The reason why the connection is
2433
- * closing
2434
- * @public
2435
- */
2436
- close(code, data) {
2437
- if (this.readyState === _WebSocket.CLOSED)
2438
- return;
2439
- if (this.readyState === _WebSocket.CONNECTING) {
2440
- const msg = "WebSocket was closed before the connection was established";
2441
- abortHandshake(this, this._req, msg);
2442
- return;
2443
- }
2444
- if (this.readyState === _WebSocket.CLOSING) {
2445
- if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2446
- this._socket.end();
2447
- }
2448
- return;
2449
- }
2450
- this._readyState = _WebSocket.CLOSING;
2451
- this._sender.close(code, data, !this._isServer, (err) => {
2452
- if (err)
2453
- return;
2454
- this._closeFrameSent = true;
2455
- if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2456
- this._socket.end();
2457
- }
2458
- });
2459
- this._closeTimer = setTimeout(
2460
- this._socket.destroy.bind(this._socket),
2461
- closeTimeout
2462
- );
2463
- }
2464
- /**
2465
- * Pause the socket.
2466
- *
2467
- * @public
2468
- */
2469
- pause() {
2470
- if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2471
- return;
2472
- }
2473
- this._paused = true;
2474
- this._socket.pause();
2475
- }
2476
- /**
2477
- * Send a ping.
2478
- *
2479
- * @param {*} [data] The data to send
2480
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
2481
- * @param {Function} [cb] Callback which is executed when the ping is sent
2482
- * @public
2483
- */
2484
- ping(data, mask, cb) {
2485
- if (this.readyState === _WebSocket.CONNECTING) {
2486
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2487
- }
2488
- if (typeof data === "function") {
2489
- cb = data;
2490
- data = mask = void 0;
2491
- } else if (typeof mask === "function") {
2492
- cb = mask;
2493
- mask = void 0;
2494
- }
2495
- if (typeof data === "number")
2496
- data = data.toString();
2497
- if (this.readyState !== _WebSocket.OPEN) {
2498
- sendAfterClose(this, data, cb);
2499
- return;
2500
- }
2501
- if (mask === void 0)
2502
- mask = !this._isServer;
2503
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2504
- }
2505
- /**
2506
- * Send a pong.
2507
- *
2508
- * @param {*} [data] The data to send
2509
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
2510
- * @param {Function} [cb] Callback which is executed when the pong is sent
2511
- * @public
2512
- */
2513
- pong(data, mask, cb) {
2514
- if (this.readyState === _WebSocket.CONNECTING) {
2515
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2516
- }
2517
- if (typeof data === "function") {
2518
- cb = data;
2519
- data = mask = void 0;
2520
- } else if (typeof mask === "function") {
2521
- cb = mask;
2522
- mask = void 0;
2523
- }
2524
- if (typeof data === "number")
2525
- data = data.toString();
2526
- if (this.readyState !== _WebSocket.OPEN) {
2527
- sendAfterClose(this, data, cb);
2528
- return;
2529
- }
2530
- if (mask === void 0)
2531
- mask = !this._isServer;
2532
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2533
- }
2534
- /**
2535
- * Resume the socket.
2536
- *
2537
- * @public
2538
- */
2539
- resume() {
2540
- if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2541
- return;
2542
- }
2543
- this._paused = false;
2544
- if (!this._receiver._writableState.needDrain)
2545
- this._socket.resume();
2546
- }
2547
- /**
2548
- * Send a data message.
2549
- *
2550
- * @param {*} data The message to send
2551
- * @param {Object} [options] Options object
2552
- * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2553
- * text
2554
- * @param {Boolean} [options.compress] Specifies whether or not to compress
2555
- * `data`
2556
- * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2557
- * last one
2558
- * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2559
- * @param {Function} [cb] Callback which is executed when data is written out
2560
- * @public
2561
- */
2562
- send(data, options, cb) {
2563
- if (this.readyState === _WebSocket.CONNECTING) {
2564
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2565
- }
2566
- if (typeof options === "function") {
2567
- cb = options;
2568
- options = {};
2569
- }
2570
- if (typeof data === "number")
2571
- data = data.toString();
2572
- if (this.readyState !== _WebSocket.OPEN) {
2573
- sendAfterClose(this, data, cb);
2574
- return;
2575
- }
2576
- const opts = {
2577
- binary: typeof data !== "string",
2578
- mask: !this._isServer,
2579
- compress: true,
2580
- fin: true,
2581
- ...options
2582
- };
2583
- if (!this._extensions[PerMessageDeflate.extensionName]) {
2584
- opts.compress = false;
2585
- }
2586
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
2587
- }
2588
- /**
2589
- * Forcibly close the connection.
2590
- *
2591
- * @public
2592
- */
2593
- terminate() {
2594
- if (this.readyState === _WebSocket.CLOSED)
2595
- return;
2596
- if (this.readyState === _WebSocket.CONNECTING) {
2597
- const msg = "WebSocket was closed before the connection was established";
2598
- abortHandshake(this, this._req, msg);
2599
- return;
2600
- }
2601
- if (this._socket) {
2602
- this._readyState = _WebSocket.CLOSING;
2603
- this._socket.destroy();
2604
- }
2605
- }
2606
- };
2607
- Object.defineProperty(WebSocket2, "CONNECTING", {
2608
- enumerable: true,
2609
- value: readyStates.indexOf("CONNECTING")
2610
- });
2611
- Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
2612
- enumerable: true,
2613
- value: readyStates.indexOf("CONNECTING")
2614
- });
2615
- Object.defineProperty(WebSocket2, "OPEN", {
2616
- enumerable: true,
2617
- value: readyStates.indexOf("OPEN")
2618
- });
2619
- Object.defineProperty(WebSocket2.prototype, "OPEN", {
2620
- enumerable: true,
2621
- value: readyStates.indexOf("OPEN")
2622
- });
2623
- Object.defineProperty(WebSocket2, "CLOSING", {
2624
- enumerable: true,
2625
- value: readyStates.indexOf("CLOSING")
2626
- });
2627
- Object.defineProperty(WebSocket2.prototype, "CLOSING", {
2628
- enumerable: true,
2629
- value: readyStates.indexOf("CLOSING")
2630
- });
2631
- Object.defineProperty(WebSocket2, "CLOSED", {
2632
- enumerable: true,
2633
- value: readyStates.indexOf("CLOSED")
2634
- });
2635
- Object.defineProperty(WebSocket2.prototype, "CLOSED", {
2636
- enumerable: true,
2637
- value: readyStates.indexOf("CLOSED")
2638
- });
2639
- [
2640
- "binaryType",
2641
- "bufferedAmount",
2642
- "extensions",
2643
- "isPaused",
2644
- "protocol",
2645
- "readyState",
2646
- "url"
2647
- ].forEach((property) => {
2648
- Object.defineProperty(WebSocket2.prototype, property, { enumerable: true });
2649
- });
2650
- ["open", "error", "close", "message"].forEach((method) => {
2651
- Object.defineProperty(WebSocket2.prototype, `on${method}`, {
2652
- enumerable: true,
2653
- get() {
2654
- for (const listener of this.listeners(method)) {
2655
- if (listener[kForOnEventAttribute])
2656
- return listener[kListener];
2657
- }
2658
- return null;
2659
- },
2660
- set(handler) {
2661
- for (const listener of this.listeners(method)) {
2662
- if (listener[kForOnEventAttribute]) {
2663
- this.removeListener(method, listener);
2664
- break;
2665
- }
2666
- }
2667
- if (typeof handler !== "function")
2668
- return;
2669
- this.addEventListener(method, handler, {
2670
- [kForOnEventAttribute]: true
2671
- });
2672
- }
2673
- });
2674
- });
2675
- WebSocket2.prototype.addEventListener = addEventListener;
2676
- WebSocket2.prototype.removeEventListener = removeEventListener;
2677
- module.exports = WebSocket2;
2678
- function initAsClient(websocket, address, protocols, options) {
2679
- const opts = {
2680
- protocolVersion: protocolVersions[1],
2681
- maxPayload: 100 * 1024 * 1024,
2682
- skipUTF8Validation: false,
2683
- perMessageDeflate: true,
2684
- followRedirects: false,
2685
- maxRedirects: 10,
2686
- ...options,
2687
- createConnection: void 0,
2688
- socketPath: void 0,
2689
- hostname: void 0,
2690
- protocol: void 0,
2691
- timeout: void 0,
2692
- method: "GET",
2693
- host: void 0,
2694
- path: void 0,
2695
- port: void 0
2696
- };
2697
- if (!protocolVersions.includes(opts.protocolVersion)) {
2698
- throw new RangeError(
2699
- `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
2700
- );
2701
- }
2702
- let parsedUrl;
2703
- if (address instanceof URL) {
2704
- parsedUrl = address;
2705
- websocket._url = address.href;
2706
- } else {
2707
- try {
2708
- parsedUrl = new URL(address);
2709
- } catch (e) {
2710
- throw new SyntaxError(`Invalid URL: ${address}`);
2711
- }
2712
- websocket._url = address;
2713
- }
2714
- const isSecure = parsedUrl.protocol === "wss:";
2715
- const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2716
- let invalidUrlMessage;
2717
- if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2718
- invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", or "ws+unix:"`;
2719
- } else if (isIpcUrl && !parsedUrl.pathname) {
2720
- invalidUrlMessage = "The URL's pathname is empty";
2721
- } else if (parsedUrl.hash) {
2722
- invalidUrlMessage = "The URL contains a fragment identifier";
2723
- }
2724
- if (invalidUrlMessage) {
2725
- const err = new SyntaxError(invalidUrlMessage);
2726
- if (websocket._redirects === 0) {
2727
- throw err;
2728
- } else {
2729
- emitErrorAndClose(websocket, err);
2730
- return;
2731
- }
2732
- }
2733
- const defaultPort = isSecure ? 443 : 80;
2734
- const key = randomBytes(16).toString("base64");
2735
- const request = isSecure ? https.request : http.request;
2736
- const protocolSet = /* @__PURE__ */ new Set();
2737
- let perMessageDeflate;
2738
- opts.createConnection = isSecure ? tlsConnect : netConnect;
2739
- opts.defaultPort = opts.defaultPort || defaultPort;
2740
- opts.port = parsedUrl.port || defaultPort;
2741
- opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2742
- opts.headers = {
2743
- ...opts.headers,
2744
- "Sec-WebSocket-Version": opts.protocolVersion,
2745
- "Sec-WebSocket-Key": key,
2746
- Connection: "Upgrade",
2747
- Upgrade: "websocket"
2748
- };
2749
- opts.path = parsedUrl.pathname + parsedUrl.search;
2750
- opts.timeout = opts.handshakeTimeout;
2751
- if (opts.perMessageDeflate) {
2752
- perMessageDeflate = new PerMessageDeflate(
2753
- opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
2754
- false,
2755
- opts.maxPayload
2756
- );
2757
- opts.headers["Sec-WebSocket-Extensions"] = format({
2758
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2759
- });
2760
- }
2761
- if (protocols.length) {
2762
- for (const protocol of protocols) {
2763
- if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2764
- throw new SyntaxError(
2765
- "An invalid or duplicated subprotocol was specified"
2766
- );
2767
- }
2768
- protocolSet.add(protocol);
2769
- }
2770
- opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2771
- }
2772
- if (opts.origin) {
2773
- if (opts.protocolVersion < 13) {
2774
- opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2775
- } else {
2776
- opts.headers.Origin = opts.origin;
2777
- }
2778
- }
2779
- if (parsedUrl.username || parsedUrl.password) {
2780
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2781
- }
2782
- if (isIpcUrl) {
2783
- const parts = opts.path.split(":");
2784
- opts.socketPath = parts[0];
2785
- opts.path = parts[1];
2786
- }
2787
- let req;
2788
- if (opts.followRedirects) {
2789
- if (websocket._redirects === 0) {
2790
- websocket._originalIpc = isIpcUrl;
2791
- websocket._originalSecure = isSecure;
2792
- websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2793
- const headers = options && options.headers;
2794
- options = { ...options, headers: {} };
2795
- if (headers) {
2796
- for (const [key2, value] of Object.entries(headers)) {
2797
- options.headers[key2.toLowerCase()] = value;
2798
- }
2799
- }
2800
- } else if (websocket.listenerCount("redirect") === 0) {
2801
- const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2802
- if (!isSameHost || websocket._originalSecure && !isSecure) {
2803
- delete opts.headers.authorization;
2804
- delete opts.headers.cookie;
2805
- if (!isSameHost)
2806
- delete opts.headers.host;
2807
- opts.auth = void 0;
2808
- }
2809
- }
2810
- if (opts.auth && !options.headers.authorization) {
2811
- options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2812
- }
2813
- req = websocket._req = request(opts);
2814
- if (websocket._redirects) {
2815
- websocket.emit("redirect", websocket.url, req);
2816
- }
2817
- } else {
2818
- req = websocket._req = request(opts);
2819
- }
2820
- if (opts.timeout) {
2821
- req.on("timeout", () => {
2822
- abortHandshake(websocket, req, "Opening handshake has timed out");
2823
- });
2824
- }
2825
- req.on("error", (err) => {
2826
- if (req === null || req[kAborted])
2827
- return;
2828
- req = websocket._req = null;
2829
- emitErrorAndClose(websocket, err);
2830
- });
2831
- req.on("response", (res) => {
2832
- const location = res.headers.location;
2833
- const statusCode = res.statusCode;
2834
- if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2835
- if (++websocket._redirects > opts.maxRedirects) {
2836
- abortHandshake(websocket, req, "Maximum redirects exceeded");
2837
- return;
2838
- }
2839
- req.abort();
2840
- let addr;
2841
- try {
2842
- addr = new URL(location, address);
2843
- } catch (e) {
2844
- const err = new SyntaxError(`Invalid URL: ${location}`);
2845
- emitErrorAndClose(websocket, err);
2846
- return;
2847
- }
2848
- initAsClient(websocket, addr, protocols, options);
2849
- } else if (!websocket.emit("unexpected-response", req, res)) {
2850
- abortHandshake(
2851
- websocket,
2852
- req,
2853
- `Unexpected server response: ${res.statusCode}`
2854
- );
2855
- }
2856
- });
2857
- req.on("upgrade", (res, socket, head) => {
2858
- websocket.emit("upgrade", res);
2859
- if (websocket.readyState !== WebSocket2.CONNECTING)
2860
- return;
2861
- req = websocket._req = null;
2862
- if (res.headers.upgrade.toLowerCase() !== "websocket") {
2863
- abortHandshake(websocket, socket, "Invalid Upgrade header");
2864
- return;
2865
- }
2866
- const digest = createHash("sha1").update(key + GUID).digest("base64");
2867
- if (res.headers["sec-websocket-accept"] !== digest) {
2868
- abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
2869
- return;
2870
- }
2871
- const serverProt = res.headers["sec-websocket-protocol"];
2872
- let protError;
2873
- if (serverProt !== void 0) {
2874
- if (!protocolSet.size) {
2875
- protError = "Server sent a subprotocol but none was requested";
2876
- } else if (!protocolSet.has(serverProt)) {
2877
- protError = "Server sent an invalid subprotocol";
2878
- }
2879
- } else if (protocolSet.size) {
2880
- protError = "Server sent no subprotocol";
2881
- }
2882
- if (protError) {
2883
- abortHandshake(websocket, socket, protError);
2884
- return;
2885
- }
2886
- if (serverProt)
2887
- websocket._protocol = serverProt;
2888
- const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2889
- if (secWebSocketExtensions !== void 0) {
2890
- if (!perMessageDeflate) {
2891
- const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
2892
- abortHandshake(websocket, socket, message);
2893
- return;
2894
- }
2895
- let extensions;
2896
- try {
2897
- extensions = parse(secWebSocketExtensions);
2898
- } catch (err) {
2899
- const message = "Invalid Sec-WebSocket-Extensions header";
2900
- abortHandshake(websocket, socket, message);
2901
- return;
2902
- }
2903
- const extensionNames = Object.keys(extensions);
2904
- if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
2905
- const message = "Server indicated an extension that was not requested";
2906
- abortHandshake(websocket, socket, message);
2907
- return;
2908
- }
2909
- try {
2910
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2911
- } catch (err) {
2912
- const message = "Invalid Sec-WebSocket-Extensions header";
2913
- abortHandshake(websocket, socket, message);
2914
- return;
2915
- }
2916
- websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2917
- }
2918
- websocket.setSocket(socket, head, {
2919
- generateMask: opts.generateMask,
2920
- maxPayload: opts.maxPayload,
2921
- skipUTF8Validation: opts.skipUTF8Validation
2922
- });
2923
- });
2924
- if (opts.finishRequest) {
2925
- opts.finishRequest(req, websocket);
2926
- } else {
2927
- req.end();
2928
- }
2929
- }
2930
- function emitErrorAndClose(websocket, err) {
2931
- websocket._readyState = WebSocket2.CLOSING;
2932
- websocket.emit("error", err);
2933
- websocket.emitClose();
2934
- }
2935
- function netConnect(options) {
2936
- options.path = options.socketPath;
2937
- return net.connect(options);
2938
- }
2939
- function tlsConnect(options) {
2940
- options.path = void 0;
2941
- if (!options.servername && options.servername !== "") {
2942
- options.servername = net.isIP(options.host) ? "" : options.host;
2943
- }
2944
- return tls.connect(options);
2945
- }
2946
- function abortHandshake(websocket, stream, message) {
2947
- websocket._readyState = WebSocket2.CLOSING;
2948
- const err = new Error(message);
2949
- Error.captureStackTrace(err, abortHandshake);
2950
- if (stream.setHeader) {
2951
- stream[kAborted] = true;
2952
- stream.abort();
2953
- if (stream.socket && !stream.socket.destroyed) {
2954
- stream.socket.destroy();
2955
- }
2956
- process.nextTick(emitErrorAndClose, websocket, err);
2957
- } else {
2958
- stream.destroy(err);
2959
- stream.once("error", websocket.emit.bind(websocket, "error"));
2960
- stream.once("close", websocket.emitClose.bind(websocket));
2961
- }
2962
- }
2963
- function sendAfterClose(websocket, data, cb) {
2964
- if (data) {
2965
- const length = toBuffer(data).length;
2966
- if (websocket._socket)
2967
- websocket._sender._bufferedBytes += length;
2968
- else
2969
- websocket._bufferedAmount += length;
2970
- }
2971
- if (cb) {
2972
- const err = new Error(
2973
- `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
2974
- );
2975
- process.nextTick(cb, err);
2976
- }
2977
- }
2978
- function receiverOnConclude(code, reason) {
2979
- const websocket = this[kWebSocket];
2980
- websocket._closeFrameReceived = true;
2981
- websocket._closeMessage = reason;
2982
- websocket._closeCode = code;
2983
- if (websocket._socket[kWebSocket] === void 0)
2984
- return;
2985
- websocket._socket.removeListener("data", socketOnData);
2986
- process.nextTick(resume, websocket._socket);
2987
- if (code === 1005)
2988
- websocket.close();
2989
- else
2990
- websocket.close(code, reason);
2991
- }
2992
- function receiverOnDrain() {
2993
- const websocket = this[kWebSocket];
2994
- if (!websocket.isPaused)
2995
- websocket._socket.resume();
2996
- }
2997
- function receiverOnError(err) {
2998
- const websocket = this[kWebSocket];
2999
- if (websocket._socket[kWebSocket] !== void 0) {
3000
- websocket._socket.removeListener("data", socketOnData);
3001
- process.nextTick(resume, websocket._socket);
3002
- websocket.close(err[kStatusCode]);
3003
- }
3004
- websocket.emit("error", err);
3005
- }
3006
- function receiverOnFinish() {
3007
- this[kWebSocket].emitClose();
3008
- }
3009
- function receiverOnMessage(data, isBinary) {
3010
- this[kWebSocket].emit("message", data, isBinary);
3011
- }
3012
- function receiverOnPing(data) {
3013
- const websocket = this[kWebSocket];
3014
- websocket.pong(data, !websocket._isServer, NOOP);
3015
- websocket.emit("ping", data);
3016
- }
3017
- function receiverOnPong(data) {
3018
- this[kWebSocket].emit("pong", data);
3019
- }
3020
- function resume(stream) {
3021
- stream.resume();
3022
- }
3023
- function socketOnClose() {
3024
- const websocket = this[kWebSocket];
3025
- this.removeListener("close", socketOnClose);
3026
- this.removeListener("data", socketOnData);
3027
- this.removeListener("end", socketOnEnd);
3028
- websocket._readyState = WebSocket2.CLOSING;
3029
- let chunk;
3030
- if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
3031
- websocket._receiver.write(chunk);
3032
- }
3033
- websocket._receiver.end();
3034
- this[kWebSocket] = void 0;
3035
- clearTimeout(websocket._closeTimer);
3036
- if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3037
- websocket.emitClose();
3038
- } else {
3039
- websocket._receiver.on("error", receiverOnFinish);
3040
- websocket._receiver.on("finish", receiverOnFinish);
3041
- }
3042
- }
3043
- function socketOnData(chunk) {
3044
- if (!this[kWebSocket]._receiver.write(chunk)) {
3045
- this.pause();
3046
- }
3047
- }
3048
- function socketOnEnd() {
3049
- const websocket = this[kWebSocket];
3050
- websocket._readyState = WebSocket2.CLOSING;
3051
- websocket._receiver.end();
3052
- this.end();
3053
- }
3054
- function socketOnError() {
3055
- const websocket = this[kWebSocket];
3056
- this.removeListener("error", socketOnError);
3057
- this.on("error", NOOP);
3058
- if (websocket) {
3059
- websocket._readyState = WebSocket2.CLOSING;
3060
- this.destroy();
3061
- }
3062
- }
3063
- }
3064
- });
3065
-
3066
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/subprotocol.js
3067
- var require_subprotocol = __commonJS({
3068
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/subprotocol.js"(exports, module) {
3069
- "use strict";
3070
- init_cjs_shims();
3071
- var { tokenChars } = require_validation();
3072
- function parse(header) {
3073
- const protocols = /* @__PURE__ */ new Set();
3074
- let start = -1;
3075
- let end = -1;
3076
- let i = 0;
3077
- for (i; i < header.length; i++) {
3078
- const code = header.charCodeAt(i);
3079
- if (end === -1 && tokenChars[code] === 1) {
3080
- if (start === -1)
3081
- start = i;
3082
- } else if (i !== 0 && (code === 32 || code === 9)) {
3083
- if (end === -1 && start !== -1)
3084
- end = i;
3085
- } else if (code === 44) {
3086
- if (start === -1) {
3087
- throw new SyntaxError(`Unexpected character at index ${i}`);
3088
- }
3089
- if (end === -1)
3090
- end = i;
3091
- const protocol2 = header.slice(start, end);
3092
- if (protocols.has(protocol2)) {
3093
- throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3094
- }
3095
- protocols.add(protocol2);
3096
- start = end = -1;
3097
- } else {
3098
- throw new SyntaxError(`Unexpected character at index ${i}`);
3099
- }
3100
- }
3101
- if (start === -1 || end !== -1) {
3102
- throw new SyntaxError("Unexpected end of input");
3103
- }
3104
- const protocol = header.slice(start, i);
3105
- if (protocols.has(protocol)) {
3106
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3107
- }
3108
- protocols.add(protocol);
3109
- return protocols;
3110
- }
3111
- module.exports = { parse };
3112
- }
3113
- });
3114
-
3115
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/websocket-server.js
3116
- var require_websocket_server = __commonJS({
3117
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/websocket-server.js"(exports, module) {
3118
- "use strict";
3119
- init_cjs_shims();
3120
- var EventEmitter = __require("events");
3121
- var http = __require("http");
3122
- var https = __require("https");
3123
- var net = __require("net");
3124
- var tls = __require("tls");
3125
- var { createHash } = __require("crypto");
3126
- var extension = require_extension();
3127
- var PerMessageDeflate = require_permessage_deflate();
3128
- var subprotocol = require_subprotocol();
3129
- var WebSocket2 = require_websocket();
3130
- var { GUID, kWebSocket } = require_constants();
3131
- var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3132
- var RUNNING = 0;
3133
- var CLOSING = 1;
3134
- var CLOSED = 2;
3135
- var WebSocketServer2 = class extends EventEmitter {
3136
- /**
3137
- * Create a `WebSocketServer` instance.
3138
- *
3139
- * @param {Object} options Configuration options
3140
- * @param {Number} [options.backlog=511] The maximum length of the queue of
3141
- * pending connections
3142
- * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3143
- * track clients
3144
- * @param {Function} [options.handleProtocols] A hook to handle protocols
3145
- * @param {String} [options.host] The hostname where to bind the server
3146
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3147
- * size
3148
- * @param {Boolean} [options.noServer=false] Enable no server mode
3149
- * @param {String} [options.path] Accept only connections matching this path
3150
- * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3151
- * permessage-deflate
3152
- * @param {Number} [options.port] The port where to bind the server
3153
- * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3154
- * server to use
3155
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3156
- * not to skip UTF-8 validation for text and close messages
3157
- * @param {Function} [options.verifyClient] A hook to reject connections
3158
- * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3159
- * class to use. It must be the `WebSocket` class or class that extends it
3160
- * @param {Function} [callback] A listener for the `listening` event
3161
- */
3162
- constructor(options, callback) {
3163
- super();
3164
- options = {
3165
- maxPayload: 100 * 1024 * 1024,
3166
- skipUTF8Validation: false,
3167
- perMessageDeflate: false,
3168
- handleProtocols: null,
3169
- clientTracking: true,
3170
- verifyClient: null,
3171
- noServer: false,
3172
- backlog: null,
3173
- // use default (511 as implemented in net.js)
3174
- server: null,
3175
- host: null,
3176
- path: null,
3177
- port: null,
3178
- WebSocket: WebSocket2,
3179
- ...options
3180
- };
3181
- if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3182
- throw new TypeError(
3183
- 'One and only one of the "port", "server", or "noServer" options must be specified'
3184
- );
3185
- }
3186
- if (options.port != null) {
3187
- this._server = http.createServer((req, res) => {
3188
- const body = http.STATUS_CODES[426];
3189
- res.writeHead(426, {
3190
- "Content-Length": body.length,
3191
- "Content-Type": "text/plain"
3192
- });
3193
- res.end(body);
3194
- });
3195
- this._server.listen(
3196
- options.port,
3197
- options.host,
3198
- options.backlog,
3199
- callback
3200
- );
3201
- } else if (options.server) {
3202
- this._server = options.server;
3203
- }
3204
- if (this._server) {
3205
- const emitConnection = this.emit.bind(this, "connection");
3206
- this._removeListeners = addListeners(this._server, {
3207
- listening: this.emit.bind(this, "listening"),
3208
- error: this.emit.bind(this, "error"),
3209
- upgrade: (req, socket, head) => {
3210
- this.handleUpgrade(req, socket, head, emitConnection);
3211
- }
3212
- });
3213
- }
3214
- if (options.perMessageDeflate === true)
3215
- options.perMessageDeflate = {};
3216
- if (options.clientTracking) {
3217
- this.clients = /* @__PURE__ */ new Set();
3218
- this._shouldEmitClose = false;
3219
- }
3220
- this.options = options;
3221
- this._state = RUNNING;
3222
- }
3223
- /**
3224
- * Returns the bound address, the address family name, and port of the server
3225
- * as reported by the operating system if listening on an IP socket.
3226
- * If the server is listening on a pipe or UNIX domain socket, the name is
3227
- * returned as a string.
3228
- *
3229
- * @return {(Object|String|null)} The address of the server
3230
- * @public
3231
- */
3232
- address() {
3233
- if (this.options.noServer) {
3234
- throw new Error('The server is operating in "noServer" mode');
3235
- }
3236
- if (!this._server)
3237
- return null;
3238
- return this._server.address();
3239
- }
3240
- /**
3241
- * Stop the server from accepting new connections and emit the `'close'` event
3242
- * when all existing connections are closed.
3243
- *
3244
- * @param {Function} [cb] A one-time listener for the `'close'` event
3245
- * @public
3246
- */
3247
- close(cb) {
3248
- if (this._state === CLOSED) {
3249
- if (cb) {
3250
- this.once("close", () => {
3251
- cb(new Error("The server is not running"));
3252
- });
3253
- }
3254
- process.nextTick(emitClose, this);
3255
- return;
3256
- }
3257
- if (cb)
3258
- this.once("close", cb);
3259
- if (this._state === CLOSING)
3260
- return;
3261
- this._state = CLOSING;
3262
- if (this.options.noServer || this.options.server) {
3263
- if (this._server) {
3264
- this._removeListeners();
3265
- this._removeListeners = this._server = null;
3266
- }
3267
- if (this.clients) {
3268
- if (!this.clients.size) {
3269
- process.nextTick(emitClose, this);
3270
- } else {
3271
- this._shouldEmitClose = true;
3272
- }
3273
- } else {
3274
- process.nextTick(emitClose, this);
3275
- }
3276
- } else {
3277
- const server = this._server;
3278
- this._removeListeners();
3279
- this._removeListeners = this._server = null;
3280
- server.close(() => {
3281
- emitClose(this);
3282
- });
3283
- }
3284
- }
3285
- /**
3286
- * See if a given request should be handled by this server instance.
3287
- *
3288
- * @param {http.IncomingMessage} req Request object to inspect
3289
- * @return {Boolean} `true` if the request is valid, else `false`
3290
- * @public
3291
- */
3292
- shouldHandle(req) {
3293
- if (this.options.path) {
3294
- const index = req.url.indexOf("?");
3295
- const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3296
- if (pathname !== this.options.path)
3297
- return false;
3298
- }
3299
- return true;
3300
- }
3301
- /**
3302
- * Handle a HTTP Upgrade request.
3303
- *
3304
- * @param {http.IncomingMessage} req The request object
3305
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
3306
- * server and client
3307
- * @param {Buffer} head The first packet of the upgraded stream
3308
- * @param {Function} cb Callback
3309
- * @public
3310
- */
3311
- handleUpgrade(req, socket, head, cb) {
3312
- socket.on("error", socketOnError);
3313
- const key = req.headers["sec-websocket-key"];
3314
- const version = +req.headers["sec-websocket-version"];
3315
- if (req.method !== "GET") {
3316
- const message = "Invalid HTTP method";
3317
- abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3318
- return;
3319
- }
3320
- if (req.headers.upgrade.toLowerCase() !== "websocket") {
3321
- const message = "Invalid Upgrade header";
3322
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3323
- return;
3324
- }
3325
- if (!key || !keyRegex.test(key)) {
3326
- const message = "Missing or invalid Sec-WebSocket-Key header";
3327
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3328
- return;
3329
- }
3330
- if (version !== 8 && version !== 13) {
3331
- const message = "Missing or invalid Sec-WebSocket-Version header";
3332
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3333
- return;
3334
- }
3335
- if (!this.shouldHandle(req)) {
3336
- abortHandshake(socket, 400);
3337
- return;
3338
- }
3339
- const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3340
- let protocols = /* @__PURE__ */ new Set();
3341
- if (secWebSocketProtocol !== void 0) {
3342
- try {
3343
- protocols = subprotocol.parse(secWebSocketProtocol);
3344
- } catch (err) {
3345
- const message = "Invalid Sec-WebSocket-Protocol header";
3346
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3347
- return;
3348
- }
3349
- }
3350
- const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3351
- const extensions = {};
3352
- if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3353
- const perMessageDeflate = new PerMessageDeflate(
3354
- this.options.perMessageDeflate,
3355
- true,
3356
- this.options.maxPayload
3357
- );
3358
- try {
3359
- const offers = extension.parse(secWebSocketExtensions);
3360
- if (offers[PerMessageDeflate.extensionName]) {
3361
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3362
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3363
- }
3364
- } catch (err) {
3365
- const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3366
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3367
- return;
3368
- }
3369
- }
3370
- if (this.options.verifyClient) {
3371
- const info = {
3372
- origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3373
- secure: !!(req.socket.authorized || req.socket.encrypted),
3374
- req
3375
- };
3376
- if (this.options.verifyClient.length === 2) {
3377
- this.options.verifyClient(info, (verified, code, message, headers) => {
3378
- if (!verified) {
3379
- return abortHandshake(socket, code || 401, message, headers);
3380
- }
3381
- this.completeUpgrade(
3382
- extensions,
3383
- key,
3384
- protocols,
3385
- req,
3386
- socket,
3387
- head,
3388
- cb
3389
- );
3390
- });
3391
- return;
3392
- }
3393
- if (!this.options.verifyClient(info))
3394
- return abortHandshake(socket, 401);
3395
- }
3396
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3397
- }
3398
- /**
3399
- * Upgrade the connection to WebSocket.
3400
- *
3401
- * @param {Object} extensions The accepted extensions
3402
- * @param {String} key The value of the `Sec-WebSocket-Key` header
3403
- * @param {Set} protocols The subprotocols
3404
- * @param {http.IncomingMessage} req The request object
3405
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
3406
- * server and client
3407
- * @param {Buffer} head The first packet of the upgraded stream
3408
- * @param {Function} cb Callback
3409
- * @throws {Error} If called more than once with the same socket
3410
- * @private
3411
- */
3412
- completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3413
- if (!socket.readable || !socket.writable)
3414
- return socket.destroy();
3415
- if (socket[kWebSocket]) {
3416
- throw new Error(
3417
- "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3418
- );
3419
- }
3420
- if (this._state > RUNNING)
3421
- return abortHandshake(socket, 503);
3422
- const digest = createHash("sha1").update(key + GUID).digest("base64");
3423
- const headers = [
3424
- "HTTP/1.1 101 Switching Protocols",
3425
- "Upgrade: websocket",
3426
- "Connection: Upgrade",
3427
- `Sec-WebSocket-Accept: ${digest}`
3428
- ];
3429
- const ws = new this.options.WebSocket(null);
3430
- if (protocols.size) {
3431
- const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3432
- if (protocol) {
3433
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3434
- ws._protocol = protocol;
3435
- }
3436
- }
3437
- if (extensions[PerMessageDeflate.extensionName]) {
3438
- const params = extensions[PerMessageDeflate.extensionName].params;
3439
- const value = extension.format({
3440
- [PerMessageDeflate.extensionName]: [params]
3441
- });
3442
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
3443
- ws._extensions = extensions;
3444
- }
3445
- this.emit("headers", headers, req);
3446
- socket.write(headers.concat("\r\n").join("\r\n"));
3447
- socket.removeListener("error", socketOnError);
3448
- ws.setSocket(socket, head, {
3449
- maxPayload: this.options.maxPayload,
3450
- skipUTF8Validation: this.options.skipUTF8Validation
3451
- });
3452
- if (this.clients) {
3453
- this.clients.add(ws);
3454
- ws.on("close", () => {
3455
- this.clients.delete(ws);
3456
- if (this._shouldEmitClose && !this.clients.size) {
3457
- process.nextTick(emitClose, this);
3458
- }
3459
- });
3460
- }
3461
- cb(ws, req);
3462
- }
3463
- };
3464
- module.exports = WebSocketServer2;
3465
- function addListeners(server, map) {
3466
- for (const event of Object.keys(map))
3467
- server.on(event, map[event]);
3468
- return function removeListeners() {
3469
- for (const event of Object.keys(map)) {
3470
- server.removeListener(event, map[event]);
3471
- }
3472
- };
3473
- }
3474
- function emitClose(server) {
3475
- server._state = CLOSED;
3476
- server.emit("close");
3477
- }
3478
- function socketOnError() {
3479
- this.destroy();
3480
- }
3481
- function abortHandshake(socket, code, message, headers) {
3482
- message = message || http.STATUS_CODES[code];
3483
- headers = {
3484
- Connection: "close",
3485
- "Content-Type": "text/html",
3486
- "Content-Length": Buffer.byteLength(message),
3487
- ...headers
3488
- };
3489
- socket.once("finish", socket.destroy);
3490
- socket.end(
3491
- `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3492
- ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3493
- );
3494
- }
3495
- function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
3496
- if (server.listenerCount("wsClientError")) {
3497
- const err = new Error(message);
3498
- Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3499
- server.emit("wsClientError", err, socket, req);
3500
- } else {
3501
- abortHandshake(socket, code, message);
3502
- }
3503
- }
3504
- }
3505
- });
3506
-
3507
- // ../../node_modules/.pnpm/ink@4.4.1_@types+react@17.0.2_react@18.2.0/node_modules/ink/build/devtools.js
3508
- init_cjs_shims();
3509
-
3510
- // ../../node_modules/.pnpm/ink@4.4.1_@types+react@17.0.2_react@18.2.0/node_modules/ink/build/devtools-window-polyfill.js
3511
- init_cjs_shims();
3512
-
3513
- // ../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/wrapper.mjs
3514
- init_cjs_shims();
3515
- var import_stream = __toESM(require_stream(), 1);
3516
- var import_receiver = __toESM(require_receiver(), 1);
3517
- var import_sender = __toESM(require_sender(), 1);
3518
- var import_websocket = __toESM(require_websocket(), 1);
3519
- var import_websocket_server = __toESM(require_websocket_server(), 1);
3520
- var wrapper_default = import_websocket.default;
3521
-
3522
- // ../../node_modules/.pnpm/ink@4.4.1_@types+react@17.0.2_react@18.2.0/node_modules/ink/build/devtools-window-polyfill.js
3523
- var customGlobal = global;
3524
- if (!customGlobal.WebSocket) {
3525
- customGlobal.WebSocket = wrapper_default;
3526
- }
3527
- if (!customGlobal.window) {
3528
- customGlobal.window = global;
3529
- }
3530
- if (!customGlobal.self) {
3531
- customGlobal.self = global;
3532
- }
3533
- customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [
3534
- {
3535
- // ComponentFilterElementType
3536
- type: 1,
3537
- // ElementTypeHostComponent
3538
- value: 7,
3539
- isEnabled: true
3540
- },
3541
- {
3542
- // ComponentFilterDisplayName
3543
- type: 2,
3544
- value: "InternalApp",
3545
- isEnabled: true,
3546
- isValid: true
3547
- },
3548
- {
3549
- // ComponentFilterDisplayName
3550
- type: 2,
3551
- value: "InternalAppContext",
3552
- isEnabled: true,
3553
- isValid: true
3554
- },
3555
- {
3556
- // ComponentFilterDisplayName
3557
- type: 2,
3558
- value: "InternalStdoutContext",
3559
- isEnabled: true,
3560
- isValid: true
3561
- },
3562
- {
3563
- // ComponentFilterDisplayName
3564
- type: 2,
3565
- value: "InternalStderrContext",
3566
- isEnabled: true,
3567
- isValid: true
3568
- },
3569
- {
3570
- // ComponentFilterDisplayName
3571
- type: 2,
3572
- value: "InternalStdinContext",
3573
- isEnabled: true,
3574
- isValid: true
3575
- },
3576
- {
3577
- // ComponentFilterDisplayName
3578
- type: 2,
3579
- value: "InternalFocusContext",
3580
- isEnabled: true,
3581
- isValid: true
3582
- }
3583
- ];
3584
-
3585
- // ../../node_modules/.pnpm/ink@4.4.1_@types+react@17.0.2_react@18.2.0/node_modules/ink/build/devtools.js
3586
- import devtools from "react-devtools-core";
3587
- devtools.connectToDevTools();
3588
- //# sourceMappingURL=devtools-5N4JAP3R.js.map