bdy 1.22.18-dev → 1.22.22-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +1 -1
- package/distTs/src/agent/agent.js +24 -24
- package/distTs/src/command/pre.js +4 -4
- package/distTs/src/output.js +12 -11
- package/distTs/src/texts.js +10 -7
- package/distTs/src/tunnel/http/log.js +3 -5
- package/distTs/src/tunnel/http/stream.js +18 -5
- package/distTs/src/tunnel/server/ssh.js +20 -3
- package/distTs/src/tunnel/tunnel.js +10 -47
- package/distTs/src/utils.js +1 -2
- package/package.json +1 -1
package/distTs/package.json
CHANGED
|
@@ -7,10 +7,9 @@ const events_1 = __importDefault(require("events"));
|
|
|
7
7
|
const logger_1 = __importDefault(require("../logger"));
|
|
8
8
|
const texts_1 = require("../texts");
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
|
-
const tunnel_1 = __importDefault(require("../tunnel/tunnel"));
|
|
11
10
|
const output_1 = __importDefault(require("../output"));
|
|
12
11
|
const client_1 = __importDefault(require("./socket/client"));
|
|
13
|
-
const
|
|
12
|
+
const tunnel_1 = require("../types/tunnel");
|
|
14
13
|
class Agent extends events_1.default {
|
|
15
14
|
id;
|
|
16
15
|
host;
|
|
@@ -44,12 +43,12 @@ class Agent extends events_1.default {
|
|
|
44
43
|
this.manager = null;
|
|
45
44
|
this.onRefresh = null;
|
|
46
45
|
this.socket = new client_1.default(host, id, token);
|
|
47
|
-
this.socket.on(
|
|
48
|
-
this.socket.on(
|
|
49
|
-
this.socket.on(
|
|
50
|
-
this.socket.on(
|
|
51
|
-
this.socket.on(
|
|
52
|
-
this.socket.on(
|
|
46
|
+
this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_SUCCESS, (data) => this._onSocketFetch(data));
|
|
47
|
+
this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_FAILED, (err) => this._onSocketFetchFailed(err));
|
|
48
|
+
this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.CONNECTED, () => this._onSocketConnected());
|
|
49
|
+
this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.DISCONNECTED, () => this._onSocketDisconnected());
|
|
50
|
+
this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.TUNNEL, (tunnel, action) => this._onSocketTunnel(tunnel, action));
|
|
51
|
+
this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.AGENT, (agent, action) => this._onSocketAgent(agent, action));
|
|
53
52
|
}
|
|
54
53
|
destroy() {
|
|
55
54
|
if (this.socket) {
|
|
@@ -245,7 +244,7 @@ class Agent extends events_1.default {
|
|
|
245
244
|
}
|
|
246
245
|
}
|
|
247
246
|
async makeAction(action) {
|
|
248
|
-
if (action ===
|
|
247
|
+
if (action === tunnel_1.TUNNEL_AGENT_ACTION.DELETE) {
|
|
249
248
|
if (this.manager) {
|
|
250
249
|
return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
|
|
251
250
|
}
|
|
@@ -270,7 +269,8 @@ class Agent extends events_1.default {
|
|
|
270
269
|
sshHostKey = this.manager.sshHostKey;
|
|
271
270
|
const tunnel = tt.find((tunnel) => data.id === tunnel.id);
|
|
272
271
|
if (!tunnel) {
|
|
273
|
-
|
|
272
|
+
const TunnelImpl = require('../tunnel/tunnel').default;
|
|
273
|
+
this.addTunnel(new TunnelImpl({
|
|
274
274
|
...data,
|
|
275
275
|
sshHostKey,
|
|
276
276
|
agent: {
|
|
@@ -298,7 +298,7 @@ class Agent extends events_1.default {
|
|
|
298
298
|
this.tunnels.forEach((t) => {
|
|
299
299
|
update.push({
|
|
300
300
|
id: t.id,
|
|
301
|
-
active: t.status ===
|
|
301
|
+
active: t.status === tunnel_1.TUNNEL_STATUS.OPEN && !forceInactive,
|
|
302
302
|
regionLatency: t.regionLatency ? t.regionLatency.latency : -1,
|
|
303
303
|
targetLatency: t.targetLatency ? t.targetLatency.latency : -1,
|
|
304
304
|
totalConnections: t.totalConnections,
|
|
@@ -311,25 +311,25 @@ class Agent extends events_1.default {
|
|
|
311
311
|
canStartTunnel(tunnel) {
|
|
312
312
|
if (this.disabled)
|
|
313
313
|
return false;
|
|
314
|
-
if (!this.proxy && !this.target && tunnel.type ===
|
|
314
|
+
if (!this.proxy && !this.target && tunnel.type === tunnel_1.TUNNEL_TYPE.SSH)
|
|
315
315
|
return false;
|
|
316
|
-
return !(!this.tunneling && tunnel.type !==
|
|
316
|
+
return !(!this.tunneling && tunnel.type !== tunnel_1.TUNNEL_TYPE.SSH);
|
|
317
317
|
}
|
|
318
318
|
addTunnel(tunnel) {
|
|
319
319
|
this.tunnels.push(tunnel);
|
|
320
320
|
if (this.canStartTunnel(tunnel))
|
|
321
321
|
tunnel.start();
|
|
322
|
-
tunnel.on(
|
|
323
|
-
tunnel.on(
|
|
324
|
-
tunnel.on(
|
|
325
|
-
tunnel.on(
|
|
326
|
-
tunnel.on(
|
|
327
|
-
tunnel.on(
|
|
328
|
-
tunnel.on(
|
|
329
|
-
tunnel.on(
|
|
330
|
-
tunnel.on(
|
|
331
|
-
tunnel.on(
|
|
332
|
-
tunnel.on(
|
|
322
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.OPEN, () => this.update(true));
|
|
323
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.CLOSED, () => this.update());
|
|
324
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.TCP_OPEN, () => this.update());
|
|
325
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.TCP_CLOSED, () => this.update());
|
|
326
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.TLS_OPEN, () => this.update());
|
|
327
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.TLS_CLOSED, () => this.update());
|
|
328
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_IDENTIFIED, () => this.update());
|
|
329
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_OPEN, () => this.update());
|
|
330
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_CLOSED, () => this.update());
|
|
331
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.STOPPED, () => this.update());
|
|
332
|
+
tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, (t, logRequest) => this.httpRequest(t.id, logRequest));
|
|
333
333
|
}
|
|
334
334
|
destroyTunnel(id) {
|
|
335
335
|
const tunnel = this.tunnels.find((t) => t.id === id);
|
|
@@ -42,13 +42,13 @@ const commandPre = async (_, command) => {
|
|
|
42
42
|
if (command.hideVersionUpdate) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
const newCli = command.currentVersion !== command.latestVersion;
|
|
46
|
-
const newAgent = command.agentStatus &&
|
|
45
|
+
const newCli = !!command.latestVersion && command.currentVersion !== command.latestVersion;
|
|
46
|
+
const newAgent = !!command.agentStatus && !!command.latestVersion &&
|
|
47
47
|
command.agentStatus.version !== command.latestVersion;
|
|
48
|
-
if ((0, utils_1.isDocker)() && newCli) {
|
|
48
|
+
if ((0, utils_1.isDocker)() && newCli && command.latestVersion) {
|
|
49
49
|
output_1.default.newCliDockerVersion(command.latestVersion);
|
|
50
50
|
}
|
|
51
|
-
else if (newCli) {
|
|
51
|
+
else if (newCli && command.latestVersion) {
|
|
52
52
|
output_1.default.newCliVersion(command.latestVersion);
|
|
53
53
|
}
|
|
54
54
|
else if (newAgent) {
|
package/distTs/src/output.js
CHANGED
|
@@ -3,14 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const tunnel_1 = __importDefault(require("./tunnel/output/noninteractive/tunnel"));
|
|
7
|
-
const tunnel_2 = __importDefault(require("./tunnel/output/noninteractive/config/tunnel"));
|
|
8
|
-
const tunnels_1 = __importDefault(require("./tunnel/output/noninteractive/config/tunnels"));
|
|
9
6
|
const texts_1 = require("./texts");
|
|
10
|
-
const tunnels_2 = __importDefault(require("./tunnel/output/noninteractive/agent/tunnels"));
|
|
11
7
|
const utils_1 = require("./utils");
|
|
12
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
13
|
-
const undici_1 = __importDefault(require("undici"));
|
|
14
9
|
let _terminal = null;
|
|
15
10
|
function getTerminal() {
|
|
16
11
|
if (!_terminal) {
|
|
@@ -178,7 +173,8 @@ class Output {
|
|
|
178
173
|
}
|
|
179
174
|
}
|
|
180
175
|
static agentTunnels(tunnels) {
|
|
181
|
-
const
|
|
176
|
+
const OutputNoninteractiveAgentTunnels = require('./tunnel/output/noninteractive/agent/tunnels').default;
|
|
177
|
+
const on = new OutputNoninteractiveAgentTunnels(getTerminal(), tunnels);
|
|
182
178
|
on.start(this);
|
|
183
179
|
}
|
|
184
180
|
static tunnelInteractive(tunnel) {
|
|
@@ -189,7 +185,8 @@ class Output {
|
|
|
189
185
|
}
|
|
190
186
|
static tunnelNonInteractive(tunnel) {
|
|
191
187
|
this.killSpinner();
|
|
192
|
-
const
|
|
188
|
+
const OutputNoninteractiveTunnel = require('./tunnel/output/noninteractive/tunnel').default;
|
|
189
|
+
const on = new OutputNoninteractiveTunnel(getTerminal(), tunnel);
|
|
193
190
|
on.start();
|
|
194
191
|
}
|
|
195
192
|
static newCliVersion(version) {
|
|
@@ -241,11 +238,13 @@ class Output {
|
|
|
241
238
|
});
|
|
242
239
|
}
|
|
243
240
|
static configTunnels(tunnels) {
|
|
244
|
-
const
|
|
241
|
+
const OutputNoninteractiveConfigTunnels = require('./tunnel/output/noninteractive/config/tunnels').default;
|
|
242
|
+
const on = new OutputNoninteractiveConfigTunnels(getTerminal(), tunnels);
|
|
245
243
|
on.start(this);
|
|
246
244
|
}
|
|
247
245
|
static configTunnel(tunnel) {
|
|
248
|
-
const
|
|
246
|
+
const OutputNoninteractiveConfigTunnel = require('./tunnel/output/noninteractive/config/tunnel').default;
|
|
247
|
+
const on = new OutputNoninteractiveConfigTunnel(getTerminal(), tunnel);
|
|
249
248
|
on.start(this);
|
|
250
249
|
}
|
|
251
250
|
static handleSignals() {
|
|
@@ -409,7 +408,8 @@ class Output {
|
|
|
409
408
|
}
|
|
410
409
|
static getUndiciUnauthorizedAgent() {
|
|
411
410
|
if (!this._a) {
|
|
412
|
-
|
|
411
|
+
const undici = require('undici');
|
|
412
|
+
this._a = new undici.Agent({
|
|
413
413
|
connect: {
|
|
414
414
|
rejectUnauthorized: false,
|
|
415
415
|
},
|
|
@@ -418,7 +418,8 @@ class Output {
|
|
|
418
418
|
return this._a;
|
|
419
419
|
}
|
|
420
420
|
static clearUndici() {
|
|
421
|
-
|
|
421
|
+
const undici = require('undici');
|
|
422
|
+
undici.getGlobalDispatcher().destroy(() => { });
|
|
422
423
|
if (this._a)
|
|
423
424
|
this._a.destroy(() => { });
|
|
424
425
|
}
|
package/distTs/src/texts.js
CHANGED
|
@@ -20,7 +20,7 @@ const utils_1 = require("./utils");
|
|
|
20
20
|
exports.ERR_REST_API_GENERAL_ERROR = 'Something went wrong';
|
|
21
21
|
exports.ERR_REST_API_NOT_RESPONDING = 'Api endpoint not responding. Try again later...';
|
|
22
22
|
exports.ERR_REST_API_CONNECT_ERROR = 'Connection refused. Check selected endpoint';
|
|
23
|
-
exports.ERR_REST_API_WRONG_TOKEN =
|
|
23
|
+
exports.ERR_REST_API_WRONG_TOKEN = "Unauthorized (401): Invalid or missing token. Run 'buddy login' to authenticate";
|
|
24
24
|
exports.ERR_REST_API_RESOURCE_NOT_FOUND = 'Resource not found';
|
|
25
25
|
const ERR_REST_API_RATE_LIMIT = (rateLimitReset) => {
|
|
26
26
|
if (rateLimitReset) {
|
|
@@ -812,6 +812,9 @@ const ERR_API_MESSAGE_REPLACER = (message, path, baseUrl, rateLimitTs) => {
|
|
|
812
812
|
workspaceUrl = (0, utils_1.getAppWorkspaceSettingsUrl)(baseUrl, m[1]);
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
|
+
if (message === 'Rate limit exceeded') {
|
|
816
|
+
return (0, exports.ERR_REST_API_RATE_LIMIT)(rateLimitTs);
|
|
817
|
+
}
|
|
815
818
|
if (message === 'API is disabled in this workspace') {
|
|
816
819
|
message =
|
|
817
820
|
'API is disabled in this workspace. To enable it, ask a workspace admin to update the settings';
|
|
@@ -819,8 +822,8 @@ const ERR_API_MESSAGE_REPLACER = (message, path, baseUrl, rateLimitTs) => {
|
|
|
819
822
|
message += `: ${workspaceUrl}`;
|
|
820
823
|
}
|
|
821
824
|
}
|
|
822
|
-
if (message === '
|
|
823
|
-
|
|
825
|
+
else if (message === 'Access denied') {
|
|
826
|
+
message = "You don't have permission to perform this action";
|
|
824
827
|
}
|
|
825
828
|
return message;
|
|
826
829
|
};
|
|
@@ -1151,23 +1154,23 @@ EXAMPLES:
|
|
|
1151
1154
|
exports.EXAMPLE_ARTIFACT_PUBLISH = `
|
|
1152
1155
|
EXAMPLES:
|
|
1153
1156
|
# publish new version of file artifact:
|
|
1154
|
-
bdy art pub artifact-identifier
|
|
1157
|
+
bdy art pub artifact-identifier:version /path/to/dir
|
|
1155
1158
|
|
|
1156
1159
|
# create new file artifact:
|
|
1157
1160
|
bdy art pub artifact-identifier --create
|
|
1158
1161
|
|
|
1159
1162
|
# overwrite existing version:
|
|
1160
|
-
bdy art pub artifact-identifier
|
|
1163
|
+
bdy art pub artifact-identifier:version /path/to/dir -f`;
|
|
1161
1164
|
exports.EXAMPLE_ARTIFACT_DOWNLOAD = `
|
|
1162
1165
|
EXAMPLES:
|
|
1163
1166
|
# download file artifact version to local directory:
|
|
1164
|
-
bdy art dd artifact-identifier
|
|
1167
|
+
bdy art dd artifact-identifier:version /path/to/dir
|
|
1165
1168
|
|
|
1166
1169
|
# download latest file artifact version and replace contents of existing local directory:
|
|
1167
1170
|
bdy art dd artifact-identifier /path/to/dir --replace
|
|
1168
1171
|
|
|
1169
1172
|
# download file artifact version and merge it with existing local directory:
|
|
1170
|
-
bdy art dd artifact-identifier
|
|
1173
|
+
bdy art dd artifact-identifier:version /path/to/dir --merge`;
|
|
1171
1174
|
exports.EXAMPLE_ARTIFACT_DELETE = `
|
|
1172
1175
|
EXAMPLES:
|
|
1173
1176
|
# delete artifact:
|
|
@@ -5,9 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TunnelHttpLogRequest = void 0;
|
|
7
7
|
const events_1 = __importDefault(require("events"));
|
|
8
|
-
const uuid_1 = require("uuid");
|
|
9
8
|
const stream_1 = __importDefault(require("./stream"));
|
|
10
|
-
const isbinaryfile_1 = require("isbinaryfile");
|
|
11
9
|
const utils_1 = require("../../utils");
|
|
12
10
|
const tunnel_1 = require("../../types/tunnel");
|
|
13
11
|
class TunnelHttpLogRequest extends events_1.default {
|
|
@@ -32,7 +30,7 @@ class TunnelHttpLogRequest extends events_1.default {
|
|
|
32
30
|
this.status = 'NEW';
|
|
33
31
|
this.start = process.hrtime();
|
|
34
32
|
this.finished = false;
|
|
35
|
-
this.id = (
|
|
33
|
+
this.id = require('uuid').v4();
|
|
36
34
|
this.requestBody = new stream_1.default(utils_1.TUNNEL_HTTP_LOG_MAX_BODY);
|
|
37
35
|
this.requestBody.once('close', () => {
|
|
38
36
|
this.emit(tunnel_1.TUNNEL_EVENT_HTTP.NEW_REQUEST_END);
|
|
@@ -62,7 +60,7 @@ class TunnelHttpLogRequest extends events_1.default {
|
|
|
62
60
|
requestBodyLength = this.requestBody.realLength;
|
|
63
61
|
requestBodyTooLarge =
|
|
64
62
|
requestBodyLength >= utils_1.TUNNEL_MAX_REQUEST_SIZE_TO_SYNC;
|
|
65
|
-
requestBodyBinary = (
|
|
63
|
+
requestBodyBinary = require('isbinaryfile').isBinaryFileSync(this.requestBody.data);
|
|
66
64
|
if (!requestBodyTooLarge && !requestBodyBinary) {
|
|
67
65
|
requestBody = this.requestBody.data.toString('base64');
|
|
68
66
|
}
|
|
@@ -71,7 +69,7 @@ class TunnelHttpLogRequest extends events_1.default {
|
|
|
71
69
|
responseBodyLength = this.responseBody.realLength;
|
|
72
70
|
responseBodyTooLarge =
|
|
73
71
|
requestBodyLength >= utils_1.TUNNEL_MAX_REQUEST_SIZE_TO_SYNC;
|
|
74
|
-
responseBodyBinary = (
|
|
72
|
+
responseBodyBinary = require('isbinaryfile').isBinaryFileSync(this.responseBody.data);
|
|
75
73
|
if (!responseBodyTooLarge && !responseBodyBinary) {
|
|
76
74
|
responseBody = this.responseBody.data.toString('base64');
|
|
77
75
|
}
|
|
@@ -3,24 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const stream_1 = require("stream");
|
|
4
4
|
class TunnelHttpStream extends stream_1.Transform {
|
|
5
5
|
maxSize;
|
|
6
|
-
|
|
6
|
+
chunks;
|
|
7
|
+
chunksLength;
|
|
7
8
|
realLength;
|
|
8
9
|
tooLarge;
|
|
9
10
|
constructor(maxSize) {
|
|
10
11
|
super();
|
|
11
12
|
this.maxSize = maxSize;
|
|
12
|
-
this.
|
|
13
|
+
this.chunks = [];
|
|
14
|
+
this.chunksLength = 0;
|
|
13
15
|
this.realLength = 0;
|
|
14
16
|
this.tooLarge = false;
|
|
15
17
|
}
|
|
18
|
+
get data() {
|
|
19
|
+
if (this.chunks.length === 0)
|
|
20
|
+
return Buffer.alloc(0);
|
|
21
|
+
if (this.chunks.length === 1)
|
|
22
|
+
return this.chunks[0];
|
|
23
|
+
const buf = Buffer.concat(this.chunks, this.chunksLength);
|
|
24
|
+
this.chunks = [buf];
|
|
25
|
+
return buf;
|
|
26
|
+
}
|
|
16
27
|
_transform(chunk, _, callback) {
|
|
17
28
|
if (!this.tooLarge) {
|
|
18
|
-
if (this.
|
|
29
|
+
if (this.chunksLength + chunk.length > this.maxSize) {
|
|
19
30
|
this.tooLarge = true;
|
|
20
|
-
this.
|
|
31
|
+
this.chunks = [];
|
|
32
|
+
this.chunksLength = 0;
|
|
21
33
|
}
|
|
22
34
|
else {
|
|
23
|
-
this.
|
|
35
|
+
this.chunks.push(chunk);
|
|
36
|
+
this.chunksLength += chunk.length;
|
|
24
37
|
}
|
|
25
38
|
}
|
|
26
39
|
this.realLength += chunk.length;
|
|
@@ -40,7 +40,7 @@ class ServerSsh extends events_1.default {
|
|
|
40
40
|
this.password = password;
|
|
41
41
|
this.server = new ssh2_1.default.Server({
|
|
42
42
|
hostKeys: [hostKey],
|
|
43
|
-
highWaterMark:
|
|
43
|
+
highWaterMark: 65536,
|
|
44
44
|
ident: 'ssh2 server',
|
|
45
45
|
}, (client) => this.processClient(client));
|
|
46
46
|
this.server.listen();
|
|
@@ -251,9 +251,26 @@ class ServerSsh extends events_1.default {
|
|
|
251
251
|
session.on('close', () => closeSession());
|
|
252
252
|
session.on('end', () => closeSession());
|
|
253
253
|
session.on('eof', () => {
|
|
254
|
+
// fix for sftp/scp exit status -1: send exit-status before EOF https://github.com/mscdex/ssh2/pull/1492
|
|
255
|
+
if (sftp) {
|
|
256
|
+
try {
|
|
257
|
+
logger_1.default.debug('sftp eof: sending exit-status 0');
|
|
258
|
+
session.exit(0);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
// do nothing
|
|
262
|
+
}
|
|
263
|
+
}
|
|
254
264
|
// @ts-ignore fix for sftp channel not ending properly https://github.com/mscdex/ssh2/pull/1111
|
|
255
|
-
if (session._channel)
|
|
256
|
-
|
|
265
|
+
if (session._channel) {
|
|
266
|
+
try {
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
session._channel.end();
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// do nothing
|
|
272
|
+
}
|
|
273
|
+
}
|
|
257
274
|
});
|
|
258
275
|
session.on('pty', (accept, reject, info) => {
|
|
259
276
|
logger_1.default.debug('ssh pty');
|
|
@@ -1,42 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const basic_auth_1 = __importDefault(require("basic-auth"));
|
|
40
6
|
const utils_1 = require("../utils");
|
|
41
7
|
const latency_1 = __importDefault(require("./latency"));
|
|
42
8
|
const events_1 = __importDefault(require("events"));
|
|
@@ -49,10 +15,6 @@ const http1_1 = __importDefault(require("./server/http1"));
|
|
|
49
15
|
const log_1 = __importDefault(require("./http/log"));
|
|
50
16
|
const format_1 = __importDefault(require("../format"));
|
|
51
17
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
52
|
-
const cookie = __importStar(require("cookie"));
|
|
53
|
-
const uuid_1 = require("uuid");
|
|
54
|
-
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
55
|
-
const undici_1 = require("undici");
|
|
56
18
|
const texts_1 = require("../texts");
|
|
57
19
|
const dns_1 = __importDefault(require("./dns"));
|
|
58
20
|
const tunnel_1 = require("../types/tunnel");
|
|
@@ -669,7 +631,7 @@ class Tunnel extends events_1.default {
|
|
|
669
631
|
}
|
|
670
632
|
async httpBasicAuth(req, res) {
|
|
671
633
|
if (this.authType === tunnel_1.TUNNEL_HTTP_AUTH_TYPE.BASIC) {
|
|
672
|
-
const user = (
|
|
634
|
+
const user = require('basic-auth')(req);
|
|
673
635
|
if (user && user.name === this.login && user.pass === this.password) {
|
|
674
636
|
return true;
|
|
675
637
|
}
|
|
@@ -686,7 +648,7 @@ class Tunnel extends events_1.default {
|
|
|
686
648
|
return true;
|
|
687
649
|
}
|
|
688
650
|
async _checkHttpPat(req, res, setCookie) {
|
|
689
|
-
const user = (
|
|
651
|
+
const user = require('basic-auth')(req);
|
|
690
652
|
if (!user || !user.name || !user.pass)
|
|
691
653
|
return false;
|
|
692
654
|
const client = this._getHttpAuthClient();
|
|
@@ -722,7 +684,8 @@ class Tunnel extends events_1.default {
|
|
|
722
684
|
_getHttpAuthClient() {
|
|
723
685
|
const host = this.agent.host;
|
|
724
686
|
if (!this.httpAuthClient[host]) {
|
|
725
|
-
|
|
687
|
+
const { Pool: UndiciPool } = require('undici');
|
|
688
|
+
this.httpAuthClient[host] = new UndiciPool(host, {
|
|
726
689
|
connect: {
|
|
727
690
|
rejectUnauthorized: false,
|
|
728
691
|
},
|
|
@@ -761,7 +724,7 @@ class Tunnel extends events_1.default {
|
|
|
761
724
|
reject(new Error(msg));
|
|
762
725
|
return;
|
|
763
726
|
}
|
|
764
|
-
const data = (
|
|
727
|
+
const data = require('jsonwebtoken').decode(token);
|
|
765
728
|
if (!data || !data.iss) {
|
|
766
729
|
reject(new Error(msg));
|
|
767
730
|
return;
|
|
@@ -771,7 +734,7 @@ class Tunnel extends events_1.default {
|
|
|
771
734
|
cert = ISSUERS[data.iss];
|
|
772
735
|
else
|
|
773
736
|
cert = ISSUERS['*'];
|
|
774
|
-
(
|
|
737
|
+
require('jsonwebtoken').verify(token, cert, {
|
|
775
738
|
complete: true,
|
|
776
739
|
issuer: data.iss,
|
|
777
740
|
}, (err, data) => {
|
|
@@ -796,7 +759,7 @@ class Tunnel extends events_1.default {
|
|
|
796
759
|
});
|
|
797
760
|
}
|
|
798
761
|
_httpSetAuthCookie(res, token) {
|
|
799
|
-
res.setHeader('set-cookie', cookie.serialize(COOKIE_NAME, token, {
|
|
762
|
+
res.setHeader('set-cookie', require('cookie').serialize(COOKIE_NAME, token, {
|
|
800
763
|
maxAge: 3600,
|
|
801
764
|
path: '/',
|
|
802
765
|
secure: true,
|
|
@@ -810,7 +773,7 @@ class Tunnel extends events_1.default {
|
|
|
810
773
|
token = await this._httpExchangeAuthCode(code, verifier);
|
|
811
774
|
}
|
|
812
775
|
if (!token) {
|
|
813
|
-
const cookies = cookie.parse(req.headers.cookie || '');
|
|
776
|
+
const cookies = require('cookie').parse(req.headers.cookie || '');
|
|
814
777
|
token = cookies[COOKIE_NAME] || '';
|
|
815
778
|
fromCookie = true;
|
|
816
779
|
}
|
|
@@ -877,7 +840,7 @@ class Tunnel extends events_1.default {
|
|
|
877
840
|
if (/^https:\/\/\d+\.\d+\.\d+\.\d+$/.test(host)) {
|
|
878
841
|
host = 'https://app.local.io';
|
|
879
842
|
}
|
|
880
|
-
const verifier = (
|
|
843
|
+
const verifier = require('uuid').v4();
|
|
881
844
|
const challenge = node_crypto_1.default
|
|
882
845
|
.createHash('sha256')
|
|
883
846
|
.update(verifier)
|
|
@@ -929,7 +892,7 @@ class Tunnel extends events_1.default {
|
|
|
929
892
|
this.httpEndFast(req, res, 404, 'Not found');
|
|
930
893
|
return false;
|
|
931
894
|
}
|
|
932
|
-
const auth = (
|
|
895
|
+
const auth = require('basic-auth')(req);
|
|
933
896
|
if (auth) {
|
|
934
897
|
const authorized = await this._checkHttpPat(req, res, true);
|
|
935
898
|
if (authorized) {
|
package/distTs/src/utils.js
CHANGED
|
@@ -54,7 +54,6 @@ exports.getPopularTlds = getPopularTlds;
|
|
|
54
54
|
exports.getAppHostByApiBaseUrl = getAppHostByApiBaseUrl;
|
|
55
55
|
const node_path_1 = __importDefault(require("node:path"));
|
|
56
56
|
const node_fs_1 = require("node:fs");
|
|
57
|
-
const undici_1 = __importDefault(require("undici"));
|
|
58
57
|
const texts_1 = require("./texts");
|
|
59
58
|
const node_sea_1 = require("node:sea");
|
|
60
59
|
const commander_1 = require("commander");
|
|
@@ -461,7 +460,7 @@ const getLatestVersion = async () => {
|
|
|
461
460
|
setTimeout(() => {
|
|
462
461
|
c.abort();
|
|
463
462
|
}, 10000);
|
|
464
|
-
const response = await
|
|
463
|
+
const response = await require('undici').fetch(`https://es.buddy.works/bdy/${env}/latest`, {
|
|
465
464
|
method: 'GET',
|
|
466
465
|
signal: c.signal,
|
|
467
466
|
});
|