@ones-open/cli 1.0.1-5596.1908 → 1.0.1-6087.2002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1027 -555
- package/dist/index.js +1030 -558
- package/dist/types/actions/build/index.d.ts.map +1 -1
- package/dist/types/actions/build/normalize.d.ts.map +1 -1
- package/dist/types/actions/dev/enums.d.ts +5 -0
- package/dist/types/actions/dev/enums.d.ts.map +1 -1
- package/dist/types/actions/dev/index.d.ts.map +1 -1
- package/dist/types/actions/dev/normalize.d.ts.map +1 -1
- package/dist/types/actions/dev/types.d.ts +10 -0
- package/dist/types/actions/dev/types.d.ts.map +1 -0
- package/dist/types/actions/disable/index.d.ts.map +1 -1
- package/dist/types/actions/enable/index.d.ts.map +1 -1
- package/dist/types/actions/install/index.d.ts +1 -1
- package/dist/types/actions/install/index.d.ts.map +1 -1
- package/dist/types/actions/install/install.d.ts +2 -2
- package/dist/types/actions/install/install.d.ts.map +1 -1
- package/dist/types/actions/legacy/index.d.ts.map +1 -1
- package/dist/types/actions/legacy/normalize.d.ts.map +1 -1
- package/dist/types/actions/login/index.d.ts +1 -1
- package/dist/types/actions/login/index.d.ts.map +1 -1
- package/dist/types/actions/tunnel/consts.d.ts +3 -0
- package/dist/types/actions/tunnel/consts.d.ts.map +1 -1
- package/dist/types/actions/tunnel/index.d.ts +3 -1
- package/dist/types/actions/tunnel/index.d.ts.map +1 -1
- package/dist/types/actions/tunnel/normalize.d.ts.map +1 -1
- package/dist/types/actions/tunnel/tunnel-client.d.ts +3 -1
- package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -1
- package/dist/types/actions/tunnel/tunnel.d.ts +2 -3
- package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
- package/dist/types/actions/tunnel/types.d.ts +34 -0
- package/dist/types/actions/tunnel/types.d.ts.map +1 -0
- package/dist/types/actions/tunnel/utils.d.ts +7 -0
- package/dist/types/actions/tunnel/utils.d.ts.map +1 -0
- package/dist/types/actions/uninstall/index.d.ts.map +1 -1
- package/dist/types/actions/whoami/index.d.ts.map +1 -1
- package/dist/types/cli/index.d.ts.map +1 -1
- package/dist/types/command/build/index.d.ts +1 -0
- package/dist/types/command/build/index.d.ts.map +1 -1
- package/dist/types/command/dev/index.d.ts +2 -0
- package/dist/types/command/dev/index.d.ts.map +1 -1
- package/dist/types/command/legacy/index.d.ts +1 -1
- package/dist/types/command/legacy/index.d.ts.map +1 -1
- package/dist/types/command/tunnel/index.d.ts +1 -0
- package/dist/types/command/tunnel/index.d.ts.map +1 -1
- package/dist/types/common/config/types.d.ts +2 -1
- package/dist/types/common/config/types.d.ts.map +1 -1
- package/dist/types/common/config/utils.d.ts.map +1 -1
- package/dist/types/common/error/enums.d.ts +3 -1
- package/dist/types/common/error/enums.d.ts.map +1 -1
- package/dist/types/common/error/utils.d.ts +1 -0
- package/dist/types/common/error/utils.d.ts.map +1 -1
- package/dist/types/common/locales/en/index.d.ts +37 -28
- package/dist/types/common/locales/en/index.d.ts.map +1 -1
- package/dist/types/common/package/schema.d.ts +1 -1
- package/dist/types/common/package/schema.d.ts.map +1 -1
- package/dist/types/common/package/utils.d.ts +4 -0
- package/dist/types/common/package/utils.d.ts.map +1 -1
- package/dist/types/common/request/consts.d.ts +2 -0
- package/dist/types/common/request/consts.d.ts.map +1 -1
- package/dist/types/common/request/fetch.d.ts +4 -1
- package/dist/types/common/request/fetch.d.ts.map +1 -1
- package/dist/types/common/request/types.d.ts +26 -5
- package/dist/types/common/request/types.d.ts.map +1 -1
- package/dist/types/common/request/utils.d.ts +5 -2
- package/dist/types/common/request/utils.d.ts.map +1 -1
- 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/package.json +6 -3
- 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/types/actions/tunnel/hosted-token.d.ts +0 -5
- package/dist/types/actions/tunnel/hosted-token.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -6,53 +6,62 @@ const createOnesApp = require("create-ones-app");
|
|
|
6
6
|
const node_path = require("node:path");
|
|
7
7
|
const node_child_process = require("node:child_process");
|
|
8
8
|
const node_fs = require("node:fs");
|
|
9
|
+
const fse = require("fs-extra");
|
|
9
10
|
const archiver = require("archiver");
|
|
10
11
|
const lodashEs = require("lodash-es");
|
|
12
|
+
const chalk = require("chalk");
|
|
11
13
|
const process$1 = require("node:process");
|
|
12
14
|
const node_url = require("node:url");
|
|
13
15
|
const cosmiconfig = require("cosmiconfig");
|
|
14
|
-
const
|
|
16
|
+
const getPort = require("get-port");
|
|
15
17
|
const envPaths = require("env-paths");
|
|
16
18
|
const zod = require("zod");
|
|
17
|
-
const _defineProperty = require("@babel/runtime-corejs3/helpers/defineProperty");
|
|
18
|
-
const WebSocket = require("ws");
|
|
19
19
|
const axios = require("axios");
|
|
20
20
|
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
21
|
-
const http = require("node:http");
|
|
22
21
|
const ora = require("ora");
|
|
22
|
+
const WebSocket = require("ws");
|
|
23
|
+
const http = require("node:http");
|
|
23
24
|
const open = require("open");
|
|
24
|
-
const getPort = require("get-port");
|
|
25
25
|
const uuid = require("uuid");
|
|
26
26
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
27
27
|
const en = {
|
|
28
|
-
"desc.ones": "
|
|
29
|
-
"desc.build": "
|
|
30
|
-
"desc.build.output": "
|
|
31
|
-
"desc.
|
|
32
|
-
"desc.dev
|
|
33
|
-
"desc.
|
|
34
|
-
"desc.
|
|
35
|
-
"desc.
|
|
36
|
-
"desc.
|
|
37
|
-
"desc.
|
|
38
|
-
"desc.
|
|
39
|
-
"desc.
|
|
40
|
-
"desc.
|
|
41
|
-
"desc.
|
|
42
|
-
"desc.
|
|
43
|
-
"desc.
|
|
44
|
-
"desc.
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"error.
|
|
51
|
-
"error.
|
|
52
|
-
"error.
|
|
53
|
-
"error.
|
|
54
|
-
"error.
|
|
55
|
-
"error.
|
|
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.useStorage": "Use hosted storage ability",
|
|
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": "Please check for this error or upgrade your ONES CLI to the latest version",
|
|
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"
|
|
56
65
|
};
|
|
57
66
|
const map = {
|
|
58
67
|
en
|
|
@@ -81,6 +90,10 @@ const translate = (key, params) => {
|
|
|
81
90
|
const i18n = {
|
|
82
91
|
t: translate
|
|
83
92
|
};
|
|
93
|
+
const throwWarning = (code, message) => {
|
|
94
|
+
const text = `${message.trim().replace(/\s+$/, "")}[${code}]`;
|
|
95
|
+
console.warn(chalk.yellow(text));
|
|
96
|
+
};
|
|
84
97
|
var ErrorCode = ((ErrorCode2) => {
|
|
85
98
|
ErrorCode2[ErrorCode2["UNKNOWN_ERROR"] = createOnesApp.ErrorCode.UNKNOWN_ERROR] = "UNKNOWN_ERROR";
|
|
86
99
|
ErrorCode2[ErrorCode2["COMMAND_ERROR"] = createOnesApp.ErrorCode.COMMAND_ERROR] = "COMMAND_ERROR";
|
|
@@ -97,6 +110,8 @@ var ErrorCode = ((ErrorCode2) => {
|
|
|
97
110
|
ErrorCode2["STORE_PERMISSION"] = "E12";
|
|
98
111
|
ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
|
|
99
112
|
ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
|
|
113
|
+
ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
|
|
114
|
+
ErrorCode2["INCORRECT_BUILD_COMMAND"] = "E16";
|
|
100
115
|
return ErrorCode2;
|
|
101
116
|
})(ErrorCode || {});
|
|
102
117
|
const getPublicPath = () => {
|
|
@@ -133,8 +148,8 @@ const getAppPackageJSON = () => {
|
|
|
133
148
|
const json = JSON.parse(string);
|
|
134
149
|
return createOnesApp.AppPackageJSONSchema.parse(json);
|
|
135
150
|
} catch (error) {
|
|
136
|
-
|
|
137
|
-
return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, i18n.t("error.schema.app.package.parseError"));
|
|
151
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
152
|
+
return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.package.parseError")}: ${details}`);
|
|
138
153
|
}
|
|
139
154
|
};
|
|
140
155
|
const getAppManifestJSONPath = () => {
|
|
@@ -149,13 +164,27 @@ const getAppManifestJSON = () => {
|
|
|
149
164
|
const json = JSON.parse(string);
|
|
150
165
|
return createOnesApp.AppManifestJSONSchema.parse(json);
|
|
151
166
|
} catch (error) {
|
|
152
|
-
|
|
153
|
-
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, i18n.t("error.schema.app.manifest.parseError"));
|
|
167
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
168
|
+
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const validateAppManifestJSON = () => {
|
|
172
|
+
const appManifestJSON = getAppManifestJSON();
|
|
173
|
+
try {
|
|
174
|
+
createOnesApp.AppManifestStrictJSONSchema.parse(appManifestJSON);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
177
|
+
return throwWarning(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.validateError")}: ${details}`);
|
|
154
178
|
}
|
|
155
179
|
};
|
|
180
|
+
const defaultDevCommand = ["npm", "run", "dev"];
|
|
181
|
+
const defaultBuildCommand = ["npm", "run", "build"];
|
|
156
182
|
const defaultAppRcJSON = {
|
|
157
183
|
dev: {
|
|
158
|
-
command:
|
|
184
|
+
command: defaultDevCommand
|
|
185
|
+
},
|
|
186
|
+
build: {
|
|
187
|
+
command: defaultBuildCommand
|
|
159
188
|
}
|
|
160
189
|
};
|
|
161
190
|
let storeAppRcJSON = null;
|
|
@@ -184,17 +213,14 @@ const getAppRcJSON = async () => {
|
|
|
184
213
|
} catch (error) {
|
|
185
214
|
currentAppRcJSON = {};
|
|
186
215
|
}
|
|
187
|
-
return
|
|
188
|
-
...defaultAppRcJSON,
|
|
189
|
-
...templateAppRcJSON,
|
|
190
|
-
...currentAppRcJSON
|
|
191
|
-
};
|
|
216
|
+
return lodashEs.merge(defaultAppRcJSON, templateAppRcJSON, currentAppRcJSON);
|
|
192
217
|
};
|
|
193
218
|
const isOPKXFilename = /\.opkx$/;
|
|
194
219
|
const defaultOutputPath = "";
|
|
195
220
|
const normalize$a = async (options) => {
|
|
196
|
-
var _options$output;
|
|
221
|
+
var _options$output, _options$command;
|
|
197
222
|
let output = node_path.resolve(process$1.cwd(), (_options$output = options.output) !== null && _options$output !== void 0 ? _options$output : defaultOutputPath);
|
|
223
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
198
224
|
if (isOPKXFilename.test(output))
|
|
199
225
|
;
|
|
200
226
|
else {
|
|
@@ -202,12 +228,18 @@ const normalize$a = async (options) => {
|
|
|
202
228
|
const defaultOutputFilename = `${appManifestJSON.app.name}.opkx`;
|
|
203
229
|
output = node_path.resolve(output, defaultOutputFilename);
|
|
204
230
|
}
|
|
231
|
+
validateAppManifestJSON();
|
|
205
232
|
return {
|
|
206
|
-
output
|
|
233
|
+
output,
|
|
234
|
+
command
|
|
207
235
|
};
|
|
208
236
|
};
|
|
237
|
+
const {
|
|
238
|
+
existsSync,
|
|
239
|
+
ensureDirSync
|
|
240
|
+
} = fse;
|
|
209
241
|
const build = async function() {
|
|
210
|
-
var
|
|
242
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$build$comm, _appRcJSON$build, _appRcJSON$build$comp, _appRcJSON$build2;
|
|
211
243
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
212
244
|
args[_key] = arguments[_key];
|
|
213
245
|
}
|
|
@@ -215,18 +247,55 @@ const build = async function() {
|
|
|
215
247
|
options
|
|
216
248
|
} = createOnesApp.getCommandOptions(args, buildCommandArguments);
|
|
217
249
|
const normalizedOptions = await normalize$a(options);
|
|
218
|
-
const appPackageJSON = getAppPackageJSON();
|
|
219
250
|
const appManifestJSON = getAppManifestJSON();
|
|
220
251
|
const appRcJSON = await getAppRcJSON();
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
|
|
252
|
+
const firstCommand = normalizedOptions.command || ((_appRcJSON$dev = appRcJSON.dev) === null || _appRcJSON$dev === void 0 || (_appRcJSON$dev = _appRcJSON$dev.command) === null || _appRcJSON$dev === void 0 ? void 0 : _appRcJSON$dev[0]) || ((_defaultAppRcJSON$dev = defaultAppRcJSON.dev) === null || _defaultAppRcJSON$dev === void 0 || (_defaultAppRcJSON$dev = _defaultAppRcJSON$dev.command) === null || _defaultAppRcJSON$dev === void 0 ? void 0 : _defaultAppRcJSON$dev[0]) || "";
|
|
253
|
+
if (!firstCommand) {
|
|
254
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BUILD_COMMAND, i18n.t("error.build.incorrectCommand"));
|
|
255
|
+
}
|
|
256
|
+
const currentCommand = normalizedOptions.command ? normalizedOptions.command.split(" ") : (_appRcJSON$build$comm = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.command) !== null && _appRcJSON$build$comm !== void 0 ? _appRcJSON$build$comm : [];
|
|
257
|
+
const currentCommandString = currentCommand.join(" ");
|
|
258
|
+
const defaultBuildCommandString = defaultBuildCommand.join(" ");
|
|
259
|
+
let shouldBuild = false;
|
|
260
|
+
if (firstCommand === "npm") {
|
|
261
|
+
const appPackageJSONPath = getAppPackageJSONPath();
|
|
262
|
+
const isExists = existsSync(appPackageJSONPath);
|
|
263
|
+
if (isExists) {
|
|
264
|
+
shouldBuild = true;
|
|
265
|
+
const appPackageJSON = getAppPackageJSON();
|
|
266
|
+
if (currentCommandString === defaultBuildCommandString) {
|
|
267
|
+
var _appPackageJSON$scrip;
|
|
268
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build)
|
|
269
|
+
;
|
|
270
|
+
else {
|
|
271
|
+
return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
shouldBuild = true;
|
|
277
|
+
}
|
|
278
|
+
if (shouldBuild) {
|
|
279
|
+
const buildResult = node_child_process.spawnSync(firstCommand, currentCommand.slice(1), {
|
|
224
280
|
cwd: getAppWorkspacePath(),
|
|
225
|
-
stdio: "inherit"
|
|
281
|
+
stdio: "inherit",
|
|
282
|
+
env: {
|
|
283
|
+
...process.env,
|
|
284
|
+
NODE_ENV: "production"
|
|
285
|
+
}
|
|
226
286
|
});
|
|
227
|
-
|
|
228
|
-
|
|
287
|
+
if (buildResult.status !== 0 || buildResult.signal) {
|
|
288
|
+
var _buildResult$status;
|
|
289
|
+
process.exit((_buildResult$status = buildResult.status) !== null && _buildResult$status !== void 0 ? _buildResult$status : 1);
|
|
290
|
+
}
|
|
229
291
|
}
|
|
292
|
+
const appName = appManifestJSON.app.name;
|
|
293
|
+
const outputPath = normalizedOptions.output;
|
|
294
|
+
const outputDir = node_path.dirname(outputPath);
|
|
295
|
+
const outputFilename = node_path.basename(outputPath);
|
|
296
|
+
ensureDirSync(outputDir);
|
|
297
|
+
const outputStream = node_fs.createWriteStream(outputPath);
|
|
298
|
+
const files = (_appRcJSON$build$comp = (_appRcJSON$build2 = appRcJSON.build) === null || _appRcJSON$build2 === void 0 || (_appRcJSON$build2 = _appRcJSON$build2.compress) === null || _appRcJSON$build2 === void 0 ? void 0 : _appRcJSON$build2.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
|
|
230
299
|
const archive = archiver("zip", {
|
|
231
300
|
zlib: {
|
|
232
301
|
level: 9
|
|
@@ -249,18 +318,19 @@ const build = async function() {
|
|
|
249
318
|
});
|
|
250
319
|
archive.on("finish", () => {
|
|
251
320
|
process.stdout.write("\n");
|
|
252
|
-
console.log(
|
|
253
|
-
console.log(
|
|
321
|
+
console.log("");
|
|
322
|
+
console.log("Files in archive: ", createOnesApp.PUBLIC_FILENAME.MANIFEST, files);
|
|
323
|
+
console.log(`App "${appName}" built successfully!`);
|
|
324
|
+
console.log(`OPKX "${outputFilename}" created successfully!`);
|
|
325
|
+
console.log(`Output file: ${outputPath}`);
|
|
254
326
|
});
|
|
255
|
-
const outputStream = node_fs.createWriteStream(normalizedOptions.output);
|
|
256
327
|
archive.pipe(outputStream);
|
|
257
|
-
const files = (_appRcJSON$build$comp = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 || (_appRcJSON$build = _appRcJSON$build.compress) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
|
|
258
328
|
files.forEach((file) => {
|
|
259
329
|
archive.glob(file, {
|
|
260
330
|
cwd: getAppWorkspacePath()
|
|
261
331
|
});
|
|
262
332
|
});
|
|
263
|
-
archive.file(createOnesApp.PUBLIC_FILENAME.MANIFEST, {
|
|
333
|
+
archive.file(node_path.join(getAppWorkspacePath(), createOnesApp.PUBLIC_FILENAME.MANIFEST), {
|
|
264
334
|
name: createOnesApp.PUBLIC_FILENAME.MANIFEST
|
|
265
335
|
});
|
|
266
336
|
archive.finalize();
|
|
@@ -268,113 +338,11 @@ const build = async function() {
|
|
|
268
338
|
const config = {
|
|
269
339
|
defaultPort: {
|
|
270
340
|
login: 8200,
|
|
271
|
-
|
|
341
|
+
hosted: 8201,
|
|
342
|
+
devWebServer: 8202
|
|
272
343
|
}
|
|
273
344
|
};
|
|
274
345
|
const getConfig = () => config;
|
|
275
|
-
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
276
|
-
InstallOptions2["AUTO"] = "auto";
|
|
277
|
-
InstallOptions2["TRUE"] = "true";
|
|
278
|
-
InstallOptions2["FALSE"] = "false";
|
|
279
|
-
return InstallOptions2;
|
|
280
|
-
})(InstallOptions || {});
|
|
281
|
-
const defaultInstall = InstallOptions.AUTO;
|
|
282
|
-
const normalize$9 = async (options) => {
|
|
283
|
-
var _options$install;
|
|
284
|
-
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
285
|
-
switch (true) {
|
|
286
|
-
case install2 === InstallOptions.AUTO:
|
|
287
|
-
break;
|
|
288
|
-
case Boolean(install2):
|
|
289
|
-
install2 = InstallOptions.TRUE;
|
|
290
|
-
break;
|
|
291
|
-
default:
|
|
292
|
-
install2 = InstallOptions.FALSE;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
return {
|
|
296
|
-
install: install2
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
|
-
const dev = async function() {
|
|
300
|
-
var _appPackageJSON$scrip;
|
|
301
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
302
|
-
args[_key] = arguments[_key];
|
|
303
|
-
}
|
|
304
|
-
const {
|
|
305
|
-
options
|
|
306
|
-
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
307
|
-
const normalizedOptions = await normalize$9(options);
|
|
308
|
-
const appPackageJSON = getAppPackageJSON();
|
|
309
|
-
const appManifestJSON = getAppManifestJSON();
|
|
310
|
-
const appRcJSON = getAppRcJSON();
|
|
311
|
-
lodashEs.noop(appManifestJSON);
|
|
312
|
-
lodashEs.noop(appRcJSON);
|
|
313
|
-
if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
|
|
314
|
-
return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
315
|
-
}
|
|
316
|
-
const port = getConfig().defaultPort.tunnel;
|
|
317
|
-
const cwd = getAppWorkspacePath();
|
|
318
|
-
const env = {
|
|
319
|
-
...process.env,
|
|
320
|
-
ONES_HOSTED_PORT: `${port}`
|
|
321
|
-
};
|
|
322
|
-
const tunnelChild = node_child_process.spawn("ones", ["tunnel", String(port)], {
|
|
323
|
-
cwd,
|
|
324
|
-
stdio: "inherit"
|
|
325
|
-
});
|
|
326
|
-
const devChild = node_child_process.spawn("npm", ["run", "dev"], {
|
|
327
|
-
cwd,
|
|
328
|
-
stdio: "inherit",
|
|
329
|
-
env
|
|
330
|
-
});
|
|
331
|
-
const cleanup = () => {
|
|
332
|
-
tunnelChild.kill();
|
|
333
|
-
devChild.kill();
|
|
334
|
-
};
|
|
335
|
-
const onSignal = () => {
|
|
336
|
-
cleanup();
|
|
337
|
-
process.exit(128 + 2);
|
|
338
|
-
};
|
|
339
|
-
process.on("SIGINT", onSignal);
|
|
340
|
-
process.on("SIGTERM", onSignal);
|
|
341
|
-
if (normalizedOptions.install) {
|
|
342
|
-
lodashEs.noop(normalizedOptions.install);
|
|
343
|
-
}
|
|
344
|
-
await new Promise((resolve) => {
|
|
345
|
-
devChild.on("exit", () => {
|
|
346
|
-
cleanup();
|
|
347
|
-
process.off("SIGINT", onSignal);
|
|
348
|
-
process.off("SIGTERM", onSignal);
|
|
349
|
-
resolve();
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
};
|
|
353
|
-
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
354
|
-
const minPortNumber = 1;
|
|
355
|
-
const maxPortNumber = 65535;
|
|
356
|
-
const normalize$8 = async (options) => {
|
|
357
|
-
const portInput = options.port;
|
|
358
|
-
if (portInput)
|
|
359
|
-
;
|
|
360
|
-
else {
|
|
361
|
-
return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
362
|
-
}
|
|
363
|
-
const portString = String(portInput);
|
|
364
|
-
const portNumber = Number(portString);
|
|
365
|
-
if (isPortNumber.test(portString))
|
|
366
|
-
;
|
|
367
|
-
else {
|
|
368
|
-
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
369
|
-
}
|
|
370
|
-
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
371
|
-
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
372
|
-
}
|
|
373
|
-
const port = portString;
|
|
374
|
-
return {
|
|
375
|
-
port
|
|
376
|
-
};
|
|
377
|
-
};
|
|
378
346
|
const StoreJSONSchema = zod.z.object({
|
|
379
347
|
version: zod.z.string().optional(),
|
|
380
348
|
timestamp: zod.z.number().optional(),
|
|
@@ -420,11 +388,11 @@ const getStore = async () => {
|
|
|
420
388
|
const setStore = async (store) => {
|
|
421
389
|
try {
|
|
422
390
|
await ensureFile(storePath);
|
|
423
|
-
const
|
|
391
|
+
const version2 = `${getPackageJSON().version}`;
|
|
424
392
|
const timestamp = Date.now();
|
|
425
393
|
return await writeJSON(storePath, {
|
|
426
394
|
...store,
|
|
427
|
-
version,
|
|
395
|
+
version: version2,
|
|
428
396
|
timestamp
|
|
429
397
|
}, {
|
|
430
398
|
encoding: "utf8"
|
|
@@ -476,122 +444,459 @@ const setONESToken = async (token) => {
|
|
|
476
444
|
ones_token: token
|
|
477
445
|
});
|
|
478
446
|
};
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
447
|
+
const getHostToken = async () => {
|
|
448
|
+
var _store$host_token;
|
|
449
|
+
const store = await getStore();
|
|
450
|
+
return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
|
|
451
|
+
};
|
|
452
|
+
const setHostToken = async (token) => {
|
|
453
|
+
return mergeStore({
|
|
454
|
+
host_token: token
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
const API = {
|
|
458
|
+
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
459
|
+
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
460
|
+
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/:appID/dev_declare",
|
|
461
|
+
APP_LIST: "/platform/api/app/list",
|
|
462
|
+
APP_INSTALL: "/platform/api/app/install",
|
|
463
|
+
APP_UPGRADE: "/platform/api/app/:installation_id/upgrade",
|
|
464
|
+
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
465
|
+
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
466
|
+
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
467
|
+
};
|
|
468
|
+
const REQUEST_TIMEOUT = 5e3;
|
|
469
|
+
const getPath = (path, map2) => {
|
|
470
|
+
var _context;
|
|
471
|
+
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
472
|
+
if (/^:/.test(part)) {
|
|
473
|
+
return `${base}/${map2[part.slice(1)]}`;
|
|
474
|
+
}
|
|
475
|
+
return `${base}/${part}`;
|
|
476
|
+
}, "").slice(1);
|
|
477
|
+
};
|
|
478
|
+
const consoleUnauthorizedMessage = () => {
|
|
479
|
+
console.log("Not logged in");
|
|
480
|
+
console.log('Login with "ones login" command');
|
|
481
|
+
process.exit(1);
|
|
482
|
+
};
|
|
483
|
+
const consoleAppNotInstalledMessage = () => {
|
|
484
|
+
console.log("App not installed");
|
|
485
|
+
process.exit(1);
|
|
486
|
+
};
|
|
487
|
+
const getURL = async (path, pathMap, queryMap) => {
|
|
488
|
+
const base = await getRegionURL();
|
|
489
|
+
if (base) {
|
|
490
|
+
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
491
|
+
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
513
492
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
493
|
+
consoleUnauthorizedMessage();
|
|
494
|
+
};
|
|
495
|
+
const getHostedFetchHeaders = async (value) => {
|
|
496
|
+
const hostedToken = await getHostToken();
|
|
497
|
+
if (hostedToken) {
|
|
498
|
+
return lodashEs.merge({
|
|
499
|
+
Authorization: `Bearer ${hostedToken}`
|
|
500
|
+
}, value);
|
|
517
501
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
502
|
+
consoleUnauthorizedMessage();
|
|
503
|
+
process.exit(1);
|
|
504
|
+
};
|
|
505
|
+
const getHeaders = async (value) => {
|
|
506
|
+
const token = await getONESToken();
|
|
507
|
+
if (token) {
|
|
508
|
+
return lodashEs.merge({
|
|
509
|
+
Authorization: `Bearer ${token}`
|
|
510
|
+
}, value);
|
|
523
511
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return this.parseJSONEnvelope(buffer.toString());
|
|
512
|
+
consoleUnauthorizedMessage();
|
|
513
|
+
process.exit(1);
|
|
514
|
+
};
|
|
515
|
+
const handleError = (error) => {
|
|
516
|
+
var _error$response, _error$response2;
|
|
517
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
518
|
+
console.log(error.response.statusText);
|
|
519
|
+
consoleUnauthorizedMessage();
|
|
520
|
+
process.exit(1);
|
|
536
521
|
}
|
|
537
|
-
|
|
538
|
-
const request = this.getRequestPayload(message);
|
|
539
|
-
if (!request) {
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
if (request.path === ONES_CLI_MANIFEST_PATH) {
|
|
543
|
-
const appManifest = getAppManifestJSON().app;
|
|
544
|
-
const baseURL = await buildTunnelUrl();
|
|
545
|
-
const reply = {
|
|
546
|
-
id: message.id,
|
|
547
|
-
payload: {
|
|
548
|
-
status: 200,
|
|
549
|
-
headers: {
|
|
550
|
-
"content-type": ["application/json"]
|
|
551
|
-
},
|
|
552
|
-
body: {
|
|
553
|
-
...appManifest,
|
|
554
|
-
base_url: baseURL
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
this.sendBinaryEnvelope(reply);
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
522
|
+
if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
|
|
561
523
|
try {
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
};
|
|
567
|
-
this.sendBinaryEnvelope(reply);
|
|
568
|
-
} catch (error) {
|
|
569
|
-
const reply = {
|
|
570
|
-
id: message.id,
|
|
571
|
-
payload: {
|
|
572
|
-
status: 500,
|
|
573
|
-
headers: {
|
|
574
|
-
"x-agent-error": [error instanceof Error ? error.message : "Unknown error"]
|
|
575
|
-
},
|
|
576
|
-
body: "agent request error"
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
this.sendBinaryEnvelope(reply);
|
|
524
|
+
const message = JSON.stringify(error.response.data, null, 2);
|
|
525
|
+
console.error(message);
|
|
526
|
+
process.exit(1);
|
|
527
|
+
} catch (error2) {
|
|
580
528
|
}
|
|
581
529
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
530
|
+
console.error(error);
|
|
531
|
+
return {};
|
|
532
|
+
};
|
|
533
|
+
const startWaiting = () => {
|
|
534
|
+
const time = 3e3;
|
|
535
|
+
let spinner = null;
|
|
536
|
+
const sid = setTimeout(() => {
|
|
537
|
+
spinner = ora("Waiting for response...");
|
|
538
|
+
spinner.start();
|
|
539
|
+
}, time);
|
|
540
|
+
const cancelWaiting = () => {
|
|
541
|
+
clearTimeout(sid);
|
|
542
|
+
if (spinner) {
|
|
543
|
+
spinner.stop();
|
|
586
544
|
}
|
|
587
|
-
|
|
545
|
+
};
|
|
546
|
+
return cancelWaiting;
|
|
547
|
+
};
|
|
548
|
+
const fetchAppBase = async (params) => {
|
|
549
|
+
var _params$url;
|
|
550
|
+
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
551
|
+
const headers = await getHeaders(params.headers);
|
|
552
|
+
const response = await axios({
|
|
553
|
+
...params,
|
|
554
|
+
url,
|
|
555
|
+
headers,
|
|
556
|
+
timeout: REQUEST_TIMEOUT
|
|
557
|
+
});
|
|
558
|
+
return response.data;
|
|
559
|
+
};
|
|
560
|
+
const fetchHostedAbilityBase = async (params) => {
|
|
561
|
+
var _params$url2;
|
|
562
|
+
const url = await getURL((_params$url2 = params.url) !== null && _params$url2 !== void 0 ? _params$url2 : "", params.pathMap, params.queryMap);
|
|
563
|
+
const headers = await getHostedFetchHeaders(params.headers);
|
|
564
|
+
const response = await axios({
|
|
565
|
+
...params,
|
|
566
|
+
url,
|
|
567
|
+
headers,
|
|
568
|
+
timeout: REQUEST_TIMEOUT
|
|
569
|
+
});
|
|
570
|
+
return response.data;
|
|
571
|
+
};
|
|
572
|
+
const fetchAppList = async (appID) => {
|
|
573
|
+
return await fetchAppBase({
|
|
574
|
+
url: API.APP_LIST,
|
|
575
|
+
method: "GET",
|
|
576
|
+
queryMap: {
|
|
577
|
+
app_id: appID
|
|
578
|
+
}
|
|
579
|
+
}).catch(handleError);
|
|
580
|
+
};
|
|
581
|
+
const fetchTokenInfo = async () => {
|
|
582
|
+
return await fetchAppBase({
|
|
583
|
+
url: API.TOKEN_INFO,
|
|
584
|
+
method: "GET"
|
|
585
|
+
}).catch(handleError);
|
|
586
|
+
};
|
|
587
|
+
const fetchHostedToken = async (data) => {
|
|
588
|
+
return await fetchAppBase({
|
|
589
|
+
url: API.HOSTED_TOKEN,
|
|
590
|
+
method: "POST",
|
|
591
|
+
data
|
|
592
|
+
}).catch(handleError);
|
|
593
|
+
};
|
|
594
|
+
const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
|
|
595
|
+
return await fetchHostedAbilityBase({
|
|
596
|
+
url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
|
|
597
|
+
method: "POST",
|
|
598
|
+
pathMap: {
|
|
599
|
+
appID
|
|
600
|
+
},
|
|
601
|
+
data
|
|
602
|
+
}).catch(handleError);
|
|
603
|
+
};
|
|
604
|
+
const fetchAppInstall = async (data) => {
|
|
605
|
+
var _appList$data$0$insta, _appList$data;
|
|
606
|
+
const appID = getAppManifestJSON().app.id;
|
|
607
|
+
const appList = await fetchAppList(appID);
|
|
608
|
+
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
609
|
+
if (installationID) {
|
|
610
|
+
return await fetchAppBase({
|
|
611
|
+
url: API.APP_UPGRADE,
|
|
612
|
+
method: "POST",
|
|
613
|
+
pathMap: {
|
|
614
|
+
installation_id: installationID
|
|
615
|
+
},
|
|
616
|
+
data
|
|
617
|
+
}).catch(handleError);
|
|
618
|
+
}
|
|
619
|
+
return await fetchAppBase({
|
|
620
|
+
url: API.APP_INSTALL,
|
|
621
|
+
method: "POST",
|
|
622
|
+
data
|
|
623
|
+
}).catch(handleError);
|
|
624
|
+
};
|
|
625
|
+
const fetchAppUninstall = async () => {
|
|
626
|
+
var _appList$data$0$insta2, _appList$data2;
|
|
627
|
+
const appID = getAppManifestJSON().app.id;
|
|
628
|
+
const appList = await fetchAppList(appID);
|
|
629
|
+
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 : "";
|
|
630
|
+
if (installationID) {
|
|
631
|
+
return await fetchAppBase({
|
|
632
|
+
url: API.APP_UNINSTALL,
|
|
633
|
+
method: "POST",
|
|
634
|
+
pathMap: {
|
|
635
|
+
installation_id: installationID
|
|
636
|
+
}
|
|
637
|
+
}).catch(handleError);
|
|
638
|
+
}
|
|
639
|
+
consoleAppNotInstalledMessage();
|
|
640
|
+
process.exit(1);
|
|
641
|
+
};
|
|
642
|
+
const fetchAppEnable = async () => {
|
|
643
|
+
var _appList$data$0$insta3, _appList$data3;
|
|
644
|
+
const appID = getAppManifestJSON().app.id;
|
|
645
|
+
const appList = await fetchAppList(appID);
|
|
646
|
+
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 : "";
|
|
647
|
+
if (installationID) {
|
|
648
|
+
return await fetchAppBase({
|
|
649
|
+
url: API.APP_ENABLE,
|
|
650
|
+
method: "POST",
|
|
651
|
+
pathMap: {
|
|
652
|
+
installation_id: installationID
|
|
653
|
+
}
|
|
654
|
+
}).catch(handleError);
|
|
655
|
+
}
|
|
656
|
+
consoleAppNotInstalledMessage();
|
|
657
|
+
process.exit(1);
|
|
658
|
+
};
|
|
659
|
+
const fetchAppDisable = async () => {
|
|
660
|
+
var _appList$data$0$insta4, _appList$data4;
|
|
661
|
+
const appID = getAppManifestJSON().app.id;
|
|
662
|
+
const appList = await fetchAppList(appID);
|
|
663
|
+
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 : "";
|
|
664
|
+
if (installationID) {
|
|
665
|
+
return await fetchAppBase({
|
|
666
|
+
url: API.APP_DISABLE,
|
|
667
|
+
method: "POST",
|
|
668
|
+
pathMap: {
|
|
669
|
+
installation_id: installationID
|
|
670
|
+
}
|
|
671
|
+
}).catch(handleError);
|
|
672
|
+
}
|
|
673
|
+
consoleAppNotInstalledMessage();
|
|
674
|
+
process.exit(1);
|
|
675
|
+
};
|
|
676
|
+
const checkTokenInfo = async () => {
|
|
677
|
+
var _store$ones_token, _store$region_url;
|
|
678
|
+
let boolean = true;
|
|
679
|
+
const store = await getStore();
|
|
680
|
+
const token = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
|
|
681
|
+
const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
682
|
+
if (token && regionURL) {
|
|
683
|
+
await fetchAppBase({
|
|
684
|
+
url: API.APP_LIST,
|
|
685
|
+
method: "GET"
|
|
686
|
+
}).catch(() => {
|
|
687
|
+
boolean = false;
|
|
688
|
+
});
|
|
689
|
+
} else {
|
|
690
|
+
boolean = false;
|
|
691
|
+
}
|
|
692
|
+
return boolean;
|
|
693
|
+
};
|
|
694
|
+
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
695
|
+
const minPortNumber = 1;
|
|
696
|
+
const maxPortNumber = 65535;
|
|
697
|
+
const MANIFEST_PATH = "/manifest";
|
|
698
|
+
const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
|
|
699
|
+
const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
|
|
700
|
+
const normalize$9 = async (options) => {
|
|
701
|
+
var _options$useStorage;
|
|
702
|
+
const portInput = options.port;
|
|
703
|
+
if (portInput)
|
|
704
|
+
;
|
|
705
|
+
else {
|
|
706
|
+
return createOnesApp.throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
707
|
+
}
|
|
708
|
+
const portString = String(portInput);
|
|
709
|
+
const portNumber = Number(portString);
|
|
710
|
+
if (isPortNumber.test(portString))
|
|
711
|
+
;
|
|
712
|
+
else {
|
|
713
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
714
|
+
}
|
|
715
|
+
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
716
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
717
|
+
}
|
|
718
|
+
const port = portString;
|
|
719
|
+
validateAppManifestJSON();
|
|
720
|
+
return {
|
|
721
|
+
port,
|
|
722
|
+
useStorage: (_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : false
|
|
723
|
+
};
|
|
724
|
+
};
|
|
725
|
+
const getTunnelContext = async () => {
|
|
726
|
+
var _appManifestJSON$app$, _appManifestJSON$app, _store$region_url, _store$ones_token;
|
|
727
|
+
const appManifestJSON = getAppManifestJSON();
|
|
728
|
+
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$ : "";
|
|
729
|
+
const store = await getStore();
|
|
730
|
+
const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
731
|
+
const onesToken = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
|
|
732
|
+
if (appID && regionURL && onesToken) {
|
|
733
|
+
return {
|
|
734
|
+
appID,
|
|
735
|
+
regionURL,
|
|
736
|
+
onesToken,
|
|
737
|
+
store,
|
|
738
|
+
appManifestJSON
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
consoleUnauthorizedMessage();
|
|
742
|
+
process.exit(1);
|
|
743
|
+
};
|
|
744
|
+
const getStorageTokenScopes = (ones2) => {
|
|
745
|
+
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
746
|
+
if (!storage) {
|
|
747
|
+
return [];
|
|
748
|
+
}
|
|
749
|
+
const scopes = /* @__PURE__ */ new Set();
|
|
750
|
+
if (Array.isArray(storage.entities) && storage.entities.length > 0) {
|
|
751
|
+
scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
|
|
752
|
+
}
|
|
753
|
+
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
754
|
+
scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
|
|
755
|
+
}
|
|
756
|
+
return Array.from(scopes);
|
|
757
|
+
};
|
|
758
|
+
const getRelayScope = () => {
|
|
759
|
+
return createOnesApp.HostedTokenScope.RELAY;
|
|
760
|
+
};
|
|
761
|
+
const buildTunnelUrl = async () => {
|
|
762
|
+
const {
|
|
763
|
+
appID,
|
|
764
|
+
regionURL
|
|
765
|
+
} = await getTunnelContext();
|
|
766
|
+
const url = new URL(regionURL);
|
|
767
|
+
url.pathname = `/platform/app/relay/dispatch/${appID}`;
|
|
768
|
+
return url.toString();
|
|
769
|
+
};
|
|
770
|
+
class TunnelClient {
|
|
771
|
+
constructor(localPort, baseUrl, appID, hostedToken) {
|
|
772
|
+
let enableInternalManifestRoute = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
773
|
+
let replaceExisting = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
|
|
774
|
+
this.ws = null;
|
|
775
|
+
this.localPort = localPort;
|
|
776
|
+
this.baseUrl = baseUrl;
|
|
777
|
+
this.appID = appID;
|
|
778
|
+
this.hostedToken = hostedToken;
|
|
779
|
+
this.enableInternalManifestRoute = enableInternalManifestRoute;
|
|
780
|
+
this.replaceExisting = replaceExisting;
|
|
781
|
+
}
|
|
782
|
+
async connect() {
|
|
783
|
+
const proxyUrl = this.buildProxyUrl();
|
|
784
|
+
this.ws = new WebSocket(proxyUrl, {
|
|
785
|
+
headers: {
|
|
786
|
+
Authorization: `Bearer ${this.hostedToken}`
|
|
787
|
+
},
|
|
788
|
+
maxPayload: MAX_RELAY_BODY_BYTES
|
|
789
|
+
});
|
|
790
|
+
this.ws.on("message", async (data) => {
|
|
791
|
+
const message = this.parseMessage(data);
|
|
792
|
+
if (!message) {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
await this.handleMessage(message);
|
|
796
|
+
});
|
|
797
|
+
this.ws.on("ping", (data) => {
|
|
798
|
+
var _this$ws;
|
|
799
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.pong(data);
|
|
800
|
+
});
|
|
801
|
+
this.ws.on("error", (error) => {
|
|
802
|
+
console.error("WebSocket error:", error);
|
|
803
|
+
});
|
|
804
|
+
return new Promise((resolve, reject) => {
|
|
805
|
+
var _this$ws2, _this$ws3;
|
|
806
|
+
(_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.on("open", () => resolve());
|
|
807
|
+
(_this$ws3 = this.ws) === null || _this$ws3 === void 0 || _this$ws3.on("error", reject);
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
close() {
|
|
811
|
+
var _this$ws4;
|
|
812
|
+
(_this$ws4 = this.ws) === null || _this$ws4 === void 0 || _this$ws4.close();
|
|
813
|
+
}
|
|
814
|
+
buildProxyUrl() {
|
|
815
|
+
const url = new URL("/platform/app/relay/", this.baseUrl);
|
|
816
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
817
|
+
url.searchParams.set("app_id", this.appID);
|
|
818
|
+
url.searchParams.set("replace_existing", String(this.replaceExisting));
|
|
819
|
+
return url.toString();
|
|
820
|
+
}
|
|
821
|
+
parseMessage(data) {
|
|
822
|
+
const buffer = this.toBuffer(data);
|
|
823
|
+
if (!buffer) {
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
if (buffer.length >= 4) {
|
|
827
|
+
const binary = this.parseBinaryEnvelope(buffer);
|
|
828
|
+
if (binary) {
|
|
829
|
+
return binary;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return this.parseJSONEnvelope(buffer.toString());
|
|
833
|
+
}
|
|
834
|
+
async handleMessage(message) {
|
|
835
|
+
const request = this.getRequestPayload(message);
|
|
836
|
+
if (!request) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
|
|
840
|
+
const appManifest = getAppManifestJSON().app;
|
|
841
|
+
const baseURL = await buildTunnelUrl();
|
|
842
|
+
const reply = {
|
|
843
|
+
id: message.id,
|
|
844
|
+
payload: {
|
|
845
|
+
status: 200,
|
|
846
|
+
headers: {
|
|
847
|
+
"content-type": ["application/json"]
|
|
848
|
+
},
|
|
849
|
+
body: {
|
|
850
|
+
...appManifest,
|
|
851
|
+
base_url: baseURL
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
this.sendBinaryEnvelope(reply);
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
try {
|
|
859
|
+
const response = await this.forwardRequest(request);
|
|
860
|
+
const reply = {
|
|
861
|
+
id: message.id,
|
|
862
|
+
payload: response
|
|
863
|
+
};
|
|
864
|
+
this.sendBinaryEnvelope(reply);
|
|
865
|
+
} catch (error) {
|
|
866
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
867
|
+
console.error("Error forwarding request:", errorMessage);
|
|
868
|
+
const reply = {
|
|
869
|
+
id: message.id,
|
|
870
|
+
payload: {
|
|
871
|
+
status: 500,
|
|
872
|
+
headers: {
|
|
873
|
+
"x-agent-error": [errorMessage]
|
|
874
|
+
},
|
|
875
|
+
body: errorMessage
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
this.sendBinaryEnvelope(reply);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
getRequestPayload(message) {
|
|
882
|
+
const payload = message.payload;
|
|
883
|
+
if (!(payload !== null && payload !== void 0 && payload.method) || !(payload !== null && payload !== void 0 && payload.path)) {
|
|
884
|
+
return null;
|
|
885
|
+
}
|
|
886
|
+
return payload;
|
|
588
887
|
}
|
|
589
888
|
async forwardRequest(payload) {
|
|
590
889
|
const url = new URL(payload.path, `http://127.0.0.1:${this.localPort}`);
|
|
591
890
|
if (payload.query) {
|
|
592
891
|
Object.entries(payload.query).forEach((_ref) => {
|
|
593
892
|
let [key, value] = _ref;
|
|
594
|
-
|
|
893
|
+
if (Array.isArray(value)) {
|
|
894
|
+
value.forEach((item) => {
|
|
895
|
+
url.searchParams.append(key, item);
|
|
896
|
+
});
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
url.searchParams.append(key, value);
|
|
595
900
|
});
|
|
596
901
|
}
|
|
597
902
|
const response = await axios.request({
|
|
@@ -600,7 +905,9 @@ class TunnelClient {
|
|
|
600
905
|
headers: payload.headers,
|
|
601
906
|
data: payload.body,
|
|
602
907
|
responseType: "arraybuffer",
|
|
603
|
-
validateStatus: () => true
|
|
908
|
+
validateStatus: () => true,
|
|
909
|
+
maxBodyLength: MAX_RELAY_BODY_BYTES,
|
|
910
|
+
maxContentLength: MAX_RELAY_BODY_BYTES
|
|
604
911
|
});
|
|
605
912
|
const responseBytes = Buffer.from(response.data);
|
|
606
913
|
return {
|
|
@@ -632,6 +939,9 @@ class TunnelClient {
|
|
|
632
939
|
var _envelope$payload;
|
|
633
940
|
const payload = (_envelope$payload = envelope.payload) !== null && _envelope$payload !== void 0 ? _envelope$payload : {};
|
|
634
941
|
const body = this.toBodyBuffer(payload.body);
|
|
942
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
943
|
+
throw new Error("relay body too large");
|
|
944
|
+
}
|
|
635
945
|
const metaPayload = {
|
|
636
946
|
...payload
|
|
637
947
|
};
|
|
@@ -674,7 +984,12 @@ class TunnelClient {
|
|
|
674
984
|
return envelope;
|
|
675
985
|
}
|
|
676
986
|
const body = buffer.subarray(4 + metaLength);
|
|
677
|
-
|
|
987
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
988
|
+
console.error("Binary tunnel body exceeds size limit");
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
const payload = envelope.payload;
|
|
992
|
+
payload.body = body;
|
|
678
993
|
return envelope;
|
|
679
994
|
} catch (error) {
|
|
680
995
|
console.error("Invalid binary tunnel message:", error);
|
|
@@ -706,240 +1021,377 @@ class TunnelClient {
|
|
|
706
1021
|
return null;
|
|
707
1022
|
}
|
|
708
1023
|
}
|
|
709
|
-
const
|
|
710
|
-
var
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
726
|
-
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
727
|
-
}
|
|
728
|
-
consoleUnauthorizedMessage();
|
|
729
|
-
process$1.exit(1);
|
|
730
|
-
};
|
|
731
|
-
const getHeaders = async (value) => {
|
|
732
|
-
const token = await getONESToken();
|
|
733
|
-
if (token) {
|
|
734
|
-
return lodashEs.merge({
|
|
735
|
-
Authorization: `Bearer ${token}`
|
|
736
|
-
}, value);
|
|
737
|
-
}
|
|
738
|
-
consoleUnauthorizedMessage();
|
|
739
|
-
process$1.exit(1);
|
|
740
|
-
};
|
|
741
|
-
const handleError = (error) => {
|
|
742
|
-
var _error$response;
|
|
743
|
-
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
744
|
-
console.log(error.response.statusText);
|
|
745
|
-
consoleUnauthorizedMessage();
|
|
746
|
-
} else {
|
|
747
|
-
console.error(error);
|
|
748
|
-
}
|
|
749
|
-
return {};
|
|
750
|
-
};
|
|
751
|
-
const API = {
|
|
752
|
-
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
753
|
-
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
754
|
-
APP_LIST: "/platform/api/app/list",
|
|
755
|
-
APP_INSTALL: "/platform/api/app/install",
|
|
756
|
-
APP_UPGRADE: "/platform/api/app/upgrade",
|
|
757
|
-
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
758
|
-
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
759
|
-
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
760
|
-
};
|
|
761
|
-
const isRecord = (value) => {
|
|
762
|
-
return typeof value === "object" && value !== null;
|
|
763
|
-
};
|
|
764
|
-
const getHostedTokenScopes = (ones2) => {
|
|
765
|
-
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
766
|
-
if (!storage) {
|
|
767
|
-
return [];
|
|
768
|
-
}
|
|
769
|
-
const scopes = /* @__PURE__ */ new Set();
|
|
770
|
-
if (Array.isArray(storage.entities) && storage.entities.length > 0) {
|
|
771
|
-
scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
|
|
772
|
-
}
|
|
773
|
-
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
774
|
-
scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
|
|
775
|
-
}
|
|
776
|
-
return Array.from(scopes);
|
|
777
|
-
};
|
|
778
|
-
const getRelayScope = () => {
|
|
779
|
-
return createOnesApp.HostedTokenScope.RELAY;
|
|
780
|
-
};
|
|
781
|
-
const getHostToken = async (baseUrl, userToken, appID, scopes) => {
|
|
782
|
-
const url = `${baseUrl.replace(/\/$/, "")}${API.HOSTED_TOKEN}`;
|
|
783
|
-
return axios.post(url, {
|
|
784
|
-
app_id: appID,
|
|
785
|
-
scopes
|
|
786
|
-
}, {
|
|
787
|
-
headers: {
|
|
788
|
-
Authorization: `Bearer ${userToken}`
|
|
789
|
-
}
|
|
790
|
-
}).then((resp) => {
|
|
791
|
-
const data = resp === null || resp === void 0 ? void 0 : resp.data;
|
|
792
|
-
const tokenFromData = (value) => {
|
|
793
|
-
if (isRecord(value) && isRecord(value.data)) {
|
|
794
|
-
const hosted_token = value.data.hosted_token;
|
|
795
|
-
if (typeof hosted_token === "string" && hosted_token.length > 0) {
|
|
796
|
-
return hosted_token;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return null;
|
|
800
|
-
};
|
|
801
|
-
const token = tokenFromData(data);
|
|
802
|
-
if (token) {
|
|
803
|
-
return token;
|
|
804
|
-
}
|
|
805
|
-
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
806
|
-
}).catch((error) => {
|
|
807
|
-
handleError(error);
|
|
808
|
-
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_REQUEST_FAILED, i18n.t("error.hostedToken.requestFailed"));
|
|
809
|
-
});
|
|
810
|
-
};
|
|
811
|
-
const fetchAppBase = async (params) => {
|
|
812
|
-
var _params$url;
|
|
813
|
-
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
814
|
-
const headers = await getHeaders(params.headers);
|
|
815
|
-
const response = await axios({
|
|
816
|
-
...params,
|
|
817
|
-
url,
|
|
818
|
-
headers
|
|
1024
|
+
const invokeTunnel = async function(port) {
|
|
1025
|
+
var _options$rebuildWhenE, _options$enableIntern, _options$useStorageFo, _hostedTokenResponse$, _appManifestJSON$ones, _appManifestJSON$ones2;
|
|
1026
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1027
|
+
const {
|
|
1028
|
+
appManifestJSON,
|
|
1029
|
+
appID,
|
|
1030
|
+
regionURL
|
|
1031
|
+
} = await getTunnelContext();
|
|
1032
|
+
const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
|
|
1033
|
+
const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
|
|
1034
|
+
const storageScopes = getStorageTokenScopes(appManifestJSON.ones);
|
|
1035
|
+
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
1036
|
+
const hostedTokenResponse = await fetchHostedToken({
|
|
1037
|
+
app_id: appID,
|
|
1038
|
+
scopes,
|
|
1039
|
+
confirm_for_dev: (_options$useStorageFo = options.useStorageForDev) !== null && _options$useStorageFo !== void 0 ? _options$useStorageFo : false
|
|
819
1040
|
});
|
|
820
|
-
|
|
1041
|
+
const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
|
|
1042
|
+
if (!hostedToken) {
|
|
1043
|
+
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
1044
|
+
}
|
|
1045
|
+
await setHostToken(hostedToken);
|
|
1046
|
+
const entities = (_appManifestJSON$ones = (_appManifestJSON$ones2 = appManifestJSON.ones) === null || _appManifestJSON$ones2 === void 0 || (_appManifestJSON$ones2 = _appManifestJSON$ones2.storage) === null || _appManifestJSON$ones2 === void 0 ? void 0 : _appManifestJSON$ones2.entities) !== null && _appManifestJSON$ones !== void 0 ? _appManifestJSON$ones : [];
|
|
1047
|
+
if (entities.length > 0) {
|
|
1048
|
+
await fetchHostedAbilityStorageDevDeclare(appID, {
|
|
1049
|
+
opkx_content: appManifestJSON
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
|
|
1053
|
+
await client.connect();
|
|
821
1054
|
};
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
}
|
|
1055
|
+
const tunnel = async function() {
|
|
1056
|
+
var _normalizedOptions$us;
|
|
1057
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1058
|
+
args[_key] = arguments[_key];
|
|
1059
|
+
}
|
|
1060
|
+
const {
|
|
1061
|
+
options
|
|
1062
|
+
} = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
|
|
1063
|
+
const normalizedOptions = await normalize$9(options);
|
|
1064
|
+
const port = Number(normalizedOptions.port);
|
|
1065
|
+
const cancelWaiting = startWaiting();
|
|
1066
|
+
await invokeTunnel(port, {
|
|
1067
|
+
enableInternalManifestRoute: false,
|
|
1068
|
+
rebuildWhenExists: true,
|
|
1069
|
+
useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
|
|
1070
|
+
});
|
|
1071
|
+
cancelWaiting();
|
|
1072
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1073
|
+
console.log(`Relay endpoint: ${tunnelUrl}`);
|
|
830
1074
|
};
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
method: "GET"
|
|
835
|
-
}).catch(handleError);
|
|
1075
|
+
const normalize$8 = async (options) => {
|
|
1076
|
+
lodashEs.noop(options);
|
|
1077
|
+
return {};
|
|
836
1078
|
};
|
|
837
|
-
const
|
|
838
|
-
var
|
|
839
|
-
const
|
|
840
|
-
const
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
}
|
|
1079
|
+
const displayAppDetail = async (installationID) => {
|
|
1080
|
+
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
1081
|
+
const tokenInfo = await fetchTokenInfo();
|
|
1082
|
+
const orgUUID = (_tokenInfo$org$uuid = (_tokenInfo$org = tokenInfo.org) === null || _tokenInfo$org === void 0 ? void 0 : _tokenInfo$org.uuid) !== null && _tokenInfo$org$uuid !== void 0 ? _tokenInfo$org$uuid : "";
|
|
1083
|
+
const teamUUID = (_tokenInfo$teams$0$uu = (_tokenInfo$teams = tokenInfo.teams) === null || _tokenInfo$teams === void 0 || (_tokenInfo$teams = _tokenInfo$teams[0]) === null || _tokenInfo$teams === void 0 ? void 0 : _tokenInfo$teams.uuid) !== null && _tokenInfo$teams$0$uu !== void 0 ? _tokenInfo$teams$0$uu : "";
|
|
1084
|
+
const isOrgVisible = (_tokenInfo$org$visibi = (_tokenInfo$org2 = tokenInfo.org) === null || _tokenInfo$org2 === void 0 ? void 0 : _tokenInfo$org2.visibility) !== null && _tokenInfo$org$visibi !== void 0 ? _tokenInfo$org$visibi : false;
|
|
1085
|
+
const baseURL = await getBaseURL();
|
|
1086
|
+
if (isOrgVisible && orgUUID) {
|
|
1087
|
+
const url = `${baseURL}project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
1088
|
+
console.log(`See App detail: ${url}`);
|
|
1089
|
+
}
|
|
1090
|
+
if (!isOrgVisible && teamUUID) {
|
|
1091
|
+
const url = `${baseURL}project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
1092
|
+
console.log(`See App detail: ${url}`);
|
|
1093
|
+
}
|
|
848
1094
|
};
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
const
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1095
|
+
const invokeInstall = async (manifestUrl) => {
|
|
1096
|
+
const {
|
|
1097
|
+
app
|
|
1098
|
+
} = getAppManifestJSON();
|
|
1099
|
+
const appName = app.name;
|
|
1100
|
+
const appID = app.id;
|
|
1101
|
+
const cancelWaiting = startWaiting();
|
|
1102
|
+
const result = await fetchAppInstall({
|
|
1103
|
+
manifest_url: manifestUrl,
|
|
1104
|
+
options: {
|
|
1105
|
+
enable: true
|
|
859
1106
|
}
|
|
860
|
-
})
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
method: "POST",
|
|
870
|
-
pathMap: {
|
|
871
|
-
installation_id: installationID
|
|
1107
|
+
});
|
|
1108
|
+
cancelWaiting();
|
|
1109
|
+
if (result.code === "OK") {
|
|
1110
|
+
var _appList$data$0$insta, _appList$data;
|
|
1111
|
+
console.log(`App "${appName}" installed successfully!`);
|
|
1112
|
+
const appList = await fetchAppList(appID);
|
|
1113
|
+
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
1114
|
+
if (installationID) {
|
|
1115
|
+
await displayAppDetail(installationID);
|
|
872
1116
|
}
|
|
873
|
-
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
1117
|
+
return true;
|
|
1118
|
+
} else {
|
|
1119
|
+
console.log(`App "${appName}" installed failed!`);
|
|
1120
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1121
|
+
}
|
|
1122
|
+
return false;
|
|
1123
|
+
};
|
|
1124
|
+
const getManifestUrl = async () => {
|
|
1125
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1126
|
+
const customManifestUrl = `${tunnelUrl}${MANIFEST_PATH}`;
|
|
1127
|
+
const internalManifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1128
|
+
const internalResult = await axios.get(internalManifestUrl, {
|
|
1129
|
+
timeout: REQUEST_TIMEOUT
|
|
1130
|
+
}).then((response) => {
|
|
1131
|
+
if (response.status === 200) {
|
|
1132
|
+
return internalManifestUrl;
|
|
885
1133
|
}
|
|
886
|
-
|
|
887
|
-
};
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
var _appManifestJSON$app$, _appManifestJSON$app;
|
|
891
|
-
const appManifestJSON = getAppManifestJSON();
|
|
892
|
-
const appID = (_appManifestJSON$app$ = (_appManifestJSON$app = appManifestJSON.app) === null || _appManifestJSON$app === void 0 ? void 0 : _appManifestJSON$app.id) !== null && _appManifestJSON$app$ !== void 0 ? _appManifestJSON$app$ : "";
|
|
893
|
-
if (!appID) {
|
|
894
|
-
throw new Error("app id is empty");
|
|
1134
|
+
return null;
|
|
1135
|
+
}).catch(lodashEs.noop);
|
|
1136
|
+
if (internalResult) {
|
|
1137
|
+
return internalResult;
|
|
895
1138
|
}
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
1139
|
+
const customResult = await axios.get(customManifestUrl, {
|
|
1140
|
+
timeout: REQUEST_TIMEOUT
|
|
1141
|
+
}).then((response) => {
|
|
1142
|
+
if (response.status === 200) {
|
|
1143
|
+
return customManifestUrl;
|
|
1144
|
+
}
|
|
1145
|
+
return null;
|
|
1146
|
+
}).catch(lodashEs.noop);
|
|
1147
|
+
if (customResult) {
|
|
1148
|
+
return customResult;
|
|
899
1149
|
}
|
|
900
|
-
return
|
|
901
|
-
appManifestJSON,
|
|
902
|
-
appID,
|
|
903
|
-
regionURL
|
|
904
|
-
};
|
|
1150
|
+
return null;
|
|
905
1151
|
};
|
|
906
|
-
const
|
|
1152
|
+
const install = async function() {
|
|
1153
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1154
|
+
args[_key] = arguments[_key];
|
|
1155
|
+
}
|
|
907
1156
|
const {
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
return `${url.protocol}//${url.host}/platform/app/relay/dispatch/${appID}`;
|
|
913
|
-
};
|
|
914
|
-
const invokeTunnel = async (port) => {
|
|
1157
|
+
options
|
|
1158
|
+
} = createOnesApp.getCommandOptions(args, installCommandArguments);
|
|
1159
|
+
const normalizedOptions = await normalize$8(options);
|
|
1160
|
+
lodashEs.noop(normalizedOptions);
|
|
915
1161
|
const {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
process
|
|
1162
|
+
app
|
|
1163
|
+
} = getAppManifestJSON();
|
|
1164
|
+
const appName = app.name;
|
|
1165
|
+
const manifestUrl = await getManifestUrl();
|
|
1166
|
+
if (!manifestUrl) {
|
|
1167
|
+
console.log(`App "${appName}" server not available!`);
|
|
1168
|
+
console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
|
|
1169
|
+
process.exit(1);
|
|
924
1170
|
}
|
|
925
|
-
|
|
926
|
-
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
927
|
-
const hostedToken = await getHostToken(regionURL, onesToken, appID, scopes);
|
|
928
|
-
process.env.ONES_HOSTED_TOKEN = hostedToken;
|
|
929
|
-
const client = new TunnelClient(port, regionURL, appID, hostedToken);
|
|
930
|
-
await client.connect();
|
|
931
|
-
const runnelUrl = await buildTunnelUrl();
|
|
932
|
-
console.log(`Relay endpoint: ${runnelUrl}`);
|
|
1171
|
+
await invokeInstall(manifestUrl);
|
|
933
1172
|
};
|
|
934
|
-
|
|
1173
|
+
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
1174
|
+
InstallOptions2["AUTO"] = "auto";
|
|
1175
|
+
InstallOptions2["TRUE"] = "true";
|
|
1176
|
+
InstallOptions2["FALSE"] = "false";
|
|
1177
|
+
return InstallOptions2;
|
|
1178
|
+
})(InstallOptions || {});
|
|
1179
|
+
var DevCommandScripts = /* @__PURE__ */ ((DevCommandScripts2) => {
|
|
1180
|
+
DevCommandScripts2["Concurrently"] = "concurrently";
|
|
1181
|
+
DevCommandScripts2["Nest"] = "nest";
|
|
1182
|
+
DevCommandScripts2["Vite"] = "vite";
|
|
1183
|
+
return DevCommandScripts2;
|
|
1184
|
+
})(DevCommandScripts || {});
|
|
1185
|
+
const defaultInstall = InstallOptions.AUTO;
|
|
1186
|
+
const normalize$7 = async (options) => {
|
|
1187
|
+
var _options$install, _options$command, _options$useStorage;
|
|
1188
|
+
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
1189
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
1190
|
+
const useStorageString = `${(_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : ""}`;
|
|
1191
|
+
switch (true) {
|
|
1192
|
+
case install2 === InstallOptions.AUTO:
|
|
1193
|
+
break;
|
|
1194
|
+
case install2 === InstallOptions.FALSE:
|
|
1195
|
+
break;
|
|
1196
|
+
default:
|
|
1197
|
+
install2 = InstallOptions.TRUE;
|
|
1198
|
+
break;
|
|
1199
|
+
}
|
|
1200
|
+
validateAppManifestJSON();
|
|
1201
|
+
return {
|
|
1202
|
+
install: install2,
|
|
1203
|
+
command,
|
|
1204
|
+
useStorage: useStorageString === "false" ? false : true
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
const IDLE_MS = 2e3;
|
|
1208
|
+
const dev = async function() {
|
|
1209
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2;
|
|
935
1210
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
936
1211
|
args[_key] = arguments[_key];
|
|
937
1212
|
}
|
|
938
1213
|
const {
|
|
939
1214
|
options
|
|
940
|
-
} = createOnesApp.getCommandOptions(args,
|
|
941
|
-
const normalizedOptions = await normalize$
|
|
942
|
-
await
|
|
1215
|
+
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
1216
|
+
const normalizedOptions = await normalize$7(options);
|
|
1217
|
+
const appRcJSON = await getAppRcJSON();
|
|
1218
|
+
const firstCommand = normalizedOptions.command || ((_appRcJSON$dev = appRcJSON.dev) === null || _appRcJSON$dev === void 0 || (_appRcJSON$dev = _appRcJSON$dev.command) === null || _appRcJSON$dev === void 0 ? void 0 : _appRcJSON$dev[0]) || ((_defaultAppRcJSON$dev = defaultAppRcJSON.dev) === null || _defaultAppRcJSON$dev === void 0 || (_defaultAppRcJSON$dev = _defaultAppRcJSON$dev.command) === null || _defaultAppRcJSON$dev === void 0 ? void 0 : _defaultAppRcJSON$dev[0]) || "";
|
|
1219
|
+
if (!firstCommand) {
|
|
1220
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
|
|
1221
|
+
}
|
|
1222
|
+
const currentCommand = normalizedOptions.command ? normalizedOptions.command.split(" ") : (_appRcJSON$dev$comman = (_appRcJSON$dev2 = appRcJSON.dev) === null || _appRcJSON$dev2 === void 0 ? void 0 : _appRcJSON$dev2.command) !== null && _appRcJSON$dev$comman !== void 0 ? _appRcJSON$dev$comman : [];
|
|
1223
|
+
const currentCommandString = currentCommand.join(" ");
|
|
1224
|
+
const defaultDevCommandString = defaultDevCommand.join(" ");
|
|
1225
|
+
let templateCommand = false;
|
|
1226
|
+
if (firstCommand === "npm") {
|
|
1227
|
+
const appPackageJSON = getAppPackageJSON();
|
|
1228
|
+
if (currentCommandString === defaultDevCommandString) {
|
|
1229
|
+
var _appPackageJSON$scrip;
|
|
1230
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev) {
|
|
1231
|
+
var _appPackageJSON$scrip2, _appPackageJSON$scrip3, _appPackageJSON$scrip4;
|
|
1232
|
+
const dev2 = (_appPackageJSON$scrip2 = appPackageJSON.scripts.dev) !== null && _appPackageJSON$scrip2 !== void 0 ? _appPackageJSON$scrip2 : "";
|
|
1233
|
+
const devWeb = (_appPackageJSON$scrip3 = appPackageJSON.scripts["dev:web"]) !== null && _appPackageJSON$scrip3 !== void 0 ? _appPackageJSON$scrip3 : "";
|
|
1234
|
+
const devBackend = (_appPackageJSON$scrip4 = appPackageJSON.scripts["dev:backend"]) !== null && _appPackageJSON$scrip4 !== void 0 ? _appPackageJSON$scrip4 : "";
|
|
1235
|
+
const hasConcurrently = _includesInstanceProperty(dev2).call(dev2, DevCommandScripts.Concurrently);
|
|
1236
|
+
const hasNest = _includesInstanceProperty(devBackend).call(devBackend, DevCommandScripts.Nest);
|
|
1237
|
+
const hasVite = _includesInstanceProperty(devWeb).call(devWeb, DevCommandScripts.Vite);
|
|
1238
|
+
templateCommand = hasConcurrently && hasNest && hasVite;
|
|
1239
|
+
} else {
|
|
1240
|
+
return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
const appManifestJSON = getAppManifestJSON();
|
|
1245
|
+
const {
|
|
1246
|
+
app
|
|
1247
|
+
} = appManifestJSON;
|
|
1248
|
+
const appID = app.id;
|
|
1249
|
+
const config2 = getConfig();
|
|
1250
|
+
const ONES_HOSTED_PORT = await getPort({
|
|
1251
|
+
port: config2.defaultPort.hosted
|
|
1252
|
+
});
|
|
1253
|
+
const ONES_DEV_WEB_SERVER_PORT = await getPort({
|
|
1254
|
+
port: config2.defaultPort.devWebServer
|
|
1255
|
+
});
|
|
1256
|
+
const env2 = {
|
|
1257
|
+
...process.env,
|
|
1258
|
+
NODE_ENV: "development",
|
|
1259
|
+
ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
|
|
1260
|
+
ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
|
|
1261
|
+
ONES_HOSTED_TOKEN: "",
|
|
1262
|
+
ONES_HOSTED_APP_ID: "",
|
|
1263
|
+
ONES_HOSTED_BASE_URL: ""
|
|
1264
|
+
};
|
|
1265
|
+
const cancelWaiting = startWaiting();
|
|
1266
|
+
let enableTunnel = true;
|
|
1267
|
+
if (normalizedOptions.install === InstallOptions.TRUE)
|
|
1268
|
+
;
|
|
1269
|
+
else {
|
|
1270
|
+
enableTunnel = await checkTokenInfo();
|
|
1271
|
+
}
|
|
1272
|
+
if (enableTunnel) {
|
|
1273
|
+
var _normalizedOptions$us;
|
|
1274
|
+
await invokeTunnel(ONES_HOSTED_PORT, {
|
|
1275
|
+
enableInternalManifestRoute: true,
|
|
1276
|
+
rebuildWhenExists: true,
|
|
1277
|
+
useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
|
|
1278
|
+
});
|
|
1279
|
+
const regionURL = await getRegionURL();
|
|
1280
|
+
const ONES_HOSTED_TOKEN = await getHostToken();
|
|
1281
|
+
const ONES_HOSTED_APP_ID = appID;
|
|
1282
|
+
const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
|
|
1283
|
+
env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
|
|
1284
|
+
env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
|
|
1285
|
+
env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
|
|
1286
|
+
} else {
|
|
1287
|
+
console.log("Not logged in or session expired, skipping tunnel connection...");
|
|
1288
|
+
}
|
|
1289
|
+
cancelWaiting();
|
|
1290
|
+
const onReady = async () => {
|
|
1291
|
+
const appName = app.name;
|
|
1292
|
+
let manifestUrl = "";
|
|
1293
|
+
console.log("");
|
|
1294
|
+
console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
|
|
1295
|
+
if (enableTunnel) {
|
|
1296
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1297
|
+
console.log(`URL: ${tunnelUrl}`);
|
|
1298
|
+
manifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1299
|
+
}
|
|
1300
|
+
console.log(`App "${appName}" server is ready!`);
|
|
1301
|
+
console.log("");
|
|
1302
|
+
if (enableTunnel) {
|
|
1303
|
+
switch (normalizedOptions.install) {
|
|
1304
|
+
case InstallOptions.TRUE:
|
|
1305
|
+
await invokeInstall(manifestUrl);
|
|
1306
|
+
break;
|
|
1307
|
+
case InstallOptions.AUTO:
|
|
1308
|
+
{
|
|
1309
|
+
var _appList$data$0$insta, _appList$data;
|
|
1310
|
+
const appList = await fetchAppList(appID);
|
|
1311
|
+
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
1312
|
+
if (installationID) {
|
|
1313
|
+
await displayAppDetail(installationID);
|
|
1314
|
+
} else {
|
|
1315
|
+
await invokeInstall(manifestUrl);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
break;
|
|
1319
|
+
case InstallOptions.FALSE:
|
|
1320
|
+
break;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
const cwd = getAppWorkspacePath();
|
|
1325
|
+
const child = node_child_process.spawn(firstCommand, currentCommand.slice(1), {
|
|
1326
|
+
cwd,
|
|
1327
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
1328
|
+
env: env2,
|
|
1329
|
+
shell: true
|
|
1330
|
+
});
|
|
1331
|
+
const createReadyStatusPipes = (onReady2) => {
|
|
1332
|
+
let readyTimer = null;
|
|
1333
|
+
let summaryPrinted = false;
|
|
1334
|
+
const scheduleReady = () => {
|
|
1335
|
+
if (summaryPrinted)
|
|
1336
|
+
return;
|
|
1337
|
+
if (readyTimer)
|
|
1338
|
+
clearTimeout(readyTimer);
|
|
1339
|
+
readyTimer = setTimeout(() => {
|
|
1340
|
+
readyTimer = null;
|
|
1341
|
+
if (!summaryPrinted) {
|
|
1342
|
+
summaryPrinted = true;
|
|
1343
|
+
onReady2();
|
|
1344
|
+
}
|
|
1345
|
+
}, IDLE_MS);
|
|
1346
|
+
};
|
|
1347
|
+
const pipe2 = (stream, isStderr) => {
|
|
1348
|
+
const write = (chunk) => {
|
|
1349
|
+
if (isStderr)
|
|
1350
|
+
process.stderr.write(chunk);
|
|
1351
|
+
else
|
|
1352
|
+
process.stdout.write(chunk);
|
|
1353
|
+
};
|
|
1354
|
+
if (templateCommand) {
|
|
1355
|
+
stream.on("data", (chunk) => {
|
|
1356
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1357
|
+
write(str);
|
|
1358
|
+
if (str.startsWith("[backend]") || str.startsWith("[web]")) {
|
|
1359
|
+
scheduleReady();
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
} else {
|
|
1363
|
+
scheduleReady();
|
|
1364
|
+
stream.on("data", (chunk) => {
|
|
1365
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1366
|
+
write(str);
|
|
1367
|
+
scheduleReady();
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
return pipe2;
|
|
1372
|
+
};
|
|
1373
|
+
const pipe = createReadyStatusPipes(onReady);
|
|
1374
|
+
if (child.stdout)
|
|
1375
|
+
pipe(child.stdout, false);
|
|
1376
|
+
if (child.stderr)
|
|
1377
|
+
pipe(child.stderr, true);
|
|
1378
|
+
const cleanup = () => {
|
|
1379
|
+
child.kill();
|
|
1380
|
+
};
|
|
1381
|
+
const onSignal = () => {
|
|
1382
|
+
cleanup();
|
|
1383
|
+
process.exit(128 + 2);
|
|
1384
|
+
};
|
|
1385
|
+
process.on("SIGINT", onSignal);
|
|
1386
|
+
process.on("SIGTERM", onSignal);
|
|
1387
|
+
await new Promise((resolve) => {
|
|
1388
|
+
child.on("exit", () => {
|
|
1389
|
+
cleanup();
|
|
1390
|
+
process.off("SIGINT", onSignal);
|
|
1391
|
+
process.off("SIGTERM", onSignal);
|
|
1392
|
+
resolve();
|
|
1393
|
+
});
|
|
1394
|
+
});
|
|
943
1395
|
};
|
|
944
1396
|
function createPromise() {
|
|
945
1397
|
let resolve;
|
|
@@ -961,7 +1413,7 @@ const sleep = (number) => {
|
|
|
961
1413
|
};
|
|
962
1414
|
const isURL = /^https?:\/\//;
|
|
963
1415
|
const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
|
|
964
|
-
const normalize$
|
|
1416
|
+
const normalize$6 = async (options) => {
|
|
965
1417
|
const baseURLInput = options.baseURL;
|
|
966
1418
|
if (baseURLInput)
|
|
967
1419
|
;
|
|
@@ -998,7 +1450,7 @@ const login = async function() {
|
|
|
998
1450
|
const {
|
|
999
1451
|
options
|
|
1000
1452
|
} = createOnesApp.getCommandOptions(args, loginCommandArguments);
|
|
1001
|
-
const normalizedOptions = await normalize$
|
|
1453
|
+
const normalizedOptions = await normalize$6(options);
|
|
1002
1454
|
const base = normalizedOptions.baseURL;
|
|
1003
1455
|
const path = "project/oauth2.html";
|
|
1004
1456
|
const config2 = getConfig();
|
|
@@ -1075,14 +1527,28 @@ const login = async function() {
|
|
|
1075
1527
|
} else {
|
|
1076
1528
|
console.log("Login canceled!");
|
|
1077
1529
|
}
|
|
1530
|
+
}).finally(() => {
|
|
1078
1531
|
process$1.exit(0);
|
|
1079
1532
|
});
|
|
1533
|
+
let exited = false;
|
|
1534
|
+
const handleExit = () => {
|
|
1535
|
+
if (exited)
|
|
1536
|
+
return;
|
|
1537
|
+
exited = true;
|
|
1538
|
+
resolve(null);
|
|
1539
|
+
};
|
|
1540
|
+
process$1.on("SIGINT", handleExit);
|
|
1541
|
+
process$1.on("SIGTERM", handleExit);
|
|
1080
1542
|
console.log("Logging into your ONES account...");
|
|
1081
1543
|
console.log(`Opening ${url}`);
|
|
1082
1544
|
ora("Waiting for authorization...").start();
|
|
1083
|
-
|
|
1545
|
+
try {
|
|
1546
|
+
await open(url);
|
|
1547
|
+
} catch (error) {
|
|
1548
|
+
return createOnesApp.throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1549
|
+
}
|
|
1084
1550
|
};
|
|
1085
|
-
const normalize$
|
|
1551
|
+
const normalize$5 = async (options) => {
|
|
1086
1552
|
lodashEs.noop(options);
|
|
1087
1553
|
return {};
|
|
1088
1554
|
};
|
|
@@ -1093,12 +1559,12 @@ const logout = async function() {
|
|
|
1093
1559
|
const {
|
|
1094
1560
|
options
|
|
1095
1561
|
} = createOnesApp.getCommandOptions(args, logoutCommandArguments);
|
|
1096
|
-
const normalizedOptions = await normalize$
|
|
1562
|
+
const normalizedOptions = await normalize$5(options);
|
|
1097
1563
|
lodashEs.noop(normalizedOptions);
|
|
1098
1564
|
await setStore({});
|
|
1099
1565
|
console.log("Logged out successfully!");
|
|
1100
1566
|
};
|
|
1101
|
-
const normalize$
|
|
1567
|
+
const normalize$4 = async (options) => {
|
|
1102
1568
|
lodashEs.noop(options);
|
|
1103
1569
|
return {};
|
|
1104
1570
|
};
|
|
@@ -1110,67 +1576,22 @@ const whoami = async function() {
|
|
|
1110
1576
|
const {
|
|
1111
1577
|
options
|
|
1112
1578
|
} = createOnesApp.getCommandOptions(args, whoamiCommandArguments);
|
|
1113
|
-
const normalizedOptions = await normalize$
|
|
1579
|
+
const normalizedOptions = await normalize$4(options);
|
|
1114
1580
|
lodashEs.noop(normalizedOptions);
|
|
1115
1581
|
const baseURL = await getBaseURL();
|
|
1582
|
+
const cancelWaiting = startWaiting();
|
|
1116
1583
|
const tokenInfo = await fetchTokenInfo();
|
|
1584
|
+
cancelWaiting();
|
|
1117
1585
|
const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
|
|
1118
1586
|
const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
|
|
1119
1587
|
if (name2 && email) {
|
|
1120
|
-
console.log(
|
|
1588
|
+
console.log(`User: ${name2}`);
|
|
1589
|
+
console.log(`Email: ${email}`);
|
|
1121
1590
|
console.log(`ONES: ${baseURL}`);
|
|
1122
1591
|
} else {
|
|
1123
1592
|
consoleUnauthorizedMessage();
|
|
1124
1593
|
}
|
|
1125
1594
|
};
|
|
1126
|
-
const normalize$4 = async (options) => {
|
|
1127
|
-
lodashEs.noop(options);
|
|
1128
|
-
return {};
|
|
1129
|
-
};
|
|
1130
|
-
const invokeInstall = async () => {
|
|
1131
|
-
const runnelUrl = await buildTunnelUrl();
|
|
1132
|
-
const result = await fetchAppInstall({
|
|
1133
|
-
manifest_url: `${runnelUrl}${ONES_CLI_MANIFEST_PATH}`
|
|
1134
|
-
});
|
|
1135
|
-
return result;
|
|
1136
|
-
};
|
|
1137
|
-
const install = async function() {
|
|
1138
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1139
|
-
args[_key] = arguments[_key];
|
|
1140
|
-
}
|
|
1141
|
-
const {
|
|
1142
|
-
options
|
|
1143
|
-
} = createOnesApp.getCommandOptions(args, installCommandArguments);
|
|
1144
|
-
const normalizedOptions = await normalize$4(options);
|
|
1145
|
-
lodashEs.noop(normalizedOptions);
|
|
1146
|
-
await invokeTunnel(getConfig().defaultPort.tunnel);
|
|
1147
|
-
const result = await invokeInstall();
|
|
1148
|
-
if (result.code === "OK") {
|
|
1149
|
-
var _appList$data$0$insta, _appList$data;
|
|
1150
|
-
console.log("App installed successfully!");
|
|
1151
|
-
const appID = getAppManifestJSON().app.id;
|
|
1152
|
-
const appList = await fetchAppList(appID);
|
|
1153
|
-
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
1154
|
-
if (installationID) {
|
|
1155
|
-
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
1156
|
-
const tokenInfo = await fetchTokenInfo();
|
|
1157
|
-
const orgUUID = (_tokenInfo$org$uuid = (_tokenInfo$org = tokenInfo.org) === null || _tokenInfo$org === void 0 ? void 0 : _tokenInfo$org.uuid) !== null && _tokenInfo$org$uuid !== void 0 ? _tokenInfo$org$uuid : "";
|
|
1158
|
-
const teamUUID = (_tokenInfo$teams$0$uu = (_tokenInfo$teams = tokenInfo.teams) === null || _tokenInfo$teams === void 0 || (_tokenInfo$teams = _tokenInfo$teams[0]) === null || _tokenInfo$teams === void 0 ? void 0 : _tokenInfo$teams.uuid) !== null && _tokenInfo$teams$0$uu !== void 0 ? _tokenInfo$teams$0$uu : "";
|
|
1159
|
-
const isOrgVisible = (_tokenInfo$org$visibi = (_tokenInfo$org2 = tokenInfo.org) === null || _tokenInfo$org2 === void 0 ? void 0 : _tokenInfo$org2.visibility) !== null && _tokenInfo$org$visibi !== void 0 ? _tokenInfo$org$visibi : false;
|
|
1160
|
-
const baseURL = await getBaseURL();
|
|
1161
|
-
if (isOrgVisible && orgUUID) {
|
|
1162
|
-
const url = `${baseURL}/project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
1163
|
-
console.log(`See App detail: ${url}`);
|
|
1164
|
-
}
|
|
1165
|
-
if (!isOrgVisible && teamUUID) {
|
|
1166
|
-
const url = `${baseURL}/project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
1167
|
-
console.log(`See App detail: ${url}`);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
} else {
|
|
1171
|
-
console.error(result);
|
|
1172
|
-
}
|
|
1173
|
-
};
|
|
1174
1595
|
const normalize$3 = async (options) => {
|
|
1175
1596
|
lodashEs.noop(options);
|
|
1176
1597
|
return {};
|
|
@@ -1184,11 +1605,15 @@ const enable = async function() {
|
|
|
1184
1605
|
} = createOnesApp.getCommandOptions(args, enableCommandArguments);
|
|
1185
1606
|
const normalizedOptions = await normalize$3(options);
|
|
1186
1607
|
lodashEs.noop(normalizedOptions);
|
|
1608
|
+
const appName = getAppManifestJSON().app.name;
|
|
1609
|
+
const cancelWaiting = startWaiting();
|
|
1187
1610
|
const result = await fetchAppEnable();
|
|
1611
|
+
cancelWaiting();
|
|
1188
1612
|
if (result.code === "OK") {
|
|
1189
|
-
console.log(
|
|
1613
|
+
console.log(`App "${appName}" enabled successfully!`);
|
|
1190
1614
|
} else {
|
|
1191
|
-
console.
|
|
1615
|
+
console.log(`App "${appName}" enabled failed!`);
|
|
1616
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1192
1617
|
}
|
|
1193
1618
|
};
|
|
1194
1619
|
const normalize$2 = async (options) => {
|
|
@@ -1204,11 +1629,15 @@ const disable = async function() {
|
|
|
1204
1629
|
} = createOnesApp.getCommandOptions(args, disableCommandArguments);
|
|
1205
1630
|
const normalizedOptions = await normalize$2(options);
|
|
1206
1631
|
lodashEs.noop(normalizedOptions);
|
|
1632
|
+
const appName = getAppManifestJSON().app.name;
|
|
1633
|
+
const cancelWaiting = startWaiting();
|
|
1207
1634
|
const result = await fetchAppDisable();
|
|
1635
|
+
cancelWaiting();
|
|
1208
1636
|
if (result.code === "OK") {
|
|
1209
|
-
console.log(
|
|
1637
|
+
console.log(`App "${appName}" disabled successfully!`);
|
|
1210
1638
|
} else {
|
|
1211
|
-
console.
|
|
1639
|
+
console.log(`App "${appName}" disabled failed!`);
|
|
1640
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1212
1641
|
}
|
|
1213
1642
|
};
|
|
1214
1643
|
const normalize$1 = async (options) => {
|
|
@@ -1224,17 +1653,40 @@ const uninstall = async function() {
|
|
|
1224
1653
|
} = createOnesApp.getCommandOptions(args, uninstallCommandArguments);
|
|
1225
1654
|
const normalizedOptions = await normalize$1(options);
|
|
1226
1655
|
lodashEs.noop(normalizedOptions);
|
|
1656
|
+
const appName = getAppManifestJSON().app.name;
|
|
1657
|
+
const cancelWaiting = startWaiting();
|
|
1227
1658
|
const result = await fetchAppUninstall();
|
|
1659
|
+
cancelWaiting();
|
|
1228
1660
|
if (result.code === "OK") {
|
|
1229
|
-
console.log(
|
|
1661
|
+
console.log(`App "${appName}" uninstalled successfully!`);
|
|
1230
1662
|
} else {
|
|
1231
|
-
console.
|
|
1663
|
+
console.log(`App "${appName}" uninstalled failed!`);
|
|
1664
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1232
1665
|
}
|
|
1233
1666
|
};
|
|
1667
|
+
const getTemplatePath = () => {
|
|
1668
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
1669
|
+
return node_path.join(__dirname, "../template");
|
|
1670
|
+
};
|
|
1671
|
+
const getTemplateLegacy = () => {
|
|
1672
|
+
return "legacy";
|
|
1673
|
+
};
|
|
1234
1674
|
const normalize = async (options) => {
|
|
1235
|
-
|
|
1236
|
-
|
|
1675
|
+
const projectPathInput = options.projectPath;
|
|
1676
|
+
if (projectPathInput)
|
|
1677
|
+
;
|
|
1678
|
+
else {
|
|
1679
|
+
return createOnesApp.throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.legacy.create.missingProjectPath"));
|
|
1680
|
+
}
|
|
1681
|
+
const projectPath = node_path.resolve(process$1.cwd(), projectPathInput);
|
|
1682
|
+
return {
|
|
1683
|
+
projectPath
|
|
1684
|
+
};
|
|
1237
1685
|
};
|
|
1686
|
+
const {
|
|
1687
|
+
copy,
|
|
1688
|
+
moveSync
|
|
1689
|
+
} = fse;
|
|
1238
1690
|
const legacy = async function() {
|
|
1239
1691
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1240
1692
|
args[_key] = arguments[_key];
|
|
@@ -1243,18 +1695,30 @@ const legacy = async function() {
|
|
|
1243
1695
|
options
|
|
1244
1696
|
} = createOnesApp.getCommandOptions(args, legacyCommandArguments);
|
|
1245
1697
|
const normalizedOptions = await normalize(options);
|
|
1246
|
-
|
|
1698
|
+
const {
|
|
1699
|
+
projectPath
|
|
1700
|
+
} = normalizedOptions;
|
|
1701
|
+
const templatePath = node_path.join(getTemplatePath(), getTemplateLegacy());
|
|
1702
|
+
await copy(templatePath, projectPath);
|
|
1703
|
+
const rename = [["_eslintignore", ".eslintignore"], ["_eslintrc.js", ".eslintrc.js"], ["_gitignore", ".gitignore"], ["_gitlab-ci.yml", ".gitlab-ci.yml"], ["_npmrc", ".npmrc"], ["_prettierignore", ".prettierignore"], ["_prettierrc", ".prettierrc"], ["_backend_npmrc", "backend/.npmrc"], ["_backend_tsconfig.json", "backend/tsconfig.json"], ["_web_npmrc", "web/.npmrc"], ["_web_tsconfig.json", "web/tsconfig.json"], ["_husky_pre-commit", ".husky/pre-commit"]];
|
|
1704
|
+
rename.forEach((_ref) => {
|
|
1705
|
+
let [from, to] = _ref;
|
|
1706
|
+
moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
|
|
1707
|
+
overwrite: true
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
console.log("Plugin created successfully!");
|
|
1247
1711
|
};
|
|
1248
1712
|
const buildCommandArguments = [];
|
|
1249
|
-
const $build = new commander.Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).action(build);
|
|
1713
|
+
const $build = new commander.Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).option("-c, --command [string]", i18n.t("desc.build.command")).action(build);
|
|
1250
1714
|
createOnesApp.addCommandUsage($build);
|
|
1251
1715
|
createOnesApp.addCommandOutput($build);
|
|
1252
1716
|
const devCommandArguments = [];
|
|
1253
|
-
const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).action(dev);
|
|
1717
|
+
const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).option("-c, --command [string]", i18n.t("desc.dev.command")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(dev);
|
|
1254
1718
|
createOnesApp.addCommandUsage($dev);
|
|
1255
1719
|
createOnesApp.addCommandOutput($dev);
|
|
1256
1720
|
const tunnelCommandArguments = ["port"];
|
|
1257
|
-
const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).action(tunnel);
|
|
1721
|
+
const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(tunnel);
|
|
1258
1722
|
createOnesApp.addCommandUsage($tunnel);
|
|
1259
1723
|
createOnesApp.addCommandOutput($tunnel);
|
|
1260
1724
|
const loginCommandArguments = ["baseURL"];
|
|
@@ -1289,12 +1753,20 @@ const $app = new commander.Command("app").description(i18n.t("desc.app"));
|
|
|
1289
1753
|
$app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
|
|
1290
1754
|
createOnesApp.addCommandUsage($app);
|
|
1291
1755
|
createOnesApp.addCommandOutput($app);
|
|
1292
|
-
const legacyCommandArguments = [];
|
|
1293
|
-
const $
|
|
1756
|
+
const legacyCommandArguments = ["projectPath"];
|
|
1757
|
+
const $create = new commander.Command("create").description(i18n.t("desc.legacy.create")).argument("<project-path>", i18n.t("desc.legacy.create.projectPath")).action(legacy);
|
|
1758
|
+
createOnesApp.addCommandUsage($create);
|
|
1759
|
+
createOnesApp.addCommandOutput($create);
|
|
1760
|
+
const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"));
|
|
1761
|
+
$legacy.addCommand($create);
|
|
1294
1762
|
createOnesApp.addCommandUsage($legacy);
|
|
1295
1763
|
createOnesApp.addCommandOutput($legacy);
|
|
1296
1764
|
const ones = new commander.Command("ones");
|
|
1297
|
-
|
|
1765
|
+
const version = `${getPackageJSON().version}`;
|
|
1766
|
+
const env = `${version} Node/${process.version}`;
|
|
1767
|
+
ones.description(i18n.t("desc.ones", {
|
|
1768
|
+
env
|
|
1769
|
+
})).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
|
|
1298
1770
|
visibleCommands: (cmd) => {
|
|
1299
1771
|
const blackList = ["legacy"];
|
|
1300
1772
|
return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
|
|
@@ -1307,8 +1779,8 @@ createOnesApp.addCommandOutput(ones);
|
|
|
1307
1779
|
const runCommandONES = async () => {
|
|
1308
1780
|
const command = ones;
|
|
1309
1781
|
createOnesApp.setContext("command", command);
|
|
1310
|
-
const
|
|
1311
|
-
command.version(version);
|
|
1782
|
+
const version2 = `${getPackageJSON().version}`;
|
|
1783
|
+
command.version(version2, "-v, --version");
|
|
1312
1784
|
await command.parse();
|
|
1313
1785
|
};
|
|
1314
1786
|
exports.runCommandONES = runCommandONES;
|