sandbox 3.1.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { a as __toCommonJS$3, i as __require
|
|
1
|
+
import { a as __toCommonJS$3, i as __require, n as __esm, o as __toDynamicImportESM, r as __export$3, s as __toESM, t as __commonJS } from "./chunk-btbCw1m3.mjs";
|
|
2
2
|
import { i as init_strip_ansi, o as strip_ansi_exports, t as stringWidth } from "./string-width-D78SVDLD.mjs";
|
|
3
3
|
import { a as _classPrivateFieldInitSpec, i as _assertClassBrand, n as _classPrivateFieldGet2, o as _classPrivateMethodInitSpec, r as _classPrivateFieldSet2, t as cli_cursor_default } from "./cli-cursor-Dab4mDU2.mjs";
|
|
4
4
|
import { n as require_auth_errors, r as require_token_error, t as require_token_util } from "./token-util-DACSFqcB.mjs";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
5
|
import process$1 from "node:process";
|
|
7
6
|
import os, { tmpdir } from "node:os";
|
|
8
7
|
import tty, { isatty } from "node:tty";
|
|
@@ -13,7 +12,7 @@ import path from "node:path";
|
|
|
13
12
|
import { fileURLToPath } from "node:url";
|
|
14
13
|
import childProcess, { execFile } from "node:child_process";
|
|
15
14
|
import fs, { constants, writeFile } from "node:fs/promises";
|
|
16
|
-
import fs$1
|
|
15
|
+
import fs$1 from "node:fs";
|
|
17
16
|
import * as Auth from "@vercel/sandbox/dist/auth/index.js";
|
|
18
17
|
import { NotOk, OAuth, getAuth, inferScope, pollForToken, updateAuthConfig } from "@vercel/sandbox/dist/auth/index.js";
|
|
19
18
|
import { EOL } from "os";
|
|
@@ -21,16 +20,13 @@ import { z } from "zod/v4";
|
|
|
21
20
|
import { z as z$1 } from "zod";
|
|
22
21
|
import retry from "async-retry";
|
|
23
22
|
import { APIError, Sandbox, Snapshot } from "@vercel/sandbox";
|
|
24
|
-
import
|
|
25
|
-
import { randomUUID } from "crypto";
|
|
26
|
-
import { Writable } from "stream";
|
|
27
|
-
import { PassThrough } from "node:stream";
|
|
28
|
-
import { randomUUID as randomUUID$1 } from "node:crypto";
|
|
29
|
-
import assert from "node:assert";
|
|
23
|
+
import { WebSocket } from "ws";
|
|
30
24
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
31
25
|
import * as tty$1 from "tty";
|
|
32
26
|
import { format } from "util";
|
|
33
27
|
import { StringDecoder } from "string_decoder";
|
|
28
|
+
import { Writable } from "stream";
|
|
29
|
+
import { randomUUID } from "crypto";
|
|
34
30
|
import consume from "node:stream/consumers";
|
|
35
31
|
|
|
36
32
|
//#region ../../node_modules/.pnpm/chalk@5.6.0/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
@@ -476,7 +472,7 @@ var init_source = __esm({ "../../node_modules/.pnpm/chalk@5.6.0/node_modules/cha
|
|
|
476
472
|
|
|
477
473
|
//#endregion
|
|
478
474
|
//#region ../../node_modules/.pnpm/didyoumean@1.2.2/node_modules/didyoumean/didYouMean-1.2.1.js
|
|
479
|
-
var require_didYouMean_1_2_1 = /* @__PURE__ */ __commonJS
|
|
475
|
+
var require_didYouMean_1_2_1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/didyoumean@1.2.2/node_modules/didyoumean/didYouMean-1.2.1.js": ((exports, module) => {
|
|
480
476
|
(function() {
|
|
481
477
|
"use strict";
|
|
482
478
|
function didYouMean(str, list$3, key) {
|
|
@@ -544,7 +540,7 @@ var require_didYouMean_1_2_1 = /* @__PURE__ */ __commonJS$1({ "../../node_module
|
|
|
544
540
|
|
|
545
541
|
//#endregion
|
|
546
542
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/Result.js
|
|
547
|
-
var require_Result = /* @__PURE__ */ __commonJS
|
|
543
|
+
var require_Result = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/Result.js": ((exports) => {
|
|
548
544
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
549
545
|
exports.ok = ok;
|
|
550
546
|
exports.err = err;
|
|
@@ -592,7 +588,7 @@ var require_Result = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cm
|
|
|
592
588
|
|
|
593
589
|
//#endregion
|
|
594
590
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/effects.js
|
|
595
|
-
var require_effects = /* @__PURE__ */ __commonJS
|
|
591
|
+
var require_effects = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/effects.js": ((exports) => {
|
|
596
592
|
/**
|
|
597
593
|
* "Effects" are custom exceptions that can do stuff.
|
|
598
594
|
* The concept comes from React, where they throw a `Promise` to provide the ability to write
|
|
@@ -644,7 +640,7 @@ var require_effects = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/c
|
|
|
644
640
|
|
|
645
641
|
//#endregion
|
|
646
642
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/newparser/findOption.js
|
|
647
|
-
var require_findOption = /* @__PURE__ */ __commonJS
|
|
643
|
+
var require_findOption = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/newparser/findOption.js": ((exports) => {
|
|
648
644
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
649
645
|
exports.findOption = findOption;
|
|
650
646
|
/**
|
|
@@ -670,7 +666,7 @@ var require_findOption = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnp
|
|
|
670
666
|
|
|
671
667
|
//#endregion
|
|
672
668
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/from.js
|
|
673
|
-
var require_from = /* @__PURE__ */ __commonJS
|
|
669
|
+
var require_from = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/from.js": ((exports) => {
|
|
674
670
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
675
671
|
exports.identity = identity;
|
|
676
672
|
/**
|
|
@@ -685,7 +681,7 @@ var require_from = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd-
|
|
|
685
681
|
|
|
686
682
|
//#endregion
|
|
687
683
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/type.js
|
|
688
|
-
var require_type = /* @__PURE__ */ __commonJS
|
|
684
|
+
var require_type = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/type.js": ((exports) => {
|
|
689
685
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
690
686
|
exports.identity = void 0;
|
|
691
687
|
exports.typeDef = typeDef;
|
|
@@ -738,7 +734,7 @@ var require_type = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd-
|
|
|
738
734
|
|
|
739
735
|
//#endregion
|
|
740
736
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/types.js
|
|
741
|
-
var require_types = /* @__PURE__ */ __commonJS
|
|
737
|
+
var require_types = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/types.js": ((exports) => {
|
|
742
738
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
743
739
|
exports.boolean = exports.string = exports.number = void 0;
|
|
744
740
|
exports.optional = optional;
|
|
@@ -801,7 +797,7 @@ var require_types = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd
|
|
|
801
797
|
|
|
802
798
|
//#endregion
|
|
803
799
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/flag.js
|
|
804
|
-
var require_flag = /* @__PURE__ */ __commonJS
|
|
800
|
+
var require_flag = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/flag.js": ((exports) => {
|
|
805
801
|
var __createBinding$11 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
806
802
|
if (k2 === void 0) k2 = k;
|
|
807
803
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -976,7 +972,7 @@ var require_flag = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd-
|
|
|
976
972
|
|
|
977
973
|
//#endregion
|
|
978
974
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/circuitbreaker.js
|
|
979
|
-
var require_circuitbreaker = /* @__PURE__ */ __commonJS
|
|
975
|
+
var require_circuitbreaker = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/circuitbreaker.js": ((exports) => {
|
|
980
976
|
var __createBinding$10 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
981
977
|
if (k2 === void 0) k2 = k;
|
|
982
978
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -1097,7 +1093,7 @@ var require_circuitbreaker = /* @__PURE__ */ __commonJS$1({ "../../node_modules/
|
|
|
1097
1093
|
|
|
1098
1094
|
//#endregion
|
|
1099
1095
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/utils.js
|
|
1100
|
-
var require_utils = /* @__PURE__ */ __commonJS
|
|
1096
|
+
var require_utils = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/utils.js": ((exports) => {
|
|
1101
1097
|
var __importDefault$7 = exports && exports.__importDefault || function(mod) {
|
|
1102
1098
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1103
1099
|
};
|
|
@@ -1174,7 +1170,7 @@ var require_utils = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd
|
|
|
1174
1170
|
|
|
1175
1171
|
//#endregion
|
|
1176
1172
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/helpFormatter.js
|
|
1177
|
-
var require_helpFormatter = /* @__PURE__ */ __commonJS
|
|
1173
|
+
var require_helpFormatter = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/helpFormatter.js": ((exports) => {
|
|
1178
1174
|
var __importDefault$6 = exports && exports.__importDefault || function(mod) {
|
|
1179
1175
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1180
1176
|
};
|
|
@@ -1297,7 +1293,7 @@ var require_helpFormatter = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.
|
|
|
1297
1293
|
|
|
1298
1294
|
//#endregion
|
|
1299
1295
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/positional.js
|
|
1300
|
-
var require_positional = /* @__PURE__ */ __commonJS
|
|
1296
|
+
var require_positional = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/positional.js": ((exports) => {
|
|
1301
1297
|
var __createBinding$9 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
1302
1298
|
if (k2 === void 0) k2 = k;
|
|
1303
1299
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -1401,7 +1397,7 @@ var require_positional = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnp
|
|
|
1401
1397
|
|
|
1402
1398
|
//#endregion
|
|
1403
1399
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/subcommands.js
|
|
1404
|
-
var require_subcommands = /* @__PURE__ */ __commonJS
|
|
1400
|
+
var require_subcommands = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/subcommands.js": ((exports) => {
|
|
1405
1401
|
var __createBinding$8 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
1406
1402
|
if (k2 === void 0) k2 = k;
|
|
1407
1403
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -1581,7 +1577,7 @@ var require_subcommands = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pn
|
|
|
1581
1577
|
|
|
1582
1578
|
//#endregion
|
|
1583
1579
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/binary.js
|
|
1584
|
-
var require_binary = /* @__PURE__ */ __commonJS
|
|
1580
|
+
var require_binary = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/binary.js": ((exports) => {
|
|
1585
1581
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1586
1582
|
exports.binary = binary;
|
|
1587
1583
|
/**
|
|
@@ -1607,7 +1603,7 @@ var require_binary = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cm
|
|
|
1607
1603
|
|
|
1608
1604
|
//#endregion
|
|
1609
1605
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/command.js
|
|
1610
|
-
var require_command = /* @__PURE__ */ __commonJS
|
|
1606
|
+
var require_command = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/command.js": ((exports) => {
|
|
1611
1607
|
var __createBinding$7 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
1612
1608
|
if (k2 === void 0) k2 = k;
|
|
1613
1609
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -1735,7 +1731,7 @@ var require_command = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/c
|
|
|
1735
1731
|
|
|
1736
1732
|
//#endregion
|
|
1737
1733
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/option.js
|
|
1738
|
-
var require_option = /* @__PURE__ */ __commonJS
|
|
1734
|
+
var require_option = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/option.js": ((exports) => {
|
|
1739
1735
|
var __createBinding$6 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
1740
1736
|
if (k2 === void 0) k2 = k;
|
|
1741
1737
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -1892,7 +1888,7 @@ var require_option = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cm
|
|
|
1892
1888
|
|
|
1893
1889
|
//#endregion
|
|
1894
1890
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/errorBox.js
|
|
1895
|
-
var require_errorBox = /* @__PURE__ */ __commonJS
|
|
1891
|
+
var require_errorBox = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/errorBox.js": ((exports) => {
|
|
1896
1892
|
var __importDefault$2 = exports && exports.__importDefault || function(mod) {
|
|
1897
1893
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1898
1894
|
};
|
|
@@ -1992,20 +1988,20 @@ var require_errorBox = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/
|
|
|
1992
1988
|
|
|
1993
1989
|
//#endregion
|
|
1994
1990
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/newparser/parser.js
|
|
1995
|
-
var require_parser
|
|
1991
|
+
var require_parser = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/newparser/parser.js": ((exports) => {
|
|
1996
1992
|
var __importDefault$1 = exports && exports.__importDefault || function(mod) {
|
|
1997
1993
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1998
1994
|
};
|
|
1999
1995
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2000
|
-
exports.parse = parse$
|
|
2001
|
-
const debug$7 = (0, __importDefault$1(__require
|
|
1996
|
+
exports.parse = parse$2;
|
|
1997
|
+
const debug$7 = (0, __importDefault$1(__require("debug")).default)("cmd-ts:parser");
|
|
2002
1998
|
/**
|
|
2003
1999
|
* Create an AST from a token list
|
|
2004
2000
|
*
|
|
2005
2001
|
* @param tokens A token list, coming from `tokenizer.ts`
|
|
2006
2002
|
* @param forceFlag Keys to force as flag. {@see ForceFlag} to read more about it.
|
|
2007
2003
|
*/
|
|
2008
|
-
function parse$
|
|
2004
|
+
function parse$2(tokens, forceFlag) {
|
|
2009
2005
|
if (debug$7.enabled) {
|
|
2010
2006
|
const registered = {
|
|
2011
2007
|
shortFlags: [...forceFlag.forceFlagShortNames],
|
|
@@ -2185,7 +2181,7 @@ var require_parser$1 = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/
|
|
|
2185
2181
|
|
|
2186
2182
|
//#endregion
|
|
2187
2183
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/newparser/tokenizer.js
|
|
2188
|
-
var require_tokenizer = /* @__PURE__ */ __commonJS
|
|
2184
|
+
var require_tokenizer = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/newparser/tokenizer.js": ((exports) => {
|
|
2189
2185
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2190
2186
|
exports.tokenize = tokenize;
|
|
2191
2187
|
const utils_1 = require_utils();
|
|
@@ -2197,30 +2193,30 @@ var require_tokenizer = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm
|
|
|
2197
2193
|
function tokenize(strings) {
|
|
2198
2194
|
const tokens = [];
|
|
2199
2195
|
let overallIndex = 0;
|
|
2200
|
-
const push
|
|
2196
|
+
const push = (token$1) => {
|
|
2201
2197
|
tokens.push(token$1);
|
|
2202
2198
|
overallIndex += token$1.raw.length;
|
|
2203
2199
|
};
|
|
2204
2200
|
for (const [stringIndex, string$2] of (0, utils_1.enumerate)(strings)) {
|
|
2205
2201
|
const chars = [...string$2];
|
|
2206
2202
|
for (let i = 0; i < chars.length; i++) if (chars[i] === "-" && chars[i + 1] === "-") {
|
|
2207
|
-
push
|
|
2203
|
+
push({
|
|
2208
2204
|
type: "longPrefix",
|
|
2209
2205
|
raw: "--",
|
|
2210
2206
|
index: overallIndex
|
|
2211
2207
|
});
|
|
2212
2208
|
i++;
|
|
2213
|
-
} else if (chars[i] === "-") push
|
|
2209
|
+
} else if (chars[i] === "-") push({
|
|
2214
2210
|
type: "shortPrefix",
|
|
2215
2211
|
raw: "-",
|
|
2216
2212
|
index: overallIndex
|
|
2217
2213
|
});
|
|
2218
|
-
else push
|
|
2214
|
+
else push({
|
|
2219
2215
|
type: "char",
|
|
2220
2216
|
raw: chars[i],
|
|
2221
2217
|
index: overallIndex
|
|
2222
2218
|
});
|
|
2223
|
-
if (stringIndex + 1 !== strings.length) push
|
|
2219
|
+
if (stringIndex + 1 !== strings.length) push({
|
|
2224
2220
|
type: "argumentDivider",
|
|
2225
2221
|
raw: " ",
|
|
2226
2222
|
index: overallIndex
|
|
@@ -2232,16 +2228,16 @@ var require_tokenizer = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm
|
|
|
2232
2228
|
|
|
2233
2229
|
//#endregion
|
|
2234
2230
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/runner.js
|
|
2235
|
-
var require_runner = /* @__PURE__ */ __commonJS
|
|
2231
|
+
var require_runner = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/runner.js": ((exports) => {
|
|
2236
2232
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2237
2233
|
exports.run = run$1;
|
|
2238
2234
|
exports.runSafely = runSafely;
|
|
2239
2235
|
exports.dryRun = dryRun;
|
|
2240
|
-
exports.parse = parse$
|
|
2236
|
+
exports.parse = parse$1;
|
|
2241
2237
|
const Result_1 = require_Result();
|
|
2242
2238
|
const effects_1 = require_effects();
|
|
2243
2239
|
const errorBox_1 = require_errorBox();
|
|
2244
|
-
const parser_1 = require_parser
|
|
2240
|
+
const parser_1 = require_parser();
|
|
2245
2241
|
const tokenizer_1 = require_tokenizer();
|
|
2246
2242
|
async function run$1(ap, strings) {
|
|
2247
2243
|
const result = await runSafely(ap, strings);
|
|
@@ -2282,7 +2278,7 @@ var require_runner = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cm
|
|
|
2282
2278
|
/**
|
|
2283
2279
|
* Parse the command as if to run it, but only return the parse result and don't run the command.
|
|
2284
2280
|
*/
|
|
2285
|
-
function parse$
|
|
2281
|
+
function parse$1(ap, strings) {
|
|
2286
2282
|
const hotPath = [];
|
|
2287
2283
|
const nodes = parseCommon(ap, strings);
|
|
2288
2284
|
return ap.parse({
|
|
@@ -2309,7 +2305,7 @@ var require_runner = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cm
|
|
|
2309
2305
|
|
|
2310
2306
|
//#endregion
|
|
2311
2307
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/restPositionals.js
|
|
2312
|
-
var require_restPositionals = /* @__PURE__ */ __commonJS
|
|
2308
|
+
var require_restPositionals = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/restPositionals.js": ((exports) => {
|
|
2313
2309
|
var __createBinding$5 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
2314
2310
|
if (k2 === void 0) k2 = k;
|
|
2315
2311
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -2400,7 +2396,7 @@ var require_restPositionals = /* @__PURE__ */ __commonJS$1({ "../../node_modules
|
|
|
2400
2396
|
|
|
2401
2397
|
//#endregion
|
|
2402
2398
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/multiflag.js
|
|
2403
|
-
var require_multiflag = /* @__PURE__ */ __commonJS
|
|
2399
|
+
var require_multiflag = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/multiflag.js": ((exports) => {
|
|
2404
2400
|
var __createBinding$4 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
2405
2401
|
if (k2 === void 0) k2 = k;
|
|
2406
2402
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -2499,7 +2495,7 @@ var require_multiflag = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm
|
|
|
2499
2495
|
|
|
2500
2496
|
//#endregion
|
|
2501
2497
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/multioption.js
|
|
2502
|
-
var require_multioption = /* @__PURE__ */ __commonJS
|
|
2498
|
+
var require_multioption = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/multioption.js": ((exports) => {
|
|
2503
2499
|
var __createBinding$3 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
2504
2500
|
if (k2 === void 0) k2 = k;
|
|
2505
2501
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -2641,7 +2637,7 @@ var require_multioption = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pn
|
|
|
2641
2637
|
|
|
2642
2638
|
//#endregion
|
|
2643
2639
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/union.js
|
|
2644
|
-
var require_union = /* @__PURE__ */ __commonJS
|
|
2640
|
+
var require_union = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/union.js": ((exports) => {
|
|
2645
2641
|
var __createBinding$2 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
2646
2642
|
if (k2 === void 0) k2 = k;
|
|
2647
2643
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -2709,10 +2705,10 @@ var require_union = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd
|
|
|
2709
2705
|
|
|
2710
2706
|
//#endregion
|
|
2711
2707
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/oneOf.js
|
|
2712
|
-
var require_oneOf = /* @__PURE__ */ __commonJS
|
|
2708
|
+
var require_oneOf = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/oneOf.js": ((exports) => {
|
|
2713
2709
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2714
2710
|
exports.oneOf = oneOf;
|
|
2715
|
-
const node_util_1 = __require
|
|
2711
|
+
const node_util_1 = __require("node:util");
|
|
2716
2712
|
/**
|
|
2717
2713
|
* A union of literals. When you want to take an exact enum value.
|
|
2718
2714
|
*/
|
|
@@ -2731,7 +2727,7 @@ var require_oneOf = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd
|
|
|
2731
2727
|
|
|
2732
2728
|
//#endregion
|
|
2733
2729
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/rest.js
|
|
2734
|
-
var require_rest = /* @__PURE__ */ __commonJS
|
|
2730
|
+
var require_rest = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/rest.js": ((exports) => {
|
|
2735
2731
|
var __createBinding$1 = exports && exports.__createBinding || (Object.create ? (function(o, m$1, k, k2) {
|
|
2736
2732
|
if (k2 === void 0) k2 = k;
|
|
2737
2733
|
var desc = Object.getOwnPropertyDescriptor(m$1, k);
|
|
@@ -2833,7 +2829,7 @@ var require_rest = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/cmd-
|
|
|
2833
2829
|
|
|
2834
2830
|
//#endregion
|
|
2835
2831
|
//#region ../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/index.js
|
|
2836
|
-
var require_cjs = /* @__PURE__ */ __commonJS
|
|
2832
|
+
var require_cjs = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cmd-ts@0.15.0/node_modules/cmd-ts/dist/cjs/index.js": ((exports) => {
|
|
2837
2833
|
/**
|
|
2838
2834
|
* The index module: the entrance to the world of cmd-ts 😎
|
|
2839
2835
|
*
|
|
@@ -3017,7 +3013,7 @@ const runtime = import_cjs$30.option({
|
|
|
3017
3013
|
|
|
3018
3014
|
//#endregion
|
|
3019
3015
|
//#region ../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js
|
|
3020
|
-
var require_ms = /* @__PURE__ */ __commonJS
|
|
3016
|
+
var require_ms = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js": ((exports, module) => {
|
|
3021
3017
|
/**
|
|
3022
3018
|
* Helpers.
|
|
3023
3019
|
*/
|
|
@@ -3043,7 +3039,7 @@ var require_ms = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ms@2.1
|
|
|
3043
3039
|
module.exports = function(val, options) {
|
|
3044
3040
|
options = options || {};
|
|
3045
3041
|
var type = typeof val;
|
|
3046
|
-
if (type === "string" && val.length > 0) return parse
|
|
3042
|
+
if (type === "string" && val.length > 0) return parse(val);
|
|
3047
3043
|
else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
|
|
3048
3044
|
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
3049
3045
|
};
|
|
@@ -3054,7 +3050,7 @@ var require_ms = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ms@2.1
|
|
|
3054
3050
|
* @return {Number}
|
|
3055
3051
|
* @api private
|
|
3056
3052
|
*/
|
|
3057
|
-
function parse
|
|
3053
|
+
function parse(str) {
|
|
3058
3054
|
str = String(str);
|
|
3059
3055
|
if (str.length > 100) return;
|
|
3060
3056
|
var match$1 = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
@@ -4683,7 +4679,7 @@ var open_default = open;
|
|
|
4683
4679
|
|
|
4684
4680
|
//#endregion
|
|
4685
4681
|
//#region ../../node_modules/.pnpm/cli-spinners@2.9.2/node_modules/cli-spinners/spinners.json
|
|
4686
|
-
var require_spinners = /* @__PURE__ */ __commonJS
|
|
4682
|
+
var require_spinners = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cli-spinners@2.9.2/node_modules/cli-spinners/spinners.json": ((exports, module) => {
|
|
4687
4683
|
module.exports = {
|
|
4688
4684
|
"dots": {
|
|
4689
4685
|
"interval": 80,
|
|
@@ -6268,7 +6264,7 @@ var require_spinners = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/
|
|
|
6268
6264
|
|
|
6269
6265
|
//#endregion
|
|
6270
6266
|
//#region ../../node_modules/.pnpm/cli-spinners@2.9.2/node_modules/cli-spinners/index.js
|
|
6271
|
-
var require_cli_spinners = /* @__PURE__ */ __commonJS
|
|
6267
|
+
var require_cli_spinners = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/cli-spinners@2.9.2/node_modules/cli-spinners/index.js": ((exports, module) => {
|
|
6272
6268
|
const spinners$1 = Object.assign({}, require_spinners());
|
|
6273
6269
|
const spinnersList = Object.keys(spinners$1);
|
|
6274
6270
|
Object.defineProperty(spinners$1, "random", { get() {
|
|
@@ -6840,10 +6836,10 @@ const login = import_cjs$26.command({
|
|
|
6840
6836
|
|
|
6841
6837
|
//#endregion
|
|
6842
6838
|
//#region ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/get-context.js
|
|
6843
|
-
var require_get_context = /* @__PURE__ */ __commonJS
|
|
6839
|
+
var require_get_context = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/get-context.js": ((exports, module) => {
|
|
6844
6840
|
var __defProp$2 = Object.defineProperty;
|
|
6845
6841
|
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
6846
|
-
var __getOwnPropNames$
|
|
6842
|
+
var __getOwnPropNames$2 = Object.getOwnPropertyNames;
|
|
6847
6843
|
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
6848
6844
|
var __export$2 = (target, all) => {
|
|
6849
6845
|
for (var name in all) __defProp$2(target, name, {
|
|
@@ -6853,7 +6849,7 @@ var require_get_context = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pn
|
|
|
6853
6849
|
};
|
|
6854
6850
|
var __copyProps$2 = (to, from, except, desc) => {
|
|
6855
6851
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
6856
|
-
for (let key of __getOwnPropNames$
|
|
6852
|
+
for (let key of __getOwnPropNames$2(from)) if (!__hasOwnProp$2.call(to, key) && key !== except) __defProp$2(to, key, {
|
|
6857
6853
|
get: () => from[key],
|
|
6858
6854
|
enumerable: !(desc = __getOwnPropDesc$2(from, key)) || desc.enumerable
|
|
6859
6855
|
});
|
|
@@ -6875,10 +6871,10 @@ var require_get_context = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pn
|
|
|
6875
6871
|
|
|
6876
6872
|
//#endregion
|
|
6877
6873
|
//#region ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js
|
|
6878
|
-
var require_get_vercel_oidc_token = /* @__PURE__ */ __commonJS
|
|
6874
|
+
var require_get_vercel_oidc_token = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js": ((exports, module) => {
|
|
6879
6875
|
var __defProp$1 = Object.defineProperty;
|
|
6880
6876
|
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
6881
|
-
var __getOwnPropNames$
|
|
6877
|
+
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
6882
6878
|
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
6883
6879
|
var __export$1 = (target, all) => {
|
|
6884
6880
|
for (var name in all) __defProp$1(target, name, {
|
|
@@ -6888,7 +6884,7 @@ var require_get_vercel_oidc_token = /* @__PURE__ */ __commonJS$1({ "../../node_m
|
|
|
6888
6884
|
};
|
|
6889
6885
|
var __copyProps$1 = (to, from, except, desc) => {
|
|
6890
6886
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
6891
|
-
for (let key of __getOwnPropNames$
|
|
6887
|
+
for (let key of __getOwnPropNames$1(from)) if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
|
|
6892
6888
|
get: () => from[key],
|
|
6893
6889
|
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
6894
6890
|
});
|
|
@@ -6936,10 +6932,10 @@ ${error.message}`;
|
|
|
6936
6932
|
|
|
6937
6933
|
//#endregion
|
|
6938
6934
|
//#region ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/index.js
|
|
6939
|
-
var require_dist = /* @__PURE__ */ __commonJS
|
|
6935
|
+
var require_dist = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/index.js": ((exports, module) => {
|
|
6940
6936
|
var __defProp = Object.defineProperty;
|
|
6941
6937
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6942
|
-
var __getOwnPropNames
|
|
6938
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6943
6939
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6944
6940
|
var __export = (target, all) => {
|
|
6945
6941
|
for (var name in all) __defProp(target, name, {
|
|
@@ -6949,7 +6945,7 @@ var require_dist = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/@ver
|
|
|
6949
6945
|
};
|
|
6950
6946
|
var __copyProps = (to, from, except, desc) => {
|
|
6951
6947
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
6952
|
-
for (let key of __getOwnPropNames
|
|
6948
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
6953
6949
|
get: () => from[key],
|
|
6954
6950
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
6955
6951
|
});
|
|
@@ -7290,7 +7286,7 @@ const scope = {
|
|
|
7290
7286
|
|
|
7291
7287
|
//#endregion
|
|
7292
7288
|
//#region package.json
|
|
7293
|
-
var version = "3.
|
|
7289
|
+
var version = "3.2.0";
|
|
7294
7290
|
|
|
7295
7291
|
//#endregion
|
|
7296
7292
|
//#region src/error.ts
|
|
@@ -7490,4030 +7486,154 @@ const sandboxName = import_cjs$19.extendType(import_cjs$19.string, {
|
|
|
7490
7486
|
});
|
|
7491
7487
|
|
|
7492
7488
|
//#endregion
|
|
7493
|
-
//#region
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
"fragments"
|
|
7499
|
-
];
|
|
7500
|
-
const hasBlob$1 = typeof Blob !== "undefined";
|
|
7501
|
-
if (hasBlob$1) BINARY_TYPES$2.push("blob");
|
|
7502
|
-
module.exports = {
|
|
7503
|
-
BINARY_TYPES: BINARY_TYPES$2,
|
|
7504
|
-
EMPTY_BUFFER: Buffer.alloc(0),
|
|
7505
|
-
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
7506
|
-
hasBlob: hasBlob$1,
|
|
7507
|
-
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
7508
|
-
kListener: Symbol("kListener"),
|
|
7509
|
-
kStatusCode: Symbol("status-code"),
|
|
7510
|
-
kWebSocket: Symbol("websocket"),
|
|
7511
|
-
NOOP: () => {}
|
|
7512
|
-
};
|
|
7513
|
-
}) });
|
|
7514
|
-
|
|
7515
|
-
//#endregion
|
|
7516
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js
|
|
7517
|
-
var require_buffer_util = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js": ((exports, module) => {
|
|
7518
|
-
const { EMPTY_BUFFER: EMPTY_BUFFER$3 } = require_constants();
|
|
7519
|
-
const FastBuffer$2 = Buffer[Symbol.species];
|
|
7520
|
-
/**
|
|
7521
|
-
* Merges an array of buffers into a new buffer.
|
|
7522
|
-
*
|
|
7523
|
-
* @param {Buffer[]} list The array of buffers to concat
|
|
7524
|
-
* @param {Number} totalLength The total length of buffers in the list
|
|
7525
|
-
* @return {Buffer} The resulting buffer
|
|
7526
|
-
* @public
|
|
7527
|
-
*/
|
|
7528
|
-
function concat$1(list$3, totalLength) {
|
|
7529
|
-
if (list$3.length === 0) return EMPTY_BUFFER$3;
|
|
7530
|
-
if (list$3.length === 1) return list$3[0];
|
|
7531
|
-
const target = Buffer.allocUnsafe(totalLength);
|
|
7532
|
-
let offset = 0;
|
|
7533
|
-
for (let i = 0; i < list$3.length; i++) {
|
|
7534
|
-
const buf = list$3[i];
|
|
7535
|
-
target.set(buf, offset);
|
|
7536
|
-
offset += buf.length;
|
|
7537
|
-
}
|
|
7538
|
-
if (offset < totalLength) return new FastBuffer$2(target.buffer, target.byteOffset, offset);
|
|
7539
|
-
return target;
|
|
7540
|
-
}
|
|
7541
|
-
/**
|
|
7542
|
-
* Masks a buffer using the given mask.
|
|
7543
|
-
*
|
|
7544
|
-
* @param {Buffer} source The buffer to mask
|
|
7545
|
-
* @param {Buffer} mask The mask to use
|
|
7546
|
-
* @param {Buffer} output The buffer where to store the result
|
|
7547
|
-
* @param {Number} offset The offset at which to start writing
|
|
7548
|
-
* @param {Number} length The number of bytes to mask.
|
|
7549
|
-
* @public
|
|
7550
|
-
*/
|
|
7551
|
-
function _mask(source, mask, output$1, offset, length) {
|
|
7552
|
-
for (let i = 0; i < length; i++) output$1[offset + i] = source[i] ^ mask[i & 3];
|
|
7553
|
-
}
|
|
7554
|
-
/**
|
|
7555
|
-
* Unmasks a buffer using the given mask.
|
|
7556
|
-
*
|
|
7557
|
-
* @param {Buffer} buffer The buffer to unmask
|
|
7558
|
-
* @param {Buffer} mask The mask to use
|
|
7559
|
-
* @public
|
|
7560
|
-
*/
|
|
7561
|
-
function _unmask(buffer, mask) {
|
|
7562
|
-
for (let i = 0; i < buffer.length; i++) buffer[i] ^= mask[i & 3];
|
|
7563
|
-
}
|
|
7564
|
-
/**
|
|
7565
|
-
* Converts a buffer to an `ArrayBuffer`.
|
|
7566
|
-
*
|
|
7567
|
-
* @param {Buffer} buf The buffer to convert
|
|
7568
|
-
* @return {ArrayBuffer} Converted buffer
|
|
7569
|
-
* @public
|
|
7570
|
-
*/
|
|
7571
|
-
function toArrayBuffer$1(buf) {
|
|
7572
|
-
if (buf.length === buf.buffer.byteLength) return buf.buffer;
|
|
7573
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
7574
|
-
}
|
|
7575
|
-
/**
|
|
7576
|
-
* Converts `data` to a `Buffer`.
|
|
7577
|
-
*
|
|
7578
|
-
* @param {*} data The data to convert
|
|
7579
|
-
* @return {Buffer} The buffer
|
|
7580
|
-
* @throws {TypeError}
|
|
7581
|
-
* @public
|
|
7582
|
-
*/
|
|
7583
|
-
function toBuffer$2(data) {
|
|
7584
|
-
toBuffer$2.readOnly = true;
|
|
7585
|
-
if (Buffer.isBuffer(data)) return data;
|
|
7586
|
-
let buf;
|
|
7587
|
-
if (data instanceof ArrayBuffer) buf = new FastBuffer$2(data);
|
|
7588
|
-
else if (ArrayBuffer.isView(data)) buf = new FastBuffer$2(data.buffer, data.byteOffset, data.byteLength);
|
|
7589
|
-
else {
|
|
7590
|
-
buf = Buffer.from(data);
|
|
7591
|
-
toBuffer$2.readOnly = false;
|
|
7592
|
-
}
|
|
7593
|
-
return buf;
|
|
7594
|
-
}
|
|
7595
|
-
module.exports = {
|
|
7596
|
-
concat: concat$1,
|
|
7597
|
-
mask: _mask,
|
|
7598
|
-
toArrayBuffer: toArrayBuffer$1,
|
|
7599
|
-
toBuffer: toBuffer$2,
|
|
7600
|
-
unmask: _unmask
|
|
7601
|
-
};
|
|
7602
|
-
/* istanbul ignore else */
|
|
7603
|
-
if (!process.env.WS_NO_BUFFER_UTIL) try {
|
|
7604
|
-
const bufferUtil$1 = __require$1("bufferutil");
|
|
7605
|
-
module.exports.mask = function(source, mask, output$1, offset, length) {
|
|
7606
|
-
if (length < 48) _mask(source, mask, output$1, offset, length);
|
|
7607
|
-
else bufferUtil$1.mask(source, mask, output$1, offset, length);
|
|
7608
|
-
};
|
|
7609
|
-
module.exports.unmask = function(buffer, mask) {
|
|
7610
|
-
if (buffer.length < 32) _unmask(buffer, mask);
|
|
7611
|
-
else bufferUtil$1.unmask(buffer, mask);
|
|
7612
|
-
};
|
|
7613
|
-
} catch (e) {}
|
|
7614
|
-
}) });
|
|
7615
|
-
|
|
7616
|
-
//#endregion
|
|
7617
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js
|
|
7618
|
-
var require_limiter = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js": ((exports, module) => {
|
|
7619
|
-
const kDone = Symbol("kDone");
|
|
7620
|
-
const kRun = Symbol("kRun");
|
|
7621
|
-
/**
|
|
7622
|
-
* A very simple job queue with adjustable concurrency. Adapted from
|
|
7623
|
-
* https://github.com/STRML/async-limiter
|
|
7624
|
-
*/
|
|
7625
|
-
var Limiter$1 = class {
|
|
7626
|
-
/**
|
|
7627
|
-
* Creates a new `Limiter`.
|
|
7628
|
-
*
|
|
7629
|
-
* @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
|
|
7630
|
-
* to run concurrently
|
|
7631
|
-
*/
|
|
7632
|
-
constructor(concurrency) {
|
|
7633
|
-
this[kDone] = () => {
|
|
7634
|
-
this.pending--;
|
|
7635
|
-
this[kRun]();
|
|
7636
|
-
};
|
|
7637
|
-
this.concurrency = concurrency || Infinity;
|
|
7638
|
-
this.jobs = [];
|
|
7639
|
-
this.pending = 0;
|
|
7640
|
-
}
|
|
7641
|
-
/**
|
|
7642
|
-
* Adds a job to the queue.
|
|
7643
|
-
*
|
|
7644
|
-
* @param {Function} job The job to run
|
|
7645
|
-
* @public
|
|
7646
|
-
*/
|
|
7647
|
-
add(job) {
|
|
7648
|
-
this.jobs.push(job);
|
|
7649
|
-
this[kRun]();
|
|
7650
|
-
}
|
|
7651
|
-
/**
|
|
7652
|
-
* Removes a job from the queue and runs it if possible.
|
|
7653
|
-
*
|
|
7654
|
-
* @private
|
|
7655
|
-
*/
|
|
7656
|
-
[kRun]() {
|
|
7657
|
-
if (this.pending === this.concurrency) return;
|
|
7658
|
-
if (this.jobs.length) {
|
|
7659
|
-
const job = this.jobs.shift();
|
|
7660
|
-
this.pending++;
|
|
7661
|
-
job(this[kDone]);
|
|
7662
|
-
}
|
|
7663
|
-
}
|
|
7664
|
-
};
|
|
7665
|
-
module.exports = Limiter$1;
|
|
7666
|
-
}) });
|
|
7489
|
+
//#region src/util/print-command.ts
|
|
7490
|
+
init_source();
|
|
7491
|
+
function printCommand(command$1, args$5) {
|
|
7492
|
+
return source_default.gray(source_default.dim("$ ") + [command$1, ...args$5].join(" "));
|
|
7493
|
+
}
|
|
7667
7494
|
|
|
7668
7495
|
//#endregion
|
|
7669
|
-
//#region
|
|
7670
|
-
var
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
const
|
|
7675
|
-
const
|
|
7676
|
-
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
const kError$1 = Symbol("error");
|
|
7687
|
-
let zlibLimiter;
|
|
7688
|
-
/**
|
|
7689
|
-
* permessage-deflate implementation.
|
|
7690
|
-
*/
|
|
7691
|
-
var PerMessageDeflate$4 = class {
|
|
7692
|
-
/**
|
|
7693
|
-
* Creates a PerMessageDeflate instance.
|
|
7694
|
-
*
|
|
7695
|
-
* @param {Object} [options] Configuration options
|
|
7696
|
-
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
|
|
7697
|
-
* for, or request, a custom client window size
|
|
7698
|
-
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
|
|
7699
|
-
* acknowledge disabling of client context takeover
|
|
7700
|
-
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
|
|
7701
|
-
* calls to zlib
|
|
7702
|
-
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
|
|
7703
|
-
* use of a custom server window size
|
|
7704
|
-
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
|
|
7705
|
-
* disabling of server context takeover
|
|
7706
|
-
* @param {Number} [options.threshold=1024] Size (in bytes) below which
|
|
7707
|
-
* messages should not be compressed if context takeover is disabled
|
|
7708
|
-
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
|
|
7709
|
-
* deflate
|
|
7710
|
-
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
|
|
7711
|
-
* inflate
|
|
7712
|
-
* @param {Boolean} [isServer=false] Create the instance in either server or
|
|
7713
|
-
* client mode
|
|
7714
|
-
* @param {Number} [maxPayload=0] The maximum allowed message length
|
|
7715
|
-
*/
|
|
7716
|
-
constructor(options, isServer, maxPayload) {
|
|
7717
|
-
this._maxPayload = maxPayload | 0;
|
|
7718
|
-
this._options = options || {};
|
|
7719
|
-
this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
|
|
7720
|
-
this._isServer = !!isServer;
|
|
7721
|
-
this._deflate = null;
|
|
7722
|
-
this._inflate = null;
|
|
7723
|
-
this.params = null;
|
|
7724
|
-
if (!zlibLimiter) zlibLimiter = new Limiter(this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10);
|
|
7725
|
-
}
|
|
7726
|
-
/**
|
|
7727
|
-
* @type {String}
|
|
7728
|
-
*/
|
|
7729
|
-
static get extensionName() {
|
|
7730
|
-
return "permessage-deflate";
|
|
7731
|
-
}
|
|
7732
|
-
/**
|
|
7733
|
-
* Create an extension negotiation offer.
|
|
7734
|
-
*
|
|
7735
|
-
* @return {Object} Extension parameters
|
|
7736
|
-
* @public
|
|
7737
|
-
*/
|
|
7738
|
-
offer() {
|
|
7739
|
-
const params = {};
|
|
7740
|
-
if (this._options.serverNoContextTakeover) params.server_no_context_takeover = true;
|
|
7741
|
-
if (this._options.clientNoContextTakeover) params.client_no_context_takeover = true;
|
|
7742
|
-
if (this._options.serverMaxWindowBits) params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
7743
|
-
if (this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
7744
|
-
else if (this._options.clientMaxWindowBits == null) params.client_max_window_bits = true;
|
|
7745
|
-
return params;
|
|
7746
|
-
}
|
|
7747
|
-
/**
|
|
7748
|
-
* Accept an extension negotiation offer/response.
|
|
7749
|
-
*
|
|
7750
|
-
* @param {Array} configurations The extension negotiation offers/reponse
|
|
7751
|
-
* @return {Object} Accepted configuration
|
|
7752
|
-
* @public
|
|
7753
|
-
*/
|
|
7754
|
-
accept(configurations) {
|
|
7755
|
-
configurations = this.normalizeParams(configurations);
|
|
7756
|
-
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
7757
|
-
return this.params;
|
|
7758
|
-
}
|
|
7759
|
-
/**
|
|
7760
|
-
* Releases all resources used by the extension.
|
|
7761
|
-
*
|
|
7762
|
-
* @public
|
|
7763
|
-
*/
|
|
7764
|
-
cleanup() {
|
|
7765
|
-
if (this._inflate) {
|
|
7766
|
-
this._inflate.close();
|
|
7767
|
-
this._inflate = null;
|
|
7768
|
-
}
|
|
7769
|
-
if (this._deflate) {
|
|
7770
|
-
const callback = this._deflate[kCallback];
|
|
7771
|
-
this._deflate.close();
|
|
7772
|
-
this._deflate = null;
|
|
7773
|
-
if (callback) callback(/* @__PURE__ */ new Error("The deflate stream was closed while data was being processed"));
|
|
7774
|
-
}
|
|
7775
|
-
}
|
|
7776
|
-
/**
|
|
7777
|
-
* Accept an extension negotiation offer.
|
|
7778
|
-
*
|
|
7779
|
-
* @param {Array} offers The extension negotiation offers
|
|
7780
|
-
* @return {Object} Accepted configuration
|
|
7781
|
-
* @private
|
|
7782
|
-
*/
|
|
7783
|
-
acceptAsServer(offers) {
|
|
7784
|
-
const opts = this._options;
|
|
7785
|
-
const accepted = offers.find((params) => {
|
|
7786
|
-
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) return false;
|
|
7787
|
-
return true;
|
|
7788
|
-
});
|
|
7789
|
-
if (!accepted) throw new Error("None of the extension offers can be accepted");
|
|
7790
|
-
if (opts.serverNoContextTakeover) accepted.server_no_context_takeover = true;
|
|
7791
|
-
if (opts.clientNoContextTakeover) accepted.client_no_context_takeover = true;
|
|
7792
|
-
if (typeof opts.serverMaxWindowBits === "number") accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
7793
|
-
if (typeof opts.clientMaxWindowBits === "number") accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
7794
|
-
else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) delete accepted.client_max_window_bits;
|
|
7795
|
-
return accepted;
|
|
7796
|
-
}
|
|
7797
|
-
/**
|
|
7798
|
-
* Accept the extension negotiation response.
|
|
7799
|
-
*
|
|
7800
|
-
* @param {Array} response The extension negotiation response
|
|
7801
|
-
* @return {Object} Accepted configuration
|
|
7802
|
-
* @private
|
|
7803
|
-
*/
|
|
7804
|
-
acceptAsClient(response) {
|
|
7805
|
-
const params = response[0];
|
|
7806
|
-
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) throw new Error("Unexpected parameter \"client_no_context_takeover\"");
|
|
7807
|
-
if (!params.client_max_window_bits) {
|
|
7808
|
-
if (typeof this._options.clientMaxWindowBits === "number") params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
7809
|
-
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) throw new Error("Unexpected or invalid parameter \"client_max_window_bits\"");
|
|
7810
|
-
return params;
|
|
7811
|
-
}
|
|
7812
|
-
/**
|
|
7813
|
-
* Normalize parameters.
|
|
7814
|
-
*
|
|
7815
|
-
* @param {Array} configurations The extension negotiation offers/reponse
|
|
7816
|
-
* @return {Array} The offers/response with normalized parameters
|
|
7817
|
-
* @private
|
|
7818
|
-
*/
|
|
7819
|
-
normalizeParams(configurations) {
|
|
7820
|
-
configurations.forEach((params) => {
|
|
7821
|
-
Object.keys(params).forEach((key) => {
|
|
7822
|
-
let value = params[key];
|
|
7823
|
-
if (value.length > 1) throw new Error(`Parameter "${key}" must have only a single value`);
|
|
7824
|
-
value = value[0];
|
|
7825
|
-
if (key === "client_max_window_bits") {
|
|
7826
|
-
if (value !== true) {
|
|
7827
|
-
const num = +value;
|
|
7828
|
-
if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
7829
|
-
value = num;
|
|
7830
|
-
} else if (!this._isServer) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
7831
|
-
} else if (key === "server_max_window_bits") {
|
|
7832
|
-
const num = +value;
|
|
7833
|
-
if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
7834
|
-
value = num;
|
|
7835
|
-
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
7836
|
-
if (value !== true) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
7837
|
-
} else throw new Error(`Unknown parameter "${key}"`);
|
|
7838
|
-
params[key] = value;
|
|
7839
|
-
});
|
|
7840
|
-
});
|
|
7841
|
-
return configurations;
|
|
7842
|
-
}
|
|
7843
|
-
/**
|
|
7844
|
-
* Decompress data. Concurrency limited.
|
|
7845
|
-
*
|
|
7846
|
-
* @param {Buffer} data Compressed data
|
|
7847
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
7848
|
-
* @param {Function} callback Callback
|
|
7849
|
-
* @public
|
|
7850
|
-
*/
|
|
7851
|
-
decompress(data, fin, callback) {
|
|
7852
|
-
zlibLimiter.add((done) => {
|
|
7853
|
-
this._decompress(data, fin, (err$1, result) => {
|
|
7854
|
-
done();
|
|
7855
|
-
callback(err$1, result);
|
|
7856
|
-
});
|
|
7857
|
-
});
|
|
7858
|
-
}
|
|
7859
|
-
/**
|
|
7860
|
-
* Compress data. Concurrency limited.
|
|
7861
|
-
*
|
|
7862
|
-
* @param {(Buffer|String)} data Data to compress
|
|
7863
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
7864
|
-
* @param {Function} callback Callback
|
|
7865
|
-
* @public
|
|
7866
|
-
*/
|
|
7867
|
-
compress(data, fin, callback) {
|
|
7868
|
-
zlibLimiter.add((done) => {
|
|
7869
|
-
this._compress(data, fin, (err$1, result) => {
|
|
7870
|
-
done();
|
|
7871
|
-
callback(err$1, result);
|
|
7872
|
-
});
|
|
7873
|
-
});
|
|
7874
|
-
}
|
|
7875
|
-
/**
|
|
7876
|
-
* Decompress data.
|
|
7877
|
-
*
|
|
7878
|
-
* @param {Buffer} data Compressed data
|
|
7879
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
7880
|
-
* @param {Function} callback Callback
|
|
7881
|
-
* @private
|
|
7882
|
-
*/
|
|
7883
|
-
_decompress(data, fin, callback) {
|
|
7884
|
-
const endpoint = this._isServer ? "client" : "server";
|
|
7885
|
-
if (!this._inflate) {
|
|
7886
|
-
const key = `${endpoint}_max_window_bits`;
|
|
7887
|
-
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
7888
|
-
this._inflate = zlib.createInflateRaw({
|
|
7889
|
-
...this._options.zlibInflateOptions,
|
|
7890
|
-
windowBits
|
|
7891
|
-
});
|
|
7892
|
-
this._inflate[kPerMessageDeflate] = this;
|
|
7893
|
-
this._inflate[kTotalLength] = 0;
|
|
7894
|
-
this._inflate[kBuffers] = [];
|
|
7895
|
-
this._inflate.on("error", inflateOnError);
|
|
7896
|
-
this._inflate.on("data", inflateOnData);
|
|
7897
|
-
}
|
|
7898
|
-
this._inflate[kCallback] = callback;
|
|
7899
|
-
this._inflate.write(data);
|
|
7900
|
-
if (fin) this._inflate.write(TRAILER);
|
|
7901
|
-
this._inflate.flush(() => {
|
|
7902
|
-
const err$1 = this._inflate[kError$1];
|
|
7903
|
-
if (err$1) {
|
|
7904
|
-
this._inflate.close();
|
|
7905
|
-
this._inflate = null;
|
|
7906
|
-
callback(err$1);
|
|
7907
|
-
return;
|
|
7908
|
-
}
|
|
7909
|
-
const data$1 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
7910
|
-
if (this._inflate._readableState.endEmitted) {
|
|
7911
|
-
this._inflate.close();
|
|
7912
|
-
this._inflate = null;
|
|
7913
|
-
} else {
|
|
7914
|
-
this._inflate[kTotalLength] = 0;
|
|
7915
|
-
this._inflate[kBuffers] = [];
|
|
7916
|
-
if (fin && this.params[`${endpoint}_no_context_takeover`]) this._inflate.reset();
|
|
7917
|
-
}
|
|
7918
|
-
callback(null, data$1);
|
|
7919
|
-
});
|
|
7920
|
-
}
|
|
7921
|
-
/**
|
|
7922
|
-
* Compress data.
|
|
7923
|
-
*
|
|
7924
|
-
* @param {(Buffer|String)} data Data to compress
|
|
7925
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
7926
|
-
* @param {Function} callback Callback
|
|
7927
|
-
* @private
|
|
7928
|
-
*/
|
|
7929
|
-
_compress(data, fin, callback) {
|
|
7930
|
-
const endpoint = this._isServer ? "server" : "client";
|
|
7931
|
-
if (!this._deflate) {
|
|
7932
|
-
const key = `${endpoint}_max_window_bits`;
|
|
7933
|
-
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
7934
|
-
this._deflate = zlib.createDeflateRaw({
|
|
7935
|
-
...this._options.zlibDeflateOptions,
|
|
7936
|
-
windowBits
|
|
7937
|
-
});
|
|
7938
|
-
this._deflate[kTotalLength] = 0;
|
|
7939
|
-
this._deflate[kBuffers] = [];
|
|
7940
|
-
this._deflate.on("data", deflateOnData);
|
|
7941
|
-
}
|
|
7942
|
-
this._deflate[kCallback] = callback;
|
|
7943
|
-
this._deflate.write(data);
|
|
7944
|
-
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
7945
|
-
if (!this._deflate) return;
|
|
7946
|
-
let data$1 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
7947
|
-
if (fin) data$1 = new FastBuffer$1(data$1.buffer, data$1.byteOffset, data$1.length - 4);
|
|
7948
|
-
this._deflate[kCallback] = null;
|
|
7949
|
-
this._deflate[kTotalLength] = 0;
|
|
7950
|
-
this._deflate[kBuffers] = [];
|
|
7951
|
-
if (fin && this.params[`${endpoint}_no_context_takeover`]) this._deflate.reset();
|
|
7952
|
-
callback(null, data$1);
|
|
7953
|
-
});
|
|
7954
|
-
}
|
|
7955
|
-
};
|
|
7956
|
-
module.exports = PerMessageDeflate$4;
|
|
7957
|
-
/**
|
|
7958
|
-
* The listener of the `zlib.DeflateRaw` stream `'data'` event.
|
|
7959
|
-
*
|
|
7960
|
-
* @param {Buffer} chunk A chunk of data
|
|
7961
|
-
* @private
|
|
7962
|
-
*/
|
|
7963
|
-
function deflateOnData(chunk) {
|
|
7964
|
-
this[kBuffers].push(chunk);
|
|
7965
|
-
this[kTotalLength] += chunk.length;
|
|
7966
|
-
}
|
|
7967
|
-
/**
|
|
7968
|
-
* The listener of the `zlib.InflateRaw` stream `'data'` event.
|
|
7969
|
-
*
|
|
7970
|
-
* @param {Buffer} chunk A chunk of data
|
|
7971
|
-
* @private
|
|
7972
|
-
*/
|
|
7973
|
-
function inflateOnData(chunk) {
|
|
7974
|
-
this[kTotalLength] += chunk.length;
|
|
7975
|
-
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
7976
|
-
this[kBuffers].push(chunk);
|
|
7977
|
-
return;
|
|
7978
|
-
}
|
|
7979
|
-
this[kError$1] = /* @__PURE__ */ new RangeError("Max payload size exceeded");
|
|
7980
|
-
this[kError$1].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
7981
|
-
this[kError$1][kStatusCode$2] = 1009;
|
|
7982
|
-
this.removeListener("data", inflateOnData);
|
|
7983
|
-
this.reset();
|
|
7984
|
-
}
|
|
7985
|
-
/**
|
|
7986
|
-
* The listener of the `zlib.InflateRaw` stream `'error'` event.
|
|
7987
|
-
*
|
|
7988
|
-
* @param {Error} err The emitted error
|
|
7989
|
-
* @private
|
|
7990
|
-
*/
|
|
7991
|
-
function inflateOnError(err$1) {
|
|
7992
|
-
this[kPerMessageDeflate]._inflate = null;
|
|
7993
|
-
if (this[kError$1]) {
|
|
7994
|
-
this[kCallback](this[kError$1]);
|
|
7995
|
-
return;
|
|
7496
|
+
//#region src/interactive-shell/extend-sandbox-timeout.ts
|
|
7497
|
+
var import_ms$6 = /* @__PURE__ */ __toESM(require_ms());
|
|
7498
|
+
const debug$2 = createDebugger("sandbox:timeout");
|
|
7499
|
+
const BUFFER = (0, import_ms$6.default)("10 seconds");
|
|
7500
|
+
async function extendSandboxTimeoutPeriodically(sandbox, signal) {
|
|
7501
|
+
const session = sandbox.currentSession();
|
|
7502
|
+
const timeout$1 = session.timeout;
|
|
7503
|
+
if (timeout$1 == null) return;
|
|
7504
|
+
const nextTick = session.createdAt.getTime() + timeout$1;
|
|
7505
|
+
debug$2(`next tick: ${new Date(nextTick).toISOString()}`);
|
|
7506
|
+
while (!signal.aborted) {
|
|
7507
|
+
const currentTimeout = session.timeout;
|
|
7508
|
+
if (currentTimeout == null) return;
|
|
7509
|
+
const sleepMs = session.createdAt.getTime() + currentTimeout - Date.now() - BUFFER;
|
|
7510
|
+
if (sleepMs > 2e3) {
|
|
7511
|
+
debug$2(`sleeping for ${sleepMs}ms until next timeout extension`);
|
|
7512
|
+
await setTimeout$1(sleepMs, null, { signal });
|
|
7996
7513
|
}
|
|
7997
|
-
|
|
7998
|
-
|
|
7514
|
+
await sandbox.extendTimeout((0, import_ms$6.default)("5 minutes"));
|
|
7515
|
+
const updatedTimeout = session.timeout;
|
|
7516
|
+
if (updatedTimeout == null) return;
|
|
7517
|
+
const nextTick$1 = session.createdAt.getTime() + updatedTimeout;
|
|
7518
|
+
debug$2(`extended sandbox timeout by 5 minutes. next tick: ${new Date(nextTick$1).toISOString()}`);
|
|
7999
7519
|
}
|
|
8000
|
-
}
|
|
7520
|
+
}
|
|
8001
7521
|
|
|
8002
7522
|
//#endregion
|
|
8003
|
-
//#region
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
0,
|
|
8034
|
-
0,
|
|
8035
|
-
0,
|
|
8036
|
-
0,
|
|
8037
|
-
0,
|
|
8038
|
-
0,
|
|
8039
|
-
0,
|
|
8040
|
-
0,
|
|
8041
|
-
1,
|
|
8042
|
-
0,
|
|
8043
|
-
1,
|
|
8044
|
-
1,
|
|
8045
|
-
1,
|
|
8046
|
-
1,
|
|
8047
|
-
1,
|
|
8048
|
-
0,
|
|
8049
|
-
0,
|
|
8050
|
-
1,
|
|
8051
|
-
1,
|
|
8052
|
-
0,
|
|
8053
|
-
1,
|
|
8054
|
-
1,
|
|
8055
|
-
0,
|
|
8056
|
-
1,
|
|
8057
|
-
1,
|
|
8058
|
-
1,
|
|
8059
|
-
1,
|
|
8060
|
-
1,
|
|
8061
|
-
1,
|
|
8062
|
-
1,
|
|
8063
|
-
1,
|
|
8064
|
-
1,
|
|
8065
|
-
1,
|
|
8066
|
-
0,
|
|
8067
|
-
0,
|
|
8068
|
-
0,
|
|
8069
|
-
0,
|
|
8070
|
-
0,
|
|
8071
|
-
0,
|
|
8072
|
-
0,
|
|
8073
|
-
1,
|
|
8074
|
-
1,
|
|
8075
|
-
1,
|
|
8076
|
-
1,
|
|
8077
|
-
1,
|
|
8078
|
-
1,
|
|
8079
|
-
1,
|
|
8080
|
-
1,
|
|
8081
|
-
1,
|
|
8082
|
-
1,
|
|
8083
|
-
1,
|
|
8084
|
-
1,
|
|
8085
|
-
1,
|
|
8086
|
-
1,
|
|
8087
|
-
1,
|
|
8088
|
-
1,
|
|
8089
|
-
1,
|
|
8090
|
-
1,
|
|
8091
|
-
1,
|
|
8092
|
-
1,
|
|
8093
|
-
1,
|
|
8094
|
-
1,
|
|
8095
|
-
1,
|
|
8096
|
-
1,
|
|
8097
|
-
1,
|
|
8098
|
-
1,
|
|
8099
|
-
0,
|
|
8100
|
-
0,
|
|
8101
|
-
0,
|
|
8102
|
-
1,
|
|
8103
|
-
1,
|
|
8104
|
-
1,
|
|
8105
|
-
1,
|
|
8106
|
-
1,
|
|
8107
|
-
1,
|
|
8108
|
-
1,
|
|
8109
|
-
1,
|
|
8110
|
-
1,
|
|
8111
|
-
1,
|
|
8112
|
-
1,
|
|
8113
|
-
1,
|
|
8114
|
-
1,
|
|
8115
|
-
1,
|
|
8116
|
-
1,
|
|
8117
|
-
1,
|
|
8118
|
-
1,
|
|
8119
|
-
1,
|
|
8120
|
-
1,
|
|
8121
|
-
1,
|
|
8122
|
-
1,
|
|
8123
|
-
1,
|
|
8124
|
-
1,
|
|
8125
|
-
1,
|
|
8126
|
-
1,
|
|
8127
|
-
1,
|
|
8128
|
-
1,
|
|
8129
|
-
1,
|
|
8130
|
-
1,
|
|
8131
|
-
0,
|
|
8132
|
-
1,
|
|
8133
|
-
0,
|
|
8134
|
-
1,
|
|
8135
|
-
0
|
|
8136
|
-
];
|
|
8137
|
-
/**
|
|
8138
|
-
* Checks if a status code is allowed in a close frame.
|
|
8139
|
-
*
|
|
8140
|
-
* @param {Number} code The status code
|
|
8141
|
-
* @return {Boolean} `true` if the status code is valid, else `false`
|
|
8142
|
-
* @public
|
|
8143
|
-
*/
|
|
8144
|
-
function isValidStatusCode$2(code) {
|
|
8145
|
-
return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
|
|
8146
|
-
}
|
|
8147
|
-
/**
|
|
8148
|
-
* Checks if a given buffer contains only correct UTF-8.
|
|
8149
|
-
* Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
|
|
8150
|
-
* Markus Kuhn.
|
|
8151
|
-
*
|
|
8152
|
-
* @param {Buffer} buf The buffer to check
|
|
8153
|
-
* @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
|
|
8154
|
-
* @public
|
|
8155
|
-
*/
|
|
8156
|
-
function _isValidUTF8(buf) {
|
|
8157
|
-
const len = buf.length;
|
|
8158
|
-
let i = 0;
|
|
8159
|
-
while (i < len) if ((buf[i] & 128) === 0) i++;
|
|
8160
|
-
else if ((buf[i] & 224) === 192) {
|
|
8161
|
-
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) return false;
|
|
8162
|
-
i += 2;
|
|
8163
|
-
} else if ((buf[i] & 240) === 224) {
|
|
8164
|
-
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) return false;
|
|
8165
|
-
i += 3;
|
|
8166
|
-
} else if ((buf[i] & 248) === 240) {
|
|
8167
|
-
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) return false;
|
|
8168
|
-
i += 4;
|
|
8169
|
-
} else return false;
|
|
8170
|
-
return true;
|
|
8171
|
-
}
|
|
8172
|
-
/**
|
|
8173
|
-
* Determines whether a value is a `Blob`.
|
|
8174
|
-
*
|
|
8175
|
-
* @param {*} value The value to be tested
|
|
8176
|
-
* @return {Boolean} `true` if `value` is a `Blob`, else `false`
|
|
8177
|
-
* @private
|
|
8178
|
-
*/
|
|
8179
|
-
function isBlob$2(value) {
|
|
8180
|
-
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");
|
|
8181
|
-
}
|
|
8182
|
-
module.exports = {
|
|
8183
|
-
isBlob: isBlob$2,
|
|
8184
|
-
isValidStatusCode: isValidStatusCode$2,
|
|
8185
|
-
isValidUTF8: _isValidUTF8,
|
|
8186
|
-
tokenChars: tokenChars$2
|
|
8187
|
-
};
|
|
8188
|
-
if (isUtf8) module.exports.isValidUTF8 = function(buf) {
|
|
8189
|
-
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
8190
|
-
};
|
|
8191
|
-
else if (!process.env.WS_NO_UTF_8_VALIDATE) try {
|
|
8192
|
-
const isValidUTF8$1 = __require$1("utf-8-validate");
|
|
8193
|
-
module.exports.isValidUTF8 = function(buf) {
|
|
8194
|
-
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8$1(buf);
|
|
7523
|
+
//#region src/interactive-shell/interactive-shell.ts
|
|
7524
|
+
init_source();
|
|
7525
|
+
const debug$1 = createDebugger("sandbox:interactive-shell");
|
|
7526
|
+
/**
|
|
7527
|
+
* A default TERM value so applications like `vim` and `nano` work properly.
|
|
7528
|
+
*/
|
|
7529
|
+
const TERM = "xterm-256color";
|
|
7530
|
+
/**
|
|
7531
|
+
* A custom prompt so interactive sessions show the Vercel triangle and the
|
|
7532
|
+
* working directory (e.g. `▲ /vercel/sandbox/ `) instead of the shell's
|
|
7533
|
+
* default prompt. The server passes this through to the shell verbatim.
|
|
7534
|
+
*/
|
|
7535
|
+
const PS1 = `▲ \\[\\e[2m\\]\\w/\\[\\e[0m\\] `;
|
|
7536
|
+
/**
|
|
7537
|
+
* Starts an interactive shell session with a sandbox. The API hands us a
|
|
7538
|
+
* WebSocket URL and token, and we tunnel stdin/stdout over it.
|
|
7539
|
+
*/
|
|
7540
|
+
async function startInteractiveShell(options) {
|
|
7541
|
+
try {
|
|
7542
|
+
var _usingCtx$1 = _usingCtx();
|
|
7543
|
+
let cleaned = false;
|
|
7544
|
+
const cleanup = () => {
|
|
7545
|
+
if (cleaned) return;
|
|
7546
|
+
process.stdin.removeAllListeners();
|
|
7547
|
+
try {
|
|
7548
|
+
process.stdin.setRawMode(false);
|
|
7549
|
+
process.stdin.pause();
|
|
7550
|
+
process.stdin.unref();
|
|
7551
|
+
} catch {}
|
|
7552
|
+
cleaned = true;
|
|
8195
7553
|
};
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
super();
|
|
8239
|
-
this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
|
|
8240
|
-
this._binaryType = options.binaryType || BINARY_TYPES$1[0];
|
|
8241
|
-
this._extensions = options.extensions || {};
|
|
8242
|
-
this._isServer = !!options.isServer;
|
|
8243
|
-
this._maxPayload = options.maxPayload | 0;
|
|
8244
|
-
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
8245
|
-
this[kWebSocket$3] = void 0;
|
|
8246
|
-
this._bufferedBytes = 0;
|
|
8247
|
-
this._buffers = [];
|
|
8248
|
-
this._compressed = false;
|
|
8249
|
-
this._payloadLength = 0;
|
|
8250
|
-
this._mask = void 0;
|
|
8251
|
-
this._fragmented = 0;
|
|
8252
|
-
this._masked = false;
|
|
8253
|
-
this._fin = false;
|
|
8254
|
-
this._opcode = 0;
|
|
8255
|
-
this._totalPayloadLength = 0;
|
|
8256
|
-
this._messageLength = 0;
|
|
8257
|
-
this._fragments = [];
|
|
8258
|
-
this._errored = false;
|
|
8259
|
-
this._loop = false;
|
|
8260
|
-
this._state = GET_INFO;
|
|
8261
|
-
}
|
|
8262
|
-
/**
|
|
8263
|
-
* Implements `Writable.prototype._write()`.
|
|
8264
|
-
*
|
|
8265
|
-
* @param {Buffer} chunk The chunk of data to write
|
|
8266
|
-
* @param {String} encoding The character encoding of `chunk`
|
|
8267
|
-
* @param {Function} cb Callback
|
|
8268
|
-
* @private
|
|
8269
|
-
*/
|
|
8270
|
-
_write(chunk, encoding, cb) {
|
|
8271
|
-
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
8272
|
-
this._bufferedBytes += chunk.length;
|
|
8273
|
-
this._buffers.push(chunk);
|
|
8274
|
-
this.startLoop(cb);
|
|
8275
|
-
}
|
|
8276
|
-
/**
|
|
8277
|
-
* Consumes `n` bytes from the buffered data.
|
|
8278
|
-
*
|
|
8279
|
-
* @param {Number} n The number of bytes to consume
|
|
8280
|
-
* @return {Buffer} The consumed bytes
|
|
8281
|
-
* @private
|
|
8282
|
-
*/
|
|
8283
|
-
consume(n) {
|
|
8284
|
-
this._bufferedBytes -= n;
|
|
8285
|
-
if (n === this._buffers[0].length) return this._buffers.shift();
|
|
8286
|
-
if (n < this._buffers[0].length) {
|
|
8287
|
-
const buf = this._buffers[0];
|
|
8288
|
-
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
8289
|
-
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
8290
|
-
}
|
|
8291
|
-
const dst = Buffer.allocUnsafe(n);
|
|
8292
|
-
do {
|
|
8293
|
-
const buf = this._buffers[0];
|
|
8294
|
-
const offset = dst.length - n;
|
|
8295
|
-
if (n >= buf.length) dst.set(this._buffers.shift(), offset);
|
|
8296
|
-
else {
|
|
8297
|
-
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
8298
|
-
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
8299
|
-
}
|
|
8300
|
-
n -= buf.length;
|
|
8301
|
-
} while (n > 0);
|
|
8302
|
-
return dst;
|
|
8303
|
-
}
|
|
8304
|
-
/**
|
|
8305
|
-
* Starts the parsing loop.
|
|
8306
|
-
*
|
|
8307
|
-
* @param {Function} cb Callback
|
|
8308
|
-
* @private
|
|
8309
|
-
*/
|
|
8310
|
-
startLoop(cb) {
|
|
8311
|
-
this._loop = true;
|
|
8312
|
-
do
|
|
8313
|
-
switch (this._state) {
|
|
8314
|
-
case GET_INFO:
|
|
8315
|
-
this.getInfo(cb);
|
|
8316
|
-
break;
|
|
8317
|
-
case GET_PAYLOAD_LENGTH_16:
|
|
8318
|
-
this.getPayloadLength16(cb);
|
|
8319
|
-
break;
|
|
8320
|
-
case GET_PAYLOAD_LENGTH_64:
|
|
8321
|
-
this.getPayloadLength64(cb);
|
|
8322
|
-
break;
|
|
8323
|
-
case GET_MASK:
|
|
8324
|
-
this.getMask();
|
|
8325
|
-
break;
|
|
8326
|
-
case GET_DATA:
|
|
8327
|
-
this.getData(cb);
|
|
8328
|
-
break;
|
|
8329
|
-
case INFLATING:
|
|
8330
|
-
case DEFER_EVENT:
|
|
8331
|
-
this._loop = false;
|
|
8332
|
-
return;
|
|
8333
|
-
}
|
|
8334
|
-
while (this._loop);
|
|
8335
|
-
if (!this._errored) cb();
|
|
8336
|
-
}
|
|
8337
|
-
/**
|
|
8338
|
-
* Reads the first two bytes of a frame.
|
|
8339
|
-
*
|
|
8340
|
-
* @param {Function} cb Callback
|
|
8341
|
-
* @private
|
|
8342
|
-
*/
|
|
8343
|
-
getInfo(cb) {
|
|
8344
|
-
if (this._bufferedBytes < 2) {
|
|
8345
|
-
this._loop = false;
|
|
8346
|
-
return;
|
|
8347
|
-
}
|
|
8348
|
-
const buf = this.consume(2);
|
|
8349
|
-
if ((buf[0] & 48) !== 0) {
|
|
8350
|
-
cb(this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3"));
|
|
8351
|
-
return;
|
|
8352
|
-
}
|
|
8353
|
-
const compressed = (buf[0] & 64) === 64;
|
|
8354
|
-
if (compressed && !this._extensions[PerMessageDeflate$3.extensionName]) {
|
|
8355
|
-
cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
|
|
8356
|
-
return;
|
|
8357
|
-
}
|
|
8358
|
-
this._fin = (buf[0] & 128) === 128;
|
|
8359
|
-
this._opcode = buf[0] & 15;
|
|
8360
|
-
this._payloadLength = buf[1] & 127;
|
|
8361
|
-
if (this._opcode === 0) {
|
|
8362
|
-
if (compressed) {
|
|
8363
|
-
cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
|
|
8364
|
-
return;
|
|
8365
|
-
}
|
|
8366
|
-
if (!this._fragmented) {
|
|
8367
|
-
cb(this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE"));
|
|
8368
|
-
return;
|
|
8369
|
-
}
|
|
8370
|
-
this._opcode = this._fragmented;
|
|
8371
|
-
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
8372
|
-
if (this._fragmented) {
|
|
8373
|
-
cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE"));
|
|
8374
|
-
return;
|
|
8375
|
-
}
|
|
8376
|
-
this._compressed = compressed;
|
|
8377
|
-
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
8378
|
-
if (!this._fin) {
|
|
8379
|
-
cb(this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN"));
|
|
8380
|
-
return;
|
|
8381
|
-
}
|
|
8382
|
-
if (compressed) {
|
|
8383
|
-
cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
|
|
8384
|
-
return;
|
|
8385
|
-
}
|
|
8386
|
-
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
8387
|
-
cb(this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"));
|
|
8388
|
-
return;
|
|
8389
|
-
}
|
|
8390
|
-
} else {
|
|
8391
|
-
cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE"));
|
|
8392
|
-
return;
|
|
8393
|
-
}
|
|
8394
|
-
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
8395
|
-
this._masked = (buf[1] & 128) === 128;
|
|
8396
|
-
if (this._isServer) {
|
|
8397
|
-
if (!this._masked) {
|
|
8398
|
-
cb(this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK"));
|
|
8399
|
-
return;
|
|
8400
|
-
}
|
|
8401
|
-
} else if (this._masked) {
|
|
8402
|
-
cb(this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK"));
|
|
8403
|
-
return;
|
|
8404
|
-
}
|
|
8405
|
-
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
8406
|
-
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
8407
|
-
else this.haveLength(cb);
|
|
8408
|
-
}
|
|
8409
|
-
/**
|
|
8410
|
-
* Gets extended payload length (7+16).
|
|
8411
|
-
*
|
|
8412
|
-
* @param {Function} cb Callback
|
|
8413
|
-
* @private
|
|
8414
|
-
*/
|
|
8415
|
-
getPayloadLength16(cb) {
|
|
8416
|
-
if (this._bufferedBytes < 2) {
|
|
8417
|
-
this._loop = false;
|
|
8418
|
-
return;
|
|
8419
|
-
}
|
|
8420
|
-
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
8421
|
-
this.haveLength(cb);
|
|
8422
|
-
}
|
|
8423
|
-
/**
|
|
8424
|
-
* Gets extended payload length (7+64).
|
|
8425
|
-
*
|
|
8426
|
-
* @param {Function} cb Callback
|
|
8427
|
-
* @private
|
|
8428
|
-
*/
|
|
8429
|
-
getPayloadLength64(cb) {
|
|
8430
|
-
if (this._bufferedBytes < 8) {
|
|
8431
|
-
this._loop = false;
|
|
8432
|
-
return;
|
|
8433
|
-
}
|
|
8434
|
-
const buf = this.consume(8);
|
|
8435
|
-
const num = buf.readUInt32BE(0);
|
|
8436
|
-
if (num > Math.pow(2, 21) - 1) {
|
|
8437
|
-
cb(this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"));
|
|
8438
|
-
return;
|
|
8439
|
-
}
|
|
8440
|
-
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
8441
|
-
this.haveLength(cb);
|
|
8442
|
-
}
|
|
8443
|
-
/**
|
|
8444
|
-
* Payload length has been read.
|
|
8445
|
-
*
|
|
8446
|
-
* @param {Function} cb Callback
|
|
8447
|
-
* @private
|
|
8448
|
-
*/
|
|
8449
|
-
haveLength(cb) {
|
|
8450
|
-
if (this._payloadLength && this._opcode < 8) {
|
|
8451
|
-
this._totalPayloadLength += this._payloadLength;
|
|
8452
|
-
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
8453
|
-
cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
|
|
8454
|
-
return;
|
|
8455
|
-
}
|
|
8456
|
-
}
|
|
8457
|
-
if (this._masked) this._state = GET_MASK;
|
|
8458
|
-
else this._state = GET_DATA;
|
|
8459
|
-
}
|
|
8460
|
-
/**
|
|
8461
|
-
* Reads mask bytes.
|
|
8462
|
-
*
|
|
8463
|
-
* @private
|
|
8464
|
-
*/
|
|
8465
|
-
getMask() {
|
|
8466
|
-
if (this._bufferedBytes < 4) {
|
|
8467
|
-
this._loop = false;
|
|
8468
|
-
return;
|
|
8469
|
-
}
|
|
8470
|
-
this._mask = this.consume(4);
|
|
8471
|
-
this._state = GET_DATA;
|
|
8472
|
-
}
|
|
8473
|
-
/**
|
|
8474
|
-
* Reads data bytes.
|
|
8475
|
-
*
|
|
8476
|
-
* @param {Function} cb Callback
|
|
8477
|
-
* @private
|
|
8478
|
-
*/
|
|
8479
|
-
getData(cb) {
|
|
8480
|
-
let data = EMPTY_BUFFER$2;
|
|
8481
|
-
if (this._payloadLength) {
|
|
8482
|
-
if (this._bufferedBytes < this._payloadLength) {
|
|
8483
|
-
this._loop = false;
|
|
8484
|
-
return;
|
|
8485
|
-
}
|
|
8486
|
-
data = this.consume(this._payloadLength);
|
|
8487
|
-
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
|
|
8488
|
-
}
|
|
8489
|
-
if (this._opcode > 7) {
|
|
8490
|
-
this.controlMessage(data, cb);
|
|
8491
|
-
return;
|
|
8492
|
-
}
|
|
8493
|
-
if (this._compressed) {
|
|
8494
|
-
this._state = INFLATING;
|
|
8495
|
-
this.decompress(data, cb);
|
|
8496
|
-
return;
|
|
8497
|
-
}
|
|
8498
|
-
if (data.length) {
|
|
8499
|
-
this._messageLength = this._totalPayloadLength;
|
|
8500
|
-
this._fragments.push(data);
|
|
8501
|
-
}
|
|
8502
|
-
this.dataMessage(cb);
|
|
8503
|
-
}
|
|
8504
|
-
/**
|
|
8505
|
-
* Decompresses data.
|
|
8506
|
-
*
|
|
8507
|
-
* @param {Buffer} data Compressed data
|
|
8508
|
-
* @param {Function} cb Callback
|
|
8509
|
-
* @private
|
|
8510
|
-
*/
|
|
8511
|
-
decompress(data, cb) {
|
|
8512
|
-
this._extensions[PerMessageDeflate$3.extensionName].decompress(data, this._fin, (err$1, buf) => {
|
|
8513
|
-
if (err$1) return cb(err$1);
|
|
8514
|
-
if (buf.length) {
|
|
8515
|
-
this._messageLength += buf.length;
|
|
8516
|
-
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
8517
|
-
cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
|
|
8518
|
-
return;
|
|
8519
|
-
}
|
|
8520
|
-
this._fragments.push(buf);
|
|
8521
|
-
}
|
|
8522
|
-
this.dataMessage(cb);
|
|
8523
|
-
if (this._state === GET_INFO) this.startLoop(cb);
|
|
8524
|
-
});
|
|
8525
|
-
}
|
|
8526
|
-
/**
|
|
8527
|
-
* Handles a data message.
|
|
8528
|
-
*
|
|
8529
|
-
* @param {Function} cb Callback
|
|
8530
|
-
* @private
|
|
8531
|
-
*/
|
|
8532
|
-
dataMessage(cb) {
|
|
8533
|
-
if (!this._fin) {
|
|
8534
|
-
this._state = GET_INFO;
|
|
8535
|
-
return;
|
|
8536
|
-
}
|
|
8537
|
-
const messageLength = this._messageLength;
|
|
8538
|
-
const fragments = this._fragments;
|
|
8539
|
-
this._totalPayloadLength = 0;
|
|
8540
|
-
this._messageLength = 0;
|
|
8541
|
-
this._fragmented = 0;
|
|
8542
|
-
this._fragments = [];
|
|
8543
|
-
if (this._opcode === 2) {
|
|
8544
|
-
let data;
|
|
8545
|
-
if (this._binaryType === "nodebuffer") data = concat(fragments, messageLength);
|
|
8546
|
-
else if (this._binaryType === "arraybuffer") data = toArrayBuffer(concat(fragments, messageLength));
|
|
8547
|
-
else if (this._binaryType === "blob") data = new Blob(fragments);
|
|
8548
|
-
else data = fragments;
|
|
8549
|
-
if (this._allowSynchronousEvents) {
|
|
8550
|
-
this.emit("message", data, true);
|
|
8551
|
-
this._state = GET_INFO;
|
|
8552
|
-
} else {
|
|
8553
|
-
this._state = DEFER_EVENT;
|
|
8554
|
-
setImmediate(() => {
|
|
8555
|
-
this.emit("message", data, true);
|
|
8556
|
-
this._state = GET_INFO;
|
|
8557
|
-
this.startLoop(cb);
|
|
8558
|
-
});
|
|
8559
|
-
}
|
|
8560
|
-
} else {
|
|
8561
|
-
const buf = concat(fragments, messageLength);
|
|
8562
|
-
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
8563
|
-
cb(this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8"));
|
|
8564
|
-
return;
|
|
8565
|
-
}
|
|
8566
|
-
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
8567
|
-
this.emit("message", buf, false);
|
|
8568
|
-
this._state = GET_INFO;
|
|
8569
|
-
} else {
|
|
8570
|
-
this._state = DEFER_EVENT;
|
|
8571
|
-
setImmediate(() => {
|
|
8572
|
-
this.emit("message", buf, false);
|
|
8573
|
-
this._state = GET_INFO;
|
|
8574
|
-
this.startLoop(cb);
|
|
8575
|
-
});
|
|
8576
|
-
}
|
|
8577
|
-
}
|
|
8578
|
-
}
|
|
8579
|
-
/**
|
|
8580
|
-
* Handles a control message.
|
|
8581
|
-
*
|
|
8582
|
-
* @param {Buffer} data Data to handle
|
|
8583
|
-
* @return {(Error|RangeError|undefined)} A possible error
|
|
8584
|
-
* @private
|
|
8585
|
-
*/
|
|
8586
|
-
controlMessage(data, cb) {
|
|
8587
|
-
if (this._opcode === 8) {
|
|
8588
|
-
if (data.length === 0) {
|
|
8589
|
-
this._loop = false;
|
|
8590
|
-
this.emit("conclude", 1005, EMPTY_BUFFER$2);
|
|
8591
|
-
this.end();
|
|
8592
|
-
} else {
|
|
8593
|
-
const code = data.readUInt16BE(0);
|
|
8594
|
-
if (!isValidStatusCode$1(code)) {
|
|
8595
|
-
cb(this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE"));
|
|
8596
|
-
return;
|
|
8597
|
-
}
|
|
8598
|
-
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
8599
|
-
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
8600
|
-
cb(this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8"));
|
|
8601
|
-
return;
|
|
8602
|
-
}
|
|
8603
|
-
this._loop = false;
|
|
8604
|
-
this.emit("conclude", code, buf);
|
|
8605
|
-
this.end();
|
|
8606
|
-
}
|
|
8607
|
-
this._state = GET_INFO;
|
|
7554
|
+
process.once("beforeExit", cleanup);
|
|
7555
|
+
const _cleanup = _usingCtx$1.u(defer(cleanup));
|
|
7556
|
+
const progress = _usingCtx$1.u(acquireRelease(() => ora({ discardStdin: false }).start(), (s$1) => s$1.stop()));
|
|
7557
|
+
progress.text = "Opening interactive session...";
|
|
7558
|
+
const { url, token: token$1 } = await options.sandbox.openInteractive();
|
|
7559
|
+
const [command$1, ...args$5] = options.execution;
|
|
7560
|
+
const execution = options.sudo ? [
|
|
7561
|
+
"sudo",
|
|
7562
|
+
command$1,
|
|
7563
|
+
...args$5
|
|
7564
|
+
] : [command$1, ...args$5];
|
|
7565
|
+
progress.text = "Connecting...";
|
|
7566
|
+
const client = new WebSocket(`${url}?token=${encodeURIComponent(token$1)}`);
|
|
7567
|
+
const _client = _usingCtx$1.u(defer(() => {
|
|
7568
|
+
try {
|
|
7569
|
+
client.close();
|
|
7570
|
+
} catch {}
|
|
7571
|
+
}));
|
|
7572
|
+
await new Promise((resolve, reject) => {
|
|
7573
|
+
client.once("open", () => resolve());
|
|
7574
|
+
client.once("error", (err$1) => reject(err$1));
|
|
7575
|
+
});
|
|
7576
|
+
debug$1("connected to %s", url);
|
|
7577
|
+
client.send(JSON.stringify({
|
|
7578
|
+
type: "start",
|
|
7579
|
+
command: execution[0],
|
|
7580
|
+
args: execution.slice(1),
|
|
7581
|
+
env: toEnvArray({
|
|
7582
|
+
TERM,
|
|
7583
|
+
PS1,
|
|
7584
|
+
...options.envVars
|
|
7585
|
+
}),
|
|
7586
|
+
cwd: options.cwd ?? options.sandbox.cwd,
|
|
7587
|
+
cols: process.stdout.columns,
|
|
7588
|
+
rows: process.stdout.rows
|
|
7589
|
+
}));
|
|
7590
|
+
progress.stop();
|
|
7591
|
+
const extension = _usingCtx$1.u(createAbortController("stopped extensions"));
|
|
7592
|
+
if (!options.skipExtendingTimeout) extendSandboxTimeoutPeriodically(options.sandbox, extension.signal).catch(extension.ignoreInterruptions);
|
|
7593
|
+
client.on("message", (data, isBinary) => {
|
|
7594
|
+
if (isBinary) {
|
|
7595
|
+
process.stdout.write(data);
|
|
8608
7596
|
return;
|
|
8609
7597
|
}
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
}
|
|
8614
|
-
|
|
8615
|
-
setImmediate(() => {
|
|
8616
|
-
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
8617
|
-
this._state = GET_INFO;
|
|
8618
|
-
this.startLoop(cb);
|
|
8619
|
-
});
|
|
7598
|
+
try {
|
|
7599
|
+
const msg = JSON.parse(data.toString());
|
|
7600
|
+
if (msg.type === "exit") process.exitCode = typeof msg.code === "number" ? msg.code : void 0;
|
|
7601
|
+
} catch {
|
|
7602
|
+
process.stdout.write(data);
|
|
8620
7603
|
}
|
|
8621
|
-
}
|
|
8622
|
-
/**
|
|
8623
|
-
* Builds an error object.
|
|
8624
|
-
*
|
|
8625
|
-
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
8626
|
-
* @param {String} message The error message
|
|
8627
|
-
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
8628
|
-
* `message`
|
|
8629
|
-
* @param {Number} statusCode The status code
|
|
8630
|
-
* @param {String} errorCode The exposed error code
|
|
8631
|
-
* @return {(Error|RangeError)} The error
|
|
8632
|
-
* @private
|
|
8633
|
-
*/
|
|
8634
|
-
createError(ErrorCtor, message, prefix$1, statusCode, errorCode) {
|
|
8635
|
-
this._loop = false;
|
|
8636
|
-
this._errored = true;
|
|
8637
|
-
const err$1 = new ErrorCtor(prefix$1 ? `Invalid WebSocket frame: ${message}` : message);
|
|
8638
|
-
Error.captureStackTrace(err$1, this.createError);
|
|
8639
|
-
err$1.code = errorCode;
|
|
8640
|
-
err$1[kStatusCode$1] = statusCode;
|
|
8641
|
-
return err$1;
|
|
8642
|
-
}
|
|
8643
|
-
};
|
|
8644
|
-
module.exports = Receiver$2;
|
|
8645
|
-
}) });
|
|
8646
|
-
|
|
8647
|
-
//#endregion
|
|
8648
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js
|
|
8649
|
-
var require_sender = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js": ((exports, module) => {
|
|
8650
|
-
const { Duplex: Duplex$3 } = __require$1("stream");
|
|
8651
|
-
const { randomFillSync } = __require$1("crypto");
|
|
8652
|
-
const PerMessageDeflate$2 = require_permessage_deflate();
|
|
8653
|
-
const { EMPTY_BUFFER: EMPTY_BUFFER$1, kWebSocket: kWebSocket$2, NOOP: NOOP$1 } = require_constants();
|
|
8654
|
-
const { isBlob: isBlob$1, isValidStatusCode } = require_validation();
|
|
8655
|
-
const { mask: applyMask, toBuffer: toBuffer$1 } = require_buffer_util();
|
|
8656
|
-
const kByteLength = Symbol("kByteLength");
|
|
8657
|
-
const maskBuffer = Buffer.alloc(4);
|
|
8658
|
-
const RANDOM_POOL_SIZE = 8 * 1024;
|
|
8659
|
-
let randomPool;
|
|
8660
|
-
let randomPoolPointer = RANDOM_POOL_SIZE;
|
|
8661
|
-
const DEFAULT = 0;
|
|
8662
|
-
const DEFLATING = 1;
|
|
8663
|
-
const GET_BLOB_DATA = 2;
|
|
8664
|
-
/**
|
|
8665
|
-
* HyBi Sender implementation.
|
|
8666
|
-
*/
|
|
8667
|
-
var Sender$2 = class Sender$2 {
|
|
8668
|
-
/**
|
|
8669
|
-
* Creates a Sender instance.
|
|
8670
|
-
*
|
|
8671
|
-
* @param {Duplex} socket The connection socket
|
|
8672
|
-
* @param {Object} [extensions] An object containing the negotiated extensions
|
|
8673
|
-
* @param {Function} [generateMask] The function used to generate the masking
|
|
8674
|
-
* key
|
|
8675
|
-
*/
|
|
8676
|
-
constructor(socket, extensions, generateMask) {
|
|
8677
|
-
this._extensions = extensions || {};
|
|
8678
|
-
if (generateMask) {
|
|
8679
|
-
this._generateMask = generateMask;
|
|
8680
|
-
this._maskBuffer = Buffer.alloc(4);
|
|
8681
|
-
}
|
|
8682
|
-
this._socket = socket;
|
|
8683
|
-
this._firstFragment = true;
|
|
8684
|
-
this._compress = false;
|
|
8685
|
-
this._bufferedBytes = 0;
|
|
8686
|
-
this._queue = [];
|
|
8687
|
-
this._state = DEFAULT;
|
|
8688
|
-
this.onerror = NOOP$1;
|
|
8689
|
-
this[kWebSocket$2] = void 0;
|
|
8690
|
-
}
|
|
8691
|
-
/**
|
|
8692
|
-
* Frames a piece of data according to the HyBi WebSocket protocol.
|
|
8693
|
-
*
|
|
8694
|
-
* @param {(Buffer|String)} data The data to frame
|
|
8695
|
-
* @param {Object} options Options object
|
|
8696
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
8697
|
-
* FIN bit
|
|
8698
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
8699
|
-
* masking key
|
|
8700
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
8701
|
-
* `data`
|
|
8702
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
8703
|
-
* key
|
|
8704
|
-
* @param {Number} options.opcode The opcode
|
|
8705
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
8706
|
-
* modified
|
|
8707
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
8708
|
-
* RSV1 bit
|
|
8709
|
-
* @return {(Buffer|String)[]} The framed data
|
|
8710
|
-
* @public
|
|
8711
|
-
*/
|
|
8712
|
-
static frame(data, options) {
|
|
8713
|
-
let mask;
|
|
8714
|
-
let merge = false;
|
|
8715
|
-
let offset = 2;
|
|
8716
|
-
let skipMasking = false;
|
|
8717
|
-
if (options.mask) {
|
|
8718
|
-
mask = options.maskBuffer || maskBuffer;
|
|
8719
|
-
if (options.generateMask) options.generateMask(mask);
|
|
8720
|
-
else {
|
|
8721
|
-
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
8722
|
-
/* istanbul ignore else */
|
|
8723
|
-
if (randomPool === void 0) randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
8724
|
-
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
8725
|
-
randomPoolPointer = 0;
|
|
8726
|
-
}
|
|
8727
|
-
mask[0] = randomPool[randomPoolPointer++];
|
|
8728
|
-
mask[1] = randomPool[randomPoolPointer++];
|
|
8729
|
-
mask[2] = randomPool[randomPoolPointer++];
|
|
8730
|
-
mask[3] = randomPool[randomPoolPointer++];
|
|
8731
|
-
}
|
|
8732
|
-
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
8733
|
-
offset = 6;
|
|
8734
|
-
}
|
|
8735
|
-
let dataLength;
|
|
8736
|
-
if (typeof data === "string") if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) dataLength = options[kByteLength];
|
|
8737
|
-
else {
|
|
8738
|
-
data = Buffer.from(data);
|
|
8739
|
-
dataLength = data.length;
|
|
8740
|
-
}
|
|
8741
|
-
else {
|
|
8742
|
-
dataLength = data.length;
|
|
8743
|
-
merge = options.mask && options.readOnly && !skipMasking;
|
|
8744
|
-
}
|
|
8745
|
-
let payloadLength = dataLength;
|
|
8746
|
-
if (dataLength >= 65536) {
|
|
8747
|
-
offset += 8;
|
|
8748
|
-
payloadLength = 127;
|
|
8749
|
-
} else if (dataLength > 125) {
|
|
8750
|
-
offset += 2;
|
|
8751
|
-
payloadLength = 126;
|
|
8752
|
-
}
|
|
8753
|
-
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
8754
|
-
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
8755
|
-
if (options.rsv1) target[0] |= 64;
|
|
8756
|
-
target[1] = payloadLength;
|
|
8757
|
-
if (payloadLength === 126) target.writeUInt16BE(dataLength, 2);
|
|
8758
|
-
else if (payloadLength === 127) {
|
|
8759
|
-
target[2] = target[3] = 0;
|
|
8760
|
-
target.writeUIntBE(dataLength, 4, 6);
|
|
8761
|
-
}
|
|
8762
|
-
if (!options.mask) return [target, data];
|
|
8763
|
-
target[1] |= 128;
|
|
8764
|
-
target[offset - 4] = mask[0];
|
|
8765
|
-
target[offset - 3] = mask[1];
|
|
8766
|
-
target[offset - 2] = mask[2];
|
|
8767
|
-
target[offset - 1] = mask[3];
|
|
8768
|
-
if (skipMasking) return [target, data];
|
|
8769
|
-
if (merge) {
|
|
8770
|
-
applyMask(data, mask, target, offset, dataLength);
|
|
8771
|
-
return [target];
|
|
8772
|
-
}
|
|
8773
|
-
applyMask(data, mask, data, 0, dataLength);
|
|
8774
|
-
return [target, data];
|
|
8775
|
-
}
|
|
8776
|
-
/**
|
|
8777
|
-
* Sends a close message to the other peer.
|
|
8778
|
-
*
|
|
8779
|
-
* @param {Number} [code] The status code component of the body
|
|
8780
|
-
* @param {(String|Buffer)} [data] The message component of the body
|
|
8781
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask the message
|
|
8782
|
-
* @param {Function} [cb] Callback
|
|
8783
|
-
* @public
|
|
8784
|
-
*/
|
|
8785
|
-
close(code, data, mask, cb) {
|
|
8786
|
-
let buf;
|
|
8787
|
-
if (code === void 0) buf = EMPTY_BUFFER$1;
|
|
8788
|
-
else if (typeof code !== "number" || !isValidStatusCode(code)) throw new TypeError("First argument must be a valid error code number");
|
|
8789
|
-
else if (data === void 0 || !data.length) {
|
|
8790
|
-
buf = Buffer.allocUnsafe(2);
|
|
8791
|
-
buf.writeUInt16BE(code, 0);
|
|
8792
|
-
} else {
|
|
8793
|
-
const length = Buffer.byteLength(data);
|
|
8794
|
-
if (length > 123) throw new RangeError("The message must not be greater than 123 bytes");
|
|
8795
|
-
buf = Buffer.allocUnsafe(2 + length);
|
|
8796
|
-
buf.writeUInt16BE(code, 0);
|
|
8797
|
-
if (typeof data === "string") buf.write(data, 2);
|
|
8798
|
-
else buf.set(data, 2);
|
|
8799
|
-
}
|
|
8800
|
-
const options = {
|
|
8801
|
-
[kByteLength]: buf.length,
|
|
8802
|
-
fin: true,
|
|
8803
|
-
generateMask: this._generateMask,
|
|
8804
|
-
mask,
|
|
8805
|
-
maskBuffer: this._maskBuffer,
|
|
8806
|
-
opcode: 8,
|
|
8807
|
-
readOnly: false,
|
|
8808
|
-
rsv1: false
|
|
8809
|
-
};
|
|
8810
|
-
if (this._state !== DEFAULT) this.enqueue([
|
|
8811
|
-
this.dispatch,
|
|
8812
|
-
buf,
|
|
8813
|
-
false,
|
|
8814
|
-
options,
|
|
8815
|
-
cb
|
|
8816
|
-
]);
|
|
8817
|
-
else this.sendFrame(Sender$2.frame(buf, options), cb);
|
|
8818
|
-
}
|
|
8819
|
-
/**
|
|
8820
|
-
* Sends a ping message to the other peer.
|
|
8821
|
-
*
|
|
8822
|
-
* @param {*} data The message to send
|
|
8823
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
8824
|
-
* @param {Function} [cb] Callback
|
|
8825
|
-
* @public
|
|
8826
|
-
*/
|
|
8827
|
-
ping(data, mask, cb) {
|
|
8828
|
-
let byteLength;
|
|
8829
|
-
let readOnly;
|
|
8830
|
-
if (typeof data === "string") {
|
|
8831
|
-
byteLength = Buffer.byteLength(data);
|
|
8832
|
-
readOnly = false;
|
|
8833
|
-
} else if (isBlob$1(data)) {
|
|
8834
|
-
byteLength = data.size;
|
|
8835
|
-
readOnly = false;
|
|
8836
|
-
} else {
|
|
8837
|
-
data = toBuffer$1(data);
|
|
8838
|
-
byteLength = data.length;
|
|
8839
|
-
readOnly = toBuffer$1.readOnly;
|
|
8840
|
-
}
|
|
8841
|
-
if (byteLength > 125) throw new RangeError("The data size must not be greater than 125 bytes");
|
|
8842
|
-
const options = {
|
|
8843
|
-
[kByteLength]: byteLength,
|
|
8844
|
-
fin: true,
|
|
8845
|
-
generateMask: this._generateMask,
|
|
8846
|
-
mask,
|
|
8847
|
-
maskBuffer: this._maskBuffer,
|
|
8848
|
-
opcode: 9,
|
|
8849
|
-
readOnly,
|
|
8850
|
-
rsv1: false
|
|
8851
|
-
};
|
|
8852
|
-
if (isBlob$1(data)) if (this._state !== DEFAULT) this.enqueue([
|
|
8853
|
-
this.getBlobData,
|
|
8854
|
-
data,
|
|
8855
|
-
false,
|
|
8856
|
-
options,
|
|
8857
|
-
cb
|
|
8858
|
-
]);
|
|
8859
|
-
else this.getBlobData(data, false, options, cb);
|
|
8860
|
-
else if (this._state !== DEFAULT) this.enqueue([
|
|
8861
|
-
this.dispatch,
|
|
8862
|
-
data,
|
|
8863
|
-
false,
|
|
8864
|
-
options,
|
|
8865
|
-
cb
|
|
8866
|
-
]);
|
|
8867
|
-
else this.sendFrame(Sender$2.frame(data, options), cb);
|
|
8868
|
-
}
|
|
8869
|
-
/**
|
|
8870
|
-
* Sends a pong message to the other peer.
|
|
8871
|
-
*
|
|
8872
|
-
* @param {*} data The message to send
|
|
8873
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
8874
|
-
* @param {Function} [cb] Callback
|
|
8875
|
-
* @public
|
|
8876
|
-
*/
|
|
8877
|
-
pong(data, mask, cb) {
|
|
8878
|
-
let byteLength;
|
|
8879
|
-
let readOnly;
|
|
8880
|
-
if (typeof data === "string") {
|
|
8881
|
-
byteLength = Buffer.byteLength(data);
|
|
8882
|
-
readOnly = false;
|
|
8883
|
-
} else if (isBlob$1(data)) {
|
|
8884
|
-
byteLength = data.size;
|
|
8885
|
-
readOnly = false;
|
|
8886
|
-
} else {
|
|
8887
|
-
data = toBuffer$1(data);
|
|
8888
|
-
byteLength = data.length;
|
|
8889
|
-
readOnly = toBuffer$1.readOnly;
|
|
8890
|
-
}
|
|
8891
|
-
if (byteLength > 125) throw new RangeError("The data size must not be greater than 125 bytes");
|
|
8892
|
-
const options = {
|
|
8893
|
-
[kByteLength]: byteLength,
|
|
8894
|
-
fin: true,
|
|
8895
|
-
generateMask: this._generateMask,
|
|
8896
|
-
mask,
|
|
8897
|
-
maskBuffer: this._maskBuffer,
|
|
8898
|
-
opcode: 10,
|
|
8899
|
-
readOnly,
|
|
8900
|
-
rsv1: false
|
|
8901
|
-
};
|
|
8902
|
-
if (isBlob$1(data)) if (this._state !== DEFAULT) this.enqueue([
|
|
8903
|
-
this.getBlobData,
|
|
8904
|
-
data,
|
|
8905
|
-
false,
|
|
8906
|
-
options,
|
|
8907
|
-
cb
|
|
8908
|
-
]);
|
|
8909
|
-
else this.getBlobData(data, false, options, cb);
|
|
8910
|
-
else if (this._state !== DEFAULT) this.enqueue([
|
|
8911
|
-
this.dispatch,
|
|
8912
|
-
data,
|
|
8913
|
-
false,
|
|
8914
|
-
options,
|
|
8915
|
-
cb
|
|
8916
|
-
]);
|
|
8917
|
-
else this.sendFrame(Sender$2.frame(data, options), cb);
|
|
8918
|
-
}
|
|
8919
|
-
/**
|
|
8920
|
-
* Sends a data message to the other peer.
|
|
8921
|
-
*
|
|
8922
|
-
* @param {*} data The message to send
|
|
8923
|
-
* @param {Object} options Options object
|
|
8924
|
-
* @param {Boolean} [options.binary=false] Specifies whether `data` is binary
|
|
8925
|
-
* or text
|
|
8926
|
-
* @param {Boolean} [options.compress=false] Specifies whether or not to
|
|
8927
|
-
* compress `data`
|
|
8928
|
-
* @param {Boolean} [options.fin=false] Specifies whether the fragment is the
|
|
8929
|
-
* last one
|
|
8930
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
8931
|
-
* `data`
|
|
8932
|
-
* @param {Function} [cb] Callback
|
|
8933
|
-
* @public
|
|
8934
|
-
*/
|
|
8935
|
-
send(data, options, cb) {
|
|
8936
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate$2.extensionName];
|
|
8937
|
-
let opcode = options.binary ? 2 : 1;
|
|
8938
|
-
let rsv1 = options.compress;
|
|
8939
|
-
let byteLength;
|
|
8940
|
-
let readOnly;
|
|
8941
|
-
if (typeof data === "string") {
|
|
8942
|
-
byteLength = Buffer.byteLength(data);
|
|
8943
|
-
readOnly = false;
|
|
8944
|
-
} else if (isBlob$1(data)) {
|
|
8945
|
-
byteLength = data.size;
|
|
8946
|
-
readOnly = false;
|
|
8947
|
-
} else {
|
|
8948
|
-
data = toBuffer$1(data);
|
|
8949
|
-
byteLength = data.length;
|
|
8950
|
-
readOnly = toBuffer$1.readOnly;
|
|
8951
|
-
}
|
|
8952
|
-
if (this._firstFragment) {
|
|
8953
|
-
this._firstFragment = false;
|
|
8954
|
-
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
8955
|
-
this._compress = rsv1;
|
|
8956
|
-
} else {
|
|
8957
|
-
rsv1 = false;
|
|
8958
|
-
opcode = 0;
|
|
8959
|
-
}
|
|
8960
|
-
if (options.fin) this._firstFragment = true;
|
|
8961
|
-
const opts = {
|
|
8962
|
-
[kByteLength]: byteLength,
|
|
8963
|
-
fin: options.fin,
|
|
8964
|
-
generateMask: this._generateMask,
|
|
8965
|
-
mask: options.mask,
|
|
8966
|
-
maskBuffer: this._maskBuffer,
|
|
8967
|
-
opcode,
|
|
8968
|
-
readOnly,
|
|
8969
|
-
rsv1
|
|
8970
|
-
};
|
|
8971
|
-
if (isBlob$1(data)) if (this._state !== DEFAULT) this.enqueue([
|
|
8972
|
-
this.getBlobData,
|
|
8973
|
-
data,
|
|
8974
|
-
this._compress,
|
|
8975
|
-
opts,
|
|
8976
|
-
cb
|
|
8977
|
-
]);
|
|
8978
|
-
else this.getBlobData(data, this._compress, opts, cb);
|
|
8979
|
-
else if (this._state !== DEFAULT) this.enqueue([
|
|
8980
|
-
this.dispatch,
|
|
8981
|
-
data,
|
|
8982
|
-
this._compress,
|
|
8983
|
-
opts,
|
|
8984
|
-
cb
|
|
8985
|
-
]);
|
|
8986
|
-
else this.dispatch(data, this._compress, opts, cb);
|
|
8987
|
-
}
|
|
8988
|
-
/**
|
|
8989
|
-
* Gets the contents of a blob as binary data.
|
|
8990
|
-
*
|
|
8991
|
-
* @param {Blob} blob The blob
|
|
8992
|
-
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
8993
|
-
* the data
|
|
8994
|
-
* @param {Object} options Options object
|
|
8995
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
8996
|
-
* FIN bit
|
|
8997
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
8998
|
-
* masking key
|
|
8999
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
9000
|
-
* `data`
|
|
9001
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
9002
|
-
* key
|
|
9003
|
-
* @param {Number} options.opcode The opcode
|
|
9004
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
9005
|
-
* modified
|
|
9006
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
9007
|
-
* RSV1 bit
|
|
9008
|
-
* @param {Function} [cb] Callback
|
|
9009
|
-
* @private
|
|
9010
|
-
*/
|
|
9011
|
-
getBlobData(blob, compress, options, cb) {
|
|
9012
|
-
this._bufferedBytes += options[kByteLength];
|
|
9013
|
-
this._state = GET_BLOB_DATA;
|
|
9014
|
-
blob.arrayBuffer().then((arrayBuffer) => {
|
|
9015
|
-
if (this._socket.destroyed) {
|
|
9016
|
-
const err$1 = /* @__PURE__ */ new Error("The socket was closed while the blob was being read");
|
|
9017
|
-
process.nextTick(callCallbacks, this, err$1, cb);
|
|
9018
|
-
return;
|
|
9019
|
-
}
|
|
9020
|
-
this._bufferedBytes -= options[kByteLength];
|
|
9021
|
-
const data = toBuffer$1(arrayBuffer);
|
|
9022
|
-
if (!compress) {
|
|
9023
|
-
this._state = DEFAULT;
|
|
9024
|
-
this.sendFrame(Sender$2.frame(data, options), cb);
|
|
9025
|
-
this.dequeue();
|
|
9026
|
-
} else this.dispatch(data, compress, options, cb);
|
|
9027
|
-
}).catch((err$1) => {
|
|
9028
|
-
process.nextTick(onError, this, err$1, cb);
|
|
9029
|
-
});
|
|
9030
|
-
}
|
|
9031
|
-
/**
|
|
9032
|
-
* Dispatches a message.
|
|
9033
|
-
*
|
|
9034
|
-
* @param {(Buffer|String)} data The message to send
|
|
9035
|
-
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
9036
|
-
* `data`
|
|
9037
|
-
* @param {Object} options Options object
|
|
9038
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
9039
|
-
* FIN bit
|
|
9040
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
9041
|
-
* masking key
|
|
9042
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
9043
|
-
* `data`
|
|
9044
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
9045
|
-
* key
|
|
9046
|
-
* @param {Number} options.opcode The opcode
|
|
9047
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
9048
|
-
* modified
|
|
9049
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
9050
|
-
* RSV1 bit
|
|
9051
|
-
* @param {Function} [cb] Callback
|
|
9052
|
-
* @private
|
|
9053
|
-
*/
|
|
9054
|
-
dispatch(data, compress, options, cb) {
|
|
9055
|
-
if (!compress) {
|
|
9056
|
-
this.sendFrame(Sender$2.frame(data, options), cb);
|
|
9057
|
-
return;
|
|
9058
|
-
}
|
|
9059
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate$2.extensionName];
|
|
9060
|
-
this._bufferedBytes += options[kByteLength];
|
|
9061
|
-
this._state = DEFLATING;
|
|
9062
|
-
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
9063
|
-
if (this._socket.destroyed) {
|
|
9064
|
-
callCallbacks(this, /* @__PURE__ */ new Error("The socket was closed while data was being compressed"), cb);
|
|
9065
|
-
return;
|
|
9066
|
-
}
|
|
9067
|
-
this._bufferedBytes -= options[kByteLength];
|
|
9068
|
-
this._state = DEFAULT;
|
|
9069
|
-
options.readOnly = false;
|
|
9070
|
-
this.sendFrame(Sender$2.frame(buf, options), cb);
|
|
9071
|
-
this.dequeue();
|
|
9072
|
-
});
|
|
9073
|
-
}
|
|
9074
|
-
/**
|
|
9075
|
-
* Executes queued send operations.
|
|
9076
|
-
*
|
|
9077
|
-
* @private
|
|
9078
|
-
*/
|
|
9079
|
-
dequeue() {
|
|
9080
|
-
while (this._state === DEFAULT && this._queue.length) {
|
|
9081
|
-
const params = this._queue.shift();
|
|
9082
|
-
this._bufferedBytes -= params[3][kByteLength];
|
|
9083
|
-
Reflect.apply(params[0], this, params.slice(1));
|
|
9084
|
-
}
|
|
9085
|
-
}
|
|
9086
|
-
/**
|
|
9087
|
-
* Enqueues a send operation.
|
|
9088
|
-
*
|
|
9089
|
-
* @param {Array} params Send operation parameters.
|
|
9090
|
-
* @private
|
|
9091
|
-
*/
|
|
9092
|
-
enqueue(params) {
|
|
9093
|
-
this._bufferedBytes += params[3][kByteLength];
|
|
9094
|
-
this._queue.push(params);
|
|
9095
|
-
}
|
|
9096
|
-
/**
|
|
9097
|
-
* Sends a frame.
|
|
9098
|
-
*
|
|
9099
|
-
* @param {(Buffer | String)[]} list The frame to send
|
|
9100
|
-
* @param {Function} [cb] Callback
|
|
9101
|
-
* @private
|
|
9102
|
-
*/
|
|
9103
|
-
sendFrame(list$3, cb) {
|
|
9104
|
-
if (list$3.length === 2) {
|
|
9105
|
-
this._socket.cork();
|
|
9106
|
-
this._socket.write(list$3[0]);
|
|
9107
|
-
this._socket.write(list$3[1], cb);
|
|
9108
|
-
this._socket.uncork();
|
|
9109
|
-
} else this._socket.write(list$3[0], cb);
|
|
9110
|
-
}
|
|
9111
|
-
};
|
|
9112
|
-
module.exports = Sender$2;
|
|
9113
|
-
/**
|
|
9114
|
-
* Calls queued callbacks with an error.
|
|
9115
|
-
*
|
|
9116
|
-
* @param {Sender} sender The `Sender` instance
|
|
9117
|
-
* @param {Error} err The error to call the callbacks with
|
|
9118
|
-
* @param {Function} [cb] The first callback
|
|
9119
|
-
* @private
|
|
9120
|
-
*/
|
|
9121
|
-
function callCallbacks(sender, err$1, cb) {
|
|
9122
|
-
if (typeof cb === "function") cb(err$1);
|
|
9123
|
-
for (let i = 0; i < sender._queue.length; i++) {
|
|
9124
|
-
const params = sender._queue[i];
|
|
9125
|
-
const callback = params[params.length - 1];
|
|
9126
|
-
if (typeof callback === "function") callback(err$1);
|
|
9127
|
-
}
|
|
9128
|
-
}
|
|
9129
|
-
/**
|
|
9130
|
-
* Handles a `Sender` error.
|
|
9131
|
-
*
|
|
9132
|
-
* @param {Sender} sender The `Sender` instance
|
|
9133
|
-
* @param {Error} err The error
|
|
9134
|
-
* @param {Function} [cb] The first pending callback
|
|
9135
|
-
* @private
|
|
9136
|
-
*/
|
|
9137
|
-
function onError(sender, err$1, cb) {
|
|
9138
|
-
callCallbacks(sender, err$1, cb);
|
|
9139
|
-
sender.onerror(err$1);
|
|
9140
|
-
}
|
|
9141
|
-
}) });
|
|
9142
|
-
|
|
9143
|
-
//#endregion
|
|
9144
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js
|
|
9145
|
-
var require_event_target = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js": ((exports, module) => {
|
|
9146
|
-
const { kForOnEventAttribute: kForOnEventAttribute$1, kListener: kListener$1 } = require_constants();
|
|
9147
|
-
const kCode = Symbol("kCode");
|
|
9148
|
-
const kData = Symbol("kData");
|
|
9149
|
-
const kError = Symbol("kError");
|
|
9150
|
-
const kMessage = Symbol("kMessage");
|
|
9151
|
-
const kReason = Symbol("kReason");
|
|
9152
|
-
const kTarget = Symbol("kTarget");
|
|
9153
|
-
const kType = Symbol("kType");
|
|
9154
|
-
const kWasClean = Symbol("kWasClean");
|
|
9155
|
-
/**
|
|
9156
|
-
* Class representing an event.
|
|
9157
|
-
*/
|
|
9158
|
-
var Event = class {
|
|
9159
|
-
/**
|
|
9160
|
-
* Create a new `Event`.
|
|
9161
|
-
*
|
|
9162
|
-
* @param {String} type The name of the event
|
|
9163
|
-
* @throws {TypeError} If the `type` argument is not specified
|
|
9164
|
-
*/
|
|
9165
|
-
constructor(type) {
|
|
9166
|
-
this[kTarget] = null;
|
|
9167
|
-
this[kType] = type;
|
|
9168
|
-
}
|
|
9169
|
-
/**
|
|
9170
|
-
* @type {*}
|
|
9171
|
-
*/
|
|
9172
|
-
get target() {
|
|
9173
|
-
return this[kTarget];
|
|
9174
|
-
}
|
|
9175
|
-
/**
|
|
9176
|
-
* @type {String}
|
|
9177
|
-
*/
|
|
9178
|
-
get type() {
|
|
9179
|
-
return this[kType];
|
|
9180
|
-
}
|
|
9181
|
-
};
|
|
9182
|
-
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
9183
|
-
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
9184
|
-
/**
|
|
9185
|
-
* Class representing a close event.
|
|
9186
|
-
*
|
|
9187
|
-
* @extends Event
|
|
9188
|
-
*/
|
|
9189
|
-
var CloseEvent = class extends Event {
|
|
9190
|
-
/**
|
|
9191
|
-
* Create a new `CloseEvent`.
|
|
9192
|
-
*
|
|
9193
|
-
* @param {String} type The name of the event
|
|
9194
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
9195
|
-
* attributes via object members of the same name
|
|
9196
|
-
* @param {Number} [options.code=0] The status code explaining why the
|
|
9197
|
-
* connection was closed
|
|
9198
|
-
* @param {String} [options.reason=''] A human-readable string explaining why
|
|
9199
|
-
* the connection was closed
|
|
9200
|
-
* @param {Boolean} [options.wasClean=false] Indicates whether or not the
|
|
9201
|
-
* connection was cleanly closed
|
|
9202
|
-
*/
|
|
9203
|
-
constructor(type, options = {}) {
|
|
9204
|
-
super(type);
|
|
9205
|
-
this[kCode] = options.code === void 0 ? 0 : options.code;
|
|
9206
|
-
this[kReason] = options.reason === void 0 ? "" : options.reason;
|
|
9207
|
-
this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
|
|
9208
|
-
}
|
|
9209
|
-
/**
|
|
9210
|
-
* @type {Number}
|
|
9211
|
-
*/
|
|
9212
|
-
get code() {
|
|
9213
|
-
return this[kCode];
|
|
9214
|
-
}
|
|
9215
|
-
/**
|
|
9216
|
-
* @type {String}
|
|
9217
|
-
*/
|
|
9218
|
-
get reason() {
|
|
9219
|
-
return this[kReason];
|
|
9220
|
-
}
|
|
9221
|
-
/**
|
|
9222
|
-
* @type {Boolean}
|
|
9223
|
-
*/
|
|
9224
|
-
get wasClean() {
|
|
9225
|
-
return this[kWasClean];
|
|
9226
|
-
}
|
|
9227
|
-
};
|
|
9228
|
-
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
9229
|
-
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
9230
|
-
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
9231
|
-
/**
|
|
9232
|
-
* Class representing an error event.
|
|
9233
|
-
*
|
|
9234
|
-
* @extends Event
|
|
9235
|
-
*/
|
|
9236
|
-
var ErrorEvent = class extends Event {
|
|
9237
|
-
/**
|
|
9238
|
-
* Create a new `ErrorEvent`.
|
|
9239
|
-
*
|
|
9240
|
-
* @param {String} type The name of the event
|
|
9241
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
9242
|
-
* attributes via object members of the same name
|
|
9243
|
-
* @param {*} [options.error=null] The error that generated this event
|
|
9244
|
-
* @param {String} [options.message=''] The error message
|
|
9245
|
-
*/
|
|
9246
|
-
constructor(type, options = {}) {
|
|
9247
|
-
super(type);
|
|
9248
|
-
this[kError] = options.error === void 0 ? null : options.error;
|
|
9249
|
-
this[kMessage] = options.message === void 0 ? "" : options.message;
|
|
9250
|
-
}
|
|
9251
|
-
/**
|
|
9252
|
-
* @type {*}
|
|
9253
|
-
*/
|
|
9254
|
-
get error() {
|
|
9255
|
-
return this[kError];
|
|
9256
|
-
}
|
|
9257
|
-
/**
|
|
9258
|
-
* @type {String}
|
|
9259
|
-
*/
|
|
9260
|
-
get message() {
|
|
9261
|
-
return this[kMessage];
|
|
9262
|
-
}
|
|
9263
|
-
};
|
|
9264
|
-
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
9265
|
-
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
9266
|
-
/**
|
|
9267
|
-
* Class representing a message event.
|
|
9268
|
-
*
|
|
9269
|
-
* @extends Event
|
|
9270
|
-
*/
|
|
9271
|
-
var MessageEvent = class extends Event {
|
|
9272
|
-
/**
|
|
9273
|
-
* Create a new `MessageEvent`.
|
|
9274
|
-
*
|
|
9275
|
-
* @param {String} type The name of the event
|
|
9276
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
9277
|
-
* attributes via object members of the same name
|
|
9278
|
-
* @param {*} [options.data=null] The message content
|
|
9279
|
-
*/
|
|
9280
|
-
constructor(type, options = {}) {
|
|
9281
|
-
super(type);
|
|
9282
|
-
this[kData] = options.data === void 0 ? null : options.data;
|
|
9283
|
-
}
|
|
9284
|
-
/**
|
|
9285
|
-
* @type {*}
|
|
9286
|
-
*/
|
|
9287
|
-
get data() {
|
|
9288
|
-
return this[kData];
|
|
9289
|
-
}
|
|
9290
|
-
};
|
|
9291
|
-
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
9292
|
-
/**
|
|
9293
|
-
* This provides methods for emulating the `EventTarget` interface. It's not
|
|
9294
|
-
* meant to be used directly.
|
|
9295
|
-
*
|
|
9296
|
-
* @mixin
|
|
9297
|
-
*/
|
|
9298
|
-
const EventTarget = {
|
|
9299
|
-
addEventListener(type, handler, options = {}) {
|
|
9300
|
-
for (const listener of this.listeners(type)) if (!options[kForOnEventAttribute$1] && listener[kListener$1] === handler && !listener[kForOnEventAttribute$1]) return;
|
|
9301
|
-
let wrapper;
|
|
9302
|
-
if (type === "message") wrapper = function onMessage(data, isBinary) {
|
|
9303
|
-
const event = new MessageEvent("message", { data: isBinary ? data : data.toString() });
|
|
9304
|
-
event[kTarget] = this;
|
|
9305
|
-
callListener(handler, this, event);
|
|
9306
|
-
};
|
|
9307
|
-
else if (type === "close") wrapper = function onClose(code, message) {
|
|
9308
|
-
const event = new CloseEvent("close", {
|
|
9309
|
-
code,
|
|
9310
|
-
reason: message.toString(),
|
|
9311
|
-
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
9312
|
-
});
|
|
9313
|
-
event[kTarget] = this;
|
|
9314
|
-
callListener(handler, this, event);
|
|
9315
|
-
};
|
|
9316
|
-
else if (type === "error") wrapper = function onError$1(error) {
|
|
9317
|
-
const event = new ErrorEvent("error", {
|
|
9318
|
-
error,
|
|
9319
|
-
message: error.message
|
|
9320
|
-
});
|
|
9321
|
-
event[kTarget] = this;
|
|
9322
|
-
callListener(handler, this, event);
|
|
9323
|
-
};
|
|
9324
|
-
else if (type === "open") wrapper = function onOpen() {
|
|
9325
|
-
const event = new Event("open");
|
|
9326
|
-
event[kTarget] = this;
|
|
9327
|
-
callListener(handler, this, event);
|
|
9328
|
-
};
|
|
9329
|
-
else return;
|
|
9330
|
-
wrapper[kForOnEventAttribute$1] = !!options[kForOnEventAttribute$1];
|
|
9331
|
-
wrapper[kListener$1] = handler;
|
|
9332
|
-
if (options.once) this.once(type, wrapper);
|
|
9333
|
-
else this.on(type, wrapper);
|
|
9334
|
-
},
|
|
9335
|
-
removeEventListener(type, handler) {
|
|
9336
|
-
for (const listener of this.listeners(type)) if (listener[kListener$1] === handler && !listener[kForOnEventAttribute$1]) {
|
|
9337
|
-
this.removeListener(type, listener);
|
|
9338
|
-
break;
|
|
9339
|
-
}
|
|
9340
|
-
}
|
|
9341
|
-
};
|
|
9342
|
-
module.exports = {
|
|
9343
|
-
CloseEvent,
|
|
9344
|
-
ErrorEvent,
|
|
9345
|
-
Event,
|
|
9346
|
-
EventTarget,
|
|
9347
|
-
MessageEvent
|
|
9348
|
-
};
|
|
9349
|
-
/**
|
|
9350
|
-
* Call an event listener
|
|
9351
|
-
*
|
|
9352
|
-
* @param {(Function|Object)} listener The listener to call
|
|
9353
|
-
* @param {*} thisArg The value to use as `this`` when calling the listener
|
|
9354
|
-
* @param {Event} event The event to pass to the listener
|
|
9355
|
-
* @private
|
|
9356
|
-
*/
|
|
9357
|
-
function callListener(listener, thisArg, event) {
|
|
9358
|
-
if (typeof listener === "object" && listener.handleEvent) listener.handleEvent.call(listener, event);
|
|
9359
|
-
else listener.call(thisArg, event);
|
|
9360
|
-
}
|
|
9361
|
-
}) });
|
|
9362
|
-
|
|
9363
|
-
//#endregion
|
|
9364
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js
|
|
9365
|
-
var require_extension = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js": ((exports, module) => {
|
|
9366
|
-
const { tokenChars: tokenChars$1 } = require_validation();
|
|
9367
|
-
/**
|
|
9368
|
-
* Adds an offer to the map of extension offers or a parameter to the map of
|
|
9369
|
-
* parameters.
|
|
9370
|
-
*
|
|
9371
|
-
* @param {Object} dest The map of extension offers or parameters
|
|
9372
|
-
* @param {String} name The extension or parameter name
|
|
9373
|
-
* @param {(Object|Boolean|String)} elem The extension parameters or the
|
|
9374
|
-
* parameter value
|
|
9375
|
-
* @private
|
|
9376
|
-
*/
|
|
9377
|
-
function push(dest, name, elem) {
|
|
9378
|
-
if (dest[name] === void 0) dest[name] = [elem];
|
|
9379
|
-
else dest[name].push(elem);
|
|
9380
|
-
}
|
|
9381
|
-
/**
|
|
9382
|
-
* Parses the `Sec-WebSocket-Extensions` header into an object.
|
|
9383
|
-
*
|
|
9384
|
-
* @param {String} header The field value of the header
|
|
9385
|
-
* @return {Object} The parsed object
|
|
9386
|
-
* @public
|
|
9387
|
-
*/
|
|
9388
|
-
function parse$2(header) {
|
|
9389
|
-
const offers = Object.create(null);
|
|
9390
|
-
let params = Object.create(null);
|
|
9391
|
-
let mustUnescape = false;
|
|
9392
|
-
let isEscaping = false;
|
|
9393
|
-
let inQuotes = false;
|
|
9394
|
-
let extensionName;
|
|
9395
|
-
let paramName;
|
|
9396
|
-
let start = -1;
|
|
9397
|
-
let code = -1;
|
|
9398
|
-
let end = -1;
|
|
9399
|
-
let i = 0;
|
|
9400
|
-
for (; i < header.length; i++) {
|
|
9401
|
-
code = header.charCodeAt(i);
|
|
9402
|
-
if (extensionName === void 0) if (end === -1 && tokenChars$1[code] === 1) {
|
|
9403
|
-
if (start === -1) start = i;
|
|
9404
|
-
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
9405
|
-
if (end === -1 && start !== -1) end = i;
|
|
9406
|
-
} else if (code === 59 || code === 44) {
|
|
9407
|
-
if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9408
|
-
if (end === -1) end = i;
|
|
9409
|
-
const name = header.slice(start, end);
|
|
9410
|
-
if (code === 44) {
|
|
9411
|
-
push(offers, name, params);
|
|
9412
|
-
params = Object.create(null);
|
|
9413
|
-
} else extensionName = name;
|
|
9414
|
-
start = end = -1;
|
|
9415
|
-
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9416
|
-
else if (paramName === void 0) if (end === -1 && tokenChars$1[code] === 1) {
|
|
9417
|
-
if (start === -1) start = i;
|
|
9418
|
-
} else if (code === 32 || code === 9) {
|
|
9419
|
-
if (end === -1 && start !== -1) end = i;
|
|
9420
|
-
} else if (code === 59 || code === 44) {
|
|
9421
|
-
if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9422
|
-
if (end === -1) end = i;
|
|
9423
|
-
push(params, header.slice(start, end), true);
|
|
9424
|
-
if (code === 44) {
|
|
9425
|
-
push(offers, extensionName, params);
|
|
9426
|
-
params = Object.create(null);
|
|
9427
|
-
extensionName = void 0;
|
|
9428
|
-
}
|
|
9429
|
-
start = end = -1;
|
|
9430
|
-
} else if (code === 61 && start !== -1 && end === -1) {
|
|
9431
|
-
paramName = header.slice(start, i);
|
|
9432
|
-
start = end = -1;
|
|
9433
|
-
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9434
|
-
else if (isEscaping) {
|
|
9435
|
-
if (tokenChars$1[code] !== 1) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9436
|
-
if (start === -1) start = i;
|
|
9437
|
-
else if (!mustUnescape) mustUnescape = true;
|
|
9438
|
-
isEscaping = false;
|
|
9439
|
-
} else if (inQuotes) if (tokenChars$1[code] === 1) {
|
|
9440
|
-
if (start === -1) start = i;
|
|
9441
|
-
} else if (code === 34 && start !== -1) {
|
|
9442
|
-
inQuotes = false;
|
|
9443
|
-
end = i;
|
|
9444
|
-
} else if (code === 92) isEscaping = true;
|
|
9445
|
-
else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9446
|
-
else if (code === 34 && header.charCodeAt(i - 1) === 61) inQuotes = true;
|
|
9447
|
-
else if (end === -1 && tokenChars$1[code] === 1) {
|
|
9448
|
-
if (start === -1) start = i;
|
|
9449
|
-
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
9450
|
-
if (end === -1) end = i;
|
|
9451
|
-
} else if (code === 59 || code === 44) {
|
|
9452
|
-
if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9453
|
-
if (end === -1) end = i;
|
|
9454
|
-
let value = header.slice(start, end);
|
|
9455
|
-
if (mustUnescape) {
|
|
9456
|
-
value = value.replace(/\\/g, "");
|
|
9457
|
-
mustUnescape = false;
|
|
9458
|
-
}
|
|
9459
|
-
push(params, paramName, value);
|
|
9460
|
-
if (code === 44) {
|
|
9461
|
-
push(offers, extensionName, params);
|
|
9462
|
-
params = Object.create(null);
|
|
9463
|
-
extensionName = void 0;
|
|
9464
|
-
}
|
|
9465
|
-
paramName = void 0;
|
|
9466
|
-
start = end = -1;
|
|
9467
|
-
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
9468
|
-
}
|
|
9469
|
-
if (start === -1 || inQuotes || code === 32 || code === 9) throw new SyntaxError("Unexpected end of input");
|
|
9470
|
-
if (end === -1) end = i;
|
|
9471
|
-
const token$1 = header.slice(start, end);
|
|
9472
|
-
if (extensionName === void 0) push(offers, token$1, params);
|
|
9473
|
-
else {
|
|
9474
|
-
if (paramName === void 0) push(params, token$1, true);
|
|
9475
|
-
else if (mustUnescape) push(params, paramName, token$1.replace(/\\/g, ""));
|
|
9476
|
-
else push(params, paramName, token$1);
|
|
9477
|
-
push(offers, extensionName, params);
|
|
9478
|
-
}
|
|
9479
|
-
return offers;
|
|
9480
|
-
}
|
|
9481
|
-
/**
|
|
9482
|
-
* Builds the `Sec-WebSocket-Extensions` header field value.
|
|
9483
|
-
*
|
|
9484
|
-
* @param {Object} extensions The map of extensions and parameters to format
|
|
9485
|
-
* @return {String} A string representing the given object
|
|
9486
|
-
* @public
|
|
9487
|
-
*/
|
|
9488
|
-
function format$2(extensions) {
|
|
9489
|
-
return Object.keys(extensions).map((extension$1) => {
|
|
9490
|
-
let configurations = extensions[extension$1];
|
|
9491
|
-
if (!Array.isArray(configurations)) configurations = [configurations];
|
|
9492
|
-
return configurations.map((params) => {
|
|
9493
|
-
return [extension$1].concat(Object.keys(params).map((k) => {
|
|
9494
|
-
let values = params[k];
|
|
9495
|
-
if (!Array.isArray(values)) values = [values];
|
|
9496
|
-
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
9497
|
-
})).join("; ");
|
|
9498
|
-
}).join(", ");
|
|
9499
|
-
}).join(", ");
|
|
9500
|
-
}
|
|
9501
|
-
module.exports = {
|
|
9502
|
-
format: format$2,
|
|
9503
|
-
parse: parse$2
|
|
9504
|
-
};
|
|
9505
|
-
}) });
|
|
9506
|
-
|
|
9507
|
-
//#endregion
|
|
9508
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js
|
|
9509
|
-
var require_websocket = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js": ((exports, module) => {
|
|
9510
|
-
const EventEmitter$3 = __require$1("events");
|
|
9511
|
-
const https = __require$1("https");
|
|
9512
|
-
const http$1 = __require$1("http");
|
|
9513
|
-
const net = __require$1("net");
|
|
9514
|
-
const tls = __require$1("tls");
|
|
9515
|
-
const { randomBytes, createHash: createHash$1 } = __require$1("crypto");
|
|
9516
|
-
const { Duplex: Duplex$2, Readable } = __require$1("stream");
|
|
9517
|
-
const { URL: URL$1 } = __require$1("url");
|
|
9518
|
-
const PerMessageDeflate$1 = require_permessage_deflate();
|
|
9519
|
-
const Receiver$1 = require_receiver();
|
|
9520
|
-
const Sender$1 = require_sender();
|
|
9521
|
-
const { isBlob } = require_validation();
|
|
9522
|
-
const { BINARY_TYPES, EMPTY_BUFFER, GUID: GUID$1, kForOnEventAttribute, kListener, kStatusCode, kWebSocket: kWebSocket$1, NOOP } = require_constants();
|
|
9523
|
-
const { EventTarget: { addEventListener, removeEventListener } } = require_event_target();
|
|
9524
|
-
const { format: format$1, parse: parse$1 } = require_extension();
|
|
9525
|
-
const { toBuffer } = require_buffer_util();
|
|
9526
|
-
const closeTimeout = 30 * 1e3;
|
|
9527
|
-
const kAborted = Symbol("kAborted");
|
|
9528
|
-
const protocolVersions = [8, 13];
|
|
9529
|
-
const readyStates = [
|
|
9530
|
-
"CONNECTING",
|
|
9531
|
-
"OPEN",
|
|
9532
|
-
"CLOSING",
|
|
9533
|
-
"CLOSED"
|
|
9534
|
-
];
|
|
9535
|
-
const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
9536
|
-
/**
|
|
9537
|
-
* Class representing a WebSocket.
|
|
9538
|
-
*
|
|
9539
|
-
* @extends EventEmitter
|
|
9540
|
-
*/
|
|
9541
|
-
var WebSocket$3 = class WebSocket$3 extends EventEmitter$3 {
|
|
9542
|
-
/**
|
|
9543
|
-
* Create a new `WebSocket`.
|
|
9544
|
-
*
|
|
9545
|
-
* @param {(String|URL)} address The URL to which to connect
|
|
9546
|
-
* @param {(String|String[])} [protocols] The subprotocols
|
|
9547
|
-
* @param {Object} [options] Connection options
|
|
9548
|
-
*/
|
|
9549
|
-
constructor(address, protocols, options) {
|
|
9550
|
-
super();
|
|
9551
|
-
this._binaryType = BINARY_TYPES[0];
|
|
9552
|
-
this._closeCode = 1006;
|
|
9553
|
-
this._closeFrameReceived = false;
|
|
9554
|
-
this._closeFrameSent = false;
|
|
9555
|
-
this._closeMessage = EMPTY_BUFFER;
|
|
9556
|
-
this._closeTimer = null;
|
|
9557
|
-
this._errorEmitted = false;
|
|
9558
|
-
this._extensions = {};
|
|
9559
|
-
this._paused = false;
|
|
9560
|
-
this._protocol = "";
|
|
9561
|
-
this._readyState = WebSocket$3.CONNECTING;
|
|
9562
|
-
this._receiver = null;
|
|
9563
|
-
this._sender = null;
|
|
9564
|
-
this._socket = null;
|
|
9565
|
-
if (address !== null) {
|
|
9566
|
-
this._bufferedAmount = 0;
|
|
9567
|
-
this._isServer = false;
|
|
9568
|
-
this._redirects = 0;
|
|
9569
|
-
if (protocols === void 0) protocols = [];
|
|
9570
|
-
else if (!Array.isArray(protocols)) if (typeof protocols === "object" && protocols !== null) {
|
|
9571
|
-
options = protocols;
|
|
9572
|
-
protocols = [];
|
|
9573
|
-
} else protocols = [protocols];
|
|
9574
|
-
initAsClient(this, address, protocols, options);
|
|
9575
|
-
} else {
|
|
9576
|
-
this._autoPong = options.autoPong;
|
|
9577
|
-
this._isServer = true;
|
|
9578
|
-
}
|
|
9579
|
-
}
|
|
9580
|
-
/**
|
|
9581
|
-
* For historical reasons, the custom "nodebuffer" type is used by the default
|
|
9582
|
-
* instead of "blob".
|
|
9583
|
-
*
|
|
9584
|
-
* @type {String}
|
|
9585
|
-
*/
|
|
9586
|
-
get binaryType() {
|
|
9587
|
-
return this._binaryType;
|
|
9588
|
-
}
|
|
9589
|
-
set binaryType(type) {
|
|
9590
|
-
if (!BINARY_TYPES.includes(type)) return;
|
|
9591
|
-
this._binaryType = type;
|
|
9592
|
-
if (this._receiver) this._receiver._binaryType = type;
|
|
9593
|
-
}
|
|
9594
|
-
/**
|
|
9595
|
-
* @type {Number}
|
|
9596
|
-
*/
|
|
9597
|
-
get bufferedAmount() {
|
|
9598
|
-
if (!this._socket) return this._bufferedAmount;
|
|
9599
|
-
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
9600
|
-
}
|
|
9601
|
-
/**
|
|
9602
|
-
* @type {String}
|
|
9603
|
-
*/
|
|
9604
|
-
get extensions() {
|
|
9605
|
-
return Object.keys(this._extensions).join();
|
|
9606
|
-
}
|
|
9607
|
-
/**
|
|
9608
|
-
* @type {Boolean}
|
|
9609
|
-
*/
|
|
9610
|
-
get isPaused() {
|
|
9611
|
-
return this._paused;
|
|
9612
|
-
}
|
|
9613
|
-
/**
|
|
9614
|
-
* @type {Function}
|
|
9615
|
-
*/
|
|
9616
|
-
/* istanbul ignore next */
|
|
9617
|
-
get onclose() {
|
|
9618
|
-
return null;
|
|
9619
|
-
}
|
|
9620
|
-
/**
|
|
9621
|
-
* @type {Function}
|
|
9622
|
-
*/
|
|
9623
|
-
/* istanbul ignore next */
|
|
9624
|
-
get onerror() {
|
|
9625
|
-
return null;
|
|
9626
|
-
}
|
|
9627
|
-
/**
|
|
9628
|
-
* @type {Function}
|
|
9629
|
-
*/
|
|
9630
|
-
/* istanbul ignore next */
|
|
9631
|
-
get onopen() {
|
|
9632
|
-
return null;
|
|
9633
|
-
}
|
|
9634
|
-
/**
|
|
9635
|
-
* @type {Function}
|
|
9636
|
-
*/
|
|
9637
|
-
/* istanbul ignore next */
|
|
9638
|
-
get onmessage() {
|
|
9639
|
-
return null;
|
|
9640
|
-
}
|
|
9641
|
-
/**
|
|
9642
|
-
* @type {String}
|
|
9643
|
-
*/
|
|
9644
|
-
get protocol() {
|
|
9645
|
-
return this._protocol;
|
|
9646
|
-
}
|
|
9647
|
-
/**
|
|
9648
|
-
* @type {Number}
|
|
9649
|
-
*/
|
|
9650
|
-
get readyState() {
|
|
9651
|
-
return this._readyState;
|
|
9652
|
-
}
|
|
9653
|
-
/**
|
|
9654
|
-
* @type {String}
|
|
9655
|
-
*/
|
|
9656
|
-
get url() {
|
|
9657
|
-
return this._url;
|
|
9658
|
-
}
|
|
9659
|
-
/**
|
|
9660
|
-
* Set up the socket and the internal resources.
|
|
9661
|
-
*
|
|
9662
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
9663
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
9664
|
-
* @param {Object} options Options object
|
|
9665
|
-
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
|
|
9666
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
9667
|
-
* multiple times in the same tick
|
|
9668
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
9669
|
-
* masking key
|
|
9670
|
-
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
|
9671
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
9672
|
-
* not to skip UTF-8 validation for text and close messages
|
|
9673
|
-
* @private
|
|
9674
|
-
*/
|
|
9675
|
-
setSocket(socket, head, options) {
|
|
9676
|
-
const receiver = new Receiver$1({
|
|
9677
|
-
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
9678
|
-
binaryType: this.binaryType,
|
|
9679
|
-
extensions: this._extensions,
|
|
9680
|
-
isServer: this._isServer,
|
|
9681
|
-
maxPayload: options.maxPayload,
|
|
9682
|
-
skipUTF8Validation: options.skipUTF8Validation
|
|
9683
|
-
});
|
|
9684
|
-
const sender = new Sender$1(socket, this._extensions, options.generateMask);
|
|
9685
|
-
this._receiver = receiver;
|
|
9686
|
-
this._sender = sender;
|
|
9687
|
-
this._socket = socket;
|
|
9688
|
-
receiver[kWebSocket$1] = this;
|
|
9689
|
-
sender[kWebSocket$1] = this;
|
|
9690
|
-
socket[kWebSocket$1] = this;
|
|
9691
|
-
receiver.on("conclude", receiverOnConclude);
|
|
9692
|
-
receiver.on("drain", receiverOnDrain);
|
|
9693
|
-
receiver.on("error", receiverOnError);
|
|
9694
|
-
receiver.on("message", receiverOnMessage);
|
|
9695
|
-
receiver.on("ping", receiverOnPing);
|
|
9696
|
-
receiver.on("pong", receiverOnPong);
|
|
9697
|
-
sender.onerror = senderOnError;
|
|
9698
|
-
if (socket.setTimeout) socket.setTimeout(0);
|
|
9699
|
-
if (socket.setNoDelay) socket.setNoDelay();
|
|
9700
|
-
if (head.length > 0) socket.unshift(head);
|
|
9701
|
-
socket.on("close", socketOnClose);
|
|
9702
|
-
socket.on("data", socketOnData);
|
|
9703
|
-
socket.on("end", socketOnEnd);
|
|
9704
|
-
socket.on("error", socketOnError$1);
|
|
9705
|
-
this._readyState = WebSocket$3.OPEN;
|
|
9706
|
-
this.emit("open");
|
|
9707
|
-
}
|
|
9708
|
-
/**
|
|
9709
|
-
* Emit the `'close'` event.
|
|
9710
|
-
*
|
|
9711
|
-
* @private
|
|
9712
|
-
*/
|
|
9713
|
-
emitClose() {
|
|
9714
|
-
if (!this._socket) {
|
|
9715
|
-
this._readyState = WebSocket$3.CLOSED;
|
|
9716
|
-
this.emit("close", this._closeCode, this._closeMessage);
|
|
9717
|
-
return;
|
|
9718
|
-
}
|
|
9719
|
-
if (this._extensions[PerMessageDeflate$1.extensionName]) this._extensions[PerMessageDeflate$1.extensionName].cleanup();
|
|
9720
|
-
this._receiver.removeAllListeners();
|
|
9721
|
-
this._readyState = WebSocket$3.CLOSED;
|
|
9722
|
-
this.emit("close", this._closeCode, this._closeMessage);
|
|
9723
|
-
}
|
|
9724
|
-
/**
|
|
9725
|
-
* Start a closing handshake.
|
|
9726
|
-
*
|
|
9727
|
-
* +----------+ +-----------+ +----------+
|
|
9728
|
-
* - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
|
|
9729
|
-
* | +----------+ +-----------+ +----------+ |
|
|
9730
|
-
* +----------+ +-----------+ |
|
|
9731
|
-
* CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
|
|
9732
|
-
* +----------+ +-----------+ |
|
|
9733
|
-
* | | | +---+ |
|
|
9734
|
-
* +------------------------+-->|fin| - - - -
|
|
9735
|
-
* | +---+ | +---+
|
|
9736
|
-
* - - - - -|fin|<---------------------+
|
|
9737
|
-
* +---+
|
|
9738
|
-
*
|
|
9739
|
-
* @param {Number} [code] Status code explaining why the connection is closing
|
|
9740
|
-
* @param {(String|Buffer)} [data] The reason why the connection is
|
|
9741
|
-
* closing
|
|
9742
|
-
* @public
|
|
9743
|
-
*/
|
|
9744
|
-
close(code, data) {
|
|
9745
|
-
if (this.readyState === WebSocket$3.CLOSED) return;
|
|
9746
|
-
if (this.readyState === WebSocket$3.CONNECTING) {
|
|
9747
|
-
abortHandshake$1(this, this._req, "WebSocket was closed before the connection was established");
|
|
9748
|
-
return;
|
|
9749
|
-
}
|
|
9750
|
-
if (this.readyState === WebSocket$3.CLOSING) {
|
|
9751
|
-
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) this._socket.end();
|
|
9752
|
-
return;
|
|
9753
|
-
}
|
|
9754
|
-
this._readyState = WebSocket$3.CLOSING;
|
|
9755
|
-
this._sender.close(code, data, !this._isServer, (err$1) => {
|
|
9756
|
-
if (err$1) return;
|
|
9757
|
-
this._closeFrameSent = true;
|
|
9758
|
-
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) this._socket.end();
|
|
9759
|
-
});
|
|
9760
|
-
setCloseTimer(this);
|
|
9761
|
-
}
|
|
9762
|
-
/**
|
|
9763
|
-
* Pause the socket.
|
|
9764
|
-
*
|
|
9765
|
-
* @public
|
|
9766
|
-
*/
|
|
9767
|
-
pause() {
|
|
9768
|
-
if (this.readyState === WebSocket$3.CONNECTING || this.readyState === WebSocket$3.CLOSED) return;
|
|
9769
|
-
this._paused = true;
|
|
9770
|
-
this._socket.pause();
|
|
9771
|
-
}
|
|
9772
|
-
/**
|
|
9773
|
-
* Send a ping.
|
|
9774
|
-
*
|
|
9775
|
-
* @param {*} [data] The data to send
|
|
9776
|
-
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
9777
|
-
* @param {Function} [cb] Callback which is executed when the ping is sent
|
|
9778
|
-
* @public
|
|
9779
|
-
*/
|
|
9780
|
-
ping(data, mask, cb) {
|
|
9781
|
-
if (this.readyState === WebSocket$3.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
9782
|
-
if (typeof data === "function") {
|
|
9783
|
-
cb = data;
|
|
9784
|
-
data = mask = void 0;
|
|
9785
|
-
} else if (typeof mask === "function") {
|
|
9786
|
-
cb = mask;
|
|
9787
|
-
mask = void 0;
|
|
9788
|
-
}
|
|
9789
|
-
if (typeof data === "number") data = data.toString();
|
|
9790
|
-
if (this.readyState !== WebSocket$3.OPEN) {
|
|
9791
|
-
sendAfterClose(this, data, cb);
|
|
9792
|
-
return;
|
|
9793
|
-
}
|
|
9794
|
-
if (mask === void 0) mask = !this._isServer;
|
|
9795
|
-
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
9796
|
-
}
|
|
9797
|
-
/**
|
|
9798
|
-
* Send a pong.
|
|
9799
|
-
*
|
|
9800
|
-
* @param {*} [data] The data to send
|
|
9801
|
-
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
9802
|
-
* @param {Function} [cb] Callback which is executed when the pong is sent
|
|
9803
|
-
* @public
|
|
9804
|
-
*/
|
|
9805
|
-
pong(data, mask, cb) {
|
|
9806
|
-
if (this.readyState === WebSocket$3.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
9807
|
-
if (typeof data === "function") {
|
|
9808
|
-
cb = data;
|
|
9809
|
-
data = mask = void 0;
|
|
9810
|
-
} else if (typeof mask === "function") {
|
|
9811
|
-
cb = mask;
|
|
9812
|
-
mask = void 0;
|
|
9813
|
-
}
|
|
9814
|
-
if (typeof data === "number") data = data.toString();
|
|
9815
|
-
if (this.readyState !== WebSocket$3.OPEN) {
|
|
9816
|
-
sendAfterClose(this, data, cb);
|
|
9817
|
-
return;
|
|
9818
|
-
}
|
|
9819
|
-
if (mask === void 0) mask = !this._isServer;
|
|
9820
|
-
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
9821
|
-
}
|
|
9822
|
-
/**
|
|
9823
|
-
* Resume the socket.
|
|
9824
|
-
*
|
|
9825
|
-
* @public
|
|
9826
|
-
*/
|
|
9827
|
-
resume() {
|
|
9828
|
-
if (this.readyState === WebSocket$3.CONNECTING || this.readyState === WebSocket$3.CLOSED) return;
|
|
9829
|
-
this._paused = false;
|
|
9830
|
-
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
9831
|
-
}
|
|
9832
|
-
/**
|
|
9833
|
-
* Send a data message.
|
|
9834
|
-
*
|
|
9835
|
-
* @param {*} data The message to send
|
|
9836
|
-
* @param {Object} [options] Options object
|
|
9837
|
-
* @param {Boolean} [options.binary] Specifies whether `data` is binary or
|
|
9838
|
-
* text
|
|
9839
|
-
* @param {Boolean} [options.compress] Specifies whether or not to compress
|
|
9840
|
-
* `data`
|
|
9841
|
-
* @param {Boolean} [options.fin=true] Specifies whether the fragment is the
|
|
9842
|
-
* last one
|
|
9843
|
-
* @param {Boolean} [options.mask] Specifies whether or not to mask `data`
|
|
9844
|
-
* @param {Function} [cb] Callback which is executed when data is written out
|
|
9845
|
-
* @public
|
|
9846
|
-
*/
|
|
9847
|
-
send(data, options, cb) {
|
|
9848
|
-
if (this.readyState === WebSocket$3.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
9849
|
-
if (typeof options === "function") {
|
|
9850
|
-
cb = options;
|
|
9851
|
-
options = {};
|
|
9852
|
-
}
|
|
9853
|
-
if (typeof data === "number") data = data.toString();
|
|
9854
|
-
if (this.readyState !== WebSocket$3.OPEN) {
|
|
9855
|
-
sendAfterClose(this, data, cb);
|
|
9856
|
-
return;
|
|
9857
|
-
}
|
|
9858
|
-
const opts = {
|
|
9859
|
-
binary: typeof data !== "string",
|
|
9860
|
-
mask: !this._isServer,
|
|
9861
|
-
compress: true,
|
|
9862
|
-
fin: true,
|
|
9863
|
-
...options
|
|
9864
|
-
};
|
|
9865
|
-
if (!this._extensions[PerMessageDeflate$1.extensionName]) opts.compress = false;
|
|
9866
|
-
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
9867
|
-
}
|
|
9868
|
-
/**
|
|
9869
|
-
* Forcibly close the connection.
|
|
9870
|
-
*
|
|
9871
|
-
* @public
|
|
9872
|
-
*/
|
|
9873
|
-
terminate() {
|
|
9874
|
-
if (this.readyState === WebSocket$3.CLOSED) return;
|
|
9875
|
-
if (this.readyState === WebSocket$3.CONNECTING) {
|
|
9876
|
-
abortHandshake$1(this, this._req, "WebSocket was closed before the connection was established");
|
|
9877
|
-
return;
|
|
9878
|
-
}
|
|
9879
|
-
if (this._socket) {
|
|
9880
|
-
this._readyState = WebSocket$3.CLOSING;
|
|
9881
|
-
this._socket.destroy();
|
|
9882
|
-
}
|
|
9883
|
-
}
|
|
9884
|
-
};
|
|
9885
|
-
/**
|
|
9886
|
-
* @constant {Number} CONNECTING
|
|
9887
|
-
* @memberof WebSocket
|
|
9888
|
-
*/
|
|
9889
|
-
Object.defineProperty(WebSocket$3, "CONNECTING", {
|
|
9890
|
-
enumerable: true,
|
|
9891
|
-
value: readyStates.indexOf("CONNECTING")
|
|
9892
|
-
});
|
|
9893
|
-
/**
|
|
9894
|
-
* @constant {Number} CONNECTING
|
|
9895
|
-
* @memberof WebSocket.prototype
|
|
9896
|
-
*/
|
|
9897
|
-
Object.defineProperty(WebSocket$3.prototype, "CONNECTING", {
|
|
9898
|
-
enumerable: true,
|
|
9899
|
-
value: readyStates.indexOf("CONNECTING")
|
|
9900
|
-
});
|
|
9901
|
-
/**
|
|
9902
|
-
* @constant {Number} OPEN
|
|
9903
|
-
* @memberof WebSocket
|
|
9904
|
-
*/
|
|
9905
|
-
Object.defineProperty(WebSocket$3, "OPEN", {
|
|
9906
|
-
enumerable: true,
|
|
9907
|
-
value: readyStates.indexOf("OPEN")
|
|
9908
|
-
});
|
|
9909
|
-
/**
|
|
9910
|
-
* @constant {Number} OPEN
|
|
9911
|
-
* @memberof WebSocket.prototype
|
|
9912
|
-
*/
|
|
9913
|
-
Object.defineProperty(WebSocket$3.prototype, "OPEN", {
|
|
9914
|
-
enumerable: true,
|
|
9915
|
-
value: readyStates.indexOf("OPEN")
|
|
9916
|
-
});
|
|
9917
|
-
/**
|
|
9918
|
-
* @constant {Number} CLOSING
|
|
9919
|
-
* @memberof WebSocket
|
|
9920
|
-
*/
|
|
9921
|
-
Object.defineProperty(WebSocket$3, "CLOSING", {
|
|
9922
|
-
enumerable: true,
|
|
9923
|
-
value: readyStates.indexOf("CLOSING")
|
|
9924
|
-
});
|
|
9925
|
-
/**
|
|
9926
|
-
* @constant {Number} CLOSING
|
|
9927
|
-
* @memberof WebSocket.prototype
|
|
9928
|
-
*/
|
|
9929
|
-
Object.defineProperty(WebSocket$3.prototype, "CLOSING", {
|
|
9930
|
-
enumerable: true,
|
|
9931
|
-
value: readyStates.indexOf("CLOSING")
|
|
9932
|
-
});
|
|
9933
|
-
/**
|
|
9934
|
-
* @constant {Number} CLOSED
|
|
9935
|
-
* @memberof WebSocket
|
|
9936
|
-
*/
|
|
9937
|
-
Object.defineProperty(WebSocket$3, "CLOSED", {
|
|
9938
|
-
enumerable: true,
|
|
9939
|
-
value: readyStates.indexOf("CLOSED")
|
|
9940
|
-
});
|
|
9941
|
-
/**
|
|
9942
|
-
* @constant {Number} CLOSED
|
|
9943
|
-
* @memberof WebSocket.prototype
|
|
9944
|
-
*/
|
|
9945
|
-
Object.defineProperty(WebSocket$3.prototype, "CLOSED", {
|
|
9946
|
-
enumerable: true,
|
|
9947
|
-
value: readyStates.indexOf("CLOSED")
|
|
9948
|
-
});
|
|
9949
|
-
[
|
|
9950
|
-
"binaryType",
|
|
9951
|
-
"bufferedAmount",
|
|
9952
|
-
"extensions",
|
|
9953
|
-
"isPaused",
|
|
9954
|
-
"protocol",
|
|
9955
|
-
"readyState",
|
|
9956
|
-
"url"
|
|
9957
|
-
].forEach((property) => {
|
|
9958
|
-
Object.defineProperty(WebSocket$3.prototype, property, { enumerable: true });
|
|
9959
|
-
});
|
|
9960
|
-
[
|
|
9961
|
-
"open",
|
|
9962
|
-
"error",
|
|
9963
|
-
"close",
|
|
9964
|
-
"message"
|
|
9965
|
-
].forEach((method) => {
|
|
9966
|
-
Object.defineProperty(WebSocket$3.prototype, `on${method}`, {
|
|
9967
|
-
enumerable: true,
|
|
9968
|
-
get() {
|
|
9969
|
-
for (const listener of this.listeners(method)) if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
9970
|
-
return null;
|
|
9971
|
-
},
|
|
9972
|
-
set(handler) {
|
|
9973
|
-
for (const listener of this.listeners(method)) if (listener[kForOnEventAttribute]) {
|
|
9974
|
-
this.removeListener(method, listener);
|
|
9975
|
-
break;
|
|
9976
|
-
}
|
|
9977
|
-
if (typeof handler !== "function") return;
|
|
9978
|
-
this.addEventListener(method, handler, { [kForOnEventAttribute]: true });
|
|
9979
|
-
}
|
|
9980
|
-
});
|
|
9981
|
-
});
|
|
9982
|
-
WebSocket$3.prototype.addEventListener = addEventListener;
|
|
9983
|
-
WebSocket$3.prototype.removeEventListener = removeEventListener;
|
|
9984
|
-
module.exports = WebSocket$3;
|
|
9985
|
-
/**
|
|
9986
|
-
* Initialize a WebSocket client.
|
|
9987
|
-
*
|
|
9988
|
-
* @param {WebSocket} websocket The client to initialize
|
|
9989
|
-
* @param {(String|URL)} address The URL to which to connect
|
|
9990
|
-
* @param {Array} protocols The subprotocols
|
|
9991
|
-
* @param {Object} [options] Connection options
|
|
9992
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether any
|
|
9993
|
-
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
|
|
9994
|
-
* times in the same tick
|
|
9995
|
-
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
9996
|
-
* automatically send a pong in response to a ping
|
|
9997
|
-
* @param {Function} [options.finishRequest] A function which can be used to
|
|
9998
|
-
* customize the headers of each http request before it is sent
|
|
9999
|
-
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
|
|
10000
|
-
* redirects
|
|
10001
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
10002
|
-
* masking key
|
|
10003
|
-
* @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
|
|
10004
|
-
* handshake request
|
|
10005
|
-
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
10006
|
-
* size
|
|
10007
|
-
* @param {Number} [options.maxRedirects=10] The maximum number of redirects
|
|
10008
|
-
* allowed
|
|
10009
|
-
* @param {String} [options.origin] Value of the `Origin` or
|
|
10010
|
-
* `Sec-WebSocket-Origin` header
|
|
10011
|
-
* @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
|
|
10012
|
-
* permessage-deflate
|
|
10013
|
-
* @param {Number} [options.protocolVersion=13] Value of the
|
|
10014
|
-
* `Sec-WebSocket-Version` header
|
|
10015
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
10016
|
-
* not to skip UTF-8 validation for text and close messages
|
|
10017
|
-
* @private
|
|
10018
|
-
*/
|
|
10019
|
-
function initAsClient(websocket, address, protocols, options) {
|
|
10020
|
-
const opts = {
|
|
10021
|
-
allowSynchronousEvents: true,
|
|
10022
|
-
autoPong: true,
|
|
10023
|
-
protocolVersion: protocolVersions[1],
|
|
10024
|
-
maxPayload: 100 * 1024 * 1024,
|
|
10025
|
-
skipUTF8Validation: false,
|
|
10026
|
-
perMessageDeflate: true,
|
|
10027
|
-
followRedirects: false,
|
|
10028
|
-
maxRedirects: 10,
|
|
10029
|
-
...options,
|
|
10030
|
-
socketPath: void 0,
|
|
10031
|
-
hostname: void 0,
|
|
10032
|
-
protocol: void 0,
|
|
10033
|
-
timeout: void 0,
|
|
10034
|
-
method: "GET",
|
|
10035
|
-
host: void 0,
|
|
10036
|
-
path: void 0,
|
|
10037
|
-
port: void 0
|
|
10038
|
-
};
|
|
10039
|
-
websocket._autoPong = opts.autoPong;
|
|
10040
|
-
if (!protocolVersions.includes(opts.protocolVersion)) throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`);
|
|
10041
|
-
let parsedUrl;
|
|
10042
|
-
if (address instanceof URL$1) parsedUrl = address;
|
|
10043
|
-
else try {
|
|
10044
|
-
parsedUrl = new URL$1(address);
|
|
10045
|
-
} catch (e) {
|
|
10046
|
-
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
10047
|
-
}
|
|
10048
|
-
if (parsedUrl.protocol === "http:") parsedUrl.protocol = "ws:";
|
|
10049
|
-
else if (parsedUrl.protocol === "https:") parsedUrl.protocol = "wss:";
|
|
10050
|
-
websocket._url = parsedUrl.href;
|
|
10051
|
-
const isSecure = parsedUrl.protocol === "wss:";
|
|
10052
|
-
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
10053
|
-
let invalidUrlMessage;
|
|
10054
|
-
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) invalidUrlMessage = "The URL's protocol must be one of \"ws:\", \"wss:\", \"http:\", \"https:\", or \"ws+unix:\"";
|
|
10055
|
-
else if (isIpcUrl && !parsedUrl.pathname) invalidUrlMessage = "The URL's pathname is empty";
|
|
10056
|
-
else if (parsedUrl.hash) invalidUrlMessage = "The URL contains a fragment identifier";
|
|
10057
|
-
if (invalidUrlMessage) {
|
|
10058
|
-
const err$1 = new SyntaxError(invalidUrlMessage);
|
|
10059
|
-
if (websocket._redirects === 0) throw err$1;
|
|
10060
|
-
else {
|
|
10061
|
-
emitErrorAndClose(websocket, err$1);
|
|
10062
|
-
return;
|
|
10063
|
-
}
|
|
10064
|
-
}
|
|
10065
|
-
const defaultPort = isSecure ? 443 : 80;
|
|
10066
|
-
const key = randomBytes(16).toString("base64");
|
|
10067
|
-
const request = isSecure ? https.request : http$1.request;
|
|
10068
|
-
const protocolSet = /* @__PURE__ */ new Set();
|
|
10069
|
-
let perMessageDeflate;
|
|
10070
|
-
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
10071
|
-
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
10072
|
-
opts.port = parsedUrl.port || defaultPort;
|
|
10073
|
-
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
10074
|
-
opts.headers = {
|
|
10075
|
-
...opts.headers,
|
|
10076
|
-
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
10077
|
-
"Sec-WebSocket-Key": key,
|
|
10078
|
-
Connection: "Upgrade",
|
|
10079
|
-
Upgrade: "websocket"
|
|
10080
|
-
};
|
|
10081
|
-
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
10082
|
-
opts.timeout = opts.handshakeTimeout;
|
|
10083
|
-
if (opts.perMessageDeflate) {
|
|
10084
|
-
perMessageDeflate = new PerMessageDeflate$1(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
|
|
10085
|
-
opts.headers["Sec-WebSocket-Extensions"] = format$1({ [PerMessageDeflate$1.extensionName]: perMessageDeflate.offer() });
|
|
10086
|
-
}
|
|
10087
|
-
if (protocols.length) {
|
|
10088
|
-
for (const protocol of protocols) {
|
|
10089
|
-
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
10090
|
-
protocolSet.add(protocol);
|
|
10091
|
-
}
|
|
10092
|
-
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
10093
|
-
}
|
|
10094
|
-
if (opts.origin) if (opts.protocolVersion < 13) opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
10095
|
-
else opts.headers.Origin = opts.origin;
|
|
10096
|
-
if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
10097
|
-
if (isIpcUrl) {
|
|
10098
|
-
const parts = opts.path.split(":");
|
|
10099
|
-
opts.socketPath = parts[0];
|
|
10100
|
-
opts.path = parts[1];
|
|
10101
|
-
}
|
|
10102
|
-
let req;
|
|
10103
|
-
if (opts.followRedirects) {
|
|
10104
|
-
if (websocket._redirects === 0) {
|
|
10105
|
-
websocket._originalIpc = isIpcUrl;
|
|
10106
|
-
websocket._originalSecure = isSecure;
|
|
10107
|
-
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
10108
|
-
const headers = options && options.headers;
|
|
10109
|
-
options = {
|
|
10110
|
-
...options,
|
|
10111
|
-
headers: {}
|
|
10112
|
-
};
|
|
10113
|
-
if (headers) for (const [key$1, value] of Object.entries(headers)) options.headers[key$1.toLowerCase()] = value;
|
|
10114
|
-
} else if (websocket.listenerCount("redirect") === 0) {
|
|
10115
|
-
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
10116
|
-
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
10117
|
-
delete opts.headers.authorization;
|
|
10118
|
-
delete opts.headers.cookie;
|
|
10119
|
-
if (!isSameHost) delete opts.headers.host;
|
|
10120
|
-
opts.auth = void 0;
|
|
10121
|
-
}
|
|
10122
|
-
}
|
|
10123
|
-
if (opts.auth && !options.headers.authorization) options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
10124
|
-
req = websocket._req = request(opts);
|
|
10125
|
-
if (websocket._redirects) websocket.emit("redirect", websocket.url, req);
|
|
10126
|
-
} else req = websocket._req = request(opts);
|
|
10127
|
-
if (opts.timeout) req.on("timeout", () => {
|
|
10128
|
-
abortHandshake$1(websocket, req, "Opening handshake has timed out");
|
|
10129
|
-
});
|
|
10130
|
-
req.on("error", (err$1) => {
|
|
10131
|
-
if (req === null || req[kAborted]) return;
|
|
10132
|
-
req = websocket._req = null;
|
|
10133
|
-
emitErrorAndClose(websocket, err$1);
|
|
10134
|
-
});
|
|
10135
|
-
req.on("response", (res) => {
|
|
10136
|
-
const location = res.headers.location;
|
|
10137
|
-
const statusCode = res.statusCode;
|
|
10138
|
-
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
10139
|
-
if (++websocket._redirects > opts.maxRedirects) {
|
|
10140
|
-
abortHandshake$1(websocket, req, "Maximum redirects exceeded");
|
|
10141
|
-
return;
|
|
10142
|
-
}
|
|
10143
|
-
req.abort();
|
|
10144
|
-
let addr;
|
|
10145
|
-
try {
|
|
10146
|
-
addr = new URL$1(location, address);
|
|
10147
|
-
} catch (e) {
|
|
10148
|
-
emitErrorAndClose(websocket, /* @__PURE__ */ new SyntaxError(`Invalid URL: ${location}`));
|
|
10149
|
-
return;
|
|
10150
|
-
}
|
|
10151
|
-
initAsClient(websocket, addr, protocols, options);
|
|
10152
|
-
} else if (!websocket.emit("unexpected-response", req, res)) abortHandshake$1(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
10153
|
-
});
|
|
10154
|
-
req.on("upgrade", (res, socket, head) => {
|
|
10155
|
-
websocket.emit("upgrade", res);
|
|
10156
|
-
if (websocket.readyState !== WebSocket$3.CONNECTING) return;
|
|
10157
|
-
req = websocket._req = null;
|
|
10158
|
-
const upgrade = res.headers.upgrade;
|
|
10159
|
-
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
10160
|
-
abortHandshake$1(websocket, socket, "Invalid Upgrade header");
|
|
10161
|
-
return;
|
|
10162
|
-
}
|
|
10163
|
-
const digest = createHash$1("sha1").update(key + GUID$1).digest("base64");
|
|
10164
|
-
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
10165
|
-
abortHandshake$1(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
10166
|
-
return;
|
|
10167
|
-
}
|
|
10168
|
-
const serverProt = res.headers["sec-websocket-protocol"];
|
|
10169
|
-
let protError;
|
|
10170
|
-
if (serverProt !== void 0) {
|
|
10171
|
-
if (!protocolSet.size) protError = "Server sent a subprotocol but none was requested";
|
|
10172
|
-
else if (!protocolSet.has(serverProt)) protError = "Server sent an invalid subprotocol";
|
|
10173
|
-
} else if (protocolSet.size) protError = "Server sent no subprotocol";
|
|
10174
|
-
if (protError) {
|
|
10175
|
-
abortHandshake$1(websocket, socket, protError);
|
|
10176
|
-
return;
|
|
10177
|
-
}
|
|
10178
|
-
if (serverProt) websocket._protocol = serverProt;
|
|
10179
|
-
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
10180
|
-
if (secWebSocketExtensions !== void 0) {
|
|
10181
|
-
if (!perMessageDeflate) {
|
|
10182
|
-
abortHandshake$1(websocket, socket, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
|
|
10183
|
-
return;
|
|
10184
|
-
}
|
|
10185
|
-
let extensions;
|
|
10186
|
-
try {
|
|
10187
|
-
extensions = parse$1(secWebSocketExtensions);
|
|
10188
|
-
} catch (err$1) {
|
|
10189
|
-
abortHandshake$1(websocket, socket, "Invalid Sec-WebSocket-Extensions header");
|
|
10190
|
-
return;
|
|
10191
|
-
}
|
|
10192
|
-
const extensionNames = Object.keys(extensions);
|
|
10193
|
-
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate$1.extensionName) {
|
|
10194
|
-
abortHandshake$1(websocket, socket, "Server indicated an extension that was not requested");
|
|
10195
|
-
return;
|
|
10196
|
-
}
|
|
10197
|
-
try {
|
|
10198
|
-
perMessageDeflate.accept(extensions[PerMessageDeflate$1.extensionName]);
|
|
10199
|
-
} catch (err$1) {
|
|
10200
|
-
abortHandshake$1(websocket, socket, "Invalid Sec-WebSocket-Extensions header");
|
|
10201
|
-
return;
|
|
10202
|
-
}
|
|
10203
|
-
websocket._extensions[PerMessageDeflate$1.extensionName] = perMessageDeflate;
|
|
10204
|
-
}
|
|
10205
|
-
websocket.setSocket(socket, head, {
|
|
10206
|
-
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
10207
|
-
generateMask: opts.generateMask,
|
|
10208
|
-
maxPayload: opts.maxPayload,
|
|
10209
|
-
skipUTF8Validation: opts.skipUTF8Validation
|
|
10210
|
-
});
|
|
10211
|
-
});
|
|
10212
|
-
if (opts.finishRequest) opts.finishRequest(req, websocket);
|
|
10213
|
-
else req.end();
|
|
10214
|
-
}
|
|
10215
|
-
/**
|
|
10216
|
-
* Emit the `'error'` and `'close'` events.
|
|
10217
|
-
*
|
|
10218
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
10219
|
-
* @param {Error} The error to emit
|
|
10220
|
-
* @private
|
|
10221
|
-
*/
|
|
10222
|
-
function emitErrorAndClose(websocket, err$1) {
|
|
10223
|
-
websocket._readyState = WebSocket$3.CLOSING;
|
|
10224
|
-
websocket._errorEmitted = true;
|
|
10225
|
-
websocket.emit("error", err$1);
|
|
10226
|
-
websocket.emitClose();
|
|
10227
|
-
}
|
|
10228
|
-
/**
|
|
10229
|
-
* Create a `net.Socket` and initiate a connection.
|
|
10230
|
-
*
|
|
10231
|
-
* @param {Object} options Connection options
|
|
10232
|
-
* @return {net.Socket} The newly created socket used to start the connection
|
|
10233
|
-
* @private
|
|
10234
|
-
*/
|
|
10235
|
-
function netConnect(options) {
|
|
10236
|
-
options.path = options.socketPath;
|
|
10237
|
-
return net.connect(options);
|
|
10238
|
-
}
|
|
10239
|
-
/**
|
|
10240
|
-
* Create a `tls.TLSSocket` and initiate a connection.
|
|
10241
|
-
*
|
|
10242
|
-
* @param {Object} options Connection options
|
|
10243
|
-
* @return {tls.TLSSocket} The newly created socket used to start the connection
|
|
10244
|
-
* @private
|
|
10245
|
-
*/
|
|
10246
|
-
function tlsConnect(options) {
|
|
10247
|
-
options.path = void 0;
|
|
10248
|
-
if (!options.servername && options.servername !== "") options.servername = net.isIP(options.host) ? "" : options.host;
|
|
10249
|
-
return tls.connect(options);
|
|
10250
|
-
}
|
|
10251
|
-
/**
|
|
10252
|
-
* Abort the handshake and emit an error.
|
|
10253
|
-
*
|
|
10254
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
10255
|
-
* @param {(http.ClientRequest|net.Socket|tls.Socket)} stream The request to
|
|
10256
|
-
* abort or the socket to destroy
|
|
10257
|
-
* @param {String} message The error message
|
|
10258
|
-
* @private
|
|
10259
|
-
*/
|
|
10260
|
-
function abortHandshake$1(websocket, stream, message) {
|
|
10261
|
-
websocket._readyState = WebSocket$3.CLOSING;
|
|
10262
|
-
const err$1 = new Error(message);
|
|
10263
|
-
Error.captureStackTrace(err$1, abortHandshake$1);
|
|
10264
|
-
if (stream.setHeader) {
|
|
10265
|
-
stream[kAborted] = true;
|
|
10266
|
-
stream.abort();
|
|
10267
|
-
if (stream.socket && !stream.socket.destroyed) stream.socket.destroy();
|
|
10268
|
-
process.nextTick(emitErrorAndClose, websocket, err$1);
|
|
10269
|
-
} else {
|
|
10270
|
-
stream.destroy(err$1);
|
|
10271
|
-
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
10272
|
-
stream.once("close", websocket.emitClose.bind(websocket));
|
|
10273
|
-
}
|
|
10274
|
-
}
|
|
10275
|
-
/**
|
|
10276
|
-
* Handle cases where the `ping()`, `pong()`, or `send()` methods are called
|
|
10277
|
-
* when the `readyState` attribute is `CLOSING` or `CLOSED`.
|
|
10278
|
-
*
|
|
10279
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
10280
|
-
* @param {*} [data] The data to send
|
|
10281
|
-
* @param {Function} [cb] Callback
|
|
10282
|
-
* @private
|
|
10283
|
-
*/
|
|
10284
|
-
function sendAfterClose(websocket, data, cb) {
|
|
10285
|
-
if (data) {
|
|
10286
|
-
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
10287
|
-
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
10288
|
-
else websocket._bufferedAmount += length;
|
|
10289
|
-
}
|
|
10290
|
-
if (cb) {
|
|
10291
|
-
const err$1 = /* @__PURE__ */ new Error(`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`);
|
|
10292
|
-
process.nextTick(cb, err$1);
|
|
10293
|
-
}
|
|
10294
|
-
}
|
|
10295
|
-
/**
|
|
10296
|
-
* The listener of the `Receiver` `'conclude'` event.
|
|
10297
|
-
*
|
|
10298
|
-
* @param {Number} code The status code
|
|
10299
|
-
* @param {Buffer} reason The reason for closing
|
|
10300
|
-
* @private
|
|
10301
|
-
*/
|
|
10302
|
-
function receiverOnConclude(code, reason) {
|
|
10303
|
-
const websocket = this[kWebSocket$1];
|
|
10304
|
-
websocket._closeFrameReceived = true;
|
|
10305
|
-
websocket._closeMessage = reason;
|
|
10306
|
-
websocket._closeCode = code;
|
|
10307
|
-
if (websocket._socket[kWebSocket$1] === void 0) return;
|
|
10308
|
-
websocket._socket.removeListener("data", socketOnData);
|
|
10309
|
-
process.nextTick(resume, websocket._socket);
|
|
10310
|
-
if (code === 1005) websocket.close();
|
|
10311
|
-
else websocket.close(code, reason);
|
|
10312
|
-
}
|
|
10313
|
-
/**
|
|
10314
|
-
* The listener of the `Receiver` `'drain'` event.
|
|
10315
|
-
*
|
|
10316
|
-
* @private
|
|
10317
|
-
*/
|
|
10318
|
-
function receiverOnDrain() {
|
|
10319
|
-
const websocket = this[kWebSocket$1];
|
|
10320
|
-
if (!websocket.isPaused) websocket._socket.resume();
|
|
10321
|
-
}
|
|
10322
|
-
/**
|
|
10323
|
-
* The listener of the `Receiver` `'error'` event.
|
|
10324
|
-
*
|
|
10325
|
-
* @param {(RangeError|Error)} err The emitted error
|
|
10326
|
-
* @private
|
|
10327
|
-
*/
|
|
10328
|
-
function receiverOnError(err$1) {
|
|
10329
|
-
const websocket = this[kWebSocket$1];
|
|
10330
|
-
if (websocket._socket[kWebSocket$1] !== void 0) {
|
|
10331
|
-
websocket._socket.removeListener("data", socketOnData);
|
|
10332
|
-
process.nextTick(resume, websocket._socket);
|
|
10333
|
-
websocket.close(err$1[kStatusCode]);
|
|
10334
|
-
}
|
|
10335
|
-
if (!websocket._errorEmitted) {
|
|
10336
|
-
websocket._errorEmitted = true;
|
|
10337
|
-
websocket.emit("error", err$1);
|
|
10338
|
-
}
|
|
10339
|
-
}
|
|
10340
|
-
/**
|
|
10341
|
-
* The listener of the `Receiver` `'finish'` event.
|
|
10342
|
-
*
|
|
10343
|
-
* @private
|
|
10344
|
-
*/
|
|
10345
|
-
function receiverOnFinish() {
|
|
10346
|
-
this[kWebSocket$1].emitClose();
|
|
10347
|
-
}
|
|
10348
|
-
/**
|
|
10349
|
-
* The listener of the `Receiver` `'message'` event.
|
|
10350
|
-
*
|
|
10351
|
-
* @param {Buffer|ArrayBuffer|Buffer[])} data The message
|
|
10352
|
-
* @param {Boolean} isBinary Specifies whether the message is binary or not
|
|
10353
|
-
* @private
|
|
10354
|
-
*/
|
|
10355
|
-
function receiverOnMessage(data, isBinary) {
|
|
10356
|
-
this[kWebSocket$1].emit("message", data, isBinary);
|
|
10357
|
-
}
|
|
10358
|
-
/**
|
|
10359
|
-
* The listener of the `Receiver` `'ping'` event.
|
|
10360
|
-
*
|
|
10361
|
-
* @param {Buffer} data The data included in the ping frame
|
|
10362
|
-
* @private
|
|
10363
|
-
*/
|
|
10364
|
-
function receiverOnPing(data) {
|
|
10365
|
-
const websocket = this[kWebSocket$1];
|
|
10366
|
-
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
|
10367
|
-
websocket.emit("ping", data);
|
|
10368
|
-
}
|
|
10369
|
-
/**
|
|
10370
|
-
* The listener of the `Receiver` `'pong'` event.
|
|
10371
|
-
*
|
|
10372
|
-
* @param {Buffer} data The data included in the pong frame
|
|
10373
|
-
* @private
|
|
10374
|
-
*/
|
|
10375
|
-
function receiverOnPong(data) {
|
|
10376
|
-
this[kWebSocket$1].emit("pong", data);
|
|
10377
|
-
}
|
|
10378
|
-
/**
|
|
10379
|
-
* Resume a readable stream
|
|
10380
|
-
*
|
|
10381
|
-
* @param {Readable} stream The readable stream
|
|
10382
|
-
* @private
|
|
10383
|
-
*/
|
|
10384
|
-
function resume(stream) {
|
|
10385
|
-
stream.resume();
|
|
10386
|
-
}
|
|
10387
|
-
/**
|
|
10388
|
-
* The `Sender` error event handler.
|
|
10389
|
-
*
|
|
10390
|
-
* @param {Error} The error
|
|
10391
|
-
* @private
|
|
10392
|
-
*/
|
|
10393
|
-
function senderOnError(err$1) {
|
|
10394
|
-
const websocket = this[kWebSocket$1];
|
|
10395
|
-
if (websocket.readyState === WebSocket$3.CLOSED) return;
|
|
10396
|
-
if (websocket.readyState === WebSocket$3.OPEN) {
|
|
10397
|
-
websocket._readyState = WebSocket$3.CLOSING;
|
|
10398
|
-
setCloseTimer(websocket);
|
|
10399
|
-
}
|
|
10400
|
-
this._socket.end();
|
|
10401
|
-
if (!websocket._errorEmitted) {
|
|
10402
|
-
websocket._errorEmitted = true;
|
|
10403
|
-
websocket.emit("error", err$1);
|
|
10404
|
-
}
|
|
10405
|
-
}
|
|
10406
|
-
/**
|
|
10407
|
-
* Set a timer to destroy the underlying raw socket of a WebSocket.
|
|
10408
|
-
*
|
|
10409
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
10410
|
-
* @private
|
|
10411
|
-
*/
|
|
10412
|
-
function setCloseTimer(websocket) {
|
|
10413
|
-
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), closeTimeout);
|
|
10414
|
-
}
|
|
10415
|
-
/**
|
|
10416
|
-
* The listener of the socket `'close'` event.
|
|
10417
|
-
*
|
|
10418
|
-
* @private
|
|
10419
|
-
*/
|
|
10420
|
-
function socketOnClose() {
|
|
10421
|
-
const websocket = this[kWebSocket$1];
|
|
10422
|
-
this.removeListener("close", socketOnClose);
|
|
10423
|
-
this.removeListener("data", socketOnData);
|
|
10424
|
-
this.removeListener("end", socketOnEnd);
|
|
10425
|
-
websocket._readyState = WebSocket$3.CLOSING;
|
|
10426
|
-
let chunk;
|
|
10427
|
-
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) websocket._receiver.write(chunk);
|
|
10428
|
-
websocket._receiver.end();
|
|
10429
|
-
this[kWebSocket$1] = void 0;
|
|
10430
|
-
clearTimeout(websocket._closeTimer);
|
|
10431
|
-
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) websocket.emitClose();
|
|
10432
|
-
else {
|
|
10433
|
-
websocket._receiver.on("error", receiverOnFinish);
|
|
10434
|
-
websocket._receiver.on("finish", receiverOnFinish);
|
|
10435
|
-
}
|
|
10436
|
-
}
|
|
10437
|
-
/**
|
|
10438
|
-
* The listener of the socket `'data'` event.
|
|
10439
|
-
*
|
|
10440
|
-
* @param {Buffer} chunk A chunk of data
|
|
10441
|
-
* @private
|
|
10442
|
-
*/
|
|
10443
|
-
function socketOnData(chunk) {
|
|
10444
|
-
if (!this[kWebSocket$1]._receiver.write(chunk)) this.pause();
|
|
10445
|
-
}
|
|
10446
|
-
/**
|
|
10447
|
-
* The listener of the socket `'end'` event.
|
|
10448
|
-
*
|
|
10449
|
-
* @private
|
|
10450
|
-
*/
|
|
10451
|
-
function socketOnEnd() {
|
|
10452
|
-
const websocket = this[kWebSocket$1];
|
|
10453
|
-
websocket._readyState = WebSocket$3.CLOSING;
|
|
10454
|
-
websocket._receiver.end();
|
|
10455
|
-
this.end();
|
|
10456
|
-
}
|
|
10457
|
-
/**
|
|
10458
|
-
* The listener of the socket `'error'` event.
|
|
10459
|
-
*
|
|
10460
|
-
* @private
|
|
10461
|
-
*/
|
|
10462
|
-
function socketOnError$1() {
|
|
10463
|
-
const websocket = this[kWebSocket$1];
|
|
10464
|
-
this.removeListener("error", socketOnError$1);
|
|
10465
|
-
this.on("error", NOOP);
|
|
10466
|
-
if (websocket) {
|
|
10467
|
-
websocket._readyState = WebSocket$3.CLOSING;
|
|
10468
|
-
this.destroy();
|
|
10469
|
-
}
|
|
10470
|
-
}
|
|
10471
|
-
}) });
|
|
10472
|
-
|
|
10473
|
-
//#endregion
|
|
10474
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js
|
|
10475
|
-
var require_stream = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js": ((exports, module) => {
|
|
10476
|
-
require_websocket();
|
|
10477
|
-
const { Duplex: Duplex$1 } = __require$1("stream");
|
|
10478
|
-
/**
|
|
10479
|
-
* Emits the `'close'` event on a stream.
|
|
10480
|
-
*
|
|
10481
|
-
* @param {Duplex} stream The stream.
|
|
10482
|
-
* @private
|
|
10483
|
-
*/
|
|
10484
|
-
function emitClose$1(stream) {
|
|
10485
|
-
stream.emit("close");
|
|
10486
|
-
}
|
|
10487
|
-
/**
|
|
10488
|
-
* The listener of the `'end'` event.
|
|
10489
|
-
*
|
|
10490
|
-
* @private
|
|
10491
|
-
*/
|
|
10492
|
-
function duplexOnEnd() {
|
|
10493
|
-
if (!this.destroyed && this._writableState.finished) this.destroy();
|
|
10494
|
-
}
|
|
10495
|
-
/**
|
|
10496
|
-
* The listener of the `'error'` event.
|
|
10497
|
-
*
|
|
10498
|
-
* @param {Error} err The error
|
|
10499
|
-
* @private
|
|
10500
|
-
*/
|
|
10501
|
-
function duplexOnError(err$1) {
|
|
10502
|
-
this.removeListener("error", duplexOnError);
|
|
10503
|
-
this.destroy();
|
|
10504
|
-
if (this.listenerCount("error") === 0) this.emit("error", err$1);
|
|
10505
|
-
}
|
|
10506
|
-
/**
|
|
10507
|
-
* Wraps a `WebSocket` in a duplex stream.
|
|
10508
|
-
*
|
|
10509
|
-
* @param {WebSocket} ws The `WebSocket` to wrap
|
|
10510
|
-
* @param {Object} [options] The options for the `Duplex` constructor
|
|
10511
|
-
* @return {Duplex} The duplex stream
|
|
10512
|
-
* @public
|
|
10513
|
-
*/
|
|
10514
|
-
function createWebSocketStream$1(ws, options) {
|
|
10515
|
-
let terminateOnDestroy = true;
|
|
10516
|
-
const duplex = new Duplex$1({
|
|
10517
|
-
...options,
|
|
10518
|
-
autoDestroy: false,
|
|
10519
|
-
emitClose: false,
|
|
10520
|
-
objectMode: false,
|
|
10521
|
-
writableObjectMode: false
|
|
10522
|
-
});
|
|
10523
|
-
ws.on("message", function message(msg, isBinary) {
|
|
10524
|
-
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
10525
|
-
if (!duplex.push(data)) ws.pause();
|
|
10526
|
-
});
|
|
10527
|
-
ws.once("error", function error(err$1) {
|
|
10528
|
-
if (duplex.destroyed) return;
|
|
10529
|
-
terminateOnDestroy = false;
|
|
10530
|
-
duplex.destroy(err$1);
|
|
10531
|
-
});
|
|
10532
|
-
ws.once("close", function close() {
|
|
10533
|
-
if (duplex.destroyed) return;
|
|
10534
|
-
duplex.push(null);
|
|
10535
|
-
});
|
|
10536
|
-
duplex._destroy = function(err$1, callback) {
|
|
10537
|
-
if (ws.readyState === ws.CLOSED) {
|
|
10538
|
-
callback(err$1);
|
|
10539
|
-
process.nextTick(emitClose$1, duplex);
|
|
10540
|
-
return;
|
|
10541
|
-
}
|
|
10542
|
-
let called = false;
|
|
10543
|
-
ws.once("error", function error(err$2) {
|
|
10544
|
-
called = true;
|
|
10545
|
-
callback(err$2);
|
|
10546
|
-
});
|
|
10547
|
-
ws.once("close", function close() {
|
|
10548
|
-
if (!called) callback(err$1);
|
|
10549
|
-
process.nextTick(emitClose$1, duplex);
|
|
10550
|
-
});
|
|
10551
|
-
if (terminateOnDestroy) ws.terminate();
|
|
10552
|
-
};
|
|
10553
|
-
duplex._final = function(callback) {
|
|
10554
|
-
if (ws.readyState === ws.CONNECTING) {
|
|
10555
|
-
ws.once("open", function open$1() {
|
|
10556
|
-
duplex._final(callback);
|
|
10557
|
-
});
|
|
10558
|
-
return;
|
|
10559
|
-
}
|
|
10560
|
-
if (ws._socket === null) return;
|
|
10561
|
-
if (ws._socket._writableState.finished) {
|
|
10562
|
-
callback();
|
|
10563
|
-
if (duplex._readableState.endEmitted) duplex.destroy();
|
|
10564
|
-
} else {
|
|
10565
|
-
ws._socket.once("finish", function finish() {
|
|
10566
|
-
callback();
|
|
10567
|
-
});
|
|
10568
|
-
ws.close();
|
|
10569
|
-
}
|
|
10570
|
-
};
|
|
10571
|
-
duplex._read = function() {
|
|
10572
|
-
if (ws.isPaused) ws.resume();
|
|
10573
|
-
};
|
|
10574
|
-
duplex._write = function(chunk, encoding, callback) {
|
|
10575
|
-
if (ws.readyState === ws.CONNECTING) {
|
|
10576
|
-
ws.once("open", function open$1() {
|
|
10577
|
-
duplex._write(chunk, encoding, callback);
|
|
10578
|
-
});
|
|
10579
|
-
return;
|
|
10580
|
-
}
|
|
10581
|
-
ws.send(chunk, callback);
|
|
10582
|
-
};
|
|
10583
|
-
duplex.on("end", duplexOnEnd);
|
|
10584
|
-
duplex.on("error", duplexOnError);
|
|
10585
|
-
return duplex;
|
|
10586
|
-
}
|
|
10587
|
-
module.exports = createWebSocketStream$1;
|
|
10588
|
-
}) });
|
|
10589
|
-
|
|
10590
|
-
//#endregion
|
|
10591
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js
|
|
10592
|
-
var require_subprotocol = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js": ((exports, module) => {
|
|
10593
|
-
const { tokenChars } = require_validation();
|
|
10594
|
-
/**
|
|
10595
|
-
* Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
|
|
10596
|
-
*
|
|
10597
|
-
* @param {String} header The field value of the header
|
|
10598
|
-
* @return {Set} The subprotocol names
|
|
10599
|
-
* @public
|
|
10600
|
-
*/
|
|
10601
|
-
function parse(header) {
|
|
10602
|
-
const protocols = /* @__PURE__ */ new Set();
|
|
10603
|
-
let start = -1;
|
|
10604
|
-
let end = -1;
|
|
10605
|
-
let i = 0;
|
|
10606
|
-
for (; i < header.length; i++) {
|
|
10607
|
-
const code = header.charCodeAt(i);
|
|
10608
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
10609
|
-
if (start === -1) start = i;
|
|
10610
|
-
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
10611
|
-
if (end === -1 && start !== -1) end = i;
|
|
10612
|
-
} else if (code === 44) {
|
|
10613
|
-
if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
10614
|
-
if (end === -1) end = i;
|
|
10615
|
-
const protocol$1 = header.slice(start, end);
|
|
10616
|
-
if (protocols.has(protocol$1)) throw new SyntaxError(`The "${protocol$1}" subprotocol is duplicated`);
|
|
10617
|
-
protocols.add(protocol$1);
|
|
10618
|
-
start = end = -1;
|
|
10619
|
-
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
10620
|
-
}
|
|
10621
|
-
if (start === -1 || end !== -1) throw new SyntaxError("Unexpected end of input");
|
|
10622
|
-
const protocol = header.slice(start, i);
|
|
10623
|
-
if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
10624
|
-
protocols.add(protocol);
|
|
10625
|
-
return protocols;
|
|
10626
|
-
}
|
|
10627
|
-
module.exports = { parse };
|
|
10628
|
-
}) });
|
|
10629
|
-
|
|
10630
|
-
//#endregion
|
|
10631
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js
|
|
10632
|
-
var require_websocket_server = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js": ((exports, module) => {
|
|
10633
|
-
const EventEmitter$2 = __require$1("events");
|
|
10634
|
-
const http = __require$1("http");
|
|
10635
|
-
const { Duplex } = __require$1("stream");
|
|
10636
|
-
const { createHash } = __require$1("crypto");
|
|
10637
|
-
const extension = require_extension();
|
|
10638
|
-
const PerMessageDeflate = require_permessage_deflate();
|
|
10639
|
-
const subprotocol = require_subprotocol();
|
|
10640
|
-
const WebSocket$2 = require_websocket();
|
|
10641
|
-
const { GUID, kWebSocket } = require_constants();
|
|
10642
|
-
const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
10643
|
-
const RUNNING = 0;
|
|
10644
|
-
const CLOSING = 1;
|
|
10645
|
-
const CLOSED = 2;
|
|
10646
|
-
/**
|
|
10647
|
-
* Class representing a WebSocket server.
|
|
10648
|
-
*
|
|
10649
|
-
* @extends EventEmitter
|
|
10650
|
-
*/
|
|
10651
|
-
var WebSocketServer$1 = class extends EventEmitter$2 {
|
|
10652
|
-
/**
|
|
10653
|
-
* Create a `WebSocketServer` instance.
|
|
10654
|
-
*
|
|
10655
|
-
* @param {Object} options Configuration options
|
|
10656
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
10657
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
10658
|
-
* multiple times in the same tick
|
|
10659
|
-
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
10660
|
-
* automatically send a pong in response to a ping
|
|
10661
|
-
* @param {Number} [options.backlog=511] The maximum length of the queue of
|
|
10662
|
-
* pending connections
|
|
10663
|
-
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
|
10664
|
-
* track clients
|
|
10665
|
-
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
10666
|
-
* @param {String} [options.host] The hostname where to bind the server
|
|
10667
|
-
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
10668
|
-
* size
|
|
10669
|
-
* @param {Boolean} [options.noServer=false] Enable no server mode
|
|
10670
|
-
* @param {String} [options.path] Accept only connections matching this path
|
|
10671
|
-
* @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
|
|
10672
|
-
* permessage-deflate
|
|
10673
|
-
* @param {Number} [options.port] The port where to bind the server
|
|
10674
|
-
* @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
|
|
10675
|
-
* server to use
|
|
10676
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
10677
|
-
* not to skip UTF-8 validation for text and close messages
|
|
10678
|
-
* @param {Function} [options.verifyClient] A hook to reject connections
|
|
10679
|
-
* @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
|
|
10680
|
-
* class to use. It must be the `WebSocket` class or class that extends it
|
|
10681
|
-
* @param {Function} [callback] A listener for the `listening` event
|
|
10682
|
-
*/
|
|
10683
|
-
constructor(options, callback) {
|
|
10684
|
-
super();
|
|
10685
|
-
options = {
|
|
10686
|
-
allowSynchronousEvents: true,
|
|
10687
|
-
autoPong: true,
|
|
10688
|
-
maxPayload: 100 * 1024 * 1024,
|
|
10689
|
-
skipUTF8Validation: false,
|
|
10690
|
-
perMessageDeflate: false,
|
|
10691
|
-
handleProtocols: null,
|
|
10692
|
-
clientTracking: true,
|
|
10693
|
-
verifyClient: null,
|
|
10694
|
-
noServer: false,
|
|
10695
|
-
backlog: null,
|
|
10696
|
-
server: null,
|
|
10697
|
-
host: null,
|
|
10698
|
-
path: null,
|
|
10699
|
-
port: null,
|
|
10700
|
-
WebSocket: WebSocket$2,
|
|
10701
|
-
...options
|
|
10702
|
-
};
|
|
10703
|
-
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) throw new TypeError("One and only one of the \"port\", \"server\", or \"noServer\" options must be specified");
|
|
10704
|
-
if (options.port != null) {
|
|
10705
|
-
this._server = http.createServer((req, res) => {
|
|
10706
|
-
const body = http.STATUS_CODES[426];
|
|
10707
|
-
res.writeHead(426, {
|
|
10708
|
-
"Content-Length": body.length,
|
|
10709
|
-
"Content-Type": "text/plain"
|
|
10710
|
-
});
|
|
10711
|
-
res.end(body);
|
|
10712
|
-
});
|
|
10713
|
-
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
10714
|
-
} else if (options.server) this._server = options.server;
|
|
10715
|
-
if (this._server) {
|
|
10716
|
-
const emitConnection = this.emit.bind(this, "connection");
|
|
10717
|
-
this._removeListeners = addListeners(this._server, {
|
|
10718
|
-
listening: this.emit.bind(this, "listening"),
|
|
10719
|
-
error: this.emit.bind(this, "error"),
|
|
10720
|
-
upgrade: (req, socket, head) => {
|
|
10721
|
-
this.handleUpgrade(req, socket, head, emitConnection);
|
|
10722
|
-
}
|
|
10723
|
-
});
|
|
10724
|
-
}
|
|
10725
|
-
if (options.perMessageDeflate === true) options.perMessageDeflate = {};
|
|
10726
|
-
if (options.clientTracking) {
|
|
10727
|
-
this.clients = /* @__PURE__ */ new Set();
|
|
10728
|
-
this._shouldEmitClose = false;
|
|
10729
|
-
}
|
|
10730
|
-
this.options = options;
|
|
10731
|
-
this._state = RUNNING;
|
|
10732
|
-
}
|
|
10733
|
-
/**
|
|
10734
|
-
* Returns the bound address, the address family name, and port of the server
|
|
10735
|
-
* as reported by the operating system if listening on an IP socket.
|
|
10736
|
-
* If the server is listening on a pipe or UNIX domain socket, the name is
|
|
10737
|
-
* returned as a string.
|
|
10738
|
-
*
|
|
10739
|
-
* @return {(Object|String|null)} The address of the server
|
|
10740
|
-
* @public
|
|
10741
|
-
*/
|
|
10742
|
-
address() {
|
|
10743
|
-
if (this.options.noServer) throw new Error("The server is operating in \"noServer\" mode");
|
|
10744
|
-
if (!this._server) return null;
|
|
10745
|
-
return this._server.address();
|
|
10746
|
-
}
|
|
10747
|
-
/**
|
|
10748
|
-
* Stop the server from accepting new connections and emit the `'close'` event
|
|
10749
|
-
* when all existing connections are closed.
|
|
10750
|
-
*
|
|
10751
|
-
* @param {Function} [cb] A one-time listener for the `'close'` event
|
|
10752
|
-
* @public
|
|
10753
|
-
*/
|
|
10754
|
-
close(cb) {
|
|
10755
|
-
if (this._state === CLOSED) {
|
|
10756
|
-
if (cb) this.once("close", () => {
|
|
10757
|
-
cb(/* @__PURE__ */ new Error("The server is not running"));
|
|
10758
|
-
});
|
|
10759
|
-
process.nextTick(emitClose, this);
|
|
10760
|
-
return;
|
|
10761
|
-
}
|
|
10762
|
-
if (cb) this.once("close", cb);
|
|
10763
|
-
if (this._state === CLOSING) return;
|
|
10764
|
-
this._state = CLOSING;
|
|
10765
|
-
if (this.options.noServer || this.options.server) {
|
|
10766
|
-
if (this._server) {
|
|
10767
|
-
this._removeListeners();
|
|
10768
|
-
this._removeListeners = this._server = null;
|
|
10769
|
-
}
|
|
10770
|
-
if (this.clients) if (!this.clients.size) process.nextTick(emitClose, this);
|
|
10771
|
-
else this._shouldEmitClose = true;
|
|
10772
|
-
else process.nextTick(emitClose, this);
|
|
10773
|
-
} else {
|
|
10774
|
-
const server = this._server;
|
|
10775
|
-
this._removeListeners();
|
|
10776
|
-
this._removeListeners = this._server = null;
|
|
10777
|
-
server.close(() => {
|
|
10778
|
-
emitClose(this);
|
|
10779
|
-
});
|
|
10780
|
-
}
|
|
10781
|
-
}
|
|
10782
|
-
/**
|
|
10783
|
-
* See if a given request should be handled by this server instance.
|
|
10784
|
-
*
|
|
10785
|
-
* @param {http.IncomingMessage} req Request object to inspect
|
|
10786
|
-
* @return {Boolean} `true` if the request is valid, else `false`
|
|
10787
|
-
* @public
|
|
10788
|
-
*/
|
|
10789
|
-
shouldHandle(req) {
|
|
10790
|
-
if (this.options.path) {
|
|
10791
|
-
const index = req.url.indexOf("?");
|
|
10792
|
-
if ((index !== -1 ? req.url.slice(0, index) : req.url) !== this.options.path) return false;
|
|
10793
|
-
}
|
|
10794
|
-
return true;
|
|
10795
|
-
}
|
|
10796
|
-
/**
|
|
10797
|
-
* Handle a HTTP Upgrade request.
|
|
10798
|
-
*
|
|
10799
|
-
* @param {http.IncomingMessage} req The request object
|
|
10800
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
10801
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
10802
|
-
* @param {Function} cb Callback
|
|
10803
|
-
* @public
|
|
10804
|
-
*/
|
|
10805
|
-
handleUpgrade(req, socket, head, cb) {
|
|
10806
|
-
socket.on("error", socketOnError);
|
|
10807
|
-
const key = req.headers["sec-websocket-key"];
|
|
10808
|
-
const upgrade = req.headers.upgrade;
|
|
10809
|
-
const version$1 = +req.headers["sec-websocket-version"];
|
|
10810
|
-
if (req.method !== "GET") {
|
|
10811
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 405, "Invalid HTTP method");
|
|
10812
|
-
return;
|
|
10813
|
-
}
|
|
10814
|
-
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
10815
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Invalid Upgrade header");
|
|
10816
|
-
return;
|
|
10817
|
-
}
|
|
10818
|
-
if (key === void 0 || !keyRegex.test(key)) {
|
|
10819
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Missing or invalid Sec-WebSocket-Key header");
|
|
10820
|
-
return;
|
|
10821
|
-
}
|
|
10822
|
-
if (version$1 !== 13 && version$1 !== 8) {
|
|
10823
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Missing or invalid Sec-WebSocket-Version header", { "Sec-WebSocket-Version": "13, 8" });
|
|
10824
|
-
return;
|
|
10825
|
-
}
|
|
10826
|
-
if (!this.shouldHandle(req)) {
|
|
10827
|
-
abortHandshake(socket, 400);
|
|
10828
|
-
return;
|
|
10829
|
-
}
|
|
10830
|
-
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
10831
|
-
let protocols = /* @__PURE__ */ new Set();
|
|
10832
|
-
if (secWebSocketProtocol !== void 0) try {
|
|
10833
|
-
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
10834
|
-
} catch (err$1) {
|
|
10835
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Invalid Sec-WebSocket-Protocol header");
|
|
10836
|
-
return;
|
|
10837
|
-
}
|
|
10838
|
-
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
10839
|
-
const extensions = {};
|
|
10840
|
-
if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
|
|
10841
|
-
const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
|
|
10842
|
-
try {
|
|
10843
|
-
const offers = extension.parse(secWebSocketExtensions);
|
|
10844
|
-
if (offers[PerMessageDeflate.extensionName]) {
|
|
10845
|
-
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
10846
|
-
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
10847
|
-
}
|
|
10848
|
-
} catch (err$1) {
|
|
10849
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, "Invalid or unacceptable Sec-WebSocket-Extensions header");
|
|
10850
|
-
return;
|
|
10851
|
-
}
|
|
10852
|
-
}
|
|
10853
|
-
if (this.options.verifyClient) {
|
|
10854
|
-
const info = {
|
|
10855
|
-
origin: req.headers[`${version$1 === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
10856
|
-
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
10857
|
-
req
|
|
10858
|
-
};
|
|
10859
|
-
if (this.options.verifyClient.length === 2) {
|
|
10860
|
-
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
10861
|
-
if (!verified) return abortHandshake(socket, code || 401, message, headers);
|
|
10862
|
-
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
10863
|
-
});
|
|
10864
|
-
return;
|
|
10865
|
-
}
|
|
10866
|
-
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
10867
|
-
}
|
|
10868
|
-
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
10869
|
-
}
|
|
10870
|
-
/**
|
|
10871
|
-
* Upgrade the connection to WebSocket.
|
|
10872
|
-
*
|
|
10873
|
-
* @param {Object} extensions The accepted extensions
|
|
10874
|
-
* @param {String} key The value of the `Sec-WebSocket-Key` header
|
|
10875
|
-
* @param {Set} protocols The subprotocols
|
|
10876
|
-
* @param {http.IncomingMessage} req The request object
|
|
10877
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
10878
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
10879
|
-
* @param {Function} cb Callback
|
|
10880
|
-
* @throws {Error} If called more than once with the same socket
|
|
10881
|
-
* @private
|
|
10882
|
-
*/
|
|
10883
|
-
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
10884
|
-
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
10885
|
-
if (socket[kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
|
|
10886
|
-
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
10887
|
-
const headers = [
|
|
10888
|
-
"HTTP/1.1 101 Switching Protocols",
|
|
10889
|
-
"Upgrade: websocket",
|
|
10890
|
-
"Connection: Upgrade",
|
|
10891
|
-
`Sec-WebSocket-Accept: ${createHash("sha1").update(key + GUID).digest("base64")}`
|
|
10892
|
-
];
|
|
10893
|
-
const ws = new this.options.WebSocket(null, void 0, this.options);
|
|
10894
|
-
if (protocols.size) {
|
|
10895
|
-
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
10896
|
-
if (protocol) {
|
|
10897
|
-
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
10898
|
-
ws._protocol = protocol;
|
|
10899
|
-
}
|
|
10900
|
-
}
|
|
10901
|
-
if (extensions[PerMessageDeflate.extensionName]) {
|
|
10902
|
-
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
10903
|
-
const value = extension.format({ [PerMessageDeflate.extensionName]: [params] });
|
|
10904
|
-
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
10905
|
-
ws._extensions = extensions;
|
|
10906
|
-
}
|
|
10907
|
-
this.emit("headers", headers, req);
|
|
10908
|
-
socket.write(headers.concat("\r\n").join("\r\n"));
|
|
10909
|
-
socket.removeListener("error", socketOnError);
|
|
10910
|
-
ws.setSocket(socket, head, {
|
|
10911
|
-
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
10912
|
-
maxPayload: this.options.maxPayload,
|
|
10913
|
-
skipUTF8Validation: this.options.skipUTF8Validation
|
|
10914
|
-
});
|
|
10915
|
-
if (this.clients) {
|
|
10916
|
-
this.clients.add(ws);
|
|
10917
|
-
ws.on("close", () => {
|
|
10918
|
-
this.clients.delete(ws);
|
|
10919
|
-
if (this._shouldEmitClose && !this.clients.size) process.nextTick(emitClose, this);
|
|
10920
|
-
});
|
|
10921
|
-
}
|
|
10922
|
-
cb(ws, req);
|
|
10923
|
-
}
|
|
10924
|
-
};
|
|
10925
|
-
module.exports = WebSocketServer$1;
|
|
10926
|
-
/**
|
|
10927
|
-
* Add event listeners on an `EventEmitter` using a map of <event, listener>
|
|
10928
|
-
* pairs.
|
|
10929
|
-
*
|
|
10930
|
-
* @param {EventEmitter} server The event emitter
|
|
10931
|
-
* @param {Object.<String, Function>} map The listeners to add
|
|
10932
|
-
* @return {Function} A function that will remove the added listeners when
|
|
10933
|
-
* called
|
|
10934
|
-
* @private
|
|
10935
|
-
*/
|
|
10936
|
-
function addListeners(server, map) {
|
|
10937
|
-
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
10938
|
-
return function removeListeners() {
|
|
10939
|
-
for (const event of Object.keys(map)) server.removeListener(event, map[event]);
|
|
10940
|
-
};
|
|
10941
|
-
}
|
|
10942
|
-
/**
|
|
10943
|
-
* Emit a `'close'` event on an `EventEmitter`.
|
|
10944
|
-
*
|
|
10945
|
-
* @param {EventEmitter} server The event emitter
|
|
10946
|
-
* @private
|
|
10947
|
-
*/
|
|
10948
|
-
function emitClose(server) {
|
|
10949
|
-
server._state = CLOSED;
|
|
10950
|
-
server.emit("close");
|
|
10951
|
-
}
|
|
10952
|
-
/**
|
|
10953
|
-
* Handle socket errors.
|
|
10954
|
-
*
|
|
10955
|
-
* @private
|
|
10956
|
-
*/
|
|
10957
|
-
function socketOnError() {
|
|
10958
|
-
this.destroy();
|
|
10959
|
-
}
|
|
10960
|
-
/**
|
|
10961
|
-
* Close the connection when preconditions are not fulfilled.
|
|
10962
|
-
*
|
|
10963
|
-
* @param {Duplex} socket The socket of the upgrade request
|
|
10964
|
-
* @param {Number} code The HTTP response status code
|
|
10965
|
-
* @param {String} [message] The HTTP response body
|
|
10966
|
-
* @param {Object} [headers] Additional HTTP response headers
|
|
10967
|
-
* @private
|
|
10968
|
-
*/
|
|
10969
|
-
function abortHandshake(socket, code, message, headers) {
|
|
10970
|
-
message = message || http.STATUS_CODES[code];
|
|
10971
|
-
headers = {
|
|
10972
|
-
Connection: "close",
|
|
10973
|
-
"Content-Type": "text/html",
|
|
10974
|
-
"Content-Length": Buffer.byteLength(message),
|
|
10975
|
-
...headers
|
|
10976
|
-
};
|
|
10977
|
-
socket.once("finish", socket.destroy);
|
|
10978
|
-
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + Object.keys(headers).map((h$1) => `${h$1}: ${headers[h$1]}`).join("\r\n") + "\r\n\r\n" + message);
|
|
10979
|
-
}
|
|
10980
|
-
/**
|
|
10981
|
-
* Emit a `'wsClientError'` event on a `WebSocketServer` if there is at least
|
|
10982
|
-
* one listener for it, otherwise call `abortHandshake()`.
|
|
10983
|
-
*
|
|
10984
|
-
* @param {WebSocketServer} server The WebSocket server
|
|
10985
|
-
* @param {http.IncomingMessage} req The request object
|
|
10986
|
-
* @param {Duplex} socket The socket of the upgrade request
|
|
10987
|
-
* @param {Number} code The HTTP response status code
|
|
10988
|
-
* @param {String} message The HTTP response body
|
|
10989
|
-
* @param {Object} [headers] The HTTP response headers
|
|
10990
|
-
* @private
|
|
10991
|
-
*/
|
|
10992
|
-
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
10993
|
-
if (server.listenerCount("wsClientError")) {
|
|
10994
|
-
const err$1 = new Error(message);
|
|
10995
|
-
Error.captureStackTrace(err$1, abortHandshakeOrEmitwsClientError);
|
|
10996
|
-
server.emit("wsClientError", err$1, socket, req);
|
|
10997
|
-
} else abortHandshake(socket, code, message, headers);
|
|
10998
|
-
}
|
|
10999
|
-
}) });
|
|
11000
|
-
|
|
11001
|
-
//#endregion
|
|
11002
|
-
//#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/wrapper.mjs
|
|
11003
|
-
var import_stream = /* @__PURE__ */ __toESM(require_stream(), 1);
|
|
11004
|
-
var import_receiver = /* @__PURE__ */ __toESM(require_receiver(), 1);
|
|
11005
|
-
var import_sender = /* @__PURE__ */ __toESM(require_sender(), 1);
|
|
11006
|
-
var import_websocket = /* @__PURE__ */ __toESM(require_websocket(), 1);
|
|
11007
|
-
var import_websocket_server = /* @__PURE__ */ __toESM(require_websocket_server(), 1);
|
|
11008
|
-
|
|
11009
|
-
//#endregion
|
|
11010
|
-
//#region ../pty-tunnel/dist/index.mjs
|
|
11011
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11012
|
-
var __commonJS = (cb, mod) => function() {
|
|
11013
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11014
|
-
};
|
|
11015
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
11016
|
-
function captureStdin({ redirectTo }) {
|
|
11017
|
-
readline.emitKeypressEvents(process.stdin);
|
|
11018
|
-
process.stdin.setRawMode(true);
|
|
11019
|
-
process.stdin.resume();
|
|
11020
|
-
process.on("exit", () => {
|
|
11021
|
-
process.stdin.setRawMode(false);
|
|
11022
|
-
});
|
|
11023
|
-
process.stdin.on("data", (chunk) => {
|
|
11024
|
-
try {
|
|
11025
|
-
redirectTo.sendMessage({
|
|
11026
|
-
type: "message",
|
|
11027
|
-
message: String(chunk)
|
|
11028
|
-
});
|
|
11029
|
-
} catch {}
|
|
11030
|
-
});
|
|
11031
|
-
return () => {
|
|
11032
|
-
process.stdin.setRawMode(false);
|
|
11033
|
-
process.stdin.pause();
|
|
11034
|
-
process.stdin.end();
|
|
11035
|
-
};
|
|
11036
|
-
}
|
|
11037
|
-
var require_parser = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/jsonlines@0.1.1/node_modules/jsonlines/lib/parser.js": ((exports$1, module$1) => {
|
|
11038
|
-
var Transform$1 = __require("stream").Transform;
|
|
11039
|
-
function Parser$1(options) {
|
|
11040
|
-
if (!(this instanceof Parser$1)) throw new TypeError("Cannot call a class as a function");
|
|
11041
|
-
options = options || {};
|
|
11042
|
-
Transform$1.call(this, { objectMode: true });
|
|
11043
|
-
this._memory = "";
|
|
11044
|
-
this._emitInvalidLines = options.emitInvalidLines || false;
|
|
11045
|
-
}
|
|
11046
|
-
Parser$1.prototype = Object.create(Transform$1.prototype);
|
|
11047
|
-
Parser$1.prototype._handleLines = function(lines, cb) {
|
|
11048
|
-
for (var i = 0; i < lines.length; i++) {
|
|
11049
|
-
if (lines[i] === "") continue;
|
|
11050
|
-
var err$1 = null;
|
|
11051
|
-
var json = null;
|
|
11052
|
-
try {
|
|
11053
|
-
json = JSON.parse(lines[i]);
|
|
11054
|
-
} catch (_err) {
|
|
11055
|
-
_err.source = lines[i];
|
|
11056
|
-
err$1 = _err;
|
|
11057
|
-
}
|
|
11058
|
-
if (err$1) if (this._emitInvalidLines) this.emit("invalid-line", err$1);
|
|
11059
|
-
else return cb(err$1);
|
|
11060
|
-
else this.push(json);
|
|
11061
|
-
}
|
|
11062
|
-
cb(null);
|
|
11063
|
-
};
|
|
11064
|
-
Parser$1.prototype._transform = function(chunk, encoding, cb) {
|
|
11065
|
-
var lines = (this._memory + chunk.toString()).split("\n");
|
|
11066
|
-
this._memory = lines.pop();
|
|
11067
|
-
this._handleLines(lines, cb);
|
|
11068
|
-
};
|
|
11069
|
-
Parser$1.prototype._flush = function(cb) {
|
|
11070
|
-
if (!this._memory) return cb(null);
|
|
11071
|
-
var line = this._memory;
|
|
11072
|
-
this._memory = "";
|
|
11073
|
-
this._handleLines([line], cb);
|
|
11074
|
-
};
|
|
11075
|
-
module$1.exports = Parser$1;
|
|
11076
|
-
}) });
|
|
11077
|
-
var require_stringifier = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/jsonlines@0.1.1/node_modules/jsonlines/lib/stringifier.js": ((exports$1, module$1) => {
|
|
11078
|
-
var Transform = __require("stream").Transform;
|
|
11079
|
-
function Stringifier$1() {
|
|
11080
|
-
if (!(this instanceof Stringifier$1)) throw new TypeError("Cannot call a class as a function");
|
|
11081
|
-
Transform.call(this, { objectMode: true });
|
|
11082
|
-
}
|
|
11083
|
-
Stringifier$1.prototype = Object.create(Transform.prototype);
|
|
11084
|
-
Stringifier$1.prototype._transform = function(data, _, cb) {
|
|
11085
|
-
var value;
|
|
11086
|
-
try {
|
|
11087
|
-
value = JSON.stringify(data);
|
|
11088
|
-
} catch (err$1) {
|
|
11089
|
-
err$1.source = data;
|
|
11090
|
-
return cb(err$1);
|
|
11091
|
-
}
|
|
11092
|
-
cb(null, value + "\n");
|
|
11093
|
-
};
|
|
11094
|
-
module$1.exports = Stringifier$1;
|
|
11095
|
-
}) });
|
|
11096
|
-
var import_jsonlines = (/* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/jsonlines@0.1.1/node_modules/jsonlines/index.js": ((exports$1) => {
|
|
11097
|
-
var Parser = require_parser();
|
|
11098
|
-
require_stringifier();
|
|
11099
|
-
exports$1.parse = function parse$1$1(options) {
|
|
11100
|
-
return new Parser(options);
|
|
11101
|
-
};
|
|
11102
|
-
}) }))();
|
|
11103
|
-
function serialize(msg) {
|
|
11104
|
-
switch (msg.type) {
|
|
11105
|
-
case "message": {
|
|
11106
|
-
const messageBuf = Buffer.from(msg.message, "utf-8");
|
|
11107
|
-
const buf = Buffer.alloc(1 + messageBuf.length);
|
|
11108
|
-
buf.writeUInt8(0, 0);
|
|
11109
|
-
messageBuf.copy(buf, 1);
|
|
11110
|
-
return buf;
|
|
11111
|
-
}
|
|
11112
|
-
case "resize": {
|
|
11113
|
-
const buf = Buffer.alloc(5);
|
|
11114
|
-
buf.writeUInt8(1, 0);
|
|
11115
|
-
buf.writeUInt16BE(msg.cols, 1);
|
|
11116
|
-
buf.writeUInt16BE(msg.rows, 3);
|
|
11117
|
-
return buf;
|
|
11118
|
-
}
|
|
11119
|
-
case "ready": {
|
|
11120
|
-
const buf = Buffer.alloc(1);
|
|
11121
|
-
buf.writeUInt8(2, 0);
|
|
11122
|
-
return buf;
|
|
11123
|
-
}
|
|
11124
|
-
}
|
|
11125
|
-
}
|
|
11126
|
-
async function readConnectionInfo(stream) {
|
|
11127
|
-
try {
|
|
11128
|
-
for await (const msg of stream) if (msg && typeof msg.port === "number" && typeof msg.token === "string" && typeof msg.processId === "number" && typeof msg.serverProcessId === "number") return msg;
|
|
11129
|
-
throw new Error("Did not receive port and token from server");
|
|
11130
|
-
} finally {
|
|
11131
|
-
stream.end();
|
|
11132
|
-
stream.destroy();
|
|
11133
|
-
}
|
|
11134
|
-
}
|
|
11135
|
-
function createListener() {
|
|
11136
|
-
const controlFd = (0, import_jsonlines.parse)();
|
|
11137
|
-
return {
|
|
11138
|
-
stdoutStream: controlFd,
|
|
11139
|
-
connection: (async () => {
|
|
11140
|
-
const info = await readConnectionInfo(controlFd);
|
|
11141
|
-
const qs = new URLSearchParams({
|
|
11142
|
-
processId: String(info.processId),
|
|
11143
|
-
token: info.token
|
|
11144
|
-
});
|
|
11145
|
-
return {
|
|
11146
|
-
port: info.port,
|
|
11147
|
-
token: info.token,
|
|
11148
|
-
processId: info.processId,
|
|
11149
|
-
serverProcessId: info.serverProcessId,
|
|
11150
|
-
createClient(origin) {
|
|
11151
|
-
return new ListenerSocket(`${origin}/ws/client?${qs}`);
|
|
11152
|
-
}
|
|
11153
|
-
};
|
|
11154
|
-
})()
|
|
11155
|
-
};
|
|
11156
|
-
}
|
|
11157
|
-
/**
|
|
11158
|
-
* A typed WebSocket that can send and receive pty-tunnel messages.
|
|
11159
|
-
*/
|
|
11160
|
-
var ListenerSocket = class extends import_websocket.default {
|
|
11161
|
-
async waitForOpen() {
|
|
11162
|
-
await waitForOpen(this);
|
|
11163
|
-
return this;
|
|
11164
|
-
}
|
|
11165
|
-
sendMessage(message) {
|
|
11166
|
-
return this.send(serialize(message));
|
|
11167
|
-
}
|
|
11168
|
-
};
|
|
11169
|
-
async function waitForOpen(ws) {
|
|
11170
|
-
let release;
|
|
11171
|
-
await new Promise((resolve, reject) => {
|
|
11172
|
-
ws.addEventListener("open", resolve, { once: true });
|
|
11173
|
-
ws.addEventListener("error", reject, { once: true });
|
|
11174
|
-
ws.addEventListener("close", reject, { once: true });
|
|
11175
|
-
release = () => {
|
|
11176
|
-
ws.removeEventListener("open", resolve);
|
|
11177
|
-
ws.removeEventListener("error", reject);
|
|
11178
|
-
ws.removeEventListener("close", reject);
|
|
11179
|
-
};
|
|
11180
|
-
});
|
|
11181
|
-
release?.();
|
|
11182
|
-
}
|
|
11183
|
-
|
|
11184
|
-
//#endregion
|
|
11185
|
-
//#region src/util/print-command.ts
|
|
11186
|
-
init_source();
|
|
11187
|
-
function printCommand(command$1, args$5) {
|
|
11188
|
-
return source_default.gray(source_default.dim("$ ") + [command$1, ...args$5].join(" "));
|
|
11189
|
-
}
|
|
11190
|
-
|
|
11191
|
-
//#endregion
|
|
11192
|
-
//#region src/interactive-shell/extend-sandbox-timeout.ts
|
|
11193
|
-
var import_ms$6 = /* @__PURE__ */ __toESM(require_ms());
|
|
11194
|
-
const debug$2 = createDebugger("sandbox:timeout");
|
|
11195
|
-
const BUFFER = (0, import_ms$6.default)("10 seconds");
|
|
11196
|
-
async function extendSandboxTimeoutPeriodically(sandbox, signal) {
|
|
11197
|
-
const session = sandbox.currentSession();
|
|
11198
|
-
const timeout$1 = session.timeout;
|
|
11199
|
-
if (timeout$1 == null) return;
|
|
11200
|
-
const nextTick = session.createdAt.getTime() + timeout$1;
|
|
11201
|
-
debug$2(`next tick: ${new Date(nextTick).toISOString()}`);
|
|
11202
|
-
while (!signal.aborted) {
|
|
11203
|
-
const currentTimeout = session.timeout;
|
|
11204
|
-
if (currentTimeout == null) return;
|
|
11205
|
-
const sleepMs = session.createdAt.getTime() + currentTimeout - Date.now() - BUFFER;
|
|
11206
|
-
if (sleepMs > 2e3) {
|
|
11207
|
-
debug$2(`sleeping for ${sleepMs}ms until next timeout extension`);
|
|
11208
|
-
await setTimeout$1(sleepMs, null, { signal });
|
|
11209
|
-
}
|
|
11210
|
-
await sandbox.extendTimeout((0, import_ms$6.default)("5 minutes"));
|
|
11211
|
-
const updatedTimeout = session.timeout;
|
|
11212
|
-
if (updatedTimeout == null) return;
|
|
11213
|
-
const nextTick$1 = session.createdAt.getTime() + updatedTimeout;
|
|
11214
|
-
debug$2(`extended sandbox timeout by 5 minutes. next tick: ${new Date(nextTick$1).toISOString()}`);
|
|
11215
|
-
}
|
|
11216
|
-
}
|
|
11217
|
-
|
|
11218
|
-
//#endregion
|
|
11219
|
-
//#region src/interactive-shell/interactive-shell.ts
|
|
11220
|
-
init_source();
|
|
11221
|
-
const debug$1 = createDebugger("sandbox:interactive-shell");
|
|
11222
|
-
const debugPty = createDebugger("sandbox:interactive-shell:pty");
|
|
11223
|
-
/**
|
|
11224
|
-
* A default TERM value to use if none is set in the environment.
|
|
11225
|
-
* That way, applications like `vim` and `nano` will work properly.
|
|
11226
|
-
*/
|
|
11227
|
-
const TERM = "xterm-256color";
|
|
11228
|
-
/**
|
|
11229
|
-
* Prepares the sandbox environment for interactive shell by installing required dependencies
|
|
11230
|
-
* and copying the TTY server script.
|
|
11231
|
-
*
|
|
11232
|
-
* @param sandbox - The sandbox instance to prepare
|
|
11233
|
-
* @returns Promise that resolves when environment is ready
|
|
11234
|
-
*/
|
|
11235
|
-
async function setupSandboxEnvironment(sandbox, ora$1) {
|
|
11236
|
-
let alreadyInstalled = false;
|
|
11237
|
-
try {
|
|
11238
|
-
alreadyInstalled = await checkIfServerInstalled(sandbox);
|
|
11239
|
-
} catch (err$1) {
|
|
11240
|
-
debug$1("Error checking if server is installed:", err$1);
|
|
11241
|
-
}
|
|
11242
|
-
if (alreadyInstalled) {
|
|
11243
|
-
debug$1("Server binary already installed");
|
|
11244
|
-
return;
|
|
11245
|
-
}
|
|
11246
|
-
await installServerBinary(sandbox, ora$1);
|
|
11247
|
-
}
|
|
11248
|
-
async function checkIfServerInstalled(sandbox, signal) {
|
|
11249
|
-
return (await sandbox.runCommand({
|
|
11250
|
-
cmd: "command",
|
|
11251
|
-
args: ["-v", SERVER_BIN_NAME],
|
|
11252
|
-
signal
|
|
11253
|
-
})).exitCode === 0;
|
|
11254
|
-
}
|
|
11255
|
-
async function installServerBinary(sandbox, ora$1, signal) {
|
|
11256
|
-
let firstSent = false;
|
|
11257
|
-
const createPassthrough = () => {
|
|
11258
|
-
const passthrough = new PassThrough();
|
|
11259
|
-
passthrough.on("data", (chunk) => {
|
|
11260
|
-
if (!firstSent) {
|
|
11261
|
-
firstSent = true;
|
|
11262
|
-
ora$1.text += `\n`;
|
|
11263
|
-
}
|
|
11264
|
-
ora$1.text += chunk.toString();
|
|
11265
7604
|
});
|
|
11266
|
-
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
await sandbox.writeFiles([{
|
|
11271
|
-
path: pathname,
|
|
11272
|
-
content: await fs.readFile(new URL("./pty-server-linux-x86_64", currentPath))
|
|
11273
|
-
}], { signal });
|
|
11274
|
-
await sandbox.runCommand({
|
|
11275
|
-
cmd: "bash",
|
|
11276
|
-
args: ["-c", `mv "${pathname}" /usr/local/bin/${SERVER_BIN_NAME}; chmod +x /usr/local/bin/${SERVER_BIN_NAME}`],
|
|
11277
|
-
sudo: true,
|
|
11278
|
-
signal,
|
|
11279
|
-
stdout: createPassthrough(),
|
|
11280
|
-
stderr: createPassthrough()
|
|
11281
|
-
});
|
|
11282
|
-
}
|
|
11283
|
-
const SERVER_BIN_NAME = "vc-interactive-server";
|
|
11284
|
-
const INTERACTIVE_BIN_OUTPUT = process.env.VERCEL_CLI_INTERACTIVE_BIN_OUTPUT;
|
|
11285
|
-
/**
|
|
11286
|
-
* Starts the TTY server command inside the sandbox with proper WebRTC configuration.
|
|
11287
|
-
*/
|
|
11288
|
-
async function startServerCommand(sandbox, _listener, execution, sudo, env$2, cwd) {
|
|
11289
|
-
return sandbox.runCommand({
|
|
11290
|
-
cmd: SERVER_BIN_NAME,
|
|
11291
|
-
args: [
|
|
11292
|
-
`--port=${sandbox.interactivePort}`,
|
|
11293
|
-
`--mode=client`,
|
|
11294
|
-
...debugPty.enabled ? [`--debug`] : [],
|
|
11295
|
-
`--cols=${process.stdout.columns}`,
|
|
11296
|
-
`--rows=${process.stdout.rows}`,
|
|
11297
|
-
...execution
|
|
11298
|
-
],
|
|
11299
|
-
sudo,
|
|
11300
|
-
cwd,
|
|
11301
|
-
env: {
|
|
11302
|
-
TERM,
|
|
11303
|
-
PS1: `▲ \\[\\e[2m\\]\\w/\\[\\e[0m\\] `,
|
|
11304
|
-
...env$2
|
|
11305
|
-
},
|
|
11306
|
-
detached: true
|
|
11307
|
-
});
|
|
11308
|
-
}
|
|
11309
|
-
/**
|
|
11310
|
-
* Starts an interactive shell session with a sandbox using WebRTC for real-time communication.
|
|
11311
|
-
*
|
|
11312
|
-
* @param options - Configuration including sandbox, command to execute, and sudo flag
|
|
11313
|
-
* @returns Object with wait promise and cleanup function
|
|
11314
|
-
*/
|
|
11315
|
-
async function startInteractiveShell(options) {
|
|
11316
|
-
try {
|
|
11317
|
-
var _usingCtx$1 = _usingCtx();
|
|
11318
|
-
const listener = createListener();
|
|
11319
|
-
let command$1 = null;
|
|
11320
|
-
let cleaned = false;
|
|
11321
|
-
const cleanup = () => {
|
|
11322
|
-
if (cleaned) return;
|
|
11323
|
-
process.stdin.removeAllListeners();
|
|
11324
|
-
listener.stdoutStream.end();
|
|
11325
|
-
try {
|
|
11326
|
-
process.stdin.destroy();
|
|
11327
|
-
} catch {}
|
|
11328
|
-
process.stdin.setRawMode(false);
|
|
11329
|
-
command$1?.kill().catch(() => {});
|
|
11330
|
-
cleaned = true;
|
|
7605
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(true);
|
|
7606
|
+
process.stdin.resume();
|
|
7607
|
+
const onStdin = (chunk) => {
|
|
7608
|
+
if (client.readyState === WebSocket.OPEN) client.send(chunk);
|
|
11331
7609
|
};
|
|
11332
|
-
process.
|
|
11333
|
-
const
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
await setupSandboxEnvironment(options.sandbox, progress);
|
|
11337
|
-
progress.text = "Booting up interactive listener...";
|
|
11338
|
-
command$1 = await startServerCommand(options.sandbox, listener, options.execution, options.sudo, options.envVars, options.cwd);
|
|
11339
|
-
debug$1("startServerCommand completed, cmdId=%s, interactivePort=%s", command$1.cmdId, options.sandbox.interactivePort);
|
|
11340
|
-
const waitForProcess = _usingCtx$1.u(createAbortController("Connection established successfully"));
|
|
11341
|
-
listener.connection.then(() => {
|
|
11342
|
-
debug$1("listener.connection resolved");
|
|
11343
|
-
waitForProcess.abort();
|
|
11344
|
-
});
|
|
11345
|
-
connect$1(command$1, listener, waitForProcess.signal).catch((err$1) => {
|
|
11346
|
-
if (waitForProcess.signal.aborted) return;
|
|
11347
|
-
listener.stdoutStream.destroy(err$1 instanceof Error ? err$1 : new Error(String(err$1)));
|
|
11348
|
-
});
|
|
11349
|
-
await Promise.all([throwIfCommandPrematurelyExited(command$1, waitForProcess.signal).catch(waitForProcess.ignoreInterruptions), attach({
|
|
11350
|
-
sandbox: options.sandbox,
|
|
11351
|
-
progress,
|
|
11352
|
-
listener,
|
|
11353
|
-
skipExtendingTimeout: options.skipExtendingTimeout,
|
|
11354
|
-
printCommand: () => console.error(printCommand(options.execution[0], options.execution.slice(1)))
|
|
11355
|
-
})]);
|
|
11356
|
-
} catch (_) {
|
|
11357
|
-
_usingCtx$1.e = _;
|
|
11358
|
-
} finally {
|
|
11359
|
-
_usingCtx$1.d();
|
|
11360
|
-
}
|
|
11361
|
-
}
|
|
11362
|
-
async function throwIfCommandPrematurelyExited(command$1, signal) {
|
|
11363
|
-
let exitCode;
|
|
11364
|
-
try {
|
|
11365
|
-
({exitCode} = await command$1.wait({ signal }));
|
|
11366
|
-
} catch (err$1) {
|
|
11367
|
-
if (signal.aborted) return;
|
|
11368
|
-
throw err$1;
|
|
11369
|
-
}
|
|
11370
|
-
let serverError = "";
|
|
11371
|
-
try {
|
|
11372
|
-
serverError = (await command$1.stderr({ signal })).trim();
|
|
11373
|
-
} catch {}
|
|
11374
|
-
throw new Error([
|
|
11375
|
-
`Interactive shell failed to start (exit code: ${exitCode}).`,
|
|
11376
|
-
`${source_default.bold("hint:")} The sandbox may have timed out or encountered an error.`,
|
|
11377
|
-
...serverError ? [source_default.dim(serverError)] : [],
|
|
11378
|
-
"╰▶ Check sandbox status with `sandbox list` or view logs for details."
|
|
11379
|
-
].join("\n"));
|
|
11380
|
-
}
|
|
11381
|
-
async function attach({ progress, listener, printCommand: printCommand$1, sandbox, skipExtendingTimeout }) {
|
|
11382
|
-
try {
|
|
11383
|
-
var _usingCtx3 = _usingCtx();
|
|
11384
|
-
progress.text = "Waiting for connection...";
|
|
11385
|
-
const details = await listener.connection;
|
|
11386
|
-
assert(sandbox.interactivePort, "Sandbox interactive port is not defined");
|
|
11387
|
-
const url = `wss://${sandbox.domain(sandbox.interactivePort).replace(/^https?:\/\//, "")}`;
|
|
11388
|
-
debug$1("Connecting to WebSocket URL:", url);
|
|
11389
|
-
const stdoutPipe = messageReader(process.stdout);
|
|
11390
|
-
const client = await openWithRetry(() => {
|
|
11391
|
-
const c$1 = details.createClient(url);
|
|
11392
|
-
c$1.addEventListener("message", async ({ data }) => {
|
|
11393
|
-
stdoutPipe.next(data);
|
|
11394
|
-
});
|
|
11395
|
-
return c$1;
|
|
11396
|
-
});
|
|
11397
|
-
progress.stop();
|
|
11398
|
-
const extensionController = _usingCtx3.u(createAbortController("stopped extensions"));
|
|
11399
|
-
if (!skipExtendingTimeout) extendSandboxTimeoutPeriodically(sandbox, extensionController.signal).catch(extensionController.ignoreInterruptions);
|
|
11400
|
-
client.sendMessage({ type: "ready" });
|
|
11401
|
-
client.sendMessage({
|
|
11402
|
-
type: "resize",
|
|
11403
|
-
cols: process.stdout.columns,
|
|
11404
|
-
rows: process.stdout.rows
|
|
11405
|
-
});
|
|
11406
|
-
process.on("SIGWINCH", () => {
|
|
11407
|
-
client.sendMessage({
|
|
7610
|
+
process.stdin.on("data", onStdin);
|
|
7611
|
+
const onResize = () => {
|
|
7612
|
+
if (client.readyState !== WebSocket.OPEN) return;
|
|
7613
|
+
client.send(JSON.stringify({
|
|
11408
7614
|
type: "resize",
|
|
11409
7615
|
cols: process.stdout.columns,
|
|
11410
7616
|
rows: process.stdout.rows
|
|
11411
|
-
});
|
|
11412
|
-
}
|
|
11413
|
-
process.
|
|
11414
|
-
|
|
11415
|
-
printCommand$1();
|
|
7617
|
+
}));
|
|
7618
|
+
};
|
|
7619
|
+
process.on("SIGWINCH", onResize);
|
|
7620
|
+
console.error(printCommand(options.execution[0], options.execution.slice(1)));
|
|
11416
7621
|
await new Promise((resolve, reject) => {
|
|
11417
|
-
client.
|
|
11418
|
-
client.
|
|
7622
|
+
client.once("close", () => resolve());
|
|
7623
|
+
client.once("error", (err$1) => reject(err$1));
|
|
11419
7624
|
});
|
|
11420
|
-
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
|
|
11424
|
-
_usingCtx3.e = _;
|
|
11425
|
-
} finally {
|
|
11426
|
-
_usingCtx3.d();
|
|
11427
|
-
}
|
|
11428
|
-
}
|
|
11429
|
-
/**
|
|
11430
|
-
* Async generator to allow easy coordination of parsing the events from the {@link Listener}
|
|
11431
|
-
*
|
|
11432
|
-
* @example
|
|
11433
|
-
* const pipe = messageReader(process.stdout);
|
|
11434
|
-
* pipe.next(new Blob(["Hello, World!"]));
|
|
11435
|
-
*/
|
|
11436
|
-
async function* messageReader(stream) {
|
|
11437
|
-
while (true) {
|
|
11438
|
-
const value = yield;
|
|
11439
|
-
if (!value) continue;
|
|
11440
|
-
let output$1;
|
|
11441
|
-
if (typeof value === "string" || Buffer.isBuffer(value)) output$1 = value;
|
|
11442
|
-
else if (typeof value === "object" && "arrayBuffer" in value && typeof value.arrayBuffer === "function") output$1 = Buffer.from(await value.arrayBuffer());
|
|
11443
|
-
else if (value instanceof Blob) output$1 = Buffer.from(await value.arrayBuffer());
|
|
11444
|
-
else if (Array.isArray(value)) output$1 = Buffer.concat(value);
|
|
11445
|
-
else output$1 = Buffer.from(value);
|
|
11446
|
-
stream.write(output$1);
|
|
11447
|
-
}
|
|
11448
|
-
}
|
|
11449
|
-
/**
|
|
11450
|
-
* Connects the command's logs to the listener's stdout and stderr streams.
|
|
11451
|
-
*/
|
|
11452
|
-
async function connect$1(command$1, listener, signal) {
|
|
11453
|
-
try {
|
|
11454
|
-
var _usingCtx4 = _usingCtx();
|
|
11455
|
-
const logs = _usingCtx4.u(command$1.logs({ signal }));
|
|
11456
|
-
const stderrStream = _usingCtx4.u(getStderrStream());
|
|
11457
|
-
for await (const chunk of logs) if (chunk.stream === "stdout") listener.stdoutStream.write(chunk.data);
|
|
11458
|
-
else stderrStream.write(chunk.data);
|
|
11459
|
-
listener.stdoutStream.end();
|
|
7625
|
+
extension.abort("client disconnected");
|
|
7626
|
+
process.removeListener("SIGWINCH", onResize);
|
|
7627
|
+
process.stdin.removeListener("data", onStdin);
|
|
7628
|
+
console.error(source_default.dim(`\n╰▶ connection to ▲ ${options.sandbox.name} closed.`));
|
|
11460
7629
|
} catch (_) {
|
|
11461
|
-
|
|
7630
|
+
_usingCtx$1.e = _;
|
|
11462
7631
|
} finally {
|
|
11463
|
-
|
|
7632
|
+
_usingCtx$1.d();
|
|
11464
7633
|
}
|
|
11465
7634
|
}
|
|
11466
|
-
|
|
11467
|
-
return
|
|
11468
|
-
const client = create$1();
|
|
11469
|
-
try {
|
|
11470
|
-
await withTimeout(client.waitForOpen(), 2500);
|
|
11471
|
-
return client;
|
|
11472
|
-
} catch (err$1) {
|
|
11473
|
-
debug$1("WebSocket open attempt %d failed: %o", attempt, err$1);
|
|
11474
|
-
try {
|
|
11475
|
-
client.close();
|
|
11476
|
-
} catch (closeErr) {
|
|
11477
|
-
debug$1("WebSocket close after failed open errored: %o", closeErr);
|
|
11478
|
-
}
|
|
11479
|
-
throw err$1;
|
|
11480
|
-
}
|
|
11481
|
-
}, {
|
|
11482
|
-
retries: 2,
|
|
11483
|
-
minTimeout: 500,
|
|
11484
|
-
factor: 0
|
|
11485
|
-
});
|
|
11486
|
-
}
|
|
11487
|
-
function withTimeout(promise, ms$7) {
|
|
11488
|
-
promise.catch(() => {});
|
|
11489
|
-
let timer;
|
|
11490
|
-
const timeout$1 = new Promise((_, reject) => {
|
|
11491
|
-
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Operation timed out after ${ms$7}ms`)), ms$7);
|
|
11492
|
-
});
|
|
11493
|
-
return Promise.race([promise, timeout$1]).finally(() => {
|
|
11494
|
-
if (timer) clearTimeout(timer);
|
|
11495
|
-
});
|
|
11496
|
-
}
|
|
11497
|
-
function getStderrStream() {
|
|
11498
|
-
return acquireRelease(() => {
|
|
11499
|
-
if (INTERACTIVE_BIN_OUTPUT) {
|
|
11500
|
-
const writeStream = createWriteStream(INTERACTIVE_BIN_OUTPUT);
|
|
11501
|
-
return {
|
|
11502
|
-
write(chunk) {
|
|
11503
|
-
writeStream.write(chunk);
|
|
11504
|
-
},
|
|
11505
|
-
close() {
|
|
11506
|
-
writeStream.close();
|
|
11507
|
-
}
|
|
11508
|
-
};
|
|
11509
|
-
}
|
|
11510
|
-
if (debugPty.enabled) return { write(chunk) {
|
|
11511
|
-
process.stderr.write(chunk);
|
|
11512
|
-
} };
|
|
11513
|
-
return { write() {} };
|
|
11514
|
-
}, (s$1) => {
|
|
11515
|
-
s$1.close?.();
|
|
11516
|
-
});
|
|
7635
|
+
function toEnvArray(env$2) {
|
|
7636
|
+
return Object.entries(env$2).map(([key, value]) => `${key}=${value}`);
|
|
11517
7637
|
}
|
|
11518
7638
|
|
|
11519
7639
|
//#endregion
|
|
@@ -11830,7 +7950,7 @@ const create = import_cjs$15.command({
|
|
|
11830
7950
|
description: "Create and connect to a sandbox without a network access",
|
|
11831
7951
|
command: `sandbox run --network-policy=none --connect`
|
|
11832
7952
|
}],
|
|
11833
|
-
async handler({ name, nonPersistent, ports, scope: scope$1, runtime: runtime$1, timeout: timeout$1, vcpus: vcpus$1, silent, snapshot: snapshot$1, connect: connect$
|
|
7953
|
+
async handler({ name, nonPersistent, ports, scope: scope$1, runtime: runtime$1, timeout: timeout$1, vcpus: vcpus$1, silent, snapshot: snapshot$1, connect: connect$1, envVars, tags, snapshotExpiration: snapshotExpiration$1, keepLastSnapshots: keepLastSnapshots$1, keepLastSnapshotsFor: keepLastSnapshotsFor$1, deleteEvictedSnapshots: deleteEvictedSnapshots$1, networkPolicy: networkPolicyMode$1, allowedDomains: allowedDomains$1, allowedCIDRs: allowedCIDRs$1, deniedCIDRs: deniedCIDRs$1 }) {
|
|
11834
7954
|
const networkPolicy$1 = buildNetworkPolicy({
|
|
11835
7955
|
networkPolicy: networkPolicyMode$1,
|
|
11836
7956
|
allowedDomains: allowedDomains$1,
|
|
@@ -11893,7 +8013,7 @@ const create = import_cjs$15.command({
|
|
|
11893
8013
|
scope: scope$1,
|
|
11894
8014
|
action: "created"
|
|
11895
8015
|
});
|
|
11896
|
-
if (connect$
|
|
8016
|
+
if (connect$1) await exec.handler({
|
|
11897
8017
|
scope: scope$1,
|
|
11898
8018
|
asSudo: false,
|
|
11899
8019
|
args: [],
|
|
@@ -11972,7 +8092,7 @@ const fork = import_cjs$14.command({
|
|
|
11972
8092
|
description: "Fork with a specific name and overridden vcpus",
|
|
11973
8093
|
command: `sandbox fork my-source --name my-forked-sandbox --vcpus 4`
|
|
11974
8094
|
}],
|
|
11975
|
-
async handler({ source, name, nonPersistent, ports, scope: scope$1, timeout: timeout$1, vcpus: vcpus$1, silent, connect: connect$
|
|
8095
|
+
async handler({ source, name, nonPersistent, ports, scope: scope$1, timeout: timeout$1, vcpus: vcpus$1, silent, connect: connect$1, envVars, tags, snapshotExpiration: snapshotExpiration$1, keepLastSnapshots: keepLastSnapshots$1, keepLastSnapshotsFor: keepLastSnapshotsFor$1, deleteEvictedSnapshots: deleteEvictedSnapshots$1, networkPolicy: networkPolicyMode$1, allowedDomains: allowedDomains$1, allowedCIDRs: allowedCIDRs$1, deniedCIDRs: deniedCIDRs$1 }) {
|
|
11976
8096
|
const networkPolicy$1 = networkPolicyMode$1 !== void 0 || allowedDomains$1.length > 0 || allowedCIDRs$1.length > 0 || deniedCIDRs$1.length > 0 ? buildNetworkPolicy({
|
|
11977
8097
|
networkPolicy: networkPolicyMode$1,
|
|
11978
8098
|
allowedDomains: allowedDomains$1,
|
|
@@ -12015,7 +8135,7 @@ const fork = import_cjs$14.command({
|
|
|
12015
8135
|
scope: scope$1,
|
|
12016
8136
|
action: `forked from ${source_default.cyan(source)}`
|
|
12017
8137
|
});
|
|
12018
|
-
if (connect$
|
|
8138
|
+
if (connect$1) await exec.handler({
|
|
12019
8139
|
scope: scope$1,
|
|
12020
8140
|
asSudo: false,
|
|
12021
8141
|
args: [],
|
|
@@ -12335,7 +8455,7 @@ const stop = import_cjs$10.command({
|
|
|
12335
8455
|
|
|
12336
8456
|
//#endregion
|
|
12337
8457
|
//#region ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js
|
|
12338
|
-
var require_eventemitter3 = /* @__PURE__ */ __commonJS
|
|
8458
|
+
var require_eventemitter3 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js": ((exports, module) => {
|
|
12339
8459
|
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
12340
8460
|
/**
|
|
12341
8461
|
* Constructor to create a storage for our `EE` objects.
|
|
@@ -12639,7 +8759,7 @@ const { reset, bold, dim, italic, underline, inverse, hidden, strikethrough, bla
|
|
|
12639
8759
|
|
|
12640
8760
|
//#endregion
|
|
12641
8761
|
//#region ../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js
|
|
12642
|
-
var require_rfdc = /* @__PURE__ */ __commonJS
|
|
8762
|
+
var require_rfdc = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js": ((exports, module) => {
|
|
12643
8763
|
module.exports = rfdc$1;
|
|
12644
8764
|
function copyBuffer(cur) {
|
|
12645
8765
|
if (cur instanceof Buffer) return Buffer.from(cur);
|
|
@@ -15877,4 +11997,4 @@ const app = (opts) => (0, import_cjs.subcommands)({
|
|
|
15877
11997
|
|
|
15878
11998
|
//#endregion
|
|
15879
11999
|
export { source_exports as a, init_source as i, StyledError as n, require_cjs as r, app as t };
|
|
15880
|
-
//# sourceMappingURL=app-
|
|
12000
|
+
//# sourceMappingURL=app-Cil_fM4x.mjs.map
|