@ones-open/cli 1.0.1-27659.1892 → 1.0.1-27971.1958
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/dist/index.cjs +898 -557
- package/dist/index.js +901 -560
- package/dist/types/actions/build/index.d.ts.map +1 -1
- package/dist/types/actions/dev/index.d.ts.map +1 -1
- package/dist/types/actions/dev/normalize.d.ts.map +1 -1
- package/dist/types/actions/dev/types.d.ts +10 -0
- package/dist/types/actions/dev/types.d.ts.map +1 -0
- package/dist/types/actions/disable/index.d.ts.map +1 -1
- package/dist/types/actions/enable/index.d.ts.map +1 -1
- package/dist/types/actions/install/index.d.ts +1 -1
- package/dist/types/actions/install/index.d.ts.map +1 -1
- package/dist/types/actions/install/install.d.ts +2 -2
- package/dist/types/actions/install/install.d.ts.map +1 -1
- package/dist/types/actions/tunnel/consts.d.ts +3 -0
- package/dist/types/actions/tunnel/consts.d.ts.map +1 -1
- package/dist/types/actions/tunnel/index.d.ts +3 -1
- package/dist/types/actions/tunnel/index.d.ts.map +1 -1
- package/dist/types/actions/tunnel/tunnel-client.d.ts +9 -4
- package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -1
- package/dist/types/actions/tunnel/tunnel.d.ts +2 -3
- package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
- package/dist/types/actions/tunnel/types.d.ts +33 -0
- package/dist/types/actions/tunnel/types.d.ts.map +1 -0
- package/dist/types/actions/tunnel/utils.d.ts +7 -0
- package/dist/types/actions/tunnel/utils.d.ts.map +1 -0
- package/dist/types/actions/uninstall/index.d.ts.map +1 -1
- package/dist/types/actions/whoami/index.d.ts.map +1 -1
- package/dist/types/cli/index.d.ts.map +1 -1
- package/dist/types/command/dev/index.d.ts +1 -0
- package/dist/types/command/dev/index.d.ts.map +1 -1
- package/dist/types/common/config/types.d.ts +2 -1
- package/dist/types/common/config/types.d.ts.map +1 -1
- package/dist/types/common/config/utils.d.ts.map +1 -1
- package/dist/types/common/error/enums.d.ts +13 -11
- package/dist/types/common/error/enums.d.ts.map +1 -1
- package/dist/types/common/locales/en/index.d.ts +30 -28
- package/dist/types/common/locales/en/index.d.ts.map +1 -1
- package/dist/types/common/package/utils.d.ts +2 -0
- package/dist/types/common/package/utils.d.ts.map +1 -1
- package/dist/types/common/request/consts.d.ts +2 -0
- package/dist/types/common/request/consts.d.ts.map +1 -1
- package/dist/types/common/request/fetch.d.ts +3 -1
- package/dist/types/common/request/fetch.d.ts.map +1 -1
- package/dist/types/common/request/types.d.ts +27 -5
- package/dist/types/common/request/types.d.ts.map +1 -1
- package/dist/types/common/request/utils.d.ts +3 -2
- package/dist/types/common/request/utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/types/actions/tunnel/hosted-token.d.ts +0 -5
- package/dist/types/actions/tunnel/hosted-token.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -6,53 +6,54 @@ const createOnesApp = require("create-ones-app");
|
|
|
6
6
|
const node_path = require("node:path");
|
|
7
7
|
const node_child_process = require("node:child_process");
|
|
8
8
|
const node_fs = require("node:fs");
|
|
9
|
+
const fse = require("fs-extra");
|
|
9
10
|
const archiver = require("archiver");
|
|
10
11
|
const lodashEs = require("lodash-es");
|
|
11
12
|
const process$1 = require("node:process");
|
|
12
13
|
const node_url = require("node:url");
|
|
13
14
|
const cosmiconfig = require("cosmiconfig");
|
|
14
|
-
const
|
|
15
|
+
const getPort = require("get-port");
|
|
15
16
|
const envPaths = require("env-paths");
|
|
16
17
|
const zod = require("zod");
|
|
17
|
-
const _defineProperty = require("@babel/runtime-corejs3/helpers/defineProperty");
|
|
18
|
-
const WebSocket = require("ws");
|
|
19
18
|
const axios = require("axios");
|
|
20
19
|
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
20
|
+
const WebSocket = require("ws");
|
|
21
21
|
const http = require("node:http");
|
|
22
22
|
const ora = require("ora");
|
|
23
23
|
const open = require("open");
|
|
24
|
-
const getPort = require("get-port");
|
|
25
24
|
const uuid = require("uuid");
|
|
26
25
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
27
26
|
const en = {
|
|
28
|
-
"desc.ones": "
|
|
29
|
-
"desc.build": "
|
|
30
|
-
"desc.build.output": "
|
|
31
|
-
"desc.dev": "
|
|
32
|
-
"desc.dev.install": "
|
|
33
|
-
"desc.
|
|
34
|
-
"desc.tunnel
|
|
35
|
-
"desc.
|
|
36
|
-
"desc.login
|
|
37
|
-
"desc.
|
|
38
|
-
"desc.
|
|
39
|
-
"desc.
|
|
40
|
-
"desc.
|
|
41
|
-
"desc.
|
|
42
|
-
"desc.
|
|
43
|
-
"desc.
|
|
44
|
-
"desc.
|
|
45
|
-
"
|
|
46
|
-
"error.login.
|
|
47
|
-
"error.
|
|
48
|
-
"error.tunnel.
|
|
49
|
-
"error.
|
|
50
|
-
"error.schema.app.
|
|
51
|
-
"error.
|
|
52
|
-
"error.
|
|
53
|
-
"error.
|
|
54
|
-
"error.
|
|
55
|
-
"error.
|
|
27
|
+
"desc.ones": "ONES CLI/{env}",
|
|
28
|
+
"desc.build": "Build your ONES App",
|
|
29
|
+
"desc.build.output": "Specify the output file path",
|
|
30
|
+
"desc.dev": "Start your local development server and connect to ONES",
|
|
31
|
+
"desc.dev.install": "Install your ONES App after the server is ready",
|
|
32
|
+
"desc.dev.command": "Specify the dev command",
|
|
33
|
+
"desc.tunnel": "Start a tunnel to connect your local server with ONES",
|
|
34
|
+
"desc.tunnel.port": "Specify the port number for tunnel",
|
|
35
|
+
"desc.login": "Log in to your ONES account",
|
|
36
|
+
"desc.login.baseUrl": "Specify the ONES URL for login",
|
|
37
|
+
"desc.logout": "Log out of your ONES account",
|
|
38
|
+
"desc.whoami": "Display the account information of the logged in user",
|
|
39
|
+
"desc.app": "Manage app installations",
|
|
40
|
+
"desc.install": "Install your ONES App",
|
|
41
|
+
"desc.enable": "Enable your ONES App",
|
|
42
|
+
"desc.disable": "Disable your ONES App",
|
|
43
|
+
"desc.uninstall": "Uninstall your ONES App",
|
|
44
|
+
"desc.legacy": "Legacy command",
|
|
45
|
+
"error.login.missingBaseURL": "Missing base URL",
|
|
46
|
+
"error.login.incorrectBaseURL": "Incorrect base URL",
|
|
47
|
+
"error.tunnel.missingPort": "Missing port",
|
|
48
|
+
"error.tunnel.incorrectPort": "Incorrect port",
|
|
49
|
+
"error.schema.app.package.parseError": "App package JSON parse error",
|
|
50
|
+
"error.schema.app.manifest.parseError": 'App "opkx.json" JSON parse error',
|
|
51
|
+
"error.build.scriptNotFound": 'Npm "build" script not found',
|
|
52
|
+
"error.dev.scriptNotFound": 'Npm "dev" script not found',
|
|
53
|
+
"error.dev.incorrectCommand": "Incorrect dev command",
|
|
54
|
+
"error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
|
|
55
|
+
"error.hostedToken.requestFailed": "Failed to request hosted token",
|
|
56
|
+
"error.hostedToken.empty": "Hosted token is empty"
|
|
56
57
|
};
|
|
57
58
|
const map = {
|
|
58
59
|
en
|
|
@@ -85,17 +86,19 @@ var ErrorCode = ((ErrorCode2) => {
|
|
|
85
86
|
ErrorCode2[ErrorCode2["UNKNOWN_ERROR"] = createOnesApp.ErrorCode.UNKNOWN_ERROR] = "UNKNOWN_ERROR";
|
|
86
87
|
ErrorCode2[ErrorCode2["COMMAND_ERROR"] = createOnesApp.ErrorCode.COMMAND_ERROR] = "COMMAND_ERROR";
|
|
87
88
|
ErrorCode2[ErrorCode2["TEMPLATE_NOT_FOUND"] = createOnesApp.ErrorCode.TEMPLATE_NOT_FOUND] = "TEMPLATE_NOT_FOUND";
|
|
88
|
-
ErrorCode2["
|
|
89
|
-
ErrorCode2["
|
|
90
|
-
ErrorCode2["
|
|
91
|
-
ErrorCode2["
|
|
92
|
-
ErrorCode2["
|
|
93
|
-
ErrorCode2["
|
|
94
|
-
ErrorCode2["
|
|
95
|
-
ErrorCode2["
|
|
96
|
-
ErrorCode2["
|
|
97
|
-
ErrorCode2["
|
|
98
|
-
ErrorCode2["
|
|
89
|
+
ErrorCode2[ErrorCode2["MISSING_PROJECT_PATH"] = createOnesApp.ErrorCode.MISSING_PROJECT_PATH] = "MISSING_PROJECT_PATH";
|
|
90
|
+
ErrorCode2["MISSING_BASE_URL"] = "E04";
|
|
91
|
+
ErrorCode2["MISSING_PORT"] = "E05";
|
|
92
|
+
ErrorCode2["INCORRECT_BASE_URL"] = "E06";
|
|
93
|
+
ErrorCode2["INCORRECT_PORT"] = "E07";
|
|
94
|
+
ErrorCode2["APP_PACKAGE_JSON_PARSE_ERROR"] = "E08";
|
|
95
|
+
ErrorCode2["APP_MANIFEST_JSON_PARSE_ERROR"] = "E09";
|
|
96
|
+
ErrorCode2["BUILD_SCRIPT_NOT_FOUND"] = "E10";
|
|
97
|
+
ErrorCode2["DEV_SCRIPT_NOT_FOUND"] = "E11";
|
|
98
|
+
ErrorCode2["STORE_PERMISSION"] = "E12";
|
|
99
|
+
ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
|
|
100
|
+
ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
|
|
101
|
+
ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
|
|
99
102
|
return ErrorCode2;
|
|
100
103
|
})(ErrorCode || {});
|
|
101
104
|
const getPublicPath = () => {
|
|
@@ -132,8 +135,8 @@ const getAppPackageJSON = () => {
|
|
|
132
135
|
const json = JSON.parse(string);
|
|
133
136
|
return createOnesApp.AppPackageJSONSchema.parse(json);
|
|
134
137
|
} catch (error) {
|
|
135
|
-
|
|
136
|
-
return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, i18n.t("error.schema.app.package.parseError"));
|
|
138
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
139
|
+
return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.package.parseError")}: ${details}`);
|
|
137
140
|
}
|
|
138
141
|
};
|
|
139
142
|
const getAppManifestJSONPath = () => {
|
|
@@ -148,13 +151,14 @@ const getAppManifestJSON = () => {
|
|
|
148
151
|
const json = JSON.parse(string);
|
|
149
152
|
return createOnesApp.AppManifestJSONSchema.parse(json);
|
|
150
153
|
} catch (error) {
|
|
151
|
-
|
|
152
|
-
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, i18n.t("error.schema.app.manifest.parseError"));
|
|
154
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
155
|
+
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
153
156
|
}
|
|
154
157
|
};
|
|
158
|
+
const defaultDevCommand = ["npm", "run", "dev"];
|
|
155
159
|
const defaultAppRcJSON = {
|
|
156
160
|
dev: {
|
|
157
|
-
command:
|
|
161
|
+
command: defaultDevCommand
|
|
158
162
|
}
|
|
159
163
|
};
|
|
160
164
|
let storeAppRcJSON = null;
|
|
@@ -205,8 +209,12 @@ const normalize$a = async (options) => {
|
|
|
205
209
|
output
|
|
206
210
|
};
|
|
207
211
|
};
|
|
212
|
+
const {
|
|
213
|
+
existsSync,
|
|
214
|
+
ensureDirSync
|
|
215
|
+
} = fse;
|
|
208
216
|
const build = async function() {
|
|
209
|
-
var
|
|
217
|
+
var _appRcJSON$build$comp, _appRcJSON$build;
|
|
210
218
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
211
219
|
args[_key] = arguments[_key];
|
|
212
220
|
}
|
|
@@ -214,18 +222,37 @@ const build = async function() {
|
|
|
214
222
|
options
|
|
215
223
|
} = createOnesApp.getCommandOptions(args, buildCommandArguments);
|
|
216
224
|
const normalizedOptions = await normalize$a(options);
|
|
217
|
-
const appPackageJSON = getAppPackageJSON();
|
|
218
225
|
const appManifestJSON = getAppManifestJSON();
|
|
219
226
|
const appRcJSON = await getAppRcJSON();
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
const appPackageJSONPath = getAppPackageJSONPath();
|
|
228
|
+
const isExists = existsSync(appPackageJSONPath);
|
|
229
|
+
if (isExists) {
|
|
230
|
+
var _appPackageJSON$scrip;
|
|
231
|
+
const appPackageJSON = getAppPackageJSON();
|
|
232
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build) {
|
|
233
|
+
const buildResult = node_child_process.spawnSync("npm", ["run", "build"], {
|
|
234
|
+
cwd: getAppWorkspacePath(),
|
|
235
|
+
stdio: "inherit",
|
|
236
|
+
env: {
|
|
237
|
+
...process.env,
|
|
238
|
+
NODE_ENV: "production"
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
if (buildResult.status !== 0 || buildResult.signal) {
|
|
242
|
+
var _buildResult$status;
|
|
243
|
+
process.exit((_buildResult$status = buildResult.status) !== null && _buildResult$status !== void 0 ? _buildResult$status : 1);
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
|
|
247
|
+
}
|
|
228
248
|
}
|
|
249
|
+
const appName = appManifestJSON.app.name;
|
|
250
|
+
const outputPath = normalizedOptions.output;
|
|
251
|
+
const outputDir = node_path.dirname(outputPath);
|
|
252
|
+
const outputFilename = node_path.basename(outputPath);
|
|
253
|
+
ensureDirSync(outputDir);
|
|
254
|
+
const outputStream = node_fs.createWriteStream(outputPath);
|
|
255
|
+
const files = (_appRcJSON$build$comp = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 || (_appRcJSON$build = _appRcJSON$build.compress) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
|
|
229
256
|
const archive = archiver("zip", {
|
|
230
257
|
zlib: {
|
|
231
258
|
level: 9
|
|
@@ -248,12 +275,13 @@ const build = async function() {
|
|
|
248
275
|
});
|
|
249
276
|
archive.on("finish", () => {
|
|
250
277
|
process.stdout.write("\n");
|
|
251
|
-
console.log(
|
|
252
|
-
console.log(
|
|
278
|
+
console.log("");
|
|
279
|
+
console.log("Files in archive: ", createOnesApp.PUBLIC_FILENAME.MANIFEST, files);
|
|
280
|
+
console.log(`App "${appName}" built successfully!`);
|
|
281
|
+
console.log(`OPKX "${outputFilename}" created successfully!`);
|
|
282
|
+
console.log(`Output file: ${outputPath}`);
|
|
253
283
|
});
|
|
254
|
-
const outputStream = node_fs.createWriteStream(normalizedOptions.output);
|
|
255
284
|
archive.pipe(outputStream);
|
|
256
|
-
const files = (_appRcJSON$build$comp = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 || (_appRcJSON$build = _appRcJSON$build.compress) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
|
|
257
285
|
files.forEach((file) => {
|
|
258
286
|
archive.glob(file, {
|
|
259
287
|
cwd: getAppWorkspacePath()
|
|
@@ -267,113 +295,11 @@ const build = async function() {
|
|
|
267
295
|
const config = {
|
|
268
296
|
defaultPort: {
|
|
269
297
|
login: 8200,
|
|
270
|
-
|
|
298
|
+
hosted: 8201,
|
|
299
|
+
devWebServer: 8202
|
|
271
300
|
}
|
|
272
301
|
};
|
|
273
302
|
const getConfig = () => config;
|
|
274
|
-
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
275
|
-
InstallOptions2["AUTO"] = "auto";
|
|
276
|
-
InstallOptions2["TRUE"] = "true";
|
|
277
|
-
InstallOptions2["FALSE"] = "false";
|
|
278
|
-
return InstallOptions2;
|
|
279
|
-
})(InstallOptions || {});
|
|
280
|
-
const defaultInstall = InstallOptions.AUTO;
|
|
281
|
-
const normalize$9 = async (options) => {
|
|
282
|
-
var _options$install;
|
|
283
|
-
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
284
|
-
switch (true) {
|
|
285
|
-
case install2 === InstallOptions.AUTO:
|
|
286
|
-
break;
|
|
287
|
-
case Boolean(install2):
|
|
288
|
-
install2 = InstallOptions.TRUE;
|
|
289
|
-
break;
|
|
290
|
-
default:
|
|
291
|
-
install2 = InstallOptions.FALSE;
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
return {
|
|
295
|
-
install: install2
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
const dev = async function() {
|
|
299
|
-
var _appPackageJSON$scrip;
|
|
300
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
301
|
-
args[_key] = arguments[_key];
|
|
302
|
-
}
|
|
303
|
-
const {
|
|
304
|
-
options
|
|
305
|
-
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
306
|
-
const normalizedOptions = await normalize$9(options);
|
|
307
|
-
const appPackageJSON = getAppPackageJSON();
|
|
308
|
-
const appManifestJSON = getAppManifestJSON();
|
|
309
|
-
const appRcJSON = getAppRcJSON();
|
|
310
|
-
lodashEs.noop(appManifestJSON);
|
|
311
|
-
lodashEs.noop(appRcJSON);
|
|
312
|
-
if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
|
|
313
|
-
return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
314
|
-
}
|
|
315
|
-
const port = getConfig().defaultPort.tunnel;
|
|
316
|
-
const cwd = getAppWorkspacePath();
|
|
317
|
-
const env = {
|
|
318
|
-
...process.env,
|
|
319
|
-
ONES_HOSTED_PORT: `${port}`
|
|
320
|
-
};
|
|
321
|
-
const tunnelChild = node_child_process.spawn("ones", ["tunnel", String(port)], {
|
|
322
|
-
cwd,
|
|
323
|
-
stdio: "inherit"
|
|
324
|
-
});
|
|
325
|
-
const devChild = node_child_process.spawn("npm", ["run", "dev"], {
|
|
326
|
-
cwd,
|
|
327
|
-
stdio: "inherit",
|
|
328
|
-
env
|
|
329
|
-
});
|
|
330
|
-
const cleanup = () => {
|
|
331
|
-
tunnelChild.kill();
|
|
332
|
-
devChild.kill();
|
|
333
|
-
};
|
|
334
|
-
const onSignal = () => {
|
|
335
|
-
cleanup();
|
|
336
|
-
process.exit(128 + 2);
|
|
337
|
-
};
|
|
338
|
-
process.on("SIGINT", onSignal);
|
|
339
|
-
process.on("SIGTERM", onSignal);
|
|
340
|
-
if (normalizedOptions.install) {
|
|
341
|
-
lodashEs.noop(normalizedOptions.install);
|
|
342
|
-
}
|
|
343
|
-
await new Promise((resolve) => {
|
|
344
|
-
devChild.on("exit", () => {
|
|
345
|
-
cleanup();
|
|
346
|
-
process.off("SIGINT", onSignal);
|
|
347
|
-
process.off("SIGTERM", onSignal);
|
|
348
|
-
resolve();
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
353
|
-
const minPortNumber = 1;
|
|
354
|
-
const maxPortNumber = 65535;
|
|
355
|
-
const normalize$8 = async (options) => {
|
|
356
|
-
const portInput = options.port;
|
|
357
|
-
if (portInput)
|
|
358
|
-
;
|
|
359
|
-
else {
|
|
360
|
-
return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
361
|
-
}
|
|
362
|
-
const portString = String(portInput);
|
|
363
|
-
const portNumber = Number(portString);
|
|
364
|
-
if (isPortNumber.test(portString))
|
|
365
|
-
;
|
|
366
|
-
else {
|
|
367
|
-
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
368
|
-
}
|
|
369
|
-
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
370
|
-
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
371
|
-
}
|
|
372
|
-
const port = portString;
|
|
373
|
-
return {
|
|
374
|
-
port
|
|
375
|
-
};
|
|
376
|
-
};
|
|
377
303
|
const StoreJSONSchema = zod.z.object({
|
|
378
304
|
version: zod.z.string().optional(),
|
|
379
305
|
timestamp: zod.z.number().optional(),
|
|
@@ -419,11 +345,11 @@ const getStore = async () => {
|
|
|
419
345
|
const setStore = async (store) => {
|
|
420
346
|
try {
|
|
421
347
|
await ensureFile(storePath);
|
|
422
|
-
const
|
|
348
|
+
const version2 = `${getPackageJSON().version}`;
|
|
423
349
|
const timestamp = Date.now();
|
|
424
350
|
return await writeJSON(storePath, {
|
|
425
351
|
...store,
|
|
426
|
-
version,
|
|
352
|
+
version: version2,
|
|
427
353
|
timestamp
|
|
428
354
|
}, {
|
|
429
355
|
encoding: "utf8"
|
|
@@ -475,112 +401,386 @@ const setONESToken = async (token) => {
|
|
|
475
401
|
ones_token: token
|
|
476
402
|
});
|
|
477
403
|
};
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
404
|
+
const getHostToken = async () => {
|
|
405
|
+
var _store$host_token;
|
|
406
|
+
const store = await getStore();
|
|
407
|
+
return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
|
|
408
|
+
};
|
|
409
|
+
const setHostToken = async (token) => {
|
|
410
|
+
return mergeStore({
|
|
411
|
+
host_token: token
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
const API = {
|
|
415
|
+
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
416
|
+
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
417
|
+
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/dev_declare",
|
|
418
|
+
APP_LIST: "/platform/api/app/list",
|
|
419
|
+
APP_INSTALL: "/platform/api/app/install",
|
|
420
|
+
APP_UPGRADE: "/platform/api/app/upgrade",
|
|
421
|
+
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
422
|
+
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
423
|
+
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
424
|
+
};
|
|
425
|
+
const REQUEST_TIMEOUT = 1e4;
|
|
426
|
+
const getPath = (path, map2) => {
|
|
427
|
+
var _context;
|
|
428
|
+
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
429
|
+
if (/^:/.test(part)) {
|
|
430
|
+
return `${base}/${map2[part.slice(1)]}`;
|
|
431
|
+
}
|
|
432
|
+
return `${base}/${part}`;
|
|
433
|
+
}, "").slice(1);
|
|
434
|
+
};
|
|
435
|
+
const consoleUnauthorizedMessage = () => {
|
|
436
|
+
console.log("Not logged in");
|
|
437
|
+
console.log('Login with "ones login" command');
|
|
438
|
+
process.exit(1);
|
|
439
|
+
};
|
|
440
|
+
const consoleAppNotInstalledMessage = () => {
|
|
441
|
+
console.log("App not installed");
|
|
442
|
+
process.exit(1);
|
|
443
|
+
};
|
|
444
|
+
const getURL = async (path, pathMap, queryMap) => {
|
|
445
|
+
const base = await getRegionURL();
|
|
446
|
+
if (base) {
|
|
447
|
+
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
448
|
+
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
512
449
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
450
|
+
consoleUnauthorizedMessage();
|
|
451
|
+
};
|
|
452
|
+
const getHeaders = async (value) => {
|
|
453
|
+
const token = await getONESToken();
|
|
454
|
+
if (token) {
|
|
455
|
+
return lodashEs.merge({
|
|
456
|
+
Authorization: `Bearer ${token}`
|
|
457
|
+
}, value);
|
|
516
458
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
459
|
+
consoleUnauthorizedMessage();
|
|
460
|
+
process.exit(1);
|
|
461
|
+
};
|
|
462
|
+
const handleError = (error) => {
|
|
463
|
+
var _error$response, _error$response2;
|
|
464
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
465
|
+
console.log(error.response.statusText);
|
|
466
|
+
consoleUnauthorizedMessage();
|
|
467
|
+
process.exit(1);
|
|
522
468
|
}
|
|
523
|
-
|
|
524
|
-
const payload = data.toString();
|
|
469
|
+
if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
|
|
525
470
|
try {
|
|
526
|
-
const message = JSON.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return message;
|
|
531
|
-
} catch (error) {
|
|
532
|
-
console.error("Invalid tunnel message:", error);
|
|
533
|
-
return null;
|
|
471
|
+
const message = JSON.stringify(error.response.data, null, 2);
|
|
472
|
+
console.error(message);
|
|
473
|
+
process.exit(1);
|
|
474
|
+
} catch (error2) {
|
|
534
475
|
}
|
|
535
476
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
};
|
|
558
|
-
(_this$ws5 = this.ws) === null || _this$ws5 === void 0 || _this$ws5.send(JSON.stringify(reply));
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
try {
|
|
562
|
-
var _this$ws6;
|
|
563
|
-
const response = await this.forwardRequest(request);
|
|
564
|
-
const reply = {
|
|
565
|
-
id: message.id,
|
|
566
|
-
payload: response
|
|
567
|
-
};
|
|
568
|
-
(_this$ws6 = this.ws) === null || _this$ws6 === void 0 || _this$ws6.send(JSON.stringify(reply));
|
|
569
|
-
} catch (error) {
|
|
570
|
-
var _this$ws7;
|
|
571
|
-
const reply = {
|
|
572
|
-
id: message.id,
|
|
573
|
-
payload: {
|
|
574
|
-
status: 500,
|
|
575
|
-
headers: {
|
|
576
|
-
"x-agent-error": [error instanceof Error ? error.message : "Unknown error"]
|
|
577
|
-
},
|
|
578
|
-
body: "agent request error"
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
(_this$ws7 = this.ws) === null || _this$ws7 === void 0 || _this$ws7.send(JSON.stringify(reply));
|
|
477
|
+
console.error(error);
|
|
478
|
+
return {};
|
|
479
|
+
};
|
|
480
|
+
const fetchAppBase = async (params) => {
|
|
481
|
+
var _params$url;
|
|
482
|
+
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
483
|
+
const headers = await getHeaders(params.headers);
|
|
484
|
+
const response = await axios({
|
|
485
|
+
...params,
|
|
486
|
+
url,
|
|
487
|
+
headers,
|
|
488
|
+
timeout: REQUEST_TIMEOUT
|
|
489
|
+
});
|
|
490
|
+
return response.data;
|
|
491
|
+
};
|
|
492
|
+
const fetchAppList = async (appID) => {
|
|
493
|
+
return await fetchAppBase({
|
|
494
|
+
url: API.APP_LIST,
|
|
495
|
+
method: "GET",
|
|
496
|
+
queryMap: {
|
|
497
|
+
app_id: appID
|
|
582
498
|
}
|
|
583
|
-
}
|
|
499
|
+
}).catch(handleError);
|
|
500
|
+
};
|
|
501
|
+
const fetchTokenInfo = async () => {
|
|
502
|
+
return await fetchAppBase({
|
|
503
|
+
url: API.TOKEN_INFO,
|
|
504
|
+
method: "GET"
|
|
505
|
+
}).catch(handleError);
|
|
506
|
+
};
|
|
507
|
+
const fetchHostedToken = async (data) => {
|
|
508
|
+
return await fetchAppBase({
|
|
509
|
+
url: API.HOSTED_TOKEN,
|
|
510
|
+
method: "POST",
|
|
511
|
+
data
|
|
512
|
+
}).catch(handleError);
|
|
513
|
+
};
|
|
514
|
+
const fetchHostedAbilityStorageDevDeclare = async (data) => {
|
|
515
|
+
return await fetchAppBase({
|
|
516
|
+
url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
|
|
517
|
+
method: "POST",
|
|
518
|
+
data
|
|
519
|
+
}).catch(handleError);
|
|
520
|
+
};
|
|
521
|
+
const fetchAppInstall = async (data) => {
|
|
522
|
+
var _appList$data$0$insta, _appList$data;
|
|
523
|
+
const appID = getAppManifestJSON().app.id;
|
|
524
|
+
const appList = await fetchAppList(appID);
|
|
525
|
+
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
526
|
+
const url = installationID ? API.APP_UPGRADE : API.APP_INSTALL;
|
|
527
|
+
return await fetchAppBase({
|
|
528
|
+
url,
|
|
529
|
+
method: "POST",
|
|
530
|
+
data
|
|
531
|
+
}).catch(handleError);
|
|
532
|
+
};
|
|
533
|
+
const fetchAppUninstall = async () => {
|
|
534
|
+
var _appList$data$0$insta2, _appList$data2;
|
|
535
|
+
const appID = getAppManifestJSON().app.id;
|
|
536
|
+
const appList = await fetchAppList(appID);
|
|
537
|
+
const installationID = (_appList$data$0$insta2 = (_appList$data2 = appList.data) === null || _appList$data2 === void 0 || (_appList$data2 = _appList$data2[0]) === null || _appList$data2 === void 0 ? void 0 : _appList$data2.installation_id) !== null && _appList$data$0$insta2 !== void 0 ? _appList$data$0$insta2 : "";
|
|
538
|
+
if (installationID) {
|
|
539
|
+
return await fetchAppBase({
|
|
540
|
+
url: API.APP_UNINSTALL,
|
|
541
|
+
method: "POST",
|
|
542
|
+
pathMap: {
|
|
543
|
+
installation_id: installationID
|
|
544
|
+
}
|
|
545
|
+
}).catch(handleError);
|
|
546
|
+
}
|
|
547
|
+
consoleAppNotInstalledMessage();
|
|
548
|
+
process.exit(1);
|
|
549
|
+
};
|
|
550
|
+
const fetchAppEnable = async () => {
|
|
551
|
+
var _appList$data$0$insta3, _appList$data3;
|
|
552
|
+
const appID = getAppManifestJSON().app.id;
|
|
553
|
+
const appList = await fetchAppList(appID);
|
|
554
|
+
const installationID = (_appList$data$0$insta3 = (_appList$data3 = appList.data) === null || _appList$data3 === void 0 || (_appList$data3 = _appList$data3[0]) === null || _appList$data3 === void 0 ? void 0 : _appList$data3.installation_id) !== null && _appList$data$0$insta3 !== void 0 ? _appList$data$0$insta3 : "";
|
|
555
|
+
if (installationID) {
|
|
556
|
+
return await fetchAppBase({
|
|
557
|
+
url: API.APP_ENABLE,
|
|
558
|
+
method: "POST",
|
|
559
|
+
pathMap: {
|
|
560
|
+
installation_id: installationID
|
|
561
|
+
}
|
|
562
|
+
}).catch(handleError);
|
|
563
|
+
}
|
|
564
|
+
consoleAppNotInstalledMessage();
|
|
565
|
+
process.exit(1);
|
|
566
|
+
};
|
|
567
|
+
const fetchAppDisable = async () => {
|
|
568
|
+
var _appList$data$0$insta4, _appList$data4;
|
|
569
|
+
const appID = getAppManifestJSON().app.id;
|
|
570
|
+
const appList = await fetchAppList(appID);
|
|
571
|
+
const installationID = (_appList$data$0$insta4 = (_appList$data4 = appList.data) === null || _appList$data4 === void 0 || (_appList$data4 = _appList$data4[0]) === null || _appList$data4 === void 0 ? void 0 : _appList$data4.installation_id) !== null && _appList$data$0$insta4 !== void 0 ? _appList$data$0$insta4 : "";
|
|
572
|
+
if (installationID) {
|
|
573
|
+
return await fetchAppBase({
|
|
574
|
+
url: API.APP_DISABLE,
|
|
575
|
+
method: "POST",
|
|
576
|
+
pathMap: {
|
|
577
|
+
installation_id: installationID
|
|
578
|
+
}
|
|
579
|
+
}).catch(handleError);
|
|
580
|
+
}
|
|
581
|
+
consoleAppNotInstalledMessage();
|
|
582
|
+
process.exit(1);
|
|
583
|
+
};
|
|
584
|
+
const checkTokenInfo = async () => {
|
|
585
|
+
var _store$ones_token, _store$region_url;
|
|
586
|
+
let boolean = true;
|
|
587
|
+
const store = await getStore();
|
|
588
|
+
const token = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
|
|
589
|
+
const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
590
|
+
if (token && regionURL) {
|
|
591
|
+
await fetchAppBase({
|
|
592
|
+
url: API.TOKEN_INFO,
|
|
593
|
+
method: "GET"
|
|
594
|
+
}).catch(() => {
|
|
595
|
+
boolean = false;
|
|
596
|
+
});
|
|
597
|
+
} else {
|
|
598
|
+
boolean = false;
|
|
599
|
+
}
|
|
600
|
+
return boolean;
|
|
601
|
+
};
|
|
602
|
+
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
603
|
+
const minPortNumber = 1;
|
|
604
|
+
const maxPortNumber = 65535;
|
|
605
|
+
const MANIFEST_PATH = "/manifest";
|
|
606
|
+
const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
|
|
607
|
+
const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
|
|
608
|
+
const normalize$9 = async (options) => {
|
|
609
|
+
const portInput = options.port;
|
|
610
|
+
if (portInput)
|
|
611
|
+
;
|
|
612
|
+
else {
|
|
613
|
+
return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
614
|
+
}
|
|
615
|
+
const portString = String(portInput);
|
|
616
|
+
const portNumber = Number(portString);
|
|
617
|
+
if (isPortNumber.test(portString))
|
|
618
|
+
;
|
|
619
|
+
else {
|
|
620
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
621
|
+
}
|
|
622
|
+
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
623
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
624
|
+
}
|
|
625
|
+
const port = portString;
|
|
626
|
+
return {
|
|
627
|
+
port
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
const getTunnelContext = async () => {
|
|
631
|
+
var _appManifestJSON$app$, _appManifestJSON$app, _store$region_url, _store$ones_token;
|
|
632
|
+
const appManifestJSON = getAppManifestJSON();
|
|
633
|
+
const appID = (_appManifestJSON$app$ = (_appManifestJSON$app = appManifestJSON.app) === null || _appManifestJSON$app === void 0 ? void 0 : _appManifestJSON$app.id) !== null && _appManifestJSON$app$ !== void 0 ? _appManifestJSON$app$ : "";
|
|
634
|
+
const store = await getStore();
|
|
635
|
+
const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
636
|
+
const onesToken = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
|
|
637
|
+
if (appID && regionURL && onesToken) {
|
|
638
|
+
return {
|
|
639
|
+
appID,
|
|
640
|
+
regionURL,
|
|
641
|
+
onesToken,
|
|
642
|
+
store,
|
|
643
|
+
appManifestJSON
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
consoleUnauthorizedMessage();
|
|
647
|
+
process.exit(1);
|
|
648
|
+
};
|
|
649
|
+
const getHostedTokenScopes = (ones2) => {
|
|
650
|
+
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
651
|
+
if (!storage) {
|
|
652
|
+
return [];
|
|
653
|
+
}
|
|
654
|
+
const scopes = /* @__PURE__ */ new Set();
|
|
655
|
+
if (Array.isArray(storage.entities) && storage.entities.length > 0) {
|
|
656
|
+
scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
|
|
657
|
+
}
|
|
658
|
+
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
659
|
+
scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
|
|
660
|
+
}
|
|
661
|
+
return Array.from(scopes);
|
|
662
|
+
};
|
|
663
|
+
const getRelayScope = () => {
|
|
664
|
+
return createOnesApp.HostedTokenScope.RELAY;
|
|
665
|
+
};
|
|
666
|
+
const buildTunnelUrl = async () => {
|
|
667
|
+
const {
|
|
668
|
+
appID,
|
|
669
|
+
regionURL
|
|
670
|
+
} = await getTunnelContext();
|
|
671
|
+
const url = new URL(regionURL);
|
|
672
|
+
url.pathname = `/platform/app/relay/dispatch/${appID}`;
|
|
673
|
+
return url.toString();
|
|
674
|
+
};
|
|
675
|
+
class TunnelClient {
|
|
676
|
+
constructor(localPort, baseUrl, appID, hostedToken) {
|
|
677
|
+
let enableInternalManifestRoute = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
678
|
+
let replaceExisting = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
|
|
679
|
+
this.ws = null;
|
|
680
|
+
this.localPort = localPort;
|
|
681
|
+
this.baseUrl = baseUrl;
|
|
682
|
+
this.appID = appID;
|
|
683
|
+
this.hostedToken = hostedToken;
|
|
684
|
+
this.enableInternalManifestRoute = enableInternalManifestRoute;
|
|
685
|
+
this.replaceExisting = replaceExisting;
|
|
686
|
+
}
|
|
687
|
+
async connect() {
|
|
688
|
+
const proxyUrl = this.buildProxyUrl();
|
|
689
|
+
this.ws = new WebSocket(proxyUrl, {
|
|
690
|
+
headers: {
|
|
691
|
+
Authorization: `Bearer ${this.hostedToken}`
|
|
692
|
+
},
|
|
693
|
+
maxPayload: MAX_RELAY_BODY_BYTES
|
|
694
|
+
});
|
|
695
|
+
this.ws.on("message", async (data) => {
|
|
696
|
+
const message = this.parseMessage(data);
|
|
697
|
+
if (!message) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
await this.handleMessage(message);
|
|
701
|
+
});
|
|
702
|
+
this.ws.on("ping", (data) => {
|
|
703
|
+
var _this$ws;
|
|
704
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.pong(data);
|
|
705
|
+
});
|
|
706
|
+
this.ws.on("error", (error) => {
|
|
707
|
+
console.error("WebSocket error:", error);
|
|
708
|
+
});
|
|
709
|
+
return new Promise((resolve, reject) => {
|
|
710
|
+
var _this$ws2, _this$ws3;
|
|
711
|
+
(_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.on("open", () => resolve());
|
|
712
|
+
(_this$ws3 = this.ws) === null || _this$ws3 === void 0 || _this$ws3.on("error", reject);
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
close() {
|
|
716
|
+
var _this$ws4;
|
|
717
|
+
(_this$ws4 = this.ws) === null || _this$ws4 === void 0 || _this$ws4.close();
|
|
718
|
+
}
|
|
719
|
+
buildProxyUrl() {
|
|
720
|
+
const url = new URL("/platform/app/relay/", this.baseUrl);
|
|
721
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
722
|
+
url.searchParams.set("app_id", this.appID);
|
|
723
|
+
url.searchParams.set("replace_existing", String(this.replaceExisting));
|
|
724
|
+
return url.toString();
|
|
725
|
+
}
|
|
726
|
+
parseMessage(data) {
|
|
727
|
+
const buffer = this.toBuffer(data);
|
|
728
|
+
if (!buffer) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
if (buffer.length >= 4) {
|
|
732
|
+
const binary = this.parseBinaryEnvelope(buffer);
|
|
733
|
+
if (binary) {
|
|
734
|
+
return binary;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return this.parseJSONEnvelope(buffer.toString());
|
|
738
|
+
}
|
|
739
|
+
async handleMessage(message) {
|
|
740
|
+
const request = this.getRequestPayload(message);
|
|
741
|
+
if (!request) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
|
|
745
|
+
const appManifest = getAppManifestJSON().app;
|
|
746
|
+
const baseURL = await buildTunnelUrl();
|
|
747
|
+
const reply = {
|
|
748
|
+
id: message.id,
|
|
749
|
+
payload: {
|
|
750
|
+
status: 200,
|
|
751
|
+
headers: {
|
|
752
|
+
"content-type": ["application/json"]
|
|
753
|
+
},
|
|
754
|
+
body: {
|
|
755
|
+
...appManifest,
|
|
756
|
+
base_url: baseURL
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
this.sendBinaryEnvelope(reply);
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
try {
|
|
764
|
+
const response = await this.forwardRequest(request);
|
|
765
|
+
const reply = {
|
|
766
|
+
id: message.id,
|
|
767
|
+
payload: response
|
|
768
|
+
};
|
|
769
|
+
this.sendBinaryEnvelope(reply);
|
|
770
|
+
} catch (error) {
|
|
771
|
+
const reply = {
|
|
772
|
+
id: message.id,
|
|
773
|
+
payload: {
|
|
774
|
+
status: 500,
|
|
775
|
+
headers: {
|
|
776
|
+
"x-agent-error": [error instanceof Error ? error.message : "Unknown error"]
|
|
777
|
+
},
|
|
778
|
+
body: "agent request error"
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
this.sendBinaryEnvelope(reply);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
584
784
|
getRequestPayload(message) {
|
|
585
785
|
const payload = message.payload;
|
|
586
786
|
if (!(payload !== null && payload !== void 0 && payload.method) || !(payload !== null && payload !== void 0 && payload.path)) {
|
|
@@ -593,43 +793,36 @@ class TunnelClient {
|
|
|
593
793
|
if (payload.query) {
|
|
594
794
|
Object.entries(payload.query).forEach((_ref) => {
|
|
595
795
|
let [key, value] = _ref;
|
|
596
|
-
|
|
796
|
+
if (Array.isArray(value)) {
|
|
797
|
+
value.forEach((item) => {
|
|
798
|
+
url.searchParams.append(key, item);
|
|
799
|
+
});
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
url.searchParams.append(key, value);
|
|
597
803
|
});
|
|
598
804
|
}
|
|
599
|
-
const headers = this.normalizeHeaders(payload.headers);
|
|
600
|
-
const body = this.normalizeBody(payload.body);
|
|
601
805
|
const response = await axios.request({
|
|
602
806
|
url: url.toString(),
|
|
603
807
|
method: payload.method,
|
|
604
|
-
headers,
|
|
605
|
-
data: body,
|
|
606
|
-
responseType: "
|
|
607
|
-
validateStatus: () => true
|
|
808
|
+
headers: payload.headers,
|
|
809
|
+
data: payload.body,
|
|
810
|
+
responseType: "arraybuffer",
|
|
811
|
+
validateStatus: () => true,
|
|
812
|
+
maxBodyLength: MAX_RELAY_BODY_BYTES,
|
|
813
|
+
maxContentLength: MAX_RELAY_BODY_BYTES
|
|
608
814
|
});
|
|
815
|
+
const responseBytes = Buffer.from(response.data);
|
|
609
816
|
return {
|
|
610
817
|
status: response.status,
|
|
611
818
|
headers: this.collectHeaders(response.headers),
|
|
612
|
-
body:
|
|
819
|
+
body: responseBytes
|
|
613
820
|
};
|
|
614
821
|
}
|
|
615
|
-
normalizeHeaders(headers) {
|
|
616
|
-
if (!headers) {
|
|
617
|
-
return void 0;
|
|
618
|
-
}
|
|
619
|
-
const normalized = {};
|
|
620
|
-
Object.entries(headers).forEach((_ref2) => {
|
|
621
|
-
let [key, values] = _ref2;
|
|
622
|
-
if (!values || values.length === 0) {
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
normalized[key] = values.join(",");
|
|
626
|
-
});
|
|
627
|
-
return normalized;
|
|
628
|
-
}
|
|
629
822
|
collectHeaders(headers) {
|
|
630
823
|
const collected = {};
|
|
631
|
-
Object.entries(headers).forEach((
|
|
632
|
-
let [key, value] =
|
|
824
|
+
Object.entries(headers).forEach((_ref2) => {
|
|
825
|
+
let [key, value] = _ref2;
|
|
633
826
|
if (Array.isArray(value)) {
|
|
634
827
|
collected[key] = value.map((item) => String(item));
|
|
635
828
|
return;
|
|
@@ -640,260 +833,425 @@ class TunnelClient {
|
|
|
640
833
|
});
|
|
641
834
|
return collected;
|
|
642
835
|
}
|
|
643
|
-
|
|
836
|
+
sendBinaryEnvelope(envelope) {
|
|
837
|
+
var _this$ws5;
|
|
838
|
+
const encoded = this.encodeBinaryEnvelope(envelope);
|
|
839
|
+
(_this$ws5 = this.ws) === null || _this$ws5 === void 0 || _this$ws5.send(encoded);
|
|
840
|
+
}
|
|
841
|
+
encodeBinaryEnvelope(envelope) {
|
|
842
|
+
var _envelope$payload;
|
|
843
|
+
const payload = (_envelope$payload = envelope.payload) !== null && _envelope$payload !== void 0 ? _envelope$payload : {};
|
|
844
|
+
const body = this.toBodyBuffer(payload.body);
|
|
845
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
846
|
+
throw new Error("relay body too large");
|
|
847
|
+
}
|
|
848
|
+
const metaPayload = {
|
|
849
|
+
...payload
|
|
850
|
+
};
|
|
851
|
+
delete metaPayload.body;
|
|
852
|
+
const meta = Buffer.from(JSON.stringify({
|
|
853
|
+
id: envelope.id,
|
|
854
|
+
payload: metaPayload
|
|
855
|
+
}), "utf8");
|
|
856
|
+
const header = Buffer.allocUnsafe(4);
|
|
857
|
+
header.writeUInt32BE(meta.length, 0);
|
|
858
|
+
return Buffer.concat([header, meta, body]);
|
|
859
|
+
}
|
|
860
|
+
toBodyBuffer(body) {
|
|
644
861
|
if (body === void 0 || body === null) {
|
|
645
|
-
return
|
|
862
|
+
return Buffer.alloc(0);
|
|
646
863
|
}
|
|
647
|
-
if (
|
|
864
|
+
if (Buffer.isBuffer(body)) {
|
|
648
865
|
return body;
|
|
649
866
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
normalizeResponseBody(body) {
|
|
653
|
-
if (!body) {
|
|
654
|
-
return void 0;
|
|
867
|
+
if (body instanceof ArrayBuffer) {
|
|
868
|
+
return Buffer.from(body);
|
|
655
869
|
}
|
|
656
|
-
|
|
657
|
-
return
|
|
658
|
-
} catch {
|
|
659
|
-
return body;
|
|
870
|
+
if (ArrayBuffer.isView(body)) {
|
|
871
|
+
return Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
660
872
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const getPath = (path, map2) => {
|
|
664
|
-
var _context;
|
|
665
|
-
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
666
|
-
if (/^:/.test(part)) {
|
|
667
|
-
return `${base}/${map2[part.slice(1)]}`;
|
|
873
|
+
if (typeof body === "string") {
|
|
874
|
+
return Buffer.from(body, "utf8");
|
|
668
875
|
}
|
|
669
|
-
return
|
|
670
|
-
}, "").slice(1);
|
|
671
|
-
};
|
|
672
|
-
const consoleUnauthorizedMessage = () => {
|
|
673
|
-
console.log("Not logged in");
|
|
674
|
-
console.log('Login with "ones login" command');
|
|
675
|
-
};
|
|
676
|
-
const getURL = async (path, pathMap, queryMap) => {
|
|
677
|
-
const base = await getRegionURL();
|
|
678
|
-
if (base) {
|
|
679
|
-
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
680
|
-
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
681
|
-
}
|
|
682
|
-
consoleUnauthorizedMessage();
|
|
683
|
-
process$1.exit(1);
|
|
684
|
-
};
|
|
685
|
-
const getHeaders = async (value) => {
|
|
686
|
-
const token = await getONESToken();
|
|
687
|
-
if (token) {
|
|
688
|
-
return lodashEs.merge({
|
|
689
|
-
Authorization: `Bearer ${token}`
|
|
690
|
-
}, value);
|
|
691
|
-
}
|
|
692
|
-
consoleUnauthorizedMessage();
|
|
693
|
-
process$1.exit(1);
|
|
694
|
-
};
|
|
695
|
-
const handleError = (error) => {
|
|
696
|
-
var _error$response;
|
|
697
|
-
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
698
|
-
console.log(error.response.statusText);
|
|
699
|
-
consoleUnauthorizedMessage();
|
|
700
|
-
} else {
|
|
701
|
-
console.error(error);
|
|
876
|
+
return Buffer.from(JSON.stringify(body), "utf8");
|
|
702
877
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
|
|
726
|
-
}
|
|
727
|
-
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
728
|
-
scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
|
|
729
|
-
}
|
|
730
|
-
return Array.from(scopes);
|
|
731
|
-
};
|
|
732
|
-
const getRelayScope = () => {
|
|
733
|
-
return createOnesApp.HostedTokenScope.RELAY;
|
|
734
|
-
};
|
|
735
|
-
const getHostToken = async (baseUrl, userToken, appID, scopes) => {
|
|
736
|
-
const url = `${baseUrl.replace(/\/$/, "")}${API.HOSTED_TOKEN}`;
|
|
737
|
-
return axios.post(url, {
|
|
738
|
-
app_id: appID,
|
|
739
|
-
scopes
|
|
740
|
-
}, {
|
|
741
|
-
headers: {
|
|
742
|
-
Authorization: `Bearer ${userToken}`
|
|
878
|
+
parseBinaryEnvelope(buffer) {
|
|
879
|
+
const metaLength = buffer.readUInt32BE(0);
|
|
880
|
+
if (metaLength <= 0 || 4 + metaLength > buffer.length) {
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
const metaRaw = buffer.subarray(4, 4 + metaLength).toString("utf8");
|
|
884
|
+
try {
|
|
885
|
+
const envelope = JSON.parse(metaRaw);
|
|
886
|
+
if (!(envelope !== null && envelope !== void 0 && envelope.payload)) {
|
|
887
|
+
return envelope;
|
|
888
|
+
}
|
|
889
|
+
const body = buffer.subarray(4 + metaLength);
|
|
890
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
891
|
+
console.error("Binary tunnel body exceeds size limit");
|
|
892
|
+
return null;
|
|
893
|
+
}
|
|
894
|
+
const payload = envelope.payload;
|
|
895
|
+
payload.body = body;
|
|
896
|
+
return envelope;
|
|
897
|
+
} catch (error) {
|
|
898
|
+
console.error("Invalid binary tunnel message:", error);
|
|
899
|
+
return null;
|
|
743
900
|
}
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
return hosted_token;
|
|
751
|
-
}
|
|
901
|
+
}
|
|
902
|
+
parseJSONEnvelope(payload) {
|
|
903
|
+
try {
|
|
904
|
+
const message = JSON.parse(payload);
|
|
905
|
+
if (!message) {
|
|
906
|
+
return null;
|
|
752
907
|
}
|
|
908
|
+
return message;
|
|
909
|
+
} catch (error) {
|
|
910
|
+
console.error("Invalid tunnel message:", error);
|
|
753
911
|
return null;
|
|
754
|
-
};
|
|
755
|
-
const token = tokenFromData(data);
|
|
756
|
-
if (token) {
|
|
757
|
-
return token;
|
|
758
912
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
913
|
+
}
|
|
914
|
+
toBuffer(data) {
|
|
915
|
+
if (Buffer.isBuffer(data)) {
|
|
916
|
+
return data;
|
|
917
|
+
}
|
|
918
|
+
if (Array.isArray(data)) {
|
|
919
|
+
return Buffer.concat(data);
|
|
920
|
+
}
|
|
921
|
+
if (data instanceof ArrayBuffer) {
|
|
922
|
+
return Buffer.from(data);
|
|
923
|
+
}
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const invokeTunnel = async function(port) {
|
|
928
|
+
var _options$rebuildWhenE, _options$enableIntern, _hostedTokenResponse$;
|
|
929
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
930
|
+
const {
|
|
931
|
+
appManifestJSON,
|
|
932
|
+
appID,
|
|
933
|
+
regionURL
|
|
934
|
+
} = await getTunnelContext();
|
|
935
|
+
const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
|
|
936
|
+
const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
|
|
937
|
+
const storageScopes = getHostedTokenScopes(appManifestJSON.ones);
|
|
938
|
+
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
939
|
+
const hostedTokenResponse = await fetchHostedToken({
|
|
940
|
+
app_id: appID,
|
|
941
|
+
scopes
|
|
763
942
|
});
|
|
943
|
+
const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
|
|
944
|
+
if (!hostedToken) {
|
|
945
|
+
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
946
|
+
}
|
|
947
|
+
await setHostToken(hostedToken);
|
|
948
|
+
const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
|
|
949
|
+
await client.connect();
|
|
764
950
|
};
|
|
765
|
-
const
|
|
766
|
-
var
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
951
|
+
const tunnel = async function() {
|
|
952
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
953
|
+
args[_key] = arguments[_key];
|
|
954
|
+
}
|
|
955
|
+
const {
|
|
956
|
+
options
|
|
957
|
+
} = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
|
|
958
|
+
const normalizedOptions = await normalize$9(options);
|
|
959
|
+
const port = Number(normalizedOptions.port);
|
|
960
|
+
await invokeTunnel(port, {
|
|
961
|
+
enableInternalManifestRoute: false,
|
|
962
|
+
rebuildWhenExists: true
|
|
773
963
|
});
|
|
774
|
-
|
|
775
|
-
};
|
|
776
|
-
const fetchAppList = async (appID) => {
|
|
777
|
-
return await fetchAppBase({
|
|
778
|
-
url: API.APP_LIST,
|
|
779
|
-
method: "GET",
|
|
780
|
-
queryMap: {
|
|
781
|
-
app_id: appID
|
|
782
|
-
}
|
|
783
|
-
}).catch(handleError);
|
|
964
|
+
const runnelUrl = await buildTunnelUrl();
|
|
965
|
+
console.log(`Relay endpoint: ${runnelUrl}`);
|
|
784
966
|
};
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
method: "GET"
|
|
789
|
-
}).catch(handleError);
|
|
967
|
+
const normalize$8 = async (options) => {
|
|
968
|
+
lodashEs.noop(options);
|
|
969
|
+
return {};
|
|
790
970
|
};
|
|
791
|
-
const
|
|
792
|
-
var
|
|
793
|
-
const
|
|
794
|
-
const
|
|
795
|
-
const
|
|
796
|
-
const
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
971
|
+
const displayAppDetail = async (installationID) => {
|
|
972
|
+
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
973
|
+
const tokenInfo = await fetchTokenInfo();
|
|
974
|
+
const orgUUID = (_tokenInfo$org$uuid = (_tokenInfo$org = tokenInfo.org) === null || _tokenInfo$org === void 0 ? void 0 : _tokenInfo$org.uuid) !== null && _tokenInfo$org$uuid !== void 0 ? _tokenInfo$org$uuid : "";
|
|
975
|
+
const teamUUID = (_tokenInfo$teams$0$uu = (_tokenInfo$teams = tokenInfo.teams) === null || _tokenInfo$teams === void 0 || (_tokenInfo$teams = _tokenInfo$teams[0]) === null || _tokenInfo$teams === void 0 ? void 0 : _tokenInfo$teams.uuid) !== null && _tokenInfo$teams$0$uu !== void 0 ? _tokenInfo$teams$0$uu : "";
|
|
976
|
+
const isOrgVisible = (_tokenInfo$org$visibi = (_tokenInfo$org2 = tokenInfo.org) === null || _tokenInfo$org2 === void 0 ? void 0 : _tokenInfo$org2.visibility) !== null && _tokenInfo$org$visibi !== void 0 ? _tokenInfo$org$visibi : false;
|
|
977
|
+
const baseURL = await getBaseURL();
|
|
978
|
+
if (isOrgVisible && orgUUID) {
|
|
979
|
+
const url = `${baseURL}project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
980
|
+
console.log(`See App detail: ${url}`);
|
|
981
|
+
}
|
|
982
|
+
if (!isOrgVisible && teamUUID) {
|
|
983
|
+
const url = `${baseURL}project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
984
|
+
console.log(`See App detail: ${url}`);
|
|
985
|
+
}
|
|
802
986
|
};
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
987
|
+
const invokeInstall = async (manifestUrl) => {
|
|
988
|
+
const {
|
|
989
|
+
app
|
|
990
|
+
} = getAppManifestJSON();
|
|
991
|
+
const appName = app.name;
|
|
992
|
+
const appID = app.id;
|
|
993
|
+
const result = await fetchAppInstall({
|
|
994
|
+
manifest_url: manifestUrl,
|
|
995
|
+
options: {
|
|
996
|
+
enable: true
|
|
813
997
|
}
|
|
814
|
-
})
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
url: API.APP_ENABLE,
|
|
823
|
-
method: "POST",
|
|
824
|
-
pathMap: {
|
|
825
|
-
installation_id: installationID
|
|
998
|
+
});
|
|
999
|
+
if (result.code === "OK") {
|
|
1000
|
+
var _appList$data$0$insta, _appList$data;
|
|
1001
|
+
console.log(`App "${appName}" installed successfully!`);
|
|
1002
|
+
const appList = await fetchAppList(appID);
|
|
1003
|
+
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
1004
|
+
if (installationID) {
|
|
1005
|
+
await displayAppDetail(installationID);
|
|
826
1006
|
}
|
|
827
|
-
}
|
|
1007
|
+
} else {
|
|
1008
|
+
console.log(`App "${appName}" installed failed!`);
|
|
1009
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1010
|
+
}
|
|
828
1011
|
};
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
const
|
|
832
|
-
const
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
method: "POST",
|
|
837
|
-
pathMap: {
|
|
838
|
-
installation_id: installationID
|
|
1012
|
+
const getManifestUrl = async () => {
|
|
1013
|
+
const runnelUrl = await buildTunnelUrl();
|
|
1014
|
+
const customManifestUrl = `${runnelUrl}${MANIFEST_PATH}`;
|
|
1015
|
+
const internalManifestUrl = `${runnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1016
|
+
const internalResult = await axios.get(internalManifestUrl).then((response) => {
|
|
1017
|
+
if (response.status === 200) {
|
|
1018
|
+
return internalManifestUrl;
|
|
839
1019
|
}
|
|
840
|
-
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
var _appManifestJSON$app$, _appManifestJSON$app;
|
|
845
|
-
const appManifestJSON = getAppManifestJSON();
|
|
846
|
-
const appID = (_appManifestJSON$app$ = (_appManifestJSON$app = appManifestJSON.app) === null || _appManifestJSON$app === void 0 ? void 0 : _appManifestJSON$app.id) !== null && _appManifestJSON$app$ !== void 0 ? _appManifestJSON$app$ : "";
|
|
847
|
-
if (!appID) {
|
|
848
|
-
throw new Error("app id is empty");
|
|
1020
|
+
return null;
|
|
1021
|
+
}).catch(lodashEs.noop);
|
|
1022
|
+
if (internalResult) {
|
|
1023
|
+
return internalResult;
|
|
849
1024
|
}
|
|
850
|
-
const
|
|
851
|
-
|
|
852
|
-
|
|
1025
|
+
const customResult = await axios.get(customManifestUrl).then((response) => {
|
|
1026
|
+
if (response.status === 200) {
|
|
1027
|
+
return customManifestUrl;
|
|
1028
|
+
}
|
|
1029
|
+
return null;
|
|
1030
|
+
}).catch(lodashEs.noop);
|
|
1031
|
+
if (customResult) {
|
|
1032
|
+
return customResult;
|
|
853
1033
|
}
|
|
854
|
-
return
|
|
855
|
-
appManifestJSON,
|
|
856
|
-
appID,
|
|
857
|
-
regionURL
|
|
858
|
-
};
|
|
1034
|
+
return null;
|
|
859
1035
|
};
|
|
860
|
-
const
|
|
1036
|
+
const install = async function() {
|
|
1037
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1038
|
+
args[_key] = arguments[_key];
|
|
1039
|
+
}
|
|
861
1040
|
const {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return `${url.protocol}//${url.host}/platform/app/relay/dispatch/${appID}`;
|
|
867
|
-
};
|
|
868
|
-
const invokeTunnel = async (port) => {
|
|
1041
|
+
options
|
|
1042
|
+
} = createOnesApp.getCommandOptions(args, installCommandArguments);
|
|
1043
|
+
const normalizedOptions = await normalize$8(options);
|
|
1044
|
+
lodashEs.noop(normalizedOptions);
|
|
869
1045
|
const {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
process
|
|
1046
|
+
app
|
|
1047
|
+
} = getAppManifestJSON();
|
|
1048
|
+
const appName = app.name;
|
|
1049
|
+
const manifestUrl = await getManifestUrl();
|
|
1050
|
+
if (!manifestUrl) {
|
|
1051
|
+
console.log(`App "${appName}" server not available!`);
|
|
1052
|
+
console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
|
|
1053
|
+
process.exit(1);
|
|
878
1054
|
}
|
|
879
|
-
|
|
880
|
-
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
881
|
-
const hostedToken = await getHostToken(regionURL, onesToken, appID, scopes);
|
|
882
|
-
process.env.ONES_HOSTED_TOKEN = hostedToken;
|
|
883
|
-
const client = new TunnelClient(port, regionURL, appID, hostedToken);
|
|
884
|
-
await client.connect();
|
|
885
|
-
const runnelUrl = await buildTunnelUrl();
|
|
886
|
-
console.log(`Relay endpoint: ${runnelUrl}`);
|
|
1055
|
+
await invokeInstall(manifestUrl);
|
|
887
1056
|
};
|
|
888
|
-
|
|
1057
|
+
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
1058
|
+
InstallOptions2["AUTO"] = "auto";
|
|
1059
|
+
InstallOptions2["TRUE"] = "true";
|
|
1060
|
+
InstallOptions2["FALSE"] = "false";
|
|
1061
|
+
return InstallOptions2;
|
|
1062
|
+
})(InstallOptions || {});
|
|
1063
|
+
const defaultInstall = InstallOptions.AUTO;
|
|
1064
|
+
const normalize$7 = async (options) => {
|
|
1065
|
+
var _options$install, _options$command;
|
|
1066
|
+
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
1067
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
1068
|
+
switch (true) {
|
|
1069
|
+
case install2 === InstallOptions.AUTO:
|
|
1070
|
+
break;
|
|
1071
|
+
case Boolean(install2):
|
|
1072
|
+
install2 = InstallOptions.TRUE;
|
|
1073
|
+
break;
|
|
1074
|
+
default:
|
|
1075
|
+
install2 = InstallOptions.FALSE;
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
return {
|
|
1079
|
+
install: install2,
|
|
1080
|
+
command
|
|
1081
|
+
};
|
|
1082
|
+
};
|
|
1083
|
+
const IDLE_MS = 2e3;
|
|
1084
|
+
function createReadyStatusPipes(onReady) {
|
|
1085
|
+
let readyTimer = null;
|
|
1086
|
+
let summaryPrinted = false;
|
|
1087
|
+
const scheduleReady = () => {
|
|
1088
|
+
if (summaryPrinted)
|
|
1089
|
+
return;
|
|
1090
|
+
if (readyTimer)
|
|
1091
|
+
clearTimeout(readyTimer);
|
|
1092
|
+
readyTimer = setTimeout(() => {
|
|
1093
|
+
readyTimer = null;
|
|
1094
|
+
if (!summaryPrinted) {
|
|
1095
|
+
summaryPrinted = true;
|
|
1096
|
+
onReady();
|
|
1097
|
+
}
|
|
1098
|
+
}, IDLE_MS);
|
|
1099
|
+
};
|
|
1100
|
+
const pipe = (stream, isStderr) => {
|
|
1101
|
+
const write = (chunk) => {
|
|
1102
|
+
if (isStderr)
|
|
1103
|
+
process.stderr.write(chunk);
|
|
1104
|
+
else
|
|
1105
|
+
process.stdout.write(chunk);
|
|
1106
|
+
};
|
|
1107
|
+
stream.on("data", (chunk) => {
|
|
1108
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1109
|
+
write(str);
|
|
1110
|
+
if (str.startsWith("[backend]") || str.startsWith("[web]")) {
|
|
1111
|
+
scheduleReady();
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
};
|
|
1115
|
+
return pipe;
|
|
1116
|
+
}
|
|
1117
|
+
const dev = async function() {
|
|
1118
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2;
|
|
889
1119
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
890
1120
|
args[_key] = arguments[_key];
|
|
891
1121
|
}
|
|
892
1122
|
const {
|
|
893
1123
|
options
|
|
894
|
-
} = createOnesApp.getCommandOptions(args,
|
|
895
|
-
const normalizedOptions = await normalize$
|
|
896
|
-
await
|
|
1124
|
+
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
1125
|
+
const normalizedOptions = await normalize$7(options);
|
|
1126
|
+
const appRcJSON = await getAppRcJSON();
|
|
1127
|
+
const appPackageJSON = getAppPackageJSON();
|
|
1128
|
+
const firstCommand = normalizedOptions.command || ((_appRcJSON$dev = appRcJSON.dev) === null || _appRcJSON$dev === void 0 || (_appRcJSON$dev = _appRcJSON$dev.command) === null || _appRcJSON$dev === void 0 ? void 0 : _appRcJSON$dev[0]) || ((_defaultAppRcJSON$dev = defaultAppRcJSON.dev) === null || _defaultAppRcJSON$dev === void 0 || (_defaultAppRcJSON$dev = _defaultAppRcJSON$dev.command) === null || _defaultAppRcJSON$dev === void 0 ? void 0 : _defaultAppRcJSON$dev[0]) || "";
|
|
1129
|
+
if (!firstCommand) {
|
|
1130
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
|
|
1131
|
+
}
|
|
1132
|
+
const currentCommand = normalizedOptions.command ? normalizedOptions.command.split(" ") : (_appRcJSON$dev$comman = (_appRcJSON$dev2 = appRcJSON.dev) === null || _appRcJSON$dev2 === void 0 ? void 0 : _appRcJSON$dev2.command) !== null && _appRcJSON$dev$comman !== void 0 ? _appRcJSON$dev$comman : [];
|
|
1133
|
+
const currentCommandString = currentCommand.join(" ");
|
|
1134
|
+
const defaultDevCommandString = defaultDevCommand.join(" ");
|
|
1135
|
+
if (currentCommandString === defaultDevCommandString) {
|
|
1136
|
+
var _appPackageJSON$scrip;
|
|
1137
|
+
if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
|
|
1138
|
+
return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
let enableTunnel = true;
|
|
1142
|
+
if (normalizedOptions.install === InstallOptions.TRUE)
|
|
1143
|
+
;
|
|
1144
|
+
else {
|
|
1145
|
+
enableTunnel = await checkTokenInfo();
|
|
1146
|
+
}
|
|
1147
|
+
const appManifestJSON = getAppManifestJSON();
|
|
1148
|
+
const {
|
|
1149
|
+
app,
|
|
1150
|
+
ones: ones2
|
|
1151
|
+
} = appManifestJSON;
|
|
1152
|
+
const appID = app.id;
|
|
1153
|
+
const config2 = getConfig();
|
|
1154
|
+
const ONES_HOSTED_PORT = await getPort({
|
|
1155
|
+
port: config2.defaultPort.hosted
|
|
1156
|
+
});
|
|
1157
|
+
const ONES_DEV_WEB_SERVER_PORT = await getPort({
|
|
1158
|
+
port: config2.defaultPort.devWebServer
|
|
1159
|
+
});
|
|
1160
|
+
const env2 = {
|
|
1161
|
+
...process.env,
|
|
1162
|
+
NODE_ENV: "development",
|
|
1163
|
+
ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
|
|
1164
|
+
ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
|
|
1165
|
+
ONES_HOSTED_TOKEN: "",
|
|
1166
|
+
ONES_HOSTED_APP_ID: "",
|
|
1167
|
+
ONES_HOSTED_BASE_URL: ""
|
|
1168
|
+
};
|
|
1169
|
+
if (enableTunnel) {
|
|
1170
|
+
var _ones$storage$entitie, _ones$storage;
|
|
1171
|
+
await invokeTunnel(ONES_HOSTED_PORT, {
|
|
1172
|
+
enableInternalManifestRoute: true,
|
|
1173
|
+
rebuildWhenExists: true
|
|
1174
|
+
});
|
|
1175
|
+
const regionURL = await getRegionURL();
|
|
1176
|
+
const ONES_HOSTED_TOKEN = await getHostToken();
|
|
1177
|
+
const ONES_HOSTED_APP_ID = appID;
|
|
1178
|
+
const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
|
|
1179
|
+
env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
|
|
1180
|
+
env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
|
|
1181
|
+
env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
|
|
1182
|
+
const entities = (_ones$storage$entitie = ones2 === null || ones2 === void 0 || (_ones$storage = ones2.storage) === null || _ones$storage === void 0 ? void 0 : _ones$storage.entities) !== null && _ones$storage$entitie !== void 0 ? _ones$storage$entitie : [];
|
|
1183
|
+
if (entities.length > 0) {
|
|
1184
|
+
await fetchHostedAbilityStorageDevDeclare({
|
|
1185
|
+
app_id: appID,
|
|
1186
|
+
cleanup_legacy: false,
|
|
1187
|
+
opkx_content: appManifestJSON
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
const onReady = async () => {
|
|
1192
|
+
const appName = app.name;
|
|
1193
|
+
let manifestUrl = "";
|
|
1194
|
+
console.log("");
|
|
1195
|
+
console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
|
|
1196
|
+
if (enableTunnel) {
|
|
1197
|
+
const runnelUrl = await buildTunnelUrl();
|
|
1198
|
+
console.log(`URL: ${runnelUrl}`);
|
|
1199
|
+
manifestUrl = `${runnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1200
|
+
}
|
|
1201
|
+
console.log("Docs site: https://open.ones.com/");
|
|
1202
|
+
console.log(`App "${appName}" server is ready!`);
|
|
1203
|
+
console.log("");
|
|
1204
|
+
if (enableTunnel) {
|
|
1205
|
+
switch (normalizedOptions.install) {
|
|
1206
|
+
case InstallOptions.TRUE:
|
|
1207
|
+
await invokeInstall(manifestUrl);
|
|
1208
|
+
break;
|
|
1209
|
+
case InstallOptions.AUTO:
|
|
1210
|
+
{
|
|
1211
|
+
var _appList$data$0$insta, _appList$data;
|
|
1212
|
+
const appList = await fetchAppList(appID);
|
|
1213
|
+
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
1214
|
+
if (installationID) {
|
|
1215
|
+
await displayAppDetail(installationID);
|
|
1216
|
+
} else {
|
|
1217
|
+
await invokeInstall(manifestUrl);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
break;
|
|
1221
|
+
case InstallOptions.FALSE:
|
|
1222
|
+
break;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
const cwd = getAppWorkspacePath();
|
|
1227
|
+
const child = node_child_process.spawn(firstCommand, currentCommand.slice(1), {
|
|
1228
|
+
cwd,
|
|
1229
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
1230
|
+
env: env2,
|
|
1231
|
+
shell: true
|
|
1232
|
+
});
|
|
1233
|
+
const pipe = createReadyStatusPipes(onReady);
|
|
1234
|
+
if (child.stdout)
|
|
1235
|
+
pipe(child.stdout, false);
|
|
1236
|
+
if (child.stderr)
|
|
1237
|
+
pipe(child.stderr, true);
|
|
1238
|
+
const cleanup = () => {
|
|
1239
|
+
child.kill();
|
|
1240
|
+
};
|
|
1241
|
+
const onSignal = () => {
|
|
1242
|
+
cleanup();
|
|
1243
|
+
process.exit(128 + 2);
|
|
1244
|
+
};
|
|
1245
|
+
process.on("SIGINT", onSignal);
|
|
1246
|
+
process.on("SIGTERM", onSignal);
|
|
1247
|
+
await new Promise((resolve) => {
|
|
1248
|
+
child.on("exit", () => {
|
|
1249
|
+
cleanup();
|
|
1250
|
+
process.off("SIGINT", onSignal);
|
|
1251
|
+
process.off("SIGTERM", onSignal);
|
|
1252
|
+
resolve();
|
|
1253
|
+
});
|
|
1254
|
+
});
|
|
897
1255
|
};
|
|
898
1256
|
function createPromise() {
|
|
899
1257
|
let resolve;
|
|
@@ -915,7 +1273,7 @@ const sleep = (number) => {
|
|
|
915
1273
|
};
|
|
916
1274
|
const isURL = /^https?:\/\//;
|
|
917
1275
|
const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
|
|
918
|
-
const normalize$
|
|
1276
|
+
const normalize$6 = async (options) => {
|
|
919
1277
|
const baseURLInput = options.baseURL;
|
|
920
1278
|
if (baseURLInput)
|
|
921
1279
|
;
|
|
@@ -952,14 +1310,14 @@ const login = async function() {
|
|
|
952
1310
|
const {
|
|
953
1311
|
options
|
|
954
1312
|
} = createOnesApp.getCommandOptions(args, loginCommandArguments);
|
|
955
|
-
const normalizedOptions = await normalize$
|
|
1313
|
+
const normalizedOptions = await normalize$6(options);
|
|
956
1314
|
const base = normalizedOptions.baseURL;
|
|
957
1315
|
const path = "project/oauth2.html";
|
|
958
1316
|
const config2 = getConfig();
|
|
959
1317
|
const port = await getPort({
|
|
960
1318
|
port: config2.defaultPort.login
|
|
961
1319
|
});
|
|
962
|
-
const uuid$1 = uuid.
|
|
1320
|
+
const uuid$1 = uuid.v4();
|
|
963
1321
|
const search = new URLSearchParams();
|
|
964
1322
|
search.set("redirect_path", "/developer/cli");
|
|
965
1323
|
search.set("redirect_url", `http://localhost:${port}`);
|
|
@@ -1036,7 +1394,7 @@ const login = async function() {
|
|
|
1036
1394
|
ora("Waiting for authorization...").start();
|
|
1037
1395
|
await open(url);
|
|
1038
1396
|
};
|
|
1039
|
-
const normalize$
|
|
1397
|
+
const normalize$5 = async (options) => {
|
|
1040
1398
|
lodashEs.noop(options);
|
|
1041
1399
|
return {};
|
|
1042
1400
|
};
|
|
@@ -1047,12 +1405,12 @@ const logout = async function() {
|
|
|
1047
1405
|
const {
|
|
1048
1406
|
options
|
|
1049
1407
|
} = createOnesApp.getCommandOptions(args, logoutCommandArguments);
|
|
1050
|
-
const normalizedOptions = await normalize$
|
|
1408
|
+
const normalizedOptions = await normalize$5(options);
|
|
1051
1409
|
lodashEs.noop(normalizedOptions);
|
|
1052
1410
|
await setStore({});
|
|
1053
1411
|
console.log("Logged out successfully!");
|
|
1054
1412
|
};
|
|
1055
|
-
const normalize$
|
|
1413
|
+
const normalize$4 = async (options) => {
|
|
1056
1414
|
lodashEs.noop(options);
|
|
1057
1415
|
return {};
|
|
1058
1416
|
};
|
|
@@ -1064,47 +1422,20 @@ const whoami = async function() {
|
|
|
1064
1422
|
const {
|
|
1065
1423
|
options
|
|
1066
1424
|
} = createOnesApp.getCommandOptions(args, whoamiCommandArguments);
|
|
1067
|
-
const normalizedOptions = await normalize$
|
|
1425
|
+
const normalizedOptions = await normalize$4(options);
|
|
1068
1426
|
lodashEs.noop(normalizedOptions);
|
|
1069
1427
|
const baseURL = await getBaseURL();
|
|
1070
1428
|
const tokenInfo = await fetchTokenInfo();
|
|
1071
1429
|
const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
|
|
1072
1430
|
const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
|
|
1073
1431
|
if (name2 && email) {
|
|
1074
|
-
console.log(
|
|
1432
|
+
console.log(`User: ${name2}`);
|
|
1433
|
+
console.log(`Email: ${email}`);
|
|
1075
1434
|
console.log(`ONES: ${baseURL}`);
|
|
1076
1435
|
} else {
|
|
1077
1436
|
consoleUnauthorizedMessage();
|
|
1078
1437
|
}
|
|
1079
1438
|
};
|
|
1080
|
-
const normalize$4 = async (options) => {
|
|
1081
|
-
lodashEs.noop(options);
|
|
1082
|
-
return {};
|
|
1083
|
-
};
|
|
1084
|
-
const invokeInstall = async () => {
|
|
1085
|
-
const runnelUrl = await buildTunnelUrl();
|
|
1086
|
-
const result = await fetchAppInstall({
|
|
1087
|
-
manifest_url: `${runnelUrl}${ONES_CLI_MANIFEST_PATH}`
|
|
1088
|
-
});
|
|
1089
|
-
return result;
|
|
1090
|
-
};
|
|
1091
|
-
const install = async function() {
|
|
1092
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1093
|
-
args[_key] = arguments[_key];
|
|
1094
|
-
}
|
|
1095
|
-
const {
|
|
1096
|
-
options
|
|
1097
|
-
} = createOnesApp.getCommandOptions(args, installCommandArguments);
|
|
1098
|
-
const normalizedOptions = await normalize$4(options);
|
|
1099
|
-
lodashEs.noop(normalizedOptions);
|
|
1100
|
-
await invokeTunnel(getConfig().defaultPort.tunnel);
|
|
1101
|
-
const result = await invokeInstall();
|
|
1102
|
-
if (result.code === "OK") {
|
|
1103
|
-
console.log("App installed successfully!");
|
|
1104
|
-
} else {
|
|
1105
|
-
console.error(result);
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
1439
|
const normalize$3 = async (options) => {
|
|
1109
1440
|
lodashEs.noop(options);
|
|
1110
1441
|
return {};
|
|
@@ -1118,11 +1449,13 @@ const enable = async function() {
|
|
|
1118
1449
|
} = createOnesApp.getCommandOptions(args, enableCommandArguments);
|
|
1119
1450
|
const normalizedOptions = await normalize$3(options);
|
|
1120
1451
|
lodashEs.noop(normalizedOptions);
|
|
1452
|
+
const appName = getAppManifestJSON().app.name;
|
|
1121
1453
|
const result = await fetchAppEnable();
|
|
1122
1454
|
if (result.code === "OK") {
|
|
1123
|
-
console.log(
|
|
1455
|
+
console.log(`App "${appName}" enabled successfully!`);
|
|
1124
1456
|
} else {
|
|
1125
|
-
console.
|
|
1457
|
+
console.log(`App "${appName}" enabled failed!`);
|
|
1458
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1126
1459
|
}
|
|
1127
1460
|
};
|
|
1128
1461
|
const normalize$2 = async (options) => {
|
|
@@ -1138,11 +1471,13 @@ const disable = async function() {
|
|
|
1138
1471
|
} = createOnesApp.getCommandOptions(args, disableCommandArguments);
|
|
1139
1472
|
const normalizedOptions = await normalize$2(options);
|
|
1140
1473
|
lodashEs.noop(normalizedOptions);
|
|
1474
|
+
const appName = getAppManifestJSON().app.name;
|
|
1141
1475
|
const result = await fetchAppDisable();
|
|
1142
1476
|
if (result.code === "OK") {
|
|
1143
|
-
console.log(
|
|
1477
|
+
console.log(`App "${appName}" disabled successfully!`);
|
|
1144
1478
|
} else {
|
|
1145
|
-
console.
|
|
1479
|
+
console.log(`App "${appName}" disabled failed!`);
|
|
1480
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1146
1481
|
}
|
|
1147
1482
|
};
|
|
1148
1483
|
const normalize$1 = async (options) => {
|
|
@@ -1158,11 +1493,13 @@ const uninstall = async function() {
|
|
|
1158
1493
|
} = createOnesApp.getCommandOptions(args, uninstallCommandArguments);
|
|
1159
1494
|
const normalizedOptions = await normalize$1(options);
|
|
1160
1495
|
lodashEs.noop(normalizedOptions);
|
|
1496
|
+
const appName = getAppManifestJSON().app.name;
|
|
1161
1497
|
const result = await fetchAppUninstall();
|
|
1162
1498
|
if (result.code === "OK") {
|
|
1163
|
-
console.log(
|
|
1499
|
+
console.log(`App "${appName}" uninstalled successfully!`);
|
|
1164
1500
|
} else {
|
|
1165
|
-
console.
|
|
1501
|
+
console.log(`App "${appName}" uninstalled failed!`);
|
|
1502
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1166
1503
|
}
|
|
1167
1504
|
};
|
|
1168
1505
|
const normalize = async (options) => {
|
|
@@ -1184,7 +1521,7 @@ const $build = new commander.Command("build").description(i18n.t("desc.build")).
|
|
|
1184
1521
|
createOnesApp.addCommandUsage($build);
|
|
1185
1522
|
createOnesApp.addCommandOutput($build);
|
|
1186
1523
|
const devCommandArguments = [];
|
|
1187
|
-
const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).action(dev);
|
|
1524
|
+
const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).option("-c, --command [string]", i18n.t("desc.dev.command")).action(dev);
|
|
1188
1525
|
createOnesApp.addCommandUsage($dev);
|
|
1189
1526
|
createOnesApp.addCommandOutput($dev);
|
|
1190
1527
|
const tunnelCommandArguments = ["port"];
|
|
@@ -1228,7 +1565,11 @@ const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"
|
|
|
1228
1565
|
createOnesApp.addCommandUsage($legacy);
|
|
1229
1566
|
createOnesApp.addCommandOutput($legacy);
|
|
1230
1567
|
const ones = new commander.Command("ones");
|
|
1231
|
-
|
|
1568
|
+
const version = `${getPackageJSON().version}`;
|
|
1569
|
+
const env = `${version} Node/${process.version}`;
|
|
1570
|
+
ones.description(i18n.t("desc.ones", {
|
|
1571
|
+
env
|
|
1572
|
+
})).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
|
|
1232
1573
|
visibleCommands: (cmd) => {
|
|
1233
1574
|
const blackList = ["legacy"];
|
|
1234
1575
|
return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
|
|
@@ -1241,8 +1582,8 @@ createOnesApp.addCommandOutput(ones);
|
|
|
1241
1582
|
const runCommandONES = async () => {
|
|
1242
1583
|
const command = ones;
|
|
1243
1584
|
createOnesApp.setContext("command", command);
|
|
1244
|
-
const
|
|
1245
|
-
command.version(version);
|
|
1585
|
+
const version2 = `${getPackageJSON().version}`;
|
|
1586
|
+
command.version(version2, "-v, --version");
|
|
1246
1587
|
await command.parse();
|
|
1247
1588
|
};
|
|
1248
1589
|
exports.runCommandONES = runCommandONES;
|