bdy 1.14.8-dev → 1.14.9-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 +102 -25
- package/distTs/src/command/package/download.js +249 -0
- package/distTs/src/command/package/publish.js +229 -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 +19 -1
- package/distTs/src/output.js +5 -2
- package/distTs/src/texts.js +58 -12
- package/package.json +1 -1
- 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,59 @@ 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
|
+
package_version: version
|
|
138
|
+
};
|
|
139
|
+
if (project)
|
|
140
|
+
opts.project = project;
|
|
141
|
+
if (version)
|
|
142
|
+
opts.package_version = version;
|
|
143
|
+
return await this.getResourceByIdentifier(workspace, opts);
|
|
108
144
|
}
|
|
109
145
|
async getPipelineRun(workspace, project, pipelineId, executionId) {
|
|
110
146
|
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/pipelines/${encodeURIComponent(pipelineId)}/executions/${encodeURIComponent(executionId)}`, null, true);
|
|
@@ -112,5 +148,46 @@ class ApiClient {
|
|
|
112
148
|
async postPipelineRun(workspace, project, pipelineId, body) {
|
|
113
149
|
return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/pipelines/${encodeURIComponent(pipelineId)}/executions`, body, true);
|
|
114
150
|
}
|
|
151
|
+
async getPackageVersion(workspace, pkgId, versionId) {
|
|
152
|
+
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions/${encodeURIComponent(versionId)}`, null, true);
|
|
153
|
+
}
|
|
154
|
+
async getPackageLatest(workspace, pkgId) {
|
|
155
|
+
const res = await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions?page=1&per_page=1`, null, true);
|
|
156
|
+
if (res && res.versions && res.versions.length > 0) {
|
|
157
|
+
return res.versions[0];
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
async downloadPackageVersion(workspace, pkgId, versionId) {
|
|
162
|
+
return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions/${encodeURIComponent(versionId)}/download`, null, false, true);
|
|
163
|
+
}
|
|
164
|
+
async postPackageVersion(workspace, pkgId, version) {
|
|
165
|
+
return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions`, {
|
|
166
|
+
version
|
|
167
|
+
}, true);
|
|
168
|
+
}
|
|
169
|
+
async postPackageVersionZip(workspace, pkgId, versionId, file) {
|
|
170
|
+
const form = new undici_1.FormData();
|
|
171
|
+
form.append('file', file);
|
|
172
|
+
return await this.requestMultipart(`/workspaces/${encodeURIComponent(workspace)}/packages/${encodeURIComponent(pkgId)}/versions/${versionId}/upload`, form, true);
|
|
173
|
+
}
|
|
174
|
+
async postPackage(workspace, project, identifier) {
|
|
175
|
+
const body = {
|
|
176
|
+
name: identifier,
|
|
177
|
+
identifier,
|
|
178
|
+
type: 'FILE',
|
|
179
|
+
scope: 'WORKSPACE',
|
|
180
|
+
authorization: {
|
|
181
|
+
type: 'BUDDY'
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
if (project) {
|
|
185
|
+
body.project = {
|
|
186
|
+
name: project
|
|
187
|
+
};
|
|
188
|
+
body.scope = 'PROJECT';
|
|
189
|
+
}
|
|
190
|
+
return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/packages`, body, true);
|
|
191
|
+
}
|
|
115
192
|
}
|
|
116
193
|
exports.default = ApiClient;
|
|
@@ -0,0 +1,249 @@
|
|
|
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('--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('-v, --version <version>', texts_1.OPTION_PACKAGE_DOWNLOAD_VERSION);
|
|
25
|
+
commandPackageDownload.option('-m, --merge', texts_1.OPTION_PACKAGE_DOWNLOAD_MERGE);
|
|
26
|
+
commandPackageDownload.option('-r, --replace', texts_1.OPTION_PACKAGE_DOWNLOAD_REPLACE);
|
|
27
|
+
commandPackageDownload.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
28
|
+
commandPackageDownload.argument('<directory>', texts_1.OPTION_PACKAGE_DOWNLOAD_PATH);
|
|
29
|
+
commandPackageDownload.action(async (identifier, path, options) => {
|
|
30
|
+
const token = input_1.default.restApiToken(options.token);
|
|
31
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
32
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
33
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
34
|
+
const client = new client_1.default(baseUrl, token);
|
|
35
|
+
let version = options.version;
|
|
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
|
+
let empty = true;
|
|
88
|
+
try {
|
|
89
|
+
const entries = fs_1.default.readdirSync(dirPath);
|
|
90
|
+
empty = !entries.length;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
logger_1.default.error(err);
|
|
94
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_READDIR)(dirPath));
|
|
95
|
+
}
|
|
96
|
+
if (!empty && !options.merge) {
|
|
97
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
|
|
98
|
+
}
|
|
99
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
100
|
+
const clearZip = () => {
|
|
101
|
+
try {
|
|
102
|
+
fs_1.default.rmSync(zipPath);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// do nothing
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADING_ZIP);
|
|
109
|
+
const body = await client.downloadPackageVersion(workspace, packageId, versionId);
|
|
110
|
+
try {
|
|
111
|
+
await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
|
|
112
|
+
output_1.default.clearPreviousLine();
|
|
113
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADED_ZIP);
|
|
114
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPING);
|
|
115
|
+
let count = 0;
|
|
116
|
+
await unzip(dirPath, zipPath, () => {
|
|
117
|
+
count += 1;
|
|
118
|
+
output_1.default.clearPreviousLine();
|
|
119
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_UNZIPPING_COUNT)(count));
|
|
120
|
+
});
|
|
121
|
+
clearZip();
|
|
122
|
+
output_1.default.clearPreviousLine();
|
|
123
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPED);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
logger_1.default.error(err);
|
|
127
|
+
clearZip();
|
|
128
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
129
|
+
}
|
|
130
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_DOWNLOADED)(version, dirPath));
|
|
131
|
+
});
|
|
132
|
+
const unzip = (dirPath, zipPath, onFile) => {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
let _startedFiles = 0;
|
|
135
|
+
let _finishedFiles = 0;
|
|
136
|
+
let _finishedStream = false;
|
|
137
|
+
let _finishedError = null;
|
|
138
|
+
let _calledResolve = false;
|
|
139
|
+
const rs = fs_1.default.createReadStream(zipPath);
|
|
140
|
+
const _finish = () => {
|
|
141
|
+
if (_finishedError || _finishedStream) {
|
|
142
|
+
try {
|
|
143
|
+
rs.removeAllListeners();
|
|
144
|
+
rs.close();
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// do nothing
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (_calledResolve)
|
|
151
|
+
return;
|
|
152
|
+
if (_finishedError) {
|
|
153
|
+
_calledResolve = true;
|
|
154
|
+
reject(_finishedError);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (_finishedStream && _startedFiles === _finishedFiles) {
|
|
158
|
+
_calledResolve = true;
|
|
159
|
+
resolve();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const finishFile = (err, fws) => {
|
|
163
|
+
if (!_finishedError && err)
|
|
164
|
+
_finishedError = err;
|
|
165
|
+
_finishedFiles += 1;
|
|
166
|
+
if (fws) {
|
|
167
|
+
try {
|
|
168
|
+
fws.removeAllListeners();
|
|
169
|
+
fws.close();
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// do nothing
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
onFile();
|
|
176
|
+
_finish();
|
|
177
|
+
};
|
|
178
|
+
const finishStream = (err) => {
|
|
179
|
+
if (!_finishedError && err)
|
|
180
|
+
_finishedError = err;
|
|
181
|
+
_finishedStream = true;
|
|
182
|
+
_finish();
|
|
183
|
+
};
|
|
184
|
+
const unzip = new fflate_1.Unzip(async (file) => {
|
|
185
|
+
if (_finishedError)
|
|
186
|
+
return;
|
|
187
|
+
_startedFiles += 1;
|
|
188
|
+
const fullPath = (0, path_1.join)(dirPath, file.name);
|
|
189
|
+
const parentPath = (0, path_1.dirname)(fullPath);
|
|
190
|
+
let fws;
|
|
191
|
+
try {
|
|
192
|
+
await fs_1.default.promises.rm(fullPath, {
|
|
193
|
+
recursive: true,
|
|
194
|
+
force: true,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// do nothing
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
if (fullPath.endsWith('/')) {
|
|
202
|
+
await fs_1.default.promises.mkdir(fullPath, {
|
|
203
|
+
recursive: true,
|
|
204
|
+
});
|
|
205
|
+
finishFile();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
await fs_1.default.promises.mkdir(parentPath, {
|
|
209
|
+
recursive: true,
|
|
210
|
+
});
|
|
211
|
+
fws = fs_1.default.createWriteStream(fullPath, {
|
|
212
|
+
flags: 'w',
|
|
213
|
+
});
|
|
214
|
+
fws.on('error', (err) => {
|
|
215
|
+
finishFile(err, fws);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
finishFile(err, fws);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
file.ondata = (err, data, final) => {
|
|
223
|
+
if (_finishedError)
|
|
224
|
+
return;
|
|
225
|
+
if (err)
|
|
226
|
+
finishFile(err, fws);
|
|
227
|
+
else {
|
|
228
|
+
if (fws)
|
|
229
|
+
fws.write(data);
|
|
230
|
+
if (final)
|
|
231
|
+
finishFile(null, fws);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
file.start();
|
|
235
|
+
});
|
|
236
|
+
unzip.register(fflate_1.AsyncUnzipInflate);
|
|
237
|
+
rs.on('data', (chunk) => {
|
|
238
|
+
unzip.push(chunk, false);
|
|
239
|
+
});
|
|
240
|
+
rs.on('error', (err) => {
|
|
241
|
+
finishStream(err);
|
|
242
|
+
});
|
|
243
|
+
rs.on('end', () => {
|
|
244
|
+
unzip.push(new Uint8Array(0), true);
|
|
245
|
+
finishStream();
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
exports.default = commandPackageDownload;
|
|
@@ -0,0 +1,229 @@
|
|
|
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('--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('-v, --version <version>', texts_1.OPTION_PACKAGE_PUBLISH_VERSION);
|
|
25
|
+
commandPackagePublish.option('-f, --force', texts_1.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION);
|
|
26
|
+
commandPackagePublish.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
27
|
+
commandPackagePublish.argument('<directory>', texts_1.OPTION_PACKAGE_PUBLISH_PATH);
|
|
28
|
+
commandPackagePublish.action(async (identifier, path, options) => {
|
|
29
|
+
let dirPath = input_1.default.resolvePath(path);
|
|
30
|
+
const token = input_1.default.restApiToken(options.token);
|
|
31
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
32
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
33
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
34
|
+
const version = input_1.default.restApiPackageVersion(options.version);
|
|
35
|
+
const client = new client_1.default(baseUrl, token);
|
|
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
|
+
let packageId = data.pkg_id;
|
|
44
|
+
if (!packageId) {
|
|
45
|
+
if (options.create) {
|
|
46
|
+
const d = await client.postPackage(workspace, project, identifier);
|
|
47
|
+
packageId = d.id;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_PUBLISH_NOT_FOUND);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let packageVersionId = data.pkg_version_id;
|
|
54
|
+
let url;
|
|
55
|
+
if (packageVersionId && !options.force) {
|
|
56
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_EXISTS);
|
|
57
|
+
}
|
|
58
|
+
if (!packageVersionId) {
|
|
59
|
+
const d = await client.postPackageVersion(workspace, packageId, version);
|
|
60
|
+
url = d.version_url;
|
|
61
|
+
packageVersionId = d.id;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const d = await client.getPackageVersion(workspace, packageId, packageVersionId);
|
|
65
|
+
url = d.version_url;
|
|
66
|
+
}
|
|
67
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_SCANNING_DIR, false);
|
|
68
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
69
|
+
let entries;
|
|
70
|
+
if (stat.isDirectory()) {
|
|
71
|
+
entries = fs_1.default.readdirSync(dirPath, {
|
|
72
|
+
withFileTypes: true,
|
|
73
|
+
recursive: true,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const parentPath = (0, path_1.dirname)(dirPath);
|
|
78
|
+
entries = [
|
|
79
|
+
{
|
|
80
|
+
isDirectory: () => stat.isDirectory(),
|
|
81
|
+
isFile: () => stat.isFile(),
|
|
82
|
+
isBlockDevice: () => stat.isBlockDevice(),
|
|
83
|
+
isCharacterDevice: () => stat.isCharacterDevice(),
|
|
84
|
+
isFIFO: () => stat.isFIFO(),
|
|
85
|
+
isSocket: () => stat.isSocket(),
|
|
86
|
+
isSymbolicLink: () => stat.isSymbolicLink(),
|
|
87
|
+
name: (0, path_1.basename)(dirPath),
|
|
88
|
+
parentPath,
|
|
89
|
+
path: parentPath,
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
dirPath = parentPath;
|
|
93
|
+
}
|
|
94
|
+
if (!entries.length) {
|
|
95
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_NO_ENTRIES_FOUND);
|
|
96
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
97
|
+
}
|
|
98
|
+
else if (entries.length === 1) {
|
|
99
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ONE_ENTRY_FOUND);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ENTRIES_FOUND)(entries.length));
|
|
103
|
+
}
|
|
104
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(0));
|
|
105
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
106
|
+
const clearZip = () => {
|
|
107
|
+
try {
|
|
108
|
+
fs_1.default.rmSync(zipPath);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// do nothing
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
let blob;
|
|
115
|
+
try {
|
|
116
|
+
let proc = 0;
|
|
117
|
+
await createZip(dirPath, zipPath, entries, () => {
|
|
118
|
+
proc += 1;
|
|
119
|
+
output_1.default.clearPreviousLine();
|
|
120
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(proc));
|
|
121
|
+
});
|
|
122
|
+
output_1.default.clearPreviousLine();
|
|
123
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ZIPPED);
|
|
124
|
+
blob = await fs_1.default.openAsBlob(zipPath);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
logger_1.default.error(err);
|
|
128
|
+
clearZip();
|
|
129
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADING);
|
|
133
|
+
await client.postPackageVersionZip(workspace, packageId, packageVersionId, blob);
|
|
134
|
+
output_1.default.clearPreviousLine();
|
|
135
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADED);
|
|
136
|
+
clearZip();
|
|
137
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
clearZip();
|
|
141
|
+
logger_1.default.error(err);
|
|
142
|
+
output_1.default.exitError(err);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const addEntryToZip = (dirPath, zip, entry) => {
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const isDir = entry.isDirectory();
|
|
148
|
+
let name = (0, path_1.join)(entry.parentPath.replace(dirPath, ''), entry.name);
|
|
149
|
+
if (isDir)
|
|
150
|
+
name += '/';
|
|
151
|
+
const file = new fflate_1.default.AsyncZipDeflate(name, {
|
|
152
|
+
level: 9,
|
|
153
|
+
});
|
|
154
|
+
zip.add(file);
|
|
155
|
+
if (isDir) {
|
|
156
|
+
file.push(new Uint8Array(0), true);
|
|
157
|
+
resolve();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const fullPath = (0, path_1.join)(entry.parentPath, entry.name);
|
|
161
|
+
const rs = fs_1.default.createReadStream(fullPath);
|
|
162
|
+
const finish = (err) => {
|
|
163
|
+
try {
|
|
164
|
+
rs.removeAllListeners();
|
|
165
|
+
rs.close();
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// do nothing
|
|
169
|
+
}
|
|
170
|
+
if (err)
|
|
171
|
+
reject(err);
|
|
172
|
+
else
|
|
173
|
+
resolve();
|
|
174
|
+
};
|
|
175
|
+
rs.on('data', (chunk) => {
|
|
176
|
+
file.push(chunk, false);
|
|
177
|
+
});
|
|
178
|
+
rs.on('error', (err) => {
|
|
179
|
+
finish(err);
|
|
180
|
+
});
|
|
181
|
+
rs.on('end', () => {
|
|
182
|
+
file.push(new Uint8Array(0), true);
|
|
183
|
+
finish();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
const addEntriesToZip = async (dirPath, zip, entries, onEntry) => {
|
|
188
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
189
|
+
await addEntryToZip(dirPath, zip, entries[i]);
|
|
190
|
+
onEntry();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const createZip = (dirPath, zipPath, entries, onEntry) => {
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
const ws = fs_1.default.createWriteStream(zipPath);
|
|
196
|
+
let wasError = false;
|
|
197
|
+
const zip = new fflate_1.default.Zip((err, data, final) => {
|
|
198
|
+
if (wasError) {
|
|
199
|
+
// do nothing
|
|
200
|
+
}
|
|
201
|
+
else if (err) {
|
|
202
|
+
wasError = true;
|
|
203
|
+
ws.close();
|
|
204
|
+
reject(err);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
ws.write(data);
|
|
208
|
+
if (final) {
|
|
209
|
+
ws.close((err) => {
|
|
210
|
+
if (err)
|
|
211
|
+
reject(err);
|
|
212
|
+
else
|
|
213
|
+
resolve();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
addEntriesToZip(dirPath, zip, entries, onEntry)
|
|
219
|
+
.then(() => {
|
|
220
|
+
zip.end();
|
|
221
|
+
})
|
|
222
|
+
.catch((err) => {
|
|
223
|
+
ws.close(() => {
|
|
224
|
+
reject(err);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
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,8 @@ 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 uuid_1 = require("uuid");
|
|
49
|
+
const node_path_1 = require("node:path");
|
|
48
50
|
class Input {
|
|
49
51
|
static timeout(timeout) {
|
|
50
52
|
const t = parseInt(timeout, 10);
|
|
@@ -339,6 +341,14 @@ class Input {
|
|
|
339
341
|
t = 1440;
|
|
340
342
|
return t;
|
|
341
343
|
}
|
|
344
|
+
static resolvePath(path) {
|
|
345
|
+
const p = (0, node_path_1.resolve)(path);
|
|
346
|
+
const exists = fs_1.default.existsSync(p);
|
|
347
|
+
if (!exists) {
|
|
348
|
+
output_1.default.exitError(texts_1.ERR_PATH_NOT_EXISTS);
|
|
349
|
+
}
|
|
350
|
+
return p;
|
|
351
|
+
}
|
|
342
352
|
static restApiWorkspace(workspace) {
|
|
343
353
|
let w = process.env.BUDDY_WORKSPACE;
|
|
344
354
|
if (workspace)
|
|
@@ -348,15 +358,23 @@ class Input {
|
|
|
348
358
|
}
|
|
349
359
|
return w;
|
|
350
360
|
}
|
|
351
|
-
static restApiProject(project) {
|
|
361
|
+
static restApiProject(project, allowNull = false) {
|
|
352
362
|
let p = process.env.BUDDY_PROJECT;
|
|
353
363
|
if (project)
|
|
354
364
|
p = project;
|
|
355
365
|
if (!p) {
|
|
366
|
+
if (allowNull)
|
|
367
|
+
return null;
|
|
356
368
|
output_1.default.exitError(texts_1.ERR_REST_API_PROJECT);
|
|
357
369
|
}
|
|
358
370
|
return p;
|
|
359
371
|
}
|
|
372
|
+
static restApiPackageVersion(version) {
|
|
373
|
+
let v = version;
|
|
374
|
+
if (!v)
|
|
375
|
+
v = (0, uuid_1.v4)();
|
|
376
|
+
return v;
|
|
377
|
+
}
|
|
360
378
|
static name(name) {
|
|
361
379
|
if (name.includes('*')) {
|
|
362
380
|
output_1.default.exitError(texts_1.ERR_NAME_WITHOUT_ASTERISK);
|
package/distTs/src/output.js
CHANGED
|
@@ -29,8 +29,11 @@ class Output {
|
|
|
29
29
|
static newline() {
|
|
30
30
|
terminal('\n');
|
|
31
31
|
}
|
|
32
|
-
static normal(txt) {
|
|
33
|
-
|
|
32
|
+
static normal(txt, newLine = true) {
|
|
33
|
+
let msg = txt;
|
|
34
|
+
if (newLine)
|
|
35
|
+
msg += '\n';
|
|
36
|
+
terminal(msg);
|
|
34
37
|
}
|
|
35
38
|
static warning(txt) {
|
|
36
39
|
terminal.yellow(`${txt}\n`);
|
package/distTs/src/texts.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
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.
|
|
3
|
+
exports.ERR_SWW_AGENT_UPDATING = exports.ERR_SWW_AGENT_DISABLING = exports.ERR_SWW_AGENT_ENABLING = exports.ERR_AGENT_NOT_FOUND = exports.ERR_AGENT_NOT_RUNNING = 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_INVALID_SNAPSHOT = 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_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_AGENT_ENABLE = void 0;
|
|
5
|
+
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 = 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_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 = void 0;
|
|
6
|
+
exports.TXT_PIPELINE_RUN_SUCCESS = exports.TXT_OPENING_TUNNEL = exports.TXT_UPDATING_AGENT = exports.TXT_ENABLING_AGENT = exports.TXT_DISABLING_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 = 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_INSTALL = exports.DESC_COMMAND_AGENT_UNINSTALL = exports.DESC_COMMAND_AGENT_TUNNEL_REMOVE = void 0;
|
|
7
|
+
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_DOWNLOAD_VERSION = exports.OPTION_PACKAGE_PUBLISH_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 = 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 = void 0;
|
|
8
|
+
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 = 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 = void 0;
|
|
9
|
+
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 = 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_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_ERROR_SAVING_AGENT_CONFIG = exports.LOG_SAVING_AGENT_LOCAL_CONFIG = exports.LOG_SAVING_AGENT_SYSTEM_CONFIG = exports.LOG_SAVING_AGENT_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 = void 0;
|
|
10
|
+
exports.DEBUG_WAIT_FOR_IDLE_TIMEOUT = exports.DEBUG_WAIT_FOR_IDLE = exports.DEBUG_RESOURCE_DISCOVERY_TIMEOUT = 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 = void 0;
|
|
10
11
|
const utils_1 = require("./utils");
|
|
11
12
|
exports.ERR_REST_API_GENERAL_ERROR = 'Something went wrong';
|
|
12
13
|
exports.ERR_REST_API_WRONG_TOKEN = 'Valid token with proper scopes is required';
|
|
@@ -14,11 +15,16 @@ exports.ERR_REST_API_RESOURCE_NOT_FOUND = 'Resource not found';
|
|
|
14
15
|
exports.ERR_REST_API_RATE_LIMIT = 'Rate limit exceeded';
|
|
15
16
|
exports.ERR_REST_API_TOKEN = 'Personal access token is required (--token)';
|
|
16
17
|
exports.ERR_REST_API_URL = 'Valid rest api endpoint is required (--api)';
|
|
18
|
+
exports.ERR_PATH_NOT_EXISTS = 'path not exists';
|
|
17
19
|
exports.ERR_REST_API_WORKSPACE = 'Workspace domain is required (--workspace)';
|
|
18
20
|
exports.ERR_REST_API_PROJECT = 'Project name is required (--project)';
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
21
|
+
exports.ERR_WORKSPACE_NOT_FOUND = 'Workspace not found';
|
|
22
|
+
exports.ERR_PROJECT_NOT_FOUND = 'Project not found';
|
|
23
|
+
exports.ERR_PIPELINE_NOT_FOUND = 'Pipeline not found';
|
|
24
|
+
exports.ERR_PACKAGE_DOWNLOAD_NOT_FOUND = 'Package not found';
|
|
25
|
+
exports.ERR_PACKAGE_PUBLISH_NOT_FOUND = 'Package not found. Change package name or use --create to create one';
|
|
26
|
+
exports.ERR_PACKAGE_VERSION_EXISTS = 'Package version exists. Change version name or use --force flag';
|
|
27
|
+
exports.ERR_PACKAGE_VERSION_NOT_FOUND = 'Package version not found';
|
|
22
28
|
exports.ERR_RUN_PIPELINE_WAIT_TIMEOUT = 'Timeout waiting for run to finish';
|
|
23
29
|
exports.ERR_RUN_PIPELINE_WRONG_PRIORITY = 'Priority has wrong value. Possible: LOW, NORMAL, HIGH';
|
|
24
30
|
exports.ERR_RUN_PIPELINE_WRONG_DELAY = 'Delay must be a valid date format: 2016-11-18T12:38:16.000Z or 30s, 10m, 3h10m30s';
|
|
@@ -89,6 +95,14 @@ exports.ERR_TUNNEL_REMOVED = 'Tunnel removed';
|
|
|
89
95
|
exports.ERR_FAILED_TO_CONNECT_TO_AGENT = 'Failed connecting to agent';
|
|
90
96
|
exports.ERR_NOT_FOUND = 'Not found';
|
|
91
97
|
exports.ERR_SWW = 'Something went wrong';
|
|
98
|
+
const ERR_PACKAGE_DOWNLOAD_MKDIR = (dirPath) => `Error while creating directory ${dirPath}`;
|
|
99
|
+
exports.ERR_PACKAGE_DOWNLOAD_MKDIR = ERR_PACKAGE_DOWNLOAD_MKDIR;
|
|
100
|
+
const ERR_PACKAGE_DOWNLOAD_READDIR = (dirPath) => `Error while reading directory ${dirPath}`;
|
|
101
|
+
exports.ERR_PACKAGE_DOWNLOAD_READDIR = ERR_PACKAGE_DOWNLOAD_READDIR;
|
|
102
|
+
const ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR = (dirPath) => `Directory ${dirPath} is not empty. Use --merge or --replace flags`;
|
|
103
|
+
exports.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR = ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR;
|
|
104
|
+
const ERR_PACKAGE_DOWNLOAD_REPLACE = (dirPath) => `Error while replacing directory ${dirPath}`;
|
|
105
|
+
exports.ERR_PACKAGE_DOWNLOAD_REPLACE = ERR_PACKAGE_DOWNLOAD_REPLACE;
|
|
92
106
|
exports.ERR_FETCH_VERSION = 'Failed to fetch version';
|
|
93
107
|
exports.ERR_WRONG_HANDSHAKE = 'Wrong handshake data';
|
|
94
108
|
exports.ERR_WRONG_STREAM = 'Wrong stream type';
|
|
@@ -202,7 +216,10 @@ exports.DESC_COMMAND_TCP = 'Starts a tunnel which forwards all TCP traffic on a
|
|
|
202
216
|
exports.DESC_COMMAND_TLS = 'Starts a tunnel listening for TLS traffic on port 443 with a specific hostname.';
|
|
203
217
|
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.';
|
|
204
218
|
exports.DESC_COMMAND_PIPELINE = 'Commands to interact with the pipeline service';
|
|
205
|
-
exports.
|
|
219
|
+
exports.DESC_COMMAND_PACKAGE = 'Commands to interact with the package service';
|
|
220
|
+
exports.DESC_COMMAND_PACKAGE_PUBLISH = 'Publish package. Required scopes: PACKAGE_READ, PACKAGE_WRITE, PACKAGE_MANAGE';
|
|
221
|
+
exports.DESC_COMMAND_PACKAGE_DOWNLOAD = 'Download package. Required scopes: PACKAGE_READ';
|
|
222
|
+
exports.DESC_COMMAND_PIPELINE_RUN = 'Run pipeline. Required scopes: EXECUTION_INFO, EXECUTION_RUN';
|
|
206
223
|
exports.DESC_COMMAND_VT = 'Commands to interact with the visual test service';
|
|
207
224
|
exports.DESC_COMMAND_VT_CLOSE = 'Close visual test session.';
|
|
208
225
|
exports.DESC_COMMAND_VT_STORYBOOK = 'Create visual test session from storybook';
|
|
@@ -236,6 +253,26 @@ const TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY = (runUrl) => `Run finished successfu
|
|
|
236
253
|
exports.TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY = TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY;
|
|
237
254
|
const TXT_PIPELINE_RUN_FINISH_FAILED = (status, runUrl) => `Run finished with status ${status}: ${runUrl}`;
|
|
238
255
|
exports.TXT_PIPELINE_RUN_FINISH_FAILED = TXT_PIPELINE_RUN_FINISH_FAILED;
|
|
256
|
+
exports.TXT_PACKAGE_SCANNING_DIR = 'Scanning...';
|
|
257
|
+
exports.TXT_PACKAGE_NO_ENTRIES_FOUND = 'no entries found';
|
|
258
|
+
exports.TXT_PACKAGE_ONE_ENTRY_FOUND = '1 entry found';
|
|
259
|
+
const TXT_PACKAGE_ZIP_ENTRIES = (count) => `Archiving...${count}`;
|
|
260
|
+
exports.TXT_PACKAGE_ZIP_ENTRIES = TXT_PACKAGE_ZIP_ENTRIES;
|
|
261
|
+
exports.TXT_PACKAGE_ZIPPED = `Archiving...Done`;
|
|
262
|
+
exports.TXT_PACKAGE_UPLOADING = 'Uploading...';
|
|
263
|
+
exports.TXT_PACKAGE_UPLOADED = 'Uploading...Done';
|
|
264
|
+
const TXT_PACKAGE_ENTRIES_FOUND = (count) => `${count} entries found`;
|
|
265
|
+
exports.TXT_PACKAGE_ENTRIES_FOUND = TXT_PACKAGE_ENTRIES_FOUND;
|
|
266
|
+
const TXT_PACKAGE_PUBLISHED = (versionUrl) => `Package published: ${versionUrl}`;
|
|
267
|
+
exports.TXT_PACKAGE_PUBLISHED = TXT_PACKAGE_PUBLISHED;
|
|
268
|
+
const TXT_PACKAGE_DOWNLOADED = (version, dirPath) => `Package version '${version}' downloaded to ${dirPath}`;
|
|
269
|
+
exports.TXT_PACKAGE_DOWNLOADED = TXT_PACKAGE_DOWNLOADED;
|
|
270
|
+
exports.TXT_PACKAGE_DOWNLOADING_ZIP = 'Downloading...';
|
|
271
|
+
exports.TXT_PACKAGE_DOWNLOADED_ZIP = 'Downloading...Done';
|
|
272
|
+
exports.TXT_PACKAGE_UNZIPPING = 'Unzipping...';
|
|
273
|
+
exports.TXT_PACKAGE_UNZIPPED = 'Unzipping...Done';
|
|
274
|
+
const TXT_PACKAGE_UNZIPPING_COUNT = (count) => `Unzipping...${count}`;
|
|
275
|
+
exports.TXT_PACKAGE_UNZIPPING_COUNT = TXT_PACKAGE_UNZIPPING_COUNT;
|
|
239
276
|
exports.OPTION_REGION = 'override default region ("eu", "us")';
|
|
240
277
|
exports.OPTION_DEFAULT_REGION = 'default region ("eu", "us")';
|
|
241
278
|
exports.OPTION_REST_API_ENDPOINT = 'override default base url (api.buddy.works) and region. You can use env variable: BUDDY_API_ENDPOINT.';
|
|
@@ -250,7 +287,16 @@ exports.OPTION_PIPELINE_RUN_CLEAR_CACHE = 'clear cache before running the pipeli
|
|
|
250
287
|
exports.OPTION_PIPELINE_RUN_PRIORITY = 'run priority. Can be one of "LOW", "NORMAL" or "HIGH". Default is "NORMAL"';
|
|
251
288
|
exports.OPTION_PIPELINE_RUN_VAR = 'variable key:value. Can be passed multiple times to pass multiple variables';
|
|
252
289
|
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';
|
|
253
|
-
exports.OPTION_PIPELINE_RUN_ARGUMENT = 'human-readable ID of pipeline';
|
|
290
|
+
exports.OPTION_PIPELINE_RUN_ARGUMENT = 'human-readable ID of the pipeline';
|
|
291
|
+
exports.OPTION_PACKAGE_PUBLISH_PATH = 'path to the directory or file';
|
|
292
|
+
exports.OPTION_PACKAGE_DOWNLOAD_PATH = 'path to the directory or file';
|
|
293
|
+
exports.OPTION_PACKAGE_ID = 'human-readable ID of the package';
|
|
294
|
+
exports.OPTION_PACKAGE_PUBLISH_CREATE = 'create package if not exists';
|
|
295
|
+
exports.OPTION_PACKAGE_PUBLISH_VERSION = 'version name to publish';
|
|
296
|
+
exports.OPTION_PACKAGE_DOWNLOAD_VERSION = 'version name to download. If omitted latest version will be fetched';
|
|
297
|
+
exports.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION = 'allow overwriting existing version';
|
|
298
|
+
exports.OPTION_PACKAGE_DOWNLOAD_MERGE = 'merge contents of the directory with package';
|
|
299
|
+
exports.OPTION_PACKAGE_DOWNLOAD_REPLACE = 'replace contents of the directory with package';
|
|
254
300
|
exports.OPTION_REST_API_TOKEN = 'personal access token. You can use env variable: BUDDY_TOKEN';
|
|
255
301
|
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";
|
|
256
302
|
exports.OPTION_PIPELINE_RUN_WAIT = 'wait for run to finish';
|
package/package.json
CHANGED
|
@@ -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;
|