@base44-preview/cli 0.2.2-pr.679.e8470cb → 0.2.3-pr.659.75c0aac
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 +3204 -522
- package/dist/cli/index.js.map +28 -16
- 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;
|
|
@@ -228838,7 +231721,7 @@ function normalizeBase44Env() {
|
|
|
228838
231721
|
loadProjectEnvFiles();
|
|
228839
231722
|
|
|
228840
231723
|
// src/cli/index.ts
|
|
228841
|
-
import { dirname as
|
|
231724
|
+
import { dirname as dirname30, join as join41 } from "node:path";
|
|
228842
231725
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
228843
231726
|
|
|
228844
231727
|
// ../../node_modules/@clack/core/dist/index.mjs
|
|
@@ -230795,8 +233678,7 @@ var TestOverridesSchema = object({
|
|
|
230795
233678
|
id: string2(),
|
|
230796
233679
|
projectRoot: string2()
|
|
230797
233680
|
}).optional(),
|
|
230798
|
-
latestVersion: string2().nullable().optional()
|
|
230799
|
-
claudeBin: string2().optional()
|
|
233681
|
+
latestVersion: string2().nullable().optional()
|
|
230800
233682
|
});
|
|
230801
233683
|
|
|
230802
233684
|
// src/core/config.ts
|
|
@@ -236978,9 +239860,16 @@ var BackendFunctionToolConfigSchema = object({
|
|
|
236978
239860
|
function_name: string2().min(1),
|
|
236979
239861
|
description: string2().default("agent backend function")
|
|
236980
239862
|
});
|
|
239863
|
+
var ServerRouteToolConfigSchema = object({
|
|
239864
|
+
tool_name: string2().regex(/^[A-Za-z0-9_-]{1,64}$/, "tool_name must be 1-64 letters, digits, '_' or '-'"),
|
|
239865
|
+
route_path: string2().trim().max(2000).regex(/^\/(?!\/)[A-Za-z0-9\-._~!$&'()*+,;=:@%/]*$/, "route_path must be an app-relative route like '/api/orders'"),
|
|
239866
|
+
method: _enum(["get", "post", "put", "patch", "delete"]).default("post"),
|
|
239867
|
+
description: string2().default("agent server route")
|
|
239868
|
+
});
|
|
236981
239869
|
var ToolConfigSchema = union([
|
|
236982
239870
|
EntityToolConfigSchema,
|
|
236983
|
-
BackendFunctionToolConfigSchema
|
|
239871
|
+
BackendFunctionToolConfigSchema,
|
|
239872
|
+
ServerRouteToolConfigSchema
|
|
236984
239873
|
]);
|
|
236985
239874
|
var MemoryConfigSchema = object({
|
|
236986
239875
|
enabled: boolean2().default(true),
|
|
@@ -239377,7 +242266,7 @@ import { join as join13 } from "node:path";
|
|
|
239377
242266
|
// package.json
|
|
239378
242267
|
var package_default = {
|
|
239379
242268
|
name: "base44",
|
|
239380
|
-
version: "0.2.
|
|
242269
|
+
version: "0.2.3",
|
|
239381
242270
|
description: "Base44 CLI - Unified interface for managing Base44 applications",
|
|
239382
242271
|
type: "module",
|
|
239383
242272
|
bin: {
|
|
@@ -239433,6 +242322,7 @@ var package_default = {
|
|
|
239433
242322
|
"@types/ms": "^2.1.0",
|
|
239434
242323
|
"@types/multer": "^2.0.0",
|
|
239435
242324
|
"@types/node": "^22.10.5",
|
|
242325
|
+
"@types/ws": "^8.18.1",
|
|
239436
242326
|
"@vercel/detect-agent": "^1.1.0",
|
|
239437
242327
|
chalk: "^5.6.2",
|
|
239438
242328
|
chokidar: "^5.0.0",
|
|
@@ -239468,6 +242358,7 @@ var package_default = {
|
|
|
239468
242358
|
"tmp-promise": "^3.0.3",
|
|
239469
242359
|
typescript: "^5.7.2",
|
|
239470
242360
|
vitest: "^4.0.16",
|
|
242361
|
+
ws: "8.21.0",
|
|
239471
242362
|
yaml: "^2.8.2",
|
|
239472
242363
|
zod: "^4.3.5"
|
|
239473
242364
|
},
|
|
@@ -246852,23 +249743,6 @@ var GIT_HASH_PATTERN = /^[a-fA-F0-9]{7,64}$/;
|
|
|
246852
249743
|
function isGitCommitHash(value) {
|
|
246853
249744
|
return GIT_HASH_PATTERN.test(value);
|
|
246854
249745
|
}
|
|
246855
|
-
async function readGitState(cwd) {
|
|
246856
|
-
const status = await execa("git", ["status", "--porcelain", "--branch"], {
|
|
246857
|
-
cwd,
|
|
246858
|
-
reject: false
|
|
246859
|
-
});
|
|
246860
|
-
if (status.exitCode !== 0)
|
|
246861
|
-
return;
|
|
246862
|
-
const [header = "", ...changes] = status.stdout.split(`
|
|
246863
|
-
`).filter(Boolean);
|
|
246864
|
-
const head = await execa("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
246865
|
-
cwd,
|
|
246866
|
-
reject: false
|
|
246867
|
-
});
|
|
246868
|
-
const branch = head.exitCode === 0 && head.stdout !== "HEAD" ? head.stdout : undefined;
|
|
246869
|
-
const offRemote = branch !== undefined && (!header.includes("...") || /\[(ahead|gone)/.test(header));
|
|
246870
|
-
return { branch, unpushed: changes.length > 0 || offRemote };
|
|
246871
|
-
}
|
|
246872
249746
|
|
|
246873
249747
|
// src/core/site/git-hash.ts
|
|
246874
249748
|
function workerBuildNeedsGitHashError() {
|
|
@@ -264919,12 +267793,17 @@ function createDevLogger(label, labelColor = theme.styles.dim) {
|
|
|
264919
267793
|
// src/cli/dev/dev-server/serve-runner.ts
|
|
264920
267794
|
import { spawn as spawn2 } from "node:child_process";
|
|
264921
267795
|
import process21 from "node:process";
|
|
267796
|
+
var ANSI_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
267797
|
+
var LOCAL_ORIGIN_PATTERN = /https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):(\d+)/g;
|
|
264922
267798
|
|
|
264923
267799
|
class ServeRunner {
|
|
264924
267800
|
command;
|
|
264925
267801
|
cwd;
|
|
264926
267802
|
env;
|
|
264927
267803
|
logger;
|
|
267804
|
+
onOrigin;
|
|
267805
|
+
ignorePort;
|
|
267806
|
+
originReported = false;
|
|
264928
267807
|
child;
|
|
264929
267808
|
stopping = false;
|
|
264930
267809
|
stopPromise;
|
|
@@ -264934,6 +267813,8 @@ class ServeRunner {
|
|
|
264934
267813
|
this.cwd = options.cwd;
|
|
264935
267814
|
this.env = options.env;
|
|
264936
267815
|
this.logger = options.logger;
|
|
267816
|
+
this.onOrigin = options.onOrigin;
|
|
267817
|
+
this.ignorePort = options.ignorePort;
|
|
264937
267818
|
}
|
|
264938
267819
|
start() {
|
|
264939
267820
|
if (this.child) {
|
|
@@ -265010,6 +267891,7 @@ class ServeRunner {
|
|
|
265010
267891
|
const lines = data.toString().trimEnd().split(`
|
|
265011
267892
|
`);
|
|
265012
267893
|
for (const line of lines) {
|
|
267894
|
+
this.reportOrigin(line);
|
|
265013
267895
|
if (type === "error") {
|
|
265014
267896
|
this.logger.error(line);
|
|
265015
267897
|
} else {
|
|
@@ -265017,6 +267899,20 @@ class ServeRunner {
|
|
|
265017
267899
|
}
|
|
265018
267900
|
}
|
|
265019
267901
|
}
|
|
267902
|
+
reportOrigin(line) {
|
|
267903
|
+
if (this.originReported || !this.onOrigin) {
|
|
267904
|
+
return;
|
|
267905
|
+
}
|
|
267906
|
+
const matches = line.replace(ANSI_PATTERN, "").matchAll(LOCAL_ORIGIN_PATTERN);
|
|
267907
|
+
for (const [origin, port] of matches) {
|
|
267908
|
+
if (Number(port) === this.ignorePort) {
|
|
267909
|
+
continue;
|
|
267910
|
+
}
|
|
267911
|
+
this.originReported = true;
|
|
267912
|
+
this.onOrigin(origin);
|
|
267913
|
+
return;
|
|
267914
|
+
}
|
|
267915
|
+
}
|
|
265020
267916
|
}
|
|
265021
267917
|
|
|
265022
267918
|
// src/cli/dev/serve-command-runner.ts
|
|
@@ -265024,7 +267920,9 @@ function createServeCommandRunner({
|
|
|
265024
267920
|
serveCommand,
|
|
265025
267921
|
projectRoot,
|
|
265026
267922
|
appId,
|
|
265027
|
-
appBaseUrl
|
|
267923
|
+
appBaseUrl,
|
|
267924
|
+
onOrigin,
|
|
267925
|
+
ignorePort
|
|
265028
267926
|
}) {
|
|
265029
267927
|
return new ServeRunner({
|
|
265030
267928
|
command: serveCommand,
|
|
@@ -265033,7 +267931,9 @@ function createServeCommandRunner({
|
|
|
265033
267931
|
VITE_BASE44_APP_ID: appId,
|
|
265034
267932
|
...appBaseUrl ? { VITE_BASE44_APP_BASE_URL: appBaseUrl } : {}
|
|
265035
267933
|
},
|
|
265036
|
-
logger: createDevLogger("frontend", theme.colors.base44Orange)
|
|
267934
|
+
logger: createDevLogger("frontend", theme.colors.base44Orange),
|
|
267935
|
+
onOrigin,
|
|
267936
|
+
ignorePort
|
|
265037
267937
|
});
|
|
265038
267938
|
}
|
|
265039
267939
|
|
|
@@ -265800,7 +268700,7 @@ async function getPorts(options) {
|
|
|
265800
268700
|
}
|
|
265801
268701
|
|
|
265802
268702
|
// src/cli/dev/dev-server/main.ts
|
|
265803
|
-
var
|
|
268703
|
+
var import_http_proxy_middleware3 = __toESM(require_dist2(), 1);
|
|
265804
268704
|
|
|
265805
268705
|
// ../../node_modules/tmp-promise/index.js
|
|
265806
268706
|
var { promisify: promisify12 } = __require("util");
|
|
@@ -266365,11 +269265,20 @@ async function createFunctionRuntime(functions, logger, denoWrapperPath) {
|
|
|
266365
269265
|
return new FunctionManager(functions, logger, denoWrapperPath);
|
|
266366
269266
|
}
|
|
266367
269267
|
|
|
266368
|
-
// src/cli/dev/dev-server/routes/
|
|
266369
|
-
var import_express = __toESM(require_express(), 1);
|
|
269268
|
+
// src/cli/dev/dev-server/routes/app-server.ts
|
|
266370
269269
|
var import_http_proxy_middleware = __toESM(require_dist2(), 1);
|
|
266371
269270
|
import { ServerResponse } from "node:http";
|
|
266372
269271
|
|
|
269272
|
+
// ../../node_modules/ws/wrapper.mjs
|
|
269273
|
+
var import_stream3 = __toESM(require_stream6(), 1);
|
|
269274
|
+
var import_extension = __toESM(require_extension(), 1);
|
|
269275
|
+
var import_permessage_deflate = __toESM(require_permessage_deflate(), 1);
|
|
269276
|
+
var import_receiver = __toESM(require_receiver(), 1);
|
|
269277
|
+
var import_sender = __toESM(require_sender(), 1);
|
|
269278
|
+
var import_subprotocol = __toESM(require_subprotocol(), 1);
|
|
269279
|
+
var import_websocket = __toESM(require_websocket(), 1);
|
|
269280
|
+
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
269281
|
+
|
|
266373
269282
|
// src/cli/dev/dev-server/auth/tokens.ts
|
|
266374
269283
|
var import_jsonwebtoken2 = __toESM(require_jsonwebtoken(), 1);
|
|
266375
269284
|
var LOCAL_DEV_SECRET = "LOCAL_DEV_SECRET";
|
|
@@ -266383,11 +269292,132 @@ var createServiceToken = () => createJwtToken(SERVICE_ROLE_EMAIL);
|
|
|
266383
269292
|
var createServiceAuthorizationHeader = () => `Bearer ${createServiceToken()}`;
|
|
266384
269293
|
var isServiceSubject = (subject) => subject === SERVICE_ROLE_EMAIL;
|
|
266385
269294
|
|
|
269295
|
+
// src/cli/dev/dev-server/routes/app-server.ts
|
|
269296
|
+
var PLATFORM_OWNED_SDK_HEADERS = [
|
|
269297
|
+
"base44-app-id",
|
|
269298
|
+
"base44-api-url",
|
|
269299
|
+
"base44-service-authorization",
|
|
269300
|
+
"base44-state",
|
|
269301
|
+
"base44-functions-version",
|
|
269302
|
+
"x-base44-app-url",
|
|
269303
|
+
"x-data-env"
|
|
269304
|
+
];
|
|
269305
|
+
var FORWARDED_HEADER = "base44-dev-forwarded";
|
|
269306
|
+
var PROXY_LOOP_MESSAGE = [
|
|
269307
|
+
"The app dev server sent this request back to the Base44 dev server instead of handling it.",
|
|
269308
|
+
"Its Vite proxy is forwarding all of /api; only /api/apps and /api/app-logs belong to the backend.",
|
|
269309
|
+
"Update @base44/vite-plugin, or narrow the proxy in vite.config.js to those paths."
|
|
269310
|
+
].join(" ");
|
|
269311
|
+
function sdkHeaders(appId, host) {
|
|
269312
|
+
return {
|
|
269313
|
+
"Base44-App-Id": appId,
|
|
269314
|
+
"Base44-Api-Url": `http://${host}`,
|
|
269315
|
+
"Base44-Service-Authorization": createServiceAuthorizationHeader(),
|
|
269316
|
+
[FORWARDED_HEADER]: "1"
|
|
269317
|
+
};
|
|
269318
|
+
}
|
|
269319
|
+
function createAppServerProxy(target, logger) {
|
|
269320
|
+
let origin = "http://127.0.0.1:0";
|
|
269321
|
+
const proxy = import_http_proxy_middleware.createProxyMiddleware({
|
|
269322
|
+
router: () => origin,
|
|
269323
|
+
changeOrigin: true,
|
|
269324
|
+
on: {
|
|
269325
|
+
proxyReq: (proxyReq, req) => {
|
|
269326
|
+
for (const header of PLATFORM_OWNED_SDK_HEADERS) {
|
|
269327
|
+
proxyReq.removeHeader(header);
|
|
269328
|
+
}
|
|
269329
|
+
for (const [name, value] of Object.entries(sdkHeaders(target.appId, req.headers.host))) {
|
|
269330
|
+
proxyReq.setHeader(name, value);
|
|
269331
|
+
}
|
|
269332
|
+
},
|
|
269333
|
+
error: (err, _req, res) => {
|
|
269334
|
+
logger.error("App dev server proxy error:", err);
|
|
269335
|
+
if (res instanceof ServerResponse && !res.headersSent) {
|
|
269336
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
269337
|
+
res.end(JSON.stringify({
|
|
269338
|
+
error: "Failed to proxy request to the app dev server",
|
|
269339
|
+
details: err.message
|
|
269340
|
+
}));
|
|
269341
|
+
}
|
|
269342
|
+
}
|
|
269343
|
+
}
|
|
269344
|
+
});
|
|
269345
|
+
const resolveOrigin = async () => {
|
|
269346
|
+
origin = await target.waitForOrigin();
|
|
269347
|
+
};
|
|
269348
|
+
const middleware = async (req, res, next) => {
|
|
269349
|
+
if (req.headers[FORWARDED_HEADER]) {
|
|
269350
|
+
logger.error(PROXY_LOOP_MESSAGE);
|
|
269351
|
+
res.status(508).json({ error: PROXY_LOOP_MESSAGE });
|
|
269352
|
+
return;
|
|
269353
|
+
}
|
|
269354
|
+
try {
|
|
269355
|
+
await resolveOrigin();
|
|
269356
|
+
} catch (error) {
|
|
269357
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
269358
|
+
logger.error(message);
|
|
269359
|
+
res.status(502).json({ error: message });
|
|
269360
|
+
return;
|
|
269361
|
+
}
|
|
269362
|
+
await proxy(req, res, next);
|
|
269363
|
+
};
|
|
269364
|
+
const relay = new import_websocket_server.default({
|
|
269365
|
+
noServer: true,
|
|
269366
|
+
handleProtocols: (protocols) => [...protocols][0] ?? false
|
|
269367
|
+
});
|
|
269368
|
+
const upgrade = (req, socket, head) => {
|
|
269369
|
+
resolveOrigin().then(() => relay.handleUpgrade(req, socket, head, (client) => relayTo(client, req)), (error) => {
|
|
269370
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
269371
|
+
socket.destroy();
|
|
269372
|
+
});
|
|
269373
|
+
};
|
|
269374
|
+
const relayTo = (client, req) => {
|
|
269375
|
+
const forwarded = {};
|
|
269376
|
+
for (let i = 0;i < req.rawHeaders.length; i += 2) {
|
|
269377
|
+
const lower = req.rawHeaders[i].toLowerCase();
|
|
269378
|
+
if (lower === "host" || lower.startsWith("sec-websocket-") || lower === "upgrade" || lower === "connection" || PLATFORM_OWNED_SDK_HEADERS.includes(lower)) {
|
|
269379
|
+
continue;
|
|
269380
|
+
}
|
|
269381
|
+
forwarded[req.rawHeaders[i]] = req.rawHeaders[i + 1];
|
|
269382
|
+
}
|
|
269383
|
+
const upstream = new import_websocket.default(`${origin.replace(/^http/, "ws")}${req.url}`, client.protocol || undefined, {
|
|
269384
|
+
headers: {
|
|
269385
|
+
...forwarded,
|
|
269386
|
+
...sdkHeaders(target.appId, req.headers.host)
|
|
269387
|
+
}
|
|
269388
|
+
});
|
|
269389
|
+
const pending = [];
|
|
269390
|
+
client.on("message", (data, isBinary) => {
|
|
269391
|
+
if (upstream.readyState === import_websocket.default.OPEN) {
|
|
269392
|
+
upstream.send(data, { binary: isBinary });
|
|
269393
|
+
} else {
|
|
269394
|
+
pending.push({ data, isBinary });
|
|
269395
|
+
}
|
|
269396
|
+
});
|
|
269397
|
+
upstream.on("open", () => {
|
|
269398
|
+
for (const { data, isBinary } of pending.splice(0)) {
|
|
269399
|
+
upstream.send(data, { binary: isBinary });
|
|
269400
|
+
}
|
|
269401
|
+
});
|
|
269402
|
+
upstream.on("message", (data, isBinary) => client.send(data, { binary: isBinary }));
|
|
269403
|
+
client.on("close", () => upstream.close());
|
|
269404
|
+
upstream.on("close", () => client.close());
|
|
269405
|
+
upstream.on("error", (error) => {
|
|
269406
|
+
logger.error("App dev server websocket error:", error);
|
|
269407
|
+
client.close();
|
|
269408
|
+
});
|
|
269409
|
+
};
|
|
269410
|
+
return { middleware, upgrade };
|
|
269411
|
+
}
|
|
269412
|
+
|
|
266386
269413
|
// src/cli/dev/dev-server/routes/functions.ts
|
|
269414
|
+
var import_express = __toESM(require_express(), 1);
|
|
269415
|
+
var import_http_proxy_middleware2 = __toESM(require_dist2(), 1);
|
|
269416
|
+
import { ServerResponse as ServerResponse2 } from "node:http";
|
|
266387
269417
|
function createFunctionRouter(manager, logger) {
|
|
266388
269418
|
const router = import_express.Router({ mergeParams: true });
|
|
266389
269419
|
const portsByRequest = new WeakMap;
|
|
266390
|
-
const proxy =
|
|
269420
|
+
const proxy = import_http_proxy_middleware2.createProxyMiddleware({
|
|
266391
269421
|
router: (req) => `http://localhost:${portsByRequest.get(req)}`,
|
|
266392
269422
|
changeOrigin: true,
|
|
266393
269423
|
on: {
|
|
@@ -266401,7 +269431,7 @@ function createFunctionRouter(manager, logger) {
|
|
|
266401
269431
|
},
|
|
266402
269432
|
error: (err, _req, res) => {
|
|
266403
269433
|
logger.error("Function proxy error:", err);
|
|
266404
|
-
if (res instanceof
|
|
269434
|
+
if (res instanceof ServerResponse2 && !res.headersSent) {
|
|
266405
269435
|
res.writeHead(502, { "Content-Type": "application/json" });
|
|
266406
269436
|
res.end(JSON.stringify({
|
|
266407
269437
|
error: "Failed to proxy request to function",
|
|
@@ -266747,9 +269777,10 @@ var import_dist = __toESM(require_dist4(), 1);
|
|
|
266747
269777
|
var { Server, Namespace, Socket } = import_dist.default;
|
|
266748
269778
|
|
|
266749
269779
|
// src/cli/dev/dev-server/realtime.ts
|
|
269780
|
+
var REALTIME_PATH = "/ws-user-apps/socket.io/";
|
|
266750
269781
|
function createRealtimeServer(httpServer) {
|
|
266751
269782
|
const io = new Server(httpServer, {
|
|
266752
|
-
path:
|
|
269783
|
+
path: REALTIME_PATH,
|
|
266753
269784
|
cors: {
|
|
266754
269785
|
origin: /^http:\/\/localhost(:\d+)?$/,
|
|
266755
269786
|
credentials: true
|
|
@@ -269344,6 +272375,7 @@ class WatchBase44 extends EventEmitter4 {
|
|
|
269344
272375
|
// src/cli/dev/dev-server/main.ts
|
|
269345
272376
|
var DEFAULT_PORT = 4400;
|
|
269346
272377
|
var BASE44_APP_URL = "https://base44.app";
|
|
272378
|
+
var PLATFORM_PATH_PATTERN = /^\/api\/(apps|app-logs)(\/|$)/;
|
|
269347
272379
|
async function createDevServer(options) {
|
|
269348
272380
|
const { port: userPort } = options;
|
|
269349
272381
|
const port = userPort ?? await getPorts({
|
|
@@ -269352,7 +272384,7 @@ async function createDevServer(options) {
|
|
|
269352
272384
|
const baseUrl = `http://localhost:${port}`;
|
|
269353
272385
|
const { functions, entities, project, siteUrl } = await options.loadResources();
|
|
269354
272386
|
const app = import_express6.default();
|
|
269355
|
-
const remoteProxy =
|
|
272387
|
+
const remoteProxy = import_http_proxy_middleware3.createProxyMiddleware({
|
|
269356
272388
|
target: BASE44_APP_URL,
|
|
269357
272389
|
changeOrigin: true
|
|
269358
272390
|
});
|
|
@@ -269414,7 +272446,11 @@ async function createDevServer(options) {
|
|
|
269414
272446
|
app.use("/api/apps/:appId/integration-endpoints", integrationRoutes);
|
|
269415
272447
|
const customIntegrationRoutes = createCustomIntegrationRoutes(remoteProxy, devLogger);
|
|
269416
272448
|
app.use("/api/apps/:appId/integrations/custom", customIntegrationRoutes);
|
|
272449
|
+
const appServerProxy = options.appServer ? createAppServerProxy(options.appServer, devLogger) : undefined;
|
|
269417
272450
|
app.use((req, res, next) => {
|
|
272451
|
+
if (appServerProxy && !PLATFORM_PATH_PATTERN.test(req.path)) {
|
|
272452
|
+
return appServerProxy.middleware(req, res, next);
|
|
272453
|
+
}
|
|
269418
272454
|
if (siteUrl && (req.path === "/login" || req.path.startsWith("/login/"))) {
|
|
269419
272455
|
const targetUrl = new URL(req.originalUrl, siteUrl);
|
|
269420
272456
|
devLogger.warn(`"${req.originalUrl}" requires hosted login, redirecting to ${targetUrl.toString()}`);
|
|
@@ -269439,6 +272475,13 @@ async function createDevServer(options) {
|
|
|
269439
272475
|
}
|
|
269440
272476
|
});
|
|
269441
272477
|
});
|
|
272478
|
+
if (appServerProxy) {
|
|
272479
|
+
server.on("upgrade", (req, socket, head) => {
|
|
272480
|
+
if (!req.url?.startsWith(REALTIME_PATH)) {
|
|
272481
|
+
appServerProxy.upgrade(req, socket, head);
|
|
272482
|
+
}
|
|
272483
|
+
});
|
|
272484
|
+
}
|
|
269442
272485
|
const io = createRealtimeServer(server);
|
|
269443
272486
|
emitEntityEvent = (appId, entityName, event) => {
|
|
269444
272487
|
broadcastEntityEvent(io, appId, entityName, event);
|
|
@@ -269512,9 +272555,24 @@ async function createDevServer(options) {
|
|
|
269512
272555
|
}
|
|
269513
272556
|
|
|
269514
272557
|
// src/cli/commands/dev.ts
|
|
272558
|
+
var APP_SERVER_START_TIMEOUT_MS = 120000;
|
|
269515
272559
|
function localServerUrl(port) {
|
|
269516
272560
|
return `http://localhost:${port}`;
|
|
269517
272561
|
}
|
|
272562
|
+
function createAppServerOrigin() {
|
|
272563
|
+
let report;
|
|
272564
|
+
const announced = new Promise((resolve) => {
|
|
272565
|
+
report = resolve;
|
|
272566
|
+
});
|
|
272567
|
+
const timedOut = new Promise((_, reject) => {
|
|
272568
|
+
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);
|
|
272569
|
+
timer.unref();
|
|
272570
|
+
});
|
|
272571
|
+
return {
|
|
272572
|
+
waitForOrigin: () => Promise.race([announced, timedOut]),
|
|
272573
|
+
report
|
|
272574
|
+
};
|
|
272575
|
+
}
|
|
269518
272576
|
function validateDevOptions(command) {
|
|
269519
272577
|
const { appId } = command.optsWithGlobals();
|
|
269520
272578
|
if (appId !== undefined) {
|
|
@@ -269567,10 +272625,12 @@ async function localDevAction(ctx, app, options) {
|
|
|
269567
272625
|
const siteUrlPromise = getSiteUrl().catch(() => {
|
|
269568
272626
|
return;
|
|
269569
272627
|
});
|
|
272628
|
+
const appServerOrigin = createAppServerOrigin();
|
|
269570
272629
|
const backend = await createDevServer({
|
|
269571
272630
|
log: ctx.log,
|
|
269572
272631
|
port: options.port ? Number(options.port) : undefined,
|
|
269573
272632
|
denoWrapperPath: getDenoWrapperPath(),
|
|
272633
|
+
appServer: site ? { appId: app.id, waitForOrigin: appServerOrigin.waitForOrigin } : undefined,
|
|
269574
272634
|
loadResources: async () => {
|
|
269575
272635
|
const { functions, entities, project } = await readProjectConfig();
|
|
269576
272636
|
const siteUrl = await siteUrlPromise;
|
|
@@ -269582,11 +272642,13 @@ async function localDevAction(ctx, app, options) {
|
|
|
269582
272642
|
const runner = createServeCommandRunner({
|
|
269583
272643
|
...site,
|
|
269584
272644
|
appId: app.id,
|
|
269585
|
-
appBaseUrl: backendUrl
|
|
272645
|
+
appBaseUrl: backendUrl,
|
|
272646
|
+
onOrigin: appServerOrigin.report,
|
|
272647
|
+
ignorePort: backend.port
|
|
269586
272648
|
});
|
|
269587
272649
|
startServeCommand(runner, { url: backendUrl, shutdown: backend.shutdown });
|
|
269588
272650
|
}
|
|
269589
|
-
const outroMessage = site ?
|
|
272651
|
+
const outroMessage = site ? `Your app is available at ${theme.colors.links(backendUrl)}` : `Dev server is available at ${theme.colors.links(backendUrl)}`;
|
|
269590
272652
|
return { outroMessage };
|
|
269591
272653
|
}
|
|
269592
272654
|
async function devAction(ctx, options) {
|
|
@@ -269804,385 +272866,6 @@ Examples:
|
|
|
269804
272866
|
$ echo "const all = await base44.entities.Task.list()" | base44 exec --privileged`).action(execAction);
|
|
269805
272867
|
}
|
|
269806
272868
|
|
|
269807
|
-
// src/cli/commands/import.ts
|
|
269808
|
-
var import_ms2 = __toESM(require_ms(), 1);
|
|
269809
|
-
|
|
269810
|
-
// src/core/session-import/api.ts
|
|
269811
|
-
var MAX_SESSION_BYTES = 25 * 1024 * 1024;
|
|
269812
|
-
var SessionImportResponseSchema = object({
|
|
269813
|
-
branch_id: string2(),
|
|
269814
|
-
branch_name: string2(),
|
|
269815
|
-
source: _enum(["claude_code", "codex"]),
|
|
269816
|
-
turn_count: number2(),
|
|
269817
|
-
branch_url: string2()
|
|
269818
|
-
}).transform((data) => ({
|
|
269819
|
-
branchId: data.branch_id,
|
|
269820
|
-
branchName: data.branch_name,
|
|
269821
|
-
source: data.source,
|
|
269822
|
-
turnCount: data.turn_count,
|
|
269823
|
-
branchUrl: data.branch_url
|
|
269824
|
-
}));
|
|
269825
|
-
var ErrorEnvelopeSchema = object({
|
|
269826
|
-
error: object({ code: string2().optional() })
|
|
269827
|
-
});
|
|
269828
|
-
var NETWORK_BLOCKED = "claude.ai is blocking Base44. In this session's environment settings, open Network access, add `app.base44.com` and `base44.app` to Allowed domains, save, and try again.";
|
|
269829
|
-
function messageFor(status, code, viaToken) {
|
|
269830
|
-
if (status === 401 && viaToken) {
|
|
269831
|
-
return "This import key expired or was already used. In Base Code, open Import session and copy a new prompt.";
|
|
269832
|
-
}
|
|
269833
|
-
if (status === 403) {
|
|
269834
|
-
return "You don't have edit access to this app, or this key was made for a different app.";
|
|
269835
|
-
}
|
|
269836
|
-
if (status === 404)
|
|
269837
|
-
return "Session import isn't available for this app.";
|
|
269838
|
-
if (status === 413)
|
|
269839
|
-
return "This session is over 25 MB and can't be imported.";
|
|
269840
|
-
if (code === "unsupported_file") {
|
|
269841
|
-
return "That file isn't a Claude Code or Codex session.";
|
|
269842
|
-
}
|
|
269843
|
-
if (code === "repository_mismatch") {
|
|
269844
|
-
return "This session is from a different repository than the app.";
|
|
269845
|
-
}
|
|
269846
|
-
if (status === 429)
|
|
269847
|
-
return "Too many imports. Wait a minute and try again.";
|
|
269848
|
-
return;
|
|
269849
|
-
}
|
|
269850
|
-
async function toImportError(error, viaToken) {
|
|
269851
|
-
if (!(error instanceof HTTPError)) {
|
|
269852
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
269853
|
-
return new ApiError(process.env.CLAUDE_CODE_REMOTE ? NETWORK_BLOCKED : `Couldn't reach Base44: ${reason}`, { hints: [] });
|
|
269854
|
-
}
|
|
269855
|
-
const { status } = error.response;
|
|
269856
|
-
const fallback = await ApiError.fromHttpError(error, "importing session");
|
|
269857
|
-
const envelope = ErrorEnvelopeSchema.safeParse(fallback.responseBody);
|
|
269858
|
-
const code = envelope.success ? envelope.data.error.code : undefined;
|
|
269859
|
-
const blocked = process.env.CLAUDE_CODE_REMOTE && status === 403 && typeof fallback.responseBody !== "object";
|
|
269860
|
-
const known = blocked ? NETWORK_BLOCKED : messageFor(status, code, viaToken);
|
|
269861
|
-
return new ApiError(known ?? fallback.message, {
|
|
269862
|
-
statusCode: status,
|
|
269863
|
-
requestUrl: error.request.url,
|
|
269864
|
-
requestMethod: error.request.method,
|
|
269865
|
-
requestId: fallback.requestId,
|
|
269866
|
-
hints: known ? [] : fallback.hints
|
|
269867
|
-
});
|
|
269868
|
-
}
|
|
269869
|
-
async function uploadSession(appId, content, { token, sourceBranch } = {}) {
|
|
269870
|
-
const form = new FormData;
|
|
269871
|
-
form.append("file", new Blob([content]), "session.jsonl");
|
|
269872
|
-
if (sourceBranch)
|
|
269873
|
-
form.append("source_branch", sourceBranch);
|
|
269874
|
-
let response;
|
|
269875
|
-
try {
|
|
269876
|
-
response = token ? await distribution_default.post(new URL(`/api/apps/${appId}/imported/session-imports`, getBase44ApiUrl()), {
|
|
269877
|
-
body: form,
|
|
269878
|
-
headers: {
|
|
269879
|
-
Authorization: `Bearer ${token}`,
|
|
269880
|
-
"User-Agent": "Base44 CLI"
|
|
269881
|
-
},
|
|
269882
|
-
timeout: 180000
|
|
269883
|
-
}) : await getAppClient().post("imported/session-imports", {
|
|
269884
|
-
body: form,
|
|
269885
|
-
timeout: 180000
|
|
269886
|
-
});
|
|
269887
|
-
} catch (error) {
|
|
269888
|
-
throw await toImportError(error, Boolean(token));
|
|
269889
|
-
}
|
|
269890
|
-
const result = SessionImportResponseSchema.safeParse(await response.json());
|
|
269891
|
-
if (!result.success) {
|
|
269892
|
-
throw new SchemaValidationError("Invalid session import response from server", result.error);
|
|
269893
|
-
}
|
|
269894
|
-
return result.data;
|
|
269895
|
-
}
|
|
269896
|
-
|
|
269897
|
-
// src/core/session-import/sessions.ts
|
|
269898
|
-
import { createReadStream as createReadStream3 } from "node:fs";
|
|
269899
|
-
import { realpath as realpath2, rm as rm5, stat as stat8 } from "node:fs/promises";
|
|
269900
|
-
import { homedir as homedir5 } from "node:os";
|
|
269901
|
-
import { dirname as dirname29, join as join41 } from "node:path";
|
|
269902
|
-
import { createInterface as createInterface2 } from "node:readline";
|
|
269903
|
-
var claudeDir = () => process.env.CLAUDE_CONFIG_DIR || join41(homedir5(), ".claude");
|
|
269904
|
-
var codexDir = () => process.env.CODEX_HOME || join41(homedir5(), ".codex");
|
|
269905
|
-
async function scanLines(path, pick, maxLines = Number.POSITIVE_INFINITY) {
|
|
269906
|
-
const lines = createInterface2({ input: createReadStream3(path) });
|
|
269907
|
-
let count = 0;
|
|
269908
|
-
try {
|
|
269909
|
-
for await (const line of lines) {
|
|
269910
|
-
if (++count > maxLines)
|
|
269911
|
-
return;
|
|
269912
|
-
try {
|
|
269913
|
-
const found = pick(JSON.parse(line));
|
|
269914
|
-
if (found !== undefined)
|
|
269915
|
-
return found;
|
|
269916
|
-
} catch {}
|
|
269917
|
-
}
|
|
269918
|
-
} finally {
|
|
269919
|
-
lines.close();
|
|
269920
|
-
}
|
|
269921
|
-
return;
|
|
269922
|
-
}
|
|
269923
|
-
var asRecord = (value) => value && typeof value === "object" ? value : {};
|
|
269924
|
-
var codexCwd = (entry) => entry.type === "session_meta" ? String(asRecord(entry.payload).cwd ?? "") : undefined;
|
|
269925
|
-
async function newest(paths) {
|
|
269926
|
-
let best;
|
|
269927
|
-
for (const path of paths) {
|
|
269928
|
-
const { mtimeMs } = await stat8(path);
|
|
269929
|
-
if (!best || mtimeMs > best.mtime)
|
|
269930
|
-
best = { path, mtime: mtimeMs };
|
|
269931
|
-
}
|
|
269932
|
-
return best?.path;
|
|
269933
|
-
}
|
|
269934
|
-
async function sameDir(a, b) {
|
|
269935
|
-
if (a === b)
|
|
269936
|
-
return true;
|
|
269937
|
-
const [ra, rb] = await Promise.all([
|
|
269938
|
-
realpath2(a).catch(() => a),
|
|
269939
|
-
realpath2(b).catch(() => b)
|
|
269940
|
-
]);
|
|
269941
|
-
return ra === rb;
|
|
269942
|
-
}
|
|
269943
|
-
var codexRollouts = () => globby("sessions/*/*/*/rollout-*.jsonl", {
|
|
269944
|
-
cwd: codexDir(),
|
|
269945
|
-
absolute: true
|
|
269946
|
-
});
|
|
269947
|
-
async function codexRolloutsIn(cwd) {
|
|
269948
|
-
const matches = [];
|
|
269949
|
-
for (const path of await codexRollouts()) {
|
|
269950
|
-
const recorded = await scanLines(path, codexCwd, 1);
|
|
269951
|
-
if (recorded && await sameDir(recorded, cwd))
|
|
269952
|
-
matches.push(path);
|
|
269953
|
-
}
|
|
269954
|
-
return matches;
|
|
269955
|
-
}
|
|
269956
|
-
async function findCurrentSession(cwd) {
|
|
269957
|
-
const claudeId = process.env.CLAUDE_CODE_SESSION_ID;
|
|
269958
|
-
if (claudeId) {
|
|
269959
|
-
const [path] = await globby(`projects/*/${claudeId}.jsonl`, {
|
|
269960
|
-
cwd: claudeDir(),
|
|
269961
|
-
absolute: true
|
|
269962
|
-
});
|
|
269963
|
-
return path;
|
|
269964
|
-
}
|
|
269965
|
-
const codexId = process.env.CODEX_THREAD_ID;
|
|
269966
|
-
if (codexId) {
|
|
269967
|
-
const rollouts = await codexRollouts();
|
|
269968
|
-
return rollouts.find((path) => path.endsWith(`-${codexId}.jsonl`));
|
|
269969
|
-
}
|
|
269970
|
-
return newest(await codexRolloutsIn(cwd));
|
|
269971
|
-
}
|
|
269972
|
-
function claudeUserText(entry) {
|
|
269973
|
-
if (entry.type !== "user" || entry.isMeta || entry.isSidechain)
|
|
269974
|
-
return;
|
|
269975
|
-
const content = asRecord(entry.message).content;
|
|
269976
|
-
return typeof content === "string" && !content.startsWith("<") ? content : undefined;
|
|
269977
|
-
}
|
|
269978
|
-
function codexUserText(entry) {
|
|
269979
|
-
const payload = asRecord(entry.payload);
|
|
269980
|
-
return entry.type === "event_msg" && payload.type === "user_message" ? String(payload.message ?? "") : undefined;
|
|
269981
|
-
}
|
|
269982
|
-
var PICKER_LIMIT = 20;
|
|
269983
|
-
async function listSessions(cwd) {
|
|
269984
|
-
const claudeFolder = cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
269985
|
-
const claude = await globby(`projects/${claudeFolder}/*.jsonl`, {
|
|
269986
|
-
cwd: claudeDir(),
|
|
269987
|
-
absolute: true
|
|
269988
|
-
});
|
|
269989
|
-
const candidates = [
|
|
269990
|
-
...claude.map((path) => ({ tool: "claude_code", path })),
|
|
269991
|
-
...(await codexRolloutsIn(cwd)).map((path) => ({
|
|
269992
|
-
tool: "codex",
|
|
269993
|
-
path
|
|
269994
|
-
}))
|
|
269995
|
-
];
|
|
269996
|
-
const dated = await Promise.all(candidates.map(async (c) => ({
|
|
269997
|
-
...c,
|
|
269998
|
-
updatedAt: (await stat8(c.path)).mtime
|
|
269999
|
-
})));
|
|
270000
|
-
dated.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
270001
|
-
const sessions = [];
|
|
270002
|
-
for (const candidate of dated.slice(0, PICKER_LIMIT)) {
|
|
270003
|
-
const firstMessage = await scanLines(candidate.path, candidate.tool === "claude_code" ? claudeUserText : codexUserText);
|
|
270004
|
-
if (firstMessage)
|
|
270005
|
-
sessions.push({ ...candidate, firstMessage });
|
|
270006
|
-
}
|
|
270007
|
-
return sessions;
|
|
270008
|
-
}
|
|
270009
|
-
var SESSION_ID = /session_[A-Za-z0-9]+/;
|
|
270010
|
-
function parseSessionLink(link) {
|
|
270011
|
-
if (/cshk_/.test(link) || !SESSION_ID.test(link)) {
|
|
270012
|
-
throw new InvalidInputError(`That isn't a claude.ai session address. Copy it from your browser's address bar (not "Copy link").`, { hints: [] });
|
|
270013
|
-
}
|
|
270014
|
-
return link.match(SESSION_ID)[0];
|
|
270015
|
-
}
|
|
270016
|
-
var TELEPORT_PROMPT = "Reply with OK.";
|
|
270017
|
-
var TELEPORT_NOTE = "This session is being continued from another machine";
|
|
270018
|
-
function parseLine(line) {
|
|
270019
|
-
try {
|
|
270020
|
-
return asRecord(JSON.parse(line));
|
|
270021
|
-
} catch {
|
|
270022
|
-
return {};
|
|
270023
|
-
}
|
|
270024
|
-
}
|
|
270025
|
-
function stripTeleportExchange(content) {
|
|
270026
|
-
const lines = content.split(`
|
|
270027
|
-
`);
|
|
270028
|
-
const entries = lines.map(parseLine);
|
|
270029
|
-
const userText = (entry) => entry.type === "user" ? asRecord(entry.message).content : undefined;
|
|
270030
|
-
let end = lines.length;
|
|
270031
|
-
for (let i = lines.length - 1;i >= 0; i--) {
|
|
270032
|
-
if (userText(entries[i] ?? {}) === TELEPORT_PROMPT) {
|
|
270033
|
-
end = i;
|
|
270034
|
-
break;
|
|
270035
|
-
}
|
|
270036
|
-
}
|
|
270037
|
-
return lines.slice(0, end).filter((_, i) => {
|
|
270038
|
-
const entry = entries[i] ?? {};
|
|
270039
|
-
const text = userText(entry);
|
|
270040
|
-
const queued = entry.type === "queue-operation" && entry.content === TELEPORT_PROMPT;
|
|
270041
|
-
const note = typeof text === "string" && text.startsWith(TELEPORT_NOTE);
|
|
270042
|
-
return !queued && !note;
|
|
270043
|
-
}).join(`
|
|
270044
|
-
`);
|
|
270045
|
-
}
|
|
270046
|
-
var NEEDS_CLAUDE = "Claude Code must be installed and signed in to the same claude.ai account to import a claude.ai session.";
|
|
270047
|
-
async function teleportSession(sessionId, cwd) {
|
|
270048
|
-
const origin = await execa("git", ["remote", "get-url", "origin"], {
|
|
270049
|
-
cwd,
|
|
270050
|
-
reject: false
|
|
270051
|
-
});
|
|
270052
|
-
if (origin.exitCode !== 0 || !origin.stdout) {
|
|
270053
|
-
throw new InvalidInputError("Run this from a folder with the app's GitHub repository, so the session can be checked out.");
|
|
270054
|
-
}
|
|
270055
|
-
const tmp = await $dir({ unsafeCleanup: true });
|
|
270056
|
-
const repo = join41(tmp.path, "repo");
|
|
270057
|
-
let projectFolder;
|
|
270058
|
-
try {
|
|
270059
|
-
await execa("git", ["clone", "--quiet", origin.stdout, repo]);
|
|
270060
|
-
const repoReal = await realpath2(repo);
|
|
270061
|
-
const startedAt = Date.now();
|
|
270062
|
-
const claudeBin = getTestOverrides()?.claudeBin ?? "claude";
|
|
270063
|
-
try {
|
|
270064
|
-
await execa(claudeBin, ["--teleport", sessionId, "-p", TELEPORT_PROMPT], {
|
|
270065
|
-
cwd: repo,
|
|
270066
|
-
stdin: "ignore"
|
|
270067
|
-
});
|
|
270068
|
-
} catch {
|
|
270069
|
-
throw new DependencyNotFoundError(NEEDS_CLAUDE, { hints: [] });
|
|
270070
|
-
}
|
|
270071
|
-
const fresh = [];
|
|
270072
|
-
for (const path of await globby("projects/*/*.jsonl", {
|
|
270073
|
-
cwd: claudeDir(),
|
|
270074
|
-
absolute: true
|
|
270075
|
-
})) {
|
|
270076
|
-
if ((await stat8(path)).mtimeMs < startedAt)
|
|
270077
|
-
continue;
|
|
270078
|
-
const sessionCwd = await scanLines(path, (entry) => typeof entry.cwd === "string" ? entry.cwd : undefined, 50);
|
|
270079
|
-
if (sessionCwd === repo || sessionCwd === repoReal)
|
|
270080
|
-
fresh.push(path);
|
|
270081
|
-
}
|
|
270082
|
-
const file = await newest(fresh);
|
|
270083
|
-
if (!file)
|
|
270084
|
-
throw new DependencyNotFoundError(NEEDS_CLAUDE, { hints: [] });
|
|
270085
|
-
projectFolder = dirname29(file);
|
|
270086
|
-
return stripTeleportExchange((await readFile(file)).toString("utf8"));
|
|
270087
|
-
} finally {
|
|
270088
|
-
if (projectFolder)
|
|
270089
|
-
await rm5(projectFolder, { recursive: true, force: true });
|
|
270090
|
-
await tmp.cleanup();
|
|
270091
|
-
}
|
|
270092
|
-
}
|
|
270093
|
-
|
|
270094
|
-
// src/cli/commands/import.ts
|
|
270095
|
-
var TOOL_LABELS = {
|
|
270096
|
-
claude_code: "Claude Code",
|
|
270097
|
-
codex: "Codex"
|
|
270098
|
-
};
|
|
270099
|
-
async function pickSession(cwd) {
|
|
270100
|
-
const sessions = await listSessions(cwd);
|
|
270101
|
-
if (sessions.length === 0) {
|
|
270102
|
-
throw new InvalidInputError("No Claude Code or Codex sessions found in this folder. Pass --file <path>.");
|
|
270103
|
-
}
|
|
270104
|
-
const choice = await Je({
|
|
270105
|
-
message: "Which session do you want to continue in Base Code?",
|
|
270106
|
-
options: sessions.map((session) => ({
|
|
270107
|
-
value: session.path,
|
|
270108
|
-
label: session.firstMessage.replace(/\s+/g, " ").slice(0, 70),
|
|
270109
|
-
hint: `${TOOL_LABELS[session.tool]}, ${import_ms2.default(Date.now() - session.updatedAt.getTime())} ago`
|
|
270110
|
-
}))
|
|
270111
|
-
});
|
|
270112
|
-
if (Ct(choice)) {
|
|
270113
|
-
Ne("Operation cancelled.");
|
|
270114
|
-
throw new CLIExitError(0);
|
|
270115
|
-
}
|
|
270116
|
-
return choice;
|
|
270117
|
-
}
|
|
270118
|
-
async function readSession(ctx, link, options) {
|
|
270119
|
-
const cwd = process.cwd();
|
|
270120
|
-
if (options.file)
|
|
270121
|
-
return readFile(options.file);
|
|
270122
|
-
if (link) {
|
|
270123
|
-
const sessionId = parseSessionLink(link);
|
|
270124
|
-
const content = await ctx.runTask("Downloading the claude.ai session", () => teleportSession(sessionId, cwd));
|
|
270125
|
-
return Buffer.from(content);
|
|
270126
|
-
}
|
|
270127
|
-
if (options.current) {
|
|
270128
|
-
const path = await findCurrentSession(cwd);
|
|
270129
|
-
if (!path) {
|
|
270130
|
-
throw new InvalidInputError("Couldn't find the current session. Run this from inside Claude Code or Codex, or pass --file <path>.", { hints: [] });
|
|
270131
|
-
}
|
|
270132
|
-
return readFile(path);
|
|
270133
|
-
}
|
|
270134
|
-
if (ctx.isNonInteractive || ctx.jsonMode) {
|
|
270135
|
-
throw new InvalidInputError("Choose a session: pass --current, a claude.ai session link, or --file <path>.");
|
|
270136
|
-
}
|
|
270137
|
-
return readFile(await pickSession(cwd));
|
|
270138
|
-
}
|
|
270139
|
-
async function importAction(ctx, link, options, command) {
|
|
270140
|
-
ctx.errorReporter.setContext({
|
|
270141
|
-
command: {
|
|
270142
|
-
name: "import",
|
|
270143
|
-
args: link ? ["[not reported]"] : [],
|
|
270144
|
-
options: {
|
|
270145
|
-
...command.opts(),
|
|
270146
|
-
...options.token ? { token: "[not reported]" } : {}
|
|
270147
|
-
}
|
|
270148
|
-
}
|
|
270149
|
-
});
|
|
270150
|
-
const chosen = [link, options.current, options.file].filter(Boolean).length;
|
|
270151
|
-
if (chosen > 1) {
|
|
270152
|
-
throw new InvalidInputError("Pass only one of: a session link, --current, or --file.");
|
|
270153
|
-
}
|
|
270154
|
-
const appId = requireApp(ctx).id;
|
|
270155
|
-
const content = await readSession(ctx, link, options);
|
|
270156
|
-
if (content.length > MAX_SESSION_BYTES) {
|
|
270157
|
-
throw new InvalidInputError("This session is over 25 MB and can't be imported.", { hints: [] });
|
|
270158
|
-
}
|
|
270159
|
-
const git = link || options.file ? undefined : await readGitState(process.cwd());
|
|
270160
|
-
if (git?.unpushed && !options.skipPushCheck) {
|
|
270161
|
-
throw new InvalidInputError("Your changes aren't on GitHub yet. Ask the user whether to commit and push them (to a new branch if on main or master), then run this again. If they don't want to, run it again with --skip-push-check.", { hints: [] });
|
|
270162
|
-
}
|
|
270163
|
-
const note = git?.unpushed ? "Base Code started from what's on GitHub; your local changes aren't included." : undefined;
|
|
270164
|
-
if (!options.token)
|
|
270165
|
-
await ensureAuth(ctx);
|
|
270166
|
-
ctx.log.info("This uploads the full conversation to Base Code.");
|
|
270167
|
-
const imported = await ctx.runTask("Importing session", () => uploadSession(appId, content, {
|
|
270168
|
-
token: options.token,
|
|
270169
|
-
sourceBranch: git?.branch
|
|
270170
|
-
}));
|
|
270171
|
-
const url = `${getBase44ApiUrl()}${imported.branchUrl}`;
|
|
270172
|
-
return {
|
|
270173
|
-
outroMessage: [
|
|
270174
|
-
`✓ Imported ${imported.turnCount} messages from ${TOOL_LABELS[imported.source]} into branch "${imported.branchName}".`,
|
|
270175
|
-
...note ? [note] : [],
|
|
270176
|
-
`Open it: ${url}`
|
|
270177
|
-
].join(`
|
|
270178
|
-
`),
|
|
270179
|
-
stdout: ctx.jsonMode ? toJsonStdout({ ...imported, url, ...note ? { note } : {} }) : undefined
|
|
270180
|
-
};
|
|
270181
|
-
}
|
|
270182
|
-
function getImportCommand() {
|
|
270183
|
-
return new Base44Command("import", { requireAuth: false }).description("Continue a Claude Code or Codex session in a new Base Code branch").argument("[session-link]", "A claude.ai session address (https://claude.ai/code/session_…)").option("--current", "Import the session this command runs inside").option("--file <path>", "Import this session file as is").option("--skip-push-check", "Import even though local changes aren't on GitHub (they won't be included)").option("--token <key>", "One-time import key from Base Code (no login needed)").action(importAction);
|
|
270184
|
-
}
|
|
270185
|
-
|
|
270186
272869
|
// src/cli/commands/project/eject.ts
|
|
270187
272870
|
import { resolve as resolve20 } from "node:path";
|
|
270188
272871
|
var import_kebabCase2 = __toESM(require_kebabCase(), 1);
|
|
@@ -270346,7 +273029,6 @@ function createProgram(context) {
|
|
|
270346
273029
|
program.addCommand(getExecCommand());
|
|
270347
273030
|
program.addCommand(getDevCommand());
|
|
270348
273031
|
program.addCommand(getLogsCommand());
|
|
270349
|
-
program.addCommand(getImportCommand());
|
|
270350
273032
|
return program;
|
|
270351
273033
|
}
|
|
270352
273034
|
|
|
@@ -270355,7 +273037,7 @@ var import_detect_agent = __toESM(require_dist5(), 1);
|
|
|
270355
273037
|
import { release, type } from "node:os";
|
|
270356
273038
|
|
|
270357
273039
|
// ../../node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.mjs
|
|
270358
|
-
import { dirname as
|
|
273040
|
+
import { dirname as dirname29, posix, sep as sep2 } from "path";
|
|
270359
273041
|
function createModulerModifier() {
|
|
270360
273042
|
const getModuleFromFileName = createGetModuleFromFilename();
|
|
270361
273043
|
return async (frames) => {
|
|
@@ -270364,7 +273046,7 @@ function createModulerModifier() {
|
|
|
270364
273046
|
return frames;
|
|
270365
273047
|
};
|
|
270366
273048
|
}
|
|
270367
|
-
function createGetModuleFromFilename(basePath = process.argv[1] ?
|
|
273049
|
+
function createGetModuleFromFilename(basePath = process.argv[1] ? dirname29(process.argv[1]) : process.cwd(), isWindows = sep2 === "\\") {
|
|
270368
273050
|
const normalizedBase = isWindows ? normalizeWindowsPath2(basePath) : basePath;
|
|
270369
273051
|
return (filename) => {
|
|
270370
273052
|
if (!filename)
|
|
@@ -272399,8 +275081,8 @@ class ReduceableCache {
|
|
|
272399
275081
|
}
|
|
272400
275082
|
}
|
|
272401
275083
|
// ../../node_modules/posthog-node/dist/extensions/error-tracking/modifiers/context-lines.node.mjs
|
|
272402
|
-
import { createReadStream as
|
|
272403
|
-
import { createInterface as
|
|
275084
|
+
import { createReadStream as createReadStream3 } from "node:fs";
|
|
275085
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
272404
275086
|
var LRU_FILE_CONTENTS_CACHE = new ReduceableCache(25);
|
|
272405
275087
|
var LRU_FILE_CONTENTS_FS_READ_FAILED = new ReduceableCache(20);
|
|
272406
275088
|
var DEFAULT_LINES_OF_CONTEXT = 7;
|
|
@@ -272443,8 +275125,8 @@ async function addSourceContext(frames) {
|
|
|
272443
275125
|
}
|
|
272444
275126
|
function getContextLinesFromFile(path, ranges, output) {
|
|
272445
275127
|
return new Promise((resolve) => {
|
|
272446
|
-
const stream =
|
|
272447
|
-
const lineReaded =
|
|
275128
|
+
const stream = createReadStream3(path);
|
|
275129
|
+
const lineReaded = createInterface2({
|
|
272448
275130
|
input: stream
|
|
272449
275131
|
});
|
|
272450
275132
|
function destroyStreamAndResolve() {
|
|
@@ -274353,9 +277035,9 @@ function addCommandInfoToErrorReporter(program, errorReporter) {
|
|
|
274353
277035
|
});
|
|
274354
277036
|
}
|
|
274355
277037
|
// src/cli/index.ts
|
|
274356
|
-
var __dirname4 =
|
|
277038
|
+
var __dirname4 = dirname30(fileURLToPath7(import.meta.url));
|
|
274357
277039
|
async function runCLI(options) {
|
|
274358
|
-
ensureNpmAssets(
|
|
277040
|
+
ensureNpmAssets(join41(__dirname4, "../assets"));
|
|
274359
277041
|
const errorReporter = new ErrorReporter;
|
|
274360
277042
|
errorReporter.registerProcessErrorHandlers();
|
|
274361
277043
|
const jsonMode = process.argv.includes("--json");
|
|
@@ -274394,4 +277076,4 @@ export {
|
|
|
274394
277076
|
runCLI
|
|
274395
277077
|
};
|
|
274396
277078
|
|
|
274397
|
-
//# debugId=
|
|
277079
|
+
//# debugId=319D69906789140664756E2164756E21
|