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

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 (91) hide show
  1. package/dist/index.cjs +550 -247
  2. package/dist/index.js +552 -249
  3. package/dist/types/actions/build/index.d.ts.map +1 -1
  4. package/dist/types/actions/build/normalize.d.ts.map +1 -1
  5. package/dist/types/actions/dev/enums.d.ts +5 -0
  6. package/dist/types/actions/dev/enums.d.ts.map +1 -1
  7. package/dist/types/actions/dev/index.d.ts.map +1 -1
  8. package/dist/types/actions/dev/normalize.d.ts.map +1 -1
  9. package/dist/types/actions/dev/types.d.ts +10 -0
  10. package/dist/types/actions/dev/types.d.ts.map +1 -0
  11. package/dist/types/actions/disable/index.d.ts.map +1 -1
  12. package/dist/types/actions/enable/index.d.ts.map +1 -1
  13. package/dist/types/actions/install/index.d.ts +1 -0
  14. package/dist/types/actions/install/index.d.ts.map +1 -1
  15. package/dist/types/actions/install/install.d.ts +3 -0
  16. package/dist/types/actions/install/install.d.ts.map +1 -0
  17. package/dist/types/actions/legacy/index.d.ts.map +1 -1
  18. package/dist/types/actions/legacy/normalize.d.ts.map +1 -1
  19. package/dist/types/actions/login/index.d.ts +1 -1
  20. package/dist/types/actions/login/index.d.ts.map +1 -1
  21. package/dist/types/actions/tunnel/index.d.ts.map +1 -1
  22. package/dist/types/actions/tunnel/normalize.d.ts.map +1 -1
  23. package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -1
  24. package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
  25. package/dist/types/actions/tunnel/types.d.ts +1 -0
  26. package/dist/types/actions/tunnel/types.d.ts.map +1 -1
  27. package/dist/types/actions/tunnel/utils.d.ts +1 -1
  28. package/dist/types/actions/tunnel/utils.d.ts.map +1 -1
  29. package/dist/types/actions/uninstall/index.d.ts.map +1 -1
  30. package/dist/types/actions/whoami/index.d.ts.map +1 -1
  31. package/dist/types/command/build/index.d.ts +1 -0
  32. package/dist/types/command/build/index.d.ts.map +1 -1
  33. package/dist/types/command/dev/index.d.ts +2 -0
  34. package/dist/types/command/dev/index.d.ts.map +1 -1
  35. package/dist/types/command/legacy/index.d.ts +1 -1
  36. package/dist/types/command/legacy/index.d.ts.map +1 -1
  37. package/dist/types/command/tunnel/index.d.ts +1 -0
  38. package/dist/types/command/tunnel/index.d.ts.map +1 -1
  39. package/dist/types/common/config/types.d.ts +2 -1
  40. package/dist/types/common/config/types.d.ts.map +1 -1
  41. package/dist/types/common/config/utils.d.ts.map +1 -1
  42. package/dist/types/common/error/enums.d.ts +3 -1
  43. package/dist/types/common/error/enums.d.ts.map +1 -1
  44. package/dist/types/common/error/utils.d.ts +1 -0
  45. package/dist/types/common/error/utils.d.ts.map +1 -1
  46. package/dist/types/common/locales/en/index.d.ts +9 -0
  47. package/dist/types/common/locales/en/index.d.ts.map +1 -1
  48. package/dist/types/common/package/schema.d.ts +1 -1
  49. package/dist/types/common/package/schema.d.ts.map +1 -1
  50. package/dist/types/common/package/utils.d.ts +3 -1
  51. package/dist/types/common/package/utils.d.ts.map +1 -1
  52. package/dist/types/common/request/consts.d.ts +2 -0
  53. package/dist/types/common/request/consts.d.ts.map +1 -1
  54. package/dist/types/common/request/fetch.d.ts +4 -1
  55. package/dist/types/common/request/fetch.d.ts.map +1 -1
  56. package/dist/types/common/request/types.d.ts +18 -0
  57. package/dist/types/common/request/types.d.ts.map +1 -1
  58. package/dist/types/common/request/utils.d.ts +2 -0
  59. package/dist/types/common/request/utils.d.ts.map +1 -1
  60. package/dist/types/common/template/index.d.ts +5 -0
  61. package/dist/types/common/template/index.d.ts.map +1 -0
  62. package/dist/types/common/template/utils.d.ts +3 -0
  63. package/dist/types/common/template/utils.d.ts.map +1 -0
  64. package/package.json +6 -3
  65. package/template/legacy/README.md +13 -0
  66. package/template/legacy/_backend_npmrc +5 -0
  67. package/template/legacy/_backend_tsconfig.json +23 -0
  68. package/template/legacy/_eslintignore +2 -0
  69. package/template/legacy/_eslintrc.js +97 -0
  70. package/template/legacy/_gitignore +21 -0
  71. package/template/legacy/_gitlab-ci.yml +3 -0
  72. package/template/legacy/_husky_pre-commit +1 -0
  73. package/template/legacy/_npmrc +5 -0
  74. package/template/legacy/_prettierignore +15 -0
  75. package/template/legacy/_prettierrc +6 -0
  76. package/template/legacy/_web_npmrc +5 -0
  77. package/template/legacy/_web_tsconfig.json +20 -0
  78. package/template/legacy/backend/package.json +10 -0
  79. package/template/legacy/backend/src/index.ts +139 -0
  80. package/template/legacy/backend/src/ones.d.ts +6 -0
  81. package/template/legacy/config/ci-deploy.yaml +11 -0
  82. package/template/legacy/config/local.yaml +30 -0
  83. package/template/legacy/config/plugin.yaml +25 -0
  84. package/template/legacy/config/upgrade.yaml +8 -0
  85. package/template/legacy/op.config.mjs +4 -0
  86. package/template/legacy/package-lock.json +17446 -0
  87. package/template/legacy/package.json +73 -0
  88. package/template/legacy/web/browserslist +4 -0
  89. package/template/legacy/web/package.json +29 -0
  90. package/template/legacy/web/public/logo.svg +5 -0
  91. package/template/legacy/workspace/plugin.sql +2 -0
package/dist/index.cjs CHANGED
@@ -9,26 +9,30 @@ const node_fs = require("node:fs");
9
9
  const fse = require("fs-extra");
10
10
  const archiver = require("archiver");
11
11
  const lodashEs = require("lodash-es");
12
+ const chalk = require("chalk");
12
13
  const process$1 = require("node:process");
13
14
  const node_url = require("node:url");
14
15
  const cosmiconfig = require("cosmiconfig");
16
+ const getPort = require("get-port");
15
17
  const envPaths = require("env-paths");
16
18
  const zod = require("zod");
17
19
  const axios = require("axios");
18
20
  const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
21
+ const ora = require("ora");
19
22
  const WebSocket = require("ws");
20
23
  const http = require("node:http");
21
- const ora = require("ora");
22
24
  const open = require("open");
23
- const getPort = require("get-port");
24
25
  const uuid = require("uuid");
25
26
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
26
27
  const en = {
27
28
  "desc.ones": "ONES CLI/{env}",
28
29
  "desc.build": "Build your ONES App",
29
30
  "desc.build.output": "Specify the output file path",
31
+ "desc.build.command": "Specify the build command",
30
32
  "desc.dev": "Start your local development server and connect to ONES",
31
33
  "desc.dev.install": "Install your ONES App after the server is ready",
34
+ "desc.dev.command": "Specify the dev command",
35
+ "desc.dev.useStorage": "Use hosted storage ability",
32
36
  "desc.tunnel": "Start a tunnel to connect your local server with ONES",
33
37
  "desc.tunnel.port": "Specify the port number for tunnel",
34
38
  "desc.login": "Log in to your ONES account",
@@ -41,17 +45,23 @@ const en = {
41
45
  "desc.disable": "Disable your ONES App",
42
46
  "desc.uninstall": "Uninstall your ONES App",
43
47
  "desc.legacy": "Legacy command",
48
+ "desc.legacy.create": "Create a new ONES plugin",
49
+ "desc.legacy.create.projectPath": "Specify the project path",
44
50
  "error.login.missingBaseURL": "Missing base URL",
45
51
  "error.login.incorrectBaseURL": "Incorrect base URL",
46
52
  "error.tunnel.missingPort": "Missing port",
47
53
  "error.tunnel.incorrectPort": "Incorrect port",
48
54
  "error.schema.app.package.parseError": "App package JSON parse error",
49
55
  "error.schema.app.manifest.parseError": 'App "opkx.json" JSON parse error',
56
+ "error.schema.app.manifest.validateError": "Please check for this error or upgrade your ONES CLI to the latest version",
50
57
  "error.build.scriptNotFound": 'Npm "build" script not found',
58
+ "error.build.incorrectCommand": "Incorrect build command",
51
59
  "error.dev.scriptNotFound": 'Npm "dev" script not found',
60
+ "error.dev.incorrectCommand": "Incorrect dev command",
52
61
  "error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
53
62
  "error.hostedToken.requestFailed": "Failed to request hosted token",
54
- "error.hostedToken.empty": "Hosted token is empty"
63
+ "error.hostedToken.empty": "Hosted token is empty",
64
+ "error.legacy.create.missingProjectPath": "Project path is required"
55
65
  };
56
66
  const map = {
57
67
  en
@@ -80,6 +90,10 @@ const translate = (key, params) => {
80
90
  const i18n = {
81
91
  t: translate
82
92
  };
93
+ const throwWarning = (code, message) => {
94
+ const text = `${message.trim().replace(/\s+$/, "")}[${code}]`;
95
+ console.warn(chalk.yellow(text));
96
+ };
83
97
  var ErrorCode = ((ErrorCode2) => {
84
98
  ErrorCode2[ErrorCode2["UNKNOWN_ERROR"] = createOnesApp.ErrorCode.UNKNOWN_ERROR] = "UNKNOWN_ERROR";
85
99
  ErrorCode2[ErrorCode2["COMMAND_ERROR"] = createOnesApp.ErrorCode.COMMAND_ERROR] = "COMMAND_ERROR";
@@ -96,6 +110,8 @@ var ErrorCode = ((ErrorCode2) => {
96
110
  ErrorCode2["STORE_PERMISSION"] = "E12";
97
111
  ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
98
112
  ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
113
+ ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
114
+ ErrorCode2["INCORRECT_BUILD_COMMAND"] = "E16";
99
115
  return ErrorCode2;
100
116
  })(ErrorCode || {});
101
117
  const getPublicPath = () => {
@@ -152,10 +168,23 @@ const getAppManifestJSON = () => {
152
168
  return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
153
169
  }
154
170
  };
155
- const defaultAppRcJSONDevCommand = "npm run dev";
171
+ const validateAppManifestJSON = () => {
172
+ const appManifestJSON = getAppManifestJSON();
173
+ try {
174
+ createOnesApp.AppManifestStrictJSONSchema.parse(appManifestJSON);
175
+ } catch (error) {
176
+ const details = error instanceof Error ? error.message : String(error);
177
+ return throwWarning(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.validateError")}: ${details}`);
178
+ }
179
+ };
180
+ const defaultDevCommand = ["npm", "run", "dev"];
181
+ const defaultBuildCommand = ["npm", "run", "build"];
156
182
  const defaultAppRcJSON = {
157
183
  dev: {
158
- command: [defaultAppRcJSONDevCommand]
184
+ command: defaultDevCommand
185
+ },
186
+ build: {
187
+ command: defaultBuildCommand
159
188
  }
160
189
  };
161
190
  let storeAppRcJSON = null;
@@ -184,17 +213,14 @@ const getAppRcJSON = async () => {
184
213
  } catch (error) {
185
214
  currentAppRcJSON = {};
186
215
  }
187
- return {
188
- ...defaultAppRcJSON,
189
- ...templateAppRcJSON,
190
- ...currentAppRcJSON
191
- };
216
+ return lodashEs.merge(defaultAppRcJSON, templateAppRcJSON, currentAppRcJSON);
192
217
  };
193
218
  const isOPKXFilename = /\.opkx$/;
194
219
  const defaultOutputPath = "";
195
220
  const normalize$a = async (options) => {
196
- var _options$output;
221
+ var _options$output, _options$command;
197
222
  let output = node_path.resolve(process$1.cwd(), (_options$output = options.output) !== null && _options$output !== void 0 ? _options$output : defaultOutputPath);
223
+ const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
198
224
  if (isOPKXFilename.test(output))
199
225
  ;
200
226
  else {
@@ -202,15 +228,18 @@ const normalize$a = async (options) => {
202
228
  const defaultOutputFilename = `${appManifestJSON.app.name}.opkx`;
203
229
  output = node_path.resolve(output, defaultOutputFilename);
204
230
  }
231
+ validateAppManifestJSON();
205
232
  return {
206
- output
233
+ output,
234
+ command
207
235
  };
208
236
  };
209
237
  const {
210
- existsSync
238
+ existsSync,
239
+ ensureDirSync
211
240
  } = fse;
212
241
  const build = async function() {
213
- var _appRcJSON$build$comp, _appRcJSON$build;
242
+ var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$build$comm, _appRcJSON$build, _appRcJSON$build$comp, _appRcJSON$build2;
214
243
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
215
244
  args[_key] = arguments[_key];
216
245
  }
@@ -220,33 +249,53 @@ const build = async function() {
220
249
  const normalizedOptions = await normalize$a(options);
221
250
  const appManifestJSON = getAppManifestJSON();
222
251
  const appRcJSON = await getAppRcJSON();
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"
252
+ 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]) || "";
253
+ if (!firstCommand) {
254
+ return createOnesApp.throwError(ErrorCode.INCORRECT_BUILD_COMMAND, i18n.t("error.build.incorrectCommand"));
255
+ }
256
+ const currentCommand = normalizedOptions.command ? normalizedOptions.command.split(" ") : (_appRcJSON$build$comm = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.command) !== null && _appRcJSON$build$comm !== void 0 ? _appRcJSON$build$comm : [];
257
+ const currentCommandString = currentCommand.join(" ");
258
+ const defaultBuildCommandString = defaultBuildCommand.join(" ");
259
+ let shouldBuild = false;
260
+ if (firstCommand === "npm") {
261
+ const appPackageJSONPath = getAppPackageJSONPath();
262
+ const isExists = existsSync(appPackageJSONPath);
263
+ if (isExists) {
264
+ shouldBuild = true;
265
+ const appPackageJSON = getAppPackageJSON();
266
+ if (currentCommandString === defaultBuildCommandString) {
267
+ var _appPackageJSON$scrip;
268
+ if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build)
269
+ ;
270
+ else {
271
+ return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
235
272
  }
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
273
  }
241
- } else {
242
- return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
274
+ }
275
+ } else {
276
+ shouldBuild = true;
277
+ }
278
+ if (shouldBuild) {
279
+ const buildResult = node_child_process.spawnSync(firstCommand, currentCommand.slice(1), {
280
+ cwd: getAppWorkspacePath(),
281
+ stdio: "inherit",
282
+ env: {
283
+ ...process.env,
284
+ NODE_ENV: "production"
285
+ }
286
+ });
287
+ if (buildResult.status !== 0 || buildResult.signal) {
288
+ var _buildResult$status;
289
+ process.exit((_buildResult$status = buildResult.status) !== null && _buildResult$status !== void 0 ? _buildResult$status : 1);
243
290
  }
244
291
  }
245
292
  const appName = appManifestJSON.app.name;
246
293
  const outputPath = normalizedOptions.output;
294
+ const outputDir = node_path.dirname(outputPath);
247
295
  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 : [];
296
+ ensureDirSync(outputDir);
297
+ const outputStream = node_fs.createWriteStream(outputPath);
298
+ const files = (_appRcJSON$build$comp = (_appRcJSON$build2 = appRcJSON.build) === null || _appRcJSON$build2 === void 0 || (_appRcJSON$build2 = _appRcJSON$build2.compress) === null || _appRcJSON$build2 === void 0 ? void 0 : _appRcJSON$build2.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
250
299
  const archive = archiver("zip", {
251
300
  zlib: {
252
301
  level: 9
@@ -281,7 +330,7 @@ const build = async function() {
281
330
  cwd: getAppWorkspacePath()
282
331
  });
283
332
  });
284
- archive.file(createOnesApp.PUBLIC_FILENAME.MANIFEST, {
333
+ archive.file(node_path.join(getAppWorkspacePath(), createOnesApp.PUBLIC_FILENAME.MANIFEST), {
285
334
  name: createOnesApp.PUBLIC_FILENAME.MANIFEST
286
335
  });
287
336
  archive.finalize();
@@ -289,7 +338,8 @@ const build = async function() {
289
338
  const config = {
290
339
  defaultPort: {
291
340
  login: 8200,
292
- tunnel: 8201
341
+ hosted: 8201,
342
+ devWebServer: 8202
293
343
  }
294
344
  };
295
345
  const getConfig = () => config;
@@ -404,44 +454,18 @@ const setHostToken = async (token) => {
404
454
  host_token: token
405
455
  });
406
456
  };
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"));
419
- }
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"));
426
- }
427
- if (portNumber < minPortNumber || portNumber > maxPortNumber) {
428
- return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
429
- }
430
- const port = portString;
431
- return {
432
- port
433
- };
434
- };
435
457
  const API = {
436
458
  TOKEN_INFO: "/project/api/project/auth/token_info",
437
459
  HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
460
+ HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/:appID/dev_declare",
438
461
  APP_LIST: "/platform/api/app/list",
439
462
  APP_INSTALL: "/platform/api/app/install",
440
- APP_UPGRADE: "/platform/api/app/upgrade",
463
+ APP_UPGRADE: "/platform/api/app/:installation_id/upgrade",
441
464
  APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
442
465
  APP_ENABLE: "/platform/api/app/:installation_id/enable",
443
466
  APP_DISABLE: "/platform/api/app/:installation_id/disable"
444
467
  };
468
+ const REQUEST_TIMEOUT = 5e3;
445
469
  const getPath = (path, map2) => {
446
470
  var _context;
447
471
  return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
@@ -468,6 +492,16 @@ const getURL = async (path, pathMap, queryMap) => {
468
492
  }
469
493
  consoleUnauthorizedMessage();
470
494
  };
495
+ const getHostedFetchHeaders = async (value) => {
496
+ const hostedToken = await getHostToken();
497
+ if (hostedToken) {
498
+ return lodashEs.merge({
499
+ Authorization: `Bearer ${hostedToken}`
500
+ }, value);
501
+ }
502
+ consoleUnauthorizedMessage();
503
+ process.exit(1);
504
+ };
471
505
  const getHeaders = async (value) => {
472
506
  const token = await getONESToken();
473
507
  if (token) {
@@ -496,6 +530,21 @@ const handleError = (error) => {
496
530
  console.error(error);
497
531
  return {};
498
532
  };
533
+ const startWaiting = () => {
534
+ const time = 3e3;
535
+ let spinner = null;
536
+ const sid = setTimeout(() => {
537
+ spinner = ora("Waiting for response...");
538
+ spinner.start();
539
+ }, time);
540
+ const cancelWaiting = () => {
541
+ clearTimeout(sid);
542
+ if (spinner) {
543
+ spinner.stop();
544
+ }
545
+ };
546
+ return cancelWaiting;
547
+ };
499
548
  const fetchAppBase = async (params) => {
500
549
  var _params$url;
501
550
  const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
@@ -503,7 +552,20 @@ const fetchAppBase = async (params) => {
503
552
  const response = await axios({
504
553
  ...params,
505
554
  url,
506
- headers
555
+ headers,
556
+ timeout: REQUEST_TIMEOUT
557
+ });
558
+ return response.data;
559
+ };
560
+ const fetchHostedAbilityBase = async (params) => {
561
+ var _params$url2;
562
+ const url = await getURL((_params$url2 = params.url) !== null && _params$url2 !== void 0 ? _params$url2 : "", params.pathMap, params.queryMap);
563
+ const headers = await getHostedFetchHeaders(params.headers);
564
+ const response = await axios({
565
+ ...params,
566
+ url,
567
+ headers,
568
+ timeout: REQUEST_TIMEOUT
507
569
  });
508
570
  return response.data;
509
571
  };
@@ -529,14 +591,33 @@ const fetchHostedToken = async (data) => {
529
591
  data
530
592
  }).catch(handleError);
531
593
  };
594
+ const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
595
+ return await fetchHostedAbilityBase({
596
+ url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
597
+ method: "POST",
598
+ pathMap: {
599
+ appID
600
+ },
601
+ data
602
+ }).catch(handleError);
603
+ };
532
604
  const fetchAppInstall = async (data) => {
533
605
  var _appList$data$0$insta, _appList$data;
534
606
  const appID = getAppManifestJSON().app.id;
535
607
  const appList = await fetchAppList(appID);
536
608
  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;
609
+ if (installationID) {
610
+ return await fetchAppBase({
611
+ url: API.APP_UPGRADE,
612
+ method: "POST",
613
+ pathMap: {
614
+ installation_id: installationID
615
+ },
616
+ data
617
+ }).catch(handleError);
618
+ }
538
619
  return await fetchAppBase({
539
- url,
620
+ url: API.APP_INSTALL,
540
621
  method: "POST",
541
622
  data
542
623
  }).catch(handleError);
@@ -592,6 +673,55 @@ const fetchAppDisable = async () => {
592
673
  consoleAppNotInstalledMessage();
593
674
  process.exit(1);
594
675
  };
676
+ const checkTokenInfo = async () => {
677
+ var _store$ones_token, _store$region_url;
678
+ let boolean = true;
679
+ const store = await getStore();
680
+ const token = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
681
+ const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
682
+ if (token && regionURL) {
683
+ await fetchAppBase({
684
+ url: API.APP_LIST,
685
+ method: "GET"
686
+ }).catch(() => {
687
+ boolean = false;
688
+ });
689
+ } else {
690
+ boolean = false;
691
+ }
692
+ return boolean;
693
+ };
694
+ const isPortNumber = /^[1-9]\d{0,4}$/;
695
+ const minPortNumber = 1;
696
+ const maxPortNumber = 65535;
697
+ const MANIFEST_PATH = "/manifest";
698
+ const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
699
+ const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
700
+ const normalize$9 = async (options) => {
701
+ var _options$useStorage;
702
+ const portInput = options.port;
703
+ if (portInput)
704
+ ;
705
+ else {
706
+ return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
707
+ }
708
+ const portString = String(portInput);
709
+ const portNumber = Number(portString);
710
+ if (isPortNumber.test(portString))
711
+ ;
712
+ else {
713
+ return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
714
+ }
715
+ if (portNumber < minPortNumber || portNumber > maxPortNumber) {
716
+ return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
717
+ }
718
+ const port = portString;
719
+ validateAppManifestJSON();
720
+ return {
721
+ port,
722
+ useStorage: (_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : false
723
+ };
724
+ };
595
725
  const getTunnelContext = async () => {
596
726
  var _appManifestJSON$app$, _appManifestJSON$app, _store$region_url, _store$ones_token;
597
727
  const appManifestJSON = getAppManifestJSON();
@@ -611,7 +741,7 @@ const getTunnelContext = async () => {
611
741
  consoleUnauthorizedMessage();
612
742
  process.exit(1);
613
743
  };
614
- const getHostedTokenScopes = (ones2) => {
744
+ const getStorageTokenScopes = (ones2) => {
615
745
  const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
616
746
  if (!storage) {
617
747
  return [];
@@ -733,14 +863,16 @@ class TunnelClient {
733
863
  };
734
864
  this.sendBinaryEnvelope(reply);
735
865
  } catch (error) {
866
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
867
+ console.error("Error forwarding request:", errorMessage);
736
868
  const reply = {
737
869
  id: message.id,
738
870
  payload: {
739
871
  status: 500,
740
872
  headers: {
741
- "x-agent-error": [error instanceof Error ? error.message : "Unknown error"]
873
+ "x-agent-error": [errorMessage]
742
874
  },
743
- body: "agent request error"
875
+ body: errorMessage
744
876
  }
745
877
  };
746
878
  this.sendBinaryEnvelope(reply);
@@ -890,7 +1022,7 @@ class TunnelClient {
890
1022
  }
891
1023
  }
892
1024
  const invokeTunnel = async function(port) {
893
- var _options$rebuildWhenE, _options$enableIntern, _hostedTokenResponse$;
1025
+ var _options$rebuildWhenE, _options$enableIntern, _options$useStorageFo, _hostedTokenResponse$, _appManifestJSON$ones, _appManifestJSON$ones2;
894
1026
  let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
895
1027
  const {
896
1028
  appManifestJSON,
@@ -899,21 +1031,29 @@ const invokeTunnel = async function(port) {
899
1031
  } = await getTunnelContext();
900
1032
  const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
901
1033
  const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
902
- const storageScopes = getHostedTokenScopes(appManifestJSON.ones);
1034
+ const storageScopes = getStorageTokenScopes(appManifestJSON.ones);
903
1035
  const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
904
1036
  const hostedTokenResponse = await fetchHostedToken({
905
1037
  app_id: appID,
906
- scopes
1038
+ scopes,
1039
+ confirm_for_dev: (_options$useStorageFo = options.useStorageForDev) !== null && _options$useStorageFo !== void 0 ? _options$useStorageFo : false
907
1040
  });
908
1041
  const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
909
1042
  if (!hostedToken) {
910
1043
  return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
911
1044
  }
912
1045
  await setHostToken(hostedToken);
1046
+ const entities = (_appManifestJSON$ones = (_appManifestJSON$ones2 = appManifestJSON.ones) === null || _appManifestJSON$ones2 === void 0 || (_appManifestJSON$ones2 = _appManifestJSON$ones2.storage) === null || _appManifestJSON$ones2 === void 0 ? void 0 : _appManifestJSON$ones2.entities) !== null && _appManifestJSON$ones !== void 0 ? _appManifestJSON$ones : [];
1047
+ if (entities.length > 0) {
1048
+ await fetchHostedAbilityStorageDevDeclare(appID, {
1049
+ opkx_content: appManifestJSON
1050
+ });
1051
+ }
913
1052
  const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
914
1053
  await client.connect();
915
1054
  };
916
1055
  const tunnel = async function() {
1056
+ var _normalizedOptions$us;
917
1057
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
918
1058
  args[_key] = arguments[_key];
919
1059
  }
@@ -921,12 +1061,114 @@ const tunnel = async function() {
921
1061
  options
922
1062
  } = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
923
1063
  const normalizedOptions = await normalize$9(options);
924
- await invokeTunnel(Number(normalizedOptions.port), {
1064
+ const port = Number(normalizedOptions.port);
1065
+ const cancelWaiting = startWaiting();
1066
+ await invokeTunnel(port, {
925
1067
  enableInternalManifestRoute: false,
926
- rebuildWhenExists: true
1068
+ rebuildWhenExists: true,
1069
+ useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
927
1070
  });
928
- const runnelUrl = await buildTunnelUrl();
929
- console.log(`Relay endpoint: ${runnelUrl}`);
1071
+ cancelWaiting();
1072
+ const tunnelUrl = await buildTunnelUrl();
1073
+ console.log(`Relay endpoint: ${tunnelUrl}`);
1074
+ };
1075
+ const normalize$8 = async (options) => {
1076
+ lodashEs.noop(options);
1077
+ return {};
1078
+ };
1079
+ const displayAppDetail = async (installationID) => {
1080
+ var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
1081
+ const tokenInfo = await fetchTokenInfo();
1082
+ 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 : "";
1083
+ 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 : "";
1084
+ 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;
1085
+ const baseURL = await getBaseURL();
1086
+ if (isOrgVisible && orgUUID) {
1087
+ const url = `${baseURL}project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
1088
+ console.log(`See App detail: ${url}`);
1089
+ }
1090
+ if (!isOrgVisible && teamUUID) {
1091
+ const url = `${baseURL}project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
1092
+ console.log(`See App detail: ${url}`);
1093
+ }
1094
+ };
1095
+ const invokeInstall = async (manifestUrl) => {
1096
+ const {
1097
+ app
1098
+ } = getAppManifestJSON();
1099
+ const appName = app.name;
1100
+ const appID = app.id;
1101
+ const cancelWaiting = startWaiting();
1102
+ const result = await fetchAppInstall({
1103
+ manifest_url: manifestUrl,
1104
+ options: {
1105
+ enable: true
1106
+ }
1107
+ });
1108
+ cancelWaiting();
1109
+ if (result.code === "OK") {
1110
+ var _appList$data$0$insta, _appList$data;
1111
+ console.log(`App "${appName}" installed successfully!`);
1112
+ const appList = await fetchAppList(appID);
1113
+ 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 : "";
1114
+ if (installationID) {
1115
+ await displayAppDetail(installationID);
1116
+ }
1117
+ return true;
1118
+ } else {
1119
+ console.log(`App "${appName}" installed failed!`);
1120
+ console.error(JSON.stringify(result, null, 2));
1121
+ }
1122
+ return false;
1123
+ };
1124
+ const getManifestUrl = async () => {
1125
+ const tunnelUrl = await buildTunnelUrl();
1126
+ const customManifestUrl = `${tunnelUrl}${MANIFEST_PATH}`;
1127
+ const internalManifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
1128
+ const internalResult = await axios.get(internalManifestUrl, {
1129
+ timeout: REQUEST_TIMEOUT
1130
+ }).then((response) => {
1131
+ if (response.status === 200) {
1132
+ return internalManifestUrl;
1133
+ }
1134
+ return null;
1135
+ }).catch(lodashEs.noop);
1136
+ if (internalResult) {
1137
+ return internalResult;
1138
+ }
1139
+ const customResult = await axios.get(customManifestUrl, {
1140
+ timeout: REQUEST_TIMEOUT
1141
+ }).then((response) => {
1142
+ if (response.status === 200) {
1143
+ return customManifestUrl;
1144
+ }
1145
+ return null;
1146
+ }).catch(lodashEs.noop);
1147
+ if (customResult) {
1148
+ return customResult;
1149
+ }
1150
+ return null;
1151
+ };
1152
+ const install = async function() {
1153
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1154
+ args[_key] = arguments[_key];
1155
+ }
1156
+ const {
1157
+ options
1158
+ } = createOnesApp.getCommandOptions(args, installCommandArguments);
1159
+ const normalizedOptions = await normalize$8(options);
1160
+ lodashEs.noop(normalizedOptions);
1161
+ const {
1162
+ app
1163
+ } = getAppManifestJSON();
1164
+ const appName = app.name;
1165
+ const manifestUrl = await getManifestUrl();
1166
+ if (!manifestUrl) {
1167
+ console.log(`App "${appName}" server not available!`);
1168
+ console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
1169
+ process.exit(1);
1170
+ }
1171
+ await invokeInstall(manifestUrl);
930
1172
  };
931
1173
  var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
932
1174
  InstallOptions2["AUTO"] = "auto";
@@ -934,119 +1176,200 @@ var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
934
1176
  InstallOptions2["FALSE"] = "false";
935
1177
  return InstallOptions2;
936
1178
  })(InstallOptions || {});
1179
+ var DevCommandScripts = /* @__PURE__ */ ((DevCommandScripts2) => {
1180
+ DevCommandScripts2["Concurrently"] = "concurrently";
1181
+ DevCommandScripts2["Nest"] = "nest";
1182
+ DevCommandScripts2["Vite"] = "vite";
1183
+ return DevCommandScripts2;
1184
+ })(DevCommandScripts || {});
937
1185
  const defaultInstall = InstallOptions.AUTO;
938
- const normalize$8 = async (options) => {
939
- var _options$install;
1186
+ const normalize$7 = async (options) => {
1187
+ var _options$install, _options$command, _options$useStorage;
940
1188
  let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
1189
+ const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
1190
+ const useStorageString = `${(_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : ""}`;
941
1191
  switch (true) {
942
1192
  case install2 === InstallOptions.AUTO:
943
1193
  break;
944
- case Boolean(install2):
945
- install2 = InstallOptions.TRUE;
1194
+ case install2 === InstallOptions.FALSE:
946
1195
  break;
947
1196
  default:
948
- install2 = InstallOptions.FALSE;
1197
+ install2 = InstallOptions.TRUE;
949
1198
  break;
950
1199
  }
1200
+ validateAppManifestJSON();
951
1201
  return {
952
- install: install2
1202
+ install: install2,
1203
+ command,
1204
+ useStorage: useStorageString === "false" ? false : true
953
1205
  };
954
1206
  };
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
- }
1207
+ const IDLE_MS = 2e3;
987
1208
  const dev = async function() {
988
- var _ref, _appRcJSON$dev$comman, _appRcJSON$dev, _defaultAppRcJSON$dev;
1209
+ var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2;
989
1210
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
990
1211
  args[_key] = arguments[_key];
991
1212
  }
992
1213
  const {
993
1214
  options
994
1215
  } = createOnesApp.getCommandOptions(args, devCommandArguments);
995
- const normalizedOptions = await normalize$8(options);
1216
+ const normalizedOptions = await normalize$7(options);
996
1217
  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"));
1218
+ 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]) || "";
1219
+ if (!firstCommand) {
1220
+ return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
1221
+ }
1222
+ 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 : [];
1223
+ const currentCommandString = currentCommand.join(" ");
1224
+ const defaultDevCommandString = defaultDevCommand.join(" ");
1225
+ let templateCommand = false;
1226
+ if (firstCommand === "npm") {
1227
+ const appPackageJSON = getAppPackageJSON();
1228
+ if (currentCommandString === defaultDevCommandString) {
1229
+ var _appPackageJSON$scrip;
1230
+ if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev) {
1231
+ var _appPackageJSON$scrip2, _appPackageJSON$scrip3, _appPackageJSON$scrip4;
1232
+ const dev2 = (_appPackageJSON$scrip2 = appPackageJSON.scripts.dev) !== null && _appPackageJSON$scrip2 !== void 0 ? _appPackageJSON$scrip2 : "";
1233
+ const devWeb = (_appPackageJSON$scrip3 = appPackageJSON.scripts["dev:web"]) !== null && _appPackageJSON$scrip3 !== void 0 ? _appPackageJSON$scrip3 : "";
1234
+ const devBackend = (_appPackageJSON$scrip4 = appPackageJSON.scripts["dev:backend"]) !== null && _appPackageJSON$scrip4 !== void 0 ? _appPackageJSON$scrip4 : "";
1235
+ const hasConcurrently = _includesInstanceProperty(dev2).call(dev2, DevCommandScripts.Concurrently);
1236
+ const hasNest = _includesInstanceProperty(devBackend).call(devBackend, DevCommandScripts.Nest);
1237
+ const hasVite = _includesInstanceProperty(devWeb).call(devWeb, DevCommandScripts.Vite);
1238
+ templateCommand = hasConcurrently && hasNest && hasVite;
1239
+ } else {
1240
+ return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
1241
+ }
1006
1242
  }
1007
1243
  }
1008
- const port = getConfig().defaultPort.tunnel;
1009
- await invokeTunnel(port, {
1010
- enableInternalManifestRoute: true,
1011
- rebuildWhenExists: true
1244
+ const appManifestJSON = getAppManifestJSON();
1245
+ const {
1246
+ app
1247
+ } = appManifestJSON;
1248
+ const appID = app.id;
1249
+ const config2 = getConfig();
1250
+ const ONES_HOSTED_PORT = await getPort({
1251
+ port: config2.defaultPort.hosted
1252
+ });
1253
+ const ONES_DEV_WEB_SERVER_PORT = await getPort({
1254
+ port: config2.defaultPort.devWebServer
1012
1255
  });
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
1256
  const env2 = {
1018
1257
  ...process.env,
1019
1258
  NODE_ENV: "development",
1020
- ONES_HOSTED_PORT: `${port}`,
1021
- ONES_HOSTED_TOKEN
1259
+ ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
1260
+ ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
1261
+ ONES_HOSTED_TOKEN: "",
1262
+ ONES_HOSTED_APP_ID: "",
1263
+ ONES_HOSTED_BASE_URL: ""
1022
1264
  };
1023
- const {
1024
- ones: ones2
1025
- } = getAppManifestJSON();
1026
- lodashEs.noop(ones2);
1027
- const onReady = () => {
1265
+ const cancelWaiting = startWaiting();
1266
+ let enableTunnel = true;
1267
+ if (normalizedOptions.install === InstallOptions.TRUE)
1268
+ ;
1269
+ else {
1270
+ enableTunnel = await checkTokenInfo();
1271
+ }
1272
+ if (enableTunnel) {
1273
+ var _normalizedOptions$us;
1274
+ await invokeTunnel(ONES_HOSTED_PORT, {
1275
+ enableInternalManifestRoute: true,
1276
+ rebuildWhenExists: true,
1277
+ useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
1278
+ });
1279
+ const regionURL = await getRegionURL();
1280
+ const ONES_HOSTED_TOKEN = await getHostToken();
1281
+ const ONES_HOSTED_APP_ID = appID;
1282
+ const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
1283
+ env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
1284
+ env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
1285
+ env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
1286
+ } else {
1287
+ console.log("Not logged in or session expired, skipping tunnel connection...");
1288
+ }
1289
+ cancelWaiting();
1290
+ const onReady = async () => {
1291
+ const appName = app.name;
1292
+ let manifestUrl = "";
1028
1293
  console.log("");
1029
- console.log(`Local: http://localhost:${port}`);
1030
- console.log(`Relay endpoint: ${runnelUrl}`);
1031
- console.log(`Manifest URL: ${manifestUrl}`);
1294
+ console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
1295
+ if (enableTunnel) {
1296
+ const tunnelUrl = await buildTunnelUrl();
1297
+ console.log(`URL: ${tunnelUrl}`);
1298
+ manifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
1299
+ }
1300
+ console.log(`App "${appName}" server is ready!`);
1032
1301
  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;
1302
+ if (enableTunnel) {
1303
+ switch (normalizedOptions.install) {
1304
+ case InstallOptions.TRUE:
1305
+ await invokeInstall(manifestUrl);
1306
+ break;
1307
+ case InstallOptions.AUTO:
1308
+ {
1309
+ var _appList$data$0$insta, _appList$data;
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
+ await displayAppDetail(installationID);
1314
+ } else {
1315
+ await invokeInstall(manifestUrl);
1316
+ }
1317
+ }
1318
+ break;
1319
+ case InstallOptions.FALSE:
1320
+ break;
1321
+ }
1042
1322
  }
1043
1323
  };
1044
- const child = node_child_process.spawn(currentCommand, [], {
1324
+ const cwd = getAppWorkspacePath();
1325
+ const child = node_child_process.spawn(firstCommand, currentCommand.slice(1), {
1045
1326
  cwd,
1046
1327
  stdio: ["inherit", "pipe", "pipe"],
1047
1328
  env: env2,
1048
1329
  shell: true
1049
1330
  });
1331
+ const createReadyStatusPipes = (onReady2) => {
1332
+ let readyTimer = null;
1333
+ let summaryPrinted = false;
1334
+ const scheduleReady = () => {
1335
+ if (summaryPrinted)
1336
+ return;
1337
+ if (readyTimer)
1338
+ clearTimeout(readyTimer);
1339
+ readyTimer = setTimeout(() => {
1340
+ readyTimer = null;
1341
+ if (!summaryPrinted) {
1342
+ summaryPrinted = true;
1343
+ onReady2();
1344
+ }
1345
+ }, IDLE_MS);
1346
+ };
1347
+ const pipe2 = (stream, isStderr) => {
1348
+ const write = (chunk) => {
1349
+ if (isStderr)
1350
+ process.stderr.write(chunk);
1351
+ else
1352
+ process.stdout.write(chunk);
1353
+ };
1354
+ if (templateCommand) {
1355
+ stream.on("data", (chunk) => {
1356
+ const str = typeof chunk === "string" ? chunk : chunk.toString();
1357
+ write(str);
1358
+ if (str.startsWith("[backend]") || str.startsWith("[web]")) {
1359
+ scheduleReady();
1360
+ }
1361
+ });
1362
+ } else {
1363
+ scheduleReady();
1364
+ stream.on("data", (chunk) => {
1365
+ const str = typeof chunk === "string" ? chunk : chunk.toString();
1366
+ write(str);
1367
+ scheduleReady();
1368
+ });
1369
+ }
1370
+ };
1371
+ return pipe2;
1372
+ };
1050
1373
  const pipe = createReadyStatusPipes(onReady);
1051
1374
  if (child.stdout)
1052
1375
  pipe(child.stdout, false);
@@ -1090,7 +1413,7 @@ const sleep = (number) => {
1090
1413
  };
1091
1414
  const isURL = /^https?:\/\//;
1092
1415
  const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
1093
- const normalize$7 = async (options) => {
1416
+ const normalize$6 = async (options) => {
1094
1417
  const baseURLInput = options.baseURL;
1095
1418
  if (baseURLInput)
1096
1419
  ;
@@ -1127,7 +1450,7 @@ const login = async function() {
1127
1450
  const {
1128
1451
  options
1129
1452
  } = createOnesApp.getCommandOptions(args, loginCommandArguments);
1130
- const normalizedOptions = await normalize$7(options);
1453
+ const normalizedOptions = await normalize$6(options);
1131
1454
  const base = normalizedOptions.baseURL;
1132
1455
  const path = "project/oauth2.html";
1133
1456
  const config2 = getConfig();
@@ -1204,14 +1527,28 @@ const login = async function() {
1204
1527
  } else {
1205
1528
  console.log("Login canceled!");
1206
1529
  }
1530
+ }).finally(() => {
1207
1531
  process$1.exit(0);
1208
1532
  });
1533
+ let exited = false;
1534
+ const handleExit = () => {
1535
+ if (exited)
1536
+ return;
1537
+ exited = true;
1538
+ resolve(null);
1539
+ };
1540
+ process$1.on("SIGINT", handleExit);
1541
+ process$1.on("SIGTERM", handleExit);
1209
1542
  console.log("Logging into your ONES account...");
1210
1543
  console.log(`Opening ${url}`);
1211
1544
  ora("Waiting for authorization...").start();
1212
- await open(url);
1545
+ try {
1546
+ await open(url);
1547
+ } catch (error) {
1548
+ return createOnesApp.throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
1549
+ }
1213
1550
  };
1214
- const normalize$6 = async (options) => {
1551
+ const normalize$5 = async (options) => {
1215
1552
  lodashEs.noop(options);
1216
1553
  return {};
1217
1554
  };
@@ -1222,12 +1559,12 @@ const logout = async function() {
1222
1559
  const {
1223
1560
  options
1224
1561
  } = createOnesApp.getCommandOptions(args, logoutCommandArguments);
1225
- const normalizedOptions = await normalize$6(options);
1562
+ const normalizedOptions = await normalize$5(options);
1226
1563
  lodashEs.noop(normalizedOptions);
1227
1564
  await setStore({});
1228
1565
  console.log("Logged out successfully!");
1229
1566
  };
1230
- const normalize$5 = async (options) => {
1567
+ const normalize$4 = async (options) => {
1231
1568
  lodashEs.noop(options);
1232
1569
  return {};
1233
1570
  };
@@ -1239,10 +1576,12 @@ const whoami = async function() {
1239
1576
  const {
1240
1577
  options
1241
1578
  } = createOnesApp.getCommandOptions(args, whoamiCommandArguments);
1242
- const normalizedOptions = await normalize$5(options);
1579
+ const normalizedOptions = await normalize$4(options);
1243
1580
  lodashEs.noop(normalizedOptions);
1244
1581
  const baseURL = await getBaseURL();
1582
+ const cancelWaiting = startWaiting();
1245
1583
  const tokenInfo = await fetchTokenInfo();
1584
+ cancelWaiting();
1246
1585
  const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
1247
1586
  const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
1248
1587
  if (name2 && email) {
@@ -1253,83 +1592,6 @@ const whoami = async function() {
1253
1592
  consoleUnauthorizedMessage();
1254
1593
  }
1255
1594
  };
1256
- const normalize$4 = async (options) => {
1257
- lodashEs.noop(options);
1258
- return {};
1259
- };
1260
- const getManifestUrl = async () => {
1261
- const runnelUrl = await buildTunnelUrl();
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;
1283
- };
1284
- const install = async function() {
1285
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1286
- args[_key] = arguments[_key];
1287
- }
1288
- const {
1289
- options
1290
- } = createOnesApp.getCommandOptions(args, installCommandArguments);
1291
- const normalizedOptions = await normalize$4(options);
1292
- lodashEs.noop(normalizedOptions);
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
- });
1307
- if (result.code === "OK") {
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
- }
1328
- } else {
1329
- console.log(`App "${appName}" installed failed!`);
1330
- console.error(JSON.stringify(result, null, 2));
1331
- }
1332
- };
1333
1595
  const normalize$3 = async (options) => {
1334
1596
  lodashEs.noop(options);
1335
1597
  return {};
@@ -1344,7 +1606,9 @@ const enable = async function() {
1344
1606
  const normalizedOptions = await normalize$3(options);
1345
1607
  lodashEs.noop(normalizedOptions);
1346
1608
  const appName = getAppManifestJSON().app.name;
1609
+ const cancelWaiting = startWaiting();
1347
1610
  const result = await fetchAppEnable();
1611
+ cancelWaiting();
1348
1612
  if (result.code === "OK") {
1349
1613
  console.log(`App "${appName}" enabled successfully!`);
1350
1614
  } else {
@@ -1366,7 +1630,9 @@ const disable = async function() {
1366
1630
  const normalizedOptions = await normalize$2(options);
1367
1631
  lodashEs.noop(normalizedOptions);
1368
1632
  const appName = getAppManifestJSON().app.name;
1633
+ const cancelWaiting = startWaiting();
1369
1634
  const result = await fetchAppDisable();
1635
+ cancelWaiting();
1370
1636
  if (result.code === "OK") {
1371
1637
  console.log(`App "${appName}" disabled successfully!`);
1372
1638
  } else {
@@ -1388,7 +1654,9 @@ const uninstall = async function() {
1388
1654
  const normalizedOptions = await normalize$1(options);
1389
1655
  lodashEs.noop(normalizedOptions);
1390
1656
  const appName = getAppManifestJSON().app.name;
1657
+ const cancelWaiting = startWaiting();
1391
1658
  const result = await fetchAppUninstall();
1659
+ cancelWaiting();
1392
1660
  if (result.code === "OK") {
1393
1661
  console.log(`App "${appName}" uninstalled successfully!`);
1394
1662
  } else {
@@ -1396,10 +1664,29 @@ const uninstall = async function() {
1396
1664
  console.error(JSON.stringify(result, null, 2));
1397
1665
  }
1398
1666
  };
1667
+ const getTemplatePath = () => {
1668
+ const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
1669
+ return node_path.join(__dirname, "../template");
1670
+ };
1671
+ const getTemplateLegacy = () => {
1672
+ return "legacy";
1673
+ };
1399
1674
  const normalize = async (options) => {
1400
- lodashEs.noop(options);
1401
- return {};
1675
+ const projectPathInput = options.projectPath;
1676
+ if (projectPathInput)
1677
+ ;
1678
+ else {
1679
+ return createOnesApp.throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.legacy.create.missingProjectPath"));
1680
+ }
1681
+ const projectPath = node_path.resolve(process$1.cwd(), projectPathInput);
1682
+ return {
1683
+ projectPath
1684
+ };
1402
1685
  };
1686
+ const {
1687
+ copy,
1688
+ moveSync
1689
+ } = fse;
1403
1690
  const legacy = async function() {
1404
1691
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1405
1692
  args[_key] = arguments[_key];
@@ -1408,18 +1695,30 @@ const legacy = async function() {
1408
1695
  options
1409
1696
  } = createOnesApp.getCommandOptions(args, legacyCommandArguments);
1410
1697
  const normalizedOptions = await normalize(options);
1411
- console.log("legacy", normalizedOptions);
1698
+ const {
1699
+ projectPath
1700
+ } = normalizedOptions;
1701
+ const templatePath = node_path.join(getTemplatePath(), getTemplateLegacy());
1702
+ await copy(templatePath, projectPath);
1703
+ const rename = [["_eslintignore", ".eslintignore"], ["_eslintrc.js", ".eslintrc.js"], ["_gitignore", ".gitignore"], ["_gitlab-ci.yml", ".gitlab-ci.yml"], ["_npmrc", ".npmrc"], ["_prettierignore", ".prettierignore"], ["_prettierrc", ".prettierrc"], ["_backend_npmrc", "backend/.npmrc"], ["_backend_tsconfig.json", "backend/tsconfig.json"], ["_web_npmrc", "web/.npmrc"], ["_web_tsconfig.json", "web/tsconfig.json"], ["_husky_pre-commit", ".husky/pre-commit"]];
1704
+ rename.forEach((_ref) => {
1705
+ let [from, to] = _ref;
1706
+ moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
1707
+ overwrite: true
1708
+ });
1709
+ });
1710
+ console.log("Plugin created successfully!");
1412
1711
  };
1413
1712
  const buildCommandArguments = [];
1414
- const $build = new commander.Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).action(build);
1713
+ const $build = new commander.Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).option("-c, --command [string]", i18n.t("desc.build.command")).action(build);
1415
1714
  createOnesApp.addCommandUsage($build);
1416
1715
  createOnesApp.addCommandOutput($build);
1417
1716
  const devCommandArguments = [];
1418
- const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).action(dev);
1717
+ 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")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(dev);
1419
1718
  createOnesApp.addCommandUsage($dev);
1420
1719
  createOnesApp.addCommandOutput($dev);
1421
1720
  const tunnelCommandArguments = ["port"];
1422
- const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).action(tunnel);
1721
+ const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(tunnel);
1423
1722
  createOnesApp.addCommandUsage($tunnel);
1424
1723
  createOnesApp.addCommandOutput($tunnel);
1425
1724
  const loginCommandArguments = ["baseURL"];
@@ -1454,8 +1753,12 @@ const $app = new commander.Command("app").description(i18n.t("desc.app"));
1454
1753
  $app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
1455
1754
  createOnesApp.addCommandUsage($app);
1456
1755
  createOnesApp.addCommandOutput($app);
1457
- const legacyCommandArguments = [];
1458
- const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy")).action(legacy);
1756
+ const legacyCommandArguments = ["projectPath"];
1757
+ const $create = new commander.Command("create").description(i18n.t("desc.legacy.create")).argument("<project-path>", i18n.t("desc.legacy.create.projectPath")).action(legacy);
1758
+ createOnesApp.addCommandUsage($create);
1759
+ createOnesApp.addCommandOutput($create);
1760
+ const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"));
1761
+ $legacy.addCommand($create);
1459
1762
  createOnesApp.addCommandUsage($legacy);
1460
1763
  createOnesApp.addCommandOutput($legacy);
1461
1764
  const ones = new commander.Command("ones");