@ones-open/cli 1.0.1-27659.1892 → 1.0.1-4995.1947

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