@ones-open/cli 1.0.1-21670.1926 → 1.0.1-21776.1956
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 +474 -216
- package/dist/index.js +475 -217
- 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 +3 -1
- 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 +2 -1
- 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 +12 -0
- 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/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
18
|
const axios = require("axios");
|
|
18
19
|
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
19
|
-
const _defineProperty = require("@babel/runtime-corejs3/helpers/defineProperty");
|
|
20
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
|
|
@@ -97,6 +98,7 @@ var ErrorCode = ((ErrorCode2) => {
|
|
|
97
98
|
ErrorCode2["STORE_PERMISSION"] = "E12";
|
|
98
99
|
ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
|
|
99
100
|
ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
|
|
101
|
+
ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
|
|
100
102
|
return ErrorCode2;
|
|
101
103
|
})(ErrorCode || {});
|
|
102
104
|
const getPublicPath = () => {
|
|
@@ -133,8 +135,8 @@ const getAppPackageJSON = () => {
|
|
|
133
135
|
const json = JSON.parse(string);
|
|
134
136
|
return createOnesApp.AppPackageJSONSchema.parse(json);
|
|
135
137
|
} catch (error) {
|
|
136
|
-
|
|
137
|
-
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}`);
|
|
138
140
|
}
|
|
139
141
|
};
|
|
140
142
|
const getAppManifestJSONPath = () => {
|
|
@@ -149,13 +151,14 @@ const getAppManifestJSON = () => {
|
|
|
149
151
|
const json = JSON.parse(string);
|
|
150
152
|
return createOnesApp.AppManifestJSONSchema.parse(json);
|
|
151
153
|
} catch (error) {
|
|
152
|
-
|
|
153
|
-
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}`);
|
|
154
156
|
}
|
|
155
157
|
};
|
|
158
|
+
const defaultDevCommand = ["npm", "run", "dev"];
|
|
156
159
|
const defaultAppRcJSON = {
|
|
157
160
|
dev: {
|
|
158
|
-
command:
|
|
161
|
+
command: defaultDevCommand
|
|
159
162
|
}
|
|
160
163
|
};
|
|
161
164
|
let storeAppRcJSON = null;
|
|
@@ -206,8 +209,12 @@ const normalize$a = async (options) => {
|
|
|
206
209
|
output
|
|
207
210
|
};
|
|
208
211
|
};
|
|
212
|
+
const {
|
|
213
|
+
existsSync,
|
|
214
|
+
ensureDirSync
|
|
215
|
+
} = fse;
|
|
209
216
|
const build = async function() {
|
|
210
|
-
var
|
|
217
|
+
var _appRcJSON$build$comp, _appRcJSON$build;
|
|
211
218
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
212
219
|
args[_key] = arguments[_key];
|
|
213
220
|
}
|
|
@@ -215,22 +222,37 @@ const build = async function() {
|
|
|
215
222
|
options
|
|
216
223
|
} = createOnesApp.getCommandOptions(args, buildCommandArguments);
|
|
217
224
|
const normalizedOptions = await normalize$a(options);
|
|
218
|
-
const appPackageJSON = getAppPackageJSON();
|
|
219
225
|
const appManifestJSON = getAppManifestJSON();
|
|
220
226
|
const appRcJSON = await getAppRcJSON();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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);
|
|
229
244
|
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
245
|
+
} else {
|
|
246
|
+
return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
|
|
247
|
+
}
|
|
233
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 : [];
|
|
234
256
|
const archive = archiver("zip", {
|
|
235
257
|
zlib: {
|
|
236
258
|
level: 9
|
|
@@ -253,12 +275,13 @@ const build = async function() {
|
|
|
253
275
|
});
|
|
254
276
|
archive.on("finish", () => {
|
|
255
277
|
process.stdout.write("\n");
|
|
256
|
-
console.log(
|
|
257
|
-
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}`);
|
|
258
283
|
});
|
|
259
|
-
const outputStream = node_fs.createWriteStream(normalizedOptions.output);
|
|
260
284
|
archive.pipe(outputStream);
|
|
261
|
-
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 : [];
|
|
262
285
|
files.forEach((file) => {
|
|
263
286
|
archive.glob(file, {
|
|
264
287
|
cwd: getAppWorkspacePath()
|
|
@@ -272,7 +295,8 @@ const build = async function() {
|
|
|
272
295
|
const config = {
|
|
273
296
|
defaultPort: {
|
|
274
297
|
login: 8200,
|
|
275
|
-
|
|
298
|
+
hosted: 8201,
|
|
299
|
+
devWebServer: 8202
|
|
276
300
|
}
|
|
277
301
|
};
|
|
278
302
|
const getConfig = () => config;
|
|
@@ -321,11 +345,11 @@ const getStore = async () => {
|
|
|
321
345
|
const setStore = async (store) => {
|
|
322
346
|
try {
|
|
323
347
|
await ensureFile(storePath);
|
|
324
|
-
const
|
|
348
|
+
const version2 = `${getPackageJSON().version}`;
|
|
325
349
|
const timestamp = Date.now();
|
|
326
350
|
return await writeJSON(storePath, {
|
|
327
351
|
...store,
|
|
328
|
-
version,
|
|
352
|
+
version: version2,
|
|
329
353
|
timestamp
|
|
330
354
|
}, {
|
|
331
355
|
encoding: "utf8"
|
|
@@ -382,9 +406,15 @@ const getHostToken = async () => {
|
|
|
382
406
|
const store = await getStore();
|
|
383
407
|
return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
|
|
384
408
|
};
|
|
409
|
+
const setHostToken = async (token) => {
|
|
410
|
+
return mergeStore({
|
|
411
|
+
host_token: token
|
|
412
|
+
});
|
|
413
|
+
};
|
|
385
414
|
const API = {
|
|
386
415
|
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
387
416
|
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
417
|
+
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/dev_declare",
|
|
388
418
|
APP_LIST: "/platform/api/app/list",
|
|
389
419
|
APP_INSTALL: "/platform/api/app/install",
|
|
390
420
|
APP_UPGRADE: "/platform/api/app/upgrade",
|
|
@@ -392,6 +422,7 @@ const API = {
|
|
|
392
422
|
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
393
423
|
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
394
424
|
};
|
|
425
|
+
const REQUEST_TIMEOUT = 1e4;
|
|
395
426
|
const getPath = (path, map2) => {
|
|
396
427
|
var _context;
|
|
397
428
|
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
@@ -404,6 +435,11 @@ const getPath = (path, map2) => {
|
|
|
404
435
|
const consoleUnauthorizedMessage = () => {
|
|
405
436
|
console.log("Not logged in");
|
|
406
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);
|
|
407
443
|
};
|
|
408
444
|
const getURL = async (path, pathMap, queryMap) => {
|
|
409
445
|
const base = await getRegionURL();
|
|
@@ -412,7 +448,6 @@ const getURL = async (path, pathMap, queryMap) => {
|
|
|
412
448
|
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
413
449
|
}
|
|
414
450
|
consoleUnauthorizedMessage();
|
|
415
|
-
process$1.exit(1);
|
|
416
451
|
};
|
|
417
452
|
const getHeaders = async (value) => {
|
|
418
453
|
const token = await getONESToken();
|
|
@@ -422,16 +457,24 @@ const getHeaders = async (value) => {
|
|
|
422
457
|
}, value);
|
|
423
458
|
}
|
|
424
459
|
consoleUnauthorizedMessage();
|
|
425
|
-
process
|
|
460
|
+
process.exit(1);
|
|
426
461
|
};
|
|
427
462
|
const handleError = (error) => {
|
|
428
|
-
var _error$response;
|
|
463
|
+
var _error$response, _error$response2;
|
|
429
464
|
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
430
465
|
console.log(error.response.statusText);
|
|
431
466
|
consoleUnauthorizedMessage();
|
|
432
|
-
|
|
433
|
-
|
|
467
|
+
process.exit(1);
|
|
468
|
+
}
|
|
469
|
+
if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
|
|
470
|
+
try {
|
|
471
|
+
const message = JSON.stringify(error.response.data, null, 2);
|
|
472
|
+
console.error(message);
|
|
473
|
+
process.exit(1);
|
|
474
|
+
} catch (error2) {
|
|
475
|
+
}
|
|
434
476
|
}
|
|
477
|
+
console.error(error);
|
|
435
478
|
return {};
|
|
436
479
|
};
|
|
437
480
|
const fetchAppBase = async (params) => {
|
|
@@ -441,7 +484,8 @@ const fetchAppBase = async (params) => {
|
|
|
441
484
|
const response = await axios({
|
|
442
485
|
...params,
|
|
443
486
|
url,
|
|
444
|
-
headers
|
|
487
|
+
headers,
|
|
488
|
+
timeout: REQUEST_TIMEOUT
|
|
445
489
|
});
|
|
446
490
|
return response.data;
|
|
447
491
|
};
|
|
@@ -467,6 +511,13 @@ const fetchHostedToken = async (data) => {
|
|
|
467
511
|
data
|
|
468
512
|
}).catch(handleError);
|
|
469
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
|
+
};
|
|
470
521
|
const fetchAppInstall = async (data) => {
|
|
471
522
|
var _appList$data$0$insta, _appList$data;
|
|
472
523
|
const appID = getAppManifestJSON().app.id;
|
|
@@ -484,43 +535,76 @@ const fetchAppUninstall = async () => {
|
|
|
484
535
|
const appID = getAppManifestJSON().app.id;
|
|
485
536
|
const appList = await fetchAppList(appID);
|
|
486
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 : "";
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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);
|
|
494
549
|
};
|
|
495
550
|
const fetchAppEnable = async () => {
|
|
496
551
|
var _appList$data$0$insta3, _appList$data3;
|
|
497
552
|
const appID = getAppManifestJSON().app.id;
|
|
498
553
|
const appList = await fetchAppList(appID);
|
|
499
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 : "";
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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);
|
|
507
566
|
};
|
|
508
567
|
const fetchAppDisable = async () => {
|
|
509
568
|
var _appList$data$0$insta4, _appList$data4;
|
|
510
569
|
const appID = getAppManifestJSON().app.id;
|
|
511
570
|
const appList = await fetchAppList(appID);
|
|
512
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 : "";
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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;
|
|
520
601
|
};
|
|
521
602
|
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
522
603
|
const minPortNumber = 1;
|
|
523
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;
|
|
524
608
|
const normalize$9 = async (options) => {
|
|
525
609
|
const portInput = options.port;
|
|
526
610
|
if (portInput)
|
|
@@ -543,14 +627,62 @@ const normalize$9 = async (options) => {
|
|
|
543
627
|
port
|
|
544
628
|
};
|
|
545
629
|
};
|
|
546
|
-
const
|
|
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
|
+
};
|
|
547
675
|
class TunnelClient {
|
|
548
676
|
constructor(localPort, baseUrl, appID, hostedToken) {
|
|
549
|
-
|
|
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;
|
|
550
680
|
this.localPort = localPort;
|
|
551
681
|
this.baseUrl = baseUrl;
|
|
552
682
|
this.appID = appID;
|
|
553
683
|
this.hostedToken = hostedToken;
|
|
684
|
+
this.enableInternalManifestRoute = enableInternalManifestRoute;
|
|
685
|
+
this.replaceExisting = replaceExisting;
|
|
554
686
|
}
|
|
555
687
|
async connect() {
|
|
556
688
|
const proxyUrl = this.buildProxyUrl();
|
|
@@ -588,6 +720,7 @@ class TunnelClient {
|
|
|
588
720
|
const url = new URL("/platform/app/relay/", this.baseUrl);
|
|
589
721
|
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
590
722
|
url.searchParams.set("app_id", this.appID);
|
|
723
|
+
url.searchParams.set("replace_existing", String(this.replaceExisting));
|
|
591
724
|
return url.toString();
|
|
592
725
|
}
|
|
593
726
|
parseMessage(data) {
|
|
@@ -608,7 +741,7 @@ class TunnelClient {
|
|
|
608
741
|
if (!request) {
|
|
609
742
|
return;
|
|
610
743
|
}
|
|
611
|
-
if (request.path ===
|
|
744
|
+
if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
|
|
612
745
|
const appManifest = getAppManifestJSON().app;
|
|
613
746
|
const baseURL = await buildTunnelUrl();
|
|
614
747
|
const reply = {
|
|
@@ -791,61 +924,16 @@ class TunnelClient {
|
|
|
791
924
|
return null;
|
|
792
925
|
}
|
|
793
926
|
}
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
const appManifestJSON = getAppManifestJSON();
|
|
798
|
-
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$ : "";
|
|
799
|
-
if (!appID) {
|
|
800
|
-
throw new Error("app id is empty");
|
|
801
|
-
}
|
|
802
|
-
const regionURL = await getRegionURL();
|
|
803
|
-
if (!regionURL) {
|
|
804
|
-
throw new Error("region url is empty");
|
|
805
|
-
}
|
|
806
|
-
return {
|
|
807
|
-
appManifestJSON,
|
|
808
|
-
appID,
|
|
809
|
-
regionURL
|
|
810
|
-
};
|
|
811
|
-
};
|
|
812
|
-
const getHostedTokenScopes = (ones2) => {
|
|
813
|
-
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
814
|
-
if (!storage) {
|
|
815
|
-
return [];
|
|
816
|
-
}
|
|
817
|
-
const scopes = /* @__PURE__ */ new Set();
|
|
818
|
-
if (Array.isArray(storage.entities) && storage.entities.length > 0) {
|
|
819
|
-
scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
|
|
820
|
-
}
|
|
821
|
-
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
822
|
-
scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
|
|
823
|
-
}
|
|
824
|
-
return Array.from(scopes);
|
|
825
|
-
};
|
|
826
|
-
const getRelayScope = () => {
|
|
827
|
-
return createOnesApp.HostedTokenScope.RELAY;
|
|
828
|
-
};
|
|
829
|
-
const buildTunnelUrl = async () => {
|
|
830
|
-
const {
|
|
831
|
-
appID,
|
|
832
|
-
regionURL
|
|
833
|
-
} = await buildTunnelContext();
|
|
834
|
-
const url = new URL(regionURL);
|
|
835
|
-
return `${url.protocol}//${url.host}/platform/app/relay/dispatch/${appID}`;
|
|
836
|
-
};
|
|
837
|
-
const invokeTunnel = async (port) => {
|
|
838
|
-
var _hostedTokenResponse$;
|
|
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] : {};
|
|
839
930
|
const {
|
|
840
931
|
appManifestJSON,
|
|
841
932
|
appID,
|
|
842
933
|
regionURL
|
|
843
|
-
} = await
|
|
844
|
-
const
|
|
845
|
-
|
|
846
|
-
consoleUnauthorizedMessage();
|
|
847
|
-
process$1.exit(1);
|
|
848
|
-
}
|
|
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;
|
|
849
937
|
const storageScopes = getHostedTokenScopes(appManifestJSON.ones);
|
|
850
938
|
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
851
939
|
const hostedTokenResponse = await fetchHostedToken({
|
|
@@ -856,11 +944,9 @@ const invokeTunnel = async (port) => {
|
|
|
856
944
|
if (!hostedToken) {
|
|
857
945
|
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
858
946
|
}
|
|
859
|
-
|
|
860
|
-
const client = new TunnelClient(port, regionURL, appID, hostedToken);
|
|
947
|
+
await setHostToken(hostedToken);
|
|
948
|
+
const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
|
|
861
949
|
await client.connect();
|
|
862
|
-
const runnelUrl = await buildTunnelUrl();
|
|
863
|
-
console.log(`Relay endpoint: ${runnelUrl}`);
|
|
864
950
|
};
|
|
865
951
|
const tunnel = async function() {
|
|
866
952
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -870,18 +956,82 @@ const tunnel = async function() {
|
|
|
870
956
|
options
|
|
871
957
|
} = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
|
|
872
958
|
const normalizedOptions = await normalize$9(options);
|
|
873
|
-
|
|
959
|
+
const port = Number(normalizedOptions.port);
|
|
960
|
+
await invokeTunnel(port, {
|
|
961
|
+
enableInternalManifestRoute: false,
|
|
962
|
+
rebuildWhenExists: true
|
|
963
|
+
});
|
|
964
|
+
const runnelUrl = await buildTunnelUrl();
|
|
965
|
+
console.log(`Relay endpoint: ${runnelUrl}`);
|
|
874
966
|
};
|
|
875
967
|
const normalize$8 = async (options) => {
|
|
876
968
|
lodashEs.noop(options);
|
|
877
969
|
return {};
|
|
878
970
|
};
|
|
879
|
-
const
|
|
880
|
-
|
|
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
|
+
}
|
|
986
|
+
};
|
|
987
|
+
const invokeInstall = async (manifestUrl) => {
|
|
988
|
+
const {
|
|
989
|
+
app
|
|
990
|
+
} = getAppManifestJSON();
|
|
991
|
+
const appName = app.name;
|
|
992
|
+
const appID = app.id;
|
|
881
993
|
const result = await fetchAppInstall({
|
|
882
|
-
manifest_url:
|
|
994
|
+
manifest_url: manifestUrl,
|
|
995
|
+
options: {
|
|
996
|
+
enable: true
|
|
997
|
+
}
|
|
883
998
|
});
|
|
884
|
-
|
|
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);
|
|
1006
|
+
}
|
|
1007
|
+
} else {
|
|
1008
|
+
console.log(`App "${appName}" installed failed!`);
|
|
1009
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
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;
|
|
1019
|
+
}
|
|
1020
|
+
return null;
|
|
1021
|
+
}).catch(lodashEs.noop);
|
|
1022
|
+
if (internalResult) {
|
|
1023
|
+
return internalResult;
|
|
1024
|
+
}
|
|
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;
|
|
1033
|
+
}
|
|
1034
|
+
return null;
|
|
885
1035
|
};
|
|
886
1036
|
const install = async function() {
|
|
887
1037
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -892,33 +1042,17 @@ const install = async function() {
|
|
|
892
1042
|
} = createOnesApp.getCommandOptions(args, installCommandArguments);
|
|
893
1043
|
const normalizedOptions = await normalize$8(options);
|
|
894
1044
|
lodashEs.noop(normalizedOptions);
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
905
|
-
const tokenInfo = await fetchTokenInfo();
|
|
906
|
-
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 : "";
|
|
907
|
-
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 : "";
|
|
908
|
-
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;
|
|
909
|
-
const baseURL = await getBaseURL();
|
|
910
|
-
if (isOrgVisible && orgUUID) {
|
|
911
|
-
const url = `${baseURL}/project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
912
|
-
console.log(`See App detail: ${url}`);
|
|
913
|
-
}
|
|
914
|
-
if (!isOrgVisible && teamUUID) {
|
|
915
|
-
const url = `${baseURL}/project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
916
|
-
console.log(`See App detail: ${url}`);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
} else {
|
|
920
|
-
console.error(result);
|
|
1045
|
+
const {
|
|
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);
|
|
921
1054
|
}
|
|
1055
|
+
await invokeInstall(manifestUrl);
|
|
922
1056
|
};
|
|
923
1057
|
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
924
1058
|
InstallOptions2["AUTO"] = "auto";
|
|
@@ -928,8 +1062,9 @@ var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
|
928
1062
|
})(InstallOptions || {});
|
|
929
1063
|
const defaultInstall = InstallOptions.AUTO;
|
|
930
1064
|
const normalize$7 = async (options) => {
|
|
931
|
-
var _options$install;
|
|
1065
|
+
var _options$install, _options$command;
|
|
932
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 : "";
|
|
933
1068
|
switch (true) {
|
|
934
1069
|
case install2 === InstallOptions.AUTO:
|
|
935
1070
|
break;
|
|
@@ -941,11 +1076,46 @@ const normalize$7 = async (options) => {
|
|
|
941
1076
|
break;
|
|
942
1077
|
}
|
|
943
1078
|
return {
|
|
944
|
-
install: install2
|
|
1079
|
+
install: install2,
|
|
1080
|
+
command
|
|
945
1081
|
};
|
|
946
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
|
+
}
|
|
947
1117
|
const dev = async function() {
|
|
948
|
-
var
|
|
1118
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2;
|
|
949
1119
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
950
1120
|
args[_key] = arguments[_key];
|
|
951
1121
|
}
|
|
@@ -953,35 +1123,120 @@ const dev = async function() {
|
|
|
953
1123
|
options
|
|
954
1124
|
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
955
1125
|
const normalizedOptions = await normalize$7(options);
|
|
1126
|
+
const appRcJSON = await getAppRcJSON();
|
|
956
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
|
+
}
|
|
957
1147
|
const appManifestJSON = getAppManifestJSON();
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
const
|
|
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 = {
|
|
968
1161
|
...process.env,
|
|
969
1162
|
NODE_ENV: "development",
|
|
970
|
-
ONES_HOSTED_PORT: `${
|
|
971
|
-
|
|
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: ""
|
|
972
1168
|
};
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
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), {
|
|
978
1228
|
cwd,
|
|
979
|
-
stdio: "inherit",
|
|
980
|
-
env
|
|
1229
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
1230
|
+
env: env2,
|
|
1231
|
+
shell: true
|
|
981
1232
|
});
|
|
1233
|
+
const pipe = createReadyStatusPipes(onReady);
|
|
1234
|
+
if (child.stdout)
|
|
1235
|
+
pipe(child.stdout, false);
|
|
1236
|
+
if (child.stderr)
|
|
1237
|
+
pipe(child.stderr, true);
|
|
982
1238
|
const cleanup = () => {
|
|
983
|
-
|
|
984
|
-
devChild.kill();
|
|
1239
|
+
child.kill();
|
|
985
1240
|
};
|
|
986
1241
|
const onSignal = () => {
|
|
987
1242
|
cleanup();
|
|
@@ -989,16 +1244,8 @@ const dev = async function() {
|
|
|
989
1244
|
};
|
|
990
1245
|
process.on("SIGINT", onSignal);
|
|
991
1246
|
process.on("SIGTERM", onSignal);
|
|
992
|
-
console.log(`Local: http://localhost:${port}`);
|
|
993
|
-
if (normalizedOptions.install === InstallOptions.TRUE) {
|
|
994
|
-
setTimeout(() => {
|
|
995
|
-
invokeInstall().catch((error) => {
|
|
996
|
-
console.error(error);
|
|
997
|
-
});
|
|
998
|
-
}, 2e3);
|
|
999
|
-
}
|
|
1000
1247
|
await new Promise((resolve) => {
|
|
1001
|
-
|
|
1248
|
+
child.on("exit", () => {
|
|
1002
1249
|
cleanup();
|
|
1003
1250
|
process.off("SIGINT", onSignal);
|
|
1004
1251
|
process.off("SIGTERM", onSignal);
|
|
@@ -1182,7 +1429,8 @@ const whoami = async function() {
|
|
|
1182
1429
|
const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
|
|
1183
1430
|
const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
|
|
1184
1431
|
if (name2 && email) {
|
|
1185
|
-
console.log(
|
|
1432
|
+
console.log(`User: ${name2}`);
|
|
1433
|
+
console.log(`Email: ${email}`);
|
|
1186
1434
|
console.log(`ONES: ${baseURL}`);
|
|
1187
1435
|
} else {
|
|
1188
1436
|
consoleUnauthorizedMessage();
|
|
@@ -1201,11 +1449,13 @@ const enable = async function() {
|
|
|
1201
1449
|
} = createOnesApp.getCommandOptions(args, enableCommandArguments);
|
|
1202
1450
|
const normalizedOptions = await normalize$3(options);
|
|
1203
1451
|
lodashEs.noop(normalizedOptions);
|
|
1452
|
+
const appName = getAppManifestJSON().app.name;
|
|
1204
1453
|
const result = await fetchAppEnable();
|
|
1205
1454
|
if (result.code === "OK") {
|
|
1206
|
-
console.log(
|
|
1455
|
+
console.log(`App "${appName}" enabled successfully!`);
|
|
1207
1456
|
} else {
|
|
1208
|
-
console.
|
|
1457
|
+
console.log(`App "${appName}" enabled failed!`);
|
|
1458
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1209
1459
|
}
|
|
1210
1460
|
};
|
|
1211
1461
|
const normalize$2 = async (options) => {
|
|
@@ -1221,11 +1471,13 @@ const disable = async function() {
|
|
|
1221
1471
|
} = createOnesApp.getCommandOptions(args, disableCommandArguments);
|
|
1222
1472
|
const normalizedOptions = await normalize$2(options);
|
|
1223
1473
|
lodashEs.noop(normalizedOptions);
|
|
1474
|
+
const appName = getAppManifestJSON().app.name;
|
|
1224
1475
|
const result = await fetchAppDisable();
|
|
1225
1476
|
if (result.code === "OK") {
|
|
1226
|
-
console.log(
|
|
1477
|
+
console.log(`App "${appName}" disabled successfully!`);
|
|
1227
1478
|
} else {
|
|
1228
|
-
console.
|
|
1479
|
+
console.log(`App "${appName}" disabled failed!`);
|
|
1480
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1229
1481
|
}
|
|
1230
1482
|
};
|
|
1231
1483
|
const normalize$1 = async (options) => {
|
|
@@ -1241,11 +1493,13 @@ const uninstall = async function() {
|
|
|
1241
1493
|
} = createOnesApp.getCommandOptions(args, uninstallCommandArguments);
|
|
1242
1494
|
const normalizedOptions = await normalize$1(options);
|
|
1243
1495
|
lodashEs.noop(normalizedOptions);
|
|
1496
|
+
const appName = getAppManifestJSON().app.name;
|
|
1244
1497
|
const result = await fetchAppUninstall();
|
|
1245
1498
|
if (result.code === "OK") {
|
|
1246
|
-
console.log(
|
|
1499
|
+
console.log(`App "${appName}" uninstalled successfully!`);
|
|
1247
1500
|
} else {
|
|
1248
|
-
console.
|
|
1501
|
+
console.log(`App "${appName}" uninstalled failed!`);
|
|
1502
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1249
1503
|
}
|
|
1250
1504
|
};
|
|
1251
1505
|
const normalize = async (options) => {
|
|
@@ -1267,7 +1521,7 @@ const $build = new commander.Command("build").description(i18n.t("desc.build")).
|
|
|
1267
1521
|
createOnesApp.addCommandUsage($build);
|
|
1268
1522
|
createOnesApp.addCommandOutput($build);
|
|
1269
1523
|
const devCommandArguments = [];
|
|
1270
|
-
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);
|
|
1271
1525
|
createOnesApp.addCommandUsage($dev);
|
|
1272
1526
|
createOnesApp.addCommandOutput($dev);
|
|
1273
1527
|
const tunnelCommandArguments = ["port"];
|
|
@@ -1311,7 +1565,11 @@ const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"
|
|
|
1311
1565
|
createOnesApp.addCommandUsage($legacy);
|
|
1312
1566
|
createOnesApp.addCommandOutput($legacy);
|
|
1313
1567
|
const ones = new commander.Command("ones");
|
|
1314
|
-
|
|
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({
|
|
1315
1573
|
visibleCommands: (cmd) => {
|
|
1316
1574
|
const blackList = ["legacy"];
|
|
1317
1575
|
return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
|
|
@@ -1324,8 +1582,8 @@ createOnesApp.addCommandOutput(ones);
|
|
|
1324
1582
|
const runCommandONES = async () => {
|
|
1325
1583
|
const command = ones;
|
|
1326
1584
|
createOnesApp.setContext("command", command);
|
|
1327
|
-
const
|
|
1328
|
-
command.version(
|
|
1585
|
+
const version2 = `${getPackageJSON().version}`;
|
|
1586
|
+
command.version(version2, "-v, --version");
|
|
1329
1587
|
await command.parse();
|
|
1330
1588
|
};
|
|
1331
1589
|
exports.runCommandONES = runCommandONES;
|