@usherlabs/cex-broker 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createRequire } from "node:module";
1
+ // @bun
2
2
  var __create = Object.create;
3
3
  var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
@@ -26,7 +26,7 @@ var __export = (target, all) => {
26
26
  });
27
27
  };
28
28
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
29
+ var __require = import.meta.require;
30
30
 
31
31
  // node_modules/@grpc/grpc-js/build/src/constants.js
32
32
  var require_constants = __commonJS((exports) => {
@@ -4173,7 +4173,7 @@ var require_lodash = __commonJS((exports, module) => {
4173
4173
  var rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde";
4174
4174
  var rsVarRange = "\\ufe0e\\ufe0f";
4175
4175
  var rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
4176
- var rsApos = "[']";
4176
+ var rsApos = "['\u2019]";
4177
4177
  var rsAstral = "[" + rsAstralRange + "]";
4178
4178
  var rsBreak = "[" + rsBreakRange + "]";
4179
4179
  var rsCombo = "[" + rsComboMarksRange + rsComboSymbolsRange + "]";
@@ -4212,196 +4212,196 @@ var require_lodash = __commonJS((exports, module) => {
4212
4212
  var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + "]");
4213
4213
  var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
4214
4214
  var deburredLetters = {
4215
- "À": "A",
4216
- "Á": "A",
4217
- "Â": "A",
4218
- "Ã": "A",
4219
- "Ä": "A",
4220
- "Å": "A",
4221
- "à": "a",
4222
- "á": "a",
4223
- "â": "a",
4224
- "ã": "a",
4225
- "ä": "a",
4226
- "å": "a",
4227
- "Ç": "C",
4228
- "ç": "c",
4229
- "Ð": "D",
4230
- "ð": "d",
4231
- "È": "E",
4232
- "É": "E",
4233
- "Ê": "E",
4234
- "Ë": "E",
4235
- "è": "e",
4236
- "é": "e",
4237
- "ê": "e",
4238
- "ë": "e",
4239
- "Ì": "I",
4240
- "Í": "I",
4241
- "Î": "I",
4242
- "Ï": "I",
4243
- "ì": "i",
4244
- "í": "i",
4245
- "î": "i",
4246
- "ï": "i",
4247
- "Ñ": "N",
4248
- "ñ": "n",
4249
- "Ò": "O",
4250
- "Ó": "O",
4251
- "Ô": "O",
4252
- "Õ": "O",
4253
- "Ö": "O",
4254
- "Ø": "O",
4255
- "ò": "o",
4256
- "ó": "o",
4257
- "ô": "o",
4258
- "õ": "o",
4259
- "ö": "o",
4260
- "ø": "o",
4261
- "Ù": "U",
4262
- "Ú": "U",
4263
- "Û": "U",
4264
- "Ü": "U",
4265
- "ù": "u",
4266
- "ú": "u",
4267
- "û": "u",
4268
- "ü": "u",
4269
- "Ý": "Y",
4270
- "ý": "y",
4271
- "ÿ": "y",
4272
- "Æ": "Ae",
4273
- "æ": "ae",
4274
- "Þ": "Th",
4275
- "þ": "th",
4276
- "ß": "ss",
4277
- "Ā": "A",
4278
- "Ă": "A",
4279
- "Ą": "A",
4280
- "ā": "a",
4281
- "ă": "a",
4282
- "ą": "a",
4283
- "Ć": "C",
4284
- "Ĉ": "C",
4285
- "Ċ": "C",
4286
- "Č": "C",
4287
- "ć": "c",
4288
- "ĉ": "c",
4289
- "ċ": "c",
4290
- "č": "c",
4291
- "Ď": "D",
4292
- "Đ": "D",
4293
- "ď": "d",
4294
- "đ": "d",
4295
- "Ē": "E",
4296
- "Ĕ": "E",
4297
- "Ė": "E",
4298
- "Ę": "E",
4299
- "Ě": "E",
4300
- "ē": "e",
4301
- "ĕ": "e",
4302
- "ė": "e",
4303
- "ę": "e",
4304
- "ě": "e",
4305
- "Ĝ": "G",
4306
- "Ğ": "G",
4307
- "Ġ": "G",
4308
- "Ģ": "G",
4309
- "ĝ": "g",
4310
- "ğ": "g",
4311
- "ġ": "g",
4312
- "ģ": "g",
4313
- "Ĥ": "H",
4314
- "Ħ": "H",
4315
- "ĥ": "h",
4316
- "ħ": "h",
4317
- "Ĩ": "I",
4318
- "Ī": "I",
4319
- "Ĭ": "I",
4320
- "Į": "I",
4321
- "İ": "I",
4322
- "ĩ": "i",
4323
- "ī": "i",
4324
- "ĭ": "i",
4325
- "į": "i",
4326
- "ı": "i",
4327
- "Ĵ": "J",
4328
- "ĵ": "j",
4329
- "Ķ": "K",
4330
- "ķ": "k",
4331
- "ĸ": "k",
4332
- "Ĺ": "L",
4333
- "Ļ": "L",
4334
- "Ľ": "L",
4335
- "Ŀ": "L",
4336
- "Ł": "L",
4337
- "ĺ": "l",
4338
- "ļ": "l",
4339
- "ľ": "l",
4340
- "ŀ": "l",
4341
- "ł": "l",
4342
- "Ń": "N",
4343
- "Ņ": "N",
4344
- "Ň": "N",
4345
- "Ŋ": "N",
4346
- "ń": "n",
4347
- "ņ": "n",
4348
- "ň": "n",
4349
- "ŋ": "n",
4350
- "Ō": "O",
4351
- "Ŏ": "O",
4352
- "Ő": "O",
4353
- "ō": "o",
4354
- "ŏ": "o",
4355
- "ő": "o",
4356
- "Ŕ": "R",
4357
- "Ŗ": "R",
4358
- "Ř": "R",
4359
- "ŕ": "r",
4360
- "ŗ": "r",
4361
- "ř": "r",
4362
- "Ś": "S",
4363
- "Ŝ": "S",
4364
- "Ş": "S",
4365
- "Š": "S",
4366
- "ś": "s",
4367
- "ŝ": "s",
4368
- "ş": "s",
4369
- "š": "s",
4370
- "Ţ": "T",
4371
- "Ť": "T",
4372
- "Ŧ": "T",
4373
- "ţ": "t",
4374
- "ť": "t",
4375
- "ŧ": "t",
4376
- "Ũ": "U",
4377
- "Ū": "U",
4378
- "Ŭ": "U",
4379
- "Ů": "U",
4380
- "Ű": "U",
4381
- "Ų": "U",
4382
- "ũ": "u",
4383
- "ū": "u",
4384
- "ŭ": "u",
4385
- "ů": "u",
4386
- "ű": "u",
4387
- "ų": "u",
4388
- "Ŵ": "W",
4389
- "ŵ": "w",
4390
- "Ŷ": "Y",
4391
- "ŷ": "y",
4392
- "Ÿ": "Y",
4393
- "Ź": "Z",
4394
- "Ż": "Z",
4395
- "Ž": "Z",
4396
- "ź": "z",
4397
- "ż": "z",
4398
- "ž": "z",
4399
- "IJ": "IJ",
4400
- "ij": "ij",
4401
- "Œ": "Oe",
4402
- "œ": "oe",
4403
- "ʼn": "'n",
4404
- "ſ": "ss"
4215
+ "\xC0": "A",
4216
+ "\xC1": "A",
4217
+ "\xC2": "A",
4218
+ "\xC3": "A",
4219
+ "\xC4": "A",
4220
+ "\xC5": "A",
4221
+ "\xE0": "a",
4222
+ "\xE1": "a",
4223
+ "\xE2": "a",
4224
+ "\xE3": "a",
4225
+ "\xE4": "a",
4226
+ "\xE5": "a",
4227
+ "\xC7": "C",
4228
+ "\xE7": "c",
4229
+ "\xD0": "D",
4230
+ "\xF0": "d",
4231
+ "\xC8": "E",
4232
+ "\xC9": "E",
4233
+ "\xCA": "E",
4234
+ "\xCB": "E",
4235
+ "\xE8": "e",
4236
+ "\xE9": "e",
4237
+ "\xEA": "e",
4238
+ "\xEB": "e",
4239
+ "\xCC": "I",
4240
+ "\xCD": "I",
4241
+ "\xCE": "I",
4242
+ "\xCF": "I",
4243
+ "\xEC": "i",
4244
+ "\xED": "i",
4245
+ "\xEE": "i",
4246
+ "\xEF": "i",
4247
+ "\xD1": "N",
4248
+ "\xF1": "n",
4249
+ "\xD2": "O",
4250
+ "\xD3": "O",
4251
+ "\xD4": "O",
4252
+ "\xD5": "O",
4253
+ "\xD6": "O",
4254
+ "\xD8": "O",
4255
+ "\xF2": "o",
4256
+ "\xF3": "o",
4257
+ "\xF4": "o",
4258
+ "\xF5": "o",
4259
+ "\xF6": "o",
4260
+ "\xF8": "o",
4261
+ "\xD9": "U",
4262
+ "\xDA": "U",
4263
+ "\xDB": "U",
4264
+ "\xDC": "U",
4265
+ "\xF9": "u",
4266
+ "\xFA": "u",
4267
+ "\xFB": "u",
4268
+ "\xFC": "u",
4269
+ "\xDD": "Y",
4270
+ "\xFD": "y",
4271
+ "\xFF": "y",
4272
+ "\xC6": "Ae",
4273
+ "\xE6": "ae",
4274
+ "\xDE": "Th",
4275
+ "\xFE": "th",
4276
+ "\xDF": "ss",
4277
+ "\u0100": "A",
4278
+ "\u0102": "A",
4279
+ "\u0104": "A",
4280
+ "\u0101": "a",
4281
+ "\u0103": "a",
4282
+ "\u0105": "a",
4283
+ "\u0106": "C",
4284
+ "\u0108": "C",
4285
+ "\u010A": "C",
4286
+ "\u010C": "C",
4287
+ "\u0107": "c",
4288
+ "\u0109": "c",
4289
+ "\u010B": "c",
4290
+ "\u010D": "c",
4291
+ "\u010E": "D",
4292
+ "\u0110": "D",
4293
+ "\u010F": "d",
4294
+ "\u0111": "d",
4295
+ "\u0112": "E",
4296
+ "\u0114": "E",
4297
+ "\u0116": "E",
4298
+ "\u0118": "E",
4299
+ "\u011A": "E",
4300
+ "\u0113": "e",
4301
+ "\u0115": "e",
4302
+ "\u0117": "e",
4303
+ "\u0119": "e",
4304
+ "\u011B": "e",
4305
+ "\u011C": "G",
4306
+ "\u011E": "G",
4307
+ "\u0120": "G",
4308
+ "\u0122": "G",
4309
+ "\u011D": "g",
4310
+ "\u011F": "g",
4311
+ "\u0121": "g",
4312
+ "\u0123": "g",
4313
+ "\u0124": "H",
4314
+ "\u0126": "H",
4315
+ "\u0125": "h",
4316
+ "\u0127": "h",
4317
+ "\u0128": "I",
4318
+ "\u012A": "I",
4319
+ "\u012C": "I",
4320
+ "\u012E": "I",
4321
+ "\u0130": "I",
4322
+ "\u0129": "i",
4323
+ "\u012B": "i",
4324
+ "\u012D": "i",
4325
+ "\u012F": "i",
4326
+ "\u0131": "i",
4327
+ "\u0134": "J",
4328
+ "\u0135": "j",
4329
+ "\u0136": "K",
4330
+ "\u0137": "k",
4331
+ "\u0138": "k",
4332
+ "\u0139": "L",
4333
+ "\u013B": "L",
4334
+ "\u013D": "L",
4335
+ "\u013F": "L",
4336
+ "\u0141": "L",
4337
+ "\u013A": "l",
4338
+ "\u013C": "l",
4339
+ "\u013E": "l",
4340
+ "\u0140": "l",
4341
+ "\u0142": "l",
4342
+ "\u0143": "N",
4343
+ "\u0145": "N",
4344
+ "\u0147": "N",
4345
+ "\u014A": "N",
4346
+ "\u0144": "n",
4347
+ "\u0146": "n",
4348
+ "\u0148": "n",
4349
+ "\u014B": "n",
4350
+ "\u014C": "O",
4351
+ "\u014E": "O",
4352
+ "\u0150": "O",
4353
+ "\u014D": "o",
4354
+ "\u014F": "o",
4355
+ "\u0151": "o",
4356
+ "\u0154": "R",
4357
+ "\u0156": "R",
4358
+ "\u0158": "R",
4359
+ "\u0155": "r",
4360
+ "\u0157": "r",
4361
+ "\u0159": "r",
4362
+ "\u015A": "S",
4363
+ "\u015C": "S",
4364
+ "\u015E": "S",
4365
+ "\u0160": "S",
4366
+ "\u015B": "s",
4367
+ "\u015D": "s",
4368
+ "\u015F": "s",
4369
+ "\u0161": "s",
4370
+ "\u0162": "T",
4371
+ "\u0164": "T",
4372
+ "\u0166": "T",
4373
+ "\u0163": "t",
4374
+ "\u0165": "t",
4375
+ "\u0167": "t",
4376
+ "\u0168": "U",
4377
+ "\u016A": "U",
4378
+ "\u016C": "U",
4379
+ "\u016E": "U",
4380
+ "\u0170": "U",
4381
+ "\u0172": "U",
4382
+ "\u0169": "u",
4383
+ "\u016B": "u",
4384
+ "\u016D": "u",
4385
+ "\u016F": "u",
4386
+ "\u0171": "u",
4387
+ "\u0173": "u",
4388
+ "\u0174": "W",
4389
+ "\u0175": "w",
4390
+ "\u0176": "Y",
4391
+ "\u0177": "y",
4392
+ "\u0178": "Y",
4393
+ "\u0179": "Z",
4394
+ "\u017B": "Z",
4395
+ "\u017D": "Z",
4396
+ "\u017A": "z",
4397
+ "\u017C": "z",
4398
+ "\u017E": "z",
4399
+ "\u0132": "IJ",
4400
+ "\u0133": "ij",
4401
+ "\u0152": "Oe",
4402
+ "\u0153": "oe",
4403
+ "\u0149": "'n",
4404
+ "\u017F": "ss"
4405
4405
  };
4406
4406
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
4407
4407
  var freeSelf = typeof self == "object" && self && self.Object === Object && self;
@@ -22168,2843 +22168,6 @@ var require_qs = __commonJS((exports, module) => {
22168
22168
  };
22169
22169
  });
22170
22170
 
22171
- // node_modules/ws/lib/constants.js
22172
- var require_constants2 = __commonJS((exports, module) => {
22173
- var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
22174
- var hasBlob = typeof Blob !== "undefined";
22175
- if (hasBlob)
22176
- BINARY_TYPES.push("blob");
22177
- module.exports = {
22178
- BINARY_TYPES,
22179
- EMPTY_BUFFER: Buffer.alloc(0),
22180
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
22181
- hasBlob,
22182
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
22183
- kListener: Symbol("kListener"),
22184
- kStatusCode: Symbol("status-code"),
22185
- kWebSocket: Symbol("websocket"),
22186
- NOOP: () => {}
22187
- };
22188
- });
22189
-
22190
- // node_modules/ws/lib/buffer-util.js
22191
- var require_buffer_util = __commonJS((exports, module) => {
22192
- var { EMPTY_BUFFER } = require_constants2();
22193
- var FastBuffer = Buffer[Symbol.species];
22194
- function concat(list, totalLength) {
22195
- if (list.length === 0)
22196
- return EMPTY_BUFFER;
22197
- if (list.length === 1)
22198
- return list[0];
22199
- const target = Buffer.allocUnsafe(totalLength);
22200
- let offset = 0;
22201
- for (let i = 0;i < list.length; i++) {
22202
- const buf = list[i];
22203
- target.set(buf, offset);
22204
- offset += buf.length;
22205
- }
22206
- if (offset < totalLength) {
22207
- return new FastBuffer(target.buffer, target.byteOffset, offset);
22208
- }
22209
- return target;
22210
- }
22211
- function _mask(source, mask, output2, offset, length) {
22212
- for (let i = 0;i < length; i++) {
22213
- output2[offset + i] = source[i] ^ mask[i & 3];
22214
- }
22215
- }
22216
- function _unmask(buffer, mask) {
22217
- for (let i = 0;i < buffer.length; i++) {
22218
- buffer[i] ^= mask[i & 3];
22219
- }
22220
- }
22221
- function toArrayBuffer(buf) {
22222
- if (buf.length === buf.buffer.byteLength) {
22223
- return buf.buffer;
22224
- }
22225
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
22226
- }
22227
- function toBuffer(data) {
22228
- toBuffer.readOnly = true;
22229
- if (Buffer.isBuffer(data))
22230
- return data;
22231
- let buf;
22232
- if (data instanceof ArrayBuffer) {
22233
- buf = new FastBuffer(data);
22234
- } else if (ArrayBuffer.isView(data)) {
22235
- buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
22236
- } else {
22237
- buf = Buffer.from(data);
22238
- toBuffer.readOnly = false;
22239
- }
22240
- return buf;
22241
- }
22242
- module.exports = {
22243
- concat,
22244
- mask: _mask,
22245
- toArrayBuffer,
22246
- toBuffer,
22247
- unmask: _unmask
22248
- };
22249
- if (!process.env.WS_NO_BUFFER_UTIL) {
22250
- try {
22251
- const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
22252
- module.exports.mask = function(source, mask, output2, offset, length) {
22253
- if (length < 48)
22254
- _mask(source, mask, output2, offset, length);
22255
- else
22256
- bufferUtil.mask(source, mask, output2, offset, length);
22257
- };
22258
- module.exports.unmask = function(buffer, mask) {
22259
- if (buffer.length < 32)
22260
- _unmask(buffer, mask);
22261
- else
22262
- bufferUtil.unmask(buffer, mask);
22263
- };
22264
- } catch (e) {}
22265
- }
22266
- });
22267
-
22268
- // node_modules/ws/lib/limiter.js
22269
- var require_limiter = __commonJS((exports, module) => {
22270
- var kDone = Symbol("kDone");
22271
- var kRun = Symbol("kRun");
22272
-
22273
- class Limiter {
22274
- constructor(concurrency) {
22275
- this[kDone] = () => {
22276
- this.pending--;
22277
- this[kRun]();
22278
- };
22279
- this.concurrency = concurrency || Infinity;
22280
- this.jobs = [];
22281
- this.pending = 0;
22282
- }
22283
- add(job) {
22284
- this.jobs.push(job);
22285
- this[kRun]();
22286
- }
22287
- [kRun]() {
22288
- if (this.pending === this.concurrency)
22289
- return;
22290
- if (this.jobs.length) {
22291
- const job = this.jobs.shift();
22292
- this.pending++;
22293
- job(this[kDone]);
22294
- }
22295
- }
22296
- }
22297
- module.exports = Limiter;
22298
- });
22299
-
22300
- // node_modules/ws/lib/permessage-deflate.js
22301
- var require_permessage_deflate = __commonJS((exports, module) => {
22302
- var zlib = __require("zlib");
22303
- var bufferUtil = require_buffer_util();
22304
- var Limiter = require_limiter();
22305
- var { kStatusCode } = require_constants2();
22306
- var FastBuffer = Buffer[Symbol.species];
22307
- var TRAILER = Buffer.from([0, 0, 255, 255]);
22308
- var kPerMessageDeflate = Symbol("permessage-deflate");
22309
- var kTotalLength = Symbol("total-length");
22310
- var kCallback = Symbol("callback");
22311
- var kBuffers = Symbol("buffers");
22312
- var kError = Symbol("error");
22313
- var zlibLimiter;
22314
-
22315
- class PerMessageDeflate {
22316
- constructor(options, isServer, maxPayload) {
22317
- this._maxPayload = maxPayload | 0;
22318
- this._options = options || {};
22319
- this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
22320
- this._isServer = !!isServer;
22321
- this._deflate = null;
22322
- this._inflate = null;
22323
- this.params = null;
22324
- if (!zlibLimiter) {
22325
- const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
22326
- zlibLimiter = new Limiter(concurrency);
22327
- }
22328
- }
22329
- static get extensionName() {
22330
- return "permessage-deflate";
22331
- }
22332
- offer() {
22333
- const params = {};
22334
- if (this._options.serverNoContextTakeover) {
22335
- params.server_no_context_takeover = true;
22336
- }
22337
- if (this._options.clientNoContextTakeover) {
22338
- params.client_no_context_takeover = true;
22339
- }
22340
- if (this._options.serverMaxWindowBits) {
22341
- params.server_max_window_bits = this._options.serverMaxWindowBits;
22342
- }
22343
- if (this._options.clientMaxWindowBits) {
22344
- params.client_max_window_bits = this._options.clientMaxWindowBits;
22345
- } else if (this._options.clientMaxWindowBits == null) {
22346
- params.client_max_window_bits = true;
22347
- }
22348
- return params;
22349
- }
22350
- accept(configurations) {
22351
- configurations = this.normalizeParams(configurations);
22352
- this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
22353
- return this.params;
22354
- }
22355
- cleanup() {
22356
- if (this._inflate) {
22357
- this._inflate.close();
22358
- this._inflate = null;
22359
- }
22360
- if (this._deflate) {
22361
- const callback = this._deflate[kCallback];
22362
- this._deflate.close();
22363
- this._deflate = null;
22364
- if (callback) {
22365
- callback(new Error("The deflate stream was closed while data was being processed"));
22366
- }
22367
- }
22368
- }
22369
- acceptAsServer(offers) {
22370
- const opts = this._options;
22371
- const accepted = offers.find((params) => {
22372
- 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) {
22373
- return false;
22374
- }
22375
- return true;
22376
- });
22377
- if (!accepted) {
22378
- throw new Error("None of the extension offers can be accepted");
22379
- }
22380
- if (opts.serverNoContextTakeover) {
22381
- accepted.server_no_context_takeover = true;
22382
- }
22383
- if (opts.clientNoContextTakeover) {
22384
- accepted.client_no_context_takeover = true;
22385
- }
22386
- if (typeof opts.serverMaxWindowBits === "number") {
22387
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
22388
- }
22389
- if (typeof opts.clientMaxWindowBits === "number") {
22390
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
22391
- } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
22392
- delete accepted.client_max_window_bits;
22393
- }
22394
- return accepted;
22395
- }
22396
- acceptAsClient(response) {
22397
- const params = response[0];
22398
- if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
22399
- throw new Error('Unexpected parameter "client_no_context_takeover"');
22400
- }
22401
- if (!params.client_max_window_bits) {
22402
- if (typeof this._options.clientMaxWindowBits === "number") {
22403
- params.client_max_window_bits = this._options.clientMaxWindowBits;
22404
- }
22405
- } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
22406
- throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
22407
- }
22408
- return params;
22409
- }
22410
- normalizeParams(configurations) {
22411
- configurations.forEach((params) => {
22412
- Object.keys(params).forEach((key) => {
22413
- let value = params[key];
22414
- if (value.length > 1) {
22415
- throw new Error(`Parameter "${key}" must have only a single value`);
22416
- }
22417
- value = value[0];
22418
- if (key === "client_max_window_bits") {
22419
- if (value !== true) {
22420
- const num = +value;
22421
- if (!Number.isInteger(num) || num < 8 || num > 15) {
22422
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
22423
- }
22424
- value = num;
22425
- } else if (!this._isServer) {
22426
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
22427
- }
22428
- } else if (key === "server_max_window_bits") {
22429
- const num = +value;
22430
- if (!Number.isInteger(num) || num < 8 || num > 15) {
22431
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
22432
- }
22433
- value = num;
22434
- } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
22435
- if (value !== true) {
22436
- throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
22437
- }
22438
- } else {
22439
- throw new Error(`Unknown parameter "${key}"`);
22440
- }
22441
- params[key] = value;
22442
- });
22443
- });
22444
- return configurations;
22445
- }
22446
- decompress(data, fin, callback) {
22447
- zlibLimiter.add((done) => {
22448
- this._decompress(data, fin, (err, result) => {
22449
- done();
22450
- callback(err, result);
22451
- });
22452
- });
22453
- }
22454
- compress(data, fin, callback) {
22455
- zlibLimiter.add((done) => {
22456
- this._compress(data, fin, (err, result) => {
22457
- done();
22458
- callback(err, result);
22459
- });
22460
- });
22461
- }
22462
- _decompress(data, fin, callback) {
22463
- const endpoint = this._isServer ? "client" : "server";
22464
- if (!this._inflate) {
22465
- const key = `${endpoint}_max_window_bits`;
22466
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
22467
- this._inflate = zlib.createInflateRaw({
22468
- ...this._options.zlibInflateOptions,
22469
- windowBits
22470
- });
22471
- this._inflate[kPerMessageDeflate] = this;
22472
- this._inflate[kTotalLength] = 0;
22473
- this._inflate[kBuffers] = [];
22474
- this._inflate.on("error", inflateOnError);
22475
- this._inflate.on("data", inflateOnData);
22476
- }
22477
- this._inflate[kCallback] = callback;
22478
- this._inflate.write(data);
22479
- if (fin)
22480
- this._inflate.write(TRAILER);
22481
- this._inflate.flush(() => {
22482
- const err = this._inflate[kError];
22483
- if (err) {
22484
- this._inflate.close();
22485
- this._inflate = null;
22486
- callback(err);
22487
- return;
22488
- }
22489
- const data2 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
22490
- if (this._inflate._readableState.endEmitted) {
22491
- this._inflate.close();
22492
- this._inflate = null;
22493
- } else {
22494
- this._inflate[kTotalLength] = 0;
22495
- this._inflate[kBuffers] = [];
22496
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
22497
- this._inflate.reset();
22498
- }
22499
- }
22500
- callback(null, data2);
22501
- });
22502
- }
22503
- _compress(data, fin, callback) {
22504
- const endpoint = this._isServer ? "server" : "client";
22505
- if (!this._deflate) {
22506
- const key = `${endpoint}_max_window_bits`;
22507
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
22508
- this._deflate = zlib.createDeflateRaw({
22509
- ...this._options.zlibDeflateOptions,
22510
- windowBits
22511
- });
22512
- this._deflate[kTotalLength] = 0;
22513
- this._deflate[kBuffers] = [];
22514
- this._deflate.on("data", deflateOnData);
22515
- }
22516
- this._deflate[kCallback] = callback;
22517
- this._deflate.write(data);
22518
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
22519
- if (!this._deflate) {
22520
- return;
22521
- }
22522
- let data2 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
22523
- if (fin) {
22524
- data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
22525
- }
22526
- this._deflate[kCallback] = null;
22527
- this._deflate[kTotalLength] = 0;
22528
- this._deflate[kBuffers] = [];
22529
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
22530
- this._deflate.reset();
22531
- }
22532
- callback(null, data2);
22533
- });
22534
- }
22535
- }
22536
- module.exports = PerMessageDeflate;
22537
- function deflateOnData(chunk) {
22538
- this[kBuffers].push(chunk);
22539
- this[kTotalLength] += chunk.length;
22540
- }
22541
- function inflateOnData(chunk) {
22542
- this[kTotalLength] += chunk.length;
22543
- if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
22544
- this[kBuffers].push(chunk);
22545
- return;
22546
- }
22547
- this[kError] = new RangeError("Max payload size exceeded");
22548
- this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
22549
- this[kError][kStatusCode] = 1009;
22550
- this.removeListener("data", inflateOnData);
22551
- this.reset();
22552
- }
22553
- function inflateOnError(err) {
22554
- this[kPerMessageDeflate]._inflate = null;
22555
- if (this[kError]) {
22556
- this[kCallback](this[kError]);
22557
- return;
22558
- }
22559
- err[kStatusCode] = 1007;
22560
- this[kCallback](err);
22561
- }
22562
- });
22563
-
22564
- // node_modules/ws/lib/validation.js
22565
- var require_validation = __commonJS((exports, module) => {
22566
- var { isUtf8 } = __require("buffer");
22567
- var { hasBlob } = require_constants2();
22568
- var tokenChars = [
22569
- 0,
22570
- 0,
22571
- 0,
22572
- 0,
22573
- 0,
22574
- 0,
22575
- 0,
22576
- 0,
22577
- 0,
22578
- 0,
22579
- 0,
22580
- 0,
22581
- 0,
22582
- 0,
22583
- 0,
22584
- 0,
22585
- 0,
22586
- 0,
22587
- 0,
22588
- 0,
22589
- 0,
22590
- 0,
22591
- 0,
22592
- 0,
22593
- 0,
22594
- 0,
22595
- 0,
22596
- 0,
22597
- 0,
22598
- 0,
22599
- 0,
22600
- 0,
22601
- 0,
22602
- 1,
22603
- 0,
22604
- 1,
22605
- 1,
22606
- 1,
22607
- 1,
22608
- 1,
22609
- 0,
22610
- 0,
22611
- 1,
22612
- 1,
22613
- 0,
22614
- 1,
22615
- 1,
22616
- 0,
22617
- 1,
22618
- 1,
22619
- 1,
22620
- 1,
22621
- 1,
22622
- 1,
22623
- 1,
22624
- 1,
22625
- 1,
22626
- 1,
22627
- 0,
22628
- 0,
22629
- 0,
22630
- 0,
22631
- 0,
22632
- 0,
22633
- 0,
22634
- 1,
22635
- 1,
22636
- 1,
22637
- 1,
22638
- 1,
22639
- 1,
22640
- 1,
22641
- 1,
22642
- 1,
22643
- 1,
22644
- 1,
22645
- 1,
22646
- 1,
22647
- 1,
22648
- 1,
22649
- 1,
22650
- 1,
22651
- 1,
22652
- 1,
22653
- 1,
22654
- 1,
22655
- 1,
22656
- 1,
22657
- 1,
22658
- 1,
22659
- 1,
22660
- 0,
22661
- 0,
22662
- 0,
22663
- 1,
22664
- 1,
22665
- 1,
22666
- 1,
22667
- 1,
22668
- 1,
22669
- 1,
22670
- 1,
22671
- 1,
22672
- 1,
22673
- 1,
22674
- 1,
22675
- 1,
22676
- 1,
22677
- 1,
22678
- 1,
22679
- 1,
22680
- 1,
22681
- 1,
22682
- 1,
22683
- 1,
22684
- 1,
22685
- 1,
22686
- 1,
22687
- 1,
22688
- 1,
22689
- 1,
22690
- 1,
22691
- 1,
22692
- 0,
22693
- 1,
22694
- 0,
22695
- 1,
22696
- 0
22697
- ];
22698
- function isValidStatusCode(code) {
22699
- return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
22700
- }
22701
- function _isValidUTF8(buf) {
22702
- const len = buf.length;
22703
- let i = 0;
22704
- while (i < len) {
22705
- if ((buf[i] & 128) === 0) {
22706
- i++;
22707
- } else if ((buf[i] & 224) === 192) {
22708
- if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
22709
- return false;
22710
- }
22711
- i += 2;
22712
- } else if ((buf[i] & 240) === 224) {
22713
- if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) {
22714
- return false;
22715
- }
22716
- i += 3;
22717
- } else if ((buf[i] & 248) === 240) {
22718
- 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 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
22719
- return false;
22720
- }
22721
- i += 4;
22722
- } else {
22723
- return false;
22724
- }
22725
- }
22726
- return true;
22727
- }
22728
- function isBlob(value) {
22729
- return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
22730
- }
22731
- module.exports = {
22732
- isBlob,
22733
- isValidStatusCode,
22734
- isValidUTF8: _isValidUTF8,
22735
- tokenChars
22736
- };
22737
- if (isUtf8) {
22738
- module.exports.isValidUTF8 = function(buf) {
22739
- return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
22740
- };
22741
- } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
22742
- try {
22743
- const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
22744
- module.exports.isValidUTF8 = function(buf) {
22745
- return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
22746
- };
22747
- } catch (e) {}
22748
- }
22749
- });
22750
-
22751
- // node_modules/ws/lib/receiver.js
22752
- var require_receiver = __commonJS((exports, module) => {
22753
- var { Writable } = __require("stream");
22754
- var PerMessageDeflate = require_permessage_deflate();
22755
- var {
22756
- BINARY_TYPES,
22757
- EMPTY_BUFFER,
22758
- kStatusCode,
22759
- kWebSocket
22760
- } = require_constants2();
22761
- var { concat, toArrayBuffer, unmask } = require_buffer_util();
22762
- var { isValidStatusCode, isValidUTF8 } = require_validation();
22763
- var FastBuffer = Buffer[Symbol.species];
22764
- var GET_INFO = 0;
22765
- var GET_PAYLOAD_LENGTH_16 = 1;
22766
- var GET_PAYLOAD_LENGTH_64 = 2;
22767
- var GET_MASK = 3;
22768
- var GET_DATA = 4;
22769
- var INFLATING = 5;
22770
- var DEFER_EVENT = 6;
22771
-
22772
- class Receiver extends Writable {
22773
- constructor(options = {}) {
22774
- super();
22775
- this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
22776
- this._binaryType = options.binaryType || BINARY_TYPES[0];
22777
- this._extensions = options.extensions || {};
22778
- this._isServer = !!options.isServer;
22779
- this._maxPayload = options.maxPayload | 0;
22780
- this._skipUTF8Validation = !!options.skipUTF8Validation;
22781
- this[kWebSocket] = undefined;
22782
- this._bufferedBytes = 0;
22783
- this._buffers = [];
22784
- this._compressed = false;
22785
- this._payloadLength = 0;
22786
- this._mask = undefined;
22787
- this._fragmented = 0;
22788
- this._masked = false;
22789
- this._fin = false;
22790
- this._opcode = 0;
22791
- this._totalPayloadLength = 0;
22792
- this._messageLength = 0;
22793
- this._fragments = [];
22794
- this._errored = false;
22795
- this._loop = false;
22796
- this._state = GET_INFO;
22797
- }
22798
- _write(chunk, encoding, cb) {
22799
- if (this._opcode === 8 && this._state == GET_INFO)
22800
- return cb();
22801
- this._bufferedBytes += chunk.length;
22802
- this._buffers.push(chunk);
22803
- this.startLoop(cb);
22804
- }
22805
- consume(n) {
22806
- this._bufferedBytes -= n;
22807
- if (n === this._buffers[0].length)
22808
- return this._buffers.shift();
22809
- if (n < this._buffers[0].length) {
22810
- const buf = this._buffers[0];
22811
- this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
22812
- return new FastBuffer(buf.buffer, buf.byteOffset, n);
22813
- }
22814
- const dst = Buffer.allocUnsafe(n);
22815
- do {
22816
- const buf = this._buffers[0];
22817
- const offset = dst.length - n;
22818
- if (n >= buf.length) {
22819
- dst.set(this._buffers.shift(), offset);
22820
- } else {
22821
- dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
22822
- this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
22823
- }
22824
- n -= buf.length;
22825
- } while (n > 0);
22826
- return dst;
22827
- }
22828
- startLoop(cb) {
22829
- this._loop = true;
22830
- do {
22831
- switch (this._state) {
22832
- case GET_INFO:
22833
- this.getInfo(cb);
22834
- break;
22835
- case GET_PAYLOAD_LENGTH_16:
22836
- this.getPayloadLength16(cb);
22837
- break;
22838
- case GET_PAYLOAD_LENGTH_64:
22839
- this.getPayloadLength64(cb);
22840
- break;
22841
- case GET_MASK:
22842
- this.getMask();
22843
- break;
22844
- case GET_DATA:
22845
- this.getData(cb);
22846
- break;
22847
- case INFLATING:
22848
- case DEFER_EVENT:
22849
- this._loop = false;
22850
- return;
22851
- }
22852
- } while (this._loop);
22853
- if (!this._errored)
22854
- cb();
22855
- }
22856
- getInfo(cb) {
22857
- if (this._bufferedBytes < 2) {
22858
- this._loop = false;
22859
- return;
22860
- }
22861
- const buf = this.consume(2);
22862
- if ((buf[0] & 48) !== 0) {
22863
- const error = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
22864
- cb(error);
22865
- return;
22866
- }
22867
- const compressed = (buf[0] & 64) === 64;
22868
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
22869
- const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
22870
- cb(error);
22871
- return;
22872
- }
22873
- this._fin = (buf[0] & 128) === 128;
22874
- this._opcode = buf[0] & 15;
22875
- this._payloadLength = buf[1] & 127;
22876
- if (this._opcode === 0) {
22877
- if (compressed) {
22878
- const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
22879
- cb(error);
22880
- return;
22881
- }
22882
- if (!this._fragmented) {
22883
- const error = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
22884
- cb(error);
22885
- return;
22886
- }
22887
- this._opcode = this._fragmented;
22888
- } else if (this._opcode === 1 || this._opcode === 2) {
22889
- if (this._fragmented) {
22890
- const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
22891
- cb(error);
22892
- return;
22893
- }
22894
- this._compressed = compressed;
22895
- } else if (this._opcode > 7 && this._opcode < 11) {
22896
- if (!this._fin) {
22897
- const error = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
22898
- cb(error);
22899
- return;
22900
- }
22901
- if (compressed) {
22902
- const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
22903
- cb(error);
22904
- return;
22905
- }
22906
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
22907
- const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
22908
- cb(error);
22909
- return;
22910
- }
22911
- } else {
22912
- const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
22913
- cb(error);
22914
- return;
22915
- }
22916
- if (!this._fin && !this._fragmented)
22917
- this._fragmented = this._opcode;
22918
- this._masked = (buf[1] & 128) === 128;
22919
- if (this._isServer) {
22920
- if (!this._masked) {
22921
- const error = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
22922
- cb(error);
22923
- return;
22924
- }
22925
- } else if (this._masked) {
22926
- const error = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
22927
- cb(error);
22928
- return;
22929
- }
22930
- if (this._payloadLength === 126)
22931
- this._state = GET_PAYLOAD_LENGTH_16;
22932
- else if (this._payloadLength === 127)
22933
- this._state = GET_PAYLOAD_LENGTH_64;
22934
- else
22935
- this.haveLength(cb);
22936
- }
22937
- getPayloadLength16(cb) {
22938
- if (this._bufferedBytes < 2) {
22939
- this._loop = false;
22940
- return;
22941
- }
22942
- this._payloadLength = this.consume(2).readUInt16BE(0);
22943
- this.haveLength(cb);
22944
- }
22945
- getPayloadLength64(cb) {
22946
- if (this._bufferedBytes < 8) {
22947
- this._loop = false;
22948
- return;
22949
- }
22950
- const buf = this.consume(8);
22951
- const num = buf.readUInt32BE(0);
22952
- if (num > Math.pow(2, 53 - 32) - 1) {
22953
- const error = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
22954
- cb(error);
22955
- return;
22956
- }
22957
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
22958
- this.haveLength(cb);
22959
- }
22960
- haveLength(cb) {
22961
- if (this._payloadLength && this._opcode < 8) {
22962
- this._totalPayloadLength += this._payloadLength;
22963
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
22964
- const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
22965
- cb(error);
22966
- return;
22967
- }
22968
- }
22969
- if (this._masked)
22970
- this._state = GET_MASK;
22971
- else
22972
- this._state = GET_DATA;
22973
- }
22974
- getMask() {
22975
- if (this._bufferedBytes < 4) {
22976
- this._loop = false;
22977
- return;
22978
- }
22979
- this._mask = this.consume(4);
22980
- this._state = GET_DATA;
22981
- }
22982
- getData(cb) {
22983
- let data = EMPTY_BUFFER;
22984
- if (this._payloadLength) {
22985
- if (this._bufferedBytes < this._payloadLength) {
22986
- this._loop = false;
22987
- return;
22988
- }
22989
- data = this.consume(this._payloadLength);
22990
- if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
22991
- unmask(data, this._mask);
22992
- }
22993
- }
22994
- if (this._opcode > 7) {
22995
- this.controlMessage(data, cb);
22996
- return;
22997
- }
22998
- if (this._compressed) {
22999
- this._state = INFLATING;
23000
- this.decompress(data, cb);
23001
- return;
23002
- }
23003
- if (data.length) {
23004
- this._messageLength = this._totalPayloadLength;
23005
- this._fragments.push(data);
23006
- }
23007
- this.dataMessage(cb);
23008
- }
23009
- decompress(data, cb) {
23010
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
23011
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
23012
- if (err)
23013
- return cb(err);
23014
- if (buf.length) {
23015
- this._messageLength += buf.length;
23016
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
23017
- const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
23018
- cb(error);
23019
- return;
23020
- }
23021
- this._fragments.push(buf);
23022
- }
23023
- this.dataMessage(cb);
23024
- if (this._state === GET_INFO)
23025
- this.startLoop(cb);
23026
- });
23027
- }
23028
- dataMessage(cb) {
23029
- if (!this._fin) {
23030
- this._state = GET_INFO;
23031
- return;
23032
- }
23033
- const messageLength = this._messageLength;
23034
- const fragments = this._fragments;
23035
- this._totalPayloadLength = 0;
23036
- this._messageLength = 0;
23037
- this._fragmented = 0;
23038
- this._fragments = [];
23039
- if (this._opcode === 2) {
23040
- let data;
23041
- if (this._binaryType === "nodebuffer") {
23042
- data = concat(fragments, messageLength);
23043
- } else if (this._binaryType === "arraybuffer") {
23044
- data = toArrayBuffer(concat(fragments, messageLength));
23045
- } else if (this._binaryType === "blob") {
23046
- data = new Blob(fragments);
23047
- } else {
23048
- data = fragments;
23049
- }
23050
- if (this._allowSynchronousEvents) {
23051
- this.emit("message", data, true);
23052
- this._state = GET_INFO;
23053
- } else {
23054
- this._state = DEFER_EVENT;
23055
- setImmediate(() => {
23056
- this.emit("message", data, true);
23057
- this._state = GET_INFO;
23058
- this.startLoop(cb);
23059
- });
23060
- }
23061
- } else {
23062
- const buf = concat(fragments, messageLength);
23063
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
23064
- const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
23065
- cb(error);
23066
- return;
23067
- }
23068
- if (this._state === INFLATING || this._allowSynchronousEvents) {
23069
- this.emit("message", buf, false);
23070
- this._state = GET_INFO;
23071
- } else {
23072
- this._state = DEFER_EVENT;
23073
- setImmediate(() => {
23074
- this.emit("message", buf, false);
23075
- this._state = GET_INFO;
23076
- this.startLoop(cb);
23077
- });
23078
- }
23079
- }
23080
- }
23081
- controlMessage(data, cb) {
23082
- if (this._opcode === 8) {
23083
- if (data.length === 0) {
23084
- this._loop = false;
23085
- this.emit("conclude", 1005, EMPTY_BUFFER);
23086
- this.end();
23087
- } else {
23088
- const code = data.readUInt16BE(0);
23089
- if (!isValidStatusCode(code)) {
23090
- const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
23091
- cb(error);
23092
- return;
23093
- }
23094
- const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
23095
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
23096
- const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
23097
- cb(error);
23098
- return;
23099
- }
23100
- this._loop = false;
23101
- this.emit("conclude", code, buf);
23102
- this.end();
23103
- }
23104
- this._state = GET_INFO;
23105
- return;
23106
- }
23107
- if (this._allowSynchronousEvents) {
23108
- this.emit(this._opcode === 9 ? "ping" : "pong", data);
23109
- this._state = GET_INFO;
23110
- } else {
23111
- this._state = DEFER_EVENT;
23112
- setImmediate(() => {
23113
- this.emit(this._opcode === 9 ? "ping" : "pong", data);
23114
- this._state = GET_INFO;
23115
- this.startLoop(cb);
23116
- });
23117
- }
23118
- }
23119
- createError(ErrorCtor, message, prefix, statusCode, errorCode) {
23120
- this._loop = false;
23121
- this._errored = true;
23122
- const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
23123
- Error.captureStackTrace(err, this.createError);
23124
- err.code = errorCode;
23125
- err[kStatusCode] = statusCode;
23126
- return err;
23127
- }
23128
- }
23129
- module.exports = Receiver;
23130
- });
23131
-
23132
- // node_modules/ws/lib/sender.js
23133
- var require_sender = __commonJS((exports, module) => {
23134
- var { Duplex } = __require("stream");
23135
- var { randomFillSync } = __require("crypto");
23136
- var PerMessageDeflate = require_permessage_deflate();
23137
- var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants2();
23138
- var { isBlob, isValidStatusCode } = require_validation();
23139
- var { mask: applyMask, toBuffer } = require_buffer_util();
23140
- var kByteLength = Symbol("kByteLength");
23141
- var maskBuffer = Buffer.alloc(4);
23142
- var RANDOM_POOL_SIZE = 8 * 1024;
23143
- var randomPool;
23144
- var randomPoolPointer = RANDOM_POOL_SIZE;
23145
- var DEFAULT = 0;
23146
- var DEFLATING = 1;
23147
- var GET_BLOB_DATA = 2;
23148
-
23149
- class Sender {
23150
- constructor(socket, extensions, generateMask) {
23151
- this._extensions = extensions || {};
23152
- if (generateMask) {
23153
- this._generateMask = generateMask;
23154
- this._maskBuffer = Buffer.alloc(4);
23155
- }
23156
- this._socket = socket;
23157
- this._firstFragment = true;
23158
- this._compress = false;
23159
- this._bufferedBytes = 0;
23160
- this._queue = [];
23161
- this._state = DEFAULT;
23162
- this.onerror = NOOP;
23163
- this[kWebSocket] = undefined;
23164
- }
23165
- static frame(data, options) {
23166
- let mask;
23167
- let merge2 = false;
23168
- let offset = 2;
23169
- let skipMasking = false;
23170
- if (options.mask) {
23171
- mask = options.maskBuffer || maskBuffer;
23172
- if (options.generateMask) {
23173
- options.generateMask(mask);
23174
- } else {
23175
- if (randomPoolPointer === RANDOM_POOL_SIZE) {
23176
- if (randomPool === undefined) {
23177
- randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
23178
- }
23179
- randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
23180
- randomPoolPointer = 0;
23181
- }
23182
- mask[0] = randomPool[randomPoolPointer++];
23183
- mask[1] = randomPool[randomPoolPointer++];
23184
- mask[2] = randomPool[randomPoolPointer++];
23185
- mask[3] = randomPool[randomPoolPointer++];
23186
- }
23187
- skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
23188
- offset = 6;
23189
- }
23190
- let dataLength;
23191
- if (typeof data === "string") {
23192
- if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
23193
- dataLength = options[kByteLength];
23194
- } else {
23195
- data = Buffer.from(data);
23196
- dataLength = data.length;
23197
- }
23198
- } else {
23199
- dataLength = data.length;
23200
- merge2 = options.mask && options.readOnly && !skipMasking;
23201
- }
23202
- let payloadLength = dataLength;
23203
- if (dataLength >= 65536) {
23204
- offset += 8;
23205
- payloadLength = 127;
23206
- } else if (dataLength > 125) {
23207
- offset += 2;
23208
- payloadLength = 126;
23209
- }
23210
- const target = Buffer.allocUnsafe(merge2 ? dataLength + offset : offset);
23211
- target[0] = options.fin ? options.opcode | 128 : options.opcode;
23212
- if (options.rsv1)
23213
- target[0] |= 64;
23214
- target[1] = payloadLength;
23215
- if (payloadLength === 126) {
23216
- target.writeUInt16BE(dataLength, 2);
23217
- } else if (payloadLength === 127) {
23218
- target[2] = target[3] = 0;
23219
- target.writeUIntBE(dataLength, 4, 6);
23220
- }
23221
- if (!options.mask)
23222
- return [target, data];
23223
- target[1] |= 128;
23224
- target[offset - 4] = mask[0];
23225
- target[offset - 3] = mask[1];
23226
- target[offset - 2] = mask[2];
23227
- target[offset - 1] = mask[3];
23228
- if (skipMasking)
23229
- return [target, data];
23230
- if (merge2) {
23231
- applyMask(data, mask, target, offset, dataLength);
23232
- return [target];
23233
- }
23234
- applyMask(data, mask, data, 0, dataLength);
23235
- return [target, data];
23236
- }
23237
- close(code, data, mask, cb) {
23238
- let buf;
23239
- if (code === undefined) {
23240
- buf = EMPTY_BUFFER;
23241
- } else if (typeof code !== "number" || !isValidStatusCode(code)) {
23242
- throw new TypeError("First argument must be a valid error code number");
23243
- } else if (data === undefined || !data.length) {
23244
- buf = Buffer.allocUnsafe(2);
23245
- buf.writeUInt16BE(code, 0);
23246
- } else {
23247
- const length = Buffer.byteLength(data);
23248
- if (length > 123) {
23249
- throw new RangeError("The message must not be greater than 123 bytes");
23250
- }
23251
- buf = Buffer.allocUnsafe(2 + length);
23252
- buf.writeUInt16BE(code, 0);
23253
- if (typeof data === "string") {
23254
- buf.write(data, 2);
23255
- } else {
23256
- buf.set(data, 2);
23257
- }
23258
- }
23259
- const options = {
23260
- [kByteLength]: buf.length,
23261
- fin: true,
23262
- generateMask: this._generateMask,
23263
- mask,
23264
- maskBuffer: this._maskBuffer,
23265
- opcode: 8,
23266
- readOnly: false,
23267
- rsv1: false
23268
- };
23269
- if (this._state !== DEFAULT) {
23270
- this.enqueue([this.dispatch, buf, false, options, cb]);
23271
- } else {
23272
- this.sendFrame(Sender.frame(buf, options), cb);
23273
- }
23274
- }
23275
- ping(data, mask, cb) {
23276
- let byteLength;
23277
- let readOnly;
23278
- if (typeof data === "string") {
23279
- byteLength = Buffer.byteLength(data);
23280
- readOnly = false;
23281
- } else if (isBlob(data)) {
23282
- byteLength = data.size;
23283
- readOnly = false;
23284
- } else {
23285
- data = toBuffer(data);
23286
- byteLength = data.length;
23287
- readOnly = toBuffer.readOnly;
23288
- }
23289
- if (byteLength > 125) {
23290
- throw new RangeError("The data size must not be greater than 125 bytes");
23291
- }
23292
- const options = {
23293
- [kByteLength]: byteLength,
23294
- fin: true,
23295
- generateMask: this._generateMask,
23296
- mask,
23297
- maskBuffer: this._maskBuffer,
23298
- opcode: 9,
23299
- readOnly,
23300
- rsv1: false
23301
- };
23302
- if (isBlob(data)) {
23303
- if (this._state !== DEFAULT) {
23304
- this.enqueue([this.getBlobData, data, false, options, cb]);
23305
- } else {
23306
- this.getBlobData(data, false, options, cb);
23307
- }
23308
- } else if (this._state !== DEFAULT) {
23309
- this.enqueue([this.dispatch, data, false, options, cb]);
23310
- } else {
23311
- this.sendFrame(Sender.frame(data, options), cb);
23312
- }
23313
- }
23314
- pong(data, mask, cb) {
23315
- let byteLength;
23316
- let readOnly;
23317
- if (typeof data === "string") {
23318
- byteLength = Buffer.byteLength(data);
23319
- readOnly = false;
23320
- } else if (isBlob(data)) {
23321
- byteLength = data.size;
23322
- readOnly = false;
23323
- } else {
23324
- data = toBuffer(data);
23325
- byteLength = data.length;
23326
- readOnly = toBuffer.readOnly;
23327
- }
23328
- if (byteLength > 125) {
23329
- throw new RangeError("The data size must not be greater than 125 bytes");
23330
- }
23331
- const options = {
23332
- [kByteLength]: byteLength,
23333
- fin: true,
23334
- generateMask: this._generateMask,
23335
- mask,
23336
- maskBuffer: this._maskBuffer,
23337
- opcode: 10,
23338
- readOnly,
23339
- rsv1: false
23340
- };
23341
- if (isBlob(data)) {
23342
- if (this._state !== DEFAULT) {
23343
- this.enqueue([this.getBlobData, data, false, options, cb]);
23344
- } else {
23345
- this.getBlobData(data, false, options, cb);
23346
- }
23347
- } else if (this._state !== DEFAULT) {
23348
- this.enqueue([this.dispatch, data, false, options, cb]);
23349
- } else {
23350
- this.sendFrame(Sender.frame(data, options), cb);
23351
- }
23352
- }
23353
- send(data, options, cb) {
23354
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
23355
- let opcode = options.binary ? 2 : 1;
23356
- let rsv1 = options.compress;
23357
- let byteLength;
23358
- let readOnly;
23359
- if (typeof data === "string") {
23360
- byteLength = Buffer.byteLength(data);
23361
- readOnly = false;
23362
- } else if (isBlob(data)) {
23363
- byteLength = data.size;
23364
- readOnly = false;
23365
- } else {
23366
- data = toBuffer(data);
23367
- byteLength = data.length;
23368
- readOnly = toBuffer.readOnly;
23369
- }
23370
- if (this._firstFragment) {
23371
- this._firstFragment = false;
23372
- if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
23373
- rsv1 = byteLength >= perMessageDeflate._threshold;
23374
- }
23375
- this._compress = rsv1;
23376
- } else {
23377
- rsv1 = false;
23378
- opcode = 0;
23379
- }
23380
- if (options.fin)
23381
- this._firstFragment = true;
23382
- const opts = {
23383
- [kByteLength]: byteLength,
23384
- fin: options.fin,
23385
- generateMask: this._generateMask,
23386
- mask: options.mask,
23387
- maskBuffer: this._maskBuffer,
23388
- opcode,
23389
- readOnly,
23390
- rsv1
23391
- };
23392
- if (isBlob(data)) {
23393
- if (this._state !== DEFAULT) {
23394
- this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
23395
- } else {
23396
- this.getBlobData(data, this._compress, opts, cb);
23397
- }
23398
- } else if (this._state !== DEFAULT) {
23399
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
23400
- } else {
23401
- this.dispatch(data, this._compress, opts, cb);
23402
- }
23403
- }
23404
- getBlobData(blob, compress, options, cb) {
23405
- this._bufferedBytes += options[kByteLength];
23406
- this._state = GET_BLOB_DATA;
23407
- blob.arrayBuffer().then((arrayBuffer) => {
23408
- if (this._socket.destroyed) {
23409
- const err = new Error("The socket was closed while the blob was being read");
23410
- process.nextTick(callCallbacks, this, err, cb);
23411
- return;
23412
- }
23413
- this._bufferedBytes -= options[kByteLength];
23414
- const data = toBuffer(arrayBuffer);
23415
- if (!compress) {
23416
- this._state = DEFAULT;
23417
- this.sendFrame(Sender.frame(data, options), cb);
23418
- this.dequeue();
23419
- } else {
23420
- this.dispatch(data, compress, options, cb);
23421
- }
23422
- }).catch((err) => {
23423
- process.nextTick(onError, this, err, cb);
23424
- });
23425
- }
23426
- dispatch(data, compress, options, cb) {
23427
- if (!compress) {
23428
- this.sendFrame(Sender.frame(data, options), cb);
23429
- return;
23430
- }
23431
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
23432
- this._bufferedBytes += options[kByteLength];
23433
- this._state = DEFLATING;
23434
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
23435
- if (this._socket.destroyed) {
23436
- const err = new Error("The socket was closed while data was being compressed");
23437
- callCallbacks(this, err, cb);
23438
- return;
23439
- }
23440
- this._bufferedBytes -= options[kByteLength];
23441
- this._state = DEFAULT;
23442
- options.readOnly = false;
23443
- this.sendFrame(Sender.frame(buf, options), cb);
23444
- this.dequeue();
23445
- });
23446
- }
23447
- dequeue() {
23448
- while (this._state === DEFAULT && this._queue.length) {
23449
- const params = this._queue.shift();
23450
- this._bufferedBytes -= params[3][kByteLength];
23451
- Reflect.apply(params[0], this, params.slice(1));
23452
- }
23453
- }
23454
- enqueue(params) {
23455
- this._bufferedBytes += params[3][kByteLength];
23456
- this._queue.push(params);
23457
- }
23458
- sendFrame(list, cb) {
23459
- if (list.length === 2) {
23460
- this._socket.cork();
23461
- this._socket.write(list[0]);
23462
- this._socket.write(list[1], cb);
23463
- this._socket.uncork();
23464
- } else {
23465
- this._socket.write(list[0], cb);
23466
- }
23467
- }
23468
- }
23469
- module.exports = Sender;
23470
- function callCallbacks(sender, err, cb) {
23471
- if (typeof cb === "function")
23472
- cb(err);
23473
- for (let i = 0;i < sender._queue.length; i++) {
23474
- const params = sender._queue[i];
23475
- const callback = params[params.length - 1];
23476
- if (typeof callback === "function")
23477
- callback(err);
23478
- }
23479
- }
23480
- function onError(sender, err, cb) {
23481
- callCallbacks(sender, err, cb);
23482
- sender.onerror(err);
23483
- }
23484
- });
23485
-
23486
- // node_modules/ws/lib/event-target.js
23487
- var require_event_target = __commonJS((exports, module) => {
23488
- var { kForOnEventAttribute, kListener } = require_constants2();
23489
- var kCode = Symbol("kCode");
23490
- var kData = Symbol("kData");
23491
- var kError = Symbol("kError");
23492
- var kMessage = Symbol("kMessage");
23493
- var kReason = Symbol("kReason");
23494
- var kTarget = Symbol("kTarget");
23495
- var kType = Symbol("kType");
23496
- var kWasClean = Symbol("kWasClean");
23497
-
23498
- class Event {
23499
- constructor(type2) {
23500
- this[kTarget] = null;
23501
- this[kType] = type2;
23502
- }
23503
- get target() {
23504
- return this[kTarget];
23505
- }
23506
- get type() {
23507
- return this[kType];
23508
- }
23509
- }
23510
- Object.defineProperty(Event.prototype, "target", { enumerable: true });
23511
- Object.defineProperty(Event.prototype, "type", { enumerable: true });
23512
-
23513
- class CloseEvent extends Event {
23514
- constructor(type2, options = {}) {
23515
- super(type2);
23516
- this[kCode] = options.code === undefined ? 0 : options.code;
23517
- this[kReason] = options.reason === undefined ? "" : options.reason;
23518
- this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
23519
- }
23520
- get code() {
23521
- return this[kCode];
23522
- }
23523
- get reason() {
23524
- return this[kReason];
23525
- }
23526
- get wasClean() {
23527
- return this[kWasClean];
23528
- }
23529
- }
23530
- Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
23531
- Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
23532
- Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
23533
-
23534
- class ErrorEvent extends Event {
23535
- constructor(type2, options = {}) {
23536
- super(type2);
23537
- this[kError] = options.error === undefined ? null : options.error;
23538
- this[kMessage] = options.message === undefined ? "" : options.message;
23539
- }
23540
- get error() {
23541
- return this[kError];
23542
- }
23543
- get message() {
23544
- return this[kMessage];
23545
- }
23546
- }
23547
- Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
23548
- Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
23549
-
23550
- class MessageEvent extends Event {
23551
- constructor(type2, options = {}) {
23552
- super(type2);
23553
- this[kData] = options.data === undefined ? null : options.data;
23554
- }
23555
- get data() {
23556
- return this[kData];
23557
- }
23558
- }
23559
- Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
23560
- var EventTarget = {
23561
- addEventListener(type2, handler, options = {}) {
23562
- for (const listener of this.listeners(type2)) {
23563
- if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
23564
- return;
23565
- }
23566
- }
23567
- let wrapper;
23568
- if (type2 === "message") {
23569
- wrapper = function onMessage(data, isBinary) {
23570
- const event = new MessageEvent("message", {
23571
- data: isBinary ? data : data.toString()
23572
- });
23573
- event[kTarget] = this;
23574
- callListener(handler, this, event);
23575
- };
23576
- } else if (type2 === "close") {
23577
- wrapper = function onClose(code, message) {
23578
- const event = new CloseEvent("close", {
23579
- code,
23580
- reason: message.toString(),
23581
- wasClean: this._closeFrameReceived && this._closeFrameSent
23582
- });
23583
- event[kTarget] = this;
23584
- callListener(handler, this, event);
23585
- };
23586
- } else if (type2 === "error") {
23587
- wrapper = function onError(error) {
23588
- const event = new ErrorEvent("error", {
23589
- error,
23590
- message: error.message
23591
- });
23592
- event[kTarget] = this;
23593
- callListener(handler, this, event);
23594
- };
23595
- } else if (type2 === "open") {
23596
- wrapper = function onOpen() {
23597
- const event = new Event("open");
23598
- event[kTarget] = this;
23599
- callListener(handler, this, event);
23600
- };
23601
- } else {
23602
- return;
23603
- }
23604
- wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
23605
- wrapper[kListener] = handler;
23606
- if (options.once) {
23607
- this.once(type2, wrapper);
23608
- } else {
23609
- this.on(type2, wrapper);
23610
- }
23611
- },
23612
- removeEventListener(type2, handler) {
23613
- for (const listener of this.listeners(type2)) {
23614
- if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
23615
- this.removeListener(type2, listener);
23616
- break;
23617
- }
23618
- }
23619
- }
23620
- };
23621
- module.exports = {
23622
- CloseEvent,
23623
- ErrorEvent,
23624
- Event,
23625
- EventTarget,
23626
- MessageEvent
23627
- };
23628
- function callListener(listener, thisArg, event) {
23629
- if (typeof listener === "object" && listener.handleEvent) {
23630
- listener.handleEvent.call(listener, event);
23631
- } else {
23632
- listener.call(thisArg, event);
23633
- }
23634
- }
23635
- });
23636
-
23637
- // node_modules/ws/lib/extension.js
23638
- var require_extension = __commonJS((exports, module) => {
23639
- var { tokenChars } = require_validation();
23640
- function push(dest, name, elem) {
23641
- if (dest[name] === undefined)
23642
- dest[name] = [elem];
23643
- else
23644
- dest[name].push(elem);
23645
- }
23646
- function parse(header) {
23647
- const offers = Object.create(null);
23648
- let params = Object.create(null);
23649
- let mustUnescape = false;
23650
- let isEscaping = false;
23651
- let inQuotes = false;
23652
- let extensionName;
23653
- let paramName;
23654
- let start = -1;
23655
- let code = -1;
23656
- let end = -1;
23657
- let i = 0;
23658
- for (;i < header.length; i++) {
23659
- code = header.charCodeAt(i);
23660
- if (extensionName === undefined) {
23661
- if (end === -1 && tokenChars[code] === 1) {
23662
- if (start === -1)
23663
- start = i;
23664
- } else if (i !== 0 && (code === 32 || code === 9)) {
23665
- if (end === -1 && start !== -1)
23666
- end = i;
23667
- } else if (code === 59 || code === 44) {
23668
- if (start === -1) {
23669
- throw new SyntaxError(`Unexpected character at index ${i}`);
23670
- }
23671
- if (end === -1)
23672
- end = i;
23673
- const name = header.slice(start, end);
23674
- if (code === 44) {
23675
- push(offers, name, params);
23676
- params = Object.create(null);
23677
- } else {
23678
- extensionName = name;
23679
- }
23680
- start = end = -1;
23681
- } else {
23682
- throw new SyntaxError(`Unexpected character at index ${i}`);
23683
- }
23684
- } else if (paramName === undefined) {
23685
- if (end === -1 && tokenChars[code] === 1) {
23686
- if (start === -1)
23687
- start = i;
23688
- } else if (code === 32 || code === 9) {
23689
- if (end === -1 && start !== -1)
23690
- end = i;
23691
- } else if (code === 59 || code === 44) {
23692
- if (start === -1) {
23693
- throw new SyntaxError(`Unexpected character at index ${i}`);
23694
- }
23695
- if (end === -1)
23696
- end = i;
23697
- push(params, header.slice(start, end), true);
23698
- if (code === 44) {
23699
- push(offers, extensionName, params);
23700
- params = Object.create(null);
23701
- extensionName = undefined;
23702
- }
23703
- start = end = -1;
23704
- } else if (code === 61 && start !== -1 && end === -1) {
23705
- paramName = header.slice(start, i);
23706
- start = end = -1;
23707
- } else {
23708
- throw new SyntaxError(`Unexpected character at index ${i}`);
23709
- }
23710
- } else {
23711
- if (isEscaping) {
23712
- if (tokenChars[code] !== 1) {
23713
- throw new SyntaxError(`Unexpected character at index ${i}`);
23714
- }
23715
- if (start === -1)
23716
- start = i;
23717
- else if (!mustUnescape)
23718
- mustUnescape = true;
23719
- isEscaping = false;
23720
- } else if (inQuotes) {
23721
- if (tokenChars[code] === 1) {
23722
- if (start === -1)
23723
- start = i;
23724
- } else if (code === 34 && start !== -1) {
23725
- inQuotes = false;
23726
- end = i;
23727
- } else if (code === 92) {
23728
- isEscaping = true;
23729
- } else {
23730
- throw new SyntaxError(`Unexpected character at index ${i}`);
23731
- }
23732
- } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
23733
- inQuotes = true;
23734
- } else if (end === -1 && tokenChars[code] === 1) {
23735
- if (start === -1)
23736
- start = i;
23737
- } else if (start !== -1 && (code === 32 || code === 9)) {
23738
- if (end === -1)
23739
- end = i;
23740
- } else if (code === 59 || code === 44) {
23741
- if (start === -1) {
23742
- throw new SyntaxError(`Unexpected character at index ${i}`);
23743
- }
23744
- if (end === -1)
23745
- end = i;
23746
- let value = header.slice(start, end);
23747
- if (mustUnescape) {
23748
- value = value.replace(/\\/g, "");
23749
- mustUnescape = false;
23750
- }
23751
- push(params, paramName, value);
23752
- if (code === 44) {
23753
- push(offers, extensionName, params);
23754
- params = Object.create(null);
23755
- extensionName = undefined;
23756
- }
23757
- paramName = undefined;
23758
- start = end = -1;
23759
- } else {
23760
- throw new SyntaxError(`Unexpected character at index ${i}`);
23761
- }
23762
- }
23763
- }
23764
- if (start === -1 || inQuotes || code === 32 || code === 9) {
23765
- throw new SyntaxError("Unexpected end of input");
23766
- }
23767
- if (end === -1)
23768
- end = i;
23769
- const token = header.slice(start, end);
23770
- if (extensionName === undefined) {
23771
- push(offers, token, params);
23772
- } else {
23773
- if (paramName === undefined) {
23774
- push(params, token, true);
23775
- } else if (mustUnescape) {
23776
- push(params, paramName, token.replace(/\\/g, ""));
23777
- } else {
23778
- push(params, paramName, token);
23779
- }
23780
- push(offers, extensionName, params);
23781
- }
23782
- return offers;
23783
- }
23784
- function format(extensions) {
23785
- return Object.keys(extensions).map((extension) => {
23786
- let configurations = extensions[extension];
23787
- if (!Array.isArray(configurations))
23788
- configurations = [configurations];
23789
- return configurations.map((params) => {
23790
- return [extension].concat(Object.keys(params).map((k) => {
23791
- let values2 = params[k];
23792
- if (!Array.isArray(values2))
23793
- values2 = [values2];
23794
- return values2.map((v) => v === true ? k : `${k}=${v}`).join("; ");
23795
- })).join("; ");
23796
- }).join(", ");
23797
- }).join(", ");
23798
- }
23799
- module.exports = { format, parse };
23800
- });
23801
-
23802
- // node_modules/ws/lib/websocket.js
23803
- var require_websocket = __commonJS((exports, module) => {
23804
- var EventEmitter = __require("events");
23805
- var https = __require("https");
23806
- var http = __require("http");
23807
- var net = __require("net");
23808
- var tls = __require("tls");
23809
- var { randomBytes: randomBytes2, createHash } = __require("crypto");
23810
- var { Duplex, Readable } = __require("stream");
23811
- var { URL: URL2 } = __require("url");
23812
- var PerMessageDeflate = require_permessage_deflate();
23813
- var Receiver = require_receiver();
23814
- var Sender = require_sender();
23815
- var { isBlob } = require_validation();
23816
- var {
23817
- BINARY_TYPES,
23818
- EMPTY_BUFFER,
23819
- GUID,
23820
- kForOnEventAttribute,
23821
- kListener,
23822
- kStatusCode,
23823
- kWebSocket,
23824
- NOOP
23825
- } = require_constants2();
23826
- var {
23827
- EventTarget: { addEventListener, removeEventListener }
23828
- } = require_event_target();
23829
- var { format, parse } = require_extension();
23830
- var { toBuffer } = require_buffer_util();
23831
- var closeTimeout = 30 * 1000;
23832
- var kAborted = Symbol("kAborted");
23833
- var protocolVersions = [8, 13];
23834
- var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
23835
- var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
23836
-
23837
- class WebSocket extends EventEmitter {
23838
- constructor(address, protocols, options) {
23839
- super();
23840
- this._binaryType = BINARY_TYPES[0];
23841
- this._closeCode = 1006;
23842
- this._closeFrameReceived = false;
23843
- this._closeFrameSent = false;
23844
- this._closeMessage = EMPTY_BUFFER;
23845
- this._closeTimer = null;
23846
- this._errorEmitted = false;
23847
- this._extensions = {};
23848
- this._paused = false;
23849
- this._protocol = "";
23850
- this._readyState = WebSocket.CONNECTING;
23851
- this._receiver = null;
23852
- this._sender = null;
23853
- this._socket = null;
23854
- if (address !== null) {
23855
- this._bufferedAmount = 0;
23856
- this._isServer = false;
23857
- this._redirects = 0;
23858
- if (protocols === undefined) {
23859
- protocols = [];
23860
- } else if (!Array.isArray(protocols)) {
23861
- if (typeof protocols === "object" && protocols !== null) {
23862
- options = protocols;
23863
- protocols = [];
23864
- } else {
23865
- protocols = [protocols];
23866
- }
23867
- }
23868
- initAsClient(this, address, protocols, options);
23869
- } else {
23870
- this._autoPong = options.autoPong;
23871
- this._isServer = true;
23872
- }
23873
- }
23874
- get binaryType() {
23875
- return this._binaryType;
23876
- }
23877
- set binaryType(type2) {
23878
- if (!BINARY_TYPES.includes(type2))
23879
- return;
23880
- this._binaryType = type2;
23881
- if (this._receiver)
23882
- this._receiver._binaryType = type2;
23883
- }
23884
- get bufferedAmount() {
23885
- if (!this._socket)
23886
- return this._bufferedAmount;
23887
- return this._socket._writableState.length + this._sender._bufferedBytes;
23888
- }
23889
- get extensions() {
23890
- return Object.keys(this._extensions).join();
23891
- }
23892
- get isPaused() {
23893
- return this._paused;
23894
- }
23895
- get onclose() {
23896
- return null;
23897
- }
23898
- get onerror() {
23899
- return null;
23900
- }
23901
- get onopen() {
23902
- return null;
23903
- }
23904
- get onmessage() {
23905
- return null;
23906
- }
23907
- get protocol() {
23908
- return this._protocol;
23909
- }
23910
- get readyState() {
23911
- return this._readyState;
23912
- }
23913
- get url() {
23914
- return this._url;
23915
- }
23916
- setSocket(socket, head, options) {
23917
- const receiver = new Receiver({
23918
- allowSynchronousEvents: options.allowSynchronousEvents,
23919
- binaryType: this.binaryType,
23920
- extensions: this._extensions,
23921
- isServer: this._isServer,
23922
- maxPayload: options.maxPayload,
23923
- skipUTF8Validation: options.skipUTF8Validation
23924
- });
23925
- const sender = new Sender(socket, this._extensions, options.generateMask);
23926
- this._receiver = receiver;
23927
- this._sender = sender;
23928
- this._socket = socket;
23929
- receiver[kWebSocket] = this;
23930
- sender[kWebSocket] = this;
23931
- socket[kWebSocket] = this;
23932
- receiver.on("conclude", receiverOnConclude);
23933
- receiver.on("drain", receiverOnDrain);
23934
- receiver.on("error", receiverOnError);
23935
- receiver.on("message", receiverOnMessage);
23936
- receiver.on("ping", receiverOnPing);
23937
- receiver.on("pong", receiverOnPong);
23938
- sender.onerror = senderOnError;
23939
- if (socket.setTimeout)
23940
- socket.setTimeout(0);
23941
- if (socket.setNoDelay)
23942
- socket.setNoDelay();
23943
- if (head.length > 0)
23944
- socket.unshift(head);
23945
- socket.on("close", socketOnClose);
23946
- socket.on("data", socketOnData);
23947
- socket.on("end", socketOnEnd);
23948
- socket.on("error", socketOnError);
23949
- this._readyState = WebSocket.OPEN;
23950
- this.emit("open");
23951
- }
23952
- emitClose() {
23953
- if (!this._socket) {
23954
- this._readyState = WebSocket.CLOSED;
23955
- this.emit("close", this._closeCode, this._closeMessage);
23956
- return;
23957
- }
23958
- if (this._extensions[PerMessageDeflate.extensionName]) {
23959
- this._extensions[PerMessageDeflate.extensionName].cleanup();
23960
- }
23961
- this._receiver.removeAllListeners();
23962
- this._readyState = WebSocket.CLOSED;
23963
- this.emit("close", this._closeCode, this._closeMessage);
23964
- }
23965
- close(code, data) {
23966
- if (this.readyState === WebSocket.CLOSED)
23967
- return;
23968
- if (this.readyState === WebSocket.CONNECTING) {
23969
- const msg = "WebSocket was closed before the connection was established";
23970
- abortHandshake(this, this._req, msg);
23971
- return;
23972
- }
23973
- if (this.readyState === WebSocket.CLOSING) {
23974
- if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
23975
- this._socket.end();
23976
- }
23977
- return;
23978
- }
23979
- this._readyState = WebSocket.CLOSING;
23980
- this._sender.close(code, data, !this._isServer, (err) => {
23981
- if (err)
23982
- return;
23983
- this._closeFrameSent = true;
23984
- if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
23985
- this._socket.end();
23986
- }
23987
- });
23988
- setCloseTimer(this);
23989
- }
23990
- pause() {
23991
- if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
23992
- return;
23993
- }
23994
- this._paused = true;
23995
- this._socket.pause();
23996
- }
23997
- ping(data, mask, cb) {
23998
- if (this.readyState === WebSocket.CONNECTING) {
23999
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
24000
- }
24001
- if (typeof data === "function") {
24002
- cb = data;
24003
- data = mask = undefined;
24004
- } else if (typeof mask === "function") {
24005
- cb = mask;
24006
- mask = undefined;
24007
- }
24008
- if (typeof data === "number")
24009
- data = data.toString();
24010
- if (this.readyState !== WebSocket.OPEN) {
24011
- sendAfterClose(this, data, cb);
24012
- return;
24013
- }
24014
- if (mask === undefined)
24015
- mask = !this._isServer;
24016
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
24017
- }
24018
- pong(data, mask, cb) {
24019
- if (this.readyState === WebSocket.CONNECTING) {
24020
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
24021
- }
24022
- if (typeof data === "function") {
24023
- cb = data;
24024
- data = mask = undefined;
24025
- } else if (typeof mask === "function") {
24026
- cb = mask;
24027
- mask = undefined;
24028
- }
24029
- if (typeof data === "number")
24030
- data = data.toString();
24031
- if (this.readyState !== WebSocket.OPEN) {
24032
- sendAfterClose(this, data, cb);
24033
- return;
24034
- }
24035
- if (mask === undefined)
24036
- mask = !this._isServer;
24037
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
24038
- }
24039
- resume() {
24040
- if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
24041
- return;
24042
- }
24043
- this._paused = false;
24044
- if (!this._receiver._writableState.needDrain)
24045
- this._socket.resume();
24046
- }
24047
- send(data, options, cb) {
24048
- if (this.readyState === WebSocket.CONNECTING) {
24049
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
24050
- }
24051
- if (typeof options === "function") {
24052
- cb = options;
24053
- options = {};
24054
- }
24055
- if (typeof data === "number")
24056
- data = data.toString();
24057
- if (this.readyState !== WebSocket.OPEN) {
24058
- sendAfterClose(this, data, cb);
24059
- return;
24060
- }
24061
- const opts = {
24062
- binary: typeof data !== "string",
24063
- mask: !this._isServer,
24064
- compress: true,
24065
- fin: true,
24066
- ...options
24067
- };
24068
- if (!this._extensions[PerMessageDeflate.extensionName]) {
24069
- opts.compress = false;
24070
- }
24071
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
24072
- }
24073
- terminate() {
24074
- if (this.readyState === WebSocket.CLOSED)
24075
- return;
24076
- if (this.readyState === WebSocket.CONNECTING) {
24077
- const msg = "WebSocket was closed before the connection was established";
24078
- abortHandshake(this, this._req, msg);
24079
- return;
24080
- }
24081
- if (this._socket) {
24082
- this._readyState = WebSocket.CLOSING;
24083
- this._socket.destroy();
24084
- }
24085
- }
24086
- }
24087
- Object.defineProperty(WebSocket, "CONNECTING", {
24088
- enumerable: true,
24089
- value: readyStates.indexOf("CONNECTING")
24090
- });
24091
- Object.defineProperty(WebSocket.prototype, "CONNECTING", {
24092
- enumerable: true,
24093
- value: readyStates.indexOf("CONNECTING")
24094
- });
24095
- Object.defineProperty(WebSocket, "OPEN", {
24096
- enumerable: true,
24097
- value: readyStates.indexOf("OPEN")
24098
- });
24099
- Object.defineProperty(WebSocket.prototype, "OPEN", {
24100
- enumerable: true,
24101
- value: readyStates.indexOf("OPEN")
24102
- });
24103
- Object.defineProperty(WebSocket, "CLOSING", {
24104
- enumerable: true,
24105
- value: readyStates.indexOf("CLOSING")
24106
- });
24107
- Object.defineProperty(WebSocket.prototype, "CLOSING", {
24108
- enumerable: true,
24109
- value: readyStates.indexOf("CLOSING")
24110
- });
24111
- Object.defineProperty(WebSocket, "CLOSED", {
24112
- enumerable: true,
24113
- value: readyStates.indexOf("CLOSED")
24114
- });
24115
- Object.defineProperty(WebSocket.prototype, "CLOSED", {
24116
- enumerable: true,
24117
- value: readyStates.indexOf("CLOSED")
24118
- });
24119
- [
24120
- "binaryType",
24121
- "bufferedAmount",
24122
- "extensions",
24123
- "isPaused",
24124
- "protocol",
24125
- "readyState",
24126
- "url"
24127
- ].forEach((property) => {
24128
- Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
24129
- });
24130
- ["open", "error", "close", "message"].forEach((method) => {
24131
- Object.defineProperty(WebSocket.prototype, `on${method}`, {
24132
- enumerable: true,
24133
- get() {
24134
- for (const listener of this.listeners(method)) {
24135
- if (listener[kForOnEventAttribute])
24136
- return listener[kListener];
24137
- }
24138
- return null;
24139
- },
24140
- set(handler) {
24141
- for (const listener of this.listeners(method)) {
24142
- if (listener[kForOnEventAttribute]) {
24143
- this.removeListener(method, listener);
24144
- break;
24145
- }
24146
- }
24147
- if (typeof handler !== "function")
24148
- return;
24149
- this.addEventListener(method, handler, {
24150
- [kForOnEventAttribute]: true
24151
- });
24152
- }
24153
- });
24154
- });
24155
- WebSocket.prototype.addEventListener = addEventListener;
24156
- WebSocket.prototype.removeEventListener = removeEventListener;
24157
- module.exports = WebSocket;
24158
- function initAsClient(websocket, address, protocols, options) {
24159
- const opts = {
24160
- allowSynchronousEvents: true,
24161
- autoPong: true,
24162
- protocolVersion: protocolVersions[1],
24163
- maxPayload: 100 * 1024 * 1024,
24164
- skipUTF8Validation: false,
24165
- perMessageDeflate: true,
24166
- followRedirects: false,
24167
- maxRedirects: 10,
24168
- ...options,
24169
- socketPath: undefined,
24170
- hostname: undefined,
24171
- protocol: undefined,
24172
- timeout: undefined,
24173
- method: "GET",
24174
- host: undefined,
24175
- path: undefined,
24176
- port: undefined
24177
- };
24178
- websocket._autoPong = opts.autoPong;
24179
- if (!protocolVersions.includes(opts.protocolVersion)) {
24180
- throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
24181
- }
24182
- let parsedUrl;
24183
- if (address instanceof URL2) {
24184
- parsedUrl = address;
24185
- } else {
24186
- try {
24187
- parsedUrl = new URL2(address);
24188
- } catch (e) {
24189
- throw new SyntaxError(`Invalid URL: ${address}`);
24190
- }
24191
- }
24192
- if (parsedUrl.protocol === "http:") {
24193
- parsedUrl.protocol = "ws:";
24194
- } else if (parsedUrl.protocol === "https:") {
24195
- parsedUrl.protocol = "wss:";
24196
- }
24197
- websocket._url = parsedUrl.href;
24198
- const isSecure = parsedUrl.protocol === "wss:";
24199
- const isIpcUrl = parsedUrl.protocol === "ws+unix:";
24200
- let invalidUrlMessage;
24201
- if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
24202
- invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
24203
- } else if (isIpcUrl && !parsedUrl.pathname) {
24204
- invalidUrlMessage = "The URL's pathname is empty";
24205
- } else if (parsedUrl.hash) {
24206
- invalidUrlMessage = "The URL contains a fragment identifier";
24207
- }
24208
- if (invalidUrlMessage) {
24209
- const err = new SyntaxError(invalidUrlMessage);
24210
- if (websocket._redirects === 0) {
24211
- throw err;
24212
- } else {
24213
- emitErrorAndClose(websocket, err);
24214
- return;
24215
- }
24216
- }
24217
- const defaultPort = isSecure ? 443 : 80;
24218
- const key = randomBytes2(16).toString("base64");
24219
- const request = isSecure ? https.request : http.request;
24220
- const protocolSet = new Set;
24221
- let perMessageDeflate;
24222
- opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
24223
- opts.defaultPort = opts.defaultPort || defaultPort;
24224
- opts.port = parsedUrl.port || defaultPort;
24225
- opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
24226
- opts.headers = {
24227
- ...opts.headers,
24228
- "Sec-WebSocket-Version": opts.protocolVersion,
24229
- "Sec-WebSocket-Key": key,
24230
- Connection: "Upgrade",
24231
- Upgrade: "websocket"
24232
- };
24233
- opts.path = parsedUrl.pathname + parsedUrl.search;
24234
- opts.timeout = opts.handshakeTimeout;
24235
- if (opts.perMessageDeflate) {
24236
- perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
24237
- opts.headers["Sec-WebSocket-Extensions"] = format({
24238
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
24239
- });
24240
- }
24241
- if (protocols.length) {
24242
- for (const protocol of protocols) {
24243
- if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
24244
- throw new SyntaxError("An invalid or duplicated subprotocol was specified");
24245
- }
24246
- protocolSet.add(protocol);
24247
- }
24248
- opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
24249
- }
24250
- if (opts.origin) {
24251
- if (opts.protocolVersion < 13) {
24252
- opts.headers["Sec-WebSocket-Origin"] = opts.origin;
24253
- } else {
24254
- opts.headers.Origin = opts.origin;
24255
- }
24256
- }
24257
- if (parsedUrl.username || parsedUrl.password) {
24258
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
24259
- }
24260
- if (isIpcUrl) {
24261
- const parts = opts.path.split(":");
24262
- opts.socketPath = parts[0];
24263
- opts.path = parts[1];
24264
- }
24265
- let req;
24266
- if (opts.followRedirects) {
24267
- if (websocket._redirects === 0) {
24268
- websocket._originalIpc = isIpcUrl;
24269
- websocket._originalSecure = isSecure;
24270
- websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
24271
- const headers = options && options.headers;
24272
- options = { ...options, headers: {} };
24273
- if (headers) {
24274
- for (const [key2, value] of Object.entries(headers)) {
24275
- options.headers[key2.toLowerCase()] = value;
24276
- }
24277
- }
24278
- } else if (websocket.listenerCount("redirect") === 0) {
24279
- const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
24280
- if (!isSameHost || websocket._originalSecure && !isSecure) {
24281
- delete opts.headers.authorization;
24282
- delete opts.headers.cookie;
24283
- if (!isSameHost)
24284
- delete opts.headers.host;
24285
- opts.auth = undefined;
24286
- }
24287
- }
24288
- if (opts.auth && !options.headers.authorization) {
24289
- options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
24290
- }
24291
- req = websocket._req = request(opts);
24292
- if (websocket._redirects) {
24293
- websocket.emit("redirect", websocket.url, req);
24294
- }
24295
- } else {
24296
- req = websocket._req = request(opts);
24297
- }
24298
- if (opts.timeout) {
24299
- req.on("timeout", () => {
24300
- abortHandshake(websocket, req, "Opening handshake has timed out");
24301
- });
24302
- }
24303
- req.on("error", (err) => {
24304
- if (req === null || req[kAborted])
24305
- return;
24306
- req = websocket._req = null;
24307
- emitErrorAndClose(websocket, err);
24308
- });
24309
- req.on("response", (res) => {
24310
- const location = res.headers.location;
24311
- const statusCode = res.statusCode;
24312
- if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
24313
- if (++websocket._redirects > opts.maxRedirects) {
24314
- abortHandshake(websocket, req, "Maximum redirects exceeded");
24315
- return;
24316
- }
24317
- req.abort();
24318
- let addr;
24319
- try {
24320
- addr = new URL2(location, address);
24321
- } catch (e) {
24322
- const err = new SyntaxError(`Invalid URL: ${location}`);
24323
- emitErrorAndClose(websocket, err);
24324
- return;
24325
- }
24326
- initAsClient(websocket, addr, protocols, options);
24327
- } else if (!websocket.emit("unexpected-response", req, res)) {
24328
- abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
24329
- }
24330
- });
24331
- req.on("upgrade", (res, socket, head) => {
24332
- websocket.emit("upgrade", res);
24333
- if (websocket.readyState !== WebSocket.CONNECTING)
24334
- return;
24335
- req = websocket._req = null;
24336
- const upgrade = res.headers.upgrade;
24337
- if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
24338
- abortHandshake(websocket, socket, "Invalid Upgrade header");
24339
- return;
24340
- }
24341
- const digest = createHash("sha1").update(key + GUID).digest("base64");
24342
- if (res.headers["sec-websocket-accept"] !== digest) {
24343
- abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
24344
- return;
24345
- }
24346
- const serverProt = res.headers["sec-websocket-protocol"];
24347
- let protError;
24348
- if (serverProt !== undefined) {
24349
- if (!protocolSet.size) {
24350
- protError = "Server sent a subprotocol but none was requested";
24351
- } else if (!protocolSet.has(serverProt)) {
24352
- protError = "Server sent an invalid subprotocol";
24353
- }
24354
- } else if (protocolSet.size) {
24355
- protError = "Server sent no subprotocol";
24356
- }
24357
- if (protError) {
24358
- abortHandshake(websocket, socket, protError);
24359
- return;
24360
- }
24361
- if (serverProt)
24362
- websocket._protocol = serverProt;
24363
- const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
24364
- if (secWebSocketExtensions !== undefined) {
24365
- if (!perMessageDeflate) {
24366
- const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
24367
- abortHandshake(websocket, socket, message);
24368
- return;
24369
- }
24370
- let extensions;
24371
- try {
24372
- extensions = parse(secWebSocketExtensions);
24373
- } catch (err) {
24374
- const message = "Invalid Sec-WebSocket-Extensions header";
24375
- abortHandshake(websocket, socket, message);
24376
- return;
24377
- }
24378
- const extensionNames = Object.keys(extensions);
24379
- if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
24380
- const message = "Server indicated an extension that was not requested";
24381
- abortHandshake(websocket, socket, message);
24382
- return;
24383
- }
24384
- try {
24385
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
24386
- } catch (err) {
24387
- const message = "Invalid Sec-WebSocket-Extensions header";
24388
- abortHandshake(websocket, socket, message);
24389
- return;
24390
- }
24391
- websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
24392
- }
24393
- websocket.setSocket(socket, head, {
24394
- allowSynchronousEvents: opts.allowSynchronousEvents,
24395
- generateMask: opts.generateMask,
24396
- maxPayload: opts.maxPayload,
24397
- skipUTF8Validation: opts.skipUTF8Validation
24398
- });
24399
- });
24400
- if (opts.finishRequest) {
24401
- opts.finishRequest(req, websocket);
24402
- } else {
24403
- req.end();
24404
- }
24405
- }
24406
- function emitErrorAndClose(websocket, err) {
24407
- websocket._readyState = WebSocket.CLOSING;
24408
- websocket._errorEmitted = true;
24409
- websocket.emit("error", err);
24410
- websocket.emitClose();
24411
- }
24412
- function netConnect(options) {
24413
- options.path = options.socketPath;
24414
- return net.connect(options);
24415
- }
24416
- function tlsConnect(options) {
24417
- options.path = undefined;
24418
- if (!options.servername && options.servername !== "") {
24419
- options.servername = net.isIP(options.host) ? "" : options.host;
24420
- }
24421
- return tls.connect(options);
24422
- }
24423
- function abortHandshake(websocket, stream, message) {
24424
- websocket._readyState = WebSocket.CLOSING;
24425
- const err = new Error(message);
24426
- Error.captureStackTrace(err, abortHandshake);
24427
- if (stream.setHeader) {
24428
- stream[kAborted] = true;
24429
- stream.abort();
24430
- if (stream.socket && !stream.socket.destroyed) {
24431
- stream.socket.destroy();
24432
- }
24433
- process.nextTick(emitErrorAndClose, websocket, err);
24434
- } else {
24435
- stream.destroy(err);
24436
- stream.once("error", websocket.emit.bind(websocket, "error"));
24437
- stream.once("close", websocket.emitClose.bind(websocket));
24438
- }
24439
- }
24440
- function sendAfterClose(websocket, data, cb) {
24441
- if (data) {
24442
- const length = isBlob(data) ? data.size : toBuffer(data).length;
24443
- if (websocket._socket)
24444
- websocket._sender._bufferedBytes += length;
24445
- else
24446
- websocket._bufferedAmount += length;
24447
- }
24448
- if (cb) {
24449
- const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
24450
- process.nextTick(cb, err);
24451
- }
24452
- }
24453
- function receiverOnConclude(code, reason) {
24454
- const websocket = this[kWebSocket];
24455
- websocket._closeFrameReceived = true;
24456
- websocket._closeMessage = reason;
24457
- websocket._closeCode = code;
24458
- if (websocket._socket[kWebSocket] === undefined)
24459
- return;
24460
- websocket._socket.removeListener("data", socketOnData);
24461
- process.nextTick(resume, websocket._socket);
24462
- if (code === 1005)
24463
- websocket.close();
24464
- else
24465
- websocket.close(code, reason);
24466
- }
24467
- function receiverOnDrain() {
24468
- const websocket = this[kWebSocket];
24469
- if (!websocket.isPaused)
24470
- websocket._socket.resume();
24471
- }
24472
- function receiverOnError(err) {
24473
- const websocket = this[kWebSocket];
24474
- if (websocket._socket[kWebSocket] !== undefined) {
24475
- websocket._socket.removeListener("data", socketOnData);
24476
- process.nextTick(resume, websocket._socket);
24477
- websocket.close(err[kStatusCode]);
24478
- }
24479
- if (!websocket._errorEmitted) {
24480
- websocket._errorEmitted = true;
24481
- websocket.emit("error", err);
24482
- }
24483
- }
24484
- function receiverOnFinish() {
24485
- this[kWebSocket].emitClose();
24486
- }
24487
- function receiverOnMessage(data, isBinary) {
24488
- this[kWebSocket].emit("message", data, isBinary);
24489
- }
24490
- function receiverOnPing(data) {
24491
- const websocket = this[kWebSocket];
24492
- if (websocket._autoPong)
24493
- websocket.pong(data, !this._isServer, NOOP);
24494
- websocket.emit("ping", data);
24495
- }
24496
- function receiverOnPong(data) {
24497
- this[kWebSocket].emit("pong", data);
24498
- }
24499
- function resume(stream) {
24500
- stream.resume();
24501
- }
24502
- function senderOnError(err) {
24503
- const websocket = this[kWebSocket];
24504
- if (websocket.readyState === WebSocket.CLOSED)
24505
- return;
24506
- if (websocket.readyState === WebSocket.OPEN) {
24507
- websocket._readyState = WebSocket.CLOSING;
24508
- setCloseTimer(websocket);
24509
- }
24510
- this._socket.end();
24511
- if (!websocket._errorEmitted) {
24512
- websocket._errorEmitted = true;
24513
- websocket.emit("error", err);
24514
- }
24515
- }
24516
- function setCloseTimer(websocket) {
24517
- websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), closeTimeout);
24518
- }
24519
- function socketOnClose() {
24520
- const websocket = this[kWebSocket];
24521
- this.removeListener("close", socketOnClose);
24522
- this.removeListener("data", socketOnData);
24523
- this.removeListener("end", socketOnEnd);
24524
- websocket._readyState = WebSocket.CLOSING;
24525
- let chunk;
24526
- if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
24527
- websocket._receiver.write(chunk);
24528
- }
24529
- websocket._receiver.end();
24530
- this[kWebSocket] = undefined;
24531
- clearTimeout(websocket._closeTimer);
24532
- if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
24533
- websocket.emitClose();
24534
- } else {
24535
- websocket._receiver.on("error", receiverOnFinish);
24536
- websocket._receiver.on("finish", receiverOnFinish);
24537
- }
24538
- }
24539
- function socketOnData(chunk) {
24540
- if (!this[kWebSocket]._receiver.write(chunk)) {
24541
- this.pause();
24542
- }
24543
- }
24544
- function socketOnEnd() {
24545
- const websocket = this[kWebSocket];
24546
- websocket._readyState = WebSocket.CLOSING;
24547
- websocket._receiver.end();
24548
- this.end();
24549
- }
24550
- function socketOnError() {
24551
- const websocket = this[kWebSocket];
24552
- this.removeListener("error", socketOnError);
24553
- this.on("error", NOOP);
24554
- if (websocket) {
24555
- websocket._readyState = WebSocket.CLOSING;
24556
- this.destroy();
24557
- }
24558
- }
24559
- });
24560
-
24561
- // node_modules/ws/lib/stream.js
24562
- var require_stream = __commonJS((exports, module) => {
24563
- var WebSocket = require_websocket();
24564
- var { Duplex } = __require("stream");
24565
- function emitClose(stream) {
24566
- stream.emit("close");
24567
- }
24568
- function duplexOnEnd() {
24569
- if (!this.destroyed && this._writableState.finished) {
24570
- this.destroy();
24571
- }
24572
- }
24573
- function duplexOnError(err) {
24574
- this.removeListener("error", duplexOnError);
24575
- this.destroy();
24576
- if (this.listenerCount("error") === 0) {
24577
- this.emit("error", err);
24578
- }
24579
- }
24580
- function createWebSocketStream(ws, options) {
24581
- let terminateOnDestroy = true;
24582
- const duplex = new Duplex({
24583
- ...options,
24584
- autoDestroy: false,
24585
- emitClose: false,
24586
- objectMode: false,
24587
- writableObjectMode: false
24588
- });
24589
- ws.on("message", function message(msg, isBinary) {
24590
- const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
24591
- if (!duplex.push(data))
24592
- ws.pause();
24593
- });
24594
- ws.once("error", function error(err) {
24595
- if (duplex.destroyed)
24596
- return;
24597
- terminateOnDestroy = false;
24598
- duplex.destroy(err);
24599
- });
24600
- ws.once("close", function close() {
24601
- if (duplex.destroyed)
24602
- return;
24603
- duplex.push(null);
24604
- });
24605
- duplex._destroy = function(err, callback) {
24606
- if (ws.readyState === ws.CLOSED) {
24607
- callback(err);
24608
- process.nextTick(emitClose, duplex);
24609
- return;
24610
- }
24611
- let called = false;
24612
- ws.once("error", function error(err2) {
24613
- called = true;
24614
- callback(err2);
24615
- });
24616
- ws.once("close", function close() {
24617
- if (!called)
24618
- callback(err);
24619
- process.nextTick(emitClose, duplex);
24620
- });
24621
- if (terminateOnDestroy)
24622
- ws.terminate();
24623
- };
24624
- duplex._final = function(callback) {
24625
- if (ws.readyState === ws.CONNECTING) {
24626
- ws.once("open", function open() {
24627
- duplex._final(callback);
24628
- });
24629
- return;
24630
- }
24631
- if (ws._socket === null)
24632
- return;
24633
- if (ws._socket._writableState.finished) {
24634
- callback();
24635
- if (duplex._readableState.endEmitted)
24636
- duplex.destroy();
24637
- } else {
24638
- ws._socket.once("finish", function finish() {
24639
- callback();
24640
- });
24641
- ws.close();
24642
- }
24643
- };
24644
- duplex._read = function() {
24645
- if (ws.isPaused)
24646
- ws.resume();
24647
- };
24648
- duplex._write = function(chunk, encoding, callback) {
24649
- if (ws.readyState === ws.CONNECTING) {
24650
- ws.once("open", function open() {
24651
- duplex._write(chunk, encoding, callback);
24652
- });
24653
- return;
24654
- }
24655
- ws.send(chunk, callback);
24656
- };
24657
- duplex.on("end", duplexOnEnd);
24658
- duplex.on("error", duplexOnError);
24659
- return duplex;
24660
- }
24661
- module.exports = createWebSocketStream;
24662
- });
24663
-
24664
- // node_modules/ws/lib/subprotocol.js
24665
- var require_subprotocol = __commonJS((exports, module) => {
24666
- var { tokenChars } = require_validation();
24667
- function parse(header) {
24668
- const protocols = new Set;
24669
- let start = -1;
24670
- let end = -1;
24671
- let i = 0;
24672
- for (i;i < header.length; i++) {
24673
- const code = header.charCodeAt(i);
24674
- if (end === -1 && tokenChars[code] === 1) {
24675
- if (start === -1)
24676
- start = i;
24677
- } else if (i !== 0 && (code === 32 || code === 9)) {
24678
- if (end === -1 && start !== -1)
24679
- end = i;
24680
- } else if (code === 44) {
24681
- if (start === -1) {
24682
- throw new SyntaxError(`Unexpected character at index ${i}`);
24683
- }
24684
- if (end === -1)
24685
- end = i;
24686
- const protocol2 = header.slice(start, end);
24687
- if (protocols.has(protocol2)) {
24688
- throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
24689
- }
24690
- protocols.add(protocol2);
24691
- start = end = -1;
24692
- } else {
24693
- throw new SyntaxError(`Unexpected character at index ${i}`);
24694
- }
24695
- }
24696
- if (start === -1 || end !== -1) {
24697
- throw new SyntaxError("Unexpected end of input");
24698
- }
24699
- const protocol = header.slice(start, i);
24700
- if (protocols.has(protocol)) {
24701
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
24702
- }
24703
- protocols.add(protocol);
24704
- return protocols;
24705
- }
24706
- module.exports = { parse };
24707
- });
24708
-
24709
- // node_modules/ws/lib/websocket-server.js
24710
- var require_websocket_server = __commonJS((exports, module) => {
24711
- var EventEmitter = __require("events");
24712
- var http = __require("http");
24713
- var { Duplex } = __require("stream");
24714
- var { createHash } = __require("crypto");
24715
- var extension = require_extension();
24716
- var PerMessageDeflate = require_permessage_deflate();
24717
- var subprotocol = require_subprotocol();
24718
- var WebSocket = require_websocket();
24719
- var { GUID, kWebSocket } = require_constants2();
24720
- var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
24721
- var RUNNING = 0;
24722
- var CLOSING = 1;
24723
- var CLOSED = 2;
24724
-
24725
- class WebSocketServer extends EventEmitter {
24726
- constructor(options, callback) {
24727
- super();
24728
- options = {
24729
- allowSynchronousEvents: true,
24730
- autoPong: true,
24731
- maxPayload: 100 * 1024 * 1024,
24732
- skipUTF8Validation: false,
24733
- perMessageDeflate: false,
24734
- handleProtocols: null,
24735
- clientTracking: true,
24736
- verifyClient: null,
24737
- noServer: false,
24738
- backlog: null,
24739
- server: null,
24740
- host: null,
24741
- path: null,
24742
- port: null,
24743
- WebSocket,
24744
- ...options
24745
- };
24746
- if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
24747
- throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
24748
- }
24749
- if (options.port != null) {
24750
- this._server = http.createServer((req, res) => {
24751
- const body = http.STATUS_CODES[426];
24752
- res.writeHead(426, {
24753
- "Content-Length": body.length,
24754
- "Content-Type": "text/plain"
24755
- });
24756
- res.end(body);
24757
- });
24758
- this._server.listen(options.port, options.host, options.backlog, callback);
24759
- } else if (options.server) {
24760
- this._server = options.server;
24761
- }
24762
- if (this._server) {
24763
- const emitConnection = this.emit.bind(this, "connection");
24764
- this._removeListeners = addListeners(this._server, {
24765
- listening: this.emit.bind(this, "listening"),
24766
- error: this.emit.bind(this, "error"),
24767
- upgrade: (req, socket, head) => {
24768
- this.handleUpgrade(req, socket, head, emitConnection);
24769
- }
24770
- });
24771
- }
24772
- if (options.perMessageDeflate === true)
24773
- options.perMessageDeflate = {};
24774
- if (options.clientTracking) {
24775
- this.clients = new Set;
24776
- this._shouldEmitClose = false;
24777
- }
24778
- this.options = options;
24779
- this._state = RUNNING;
24780
- }
24781
- address() {
24782
- if (this.options.noServer) {
24783
- throw new Error('The server is operating in "noServer" mode');
24784
- }
24785
- if (!this._server)
24786
- return null;
24787
- return this._server.address();
24788
- }
24789
- close(cb) {
24790
- if (this._state === CLOSED) {
24791
- if (cb) {
24792
- this.once("close", () => {
24793
- cb(new Error("The server is not running"));
24794
- });
24795
- }
24796
- process.nextTick(emitClose, this);
24797
- return;
24798
- }
24799
- if (cb)
24800
- this.once("close", cb);
24801
- if (this._state === CLOSING)
24802
- return;
24803
- this._state = CLOSING;
24804
- if (this.options.noServer || this.options.server) {
24805
- if (this._server) {
24806
- this._removeListeners();
24807
- this._removeListeners = this._server = null;
24808
- }
24809
- if (this.clients) {
24810
- if (!this.clients.size) {
24811
- process.nextTick(emitClose, this);
24812
- } else {
24813
- this._shouldEmitClose = true;
24814
- }
24815
- } else {
24816
- process.nextTick(emitClose, this);
24817
- }
24818
- } else {
24819
- const server = this._server;
24820
- this._removeListeners();
24821
- this._removeListeners = this._server = null;
24822
- server.close(() => {
24823
- emitClose(this);
24824
- });
24825
- }
24826
- }
24827
- shouldHandle(req) {
24828
- if (this.options.path) {
24829
- const index2 = req.url.indexOf("?");
24830
- const pathname = index2 !== -1 ? req.url.slice(0, index2) : req.url;
24831
- if (pathname !== this.options.path)
24832
- return false;
24833
- }
24834
- return true;
24835
- }
24836
- handleUpgrade(req, socket, head, cb) {
24837
- socket.on("error", socketOnError);
24838
- const key = req.headers["sec-websocket-key"];
24839
- const upgrade = req.headers.upgrade;
24840
- const version = +req.headers["sec-websocket-version"];
24841
- if (req.method !== "GET") {
24842
- const message = "Invalid HTTP method";
24843
- abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
24844
- return;
24845
- }
24846
- if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
24847
- const message = "Invalid Upgrade header";
24848
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
24849
- return;
24850
- }
24851
- if (key === undefined || !keyRegex.test(key)) {
24852
- const message = "Missing or invalid Sec-WebSocket-Key header";
24853
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
24854
- return;
24855
- }
24856
- if (version !== 8 && version !== 13) {
24857
- const message = "Missing or invalid Sec-WebSocket-Version header";
24858
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
24859
- return;
24860
- }
24861
- if (!this.shouldHandle(req)) {
24862
- abortHandshake(socket, 400);
24863
- return;
24864
- }
24865
- const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
24866
- let protocols = new Set;
24867
- if (secWebSocketProtocol !== undefined) {
24868
- try {
24869
- protocols = subprotocol.parse(secWebSocketProtocol);
24870
- } catch (err) {
24871
- const message = "Invalid Sec-WebSocket-Protocol header";
24872
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
24873
- return;
24874
- }
24875
- }
24876
- const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
24877
- const extensions = {};
24878
- if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
24879
- const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
24880
- try {
24881
- const offers = extension.parse(secWebSocketExtensions);
24882
- if (offers[PerMessageDeflate.extensionName]) {
24883
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
24884
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
24885
- }
24886
- } catch (err) {
24887
- const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
24888
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
24889
- return;
24890
- }
24891
- }
24892
- if (this.options.verifyClient) {
24893
- const info = {
24894
- origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
24895
- secure: !!(req.socket.authorized || req.socket.encrypted),
24896
- req
24897
- };
24898
- if (this.options.verifyClient.length === 2) {
24899
- this.options.verifyClient(info, (verified, code, message, headers) => {
24900
- if (!verified) {
24901
- return abortHandshake(socket, code || 401, message, headers);
24902
- }
24903
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
24904
- });
24905
- return;
24906
- }
24907
- if (!this.options.verifyClient(info))
24908
- return abortHandshake(socket, 401);
24909
- }
24910
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
24911
- }
24912
- completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
24913
- if (!socket.readable || !socket.writable)
24914
- return socket.destroy();
24915
- if (socket[kWebSocket]) {
24916
- throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
24917
- }
24918
- if (this._state > RUNNING)
24919
- return abortHandshake(socket, 503);
24920
- const digest = createHash("sha1").update(key + GUID).digest("base64");
24921
- const headers = [
24922
- "HTTP/1.1 101 Switching Protocols",
24923
- "Upgrade: websocket",
24924
- "Connection: Upgrade",
24925
- `Sec-WebSocket-Accept: ${digest}`
24926
- ];
24927
- const ws = new this.options.WebSocket(null, undefined, this.options);
24928
- if (protocols.size) {
24929
- const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
24930
- if (protocol) {
24931
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
24932
- ws._protocol = protocol;
24933
- }
24934
- }
24935
- if (extensions[PerMessageDeflate.extensionName]) {
24936
- const params = extensions[PerMessageDeflate.extensionName].params;
24937
- const value = extension.format({
24938
- [PerMessageDeflate.extensionName]: [params]
24939
- });
24940
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
24941
- ws._extensions = extensions;
24942
- }
24943
- this.emit("headers", headers, req);
24944
- socket.write(headers.concat(`\r
24945
- `).join(`\r
24946
- `));
24947
- socket.removeListener("error", socketOnError);
24948
- ws.setSocket(socket, head, {
24949
- allowSynchronousEvents: this.options.allowSynchronousEvents,
24950
- maxPayload: this.options.maxPayload,
24951
- skipUTF8Validation: this.options.skipUTF8Validation
24952
- });
24953
- if (this.clients) {
24954
- this.clients.add(ws);
24955
- ws.on("close", () => {
24956
- this.clients.delete(ws);
24957
- if (this._shouldEmitClose && !this.clients.size) {
24958
- process.nextTick(emitClose, this);
24959
- }
24960
- });
24961
- }
24962
- cb(ws, req);
24963
- }
24964
- }
24965
- module.exports = WebSocketServer;
24966
- function addListeners(server, map) {
24967
- for (const event of Object.keys(map))
24968
- server.on(event, map[event]);
24969
- return function removeListeners() {
24970
- for (const event of Object.keys(map)) {
24971
- server.removeListener(event, map[event]);
24972
- }
24973
- };
24974
- }
24975
- function emitClose(server) {
24976
- server._state = CLOSED;
24977
- server.emit("close");
24978
- }
24979
- function socketOnError() {
24980
- this.destroy();
24981
- }
24982
- function abortHandshake(socket, code, message, headers) {
24983
- message = message || http.STATUS_CODES[code];
24984
- headers = {
24985
- Connection: "close",
24986
- "Content-Type": "text/html",
24987
- "Content-Length": Buffer.byteLength(message),
24988
- ...headers
24989
- };
24990
- socket.once("finish", socket.destroy);
24991
- socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
24992
- ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
24993
- `) + `\r
24994
- \r
24995
- ` + message);
24996
- }
24997
- function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
24998
- if (server.listenerCount("wsClientError")) {
24999
- const err = new Error(message);
25000
- Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
25001
- server.emit("wsClientError", err, socket, req);
25002
- } else {
25003
- abortHandshake(socket, code, message);
25004
- }
25005
- }
25006
- });
25007
-
25008
22171
  // node_modules/delayed-stream/lib/delayed_stream.js
25009
22172
  var require_delayed_stream = __commonJS((exports, module) => {
25010
22173
  var Stream2 = __require("stream").Stream;
@@ -52672,7 +49835,7 @@ var Base64 = {
52672
49835
  if (decoder === undefined) {
52673
49836
  const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
52674
49837
  const ignore = `= \f
52675
- \r  \u2028\u2029`;
49838
+ \r \xA0\u2028\u2029`;
52676
49839
  decoder = Object.create(null);
52677
49840
  for (i = 0;i < 64; ++i) {
52678
49841
  decoder[b64.charAt(i)] = i;
@@ -52809,7 +49972,7 @@ class Int10 {
52809
49972
  }
52810
49973
 
52811
49974
  // node_modules/@usherlabs/ccxt/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js
52812
- var ellipsis = "";
49975
+ var ellipsis = "\u2026";
52813
49976
  var reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
52814
49977
  var reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
52815
49978
  function stringCut(str, len) {
@@ -56089,13 +53252,8 @@ class Precise {
56089
53252
  }
56090
53253
  var Precise_default = Precise;
56091
53254
 
56092
- // node_modules/ws/wrapper.mjs
56093
- var import_stream = __toESM(require_stream(), 1);
56094
- var import_receiver = __toESM(require_receiver(), 1);
56095
- var import_sender = __toESM(require_sender(), 1);
56096
- var import_websocket = __toESM(require_websocket(), 1);
56097
- var import_websocket_server = __toESM(require_websocket_server(), 1);
56098
- var wrapper_default = import_websocket.default;
53255
+ // node_modules/@usherlabs/ccxt/js/src/base/ws/WsClient.js
53256
+ import WebSocket from "ws";
56099
53257
 
56100
53258
  // node_modules/@usherlabs/ccxt/js/src/static_dependencies/fflake/browser.js
56101
53259
  var u8 = Uint8Array;
@@ -56857,7 +54015,7 @@ class Client {
56857
54015
  }
56858
54016
 
56859
54017
  // node_modules/@usherlabs/ccxt/js/src/base/ws/WsClient.js
56860
- var WebSocketPlatform = isNode || !selfIsDefined() ? wrapper_default : self.WebSocket;
54018
+ var WebSocketPlatform = isNode || !selfIsDefined() ? WebSocket : self.WebSocket;
56861
54019
 
56862
54020
  class WsClient extends Client {
56863
54021
  constructor() {
@@ -71772,7 +68930,7 @@ class Exchange {
71772
68930
  }
71773
68931
  async loadHttpProxyAgent() {
71774
68932
  if (!this.httpAgent) {
71775
- const httpModule = await import("node:http");
68933
+ const httpModule = await import("http");
71776
68934
  this.httpAgent = new httpModule.Agent;
71777
68935
  }
71778
68936
  return this.httpAgent;
@@ -71792,7 +68950,7 @@ class Exchange {
71792
68950
  if (isNode2) {
71793
68951
  if (!this.nodeHttpModuleLoaded) {
71794
68952
  this.nodeHttpModuleLoaded = true;
71795
- const httpsModule = await import("node:https");
68953
+ const httpsModule = await import("https");
71796
68954
  this.httpsAgent = new httpsModule.Agent({ keepAlive: true });
71797
68955
  }
71798
68956
  }
@@ -84052,7 +81210,7 @@ var Hex = {
84052
81210
  if (decoder2 === undefined) {
84053
81211
  let hex2 = "0123456789ABCDEF";
84054
81212
  const ignore = ` \f
84055
- \r  \u2028\u2029`;
81213
+ \r \xA0\u2028\u2029`;
84056
81214
  decoder2 = {};
84057
81215
  for (i2 = 0;i2 < 16; ++i2) {
84058
81216
  decoder2[hex2.charAt(i2)] = i2;
@@ -97490,7 +94648,7 @@ class binanceusdm extends binance {
97490
94648
  describe() {
97491
94649
  return this.deepExtend(super.describe(), {
97492
94650
  id: "binanceusdm",
97493
- name: "Binance USDⓈ-M",
94651
+ name: "Binance USD\u24C8-M",
97494
94652
  urls: {
97495
94653
  logo: "https://github.com/user-attachments/assets/871cbea7-eebb-4b28-b260-c1c91df0487a",
97496
94654
  doc: [
@@ -111825,7 +108983,7 @@ class bithumb extends bithumb_default {
111825
108983
  if (status !== undefined) {
111826
108984
  if (status === "0000") {
111827
108985
  return;
111828
- } else if (message === "거래 진행중인 내역이 존재하지 않습니다.") {
108986
+ } else if (message === "\uAC70\uB798 \uC9C4\uD589\uC911\uC778 \uB0B4\uC5ED\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.") {
111829
108987
  return;
111830
108988
  }
111831
108989
  const feedback = this.id + " " + message;
@@ -207174,7 +204332,7 @@ class okx extends okx_default {
207174
204332
  const targetNetwork = this.safeDict(currency["networks"], this.networkIdToCode(network), {});
207175
204333
  fee = this.safeString(targetNetwork, "fee");
207176
204334
  if (fee === undefined) {
207177
- throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.');
204335
+ throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be \u2265 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.');
207178
204336
  }
207179
204337
  }
207180
204338
  request["fee"] = this.numberToString(fee);
@@ -213670,7 +210828,7 @@ class okcoin extends okcoin_default {
213670
210828
  const targetNetwork = this.safeValue(currency["networks"], this.networkIdToCode(network), {});
213671
210829
  fee = this.safeString(targetNetwork, "fee");
213672
210830
  if (fee === undefined) {
213673
- throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.');
210831
+ throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be \u2265 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.');
213674
210832
  }
213675
210833
  }
213676
210834
  request["fee"] = this.numberToString(fee);
@@ -249113,7 +246271,7 @@ class binanceusdm2 extends binance2 {
249113
246271
  describe() {
249114
246272
  return this.deepExtend(super.describe(), {
249115
246273
  id: "binanceusdm",
249116
- name: "Binance USDⓈ-M",
246274
+ name: "Binance USD\u24C8-M",
249117
246275
  urls: {
249118
246276
  logo: "https://user-images.githubusercontent.com/1294454/117738721-668c8d80-b205-11eb-8c49-3fad84c4a07f.jpg",
249119
246277
  doc: "https://developers.binance.com/en"
@@ -287559,7 +284717,7 @@ class BaseLogger {
287559
284717
  {{errorName}} {{errorMessage}}
287560
284718
  error stack:
287561
284719
  {{errorStack}}`,
287562
- prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? ` {{fileName}} {{method}}
284720
+ prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? ` \u2022 {{fileName}} {{method}}
287563
284721
  {{filePathWithLine}}`,
287564
284722
  prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
287565
284723
  prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
@@ -288030,9 +285188,8 @@ function validateOrder(policy, fromToken, toToken, amount, broker) {
288030
285188
  // src/server.ts
288031
285189
  var grpc = __toESM(require_src3(), 1);
288032
285190
  var protoLoader = __toESM(require_src2(), 1);
288033
- import path from "path";
288034
285191
 
288035
- // proto/cexBroker/Action.ts
285192
+ // proto/cex_broker/Action.ts
288036
285193
  var Action = {
288037
285194
  NoAction: 0,
288038
285195
  Deposit: 1,
@@ -288044,7 +285201,7 @@ var Action = {
288044
285201
  FetchDepositAddresses: 7
288045
285202
  };
288046
285203
 
288047
- // proto/cexBroker/SubscriptionType.ts
285204
+ // proto/cex_broker/SubscriptionType.ts
288048
285205
  var SubscriptionType = {
288049
285206
  ORDERBOOK: 0,
288050
285207
  TRADES: 1,
@@ -288056,14 +285213,13 @@ var SubscriptionType = {
288056
285213
 
288057
285214
  // src/server.ts
288058
285215
  var import_joi2 = __toESM(require_lib4(), 1);
288059
- var __dirname = "/home/runner/work/cex-broker/cex-broker/src";
288060
- var PROTO_FILE = "../proto/node.proto";
288061
- var packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_FILE));
285216
+ var PROTO_FILE = "./proto/node.proto";
285217
+ var packageDef = protoLoader.loadSync(PROTO_FILE);
288062
285218
  var grpcObj = grpc.loadPackageDefinition(packageDef);
288063
- var cexNode = grpcObj.cexBroker;
285219
+ var cexNode = grpcObj.cex_broker;
288064
285220
  function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
288065
285221
  const server = new grpc.Server;
288066
- server.addService(cexNode.CexService.service, {
285222
+ server.addService(cexNode.cex_service.service, {
288067
285223
  ExecuteAction: async (call, callback) => {
288068
285224
  if (!authenticateRequest(call, whitelistIps)) {
288069
285225
  return callback({
@@ -288243,9 +285399,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
288243
285399
  message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
288244
285400
  }, null);
288245
285401
  }
288246
- const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price), {
288247
- ...orderValue.params
288248
- });
285402
+ const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price), orderValue.params ?? {});
288249
285403
  callback(null, { result: JSON.stringify({ ...order }) });
288250
285404
  } catch (error) {
288251
285405
  log.error({ error });
@@ -288709,7 +285863,7 @@ class CEXBroker {
288709
285863
  }
288710
285864
  match = key.match(/^CEX_BROKER_(\w+)_API_(KEY|SECRET)$/);
288711
285865
  if (!match) {
288712
- log.warn(`⚠️ Skipping unrecognized env var: ${key}`);
285866
+ log.warn(`\u26A0\uFE0F Skipping unrecognized env var: ${key}`);
288713
285867
  continue;
288714
285868
  }
288715
285869
  const broker = match[1]?.toLowerCase() ?? "";
@@ -288724,7 +285878,7 @@ class CEXBroker {
288724
285878
  }
288725
285879
  }
288726
285880
  if (Object.keys(configMap).length === 0) {
288727
- log.error(`❌ NO CEX Broker Key Found`);
285881
+ log.error(`\u274C NO CEX Broker Key Found`);
288728
285882
  }
288729
285883
  for (const [broker, creds] of Object.entries(configMap)) {
288730
285884
  const hasKey = !!creds.apiKey;
@@ -288744,7 +285898,7 @@ class CEXBroker {
288744
285898
  apiKey: sec.apiKey,
288745
285899
  apiSecret: sec.apiSecret
288746
285900
  };
288747
- secondaryBrokers[+index2] = new ExchangeClass({
285901
+ const exchange = new ExchangeClass({
288748
285902
  apiKey: sec.apiKey,
288749
285903
  secret: sec.apiSecret,
288750
285904
  enableRateLimit: true,
@@ -288757,8 +285911,9 @@ class CEXBroker {
288757
285911
  recvWindow: 60000
288758
285912
  }
288759
285913
  });
285914
+ secondaryBrokers[+index2] = exchange;
288760
285915
  } else {
288761
- log.warn(`⚠️ Incomplete secondary credentials for broker "${broker}" at index ${index2}`);
285916
+ log.warn(`\u26A0\uFE0F Incomplete secondary credentials for broker "${broker}" at index ${index2}`);
288762
285917
  }
288763
285918
  }
288764
285919
  }
@@ -288767,7 +285922,7 @@ class CEXBroker {
288767
285922
  apiSecret: creds.apiSecret ?? "",
288768
285923
  secondaryKeys
288769
285924
  };
288770
- log.info(`✅ Loaded credentials for broker "${broker}"`);
285925
+ log.info(`\u2705 Loaded credentials for broker "${broker}"`);
288771
285926
  const client = new ExchangeClass({
288772
285927
  apiKey: creds.apiKey,
288773
285928
  secret: creds.apiSecret,
@@ -288791,7 +285946,7 @@ class CEXBroker {
288791
285946
  missing.push("API_KEY");
288792
285947
  if (!hasSecret)
288793
285948
  missing.push("API_SECRET");
288794
- log.warn(`❌ Missing ${missing.join(" and ")} for broker "${broker}"`);
285949
+ log.warn(`\u274C Missing ${missing.join(" and ")} for broker "${broker}"`);
288795
285950
  }
288796
285951
  }
288797
285952
  }
@@ -288813,7 +285968,7 @@ class CEXBroker {
288813
285968
  if (!ExchangeClass) {
288814
285969
  throw new Error(`Invalid Broker : ${broker}`);
288815
285970
  }
288816
- log.info(`✅ Loaded credentials for broker "${broker}" (${1 + (creds2.secondaryKeys?.length || 0)} key sets)`);
285971
+ log.info(`\u2705 Loaded credentials for broker "${broker}" (${1 + (creds2.secondaryKeys?.length || 0)} key sets)`);
288817
285972
  const secondaryBroker = [];
288818
285973
  for (const index2 of Object.keys(creds2.secondaryKeys)) {
288819
285974
  const sec = creds2.secondaryKeys[+index2];
@@ -288832,7 +285987,7 @@ class CEXBroker {
288832
285987
  }
288833
285988
  });
288834
285989
  } else {
288835
- log.warn(`⚠️ Incomplete secondary credentials for broker "${broker}" at index ${index2}`);
285990
+ log.warn(`\u26A0\uFE0F Incomplete secondary credentials for broker "${broker}" at index ${index2}`);
288836
285991
  }
288837
285992
  }
288838
285993
  this.#brokerConfig[broker] = {