bdy 1.15.6-stage → 1.15.7-dev-package
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/api/client.js +101 -25
- package/distTs/src/command/package/download.js +259 -0
- package/distTs/src/command/package/publish.js +231 -0
- package/distTs/src/command/package.js +14 -0
- package/distTs/src/command/pipeline/run.js +3 -3
- package/distTs/src/index.js +2 -0
- package/distTs/src/input.js +24 -1
- package/distTs/src/texts.js +59 -13
- package/package.json +1 -1
- package/distTs/src/command/agent/standalone/kill.js +0 -22
- package/distTs/src/command/agent/standalone.js +0 -136
- package/distTs/src/command/vt/scrap.js +0 -193
package/distTs/package.json
CHANGED
package/distTs/src/api/client.js
CHANGED
|
@@ -19,26 +19,12 @@ class ApiClient {
|
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
async
|
|
23
|
-
const headers = {
|
|
24
|
-
authorization: `Bearer ${this.token}`,
|
|
25
|
-
};
|
|
26
|
-
let bodyParsed = undefined;
|
|
27
|
-
if (body) {
|
|
28
|
-
headers['content-type'] = 'application/json; charset=utf-8';
|
|
29
|
-
bodyParsed = JSON.stringify(body);
|
|
30
|
-
}
|
|
31
|
-
const opts = {
|
|
32
|
-
method,
|
|
33
|
-
path,
|
|
34
|
-
headers,
|
|
35
|
-
body: bodyParsed,
|
|
36
|
-
};
|
|
22
|
+
async _request(opts, parseResponseBody = false, returnRawBody = false) {
|
|
37
23
|
let status;
|
|
38
24
|
let responseBody;
|
|
39
|
-
logger_1.default.debug(`API CLIENT: ${method} ${this.baseUrl.protocol}//${this.baseUrl.host}${path}`);
|
|
40
|
-
logger_1.default.debug(headers);
|
|
41
|
-
logger_1.default.debug(body);
|
|
25
|
+
logger_1.default.debug(`API CLIENT: ${opts.method} ${this.baseUrl.protocol}//${this.baseUrl.host}${opts.path}`);
|
|
26
|
+
logger_1.default.debug(opts.headers);
|
|
27
|
+
logger_1.default.debug(opts.body);
|
|
42
28
|
try {
|
|
43
29
|
const r = await this.client.request(opts);
|
|
44
30
|
status = r.statusCode;
|
|
@@ -54,11 +40,7 @@ class ApiClient {
|
|
|
54
40
|
await responseBody.dump();
|
|
55
41
|
throw new Error(texts_1.ERR_REST_API_WRONG_TOKEN);
|
|
56
42
|
}
|
|
57
|
-
if (
|
|
58
|
-
await responseBody.dump();
|
|
59
|
-
throw new Error(texts_1.ERR_REST_API_RATE_LIMIT);
|
|
60
|
-
}
|
|
61
|
-
if ([400, 404].includes(status)) {
|
|
43
|
+
if ([400, 404, 403].includes(status)) {
|
|
62
44
|
let json;
|
|
63
45
|
try {
|
|
64
46
|
json = await responseBody.json();
|
|
@@ -79,7 +61,7 @@ class ApiClient {
|
|
|
79
61
|
else
|
|
80
62
|
throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
|
|
81
63
|
}
|
|
82
|
-
if (status
|
|
64
|
+
if ([200, 201].includes(status)) {
|
|
83
65
|
if (parseResponseBody) {
|
|
84
66
|
try {
|
|
85
67
|
const b = await responseBody.json();
|
|
@@ -93,6 +75,9 @@ class ApiClient {
|
|
|
93
75
|
throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
|
|
94
76
|
}
|
|
95
77
|
}
|
|
78
|
+
else if (returnRawBody) {
|
|
79
|
+
return responseBody;
|
|
80
|
+
}
|
|
96
81
|
else {
|
|
97
82
|
await responseBody.dump();
|
|
98
83
|
return null;
|
|
@@ -103,8 +88,58 @@ class ApiClient {
|
|
|
103
88
|
throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
|
|
104
89
|
}
|
|
105
90
|
}
|
|
91
|
+
async requestMultipart(path, body, parseResponseBody = false) {
|
|
92
|
+
const headers = {
|
|
93
|
+
authorization: `Bearer ${this.token}`,
|
|
94
|
+
};
|
|
95
|
+
const opts = {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
path,
|
|
98
|
+
headers,
|
|
99
|
+
body,
|
|
100
|
+
};
|
|
101
|
+
return await this._request(opts, parseResponseBody);
|
|
102
|
+
}
|
|
103
|
+
async request(method, path, body, parseResponseBody = false, returnRawBody = false) {
|
|
104
|
+
const headers = {
|
|
105
|
+
authorization: `Bearer ${this.token}`,
|
|
106
|
+
};
|
|
107
|
+
let bodyParsed = undefined;
|
|
108
|
+
if (body) {
|
|
109
|
+
headers['content-type'] = 'application/json; charset=utf-8';
|
|
110
|
+
bodyParsed = JSON.stringify(body);
|
|
111
|
+
}
|
|
112
|
+
const opts = {
|
|
113
|
+
method,
|
|
114
|
+
path,
|
|
115
|
+
headers,
|
|
116
|
+
body: bodyParsed,
|
|
117
|
+
};
|
|
118
|
+
return await this._request(opts, parseResponseBody, returnRawBody);
|
|
119
|
+
}
|
|
120
|
+
async getResourceByIdentifier(workspace, params) {
|
|
121
|
+
let query = '';
|
|
122
|
+
Object.keys(params).forEach((key) => {
|
|
123
|
+
if (!query)
|
|
124
|
+
query += '?';
|
|
125
|
+
else
|
|
126
|
+
query += '&';
|
|
127
|
+
query += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
|
|
128
|
+
});
|
|
129
|
+
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/identifiers${query}`, null, true);
|
|
130
|
+
}
|
|
106
131
|
async getPipelineByIdentifier(workspace, project, identifier) {
|
|
107
|
-
return await this.
|
|
132
|
+
return await this.getResourceByIdentifier(workspace, { project, pipeline: identifier });
|
|
133
|
+
}
|
|
134
|
+
async getPackageVersionByIdentifier(workspace, project, pkg, version) {
|
|
135
|
+
const opts = {
|
|
136
|
+
package: pkg,
|
|
137
|
+
};
|
|
138
|
+
if (project)
|
|
139
|
+
opts.project = project;
|
|
140
|
+
if (version)
|
|
141
|
+
opts.package_version = version;
|
|
142
|
+
return await this.getResourceByIdentifier(workspace, opts);
|
|
108
143
|
}
|
|
109
144
|
async getPipelineRun(workspace, project, pipelineId, executionId) {
|
|
110
145
|
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/pipelines/${encodeURIComponent(pipelineId)}/executions/${encodeURIComponent(executionId)}`, null, true);
|
|
@@ -112,5 +147,46 @@ class ApiClient {
|
|
|
112
147
|
async postPipelineRun(workspace, project, pipelineId, body) {
|
|
113
148
|
return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/pipelines/${encodeURIComponent(pipelineId)}/executions`, body, true);
|
|
114
149
|
}
|
|
150
|
+
async getPackageVersion(workspace, pkgId, versionId) {
|
|
151
|
+
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions/${encodeURIComponent(versionId)}`, null, true);
|
|
152
|
+
}
|
|
153
|
+
async getPackageLatest(workspace, pkgId) {
|
|
154
|
+
const res = await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions?page=1&per_page=1`, null, true);
|
|
155
|
+
if (res && res.versions && res.versions.length > 0) {
|
|
156
|
+
return res.versions[0];
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
async downloadPackageVersion(workspace, pkgId, versionId) {
|
|
161
|
+
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions/${encodeURIComponent(versionId)}/download`, null, false, true);
|
|
162
|
+
}
|
|
163
|
+
async postPackageVersion(workspace, pkgId, version) {
|
|
164
|
+
return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions`, {
|
|
165
|
+
version
|
|
166
|
+
}, true);
|
|
167
|
+
}
|
|
168
|
+
async postPackageVersionZip(workspace, pkgId, versionId, file) {
|
|
169
|
+
const form = new undici_1.FormData();
|
|
170
|
+
form.append('file', file);
|
|
171
|
+
return await this.requestMultipart(`/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions/${versionId}/upload`, form, true);
|
|
172
|
+
}
|
|
173
|
+
async postPackage(workspace, project, identifier) {
|
|
174
|
+
const body = {
|
|
175
|
+
name: identifier,
|
|
176
|
+
identifier,
|
|
177
|
+
type: 'FILE',
|
|
178
|
+
scope: 'WORKSPACE',
|
|
179
|
+
authorization: {
|
|
180
|
+
type: 'BUDDY'
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
if (project) {
|
|
184
|
+
body.project = {
|
|
185
|
+
name: project
|
|
186
|
+
};
|
|
187
|
+
body.scope = 'PROJECT';
|
|
188
|
+
}
|
|
189
|
+
return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/packages`, body, true);
|
|
190
|
+
}
|
|
115
191
|
}
|
|
116
192
|
exports.default = ApiClient;
|
|
@@ -0,0 +1,259 @@
|
|
|
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 texts_1 = require("../../texts");
|
|
8
|
+
const input_1 = __importDefault(require("../../input"));
|
|
9
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const promises_1 = __importDefault(require("stream/promises"));
|
|
16
|
+
const fflate_1 = require("fflate");
|
|
17
|
+
const commandPackageDownload = (0, utils_1.newCommand)('download', texts_1.DESC_COMMAND_PACKAGE_DOWNLOAD);
|
|
18
|
+
commandPackageDownload.alias('dd');
|
|
19
|
+
commandPackageDownload.option('-t, --token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
20
|
+
commandPackageDownload.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
21
|
+
commandPackageDownload.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
22
|
+
commandPackageDownload.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
23
|
+
commandPackageDownload.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
24
|
+
commandPackageDownload.option('-m, --merge', texts_1.OPTION_PACKAGE_DOWNLOAD_MERGE);
|
|
25
|
+
commandPackageDownload.option('-r, --replace', texts_1.OPTION_PACKAGE_DOWNLOAD_REPLACE);
|
|
26
|
+
commandPackageDownload.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
27
|
+
commandPackageDownload.argument('<directory>', texts_1.OPTION_PACKAGE_DOWNLOAD_PATH);
|
|
28
|
+
commandPackageDownload.action(async (id, path, options) => {
|
|
29
|
+
const token = input_1.default.restApiToken(options.token);
|
|
30
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
31
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
32
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
33
|
+
const client = new client_1.default(baseUrl, token);
|
|
34
|
+
// eslint-disable-next-line prefer-const
|
|
35
|
+
let { identifier, version } = input_1.default.packageSplitIdentifier(id);
|
|
36
|
+
const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
|
|
37
|
+
if (!data || !data.domain) {
|
|
38
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
39
|
+
}
|
|
40
|
+
if (project && !data.project_identifier) {
|
|
41
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
|
|
42
|
+
}
|
|
43
|
+
const packageId = data.pkg_id;
|
|
44
|
+
if (!packageId) {
|
|
45
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_DOWNLOAD_NOT_FOUND);
|
|
46
|
+
}
|
|
47
|
+
let versionId = data.pkg_version_id;
|
|
48
|
+
if (version && !versionId) {
|
|
49
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_NOT_FOUND);
|
|
50
|
+
}
|
|
51
|
+
if (!version || !versionId) {
|
|
52
|
+
const v = await client.getPackageLatest(workspace, packageId);
|
|
53
|
+
if (!v) {
|
|
54
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_NOT_FOUND);
|
|
55
|
+
}
|
|
56
|
+
version = v.version;
|
|
57
|
+
versionId = v.id;
|
|
58
|
+
}
|
|
59
|
+
const dirPath = (0, path_1.resolve)(path);
|
|
60
|
+
const exists = fs_1.default.existsSync(dirPath);
|
|
61
|
+
if (!exists) {
|
|
62
|
+
try {
|
|
63
|
+
fs_1.default.mkdirSync(dirPath, {
|
|
64
|
+
recursive: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
logger_1.default.error(err);
|
|
69
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_MKDIR)(dirPath));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (options.replace) {
|
|
73
|
+
try {
|
|
74
|
+
fs_1.default.rmSync(dirPath, {
|
|
75
|
+
recursive: true,
|
|
76
|
+
force: true,
|
|
77
|
+
});
|
|
78
|
+
fs_1.default.mkdirSync(dirPath, {
|
|
79
|
+
recursive: true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
logger_1.default.error(err);
|
|
84
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_REPLACE)(dirPath));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
89
|
+
if (!stat.isDirectory()) {
|
|
90
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_IS_FILE)(dirPath));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
logger_1.default.error(err);
|
|
95
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
96
|
+
}
|
|
97
|
+
let empty = true;
|
|
98
|
+
try {
|
|
99
|
+
const entries = fs_1.default.readdirSync(dirPath);
|
|
100
|
+
empty = !entries.length;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
logger_1.default.error(err);
|
|
104
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_READDIR)(dirPath));
|
|
105
|
+
}
|
|
106
|
+
if (!empty && !options.merge) {
|
|
107
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
|
|
108
|
+
}
|
|
109
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
110
|
+
const clearZip = () => {
|
|
111
|
+
try {
|
|
112
|
+
fs_1.default.rmSync(zipPath);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// do nothing
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADING_ZIP);
|
|
119
|
+
const body = await client.downloadPackageVersion(workspace, packageId, versionId);
|
|
120
|
+
try {
|
|
121
|
+
await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
|
|
122
|
+
output_1.default.clearPreviousLine();
|
|
123
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADED_ZIP);
|
|
124
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPING);
|
|
125
|
+
let count = 0;
|
|
126
|
+
await unzip(dirPath, zipPath, () => {
|
|
127
|
+
count += 1;
|
|
128
|
+
output_1.default.clearPreviousLine();
|
|
129
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_UNZIPPING_COUNT)(count));
|
|
130
|
+
});
|
|
131
|
+
clearZip();
|
|
132
|
+
output_1.default.clearPreviousLine();
|
|
133
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPED);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
logger_1.default.error(err);
|
|
137
|
+
clearZip();
|
|
138
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
139
|
+
}
|
|
140
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_DOWNLOADED)(version, dirPath));
|
|
141
|
+
});
|
|
142
|
+
const unzip = (dirPath, zipPath, onFile) => {
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
let _startedFiles = 0;
|
|
145
|
+
let _finishedFiles = 0;
|
|
146
|
+
let _finishedStream = false;
|
|
147
|
+
let _finishedError = null;
|
|
148
|
+
let _calledResolve = false;
|
|
149
|
+
const rs = fs_1.default.createReadStream(zipPath);
|
|
150
|
+
const _finish = () => {
|
|
151
|
+
if (_finishedError || _finishedStream) {
|
|
152
|
+
try {
|
|
153
|
+
rs.removeAllListeners();
|
|
154
|
+
rs.close();
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// do nothing
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (_calledResolve)
|
|
161
|
+
return;
|
|
162
|
+
if (_finishedError) {
|
|
163
|
+
_calledResolve = true;
|
|
164
|
+
reject(_finishedError);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (_finishedStream && _startedFiles === _finishedFiles) {
|
|
168
|
+
_calledResolve = true;
|
|
169
|
+
resolve();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const finishFile = (err, fws) => {
|
|
173
|
+
if (!_finishedError && err)
|
|
174
|
+
_finishedError = err;
|
|
175
|
+
_finishedFiles += 1;
|
|
176
|
+
if (fws) {
|
|
177
|
+
try {
|
|
178
|
+
fws.removeAllListeners();
|
|
179
|
+
fws.close();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// do nothing
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
onFile();
|
|
186
|
+
_finish();
|
|
187
|
+
};
|
|
188
|
+
const finishStream = (err) => {
|
|
189
|
+
if (!_finishedError && err)
|
|
190
|
+
_finishedError = err;
|
|
191
|
+
_finishedStream = true;
|
|
192
|
+
_finish();
|
|
193
|
+
};
|
|
194
|
+
const unzip = new fflate_1.Unzip(async (file) => {
|
|
195
|
+
if (_finishedError)
|
|
196
|
+
return;
|
|
197
|
+
_startedFiles += 1;
|
|
198
|
+
const fullPath = (0, path_1.join)(dirPath, file.name);
|
|
199
|
+
const parentPath = (0, path_1.dirname)(fullPath);
|
|
200
|
+
let fws;
|
|
201
|
+
try {
|
|
202
|
+
await fs_1.default.promises.rm(fullPath, {
|
|
203
|
+
recursive: true,
|
|
204
|
+
force: true,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// do nothing
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
if (fullPath.endsWith('/')) {
|
|
212
|
+
await fs_1.default.promises.mkdir(fullPath, {
|
|
213
|
+
recursive: true,
|
|
214
|
+
});
|
|
215
|
+
finishFile();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
await fs_1.default.promises.mkdir(parentPath, {
|
|
219
|
+
recursive: true,
|
|
220
|
+
});
|
|
221
|
+
fws = fs_1.default.createWriteStream(fullPath, {
|
|
222
|
+
flags: 'w',
|
|
223
|
+
});
|
|
224
|
+
fws.on('error', (err) => {
|
|
225
|
+
finishFile(err, fws);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
finishFile(err, fws);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
file.ondata = (err, data, final) => {
|
|
233
|
+
if (_finishedError)
|
|
234
|
+
return;
|
|
235
|
+
if (err)
|
|
236
|
+
finishFile(err, fws);
|
|
237
|
+
else {
|
|
238
|
+
if (fws)
|
|
239
|
+
fws.write(data);
|
|
240
|
+
if (final)
|
|
241
|
+
finishFile(null, fws);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
file.start();
|
|
245
|
+
});
|
|
246
|
+
unzip.register(fflate_1.AsyncUnzipInflate);
|
|
247
|
+
rs.on('data', (chunk) => {
|
|
248
|
+
unzip.push(chunk, false);
|
|
249
|
+
});
|
|
250
|
+
rs.on('error', (err) => {
|
|
251
|
+
finishStream(err);
|
|
252
|
+
});
|
|
253
|
+
rs.on('end', () => {
|
|
254
|
+
unzip.push(new Uint8Array(0), true);
|
|
255
|
+
finishStream();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
exports.default = commandPackageDownload;
|
|
@@ -0,0 +1,231 @@
|
|
|
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 texts_1 = require("../../texts");
|
|
8
|
+
const input_1 = __importDefault(require("../../input"));
|
|
9
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
+
const fflate_1 = __importDefault(require("fflate"));
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
const commandPackagePublish = (0, utils_1.newCommand)('publish', texts_1.DESC_COMMAND_PACKAGE_PUBLISH);
|
|
17
|
+
commandPackagePublish.alias('pub');
|
|
18
|
+
commandPackagePublish.option('-t, --token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
19
|
+
commandPackagePublish.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
20
|
+
commandPackagePublish.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
21
|
+
commandPackagePublish.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
22
|
+
commandPackagePublish.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
23
|
+
commandPackagePublish.option('-c, --create', texts_1.OPTION_PACKAGE_PUBLISH_CREATE);
|
|
24
|
+
commandPackagePublish.option('-f, --force', texts_1.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION);
|
|
25
|
+
commandPackagePublish.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
26
|
+
commandPackagePublish.argument('<directory>', texts_1.OPTION_PACKAGE_PUBLISH_PATH);
|
|
27
|
+
commandPackagePublish.action(async (id, path, options) => {
|
|
28
|
+
let dirPath = input_1.default.resolvePath(path);
|
|
29
|
+
const token = input_1.default.restApiToken(options.token);
|
|
30
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
31
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
32
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
33
|
+
// eslint-disable-next-line prefer-const
|
|
34
|
+
let { identifier, version } = input_1.default.packageSplitIdentifier(id);
|
|
35
|
+
if (!version)
|
|
36
|
+
version = (0, uuid_1.v4)();
|
|
37
|
+
const client = new client_1.default(baseUrl, token);
|
|
38
|
+
const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
|
|
39
|
+
if (!data || !data.domain) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
41
|
+
}
|
|
42
|
+
if (project && !data.project_identifier) {
|
|
43
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
|
|
44
|
+
}
|
|
45
|
+
let packageId = data.pkg_id;
|
|
46
|
+
if (!packageId) {
|
|
47
|
+
if (options.create) {
|
|
48
|
+
const d = await client.postPackage(workspace, project, identifier);
|
|
49
|
+
packageId = d.id;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_PUBLISH_NOT_FOUND);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let packageVersionId = data.pkg_version_id;
|
|
56
|
+
let url;
|
|
57
|
+
if (packageVersionId && !options.force) {
|
|
58
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_EXISTS);
|
|
59
|
+
}
|
|
60
|
+
if (!packageVersionId) {
|
|
61
|
+
const d = await client.postPackageVersion(workspace, packageId, version);
|
|
62
|
+
url = d.version_url;
|
|
63
|
+
packageVersionId = d.id;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const d = await client.getPackageVersion(workspace, packageId, packageVersionId);
|
|
67
|
+
url = d.version_url;
|
|
68
|
+
}
|
|
69
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_SCANNING_DIR, false);
|
|
70
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
71
|
+
let entries;
|
|
72
|
+
if (stat.isDirectory()) {
|
|
73
|
+
entries = fs_1.default.readdirSync(dirPath, {
|
|
74
|
+
withFileTypes: true,
|
|
75
|
+
recursive: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const parentPath = (0, path_1.dirname)(dirPath);
|
|
80
|
+
entries = [
|
|
81
|
+
{
|
|
82
|
+
isDirectory: () => stat.isDirectory(),
|
|
83
|
+
isFile: () => stat.isFile(),
|
|
84
|
+
isBlockDevice: () => stat.isBlockDevice(),
|
|
85
|
+
isCharacterDevice: () => stat.isCharacterDevice(),
|
|
86
|
+
isFIFO: () => stat.isFIFO(),
|
|
87
|
+
isSocket: () => stat.isSocket(),
|
|
88
|
+
isSymbolicLink: () => stat.isSymbolicLink(),
|
|
89
|
+
name: (0, path_1.basename)(dirPath),
|
|
90
|
+
parentPath,
|
|
91
|
+
path: parentPath,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
dirPath = parentPath;
|
|
95
|
+
}
|
|
96
|
+
if (!entries.length) {
|
|
97
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_NO_ENTRIES_FOUND);
|
|
98
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
99
|
+
}
|
|
100
|
+
else if (entries.length === 1) {
|
|
101
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ONE_ENTRY_FOUND);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ENTRIES_FOUND)(entries.length));
|
|
105
|
+
}
|
|
106
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(0));
|
|
107
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
108
|
+
const clearZip = () => {
|
|
109
|
+
try {
|
|
110
|
+
fs_1.default.rmSync(zipPath);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// do nothing
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
let blob;
|
|
117
|
+
try {
|
|
118
|
+
let proc = 0;
|
|
119
|
+
await createZip(dirPath, zipPath, entries, () => {
|
|
120
|
+
proc += 1;
|
|
121
|
+
output_1.default.clearPreviousLine();
|
|
122
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(proc));
|
|
123
|
+
});
|
|
124
|
+
output_1.default.clearPreviousLine();
|
|
125
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ZIPPED);
|
|
126
|
+
blob = await fs_1.default.openAsBlob(zipPath);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
logger_1.default.error(err);
|
|
130
|
+
clearZip();
|
|
131
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADING);
|
|
135
|
+
await client.postPackageVersionZip(workspace, packageId, packageVersionId, blob);
|
|
136
|
+
output_1.default.clearPreviousLine();
|
|
137
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADED);
|
|
138
|
+
clearZip();
|
|
139
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
clearZip();
|
|
143
|
+
logger_1.default.error(err);
|
|
144
|
+
output_1.default.exitError(err);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const addEntryToZip = (dirPath, zip, entry) => {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const isDir = entry.isDirectory();
|
|
150
|
+
let name = (0, path_1.join)(entry.parentPath.replace(dirPath, ''), entry.name);
|
|
151
|
+
if (isDir)
|
|
152
|
+
name += '/';
|
|
153
|
+
const file = new fflate_1.default.AsyncZipDeflate(name, {
|
|
154
|
+
level: 9,
|
|
155
|
+
});
|
|
156
|
+
zip.add(file);
|
|
157
|
+
if (isDir) {
|
|
158
|
+
file.push(new Uint8Array(0), true);
|
|
159
|
+
resolve();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const fullPath = (0, path_1.join)(entry.parentPath, entry.name);
|
|
163
|
+
const rs = fs_1.default.createReadStream(fullPath);
|
|
164
|
+
const finish = (err) => {
|
|
165
|
+
try {
|
|
166
|
+
rs.removeAllListeners();
|
|
167
|
+
rs.close();
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// do nothing
|
|
171
|
+
}
|
|
172
|
+
if (err)
|
|
173
|
+
reject(err);
|
|
174
|
+
else
|
|
175
|
+
resolve();
|
|
176
|
+
};
|
|
177
|
+
rs.on('data', (chunk) => {
|
|
178
|
+
file.push(chunk, false);
|
|
179
|
+
});
|
|
180
|
+
rs.on('error', (err) => {
|
|
181
|
+
finish(err);
|
|
182
|
+
});
|
|
183
|
+
rs.on('end', () => {
|
|
184
|
+
file.push(new Uint8Array(0), true);
|
|
185
|
+
finish();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const addEntriesToZip = async (dirPath, zip, entries, onEntry) => {
|
|
190
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
191
|
+
await addEntryToZip(dirPath, zip, entries[i]);
|
|
192
|
+
onEntry();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const createZip = (dirPath, zipPath, entries, onEntry) => {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
const ws = fs_1.default.createWriteStream(zipPath);
|
|
198
|
+
let wasError = false;
|
|
199
|
+
const zip = new fflate_1.default.Zip((err, data, final) => {
|
|
200
|
+
if (wasError) {
|
|
201
|
+
// do nothing
|
|
202
|
+
}
|
|
203
|
+
else if (err) {
|
|
204
|
+
wasError = true;
|
|
205
|
+
ws.close();
|
|
206
|
+
reject(err);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
ws.write(data);
|
|
210
|
+
if (final) {
|
|
211
|
+
ws.close((err) => {
|
|
212
|
+
if (err)
|
|
213
|
+
reject(err);
|
|
214
|
+
else
|
|
215
|
+
resolve();
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
addEntriesToZip(dirPath, zip, entries, onEntry)
|
|
221
|
+
.then(() => {
|
|
222
|
+
zip.end();
|
|
223
|
+
})
|
|
224
|
+
.catch((err) => {
|
|
225
|
+
ws.close(() => {
|
|
226
|
+
reject(err);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
exports.default = commandPackagePublish;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 texts_1 = require("../texts");
|
|
8
|
+
const publish_1 = __importDefault(require("./package/publish"));
|
|
9
|
+
const download_1 = __importDefault(require("./package/download"));
|
|
10
|
+
const commandPackage = (0, utils_1.newCommand)('package', texts_1.DESC_COMMAND_PACKAGE);
|
|
11
|
+
commandPackage.alias('pkg');
|
|
12
|
+
commandPackage.addCommand(publish_1.default);
|
|
13
|
+
commandPackage.addCommand(download_1.default);
|
|
14
|
+
exports.default = commandPackage;
|
|
@@ -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_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_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_PIPELINE_NOT_FOUND);
|
|
48
48
|
}
|
|
49
49
|
const body = {};
|
|
50
50
|
if (options.branch) {
|
package/distTs/src/index.js
CHANGED
|
@@ -15,6 +15,7 @@ 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"));
|
|
18
19
|
stream_1.default.setDefaultHighWaterMark(false, 67108864);
|
|
19
20
|
process.title = 'bdy';
|
|
20
21
|
process.on('uncaughtException', (err) => {
|
|
@@ -33,4 +34,5 @@ program.addCommand(version_1.default);
|
|
|
33
34
|
program.addCommand(vt_1.default);
|
|
34
35
|
program.addCommand(ut_1.default);
|
|
35
36
|
program.addCommand(pipeline_1.default);
|
|
37
|
+
program.addCommand(package_1.default);
|
|
36
38
|
program.parse();
|
package/distTs/src/input.js
CHANGED
|
@@ -45,6 +45,7 @@ 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");
|
|
48
49
|
class Input {
|
|
49
50
|
static timeout(timeout) {
|
|
50
51
|
const t = parseInt(timeout, 10);
|
|
@@ -339,6 +340,14 @@ class Input {
|
|
|
339
340
|
t = 1440;
|
|
340
341
|
return t;
|
|
341
342
|
}
|
|
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
|
+
}
|
|
342
351
|
static restApiWorkspace(workspace) {
|
|
343
352
|
let w = process.env.BUDDY_WORKSPACE;
|
|
344
353
|
if (workspace)
|
|
@@ -348,11 +357,25 @@ class Input {
|
|
|
348
357
|
}
|
|
349
358
|
return w;
|
|
350
359
|
}
|
|
351
|
-
static
|
|
360
|
+
static packageSplitIdentifier(identifier) {
|
|
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) {
|
|
352
373
|
let p = process.env.BUDDY_PROJECT;
|
|
353
374
|
if (project)
|
|
354
375
|
p = project;
|
|
355
376
|
if (!p) {
|
|
377
|
+
if (allowNull)
|
|
378
|
+
return null;
|
|
356
379
|
output_1.default.exitError(texts_1.ERR_REST_API_PROJECT);
|
|
357
380
|
}
|
|
358
381
|
return p;
|
package/distTs/src/texts.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
3
|
+
exports.ERR_SWW_AGENT_ENABLING = exports.ERR_AGENT_NOT_FOUND = exports.ERR_AGENT_STANDALONE_SERVICE_INSTALLED = exports.ERR_AGENT_NOT_RUNNING = exports.ERR_AGENT_STANDALONE_UPDATE = exports.ERR_AGENT_NOT_ENABLED = exports.ERR_TUNNEL_NOT_FOUND = exports.ERR_WHITELIST_IS_NOT_VALID = exports.ERR_USER_AGENT_IS_NOT_VALID = exports.ERR_BA_IS_NOT_VALID = exports.ERR_BA_LOGIN_NOT_PROVIDED = exports.ERR_BA_PASSWORD_NOT_PROVIDED = exports.ERR_CB_THRESHOLD_IS_NOT_VALID = exports.ERR_CERT_PATH_IS_NOT_VALID = exports.ERR_KEY_PATH_IS_NOT_VALID = exports.ERR_CA_PATH_IS_NOT_VALID = exports.ERR_WRONG_CA = exports.ERR_WRONG_KEY_CERT = exports.ERR_NAME_WITHOUT_ASTERISK = exports.ERR_PORT_IS_NOT_VALID = exports.ERR_REGION_IS_NOT_VALID = exports.ERR_PATH_IS_NOT_DIRECTORY = exports.ERR_DIRECTORY_DOES_NOT_EXISTS = exports.ERR_TERMINATE_IS_NOT_VALID = exports.ERR_TIMEOUT_IS_NOT_VALID = exports.ERR_TYPE_IS_NOT_VALID = exports.ERR_TARGET_IS_NOT_VALID = exports.ERR_SAVING_AGENT_CONFIG = exports.ERR_AGENT_NOT_REGISTERED = exports.ERR_RUN_PIPELINE_WRONG_VARIABLE = exports.ERR_RUN_PIPELINE_WRONG_ACTION = exports.ERR_RUN_PIPELINE_WRONG_DELAY = exports.ERR_RUN_PIPELINE_WRONG_PRIORITY = exports.ERR_RUN_PIPELINE_WAIT_TIMEOUT = exports.ERR_PACKAGE_VERSION_NOT_FOUND = exports.ERR_PACKAGE_VERSION_EXISTS = exports.ERR_PACKAGE_PUBLISH_NOT_FOUND = exports.ERR_PACKAGE_DOWNLOAD_NOT_FOUND = exports.ERR_PIPELINE_NOT_FOUND = exports.ERR_PROJECT_NOT_FOUND = exports.ERR_WORKSPACE_NOT_FOUND = exports.ERR_REST_API_PROJECT = exports.ERR_REST_API_WORKSPACE = exports.ERR_PATH_NOT_EXISTS = exports.ERR_REST_API_URL = exports.ERR_REST_API_TOKEN = exports.ERR_REST_API_RATE_LIMIT = exports.ERR_REST_API_RESOURCE_NOT_FOUND = exports.ERR_REST_API_WRONG_TOKEN = exports.ERR_REST_API_GENERAL_ERROR = void 0;
|
|
4
|
+
exports.ERR_TEST_EXECUTION = exports.ERR_INVALID_JSON = exports.ERR_INVALID_DOWNLOAD_RESPONSE = exports.ERR_INVALID_SCRAPE_RESPONSE = exports.ERR_INVALID_COMPARE_LINKS_RESPONSE = exports.ERR_INVALID_STORYBOOK_RESPONSE = exports.ERR_INVALID_DEFAULT_SETTINGS_RESPONSE = exports.ERR_INVALID_CLOSE_SESSION_RESPONSE = exports.ERR_INVALID_SNAPSHOTS_RESPONSE = exports.ERR_INVALID_SNAPSHOT_RESPONSE = exports.ERR_MISSING_URLS = exports.ERR_RESOURCE_NOT_FOUND = exports.ERR_MISSING_EXEC_COMMAND = exports.ERR_PARSING_STORIES = exports.ERR_UNSUPPORTED_STORYBOOK = exports.ERR_MISSING_STORYBOOK_INDEX_FILE = exports.ERR_WRONG_STORYBOOK_DIRECTORY = exports.ERR_MISSING_BUILD_ID = exports.ERR_MISSING_UT_TOKEN = exports.ERR_MISSING_VT_TOKEN = exports.ERR_CONFIG_CORRUPTED = exports.ERR_WRONG_TOKEN = exports.ERR_TOKEN_NOT_PROVIDED = exports.ERR_CANT_CREATE_DIR_IN_HOME = exports.ERR_CONNECTION_ERROR = exports.ERR_CONNECTION_TIMEOUT = exports.ERR_WRONG_STREAM = exports.ERR_WRONG_HANDSHAKE = exports.ERR_FETCH_VERSION = exports.ERR_PACKAGE_DOWNLOAD_REPLACE = exports.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR = exports.ERR_PACKAGE_DOWNLOAD_IS_FILE = exports.ERR_PACKAGE_DOWNLOAD_READDIR = exports.ERR_PACKAGE_DOWNLOAD_MKDIR = exports.ERR_SWW = exports.ERR_NOT_FOUND = exports.ERR_FAILED_TO_CONNECT_TO_AGENT = exports.ERR_TUNNEL_REMOVED = exports.ERR_TUNNELS_DISABLED = exports.ERR_AGENT_LIMIT_REACHED = exports.ERR_TUNNEL_TARGET_INVALID = exports.ERR_WORKSPACE_FLAGGED = exports.ERR_TUNNEL_LIMIT_REACHED = exports.ERR_DOMAIN_RESTRICTED = exports.ERR_AGENT_REMOVED = exports.ERR_FAILED_TO_CONNECT = exports.ERR_TUNNEL_ALREADY_EXISTS = exports.ERR_AGENT_NOT_SUPPORTED = exports.ERR_AGENT_ADMIN_RIGHTS = exports.ERR_SWW_AGENT_UPDATING = void 0;
|
|
5
|
+
exports.DESC_COMMAND_CONFIG_ADD_TLS = exports.DESC_COMMAND_CONFIG_ADD_TCP = exports.DESC_COMMAND_CONFIG_ADD_HTTP = exports.AGENT_FETCH_RETRY = exports.NO_TUNNELS_STARTED = exports.TXT_AGENT_STANDALONE_USING_AGENT = exports.TXT_AGENT_STANDALONE_EXITING = exports.TXT_AGENT_STANDALONE_STOPPED = exports.TXT_AGENT_STANDALONE_STARTED = exports.TXT_AGENT_STANDALONE_AGENT_REGISTER_ERROR = exports.TXT_AGENT_STANDALONE_AGENT_REGISTERED = exports.TXT_AGENT_STANDALONE_AGENT_REGISTERING = exports.TXT_AGENT_STANDALONE_AGENT_FETCH_ERROR = exports.TXT_AGENT_STANDALONE_AGENT_FETCHED = exports.TXT_AGENT_STANDALONE_AGENT_FETCHING = exports.TXT_AGENT_STANDALONE_CONFIG_NOT_FOUND = exports.TXT_AGENT_STANDALONE_CONFIG_FOUND = exports.TXT_AGENT_STANDALONE_CONFIG_CHECKING = exports.TXT_AGENT_STANDALONE_PROC_ERROR = exports.TXT_AGENT_STANDALONE_PROC_CHECKED = exports.TXT_AGENT_STANDALONE_PROC_CHECKING = exports.TXT_TUNNEL_ADDED = exports.TXT_TUNNEL_REMOVED = exports.TXT_REGION_SAVED = exports.TXT_TIMEOUT_SAVED = exports.TXT_TOKEN_REMOVED = exports.TXT_TOKEN_SAVED = exports.TXT_WHITELIST_SAVED = exports.TXT_TUNNEL_STOPPED = exports.TXT_TUNNEL_STARTED = exports.TXT_AGENT_DISABLED = exports.TXT_AGENT_ALREADY_ENABLED = exports.TXT_AGENT_UPDATED = exports.TXT_AGENT_ENABLED = exports.TXT_AGENT_TARGET_DISABLED = exports.TXT_AGENT_TARGET_ENABLED = exports.TXT_AGENT_IS_DISABLED = exports.TXT_AGENT_IS_ENABLED_AND_HAVE_TROUBLES = exports.TXT_AGENT_IS_ENABLED_AND_INITIALIZING = exports.TXT_AGENT_IS_ENABLED_AND_STOPPED = exports.TXT_AGENT_IS_ENABLED_AND_STARTED = exports.TXT_AGENT_RESTARTED = exports.TXT_AGENT_DEBUG_OFF = exports.TXT_AGENT_DEBUG_ON = exports.TXT_AGENT_STARTED = exports.TXT_AGENT_STOPPED = exports.WARN_BROWSER_VERSION = exports.ERR_RESOURCE_DISCOVERY = exports.ERR_NO_SNAPSHOTS_TO_SEND = exports.ERR_INVALID_SNAPSHOT = void 0;
|
|
6
|
+
exports.DESC_COMMAND_VT = exports.DESC_COMMAND_PIPELINE_RUN = exports.DESC_COMMAND_PACKAGE_DOWNLOAD = exports.DESC_COMMAND_PACKAGE_PUBLISH = exports.DESC_COMMAND_PACKAGE = exports.DESC_COMMAND_PIPELINE = exports.DESC_PROGRAM = exports.DESC_COMMAND_TLS = exports.DESC_COMMAND_TCP = exports.DESC_COMMAND_START = exports.DESC_COMMAND_TUNNEL = exports.DESC_COMMAND_AGENT = exports.DESC_COMMAND_HTTP = exports.DESC_COMMAND_CONFIG = exports.DESC_COMMAND_AGENT_VERSION = exports.DESC_COMMAND_AGENT_UPDATE = exports.DESC_COMMAND_AGENT_TARGET = exports.DESC_COMMAND_AGENT_TUNNEL = exports.DESC_COMMAND_AGENT_STOP = exports.DESC_COMMAND_AGENT_TARGET_DISABLE = exports.DESC_COMMAND_AGENT_TARGET_ENABLE = exports.DESC_COMMAND_AGENT_TARGET_STATUS = exports.DESC_COMMAND_AGENT_STATUS = exports.DESC_COMMAND_AGENT_RESTART = exports.DESC_COMMAND_AGENT_ENABLE = exports.DESC_COMMAND_AGENT_DEBUG = exports.DESC_COMMAND_AGENT_DISABLE = exports.DESC_COMMAND_AGENT_START = exports.DESC_COMMAND_AGENT_STANDALONE_KILL = exports.DESC_COMMAND_AGENT_STANDALONE = exports.DESC_COMMAND_AGENT_INSTALL = exports.DESC_COMMAND_AGENT_UNINSTALL = exports.DESC_COMMAND_AGENT_TUNNEL_REMOVE = exports.DESC_COMMAND_AGENT_TUNNEL_STATUS = exports.DESC_COMMAND_AGENT_TUNNEL_LIST = exports.DESC_COMMAND_CONFIG_SET = exports.DESC_COMMAND_CONFIG_REMOVE = exports.DESC_COMMAND_CONFIG_GET = exports.DESC_COMMAND_CONFIG_ADD = exports.DESC_COMMAND_CONFIG_SET_WHITELIST = exports.DESC_COMMAND_CONFIG_SET_TOKEN = exports.DESC_COMMAND_CONFIG_SET_TIMEOUT = exports.DESC_COMMAND_CONFIG_SET_REGION = exports.DESC_COMMAND_CONFIG_REMOVE_TUNNEL = exports.DESC_COMMAND_CONFIG_GET_WHITELIST = exports.DESC_COMMAND_CONFIG_GET_TUNNELS = exports.DESC_COMMAND_CONFIG_GET_TUNNEL = exports.DESC_COMMAND_CONFIG_GET_TOKEN = exports.DESC_COMMAND_CONFIG_GET_TIMEOUT = exports.DESC_COMMAND_CONFIG_GET_REGION = void 0;
|
|
7
|
+
exports.OPTION_PIPELINE_RUN_PRIORITY = exports.OPTION_PIPELINE_RUN_CLEAR_CACHE = exports.OPTION_PIPELINE_RUN_REFRESH = exports.OPTION_PIPELINE_RUN_COMMENT = exports.OPTION_PIPELINE_RUN_PULL_REQUEST = exports.OPTION_PIPELINE_RUN_REVISION = exports.OPTION_PIPELINE_RUN_TAG = exports.OPTION_PIPELINE_RUN_BRANCH = exports.OPTION_REST_API_REGION = exports.OPTION_REST_API_ENDPOINT = exports.OPTION_DEFAULT_REGION = exports.OPTION_REGION = exports.TXT_PACKAGE_UNZIPPING_COUNT = exports.TXT_PACKAGE_UNZIPPED = exports.TXT_PACKAGE_UNZIPPING = exports.TXT_PACKAGE_DOWNLOADED_ZIP = exports.TXT_PACKAGE_DOWNLOADING_ZIP = exports.TXT_PACKAGE_DOWNLOADED = exports.TXT_PACKAGE_PUBLISHED = exports.TXT_PACKAGE_ENTRIES_FOUND = exports.TXT_PACKAGE_UPLOADED = exports.TXT_PACKAGE_UPLOADING = exports.TXT_PACKAGE_ZIPPED = exports.TXT_PACKAGE_ZIP_ENTRIES = exports.TXT_PACKAGE_ONE_ENTRY_FOUND = exports.TXT_PACKAGE_NO_ENTRIES_FOUND = exports.TXT_PACKAGE_SCANNING_DIR = exports.TXT_PIPELINE_RUN_FINISH_FAILED = exports.TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY = exports.TXT_STORIES_AMOUNT = exports.TXT_PIPELINE_RUN_STILL_WAITING = exports.TXT_PIPELINE_RUN_WAIT = exports.TXT_PIPELINE_RUN_SUCCESS = exports.TXT_OPENING_TUNNEL = exports.TXT_UPDATING_AGENT = exports.TXT_ENABLING_AGENT = exports.TXT_NEW_AGENT_VERSION = exports.TXT_NEW_CLI_VERSION = exports.TXT_NEW_CLI_DOCKER_VERSION = exports.OPTION_UPLOAD_DRY_RUN = exports.OPTION_UPLOAD_REPORT_FORMAT = exports.OPTION_UPLOAD_REPORT_GLOB = exports.DESC_COMMAND_UT_UPLOAD = exports.DESC_COMMAND_UT = exports.DESC_COMMAND_VT_INSTALL_BROWSER = exports.DESC_COMMAND_VT_EXEC = exports.DESC_COMMAND_VT_SCRAPE = exports.DESC_COMMAND_VT_COMPARE = exports.DESC_COMMAND_VT_STORYBOOK = exports.DESC_COMMAND_VT_CLOSE = void 0;
|
|
8
|
+
exports.OPTION_EXEC_ONE_BY_ONE = exports.OPTION_EXEC_SKIP_DISCOVERY = exports.OPTION_EXEC_COMMAND = exports.OPTION_AGENT_DEBUG = exports.OPTION_AGENT_PORT = exports.OPTION_AGENT_TARGET = exports.OPTION_PASS = exports.OPTION_USER = exports.OPTION_AGENT_TOKEN = exports.OPTION_AGENT_START = exports.OPTION_AGENT_ID = exports.OPTION_ID = exports.OPTION_NAME = exports.OPTION_TARGET = exports.OPTION_TLS_TERMINATE = exports.OPTION_TLS_CA = exports.OPTION_TLS_CERT = exports.OPTION_TLS_KEY = exports.OPTION_HTTP_CIRCUIT_BREAKER = exports.OPTION_HTTP_COMPRESSION = exports.OPTION_HTTP_2 = exports.OPTION_HTTP_VERIFY = exports.OPTION_HTTP_LOG = exports.OPTION_HTTP_AUTH_BUDDY = exports.OPTION_HTTP_AUTH = exports.OPTION_HTTP_HOST = exports.OPTION_FORCE = exports.OPTION_TOKEN = exports.OPTION_TIMEOUT = exports.OPTION_FOLLOW = exports.OPTION_SERVE = exports.OPTION_HEADER_USER_AGENT = exports.OPTION_RESPONSE_HEADER = exports.OPTION_HEADER = exports.OPTION_WHITELIST = exports.OPTION_REST_API_PROJECT = exports.OPTION_REST_API_WORKSPACE = exports.OPTION_PIPELINE_RUN_WAIT = exports.OPTION_PIPELINE_RUN_ACTION = exports.OPTION_REST_API_TOKEN = exports.OPTION_PACKAGE_DOWNLOAD_REPLACE = exports.OPTION_PACKAGE_DOWNLOAD_MERGE = exports.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION = exports.OPTION_PACKAGE_PUBLISH_CREATE = exports.OPTION_PACKAGE_ID = exports.OPTION_PACKAGE_DOWNLOAD_PATH = exports.OPTION_PACKAGE_PUBLISH_PATH = exports.OPTION_PIPELINE_RUN_ARGUMENT = exports.OPTION_PIPELINE_RUN_DELAY = exports.OPTION_PIPELINE_RUN_VAR = void 0;
|
|
9
|
+
exports.LOG_AGENT_REGISTERED = exports.LOG_SOCKET_DISCONNECTED = exports.LOG_SOCKET_CONNECTED = exports.LOG_AGENT_NSSM_CLEARING = exports.LOG_AGENT_NSSM_EXTRACTING = exports.LOG_AGENT_NSSM_DOWNLOADING = exports.LOG_AGENT_ENABLED = exports.LOG_AGENT_STARTING_SYSTEM = exports.LOG_AGENT_STOPPING_SYSTEM = exports.LOG_AGENT_ENABLING_SYSTEM = exports.LOG_AGENT_SYSTEM_SERVICE_CONFIG = exports.LOG_AGENT_EXTRACTING_ARCHIVE = exports.LOG_AGENT_DOWNLOADING_ARCHIVE = exports.LOG_AGENT_SYSTEM_DIR = exports.LOG_ERROR_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_ERROR_REMOVING_AGENT_STANDALONE_LOCK_FILE = exports.LOG_ERROR_SAVING_AGENT_STANDALONE_CONFIG = exports.LOG_ERROR_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_REMOVING_AGENT_PROC_ID = exports.LOG_SAVING_AGENT_PROC_ID = exports.LOG_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_REGISTERING_AGENT = exports.OPTION_SCRAPE_OUTPUT_DIR = exports.OPTION_SCRAPE_DELAY = exports.OPTION_SCRAPE_DARK_MODE = exports.OPTION_SCRAPE_WAIT_FOR_ELEMENT = exports.OPTION_SCRAPE_DEVICE_PIXEL_RATIO = exports.OPTION_SCRAPE_VIEWPORT = exports.OPTION_SCRAPE_BROWSER = exports.OPTION_SCRAPE_XPATH_SELECTOR = exports.OPTION_SCRAPE_CSS_SELECTOR = exports.OPTION_SCRAPE_FULL_PAGE = exports.OPTION_SCRAPE_QUALITY = exports.OPTION_SCRAPE_OUTPUT_TYPE = exports.OPTION_SCRAPE_FOLLOW = exports.OPTION_SCRAPE_URL = exports.OPTION_COMPARE_WAIT_FOR = exports.OPTION_COMPARE_DELAY = exports.OPTION_COMPARE_HEADER = exports.OPTION_COMPARE_COOKIE = exports.OPTION_COMPARE_IGNORE = exports.OPTION_COMPARE_IGNORE_URLS = exports.OPTION_COMPARE_DRY_RUN = exports.OPTION_COMPARE_URLS_FILE = exports.OPTION_COMPARE_SITEMAP = exports.OPTION_COMPARE_URLS = exports.OPTION_COMPARE_RESPECT_ROBOTS = exports.OPTION_COMPARE_FOLLOW = exports.OPTION_EXEC_PARALLEL = void 0;
|
|
10
|
+
exports.DEBUG_AUTO_WIDTH = exports.DEBUG_AUTO_SCROLL = exports.DEBUG_RESOURCE_SCRAPPING_URL = exports.DEBUG_SNAPSHOT_PROCESSING = exports.DEBUG_SNAPSHOTS_PROCESSING = exports.DEBUG_EXEC_COMMAND = exports.DEBUG_EXEC_TEST_COMMAND = exports.LOG_INSTALLED_BROWSER = exports.LOG_SESSION_LINK = exports.LOG_SENDING_DATA = exports.LOG_SENDING_REQUEST = exports.LOG_PROCESSING_SNAPSHOTS = exports.LOG_RUNNING_EXEC_COMMAND = exports.LOG_TUNNEL_SSH_STREAM = exports.LOG_TUNNEL_TLS_AGENT_STREAM = exports.LOG_TUNNEL_TLS_REGION_STREAM = exports.LOG_TUNNEL_TLS_TARGET_STREAM = exports.LOG_TUNNEL_HTTP2_STREAM = exports.LOG_TUNNEL_HTTP1_STREAM = exports.LOG_TUNNEL_TCP_STREAM = exports.LOG_TUNNEL_HTTP_WRONG_USER_AGENTS = exports.LOG_TUNNEL_HTTP_CIRCUIT_BREAKER_OPEN = exports.LOG_TUNNEL_HTTP_RATE_LIMIT = exports.LOG_TUNNEL_HTTP_WRON_AUTH = exports.LOG_TUNNEL_IDENTIFIED = exports.LOG_TUNNEL_DISCONNECTED = exports.LOG_TUNNEL_FAILED = exports.LOG_TUNNEL_CONNECTED = exports.LOG_AGENT_STARTED = exports.LOG_AGENT_SERVER_STARTED = exports.LOG_ERROR_STARTING_AGENT_SERVER = exports.LOG_SSH_CONNECTION = exports.LOG_WRONG_STREAM = exports.LOG_DETECTED_STREAM = exports.LOG_HTTP2_REQUEST = exports.LOG_HTTP2_CONNECTION = exports.LOG_HTTP1_REQUEST = exports.LOG_HTTP1_CONNECTION = exports.LOG_ERROR = exports.LOG_STOPPING_TUNNEL = exports.LOG_STARTING_TUNNEL = exports.LOG_ENABLING_AGENT_TARGET = exports.LOG_DISABLING_AGENT_TARGET = exports.LOG_REMOVING_TUNNEL = exports.LOG_TUNNEL_REGISTERED = exports.LOG_ERROR_WHILE_REFRESHING_AGENT = exports.LOG_REGISTERING_TUNNEL = exports.LOG_GETTING_AGENT = exports.LOG_UNREGISTERING_AGENT = exports.LOG_REGION_DETECTED = void 0;
|
|
11
|
+
exports.DEBUG_WAIT_FOR_IDLE_TIMEOUT = exports.DEBUG_WAIT_FOR_IDLE = exports.DEBUG_RESOURCE_DISCOVERY_TIMEOUT = void 0;
|
|
11
12
|
const utils_1 = require("./utils");
|
|
12
13
|
exports.ERR_REST_API_GENERAL_ERROR = 'Something went wrong';
|
|
13
14
|
exports.ERR_REST_API_WRONG_TOKEN = 'Valid token with proper scopes is required';
|
|
@@ -15,11 +16,16 @@ exports.ERR_REST_API_RESOURCE_NOT_FOUND = 'Resource not found';
|
|
|
15
16
|
exports.ERR_REST_API_RATE_LIMIT = 'Rate limit exceeded';
|
|
16
17
|
exports.ERR_REST_API_TOKEN = 'Personal access token is required (--token)';
|
|
17
18
|
exports.ERR_REST_API_URL = 'Valid rest api endpoint is required (--api)';
|
|
19
|
+
exports.ERR_PATH_NOT_EXISTS = 'path not exists';
|
|
18
20
|
exports.ERR_REST_API_WORKSPACE = 'Workspace domain is required (--workspace)';
|
|
19
21
|
exports.ERR_REST_API_PROJECT = 'Project name is required (--project)';
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
22
|
+
exports.ERR_WORKSPACE_NOT_FOUND = 'Workspace not found';
|
|
23
|
+
exports.ERR_PROJECT_NOT_FOUND = 'Project not found';
|
|
24
|
+
exports.ERR_PIPELINE_NOT_FOUND = 'Pipeline not found';
|
|
25
|
+
exports.ERR_PACKAGE_DOWNLOAD_NOT_FOUND = 'Package not found';
|
|
26
|
+
exports.ERR_PACKAGE_PUBLISH_NOT_FOUND = 'Package not found. Change package name or use --create to create one';
|
|
27
|
+
exports.ERR_PACKAGE_VERSION_EXISTS = 'Package version exists. Change version name or use --force flag';
|
|
28
|
+
exports.ERR_PACKAGE_VERSION_NOT_FOUND = 'Package version not found';
|
|
23
29
|
exports.ERR_RUN_PIPELINE_WAIT_TIMEOUT = 'Timeout waiting for run to finish';
|
|
24
30
|
exports.ERR_RUN_PIPELINE_WRONG_PRIORITY = 'Priority has wrong value. Possible: LOW, NORMAL, HIGH';
|
|
25
31
|
exports.ERR_RUN_PIPELINE_WRONG_DELAY = 'Delay must be a valid date format: 2016-11-18T12:38:16.000Z or 30s, 10m, 3h10m30s';
|
|
@@ -90,6 +96,16 @@ exports.ERR_TUNNEL_REMOVED = 'Tunnel removed';
|
|
|
90
96
|
exports.ERR_FAILED_TO_CONNECT_TO_AGENT = 'Failed connecting to agent';
|
|
91
97
|
exports.ERR_NOT_FOUND = 'Not found';
|
|
92
98
|
exports.ERR_SWW = 'Something went wrong';
|
|
99
|
+
const ERR_PACKAGE_DOWNLOAD_MKDIR = (dirPath) => `Error while creating directory ${dirPath}`;
|
|
100
|
+
exports.ERR_PACKAGE_DOWNLOAD_MKDIR = ERR_PACKAGE_DOWNLOAD_MKDIR;
|
|
101
|
+
const ERR_PACKAGE_DOWNLOAD_READDIR = (dirPath) => `Error while reading directory ${dirPath}`;
|
|
102
|
+
exports.ERR_PACKAGE_DOWNLOAD_READDIR = ERR_PACKAGE_DOWNLOAD_READDIR;
|
|
103
|
+
const ERR_PACKAGE_DOWNLOAD_IS_FILE = (dirPath) => `Path ${dirPath} is not a directory. Change path or use --replace flag`;
|
|
104
|
+
exports.ERR_PACKAGE_DOWNLOAD_IS_FILE = ERR_PACKAGE_DOWNLOAD_IS_FILE;
|
|
105
|
+
const ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR = (dirPath) => `Directory ${dirPath} is not empty. Use --merge or --replace flags`;
|
|
106
|
+
exports.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR = ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR;
|
|
107
|
+
const ERR_PACKAGE_DOWNLOAD_REPLACE = (dirPath) => `Error while replacing directory ${dirPath}`;
|
|
108
|
+
exports.ERR_PACKAGE_DOWNLOAD_REPLACE = ERR_PACKAGE_DOWNLOAD_REPLACE;
|
|
93
109
|
exports.ERR_FETCH_VERSION = 'Failed to fetch version';
|
|
94
110
|
exports.ERR_WRONG_HANDSHAKE = 'Wrong handshake data';
|
|
95
111
|
exports.ERR_WRONG_STREAM = 'Wrong stream type';
|
|
@@ -222,7 +238,10 @@ exports.DESC_COMMAND_TCP = 'Starts a tunnel which forwards all TCP traffic on a
|
|
|
222
238
|
exports.DESC_COMMAND_TLS = 'Starts a tunnel listening for TLS traffic on port 443 with a specific hostname.';
|
|
223
239
|
exports.DESC_PROGRAM = 'Buddy exposes local networked services behinds NATs and firewalls to the public internet over a secure tunnel. Share local websites, build/test webhook consumers, and self-host personal services.';
|
|
224
240
|
exports.DESC_COMMAND_PIPELINE = 'Commands to interact with the pipeline service';
|
|
225
|
-
exports.
|
|
241
|
+
exports.DESC_COMMAND_PACKAGE = 'Commands to interact with the package service';
|
|
242
|
+
exports.DESC_COMMAND_PACKAGE_PUBLISH = 'Publish package. Required scopes: PACKAGE_READ, PACKAGE_WRITE, PACKAGE_MANAGE';
|
|
243
|
+
exports.DESC_COMMAND_PACKAGE_DOWNLOAD = 'Download package. Required scopes: PACKAGE_READ';
|
|
244
|
+
exports.DESC_COMMAND_PIPELINE_RUN = 'Run pipeline. Required scopes: EXECUTION_INFO, EXECUTION_RUN';
|
|
226
245
|
exports.DESC_COMMAND_VT = 'Commands to interact with the visual test service';
|
|
227
246
|
exports.DESC_COMMAND_VT_CLOSE = 'Close visual test session.';
|
|
228
247
|
exports.DESC_COMMAND_VT_STORYBOOK = 'Create visual test session from storybook';
|
|
@@ -255,6 +274,26 @@ const TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY = (runUrl) => `Run finished successfu
|
|
|
255
274
|
exports.TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY = TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY;
|
|
256
275
|
const TXT_PIPELINE_RUN_FINISH_FAILED = (status, runUrl) => `Run finished with status ${status}: ${runUrl}`;
|
|
257
276
|
exports.TXT_PIPELINE_RUN_FINISH_FAILED = TXT_PIPELINE_RUN_FINISH_FAILED;
|
|
277
|
+
exports.TXT_PACKAGE_SCANNING_DIR = 'Scanning...';
|
|
278
|
+
exports.TXT_PACKAGE_NO_ENTRIES_FOUND = 'no entries found';
|
|
279
|
+
exports.TXT_PACKAGE_ONE_ENTRY_FOUND = '1 entry found';
|
|
280
|
+
const TXT_PACKAGE_ZIP_ENTRIES = (count) => `Archiving...${count}`;
|
|
281
|
+
exports.TXT_PACKAGE_ZIP_ENTRIES = TXT_PACKAGE_ZIP_ENTRIES;
|
|
282
|
+
exports.TXT_PACKAGE_ZIPPED = `Archiving...Done`;
|
|
283
|
+
exports.TXT_PACKAGE_UPLOADING = 'Uploading...';
|
|
284
|
+
exports.TXT_PACKAGE_UPLOADED = 'Uploading...Done';
|
|
285
|
+
const TXT_PACKAGE_ENTRIES_FOUND = (count) => `${count} entries found`;
|
|
286
|
+
exports.TXT_PACKAGE_ENTRIES_FOUND = TXT_PACKAGE_ENTRIES_FOUND;
|
|
287
|
+
const TXT_PACKAGE_PUBLISHED = (versionUrl) => `Package published: ${versionUrl}`;
|
|
288
|
+
exports.TXT_PACKAGE_PUBLISHED = TXT_PACKAGE_PUBLISHED;
|
|
289
|
+
const TXT_PACKAGE_DOWNLOADED = (version, dirPath) => `Package version '${version}' downloaded to ${dirPath}`;
|
|
290
|
+
exports.TXT_PACKAGE_DOWNLOADED = TXT_PACKAGE_DOWNLOADED;
|
|
291
|
+
exports.TXT_PACKAGE_DOWNLOADING_ZIP = 'Downloading...';
|
|
292
|
+
exports.TXT_PACKAGE_DOWNLOADED_ZIP = 'Downloading...Done';
|
|
293
|
+
exports.TXT_PACKAGE_UNZIPPING = 'Unzipping...';
|
|
294
|
+
exports.TXT_PACKAGE_UNZIPPED = 'Unzipping...Done';
|
|
295
|
+
const TXT_PACKAGE_UNZIPPING_COUNT = (count) => `Unzipping...${count}`;
|
|
296
|
+
exports.TXT_PACKAGE_UNZIPPING_COUNT = TXT_PACKAGE_UNZIPPING_COUNT;
|
|
258
297
|
exports.OPTION_REGION = 'override default region ("eu", "us")';
|
|
259
298
|
exports.OPTION_DEFAULT_REGION = 'default region ("eu", "us")';
|
|
260
299
|
exports.OPTION_REST_API_ENDPOINT = 'override default base url (api.buddy.works) and region. You can use env variable: BUDDY_API_ENDPOINT.';
|
|
@@ -269,7 +308,14 @@ exports.OPTION_PIPELINE_RUN_CLEAR_CACHE = 'clear cache before running the pipeli
|
|
|
269
308
|
exports.OPTION_PIPELINE_RUN_PRIORITY = 'run priority. Can be one of "LOW", "NORMAL" or "HIGH". Default is "NORMAL"';
|
|
270
309
|
exports.OPTION_PIPELINE_RUN_VAR = 'variable key:value. Can be passed multiple times to pass multiple variables';
|
|
271
310
|
exports.OPTION_PIPELINE_RUN_DELAY = 'the date when the execution should be run. Should be set in the format: 2016-11-18T12:38:16.000Z or 30s, 10m, 3h10m30s';
|
|
272
|
-
exports.OPTION_PIPELINE_RUN_ARGUMENT = 'human-readable ID of pipeline';
|
|
311
|
+
exports.OPTION_PIPELINE_RUN_ARGUMENT = 'human-readable ID of the pipeline';
|
|
312
|
+
exports.OPTION_PACKAGE_PUBLISH_PATH = 'path to the directory or file';
|
|
313
|
+
exports.OPTION_PACKAGE_DOWNLOAD_PATH = 'path to the directory or file';
|
|
314
|
+
exports.OPTION_PACKAGE_ID = 'human-readable ID of the package and optionally version: package@version';
|
|
315
|
+
exports.OPTION_PACKAGE_PUBLISH_CREATE = 'create package if not exists';
|
|
316
|
+
exports.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION = 'allow overwriting existing version';
|
|
317
|
+
exports.OPTION_PACKAGE_DOWNLOAD_MERGE = 'merge contents of the directory with package';
|
|
318
|
+
exports.OPTION_PACKAGE_DOWNLOAD_REPLACE = 'replace contents of the directory with package';
|
|
273
319
|
exports.OPTION_REST_API_TOKEN = 'personal access token. You can use env variable: BUDDY_TOKEN';
|
|
274
320
|
exports.OPTION_PIPELINE_RUN_ACTION = "action ID to be run in this execution. If not sent, it will be run in accordance with the pipeline's definition. Can be passed multiple times to select multiple actions";
|
|
275
321
|
exports.OPTION_PIPELINE_RUN_WAIT = 'wait for run to finish';
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
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 texts_1 = require("../../../texts");
|
|
8
|
-
const manager_1 = __importDefault(require("../../../agent/manager"));
|
|
9
|
-
const output_1 = __importDefault(require("../../../output"));
|
|
10
|
-
const commandAgentStandaloneKill = (0, utils_1.newCommand)('kill', texts_1.DESC_COMMAND_AGENT_STANDALONE_KILL);
|
|
11
|
-
commandAgentStandaloneKill.action(async () => {
|
|
12
|
-
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
13
|
-
if (!hasAdminRights) {
|
|
14
|
-
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
15
|
-
}
|
|
16
|
-
if (!manager_1.default.system.isStandaloneProcRunning()) {
|
|
17
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
18
|
-
}
|
|
19
|
-
manager_1.default.system.killStandaloneProc();
|
|
20
|
-
output_1.default.exitSuccess(texts_1.TXT_AGENT_STANDALONE_STOPPED);
|
|
21
|
-
});
|
|
22
|
-
exports.default = commandAgentStandaloneKill;
|
|
@@ -1,136 +0,0 @@
|
|
|
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 texts_1 = require("../../texts");
|
|
8
|
-
const manager_1 = __importDefault(require("../../agent/manager"));
|
|
9
|
-
const output_1 = __importDefault(require("../../output"));
|
|
10
|
-
const buddy_1 = __importDefault(require("../../tunnel/api/buddy"));
|
|
11
|
-
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
-
const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
13
|
-
const input_1 = __importDefault(require("../../input"));
|
|
14
|
-
const kill_1 = __importDefault(require("./standalone/kill"));
|
|
15
|
-
const commandAgentStandalone = (0, utils_1.newCommand)('standalone', texts_1.DESC_COMMAND_AGENT_STANDALONE);
|
|
16
|
-
commandAgentStandalone.option('-i, --id <id>', texts_1.OPTION_AGENT_ID);
|
|
17
|
-
commandAgentStandalone.option('-t, --token <token>', texts_1.OPTION_AGENT_TOKEN);
|
|
18
|
-
commandAgentStandalone.option('-p, --port <port>', texts_1.OPTION_AGENT_PORT, '7456');
|
|
19
|
-
commandAgentStandalone.option('--target', texts_1.OPTION_AGENT_TARGET);
|
|
20
|
-
commandAgentStandalone.addCommand(kill_1.default);
|
|
21
|
-
commandAgentStandalone.action(async (options) => {
|
|
22
|
-
const hasAdminRights = await manager_1.default.system.hasAdminRights();
|
|
23
|
-
if (!hasAdminRights) {
|
|
24
|
-
output_1.default.exitError(texts_1.ERR_AGENT_ADMIN_RIGHTS);
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_PROC_CHECKING);
|
|
28
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_PROC_CHECKING, false);
|
|
29
|
-
manager_1.default.system.killStandaloneProc();
|
|
30
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_PROC_CHECKED);
|
|
31
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_PROC_CHECKED);
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_PROC_ERROR);
|
|
35
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_PROC_ERROR);
|
|
36
|
-
logger_1.default.error(err);
|
|
37
|
-
output_1.default.exitError(err);
|
|
38
|
-
}
|
|
39
|
-
const isEnabled = await manager_1.default.system.isEnabled();
|
|
40
|
-
if (isEnabled) {
|
|
41
|
-
output_1.default.exitError(texts_1.ERR_AGENT_STANDALONE_SERVICE_INSTALLED);
|
|
42
|
-
}
|
|
43
|
-
let id;
|
|
44
|
-
let host;
|
|
45
|
-
let token;
|
|
46
|
-
let port;
|
|
47
|
-
try {
|
|
48
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_CONFIG_CHECKING);
|
|
49
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_CONFIG_CHECKING, false);
|
|
50
|
-
const json = manager_1.default.system.loadSystemConfig();
|
|
51
|
-
id = json.id;
|
|
52
|
-
host = json.host;
|
|
53
|
-
token = json.token;
|
|
54
|
-
port = json.port;
|
|
55
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_CONFIG_FOUND);
|
|
56
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_CONFIG_FOUND);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_CONFIG_NOT_FOUND);
|
|
60
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_CONFIG_NOT_FOUND);
|
|
61
|
-
}
|
|
62
|
-
if (!port) {
|
|
63
|
-
port = input_1.default.port(options.port);
|
|
64
|
-
}
|
|
65
|
-
if (!id && options.id) {
|
|
66
|
-
id = options.id;
|
|
67
|
-
logger_1.default.info((0, texts_1.TXT_AGENT_STANDALONE_USING_AGENT)(id));
|
|
68
|
-
output_1.default.normal((0, texts_1.TXT_AGENT_STANDALONE_USING_AGENT)(id));
|
|
69
|
-
}
|
|
70
|
-
if (!token) {
|
|
71
|
-
token = options.token;
|
|
72
|
-
}
|
|
73
|
-
if (!id) {
|
|
74
|
-
if (token)
|
|
75
|
-
cfg_1.default.setToken(token);
|
|
76
|
-
host = cfg_1.default.getTokenHost();
|
|
77
|
-
try {
|
|
78
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTERING, false);
|
|
79
|
-
const agent = await buddy_1.default.register(true, !!options.target, host, cfg_1.default.getToken(), (region) => {
|
|
80
|
-
cfg_1.default.setRegionIfNotSet(region);
|
|
81
|
-
});
|
|
82
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTERED);
|
|
83
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTERED);
|
|
84
|
-
id = agent.id;
|
|
85
|
-
token = agent.token;
|
|
86
|
-
agent.destroy();
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTER_ERROR);
|
|
90
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_REGISTER_ERROR);
|
|
91
|
-
logger_1.default.error(err);
|
|
92
|
-
output_1.default.exitError(err);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
if (!host) {
|
|
97
|
-
host = cfg_1.default.getTokenHost();
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHING);
|
|
101
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHING, false);
|
|
102
|
-
const agent = await buddy_1.default.fetchAgent(id, host, token);
|
|
103
|
-
agent.destroy();
|
|
104
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHED);
|
|
105
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCHED);
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCH_ERROR);
|
|
109
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_AGENT_FETCH_ERROR);
|
|
110
|
-
logger_1.default.error(err);
|
|
111
|
-
output_1.default.exitError(err);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
let saved = manager_1.default.system.saveSystemConfig(id, host, token, port);
|
|
115
|
-
if (!saved) {
|
|
116
|
-
output_1.default.exitError(texts_1.ERR_SWW_AGENT_ENABLING);
|
|
117
|
-
}
|
|
118
|
-
saved = manager_1.default.system.saveStandaloneProcConfig();
|
|
119
|
-
if (!saved) {
|
|
120
|
-
output_1.default.exitError(texts_1.ERR_SWW_AGENT_ENABLING);
|
|
121
|
-
}
|
|
122
|
-
logger_1.default.changeRootPath(manager_1.default.system.getNewAgentConfigDir());
|
|
123
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_STARTED);
|
|
124
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_STARTED);
|
|
125
|
-
process.on('SIGINT', onExit);
|
|
126
|
-
process.on('SIGTERM', onExit);
|
|
127
|
-
process.on('SIGQUIT', onExit);
|
|
128
|
-
manager_1.default.start(id, host, token, port, true, true);
|
|
129
|
-
});
|
|
130
|
-
const onExit = () => {
|
|
131
|
-
logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_EXITING);
|
|
132
|
-
output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_EXITING);
|
|
133
|
-
manager_1.default.system.clearStandaloneProcConfig();
|
|
134
|
-
process.exit(0);
|
|
135
|
-
};
|
|
136
|
-
exports.default = commandAgentStandalone;
|
|
@@ -1,193 +0,0 @@
|
|
|
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;
|