@base44-preview/cli 0.1.29-pr.656.a562be5 → 0.1.32-pr.643.19a1aec
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/cli/index.js +3326 -180
- package/dist/cli/index.js.map +33 -18
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -171420,6 +171420,2889 @@ var require_tmp = __commonJS(function(exports, module) {
|
|
|
171420
171420
|
exports.setGracefulCleanup = setGracefulCleanup;
|
|
171421
171421
|
});
|
|
171422
171422
|
|
|
171423
|
+
// ../../node_modules/ws/lib/constants.js
|
|
171424
|
+
var require_constants6 = __commonJS(function(exports, module) {
|
|
171425
|
+
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
171426
|
+
var hasBlob = typeof Blob !== "undefined";
|
|
171427
|
+
if (hasBlob)
|
|
171428
|
+
BINARY_TYPES.push("blob");
|
|
171429
|
+
module.exports = {
|
|
171430
|
+
BINARY_TYPES,
|
|
171431
|
+
CLOSE_TIMEOUT: 30000,
|
|
171432
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
171433
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
171434
|
+
hasBlob,
|
|
171435
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
171436
|
+
kListener: Symbol("kListener"),
|
|
171437
|
+
kStatusCode: Symbol("status-code"),
|
|
171438
|
+
kWebSocket: Symbol("websocket"),
|
|
171439
|
+
NOOP: () => {}
|
|
171440
|
+
};
|
|
171441
|
+
});
|
|
171442
|
+
|
|
171443
|
+
// ../../node_modules/ws/lib/buffer-util.js
|
|
171444
|
+
var require_buffer_util = __commonJS(function(exports, module) {
|
|
171445
|
+
var { EMPTY_BUFFER } = require_constants6();
|
|
171446
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
171447
|
+
function concat(list, totalLength) {
|
|
171448
|
+
if (list.length === 0)
|
|
171449
|
+
return EMPTY_BUFFER;
|
|
171450
|
+
if (list.length === 1)
|
|
171451
|
+
return list[0];
|
|
171452
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
171453
|
+
let offset = 0;
|
|
171454
|
+
for (let i = 0;i < list.length; i++) {
|
|
171455
|
+
const buf = list[i];
|
|
171456
|
+
target.set(buf, offset);
|
|
171457
|
+
offset += buf.length;
|
|
171458
|
+
}
|
|
171459
|
+
if (offset < totalLength) {
|
|
171460
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
171461
|
+
}
|
|
171462
|
+
return target;
|
|
171463
|
+
}
|
|
171464
|
+
function _mask(source, mask, output, offset, length) {
|
|
171465
|
+
for (let i = 0;i < length; i++) {
|
|
171466
|
+
output[offset + i] = source[i] ^ mask[i & 3];
|
|
171467
|
+
}
|
|
171468
|
+
}
|
|
171469
|
+
function _unmask(buffer, mask) {
|
|
171470
|
+
for (let i = 0;i < buffer.length; i++) {
|
|
171471
|
+
buffer[i] ^= mask[i & 3];
|
|
171472
|
+
}
|
|
171473
|
+
}
|
|
171474
|
+
function toArrayBuffer(buf) {
|
|
171475
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
171476
|
+
return buf.buffer;
|
|
171477
|
+
}
|
|
171478
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
171479
|
+
}
|
|
171480
|
+
function toBuffer(data) {
|
|
171481
|
+
toBuffer.readOnly = true;
|
|
171482
|
+
if (Buffer.isBuffer(data))
|
|
171483
|
+
return data;
|
|
171484
|
+
let buf;
|
|
171485
|
+
if (data instanceof ArrayBuffer) {
|
|
171486
|
+
buf = new FastBuffer(data);
|
|
171487
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
171488
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
171489
|
+
} else {
|
|
171490
|
+
buf = Buffer.from(data);
|
|
171491
|
+
toBuffer.readOnly = false;
|
|
171492
|
+
}
|
|
171493
|
+
return buf;
|
|
171494
|
+
}
|
|
171495
|
+
module.exports = {
|
|
171496
|
+
concat,
|
|
171497
|
+
mask: _mask,
|
|
171498
|
+
toArrayBuffer,
|
|
171499
|
+
toBuffer,
|
|
171500
|
+
unmask: _unmask
|
|
171501
|
+
};
|
|
171502
|
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
171503
|
+
try {
|
|
171504
|
+
const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
|
|
171505
|
+
module.exports.mask = function(source, mask2, output, offset, length) {
|
|
171506
|
+
if (length < 48)
|
|
171507
|
+
_mask(source, mask2, output, offset, length);
|
|
171508
|
+
else
|
|
171509
|
+
bufferUtil.mask(source, mask2, output, offset, length);
|
|
171510
|
+
};
|
|
171511
|
+
module.exports.unmask = function(buffer, mask) {
|
|
171512
|
+
if (buffer.length < 32)
|
|
171513
|
+
_unmask(buffer, mask);
|
|
171514
|
+
else
|
|
171515
|
+
bufferUtil.unmask(buffer, mask);
|
|
171516
|
+
};
|
|
171517
|
+
} catch (e) {}
|
|
171518
|
+
}
|
|
171519
|
+
});
|
|
171520
|
+
|
|
171521
|
+
// ../../node_modules/ws/lib/limiter.js
|
|
171522
|
+
var require_limiter = __commonJS(function(exports, module) {
|
|
171523
|
+
var kDone = Symbol("kDone");
|
|
171524
|
+
var kRun = Symbol("kRun");
|
|
171525
|
+
|
|
171526
|
+
class Limiter {
|
|
171527
|
+
constructor(concurrency) {
|
|
171528
|
+
this[kDone] = () => {
|
|
171529
|
+
this.pending--;
|
|
171530
|
+
this[kRun]();
|
|
171531
|
+
};
|
|
171532
|
+
this.concurrency = concurrency || Infinity;
|
|
171533
|
+
this.jobs = [];
|
|
171534
|
+
this.pending = 0;
|
|
171535
|
+
}
|
|
171536
|
+
add(job) {
|
|
171537
|
+
this.jobs.push(job);
|
|
171538
|
+
this[kRun]();
|
|
171539
|
+
}
|
|
171540
|
+
[kRun]() {
|
|
171541
|
+
if (this.pending === this.concurrency)
|
|
171542
|
+
return;
|
|
171543
|
+
if (this.jobs.length) {
|
|
171544
|
+
const job = this.jobs.shift();
|
|
171545
|
+
this.pending++;
|
|
171546
|
+
job(this[kDone]);
|
|
171547
|
+
}
|
|
171548
|
+
}
|
|
171549
|
+
}
|
|
171550
|
+
module.exports = Limiter;
|
|
171551
|
+
});
|
|
171552
|
+
|
|
171553
|
+
// ../../node_modules/ws/lib/permessage-deflate.js
|
|
171554
|
+
var require_permessage_deflate = __commonJS(function(exports, module) {
|
|
171555
|
+
var zlib = __require("zlib");
|
|
171556
|
+
var bufferUtil = require_buffer_util();
|
|
171557
|
+
var Limiter = require_limiter();
|
|
171558
|
+
var { kStatusCode } = require_constants6();
|
|
171559
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
171560
|
+
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
171561
|
+
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
171562
|
+
var kTotalLength = Symbol("total-length");
|
|
171563
|
+
var kCallback = Symbol("callback");
|
|
171564
|
+
var kBuffers = Symbol("buffers");
|
|
171565
|
+
var kError = Symbol("error");
|
|
171566
|
+
var zlibLimiter;
|
|
171567
|
+
|
|
171568
|
+
class PerMessageDeflate {
|
|
171569
|
+
constructor(options) {
|
|
171570
|
+
this._options = options || {};
|
|
171571
|
+
this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
171572
|
+
this._maxPayload = this._options.maxPayload | 0;
|
|
171573
|
+
this._isServer = !!this._options.isServer;
|
|
171574
|
+
this._deflate = null;
|
|
171575
|
+
this._inflate = null;
|
|
171576
|
+
this.params = null;
|
|
171577
|
+
if (!zlibLimiter) {
|
|
171578
|
+
const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
|
|
171579
|
+
zlibLimiter = new Limiter(concurrency);
|
|
171580
|
+
}
|
|
171581
|
+
}
|
|
171582
|
+
static get extensionName() {
|
|
171583
|
+
return "permessage-deflate";
|
|
171584
|
+
}
|
|
171585
|
+
offer() {
|
|
171586
|
+
const params = {};
|
|
171587
|
+
if (this._options.serverNoContextTakeover) {
|
|
171588
|
+
params.server_no_context_takeover = true;
|
|
171589
|
+
}
|
|
171590
|
+
if (this._options.clientNoContextTakeover) {
|
|
171591
|
+
params.client_no_context_takeover = true;
|
|
171592
|
+
}
|
|
171593
|
+
if (this._options.serverMaxWindowBits) {
|
|
171594
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
171595
|
+
}
|
|
171596
|
+
if (this._options.clientMaxWindowBits) {
|
|
171597
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
171598
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
171599
|
+
params.client_max_window_bits = true;
|
|
171600
|
+
}
|
|
171601
|
+
return params;
|
|
171602
|
+
}
|
|
171603
|
+
accept(configurations) {
|
|
171604
|
+
configurations = this.normalizeParams(configurations);
|
|
171605
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
171606
|
+
return this.params;
|
|
171607
|
+
}
|
|
171608
|
+
cleanup() {
|
|
171609
|
+
if (this._inflate) {
|
|
171610
|
+
this._inflate.close();
|
|
171611
|
+
this._inflate = null;
|
|
171612
|
+
}
|
|
171613
|
+
if (this._deflate) {
|
|
171614
|
+
const callback = this._deflate[kCallback];
|
|
171615
|
+
this._deflate.close();
|
|
171616
|
+
this._deflate = null;
|
|
171617
|
+
if (callback) {
|
|
171618
|
+
callback(new Error("The deflate stream was closed while data was being processed"));
|
|
171619
|
+
}
|
|
171620
|
+
}
|
|
171621
|
+
}
|
|
171622
|
+
acceptAsServer(offers) {
|
|
171623
|
+
const opts = this._options;
|
|
171624
|
+
const accepted = offers.find((params) => {
|
|
171625
|
+
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) {
|
|
171626
|
+
return false;
|
|
171627
|
+
}
|
|
171628
|
+
return true;
|
|
171629
|
+
});
|
|
171630
|
+
if (!accepted) {
|
|
171631
|
+
throw new Error("None of the extension offers can be accepted");
|
|
171632
|
+
}
|
|
171633
|
+
if (opts.serverNoContextTakeover) {
|
|
171634
|
+
accepted.server_no_context_takeover = true;
|
|
171635
|
+
}
|
|
171636
|
+
if (opts.clientNoContextTakeover) {
|
|
171637
|
+
accepted.client_no_context_takeover = true;
|
|
171638
|
+
}
|
|
171639
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
171640
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
171641
|
+
}
|
|
171642
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
171643
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
171644
|
+
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
171645
|
+
delete accepted.client_max_window_bits;
|
|
171646
|
+
}
|
|
171647
|
+
return accepted;
|
|
171648
|
+
}
|
|
171649
|
+
acceptAsClient(response) {
|
|
171650
|
+
const params = response[0];
|
|
171651
|
+
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
171652
|
+
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
171653
|
+
}
|
|
171654
|
+
if (!params.client_max_window_bits) {
|
|
171655
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
171656
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
171657
|
+
}
|
|
171658
|
+
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
171659
|
+
throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
171660
|
+
}
|
|
171661
|
+
return params;
|
|
171662
|
+
}
|
|
171663
|
+
normalizeParams(configurations) {
|
|
171664
|
+
configurations.forEach((params) => {
|
|
171665
|
+
Object.keys(params).forEach((key) => {
|
|
171666
|
+
let value = params[key];
|
|
171667
|
+
if (value.length > 1) {
|
|
171668
|
+
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
171669
|
+
}
|
|
171670
|
+
value = value[0];
|
|
171671
|
+
if (key === "client_max_window_bits") {
|
|
171672
|
+
if (value !== true) {
|
|
171673
|
+
const num = +value;
|
|
171674
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
171675
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171676
|
+
}
|
|
171677
|
+
value = num;
|
|
171678
|
+
} else if (!this._isServer) {
|
|
171679
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171680
|
+
}
|
|
171681
|
+
} else if (key === "server_max_window_bits") {
|
|
171682
|
+
const num = +value;
|
|
171683
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
171684
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171685
|
+
}
|
|
171686
|
+
value = num;
|
|
171687
|
+
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
171688
|
+
if (value !== true) {
|
|
171689
|
+
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
171690
|
+
}
|
|
171691
|
+
} else {
|
|
171692
|
+
throw new Error(`Unknown parameter "${key}"`);
|
|
171693
|
+
}
|
|
171694
|
+
params[key] = value;
|
|
171695
|
+
});
|
|
171696
|
+
});
|
|
171697
|
+
return configurations;
|
|
171698
|
+
}
|
|
171699
|
+
decompress(data, fin, callback) {
|
|
171700
|
+
zlibLimiter.add((done) => {
|
|
171701
|
+
this._decompress(data, fin, (err, result) => {
|
|
171702
|
+
done();
|
|
171703
|
+
callback(err, result);
|
|
171704
|
+
});
|
|
171705
|
+
});
|
|
171706
|
+
}
|
|
171707
|
+
compress(data, fin, callback) {
|
|
171708
|
+
zlibLimiter.add((done) => {
|
|
171709
|
+
this._compress(data, fin, (err, result) => {
|
|
171710
|
+
done();
|
|
171711
|
+
callback(err, result);
|
|
171712
|
+
});
|
|
171713
|
+
});
|
|
171714
|
+
}
|
|
171715
|
+
_decompress(data, fin, callback) {
|
|
171716
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
171717
|
+
if (!this._inflate) {
|
|
171718
|
+
const key = `${endpoint}_max_window_bits`;
|
|
171719
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
171720
|
+
this._inflate = zlib.createInflateRaw({
|
|
171721
|
+
...this._options.zlibInflateOptions,
|
|
171722
|
+
windowBits
|
|
171723
|
+
});
|
|
171724
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
171725
|
+
this._inflate[kTotalLength] = 0;
|
|
171726
|
+
this._inflate[kBuffers] = [];
|
|
171727
|
+
this._inflate.on("error", inflateOnError);
|
|
171728
|
+
this._inflate.on("data", inflateOnData);
|
|
171729
|
+
}
|
|
171730
|
+
this._inflate[kCallback] = callback;
|
|
171731
|
+
this._inflate.write(data);
|
|
171732
|
+
if (fin)
|
|
171733
|
+
this._inflate.write(TRAILER);
|
|
171734
|
+
this._inflate.flush(() => {
|
|
171735
|
+
const err = this._inflate[kError];
|
|
171736
|
+
if (err) {
|
|
171737
|
+
this._inflate.close();
|
|
171738
|
+
this._inflate = null;
|
|
171739
|
+
callback(err);
|
|
171740
|
+
return;
|
|
171741
|
+
}
|
|
171742
|
+
const data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
171743
|
+
if (this._inflate._readableState.endEmitted) {
|
|
171744
|
+
this._inflate.close();
|
|
171745
|
+
this._inflate = null;
|
|
171746
|
+
} else {
|
|
171747
|
+
this._inflate[kTotalLength] = 0;
|
|
171748
|
+
this._inflate[kBuffers] = [];
|
|
171749
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
171750
|
+
this._inflate.reset();
|
|
171751
|
+
}
|
|
171752
|
+
}
|
|
171753
|
+
callback(null, data);
|
|
171754
|
+
});
|
|
171755
|
+
}
|
|
171756
|
+
_compress(data, fin, callback) {
|
|
171757
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
171758
|
+
if (!this._deflate) {
|
|
171759
|
+
const key = `${endpoint}_max_window_bits`;
|
|
171760
|
+
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
171761
|
+
this._deflate = zlib.createDeflateRaw({
|
|
171762
|
+
...this._options.zlibDeflateOptions,
|
|
171763
|
+
windowBits
|
|
171764
|
+
});
|
|
171765
|
+
this._deflate[kTotalLength] = 0;
|
|
171766
|
+
this._deflate[kBuffers] = [];
|
|
171767
|
+
this._deflate.on("data", deflateOnData);
|
|
171768
|
+
}
|
|
171769
|
+
this._deflate[kCallback] = callback;
|
|
171770
|
+
this._deflate.write(data);
|
|
171771
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
171772
|
+
if (!this._deflate) {
|
|
171773
|
+
return;
|
|
171774
|
+
}
|
|
171775
|
+
let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
171776
|
+
if (fin) {
|
|
171777
|
+
data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
|
|
171778
|
+
}
|
|
171779
|
+
this._deflate[kCallback] = null;
|
|
171780
|
+
this._deflate[kTotalLength] = 0;
|
|
171781
|
+
this._deflate[kBuffers] = [];
|
|
171782
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
171783
|
+
this._deflate.reset();
|
|
171784
|
+
}
|
|
171785
|
+
callback(null, data);
|
|
171786
|
+
});
|
|
171787
|
+
}
|
|
171788
|
+
}
|
|
171789
|
+
module.exports = PerMessageDeflate;
|
|
171790
|
+
function deflateOnData(chunk) {
|
|
171791
|
+
this[kBuffers].push(chunk);
|
|
171792
|
+
this[kTotalLength] += chunk.length;
|
|
171793
|
+
}
|
|
171794
|
+
function inflateOnData(chunk) {
|
|
171795
|
+
this[kTotalLength] += chunk.length;
|
|
171796
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
171797
|
+
this[kBuffers].push(chunk);
|
|
171798
|
+
return;
|
|
171799
|
+
}
|
|
171800
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
171801
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
171802
|
+
this[kError][kStatusCode] = 1009;
|
|
171803
|
+
this.removeListener("data", inflateOnData);
|
|
171804
|
+
this.reset();
|
|
171805
|
+
}
|
|
171806
|
+
function inflateOnError(err) {
|
|
171807
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
171808
|
+
if (this[kError]) {
|
|
171809
|
+
this[kCallback](this[kError]);
|
|
171810
|
+
return;
|
|
171811
|
+
}
|
|
171812
|
+
err[kStatusCode] = 1007;
|
|
171813
|
+
this[kCallback](err);
|
|
171814
|
+
}
|
|
171815
|
+
});
|
|
171816
|
+
|
|
171817
|
+
// ../../node_modules/ws/lib/validation.js
|
|
171818
|
+
var require_validation = __commonJS(function(exports, module) {
|
|
171819
|
+
var { isUtf8 } = __require("buffer");
|
|
171820
|
+
var { hasBlob } = require_constants6();
|
|
171821
|
+
var tokenChars = [
|
|
171822
|
+
0,
|
|
171823
|
+
0,
|
|
171824
|
+
0,
|
|
171825
|
+
0,
|
|
171826
|
+
0,
|
|
171827
|
+
0,
|
|
171828
|
+
0,
|
|
171829
|
+
0,
|
|
171830
|
+
0,
|
|
171831
|
+
0,
|
|
171832
|
+
0,
|
|
171833
|
+
0,
|
|
171834
|
+
0,
|
|
171835
|
+
0,
|
|
171836
|
+
0,
|
|
171837
|
+
0,
|
|
171838
|
+
0,
|
|
171839
|
+
0,
|
|
171840
|
+
0,
|
|
171841
|
+
0,
|
|
171842
|
+
0,
|
|
171843
|
+
0,
|
|
171844
|
+
0,
|
|
171845
|
+
0,
|
|
171846
|
+
0,
|
|
171847
|
+
0,
|
|
171848
|
+
0,
|
|
171849
|
+
0,
|
|
171850
|
+
0,
|
|
171851
|
+
0,
|
|
171852
|
+
0,
|
|
171853
|
+
0,
|
|
171854
|
+
0,
|
|
171855
|
+
1,
|
|
171856
|
+
0,
|
|
171857
|
+
1,
|
|
171858
|
+
1,
|
|
171859
|
+
1,
|
|
171860
|
+
1,
|
|
171861
|
+
1,
|
|
171862
|
+
0,
|
|
171863
|
+
0,
|
|
171864
|
+
1,
|
|
171865
|
+
1,
|
|
171866
|
+
0,
|
|
171867
|
+
1,
|
|
171868
|
+
1,
|
|
171869
|
+
0,
|
|
171870
|
+
1,
|
|
171871
|
+
1,
|
|
171872
|
+
1,
|
|
171873
|
+
1,
|
|
171874
|
+
1,
|
|
171875
|
+
1,
|
|
171876
|
+
1,
|
|
171877
|
+
1,
|
|
171878
|
+
1,
|
|
171879
|
+
1,
|
|
171880
|
+
0,
|
|
171881
|
+
0,
|
|
171882
|
+
0,
|
|
171883
|
+
0,
|
|
171884
|
+
0,
|
|
171885
|
+
0,
|
|
171886
|
+
0,
|
|
171887
|
+
1,
|
|
171888
|
+
1,
|
|
171889
|
+
1,
|
|
171890
|
+
1,
|
|
171891
|
+
1,
|
|
171892
|
+
1,
|
|
171893
|
+
1,
|
|
171894
|
+
1,
|
|
171895
|
+
1,
|
|
171896
|
+
1,
|
|
171897
|
+
1,
|
|
171898
|
+
1,
|
|
171899
|
+
1,
|
|
171900
|
+
1,
|
|
171901
|
+
1,
|
|
171902
|
+
1,
|
|
171903
|
+
1,
|
|
171904
|
+
1,
|
|
171905
|
+
1,
|
|
171906
|
+
1,
|
|
171907
|
+
1,
|
|
171908
|
+
1,
|
|
171909
|
+
1,
|
|
171910
|
+
1,
|
|
171911
|
+
1,
|
|
171912
|
+
1,
|
|
171913
|
+
0,
|
|
171914
|
+
0,
|
|
171915
|
+
0,
|
|
171916
|
+
1,
|
|
171917
|
+
1,
|
|
171918
|
+
1,
|
|
171919
|
+
1,
|
|
171920
|
+
1,
|
|
171921
|
+
1,
|
|
171922
|
+
1,
|
|
171923
|
+
1,
|
|
171924
|
+
1,
|
|
171925
|
+
1,
|
|
171926
|
+
1,
|
|
171927
|
+
1,
|
|
171928
|
+
1,
|
|
171929
|
+
1,
|
|
171930
|
+
1,
|
|
171931
|
+
1,
|
|
171932
|
+
1,
|
|
171933
|
+
1,
|
|
171934
|
+
1,
|
|
171935
|
+
1,
|
|
171936
|
+
1,
|
|
171937
|
+
1,
|
|
171938
|
+
1,
|
|
171939
|
+
1,
|
|
171940
|
+
1,
|
|
171941
|
+
1,
|
|
171942
|
+
1,
|
|
171943
|
+
1,
|
|
171944
|
+
1,
|
|
171945
|
+
0,
|
|
171946
|
+
1,
|
|
171947
|
+
0,
|
|
171948
|
+
1,
|
|
171949
|
+
0
|
|
171950
|
+
];
|
|
171951
|
+
function isValidStatusCode(code) {
|
|
171952
|
+
return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
171953
|
+
}
|
|
171954
|
+
function _isValidUTF8(buf) {
|
|
171955
|
+
const len = buf.length;
|
|
171956
|
+
let i = 0;
|
|
171957
|
+
while (i < len) {
|
|
171958
|
+
if ((buf[i] & 128) === 0) {
|
|
171959
|
+
i++;
|
|
171960
|
+
} else if ((buf[i] & 224) === 192) {
|
|
171961
|
+
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
171962
|
+
return false;
|
|
171963
|
+
}
|
|
171964
|
+
i += 2;
|
|
171965
|
+
} else if ((buf[i] & 240) === 224) {
|
|
171966
|
+
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) {
|
|
171967
|
+
return false;
|
|
171968
|
+
}
|
|
171969
|
+
i += 3;
|
|
171970
|
+
} else if ((buf[i] & 248) === 240) {
|
|
171971
|
+
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) {
|
|
171972
|
+
return false;
|
|
171973
|
+
}
|
|
171974
|
+
i += 4;
|
|
171975
|
+
} else {
|
|
171976
|
+
return false;
|
|
171977
|
+
}
|
|
171978
|
+
}
|
|
171979
|
+
return true;
|
|
171980
|
+
}
|
|
171981
|
+
function isBlob(value) {
|
|
171982
|
+
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");
|
|
171983
|
+
}
|
|
171984
|
+
module.exports = {
|
|
171985
|
+
isBlob,
|
|
171986
|
+
isValidStatusCode,
|
|
171987
|
+
isValidUTF8: _isValidUTF8,
|
|
171988
|
+
tokenChars
|
|
171989
|
+
};
|
|
171990
|
+
if (isUtf8) {
|
|
171991
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
171992
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
171993
|
+
};
|
|
171994
|
+
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
171995
|
+
try {
|
|
171996
|
+
const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
|
|
171997
|
+
module.exports.isValidUTF8 = function(buf) {
|
|
171998
|
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
171999
|
+
};
|
|
172000
|
+
} catch (e) {}
|
|
172001
|
+
}
|
|
172002
|
+
});
|
|
172003
|
+
|
|
172004
|
+
// ../../node_modules/ws/lib/receiver.js
|
|
172005
|
+
var require_receiver = __commonJS(function(exports, module) {
|
|
172006
|
+
var { Writable } = __require("stream");
|
|
172007
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
172008
|
+
var {
|
|
172009
|
+
BINARY_TYPES,
|
|
172010
|
+
EMPTY_BUFFER,
|
|
172011
|
+
kStatusCode,
|
|
172012
|
+
kWebSocket
|
|
172013
|
+
} = require_constants6();
|
|
172014
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
172015
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
172016
|
+
var FastBuffer = Buffer[Symbol.species];
|
|
172017
|
+
var GET_INFO = 0;
|
|
172018
|
+
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
172019
|
+
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
172020
|
+
var GET_MASK = 3;
|
|
172021
|
+
var GET_DATA = 4;
|
|
172022
|
+
var INFLATING = 5;
|
|
172023
|
+
var DEFER_EVENT = 6;
|
|
172024
|
+
|
|
172025
|
+
class Receiver extends Writable {
|
|
172026
|
+
constructor(options = {}) {
|
|
172027
|
+
super();
|
|
172028
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
|
|
172029
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
172030
|
+
this._extensions = options.extensions || {};
|
|
172031
|
+
this._isServer = !!options.isServer;
|
|
172032
|
+
this._maxBufferedChunks = options.maxBufferedChunks | 0;
|
|
172033
|
+
this._maxFragments = options.maxFragments | 0;
|
|
172034
|
+
this._maxPayload = options.maxPayload | 0;
|
|
172035
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
172036
|
+
this[kWebSocket] = undefined;
|
|
172037
|
+
this._bufferedBytes = 0;
|
|
172038
|
+
this._buffers = [];
|
|
172039
|
+
this._compressed = false;
|
|
172040
|
+
this._payloadLength = 0;
|
|
172041
|
+
this._mask = undefined;
|
|
172042
|
+
this._fragmented = 0;
|
|
172043
|
+
this._masked = false;
|
|
172044
|
+
this._fin = false;
|
|
172045
|
+
this._opcode = 0;
|
|
172046
|
+
this._totalPayloadLength = 0;
|
|
172047
|
+
this._messageLength = 0;
|
|
172048
|
+
this._fragments = [];
|
|
172049
|
+
this._errored = false;
|
|
172050
|
+
this._loop = false;
|
|
172051
|
+
this._state = GET_INFO;
|
|
172052
|
+
}
|
|
172053
|
+
_write(chunk, encoding, cb) {
|
|
172054
|
+
if (this._opcode === 8 && this._state == GET_INFO)
|
|
172055
|
+
return cb();
|
|
172056
|
+
if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
|
|
172057
|
+
cb(this.createError(RangeError, "Too many buffered chunks", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
172058
|
+
return;
|
|
172059
|
+
}
|
|
172060
|
+
this._bufferedBytes += chunk.length;
|
|
172061
|
+
this._buffers.push(chunk);
|
|
172062
|
+
this.startLoop(cb);
|
|
172063
|
+
}
|
|
172064
|
+
consume(n) {
|
|
172065
|
+
this._bufferedBytes -= n;
|
|
172066
|
+
if (n === this._buffers[0].length)
|
|
172067
|
+
return this._buffers.shift();
|
|
172068
|
+
if (n < this._buffers[0].length) {
|
|
172069
|
+
const buf = this._buffers[0];
|
|
172070
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
172071
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
172072
|
+
}
|
|
172073
|
+
const dst = Buffer.allocUnsafe(n);
|
|
172074
|
+
do {
|
|
172075
|
+
const buf = this._buffers[0];
|
|
172076
|
+
const offset = dst.length - n;
|
|
172077
|
+
if (n >= buf.length) {
|
|
172078
|
+
dst.set(this._buffers.shift(), offset);
|
|
172079
|
+
} else {
|
|
172080
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
172081
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
172082
|
+
}
|
|
172083
|
+
n -= buf.length;
|
|
172084
|
+
} while (n > 0);
|
|
172085
|
+
return dst;
|
|
172086
|
+
}
|
|
172087
|
+
startLoop(cb) {
|
|
172088
|
+
this._loop = true;
|
|
172089
|
+
do {
|
|
172090
|
+
switch (this._state) {
|
|
172091
|
+
case GET_INFO:
|
|
172092
|
+
this.getInfo(cb);
|
|
172093
|
+
break;
|
|
172094
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
172095
|
+
this.getPayloadLength16(cb);
|
|
172096
|
+
break;
|
|
172097
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
172098
|
+
this.getPayloadLength64(cb);
|
|
172099
|
+
break;
|
|
172100
|
+
case GET_MASK:
|
|
172101
|
+
this.getMask();
|
|
172102
|
+
break;
|
|
172103
|
+
case GET_DATA:
|
|
172104
|
+
this.getData(cb);
|
|
172105
|
+
break;
|
|
172106
|
+
case INFLATING:
|
|
172107
|
+
case DEFER_EVENT:
|
|
172108
|
+
this._loop = false;
|
|
172109
|
+
return;
|
|
172110
|
+
}
|
|
172111
|
+
} while (this._loop);
|
|
172112
|
+
if (!this._errored)
|
|
172113
|
+
cb();
|
|
172114
|
+
}
|
|
172115
|
+
getInfo(cb) {
|
|
172116
|
+
if (this._bufferedBytes < 2) {
|
|
172117
|
+
this._loop = false;
|
|
172118
|
+
return;
|
|
172119
|
+
}
|
|
172120
|
+
const buf = this.consume(2);
|
|
172121
|
+
if ((buf[0] & 48) !== 0) {
|
|
172122
|
+
const error = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
|
|
172123
|
+
cb(error);
|
|
172124
|
+
return;
|
|
172125
|
+
}
|
|
172126
|
+
const compressed = (buf[0] & 64) === 64;
|
|
172127
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
172128
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
172129
|
+
cb(error);
|
|
172130
|
+
return;
|
|
172131
|
+
}
|
|
172132
|
+
this._fin = (buf[0] & 128) === 128;
|
|
172133
|
+
this._opcode = buf[0] & 15;
|
|
172134
|
+
this._payloadLength = buf[1] & 127;
|
|
172135
|
+
if (this._opcode === 0) {
|
|
172136
|
+
if (compressed) {
|
|
172137
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
172138
|
+
cb(error);
|
|
172139
|
+
return;
|
|
172140
|
+
}
|
|
172141
|
+
if (!this._fragmented) {
|
|
172142
|
+
const error = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
172143
|
+
cb(error);
|
|
172144
|
+
return;
|
|
172145
|
+
}
|
|
172146
|
+
this._opcode = this._fragmented;
|
|
172147
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
172148
|
+
if (this._fragmented) {
|
|
172149
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
172150
|
+
cb(error);
|
|
172151
|
+
return;
|
|
172152
|
+
}
|
|
172153
|
+
this._compressed = compressed;
|
|
172154
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
172155
|
+
if (!this._fin) {
|
|
172156
|
+
const error = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
|
|
172157
|
+
cb(error);
|
|
172158
|
+
return;
|
|
172159
|
+
}
|
|
172160
|
+
if (compressed) {
|
|
172161
|
+
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
172162
|
+
cb(error);
|
|
172163
|
+
return;
|
|
172164
|
+
}
|
|
172165
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
172166
|
+
const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
|
|
172167
|
+
cb(error);
|
|
172168
|
+
return;
|
|
172169
|
+
}
|
|
172170
|
+
} else {
|
|
172171
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
172172
|
+
cb(error);
|
|
172173
|
+
return;
|
|
172174
|
+
}
|
|
172175
|
+
if (!this._fin && !this._fragmented)
|
|
172176
|
+
this._fragmented = this._opcode;
|
|
172177
|
+
this._masked = (buf[1] & 128) === 128;
|
|
172178
|
+
if (this._isServer) {
|
|
172179
|
+
if (!this._masked) {
|
|
172180
|
+
const error = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
|
|
172181
|
+
cb(error);
|
|
172182
|
+
return;
|
|
172183
|
+
}
|
|
172184
|
+
} else if (this._masked) {
|
|
172185
|
+
const error = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
|
|
172186
|
+
cb(error);
|
|
172187
|
+
return;
|
|
172188
|
+
}
|
|
172189
|
+
if (this._payloadLength === 126)
|
|
172190
|
+
this._state = GET_PAYLOAD_LENGTH_16;
|
|
172191
|
+
else if (this._payloadLength === 127)
|
|
172192
|
+
this._state = GET_PAYLOAD_LENGTH_64;
|
|
172193
|
+
else
|
|
172194
|
+
this.haveLength(cb);
|
|
172195
|
+
}
|
|
172196
|
+
getPayloadLength16(cb) {
|
|
172197
|
+
if (this._bufferedBytes < 2) {
|
|
172198
|
+
this._loop = false;
|
|
172199
|
+
return;
|
|
172200
|
+
}
|
|
172201
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
172202
|
+
this.haveLength(cb);
|
|
172203
|
+
}
|
|
172204
|
+
getPayloadLength64(cb) {
|
|
172205
|
+
if (this._bufferedBytes < 8) {
|
|
172206
|
+
this._loop = false;
|
|
172207
|
+
return;
|
|
172208
|
+
}
|
|
172209
|
+
const buf = this.consume(8);
|
|
172210
|
+
const num = buf.readUInt32BE(0);
|
|
172211
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
172212
|
+
const error = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
|
|
172213
|
+
cb(error);
|
|
172214
|
+
return;
|
|
172215
|
+
}
|
|
172216
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
172217
|
+
this.haveLength(cb);
|
|
172218
|
+
}
|
|
172219
|
+
haveLength(cb) {
|
|
172220
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
172221
|
+
this._totalPayloadLength += this._payloadLength;
|
|
172222
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
172223
|
+
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
172224
|
+
cb(error);
|
|
172225
|
+
return;
|
|
172226
|
+
}
|
|
172227
|
+
}
|
|
172228
|
+
if (this._masked)
|
|
172229
|
+
this._state = GET_MASK;
|
|
172230
|
+
else
|
|
172231
|
+
this._state = GET_DATA;
|
|
172232
|
+
}
|
|
172233
|
+
getMask() {
|
|
172234
|
+
if (this._bufferedBytes < 4) {
|
|
172235
|
+
this._loop = false;
|
|
172236
|
+
return;
|
|
172237
|
+
}
|
|
172238
|
+
this._mask = this.consume(4);
|
|
172239
|
+
this._state = GET_DATA;
|
|
172240
|
+
}
|
|
172241
|
+
getData(cb) {
|
|
172242
|
+
let data = EMPTY_BUFFER;
|
|
172243
|
+
if (this._payloadLength) {
|
|
172244
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
172245
|
+
this._loop = false;
|
|
172246
|
+
return;
|
|
172247
|
+
}
|
|
172248
|
+
data = this.consume(this._payloadLength);
|
|
172249
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
172250
|
+
unmask(data, this._mask);
|
|
172251
|
+
}
|
|
172252
|
+
}
|
|
172253
|
+
if (this._opcode > 7) {
|
|
172254
|
+
this.controlMessage(data, cb);
|
|
172255
|
+
return;
|
|
172256
|
+
}
|
|
172257
|
+
if (this._compressed) {
|
|
172258
|
+
this._state = INFLATING;
|
|
172259
|
+
this.decompress(data, cb);
|
|
172260
|
+
return;
|
|
172261
|
+
}
|
|
172262
|
+
if (data.length) {
|
|
172263
|
+
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
172264
|
+
const error = this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS");
|
|
172265
|
+
cb(error);
|
|
172266
|
+
return;
|
|
172267
|
+
}
|
|
172268
|
+
this._messageLength = this._totalPayloadLength;
|
|
172269
|
+
this._fragments.push(data);
|
|
172270
|
+
}
|
|
172271
|
+
this.dataMessage(cb);
|
|
172272
|
+
}
|
|
172273
|
+
decompress(data, cb) {
|
|
172274
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
172275
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
172276
|
+
if (err)
|
|
172277
|
+
return cb(err);
|
|
172278
|
+
if (buf.length) {
|
|
172279
|
+
this._messageLength += buf.length;
|
|
172280
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
172281
|
+
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
172282
|
+
cb(error);
|
|
172283
|
+
return;
|
|
172284
|
+
}
|
|
172285
|
+
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
172286
|
+
const error = this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS");
|
|
172287
|
+
cb(error);
|
|
172288
|
+
return;
|
|
172289
|
+
}
|
|
172290
|
+
this._fragments.push(buf);
|
|
172291
|
+
}
|
|
172292
|
+
this.dataMessage(cb);
|
|
172293
|
+
if (this._state === GET_INFO)
|
|
172294
|
+
this.startLoop(cb);
|
|
172295
|
+
});
|
|
172296
|
+
}
|
|
172297
|
+
dataMessage(cb) {
|
|
172298
|
+
if (!this._fin) {
|
|
172299
|
+
this._state = GET_INFO;
|
|
172300
|
+
return;
|
|
172301
|
+
}
|
|
172302
|
+
const messageLength = this._messageLength;
|
|
172303
|
+
const fragments = this._fragments;
|
|
172304
|
+
this._totalPayloadLength = 0;
|
|
172305
|
+
this._messageLength = 0;
|
|
172306
|
+
this._fragmented = 0;
|
|
172307
|
+
this._fragments = [];
|
|
172308
|
+
if (this._opcode === 2) {
|
|
172309
|
+
let data;
|
|
172310
|
+
if (this._binaryType === "nodebuffer") {
|
|
172311
|
+
data = concat(fragments, messageLength);
|
|
172312
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
172313
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
172314
|
+
} else if (this._binaryType === "blob") {
|
|
172315
|
+
data = new Blob(fragments);
|
|
172316
|
+
} else {
|
|
172317
|
+
data = fragments;
|
|
172318
|
+
}
|
|
172319
|
+
if (this._allowSynchronousEvents) {
|
|
172320
|
+
this.emit("message", data, true);
|
|
172321
|
+
this._state = GET_INFO;
|
|
172322
|
+
} else {
|
|
172323
|
+
this._state = DEFER_EVENT;
|
|
172324
|
+
setImmediate(() => {
|
|
172325
|
+
this.emit("message", data, true);
|
|
172326
|
+
this._state = GET_INFO;
|
|
172327
|
+
this.startLoop(cb);
|
|
172328
|
+
});
|
|
172329
|
+
}
|
|
172330
|
+
} else {
|
|
172331
|
+
const buf = concat(fragments, messageLength);
|
|
172332
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
172333
|
+
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
172334
|
+
cb(error);
|
|
172335
|
+
return;
|
|
172336
|
+
}
|
|
172337
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
172338
|
+
this.emit("message", buf, false);
|
|
172339
|
+
this._state = GET_INFO;
|
|
172340
|
+
} else {
|
|
172341
|
+
this._state = DEFER_EVENT;
|
|
172342
|
+
setImmediate(() => {
|
|
172343
|
+
this.emit("message", buf, false);
|
|
172344
|
+
this._state = GET_INFO;
|
|
172345
|
+
this.startLoop(cb);
|
|
172346
|
+
});
|
|
172347
|
+
}
|
|
172348
|
+
}
|
|
172349
|
+
}
|
|
172350
|
+
controlMessage(data, cb) {
|
|
172351
|
+
if (this._opcode === 8) {
|
|
172352
|
+
if (data.length === 0) {
|
|
172353
|
+
this._loop = false;
|
|
172354
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
172355
|
+
this.end();
|
|
172356
|
+
} else {
|
|
172357
|
+
const code = data.readUInt16BE(0);
|
|
172358
|
+
if (!isValidStatusCode(code)) {
|
|
172359
|
+
const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
|
|
172360
|
+
cb(error);
|
|
172361
|
+
return;
|
|
172362
|
+
}
|
|
172363
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
172364
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
172365
|
+
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
172366
|
+
cb(error);
|
|
172367
|
+
return;
|
|
172368
|
+
}
|
|
172369
|
+
this._loop = false;
|
|
172370
|
+
this.emit("conclude", code, buf);
|
|
172371
|
+
this.end();
|
|
172372
|
+
}
|
|
172373
|
+
this._state = GET_INFO;
|
|
172374
|
+
return;
|
|
172375
|
+
}
|
|
172376
|
+
if (this._allowSynchronousEvents) {
|
|
172377
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
172378
|
+
this._state = GET_INFO;
|
|
172379
|
+
} else {
|
|
172380
|
+
this._state = DEFER_EVENT;
|
|
172381
|
+
setImmediate(() => {
|
|
172382
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
172383
|
+
this._state = GET_INFO;
|
|
172384
|
+
this.startLoop(cb);
|
|
172385
|
+
});
|
|
172386
|
+
}
|
|
172387
|
+
}
|
|
172388
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
172389
|
+
this._loop = false;
|
|
172390
|
+
this._errored = true;
|
|
172391
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
172392
|
+
Error.captureStackTrace(err, this.createError);
|
|
172393
|
+
err.code = errorCode;
|
|
172394
|
+
err[kStatusCode] = statusCode;
|
|
172395
|
+
return err;
|
|
172396
|
+
}
|
|
172397
|
+
}
|
|
172398
|
+
module.exports = Receiver;
|
|
172399
|
+
});
|
|
172400
|
+
|
|
172401
|
+
// ../../node_modules/ws/lib/sender.js
|
|
172402
|
+
var require_sender = __commonJS(function(exports, module) {
|
|
172403
|
+
var { Duplex } = __require("stream");
|
|
172404
|
+
var { randomFillSync } = __require("crypto");
|
|
172405
|
+
var {
|
|
172406
|
+
types: { isUint8Array }
|
|
172407
|
+
} = __require("util");
|
|
172408
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
172409
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants6();
|
|
172410
|
+
var { isBlob, isValidStatusCode } = require_validation();
|
|
172411
|
+
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
172412
|
+
var kByteLength = Symbol("kByteLength");
|
|
172413
|
+
var maskBuffer = Buffer.alloc(4);
|
|
172414
|
+
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
172415
|
+
var randomPool;
|
|
172416
|
+
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
172417
|
+
var DEFAULT = 0;
|
|
172418
|
+
var DEFLATING = 1;
|
|
172419
|
+
var GET_BLOB_DATA = 2;
|
|
172420
|
+
|
|
172421
|
+
class Sender {
|
|
172422
|
+
constructor(socket, extensions, generateMask) {
|
|
172423
|
+
this._extensions = extensions || {};
|
|
172424
|
+
if (generateMask) {
|
|
172425
|
+
this._generateMask = generateMask;
|
|
172426
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
172427
|
+
}
|
|
172428
|
+
this._socket = socket;
|
|
172429
|
+
this._firstFragment = true;
|
|
172430
|
+
this._compress = false;
|
|
172431
|
+
this._bufferedBytes = 0;
|
|
172432
|
+
this._queue = [];
|
|
172433
|
+
this._state = DEFAULT;
|
|
172434
|
+
this.onerror = NOOP;
|
|
172435
|
+
this[kWebSocket] = undefined;
|
|
172436
|
+
}
|
|
172437
|
+
static frame(data, options) {
|
|
172438
|
+
let mask;
|
|
172439
|
+
let merge = false;
|
|
172440
|
+
let offset = 2;
|
|
172441
|
+
let skipMasking = false;
|
|
172442
|
+
if (options.mask) {
|
|
172443
|
+
mask = options.maskBuffer || maskBuffer;
|
|
172444
|
+
if (options.generateMask) {
|
|
172445
|
+
options.generateMask(mask);
|
|
172446
|
+
} else {
|
|
172447
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
172448
|
+
if (randomPool === undefined) {
|
|
172449
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
172450
|
+
}
|
|
172451
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
172452
|
+
randomPoolPointer = 0;
|
|
172453
|
+
}
|
|
172454
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
172455
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
172456
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
172457
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
172458
|
+
}
|
|
172459
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
172460
|
+
offset = 6;
|
|
172461
|
+
}
|
|
172462
|
+
let dataLength;
|
|
172463
|
+
if (typeof data === "string") {
|
|
172464
|
+
if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
|
|
172465
|
+
dataLength = options[kByteLength];
|
|
172466
|
+
} else {
|
|
172467
|
+
data = Buffer.from(data);
|
|
172468
|
+
dataLength = data.length;
|
|
172469
|
+
}
|
|
172470
|
+
} else {
|
|
172471
|
+
dataLength = data.length;
|
|
172472
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
172473
|
+
}
|
|
172474
|
+
let payloadLength = dataLength;
|
|
172475
|
+
if (dataLength >= 65536) {
|
|
172476
|
+
offset += 8;
|
|
172477
|
+
payloadLength = 127;
|
|
172478
|
+
} else if (dataLength > 125) {
|
|
172479
|
+
offset += 2;
|
|
172480
|
+
payloadLength = 126;
|
|
172481
|
+
}
|
|
172482
|
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
172483
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
172484
|
+
if (options.rsv1)
|
|
172485
|
+
target[0] |= 64;
|
|
172486
|
+
target[1] = payloadLength;
|
|
172487
|
+
if (payloadLength === 126) {
|
|
172488
|
+
target.writeUInt16BE(dataLength, 2);
|
|
172489
|
+
} else if (payloadLength === 127) {
|
|
172490
|
+
target[2] = target[3] = 0;
|
|
172491
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
172492
|
+
}
|
|
172493
|
+
if (!options.mask)
|
|
172494
|
+
return [target, data];
|
|
172495
|
+
target[1] |= 128;
|
|
172496
|
+
target[offset - 4] = mask[0];
|
|
172497
|
+
target[offset - 3] = mask[1];
|
|
172498
|
+
target[offset - 2] = mask[2];
|
|
172499
|
+
target[offset - 1] = mask[3];
|
|
172500
|
+
if (skipMasking)
|
|
172501
|
+
return [target, data];
|
|
172502
|
+
if (merge) {
|
|
172503
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
172504
|
+
return [target];
|
|
172505
|
+
}
|
|
172506
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
172507
|
+
return [target, data];
|
|
172508
|
+
}
|
|
172509
|
+
close(code, data, mask, cb) {
|
|
172510
|
+
let buf;
|
|
172511
|
+
if (code === undefined) {
|
|
172512
|
+
buf = EMPTY_BUFFER;
|
|
172513
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
172514
|
+
throw new TypeError("First argument must be a valid error code number");
|
|
172515
|
+
} else if (data === undefined || !data.length) {
|
|
172516
|
+
buf = Buffer.allocUnsafe(2);
|
|
172517
|
+
buf.writeUInt16BE(code, 0);
|
|
172518
|
+
} else {
|
|
172519
|
+
const length = Buffer.byteLength(data);
|
|
172520
|
+
if (length > 123) {
|
|
172521
|
+
throw new RangeError("The message must not be greater than 123 bytes");
|
|
172522
|
+
}
|
|
172523
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
172524
|
+
buf.writeUInt16BE(code, 0);
|
|
172525
|
+
if (typeof data === "string") {
|
|
172526
|
+
buf.write(data, 2);
|
|
172527
|
+
} else if (isUint8Array(data)) {
|
|
172528
|
+
buf.set(data, 2);
|
|
172529
|
+
} else {
|
|
172530
|
+
throw new TypeError("Second argument must be a string or a Uint8Array");
|
|
172531
|
+
}
|
|
172532
|
+
}
|
|
172533
|
+
const options = {
|
|
172534
|
+
[kByteLength]: buf.length,
|
|
172535
|
+
fin: true,
|
|
172536
|
+
generateMask: this._generateMask,
|
|
172537
|
+
mask,
|
|
172538
|
+
maskBuffer: this._maskBuffer,
|
|
172539
|
+
opcode: 8,
|
|
172540
|
+
readOnly: false,
|
|
172541
|
+
rsv1: false
|
|
172542
|
+
};
|
|
172543
|
+
if (this._state !== DEFAULT) {
|
|
172544
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
172545
|
+
} else {
|
|
172546
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
172547
|
+
}
|
|
172548
|
+
}
|
|
172549
|
+
ping(data, mask, cb) {
|
|
172550
|
+
let byteLength;
|
|
172551
|
+
let readOnly;
|
|
172552
|
+
if (typeof data === "string") {
|
|
172553
|
+
byteLength = Buffer.byteLength(data);
|
|
172554
|
+
readOnly = false;
|
|
172555
|
+
} else if (isBlob(data)) {
|
|
172556
|
+
byteLength = data.size;
|
|
172557
|
+
readOnly = false;
|
|
172558
|
+
} else {
|
|
172559
|
+
data = toBuffer(data);
|
|
172560
|
+
byteLength = data.length;
|
|
172561
|
+
readOnly = toBuffer.readOnly;
|
|
172562
|
+
}
|
|
172563
|
+
if (byteLength > 125) {
|
|
172564
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
172565
|
+
}
|
|
172566
|
+
const options = {
|
|
172567
|
+
[kByteLength]: byteLength,
|
|
172568
|
+
fin: true,
|
|
172569
|
+
generateMask: this._generateMask,
|
|
172570
|
+
mask,
|
|
172571
|
+
maskBuffer: this._maskBuffer,
|
|
172572
|
+
opcode: 9,
|
|
172573
|
+
readOnly,
|
|
172574
|
+
rsv1: false
|
|
172575
|
+
};
|
|
172576
|
+
if (isBlob(data)) {
|
|
172577
|
+
if (this._state !== DEFAULT) {
|
|
172578
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
172579
|
+
} else {
|
|
172580
|
+
this.getBlobData(data, false, options, cb);
|
|
172581
|
+
}
|
|
172582
|
+
} else if (this._state !== DEFAULT) {
|
|
172583
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
172584
|
+
} else {
|
|
172585
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172586
|
+
}
|
|
172587
|
+
}
|
|
172588
|
+
pong(data, mask, cb) {
|
|
172589
|
+
let byteLength;
|
|
172590
|
+
let readOnly;
|
|
172591
|
+
if (typeof data === "string") {
|
|
172592
|
+
byteLength = Buffer.byteLength(data);
|
|
172593
|
+
readOnly = false;
|
|
172594
|
+
} else if (isBlob(data)) {
|
|
172595
|
+
byteLength = data.size;
|
|
172596
|
+
readOnly = false;
|
|
172597
|
+
} else {
|
|
172598
|
+
data = toBuffer(data);
|
|
172599
|
+
byteLength = data.length;
|
|
172600
|
+
readOnly = toBuffer.readOnly;
|
|
172601
|
+
}
|
|
172602
|
+
if (byteLength > 125) {
|
|
172603
|
+
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
172604
|
+
}
|
|
172605
|
+
const options = {
|
|
172606
|
+
[kByteLength]: byteLength,
|
|
172607
|
+
fin: true,
|
|
172608
|
+
generateMask: this._generateMask,
|
|
172609
|
+
mask,
|
|
172610
|
+
maskBuffer: this._maskBuffer,
|
|
172611
|
+
opcode: 10,
|
|
172612
|
+
readOnly,
|
|
172613
|
+
rsv1: false
|
|
172614
|
+
};
|
|
172615
|
+
if (isBlob(data)) {
|
|
172616
|
+
if (this._state !== DEFAULT) {
|
|
172617
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
172618
|
+
} else {
|
|
172619
|
+
this.getBlobData(data, false, options, cb);
|
|
172620
|
+
}
|
|
172621
|
+
} else if (this._state !== DEFAULT) {
|
|
172622
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
172623
|
+
} else {
|
|
172624
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172625
|
+
}
|
|
172626
|
+
}
|
|
172627
|
+
send(data, options, cb) {
|
|
172628
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
172629
|
+
let opcode = options.binary ? 2 : 1;
|
|
172630
|
+
let rsv1 = options.compress;
|
|
172631
|
+
let byteLength;
|
|
172632
|
+
let readOnly;
|
|
172633
|
+
if (typeof data === "string") {
|
|
172634
|
+
byteLength = Buffer.byteLength(data);
|
|
172635
|
+
readOnly = false;
|
|
172636
|
+
} else if (isBlob(data)) {
|
|
172637
|
+
byteLength = data.size;
|
|
172638
|
+
readOnly = false;
|
|
172639
|
+
} else {
|
|
172640
|
+
data = toBuffer(data);
|
|
172641
|
+
byteLength = data.length;
|
|
172642
|
+
readOnly = toBuffer.readOnly;
|
|
172643
|
+
}
|
|
172644
|
+
if (this._firstFragment) {
|
|
172645
|
+
this._firstFragment = false;
|
|
172646
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
172647
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
172648
|
+
}
|
|
172649
|
+
this._compress = rsv1;
|
|
172650
|
+
} else {
|
|
172651
|
+
rsv1 = false;
|
|
172652
|
+
opcode = 0;
|
|
172653
|
+
}
|
|
172654
|
+
if (options.fin)
|
|
172655
|
+
this._firstFragment = true;
|
|
172656
|
+
const opts = {
|
|
172657
|
+
[kByteLength]: byteLength,
|
|
172658
|
+
fin: options.fin,
|
|
172659
|
+
generateMask: this._generateMask,
|
|
172660
|
+
mask: options.mask,
|
|
172661
|
+
maskBuffer: this._maskBuffer,
|
|
172662
|
+
opcode,
|
|
172663
|
+
readOnly,
|
|
172664
|
+
rsv1
|
|
172665
|
+
};
|
|
172666
|
+
if (isBlob(data)) {
|
|
172667
|
+
if (this._state !== DEFAULT) {
|
|
172668
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
172669
|
+
} else {
|
|
172670
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
172671
|
+
}
|
|
172672
|
+
} else if (this._state !== DEFAULT) {
|
|
172673
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
172674
|
+
} else {
|
|
172675
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
172676
|
+
}
|
|
172677
|
+
}
|
|
172678
|
+
getBlobData(blob, compress, options, cb) {
|
|
172679
|
+
this._bufferedBytes += options[kByteLength];
|
|
172680
|
+
this._state = GET_BLOB_DATA;
|
|
172681
|
+
blob.arrayBuffer().then((arrayBuffer) => {
|
|
172682
|
+
if (this._socket.destroyed) {
|
|
172683
|
+
const err = new Error("The socket was closed while the blob was being read");
|
|
172684
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
172685
|
+
return;
|
|
172686
|
+
}
|
|
172687
|
+
this._bufferedBytes -= options[kByteLength];
|
|
172688
|
+
const data = toBuffer(arrayBuffer);
|
|
172689
|
+
if (!compress) {
|
|
172690
|
+
this._state = DEFAULT;
|
|
172691
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172692
|
+
this.dequeue();
|
|
172693
|
+
} else {
|
|
172694
|
+
this.dispatch(data, compress, options, cb);
|
|
172695
|
+
}
|
|
172696
|
+
}).catch((err) => {
|
|
172697
|
+
process.nextTick(onError, this, err, cb);
|
|
172698
|
+
});
|
|
172699
|
+
}
|
|
172700
|
+
dispatch(data, compress, options, cb) {
|
|
172701
|
+
if (!compress) {
|
|
172702
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
172703
|
+
return;
|
|
172704
|
+
}
|
|
172705
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
172706
|
+
this._bufferedBytes += options[kByteLength];
|
|
172707
|
+
this._state = DEFLATING;
|
|
172708
|
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
172709
|
+
if (this._socket.destroyed) {
|
|
172710
|
+
const err = new Error("The socket was closed while data was being compressed");
|
|
172711
|
+
callCallbacks(this, err, cb);
|
|
172712
|
+
return;
|
|
172713
|
+
}
|
|
172714
|
+
this._bufferedBytes -= options[kByteLength];
|
|
172715
|
+
this._state = DEFAULT;
|
|
172716
|
+
options.readOnly = false;
|
|
172717
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
172718
|
+
this.dequeue();
|
|
172719
|
+
});
|
|
172720
|
+
}
|
|
172721
|
+
dequeue() {
|
|
172722
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
172723
|
+
const params = this._queue.shift();
|
|
172724
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
172725
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
172726
|
+
}
|
|
172727
|
+
}
|
|
172728
|
+
enqueue(params) {
|
|
172729
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
172730
|
+
this._queue.push(params);
|
|
172731
|
+
}
|
|
172732
|
+
sendFrame(list, cb) {
|
|
172733
|
+
if (list.length === 2) {
|
|
172734
|
+
this._socket.cork();
|
|
172735
|
+
this._socket.write(list[0]);
|
|
172736
|
+
this._socket.write(list[1], cb);
|
|
172737
|
+
this._socket.uncork();
|
|
172738
|
+
} else {
|
|
172739
|
+
this._socket.write(list[0], cb);
|
|
172740
|
+
}
|
|
172741
|
+
}
|
|
172742
|
+
}
|
|
172743
|
+
module.exports = Sender;
|
|
172744
|
+
function callCallbacks(sender, err, cb) {
|
|
172745
|
+
if (typeof cb === "function")
|
|
172746
|
+
cb(err);
|
|
172747
|
+
for (let i = 0;i < sender._queue.length; i++) {
|
|
172748
|
+
const params = sender._queue[i];
|
|
172749
|
+
const callback = params[params.length - 1];
|
|
172750
|
+
if (typeof callback === "function")
|
|
172751
|
+
callback(err);
|
|
172752
|
+
}
|
|
172753
|
+
}
|
|
172754
|
+
function onError(sender, err, cb) {
|
|
172755
|
+
callCallbacks(sender, err, cb);
|
|
172756
|
+
sender.onerror(err);
|
|
172757
|
+
}
|
|
172758
|
+
});
|
|
172759
|
+
|
|
172760
|
+
// ../../node_modules/ws/lib/event-target.js
|
|
172761
|
+
var require_event_target = __commonJS(function(exports, module) {
|
|
172762
|
+
var { kForOnEventAttribute, kListener } = require_constants6();
|
|
172763
|
+
var kCode = Symbol("kCode");
|
|
172764
|
+
var kData = Symbol("kData");
|
|
172765
|
+
var kError = Symbol("kError");
|
|
172766
|
+
var kMessage = Symbol("kMessage");
|
|
172767
|
+
var kReason = Symbol("kReason");
|
|
172768
|
+
var kTarget = Symbol("kTarget");
|
|
172769
|
+
var kType = Symbol("kType");
|
|
172770
|
+
var kWasClean = Symbol("kWasClean");
|
|
172771
|
+
|
|
172772
|
+
class Event2 {
|
|
172773
|
+
constructor(type) {
|
|
172774
|
+
this[kTarget] = null;
|
|
172775
|
+
this[kType] = type;
|
|
172776
|
+
}
|
|
172777
|
+
get target() {
|
|
172778
|
+
return this[kTarget];
|
|
172779
|
+
}
|
|
172780
|
+
get type() {
|
|
172781
|
+
return this[kType];
|
|
172782
|
+
}
|
|
172783
|
+
}
|
|
172784
|
+
Object.defineProperty(Event2.prototype, "target", { enumerable: true });
|
|
172785
|
+
Object.defineProperty(Event2.prototype, "type", { enumerable: true });
|
|
172786
|
+
|
|
172787
|
+
class CloseEvent extends Event2 {
|
|
172788
|
+
constructor(type, options = {}) {
|
|
172789
|
+
super(type);
|
|
172790
|
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
172791
|
+
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
172792
|
+
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
172793
|
+
}
|
|
172794
|
+
get code() {
|
|
172795
|
+
return this[kCode];
|
|
172796
|
+
}
|
|
172797
|
+
get reason() {
|
|
172798
|
+
return this[kReason];
|
|
172799
|
+
}
|
|
172800
|
+
get wasClean() {
|
|
172801
|
+
return this[kWasClean];
|
|
172802
|
+
}
|
|
172803
|
+
}
|
|
172804
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
172805
|
+
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
172806
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
172807
|
+
|
|
172808
|
+
class ErrorEvent extends Event2 {
|
|
172809
|
+
constructor(type, options = {}) {
|
|
172810
|
+
super(type);
|
|
172811
|
+
this[kError] = options.error === undefined ? null : options.error;
|
|
172812
|
+
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
172813
|
+
}
|
|
172814
|
+
get error() {
|
|
172815
|
+
return this[kError];
|
|
172816
|
+
}
|
|
172817
|
+
get message() {
|
|
172818
|
+
return this[kMessage];
|
|
172819
|
+
}
|
|
172820
|
+
}
|
|
172821
|
+
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
172822
|
+
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
172823
|
+
|
|
172824
|
+
class MessageEvent extends Event2 {
|
|
172825
|
+
constructor(type, options = {}) {
|
|
172826
|
+
super(type);
|
|
172827
|
+
this[kData] = options.data === undefined ? null : options.data;
|
|
172828
|
+
}
|
|
172829
|
+
get data() {
|
|
172830
|
+
return this[kData];
|
|
172831
|
+
}
|
|
172832
|
+
}
|
|
172833
|
+
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
172834
|
+
var EventTarget = {
|
|
172835
|
+
addEventListener(type, handler, options = {}) {
|
|
172836
|
+
for (const listener of this.listeners(type)) {
|
|
172837
|
+
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
172838
|
+
return;
|
|
172839
|
+
}
|
|
172840
|
+
}
|
|
172841
|
+
let wrapper;
|
|
172842
|
+
if (type === "message") {
|
|
172843
|
+
wrapper = function onMessage(data, isBinary) {
|
|
172844
|
+
const event = new MessageEvent("message", {
|
|
172845
|
+
data: isBinary ? data : data.toString()
|
|
172846
|
+
});
|
|
172847
|
+
event[kTarget] = this;
|
|
172848
|
+
callListener(handler, this, event);
|
|
172849
|
+
};
|
|
172850
|
+
} else if (type === "close") {
|
|
172851
|
+
wrapper = function onClose(code, message) {
|
|
172852
|
+
const event = new CloseEvent("close", {
|
|
172853
|
+
code,
|
|
172854
|
+
reason: message.toString(),
|
|
172855
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
172856
|
+
});
|
|
172857
|
+
event[kTarget] = this;
|
|
172858
|
+
callListener(handler, this, event);
|
|
172859
|
+
};
|
|
172860
|
+
} else if (type === "error") {
|
|
172861
|
+
wrapper = function onError(error) {
|
|
172862
|
+
const event = new ErrorEvent("error", {
|
|
172863
|
+
error,
|
|
172864
|
+
message: error.message
|
|
172865
|
+
});
|
|
172866
|
+
event[kTarget] = this;
|
|
172867
|
+
callListener(handler, this, event);
|
|
172868
|
+
};
|
|
172869
|
+
} else if (type === "open") {
|
|
172870
|
+
wrapper = function onOpen() {
|
|
172871
|
+
const event = new Event2("open");
|
|
172872
|
+
event[kTarget] = this;
|
|
172873
|
+
callListener(handler, this, event);
|
|
172874
|
+
};
|
|
172875
|
+
} else {
|
|
172876
|
+
return;
|
|
172877
|
+
}
|
|
172878
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
172879
|
+
wrapper[kListener] = handler;
|
|
172880
|
+
if (options.once) {
|
|
172881
|
+
this.once(type, wrapper);
|
|
172882
|
+
} else {
|
|
172883
|
+
this.on(type, wrapper);
|
|
172884
|
+
}
|
|
172885
|
+
},
|
|
172886
|
+
removeEventListener(type, handler) {
|
|
172887
|
+
for (const listener of this.listeners(type)) {
|
|
172888
|
+
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
172889
|
+
this.removeListener(type, listener);
|
|
172890
|
+
break;
|
|
172891
|
+
}
|
|
172892
|
+
}
|
|
172893
|
+
}
|
|
172894
|
+
};
|
|
172895
|
+
module.exports = {
|
|
172896
|
+
CloseEvent,
|
|
172897
|
+
ErrorEvent,
|
|
172898
|
+
Event: Event2,
|
|
172899
|
+
EventTarget,
|
|
172900
|
+
MessageEvent
|
|
172901
|
+
};
|
|
172902
|
+
function callListener(listener, thisArg, event) {
|
|
172903
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
172904
|
+
listener.handleEvent.call(listener, event);
|
|
172905
|
+
} else {
|
|
172906
|
+
listener.call(thisArg, event);
|
|
172907
|
+
}
|
|
172908
|
+
}
|
|
172909
|
+
});
|
|
172910
|
+
|
|
172911
|
+
// ../../node_modules/ws/lib/extension.js
|
|
172912
|
+
var require_extension = __commonJS(function(exports, module) {
|
|
172913
|
+
var { tokenChars } = require_validation();
|
|
172914
|
+
function push(dest, name, elem) {
|
|
172915
|
+
if (dest[name] === undefined)
|
|
172916
|
+
dest[name] = [elem];
|
|
172917
|
+
else
|
|
172918
|
+
dest[name].push(elem);
|
|
172919
|
+
}
|
|
172920
|
+
function parse(header) {
|
|
172921
|
+
const offers = Object.create(null);
|
|
172922
|
+
let params = Object.create(null);
|
|
172923
|
+
let mustUnescape = false;
|
|
172924
|
+
let isEscaping = false;
|
|
172925
|
+
let inQuotes = false;
|
|
172926
|
+
let extensionName;
|
|
172927
|
+
let paramName;
|
|
172928
|
+
let start = -1;
|
|
172929
|
+
let code = -1;
|
|
172930
|
+
let end = -1;
|
|
172931
|
+
let i = 0;
|
|
172932
|
+
for (;i < header.length; i++) {
|
|
172933
|
+
code = header.charCodeAt(i);
|
|
172934
|
+
if (extensionName === undefined) {
|
|
172935
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
172936
|
+
if (start === -1)
|
|
172937
|
+
start = i;
|
|
172938
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
172939
|
+
if (end === -1 && start !== -1)
|
|
172940
|
+
end = i;
|
|
172941
|
+
} else if (code === 59 || code === 44) {
|
|
172942
|
+
if (start === -1) {
|
|
172943
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172944
|
+
}
|
|
172945
|
+
if (end === -1)
|
|
172946
|
+
end = i;
|
|
172947
|
+
const name = header.slice(start, end);
|
|
172948
|
+
if (code === 44) {
|
|
172949
|
+
push(offers, name, params);
|
|
172950
|
+
params = Object.create(null);
|
|
172951
|
+
} else {
|
|
172952
|
+
extensionName = name;
|
|
172953
|
+
}
|
|
172954
|
+
start = end = -1;
|
|
172955
|
+
} else {
|
|
172956
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172957
|
+
}
|
|
172958
|
+
} else if (paramName === undefined) {
|
|
172959
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
172960
|
+
if (start === -1)
|
|
172961
|
+
start = i;
|
|
172962
|
+
} else if (code === 32 || code === 9) {
|
|
172963
|
+
if (end === -1 && start !== -1)
|
|
172964
|
+
end = i;
|
|
172965
|
+
} else if (code === 59 || code === 44) {
|
|
172966
|
+
if (start === -1) {
|
|
172967
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172968
|
+
}
|
|
172969
|
+
if (end === -1)
|
|
172970
|
+
end = i;
|
|
172971
|
+
push(params, header.slice(start, end), true);
|
|
172972
|
+
if (code === 44) {
|
|
172973
|
+
push(offers, extensionName, params);
|
|
172974
|
+
params = Object.create(null);
|
|
172975
|
+
extensionName = undefined;
|
|
172976
|
+
}
|
|
172977
|
+
start = end = -1;
|
|
172978
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
172979
|
+
paramName = header.slice(start, i);
|
|
172980
|
+
start = end = -1;
|
|
172981
|
+
} else {
|
|
172982
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172983
|
+
}
|
|
172984
|
+
} else {
|
|
172985
|
+
if (isEscaping) {
|
|
172986
|
+
if (tokenChars[code] !== 1) {
|
|
172987
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
172988
|
+
}
|
|
172989
|
+
if (start === -1)
|
|
172990
|
+
start = i;
|
|
172991
|
+
else if (!mustUnescape)
|
|
172992
|
+
mustUnescape = true;
|
|
172993
|
+
isEscaping = false;
|
|
172994
|
+
} else if (inQuotes) {
|
|
172995
|
+
if (tokenChars[code] === 1) {
|
|
172996
|
+
if (start === -1)
|
|
172997
|
+
start = i;
|
|
172998
|
+
} else if (code === 34 && start !== -1) {
|
|
172999
|
+
inQuotes = false;
|
|
173000
|
+
end = i;
|
|
173001
|
+
} else if (code === 92) {
|
|
173002
|
+
isEscaping = true;
|
|
173003
|
+
} else {
|
|
173004
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173005
|
+
}
|
|
173006
|
+
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
173007
|
+
inQuotes = true;
|
|
173008
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
173009
|
+
if (start === -1)
|
|
173010
|
+
start = i;
|
|
173011
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
173012
|
+
if (end === -1)
|
|
173013
|
+
end = i;
|
|
173014
|
+
} else if (code === 59 || code === 44) {
|
|
173015
|
+
if (start === -1) {
|
|
173016
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173017
|
+
}
|
|
173018
|
+
if (end === -1)
|
|
173019
|
+
end = i;
|
|
173020
|
+
let value = header.slice(start, end);
|
|
173021
|
+
if (mustUnescape) {
|
|
173022
|
+
value = value.replace(/\\/g, "");
|
|
173023
|
+
mustUnescape = false;
|
|
173024
|
+
}
|
|
173025
|
+
push(params, paramName, value);
|
|
173026
|
+
if (code === 44) {
|
|
173027
|
+
push(offers, extensionName, params);
|
|
173028
|
+
params = Object.create(null);
|
|
173029
|
+
extensionName = undefined;
|
|
173030
|
+
}
|
|
173031
|
+
paramName = undefined;
|
|
173032
|
+
start = end = -1;
|
|
173033
|
+
} else {
|
|
173034
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173035
|
+
}
|
|
173036
|
+
}
|
|
173037
|
+
}
|
|
173038
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
173039
|
+
throw new SyntaxError("Unexpected end of input");
|
|
173040
|
+
}
|
|
173041
|
+
if (end === -1)
|
|
173042
|
+
end = i;
|
|
173043
|
+
const token = header.slice(start, end);
|
|
173044
|
+
if (extensionName === undefined) {
|
|
173045
|
+
push(offers, token, params);
|
|
173046
|
+
} else {
|
|
173047
|
+
if (paramName === undefined) {
|
|
173048
|
+
push(params, token, true);
|
|
173049
|
+
} else if (mustUnescape) {
|
|
173050
|
+
push(params, paramName, token.replace(/\\/g, ""));
|
|
173051
|
+
} else {
|
|
173052
|
+
push(params, paramName, token);
|
|
173053
|
+
}
|
|
173054
|
+
push(offers, extensionName, params);
|
|
173055
|
+
}
|
|
173056
|
+
return offers;
|
|
173057
|
+
}
|
|
173058
|
+
function format(extensions) {
|
|
173059
|
+
return Object.keys(extensions).map((extension) => {
|
|
173060
|
+
let configurations = extensions[extension];
|
|
173061
|
+
if (!Array.isArray(configurations))
|
|
173062
|
+
configurations = [configurations];
|
|
173063
|
+
return configurations.map((params) => {
|
|
173064
|
+
return [extension].concat(Object.keys(params).map((k) => {
|
|
173065
|
+
let values = params[k];
|
|
173066
|
+
if (!Array.isArray(values))
|
|
173067
|
+
values = [values];
|
|
173068
|
+
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
173069
|
+
})).join("; ");
|
|
173070
|
+
}).join(", ");
|
|
173071
|
+
}).join(", ");
|
|
173072
|
+
}
|
|
173073
|
+
module.exports = { format, parse };
|
|
173074
|
+
});
|
|
173075
|
+
|
|
173076
|
+
// ../../node_modules/ws/lib/websocket.js
|
|
173077
|
+
var require_websocket = __commonJS(function(exports, module) {
|
|
173078
|
+
var EventEmitter = __require("events");
|
|
173079
|
+
var https = __require("https");
|
|
173080
|
+
var http = __require("http");
|
|
173081
|
+
var net = __require("net");
|
|
173082
|
+
var tls = __require("tls");
|
|
173083
|
+
var { randomBytes, createHash } = __require("crypto");
|
|
173084
|
+
var { Duplex, Readable } = __require("stream");
|
|
173085
|
+
var { URL: URL2 } = __require("url");
|
|
173086
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
173087
|
+
var Receiver = require_receiver();
|
|
173088
|
+
var Sender = require_sender();
|
|
173089
|
+
var { isBlob } = require_validation();
|
|
173090
|
+
var {
|
|
173091
|
+
BINARY_TYPES,
|
|
173092
|
+
CLOSE_TIMEOUT,
|
|
173093
|
+
EMPTY_BUFFER,
|
|
173094
|
+
GUID,
|
|
173095
|
+
kForOnEventAttribute,
|
|
173096
|
+
kListener,
|
|
173097
|
+
kStatusCode,
|
|
173098
|
+
kWebSocket,
|
|
173099
|
+
NOOP
|
|
173100
|
+
} = require_constants6();
|
|
173101
|
+
var {
|
|
173102
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
173103
|
+
} = require_event_target();
|
|
173104
|
+
var { format, parse } = require_extension();
|
|
173105
|
+
var { toBuffer } = require_buffer_util();
|
|
173106
|
+
var kAborted = Symbol("kAborted");
|
|
173107
|
+
var protocolVersions = [8, 13];
|
|
173108
|
+
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
173109
|
+
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
173110
|
+
|
|
173111
|
+
class WebSocket extends EventEmitter {
|
|
173112
|
+
constructor(address, protocols, options) {
|
|
173113
|
+
super();
|
|
173114
|
+
this._binaryType = BINARY_TYPES[0];
|
|
173115
|
+
this._closeCode = 1006;
|
|
173116
|
+
this._closeFrameReceived = false;
|
|
173117
|
+
this._closeFrameSent = false;
|
|
173118
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
173119
|
+
this._closeTimer = null;
|
|
173120
|
+
this._errorEmitted = false;
|
|
173121
|
+
this._extensions = {};
|
|
173122
|
+
this._paused = false;
|
|
173123
|
+
this._protocol = "";
|
|
173124
|
+
this._readyState = WebSocket.CONNECTING;
|
|
173125
|
+
this._receiver = null;
|
|
173126
|
+
this._sender = null;
|
|
173127
|
+
this._socket = null;
|
|
173128
|
+
if (address !== null) {
|
|
173129
|
+
this._bufferedAmount = 0;
|
|
173130
|
+
this._isServer = false;
|
|
173131
|
+
this._redirects = 0;
|
|
173132
|
+
if (protocols === undefined) {
|
|
173133
|
+
protocols = [];
|
|
173134
|
+
} else if (!Array.isArray(protocols)) {
|
|
173135
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
173136
|
+
options = protocols;
|
|
173137
|
+
protocols = [];
|
|
173138
|
+
} else {
|
|
173139
|
+
protocols = [protocols];
|
|
173140
|
+
}
|
|
173141
|
+
}
|
|
173142
|
+
initAsClient(this, address, protocols, options);
|
|
173143
|
+
} else {
|
|
173144
|
+
this._autoPong = options.autoPong;
|
|
173145
|
+
this._closeTimeout = options.closeTimeout;
|
|
173146
|
+
this._isServer = true;
|
|
173147
|
+
}
|
|
173148
|
+
}
|
|
173149
|
+
get binaryType() {
|
|
173150
|
+
return this._binaryType;
|
|
173151
|
+
}
|
|
173152
|
+
set binaryType(type) {
|
|
173153
|
+
if (!BINARY_TYPES.includes(type))
|
|
173154
|
+
return;
|
|
173155
|
+
this._binaryType = type;
|
|
173156
|
+
if (this._receiver)
|
|
173157
|
+
this._receiver._binaryType = type;
|
|
173158
|
+
}
|
|
173159
|
+
get bufferedAmount() {
|
|
173160
|
+
if (!this._socket)
|
|
173161
|
+
return this._bufferedAmount;
|
|
173162
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
173163
|
+
}
|
|
173164
|
+
get extensions() {
|
|
173165
|
+
return Object.keys(this._extensions).join();
|
|
173166
|
+
}
|
|
173167
|
+
get isPaused() {
|
|
173168
|
+
return this._paused;
|
|
173169
|
+
}
|
|
173170
|
+
get onclose() {
|
|
173171
|
+
return null;
|
|
173172
|
+
}
|
|
173173
|
+
get onerror() {
|
|
173174
|
+
return null;
|
|
173175
|
+
}
|
|
173176
|
+
get onopen() {
|
|
173177
|
+
return null;
|
|
173178
|
+
}
|
|
173179
|
+
get onmessage() {
|
|
173180
|
+
return null;
|
|
173181
|
+
}
|
|
173182
|
+
get protocol() {
|
|
173183
|
+
return this._protocol;
|
|
173184
|
+
}
|
|
173185
|
+
get readyState() {
|
|
173186
|
+
return this._readyState;
|
|
173187
|
+
}
|
|
173188
|
+
get url() {
|
|
173189
|
+
return this._url;
|
|
173190
|
+
}
|
|
173191
|
+
setSocket(socket, head, options) {
|
|
173192
|
+
const receiver = new Receiver({
|
|
173193
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
173194
|
+
binaryType: this.binaryType,
|
|
173195
|
+
extensions: this._extensions,
|
|
173196
|
+
isServer: this._isServer,
|
|
173197
|
+
maxBufferedChunks: options.maxBufferedChunks,
|
|
173198
|
+
maxFragments: options.maxFragments,
|
|
173199
|
+
maxPayload: options.maxPayload,
|
|
173200
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
173201
|
+
});
|
|
173202
|
+
const sender = new Sender(socket, this._extensions, options.generateMask);
|
|
173203
|
+
this._receiver = receiver;
|
|
173204
|
+
this._sender = sender;
|
|
173205
|
+
this._socket = socket;
|
|
173206
|
+
receiver[kWebSocket] = this;
|
|
173207
|
+
sender[kWebSocket] = this;
|
|
173208
|
+
socket[kWebSocket] = this;
|
|
173209
|
+
receiver.on("conclude", receiverOnConclude);
|
|
173210
|
+
receiver.on("drain", receiverOnDrain);
|
|
173211
|
+
receiver.on("error", receiverOnError);
|
|
173212
|
+
receiver.on("message", receiverOnMessage);
|
|
173213
|
+
receiver.on("ping", receiverOnPing);
|
|
173214
|
+
receiver.on("pong", receiverOnPong);
|
|
173215
|
+
sender.onerror = senderOnError;
|
|
173216
|
+
if (socket.setTimeout)
|
|
173217
|
+
socket.setTimeout(0);
|
|
173218
|
+
if (socket.setNoDelay)
|
|
173219
|
+
socket.setNoDelay();
|
|
173220
|
+
if (head.length > 0)
|
|
173221
|
+
socket.unshift(head);
|
|
173222
|
+
socket.on("close", socketOnClose);
|
|
173223
|
+
socket.on("data", socketOnData);
|
|
173224
|
+
socket.on("end", socketOnEnd);
|
|
173225
|
+
socket.on("error", socketOnError);
|
|
173226
|
+
this._readyState = WebSocket.OPEN;
|
|
173227
|
+
this.emit("open");
|
|
173228
|
+
}
|
|
173229
|
+
emitClose() {
|
|
173230
|
+
if (!this._socket) {
|
|
173231
|
+
this._readyState = WebSocket.CLOSED;
|
|
173232
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
173233
|
+
return;
|
|
173234
|
+
}
|
|
173235
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
173236
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
173237
|
+
}
|
|
173238
|
+
this._receiver.removeAllListeners();
|
|
173239
|
+
this._readyState = WebSocket.CLOSED;
|
|
173240
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
173241
|
+
}
|
|
173242
|
+
close(code, data) {
|
|
173243
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
173244
|
+
return;
|
|
173245
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173246
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
173247
|
+
abortHandshake(this, this._req, msg);
|
|
173248
|
+
return;
|
|
173249
|
+
}
|
|
173250
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
173251
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
173252
|
+
this._socket.end();
|
|
173253
|
+
}
|
|
173254
|
+
return;
|
|
173255
|
+
}
|
|
173256
|
+
this._readyState = WebSocket.CLOSING;
|
|
173257
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
173258
|
+
if (err)
|
|
173259
|
+
return;
|
|
173260
|
+
this._closeFrameSent = true;
|
|
173261
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
173262
|
+
this._socket.end();
|
|
173263
|
+
}
|
|
173264
|
+
});
|
|
173265
|
+
setCloseTimer(this);
|
|
173266
|
+
}
|
|
173267
|
+
pause() {
|
|
173268
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
173269
|
+
return;
|
|
173270
|
+
}
|
|
173271
|
+
this._paused = true;
|
|
173272
|
+
this._socket.pause();
|
|
173273
|
+
}
|
|
173274
|
+
ping(data, mask, cb) {
|
|
173275
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173276
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
173277
|
+
}
|
|
173278
|
+
if (typeof data === "function") {
|
|
173279
|
+
cb = data;
|
|
173280
|
+
data = mask = undefined;
|
|
173281
|
+
} else if (typeof mask === "function") {
|
|
173282
|
+
cb = mask;
|
|
173283
|
+
mask = undefined;
|
|
173284
|
+
}
|
|
173285
|
+
if (typeof data === "number")
|
|
173286
|
+
data = data.toString();
|
|
173287
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
173288
|
+
sendAfterClose(this, data, cb);
|
|
173289
|
+
return;
|
|
173290
|
+
}
|
|
173291
|
+
if (mask === undefined)
|
|
173292
|
+
mask = !this._isServer;
|
|
173293
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
173294
|
+
}
|
|
173295
|
+
pong(data, mask, cb) {
|
|
173296
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173297
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
173298
|
+
}
|
|
173299
|
+
if (typeof data === "function") {
|
|
173300
|
+
cb = data;
|
|
173301
|
+
data = mask = undefined;
|
|
173302
|
+
} else if (typeof mask === "function") {
|
|
173303
|
+
cb = mask;
|
|
173304
|
+
mask = undefined;
|
|
173305
|
+
}
|
|
173306
|
+
if (typeof data === "number")
|
|
173307
|
+
data = data.toString();
|
|
173308
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
173309
|
+
sendAfterClose(this, data, cb);
|
|
173310
|
+
return;
|
|
173311
|
+
}
|
|
173312
|
+
if (mask === undefined)
|
|
173313
|
+
mask = !this._isServer;
|
|
173314
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
173315
|
+
}
|
|
173316
|
+
resume() {
|
|
173317
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
173318
|
+
return;
|
|
173319
|
+
}
|
|
173320
|
+
this._paused = false;
|
|
173321
|
+
if (!this._receiver._writableState.needDrain)
|
|
173322
|
+
this._socket.resume();
|
|
173323
|
+
}
|
|
173324
|
+
send(data, options, cb) {
|
|
173325
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173326
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
173327
|
+
}
|
|
173328
|
+
if (typeof options === "function") {
|
|
173329
|
+
cb = options;
|
|
173330
|
+
options = {};
|
|
173331
|
+
}
|
|
173332
|
+
if (typeof data === "number")
|
|
173333
|
+
data = data.toString();
|
|
173334
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
173335
|
+
sendAfterClose(this, data, cb);
|
|
173336
|
+
return;
|
|
173337
|
+
}
|
|
173338
|
+
const opts = {
|
|
173339
|
+
binary: typeof data !== "string",
|
|
173340
|
+
mask: !this._isServer,
|
|
173341
|
+
compress: true,
|
|
173342
|
+
fin: true,
|
|
173343
|
+
...options
|
|
173344
|
+
};
|
|
173345
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
173346
|
+
opts.compress = false;
|
|
173347
|
+
}
|
|
173348
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
173349
|
+
}
|
|
173350
|
+
terminate() {
|
|
173351
|
+
if (this.readyState === WebSocket.CLOSED)
|
|
173352
|
+
return;
|
|
173353
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
173354
|
+
const msg = "WebSocket was closed before the connection was established";
|
|
173355
|
+
abortHandshake(this, this._req, msg);
|
|
173356
|
+
return;
|
|
173357
|
+
}
|
|
173358
|
+
if (this._socket) {
|
|
173359
|
+
this._readyState = WebSocket.CLOSING;
|
|
173360
|
+
this._socket.destroy();
|
|
173361
|
+
}
|
|
173362
|
+
}
|
|
173363
|
+
}
|
|
173364
|
+
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
173365
|
+
enumerable: true,
|
|
173366
|
+
value: readyStates.indexOf("CONNECTING")
|
|
173367
|
+
});
|
|
173368
|
+
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
173369
|
+
enumerable: true,
|
|
173370
|
+
value: readyStates.indexOf("CONNECTING")
|
|
173371
|
+
});
|
|
173372
|
+
Object.defineProperty(WebSocket, "OPEN", {
|
|
173373
|
+
enumerable: true,
|
|
173374
|
+
value: readyStates.indexOf("OPEN")
|
|
173375
|
+
});
|
|
173376
|
+
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
173377
|
+
enumerable: true,
|
|
173378
|
+
value: readyStates.indexOf("OPEN")
|
|
173379
|
+
});
|
|
173380
|
+
Object.defineProperty(WebSocket, "CLOSING", {
|
|
173381
|
+
enumerable: true,
|
|
173382
|
+
value: readyStates.indexOf("CLOSING")
|
|
173383
|
+
});
|
|
173384
|
+
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
173385
|
+
enumerable: true,
|
|
173386
|
+
value: readyStates.indexOf("CLOSING")
|
|
173387
|
+
});
|
|
173388
|
+
Object.defineProperty(WebSocket, "CLOSED", {
|
|
173389
|
+
enumerable: true,
|
|
173390
|
+
value: readyStates.indexOf("CLOSED")
|
|
173391
|
+
});
|
|
173392
|
+
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
173393
|
+
enumerable: true,
|
|
173394
|
+
value: readyStates.indexOf("CLOSED")
|
|
173395
|
+
});
|
|
173396
|
+
[
|
|
173397
|
+
"binaryType",
|
|
173398
|
+
"bufferedAmount",
|
|
173399
|
+
"extensions",
|
|
173400
|
+
"isPaused",
|
|
173401
|
+
"protocol",
|
|
173402
|
+
"readyState",
|
|
173403
|
+
"url"
|
|
173404
|
+
].forEach((property) => {
|
|
173405
|
+
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
|
173406
|
+
});
|
|
173407
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
173408
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
173409
|
+
enumerable: true,
|
|
173410
|
+
get() {
|
|
173411
|
+
for (const listener of this.listeners(method)) {
|
|
173412
|
+
if (listener[kForOnEventAttribute])
|
|
173413
|
+
return listener[kListener];
|
|
173414
|
+
}
|
|
173415
|
+
return null;
|
|
173416
|
+
},
|
|
173417
|
+
set(handler) {
|
|
173418
|
+
for (const listener of this.listeners(method)) {
|
|
173419
|
+
if (listener[kForOnEventAttribute]) {
|
|
173420
|
+
this.removeListener(method, listener);
|
|
173421
|
+
break;
|
|
173422
|
+
}
|
|
173423
|
+
}
|
|
173424
|
+
if (typeof handler !== "function")
|
|
173425
|
+
return;
|
|
173426
|
+
this.addEventListener(method, handler, {
|
|
173427
|
+
[kForOnEventAttribute]: true
|
|
173428
|
+
});
|
|
173429
|
+
}
|
|
173430
|
+
});
|
|
173431
|
+
});
|
|
173432
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
173433
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
173434
|
+
module.exports = WebSocket;
|
|
173435
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
173436
|
+
const opts = {
|
|
173437
|
+
allowSynchronousEvents: true,
|
|
173438
|
+
autoPong: true,
|
|
173439
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
173440
|
+
protocolVersion: protocolVersions[1],
|
|
173441
|
+
maxBufferedChunks: 1024 * 1024,
|
|
173442
|
+
maxFragments: 128 * 1024,
|
|
173443
|
+
maxPayload: 100 * 1024 * 1024,
|
|
173444
|
+
skipUTF8Validation: false,
|
|
173445
|
+
perMessageDeflate: true,
|
|
173446
|
+
followRedirects: false,
|
|
173447
|
+
maxRedirects: 10,
|
|
173448
|
+
...options,
|
|
173449
|
+
socketPath: undefined,
|
|
173450
|
+
hostname: undefined,
|
|
173451
|
+
protocol: undefined,
|
|
173452
|
+
timeout: undefined,
|
|
173453
|
+
method: "GET",
|
|
173454
|
+
host: undefined,
|
|
173455
|
+
path: undefined,
|
|
173456
|
+
port: undefined
|
|
173457
|
+
};
|
|
173458
|
+
websocket._autoPong = opts.autoPong;
|
|
173459
|
+
websocket._closeTimeout = opts.closeTimeout;
|
|
173460
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
173461
|
+
throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
|
|
173462
|
+
}
|
|
173463
|
+
let parsedUrl;
|
|
173464
|
+
if (address instanceof URL2) {
|
|
173465
|
+
parsedUrl = address;
|
|
173466
|
+
} else {
|
|
173467
|
+
try {
|
|
173468
|
+
parsedUrl = new URL2(address);
|
|
173469
|
+
} catch {
|
|
173470
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
173471
|
+
}
|
|
173472
|
+
}
|
|
173473
|
+
if (parsedUrl.protocol === "http:") {
|
|
173474
|
+
parsedUrl.protocol = "ws:";
|
|
173475
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
173476
|
+
parsedUrl.protocol = "wss:";
|
|
173477
|
+
}
|
|
173478
|
+
websocket._url = parsedUrl.href;
|
|
173479
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
173480
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
173481
|
+
let invalidUrlMessage;
|
|
173482
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
173483
|
+
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
|
|
173484
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
173485
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
173486
|
+
} else if (parsedUrl.hash) {
|
|
173487
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
173488
|
+
}
|
|
173489
|
+
if (invalidUrlMessage) {
|
|
173490
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
173491
|
+
if (websocket._redirects === 0) {
|
|
173492
|
+
throw err;
|
|
173493
|
+
} else {
|
|
173494
|
+
emitErrorAndClose(websocket, err);
|
|
173495
|
+
return;
|
|
173496
|
+
}
|
|
173497
|
+
}
|
|
173498
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
173499
|
+
const key = randomBytes(16).toString("base64");
|
|
173500
|
+
const request3 = isSecure ? https.request : http.request;
|
|
173501
|
+
const protocolSet = new Set;
|
|
173502
|
+
let perMessageDeflate;
|
|
173503
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
173504
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
173505
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
173506
|
+
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
173507
|
+
opts.headers = {
|
|
173508
|
+
...opts.headers,
|
|
173509
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
173510
|
+
"Sec-WebSocket-Key": key,
|
|
173511
|
+
Connection: "Upgrade",
|
|
173512
|
+
Upgrade: "websocket"
|
|
173513
|
+
};
|
|
173514
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
173515
|
+
opts.timeout = opts.handshakeTimeout;
|
|
173516
|
+
if (opts.perMessageDeflate) {
|
|
173517
|
+
perMessageDeflate = new PerMessageDeflate({
|
|
173518
|
+
...opts.perMessageDeflate,
|
|
173519
|
+
isServer: false,
|
|
173520
|
+
maxPayload: opts.maxPayload
|
|
173521
|
+
});
|
|
173522
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
173523
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
173524
|
+
});
|
|
173525
|
+
}
|
|
173526
|
+
if (protocols.length) {
|
|
173527
|
+
for (const protocol of protocols) {
|
|
173528
|
+
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
173529
|
+
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
173530
|
+
}
|
|
173531
|
+
protocolSet.add(protocol);
|
|
173532
|
+
}
|
|
173533
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
173534
|
+
}
|
|
173535
|
+
if (opts.origin) {
|
|
173536
|
+
if (opts.protocolVersion < 13) {
|
|
173537
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
173538
|
+
} else {
|
|
173539
|
+
opts.headers.Origin = opts.origin;
|
|
173540
|
+
}
|
|
173541
|
+
}
|
|
173542
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
173543
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
173544
|
+
}
|
|
173545
|
+
if (isIpcUrl) {
|
|
173546
|
+
const parts = opts.path.split(":");
|
|
173547
|
+
opts.socketPath = parts[0];
|
|
173548
|
+
opts.path = parts[1];
|
|
173549
|
+
}
|
|
173550
|
+
let req;
|
|
173551
|
+
if (opts.followRedirects) {
|
|
173552
|
+
if (websocket._redirects === 0) {
|
|
173553
|
+
websocket._originalIpc = isIpcUrl;
|
|
173554
|
+
websocket._originalSecure = isSecure;
|
|
173555
|
+
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
173556
|
+
const headers = options && options.headers;
|
|
173557
|
+
options = { ...options, headers: {} };
|
|
173558
|
+
if (headers) {
|
|
173559
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
173560
|
+
options.headers[key.toLowerCase()] = value;
|
|
173561
|
+
}
|
|
173562
|
+
}
|
|
173563
|
+
} else if (websocket.listenerCount("redirect") === 0) {
|
|
173564
|
+
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
173565
|
+
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
173566
|
+
delete opts.headers.authorization;
|
|
173567
|
+
delete opts.headers.cookie;
|
|
173568
|
+
if (!isSameHost)
|
|
173569
|
+
delete opts.headers.host;
|
|
173570
|
+
opts.auth = undefined;
|
|
173571
|
+
}
|
|
173572
|
+
}
|
|
173573
|
+
if (opts.auth && !options.headers.authorization) {
|
|
173574
|
+
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
173575
|
+
}
|
|
173576
|
+
req = websocket._req = request3(opts);
|
|
173577
|
+
if (websocket._redirects) {
|
|
173578
|
+
websocket.emit("redirect", websocket.url, req);
|
|
173579
|
+
}
|
|
173580
|
+
} else {
|
|
173581
|
+
req = websocket._req = request3(opts);
|
|
173582
|
+
}
|
|
173583
|
+
if (opts.timeout) {
|
|
173584
|
+
req.on("timeout", () => {
|
|
173585
|
+
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
173586
|
+
});
|
|
173587
|
+
}
|
|
173588
|
+
req.on("error", (err) => {
|
|
173589
|
+
if (req === null || req[kAborted])
|
|
173590
|
+
return;
|
|
173591
|
+
req = websocket._req = null;
|
|
173592
|
+
emitErrorAndClose(websocket, err);
|
|
173593
|
+
});
|
|
173594
|
+
req.on("response", (res) => {
|
|
173595
|
+
const location2 = res.headers.location;
|
|
173596
|
+
const statusCode = res.statusCode;
|
|
173597
|
+
if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
173598
|
+
if (++websocket._redirects > opts.maxRedirects) {
|
|
173599
|
+
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
173600
|
+
return;
|
|
173601
|
+
}
|
|
173602
|
+
req.abort();
|
|
173603
|
+
let addr;
|
|
173604
|
+
try {
|
|
173605
|
+
addr = new URL2(location2, address);
|
|
173606
|
+
} catch (e) {
|
|
173607
|
+
const err = new SyntaxError(`Invalid URL: ${location2}`);
|
|
173608
|
+
emitErrorAndClose(websocket, err);
|
|
173609
|
+
return;
|
|
173610
|
+
}
|
|
173611
|
+
initAsClient(websocket, addr, protocols, options);
|
|
173612
|
+
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
173613
|
+
abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
173614
|
+
}
|
|
173615
|
+
});
|
|
173616
|
+
req.on("upgrade", (res, socket, head) => {
|
|
173617
|
+
websocket.emit("upgrade", res);
|
|
173618
|
+
if (websocket.readyState !== WebSocket.CONNECTING)
|
|
173619
|
+
return;
|
|
173620
|
+
req = websocket._req = null;
|
|
173621
|
+
const upgrade = res.headers.upgrade;
|
|
173622
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
173623
|
+
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
173624
|
+
return;
|
|
173625
|
+
}
|
|
173626
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
173627
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
173628
|
+
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
173629
|
+
return;
|
|
173630
|
+
}
|
|
173631
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
173632
|
+
let protError;
|
|
173633
|
+
if (serverProt !== undefined) {
|
|
173634
|
+
if (!protocolSet.size) {
|
|
173635
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
173636
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
173637
|
+
protError = "Server sent an invalid subprotocol";
|
|
173638
|
+
}
|
|
173639
|
+
} else if (protocolSet.size) {
|
|
173640
|
+
protError = "Server sent no subprotocol";
|
|
173641
|
+
}
|
|
173642
|
+
if (protError) {
|
|
173643
|
+
abortHandshake(websocket, socket, protError);
|
|
173644
|
+
return;
|
|
173645
|
+
}
|
|
173646
|
+
if (serverProt)
|
|
173647
|
+
websocket._protocol = serverProt;
|
|
173648
|
+
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
173649
|
+
if (secWebSocketExtensions !== undefined) {
|
|
173650
|
+
if (!perMessageDeflate) {
|
|
173651
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
|
|
173652
|
+
abortHandshake(websocket, socket, message);
|
|
173653
|
+
return;
|
|
173654
|
+
}
|
|
173655
|
+
let extensions;
|
|
173656
|
+
try {
|
|
173657
|
+
extensions = parse(secWebSocketExtensions);
|
|
173658
|
+
} catch (err) {
|
|
173659
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
173660
|
+
abortHandshake(websocket, socket, message);
|
|
173661
|
+
return;
|
|
173662
|
+
}
|
|
173663
|
+
const extensionNames = Object.keys(extensions);
|
|
173664
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
173665
|
+
const message = "Server indicated an extension that was not requested";
|
|
173666
|
+
abortHandshake(websocket, socket, message);
|
|
173667
|
+
return;
|
|
173668
|
+
}
|
|
173669
|
+
try {
|
|
173670
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
173671
|
+
} catch (err) {
|
|
173672
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
173673
|
+
abortHandshake(websocket, socket, message);
|
|
173674
|
+
return;
|
|
173675
|
+
}
|
|
173676
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
173677
|
+
}
|
|
173678
|
+
websocket.setSocket(socket, head, {
|
|
173679
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
173680
|
+
generateMask: opts.generateMask,
|
|
173681
|
+
maxBufferedChunks: opts.maxBufferedChunks,
|
|
173682
|
+
maxFragments: opts.maxFragments,
|
|
173683
|
+
maxPayload: opts.maxPayload,
|
|
173684
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
173685
|
+
});
|
|
173686
|
+
});
|
|
173687
|
+
if (opts.finishRequest) {
|
|
173688
|
+
opts.finishRequest(req, websocket);
|
|
173689
|
+
} else {
|
|
173690
|
+
req.end();
|
|
173691
|
+
}
|
|
173692
|
+
}
|
|
173693
|
+
function emitErrorAndClose(websocket, err) {
|
|
173694
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173695
|
+
websocket._errorEmitted = true;
|
|
173696
|
+
websocket.emit("error", err);
|
|
173697
|
+
websocket.emitClose();
|
|
173698
|
+
}
|
|
173699
|
+
function netConnect(options) {
|
|
173700
|
+
options.path = options.socketPath;
|
|
173701
|
+
return net.connect(options);
|
|
173702
|
+
}
|
|
173703
|
+
function tlsConnect(options) {
|
|
173704
|
+
options.path = undefined;
|
|
173705
|
+
if (!options.servername && options.servername !== "") {
|
|
173706
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
173707
|
+
}
|
|
173708
|
+
return tls.connect(options);
|
|
173709
|
+
}
|
|
173710
|
+
function abortHandshake(websocket, stream, message) {
|
|
173711
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173712
|
+
const err = new Error(message);
|
|
173713
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
173714
|
+
if (stream.setHeader) {
|
|
173715
|
+
stream[kAborted] = true;
|
|
173716
|
+
stream.abort();
|
|
173717
|
+
if (stream.socket && !stream.socket.destroyed) {
|
|
173718
|
+
stream.socket.destroy();
|
|
173719
|
+
}
|
|
173720
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
173721
|
+
} else {
|
|
173722
|
+
stream.destroy(err);
|
|
173723
|
+
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
173724
|
+
stream.once("close", websocket.emitClose.bind(websocket));
|
|
173725
|
+
}
|
|
173726
|
+
}
|
|
173727
|
+
function sendAfterClose(websocket, data, cb) {
|
|
173728
|
+
if (data) {
|
|
173729
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
173730
|
+
if (websocket._socket)
|
|
173731
|
+
websocket._sender._bufferedBytes += length;
|
|
173732
|
+
else
|
|
173733
|
+
websocket._bufferedAmount += length;
|
|
173734
|
+
}
|
|
173735
|
+
if (cb) {
|
|
173736
|
+
const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
|
|
173737
|
+
process.nextTick(cb, err);
|
|
173738
|
+
}
|
|
173739
|
+
}
|
|
173740
|
+
function receiverOnConclude(code, reason) {
|
|
173741
|
+
const websocket = this[kWebSocket];
|
|
173742
|
+
websocket._closeFrameReceived = true;
|
|
173743
|
+
websocket._closeMessage = reason;
|
|
173744
|
+
websocket._closeCode = code;
|
|
173745
|
+
if (websocket._socket[kWebSocket] === undefined)
|
|
173746
|
+
return;
|
|
173747
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
173748
|
+
process.nextTick(resume, websocket._socket);
|
|
173749
|
+
if (code === 1005)
|
|
173750
|
+
websocket.close();
|
|
173751
|
+
else
|
|
173752
|
+
websocket.close(code, reason);
|
|
173753
|
+
}
|
|
173754
|
+
function receiverOnDrain() {
|
|
173755
|
+
const websocket = this[kWebSocket];
|
|
173756
|
+
if (!websocket.isPaused)
|
|
173757
|
+
websocket._socket.resume();
|
|
173758
|
+
}
|
|
173759
|
+
function receiverOnError(err) {
|
|
173760
|
+
const websocket = this[kWebSocket];
|
|
173761
|
+
if (websocket._socket[kWebSocket] !== undefined) {
|
|
173762
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
173763
|
+
process.nextTick(resume, websocket._socket);
|
|
173764
|
+
websocket.close(err[kStatusCode]);
|
|
173765
|
+
}
|
|
173766
|
+
if (!websocket._errorEmitted) {
|
|
173767
|
+
websocket._errorEmitted = true;
|
|
173768
|
+
websocket.emit("error", err);
|
|
173769
|
+
}
|
|
173770
|
+
}
|
|
173771
|
+
function receiverOnFinish() {
|
|
173772
|
+
this[kWebSocket].emitClose();
|
|
173773
|
+
}
|
|
173774
|
+
function receiverOnMessage(data, isBinary) {
|
|
173775
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
173776
|
+
}
|
|
173777
|
+
function receiverOnPing(data) {
|
|
173778
|
+
const websocket = this[kWebSocket];
|
|
173779
|
+
if (websocket._autoPong)
|
|
173780
|
+
websocket.pong(data, !this._isServer, NOOP);
|
|
173781
|
+
websocket.emit("ping", data);
|
|
173782
|
+
}
|
|
173783
|
+
function receiverOnPong(data) {
|
|
173784
|
+
this[kWebSocket].emit("pong", data);
|
|
173785
|
+
}
|
|
173786
|
+
function resume(stream) {
|
|
173787
|
+
stream.resume();
|
|
173788
|
+
}
|
|
173789
|
+
function senderOnError(err) {
|
|
173790
|
+
const websocket = this[kWebSocket];
|
|
173791
|
+
if (websocket.readyState === WebSocket.CLOSED)
|
|
173792
|
+
return;
|
|
173793
|
+
if (websocket.readyState === WebSocket.OPEN) {
|
|
173794
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173795
|
+
setCloseTimer(websocket);
|
|
173796
|
+
}
|
|
173797
|
+
this._socket.end();
|
|
173798
|
+
if (!websocket._errorEmitted) {
|
|
173799
|
+
websocket._errorEmitted = true;
|
|
173800
|
+
websocket.emit("error", err);
|
|
173801
|
+
}
|
|
173802
|
+
}
|
|
173803
|
+
function setCloseTimer(websocket) {
|
|
173804
|
+
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
173805
|
+
}
|
|
173806
|
+
function socketOnClose() {
|
|
173807
|
+
const websocket = this[kWebSocket];
|
|
173808
|
+
this.removeListener("close", socketOnClose);
|
|
173809
|
+
this.removeListener("data", socketOnData);
|
|
173810
|
+
this.removeListener("end", socketOnEnd);
|
|
173811
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173812
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
173813
|
+
const chunk = this.read(this._readableState.length);
|
|
173814
|
+
websocket._receiver.write(chunk);
|
|
173815
|
+
}
|
|
173816
|
+
websocket._receiver.end();
|
|
173817
|
+
this[kWebSocket] = undefined;
|
|
173818
|
+
clearTimeout(websocket._closeTimer);
|
|
173819
|
+
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
173820
|
+
websocket.emitClose();
|
|
173821
|
+
} else {
|
|
173822
|
+
websocket._receiver.on("error", receiverOnFinish);
|
|
173823
|
+
websocket._receiver.on("finish", receiverOnFinish);
|
|
173824
|
+
}
|
|
173825
|
+
}
|
|
173826
|
+
function socketOnData(chunk) {
|
|
173827
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
173828
|
+
this.pause();
|
|
173829
|
+
}
|
|
173830
|
+
}
|
|
173831
|
+
function socketOnEnd() {
|
|
173832
|
+
const websocket = this[kWebSocket];
|
|
173833
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173834
|
+
websocket._receiver.end();
|
|
173835
|
+
this.end();
|
|
173836
|
+
}
|
|
173837
|
+
function socketOnError() {
|
|
173838
|
+
const websocket = this[kWebSocket];
|
|
173839
|
+
this.removeListener("error", socketOnError);
|
|
173840
|
+
this.on("error", NOOP);
|
|
173841
|
+
if (websocket) {
|
|
173842
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
173843
|
+
this.destroy();
|
|
173844
|
+
}
|
|
173845
|
+
}
|
|
173846
|
+
});
|
|
173847
|
+
|
|
173848
|
+
// ../../node_modules/ws/lib/stream.js
|
|
173849
|
+
var require_stream6 = __commonJS(function(exports, module) {
|
|
173850
|
+
var WebSocket = require_websocket();
|
|
173851
|
+
var { Duplex } = __require("stream");
|
|
173852
|
+
function emitClose(stream) {
|
|
173853
|
+
stream.emit("close");
|
|
173854
|
+
}
|
|
173855
|
+
function duplexOnEnd() {
|
|
173856
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
173857
|
+
this.destroy();
|
|
173858
|
+
}
|
|
173859
|
+
}
|
|
173860
|
+
function duplexOnError(err) {
|
|
173861
|
+
this.removeListener("error", duplexOnError);
|
|
173862
|
+
this.destroy();
|
|
173863
|
+
if (this.listenerCount("error") === 0) {
|
|
173864
|
+
this.emit("error", err);
|
|
173865
|
+
}
|
|
173866
|
+
}
|
|
173867
|
+
function createWebSocketStream(ws, options) {
|
|
173868
|
+
let terminateOnDestroy = true;
|
|
173869
|
+
const duplex = new Duplex({
|
|
173870
|
+
...options,
|
|
173871
|
+
autoDestroy: false,
|
|
173872
|
+
emitClose: false,
|
|
173873
|
+
objectMode: false,
|
|
173874
|
+
writableObjectMode: false
|
|
173875
|
+
});
|
|
173876
|
+
ws.on("message", function message(msg, isBinary) {
|
|
173877
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
173878
|
+
if (!duplex.push(data))
|
|
173879
|
+
ws.pause();
|
|
173880
|
+
});
|
|
173881
|
+
ws.once("error", function error(err) {
|
|
173882
|
+
if (duplex.destroyed)
|
|
173883
|
+
return;
|
|
173884
|
+
terminateOnDestroy = false;
|
|
173885
|
+
duplex.destroy(err);
|
|
173886
|
+
});
|
|
173887
|
+
ws.once("close", function close() {
|
|
173888
|
+
if (duplex.destroyed)
|
|
173889
|
+
return;
|
|
173890
|
+
duplex.push(null);
|
|
173891
|
+
});
|
|
173892
|
+
duplex._destroy = function(err, callback) {
|
|
173893
|
+
if (ws.readyState === ws.CLOSED) {
|
|
173894
|
+
callback(err);
|
|
173895
|
+
process.nextTick(emitClose, duplex);
|
|
173896
|
+
return;
|
|
173897
|
+
}
|
|
173898
|
+
let called = false;
|
|
173899
|
+
ws.once("error", function error(err) {
|
|
173900
|
+
called = true;
|
|
173901
|
+
callback(err);
|
|
173902
|
+
});
|
|
173903
|
+
ws.once("close", function close() {
|
|
173904
|
+
if (!called)
|
|
173905
|
+
callback(err);
|
|
173906
|
+
process.nextTick(emitClose, duplex);
|
|
173907
|
+
});
|
|
173908
|
+
if (terminateOnDestroy)
|
|
173909
|
+
ws.terminate();
|
|
173910
|
+
};
|
|
173911
|
+
duplex._final = function(callback) {
|
|
173912
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
173913
|
+
ws.once("open", function open() {
|
|
173914
|
+
duplex._final(callback);
|
|
173915
|
+
});
|
|
173916
|
+
return;
|
|
173917
|
+
}
|
|
173918
|
+
if (ws._socket === null)
|
|
173919
|
+
return;
|
|
173920
|
+
if (ws._socket._writableState.finished) {
|
|
173921
|
+
callback();
|
|
173922
|
+
if (duplex._readableState.endEmitted)
|
|
173923
|
+
duplex.destroy();
|
|
173924
|
+
} else {
|
|
173925
|
+
ws._socket.once("finish", function finish() {
|
|
173926
|
+
callback();
|
|
173927
|
+
});
|
|
173928
|
+
ws.close();
|
|
173929
|
+
}
|
|
173930
|
+
};
|
|
173931
|
+
duplex._read = function() {
|
|
173932
|
+
if (ws.isPaused)
|
|
173933
|
+
ws.resume();
|
|
173934
|
+
};
|
|
173935
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
173936
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
173937
|
+
ws.once("open", function open() {
|
|
173938
|
+
duplex._write(chunk, encoding, callback);
|
|
173939
|
+
});
|
|
173940
|
+
return;
|
|
173941
|
+
}
|
|
173942
|
+
ws.send(chunk, callback);
|
|
173943
|
+
};
|
|
173944
|
+
duplex.on("end", duplexOnEnd);
|
|
173945
|
+
duplex.on("error", duplexOnError);
|
|
173946
|
+
return duplex;
|
|
173947
|
+
}
|
|
173948
|
+
module.exports = createWebSocketStream;
|
|
173949
|
+
});
|
|
173950
|
+
|
|
173951
|
+
// ../../node_modules/ws/lib/subprotocol.js
|
|
173952
|
+
var require_subprotocol = __commonJS(function(exports, module) {
|
|
173953
|
+
var { tokenChars } = require_validation();
|
|
173954
|
+
function parse(header) {
|
|
173955
|
+
const protocols = new Set;
|
|
173956
|
+
let start = -1;
|
|
173957
|
+
let end = -1;
|
|
173958
|
+
let i = 0;
|
|
173959
|
+
for (i;i < header.length; i++) {
|
|
173960
|
+
const code = header.charCodeAt(i);
|
|
173961
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
173962
|
+
if (start === -1)
|
|
173963
|
+
start = i;
|
|
173964
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
173965
|
+
if (end === -1 && start !== -1)
|
|
173966
|
+
end = i;
|
|
173967
|
+
} else if (code === 44) {
|
|
173968
|
+
if (start === -1) {
|
|
173969
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173970
|
+
}
|
|
173971
|
+
if (end === -1)
|
|
173972
|
+
end = i;
|
|
173973
|
+
const protocol = header.slice(start, end);
|
|
173974
|
+
if (protocols.has(protocol)) {
|
|
173975
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
173976
|
+
}
|
|
173977
|
+
protocols.add(protocol);
|
|
173978
|
+
start = end = -1;
|
|
173979
|
+
} else {
|
|
173980
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
173981
|
+
}
|
|
173982
|
+
}
|
|
173983
|
+
if (start === -1 || end !== -1) {
|
|
173984
|
+
throw new SyntaxError("Unexpected end of input");
|
|
173985
|
+
}
|
|
173986
|
+
const protocol = header.slice(start, i);
|
|
173987
|
+
if (protocols.has(protocol)) {
|
|
173988
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
173989
|
+
}
|
|
173990
|
+
protocols.add(protocol);
|
|
173991
|
+
return protocols;
|
|
173992
|
+
}
|
|
173993
|
+
module.exports = { parse };
|
|
173994
|
+
});
|
|
173995
|
+
|
|
173996
|
+
// ../../node_modules/ws/lib/websocket-server.js
|
|
173997
|
+
var require_websocket_server = __commonJS(function(exports, module) {
|
|
173998
|
+
var EventEmitter = __require("events");
|
|
173999
|
+
var http = __require("http");
|
|
174000
|
+
var { Duplex } = __require("stream");
|
|
174001
|
+
var { createHash } = __require("crypto");
|
|
174002
|
+
var extension = require_extension();
|
|
174003
|
+
var PerMessageDeflate = require_permessage_deflate();
|
|
174004
|
+
var subprotocol = require_subprotocol();
|
|
174005
|
+
var WebSocket = require_websocket();
|
|
174006
|
+
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants6();
|
|
174007
|
+
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
174008
|
+
var RUNNING = 0;
|
|
174009
|
+
var CLOSING = 1;
|
|
174010
|
+
var CLOSED = 2;
|
|
174011
|
+
|
|
174012
|
+
class WebSocketServer extends EventEmitter {
|
|
174013
|
+
constructor(options, callback) {
|
|
174014
|
+
super();
|
|
174015
|
+
options = {
|
|
174016
|
+
allowSynchronousEvents: true,
|
|
174017
|
+
autoPong: true,
|
|
174018
|
+
maxBufferedChunks: 1024 * 1024,
|
|
174019
|
+
maxFragments: 128 * 1024,
|
|
174020
|
+
maxPayload: 100 * 1024 * 1024,
|
|
174021
|
+
skipUTF8Validation: false,
|
|
174022
|
+
perMessageDeflate: false,
|
|
174023
|
+
handleProtocols: null,
|
|
174024
|
+
clientTracking: true,
|
|
174025
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
174026
|
+
verifyClient: null,
|
|
174027
|
+
noServer: false,
|
|
174028
|
+
backlog: null,
|
|
174029
|
+
server: null,
|
|
174030
|
+
host: null,
|
|
174031
|
+
path: null,
|
|
174032
|
+
port: null,
|
|
174033
|
+
WebSocket,
|
|
174034
|
+
...options
|
|
174035
|
+
};
|
|
174036
|
+
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
174037
|
+
throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
|
|
174038
|
+
}
|
|
174039
|
+
if (options.port != null) {
|
|
174040
|
+
this._server = http.createServer((req, res) => {
|
|
174041
|
+
const body = http.STATUS_CODES[426];
|
|
174042
|
+
res.writeHead(426, {
|
|
174043
|
+
"Content-Length": body.length,
|
|
174044
|
+
"Content-Type": "text/plain"
|
|
174045
|
+
});
|
|
174046
|
+
res.end(body);
|
|
174047
|
+
});
|
|
174048
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
174049
|
+
} else if (options.server) {
|
|
174050
|
+
this._server = options.server;
|
|
174051
|
+
}
|
|
174052
|
+
if (this._server) {
|
|
174053
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
174054
|
+
this._removeListeners = addListeners(this._server, {
|
|
174055
|
+
listening: this.emit.bind(this, "listening"),
|
|
174056
|
+
error: this.emit.bind(this, "error"),
|
|
174057
|
+
upgrade: (req, socket, head) => {
|
|
174058
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
174059
|
+
}
|
|
174060
|
+
});
|
|
174061
|
+
}
|
|
174062
|
+
if (options.perMessageDeflate === true)
|
|
174063
|
+
options.perMessageDeflate = {};
|
|
174064
|
+
if (options.clientTracking) {
|
|
174065
|
+
this.clients = new Set;
|
|
174066
|
+
this._shouldEmitClose = false;
|
|
174067
|
+
}
|
|
174068
|
+
this.options = options;
|
|
174069
|
+
this._state = RUNNING;
|
|
174070
|
+
}
|
|
174071
|
+
address() {
|
|
174072
|
+
if (this.options.noServer) {
|
|
174073
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
174074
|
+
}
|
|
174075
|
+
if (!this._server)
|
|
174076
|
+
return null;
|
|
174077
|
+
return this._server.address();
|
|
174078
|
+
}
|
|
174079
|
+
close(cb) {
|
|
174080
|
+
if (this._state === CLOSED) {
|
|
174081
|
+
if (cb) {
|
|
174082
|
+
this.once("close", () => {
|
|
174083
|
+
cb(new Error("The server is not running"));
|
|
174084
|
+
});
|
|
174085
|
+
}
|
|
174086
|
+
process.nextTick(emitClose, this);
|
|
174087
|
+
return;
|
|
174088
|
+
}
|
|
174089
|
+
if (cb)
|
|
174090
|
+
this.once("close", cb);
|
|
174091
|
+
if (this._state === CLOSING)
|
|
174092
|
+
return;
|
|
174093
|
+
this._state = CLOSING;
|
|
174094
|
+
if (this.options.noServer || this.options.server) {
|
|
174095
|
+
if (this._server) {
|
|
174096
|
+
this._removeListeners();
|
|
174097
|
+
this._removeListeners = this._server = null;
|
|
174098
|
+
}
|
|
174099
|
+
if (this.clients) {
|
|
174100
|
+
if (!this.clients.size) {
|
|
174101
|
+
process.nextTick(emitClose, this);
|
|
174102
|
+
} else {
|
|
174103
|
+
this._shouldEmitClose = true;
|
|
174104
|
+
}
|
|
174105
|
+
} else {
|
|
174106
|
+
process.nextTick(emitClose, this);
|
|
174107
|
+
}
|
|
174108
|
+
} else {
|
|
174109
|
+
const server = this._server;
|
|
174110
|
+
this._removeListeners();
|
|
174111
|
+
this._removeListeners = this._server = null;
|
|
174112
|
+
server.close(() => {
|
|
174113
|
+
emitClose(this);
|
|
174114
|
+
});
|
|
174115
|
+
}
|
|
174116
|
+
}
|
|
174117
|
+
shouldHandle(req) {
|
|
174118
|
+
if (this.options.path) {
|
|
174119
|
+
const index = req.url.indexOf("?");
|
|
174120
|
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
174121
|
+
if (pathname !== this.options.path)
|
|
174122
|
+
return false;
|
|
174123
|
+
}
|
|
174124
|
+
return true;
|
|
174125
|
+
}
|
|
174126
|
+
handleUpgrade(req, socket, head, cb) {
|
|
174127
|
+
socket.on("error", socketOnError);
|
|
174128
|
+
const key = req.headers["sec-websocket-key"];
|
|
174129
|
+
const upgrade = req.headers.upgrade;
|
|
174130
|
+
const version = +req.headers["sec-websocket-version"];
|
|
174131
|
+
if (req.method !== "GET") {
|
|
174132
|
+
const message = "Invalid HTTP method";
|
|
174133
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
174134
|
+
return;
|
|
174135
|
+
}
|
|
174136
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
174137
|
+
const message = "Invalid Upgrade header";
|
|
174138
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174139
|
+
return;
|
|
174140
|
+
}
|
|
174141
|
+
if (key === undefined || !keyRegex.test(key)) {
|
|
174142
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
174143
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174144
|
+
return;
|
|
174145
|
+
}
|
|
174146
|
+
if (version !== 13 && version !== 8) {
|
|
174147
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
174148
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
174149
|
+
"Sec-WebSocket-Version": "13, 8"
|
|
174150
|
+
});
|
|
174151
|
+
return;
|
|
174152
|
+
}
|
|
174153
|
+
if (!this.shouldHandle(req)) {
|
|
174154
|
+
abortHandshake(socket, 400);
|
|
174155
|
+
return;
|
|
174156
|
+
}
|
|
174157
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
174158
|
+
let protocols = new Set;
|
|
174159
|
+
if (secWebSocketProtocol !== undefined) {
|
|
174160
|
+
try {
|
|
174161
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
174162
|
+
} catch (err) {
|
|
174163
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
174164
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174165
|
+
return;
|
|
174166
|
+
}
|
|
174167
|
+
}
|
|
174168
|
+
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
174169
|
+
const extensions = {};
|
|
174170
|
+
if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
|
|
174171
|
+
const perMessageDeflate = new PerMessageDeflate({
|
|
174172
|
+
...this.options.perMessageDeflate,
|
|
174173
|
+
isServer: true,
|
|
174174
|
+
maxPayload: this.options.maxPayload
|
|
174175
|
+
});
|
|
174176
|
+
try {
|
|
174177
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
174178
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
174179
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
174180
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
174181
|
+
}
|
|
174182
|
+
} catch (err) {
|
|
174183
|
+
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
174184
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
174185
|
+
return;
|
|
174186
|
+
}
|
|
174187
|
+
}
|
|
174188
|
+
if (this.options.verifyClient) {
|
|
174189
|
+
const info = {
|
|
174190
|
+
origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
174191
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
174192
|
+
req
|
|
174193
|
+
};
|
|
174194
|
+
if (this.options.verifyClient.length === 2) {
|
|
174195
|
+
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
174196
|
+
if (!verified) {
|
|
174197
|
+
return abortHandshake(socket, code || 401, message, headers);
|
|
174198
|
+
}
|
|
174199
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
174200
|
+
});
|
|
174201
|
+
return;
|
|
174202
|
+
}
|
|
174203
|
+
if (!this.options.verifyClient(info))
|
|
174204
|
+
return abortHandshake(socket, 401);
|
|
174205
|
+
}
|
|
174206
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
174207
|
+
}
|
|
174208
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
174209
|
+
if (!socket.readable || !socket.writable)
|
|
174210
|
+
return socket.destroy();
|
|
174211
|
+
if (socket[kWebSocket]) {
|
|
174212
|
+
throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
|
|
174213
|
+
}
|
|
174214
|
+
if (this._state > RUNNING)
|
|
174215
|
+
return abortHandshake(socket, 503);
|
|
174216
|
+
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
174217
|
+
const headers = [
|
|
174218
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
174219
|
+
"Upgrade: websocket",
|
|
174220
|
+
"Connection: Upgrade",
|
|
174221
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
174222
|
+
];
|
|
174223
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
174224
|
+
if (protocols.size) {
|
|
174225
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
174226
|
+
if (protocol) {
|
|
174227
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
174228
|
+
ws._protocol = protocol;
|
|
174229
|
+
}
|
|
174230
|
+
}
|
|
174231
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
174232
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
174233
|
+
const value = extension.format({
|
|
174234
|
+
[PerMessageDeflate.extensionName]: [params]
|
|
174235
|
+
});
|
|
174236
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
174237
|
+
ws._extensions = extensions;
|
|
174238
|
+
}
|
|
174239
|
+
this.emit("headers", headers, req);
|
|
174240
|
+
socket.write(headers.concat(`\r
|
|
174241
|
+
`).join(`\r
|
|
174242
|
+
`));
|
|
174243
|
+
socket.removeListener("error", socketOnError);
|
|
174244
|
+
ws.setSocket(socket, head, {
|
|
174245
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
174246
|
+
maxBufferedChunks: this.options.maxBufferedChunks,
|
|
174247
|
+
maxFragments: this.options.maxFragments,
|
|
174248
|
+
maxPayload: this.options.maxPayload,
|
|
174249
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
174250
|
+
});
|
|
174251
|
+
if (this.clients) {
|
|
174252
|
+
this.clients.add(ws);
|
|
174253
|
+
ws.on("close", () => {
|
|
174254
|
+
this.clients.delete(ws);
|
|
174255
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
174256
|
+
process.nextTick(emitClose, this);
|
|
174257
|
+
}
|
|
174258
|
+
});
|
|
174259
|
+
}
|
|
174260
|
+
cb(ws, req);
|
|
174261
|
+
}
|
|
174262
|
+
}
|
|
174263
|
+
module.exports = WebSocketServer;
|
|
174264
|
+
function addListeners(server, map) {
|
|
174265
|
+
for (const event of Object.keys(map))
|
|
174266
|
+
server.on(event, map[event]);
|
|
174267
|
+
return function removeListeners() {
|
|
174268
|
+
for (const event of Object.keys(map)) {
|
|
174269
|
+
server.removeListener(event, map[event]);
|
|
174270
|
+
}
|
|
174271
|
+
};
|
|
174272
|
+
}
|
|
174273
|
+
function emitClose(server) {
|
|
174274
|
+
server._state = CLOSED;
|
|
174275
|
+
server.emit("close");
|
|
174276
|
+
}
|
|
174277
|
+
function socketOnError() {
|
|
174278
|
+
this.destroy();
|
|
174279
|
+
}
|
|
174280
|
+
function abortHandshake(socket, code, message, headers) {
|
|
174281
|
+
message = message || http.STATUS_CODES[code];
|
|
174282
|
+
headers = {
|
|
174283
|
+
Connection: "close",
|
|
174284
|
+
"Content-Type": "text/html",
|
|
174285
|
+
"Content-Length": Buffer.byteLength(message),
|
|
174286
|
+
...headers
|
|
174287
|
+
};
|
|
174288
|
+
socket.once("finish", socket.destroy);
|
|
174289
|
+
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
174290
|
+
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
|
|
174291
|
+
`) + `\r
|
|
174292
|
+
\r
|
|
174293
|
+
` + message);
|
|
174294
|
+
}
|
|
174295
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
174296
|
+
if (server.listenerCount("wsClientError")) {
|
|
174297
|
+
const err = new Error(message);
|
|
174298
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
174299
|
+
server.emit("wsClientError", err, socket, req);
|
|
174300
|
+
} else {
|
|
174301
|
+
abortHandshake(socket, code, message, headers);
|
|
174302
|
+
}
|
|
174303
|
+
}
|
|
174304
|
+
});
|
|
174305
|
+
|
|
171423
174306
|
// ../../node_modules/@seald-io/nedb/lib/utils.js
|
|
171424
174307
|
var require_utils11 = __commonJS(function(exports, module) {
|
|
171425
174308
|
var uniq = (array, iteratee) => {
|
|
@@ -193410,7 +196293,7 @@ var require_polling_jsonp = __commonJS(function(exports) {
|
|
|
193410
196293
|
});
|
|
193411
196294
|
|
|
193412
196295
|
// ../../node_modules/engine.io/build/transports/websocket.js
|
|
193413
|
-
var
|
|
196296
|
+
var require_websocket2 = __commonJS(function(exports) {
|
|
193414
196297
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
193415
196298
|
exports.WebSocket = undefined;
|
|
193416
196299
|
var transport_1 = require_transport();
|
|
@@ -193549,7 +196432,7 @@ var require_transports = __commonJS(function(exports) {
|
|
|
193549
196432
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
193550
196433
|
var polling_1 = require_polling();
|
|
193551
196434
|
var polling_jsonp_1 = require_polling_jsonp();
|
|
193552
|
-
var websocket_1 =
|
|
196435
|
+
var websocket_1 = require_websocket2();
|
|
193553
196436
|
var webtransport_1 = require_webtransport();
|
|
193554
196437
|
exports.default = {
|
|
193555
196438
|
polling,
|
|
@@ -193897,7 +196780,7 @@ var require_socket = __commonJS(function(exports) {
|
|
|
193897
196780
|
});
|
|
193898
196781
|
|
|
193899
196782
|
// ../../node_modules/engine.io/node_modules/ws/lib/constants.js
|
|
193900
|
-
var
|
|
196783
|
+
var require_constants7 = __commonJS(function(exports, module) {
|
|
193901
196784
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
193902
196785
|
var hasBlob = typeof Blob !== "undefined";
|
|
193903
196786
|
if (hasBlob)
|
|
@@ -193916,8 +196799,8 @@ var require_constants6 = __commonJS(function(exports, module) {
|
|
|
193916
196799
|
});
|
|
193917
196800
|
|
|
193918
196801
|
// ../../node_modules/engine.io/node_modules/ws/lib/buffer-util.js
|
|
193919
|
-
var
|
|
193920
|
-
var { EMPTY_BUFFER } =
|
|
196802
|
+
var require_buffer_util2 = __commonJS(function(exports, module) {
|
|
196803
|
+
var { EMPTY_BUFFER } = require_constants7();
|
|
193921
196804
|
var FastBuffer = Buffer[Symbol.species];
|
|
193922
196805
|
function concat(list, totalLength) {
|
|
193923
196806
|
if (list.length === 0)
|
|
@@ -193994,7 +196877,7 @@ var require_buffer_util = __commonJS(function(exports, module) {
|
|
|
193994
196877
|
});
|
|
193995
196878
|
|
|
193996
196879
|
// ../../node_modules/engine.io/node_modules/ws/lib/limiter.js
|
|
193997
|
-
var
|
|
196880
|
+
var require_limiter2 = __commonJS(function(exports, module) {
|
|
193998
196881
|
var kDone = Symbol("kDone");
|
|
193999
196882
|
var kRun = Symbol("kRun");
|
|
194000
196883
|
|
|
@@ -194026,11 +196909,11 @@ var require_limiter = __commonJS(function(exports, module) {
|
|
|
194026
196909
|
});
|
|
194027
196910
|
|
|
194028
196911
|
// ../../node_modules/engine.io/node_modules/ws/lib/permessage-deflate.js
|
|
194029
|
-
var
|
|
196912
|
+
var require_permessage_deflate2 = __commonJS(function(exports, module) {
|
|
194030
196913
|
var zlib = __require("zlib");
|
|
194031
|
-
var bufferUtil =
|
|
194032
|
-
var Limiter =
|
|
194033
|
-
var { kStatusCode } =
|
|
196914
|
+
var bufferUtil = require_buffer_util2();
|
|
196915
|
+
var Limiter = require_limiter2();
|
|
196916
|
+
var { kStatusCode } = require_constants7();
|
|
194034
196917
|
var FastBuffer = Buffer[Symbol.species];
|
|
194035
196918
|
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
194036
196919
|
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
@@ -194290,9 +197173,9 @@ var require_permessage_deflate = __commonJS(function(exports, module) {
|
|
|
194290
197173
|
});
|
|
194291
197174
|
|
|
194292
197175
|
// ../../node_modules/engine.io/node_modules/ws/lib/validation.js
|
|
194293
|
-
var
|
|
197176
|
+
var require_validation2 = __commonJS(function(exports, module) {
|
|
194294
197177
|
var { isUtf8 } = __require("buffer");
|
|
194295
|
-
var { hasBlob } =
|
|
197178
|
+
var { hasBlob } = require_constants7();
|
|
194296
197179
|
var tokenChars = [
|
|
194297
197180
|
0,
|
|
194298
197181
|
0,
|
|
@@ -194477,17 +197360,17 @@ var require_validation = __commonJS(function(exports, module) {
|
|
|
194477
197360
|
});
|
|
194478
197361
|
|
|
194479
197362
|
// ../../node_modules/engine.io/node_modules/ws/lib/receiver.js
|
|
194480
|
-
var
|
|
197363
|
+
var require_receiver2 = __commonJS(function(exports, module) {
|
|
194481
197364
|
var { Writable } = __require("stream");
|
|
194482
|
-
var PerMessageDeflate =
|
|
197365
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
194483
197366
|
var {
|
|
194484
197367
|
BINARY_TYPES,
|
|
194485
197368
|
EMPTY_BUFFER,
|
|
194486
197369
|
kStatusCode,
|
|
194487
197370
|
kWebSocket
|
|
194488
|
-
} =
|
|
194489
|
-
var { concat, toArrayBuffer, unmask } =
|
|
194490
|
-
var { isValidStatusCode, isValidUTF8 } =
|
|
197371
|
+
} = require_constants7();
|
|
197372
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util2();
|
|
197373
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation2();
|
|
194491
197374
|
var FastBuffer = Buffer[Symbol.species];
|
|
194492
197375
|
var GET_INFO = 0;
|
|
194493
197376
|
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
@@ -194858,13 +197741,13 @@ var require_receiver = __commonJS(function(exports, module) {
|
|
|
194858
197741
|
});
|
|
194859
197742
|
|
|
194860
197743
|
// ../../node_modules/engine.io/node_modules/ws/lib/sender.js
|
|
194861
|
-
var
|
|
197744
|
+
var require_sender2 = __commonJS(function(exports, module) {
|
|
194862
197745
|
var { Duplex } = __require("stream");
|
|
194863
197746
|
var { randomFillSync } = __require("crypto");
|
|
194864
|
-
var PerMessageDeflate =
|
|
194865
|
-
var { EMPTY_BUFFER, kWebSocket, NOOP } =
|
|
194866
|
-
var { isBlob, isValidStatusCode } =
|
|
194867
|
-
var { mask: applyMask, toBuffer } =
|
|
197747
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
197748
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants7();
|
|
197749
|
+
var { isBlob, isValidStatusCode } = require_validation2();
|
|
197750
|
+
var { mask: applyMask, toBuffer } = require_buffer_util2();
|
|
194868
197751
|
var kByteLength = Symbol("kByteLength");
|
|
194869
197752
|
var maskBuffer = Buffer.alloc(4);
|
|
194870
197753
|
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
@@ -195212,8 +198095,8 @@ var require_sender = __commonJS(function(exports, module) {
|
|
|
195212
198095
|
});
|
|
195213
198096
|
|
|
195214
198097
|
// ../../node_modules/engine.io/node_modules/ws/lib/event-target.js
|
|
195215
|
-
var
|
|
195216
|
-
var { kForOnEventAttribute, kListener } =
|
|
198098
|
+
var require_event_target2 = __commonJS(function(exports, module) {
|
|
198099
|
+
var { kForOnEventAttribute, kListener } = require_constants7();
|
|
195217
198100
|
var kCode = Symbol("kCode");
|
|
195218
198101
|
var kData = Symbol("kData");
|
|
195219
198102
|
var kError = Symbol("kError");
|
|
@@ -195363,8 +198246,8 @@ var require_event_target = __commonJS(function(exports, module) {
|
|
|
195363
198246
|
});
|
|
195364
198247
|
|
|
195365
198248
|
// ../../node_modules/engine.io/node_modules/ws/lib/extension.js
|
|
195366
|
-
var
|
|
195367
|
-
var { tokenChars } =
|
|
198249
|
+
var require_extension2 = __commonJS(function(exports, module) {
|
|
198250
|
+
var { tokenChars } = require_validation2();
|
|
195368
198251
|
function push(dest, name, elem) {
|
|
195369
198252
|
if (dest[name] === undefined)
|
|
195370
198253
|
dest[name] = [elem];
|
|
@@ -195528,7 +198411,7 @@ var require_extension = __commonJS(function(exports, module) {
|
|
|
195528
198411
|
});
|
|
195529
198412
|
|
|
195530
198413
|
// ../../node_modules/engine.io/node_modules/ws/lib/websocket.js
|
|
195531
|
-
var
|
|
198414
|
+
var require_websocket3 = __commonJS(function(exports, module) {
|
|
195532
198415
|
var EventEmitter = __require("events");
|
|
195533
198416
|
var https = __require("https");
|
|
195534
198417
|
var http = __require("http");
|
|
@@ -195537,10 +198420,10 @@ var require_websocket2 = __commonJS(function(exports, module) {
|
|
|
195537
198420
|
var { randomBytes, createHash } = __require("crypto");
|
|
195538
198421
|
var { Duplex, Readable } = __require("stream");
|
|
195539
198422
|
var { URL: URL2 } = __require("url");
|
|
195540
|
-
var PerMessageDeflate =
|
|
195541
|
-
var Receiver =
|
|
195542
|
-
var Sender =
|
|
195543
|
-
var { isBlob } =
|
|
198423
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
198424
|
+
var Receiver = require_receiver2();
|
|
198425
|
+
var Sender = require_sender2();
|
|
198426
|
+
var { isBlob } = require_validation2();
|
|
195544
198427
|
var {
|
|
195545
198428
|
BINARY_TYPES,
|
|
195546
198429
|
EMPTY_BUFFER,
|
|
@@ -195550,12 +198433,12 @@ var require_websocket2 = __commonJS(function(exports, module) {
|
|
|
195550
198433
|
kStatusCode,
|
|
195551
198434
|
kWebSocket,
|
|
195552
198435
|
NOOP
|
|
195553
|
-
} =
|
|
198436
|
+
} = require_constants7();
|
|
195554
198437
|
var {
|
|
195555
198438
|
EventTarget: { addEventListener, removeEventListener }
|
|
195556
|
-
} =
|
|
195557
|
-
var { format, parse } =
|
|
195558
|
-
var { toBuffer } =
|
|
198439
|
+
} = require_event_target2();
|
|
198440
|
+
var { format, parse } = require_extension2();
|
|
198441
|
+
var { toBuffer } = require_buffer_util2();
|
|
195559
198442
|
var closeTimeout = 30 * 1000;
|
|
195560
198443
|
var kAborted = Symbol("kAborted");
|
|
195561
198444
|
var protocolVersions = [8, 13];
|
|
@@ -196287,8 +199170,8 @@ var require_websocket2 = __commonJS(function(exports, module) {
|
|
|
196287
199170
|
});
|
|
196288
199171
|
|
|
196289
199172
|
// ../../node_modules/engine.io/node_modules/ws/lib/stream.js
|
|
196290
|
-
var
|
|
196291
|
-
var WebSocket =
|
|
199173
|
+
var require_stream7 = __commonJS(function(exports, module) {
|
|
199174
|
+
var WebSocket = require_websocket3();
|
|
196292
199175
|
var { Duplex } = __require("stream");
|
|
196293
199176
|
function emitClose(stream) {
|
|
196294
199177
|
stream.emit("close");
|
|
@@ -196390,8 +199273,8 @@ var require_stream6 = __commonJS(function(exports, module) {
|
|
|
196390
199273
|
});
|
|
196391
199274
|
|
|
196392
199275
|
// ../../node_modules/engine.io/node_modules/ws/lib/subprotocol.js
|
|
196393
|
-
var
|
|
196394
|
-
var { tokenChars } =
|
|
199276
|
+
var require_subprotocol2 = __commonJS(function(exports, module) {
|
|
199277
|
+
var { tokenChars } = require_validation2();
|
|
196395
199278
|
function parse(header) {
|
|
196396
199279
|
const protocols = new Set;
|
|
196397
199280
|
let start = -1;
|
|
@@ -196435,16 +199318,16 @@ var require_subprotocol = __commonJS(function(exports, module) {
|
|
|
196435
199318
|
});
|
|
196436
199319
|
|
|
196437
199320
|
// ../../node_modules/engine.io/node_modules/ws/lib/websocket-server.js
|
|
196438
|
-
var
|
|
199321
|
+
var require_websocket_server2 = __commonJS(function(exports, module) {
|
|
196439
199322
|
var EventEmitter = __require("events");
|
|
196440
199323
|
var http = __require("http");
|
|
196441
199324
|
var { Duplex } = __require("stream");
|
|
196442
199325
|
var { createHash } = __require("crypto");
|
|
196443
|
-
var extension =
|
|
196444
|
-
var PerMessageDeflate =
|
|
196445
|
-
var subprotocol =
|
|
196446
|
-
var WebSocket =
|
|
196447
|
-
var { GUID, kWebSocket } =
|
|
199326
|
+
var extension = require_extension2();
|
|
199327
|
+
var PerMessageDeflate = require_permessage_deflate2();
|
|
199328
|
+
var subprotocol = require_subprotocol2();
|
|
199329
|
+
var WebSocket = require_websocket3();
|
|
199330
|
+
var { GUID, kWebSocket } = require_constants7();
|
|
196448
199331
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
196449
199332
|
var RUNNING = 0;
|
|
196450
199333
|
var CLOSING = 1;
|
|
@@ -196737,11 +199620,11 @@ var require_websocket_server = __commonJS(function(exports, module) {
|
|
|
196737
199620
|
|
|
196738
199621
|
// ../../node_modules/engine.io/node_modules/ws/index.js
|
|
196739
199622
|
var require_ws = __commonJS(function(exports, module) {
|
|
196740
|
-
var WebSocket =
|
|
196741
|
-
WebSocket.createWebSocketStream =
|
|
196742
|
-
WebSocket.Server =
|
|
196743
|
-
WebSocket.Receiver =
|
|
196744
|
-
WebSocket.Sender =
|
|
199623
|
+
var WebSocket = require_websocket3();
|
|
199624
|
+
WebSocket.createWebSocketStream = require_stream7();
|
|
199625
|
+
WebSocket.Server = require_websocket_server2();
|
|
199626
|
+
WebSocket.Receiver = require_receiver2();
|
|
199627
|
+
WebSocket.Sender = require_sender2();
|
|
196745
199628
|
WebSocket.WebSocket = WebSocket;
|
|
196746
199629
|
WebSocket.WebSocketServer = WebSocket.Server;
|
|
196747
199630
|
module.exports = WebSocket;
|
|
@@ -197864,7 +200747,7 @@ var require_polling2 = __commonJS(function(exports) {
|
|
|
197864
200747
|
});
|
|
197865
200748
|
|
|
197866
200749
|
// ../../node_modules/engine.io/build/transports-uws/websocket.js
|
|
197867
|
-
var
|
|
200750
|
+
var require_websocket4 = __commonJS(function(exports) {
|
|
197868
200751
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
197869
200752
|
exports.WebSocket = undefined;
|
|
197870
200753
|
var transport_1 = require_transport();
|
|
@@ -197919,7 +200802,7 @@ var require_websocket3 = __commonJS(function(exports) {
|
|
|
197919
200802
|
var require_transports_uws = __commonJS(function(exports) {
|
|
197920
200803
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
197921
200804
|
var polling_1 = require_polling2();
|
|
197922
|
-
var websocket_1 =
|
|
200805
|
+
var websocket_1 = require_websocket4();
|
|
197923
200806
|
exports.default = {
|
|
197924
200807
|
polling: polling_1.Polling,
|
|
197925
200808
|
websocket: websocket_1.WebSocket
|
|
@@ -199725,7 +202608,7 @@ var require_yeast = __commonJS(function(exports) {
|
|
|
199725
202608
|
});
|
|
199726
202609
|
|
|
199727
202610
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/constants.js
|
|
199728
|
-
var
|
|
202611
|
+
var require_constants8 = __commonJS(function(exports, module) {
|
|
199729
202612
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
199730
202613
|
var hasBlob = typeof Blob !== "undefined";
|
|
199731
202614
|
if (hasBlob)
|
|
@@ -199744,8 +202627,8 @@ var require_constants7 = __commonJS(function(exports, module) {
|
|
|
199744
202627
|
});
|
|
199745
202628
|
|
|
199746
202629
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/buffer-util.js
|
|
199747
|
-
var
|
|
199748
|
-
var { EMPTY_BUFFER } =
|
|
202630
|
+
var require_buffer_util3 = __commonJS(function(exports, module) {
|
|
202631
|
+
var { EMPTY_BUFFER } = require_constants8();
|
|
199749
202632
|
var FastBuffer = Buffer[Symbol.species];
|
|
199750
202633
|
function concat(list, totalLength) {
|
|
199751
202634
|
if (list.length === 0)
|
|
@@ -199822,7 +202705,7 @@ var require_buffer_util2 = __commonJS(function(exports, module) {
|
|
|
199822
202705
|
});
|
|
199823
202706
|
|
|
199824
202707
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/limiter.js
|
|
199825
|
-
var
|
|
202708
|
+
var require_limiter3 = __commonJS(function(exports, module) {
|
|
199826
202709
|
var kDone = Symbol("kDone");
|
|
199827
202710
|
var kRun = Symbol("kRun");
|
|
199828
202711
|
|
|
@@ -199854,11 +202737,11 @@ var require_limiter2 = __commonJS(function(exports, module) {
|
|
|
199854
202737
|
});
|
|
199855
202738
|
|
|
199856
202739
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/permessage-deflate.js
|
|
199857
|
-
var
|
|
202740
|
+
var require_permessage_deflate3 = __commonJS(function(exports, module) {
|
|
199858
202741
|
var zlib = __require("zlib");
|
|
199859
|
-
var bufferUtil =
|
|
199860
|
-
var Limiter =
|
|
199861
|
-
var { kStatusCode } =
|
|
202742
|
+
var bufferUtil = require_buffer_util3();
|
|
202743
|
+
var Limiter = require_limiter3();
|
|
202744
|
+
var { kStatusCode } = require_constants8();
|
|
199862
202745
|
var FastBuffer = Buffer[Symbol.species];
|
|
199863
202746
|
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
199864
202747
|
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
@@ -200118,9 +203001,9 @@ var require_permessage_deflate2 = __commonJS(function(exports, module) {
|
|
|
200118
203001
|
});
|
|
200119
203002
|
|
|
200120
203003
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/validation.js
|
|
200121
|
-
var
|
|
203004
|
+
var require_validation3 = __commonJS(function(exports, module) {
|
|
200122
203005
|
var { isUtf8 } = __require("buffer");
|
|
200123
|
-
var { hasBlob } =
|
|
203006
|
+
var { hasBlob } = require_constants8();
|
|
200124
203007
|
var tokenChars = [
|
|
200125
203008
|
0,
|
|
200126
203009
|
0,
|
|
@@ -200305,17 +203188,17 @@ var require_validation2 = __commonJS(function(exports, module) {
|
|
|
200305
203188
|
});
|
|
200306
203189
|
|
|
200307
203190
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/receiver.js
|
|
200308
|
-
var
|
|
203191
|
+
var require_receiver3 = __commonJS(function(exports, module) {
|
|
200309
203192
|
var { Writable } = __require("stream");
|
|
200310
|
-
var PerMessageDeflate =
|
|
203193
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
200311
203194
|
var {
|
|
200312
203195
|
BINARY_TYPES,
|
|
200313
203196
|
EMPTY_BUFFER,
|
|
200314
203197
|
kStatusCode,
|
|
200315
203198
|
kWebSocket
|
|
200316
|
-
} =
|
|
200317
|
-
var { concat, toArrayBuffer, unmask } =
|
|
200318
|
-
var { isValidStatusCode, isValidUTF8 } =
|
|
203199
|
+
} = require_constants8();
|
|
203200
|
+
var { concat, toArrayBuffer, unmask } = require_buffer_util3();
|
|
203201
|
+
var { isValidStatusCode, isValidUTF8 } = require_validation3();
|
|
200319
203202
|
var FastBuffer = Buffer[Symbol.species];
|
|
200320
203203
|
var GET_INFO = 0;
|
|
200321
203204
|
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
@@ -200686,13 +203569,13 @@ var require_receiver2 = __commonJS(function(exports, module) {
|
|
|
200686
203569
|
});
|
|
200687
203570
|
|
|
200688
203571
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/sender.js
|
|
200689
|
-
var
|
|
203572
|
+
var require_sender3 = __commonJS(function(exports, module) {
|
|
200690
203573
|
var { Duplex } = __require("stream");
|
|
200691
203574
|
var { randomFillSync } = __require("crypto");
|
|
200692
|
-
var PerMessageDeflate =
|
|
200693
|
-
var { EMPTY_BUFFER, kWebSocket, NOOP } =
|
|
200694
|
-
var { isBlob, isValidStatusCode } =
|
|
200695
|
-
var { mask: applyMask, toBuffer } =
|
|
203575
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
203576
|
+
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants8();
|
|
203577
|
+
var { isBlob, isValidStatusCode } = require_validation3();
|
|
203578
|
+
var { mask: applyMask, toBuffer } = require_buffer_util3();
|
|
200696
203579
|
var kByteLength = Symbol("kByteLength");
|
|
200697
203580
|
var maskBuffer = Buffer.alloc(4);
|
|
200698
203581
|
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
@@ -201040,8 +203923,8 @@ var require_sender2 = __commonJS(function(exports, module) {
|
|
|
201040
203923
|
});
|
|
201041
203924
|
|
|
201042
203925
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/event-target.js
|
|
201043
|
-
var
|
|
201044
|
-
var { kForOnEventAttribute, kListener } =
|
|
203926
|
+
var require_event_target3 = __commonJS(function(exports, module) {
|
|
203927
|
+
var { kForOnEventAttribute, kListener } = require_constants8();
|
|
201045
203928
|
var kCode = Symbol("kCode");
|
|
201046
203929
|
var kData = Symbol("kData");
|
|
201047
203930
|
var kError = Symbol("kError");
|
|
@@ -201191,8 +204074,8 @@ var require_event_target2 = __commonJS(function(exports, module) {
|
|
|
201191
204074
|
});
|
|
201192
204075
|
|
|
201193
204076
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/extension.js
|
|
201194
|
-
var
|
|
201195
|
-
var { tokenChars } =
|
|
204077
|
+
var require_extension3 = __commonJS(function(exports, module) {
|
|
204078
|
+
var { tokenChars } = require_validation3();
|
|
201196
204079
|
function push(dest, name, elem) {
|
|
201197
204080
|
if (dest[name] === undefined)
|
|
201198
204081
|
dest[name] = [elem];
|
|
@@ -201356,7 +204239,7 @@ var require_extension2 = __commonJS(function(exports, module) {
|
|
|
201356
204239
|
});
|
|
201357
204240
|
|
|
201358
204241
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/websocket.js
|
|
201359
|
-
var
|
|
204242
|
+
var require_websocket5 = __commonJS(function(exports, module) {
|
|
201360
204243
|
var EventEmitter = __require("events");
|
|
201361
204244
|
var https = __require("https");
|
|
201362
204245
|
var http = __require("http");
|
|
@@ -201365,10 +204248,10 @@ var require_websocket4 = __commonJS(function(exports, module) {
|
|
|
201365
204248
|
var { randomBytes, createHash } = __require("crypto");
|
|
201366
204249
|
var { Duplex, Readable } = __require("stream");
|
|
201367
204250
|
var { URL: URL2 } = __require("url");
|
|
201368
|
-
var PerMessageDeflate =
|
|
201369
|
-
var Receiver =
|
|
201370
|
-
var Sender =
|
|
201371
|
-
var { isBlob } =
|
|
204251
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
204252
|
+
var Receiver = require_receiver3();
|
|
204253
|
+
var Sender = require_sender3();
|
|
204254
|
+
var { isBlob } = require_validation3();
|
|
201372
204255
|
var {
|
|
201373
204256
|
BINARY_TYPES,
|
|
201374
204257
|
EMPTY_BUFFER,
|
|
@@ -201378,12 +204261,12 @@ var require_websocket4 = __commonJS(function(exports, module) {
|
|
|
201378
204261
|
kStatusCode,
|
|
201379
204262
|
kWebSocket,
|
|
201380
204263
|
NOOP
|
|
201381
|
-
} =
|
|
204264
|
+
} = require_constants8();
|
|
201382
204265
|
var {
|
|
201383
204266
|
EventTarget: { addEventListener, removeEventListener }
|
|
201384
|
-
} =
|
|
201385
|
-
var { format, parse } =
|
|
201386
|
-
var { toBuffer } =
|
|
204267
|
+
} = require_event_target3();
|
|
204268
|
+
var { format, parse } = require_extension3();
|
|
204269
|
+
var { toBuffer } = require_buffer_util3();
|
|
201387
204270
|
var closeTimeout = 30 * 1000;
|
|
201388
204271
|
var kAborted = Symbol("kAborted");
|
|
201389
204272
|
var protocolVersions = [8, 13];
|
|
@@ -202115,8 +204998,8 @@ var require_websocket4 = __commonJS(function(exports, module) {
|
|
|
202115
204998
|
});
|
|
202116
204999
|
|
|
202117
205000
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/stream.js
|
|
202118
|
-
var
|
|
202119
|
-
var WebSocket =
|
|
205001
|
+
var require_stream8 = __commonJS(function(exports, module) {
|
|
205002
|
+
var WebSocket = require_websocket5();
|
|
202120
205003
|
var { Duplex } = __require("stream");
|
|
202121
205004
|
function emitClose(stream) {
|
|
202122
205005
|
stream.emit("close");
|
|
@@ -202218,8 +205101,8 @@ var require_stream7 = __commonJS(function(exports, module) {
|
|
|
202218
205101
|
});
|
|
202219
205102
|
|
|
202220
205103
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/subprotocol.js
|
|
202221
|
-
var
|
|
202222
|
-
var { tokenChars } =
|
|
205104
|
+
var require_subprotocol3 = __commonJS(function(exports, module) {
|
|
205105
|
+
var { tokenChars } = require_validation3();
|
|
202223
205106
|
function parse(header) {
|
|
202224
205107
|
const protocols = new Set;
|
|
202225
205108
|
let start = -1;
|
|
@@ -202263,16 +205146,16 @@ var require_subprotocol2 = __commonJS(function(exports, module) {
|
|
|
202263
205146
|
});
|
|
202264
205147
|
|
|
202265
205148
|
// ../../node_modules/socket.io-adapter/node_modules/ws/lib/websocket-server.js
|
|
202266
|
-
var
|
|
205149
|
+
var require_websocket_server3 = __commonJS(function(exports, module) {
|
|
202267
205150
|
var EventEmitter = __require("events");
|
|
202268
205151
|
var http = __require("http");
|
|
202269
205152
|
var { Duplex } = __require("stream");
|
|
202270
205153
|
var { createHash } = __require("crypto");
|
|
202271
|
-
var extension =
|
|
202272
|
-
var PerMessageDeflate =
|
|
202273
|
-
var subprotocol =
|
|
202274
|
-
var WebSocket =
|
|
202275
|
-
var { GUID, kWebSocket } =
|
|
205154
|
+
var extension = require_extension3();
|
|
205155
|
+
var PerMessageDeflate = require_permessage_deflate3();
|
|
205156
|
+
var subprotocol = require_subprotocol3();
|
|
205157
|
+
var WebSocket = require_websocket5();
|
|
205158
|
+
var { GUID, kWebSocket } = require_constants8();
|
|
202276
205159
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
202277
205160
|
var RUNNING = 0;
|
|
202278
205161
|
var CLOSING = 1;
|
|
@@ -202565,11 +205448,11 @@ var require_websocket_server2 = __commonJS(function(exports, module) {
|
|
|
202565
205448
|
|
|
202566
205449
|
// ../../node_modules/socket.io-adapter/node_modules/ws/index.js
|
|
202567
205450
|
var require_ws2 = __commonJS(function(exports, module) {
|
|
202568
|
-
var WebSocket =
|
|
202569
|
-
WebSocket.createWebSocketStream =
|
|
202570
|
-
WebSocket.Server =
|
|
202571
|
-
WebSocket.Receiver =
|
|
202572
|
-
WebSocket.Sender =
|
|
205451
|
+
var WebSocket = require_websocket5();
|
|
205452
|
+
WebSocket.createWebSocketStream = require_stream8();
|
|
205453
|
+
WebSocket.Server = require_websocket_server3();
|
|
205454
|
+
WebSocket.Receiver = require_receiver3();
|
|
205455
|
+
WebSocket.Sender = require_sender3();
|
|
202573
205456
|
WebSocket.WebSocket = WebSocket;
|
|
202574
205457
|
WebSocket.WebSocketServer = WebSocket.Server;
|
|
202575
205458
|
module.exports = WebSocket;
|
|
@@ -221164,6 +224047,34 @@ var require_dist5 = __commonJS(function(exports, module) {
|
|
|
221164
224047
|
}
|
|
221165
224048
|
});
|
|
221166
224049
|
|
|
224050
|
+
// ../../node_modules/commander/index.js
|
|
224051
|
+
var exports_commander = {};
|
|
224052
|
+
__exportCjs(exports_commander, {
|
|
224053
|
+
program: () => $program,
|
|
224054
|
+
createCommand: () => $createCommand,
|
|
224055
|
+
createOption: () => $createOption,
|
|
224056
|
+
createArgument: () => $createArgument,
|
|
224057
|
+
Command: () => $Command,
|
|
224058
|
+
Option: () => $Option,
|
|
224059
|
+
Argument: () => $Argument,
|
|
224060
|
+
Help: () => $Help,
|
|
224061
|
+
CommanderError: () => $CommanderError,
|
|
224062
|
+
InvalidArgumentError: () => $InvalidArgumentError,
|
|
224063
|
+
InvalidOptionArgumentError: () => $InvalidOptionArgumentError
|
|
224064
|
+
}, {
|
|
224065
|
+
program: (value) => $program = value,
|
|
224066
|
+
createCommand: (value) => $createCommand = value,
|
|
224067
|
+
createOption: (value) => $createOption = value,
|
|
224068
|
+
createArgument: (value) => $createArgument = value,
|
|
224069
|
+
Command: (value) => $Command = value,
|
|
224070
|
+
Option: (value) => $Option = value,
|
|
224071
|
+
Argument: (value) => $Argument = value,
|
|
224072
|
+
Help: (value) => $Help = value,
|
|
224073
|
+
CommanderError: (value) => $CommanderError = value,
|
|
224074
|
+
InvalidArgumentError: (value) => $InvalidArgumentError = value,
|
|
224075
|
+
InvalidOptionArgumentError: (value) => $InvalidOptionArgumentError = value
|
|
224076
|
+
});
|
|
224077
|
+
|
|
221167
224078
|
// src/core/utils/env.ts
|
|
221168
224079
|
var import_dotenv = __toESM(require_main(), 1);
|
|
221169
224080
|
import { basename, dirname as dirname3, join } from "node:path";
|
|
@@ -229878,32 +232789,6 @@ class SimpleLogger {
|
|
|
229878
232789
|
}
|
|
229879
232790
|
}
|
|
229880
232791
|
// ../../node_modules/commander/index.js
|
|
229881
|
-
var exports_commander = {};
|
|
229882
|
-
__exportCjs(exports_commander, {
|
|
229883
|
-
program: () => $program,
|
|
229884
|
-
createCommand: () => $createCommand,
|
|
229885
|
-
createOption: () => $createOption,
|
|
229886
|
-
createArgument: () => $createArgument,
|
|
229887
|
-
Command: () => $Command,
|
|
229888
|
-
Option: () => $Option,
|
|
229889
|
-
Argument: () => $Argument,
|
|
229890
|
-
Help: () => $Help,
|
|
229891
|
-
CommanderError: () => $CommanderError,
|
|
229892
|
-
InvalidArgumentError: () => $InvalidArgumentError,
|
|
229893
|
-
InvalidOptionArgumentError: () => $InvalidOptionArgumentError
|
|
229894
|
-
}, {
|
|
229895
|
-
program: (value) => $program = value,
|
|
229896
|
-
createCommand: (value) => $createCommand = value,
|
|
229897
|
-
createOption: (value) => $createOption = value,
|
|
229898
|
-
createArgument: (value) => $createArgument = value,
|
|
229899
|
-
Command: (value) => $Command = value,
|
|
229900
|
-
Option: (value) => $Option = value,
|
|
229901
|
-
Argument: (value) => $Argument = value,
|
|
229902
|
-
Help: (value) => $Help = value,
|
|
229903
|
-
CommanderError: (value) => $CommanderError = value,
|
|
229904
|
-
InvalidArgumentError: (value) => $InvalidArgumentError = value,
|
|
229905
|
-
InvalidOptionArgumentError: (value) => $InvalidOptionArgumentError = value
|
|
229906
|
-
});
|
|
229907
232792
|
var { Argument } = require_argument();
|
|
229908
232793
|
var { Command } = require_command();
|
|
229909
232794
|
var { CommanderError, InvalidArgumentError } = require_error2();
|
|
@@ -236596,6 +239481,15 @@ var FinalizeDeploymentResponseSchema = object({
|
|
|
236596
239481
|
}).transform((data) => ({
|
|
236597
239482
|
deploymentId: data.deployment_id
|
|
236598
239483
|
}));
|
|
239484
|
+
var PublishDeploymentResponseSchema = object({
|
|
239485
|
+
git_hash: string2(),
|
|
239486
|
+
deployed_at: string2(),
|
|
239487
|
+
app_url: string2()
|
|
239488
|
+
}).transform((data) => ({
|
|
239489
|
+
gitHash: data.git_hash,
|
|
239490
|
+
deployedAt: data.deployed_at,
|
|
239491
|
+
appUrl: data.app_url
|
|
239492
|
+
}));
|
|
236599
239493
|
|
|
236600
239494
|
// src/core/project/api.ts
|
|
236601
239495
|
var PUBLIC_SETTINGS = {
|
|
@@ -239374,7 +242268,7 @@ import { join as join13 } from "node:path";
|
|
|
239374
242268
|
// package.json
|
|
239375
242269
|
var package_default = {
|
|
239376
242270
|
name: "base44",
|
|
239377
|
-
version: "0.1.
|
|
242271
|
+
version: "0.1.32",
|
|
239378
242272
|
description: "Base44 CLI - Unified interface for managing Base44 applications",
|
|
239379
242273
|
type: "module",
|
|
239380
242274
|
bin: {
|
|
@@ -239430,6 +242324,7 @@ var package_default = {
|
|
|
239430
242324
|
"@types/ms": "^2.1.0",
|
|
239431
242325
|
"@types/multer": "^2.0.0",
|
|
239432
242326
|
"@types/node": "^22.10.5",
|
|
242327
|
+
"@types/ws": "^8.18.1",
|
|
239433
242328
|
"@vercel/detect-agent": "^1.1.0",
|
|
239434
242329
|
chalk: "^5.6.2",
|
|
239435
242330
|
chokidar: "^5.0.0",
|
|
@@ -239464,6 +242359,7 @@ var package_default = {
|
|
|
239464
242359
|
"tmp-promise": "^3.0.3",
|
|
239465
242360
|
typescript: "^5.7.2",
|
|
239466
242361
|
vitest: "^4.0.16",
|
|
242362
|
+
ws: "8.21.0",
|
|
239467
242363
|
yaml: "^2.8.2",
|
|
239468
242364
|
zod: "^4.3.5"
|
|
239469
242365
|
},
|
|
@@ -239678,6 +242574,22 @@ async function finalizeDeployment(deploymentId, sessionId, payload) {
|
|
|
239678
242574
|
}
|
|
239679
242575
|
return result.data;
|
|
239680
242576
|
}
|
|
242577
|
+
async function publishDeployment(gitHash) {
|
|
242578
|
+
const appClient = getAppClient();
|
|
242579
|
+
let response;
|
|
242580
|
+
try {
|
|
242581
|
+
response = await appClient.post(`deployments/${gitHash}/publish`, {
|
|
242582
|
+
timeout: 120000
|
|
242583
|
+
});
|
|
242584
|
+
} catch (error) {
|
|
242585
|
+
throw await ApiError.fromHttpError(error, "publishing deployment");
|
|
242586
|
+
}
|
|
242587
|
+
const result = PublishDeploymentResponseSchema.safeParse(await response.json());
|
|
242588
|
+
if (!result.success) {
|
|
242589
|
+
throw new SchemaValidationError("Invalid response from server", result.error);
|
|
242590
|
+
}
|
|
242591
|
+
return result.data;
|
|
242592
|
+
}
|
|
239681
242593
|
// src/core/site/config.ts
|
|
239682
242594
|
async function getSiteFilePaths(outputDir) {
|
|
239683
242595
|
return await globby("**/*", {
|
|
@@ -240261,11 +243173,6 @@ async function putPresignedBody(upload, body) {
|
|
|
240261
243173
|
|
|
240262
243174
|
// src/core/site/deployment.ts
|
|
240263
243175
|
var NO_ASSETS = { manifest: {}, filesByHash: new Map };
|
|
240264
|
-
var DEPLOYMENTS_API_ENV = "BASE44_DEPLOYMENTS_API";
|
|
240265
|
-
function deploymentsApiEnabled(env = process.env) {
|
|
240266
|
-
const value = env[DEPLOYMENTS_API_ENV];
|
|
240267
|
-
return value === "1" || value === "true";
|
|
240268
|
-
}
|
|
240269
243176
|
async function deployToDeployments(options) {
|
|
240270
243177
|
const { projectRoot, outputDir, gitHash, concurrency, progress } = options;
|
|
240271
243178
|
const worker = await resolveWorkerBuild(projectRoot, progress);
|
|
@@ -246871,7 +249778,7 @@ async function gitHead(projectRoot) {
|
|
|
246871
249778
|
}
|
|
246872
249779
|
}
|
|
246873
249780
|
// src/core/project/deploy.ts
|
|
246874
|
-
function hasResourcesToDeploy(projectData) {
|
|
249781
|
+
async function hasResourcesToDeploy(projectData) {
|
|
246875
249782
|
const {
|
|
246876
249783
|
project,
|
|
246877
249784
|
entities,
|
|
@@ -246882,7 +249789,7 @@ function hasResourcesToDeploy(projectData) {
|
|
|
246882
249789
|
connectors,
|
|
246883
249790
|
authConfig
|
|
246884
249791
|
} = projectData;
|
|
246885
|
-
const hasSite = Boolean(project.site?.outputDirectory);
|
|
249792
|
+
const hasSite = Boolean(project.site?.outputDirectory) || Boolean(await detectFullStackArtifact(project.root));
|
|
246886
249793
|
const hasEntities = entities.length > 0;
|
|
246887
249794
|
const hasFunctions = functions.length > 0;
|
|
246888
249795
|
const hasActors = actors.length > 0;
|
|
@@ -246941,12 +249848,59 @@ async function deployAll(projectData, options) {
|
|
|
246941
249848
|
await authConfigResource.push(authConfig);
|
|
246942
249849
|
const skipConnectorSync = connectors.length === 0 && hasWorkspaceApiKeyAuth();
|
|
246943
249850
|
const connectorResults = skipConnectorSync ? [] : (await pushConnectors(connectors)).results;
|
|
246944
|
-
|
|
246945
|
-
|
|
249851
|
+
const appUrl = await deployProjectSite(project, options);
|
|
249852
|
+
return appUrl ? { appUrl, connectorResults } : { connectorResults };
|
|
249853
|
+
}
|
|
249854
|
+
async function deployProjectSite(project, options) {
|
|
249855
|
+
const outputDirectory = project.site?.outputDirectory;
|
|
249856
|
+
const outputDir = outputDirectory ? resolve5(project.root, outputDirectory) : null;
|
|
249857
|
+
if (!outputDir) {
|
|
249858
|
+
if (!await detectFullStackArtifact(project.root)) {
|
|
249859
|
+
return;
|
|
249860
|
+
}
|
|
249861
|
+
const gitHash = await resolveGitHash(project.root, options?.gitHash);
|
|
249862
|
+
return shipCommit(project.root, null, gitHash, options);
|
|
249863
|
+
}
|
|
249864
|
+
const gitHash = await resolveGitHash(project.root, options?.gitHash).catch(() => {
|
|
249865
|
+
return;
|
|
249866
|
+
});
|
|
249867
|
+
if (!gitHash) {
|
|
249868
|
+
options?.onSiteProgress?.("No commit found for this build, so it was deployed without one. Commit your work to address deployments by it.");
|
|
246946
249869
|
const { appUrl } = await deploySite(outputDir);
|
|
246947
|
-
return
|
|
249870
|
+
return appUrl;
|
|
246948
249871
|
}
|
|
246949
|
-
return
|
|
249872
|
+
return shipCommit(project.root, outputDir, gitHash, options);
|
|
249873
|
+
}
|
|
249874
|
+
async function shipCommit(projectRoot, outputDir, gitHash, options) {
|
|
249875
|
+
await deployToDeployments({
|
|
249876
|
+
projectRoot,
|
|
249877
|
+
outputDir,
|
|
249878
|
+
gitHash,
|
|
249879
|
+
progress: {
|
|
249880
|
+
onWarning: (message) => options?.onSiteProgress?.(message),
|
|
249881
|
+
onAssets: ({ totalAssets, newAssets }) => options?.onSiteProgress?.(`Found ${totalAssets} static assets (${newAssets} new)`)
|
|
249882
|
+
}
|
|
249883
|
+
});
|
|
249884
|
+
if (options?.publish === false) {
|
|
249885
|
+
return;
|
|
249886
|
+
}
|
|
249887
|
+
try {
|
|
249888
|
+
const { appUrl } = await publishDeployment(gitHash);
|
|
249889
|
+
return appUrl;
|
|
249890
|
+
} catch (error) {
|
|
249891
|
+
if (!publishesFromBuilder(error)) {
|
|
249892
|
+
throw error;
|
|
249893
|
+
}
|
|
249894
|
+
options?.onSiteProgress?.("Site deployed. This app is published from the Base44 builder, so production was left where it was.");
|
|
249895
|
+
return;
|
|
249896
|
+
}
|
|
249897
|
+
}
|
|
249898
|
+
function publishesFromBuilder(error) {
|
|
249899
|
+
if (!(error instanceof ApiError)) {
|
|
249900
|
+
return false;
|
|
249901
|
+
}
|
|
249902
|
+
const body = error.responseBody;
|
|
249903
|
+
return body?.extra_data?.code === "app_publishes_from_builder";
|
|
246950
249904
|
}
|
|
246951
249905
|
// src/core/project/target.ts
|
|
246952
249906
|
import { dirname as dirname13, join as join19, resolve as resolve6 } from "node:path";
|
|
@@ -250078,7 +253032,7 @@ async function deployAction(ctx, options = {}) {
|
|
|
250078
253032
|
throw new InvalidInputError("--yes is required in non-interactive mode");
|
|
250079
253033
|
}
|
|
250080
253034
|
const projectData = await readProjectConfig(options.projectRoot);
|
|
250081
|
-
if (!hasResourcesToDeploy(projectData)) {
|
|
253035
|
+
if (!await hasResourcesToDeploy(projectData)) {
|
|
250082
253036
|
return {
|
|
250083
253037
|
outroMessage: "No resources found to deploy"
|
|
250084
253038
|
};
|
|
@@ -250137,6 +253091,11 @@ ${summaryLines.join(`
|
|
|
250137
253091
|
const functionTotal = functions.length;
|
|
250138
253092
|
let actorCompleted = 0;
|
|
250139
253093
|
const result = await deployAll(projectData, {
|
|
253094
|
+
gitHash: options.gitHash,
|
|
253095
|
+
publish: options.publish,
|
|
253096
|
+
onSiteProgress: (message) => {
|
|
253097
|
+
log.message(theme.styles.dim(message));
|
|
253098
|
+
},
|
|
250140
253099
|
onVisibilitySet: (level) => {
|
|
250141
253100
|
log.success(`App visibility set to ${level}`);
|
|
250142
253101
|
},
|
|
@@ -250172,7 +253131,7 @@ ${summaryLines.join(`
|
|
|
250172
253131
|
return { outroMessage: "App deployed successfully" };
|
|
250173
253132
|
}
|
|
250174
253133
|
function getDeployCommand3() {
|
|
250175
|
-
return new Base44Command("deploy").description("Deploy all project resources (entities, functions, actors, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").action(deployAction);
|
|
253134
|
+
return new Base44Command("deploy").description("Deploy all project resources (entities, functions, actors, agents, connectors, and site)").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").option("--no-publish", "Deploy the site without serving it in production yet").addOption(new Option2("--git-hash <hash>", "Commit the built site came from (defaults to the checkout's HEAD)").argParser(parseGitHash)).action(deployAction);
|
|
250176
253135
|
}
|
|
250177
253136
|
async function handleOAuthConnectors(connectorResults, isNonInteractive, options, log) {
|
|
250178
253137
|
const needsOAuth = filterPendingOAuth(connectorResults);
|
|
@@ -250193,6 +253152,12 @@ function printStripeResult(r, log) {
|
|
|
250193
253152
|
}
|
|
250194
253153
|
log.info(` Connectors dashboard: ${theme.colors.links(getConnectorsUrl())}`);
|
|
250195
253154
|
}
|
|
253155
|
+
function parseGitHash(value) {
|
|
253156
|
+
if (!isGitCommitHash(value)) {
|
|
253157
|
+
throw new InvalidArgumentError2("Expected a git commit hash (7-64 hex chars).");
|
|
253158
|
+
}
|
|
253159
|
+
return value;
|
|
253160
|
+
}
|
|
250196
253161
|
|
|
250197
253162
|
// src/cli/commands/project/app-id-options.ts
|
|
250198
253163
|
function readExplicitAppId(command) {
|
|
@@ -261311,7 +264276,7 @@ function shardOf(group, response, verdict, options) {
|
|
|
261311
264276
|
gzipBytes: verdict.gzipBytes,
|
|
261312
264277
|
...response.activation ? { activation: response.activation } : {},
|
|
261313
264278
|
wrapper: {
|
|
261314
|
-
secrets: response.activation ? `
|
|
264279
|
+
secrets: response.activation ? `blob_${response.activation}` : "binding",
|
|
261315
264280
|
postResponseTelemetry: options.postResponseTelemetry ?? false,
|
|
261316
264281
|
staticEgress: STATIC_EGRESS_ARTIFACT_MARKER
|
|
261317
264282
|
}
|
|
@@ -261394,8 +264359,9 @@ async function compilerInput(root, fn) {
|
|
|
261394
264359
|
for (const filePath of fn.filePaths) {
|
|
261395
264360
|
backendFiles[projectPath(root, filePath)] = await readTextFile(filePath);
|
|
261396
264361
|
}
|
|
261397
|
-
const
|
|
261398
|
-
|
|
264362
|
+
const source = await readTextFile(fn.entryPath);
|
|
264363
|
+
const { entry, files } = await cfwBundleInput(projectPath(root, fn.entryPath), source, backendFiles);
|
|
264364
|
+
return { input: { name: fn.name, entry, files }, source };
|
|
261399
264365
|
}
|
|
261400
264366
|
function describeFailure(failure) {
|
|
261401
264367
|
const where = failure.function ? `${failure.function}: ` : "";
|
|
@@ -261413,11 +264379,14 @@ async function compileBackendBundles(root, functionsDir) {
|
|
|
261413
264379
|
}
|
|
261414
264380
|
await requireCompilerRuntime();
|
|
261415
264381
|
const sorted = [...functions].sort((a, b) => a.name < b.name ? -1 : 1);
|
|
261416
|
-
const
|
|
264382
|
+
const compiled = await pMap(sorted, (fn) => compilerInput(root, fn), {
|
|
261417
264383
|
concurrency: 8
|
|
261418
264384
|
});
|
|
261419
|
-
const
|
|
261420
|
-
|
|
264385
|
+
const declared = new Map(compiled.map(({ input, source }) => [
|
|
264386
|
+
input.name,
|
|
264387
|
+
{ name: input.name, entry: input.entry, source }
|
|
264388
|
+
]));
|
|
264389
|
+
const built = await compileFunctionShards(compiled.map(({ input }) => input), SHARD_POLICY, COMPILE_MODES);
|
|
261421
264390
|
if (!built.ok) {
|
|
261422
264391
|
throw new InvalidInputError(`Backend functions failed to compile (${built.failures.length} error${built.failures.length === 1 ? "" : "s"}).`, { details: built.failures.map(describeFailure) });
|
|
261423
264392
|
}
|
|
@@ -261427,10 +264396,7 @@ async function compileBackendBundles(root, functionsDir) {
|
|
|
261427
264396
|
module,
|
|
261428
264397
|
size: module.byteLength,
|
|
261429
264398
|
digest: sha256(module),
|
|
261430
|
-
functions: shard.functions.map((name) => (
|
|
261431
|
-
name,
|
|
261432
|
-
entry: entries.get(name)
|
|
261433
|
-
})),
|
|
264399
|
+
functions: shard.functions.map((name) => declared.get(name)),
|
|
261434
264400
|
wrapper: shard.wrapper
|
|
261435
264401
|
};
|
|
261436
264402
|
});
|
|
@@ -262073,17 +265039,18 @@ async function deployAction2(ctx, options) {
|
|
|
262073
265039
|
return { outroMessage: "Deployment cancelled" };
|
|
262074
265040
|
}
|
|
262075
265041
|
}
|
|
262076
|
-
return
|
|
265042
|
+
return deployToDeploymentsApi(ctx, project, options);
|
|
262077
265043
|
}
|
|
262078
265044
|
async function deployToDeploymentsApi(ctx, project, options) {
|
|
262079
265045
|
const { runTask, log, jsonMode } = ctx;
|
|
262080
265046
|
const projectRoot = project.root;
|
|
265047
|
+
const outputDir = siteOutputDir(project);
|
|
262081
265048
|
const gitHash = await resolveGitHash(projectRoot, options.gitHash);
|
|
262082
265049
|
const progressLines = [];
|
|
262083
265050
|
const warnings = [];
|
|
262084
265051
|
const { deploymentId } = await runTask("Deploying site...", async (updateMessage) => await deployToDeployments({
|
|
262085
265052
|
projectRoot,
|
|
262086
|
-
outputDir
|
|
265053
|
+
outputDir,
|
|
262087
265054
|
gitHash,
|
|
262088
265055
|
concurrency: options.concurrency,
|
|
262089
265056
|
progress: {
|
|
@@ -262109,33 +265076,24 @@ async function deployToDeploymentsApi(ctx, project, options) {
|
|
|
262109
265076
|
for (const warning of warnings) {
|
|
262110
265077
|
log.warn(warning);
|
|
262111
265078
|
}
|
|
265079
|
+
const published = options.publish ? await runTask("Publishing site...", async () => await publishDeployment(gitHash), { successMessage: "Site published", errorMessage: "Publish failed" }) : undefined;
|
|
265080
|
+
if (published) {
|
|
265081
|
+
log.message(`${theme.styles.header("App URL")}: ${theme.colors.links(published.appUrl)}`);
|
|
265082
|
+
}
|
|
262112
265083
|
return {
|
|
262113
265084
|
outroMessage: `Deployment ${deploymentId} (commit ${gitHash.slice(0, 12)})`,
|
|
262114
|
-
stdout: jsonMode ? `${JSON.stringify({ deploymentId, gitHash }, null, 2)}
|
|
265085
|
+
stdout: jsonMode ? `${JSON.stringify({ deploymentId, gitHash, published: Boolean(published) }, null, 2)}
|
|
262115
265086
|
` : undefined
|
|
262116
265087
|
};
|
|
262117
265088
|
}
|
|
262118
|
-
async function deployTarball({ runTask }, project) {
|
|
262119
|
-
const outputDir = siteOutputDir(project);
|
|
262120
|
-
const { appUrl } = await runTask("Creating archive and deploying site...", async () => await deploySite(outputDir), {
|
|
262121
|
-
successMessage: "Site deployed successfully",
|
|
262122
|
-
errorMessage: "Deployment failed"
|
|
262123
|
-
});
|
|
262124
|
-
return { outroMessage: `Visit your site at: ${appUrl}` };
|
|
262125
|
-
}
|
|
262126
265089
|
function siteOutputDir(project) {
|
|
262127
265090
|
const { outputDirectory = DEFAULT_SITE.outputDirectory } = siteOrDefault(project);
|
|
262128
265091
|
return resolve15(project.root, outputDirectory);
|
|
262129
265092
|
}
|
|
262130
265093
|
function getSiteDeployCommand() {
|
|
262131
|
-
|
|
262132
|
-
if (deploymentsApiEnabled()) {
|
|
262133
|
-
command.addOption(new Option2("--git-hash <hash>", "Commit the build came from (defaults to the checkout's HEAD)").argParser(parseGitHash));
|
|
262134
|
-
command.addOption(new Option2("--concurrency <n>", "Parallel asset uploads").default(DEFAULT_UPLOAD_CONCURRENCY).argParser(parseConcurrency));
|
|
262135
|
-
}
|
|
262136
|
-
return command.action(deployAction2);
|
|
265094
|
+
return new Base44Command("deploy").description("Deploy built site files to Base44 hosting").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)").option("--publish", "Serve this build in production once it is deployed").addOption(new Option2("--git-hash <hash>", "Commit the build came from (defaults to the checkout's HEAD)").argParser(parseGitHash2)).addOption(new Option2("--concurrency <n>", "Parallel asset uploads").default(DEFAULT_UPLOAD_CONCURRENCY).argParser(parseConcurrency)).action(deployAction2);
|
|
262137
265095
|
}
|
|
262138
|
-
function
|
|
265096
|
+
function parseGitHash2(value) {
|
|
262139
265097
|
if (!isGitCommitHash(value)) {
|
|
262140
265098
|
throw new InvalidArgumentError2("Expected a git commit hash (7-64 hex chars).");
|
|
262141
265099
|
}
|
|
@@ -262189,12 +265147,17 @@ function createDevLogger(label, labelColor = theme.styles.dim) {
|
|
|
262189
265147
|
// src/cli/dev/dev-server/serve-runner.ts
|
|
262190
265148
|
import { spawn as spawn2 } from "node:child_process";
|
|
262191
265149
|
import process21 from "node:process";
|
|
265150
|
+
var ANSI_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
265151
|
+
var LOCAL_ORIGIN_PATTERN = /https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):(\d+)/g;
|
|
262192
265152
|
|
|
262193
265153
|
class ServeRunner {
|
|
262194
265154
|
command;
|
|
262195
265155
|
cwd;
|
|
262196
265156
|
env;
|
|
262197
265157
|
logger;
|
|
265158
|
+
onOrigin;
|
|
265159
|
+
ignorePort;
|
|
265160
|
+
originReported = false;
|
|
262198
265161
|
child;
|
|
262199
265162
|
stopping = false;
|
|
262200
265163
|
stopPromise;
|
|
@@ -262204,6 +265167,8 @@ class ServeRunner {
|
|
|
262204
265167
|
this.cwd = options.cwd;
|
|
262205
265168
|
this.env = options.env;
|
|
262206
265169
|
this.logger = options.logger;
|
|
265170
|
+
this.onOrigin = options.onOrigin;
|
|
265171
|
+
this.ignorePort = options.ignorePort;
|
|
262207
265172
|
}
|
|
262208
265173
|
start() {
|
|
262209
265174
|
if (this.child) {
|
|
@@ -262280,6 +265245,7 @@ class ServeRunner {
|
|
|
262280
265245
|
const lines = data.toString().trimEnd().split(`
|
|
262281
265246
|
`);
|
|
262282
265247
|
for (const line of lines) {
|
|
265248
|
+
this.reportOrigin(line);
|
|
262283
265249
|
if (type === "error") {
|
|
262284
265250
|
this.logger.error(line);
|
|
262285
265251
|
} else {
|
|
@@ -262287,6 +265253,20 @@ class ServeRunner {
|
|
|
262287
265253
|
}
|
|
262288
265254
|
}
|
|
262289
265255
|
}
|
|
265256
|
+
reportOrigin(line) {
|
|
265257
|
+
if (this.originReported || !this.onOrigin) {
|
|
265258
|
+
return;
|
|
265259
|
+
}
|
|
265260
|
+
const matches = line.replace(ANSI_PATTERN, "").matchAll(LOCAL_ORIGIN_PATTERN);
|
|
265261
|
+
for (const [origin, port] of matches) {
|
|
265262
|
+
if (Number(port) === this.ignorePort) {
|
|
265263
|
+
continue;
|
|
265264
|
+
}
|
|
265265
|
+
this.originReported = true;
|
|
265266
|
+
this.onOrigin(origin);
|
|
265267
|
+
return;
|
|
265268
|
+
}
|
|
265269
|
+
}
|
|
262290
265270
|
}
|
|
262291
265271
|
|
|
262292
265272
|
// src/cli/dev/serve-command-runner.ts
|
|
@@ -262294,7 +265274,9 @@ function createServeCommandRunner({
|
|
|
262294
265274
|
serveCommand,
|
|
262295
265275
|
projectRoot,
|
|
262296
265276
|
appId,
|
|
262297
|
-
appBaseUrl
|
|
265277
|
+
appBaseUrl,
|
|
265278
|
+
onOrigin,
|
|
265279
|
+
ignorePort
|
|
262298
265280
|
}) {
|
|
262299
265281
|
return new ServeRunner({
|
|
262300
265282
|
command: serveCommand,
|
|
@@ -262303,7 +265285,9 @@ function createServeCommandRunner({
|
|
|
262303
265285
|
VITE_BASE44_APP_ID: appId,
|
|
262304
265286
|
...appBaseUrl ? { VITE_BASE44_APP_BASE_URL: appBaseUrl } : {}
|
|
262305
265287
|
},
|
|
262306
|
-
logger: createDevLogger("frontend", theme.colors.base44Orange)
|
|
265288
|
+
logger: createDevLogger("frontend", theme.colors.base44Orange),
|
|
265289
|
+
onOrigin,
|
|
265290
|
+
ignorePort
|
|
262307
265291
|
});
|
|
262308
265292
|
}
|
|
262309
265293
|
|
|
@@ -263070,7 +266054,7 @@ async function getPorts(options) {
|
|
|
263070
266054
|
}
|
|
263071
266055
|
|
|
263072
266056
|
// src/cli/dev/dev-server/main.ts
|
|
263073
|
-
var
|
|
266057
|
+
var import_http_proxy_middleware3 = __toESM(require_dist2(), 1);
|
|
263074
266058
|
|
|
263075
266059
|
// ../../node_modules/tmp-promise/index.js
|
|
263076
266060
|
var { promisify: promisify12 } = __require("util");
|
|
@@ -263635,11 +266619,20 @@ async function createFunctionRuntime(functions, logger, denoWrapperPath) {
|
|
|
263635
266619
|
return new FunctionManager(functions, logger, denoWrapperPath);
|
|
263636
266620
|
}
|
|
263637
266621
|
|
|
263638
|
-
// src/cli/dev/dev-server/routes/
|
|
263639
|
-
var import_express = __toESM(require_express(), 1);
|
|
266622
|
+
// src/cli/dev/dev-server/routes/app-server.ts
|
|
263640
266623
|
var import_http_proxy_middleware = __toESM(require_dist2(), 1);
|
|
263641
266624
|
import { ServerResponse } from "node:http";
|
|
263642
266625
|
|
|
266626
|
+
// ../../node_modules/ws/wrapper.mjs
|
|
266627
|
+
var import_stream3 = __toESM(require_stream6(), 1);
|
|
266628
|
+
var import_extension = __toESM(require_extension(), 1);
|
|
266629
|
+
var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
|
|
266630
|
+
var import_receiver = __toESM(require_receiver(), 1);
|
|
266631
|
+
var import_sender = __toESM(require_sender(), 1);
|
|
266632
|
+
var import_subprotocol = __toESM(require_subprotocol(), 1);
|
|
266633
|
+
var import_websocket = __toESM(require_websocket(), 1);
|
|
266634
|
+
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
266635
|
+
|
|
263643
266636
|
// src/cli/dev/dev-server/auth/tokens.ts
|
|
263644
266637
|
var import_jsonwebtoken2 = __toESM(require_jsonwebtoken(), 1);
|
|
263645
266638
|
var LOCAL_DEV_SECRET = "LOCAL_DEV_SECRET";
|
|
@@ -263653,11 +266646,132 @@ var createServiceToken = () => createJwtToken(SERVICE_ROLE_EMAIL);
|
|
|
263653
266646
|
var createServiceAuthorizationHeader = () => `Bearer ${createServiceToken()}`;
|
|
263654
266647
|
var isServiceSubject = (subject) => subject === SERVICE_ROLE_EMAIL;
|
|
263655
266648
|
|
|
266649
|
+
// src/cli/dev/dev-server/routes/app-server.ts
|
|
266650
|
+
var PLATFORM_OWNED_SDK_HEADERS = [
|
|
266651
|
+
"base44-app-id",
|
|
266652
|
+
"base44-api-url",
|
|
266653
|
+
"base44-service-authorization",
|
|
266654
|
+
"base44-state",
|
|
266655
|
+
"base44-functions-version",
|
|
266656
|
+
"x-base44-app-url",
|
|
266657
|
+
"x-data-env"
|
|
266658
|
+
];
|
|
266659
|
+
var FORWARDED_HEADER = "base44-dev-forwarded";
|
|
266660
|
+
var PROXY_LOOP_MESSAGE = [
|
|
266661
|
+
"The app dev server sent this request back to the Base44 dev server instead of handling it.",
|
|
266662
|
+
"Its Vite proxy is forwarding all of /api; only /api/apps belongs to the backend.",
|
|
266663
|
+
"Update @base44/vite-plugin, or narrow the proxy in vite.config.js to /api/apps."
|
|
266664
|
+
].join(" ");
|
|
266665
|
+
function sdkHeaders(appId, host) {
|
|
266666
|
+
return {
|
|
266667
|
+
"Base44-App-Id": appId,
|
|
266668
|
+
"Base44-Api-Url": `http://${host}`,
|
|
266669
|
+
"Base44-Service-Authorization": createServiceAuthorizationHeader(),
|
|
266670
|
+
[FORWARDED_HEADER]: "1"
|
|
266671
|
+
};
|
|
266672
|
+
}
|
|
266673
|
+
function createAppServerProxy(target, logger) {
|
|
266674
|
+
let origin = "http://127.0.0.1:0";
|
|
266675
|
+
const proxy = import_http_proxy_middleware.createProxyMiddleware({
|
|
266676
|
+
router: () => origin,
|
|
266677
|
+
changeOrigin: true,
|
|
266678
|
+
on: {
|
|
266679
|
+
proxyReq: (proxyReq, req) => {
|
|
266680
|
+
for (const header of PLATFORM_OWNED_SDK_HEADERS) {
|
|
266681
|
+
proxyReq.removeHeader(header);
|
|
266682
|
+
}
|
|
266683
|
+
for (const [name, value] of Object.entries(sdkHeaders(target.appId, req.headers.host))) {
|
|
266684
|
+
proxyReq.setHeader(name, value);
|
|
266685
|
+
}
|
|
266686
|
+
},
|
|
266687
|
+
error: (err, _req, res) => {
|
|
266688
|
+
logger.error("App dev server proxy error:", err);
|
|
266689
|
+
if (res instanceof ServerResponse && !res.headersSent) {
|
|
266690
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
266691
|
+
res.end(JSON.stringify({
|
|
266692
|
+
error: "Failed to proxy request to the app dev server",
|
|
266693
|
+
details: err.message
|
|
266694
|
+
}));
|
|
266695
|
+
}
|
|
266696
|
+
}
|
|
266697
|
+
}
|
|
266698
|
+
});
|
|
266699
|
+
const resolveOrigin = async () => {
|
|
266700
|
+
origin = await target.waitForOrigin();
|
|
266701
|
+
};
|
|
266702
|
+
const middleware = async (req, res, next) => {
|
|
266703
|
+
if (req.headers[FORWARDED_HEADER]) {
|
|
266704
|
+
logger.error(PROXY_LOOP_MESSAGE);
|
|
266705
|
+
res.status(508).json({ error: PROXY_LOOP_MESSAGE });
|
|
266706
|
+
return;
|
|
266707
|
+
}
|
|
266708
|
+
try {
|
|
266709
|
+
await resolveOrigin();
|
|
266710
|
+
} catch (error) {
|
|
266711
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
266712
|
+
logger.error(message);
|
|
266713
|
+
res.status(502).json({ error: message });
|
|
266714
|
+
return;
|
|
266715
|
+
}
|
|
266716
|
+
await proxy(req, res, next);
|
|
266717
|
+
};
|
|
266718
|
+
const relay = new import_websocket_server.default({
|
|
266719
|
+
noServer: true,
|
|
266720
|
+
handleProtocols: (protocols) => [...protocols][0] ?? false
|
|
266721
|
+
});
|
|
266722
|
+
const upgrade = (req, socket, head) => {
|
|
266723
|
+
resolveOrigin().then(() => relay.handleUpgrade(req, socket, head, (client) => relayTo(client, req)), (error) => {
|
|
266724
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
266725
|
+
socket.destroy();
|
|
266726
|
+
});
|
|
266727
|
+
};
|
|
266728
|
+
const relayTo = (client, req) => {
|
|
266729
|
+
const forwarded = {};
|
|
266730
|
+
for (let i = 0;i < req.rawHeaders.length; i += 2) {
|
|
266731
|
+
const lower = req.rawHeaders[i].toLowerCase();
|
|
266732
|
+
if (lower === "host" || lower.startsWith("sec-websocket-") || lower === "upgrade" || lower === "connection" || PLATFORM_OWNED_SDK_HEADERS.includes(lower)) {
|
|
266733
|
+
continue;
|
|
266734
|
+
}
|
|
266735
|
+
forwarded[req.rawHeaders[i]] = req.rawHeaders[i + 1];
|
|
266736
|
+
}
|
|
266737
|
+
const upstream = new import_websocket.default(`${origin.replace(/^http/, "ws")}${req.url}`, client.protocol || undefined, {
|
|
266738
|
+
headers: {
|
|
266739
|
+
...forwarded,
|
|
266740
|
+
...sdkHeaders(target.appId, req.headers.host)
|
|
266741
|
+
}
|
|
266742
|
+
});
|
|
266743
|
+
const pending = [];
|
|
266744
|
+
client.on("message", (data, isBinary) => {
|
|
266745
|
+
if (upstream.readyState === import_websocket.default.OPEN) {
|
|
266746
|
+
upstream.send(data, { binary: isBinary });
|
|
266747
|
+
} else {
|
|
266748
|
+
pending.push({ data, isBinary });
|
|
266749
|
+
}
|
|
266750
|
+
});
|
|
266751
|
+
upstream.on("open", () => {
|
|
266752
|
+
for (const { data, isBinary } of pending.splice(0)) {
|
|
266753
|
+
upstream.send(data, { binary: isBinary });
|
|
266754
|
+
}
|
|
266755
|
+
});
|
|
266756
|
+
upstream.on("message", (data, isBinary) => client.send(data, { binary: isBinary }));
|
|
266757
|
+
client.on("close", () => upstream.close());
|
|
266758
|
+
upstream.on("close", () => client.close());
|
|
266759
|
+
upstream.on("error", (error) => {
|
|
266760
|
+
logger.error("App dev server websocket error:", error);
|
|
266761
|
+
client.close();
|
|
266762
|
+
});
|
|
266763
|
+
};
|
|
266764
|
+
return { middleware, upgrade };
|
|
266765
|
+
}
|
|
266766
|
+
|
|
263656
266767
|
// src/cli/dev/dev-server/routes/functions.ts
|
|
266768
|
+
var import_express = __toESM(require_express(), 1);
|
|
266769
|
+
var import_http_proxy_middleware2 = __toESM(require_dist2(), 1);
|
|
266770
|
+
import { ServerResponse as ServerResponse2 } from "node:http";
|
|
263657
266771
|
function createFunctionRouter(manager, logger) {
|
|
263658
266772
|
const router = import_express.Router({ mergeParams: true });
|
|
263659
266773
|
const portsByRequest = new WeakMap;
|
|
263660
|
-
const proxy =
|
|
266774
|
+
const proxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
263661
266775
|
router: (req) => `http://localhost:${portsByRequest.get(req)}`,
|
|
263662
266776
|
changeOrigin: true,
|
|
263663
266777
|
on: {
|
|
@@ -263671,7 +266785,7 @@ function createFunctionRouter(manager, logger) {
|
|
|
263671
266785
|
},
|
|
263672
266786
|
error: (err, _req, res) => {
|
|
263673
266787
|
logger.error("Function proxy error:", err);
|
|
263674
|
-
if (res instanceof
|
|
266788
|
+
if (res instanceof ServerResponse2 && !res.headersSent) {
|
|
263675
266789
|
res.writeHead(502, { "Content-Type": "application/json" });
|
|
263676
266790
|
res.end(JSON.stringify({
|
|
263677
266791
|
error: "Failed to proxy request to function",
|
|
@@ -264017,9 +267131,10 @@ var import_dist = __toESM(require_dist4(), 1);
|
|
|
264017
267131
|
var { Server, Namespace, Socket } = import_dist.default;
|
|
264018
267132
|
|
|
264019
267133
|
// src/cli/dev/dev-server/realtime.ts
|
|
267134
|
+
var REALTIME_PATH = "/ws-user-apps/socket.io/";
|
|
264020
267135
|
function createRealtimeServer(httpServer) {
|
|
264021
267136
|
const io = new Server(httpServer, {
|
|
264022
|
-
path:
|
|
267137
|
+
path: REALTIME_PATH,
|
|
264023
267138
|
cors: {
|
|
264024
267139
|
origin: /^http:\/\/localhost(:\d+)?$/,
|
|
264025
267140
|
credentials: true
|
|
@@ -266614,6 +269729,7 @@ class WatchBase44 extends EventEmitter4 {
|
|
|
266614
269729
|
// src/cli/dev/dev-server/main.ts
|
|
266615
269730
|
var DEFAULT_PORT = 4400;
|
|
266616
269731
|
var BASE44_APP_URL = "https://base44.app";
|
|
269732
|
+
var PLATFORM_PATH_PATTERN = /^\/api\/apps(\/|$)/;
|
|
266617
269733
|
async function createDevServer(options) {
|
|
266618
269734
|
const { port: userPort } = options;
|
|
266619
269735
|
const port = userPort ?? await getPorts({
|
|
@@ -266622,7 +269738,7 @@ async function createDevServer(options) {
|
|
|
266622
269738
|
const baseUrl = `http://localhost:${port}`;
|
|
266623
269739
|
const { functions, entities, project, siteUrl } = await options.loadResources();
|
|
266624
269740
|
const app = import_express6.default();
|
|
266625
|
-
const remoteProxy =
|
|
269741
|
+
const remoteProxy = import_http_proxy_middleware3.createProxyMiddleware({
|
|
266626
269742
|
target: BASE44_APP_URL,
|
|
266627
269743
|
changeOrigin: true
|
|
266628
269744
|
});
|
|
@@ -266684,7 +269800,11 @@ async function createDevServer(options) {
|
|
|
266684
269800
|
app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
|
|
266685
269801
|
const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
|
|
266686
269802
|
app.use("/api/apps/:appId/integrations/custom", customIntegrationRoutes);
|
|
269803
|
+
const appServerProxy = options.appServer ? createAppServerProxy(options.appServer, devLogger) : undefined;
|
|
266687
269804
|
app.use((req, res, next) => {
|
|
269805
|
+
if (appServerProxy && !PLATFORM_PATH_PATTERN.test(req.path)) {
|
|
269806
|
+
return appServerProxy.middleware(req, res, next);
|
|
269807
|
+
}
|
|
266688
269808
|
if (siteUrl && (req.path === "/login" || req.path.startsWith("/login/"))) {
|
|
266689
269809
|
const targetUrl = new URL(req.originalUrl, siteUrl);
|
|
266690
269810
|
devLogger.warn(`"${req.originalUrl}" requires hosted login, redirecting to ${targetUrl.toString()}`);
|
|
@@ -266709,6 +269829,13 @@ async function createDevServer(options) {
|
|
|
266709
269829
|
}
|
|
266710
269830
|
});
|
|
266711
269831
|
});
|
|
269832
|
+
if (appServerProxy) {
|
|
269833
|
+
server.on("upgrade", (req, socket, head) => {
|
|
269834
|
+
if (!req.url?.startsWith(REALTIME_PATH)) {
|
|
269835
|
+
appServerProxy.upgrade(req, socket, head);
|
|
269836
|
+
}
|
|
269837
|
+
});
|
|
269838
|
+
}
|
|
266712
269839
|
const io = createRealtimeServer(server);
|
|
266713
269840
|
emitEntityEvent = (appId, entityName, event) => {
|
|
266714
269841
|
broadcastEntityEvent(io, appId, entityName, event);
|
|
@@ -266782,9 +269909,24 @@ async function createDevServer(options) {
|
|
|
266782
269909
|
}
|
|
266783
269910
|
|
|
266784
269911
|
// src/cli/commands/dev.ts
|
|
269912
|
+
var APP_SERVER_START_TIMEOUT_MS = 120000;
|
|
266785
269913
|
function localServerUrl(port) {
|
|
266786
269914
|
return `http://localhost:${port}`;
|
|
266787
269915
|
}
|
|
269916
|
+
function createAppServerOrigin() {
|
|
269917
|
+
let report;
|
|
269918
|
+
const announced = new Promise((resolve) => {
|
|
269919
|
+
report = resolve;
|
|
269920
|
+
});
|
|
269921
|
+
const timedOut = new Promise((_, reject) => {
|
|
269922
|
+
const timer = setTimeout(() => reject(new Error("The app dev server did not print a local URL, so requests cannot be forwarded to it.")), APP_SERVER_START_TIMEOUT_MS);
|
|
269923
|
+
timer.unref();
|
|
269924
|
+
});
|
|
269925
|
+
return {
|
|
269926
|
+
waitForOrigin: () => Promise.race([announced, timedOut]),
|
|
269927
|
+
report
|
|
269928
|
+
};
|
|
269929
|
+
}
|
|
266788
269930
|
function validateDevOptions(command) {
|
|
266789
269931
|
const { appId } = command.optsWithGlobals();
|
|
266790
269932
|
if (appId !== undefined) {
|
|
@@ -266837,10 +269979,12 @@ async function localDevAction(ctx, app, options) {
|
|
|
266837
269979
|
const siteUrlPromise = getSiteUrl().catch(() => {
|
|
266838
269980
|
return;
|
|
266839
269981
|
});
|
|
269982
|
+
const appServerOrigin = createAppServerOrigin();
|
|
266840
269983
|
const backend = await createDevServer({
|
|
266841
269984
|
log: ctx.log,
|
|
266842
269985
|
port: options.port ? Number(options.port) : undefined,
|
|
266843
269986
|
denoWrapperPath: getDenoWrapperPath(),
|
|
269987
|
+
appServer: site ? { appId: app.id, waitForOrigin: appServerOrigin.waitForOrigin } : undefined,
|
|
266844
269988
|
loadResources: async () => {
|
|
266845
269989
|
const { functions, entities, project } = await readProjectConfig();
|
|
266846
269990
|
const siteUrl = await siteUrlPromise;
|
|
@@ -266852,11 +269996,13 @@ async function localDevAction(ctx, app, options) {
|
|
|
266852
269996
|
const runner = createServeCommandRunner({
|
|
266853
269997
|
...site,
|
|
266854
269998
|
appId: app.id,
|
|
266855
|
-
appBaseUrl: backendUrl
|
|
269999
|
+
appBaseUrl: backendUrl,
|
|
270000
|
+
onOrigin: appServerOrigin.report,
|
|
270001
|
+
ignorePort: backend.port
|
|
266856
270002
|
});
|
|
266857
270003
|
startServeCommand(runner, { url: backendUrl, shutdown: backend.shutdown });
|
|
266858
270004
|
}
|
|
266859
|
-
const outroMessage = site ?
|
|
270005
|
+
const outroMessage = site ? `Your app is available at ${theme.colors.links(backendUrl)}` : `Dev server is available at ${theme.colors.links(backendUrl)}`;
|
|
266860
270006
|
return { outroMessage };
|
|
266861
270007
|
}
|
|
266862
270008
|
async function devAction(ctx, options) {
|
|
@@ -271283,4 +274429,4 @@ export {
|
|
|
271283
274429
|
runCLI
|
|
271284
274430
|
};
|
|
271285
274431
|
|
|
271286
|
-
//# debugId=
|
|
274432
|
+
//# debugId=C5449F611EDCE78764756E2164756E21
|