bdy 1.16.31-dev → 1.16.33-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +5 -1
- package/distTs/src/command/api/info.js +268 -0
- package/distTs/src/command/api/list.js +43 -0
- package/distTs/src/command/api.js +13 -0
- package/distTs/src/command/sandbox/create.js +5 -14
- package/distTs/src/index.js +2 -0
- package/distTs/src/input.js +13 -0
- package/distTs/src/texts.js +16 -2
- package/distTs/src/utils.js +48 -9
- package/package.json +5 -1
package/distTs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.33-dev",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"cookie": "1.0.2",
|
|
30
30
|
"cross-spawn": "7.0.6",
|
|
31
31
|
"eventsource": "4.0.0",
|
|
32
|
+
"@scalar/openapi-parser": "0.24.5",
|
|
33
|
+
"@scalar/json-magic": "0.9.4",
|
|
34
|
+
"@scalar/types": "0.5.10",
|
|
35
|
+
"@scalar/openapi-types": "0.5.3",
|
|
32
36
|
"fastify": "4.28.1",
|
|
33
37
|
"fdir": "6.5.0",
|
|
34
38
|
"open": "11.0.0",
|
|
@@ -0,0 +1,268 @@
|
|
|
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 output_1 = __importDefault(require("../../output"));
|
|
10
|
+
var SCHEMA_TYPE;
|
|
11
|
+
(function (SCHEMA_TYPE) {
|
|
12
|
+
SCHEMA_TYPE["OBJECT"] = "object";
|
|
13
|
+
SCHEMA_TYPE["ARRAY"] = "array";
|
|
14
|
+
})(SCHEMA_TYPE || (SCHEMA_TYPE = {}));
|
|
15
|
+
const getRequiredScopes = (data) => {
|
|
16
|
+
if (data.security && data.security[0] && data.security[0].oauth2) {
|
|
17
|
+
return data.security[0].oauth2;
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
};
|
|
21
|
+
const getParameterType = (p) => {
|
|
22
|
+
if (p.schema && p.schema.type) {
|
|
23
|
+
return p.schema.type;
|
|
24
|
+
}
|
|
25
|
+
return 'string';
|
|
26
|
+
};
|
|
27
|
+
const outputParameters = (type, data, workspace, project) => {
|
|
28
|
+
const table = [];
|
|
29
|
+
(data.parameters || []).forEach((p) => {
|
|
30
|
+
if (p.in === type) {
|
|
31
|
+
let example = '-';
|
|
32
|
+
if (p.name === 'workspace_domain')
|
|
33
|
+
example = workspace;
|
|
34
|
+
else if (p.name === 'project_name' && project)
|
|
35
|
+
example = project;
|
|
36
|
+
else if (p.schema && p.schema.example)
|
|
37
|
+
example = p.schema.example;
|
|
38
|
+
table.push([
|
|
39
|
+
p.name || '-',
|
|
40
|
+
getParameterType(p),
|
|
41
|
+
example.toString(),
|
|
42
|
+
p.description || '-',
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (table.length > 0) {
|
|
47
|
+
table.unshift([
|
|
48
|
+
type === 'path' ? 'URL param' : 'Query param',
|
|
49
|
+
'Type',
|
|
50
|
+
'Example',
|
|
51
|
+
'Description',
|
|
52
|
+
]);
|
|
53
|
+
output_1.default.table(table);
|
|
54
|
+
output_1.default.normal('');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const outputTextWithPadding = (text, padding = 1, newLine = true) => {
|
|
58
|
+
let t = '';
|
|
59
|
+
for (let i = 0; i < padding; i += 1)
|
|
60
|
+
t += ' ';
|
|
61
|
+
t += text;
|
|
62
|
+
output_1.default.normal(t, newLine);
|
|
63
|
+
};
|
|
64
|
+
const outputSimpleProp = (name, type, description, enu, required, padding) => {
|
|
65
|
+
outputTextWithPadding(name, padding, false);
|
|
66
|
+
output_1.default.gray(`: ${type}`, false);
|
|
67
|
+
if (required)
|
|
68
|
+
output_1.default.gray(' (required)', false);
|
|
69
|
+
if (description)
|
|
70
|
+
output_1.default.gray(` - ${description}`, false);
|
|
71
|
+
if (enu && enu.length)
|
|
72
|
+
output_1.default.gray(` - ${enu.join(', ')}`, false);
|
|
73
|
+
output_1.default.normal('');
|
|
74
|
+
};
|
|
75
|
+
const outputJsonArrayProp = (data, padding, name, required) => {
|
|
76
|
+
if (name) {
|
|
77
|
+
outputTextWithPadding(name, padding, false);
|
|
78
|
+
output_1.default.gray(`: ${SCHEMA_TYPE.ARRAY}`, false);
|
|
79
|
+
if (required)
|
|
80
|
+
output_1.default.gray(' (required)', false);
|
|
81
|
+
if (data.description)
|
|
82
|
+
output_1.default.gray(` - ${data.description}`, false);
|
|
83
|
+
output_1.default.normal('');
|
|
84
|
+
}
|
|
85
|
+
outputTextWithPadding('[', padding);
|
|
86
|
+
if (data.items.type === SCHEMA_TYPE.OBJECT)
|
|
87
|
+
outputJsonObject(data.items, padding + 2);
|
|
88
|
+
else if (data.items.type === SCHEMA_TYPE.ARRAY)
|
|
89
|
+
outputJsonArrayProp(data.items, padding + 2);
|
|
90
|
+
else
|
|
91
|
+
outputSimpleProp('item', data.items.type, data.items.description, data.items.enum, false, padding + 2);
|
|
92
|
+
outputTextWithPadding(']', padding);
|
|
93
|
+
};
|
|
94
|
+
const outputJsonObject = (data, padding = 1, name, required) => {
|
|
95
|
+
const propsRequired = data.required || [];
|
|
96
|
+
const props = data.properties || {};
|
|
97
|
+
if (name) {
|
|
98
|
+
outputTextWithPadding(name, padding, false);
|
|
99
|
+
output_1.default.gray(` : ${SCHEMA_TYPE.OBJECT}`, false);
|
|
100
|
+
if (required)
|
|
101
|
+
output_1.default.gray(' (required)', false);
|
|
102
|
+
if (data.description)
|
|
103
|
+
output_1.default.gray(` - ${data.description}`, false);
|
|
104
|
+
output_1.default.normal('');
|
|
105
|
+
}
|
|
106
|
+
outputTextWithPadding('{', padding);
|
|
107
|
+
const keys = Object.keys(props);
|
|
108
|
+
if (keys.length > 0) {
|
|
109
|
+
keys.forEach((name) => {
|
|
110
|
+
const prop = props[name];
|
|
111
|
+
if (prop.type === SCHEMA_TYPE.ARRAY)
|
|
112
|
+
outputJsonArrayProp(prop, padding + 2, name, propsRequired.includes(name));
|
|
113
|
+
else if (prop.type === SCHEMA_TYPE.OBJECT)
|
|
114
|
+
outputJsonObject(prop, padding + 2, name, propsRequired.includes(name));
|
|
115
|
+
else
|
|
116
|
+
outputSimpleProp(name, prop.type, prop.description, prop.enum, propsRequired.includes(name), padding + 2);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else if (data.additionalProperties) {
|
|
120
|
+
outputTextWithPadding('key: value', padding + 2, false);
|
|
121
|
+
if (data.additionalProperties.description)
|
|
122
|
+
output_1.default.gray(` - ${data.additionalProperties.description}`, false);
|
|
123
|
+
output_1.default.normal('');
|
|
124
|
+
}
|
|
125
|
+
outputTextWithPadding('}', padding);
|
|
126
|
+
};
|
|
127
|
+
const outputMultipartBinary = (name, array, description, required, padding) => {
|
|
128
|
+
outputTextWithPadding(name, padding, false);
|
|
129
|
+
output_1.default.gray(array ? ': binary array' : ': binary', false);
|
|
130
|
+
if (required)
|
|
131
|
+
output_1.default.gray(' (required)', false);
|
|
132
|
+
if (description)
|
|
133
|
+
output_1.default.gray(` - ${description}`, false);
|
|
134
|
+
output_1.default.normal('');
|
|
135
|
+
};
|
|
136
|
+
const outputMultipartFormData = (data, padding = 1) => {
|
|
137
|
+
const propsRequired = data.required || [];
|
|
138
|
+
const props = data.properties || {};
|
|
139
|
+
const keys = Object.keys(props);
|
|
140
|
+
if (keys.length > 0) {
|
|
141
|
+
keys.forEach((name) => {
|
|
142
|
+
const prop = props[name];
|
|
143
|
+
if (prop.format === 'binary')
|
|
144
|
+
outputMultipartBinary(name, prop.type === 'array', prop.description, propsRequired.includes(name), padding);
|
|
145
|
+
else if (prop.type === SCHEMA_TYPE.ARRAY)
|
|
146
|
+
output_1.default.exitError(texts_1.ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED);
|
|
147
|
+
else if (prop.type === SCHEMA_TYPE.OBJECT)
|
|
148
|
+
output_1.default.exitError(texts_1.ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED);
|
|
149
|
+
else
|
|
150
|
+
outputSimpleProp(name, prop.type, prop.description, prop.enum, propsRequired.includes(name), padding);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const outputBodyObject = (mediaType, data) => {
|
|
155
|
+
if (mediaType === 'multipart/form-data') {
|
|
156
|
+
outputMultipartFormData(data);
|
|
157
|
+
}
|
|
158
|
+
else if (['application/json', 'application/jsonl'].includes(mediaType)) {
|
|
159
|
+
outputJsonObject(data);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
output_1.default.exitError((0, texts_1.ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED)(mediaType));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const outputResponse = (response) => {
|
|
166
|
+
const content = response.content || {};
|
|
167
|
+
Object.keys(content).forEach((mediaType, index) => {
|
|
168
|
+
if (index > 0) {
|
|
169
|
+
output_1.default.gray(' ------- or content type -------');
|
|
170
|
+
}
|
|
171
|
+
outputMediaType(mediaType, content[mediaType]);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
const outputResponsesBody = (responses) => {
|
|
175
|
+
const r = responses || {};
|
|
176
|
+
const codes = Object.keys(r);
|
|
177
|
+
if (codes.length > 0) {
|
|
178
|
+
output_1.default.blue(` Response body`);
|
|
179
|
+
codes.forEach((code, index) => {
|
|
180
|
+
if (index > 0) {
|
|
181
|
+
output_1.default.gray(' ------------');
|
|
182
|
+
}
|
|
183
|
+
output_1.default.gray(' http status: ', false);
|
|
184
|
+
output_1.default.normal(code);
|
|
185
|
+
outputResponse(r[code]);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const outputMediaType = (mediaType, mediaTypeObject) => {
|
|
190
|
+
output_1.default.gray(' content-type: ', false);
|
|
191
|
+
output_1.default.normal(mediaType);
|
|
192
|
+
if (mediaTypeObject.schema) {
|
|
193
|
+
if (mediaTypeObject.schema.oneOf) {
|
|
194
|
+
const mappings = Object.keys(mediaTypeObject.schema.discriminator?.mapping || {});
|
|
195
|
+
mediaTypeObject.schema.oneOf.forEach((schema, index) => {
|
|
196
|
+
if (mappings[index]) {
|
|
197
|
+
output_1.default.gray(` ${mappings[index]}:`);
|
|
198
|
+
}
|
|
199
|
+
else if (index > 0) {
|
|
200
|
+
output_1.default.gray(' ------------- or --------------');
|
|
201
|
+
}
|
|
202
|
+
outputBodyObject(mediaType, schema);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
outputBodyObject(mediaType, mediaTypeObject.schema);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const outputRequestBody = (data) => {
|
|
211
|
+
if (data) {
|
|
212
|
+
output_1.default.blue(` Request body`);
|
|
213
|
+
const content = data.content || {};
|
|
214
|
+
Object.keys(content).forEach((mediaType, index) => {
|
|
215
|
+
if (index > 0) {
|
|
216
|
+
output_1.default.gray(' ------- or content type -------');
|
|
217
|
+
}
|
|
218
|
+
outputMediaType(mediaType, content[mediaType]);
|
|
219
|
+
});
|
|
220
|
+
output_1.default.normal('');
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const outputUrl = (url, method, data, workspace, project) => {
|
|
224
|
+
output_1.default.normal(`${method} ${url}`);
|
|
225
|
+
if (data.summary)
|
|
226
|
+
output_1.default.gray(data.summary, false);
|
|
227
|
+
const scopes = getRequiredScopes(data);
|
|
228
|
+
if (scopes.length > 0) {
|
|
229
|
+
if (data.summary)
|
|
230
|
+
output_1.default.gray('. ', false);
|
|
231
|
+
output_1.default.gray(`${texts_1.TXT_API_ENDPOINT_REQUIRED_SCOPES}: `, false);
|
|
232
|
+
output_1.default.gray(scopes.join(', '), false);
|
|
233
|
+
}
|
|
234
|
+
output_1.default.normal('\n');
|
|
235
|
+
outputParameters('path', data, workspace, project);
|
|
236
|
+
outputParameters('query', data, workspace, project);
|
|
237
|
+
outputRequestBody(data.requestBody);
|
|
238
|
+
outputResponsesBody(data.responses);
|
|
239
|
+
output_1.default.exitNormal();
|
|
240
|
+
};
|
|
241
|
+
const commandApiInfo = (0, utils_1.newCommand)('info', texts_1.DESC_COMMAND_API_INFO);
|
|
242
|
+
commandApiInfo.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
243
|
+
commandApiInfo.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
244
|
+
commandApiInfo.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
245
|
+
commandApiInfo.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
246
|
+
commandApiInfo.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
247
|
+
commandApiInfo.argument('<method>', texts_1.OPT_COMMAND_API_INFO_METHOD);
|
|
248
|
+
commandApiInfo.argument('<url>', texts_1.OPT_COMMAND_API_INFO_URL);
|
|
249
|
+
commandApiInfo.action(async (fm, filterUrl, options) => {
|
|
250
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
251
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
252
|
+
const filterMethod = input_1.default.restApiMethod(fm, false);
|
|
253
|
+
const client = input_1.default.restApiTokenClient(options.api, options.region, options.token);
|
|
254
|
+
const schema = await (0, utils_1.fetchOpenApiSchema)(client.baseUrl);
|
|
255
|
+
const paths = schema.paths || {};
|
|
256
|
+
Object.keys(paths).forEach((url) => {
|
|
257
|
+
const preparedUrl = (0, utils_1.openApiPrepareUrl)(url, workspace, project);
|
|
258
|
+
if (filterUrl === url || filterUrl === preparedUrl) {
|
|
259
|
+
const methods = paths[url] || {};
|
|
260
|
+
Object.entries(methods).forEach(([method, data]) => {
|
|
261
|
+
if (filterMethod === method)
|
|
262
|
+
outputUrl(preparedUrl, method, data, workspace, project);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
output_1.default.exitError(texts_1.ERR_API_ENDPOINT_NOT_FOUND);
|
|
267
|
+
});
|
|
268
|
+
exports.default = commandApiInfo;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const outputUrl = (url, method, data, workspace, project) => {
|
|
11
|
+
output_1.default.normal(`${method} ${(0, utils_1.openApiPrepareUrl)(url, workspace, project)}`);
|
|
12
|
+
if (data.summary)
|
|
13
|
+
output_1.default.gray(data.summary);
|
|
14
|
+
};
|
|
15
|
+
const commandApiList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_API_LIST);
|
|
16
|
+
commandApiList.alias('ls');
|
|
17
|
+
commandApiList.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
18
|
+
commandApiList.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
19
|
+
commandApiList.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
20
|
+
commandApiList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
21
|
+
commandApiList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
22
|
+
commandApiList.option('-m, --method <method>', texts_1.OPT_COMMAND_API_LIST_METHOD);
|
|
23
|
+
commandApiList.option('-s, --search <phrase>', texts_1.OPT_COMMAND_API_LIST_SEARCH);
|
|
24
|
+
commandApiList.action(async (options) => {
|
|
25
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
26
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
27
|
+
const filterMethod = input_1.default.restApiMethod(options.method);
|
|
28
|
+
const filter = options.search;
|
|
29
|
+
const client = input_1.default.restApiTokenClient(options.api, options.region, options.token);
|
|
30
|
+
const schema = await (0, utils_1.fetchOpenApiSchema)(client.baseUrl);
|
|
31
|
+
const paths = schema.paths || {};
|
|
32
|
+
Object.keys(paths).forEach((url) => {
|
|
33
|
+
if (!filter || url.includes(filter)) {
|
|
34
|
+
const methods = paths[url] || {};
|
|
35
|
+
Object.entries(methods).forEach(([method, data]) => {
|
|
36
|
+
if (!filterMethod || filterMethod === method)
|
|
37
|
+
outputUrl(url, method, data, workspace, project);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
output_1.default.exitNormal();
|
|
42
|
+
});
|
|
43
|
+
exports.default = commandApiList;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 list_1 = __importDefault(require("./api/list"));
|
|
9
|
+
const info_1 = __importDefault(require("./api/info"));
|
|
10
|
+
const commandApi = (0, utils_1.newCommand)('api', texts_1.DESC_COMMAND_API);
|
|
11
|
+
commandApi.addCommand(list_1.default);
|
|
12
|
+
commandApi.addCommand(info_1.default);
|
|
13
|
+
exports.default = commandApi;
|
|
@@ -57,22 +57,13 @@ commandSandboxCreate.action(async (options) => {
|
|
|
57
57
|
identifier: options.identifier || defaultIdentifier,
|
|
58
58
|
};
|
|
59
59
|
if (options.snapshot) {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const snapshotsResult = await client.listSandboxSnapshots(workspace, sandbox.id);
|
|
65
|
-
const snapshots = snapshotsResult.snapshots || [];
|
|
66
|
-
const foundSnapshot = snapshots.find((s) => s.name === options.snapshot);
|
|
67
|
-
if (foundSnapshot) {
|
|
68
|
-
foundSnapshotId = foundSnapshot.id;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (!foundSnapshotId) {
|
|
60
|
+
const snapshotsResult = await client.listProjectSnapshots(workspace, project);
|
|
61
|
+
const snapshots = snapshotsResult.snapshots || [];
|
|
62
|
+
const foundSnapshot = snapshots.find((s) => s.name === options.snapshot);
|
|
63
|
+
if (!foundSnapshot) {
|
|
73
64
|
output_1.default.exitError(texts_1.ERR_SANDBOX_SNAPSHOT_NOT_FOUND);
|
|
74
65
|
}
|
|
75
|
-
body.snapshot_id =
|
|
66
|
+
body.snapshot_id = foundSnapshot.id;
|
|
76
67
|
}
|
|
77
68
|
else {
|
|
78
69
|
body.os = options.os || 'ubuntu:24.04';
|
package/distTs/src/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const workspace_1 = __importDefault(require("./command/workspace"));
|
|
|
22
22
|
const project_1 = __importDefault(require("./command/project"));
|
|
23
23
|
const whoami_1 = __importDefault(require("./command/whoami"));
|
|
24
24
|
const package_1 = __importDefault(require("./command/package"));
|
|
25
|
+
const api_1 = __importDefault(require("./command/api"));
|
|
25
26
|
stream_1.default.setDefaultHighWaterMark(false, 67108864);
|
|
26
27
|
process.title = 'bdy';
|
|
27
28
|
process.on('uncaughtException', (err) => {
|
|
@@ -47,4 +48,5 @@ program.addCommand(whoami_1.default);
|
|
|
47
48
|
program.addCommand(logout_1.default);
|
|
48
49
|
program.addCommand(workspace_1.default);
|
|
49
50
|
program.addCommand(project_1.default);
|
|
51
|
+
program.addCommand(api_1.default);
|
|
50
52
|
program.parse();
|
package/distTs/src/input.js
CHANGED
|
@@ -622,6 +622,19 @@ class Input {
|
|
|
622
622
|
}
|
|
623
623
|
return { sourceStats, sourcePath: s };
|
|
624
624
|
}
|
|
625
|
+
static restApiMethod(method, allowNull = true) {
|
|
626
|
+
if (!method) {
|
|
627
|
+
if (!allowNull)
|
|
628
|
+
output_1.default.exitError(texts_1.ERR_API_WRONG_METHOD);
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
const m = method.toLowerCase();
|
|
632
|
+
if (['get', 'post', 'put', 'patch', 'delete'].includes(m))
|
|
633
|
+
return m;
|
|
634
|
+
if (!allowNull)
|
|
635
|
+
output_1.default.exitError(texts_1.ERR_API_WRONG_METHOD);
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
625
638
|
static restApiProject(project, allowNull) {
|
|
626
639
|
let p = process.env.BUDDY_PROJECT;
|
|
627
640
|
if (project)
|
package/distTs/src/texts.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.LOG_TUNNEL_REGISTERED = exports.LOG_ERROR_WHILE_REFRESHING_AGENT = expor
|
|
|
10
10
|
exports.DESC_COMMAND_SANDBOX_LIST = exports.DESC_COMMAND_SANDBOX_CREATE = exports.DESC_COMMAND_SANDBOX = 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 = 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 = void 0;
|
|
11
11
|
exports.DESC_COMMAND_SANDBOX_SNAPSHOT_CREATE = exports.DESC_COMMAND_SANDBOX_SNAPSHOT_LIST = exports.DESC_COMMAND_SANDBOX_SNAPSHOT = exports.TXT_SANDBOX_COMMAND_KILLED = exports.OPTION_SANDBOX_COMMAND_KILL_CONFIRM = exports.OPTION_SANDBOX_COMMAND_ID = exports.DESC_COMMAND_SANDBOX_EXEC_KILL = exports.DESC_COMMAND_SANDBOX_EXEC_LOGS = exports.DESC_COMMAND_SANDBOX_EXEC_STATUS = exports.DESC_COMMAND_SANDBOX_EXEC_LIST = exports.TXT_SANDBOX_WAITING_START = exports.TXT_SANDBOX_WAITING_STOP = exports.TXT_SANDBOX_WAITING_SETUP = exports.TXT_SANDBOX_WAITING_RUNNING = exports.TXT_SANDBOX_STOPPED = exports.TXT_SANDBOX_STARTED = exports.TXT_SANDBOX_DESTROYED = exports.TXT_SANDBOX_DESTROY_CONFIRM = exports.TXT_SANDBOX_CREATED = exports.TXT_SANDBOX_CREATING = exports.OPTION_SANDBOX_WAIT = exports.OPTION_SANDBOX_WAIT_CONFIGURED = exports.OPTION_SANDBOX_WAIT_RUNNING = exports.ERR_SANDBOX_STOP_FAILED = exports.ERR_SANDBOX_NO_COMMANDS = exports.ERR_SANDBOX_RUNNING_FAILED = exports.ERR_SANDBOX_STOP_TIMEOUT = exports.ERR_SANDBOX_SNAPSHOT_TIMEOUT = exports.ERR_SANDBOX_RUNNING_TIMEOUT = exports.ERR_SANDBOX_SETUP_TIMEOUT = exports.ERR_SANDBOX_SETUP_FAILED = exports.ERR_SANDBOX_INVALID_RESOURCES = exports.ERR_SANDBOX_NOT_FOUND = exports.OPTION_SANDBOX_RUNTIME = exports.OPTION_SANDBOX_APP_TYPE = exports.OPTION_SANDBOX_APP_DIR = exports.OPTION_SANDBOX_RUN_COMMAND = exports.OPTION_SANDBOX_TAGS = exports.OPTION_SANDBOX_INSTALL_COMMANDS = exports.OPTION_SANDBOX_RESOURCES = exports.OPTION_SANDBOX_OS = exports.OPTION_SANDBOX_NAME = exports.OPTION_SANDBOX_IDENTIFIER = exports.DESC_COMMAND_SANDBOX_EXEC = exports.DESC_COMMAND_SANDBOX_STATUS = exports.DESC_COMMAND_SANDBOX_RESTART = exports.DESC_COMMAND_SANDBOX_STOP = exports.DESC_COMMAND_SANDBOX_START = exports.DESC_COMMAND_SANDBOX_DESTROY = exports.DESC_COMMAND_SANDBOX_GET = void 0;
|
|
12
12
|
exports.TXT_SANDBOX_EXEC_BACKGROUND = exports.TXT_SANDBOX_EXEC_ID = exports.ERR_SANDBOX_CP_INVALID_SOURCE = exports.ERR_SANDBOX_CP_INVALID_DEST = exports.ERR_SANDBOX_CP_REPLACE = exports.ERR_SANDBOX_CP_MKDIR = exports.ERR_SANDBOX_CP_PATH_EXISTS = exports.ERR_SANDBOX_CP_NOT_EMPTY_DIR = exports.ERR_SANDBOX_CP_READDIR = exports.ERR_SANDBOX_CP_DEST_NOT_FOLDER = exports.ERR_SANDBOX_CP_SOURCE_NOT_FOUND = exports.TXT_SANDBOX_CP_DONE = exports.TXT_SANDBOX_CP_PROGRESS = exports.TXT_SANDBOX_UNZIPPING_COUNT = exports.TXT_SANDBOX_UNZIP_DONE = exports.TXT_SANDBOX_UNZIP = exports.TXT_SANDBOX_CP_DOWNLOAD_DONE = exports.TXT_SANDBOX_CP_DOWNLOAD = exports.OPTION_SANDBOX_CP_DOWNLOAD_REPLACE = exports.OPTION_SANDBOX_CP_DOWNLOAD_MERGE = exports.OPTION_SANDBOX_CP_DEST = exports.OPTION_SANDBOX_CP_SOURCE = exports.DESC_COMMAND_SANDBOX_CP = exports.ERR_SANDBOX_ENDPOINTS_NOT_FOUND = exports.ERR_SANDBOX_ENDPOINT_NOT_FOUND = exports.ERR_SANDBOX_ENDPOINT_EXISTS = exports.TXT_SANDBOX_ENDPOINT_DELETED = exports.TXT_SANDBOX_ENDPOINT_DELETE_CONFIRM = exports.TXT_SANDBOX_ENDPOINT_ADDED = exports.OPTION_SANDBOX_ENDPOINT_TYPE = exports.OPTION_SANDBOX_ENDPOINT_PORT = exports.OPTION_SANDBOX_ENDPOINT_NAME_ARG = exports.OPTION_SANDBOX_ENDPOINT_NAME = exports.DESC_COMMAND_SANDBOX_ENDPOINT_DELETE = exports.DESC_COMMAND_SANDBOX_ENDPOINT_ADD = exports.DESC_COMMAND_SANDBOX_ENDPOINT_GET = exports.DESC_COMMAND_SANDBOX_ENDPOINT_LIST = exports.DESC_COMMAND_SANDBOX_ENDPOINT = exports.ERR_SANDBOX_SNAPSHOTS_NOT_FOUND = exports.ERR_SANDBOX_SNAPSHOT_NOT_FOUND = exports.ERR_SANDBOX_SNAPSHOT_FAILED = exports.TXT_SANDBOX_SNAPSHOT_WAITING = exports.TXT_SANDBOX_SNAPSHOT_DELETE_CONFIRM = exports.TXT_SANDBOX_SNAPSHOT_DELETED = exports.TXT_SANDBOX_SNAPSHOT_CREATED = exports.OPTION_SANDBOX_FROM_SNAPSHOT = exports.OPTION_SANDBOX_SNAPSHOT_NAME_ARG = exports.OPTION_SANDBOX_SNAPSHOT_NAME = exports.DESC_COMMAND_SANDBOX_SNAPSHOT_DELETE = exports.DESC_COMMAND_SANDBOX_SNAPSHOT_GET = void 0;
|
|
13
|
-
exports.
|
|
14
|
-
exports.EXAMPLE_PACKAGE_VERSION_DELETE = exports.EXAMPLE_PACKAGE_VERSION_GET = exports.EXAMPLE_PACKAGE_VERSION_LIST = exports.EXAMPLE_PACKAGE_CREATE = exports.EXAMPLE_PACKAGE_DELETE = exports.EXAMPLE_PACKAGE_DOWNLOAD = exports.EXAMPLE_PACKAGE_PUBLISH = exports.EXAMPLE_PIPELINE_RUN = exports.EXAMPLE_SANDBOX_ENDPOINT_LIST = exports.EXAMPLE_SANDBOX_ENDPOINT_GET = exports.EXAMPLE_SANDBOX_ENDPOINT_DELETE = exports.EXAMPLE_SANDBOX_ENDPOINT_CREATE = exports.EXAMPLE_SANDBOX_SNAPSHOT_LIST = exports.EXAMPLE_SANDBOX_SNAPSHOT_GET = exports.EXAMPLE_SANDBOX_SNAPSHOT_DELETE = exports.EXAMPLE_SANDBOX_SNAPSHOT_CREATE = exports.EXAMPLE_SANDBOX_EXEC_STATUS = exports.EXAMPLE_SANDBOX_EXEC_LOGS = exports.EXAMPLE_SANDBOX_EXEC_LIST = exports.EXAMPLE_SANDBOX_EXEC_KILL = exports.EXAMPLE_SANDBOX_EXEC_COMMAND = exports.EXAMPLE_SANDBOX_CREATE = exports.EXAMPLE_SANDBOX_CP = exports.TXT_PROJECT_NONE = exports.ERR_PROJECT_NO_PROJECTS = exports.TXT_LOGIN_SELECT_PROJECT = exports.TXT_PROJECT_SET_CLEARED = exports.TXT_PROJECT_SET_SUCCESS = exports.DESC_COMMAND_PROJECT_GET = exports.ARG_COMMAND_PROJECT_NAME = exports.DESC_COMMAND_PROJECT_SET = exports.DESC_COMMAND_PROJECT_LIST = exports.DESC_COMMAND_PROJECT = exports.TXT_PACKAGE_VERSION_DOWNLOAD = exports.TXT_PACKAGE_PUBLISH = exports.TXT_PACKAGE_CREATED = exports.TXT_PACKAGE_VERSION_DELETED = exports.TXT_PACKAGE_DELETED = void 0;
|
|
13
|
+
exports.DESC_COMMAND_PACKAGE_DELETE = exports.ERR_COMMAND_PACKAGE_NO_PROJECTS = exports.DESC_COMMAND_PACKAGE_VERSION_GET = exports.DESC_COMMAND_PACKAGE_VERSION_LIST = exports.DESC_COMMAND_PACKAGE_VERSION_DELETE = exports.DESC_COMMAND_PACKAGE_DOCKER_LOGIN = exports.DESC_COMMAND_PACKAGE_LIST = exports.DESC_COMMAND_PACKAGE_VERSION = exports.ERR_API_MESSAGE_REPLACER = exports.ERR_LOGIN_INVALID_BASE_URL = exports.ERR_LOGIN_NO_PROJECT_FOUND = exports.ERR_LOGIN_NO_WORKSPACE_FOUND = exports.ERR_LOGIN_NO_WORKSPACES = exports.ERR_LOGIN_HTTP_SUCCESS = exports.ERR_LOGIN_HTTP_FAILED = exports.TXT_LOGIN_OAUTH = exports.ERR_LOGIN_HTTP_SERVER_PORT_TAKEN = exports.TXT_LOGIN_SUCCESS = exports.TXT_LOGIN_SELECT_WORKSPACE = exports.TXT_LOGIN_ENTER_BASE_URL = exports.TXT_LOGIN_SELECT_REGION = exports.TXT_WORKSPACE_NONE = exports.TXT_WORKSPACE_SET_SUCCESS = exports.ARG_COMMAND_WORKSPACE = exports.DESC_COMMAND_WORKSPACE_GET = exports.DESC_COMMAND_WORKSPACE_SET = exports.DESC_COMMAND_WORKSPACE_LIST = exports.DESC_COMMAND_WORKSPACE = exports.TXT_LOGOUT_SUCCESS = exports.DESC_COMMAND_LOGOUT = exports.DESC_COMMAND_LOGIN = exports.ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED = exports.TXT_API_ENDPOINT_REQUIRED_SCOPES = exports.ERR_API_ENDPOINT_NOT_FOUND = exports.ERR_API_WRONG_METHOD = exports.ERR_SCHEMA_FETCH_FAILED = exports.OPT_COMMAND_API_INFO_URL = exports.OPT_COMMAND_API_INFO_METHOD = exports.OPT_COMMAND_API_LIST_SEARCH = exports.OPT_COMMAND_API_LIST_METHOD = exports.DESC_COMMAND_API_INFO = exports.DESC_COMMAND_API_LIST = exports.DESC_COMMAND_API = exports.ERR_WHOAMI_LOGOUT = exports.TXT_WHOAMI_NO_PROJECT = exports.TXT_WHOAMI_NO_WORKSPACE = exports.DESC_COMMAND_WHOAMI = exports.TXT_SANDBOX_EXEC_FAILED = exports.TXT_SANDBOX_EXEC_INPROGRESS = exports.TXT_SANDBOX_EXEC_SUCCESS = void 0;
|
|
14
|
+
exports.EXAMPLE_PACKAGE_VERSION_DELETE = exports.EXAMPLE_PACKAGE_VERSION_GET = exports.EXAMPLE_PACKAGE_VERSION_LIST = exports.EXAMPLE_PACKAGE_CREATE = exports.EXAMPLE_PACKAGE_DELETE = exports.EXAMPLE_PACKAGE_DOWNLOAD = exports.EXAMPLE_PACKAGE_PUBLISH = exports.EXAMPLE_PIPELINE_RUN = exports.EXAMPLE_SANDBOX_ENDPOINT_LIST = exports.EXAMPLE_SANDBOX_ENDPOINT_GET = exports.EXAMPLE_SANDBOX_ENDPOINT_DELETE = exports.EXAMPLE_SANDBOX_ENDPOINT_CREATE = exports.EXAMPLE_SANDBOX_SNAPSHOT_LIST = exports.EXAMPLE_SANDBOX_SNAPSHOT_GET = exports.EXAMPLE_SANDBOX_SNAPSHOT_DELETE = exports.EXAMPLE_SANDBOX_SNAPSHOT_CREATE = exports.EXAMPLE_SANDBOX_EXEC_STATUS = exports.EXAMPLE_SANDBOX_EXEC_LOGS = exports.EXAMPLE_SANDBOX_EXEC_LIST = exports.EXAMPLE_SANDBOX_EXEC_KILL = exports.EXAMPLE_SANDBOX_EXEC_COMMAND = exports.EXAMPLE_SANDBOX_CREATE = exports.EXAMPLE_SANDBOX_CP = exports.TXT_PROJECT_NONE = exports.ERR_PROJECT_NO_PROJECTS = exports.TXT_LOGIN_SELECT_PROJECT = exports.TXT_PROJECT_SET_CLEARED = exports.TXT_PROJECT_SET_SUCCESS = exports.DESC_COMMAND_PROJECT_GET = exports.ARG_COMMAND_PROJECT_NAME = exports.DESC_COMMAND_PROJECT_SET = exports.DESC_COMMAND_PROJECT_LIST = exports.DESC_COMMAND_PROJECT = exports.TXT_PACKAGE_VERSION_DOWNLOAD = exports.TXT_PACKAGE_PUBLISH = exports.TXT_PACKAGE_CREATED = exports.TXT_PACKAGE_VERSION_DELETED = exports.TXT_PACKAGE_DELETED = exports.ERR_COMMAND_PACKAGE_TYPE = exports.OPT_COMMAND_PACKAGE_VERSION = exports.OPT_COMMAND_PACKAGE_IDENTIFIER = exports.OPT_COMMAND_PACKAGE_CREATE_IDENTIFIER = exports.OPT_COMMAND_PACKAGE_NAME = exports.OPT_COMMAND_PACKAGE_TYPE = exports.DESC_COMMAND_PACKAGE_CREATE = exports.DESC_COMMAND_PACKAGE_GET = exports.TXT_PACKAGE_DOCKER_LOGIN_FAILED = exports.TXT_PACKAGE_DOCKER_LOGIN_SUCCESS = exports.TXT_PACKAGE_VERSION_DELETE_CONFIRM = exports.TXT_PACKAGE_DELETE_CONFIRM = void 0;
|
|
15
15
|
const utils_1 = require("./utils");
|
|
16
16
|
exports.ERR_REST_API_GENERAL_ERROR = 'Something went wrong';
|
|
17
17
|
exports.ERR_REST_API_NOT_RESPONDING = 'Api endpoint not responding. Try again later...';
|
|
@@ -650,6 +650,20 @@ exports.DESC_COMMAND_WHOAMI = 'Check login information';
|
|
|
650
650
|
exports.TXT_WHOAMI_NO_WORKSPACE = 'Not set. Run `bdy ws set` to set a workspace';
|
|
651
651
|
exports.TXT_WHOAMI_NO_PROJECT = 'Not set. Run `bdy proj set` to set a project';
|
|
652
652
|
exports.ERR_WHOAMI_LOGOUT = 'Not logged in. Run `bdy login` to authenticate.';
|
|
653
|
+
// api command
|
|
654
|
+
exports.DESC_COMMAND_API = 'Contact Buddy API directly';
|
|
655
|
+
exports.DESC_COMMAND_API_LIST = 'List Buddy API endpoints';
|
|
656
|
+
exports.DESC_COMMAND_API_INFO = 'Show info about API endpoint';
|
|
657
|
+
exports.OPT_COMMAND_API_LIST_METHOD = 'Filter endpoints by method (all, get, post, put, patch, delete). Default: all';
|
|
658
|
+
exports.OPT_COMMAND_API_LIST_SEARCH = 'Filter endpoints by phrase';
|
|
659
|
+
exports.OPT_COMMAND_API_INFO_METHOD = 'Endpoint method (get, post, put, patch, delete)';
|
|
660
|
+
exports.OPT_COMMAND_API_INFO_URL = 'Endpoint url';
|
|
661
|
+
exports.ERR_SCHEMA_FETCH_FAILED = 'Failed to fetch api schema';
|
|
662
|
+
exports.ERR_API_WRONG_METHOD = 'Wrong method value';
|
|
663
|
+
exports.ERR_API_ENDPOINT_NOT_FOUND = 'Endpoint not found';
|
|
664
|
+
exports.TXT_API_ENDPOINT_REQUIRED_SCOPES = 'Required scopes';
|
|
665
|
+
const ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED = (type) => `Media type not implemented (${type})`;
|
|
666
|
+
exports.ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED = ERR_API_MEDIA_TYPE_NOT_IMPLEMENTED;
|
|
653
667
|
// Login command
|
|
654
668
|
exports.DESC_COMMAND_LOGIN = 'Log in to Buddy';
|
|
655
669
|
exports.DESC_COMMAND_LOGOUT = 'Log out from Buddy';
|
package/distTs/src/utils.js
CHANGED
|
@@ -36,8 +36,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.getLatestVersion = exports.getVersionEnv = exports.getCurrentVersionWithoutEnv = exports.getVersionWithoutEnv = exports.getVersion = exports.isInstalledByChoco = exports.isInstalledByApt = exports.isInstalledByBrew = exports.isInstalledByNpm = exports.execLocally = exports.getHomeDirectory = exports.newCommand = exports.formatBytes = exports.formatHelp = exports.getPlatform = exports.getHostname = exports.isStringRegExp = exports.getRootDir = exports.TARGET_ONLY_PORT_REGEX = exports.TARGET_HTTP_REGEX = exports.TARGET_TCP_TLS_REGEX = exports.ApiErrorTunnelsDisabled = exports.ApiErrorWorkspaceFlagged = exports.ApiErrorTunnelLimitReached = exports.ApiErrorAgentLimitReached = exports.ApiErrorDomainRestricted = exports.ApiErrorTargetInvalid = exports.ApiErrorWrongToken = exports.ApiErrorFailedToConnect = exports.ApiErrorAgentNotFound = exports.PACKAGE_AUTH_TYPE = exports.PACKAGE_SCOPE = exports.PACKAGE_TYPE = exports.
|
|
40
|
-
exports.getBasicCommandTls = exports.getBasicCommandHttp = exports.getBasicCommandSandboxEndpoint = exports.getBasicCommandTcp = exports.createSshHostKey = exports.getRealTargetHost = exports.isWindows = exports.isLinux = exports.isOsx = exports.isDocker =
|
|
39
|
+
exports.sleep = exports.getLatestVersion = exports.getVersionEnv = exports.getCurrentVersionWithoutEnv = exports.getVersionWithoutEnv = exports.getVersion = exports.isInstalledByChoco = exports.isInstalledByApt = exports.isInstalledByBrew = exports.isInstalledByNpm = exports.execLocally = exports.getHomeDirectory = exports.newCommand = exports.formatBytes = exports.formatHelp = exports.getPlatform = exports.getHostname = exports.isStringRegExp = exports.getRootDir = exports.TARGET_ONLY_PORT_REGEX = exports.TARGET_HTTP_REGEX = exports.TARGET_TCP_TLS_REGEX = exports.ApiErrorTunnelsDisabled = exports.ApiErrorWorkspaceFlagged = exports.ApiErrorTunnelLimitReached = exports.ApiErrorAgentLimitReached = exports.ApiErrorDomainRestricted = exports.ApiErrorTargetInvalid = exports.ApiErrorWrongToken = exports.ApiErrorFailedToConnect = exports.ApiErrorAgentNotFound = exports.PACKAGE_AUTH_TYPE = exports.PACKAGE_SCOPE = exports.PACKAGE_TYPE = exports.SANDBOX_SNAPSHOT_STATUS = exports.SANDBOX_SETUP_STATUS = exports.SANDBOX_EXEC_STATUS = exports.SANDBOX_EXEC_RUNTIME = exports.SANDBOX_STATUS = exports.REST_API_ENDPOINT = exports.REST_API_REGION = exports.SUGGESTED_BROWSER_VERSION = exports.DEFAULT_TIMEOUT = exports.TUNNEL_HTTP_CB_MIN_REQUESTS = exports.TUNNEL_HTTP_CB_WINDOW = exports.TUNNEL_MAX_REQUEST_SIZE_TO_SYNC = exports.TUNNEL_HTTP_LOG_MAX_REQUESTS = exports.TUNNEL_HTTP_LOG_MAX_BODY = exports.TUNNEL_HTTP_RATE_WINDOW = exports.TUNNEL_HTTP_RATE_LIMIT = void 0;
|
|
40
|
+
exports.getBasicCommandTls = exports.getBasicCommandHttp = exports.getBasicCommandSandboxEndpoint = exports.getBasicCommandTcp = exports.createSshHostKey = exports.getRealTargetHost = exports.isWindows = exports.isLinux = exports.isOsx = exports.isDocker = void 0;
|
|
41
41
|
exports.apiErrorCodeToClass = apiErrorCodeToClass;
|
|
42
42
|
exports.isFile = isFile;
|
|
43
43
|
exports.getAppWorkspaceUrl = getAppWorkspaceUrl;
|
|
@@ -46,6 +46,9 @@ exports.getAppUrl = getAppUrl;
|
|
|
46
46
|
exports.untarGz = untarGz;
|
|
47
47
|
exports.unzipFile = unzipFile;
|
|
48
48
|
exports.getDockerRegistryHostByApiBaseUrl = getDockerRegistryHostByApiBaseUrl;
|
|
49
|
+
exports.fetchOpenApiSchema = fetchOpenApiSchema;
|
|
50
|
+
exports.openApiPrepareUrl = openApiPrepareUrl;
|
|
51
|
+
exports.getOpenApiEndpointByApiBaseUrl = getOpenApiEndpointByApiBaseUrl;
|
|
49
52
|
exports.getAppHostByApiBaseUrl = getAppHostByApiBaseUrl;
|
|
50
53
|
const node_path_1 = __importDefault(require("node:path"));
|
|
51
54
|
const node_fs_1 = __importStar(require("node:fs"));
|
|
@@ -57,6 +60,9 @@ const node_os_1 = __importStar(require("node:os"));
|
|
|
57
60
|
const node_child_process_1 = require("node:child_process");
|
|
58
61
|
const fflate_1 = require("fflate");
|
|
59
62
|
const tar_stream_1 = __importDefault(require("tar-stream"));
|
|
63
|
+
const bundle_1 = require("@scalar/json-magic/bundle");
|
|
64
|
+
const node_1 = require("@scalar/json-magic/bundle/plugins/node");
|
|
65
|
+
const openapi_parser_1 = require("@scalar/openapi-parser");
|
|
60
66
|
exports.TUNNEL_HTTP_RATE_LIMIT = 2000;
|
|
61
67
|
exports.TUNNEL_HTTP_RATE_WINDOW = 60000;
|
|
62
68
|
exports.TUNNEL_HTTP_LOG_MAX_BODY = 5242880; // 5MB
|
|
@@ -114,13 +120,6 @@ var SANDBOX_SNAPSHOT_STATUS;
|
|
|
114
120
|
SANDBOX_SNAPSHOT_STATUS["DELETING"] = "DELETING";
|
|
115
121
|
SANDBOX_SNAPSHOT_STATUS["FAILED"] = "FAILED";
|
|
116
122
|
})(SANDBOX_SNAPSHOT_STATUS || (exports.SANDBOX_SNAPSHOT_STATUS = SANDBOX_SNAPSHOT_STATUS = {}));
|
|
117
|
-
var SANDBOX_APP_STATUS;
|
|
118
|
-
(function (SANDBOX_APP_STATUS) {
|
|
119
|
-
SANDBOX_APP_STATUS["NONE"] = "NONE";
|
|
120
|
-
SANDBOX_APP_STATUS["ENDED"] = "ENDED";
|
|
121
|
-
SANDBOX_APP_STATUS["RUNNING"] = "RUNNING";
|
|
122
|
-
SANDBOX_APP_STATUS["FAILED"] = "FAILED";
|
|
123
|
-
})(SANDBOX_APP_STATUS || (exports.SANDBOX_APP_STATUS = SANDBOX_APP_STATUS = {}));
|
|
124
123
|
var PACKAGE_TYPE;
|
|
125
124
|
(function (PACKAGE_TYPE) {
|
|
126
125
|
PACKAGE_TYPE["FILE"] = "FILE";
|
|
@@ -915,6 +914,46 @@ function getDockerRegistryHostByApiBaseUrl(baseUrl) {
|
|
|
915
914
|
return baseUrl.hostname;
|
|
916
915
|
}
|
|
917
916
|
}
|
|
917
|
+
async function fetchOpenApiSchema(baseUrl) {
|
|
918
|
+
try {
|
|
919
|
+
const url = getOpenApiEndpointByApiBaseUrl(baseUrl);
|
|
920
|
+
const data = await (0, bundle_1.bundle)(url, {
|
|
921
|
+
plugins: [(0, node_1.readFiles)(), (0, node_1.fetchUrls)(), (0, node_1.parseYaml)(), (0, node_1.parseJson)()],
|
|
922
|
+
treeShake: true,
|
|
923
|
+
});
|
|
924
|
+
const { schema } = await (0, openapi_parser_1.dereference)(data);
|
|
925
|
+
if (schema)
|
|
926
|
+
return schema;
|
|
927
|
+
}
|
|
928
|
+
catch {
|
|
929
|
+
// do nothing
|
|
930
|
+
}
|
|
931
|
+
throw new Error(texts_1.ERR_SCHEMA_FETCH_FAILED);
|
|
932
|
+
}
|
|
933
|
+
function openApiPrepareUrl(url, workspace, project) {
|
|
934
|
+
let preparedUrl = url.replaceAll('{workspace_domain}', workspace);
|
|
935
|
+
if (project)
|
|
936
|
+
preparedUrl = preparedUrl.replaceAll('{project_name}', project);
|
|
937
|
+
return preparedUrl;
|
|
938
|
+
}
|
|
939
|
+
function getOpenApiEndpointByApiBaseUrl(baseUrl) {
|
|
940
|
+
if (baseUrl.hostname.includes('api.buddy.works') ||
|
|
941
|
+
baseUrl.hostname.includes('api.eu.buddy.works') ||
|
|
942
|
+
baseUrl.hostname.includes('api.as.buddy.works')) {
|
|
943
|
+
return 'https://es.buddy.works/openapi/production/restapi.json';
|
|
944
|
+
}
|
|
945
|
+
else if (baseUrl.hostname.includes('api.awsstage.net') ||
|
|
946
|
+
baseUrl.hostname.includes('api.eu.awsstage.net') ||
|
|
947
|
+
baseUrl.hostname.includes('api.buddy.mom')) {
|
|
948
|
+
return 'https://es.buddy.works/openapi/stage/restapi.json';
|
|
949
|
+
}
|
|
950
|
+
else if (baseUrl.hostname.includes('api.awsmaster.net')) {
|
|
951
|
+
return 'https://es.buddy.works/openapi/master/restapi.json';
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
return 'https://es.buddy.works/openapi/dev/restapi.json';
|
|
955
|
+
}
|
|
956
|
+
}
|
|
918
957
|
function getAppHostByApiBaseUrl(baseUrl) {
|
|
919
958
|
if (baseUrl.hostname.includes('api.buddy.works')) {
|
|
920
959
|
return 'app.buddy.works';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.33-dev",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"cookie": "1.0.2",
|
|
30
30
|
"cross-spawn": "7.0.6",
|
|
31
31
|
"eventsource": "4.0.0",
|
|
32
|
+
"@scalar/openapi-parser": "0.24.5",
|
|
33
|
+
"@scalar/json-magic": "0.9.4",
|
|
34
|
+
"@scalar/types": "0.5.10",
|
|
35
|
+
"@scalar/openapi-types": "0.5.3",
|
|
32
36
|
"fastify": "4.28.1",
|
|
33
37
|
"fdir": "6.5.0",
|
|
34
38
|
"open": "11.0.0",
|