@ones-open/cli 1.0.1-5596.1908 → 1.0.1-7400.1962

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.
Files changed (50) hide show
  1. package/dist/index.cjs +771 -488
  2. package/dist/index.js +773 -490
  3. package/dist/types/actions/build/index.d.ts.map +1 -1
  4. package/dist/types/actions/dev/index.d.ts.map +1 -1
  5. package/dist/types/actions/dev/normalize.d.ts.map +1 -1
  6. package/dist/types/actions/dev/types.d.ts +10 -0
  7. package/dist/types/actions/dev/types.d.ts.map +1 -0
  8. package/dist/types/actions/disable/index.d.ts.map +1 -1
  9. package/dist/types/actions/enable/index.d.ts.map +1 -1
  10. package/dist/types/actions/install/index.d.ts +1 -1
  11. package/dist/types/actions/install/index.d.ts.map +1 -1
  12. package/dist/types/actions/install/install.d.ts +2 -2
  13. package/dist/types/actions/install/install.d.ts.map +1 -1
  14. package/dist/types/actions/tunnel/consts.d.ts +3 -0
  15. package/dist/types/actions/tunnel/consts.d.ts.map +1 -1
  16. package/dist/types/actions/tunnel/index.d.ts +3 -1
  17. package/dist/types/actions/tunnel/index.d.ts.map +1 -1
  18. package/dist/types/actions/tunnel/tunnel-client.d.ts +3 -1
  19. package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -1
  20. package/dist/types/actions/tunnel/tunnel.d.ts +2 -3
  21. package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
  22. package/dist/types/actions/tunnel/types.d.ts +33 -0
  23. package/dist/types/actions/tunnel/types.d.ts.map +1 -0
  24. package/dist/types/actions/tunnel/utils.d.ts +7 -0
  25. package/dist/types/actions/tunnel/utils.d.ts.map +1 -0
  26. package/dist/types/actions/uninstall/index.d.ts.map +1 -1
  27. package/dist/types/actions/whoami/index.d.ts.map +1 -1
  28. package/dist/types/cli/index.d.ts.map +1 -1
  29. package/dist/types/command/dev/index.d.ts +1 -0
  30. package/dist/types/command/dev/index.d.ts.map +1 -1
  31. package/dist/types/common/config/types.d.ts +2 -1
  32. package/dist/types/common/config/types.d.ts.map +1 -1
  33. package/dist/types/common/config/utils.d.ts.map +1 -1
  34. package/dist/types/common/error/enums.d.ts +2 -1
  35. package/dist/types/common/error/enums.d.ts.map +1 -1
  36. package/dist/types/common/locales/en/index.d.ts +30 -28
  37. package/dist/types/common/locales/en/index.d.ts.map +1 -1
  38. package/dist/types/common/package/utils.d.ts +2 -0
  39. package/dist/types/common/package/utils.d.ts.map +1 -1
  40. package/dist/types/common/request/consts.d.ts +2 -0
  41. package/dist/types/common/request/consts.d.ts.map +1 -1
  42. package/dist/types/common/request/fetch.d.ts +3 -1
  43. package/dist/types/common/request/fetch.d.ts.map +1 -1
  44. package/dist/types/common/request/types.d.ts +20 -5
  45. package/dist/types/common/request/types.d.ts.map +1 -1
  46. package/dist/types/common/request/utils.d.ts +3 -2
  47. package/dist/types/common/request/utils.d.ts.map +1 -1
  48. package/package.json +3 -3
  49. package/dist/types/actions/tunnel/hosted-token.d.ts +0 -5
  50. 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 fse = require("fs-extra");
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": "cli for ones",
29
- "desc.build": "build the application",
30
- "desc.build.output": "specify the output file path",
31
- "desc.dev": "develop the application",
32
- "desc.dev.install": "whether to install the application",
33
- "desc.tunnel": "start a tunnel to the application",
34
- "desc.tunnel.port": "specify the port number for serve",
35
- "desc.login": "login to the environment",
36
- "desc.login.baseUrl": "specify the environment url for login",
37
- "desc.logout": "logout from the environment",
38
- "desc.whoami": "show the current user",
39
- "desc.app": "app command",
40
- "desc.install": "install the application",
41
- "desc.enable": "enable the application",
42
- "desc.disable": "disable the application",
43
- "desc.uninstall": "uninstall the application",
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 manifest json parse error",
51
- "error.build.scriptNotFound": "build script not found",
52
- "error.dev.scriptNotFound": "dev script not found",
53
- "error.store.permission": 'permission denied, please check the file permission with "{filePath}"',
54
- "error.hostedToken.requestFailed": "failed to request hosted token",
55
- "error.hostedToken.empty": "hosted token is empty"
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
- console.error(error);
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
- console.error(error);
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: ["npm run dev"]
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 _appPackageJSON$scrip, _appRcJSON$build$comp, _appRcJSON$build;
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,18 +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
- appManifestJSON.app.name;
222
- if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build) {
223
- node_child_process.spawnSync("npm", ["run", "build"], {
224
- cwd: getAppWorkspacePath(),
225
- stdio: "inherit"
226
- });
227
- } else {
228
- return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
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
+ }
229
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 : [];
230
256
  const archive = archiver("zip", {
231
257
  zlib: {
232
258
  level: 9
@@ -249,12 +275,13 @@ const build = async function() {
249
275
  });
250
276
  archive.on("finish", () => {
251
277
  process.stdout.write("\n");
252
- console.log(`Output file: ${normalizedOptions.output}`);
253
- console.log(`OPKX "${node_path.basename(normalizedOptions.output)}" created successfully!`);
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}`);
254
283
  });
255
- const outputStream = node_fs.createWriteStream(normalizedOptions.output);
256
284
  archive.pipe(outputStream);
257
- 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 : [];
258
285
  files.forEach((file) => {
259
286
  archive.glob(file, {
260
287
  cwd: getAppWorkspacePath()
@@ -268,113 +295,11 @@ const build = async function() {
268
295
  const config = {
269
296
  defaultPort: {
270
297
  login: 8200,
271
- tunnel: 8201
298
+ hosted: 8201,
299
+ devWebServer: 8202
272
300
  }
273
301
  };
274
302
  const getConfig = () => config;
275
- var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
276
- InstallOptions2["AUTO"] = "auto";
277
- InstallOptions2["TRUE"] = "true";
278
- InstallOptions2["FALSE"] = "false";
279
- return InstallOptions2;
280
- })(InstallOptions || {});
281
- const defaultInstall = InstallOptions.AUTO;
282
- const normalize$9 = async (options) => {
283
- var _options$install;
284
- let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
285
- switch (true) {
286
- case install2 === InstallOptions.AUTO:
287
- break;
288
- case Boolean(install2):
289
- install2 = InstallOptions.TRUE;
290
- break;
291
- default:
292
- install2 = InstallOptions.FALSE;
293
- break;
294
- }
295
- return {
296
- install: install2
297
- };
298
- };
299
- const dev = async function() {
300
- var _appPackageJSON$scrip;
301
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
302
- args[_key] = arguments[_key];
303
- }
304
- const {
305
- options
306
- } = createOnesApp.getCommandOptions(args, devCommandArguments);
307
- const normalizedOptions = await normalize$9(options);
308
- const appPackageJSON = getAppPackageJSON();
309
- const appManifestJSON = getAppManifestJSON();
310
- const appRcJSON = getAppRcJSON();
311
- lodashEs.noop(appManifestJSON);
312
- lodashEs.noop(appRcJSON);
313
- if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
314
- return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
315
- }
316
- const port = getConfig().defaultPort.tunnel;
317
- const cwd = getAppWorkspacePath();
318
- const env = {
319
- ...process.env,
320
- ONES_HOSTED_PORT: `${port}`
321
- };
322
- const tunnelChild = node_child_process.spawn("ones", ["tunnel", String(port)], {
323
- cwd,
324
- stdio: "inherit"
325
- });
326
- const devChild = node_child_process.spawn("npm", ["run", "dev"], {
327
- cwd,
328
- stdio: "inherit",
329
- env
330
- });
331
- const cleanup = () => {
332
- tunnelChild.kill();
333
- devChild.kill();
334
- };
335
- const onSignal = () => {
336
- cleanup();
337
- process.exit(128 + 2);
338
- };
339
- process.on("SIGINT", onSignal);
340
- process.on("SIGTERM", onSignal);
341
- if (normalizedOptions.install) {
342
- lodashEs.noop(normalizedOptions.install);
343
- }
344
- await new Promise((resolve) => {
345
- devChild.on("exit", () => {
346
- cleanup();
347
- process.off("SIGINT", onSignal);
348
- process.off("SIGTERM", onSignal);
349
- resolve();
350
- });
351
- });
352
- };
353
- const isPortNumber = /^[1-9]\d{0,4}$/;
354
- const minPortNumber = 1;
355
- const maxPortNumber = 65535;
356
- const normalize$8 = async (options) => {
357
- const portInput = options.port;
358
- if (portInput)
359
- ;
360
- else {
361
- return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
362
- }
363
- const portString = String(portInput);
364
- const portNumber = Number(portString);
365
- if (isPortNumber.test(portString))
366
- ;
367
- else {
368
- return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
369
- }
370
- if (portNumber < minPortNumber || portNumber > maxPortNumber) {
371
- return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
372
- }
373
- const port = portString;
374
- return {
375
- port
376
- };
377
- };
378
303
  const StoreJSONSchema = zod.z.object({
379
304
  version: zod.z.string().optional(),
380
305
  timestamp: zod.z.number().optional(),
@@ -420,11 +345,11 @@ const getStore = async () => {
420
345
  const setStore = async (store) => {
421
346
  try {
422
347
  await ensureFile(storePath);
423
- const version = `${getPackageJSON().version}`;
348
+ const version2 = `${getPackageJSON().version}`;
424
349
  const timestamp = Date.now();
425
350
  return await writeJSON(storePath, {
426
351
  ...store,
427
- version,
352
+ version: version2,
428
353
  timestamp
429
354
  }, {
430
355
  encoding: "utf8"
@@ -476,70 +401,347 @@ const setONESToken = async (token) => {
476
401
  ones_token: token
477
402
  });
478
403
  };
479
- class TunnelClient {
480
- constructor(localPort, baseUrl, appID, hostedToken) {
481
- _defineProperty(this, "ws", null);
482
- this.localPort = localPort;
483
- this.baseUrl = baseUrl;
484
- this.appID = appID;
485
- this.hostedToken = hostedToken;
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}` : ""}`;
486
449
  }
487
- async connect() {
488
- const proxyUrl = this.buildProxyUrl();
489
- this.ws = new WebSocket(proxyUrl, {
490
- headers: {
491
- Authorization: `Bearer ${this.hostedToken}`
492
- }
493
- });
494
- this.ws.on("message", async (data) => {
495
- const message = this.parseMessage(data);
496
- if (!message) {
497
- return;
498
- }
499
- await this.handleMessage(message);
500
- });
501
- this.ws.on("ping", (data) => {
502
- var _this$ws;
503
- (_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.pong(data);
504
- });
505
- this.ws.on("error", (error) => {
506
- console.error("WebSocket error:", error);
507
- });
508
- return new Promise((resolve, reject) => {
509
- var _this$ws2, _this$ws3;
510
- (_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.on("open", () => resolve());
511
- (_this$ws3 = this.ws) === null || _this$ws3 === void 0 || _this$ws3.on("error", reject);
512
- });
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);
513
458
  }
514
- close() {
515
- var _this$ws4;
516
- (_this$ws4 = this.ws) === null || _this$ws4 === void 0 || _this$ws4.close();
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);
517
468
  }
518
- buildProxyUrl() {
519
- const url = new URL("/platform/app/relay/", this.baseUrl);
520
- url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
521
- url.searchParams.set("app_id", this.appID);
522
- return url.toString();
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
+ }
523
476
  }
524
- parseMessage(data) {
525
- const buffer = this.toBuffer(data);
526
- if (!buffer) {
527
- return null;
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
528
498
  }
529
- if (buffer.length >= 4) {
530
- const binary = this.parseBinaryEnvelope(buffer);
531
- if (binary) {
532
- return binary;
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
533
544
  }
534
- }
535
- return this.parseJSONEnvelope(buffer.toString());
545
+ }).catch(handleError);
536
546
  }
537
- async handleMessage(message) {
538
- const request = this.getRequestPayload(message);
539
- if (!request) {
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) {
540
742
  return;
541
743
  }
542
- if (request.path === ONES_CLI_MANIFEST_PATH) {
744
+ if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
543
745
  const appManifest = getAppManifestJSON().app;
544
746
  const baseURL = await buildTunnelUrl();
545
747
  const reply = {
@@ -591,7 +793,13 @@ class TunnelClient {
591
793
  if (payload.query) {
592
794
  Object.entries(payload.query).forEach((_ref) => {
593
795
  let [key, value] = _ref;
594
- url.searchParams.set(key, value);
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);
595
803
  });
596
804
  }
597
805
  const response = await axios.request({
@@ -600,7 +808,9 @@ class TunnelClient {
600
808
  headers: payload.headers,
601
809
  data: payload.body,
602
810
  responseType: "arraybuffer",
603
- validateStatus: () => true
811
+ validateStatus: () => true,
812
+ maxBodyLength: MAX_RELAY_BODY_BYTES,
813
+ maxContentLength: MAX_RELAY_BODY_BYTES
604
814
  });
605
815
  const responseBytes = Buffer.from(response.data);
606
816
  return {
@@ -632,6 +842,9 @@ class TunnelClient {
632
842
  var _envelope$payload;
633
843
  const payload = (_envelope$payload = envelope.payload) !== null && _envelope$payload !== void 0 ? _envelope$payload : {};
634
844
  const body = this.toBodyBuffer(payload.body);
845
+ if (body.length > MAX_RELAY_BODY_BYTES) {
846
+ throw new Error("relay body too large");
847
+ }
635
848
  const metaPayload = {
636
849
  ...payload
637
850
  };
@@ -674,7 +887,12 @@ class TunnelClient {
674
887
  return envelope;
675
888
  }
676
889
  const body = buffer.subarray(4 + metaLength);
677
- envelope.payload.body = body;
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;
678
896
  return envelope;
679
897
  } catch (error) {
680
898
  console.error("Invalid binary tunnel message:", error);
@@ -706,240 +924,342 @@ class TunnelClient {
706
924
  return null;
707
925
  }
708
926
  }
709
- const getPath = (path, map2) => {
710
- var _context;
711
- return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
712
- if (/^:/.test(part)) {
713
- return `${base}/${map2[part.slice(1)]}`;
714
- }
715
- return `${base}/${part}`;
716
- }, "").slice(1);
717
- };
718
- const consoleUnauthorizedMessage = () => {
719
- console.log("Not logged in");
720
- console.log('Login with "ones login" command');
721
- };
722
- const getURL = async (path, pathMap, queryMap) => {
723
- const base = await getRegionURL();
724
- if (base) {
725
- const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
726
- return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
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
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"));
727
946
  }
728
- consoleUnauthorizedMessage();
729
- process$1.exit(1);
947
+ await setHostToken(hostedToken);
948
+ const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
949
+ await client.connect();
730
950
  };
731
- const getHeaders = async (value) => {
732
- const token = await getONESToken();
733
- if (token) {
734
- return lodashEs.merge({
735
- Authorization: `Bearer ${token}`
736
- }, value);
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];
737
954
  }
738
- consoleUnauthorizedMessage();
739
- process$1.exit(1);
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
963
+ });
964
+ const runnelUrl = await buildTunnelUrl();
965
+ console.log(`Relay endpoint: ${runnelUrl}`);
740
966
  };
741
- const handleError = (error) => {
742
- var _error$response;
743
- if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
744
- console.log(error.response.statusText);
745
- consoleUnauthorizedMessage();
746
- } else {
747
- console.error(error);
748
- }
967
+ const normalize$8 = async (options) => {
968
+ lodashEs.noop(options);
749
969
  return {};
750
970
  };
751
- const API = {
752
- TOKEN_INFO: "/project/api/project/auth/token_info",
753
- HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
754
- APP_LIST: "/platform/api/app/list",
755
- APP_INSTALL: "/platform/api/app/install",
756
- APP_UPGRADE: "/platform/api/app/upgrade",
757
- APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
758
- APP_ENABLE: "/platform/api/app/:installation_id/enable",
759
- APP_DISABLE: "/platform/api/app/:installation_id/disable"
760
- };
761
- const isRecord = (value) => {
762
- return typeof value === "object" && value !== null;
763
- };
764
- const getHostedTokenScopes = (ones2) => {
765
- const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
766
- if (!storage) {
767
- return [];
768
- }
769
- const scopes = /* @__PURE__ */ new Set();
770
- if (Array.isArray(storage.entities) && storage.entities.length > 0) {
771
- scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
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}`);
772
981
  }
773
- if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
774
- scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
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}`);
775
985
  }
776
- return Array.from(scopes);
777
- };
778
- const getRelayScope = () => {
779
- return createOnesApp.HostedTokenScope.RELAY;
780
986
  };
781
- const getHostToken = async (baseUrl, userToken, appID, scopes) => {
782
- const url = `${baseUrl.replace(/\/$/, "")}${API.HOSTED_TOKEN}`;
783
- return axios.post(url, {
784
- app_id: appID,
785
- scopes
786
- }, {
787
- headers: {
788
- Authorization: `Bearer ${userToken}`
789
- }
790
- }).then((resp) => {
791
- const data = resp === null || resp === void 0 ? void 0 : resp.data;
792
- const tokenFromData = (value) => {
793
- if (isRecord(value) && isRecord(value.data)) {
794
- const hosted_token = value.data.hosted_token;
795
- if (typeof hosted_token === "string" && hosted_token.length > 0) {
796
- return hosted_token;
797
- }
798
- }
799
- return null;
800
- };
801
- const token = tokenFromData(data);
802
- if (token) {
803
- return token;
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
804
997
  }
805
- return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
806
- }).catch((error) => {
807
- handleError(error);
808
- return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_REQUEST_FAILED, i18n.t("error.hostedToken.requestFailed"));
809
998
  });
810
- };
811
- const fetchAppBase = async (params) => {
812
- var _params$url;
813
- const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
814
- const headers = await getHeaders(params.headers);
815
- const response = await axios({
816
- ...params,
817
- url,
818
- headers
819
- });
820
- return response.data;
821
- };
822
- const fetchAppList = async (appID) => {
823
- return await fetchAppBase({
824
- url: API.APP_LIST,
825
- method: "GET",
826
- queryMap: {
827
- app_id: appID
828
- }
829
- }).catch(handleError);
830
- };
831
- const fetchTokenInfo = async () => {
832
- return await fetchAppBase({
833
- url: API.TOKEN_INFO,
834
- method: "GET"
835
- }).catch(handleError);
836
- };
837
- const fetchAppInstall = async (data) => {
838
- var _appList$data$0$insta, _appList$data;
839
- const appID = getAppManifestJSON().app.id;
840
- const appList = await fetchAppList(appID);
841
- 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 : "";
842
- const url = installationID ? API.APP_UPGRADE : API.APP_INSTALL;
843
- return await fetchAppBase({
844
- url,
845
- method: "POST",
846
- data
847
- }).catch(handleError);
848
- };
849
- const fetchAppUninstall = async () => {
850
- var _appList$data$0$insta2, _appList$data2;
851
- const appID = getAppManifestJSON().app.id;
852
- const appList = await fetchAppList(appID);
853
- 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 : "";
854
- return await fetchAppBase({
855
- url: API.APP_UNINSTALL,
856
- method: "POST",
857
- pathMap: {
858
- installation_id: installationID
859
- }
860
- }).catch(handleError);
861
- };
862
- const fetchAppEnable = async () => {
863
- var _appList$data$0$insta3, _appList$data3;
864
- const appID = getAppManifestJSON().app.id;
865
- const appList = await fetchAppList(appID);
866
- 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 : "";
867
- return await fetchAppBase({
868
- url: API.APP_ENABLE,
869
- method: "POST",
870
- pathMap: {
871
- installation_id: installationID
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);
872
1006
  }
873
- }).catch(handleError);
1007
+ return true;
1008
+ } else {
1009
+ console.log(`App "${appName}" installed failed!`);
1010
+ console.error(JSON.stringify(result, null, 2));
1011
+ }
1012
+ return false;
874
1013
  };
875
- const fetchAppDisable = async () => {
876
- var _appList$data$0$insta4, _appList$data4;
877
- const appID = getAppManifestJSON().app.id;
878
- const appList = await fetchAppList(appID);
879
- 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 : "";
880
- return await fetchAppBase({
881
- url: API.APP_DISABLE,
882
- method: "POST",
883
- pathMap: {
884
- installation_id: installationID
1014
+ const getManifestUrl = async () => {
1015
+ const runnelUrl = await buildTunnelUrl();
1016
+ const customManifestUrl = `${runnelUrl}${MANIFEST_PATH}`;
1017
+ const internalManifestUrl = `${runnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
1018
+ const internalResult = await axios.get(internalManifestUrl).then((response) => {
1019
+ if (response.status === 200) {
1020
+ return internalManifestUrl;
885
1021
  }
886
- }).catch(handleError);
887
- };
888
- const ONES_CLI_MANIFEST_PATH = "/__ones_cli_manifest__";
889
- const buildTunnelContext = async () => {
890
- var _appManifestJSON$app$, _appManifestJSON$app;
891
- const appManifestJSON = getAppManifestJSON();
892
- 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$ : "";
893
- if (!appID) {
894
- throw new Error("app id is empty");
1022
+ return null;
1023
+ }).catch(lodashEs.noop);
1024
+ if (internalResult) {
1025
+ return internalResult;
895
1026
  }
896
- const regionURL = await getRegionURL();
897
- if (!regionURL) {
898
- throw new Error("region url is empty");
1027
+ const customResult = await axios.get(customManifestUrl).then((response) => {
1028
+ if (response.status === 200) {
1029
+ return customManifestUrl;
1030
+ }
1031
+ return null;
1032
+ }).catch(lodashEs.noop);
1033
+ if (customResult) {
1034
+ return customResult;
899
1035
  }
900
- return {
901
- appManifestJSON,
902
- appID,
903
- regionURL
904
- };
1036
+ return null;
905
1037
  };
906
- const buildTunnelUrl = async () => {
1038
+ const install = async function() {
1039
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1040
+ args[_key] = arguments[_key];
1041
+ }
907
1042
  const {
908
- appID,
909
- regionURL
910
- } = await buildTunnelContext();
911
- const url = new URL(regionURL);
912
- return `${url.protocol}//${url.host}/platform/app/relay/dispatch/${appID}`;
913
- };
914
- const invokeTunnel = async (port) => {
1043
+ options
1044
+ } = createOnesApp.getCommandOptions(args, installCommandArguments);
1045
+ const normalizedOptions = await normalize$8(options);
1046
+ lodashEs.noop(normalizedOptions);
915
1047
  const {
916
- appManifestJSON,
917
- appID,
918
- regionURL
919
- } = await buildTunnelContext();
920
- const onesToken = await getONESToken();
921
- if (!onesToken) {
922
- consoleUnauthorizedMessage();
923
- process$1.exit(1);
1048
+ app
1049
+ } = getAppManifestJSON();
1050
+ const appName = app.name;
1051
+ const manifestUrl = await getManifestUrl();
1052
+ if (!manifestUrl) {
1053
+ console.log(`App "${appName}" server not available!`);
1054
+ console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
1055
+ console.log("Visit https://open.ones.com for more information and help");
1056
+ process.exit(1);
1057
+ }
1058
+ const success = await invokeInstall(manifestUrl);
1059
+ if (success)
1060
+ ;
1061
+ else {
1062
+ console.log("Visit https://open.ones.com for more information and help");
924
1063
  }
925
- const storageScopes = getHostedTokenScopes(appManifestJSON.ones);
926
- const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
927
- const hostedToken = await getHostToken(regionURL, onesToken, appID, scopes);
928
- process.env.ONES_HOSTED_TOKEN = hostedToken;
929
- const client = new TunnelClient(port, regionURL, appID, hostedToken);
930
- await client.connect();
931
- const runnelUrl = await buildTunnelUrl();
932
- console.log(`Relay endpoint: ${runnelUrl}`);
933
1064
  };
934
- const tunnel = async function() {
1065
+ var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
1066
+ InstallOptions2["AUTO"] = "auto";
1067
+ InstallOptions2["TRUE"] = "true";
1068
+ InstallOptions2["FALSE"] = "false";
1069
+ return InstallOptions2;
1070
+ })(InstallOptions || {});
1071
+ const defaultInstall = InstallOptions.AUTO;
1072
+ const normalize$7 = async (options) => {
1073
+ var _options$install, _options$command;
1074
+ let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
1075
+ const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
1076
+ switch (true) {
1077
+ case install2 === InstallOptions.AUTO:
1078
+ break;
1079
+ case Boolean(install2):
1080
+ install2 = InstallOptions.TRUE;
1081
+ break;
1082
+ default:
1083
+ install2 = InstallOptions.FALSE;
1084
+ break;
1085
+ }
1086
+ return {
1087
+ install: install2,
1088
+ command
1089
+ };
1090
+ };
1091
+ const IDLE_MS = 2e3;
1092
+ function createReadyStatusPipes(onReady) {
1093
+ let readyTimer = null;
1094
+ let summaryPrinted = false;
1095
+ const scheduleReady = () => {
1096
+ if (summaryPrinted)
1097
+ return;
1098
+ if (readyTimer)
1099
+ clearTimeout(readyTimer);
1100
+ readyTimer = setTimeout(() => {
1101
+ readyTimer = null;
1102
+ if (!summaryPrinted) {
1103
+ summaryPrinted = true;
1104
+ onReady();
1105
+ }
1106
+ }, IDLE_MS);
1107
+ };
1108
+ const pipe = (stream, isStderr) => {
1109
+ const write = (chunk) => {
1110
+ if (isStderr)
1111
+ process.stderr.write(chunk);
1112
+ else
1113
+ process.stdout.write(chunk);
1114
+ };
1115
+ stream.on("data", (chunk) => {
1116
+ const str = typeof chunk === "string" ? chunk : chunk.toString();
1117
+ write(str);
1118
+ if (str.startsWith("[backend]") || str.startsWith("[web]")) {
1119
+ scheduleReady();
1120
+ }
1121
+ });
1122
+ };
1123
+ return pipe;
1124
+ }
1125
+ const dev = async function() {
1126
+ var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2;
935
1127
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
936
1128
  args[_key] = arguments[_key];
937
1129
  }
938
1130
  const {
939
1131
  options
940
- } = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
941
- const normalizedOptions = await normalize$8(options);
942
- await invokeTunnel(Number(normalizedOptions.port));
1132
+ } = createOnesApp.getCommandOptions(args, devCommandArguments);
1133
+ const normalizedOptions = await normalize$7(options);
1134
+ const appRcJSON = await getAppRcJSON();
1135
+ const appPackageJSON = getAppPackageJSON();
1136
+ 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]) || "";
1137
+ if (!firstCommand) {
1138
+ return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
1139
+ }
1140
+ 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 : [];
1141
+ const currentCommandString = currentCommand.join(" ");
1142
+ const defaultDevCommandString = defaultDevCommand.join(" ");
1143
+ if (currentCommandString === defaultDevCommandString) {
1144
+ var _appPackageJSON$scrip;
1145
+ if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
1146
+ return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
1147
+ }
1148
+ }
1149
+ let enableTunnel = true;
1150
+ if (normalizedOptions.install === InstallOptions.TRUE)
1151
+ ;
1152
+ else {
1153
+ enableTunnel = await checkTokenInfo();
1154
+ }
1155
+ const appManifestJSON = getAppManifestJSON();
1156
+ const {
1157
+ app,
1158
+ ones: ones2
1159
+ } = appManifestJSON;
1160
+ const appID = app.id;
1161
+ const config2 = getConfig();
1162
+ const ONES_HOSTED_PORT = await getPort({
1163
+ port: config2.defaultPort.hosted
1164
+ });
1165
+ const ONES_DEV_WEB_SERVER_PORT = await getPort({
1166
+ port: config2.defaultPort.devWebServer
1167
+ });
1168
+ const env2 = {
1169
+ ...process.env,
1170
+ NODE_ENV: "development",
1171
+ ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
1172
+ ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
1173
+ ONES_HOSTED_TOKEN: "",
1174
+ ONES_HOSTED_APP_ID: "",
1175
+ ONES_HOSTED_BASE_URL: ""
1176
+ };
1177
+ if (enableTunnel) {
1178
+ var _ones$storage$entitie, _ones$storage;
1179
+ await invokeTunnel(ONES_HOSTED_PORT, {
1180
+ enableInternalManifestRoute: true,
1181
+ rebuildWhenExists: true
1182
+ });
1183
+ const regionURL = await getRegionURL();
1184
+ const ONES_HOSTED_TOKEN = await getHostToken();
1185
+ const ONES_HOSTED_APP_ID = appID;
1186
+ const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
1187
+ env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
1188
+ env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
1189
+ env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
1190
+ 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 : [];
1191
+ if (entities.length > 0) {
1192
+ await fetchHostedAbilityStorageDevDeclare({
1193
+ app_id: appID,
1194
+ cleanup_legacy: false,
1195
+ opkx_content: appManifestJSON
1196
+ });
1197
+ }
1198
+ }
1199
+ const onReady = async () => {
1200
+ const appName = app.name;
1201
+ let manifestUrl = "";
1202
+ console.log("");
1203
+ console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
1204
+ if (enableTunnel) {
1205
+ const runnelUrl = await buildTunnelUrl();
1206
+ console.log(`URL: ${runnelUrl}`);
1207
+ manifestUrl = `${runnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
1208
+ }
1209
+ console.log("Docs site: https://open.ones.com");
1210
+ console.log(`App "${appName}" server is ready!`);
1211
+ console.log("");
1212
+ if (enableTunnel) {
1213
+ switch (normalizedOptions.install) {
1214
+ case InstallOptions.TRUE:
1215
+ await invokeInstall(manifestUrl);
1216
+ break;
1217
+ case InstallOptions.AUTO:
1218
+ {
1219
+ var _appList$data$0$insta, _appList$data;
1220
+ const appList = await fetchAppList(appID);
1221
+ 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 : "";
1222
+ if (installationID) {
1223
+ await displayAppDetail(installationID);
1224
+ } else {
1225
+ await invokeInstall(manifestUrl);
1226
+ }
1227
+ }
1228
+ break;
1229
+ case InstallOptions.FALSE:
1230
+ break;
1231
+ }
1232
+ }
1233
+ };
1234
+ const cwd = getAppWorkspacePath();
1235
+ const child = node_child_process.spawn(firstCommand, currentCommand.slice(1), {
1236
+ cwd,
1237
+ stdio: ["inherit", "pipe", "pipe"],
1238
+ env: env2,
1239
+ shell: true
1240
+ });
1241
+ const pipe = createReadyStatusPipes(onReady);
1242
+ if (child.stdout)
1243
+ pipe(child.stdout, false);
1244
+ if (child.stderr)
1245
+ pipe(child.stderr, true);
1246
+ const cleanup = () => {
1247
+ child.kill();
1248
+ };
1249
+ const onSignal = () => {
1250
+ cleanup();
1251
+ process.exit(128 + 2);
1252
+ };
1253
+ process.on("SIGINT", onSignal);
1254
+ process.on("SIGTERM", onSignal);
1255
+ await new Promise((resolve) => {
1256
+ child.on("exit", () => {
1257
+ cleanup();
1258
+ process.off("SIGINT", onSignal);
1259
+ process.off("SIGTERM", onSignal);
1260
+ resolve();
1261
+ });
1262
+ });
943
1263
  };
944
1264
  function createPromise() {
945
1265
  let resolve;
@@ -961,7 +1281,7 @@ const sleep = (number) => {
961
1281
  };
962
1282
  const isURL = /^https?:\/\//;
963
1283
  const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
964
- const normalize$7 = async (options) => {
1284
+ const normalize$6 = async (options) => {
965
1285
  const baseURLInput = options.baseURL;
966
1286
  if (baseURLInput)
967
1287
  ;
@@ -998,7 +1318,7 @@ const login = async function() {
998
1318
  const {
999
1319
  options
1000
1320
  } = createOnesApp.getCommandOptions(args, loginCommandArguments);
1001
- const normalizedOptions = await normalize$7(options);
1321
+ const normalizedOptions = await normalize$6(options);
1002
1322
  const base = normalizedOptions.baseURL;
1003
1323
  const path = "project/oauth2.html";
1004
1324
  const config2 = getConfig();
@@ -1082,7 +1402,7 @@ const login = async function() {
1082
1402
  ora("Waiting for authorization...").start();
1083
1403
  await open(url);
1084
1404
  };
1085
- const normalize$6 = async (options) => {
1405
+ const normalize$5 = async (options) => {
1086
1406
  lodashEs.noop(options);
1087
1407
  return {};
1088
1408
  };
@@ -1093,12 +1413,12 @@ const logout = async function() {
1093
1413
  const {
1094
1414
  options
1095
1415
  } = createOnesApp.getCommandOptions(args, logoutCommandArguments);
1096
- const normalizedOptions = await normalize$6(options);
1416
+ const normalizedOptions = await normalize$5(options);
1097
1417
  lodashEs.noop(normalizedOptions);
1098
1418
  await setStore({});
1099
1419
  console.log("Logged out successfully!");
1100
1420
  };
1101
- const normalize$5 = async (options) => {
1421
+ const normalize$4 = async (options) => {
1102
1422
  lodashEs.noop(options);
1103
1423
  return {};
1104
1424
  };
@@ -1110,67 +1430,20 @@ const whoami = async function() {
1110
1430
  const {
1111
1431
  options
1112
1432
  } = createOnesApp.getCommandOptions(args, whoamiCommandArguments);
1113
- const normalizedOptions = await normalize$5(options);
1433
+ const normalizedOptions = await normalize$4(options);
1114
1434
  lodashEs.noop(normalizedOptions);
1115
1435
  const baseURL = await getBaseURL();
1116
1436
  const tokenInfo = await fetchTokenInfo();
1117
1437
  const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
1118
1438
  const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
1119
1439
  if (name2 && email) {
1120
- console.log(`${name2} <${email}>`);
1440
+ console.log(`User: ${name2}`);
1441
+ console.log(`Email: ${email}`);
1121
1442
  console.log(`ONES: ${baseURL}`);
1122
1443
  } else {
1123
1444
  consoleUnauthorizedMessage();
1124
1445
  }
1125
1446
  };
1126
- const normalize$4 = async (options) => {
1127
- lodashEs.noop(options);
1128
- return {};
1129
- };
1130
- const invokeInstall = async () => {
1131
- const runnelUrl = await buildTunnelUrl();
1132
- const result = await fetchAppInstall({
1133
- manifest_url: `${runnelUrl}${ONES_CLI_MANIFEST_PATH}`
1134
- });
1135
- return result;
1136
- };
1137
- const install = async function() {
1138
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1139
- args[_key] = arguments[_key];
1140
- }
1141
- const {
1142
- options
1143
- } = createOnesApp.getCommandOptions(args, installCommandArguments);
1144
- const normalizedOptions = await normalize$4(options);
1145
- lodashEs.noop(normalizedOptions);
1146
- await invokeTunnel(getConfig().defaultPort.tunnel);
1147
- const result = await invokeInstall();
1148
- if (result.code === "OK") {
1149
- var _appList$data$0$insta, _appList$data;
1150
- console.log("App installed successfully!");
1151
- const appID = getAppManifestJSON().app.id;
1152
- const appList = await fetchAppList(appID);
1153
- 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 : "";
1154
- if (installationID) {
1155
- var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
1156
- const tokenInfo = await fetchTokenInfo();
1157
- 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 : "";
1158
- 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 : "";
1159
- 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;
1160
- const baseURL = await getBaseURL();
1161
- if (isOrgVisible && orgUUID) {
1162
- const url = `${baseURL}/project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
1163
- console.log(`See App detail: ${url}`);
1164
- }
1165
- if (!isOrgVisible && teamUUID) {
1166
- const url = `${baseURL}/project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
1167
- console.log(`See App detail: ${url}`);
1168
- }
1169
- }
1170
- } else {
1171
- console.error(result);
1172
- }
1173
- };
1174
1447
  const normalize$3 = async (options) => {
1175
1448
  lodashEs.noop(options);
1176
1449
  return {};
@@ -1184,11 +1457,13 @@ const enable = async function() {
1184
1457
  } = createOnesApp.getCommandOptions(args, enableCommandArguments);
1185
1458
  const normalizedOptions = await normalize$3(options);
1186
1459
  lodashEs.noop(normalizedOptions);
1460
+ const appName = getAppManifestJSON().app.name;
1187
1461
  const result = await fetchAppEnable();
1188
1462
  if (result.code === "OK") {
1189
- console.log("App enabled successfully!");
1463
+ console.log(`App "${appName}" enabled successfully!`);
1190
1464
  } else {
1191
- console.error(result);
1465
+ console.log(`App "${appName}" enabled failed!`);
1466
+ console.error(JSON.stringify(result, null, 2));
1192
1467
  }
1193
1468
  };
1194
1469
  const normalize$2 = async (options) => {
@@ -1204,11 +1479,13 @@ const disable = async function() {
1204
1479
  } = createOnesApp.getCommandOptions(args, disableCommandArguments);
1205
1480
  const normalizedOptions = await normalize$2(options);
1206
1481
  lodashEs.noop(normalizedOptions);
1482
+ const appName = getAppManifestJSON().app.name;
1207
1483
  const result = await fetchAppDisable();
1208
1484
  if (result.code === "OK") {
1209
- console.log("App disabled successfully!");
1485
+ console.log(`App "${appName}" disabled successfully!`);
1210
1486
  } else {
1211
- console.error(result);
1487
+ console.log(`App "${appName}" disabled failed!`);
1488
+ console.error(JSON.stringify(result, null, 2));
1212
1489
  }
1213
1490
  };
1214
1491
  const normalize$1 = async (options) => {
@@ -1224,11 +1501,13 @@ const uninstall = async function() {
1224
1501
  } = createOnesApp.getCommandOptions(args, uninstallCommandArguments);
1225
1502
  const normalizedOptions = await normalize$1(options);
1226
1503
  lodashEs.noop(normalizedOptions);
1504
+ const appName = getAppManifestJSON().app.name;
1227
1505
  const result = await fetchAppUninstall();
1228
1506
  if (result.code === "OK") {
1229
- console.log("App uninstalled successfully!");
1507
+ console.log(`App "${appName}" uninstalled successfully!`);
1230
1508
  } else {
1231
- console.error(result);
1509
+ console.log(`App "${appName}" uninstalled failed!`);
1510
+ console.error(JSON.stringify(result, null, 2));
1232
1511
  }
1233
1512
  };
1234
1513
  const normalize = async (options) => {
@@ -1250,7 +1529,7 @@ const $build = new commander.Command("build").description(i18n.t("desc.build")).
1250
1529
  createOnesApp.addCommandUsage($build);
1251
1530
  createOnesApp.addCommandOutput($build);
1252
1531
  const devCommandArguments = [];
1253
- const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).action(dev);
1532
+ 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);
1254
1533
  createOnesApp.addCommandUsage($dev);
1255
1534
  createOnesApp.addCommandOutput($dev);
1256
1535
  const tunnelCommandArguments = ["port"];
@@ -1294,7 +1573,11 @@ const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"
1294
1573
  createOnesApp.addCommandUsage($legacy);
1295
1574
  createOnesApp.addCommandOutput($legacy);
1296
1575
  const ones = new commander.Command("ones");
1297
- ones.description(i18n.t("desc.ones")).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
1576
+ const version = `${getPackageJSON().version}`;
1577
+ const env = `${version} Node/${process.version}`;
1578
+ ones.description(i18n.t("desc.ones", {
1579
+ env
1580
+ })).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
1298
1581
  visibleCommands: (cmd) => {
1299
1582
  const blackList = ["legacy"];
1300
1583
  return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
@@ -1307,8 +1590,8 @@ createOnesApp.addCommandOutput(ones);
1307
1590
  const runCommandONES = async () => {
1308
1591
  const command = ones;
1309
1592
  createOnesApp.setContext("command", command);
1310
- const version = `${getPackageJSON().version}`;
1311
- command.version(version);
1593
+ const version2 = `${getPackageJSON().version}`;
1594
+ command.version(version2, "-v, --version");
1312
1595
  await command.parse();
1313
1596
  };
1314
1597
  exports.runCommandONES = runCommandONES;