@ones-open/cli 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/bin/ones.js +4 -0
- package/dist/index.cjs +1889 -0
- package/dist/index.js +1888 -0
- package/dist/types/actions/build/index.d.ts +4 -0
- package/dist/types/actions/build/index.d.ts.map +1 -0
- package/dist/types/actions/build/normalize.d.ts +6 -0
- package/dist/types/actions/build/normalize.d.ts.map +1 -0
- package/dist/types/actions/build/regexp.d.ts +2 -0
- package/dist/types/actions/build/regexp.d.ts.map +1 -0
- package/dist/types/actions/dev/enums.d.ts +11 -0
- package/dist/types/actions/dev/enums.d.ts.map +1 -0
- package/dist/types/actions/dev/index.d.ts +4 -0
- package/dist/types/actions/dev/index.d.ts.map +1 -0
- package/dist/types/actions/dev/normalize.d.ts +6 -0
- package/dist/types/actions/dev/normalize.d.ts.map +1 -0
- package/dist/types/actions/dev/types.d.ts +10 -0
- package/dist/types/actions/dev/types.d.ts.map +1 -0
- package/dist/types/actions/disable/index.d.ts +4 -0
- package/dist/types/actions/disable/index.d.ts.map +1 -0
- package/dist/types/actions/disable/normalize.d.ts +6 -0
- package/dist/types/actions/disable/normalize.d.ts.map +1 -0
- package/dist/types/actions/enable/index.d.ts +4 -0
- package/dist/types/actions/enable/index.d.ts.map +1 -0
- package/dist/types/actions/enable/normalize.d.ts +6 -0
- package/dist/types/actions/enable/normalize.d.ts.map +1 -0
- package/dist/types/actions/index.d.ts +15 -0
- package/dist/types/actions/index.d.ts.map +1 -0
- package/dist/types/actions/install/index.d.ts +5 -0
- package/dist/types/actions/install/index.d.ts.map +1 -0
- package/dist/types/actions/install/install.d.ts +3 -0
- package/dist/types/actions/install/install.d.ts.map +1 -0
- package/dist/types/actions/install/normalize.d.ts +6 -0
- package/dist/types/actions/install/normalize.d.ts.map +1 -0
- package/dist/types/actions/legacy/index.d.ts +4 -0
- package/dist/types/actions/legacy/index.d.ts.map +1 -0
- package/dist/types/actions/legacy/normalize.d.ts +6 -0
- package/dist/types/actions/legacy/normalize.d.ts.map +1 -0
- package/dist/types/actions/login/consts.d.ts +2 -0
- package/dist/types/actions/login/consts.d.ts.map +1 -0
- package/dist/types/actions/login/index.d.ts +4 -0
- package/dist/types/actions/login/index.d.ts.map +1 -0
- package/dist/types/actions/login/normalize.d.ts +6 -0
- package/dist/types/actions/login/normalize.d.ts.map +1 -0
- package/dist/types/actions/login/regexp.d.ts +2 -0
- package/dist/types/actions/login/regexp.d.ts.map +1 -0
- package/dist/types/actions/logout/index.d.ts +4 -0
- package/dist/types/actions/logout/index.d.ts.map +1 -0
- package/dist/types/actions/logout/normalize.d.ts +6 -0
- package/dist/types/actions/logout/normalize.d.ts.map +1 -0
- package/dist/types/actions/tunnel/consts.d.ts +4 -0
- package/dist/types/actions/tunnel/consts.d.ts.map +1 -0
- package/dist/types/actions/tunnel/index.d.ts +7 -0
- package/dist/types/actions/tunnel/index.d.ts.map +1 -0
- package/dist/types/actions/tunnel/normalize.d.ts +6 -0
- package/dist/types/actions/tunnel/normalize.d.ts.map +1 -0
- package/dist/types/actions/tunnel/regexp.d.ts +2 -0
- package/dist/types/actions/tunnel/regexp.d.ts.map +1 -0
- package/dist/types/actions/tunnel/tunnel-client.d.ts +25 -0
- package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -0
- package/dist/types/actions/tunnel/tunnel.d.ts +3 -0
- package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -0
- package/dist/types/actions/tunnel/types.d.ts +31 -0
- package/dist/types/actions/tunnel/types.d.ts.map +1 -0
- package/dist/types/actions/tunnel/utils.d.ts +7 -0
- package/dist/types/actions/tunnel/utils.d.ts.map +1 -0
- package/dist/types/actions/uninstall/index.d.ts +4 -0
- package/dist/types/actions/uninstall/index.d.ts.map +1 -0
- package/dist/types/actions/uninstall/normalize.d.ts +6 -0
- package/dist/types/actions/uninstall/normalize.d.ts.map +1 -0
- package/dist/types/actions/whoami/index.d.ts +4 -0
- package/dist/types/actions/whoami/index.d.ts.map +1 -0
- package/dist/types/actions/whoami/normalize.d.ts +6 -0
- package/dist/types/actions/whoami/normalize.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/command/app/index.d.ts +4 -0
- package/dist/types/command/app/index.d.ts.map +1 -0
- package/dist/types/command/build/index.d.ts +10 -0
- package/dist/types/command/build/index.d.ts.map +1 -0
- package/dist/types/command/dev/index.d.ts +11 -0
- package/dist/types/command/dev/index.d.ts.map +1 -0
- package/dist/types/command/disable/index.d.ts +8 -0
- package/dist/types/command/disable/index.d.ts.map +1 -0
- package/dist/types/command/enable/index.d.ts +8 -0
- package/dist/types/command/enable/index.d.ts.map +1 -0
- package/dist/types/command/index.d.ts +16 -0
- package/dist/types/command/index.d.ts.map +1 -0
- package/dist/types/command/install/index.d.ts +8 -0
- package/dist/types/command/install/index.d.ts.map +1 -0
- package/dist/types/command/legacy/index.d.ts +8 -0
- package/dist/types/command/legacy/index.d.ts.map +1 -0
- package/dist/types/command/login/index.d.ts +8 -0
- package/dist/types/command/login/index.d.ts.map +1 -0
- package/dist/types/command/logout/index.d.ts +8 -0
- package/dist/types/command/logout/index.d.ts.map +1 -0
- package/dist/types/command/tunnel/index.d.ts +9 -0
- package/dist/types/command/tunnel/index.d.ts.map +1 -0
- package/dist/types/command/uninstall/index.d.ts +8 -0
- package/dist/types/command/uninstall/index.d.ts.map +1 -0
- package/dist/types/command/whoami/index.d.ts +8 -0
- package/dist/types/command/whoami/index.d.ts.map +1 -0
- package/dist/types/common/base/index.d.ts +5 -0
- package/dist/types/common/base/index.d.ts.map +1 -0
- package/dist/types/common/base/utils.d.ts +7 -0
- package/dist/types/common/base/utils.d.ts.map +1 -0
- package/dist/types/common/command/index.d.ts +6 -0
- package/dist/types/common/command/index.d.ts.map +1 -0
- package/dist/types/common/command/types.d.ts +2 -0
- package/dist/types/common/command/types.d.ts.map +1 -0
- package/dist/types/common/command/utils.d.ts +2 -0
- package/dist/types/common/command/utils.d.ts.map +1 -0
- package/dist/types/common/config/consts.d.ts +5 -0
- package/dist/types/common/config/consts.d.ts.map +1 -0
- package/dist/types/common/config/index.d.ts +7 -0
- package/dist/types/common/config/index.d.ts.map +1 -0
- package/dist/types/common/config/types.d.ts +8 -0
- package/dist/types/common/config/types.d.ts.map +1 -0
- package/dist/types/common/config/utils.d.ts +3 -0
- package/dist/types/common/config/utils.d.ts.map +1 -0
- package/dist/types/common/context/index.d.ts +6 -0
- package/dist/types/common/context/index.d.ts.map +1 -0
- package/dist/types/common/context/types.d.ts +2 -0
- package/dist/types/common/context/types.d.ts.map +1 -0
- package/dist/types/common/context/utils.d.ts +2 -0
- package/dist/types/common/context/utils.d.ts.map +1 -0
- package/dist/types/common/error/enums.d.ts +20 -0
- package/dist/types/common/error/enums.d.ts.map +1 -0
- package/dist/types/common/error/index.d.ts +7 -0
- package/dist/types/common/error/index.d.ts.map +1 -0
- package/dist/types/common/error/types.d.ts +2 -0
- package/dist/types/common/error/types.d.ts.map +1 -0
- package/dist/types/common/error/utils.d.ts +2 -0
- package/dist/types/common/error/utils.d.ts.map +1 -0
- package/dist/types/common/locales/en/index.d.ts +41 -0
- package/dist/types/common/locales/en/index.d.ts.map +1 -0
- package/dist/types/common/locales/index.d.ts +6 -0
- package/dist/types/common/locales/index.d.ts.map +1 -0
- package/dist/types/common/locales/types.d.ts +4 -0
- package/dist/types/common/locales/types.d.ts.map +1 -0
- package/dist/types/common/locales/utils.d.ts +6 -0
- package/dist/types/common/locales/utils.d.ts.map +1 -0
- package/dist/types/common/package/index.d.ts +7 -0
- package/dist/types/common/package/index.d.ts.map +1 -0
- package/dist/types/common/package/schema.d.ts +3 -0
- package/dist/types/common/package/schema.d.ts.map +1 -0
- package/dist/types/common/package/types.d.ts +2 -0
- package/dist/types/common/package/types.d.ts.map +1 -0
- package/dist/types/common/package/utils.d.ts +16 -0
- package/dist/types/common/package/utils.d.ts.map +1 -0
- package/dist/types/common/public/consts.d.ts +2 -0
- package/dist/types/common/public/consts.d.ts.map +1 -0
- package/dist/types/common/public/index.d.ts +6 -0
- package/dist/types/common/public/index.d.ts.map +1 -0
- package/dist/types/common/public/utils.d.ts +2 -0
- package/dist/types/common/public/utils.d.ts.map +1 -0
- package/dist/types/common/request/consts.d.ts +16 -0
- package/dist/types/common/request/consts.d.ts.map +1 -0
- package/dist/types/common/request/fetch.d.ts +13 -0
- package/dist/types/common/request/fetch.d.ts.map +1 -0
- package/dist/types/common/request/index.d.ts +8 -0
- package/dist/types/common/request/index.d.ts.map +1 -0
- package/dist/types/common/request/types.d.ts +98 -0
- package/dist/types/common/request/types.d.ts.map +1 -0
- package/dist/types/common/request/utils.d.ts +11 -0
- package/dist/types/common/request/utils.d.ts.map +1 -0
- package/dist/types/common/store/index.d.ts +6 -0
- package/dist/types/common/store/index.d.ts.map +1 -0
- package/dist/types/common/store/schema.d.ts +75 -0
- package/dist/types/common/store/schema.d.ts.map +1 -0
- package/dist/types/common/store/utils.d.ts +13 -0
- package/dist/types/common/store/utils.d.ts.map +1 -0
- package/dist/types/common/template/index.d.ts +5 -0
- package/dist/types/common/template/index.d.ts.map +1 -0
- package/dist/types/common/template/utils.d.ts +3 -0
- package/dist/types/common/template/utils.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +83 -0
- package/public/callback.html +65 -0
- package/public/logo.svg +4 -0
- package/template/legacy/README.md +13 -0
- package/template/legacy/_backend_npmrc +5 -0
- package/template/legacy/_backend_tsconfig.json +23 -0
- package/template/legacy/_eslintignore +2 -0
- package/template/legacy/_eslintrc.js +97 -0
- package/template/legacy/_gitignore +21 -0
- package/template/legacy/_gitlab-ci.yml +3 -0
- package/template/legacy/_husky_pre-commit +1 -0
- package/template/legacy/_npmrc +5 -0
- package/template/legacy/_prettierignore +15 -0
- package/template/legacy/_prettierrc +6 -0
- package/template/legacy/_web_npmrc +5 -0
- package/template/legacy/_web_tsconfig.json +20 -0
- package/template/legacy/backend/package.json +10 -0
- package/template/legacy/backend/src/index.ts +139 -0
- package/template/legacy/backend/src/ones.d.ts +6 -0
- package/template/legacy/config/ci-deploy.yaml +11 -0
- package/template/legacy/config/local.yaml +30 -0
- package/template/legacy/config/plugin.yaml +25 -0
- package/template/legacy/config/upgrade.yaml +8 -0
- package/template/legacy/op.config.mjs +4 -0
- package/template/legacy/package-lock.json +17446 -0
- package/template/legacy/package.json +73 -0
- package/template/legacy/web/browserslist +4 -0
- package/template/legacy/web/package.json +29 -0
- package/template/legacy/web/public/logo.svg +5 -0
- package/template/legacy/workspace/plugin.sql +2 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1889 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const _includesInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/includes");
|
|
4
|
+
const commander = require("commander");
|
|
5
|
+
const createOnesApp = require("create-ones-app");
|
|
6
|
+
const node_path = require("node:path");
|
|
7
|
+
const node_child_process = require("node:child_process");
|
|
8
|
+
const node_fs = require("node:fs");
|
|
9
|
+
const fse = require("fs-extra");
|
|
10
|
+
const archiver = require("archiver");
|
|
11
|
+
const lodashEs = require("lodash-es");
|
|
12
|
+
const process$1 = require("node:process");
|
|
13
|
+
const node_url = require("node:url");
|
|
14
|
+
const cosmiconfig = require("cosmiconfig");
|
|
15
|
+
const getPort = require("get-port");
|
|
16
|
+
const envPaths = require("env-paths");
|
|
17
|
+
const zod = require("zod");
|
|
18
|
+
const axios = require("axios");
|
|
19
|
+
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
20
|
+
const ora = require("ora");
|
|
21
|
+
const WebSocket = require("ws");
|
|
22
|
+
const http = require("node:http");
|
|
23
|
+
const open = require("open");
|
|
24
|
+
const uuid = require("uuid");
|
|
25
|
+
const PKCEChallenge = require("pkce-challenge");
|
|
26
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
27
|
+
const en = {
|
|
28
|
+
"desc.ones": "ONES CLI/{env}",
|
|
29
|
+
"desc.build": "Build your ONES App",
|
|
30
|
+
"desc.build.output": "Specify the output file path",
|
|
31
|
+
"desc.build.command": "Specify the build command",
|
|
32
|
+
"desc.dev": "Start your local development server and connect to ONES",
|
|
33
|
+
"desc.dev.install": "Install your ONES App after the server is ready",
|
|
34
|
+
"desc.dev.command": "Specify the dev command",
|
|
35
|
+
"desc.dev.clearStorage": "Clear development storage namespace before applying hosted storage",
|
|
36
|
+
"desc.tunnel": "Start a tunnel to connect your local server with ONES",
|
|
37
|
+
"desc.tunnel.port": "Specify the port number for tunnel",
|
|
38
|
+
"desc.login": "Log in to your ONES account",
|
|
39
|
+
"desc.login.baseUrl": "Specify the ONES URL for login",
|
|
40
|
+
"desc.logout": "Log out of your ONES account",
|
|
41
|
+
"desc.whoami": "Display the account information of the logged in user",
|
|
42
|
+
"desc.app": "Manage app installations",
|
|
43
|
+
"desc.install": "Install your ONES App",
|
|
44
|
+
"desc.enable": "Enable your ONES App",
|
|
45
|
+
"desc.disable": "Disable your ONES App",
|
|
46
|
+
"desc.uninstall": "Uninstall your ONES App",
|
|
47
|
+
"desc.legacy": "Legacy command",
|
|
48
|
+
"desc.legacy.create": "Create a new ONES plugin",
|
|
49
|
+
"desc.legacy.create.projectPath": "Specify the project path",
|
|
50
|
+
"error.login.missingBaseURL": "Missing base URL",
|
|
51
|
+
"error.login.incorrectBaseURL": "Incorrect base URL",
|
|
52
|
+
"error.tunnel.missingPort": "Missing port",
|
|
53
|
+
"error.tunnel.incorrectPort": "Incorrect port",
|
|
54
|
+
"error.schema.app.package.parseError": "App package JSON parse error",
|
|
55
|
+
"error.schema.app.manifest.parseError": 'App "opkx.json" JSON parse error',
|
|
56
|
+
"error.schema.app.manifest.validateError": 'App "opkx.json" JSON validation failed: "{err}". Please check this issue, or upgrade your ONES CLI to the latest version if the problem persists.',
|
|
57
|
+
"error.build.scriptNotFound": 'Npm "build" script not found',
|
|
58
|
+
"error.build.incorrectCommand": "Incorrect build command",
|
|
59
|
+
"error.dev.scriptNotFound": 'Npm "dev" script not found',
|
|
60
|
+
"error.dev.incorrectCommand": "Incorrect dev command",
|
|
61
|
+
"error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
|
|
62
|
+
"error.hostedToken.requestFailed": "Failed to request hosted token",
|
|
63
|
+
"error.hostedToken.empty": "Hosted token is empty",
|
|
64
|
+
"error.legacy.create.missingProjectPath": "Project path is required"
|
|
65
|
+
};
|
|
66
|
+
const map = {
|
|
67
|
+
en
|
|
68
|
+
};
|
|
69
|
+
const getCurrentLanguageList = () => {
|
|
70
|
+
return ["en"];
|
|
71
|
+
};
|
|
72
|
+
const translate = (key, params) => {
|
|
73
|
+
const list = getCurrentLanguageList();
|
|
74
|
+
for (let index = 0; index < list.length; index++) {
|
|
75
|
+
const language = list[index];
|
|
76
|
+
let value = lodashEs.get(map[language], key);
|
|
77
|
+
if (value) {
|
|
78
|
+
if (params && typeof value === "string") {
|
|
79
|
+
value = value.replace(/\{(\w+)\}/g, (match, paramKey) => {
|
|
80
|
+
var _params$paramKey;
|
|
81
|
+
const result = (_params$paramKey = params === null || params === void 0 ? void 0 : params[paramKey]) !== null && _params$paramKey !== void 0 ? _params$paramKey : match;
|
|
82
|
+
return String(result);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return key;
|
|
89
|
+
};
|
|
90
|
+
const i18n = {
|
|
91
|
+
t: translate
|
|
92
|
+
};
|
|
93
|
+
var ErrorCode = ((ErrorCode2) => {
|
|
94
|
+
ErrorCode2[ErrorCode2["UNKNOWN_ERROR"] = createOnesApp.ErrorCode.UNKNOWN_ERROR] = "UNKNOWN_ERROR";
|
|
95
|
+
ErrorCode2[ErrorCode2["COMMAND_ERROR"] = createOnesApp.ErrorCode.COMMAND_ERROR] = "COMMAND_ERROR";
|
|
96
|
+
ErrorCode2[ErrorCode2["TEMPLATE_NOT_FOUND"] = createOnesApp.ErrorCode.TEMPLATE_NOT_FOUND] = "TEMPLATE_NOT_FOUND";
|
|
97
|
+
ErrorCode2[ErrorCode2["MISSING_PROJECT_PATH"] = createOnesApp.ErrorCode.MISSING_PROJECT_PATH] = "MISSING_PROJECT_PATH";
|
|
98
|
+
ErrorCode2["MISSING_BASE_URL"] = "E04";
|
|
99
|
+
ErrorCode2["MISSING_PORT"] = "E05";
|
|
100
|
+
ErrorCode2["INCORRECT_BASE_URL"] = "E06";
|
|
101
|
+
ErrorCode2["INCORRECT_PORT"] = "E07";
|
|
102
|
+
ErrorCode2["APP_PACKAGE_JSON_PARSE_ERROR"] = "E08";
|
|
103
|
+
ErrorCode2["APP_MANIFEST_JSON_PARSE_ERROR"] = "E09";
|
|
104
|
+
ErrorCode2["BUILD_SCRIPT_NOT_FOUND"] = "E10";
|
|
105
|
+
ErrorCode2["DEV_SCRIPT_NOT_FOUND"] = "E11";
|
|
106
|
+
ErrorCode2["STORE_PERMISSION"] = "E12";
|
|
107
|
+
ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
|
|
108
|
+
ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
|
|
109
|
+
ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
|
|
110
|
+
ErrorCode2["INCORRECT_BUILD_COMMAND"] = "E16";
|
|
111
|
+
return ErrorCode2;
|
|
112
|
+
})(ErrorCode || {});
|
|
113
|
+
const getPackageJSONPath = () => {
|
|
114
|
+
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));
|
|
115
|
+
return node_path.join(__dirname, "../package.json");
|
|
116
|
+
};
|
|
117
|
+
const getPackageJSON = () => {
|
|
118
|
+
const path = getPackageJSONPath();
|
|
119
|
+
try {
|
|
120
|
+
const string = node_fs.readFileSync(path, {
|
|
121
|
+
encoding: "utf8"
|
|
122
|
+
});
|
|
123
|
+
return JSON.parse(string);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const getAppWorkspacePath = () => {
|
|
129
|
+
return node_path.join(process$1.cwd());
|
|
130
|
+
};
|
|
131
|
+
const getAppPackageJSONPath = () => {
|
|
132
|
+
return node_path.join(process$1.cwd(), "./package.json");
|
|
133
|
+
};
|
|
134
|
+
const getAppPackageJSON = () => {
|
|
135
|
+
const path = getAppPackageJSONPath();
|
|
136
|
+
try {
|
|
137
|
+
const string = node_fs.readFileSync(path, {
|
|
138
|
+
encoding: "utf8"
|
|
139
|
+
});
|
|
140
|
+
const json = JSON.parse(string);
|
|
141
|
+
return createOnesApp.AppPackageJSONSchema.parse(json);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
144
|
+
return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.package.parseError")}: ${details}`);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const getAppManifestJSONPath = () => {
|
|
148
|
+
return node_path.join(process$1.cwd(), createOnesApp.PUBLIC_FILENAME.MANIFEST);
|
|
149
|
+
};
|
|
150
|
+
const getAppManifestJSON = () => {
|
|
151
|
+
const path = getAppManifestJSONPath();
|
|
152
|
+
try {
|
|
153
|
+
const string = node_fs.readFileSync(path, {
|
|
154
|
+
encoding: "utf8"
|
|
155
|
+
});
|
|
156
|
+
const json = JSON.parse(string);
|
|
157
|
+
createOnesApp.AppManifestJSONSchema.parse(json);
|
|
158
|
+
return json;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
161
|
+
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const validateAppManifestJSON = () => {
|
|
165
|
+
const appManifestJSON = getAppManifestJSON();
|
|
166
|
+
try {
|
|
167
|
+
createOnesApp.AppManifestStrictJSONSchema.parse(appManifestJSON);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
170
|
+
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.validateError", {
|
|
171
|
+
err: details
|
|
172
|
+
})}`);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const defaultDevCommand = ["npm", "run", "dev"];
|
|
176
|
+
const defaultBuildCommand = ["npm", "run", "build"];
|
|
177
|
+
const defaultAppRcJSON = {
|
|
178
|
+
dev: {
|
|
179
|
+
command: defaultDevCommand
|
|
180
|
+
},
|
|
181
|
+
build: {
|
|
182
|
+
command: defaultBuildCommand
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
let storeAppRcJSON = null;
|
|
186
|
+
const getAppRcJSON = async () => {
|
|
187
|
+
if (storeAppRcJSON)
|
|
188
|
+
;
|
|
189
|
+
else {
|
|
190
|
+
try {
|
|
191
|
+
const path = node_path.join(createOnesApp.getPublicPath(), createOnesApp.PUBLIC_FILENAME.RC);
|
|
192
|
+
const string = node_fs.readFileSync(path, {
|
|
193
|
+
encoding: "utf8"
|
|
194
|
+
});
|
|
195
|
+
const json = JSON.parse(string);
|
|
196
|
+
storeAppRcJSON = createOnesApp.AppRcJSONSchema.parse(json);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
storeAppRcJSON = {};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const templateAppRcJSON = storeAppRcJSON || {};
|
|
202
|
+
let currentAppRcJSON;
|
|
203
|
+
const explorer = cosmiconfig.cosmiconfig("ones");
|
|
204
|
+
try {
|
|
205
|
+
const result = await explorer.search();
|
|
206
|
+
const json = result === null || result === void 0 ? void 0 : result.config;
|
|
207
|
+
currentAppRcJSON = createOnesApp.AppRcJSONSchema.parse(json);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
currentAppRcJSON = {};
|
|
210
|
+
}
|
|
211
|
+
return lodashEs.merge(defaultAppRcJSON, templateAppRcJSON, currentAppRcJSON);
|
|
212
|
+
};
|
|
213
|
+
const isOPKXFilename = /\.opkx$/;
|
|
214
|
+
const defaultOutputPath = "";
|
|
215
|
+
const normalize$a = async (options) => {
|
|
216
|
+
var _options$output, _options$command;
|
|
217
|
+
let output = node_path.resolve(process$1.cwd(), (_options$output = options.output) !== null && _options$output !== void 0 ? _options$output : defaultOutputPath);
|
|
218
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
219
|
+
if (isOPKXFilename.test(output))
|
|
220
|
+
;
|
|
221
|
+
else {
|
|
222
|
+
const appManifestJSON = getAppManifestJSON();
|
|
223
|
+
const defaultOutputFilename = `${appManifestJSON.app.name}.opkx`;
|
|
224
|
+
output = node_path.resolve(output, defaultOutputFilename);
|
|
225
|
+
}
|
|
226
|
+
validateAppManifestJSON();
|
|
227
|
+
return {
|
|
228
|
+
output,
|
|
229
|
+
command
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
const {
|
|
233
|
+
existsSync,
|
|
234
|
+
ensureDirSync
|
|
235
|
+
} = fse;
|
|
236
|
+
const build = async function() {
|
|
237
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$build$comm, _appRcJSON$build, _currentCommand$, _appRcJSON$build$comp, _appRcJSON$build2;
|
|
238
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
239
|
+
args[_key] = arguments[_key];
|
|
240
|
+
}
|
|
241
|
+
const {
|
|
242
|
+
options
|
|
243
|
+
} = createOnesApp.getCommandOptions(args, buildCommandArguments);
|
|
244
|
+
const normalizedOptions = await normalize$a(options);
|
|
245
|
+
const appManifestJSON = getAppManifestJSON();
|
|
246
|
+
const appRcJSON = await getAppRcJSON();
|
|
247
|
+
const correctCommand = 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]) || "";
|
|
248
|
+
if (!correctCommand) {
|
|
249
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BUILD_COMMAND, i18n.t("error.build.incorrectCommand"));
|
|
250
|
+
}
|
|
251
|
+
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 : [];
|
|
252
|
+
const firstCommand = (_currentCommand$ = currentCommand[0]) !== null && _currentCommand$ !== void 0 ? _currentCommand$ : "";
|
|
253
|
+
const currentCommandString = currentCommand.join(" ");
|
|
254
|
+
const defaultBuildCommandString = defaultBuildCommand.join(" ");
|
|
255
|
+
let shouldBuild = false;
|
|
256
|
+
if (firstCommand === "npm") {
|
|
257
|
+
const appPackageJSONPath = getAppPackageJSONPath();
|
|
258
|
+
const isExists = existsSync(appPackageJSONPath);
|
|
259
|
+
if (isExists) {
|
|
260
|
+
shouldBuild = true;
|
|
261
|
+
const appPackageJSON = getAppPackageJSON();
|
|
262
|
+
if (currentCommandString === defaultBuildCommandString) {
|
|
263
|
+
var _appPackageJSON$scrip;
|
|
264
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build)
|
|
265
|
+
;
|
|
266
|
+
else {
|
|
267
|
+
return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
shouldBuild = true;
|
|
273
|
+
}
|
|
274
|
+
if (shouldBuild) {
|
|
275
|
+
const buildResult = node_child_process.spawnSync(firstCommand, currentCommand.slice(1), {
|
|
276
|
+
cwd: getAppWorkspacePath(),
|
|
277
|
+
stdio: "inherit",
|
|
278
|
+
env: {
|
|
279
|
+
...process.env,
|
|
280
|
+
NODE_ENV: "production"
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
if (buildResult.status !== 0 || buildResult.signal) {
|
|
284
|
+
var _buildResult$status;
|
|
285
|
+
process.exit((_buildResult$status = buildResult.status) !== null && _buildResult$status !== void 0 ? _buildResult$status : 1);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const appName = appManifestJSON.app.name;
|
|
289
|
+
const outputPath = normalizedOptions.output;
|
|
290
|
+
const outputDir = node_path.dirname(outputPath);
|
|
291
|
+
const outputFilename = node_path.basename(outputPath);
|
|
292
|
+
ensureDirSync(outputDir);
|
|
293
|
+
const outputStream = node_fs.createWriteStream(outputPath);
|
|
294
|
+
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 : [];
|
|
295
|
+
const archive = archiver("zip", {
|
|
296
|
+
zlib: {
|
|
297
|
+
level: 9
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
archive.on("error", (err) => {
|
|
301
|
+
throw err;
|
|
302
|
+
});
|
|
303
|
+
archive.on("warning", (err) => {
|
|
304
|
+
throw err;
|
|
305
|
+
});
|
|
306
|
+
archive.on("progress", (progress) => {
|
|
307
|
+
const {
|
|
308
|
+
entries,
|
|
309
|
+
fs
|
|
310
|
+
} = progress;
|
|
311
|
+
const entriesStr = entries.total > 0 ? ` ${entries.processed}/${entries.total} files` : "";
|
|
312
|
+
const bytesStr = fs.totalBytes > 0 ? ` ${(fs.processedBytes / 1024).toFixed(1)}/${(fs.totalBytes / 1024).toFixed(1)} KB` : "";
|
|
313
|
+
process.stdout.write(`\rCompressing:${entriesStr}${bytesStr} `);
|
|
314
|
+
});
|
|
315
|
+
archive.on("finish", () => {
|
|
316
|
+
process.stdout.write("\n");
|
|
317
|
+
console.log("");
|
|
318
|
+
console.log("Files in archive: ", createOnesApp.PUBLIC_FILENAME.MANIFEST, files);
|
|
319
|
+
console.log(`App "${appName}" built successfully!`);
|
|
320
|
+
console.log(`OPKX "${outputFilename}" created successfully!`);
|
|
321
|
+
console.log(`Output file: ${outputPath}`);
|
|
322
|
+
});
|
|
323
|
+
archive.pipe(outputStream);
|
|
324
|
+
files.forEach((file) => {
|
|
325
|
+
archive.glob(file, {
|
|
326
|
+
cwd: getAppWorkspacePath()
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
archive.file(node_path.join(getAppWorkspacePath(), createOnesApp.PUBLIC_FILENAME.MANIFEST), {
|
|
330
|
+
name: createOnesApp.PUBLIC_FILENAME.MANIFEST
|
|
331
|
+
});
|
|
332
|
+
archive.finalize();
|
|
333
|
+
};
|
|
334
|
+
const minPortNumber = 1;
|
|
335
|
+
const maxPortNumber = 65535;
|
|
336
|
+
const randomPortRangeStartNumber = 1e4;
|
|
337
|
+
const randomPortRangeEndNumber = maxPortNumber;
|
|
338
|
+
const loginRandomPort = lodashEs.random(randomPortRangeStartNumber, randomPortRangeEndNumber);
|
|
339
|
+
const config = {
|
|
340
|
+
defaultPort: {
|
|
341
|
+
login: loginRandomPort,
|
|
342
|
+
hosted: 8201,
|
|
343
|
+
devWebServer: 8202
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const getConfig = () => config;
|
|
347
|
+
const StoreONESTokenJSONSchema = zod.z.object({
|
|
348
|
+
token_type: zod.z.string().optional(),
|
|
349
|
+
expires_in: zod.z.number().optional(),
|
|
350
|
+
expires_at: zod.z.number().optional(),
|
|
351
|
+
access_token: zod.z.string().optional(),
|
|
352
|
+
refresh_token: zod.z.string().optional()
|
|
353
|
+
});
|
|
354
|
+
const StoreJSONSchema = zod.z.object({
|
|
355
|
+
version: zod.z.string().optional(),
|
|
356
|
+
timestamp: zod.z.number().optional(),
|
|
357
|
+
base_url: zod.z.string().optional(),
|
|
358
|
+
region_url: zod.z.string().optional(),
|
|
359
|
+
host_token: zod.z.string().optional(),
|
|
360
|
+
ones_token: StoreONESTokenJSONSchema.optional()
|
|
361
|
+
});
|
|
362
|
+
const {
|
|
363
|
+
ensureFile,
|
|
364
|
+
readJSON,
|
|
365
|
+
writeJSON
|
|
366
|
+
} = fse;
|
|
367
|
+
const name = "@ones-open/cli";
|
|
368
|
+
const paths = envPaths(name);
|
|
369
|
+
const storeDir = paths.config;
|
|
370
|
+
const storePath = node_path.join(storeDir, "config.json");
|
|
371
|
+
const getStore = async () => {
|
|
372
|
+
let json = {};
|
|
373
|
+
try {
|
|
374
|
+
await ensureFile(storePath);
|
|
375
|
+
json = await readJSON(storePath, {
|
|
376
|
+
encoding: "utf8"
|
|
377
|
+
});
|
|
378
|
+
} catch (error) {
|
|
379
|
+
const $error = error;
|
|
380
|
+
if ($error.code === "EPERM" || $error.code === "EACCES") {
|
|
381
|
+
return createOnesApp.throwError(ErrorCode.STORE_PERMISSION, i18n.t("error.store.permission", {
|
|
382
|
+
filePath: storePath
|
|
383
|
+
}));
|
|
384
|
+
}
|
|
385
|
+
if ($error instanceof SyntaxError) {
|
|
386
|
+
return {};
|
|
387
|
+
}
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
try {
|
|
391
|
+
return StoreJSONSchema.parse(json);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
return {};
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
const setStore = async (store) => {
|
|
397
|
+
try {
|
|
398
|
+
await ensureFile(storePath);
|
|
399
|
+
const version2 = `${getPackageJSON().version}`;
|
|
400
|
+
const timestamp = Date.now();
|
|
401
|
+
return await writeJSON(storePath, {
|
|
402
|
+
...store,
|
|
403
|
+
version: version2,
|
|
404
|
+
timestamp
|
|
405
|
+
}, {
|
|
406
|
+
encoding: "utf8"
|
|
407
|
+
});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const $error = error;
|
|
410
|
+
if ($error.code === "EPERM" || $error.code === "EACCES") {
|
|
411
|
+
return createOnesApp.throwError(ErrorCode.STORE_PERMISSION, i18n.t("error.store.permission", {
|
|
412
|
+
filePath: storePath
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
const mergeStore = async (store) => {
|
|
419
|
+
const currentStore = await getStore();
|
|
420
|
+
return setStore({
|
|
421
|
+
...currentStore,
|
|
422
|
+
...store
|
|
423
|
+
});
|
|
424
|
+
};
|
|
425
|
+
const getBaseURL = async () => {
|
|
426
|
+
var _store$base_url;
|
|
427
|
+
const store = await getStore();
|
|
428
|
+
return (_store$base_url = store.base_url) !== null && _store$base_url !== void 0 ? _store$base_url : "";
|
|
429
|
+
};
|
|
430
|
+
const getRegionURL = async () => {
|
|
431
|
+
var _store$region_url;
|
|
432
|
+
const store = await getStore();
|
|
433
|
+
return (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
434
|
+
};
|
|
435
|
+
const getONESToken = async () => {
|
|
436
|
+
var _store$ones_token;
|
|
437
|
+
const store = await getStore();
|
|
438
|
+
return (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : {};
|
|
439
|
+
};
|
|
440
|
+
const setONESToken = async (token) => {
|
|
441
|
+
return mergeStore({
|
|
442
|
+
ones_token: token
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
const getHostToken = async () => {
|
|
446
|
+
var _store$host_token;
|
|
447
|
+
const store = await getStore();
|
|
448
|
+
return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
|
|
449
|
+
};
|
|
450
|
+
const setHostToken = async (token) => {
|
|
451
|
+
return mergeStore({
|
|
452
|
+
host_token: token
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
const API = {
|
|
456
|
+
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
457
|
+
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
458
|
+
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/:appID/dev_declare",
|
|
459
|
+
APP_LIST: "/platform/api/app/list",
|
|
460
|
+
APP_INSTALL: "/platform/api/app/install",
|
|
461
|
+
APP_UPGRADE: "/platform/api/app/:installation_id/upgrade",
|
|
462
|
+
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
463
|
+
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
464
|
+
APP_DISABLE: "/platform/api/app/:installation_id/disable",
|
|
465
|
+
OAUTH_TOKEN: "/identity/oauth/token",
|
|
466
|
+
REFRESH_TOKEN: "/identity/oauth/token"
|
|
467
|
+
};
|
|
468
|
+
const REQUEST_TIMEOUT = 1e4;
|
|
469
|
+
const OAUTH_TOKEN_CLIENT_ID = "ones.v1.cli";
|
|
470
|
+
const getPath = (path, map2) => {
|
|
471
|
+
var _context;
|
|
472
|
+
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
473
|
+
if (/^:/.test(part)) {
|
|
474
|
+
return `${base}/${map2[part.slice(1)]}`;
|
|
475
|
+
}
|
|
476
|
+
return `${base}/${part}`;
|
|
477
|
+
}, "").slice(1);
|
|
478
|
+
};
|
|
479
|
+
const consoleUnauthorizedMessage = () => {
|
|
480
|
+
console.log("Not logged in");
|
|
481
|
+
console.log('Login with "ones login" command');
|
|
482
|
+
process.exit(1);
|
|
483
|
+
};
|
|
484
|
+
const consoleAppNotInstalledMessage = () => {
|
|
485
|
+
console.log("App not installed");
|
|
486
|
+
process.exit(1);
|
|
487
|
+
};
|
|
488
|
+
const getURL = async (path, pathMap, queryMap) => {
|
|
489
|
+
const base = await getRegionURL();
|
|
490
|
+
if (base) {
|
|
491
|
+
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
492
|
+
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
493
|
+
}
|
|
494
|
+
consoleUnauthorizedMessage();
|
|
495
|
+
};
|
|
496
|
+
const getHostedFetchHeaders = async (value) => {
|
|
497
|
+
const hostedToken = await getHostToken();
|
|
498
|
+
if (hostedToken) {
|
|
499
|
+
return lodashEs.merge({
|
|
500
|
+
Authorization: `Bearer ${hostedToken}`
|
|
501
|
+
}, value);
|
|
502
|
+
}
|
|
503
|
+
consoleUnauthorizedMessage();
|
|
504
|
+
process.exit(1);
|
|
505
|
+
};
|
|
506
|
+
const getAvailableONESTokeAccessToken = async () => {
|
|
507
|
+
var _token$expires_at, _token$access_token, _token$refresh_token;
|
|
508
|
+
const token = await getONESToken();
|
|
509
|
+
const now = Date.now();
|
|
510
|
+
const base = await getBaseURL();
|
|
511
|
+
const tokenExpiresAt = (_token$expires_at = token === null || token === void 0 ? void 0 : token.expires_at) !== null && _token$expires_at !== void 0 ? _token$expires_at : 0;
|
|
512
|
+
const tokenAccessToken = (_token$access_token = token === null || token === void 0 ? void 0 : token.access_token) !== null && _token$access_token !== void 0 ? _token$access_token : "";
|
|
513
|
+
const tokenRefreshToken = (_token$refresh_token = token === null || token === void 0 ? void 0 : token.refresh_token) !== null && _token$refresh_token !== void 0 ? _token$refresh_token : "";
|
|
514
|
+
if (tokenAccessToken && tokenExpiresAt > now) {
|
|
515
|
+
return tokenAccessToken;
|
|
516
|
+
}
|
|
517
|
+
if (tokenRefreshToken && base) {
|
|
518
|
+
var _data$token_type, _data$expires_in, _data$access_token, _data$refresh_token;
|
|
519
|
+
const uri = new URL(base);
|
|
520
|
+
uri.pathname = API.REFRESH_TOKEN;
|
|
521
|
+
const data = await axios({
|
|
522
|
+
url: `${uri}`,
|
|
523
|
+
method: "POST",
|
|
524
|
+
data: {
|
|
525
|
+
grant_type: "refresh_token",
|
|
526
|
+
refresh_token: tokenRefreshToken,
|
|
527
|
+
client_id: OAUTH_TOKEN_CLIENT_ID
|
|
528
|
+
},
|
|
529
|
+
headers: {
|
|
530
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
531
|
+
},
|
|
532
|
+
timeout: REQUEST_TIMEOUT
|
|
533
|
+
}).then((response) => {
|
|
534
|
+
return response.data;
|
|
535
|
+
}).catch(() => {
|
|
536
|
+
return {};
|
|
537
|
+
});
|
|
538
|
+
const tokenType = (_data$token_type = data.token_type) !== null && _data$token_type !== void 0 ? _data$token_type : "";
|
|
539
|
+
const expiresIn = (_data$expires_in = data.expires_in) !== null && _data$expires_in !== void 0 ? _data$expires_in : 0;
|
|
540
|
+
const accessToken = (_data$access_token = data.access_token) !== null && _data$access_token !== void 0 ? _data$access_token : "";
|
|
541
|
+
const refreshToken = (_data$refresh_token = data.refresh_token) !== null && _data$refresh_token !== void 0 ? _data$refresh_token : "";
|
|
542
|
+
const expiresAt = Date.now() + expiresIn * 1e3;
|
|
543
|
+
const isValid = [tokenType, expiresIn, accessToken, refreshToken].every(Boolean);
|
|
544
|
+
if (isValid) {
|
|
545
|
+
await setONESToken({
|
|
546
|
+
token_type: tokenType,
|
|
547
|
+
expires_in: expiresIn,
|
|
548
|
+
expires_at: expiresAt,
|
|
549
|
+
access_token: accessToken,
|
|
550
|
+
refresh_token: refreshToken
|
|
551
|
+
});
|
|
552
|
+
return accessToken;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return "";
|
|
556
|
+
};
|
|
557
|
+
const getHeaders = async (value) => {
|
|
558
|
+
const token = await getAvailableONESTokeAccessToken();
|
|
559
|
+
if (token) {
|
|
560
|
+
return lodashEs.merge({
|
|
561
|
+
Authorization: `Bearer ${token}`
|
|
562
|
+
}, value);
|
|
563
|
+
}
|
|
564
|
+
consoleUnauthorizedMessage();
|
|
565
|
+
process.exit(1);
|
|
566
|
+
};
|
|
567
|
+
const handleError = (error) => {
|
|
568
|
+
var _error$response, _error$response2;
|
|
569
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
570
|
+
console.log(error.response.statusText);
|
|
571
|
+
consoleUnauthorizedMessage();
|
|
572
|
+
process.exit(1);
|
|
573
|
+
}
|
|
574
|
+
if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
|
|
575
|
+
try {
|
|
576
|
+
const message = JSON.stringify(error.response.data, null, 2);
|
|
577
|
+
console.error(message);
|
|
578
|
+
process.exit(1);
|
|
579
|
+
} catch (error2) {
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
console.error(error);
|
|
583
|
+
return {};
|
|
584
|
+
};
|
|
585
|
+
const startWaiting = () => {
|
|
586
|
+
const time = 3e3;
|
|
587
|
+
let spinner = null;
|
|
588
|
+
const sid = setTimeout(() => {
|
|
589
|
+
spinner = ora("Waiting for response...");
|
|
590
|
+
spinner.start();
|
|
591
|
+
}, time);
|
|
592
|
+
const cancelWaiting = () => {
|
|
593
|
+
clearTimeout(sid);
|
|
594
|
+
if (spinner) {
|
|
595
|
+
spinner.stop();
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
return cancelWaiting;
|
|
599
|
+
};
|
|
600
|
+
const fetchAppBase = async (params) => {
|
|
601
|
+
var _params$url;
|
|
602
|
+
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
603
|
+
const headers = await getHeaders(params.headers);
|
|
604
|
+
const response = await axios({
|
|
605
|
+
...params,
|
|
606
|
+
url,
|
|
607
|
+
headers,
|
|
608
|
+
timeout: REQUEST_TIMEOUT
|
|
609
|
+
});
|
|
610
|
+
return response.data;
|
|
611
|
+
};
|
|
612
|
+
const fetchHostedAbilityBase = async (params) => {
|
|
613
|
+
var _params$url2;
|
|
614
|
+
const url = await getURL((_params$url2 = params.url) !== null && _params$url2 !== void 0 ? _params$url2 : "", params.pathMap, params.queryMap);
|
|
615
|
+
const headers = await getHostedFetchHeaders(params.headers);
|
|
616
|
+
const response = await axios({
|
|
617
|
+
...params,
|
|
618
|
+
url,
|
|
619
|
+
headers,
|
|
620
|
+
timeout: REQUEST_TIMEOUT
|
|
621
|
+
});
|
|
622
|
+
return response.data;
|
|
623
|
+
};
|
|
624
|
+
const fetchAppList = async (appID) => {
|
|
625
|
+
return await fetchAppBase({
|
|
626
|
+
url: API.APP_LIST,
|
|
627
|
+
method: "GET",
|
|
628
|
+
queryMap: {
|
|
629
|
+
app_id: appID
|
|
630
|
+
}
|
|
631
|
+
}).catch(handleError);
|
|
632
|
+
};
|
|
633
|
+
const fetchTokenInfo = async () => {
|
|
634
|
+
return await fetchAppBase({
|
|
635
|
+
url: API.TOKEN_INFO,
|
|
636
|
+
method: "GET"
|
|
637
|
+
}).catch(handleError);
|
|
638
|
+
};
|
|
639
|
+
const fetchHostedToken = async (data) => {
|
|
640
|
+
return await fetchAppBase({
|
|
641
|
+
url: API.HOSTED_TOKEN,
|
|
642
|
+
method: "POST",
|
|
643
|
+
data
|
|
644
|
+
}).catch(handleError);
|
|
645
|
+
};
|
|
646
|
+
const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
|
|
647
|
+
return await fetchHostedAbilityBase({
|
|
648
|
+
url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
|
|
649
|
+
method: "POST",
|
|
650
|
+
pathMap: {
|
|
651
|
+
appID
|
|
652
|
+
},
|
|
653
|
+
data
|
|
654
|
+
}).catch(handleError);
|
|
655
|
+
};
|
|
656
|
+
const fetchAppInstall = async (data) => {
|
|
657
|
+
var _appList$data$0$insta, _appList$data;
|
|
658
|
+
const appID = getAppManifestJSON().app.id;
|
|
659
|
+
const appList = await fetchAppList(appID);
|
|
660
|
+
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 : "";
|
|
661
|
+
if (installationID) {
|
|
662
|
+
return await fetchAppBase({
|
|
663
|
+
url: API.APP_UPGRADE,
|
|
664
|
+
method: "POST",
|
|
665
|
+
pathMap: {
|
|
666
|
+
installation_id: installationID
|
|
667
|
+
},
|
|
668
|
+
data
|
|
669
|
+
}).catch(handleError);
|
|
670
|
+
}
|
|
671
|
+
return await fetchAppBase({
|
|
672
|
+
url: API.APP_INSTALL,
|
|
673
|
+
method: "POST",
|
|
674
|
+
data
|
|
675
|
+
}).catch(handleError);
|
|
676
|
+
};
|
|
677
|
+
const fetchAppUninstall = async () => {
|
|
678
|
+
var _appList$data$0$insta2, _appList$data2;
|
|
679
|
+
const appID = getAppManifestJSON().app.id;
|
|
680
|
+
const appList = await fetchAppList(appID);
|
|
681
|
+
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 : "";
|
|
682
|
+
if (installationID) {
|
|
683
|
+
return await fetchAppBase({
|
|
684
|
+
url: API.APP_UNINSTALL,
|
|
685
|
+
method: "POST",
|
|
686
|
+
pathMap: {
|
|
687
|
+
installation_id: installationID
|
|
688
|
+
}
|
|
689
|
+
}).catch(handleError);
|
|
690
|
+
}
|
|
691
|
+
consoleAppNotInstalledMessage();
|
|
692
|
+
process.exit(1);
|
|
693
|
+
};
|
|
694
|
+
const fetchAppEnable = async () => {
|
|
695
|
+
var _appList$data$0$insta3, _appList$data3;
|
|
696
|
+
const appID = getAppManifestJSON().app.id;
|
|
697
|
+
const appList = await fetchAppList(appID);
|
|
698
|
+
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 : "";
|
|
699
|
+
if (installationID) {
|
|
700
|
+
return await fetchAppBase({
|
|
701
|
+
url: API.APP_ENABLE,
|
|
702
|
+
method: "POST",
|
|
703
|
+
pathMap: {
|
|
704
|
+
installation_id: installationID
|
|
705
|
+
}
|
|
706
|
+
}).catch(handleError);
|
|
707
|
+
}
|
|
708
|
+
consoleAppNotInstalledMessage();
|
|
709
|
+
process.exit(1);
|
|
710
|
+
};
|
|
711
|
+
const fetchAppDisable = async () => {
|
|
712
|
+
var _appList$data$0$insta4, _appList$data4;
|
|
713
|
+
const appID = getAppManifestJSON().app.id;
|
|
714
|
+
const appList = await fetchAppList(appID);
|
|
715
|
+
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 : "";
|
|
716
|
+
if (installationID) {
|
|
717
|
+
return await fetchAppBase({
|
|
718
|
+
url: API.APP_DISABLE,
|
|
719
|
+
method: "POST",
|
|
720
|
+
pathMap: {
|
|
721
|
+
installation_id: installationID
|
|
722
|
+
}
|
|
723
|
+
}).catch(handleError);
|
|
724
|
+
}
|
|
725
|
+
consoleAppNotInstalledMessage();
|
|
726
|
+
process.exit(1);
|
|
727
|
+
};
|
|
728
|
+
const checkTokenInfo = async () => {
|
|
729
|
+
let boolean = true;
|
|
730
|
+
const regionURL = await getRegionURL().catch(() => "");
|
|
731
|
+
const token = await getAvailableONESTokeAccessToken().catch(() => "");
|
|
732
|
+
if (token && regionURL) {
|
|
733
|
+
await fetchAppBase({
|
|
734
|
+
url: API.APP_LIST,
|
|
735
|
+
method: "GET"
|
|
736
|
+
}).catch(() => {
|
|
737
|
+
boolean = false;
|
|
738
|
+
});
|
|
739
|
+
} else {
|
|
740
|
+
boolean = false;
|
|
741
|
+
}
|
|
742
|
+
return boolean;
|
|
743
|
+
};
|
|
744
|
+
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
745
|
+
const normalize$9 = async (options) => {
|
|
746
|
+
var _options$clearStorage;
|
|
747
|
+
const portInput = options.port;
|
|
748
|
+
if (portInput)
|
|
749
|
+
;
|
|
750
|
+
else {
|
|
751
|
+
return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
752
|
+
}
|
|
753
|
+
const portString = String(portInput);
|
|
754
|
+
const portNumber = Number(portString);
|
|
755
|
+
if (isPortNumber.test(portString))
|
|
756
|
+
;
|
|
757
|
+
else {
|
|
758
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
759
|
+
}
|
|
760
|
+
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
761
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
762
|
+
}
|
|
763
|
+
const port = portString;
|
|
764
|
+
validateAppManifestJSON();
|
|
765
|
+
return {
|
|
766
|
+
port,
|
|
767
|
+
clearStorage: (_options$clearStorage = options.clearStorage) !== null && _options$clearStorage !== void 0 ? _options$clearStorage : false
|
|
768
|
+
};
|
|
769
|
+
};
|
|
770
|
+
const getTunnelContext = async () => {
|
|
771
|
+
var _appManifestJSON$app$, _appManifestJSON$app, _store$region_url, _store$ones_token$acc, _store$ones_token;
|
|
772
|
+
const appManifestJSON = getAppManifestJSON();
|
|
773
|
+
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$ : "";
|
|
774
|
+
const store = await getStore();
|
|
775
|
+
const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
776
|
+
const onesTokenAccessToken = (_store$ones_token$acc = (_store$ones_token = store.ones_token) === null || _store$ones_token === void 0 ? void 0 : _store$ones_token.access_token) !== null && _store$ones_token$acc !== void 0 ? _store$ones_token$acc : "";
|
|
777
|
+
if (appID && regionURL && onesTokenAccessToken) {
|
|
778
|
+
return {
|
|
779
|
+
appID,
|
|
780
|
+
regionURL,
|
|
781
|
+
appManifestJSON
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
consoleUnauthorizedMessage();
|
|
785
|
+
process.exit(1);
|
|
786
|
+
};
|
|
787
|
+
const getStorageTokenScopes = (ones2) => {
|
|
788
|
+
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
789
|
+
if (!storage) {
|
|
790
|
+
return [];
|
|
791
|
+
}
|
|
792
|
+
const scopes = /* @__PURE__ */ new Set();
|
|
793
|
+
if (Array.isArray(storage.entities) && storage.entities.length > 0) {
|
|
794
|
+
scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
|
|
795
|
+
}
|
|
796
|
+
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
797
|
+
scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
|
|
798
|
+
}
|
|
799
|
+
return Array.from(scopes);
|
|
800
|
+
};
|
|
801
|
+
const getRelayScope = () => {
|
|
802
|
+
return createOnesApp.HostedTokenScope.RELAY;
|
|
803
|
+
};
|
|
804
|
+
const buildTunnelUrl = async () => {
|
|
805
|
+
const {
|
|
806
|
+
appID,
|
|
807
|
+
regionURL
|
|
808
|
+
} = await getTunnelContext();
|
|
809
|
+
const url = new URL(regionURL);
|
|
810
|
+
url.pathname = `/platform/app/relay/dispatch/${appID}`;
|
|
811
|
+
return url.toString();
|
|
812
|
+
};
|
|
813
|
+
const MANIFEST_PATH = "/manifest";
|
|
814
|
+
const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
|
|
815
|
+
const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
|
|
816
|
+
class TunnelClient {
|
|
817
|
+
constructor(localPort, baseUrl, appID, hostedToken) {
|
|
818
|
+
let enableInternalManifestRoute = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
819
|
+
let replaceExisting = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
|
|
820
|
+
this.ws = null;
|
|
821
|
+
this.localPort = localPort;
|
|
822
|
+
this.baseUrl = baseUrl;
|
|
823
|
+
this.appID = appID;
|
|
824
|
+
this.hostedToken = hostedToken;
|
|
825
|
+
this.enableInternalManifestRoute = enableInternalManifestRoute;
|
|
826
|
+
this.replaceExisting = replaceExisting;
|
|
827
|
+
}
|
|
828
|
+
async connect() {
|
|
829
|
+
const proxyUrl = this.buildProxyUrl();
|
|
830
|
+
this.ws = new WebSocket(proxyUrl, {
|
|
831
|
+
headers: {
|
|
832
|
+
Authorization: `Bearer ${this.hostedToken}`
|
|
833
|
+
},
|
|
834
|
+
maxPayload: MAX_RELAY_BODY_BYTES
|
|
835
|
+
});
|
|
836
|
+
this.ws.on("message", async (data) => {
|
|
837
|
+
const message = this.parseMessage(data);
|
|
838
|
+
if (!message) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
await this.handleMessage(message);
|
|
842
|
+
});
|
|
843
|
+
this.ws.on("ping", (data) => {
|
|
844
|
+
var _this$ws;
|
|
845
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.pong(data);
|
|
846
|
+
});
|
|
847
|
+
this.ws.on("error", (error) => {
|
|
848
|
+
console.error("WebSocket error:", error);
|
|
849
|
+
});
|
|
850
|
+
return new Promise((resolve, reject) => {
|
|
851
|
+
var _this$ws2, _this$ws3;
|
|
852
|
+
(_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.on("open", () => resolve());
|
|
853
|
+
(_this$ws3 = this.ws) === null || _this$ws3 === void 0 || _this$ws3.on("error", reject);
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
close() {
|
|
857
|
+
var _this$ws4;
|
|
858
|
+
(_this$ws4 = this.ws) === null || _this$ws4 === void 0 || _this$ws4.close();
|
|
859
|
+
}
|
|
860
|
+
buildProxyUrl() {
|
|
861
|
+
const url = new URL("/platform/app/relay/", this.baseUrl);
|
|
862
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
863
|
+
url.searchParams.set("app_id", this.appID);
|
|
864
|
+
url.searchParams.set("replace_existing", String(this.replaceExisting));
|
|
865
|
+
return url.toString();
|
|
866
|
+
}
|
|
867
|
+
parseMessage(data) {
|
|
868
|
+
const buffer = this.toBuffer(data);
|
|
869
|
+
if (!buffer) {
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
if (buffer.length >= 4) {
|
|
873
|
+
const binary = this.parseBinaryEnvelope(buffer);
|
|
874
|
+
if (binary) {
|
|
875
|
+
return binary;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return this.parseJSONEnvelope(buffer.toString());
|
|
879
|
+
}
|
|
880
|
+
async handleMessage(message) {
|
|
881
|
+
const request = this.getRequestPayload(message);
|
|
882
|
+
if (!request) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
|
|
886
|
+
const appManifest = getAppManifestJSON().app;
|
|
887
|
+
const baseURL = await buildTunnelUrl();
|
|
888
|
+
const reply = {
|
|
889
|
+
id: message.id,
|
|
890
|
+
payload: {
|
|
891
|
+
status: 200,
|
|
892
|
+
headers: {
|
|
893
|
+
"content-type": ["application/json"]
|
|
894
|
+
},
|
|
895
|
+
body: {
|
|
896
|
+
...appManifest,
|
|
897
|
+
base_url: baseURL
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
this.sendBinaryEnvelope(reply);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
try {
|
|
905
|
+
const response = await this.forwardRequest(request);
|
|
906
|
+
const reply = {
|
|
907
|
+
id: message.id,
|
|
908
|
+
payload: response
|
|
909
|
+
};
|
|
910
|
+
this.sendBinaryEnvelope(reply);
|
|
911
|
+
} catch (error) {
|
|
912
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
913
|
+
console.error("Error forwarding request:", errorMessage);
|
|
914
|
+
const reply = {
|
|
915
|
+
id: message.id,
|
|
916
|
+
payload: {
|
|
917
|
+
status: 500,
|
|
918
|
+
headers: {
|
|
919
|
+
"x-agent-error": [errorMessage]
|
|
920
|
+
},
|
|
921
|
+
body: errorMessage
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
this.sendBinaryEnvelope(reply);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
getRequestPayload(message) {
|
|
928
|
+
const payload = message.payload;
|
|
929
|
+
if (!(payload !== null && payload !== void 0 && payload.method) || !(payload !== null && payload !== void 0 && payload.path)) {
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
return payload;
|
|
933
|
+
}
|
|
934
|
+
async forwardRequest(payload) {
|
|
935
|
+
const url = new URL(payload.path, `http://127.0.0.1:${this.localPort}`);
|
|
936
|
+
if (payload.query) {
|
|
937
|
+
Object.entries(payload.query).forEach((_ref) => {
|
|
938
|
+
let [key, value] = _ref;
|
|
939
|
+
if (Array.isArray(value)) {
|
|
940
|
+
value.forEach((item) => {
|
|
941
|
+
url.searchParams.append(key, item);
|
|
942
|
+
});
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
url.searchParams.append(key, value);
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
const response = await axios.request({
|
|
949
|
+
url: url.toString(),
|
|
950
|
+
method: payload.method,
|
|
951
|
+
headers: payload.headers,
|
|
952
|
+
data: payload.body,
|
|
953
|
+
responseType: "arraybuffer",
|
|
954
|
+
validateStatus: () => true,
|
|
955
|
+
maxBodyLength: MAX_RELAY_BODY_BYTES,
|
|
956
|
+
maxContentLength: MAX_RELAY_BODY_BYTES
|
|
957
|
+
});
|
|
958
|
+
const responseBytes = Buffer.from(response.data);
|
|
959
|
+
return {
|
|
960
|
+
status: response.status,
|
|
961
|
+
headers: this.collectHeaders(response.headers),
|
|
962
|
+
body: responseBytes
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
collectHeaders(headers) {
|
|
966
|
+
const collected = {};
|
|
967
|
+
Object.entries(headers).forEach((_ref2) => {
|
|
968
|
+
let [key, value] = _ref2;
|
|
969
|
+
if (Array.isArray(value)) {
|
|
970
|
+
collected[key] = value.map((item) => String(item));
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
if (value !== void 0 && value !== null) {
|
|
974
|
+
collected[key] = [String(value)];
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
return collected;
|
|
978
|
+
}
|
|
979
|
+
sendBinaryEnvelope(envelope) {
|
|
980
|
+
var _this$ws5;
|
|
981
|
+
const encoded = this.encodeBinaryEnvelope(envelope);
|
|
982
|
+
(_this$ws5 = this.ws) === null || _this$ws5 === void 0 || _this$ws5.send(encoded);
|
|
983
|
+
}
|
|
984
|
+
encodeBinaryEnvelope(envelope) {
|
|
985
|
+
var _envelope$payload;
|
|
986
|
+
const payload = (_envelope$payload = envelope.payload) !== null && _envelope$payload !== void 0 ? _envelope$payload : {};
|
|
987
|
+
const body = this.toBodyBuffer(payload.body);
|
|
988
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
989
|
+
throw new Error("relay body too large");
|
|
990
|
+
}
|
|
991
|
+
const metaPayload = {
|
|
992
|
+
...payload
|
|
993
|
+
};
|
|
994
|
+
delete metaPayload.body;
|
|
995
|
+
const meta = Buffer.from(JSON.stringify({
|
|
996
|
+
id: envelope.id,
|
|
997
|
+
payload: metaPayload
|
|
998
|
+
}), "utf8");
|
|
999
|
+
const header = Buffer.allocUnsafe(4);
|
|
1000
|
+
header.writeUInt32BE(meta.length, 0);
|
|
1001
|
+
return Buffer.concat([header, meta, body]);
|
|
1002
|
+
}
|
|
1003
|
+
toBodyBuffer(body) {
|
|
1004
|
+
if (body === void 0 || body === null) {
|
|
1005
|
+
return Buffer.alloc(0);
|
|
1006
|
+
}
|
|
1007
|
+
if (Buffer.isBuffer(body)) {
|
|
1008
|
+
return body;
|
|
1009
|
+
}
|
|
1010
|
+
if (body instanceof ArrayBuffer) {
|
|
1011
|
+
return Buffer.from(body);
|
|
1012
|
+
}
|
|
1013
|
+
if (ArrayBuffer.isView(body)) {
|
|
1014
|
+
return Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
1015
|
+
}
|
|
1016
|
+
if (typeof body === "string") {
|
|
1017
|
+
return Buffer.from(body, "utf8");
|
|
1018
|
+
}
|
|
1019
|
+
return Buffer.from(JSON.stringify(body), "utf8");
|
|
1020
|
+
}
|
|
1021
|
+
parseBinaryEnvelope(buffer) {
|
|
1022
|
+
const metaLength = buffer.readUInt32BE(0);
|
|
1023
|
+
if (metaLength <= 0 || 4 + metaLength > buffer.length) {
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
const metaRaw = buffer.subarray(4, 4 + metaLength).toString("utf8");
|
|
1027
|
+
try {
|
|
1028
|
+
const envelope = JSON.parse(metaRaw);
|
|
1029
|
+
if (!(envelope !== null && envelope !== void 0 && envelope.payload)) {
|
|
1030
|
+
return envelope;
|
|
1031
|
+
}
|
|
1032
|
+
const body = buffer.subarray(4 + metaLength);
|
|
1033
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
1034
|
+
console.error("Binary tunnel body exceeds size limit");
|
|
1035
|
+
return null;
|
|
1036
|
+
}
|
|
1037
|
+
const payload = envelope.payload;
|
|
1038
|
+
payload.body = body;
|
|
1039
|
+
return envelope;
|
|
1040
|
+
} catch (error) {
|
|
1041
|
+
console.error("Invalid binary tunnel message:", error);
|
|
1042
|
+
return null;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
parseJSONEnvelope(payload) {
|
|
1046
|
+
try {
|
|
1047
|
+
const message = JSON.parse(payload);
|
|
1048
|
+
if (!message) {
|
|
1049
|
+
return null;
|
|
1050
|
+
}
|
|
1051
|
+
return message;
|
|
1052
|
+
} catch (error) {
|
|
1053
|
+
console.error("Invalid tunnel message:", error);
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
toBuffer(data) {
|
|
1058
|
+
if (Buffer.isBuffer(data)) {
|
|
1059
|
+
return data;
|
|
1060
|
+
}
|
|
1061
|
+
if (Array.isArray(data)) {
|
|
1062
|
+
return Buffer.concat(data);
|
|
1063
|
+
}
|
|
1064
|
+
if (data instanceof ArrayBuffer) {
|
|
1065
|
+
return Buffer.from(data);
|
|
1066
|
+
}
|
|
1067
|
+
return null;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
const invokeTunnel = async function(port) {
|
|
1071
|
+
var _options$rebuildWhenE, _options$enableIntern, _options$clearStorage, _hostedTokenResponse$, _appManifestJSON$ones, _appManifestJSON$ones2;
|
|
1072
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1073
|
+
const {
|
|
1074
|
+
appManifestJSON,
|
|
1075
|
+
appID,
|
|
1076
|
+
regionURL
|
|
1077
|
+
} = await getTunnelContext();
|
|
1078
|
+
const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
|
|
1079
|
+
const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
|
|
1080
|
+
const storageScopes = getStorageTokenScopes(appManifestJSON.ones);
|
|
1081
|
+
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
1082
|
+
const hostedTokenResponse = await fetchHostedToken({
|
|
1083
|
+
app_id: appID,
|
|
1084
|
+
scopes,
|
|
1085
|
+
clear_storage: (_options$clearStorage = options.clearStorageForDev) !== null && _options$clearStorage !== void 0 ? _options$clearStorage : false
|
|
1086
|
+
});
|
|
1087
|
+
const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
|
|
1088
|
+
if (!hostedToken) {
|
|
1089
|
+
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
1090
|
+
}
|
|
1091
|
+
await setHostToken(hostedToken);
|
|
1092
|
+
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 : [];
|
|
1093
|
+
if (entities.length > 0) {
|
|
1094
|
+
await fetchHostedAbilityStorageDevDeclare(appID, {
|
|
1095
|
+
opkx_content: appManifestJSON
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
|
|
1099
|
+
await client.connect();
|
|
1100
|
+
};
|
|
1101
|
+
const tunnel = async function() {
|
|
1102
|
+
var _normalizedOptions$cl;
|
|
1103
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1104
|
+
args[_key] = arguments[_key];
|
|
1105
|
+
}
|
|
1106
|
+
const {
|
|
1107
|
+
options
|
|
1108
|
+
} = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
|
|
1109
|
+
const normalizedOptions = await normalize$9(options);
|
|
1110
|
+
const port = Number(normalizedOptions.port);
|
|
1111
|
+
const cancelWaiting = startWaiting();
|
|
1112
|
+
await invokeTunnel(port, {
|
|
1113
|
+
enableInternalManifestRoute: false,
|
|
1114
|
+
rebuildWhenExists: true,
|
|
1115
|
+
clearStorageForDev: (_normalizedOptions$cl = normalizedOptions.clearStorage) !== null && _normalizedOptions$cl !== void 0 ? _normalizedOptions$cl : false
|
|
1116
|
+
});
|
|
1117
|
+
cancelWaiting();
|
|
1118
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1119
|
+
console.log(`Relay endpoint: ${tunnelUrl}`);
|
|
1120
|
+
};
|
|
1121
|
+
const normalize$8 = async (options) => {
|
|
1122
|
+
lodashEs.noop(options);
|
|
1123
|
+
return {};
|
|
1124
|
+
};
|
|
1125
|
+
const displayAppDetail = async (installationID) => {
|
|
1126
|
+
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
1127
|
+
const tokenInfo = await fetchTokenInfo();
|
|
1128
|
+
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 : "";
|
|
1129
|
+
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 : "";
|
|
1130
|
+
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;
|
|
1131
|
+
const baseURL = await getBaseURL();
|
|
1132
|
+
if (isOrgVisible && orgUUID) {
|
|
1133
|
+
const url = `${baseURL}project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
1134
|
+
console.log(`See App detail: ${url}`);
|
|
1135
|
+
}
|
|
1136
|
+
if (!isOrgVisible && teamUUID) {
|
|
1137
|
+
const url = `${baseURL}project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
1138
|
+
console.log(`See App detail: ${url}`);
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
const invokeInstall = async (manifestUrl) => {
|
|
1142
|
+
const {
|
|
1143
|
+
app
|
|
1144
|
+
} = getAppManifestJSON();
|
|
1145
|
+
const appName = app.name;
|
|
1146
|
+
const appID = app.id;
|
|
1147
|
+
const cancelWaiting = startWaiting();
|
|
1148
|
+
const result = await fetchAppInstall({
|
|
1149
|
+
manifest_url: manifestUrl,
|
|
1150
|
+
options: {
|
|
1151
|
+
enable: true
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
cancelWaiting();
|
|
1155
|
+
if (result.code === "OK") {
|
|
1156
|
+
var _appList$data$0$insta, _appList$data;
|
|
1157
|
+
console.log(`App "${appName}" installed successfully!`);
|
|
1158
|
+
const appList = await fetchAppList(appID);
|
|
1159
|
+
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 : "";
|
|
1160
|
+
if (installationID) {
|
|
1161
|
+
await displayAppDetail(installationID);
|
|
1162
|
+
}
|
|
1163
|
+
return true;
|
|
1164
|
+
} else {
|
|
1165
|
+
console.log(`App "${appName}" installed failed!`);
|
|
1166
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1167
|
+
}
|
|
1168
|
+
return false;
|
|
1169
|
+
};
|
|
1170
|
+
const getManifestUrl = async () => {
|
|
1171
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1172
|
+
const customManifestUrl = `${tunnelUrl}${MANIFEST_PATH}`;
|
|
1173
|
+
const internalManifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1174
|
+
const internalResult = await axios.get(internalManifestUrl, {
|
|
1175
|
+
timeout: REQUEST_TIMEOUT
|
|
1176
|
+
}).then((response) => {
|
|
1177
|
+
if (response.status === 200) {
|
|
1178
|
+
return internalManifestUrl;
|
|
1179
|
+
}
|
|
1180
|
+
return null;
|
|
1181
|
+
}).catch(lodashEs.noop);
|
|
1182
|
+
if (internalResult) {
|
|
1183
|
+
return internalResult;
|
|
1184
|
+
}
|
|
1185
|
+
const customResult = await axios.get(customManifestUrl, {
|
|
1186
|
+
timeout: REQUEST_TIMEOUT
|
|
1187
|
+
}).then((response) => {
|
|
1188
|
+
if (response.status === 200) {
|
|
1189
|
+
return customManifestUrl;
|
|
1190
|
+
}
|
|
1191
|
+
return null;
|
|
1192
|
+
}).catch(lodashEs.noop);
|
|
1193
|
+
if (customResult) {
|
|
1194
|
+
return customResult;
|
|
1195
|
+
}
|
|
1196
|
+
return null;
|
|
1197
|
+
};
|
|
1198
|
+
const install = async function() {
|
|
1199
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1200
|
+
args[_key] = arguments[_key];
|
|
1201
|
+
}
|
|
1202
|
+
const {
|
|
1203
|
+
options
|
|
1204
|
+
} = createOnesApp.getCommandOptions(args, installCommandArguments);
|
|
1205
|
+
const normalizedOptions = await normalize$8(options);
|
|
1206
|
+
lodashEs.noop(normalizedOptions);
|
|
1207
|
+
const {
|
|
1208
|
+
app
|
|
1209
|
+
} = getAppManifestJSON();
|
|
1210
|
+
const appName = app.name;
|
|
1211
|
+
const manifestUrl = await getManifestUrl();
|
|
1212
|
+
if (!manifestUrl) {
|
|
1213
|
+
console.log(`App "${appName}" server not available!`);
|
|
1214
|
+
console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
|
|
1215
|
+
process.exit(1);
|
|
1216
|
+
}
|
|
1217
|
+
await invokeInstall(manifestUrl);
|
|
1218
|
+
};
|
|
1219
|
+
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
1220
|
+
InstallOptions2["AUTO"] = "auto";
|
|
1221
|
+
InstallOptions2["TRUE"] = "true";
|
|
1222
|
+
InstallOptions2["FALSE"] = "false";
|
|
1223
|
+
return InstallOptions2;
|
|
1224
|
+
})(InstallOptions || {});
|
|
1225
|
+
var DevCommandScripts = /* @__PURE__ */ ((DevCommandScripts2) => {
|
|
1226
|
+
DevCommandScripts2["Concurrently"] = "concurrently";
|
|
1227
|
+
DevCommandScripts2["Nest"] = "nest";
|
|
1228
|
+
DevCommandScripts2["Vite"] = "vite";
|
|
1229
|
+
return DevCommandScripts2;
|
|
1230
|
+
})(DevCommandScripts || {});
|
|
1231
|
+
const defaultInstall = InstallOptions.AUTO;
|
|
1232
|
+
const normalize$7 = async (options) => {
|
|
1233
|
+
var _options$install, _options$command, _options$clearStorage;
|
|
1234
|
+
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
1235
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
1236
|
+
const clearStorageString = `${(_options$clearStorage = options.clearStorage) !== null && _options$clearStorage !== void 0 ? _options$clearStorage : "false"}`;
|
|
1237
|
+
switch (true) {
|
|
1238
|
+
case install2 === InstallOptions.AUTO:
|
|
1239
|
+
break;
|
|
1240
|
+
case install2 === InstallOptions.FALSE:
|
|
1241
|
+
break;
|
|
1242
|
+
default:
|
|
1243
|
+
install2 = InstallOptions.TRUE;
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
validateAppManifestJSON();
|
|
1247
|
+
return {
|
|
1248
|
+
install: install2,
|
|
1249
|
+
command,
|
|
1250
|
+
clearStorage: clearStorageString === "false" ? false : true
|
|
1251
|
+
};
|
|
1252
|
+
};
|
|
1253
|
+
const IDLE_MS = 2e3;
|
|
1254
|
+
const dev = async function() {
|
|
1255
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2, _currentCommand$;
|
|
1256
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1257
|
+
args[_key] = arguments[_key];
|
|
1258
|
+
}
|
|
1259
|
+
const {
|
|
1260
|
+
options
|
|
1261
|
+
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
1262
|
+
const normalizedOptions = await normalize$7(options);
|
|
1263
|
+
const appRcJSON = await getAppRcJSON();
|
|
1264
|
+
const correctCommand = 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]) || "";
|
|
1265
|
+
if (!correctCommand) {
|
|
1266
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
|
|
1267
|
+
}
|
|
1268
|
+
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 : [];
|
|
1269
|
+
const firstCommand = (_currentCommand$ = currentCommand[0]) !== null && _currentCommand$ !== void 0 ? _currentCommand$ : "";
|
|
1270
|
+
const currentCommandString = currentCommand.join(" ");
|
|
1271
|
+
const defaultDevCommandString = defaultDevCommand.join(" ");
|
|
1272
|
+
let templateCommand = false;
|
|
1273
|
+
if (firstCommand === "npm") {
|
|
1274
|
+
const appPackageJSON = getAppPackageJSON();
|
|
1275
|
+
if (currentCommandString === defaultDevCommandString) {
|
|
1276
|
+
var _appPackageJSON$scrip;
|
|
1277
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev) {
|
|
1278
|
+
var _appPackageJSON$scrip2, _appPackageJSON$scrip3, _appPackageJSON$scrip4;
|
|
1279
|
+
const dev2 = (_appPackageJSON$scrip2 = appPackageJSON.scripts.dev) !== null && _appPackageJSON$scrip2 !== void 0 ? _appPackageJSON$scrip2 : "";
|
|
1280
|
+
const devWeb = (_appPackageJSON$scrip3 = appPackageJSON.scripts["dev:web"]) !== null && _appPackageJSON$scrip3 !== void 0 ? _appPackageJSON$scrip3 : "";
|
|
1281
|
+
const devBackend = (_appPackageJSON$scrip4 = appPackageJSON.scripts["dev:backend"]) !== null && _appPackageJSON$scrip4 !== void 0 ? _appPackageJSON$scrip4 : "";
|
|
1282
|
+
const hasConcurrently = _includesInstanceProperty(dev2).call(dev2, DevCommandScripts.Concurrently);
|
|
1283
|
+
const hasNest = _includesInstanceProperty(devBackend).call(devBackend, DevCommandScripts.Nest);
|
|
1284
|
+
const hasVite = _includesInstanceProperty(devWeb).call(devWeb, DevCommandScripts.Vite);
|
|
1285
|
+
templateCommand = hasConcurrently && hasNest && hasVite;
|
|
1286
|
+
} else {
|
|
1287
|
+
return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
const appManifestJSON = getAppManifestJSON();
|
|
1292
|
+
const {
|
|
1293
|
+
app
|
|
1294
|
+
} = appManifestJSON;
|
|
1295
|
+
const appID = app.id;
|
|
1296
|
+
const config2 = getConfig();
|
|
1297
|
+
const ONES_HOSTED_PORT = await getPort({
|
|
1298
|
+
port: config2.defaultPort.hosted
|
|
1299
|
+
});
|
|
1300
|
+
const ONES_DEV_WEB_SERVER_PORT = await getPort({
|
|
1301
|
+
port: config2.defaultPort.devWebServer
|
|
1302
|
+
});
|
|
1303
|
+
const env2 = {
|
|
1304
|
+
...process.env,
|
|
1305
|
+
NODE_ENV: "development",
|
|
1306
|
+
ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
|
|
1307
|
+
ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
|
|
1308
|
+
ONES_HOSTED_TOKEN: "",
|
|
1309
|
+
ONES_HOSTED_APP_ID: "",
|
|
1310
|
+
ONES_HOSTED_BASE_URL: ""
|
|
1311
|
+
};
|
|
1312
|
+
const cancelWaiting = startWaiting();
|
|
1313
|
+
let enableTunnel = true;
|
|
1314
|
+
if (normalizedOptions.install === InstallOptions.TRUE)
|
|
1315
|
+
;
|
|
1316
|
+
else {
|
|
1317
|
+
enableTunnel = await checkTokenInfo();
|
|
1318
|
+
}
|
|
1319
|
+
if (enableTunnel) {
|
|
1320
|
+
var _normalizedOptions$cl;
|
|
1321
|
+
await invokeTunnel(ONES_HOSTED_PORT, {
|
|
1322
|
+
enableInternalManifestRoute: true,
|
|
1323
|
+
rebuildWhenExists: true,
|
|
1324
|
+
clearStorageForDev: (_normalizedOptions$cl = normalizedOptions.clearStorage) !== null && _normalizedOptions$cl !== void 0 ? _normalizedOptions$cl : false
|
|
1325
|
+
});
|
|
1326
|
+
const regionURL = await getRegionURL();
|
|
1327
|
+
const ONES_HOSTED_TOKEN = await getHostToken();
|
|
1328
|
+
const ONES_HOSTED_APP_ID = appID;
|
|
1329
|
+
const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
|
|
1330
|
+
env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
|
|
1331
|
+
env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
|
|
1332
|
+
env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
|
|
1333
|
+
} else {
|
|
1334
|
+
console.log("Not logged in or token invalid, skipping tunnel connection...");
|
|
1335
|
+
}
|
|
1336
|
+
cancelWaiting();
|
|
1337
|
+
const onReady = async () => {
|
|
1338
|
+
const appName = app.name;
|
|
1339
|
+
let manifestUrl = "";
|
|
1340
|
+
console.log("");
|
|
1341
|
+
console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
|
|
1342
|
+
if (enableTunnel) {
|
|
1343
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1344
|
+
console.log(`URL: ${tunnelUrl}`);
|
|
1345
|
+
manifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1346
|
+
}
|
|
1347
|
+
console.log(`App "${appName}" server is ready!`);
|
|
1348
|
+
console.log("");
|
|
1349
|
+
if (enableTunnel) {
|
|
1350
|
+
switch (normalizedOptions.install) {
|
|
1351
|
+
case InstallOptions.TRUE:
|
|
1352
|
+
await invokeInstall(manifestUrl);
|
|
1353
|
+
break;
|
|
1354
|
+
case InstallOptions.AUTO:
|
|
1355
|
+
{
|
|
1356
|
+
var _appList$data$0$insta, _appList$data;
|
|
1357
|
+
const appList = await fetchAppList(appID);
|
|
1358
|
+
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 : "";
|
|
1359
|
+
if (installationID) {
|
|
1360
|
+
await displayAppDetail(installationID);
|
|
1361
|
+
} else {
|
|
1362
|
+
await invokeInstall(manifestUrl);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
break;
|
|
1366
|
+
case InstallOptions.FALSE:
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
const cwd = getAppWorkspacePath();
|
|
1372
|
+
const child = node_child_process.spawn(firstCommand, currentCommand.slice(1), {
|
|
1373
|
+
cwd,
|
|
1374
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
1375
|
+
env: env2,
|
|
1376
|
+
shell: true
|
|
1377
|
+
});
|
|
1378
|
+
const createReadyStatusPipes = (onReady2) => {
|
|
1379
|
+
let readyTimer = null;
|
|
1380
|
+
let summaryPrinted = false;
|
|
1381
|
+
const scheduleReady = () => {
|
|
1382
|
+
if (summaryPrinted)
|
|
1383
|
+
return;
|
|
1384
|
+
if (readyTimer)
|
|
1385
|
+
clearTimeout(readyTimer);
|
|
1386
|
+
readyTimer = setTimeout(() => {
|
|
1387
|
+
readyTimer = null;
|
|
1388
|
+
if (!summaryPrinted) {
|
|
1389
|
+
summaryPrinted = true;
|
|
1390
|
+
onReady2();
|
|
1391
|
+
}
|
|
1392
|
+
}, IDLE_MS);
|
|
1393
|
+
};
|
|
1394
|
+
const pipe2 = (stream, isStderr) => {
|
|
1395
|
+
const write = (chunk) => {
|
|
1396
|
+
if (isStderr)
|
|
1397
|
+
process.stderr.write(chunk);
|
|
1398
|
+
else
|
|
1399
|
+
process.stdout.write(chunk);
|
|
1400
|
+
};
|
|
1401
|
+
if (templateCommand) {
|
|
1402
|
+
stream.on("data", (chunk) => {
|
|
1403
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1404
|
+
write(str);
|
|
1405
|
+
if (str.startsWith("[backend]") || str.startsWith("[web]")) {
|
|
1406
|
+
scheduleReady();
|
|
1407
|
+
}
|
|
1408
|
+
});
|
|
1409
|
+
} else {
|
|
1410
|
+
scheduleReady();
|
|
1411
|
+
stream.on("data", (chunk) => {
|
|
1412
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1413
|
+
write(str);
|
|
1414
|
+
scheduleReady();
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
return pipe2;
|
|
1419
|
+
};
|
|
1420
|
+
const pipe = createReadyStatusPipes(onReady);
|
|
1421
|
+
if (child.stdout)
|
|
1422
|
+
pipe(child.stdout, false);
|
|
1423
|
+
if (child.stderr)
|
|
1424
|
+
pipe(child.stderr, true);
|
|
1425
|
+
let signalHandled = false;
|
|
1426
|
+
const onSignal = (signal) => {
|
|
1427
|
+
if (signalHandled)
|
|
1428
|
+
return;
|
|
1429
|
+
signalHandled = true;
|
|
1430
|
+
child.kill(signal);
|
|
1431
|
+
};
|
|
1432
|
+
process.on("SIGINT", onSignal);
|
|
1433
|
+
process.on("SIGTERM", onSignal);
|
|
1434
|
+
await new Promise((resolve) => {
|
|
1435
|
+
child.on("exit", () => {
|
|
1436
|
+
process.off("SIGINT", onSignal);
|
|
1437
|
+
process.off("SIGTERM", onSignal);
|
|
1438
|
+
resolve();
|
|
1439
|
+
});
|
|
1440
|
+
});
|
|
1441
|
+
process.exit(0);
|
|
1442
|
+
};
|
|
1443
|
+
function createPromise() {
|
|
1444
|
+
let resolve;
|
|
1445
|
+
let reject;
|
|
1446
|
+
const promise = new Promise((res, rej) => {
|
|
1447
|
+
resolve = res;
|
|
1448
|
+
reject = rej;
|
|
1449
|
+
});
|
|
1450
|
+
return {
|
|
1451
|
+
promise,
|
|
1452
|
+
resolve,
|
|
1453
|
+
reject
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
const sleep = (number) => {
|
|
1457
|
+
return new Promise((resolve) => {
|
|
1458
|
+
setTimeout(resolve, number);
|
|
1459
|
+
});
|
|
1460
|
+
};
|
|
1461
|
+
const isURL = /^https?:\/\//;
|
|
1462
|
+
const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
|
|
1463
|
+
const normalize$6 = async (options) => {
|
|
1464
|
+
const baseURLInput = options.baseURL;
|
|
1465
|
+
if (baseURLInput)
|
|
1466
|
+
;
|
|
1467
|
+
else {
|
|
1468
|
+
return createOnesApp.throwError(ErrorCode.MISSING_BASE_URL, i18n.t("error.login.missingBaseURL"));
|
|
1469
|
+
}
|
|
1470
|
+
if (isURL.test(baseURLInput))
|
|
1471
|
+
;
|
|
1472
|
+
else {
|
|
1473
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1474
|
+
}
|
|
1475
|
+
let baseURL = "";
|
|
1476
|
+
try {
|
|
1477
|
+
const url = new URL(baseURLInput);
|
|
1478
|
+
const host = url.hostname;
|
|
1479
|
+
if (_includesInstanceProperty(HostBlackList).call(HostBlackList, host)) {
|
|
1480
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1481
|
+
}
|
|
1482
|
+
url.pathname = "";
|
|
1483
|
+
url.search = "";
|
|
1484
|
+
url.hash = "";
|
|
1485
|
+
baseURL = url.toString();
|
|
1486
|
+
} catch (error) {
|
|
1487
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1488
|
+
}
|
|
1489
|
+
return {
|
|
1490
|
+
baseURL
|
|
1491
|
+
};
|
|
1492
|
+
};
|
|
1493
|
+
const pkceChallenge = PKCEChallenge;
|
|
1494
|
+
const login = async function() {
|
|
1495
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1496
|
+
args[_key] = arguments[_key];
|
|
1497
|
+
}
|
|
1498
|
+
const {
|
|
1499
|
+
options
|
|
1500
|
+
} = createOnesApp.getCommandOptions(args, loginCommandArguments);
|
|
1501
|
+
const normalizedOptions = await normalize$6(options);
|
|
1502
|
+
const {
|
|
1503
|
+
code_verifier,
|
|
1504
|
+
code_challenge
|
|
1505
|
+
} = await pkceChallenge.default();
|
|
1506
|
+
const base = normalizedOptions.baseURL;
|
|
1507
|
+
const path = "identity/authorize";
|
|
1508
|
+
const config2 = getConfig();
|
|
1509
|
+
const port = await getPort({
|
|
1510
|
+
port: config2.defaultPort.login
|
|
1511
|
+
});
|
|
1512
|
+
const uuid$1 = uuid.v4();
|
|
1513
|
+
const search = new URLSearchParams();
|
|
1514
|
+
const redirect_uri = `http://localhost:${port}/callback`;
|
|
1515
|
+
search.set("response_type", "code");
|
|
1516
|
+
search.set("client_id", OAUTH_TOKEN_CLIENT_ID);
|
|
1517
|
+
search.set("redirect_uri", redirect_uri);
|
|
1518
|
+
search.set("scope", "openid offline_access");
|
|
1519
|
+
search.set("state", uuid$1);
|
|
1520
|
+
search.set("code_challenge", code_challenge);
|
|
1521
|
+
search.set("code_challenge_method", "S256");
|
|
1522
|
+
const url = `${base}${path}?${search}`;
|
|
1523
|
+
const waitingText = "Waiting for authorization...";
|
|
1524
|
+
const {
|
|
1525
|
+
promise,
|
|
1526
|
+
resolve
|
|
1527
|
+
} = createPromise();
|
|
1528
|
+
const server = http.createServer((req, res) => {
|
|
1529
|
+
var _req$url$split$, _req$url, _req$url$split$2, _req$url2;
|
|
1530
|
+
const path2 = (_req$url$split$ = (_req$url = req.url) === null || _req$url === void 0 ? void 0 : _req$url.split("?")[0]) !== null && _req$url$split$ !== void 0 ? _req$url$split$ : "";
|
|
1531
|
+
const query = (_req$url$split$2 = (_req$url2 = req.url) === null || _req$url2 === void 0 ? void 0 : _req$url2.split("?")[1]) !== null && _req$url$split$2 !== void 0 ? _req$url$split$2 : "";
|
|
1532
|
+
const search2 = new URLSearchParams(query);
|
|
1533
|
+
if (path2 === "/callback") {
|
|
1534
|
+
var _search2$get, _search2$get2;
|
|
1535
|
+
const code = (_search2$get = search2.get("code")) !== null && _search2$get !== void 0 ? _search2$get : "";
|
|
1536
|
+
const state = (_search2$get2 = search2.get("state")) !== null && _search2$get2 !== void 0 ? _search2$get2 : "";
|
|
1537
|
+
if (state === uuid$1) {
|
|
1538
|
+
const uri = new URL(base);
|
|
1539
|
+
uri.pathname = API.OAUTH_TOKEN;
|
|
1540
|
+
let errorMessage = "";
|
|
1541
|
+
axios({
|
|
1542
|
+
url: `${uri}`,
|
|
1543
|
+
method: "POST",
|
|
1544
|
+
data: {
|
|
1545
|
+
code,
|
|
1546
|
+
code_verifier,
|
|
1547
|
+
redirect_uri,
|
|
1548
|
+
client_id: OAUTH_TOKEN_CLIENT_ID,
|
|
1549
|
+
grant_type: "authorization_code"
|
|
1550
|
+
},
|
|
1551
|
+
headers: {
|
|
1552
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1553
|
+
},
|
|
1554
|
+
timeout: REQUEST_TIMEOUT
|
|
1555
|
+
}).then((response) => {
|
|
1556
|
+
return response.data;
|
|
1557
|
+
}).catch((error) => {
|
|
1558
|
+
errorMessage = `${error}`;
|
|
1559
|
+
return {};
|
|
1560
|
+
}).then((data) => {
|
|
1561
|
+
var _data$token_type, _data$expires_in, _data$access_token, _data$refresh_token;
|
|
1562
|
+
const tokenType = (_data$token_type = data.token_type) !== null && _data$token_type !== void 0 ? _data$token_type : "";
|
|
1563
|
+
const expiresIn = (_data$expires_in = data.expires_in) !== null && _data$expires_in !== void 0 ? _data$expires_in : 0;
|
|
1564
|
+
const expiresAt = Date.now() + expiresIn * 1e3;
|
|
1565
|
+
const accessToken = (_data$access_token = data.access_token) !== null && _data$access_token !== void 0 ? _data$access_token : "";
|
|
1566
|
+
const refreshToken = (_data$refresh_token = data.refresh_token) !== null && _data$refresh_token !== void 0 ? _data$refresh_token : "";
|
|
1567
|
+
const isValid = [tokenType, expiresIn, accessToken].every(Boolean);
|
|
1568
|
+
if (isValid) {
|
|
1569
|
+
const token = {
|
|
1570
|
+
token_type: tokenType,
|
|
1571
|
+
expires_in: expiresIn,
|
|
1572
|
+
expires_at: expiresAt,
|
|
1573
|
+
access_token: accessToken,
|
|
1574
|
+
refresh_token: refreshToken
|
|
1575
|
+
};
|
|
1576
|
+
resolve({
|
|
1577
|
+
base_url: base,
|
|
1578
|
+
ones_token: token,
|
|
1579
|
+
region_url: base
|
|
1580
|
+
});
|
|
1581
|
+
const successURL = `${base}identity/consent/success`;
|
|
1582
|
+
res.writeHead(302, {
|
|
1583
|
+
Location: successURL
|
|
1584
|
+
});
|
|
1585
|
+
res.end();
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
const errorURL = `${base}identity/consent/success?error=${errorMessage}`;
|
|
1589
|
+
res.writeHead(302, {
|
|
1590
|
+
Location: errorURL
|
|
1591
|
+
});
|
|
1592
|
+
res.end();
|
|
1593
|
+
});
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
res.writeHead(200, {
|
|
1598
|
+
"Content-Type": "text/html"
|
|
1599
|
+
});
|
|
1600
|
+
res.end(waitingText);
|
|
1601
|
+
});
|
|
1602
|
+
server.listen(port);
|
|
1603
|
+
promise.then(async (store) => {
|
|
1604
|
+
await sleep(100);
|
|
1605
|
+
try {
|
|
1606
|
+
server.closeAllConnections();
|
|
1607
|
+
} catch (error) {
|
|
1608
|
+
}
|
|
1609
|
+
try {
|
|
1610
|
+
server.close();
|
|
1611
|
+
} catch (error) {
|
|
1612
|
+
}
|
|
1613
|
+
if (store) {
|
|
1614
|
+
var _store$base_url, _store$ones_token, _store$region_url;
|
|
1615
|
+
await mergeStore({
|
|
1616
|
+
base_url: (_store$base_url = store.base_url) !== null && _store$base_url !== void 0 ? _store$base_url : "",
|
|
1617
|
+
ones_token: (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : {},
|
|
1618
|
+
region_url: (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : ""
|
|
1619
|
+
});
|
|
1620
|
+
console.log("Logged in successfully!");
|
|
1621
|
+
} else {
|
|
1622
|
+
console.log("Login canceled!");
|
|
1623
|
+
}
|
|
1624
|
+
}).finally(() => {
|
|
1625
|
+
process$1.exit(0);
|
|
1626
|
+
});
|
|
1627
|
+
console.log("Logging into your ONES account...");
|
|
1628
|
+
console.log(`Opening ${url}`);
|
|
1629
|
+
const spinner = ora({
|
|
1630
|
+
text: waitingText,
|
|
1631
|
+
discardStdin: false
|
|
1632
|
+
});
|
|
1633
|
+
spinner.start();
|
|
1634
|
+
let exited = false;
|
|
1635
|
+
const handleExit = () => {
|
|
1636
|
+
spinner.stop();
|
|
1637
|
+
if (exited)
|
|
1638
|
+
return;
|
|
1639
|
+
exited = true;
|
|
1640
|
+
console.log("Exiting...");
|
|
1641
|
+
resolve(null);
|
|
1642
|
+
sleep(3e3).then(() => {
|
|
1643
|
+
process$1.exit(0);
|
|
1644
|
+
});
|
|
1645
|
+
};
|
|
1646
|
+
process$1.on("SIGINT", handleExit);
|
|
1647
|
+
process$1.on("SIGTERM", handleExit);
|
|
1648
|
+
try {
|
|
1649
|
+
await open(url);
|
|
1650
|
+
} catch (error) {
|
|
1651
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
const normalize$5 = async (options) => {
|
|
1655
|
+
lodashEs.noop(options);
|
|
1656
|
+
return {};
|
|
1657
|
+
};
|
|
1658
|
+
const logout = async function() {
|
|
1659
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1660
|
+
args[_key] = arguments[_key];
|
|
1661
|
+
}
|
|
1662
|
+
const {
|
|
1663
|
+
options
|
|
1664
|
+
} = createOnesApp.getCommandOptions(args, logoutCommandArguments);
|
|
1665
|
+
const normalizedOptions = await normalize$5(options);
|
|
1666
|
+
lodashEs.noop(normalizedOptions);
|
|
1667
|
+
await setStore({});
|
|
1668
|
+
console.log("Logged out successfully!");
|
|
1669
|
+
};
|
|
1670
|
+
const normalize$4 = async (options) => {
|
|
1671
|
+
lodashEs.noop(options);
|
|
1672
|
+
return {};
|
|
1673
|
+
};
|
|
1674
|
+
const whoami = async function() {
|
|
1675
|
+
var _tokenInfo$user, _tokenInfo$user2;
|
|
1676
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1677
|
+
args[_key] = arguments[_key];
|
|
1678
|
+
}
|
|
1679
|
+
const {
|
|
1680
|
+
options
|
|
1681
|
+
} = createOnesApp.getCommandOptions(args, whoamiCommandArguments);
|
|
1682
|
+
const normalizedOptions = await normalize$4(options);
|
|
1683
|
+
lodashEs.noop(normalizedOptions);
|
|
1684
|
+
const baseURL = await getBaseURL();
|
|
1685
|
+
const cancelWaiting = startWaiting();
|
|
1686
|
+
const tokenInfo = await fetchTokenInfo();
|
|
1687
|
+
cancelWaiting();
|
|
1688
|
+
const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
|
|
1689
|
+
const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
|
|
1690
|
+
if (name2 && email) {
|
|
1691
|
+
console.log(`User: ${name2}`);
|
|
1692
|
+
console.log(`Email: ${email}`);
|
|
1693
|
+
console.log(`ONES: ${baseURL}`);
|
|
1694
|
+
} else {
|
|
1695
|
+
consoleUnauthorizedMessage();
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
const normalize$3 = async (options) => {
|
|
1699
|
+
lodashEs.noop(options);
|
|
1700
|
+
return {};
|
|
1701
|
+
};
|
|
1702
|
+
const enable = async function() {
|
|
1703
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1704
|
+
args[_key] = arguments[_key];
|
|
1705
|
+
}
|
|
1706
|
+
const {
|
|
1707
|
+
options
|
|
1708
|
+
} = createOnesApp.getCommandOptions(args, enableCommandArguments);
|
|
1709
|
+
const normalizedOptions = await normalize$3(options);
|
|
1710
|
+
lodashEs.noop(normalizedOptions);
|
|
1711
|
+
const appName = getAppManifestJSON().app.name;
|
|
1712
|
+
const cancelWaiting = startWaiting();
|
|
1713
|
+
const result = await fetchAppEnable();
|
|
1714
|
+
cancelWaiting();
|
|
1715
|
+
if (result.code === "OK") {
|
|
1716
|
+
console.log(`App "${appName}" enabled successfully!`);
|
|
1717
|
+
} else {
|
|
1718
|
+
console.log(`App "${appName}" enabled failed!`);
|
|
1719
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
const normalize$2 = async (options) => {
|
|
1723
|
+
lodashEs.noop(options);
|
|
1724
|
+
return {};
|
|
1725
|
+
};
|
|
1726
|
+
const disable = async function() {
|
|
1727
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1728
|
+
args[_key] = arguments[_key];
|
|
1729
|
+
}
|
|
1730
|
+
const {
|
|
1731
|
+
options
|
|
1732
|
+
} = createOnesApp.getCommandOptions(args, disableCommandArguments);
|
|
1733
|
+
const normalizedOptions = await normalize$2(options);
|
|
1734
|
+
lodashEs.noop(normalizedOptions);
|
|
1735
|
+
const appName = getAppManifestJSON().app.name;
|
|
1736
|
+
const cancelWaiting = startWaiting();
|
|
1737
|
+
const result = await fetchAppDisable();
|
|
1738
|
+
cancelWaiting();
|
|
1739
|
+
if (result.code === "OK") {
|
|
1740
|
+
console.log(`App "${appName}" disabled successfully!`);
|
|
1741
|
+
} else {
|
|
1742
|
+
console.log(`App "${appName}" disabled failed!`);
|
|
1743
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
const normalize$1 = async (options) => {
|
|
1747
|
+
lodashEs.noop(options);
|
|
1748
|
+
return {};
|
|
1749
|
+
};
|
|
1750
|
+
const uninstall = async function() {
|
|
1751
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1752
|
+
args[_key] = arguments[_key];
|
|
1753
|
+
}
|
|
1754
|
+
const {
|
|
1755
|
+
options
|
|
1756
|
+
} = createOnesApp.getCommandOptions(args, uninstallCommandArguments);
|
|
1757
|
+
const normalizedOptions = await normalize$1(options);
|
|
1758
|
+
lodashEs.noop(normalizedOptions);
|
|
1759
|
+
const appName = getAppManifestJSON().app.name;
|
|
1760
|
+
const cancelWaiting = startWaiting();
|
|
1761
|
+
const result = await fetchAppUninstall();
|
|
1762
|
+
cancelWaiting();
|
|
1763
|
+
if (result.code === "OK") {
|
|
1764
|
+
console.log(`App "${appName}" uninstalled successfully!`);
|
|
1765
|
+
} else {
|
|
1766
|
+
console.log(`App "${appName}" uninstalled failed!`);
|
|
1767
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
const getTemplatePath = () => {
|
|
1771
|
+
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));
|
|
1772
|
+
return node_path.join(__dirname, "../template");
|
|
1773
|
+
};
|
|
1774
|
+
const getTemplateLegacy = () => {
|
|
1775
|
+
return "legacy";
|
|
1776
|
+
};
|
|
1777
|
+
const normalize = async (options) => {
|
|
1778
|
+
const projectPathInput = options.projectPath;
|
|
1779
|
+
if (projectPathInput)
|
|
1780
|
+
;
|
|
1781
|
+
else {
|
|
1782
|
+
return createOnesApp.throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.legacy.create.missingProjectPath"));
|
|
1783
|
+
}
|
|
1784
|
+
const projectPath = node_path.resolve(process$1.cwd(), projectPathInput);
|
|
1785
|
+
return {
|
|
1786
|
+
projectPath
|
|
1787
|
+
};
|
|
1788
|
+
};
|
|
1789
|
+
const {
|
|
1790
|
+
copy,
|
|
1791
|
+
moveSync
|
|
1792
|
+
} = fse;
|
|
1793
|
+
const legacy = async function() {
|
|
1794
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1795
|
+
args[_key] = arguments[_key];
|
|
1796
|
+
}
|
|
1797
|
+
const {
|
|
1798
|
+
options
|
|
1799
|
+
} = createOnesApp.getCommandOptions(args, legacyCommandArguments);
|
|
1800
|
+
const normalizedOptions = await normalize(options);
|
|
1801
|
+
const {
|
|
1802
|
+
projectPath
|
|
1803
|
+
} = normalizedOptions;
|
|
1804
|
+
const templatePath = node_path.join(getTemplatePath(), getTemplateLegacy());
|
|
1805
|
+
await copy(templatePath, projectPath);
|
|
1806
|
+
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"]];
|
|
1807
|
+
rename.forEach((_ref) => {
|
|
1808
|
+
let [from, to] = _ref;
|
|
1809
|
+
moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
|
|
1810
|
+
overwrite: true
|
|
1811
|
+
});
|
|
1812
|
+
});
|
|
1813
|
+
console.log("Plugin created successfully!");
|
|
1814
|
+
};
|
|
1815
|
+
const buildCommandArguments = [];
|
|
1816
|
+
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);
|
|
1817
|
+
createOnesApp.addCommandUsage($build);
|
|
1818
|
+
createOnesApp.addCommandOutput($build);
|
|
1819
|
+
const devCommandArguments = [];
|
|
1820
|
+
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, --clear-storage [boolean]", i18n.t("desc.dev.clearStorage")).action(dev);
|
|
1821
|
+
createOnesApp.addCommandUsage($dev);
|
|
1822
|
+
createOnesApp.addCommandOutput($dev);
|
|
1823
|
+
const tunnelCommandArguments = ["port"];
|
|
1824
|
+
const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).option("-s, --clear-storage [boolean]", i18n.t("desc.dev.clearStorage")).action(tunnel);
|
|
1825
|
+
createOnesApp.addCommandUsage($tunnel);
|
|
1826
|
+
createOnesApp.addCommandOutput($tunnel);
|
|
1827
|
+
const loginCommandArguments = ["baseURL"];
|
|
1828
|
+
const $login = new commander.Command("login").description(i18n.t("desc.login")).argument("<base-url>", i18n.t("desc.login.baseUrl")).action(login);
|
|
1829
|
+
createOnesApp.addCommandUsage($login);
|
|
1830
|
+
createOnesApp.addCommandOutput($login);
|
|
1831
|
+
const logoutCommandArguments = [];
|
|
1832
|
+
const $logout = new commander.Command("logout").description(i18n.t("desc.logout")).action(logout);
|
|
1833
|
+
createOnesApp.addCommandUsage($logout);
|
|
1834
|
+
createOnesApp.addCommandOutput($logout);
|
|
1835
|
+
const whoamiCommandArguments = [];
|
|
1836
|
+
const $whoami = new commander.Command("whoami").description(i18n.t("desc.whoami")).action(whoami);
|
|
1837
|
+
createOnesApp.addCommandUsage($whoami);
|
|
1838
|
+
createOnesApp.addCommandOutput($whoami);
|
|
1839
|
+
const installCommandArguments = [];
|
|
1840
|
+
const $install = new commander.Command("install").description(i18n.t("desc.install")).action(install);
|
|
1841
|
+
createOnesApp.addCommandUsage($install);
|
|
1842
|
+
createOnesApp.addCommandOutput($install);
|
|
1843
|
+
const enableCommandArguments = [];
|
|
1844
|
+
const $enable = new commander.Command("enable").description(i18n.t("desc.enable")).action(enable);
|
|
1845
|
+
createOnesApp.addCommandUsage($enable);
|
|
1846
|
+
createOnesApp.addCommandOutput($enable);
|
|
1847
|
+
const disableCommandArguments = [];
|
|
1848
|
+
const $disable = new commander.Command("disable").description(i18n.t("desc.disable")).action(disable);
|
|
1849
|
+
createOnesApp.addCommandUsage($disable);
|
|
1850
|
+
createOnesApp.addCommandOutput($disable);
|
|
1851
|
+
const uninstallCommandArguments = [];
|
|
1852
|
+
const $uninstall = new commander.Command("uninstall").description(i18n.t("desc.uninstall")).action(uninstall);
|
|
1853
|
+
createOnesApp.addCommandUsage($uninstall);
|
|
1854
|
+
createOnesApp.addCommandOutput($uninstall);
|
|
1855
|
+
const $app = new commander.Command("app").description(i18n.t("desc.app"));
|
|
1856
|
+
$app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
|
|
1857
|
+
createOnesApp.addCommandUsage($app);
|
|
1858
|
+
createOnesApp.addCommandOutput($app);
|
|
1859
|
+
const legacyCommandArguments = ["projectPath"];
|
|
1860
|
+
const $create = new commander.Command("create").description(i18n.t("desc.legacy.create")).argument("<project-path>", i18n.t("desc.legacy.create.projectPath")).action(legacy);
|
|
1861
|
+
createOnesApp.addCommandUsage($create);
|
|
1862
|
+
createOnesApp.addCommandOutput($create);
|
|
1863
|
+
const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"));
|
|
1864
|
+
$legacy.addCommand($create);
|
|
1865
|
+
createOnesApp.addCommandUsage($legacy);
|
|
1866
|
+
createOnesApp.addCommandOutput($legacy);
|
|
1867
|
+
const ones = new commander.Command("ones");
|
|
1868
|
+
const version = `${getPackageJSON().version}`;
|
|
1869
|
+
const env = `${version} Node/${process.version}`;
|
|
1870
|
+
ones.description(i18n.t("desc.ones", {
|
|
1871
|
+
env
|
|
1872
|
+
})).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
|
|
1873
|
+
visibleCommands: (cmd) => {
|
|
1874
|
+
const blackList = ["legacy"];
|
|
1875
|
+
return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
|
|
1876
|
+
},
|
|
1877
|
+
subcommandTerm: (subcommand) => {
|
|
1878
|
+
return `${subcommand.name()} ${subcommand.usage()}`.trim();
|
|
1879
|
+
}
|
|
1880
|
+
});
|
|
1881
|
+
createOnesApp.addCommandOutput(ones);
|
|
1882
|
+
const runCommandONES = async () => {
|
|
1883
|
+
const command = ones;
|
|
1884
|
+
createOnesApp.setContext("command", command);
|
|
1885
|
+
const version2 = `${getPackageJSON().version}`;
|
|
1886
|
+
command.version(version2, "-v, --version");
|
|
1887
|
+
await command.parse();
|
|
1888
|
+
};
|
|
1889
|
+
exports.runCommandONES = runCommandONES;
|