bdy 1.15.7-dev-package → 1.16.2-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 +28 -56
- package/distTs/src/agent/linux.js +22 -23
- package/distTs/src/agent/manager.js +12 -105
- package/distTs/src/agent/osx.js +22 -27
- package/distTs/src/agent/socket/client.js +4 -4
- package/distTs/src/agent/system.js +89 -21
- package/distTs/src/agent/windows.js +21 -32
- package/distTs/src/api/client.js +25 -101
- package/distTs/src/command/agent/debug.js +10 -3
- package/distTs/src/command/agent/disable.js +6 -6
- package/distTs/src/command/agent/enable.js +6 -6
- package/distTs/src/command/agent/install.js +109 -27
- package/distTs/src/command/agent/restart.js +21 -11
- package/distTs/src/command/agent/run.js +1 -1
- package/distTs/src/command/agent/standalone/kill.js +22 -0
- package/distTs/src/command/agent/standalone.js +136 -0
- package/distTs/src/command/agent/start.js +19 -12
- package/distTs/src/command/agent/status.js +44 -17
- package/distTs/src/command/agent/stop.js +20 -13
- package/distTs/src/command/agent/target/disable.js +6 -6
- package/distTs/src/command/agent/target/enable.js +6 -6
- package/distTs/src/command/agent/target/status.js +6 -6
- package/distTs/src/command/agent/tunnel/http.js +6 -6
- package/distTs/src/command/agent/tunnel/list.js +6 -6
- package/distTs/src/command/agent/tunnel/remove.js +6 -6
- package/distTs/src/command/agent/tunnel/start.js +7 -7
- package/distTs/src/command/agent/tunnel/status.js +6 -6
- package/distTs/src/command/agent/tunnel/tcp.js +6 -6
- package/distTs/src/command/agent/tunnel/tls.js +6 -6
- package/distTs/src/command/agent/uninstall.js +2 -2
- package/distTs/src/command/agent/update.js +19 -17
- package/distTs/src/command/agent/version.js +3 -5
- package/distTs/src/command/agent.js +0 -4
- package/distTs/src/command/pipeline/run.js +3 -3
- package/distTs/src/command/pre.js +10 -2
- package/distTs/src/command/vt/scrap.js +193 -0
- package/distTs/src/index.js +0 -2
- package/distTs/src/input.js +1 -24
- package/distTs/src/output.js +16 -4
- package/distTs/src/texts.js +22 -85
- package/distTs/src/tunnel/api/agent.js +0 -9
- package/distTs/src/types/tunnel.js +0 -3
- package/package.json +1 -1
- package/distTs/src/command/package/download.js +0 -259
- package/distTs/src/command/package/publish.js +0 -231
- package/distTs/src/command/package.js +0 -14
|
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const output_1 = __importDefault(require("../../../output"));
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
9
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
10
9
|
const utils_1 = require("../../../utils");
|
|
11
10
|
const commandAgentTunnelList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_AGENT_TUNNEL_LIST);
|
|
12
11
|
commandAgentTunnelList.action(async () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
if (!commandAgentTunnelList.agentInstalled) {
|
|
13
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
14
|
+
}
|
|
15
|
+
if (!commandAgentTunnelList.agentStatus) {
|
|
16
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
16
17
|
}
|
|
17
18
|
try {
|
|
18
|
-
const
|
|
19
|
-
const api = new agent_1.default(json.port);
|
|
19
|
+
const api = new agent_1.default(commandAgentTunnelList.agentPort || 0);
|
|
20
20
|
const data = await api.fetchTunnels();
|
|
21
21
|
output_1.default.agentTunnels(data.tunnels);
|
|
22
22
|
}
|
|
@@ -6,18 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const output_1 = __importDefault(require("../../../output"));
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
9
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
10
9
|
const utils_1 = require("../../../utils");
|
|
11
10
|
const commandAgentTunnelRemove = (0, utils_1.newCommand)('rm', texts_1.DESC_COMMAND_AGENT_TUNNEL_REMOVE);
|
|
12
11
|
commandAgentTunnelRemove.argument('<id>', texts_1.OPTION_ID);
|
|
13
12
|
commandAgentTunnelRemove.action(async (id) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (!commandAgentTunnelRemove.agentInstalled) {
|
|
14
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
15
|
+
}
|
|
16
|
+
if (!commandAgentTunnelRemove.agentStatus) {
|
|
17
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
17
18
|
}
|
|
18
19
|
try {
|
|
19
|
-
const
|
|
20
|
-
const api = new agent_1.default(json.port);
|
|
20
|
+
const api = new agent_1.default(commandAgentTunnelRemove.agentPort || 0);
|
|
21
21
|
await api.stopTunnel(id);
|
|
22
22
|
output_1.default.exitSuccess(texts_1.TXT_TUNNEL_STOPPED);
|
|
23
23
|
}
|
|
@@ -7,23 +7,23 @@ const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
|
7
7
|
const output_1 = __importDefault(require("../../../output"));
|
|
8
8
|
const texts_1 = require("../../../texts");
|
|
9
9
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
10
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
11
10
|
const utils_1 = require("../../../utils");
|
|
12
11
|
const commandAgentTunnelStart = (0, utils_1.newCommand)('start', texts_1.DESC_COMMAND_START);
|
|
13
12
|
commandAgentTunnelStart.argument('<name>', texts_1.OPTION_NAME);
|
|
14
13
|
commandAgentTunnelStart.action(async (name) => {
|
|
14
|
+
if (!commandAgentTunnelStart.agentInstalled) {
|
|
15
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
16
|
+
}
|
|
17
|
+
if (!commandAgentTunnelStart.agentStatus) {
|
|
18
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
19
|
+
}
|
|
15
20
|
if (!cfg_1.default.hasTunnel(name)) {
|
|
16
21
|
output_1.default.exitError((0, texts_1.ERR_TUNNEL_NOT_FOUND)(name));
|
|
17
22
|
}
|
|
18
23
|
const prepared = cfg_1.default.getTunnel(name);
|
|
19
|
-
const isEnabled = await manager_1.default.system.isEnabled();
|
|
20
|
-
if (!isEnabled) {
|
|
21
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
22
|
-
}
|
|
23
24
|
try {
|
|
24
25
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
25
|
-
const
|
|
26
|
-
const api = new agent_1.default(json.port);
|
|
26
|
+
const api = new agent_1.default(commandAgentTunnelStart.agentPort || 0);
|
|
27
27
|
const data = await api.addTunnel(prepared);
|
|
28
28
|
output_1.default.exitSuccess((0, texts_1.TXT_TUNNEL_STARTED)(data.type));
|
|
29
29
|
}
|
|
@@ -7,18 +7,18 @@ const texts_1 = require("../../../texts");
|
|
|
7
7
|
const output_1 = __importDefault(require("../../../output"));
|
|
8
8
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
9
9
|
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
10
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
11
10
|
const utils_1 = require("../../../utils");
|
|
12
11
|
const commandAgentTunnelStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_TUNNEL_STATUS);
|
|
13
12
|
commandAgentTunnelStatus.argument('<id>', texts_1.OPTION_ID);
|
|
14
13
|
commandAgentTunnelStatus.action(async (id) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (!commandAgentTunnelStatus.agentInstalled) {
|
|
15
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
16
|
+
}
|
|
17
|
+
if (!commandAgentTunnelStatus.agentStatus) {
|
|
18
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
18
19
|
}
|
|
19
20
|
try {
|
|
20
|
-
const
|
|
21
|
-
const api = new agent_1.default(json.port);
|
|
21
|
+
const api = new agent_1.default(commandAgentTunnelStatus.agentPort || 0);
|
|
22
22
|
const ws = await api.socketTunnel(id);
|
|
23
23
|
const tunnel = new tunnel_1.default(ws, id);
|
|
24
24
|
await tunnel.waitForReady();
|
|
@@ -7,7 +7,6 @@ const utils_1 = require("../../../utils");
|
|
|
7
7
|
const output_1 = __importDefault(require("../../../output"));
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const texts_1 = require("../../../texts");
|
|
10
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
11
10
|
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
12
11
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
13
12
|
const tunnel_2 = require("../../../types/tunnel");
|
|
@@ -16,15 +15,16 @@ commandAgentTunnelTcp.description(texts_1.DESC_COMMAND_TCP);
|
|
|
16
15
|
commandAgentTunnelTcp.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
17
16
|
commandAgentTunnelTcp.argument('[host:port]', texts_1.OPTION_TARGET);
|
|
18
17
|
commandAgentTunnelTcp.action(async (target, options) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (!commandAgentTunnelTcp.agentInstalled) {
|
|
19
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
20
|
+
}
|
|
21
|
+
if (!commandAgentTunnelTcp.agentStatus) {
|
|
22
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
22
23
|
}
|
|
23
24
|
const prepared = await cfg_1.default.prepareTunnel(tunnel_2.TUNNEL_TYPE.TCP, target, options, true);
|
|
24
25
|
try {
|
|
25
26
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
26
|
-
const
|
|
27
|
-
const api = new agent_1.default(json.port);
|
|
27
|
+
const api = new agent_1.default(commandAgentTunnelTcp.agentPort || 0);
|
|
28
28
|
const data = await api.addTunnel(prepared);
|
|
29
29
|
if (options.follow) {
|
|
30
30
|
const ws = await api.socketTunnel(data.id);
|
|
@@ -8,7 +8,6 @@ const output_1 = __importDefault(require("../../../output"));
|
|
|
8
8
|
const cfg_1 = __importDefault(require("../../../tunnel/cfg"));
|
|
9
9
|
const texts_1 = require("../../../texts");
|
|
10
10
|
const tunnel_1 = __importDefault(require("../../../agent/socket/tunnel"));
|
|
11
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
12
11
|
const agent_1 = __importDefault(require("../../../tunnel/api/agent"));
|
|
13
12
|
const tunnel_2 = require("../../../types/tunnel");
|
|
14
13
|
const commandAgentTunnelTls = (0, utils_1.getBasicCommandTls)();
|
|
@@ -16,15 +15,16 @@ commandAgentTunnelTls.description(texts_1.DESC_COMMAND_TLS);
|
|
|
16
15
|
commandAgentTunnelTls.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
17
16
|
commandAgentTunnelTls.argument('[host:port]', texts_1.OPTION_TARGET);
|
|
18
17
|
commandAgentTunnelTls.action(async (target, options) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (!commandAgentTunnelTls.agentInstalled) {
|
|
19
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
20
|
+
}
|
|
21
|
+
if (!commandAgentTunnelTls.agentStatus) {
|
|
22
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
22
23
|
}
|
|
23
24
|
const prepared = await cfg_1.default.prepareTunnel(tunnel_2.TUNNEL_TYPE.TLS, target, options, true);
|
|
24
25
|
try {
|
|
25
26
|
await output_1.default.spinner(texts_1.TXT_OPENING_TUNNEL);
|
|
26
|
-
const
|
|
27
|
-
const api = new agent_1.default(json.port);
|
|
27
|
+
const api = new agent_1.default(commandAgentTunnelTls.agentPort || 0);
|
|
28
28
|
const data = await api.addTunnel(prepared);
|
|
29
29
|
if (options.follow) {
|
|
30
30
|
const ws = await api.socketTunnel(data.id);
|
|
@@ -15,13 +15,13 @@ commandAgentUninstall.action(async () => {
|
|
|
15
15
|
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
await manager_1.default.system.
|
|
18
|
+
await manager_1.default.system.uninstall();
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
21
|
// do nothing
|
|
22
22
|
}
|
|
23
23
|
try {
|
|
24
|
-
manager_1.default.system.killStandaloneProc();
|
|
24
|
+
await manager_1.default.system.killStandaloneProc();
|
|
25
25
|
}
|
|
26
26
|
catch {
|
|
27
27
|
// do nothing
|
|
@@ -16,26 +16,28 @@ commandAgentUpdate.action(async () => {
|
|
|
16
16
|
if (!hasAdminRights) {
|
|
17
17
|
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
22
|
-
}
|
|
23
|
-
if (manager_1.default.system.isStandaloneProcRunning()) {
|
|
24
|
-
output_1.default.exitError(texts_1.ERR_AGENT_STANDALONE_UPDATE);
|
|
19
|
+
if (!commandAgentUpdate.agentInstalled) {
|
|
20
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
25
21
|
}
|
|
26
22
|
output_1.default.normal(texts_1.TXT_UPDATING_AGENT);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
await (0, wait_1.default)(api, 15000, () => {
|
|
32
|
-
output_1.default.exitError(texts_1.ERR_SWW_AGENT_UPDATING);
|
|
33
|
-
}, () => {
|
|
34
|
-
output_1.default.exitSuccess(texts_1.TXT_AGENT_UPDATED);
|
|
35
|
-
});
|
|
23
|
+
if (commandAgentUpdate.agentStandalone) {
|
|
24
|
+
// app
|
|
25
|
+
await manager_1.default.system.killStandaloneProc();
|
|
26
|
+
manager_1.default.system.startStandaloneProc();
|
|
36
27
|
}
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
else {
|
|
29
|
+
try {
|
|
30
|
+
await manager_1.default.system.update();
|
|
31
|
+
const api = new agent_1.default(commandAgentUpdate.agentPort || 0);
|
|
32
|
+
await (0, wait_1.default)(api, 15000, () => {
|
|
33
|
+
output_1.default.exitError(texts_1.ERR_SWW_AGENT_UPDATING);
|
|
34
|
+
}, () => {
|
|
35
|
+
output_1.default.exitSuccess(texts_1.TXT_AGENT_UPDATED);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
output_1.default.exitError(texts_1.ERR_SWW_AGENT_UPDATING);
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
43
|
exports.default = commandAgentUpdate;
|
|
@@ -5,16 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const output_1 = __importDefault(require("../../output"));
|
|
7
7
|
const texts_1 = require("../../texts");
|
|
8
|
-
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
9
8
|
const utils_1 = require("../../utils");
|
|
10
9
|
const commandAgentVersion = (0, utils_1.newCommand)('version', texts_1.DESC_COMMAND_AGENT_VERSION);
|
|
11
10
|
commandAgentVersion.action(async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_ENABLED);
|
|
11
|
+
if (!commandAgentVersion.agentInstalled) {
|
|
12
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
15
13
|
}
|
|
16
14
|
if (!commandAgentVersion.agentStatus) {
|
|
17
|
-
output_1.default.exitError(texts_1.
|
|
15
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
18
16
|
}
|
|
19
17
|
output_1.default.exitNormal(commandAgentVersion.agentStatus.version);
|
|
20
18
|
});
|
|
@@ -19,12 +19,8 @@ const target_1 = __importDefault(require("./agent/target"));
|
|
|
19
19
|
const enable_1 = __importDefault(require("./agent/enable"));
|
|
20
20
|
const disable_1 = __importDefault(require("./agent/disable"));
|
|
21
21
|
const debug_1 = __importDefault(require("./agent/debug"));
|
|
22
|
-
const up_1 = __importDefault(require("./agent/up"));
|
|
23
|
-
const down_1 = __importDefault(require("./agent/down"));
|
|
24
22
|
const commandAgent = (0, utils_1.newCommand)('agent', texts_1.DESC_COMMAND_AGENT);
|
|
25
23
|
commandAgent.addCommand(install_1.default);
|
|
26
|
-
commandAgent.addCommand(up_1.default);
|
|
27
|
-
commandAgent.addCommand(down_1.default);
|
|
28
24
|
commandAgent.addCommand(enable_1.default);
|
|
29
25
|
commandAgent.addCommand(disable_1.default);
|
|
30
26
|
commandAgent.addCommand(start_1.default);
|
|
@@ -38,13 +38,13 @@ commandPipelineRun.action(async (identifier, options) => {
|
|
|
38
38
|
const client = new client_1.default(baseUrl, token);
|
|
39
39
|
const data = await client.getPipelineByIdentifier(workspace, project, identifier);
|
|
40
40
|
if (!data || !data.domain) {
|
|
41
|
-
output_1.default.exitError(texts_1.
|
|
41
|
+
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WORKSPACE_NOT_FOUND);
|
|
42
42
|
}
|
|
43
43
|
if (!data.project_identifier) {
|
|
44
|
-
output_1.default.exitError(texts_1.
|
|
44
|
+
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_PROJECT_NOT_FOUND);
|
|
45
45
|
}
|
|
46
46
|
if (!data.pipeline_id) {
|
|
47
|
-
output_1.default.exitError(texts_1.
|
|
47
|
+
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_NOT_FOUND);
|
|
48
48
|
}
|
|
49
49
|
const body = {};
|
|
50
50
|
if (options.branch) {
|
|
@@ -9,11 +9,19 @@ const manager_1 = __importDefault(require("../agent/manager"));
|
|
|
9
9
|
const agent_1 = __importDefault(require("../tunnel/api/agent"));
|
|
10
10
|
const commandPre = async (_, command) => {
|
|
11
11
|
command.agentStatus = null;
|
|
12
|
+
command.agentStandalone = false;
|
|
13
|
+
command.agentInstalled = false;
|
|
14
|
+
command.agentPort = 0;
|
|
15
|
+
command.agentId = '';
|
|
12
16
|
try {
|
|
13
17
|
if (!(0, utils_1.isDocker)()) {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
18
|
+
const hasConfig = manager_1.default.system.hasSystemConfig();
|
|
19
|
+
if (hasConfig) {
|
|
20
|
+
command.agentInstalled = true;
|
|
16
21
|
const json = manager_1.default.system.loadSystemConfig();
|
|
22
|
+
command.agentStandalone = !!json.standalone; // nie zawsze to jest bool
|
|
23
|
+
command.agentId = json.id;
|
|
24
|
+
command.agentPort = json.port;
|
|
17
25
|
const api = new agent_1.default(json.port);
|
|
18
26
|
command.agentStatus = await api.fetchStatus();
|
|
19
27
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const texts_1 = require("../../texts");
|
|
9
|
+
const validation_1 = require("../../visualTest/validation");
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const requests_1 = require("../../visualTest/requests");
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const node_zlib_1 = require("node:zlib");
|
|
14
|
+
const tar_stream_1 = __importDefault(require("tar-stream"));
|
|
15
|
+
const promises_1 = require("node:stream/promises");
|
|
16
|
+
const node_fs_1 = require("node:fs");
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const promises_2 = require("node:fs/promises");
|
|
19
|
+
const commandScrap = (0, utils_1.newCommand)('scrap', texts_1.DESC_COMMAND_VT_SCRAP);
|
|
20
|
+
commandScrap.argument('<url>', texts_1.OPTION_SCRAP_URL);
|
|
21
|
+
commandScrap.option('--follow', texts_1.OPTION_SCRAP_FOLLOW, false);
|
|
22
|
+
commandScrap.addOption(new commander_1.Option('--outputType <type>', texts_1.OPTION_SCRAP_OUTPUT_TYPE)
|
|
23
|
+
.choices(['jpeg', 'png', 'md', 'html'])
|
|
24
|
+
.makeOptionMandatory());
|
|
25
|
+
commandScrap.option('--quality <quality>', texts_1.OPTION_SCRAP_QUALITY);
|
|
26
|
+
commandScrap.option('--fullPage', texts_1.OPTION_SCRAP_FULL_PAGE, false);
|
|
27
|
+
commandScrap.option('--cssSelector <selector>', texts_1.OPTION_SCRAP_CSS_SELECTOR);
|
|
28
|
+
commandScrap.option('--xpathSelector <selector>', texts_1.OPTION_SCRAP_XPATH_SELECTOR);
|
|
29
|
+
commandScrap.addOption(new commander_1.Option('--browser <browser>', texts_1.OPTION_SCRAP_BROWSER)
|
|
30
|
+
.choices(['chrome', 'firefox', 'safari'])
|
|
31
|
+
.default('chrome'));
|
|
32
|
+
commandScrap.option('--viewport <viewport>', texts_1.OPTION_SCRAP_VIEWPORT, '1920x1080');
|
|
33
|
+
commandScrap.option('--devicePixelRatio <ratio>', texts_1.OPTION_SCRAP_DEVICE_PIXEL_RATIO, '1');
|
|
34
|
+
commandScrap.option('--waitForElement <selector>', texts_1.OPTION_SCRAP_WAIT_FOR_ELEMENT);
|
|
35
|
+
commandScrap.option('--darkMode', texts_1.OPTION_SCRAP_DARK_MODE, false);
|
|
36
|
+
commandScrap.option('--delay <delay>', texts_1.OPTION_SCRAP_DELAY, '0');
|
|
37
|
+
commandScrap.option('--outputDir <dir>', texts_1.OPTION_SCRAP_OUTPUT_DIR, '.');
|
|
38
|
+
commandScrap.action(async (inputUrl, options) => {
|
|
39
|
+
if (!(0, validation_1.checkToken)()) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
|
|
41
|
+
}
|
|
42
|
+
const { url, follow, outputType, quality, outputDir, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement, } = validateInputAndOptions(inputUrl, options);
|
|
43
|
+
try {
|
|
44
|
+
const { buildId } = await (0, requests_1.sendScrap)(url, outputType, follow, quality, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement);
|
|
45
|
+
output_1.default.normal('Starting scrap session');
|
|
46
|
+
const status = await watchSessionStatus(buildId);
|
|
47
|
+
if (!status.ok) {
|
|
48
|
+
output_1.default.exitError(`Unexpected error while watching session status: ${status.error}`);
|
|
49
|
+
}
|
|
50
|
+
output_1.default.normal('Downloading scrap package');
|
|
51
|
+
const scrapPackageStream = await (0, requests_1.downloadScrapPackage)(buildId);
|
|
52
|
+
const brotliDecompressor = (0, node_zlib_1.createBrotliDecompress)();
|
|
53
|
+
const unpack = tar_stream_1.default.extract();
|
|
54
|
+
unpack.on('entry', async (header, stream, next) => {
|
|
55
|
+
const currentDir = process.cwd();
|
|
56
|
+
const preparedOutputDir = outputDir.startsWith('.')
|
|
57
|
+
? node_path_1.default.join(currentDir, outputDir)
|
|
58
|
+
: outputDir;
|
|
59
|
+
const newFilePath = node_path_1.default.join(preparedOutputDir, header.name);
|
|
60
|
+
try {
|
|
61
|
+
if (header.type === 'file') {
|
|
62
|
+
await (0, promises_2.mkdir)(node_path_1.default.dirname(newFilePath), { recursive: true });
|
|
63
|
+
const fileWriteStream = (0, node_fs_1.createWriteStream)(newFilePath);
|
|
64
|
+
await (0, promises_1.pipeline)(stream, fileWriteStream);
|
|
65
|
+
next();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
stream.resume();
|
|
69
|
+
next();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (entryError) {
|
|
73
|
+
output_1.default.error(`Error processing entry ${header.name}: ${entryError}`);
|
|
74
|
+
next(entryError);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
await (0, promises_1.pipeline)(scrapPackageStream, brotliDecompressor, unpack);
|
|
78
|
+
output_1.default.exitSuccess('Downloading scrap package finished');
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
output_1.default.exitError(`${error}`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
function validateInputAndOptions(input, options) {
|
|
85
|
+
const urlSchema = zod_1.z.string().url();
|
|
86
|
+
const optionsSchema = zod_1.z.object({
|
|
87
|
+
follow: zod_1.z.boolean(),
|
|
88
|
+
outputType: zod_1.z.enum(['jpeg', 'png', 'md', 'html']),
|
|
89
|
+
quality: zod_1.z.coerce.number().min(1).max(100).optional(),
|
|
90
|
+
outputDir: zod_1.z.string().default('.'),
|
|
91
|
+
fullPage: zod_1.z.boolean().optional(),
|
|
92
|
+
cssSelector: zod_1.z.string().optional(),
|
|
93
|
+
xpathSelector: zod_1.z.string().optional(),
|
|
94
|
+
browser: zod_1.z.enum(['chrome', 'firefox', 'safari']),
|
|
95
|
+
viewport: zod_1.z
|
|
96
|
+
.string()
|
|
97
|
+
.refine((value) => {
|
|
98
|
+
const [width, height] = value.split('x');
|
|
99
|
+
return (width &&
|
|
100
|
+
height &&
|
|
101
|
+
!isNaN(Number(width)) &&
|
|
102
|
+
!isNaN(Number(height)) &&
|
|
103
|
+
Number(width) > 0 &&
|
|
104
|
+
Number(height) > 0);
|
|
105
|
+
}, 'Invalid viewport format, example: 1920x1080')
|
|
106
|
+
.transform((value) => {
|
|
107
|
+
const [width, height] = value.split('x');
|
|
108
|
+
return {
|
|
109
|
+
width: Number(width),
|
|
110
|
+
height: Number(height),
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
devicePixelRatio: zod_1.z.coerce.number().min(1).max(4),
|
|
114
|
+
darkMode: zod_1.z.boolean(),
|
|
115
|
+
delay: zod_1.z.coerce.number().min(0).max(10000),
|
|
116
|
+
waitForElement: zod_1.z.string().optional(),
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
const url = urlSchema.parse(input);
|
|
120
|
+
const { follow, outputType, quality, outputDir, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement, } = optionsSchema.parse(options);
|
|
121
|
+
if (typeof quality === 'number' && outputType !== 'jpeg') {
|
|
122
|
+
output_1.default.exitError('Quality is only supported for jpeg output type, use --outputType jpeg');
|
|
123
|
+
}
|
|
124
|
+
if (cssSelector && xpathSelector) {
|
|
125
|
+
output_1.default.exitError('Only one of --cssSelector or --xpathSelector can be used');
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
url,
|
|
129
|
+
follow,
|
|
130
|
+
outputType,
|
|
131
|
+
quality,
|
|
132
|
+
outputDir,
|
|
133
|
+
fullPage,
|
|
134
|
+
cssSelector,
|
|
135
|
+
xpathSelector,
|
|
136
|
+
browser,
|
|
137
|
+
viewport,
|
|
138
|
+
devicePixelRatio,
|
|
139
|
+
darkMode,
|
|
140
|
+
delay,
|
|
141
|
+
waitForElement,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof zod_1.ZodError) {
|
|
146
|
+
output_1.default.exitError(error.errors.map((e) => `${e.path}: ${e.message}`).join(', '));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function watchSessionStatus(buildId) {
|
|
154
|
+
return new Promise((resolve) => {
|
|
155
|
+
const eventSource = (0, requests_1.connectToScrapSession)(buildId);
|
|
156
|
+
eventSource.addEventListener('SESSION_STATUS', (event) => {
|
|
157
|
+
const data = JSON.parse(event.data);
|
|
158
|
+
if (data.status === 'GATHER_URLS_COMPLETED') {
|
|
159
|
+
output_1.default.normal(`Gathering URLs completed, found ${data.text} URLs`);
|
|
160
|
+
}
|
|
161
|
+
else if (data.status === 'GATHER_URLS_FAILED') {
|
|
162
|
+
output_1.default.error('Gathering URLs failed');
|
|
163
|
+
}
|
|
164
|
+
else if (data.status === 'SCRAPE_URL_COMPLETED') {
|
|
165
|
+
output_1.default.normal(`Scraping ${data.text} completed`);
|
|
166
|
+
}
|
|
167
|
+
else if (data.status === 'SCRAPE_URL_FAILED') {
|
|
168
|
+
output_1.default.error(`Scraping ${data.text} failed`);
|
|
169
|
+
}
|
|
170
|
+
else if (data.status === 'CREATE_PACKAGE_COMPLETED') {
|
|
171
|
+
output_1.default.normal('Package created');
|
|
172
|
+
}
|
|
173
|
+
else if (data.status === 'CREATE_PACKAGE_FAILED') {
|
|
174
|
+
output_1.default.error('Package creation failed');
|
|
175
|
+
}
|
|
176
|
+
else if (data.status === 'FINISHED') {
|
|
177
|
+
eventSource.close();
|
|
178
|
+
output_1.default.normal('Scrap session finished');
|
|
179
|
+
resolve({ ok: true });
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
eventSource.addEventListener('error', (event) => {
|
|
183
|
+
if (event.code) {
|
|
184
|
+
eventSource.close();
|
|
185
|
+
if (event.code === 410) {
|
|
186
|
+
output_1.default.normal('Scrap session finished');
|
|
187
|
+
}
|
|
188
|
+
resolve({ ok: event.code === 410, error: event.code });
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
exports.default = commandScrap;
|
package/distTs/src/index.js
CHANGED
|
@@ -15,7 +15,6 @@ const vt_1 = __importDefault(require("./command/vt"));
|
|
|
15
15
|
const ut_1 = __importDefault(require("./command/ut"));
|
|
16
16
|
const tunnel_1 = __importDefault(require("./command/tunnel"));
|
|
17
17
|
const pipeline_1 = __importDefault(require("./command/pipeline"));
|
|
18
|
-
const package_1 = __importDefault(require("./command/package"));
|
|
19
18
|
stream_1.default.setDefaultHighWaterMark(false, 67108864);
|
|
20
19
|
process.title = 'bdy';
|
|
21
20
|
process.on('uncaughtException', (err) => {
|
|
@@ -34,5 +33,4 @@ program.addCommand(version_1.default);
|
|
|
34
33
|
program.addCommand(vt_1.default);
|
|
35
34
|
program.addCommand(ut_1.default);
|
|
36
35
|
program.addCommand(pipeline_1.default);
|
|
37
|
-
program.addCommand(package_1.default);
|
|
38
36
|
program.parse();
|
package/distTs/src/input.js
CHANGED
|
@@ -45,7 +45,6 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
|
45
45
|
const utils_1 = require("./utils");
|
|
46
46
|
const texts_1 = require("./texts");
|
|
47
47
|
const tunnel_1 = require("./types/tunnel");
|
|
48
|
-
const node_path_1 = require("node:path");
|
|
49
48
|
class Input {
|
|
50
49
|
static timeout(timeout) {
|
|
51
50
|
const t = parseInt(timeout, 10);
|
|
@@ -340,14 +339,6 @@ class Input {
|
|
|
340
339
|
t = 1440;
|
|
341
340
|
return t;
|
|
342
341
|
}
|
|
343
|
-
static resolvePath(path) {
|
|
344
|
-
const p = (0, node_path_1.resolve)(path);
|
|
345
|
-
const exists = fs_1.default.existsSync(p);
|
|
346
|
-
if (!exists) {
|
|
347
|
-
output_1.default.exitError(texts_1.ERR_PATH_NOT_EXISTS);
|
|
348
|
-
}
|
|
349
|
-
return p;
|
|
350
|
-
}
|
|
351
342
|
static restApiWorkspace(workspace) {
|
|
352
343
|
let w = process.env.BUDDY_WORKSPACE;
|
|
353
344
|
if (workspace)
|
|
@@ -357,25 +348,11 @@ class Input {
|
|
|
357
348
|
}
|
|
358
349
|
return w;
|
|
359
350
|
}
|
|
360
|
-
static
|
|
361
|
-
const s = (identifier || '').split('@');
|
|
362
|
-
if (s.length >= 2) {
|
|
363
|
-
return {
|
|
364
|
-
identifier: s[0],
|
|
365
|
-
version: s[1],
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
return {
|
|
369
|
-
identifier: s[0],
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
static restApiProject(project, allowNull = false) {
|
|
351
|
+
static restApiProject(project) {
|
|
373
352
|
let p = process.env.BUDDY_PROJECT;
|
|
374
353
|
if (project)
|
|
375
354
|
p = project;
|
|
376
355
|
if (!p) {
|
|
377
|
-
if (allowNull)
|
|
378
|
-
return null;
|
|
379
356
|
output_1.default.exitError(texts_1.ERR_REST_API_PROJECT);
|
|
380
357
|
}
|
|
381
358
|
return p;
|
package/distTs/src/output.js
CHANGED
|
@@ -35,11 +35,23 @@ class Output {
|
|
|
35
35
|
msg += '\n';
|
|
36
36
|
terminal(msg);
|
|
37
37
|
}
|
|
38
|
-
static warning(txt) {
|
|
39
|
-
|
|
38
|
+
static warning(txt, newLine = true) {
|
|
39
|
+
let msg = txt;
|
|
40
|
+
if (newLine)
|
|
41
|
+
msg += '\n';
|
|
42
|
+
terminal.yellow(msg);
|
|
43
|
+
}
|
|
44
|
+
static error(txt, newLine = true) {
|
|
45
|
+
let msg = txt;
|
|
46
|
+
if (newLine)
|
|
47
|
+
msg += '\n';
|
|
48
|
+
terminal.red(msg);
|
|
40
49
|
}
|
|
41
|
-
static
|
|
42
|
-
|
|
50
|
+
static green(txt, newLine = true) {
|
|
51
|
+
let msg = txt;
|
|
52
|
+
if (newLine)
|
|
53
|
+
msg += '\n';
|
|
54
|
+
terminal.green(msg);
|
|
43
55
|
}
|
|
44
56
|
static debug(txt) {
|
|
45
57
|
if (context_1.debug) {
|