@ones-open/cli 1.0.1-5596.1908 → 1.0.1-6440.1942
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 +461 -434
- package/dist/index.js +462 -435
- package/dist/types/actions/build/index.d.ts.map +1 -1
- package/dist/types/actions/dev/index.d.ts.map +1 -1
- package/dist/types/actions/tunnel/index.d.ts +1 -1
- package/dist/types/actions/tunnel/index.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 +7 -2
- package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
- package/dist/types/cli/index.d.ts.map +1 -1
- package/dist/types/common/locales/en/index.d.ts +28 -28
- package/dist/types/common/request/types.d.ts +8 -5
- package/dist/types/common/request/types.d.ts.map +1 -1
- package/package.json +3 -3
- 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.js
CHANGED
|
@@ -5,51 +5,50 @@ import { dirname, join, resolve, basename } from "node:path";
|
|
|
5
5
|
import { spawnSync, spawn } from "node:child_process";
|
|
6
6
|
import { readFileSync, createWriteStream } from "node:fs";
|
|
7
7
|
import archiver from "archiver";
|
|
8
|
-
import { get,
|
|
8
|
+
import { get, merge, noop } from "lodash-es";
|
|
9
9
|
import process$1, { cwd, exit } from "node:process";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { cosmiconfig } from "cosmiconfig";
|
|
12
12
|
import fse from "fs-extra";
|
|
13
13
|
import envPaths from "env-paths";
|
|
14
14
|
import { z } from "zod";
|
|
15
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
16
|
-
import WebSocket from "ws";
|
|
17
15
|
import axios from "axios";
|
|
18
16
|
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
17
|
+
import WebSocket from "ws";
|
|
19
18
|
import http from "node:http";
|
|
20
19
|
import ora from "ora";
|
|
21
20
|
import open from "open";
|
|
22
21
|
import getPort from "get-port";
|
|
23
22
|
import { v4 } from "uuid";
|
|
24
23
|
const en = {
|
|
25
|
-
"desc.ones": "
|
|
26
|
-
"desc.build": "
|
|
27
|
-
"desc.build.output": "
|
|
28
|
-
"desc.dev": "
|
|
29
|
-
"desc.dev.install": "
|
|
30
|
-
"desc.tunnel": "
|
|
31
|
-
"desc.tunnel.port": "
|
|
32
|
-
"desc.login": "
|
|
33
|
-
"desc.login.baseUrl": "
|
|
34
|
-
"desc.logout": "
|
|
35
|
-
"desc.whoami": "
|
|
36
|
-
"desc.app": "app
|
|
37
|
-
"desc.install": "
|
|
38
|
-
"desc.enable": "
|
|
39
|
-
"desc.disable": "
|
|
40
|
-
"desc.uninstall": "
|
|
41
|
-
"desc.legacy": "
|
|
42
|
-
"error.login.missingBaseURL": "
|
|
43
|
-
"error.login.incorrectBaseURL": "
|
|
44
|
-
"error.tunnel.missingPort": "
|
|
45
|
-
"error.tunnel.incorrectPort": "
|
|
46
|
-
"error.schema.app.package.parseError": "
|
|
47
|
-
"error.schema.app.manifest.parseError": "
|
|
48
|
-
"error.build.scriptNotFound": "build script not found
|
|
49
|
-
"error.dev.scriptNotFound": "dev script not found
|
|
50
|
-
"error.store.permission": '
|
|
51
|
-
"error.hostedToken.requestFailed": "
|
|
52
|
-
"error.hostedToken.empty": "
|
|
24
|
+
"desc.ones": "ONES CLI/{env}",
|
|
25
|
+
"desc.build": "Build your ONES App",
|
|
26
|
+
"desc.build.output": "Specify the output file path",
|
|
27
|
+
"desc.dev": "Start your local development server and connect to ONES",
|
|
28
|
+
"desc.dev.install": "Install your ONES App after the server is ready",
|
|
29
|
+
"desc.tunnel": "Start a tunnel to connect your local server with ONES",
|
|
30
|
+
"desc.tunnel.port": "Specify the port number for tunnel",
|
|
31
|
+
"desc.login": "Log in to your ONES account",
|
|
32
|
+
"desc.login.baseUrl": "Specify the ONES URL for login",
|
|
33
|
+
"desc.logout": "Log out of your ONES account",
|
|
34
|
+
"desc.whoami": "Display the account information of the logged in user",
|
|
35
|
+
"desc.app": "Manage app installations",
|
|
36
|
+
"desc.install": "Install your ONES App",
|
|
37
|
+
"desc.enable": "Enable your ONES App",
|
|
38
|
+
"desc.disable": "Disable your ONES App",
|
|
39
|
+
"desc.uninstall": "Uninstall your ONES App",
|
|
40
|
+
"desc.legacy": "Legacy command",
|
|
41
|
+
"error.login.missingBaseURL": "Missing base URL",
|
|
42
|
+
"error.login.incorrectBaseURL": "Incorrect base URL",
|
|
43
|
+
"error.tunnel.missingPort": "Missing port",
|
|
44
|
+
"error.tunnel.incorrectPort": "Incorrect port",
|
|
45
|
+
"error.schema.app.package.parseError": "App package JSON parse error",
|
|
46
|
+
"error.schema.app.manifest.parseError": 'App "opkx.json" JSON parse error',
|
|
47
|
+
"error.build.scriptNotFound": 'Npm "build" script not found',
|
|
48
|
+
"error.dev.scriptNotFound": 'Npm "dev" script not found',
|
|
49
|
+
"error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
|
|
50
|
+
"error.hostedToken.requestFailed": "Failed to request hosted token",
|
|
51
|
+
"error.hostedToken.empty": "Hosted token is empty"
|
|
53
52
|
};
|
|
54
53
|
const map = {
|
|
55
54
|
en
|
|
@@ -130,8 +129,8 @@ const getAppPackageJSON = () => {
|
|
|
130
129
|
const json = JSON.parse(string);
|
|
131
130
|
return AppPackageJSONSchema.parse(json);
|
|
132
131
|
} catch (error) {
|
|
133
|
-
|
|
134
|
-
return throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, i18n.t("error.schema.app.package.parseError"));
|
|
132
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
133
|
+
return throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.package.parseError")}: ${details}`);
|
|
135
134
|
}
|
|
136
135
|
};
|
|
137
136
|
const getAppManifestJSONPath = () => {
|
|
@@ -146,8 +145,8 @@ const getAppManifestJSON = () => {
|
|
|
146
145
|
const json = JSON.parse(string);
|
|
147
146
|
return AppManifestJSONSchema.parse(json);
|
|
148
147
|
} catch (error) {
|
|
149
|
-
|
|
150
|
-
return throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, i18n.t("error.schema.app.manifest.parseError"));
|
|
148
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
149
|
+
return throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
151
150
|
}
|
|
152
151
|
};
|
|
153
152
|
const defaultAppRcJSON = {
|
|
@@ -219,7 +218,11 @@ const build = async function() {
|
|
|
219
218
|
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build) {
|
|
220
219
|
spawnSync("npm", ["run", "build"], {
|
|
221
220
|
cwd: getAppWorkspacePath(),
|
|
222
|
-
stdio: "inherit"
|
|
221
|
+
stdio: "inherit",
|
|
222
|
+
env: {
|
|
223
|
+
...process.env,
|
|
224
|
+
NODE_ENV: "production"
|
|
225
|
+
}
|
|
223
226
|
});
|
|
224
227
|
} else {
|
|
225
228
|
return throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
|
|
@@ -269,109 +272,6 @@ const config = {
|
|
|
269
272
|
}
|
|
270
273
|
};
|
|
271
274
|
const getConfig = () => config;
|
|
272
|
-
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
273
|
-
InstallOptions2["AUTO"] = "auto";
|
|
274
|
-
InstallOptions2["TRUE"] = "true";
|
|
275
|
-
InstallOptions2["FALSE"] = "false";
|
|
276
|
-
return InstallOptions2;
|
|
277
|
-
})(InstallOptions || {});
|
|
278
|
-
const defaultInstall = InstallOptions.AUTO;
|
|
279
|
-
const normalize$9 = async (options) => {
|
|
280
|
-
var _options$install;
|
|
281
|
-
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
282
|
-
switch (true) {
|
|
283
|
-
case install2 === InstallOptions.AUTO:
|
|
284
|
-
break;
|
|
285
|
-
case Boolean(install2):
|
|
286
|
-
install2 = InstallOptions.TRUE;
|
|
287
|
-
break;
|
|
288
|
-
default:
|
|
289
|
-
install2 = InstallOptions.FALSE;
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
install: install2
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
const dev = async function() {
|
|
297
|
-
var _appPackageJSON$scrip;
|
|
298
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
299
|
-
args[_key] = arguments[_key];
|
|
300
|
-
}
|
|
301
|
-
const {
|
|
302
|
-
options
|
|
303
|
-
} = getCommandOptions(args, devCommandArguments);
|
|
304
|
-
const normalizedOptions = await normalize$9(options);
|
|
305
|
-
const appPackageJSON = getAppPackageJSON();
|
|
306
|
-
const appManifestJSON = getAppManifestJSON();
|
|
307
|
-
const appRcJSON = getAppRcJSON();
|
|
308
|
-
noop(appManifestJSON);
|
|
309
|
-
noop(appRcJSON);
|
|
310
|
-
if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
|
|
311
|
-
return throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
312
|
-
}
|
|
313
|
-
const port = getConfig().defaultPort.tunnel;
|
|
314
|
-
const cwd2 = getAppWorkspacePath();
|
|
315
|
-
const env = {
|
|
316
|
-
...process.env,
|
|
317
|
-
ONES_HOSTED_PORT: `${port}`
|
|
318
|
-
};
|
|
319
|
-
const tunnelChild = spawn("ones", ["tunnel", String(port)], {
|
|
320
|
-
cwd: cwd2,
|
|
321
|
-
stdio: "inherit"
|
|
322
|
-
});
|
|
323
|
-
const devChild = spawn("npm", ["run", "dev"], {
|
|
324
|
-
cwd: cwd2,
|
|
325
|
-
stdio: "inherit",
|
|
326
|
-
env
|
|
327
|
-
});
|
|
328
|
-
const cleanup = () => {
|
|
329
|
-
tunnelChild.kill();
|
|
330
|
-
devChild.kill();
|
|
331
|
-
};
|
|
332
|
-
const onSignal = () => {
|
|
333
|
-
cleanup();
|
|
334
|
-
process.exit(128 + 2);
|
|
335
|
-
};
|
|
336
|
-
process.on("SIGINT", onSignal);
|
|
337
|
-
process.on("SIGTERM", onSignal);
|
|
338
|
-
if (normalizedOptions.install) {
|
|
339
|
-
noop(normalizedOptions.install);
|
|
340
|
-
}
|
|
341
|
-
await new Promise((resolve2) => {
|
|
342
|
-
devChild.on("exit", () => {
|
|
343
|
-
cleanup();
|
|
344
|
-
process.off("SIGINT", onSignal);
|
|
345
|
-
process.off("SIGTERM", onSignal);
|
|
346
|
-
resolve2();
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
351
|
-
const minPortNumber = 1;
|
|
352
|
-
const maxPortNumber = 65535;
|
|
353
|
-
const normalize$8 = async (options) => {
|
|
354
|
-
const portInput = options.port;
|
|
355
|
-
if (portInput)
|
|
356
|
-
;
|
|
357
|
-
else {
|
|
358
|
-
return throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
359
|
-
}
|
|
360
|
-
const portString = String(portInput);
|
|
361
|
-
const portNumber = Number(portString);
|
|
362
|
-
if (isPortNumber.test(portString))
|
|
363
|
-
;
|
|
364
|
-
else {
|
|
365
|
-
return throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
366
|
-
}
|
|
367
|
-
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
368
|
-
return throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
369
|
-
}
|
|
370
|
-
const port = portString;
|
|
371
|
-
return {
|
|
372
|
-
port
|
|
373
|
-
};
|
|
374
|
-
};
|
|
375
275
|
const StoreJSONSchema = z.object({
|
|
376
276
|
version: z.string().optional(),
|
|
377
277
|
timestamp: z.number().optional(),
|
|
@@ -417,11 +317,11 @@ const getStore = async () => {
|
|
|
417
317
|
const setStore = async (store) => {
|
|
418
318
|
try {
|
|
419
319
|
await ensureFile(storePath);
|
|
420
|
-
const
|
|
320
|
+
const version2 = `${getPackageJSON().version}`;
|
|
421
321
|
const timestamp = Date.now();
|
|
422
322
|
return await writeJSON(storePath, {
|
|
423
323
|
...store,
|
|
424
|
-
version,
|
|
324
|
+
version: version2,
|
|
425
325
|
timestamp
|
|
426
326
|
}, {
|
|
427
327
|
encoding: "utf8"
|
|
@@ -473,61 +373,234 @@ const setONESToken = async (token) => {
|
|
|
473
373
|
ones_token: token
|
|
474
374
|
});
|
|
475
375
|
};
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
});
|
|
376
|
+
const getHostToken = async () => {
|
|
377
|
+
var _store$host_token;
|
|
378
|
+
const store = await getStore();
|
|
379
|
+
return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
|
|
380
|
+
};
|
|
381
|
+
const API = {
|
|
382
|
+
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
383
|
+
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
384
|
+
APP_LIST: "/platform/api/app/list",
|
|
385
|
+
APP_INSTALL: "/platform/api/app/install",
|
|
386
|
+
APP_UPGRADE: "/platform/api/app/upgrade",
|
|
387
|
+
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
388
|
+
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
389
|
+
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
390
|
+
};
|
|
391
|
+
const getPath = (path, map2) => {
|
|
392
|
+
var _context;
|
|
393
|
+
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
394
|
+
if (/^:/.test(part)) {
|
|
395
|
+
return `${base}/${map2[part.slice(1)]}`;
|
|
396
|
+
}
|
|
397
|
+
return `${base}/${part}`;
|
|
398
|
+
}, "").slice(1);
|
|
399
|
+
};
|
|
400
|
+
const consoleUnauthorizedMessage = () => {
|
|
401
|
+
console.log("Not logged in");
|
|
402
|
+
console.log('Login with "ones login" command');
|
|
403
|
+
};
|
|
404
|
+
const getURL = async (path, pathMap, queryMap) => {
|
|
405
|
+
const base = await getRegionURL();
|
|
406
|
+
if (base) {
|
|
407
|
+
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
408
|
+
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
510
409
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
410
|
+
consoleUnauthorizedMessage();
|
|
411
|
+
exit(1);
|
|
412
|
+
};
|
|
413
|
+
const getHeaders = async (value) => {
|
|
414
|
+
const token = await getONESToken();
|
|
415
|
+
if (token) {
|
|
416
|
+
return merge({
|
|
417
|
+
Authorization: `Bearer ${token}`
|
|
418
|
+
}, value);
|
|
514
419
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
420
|
+
consoleUnauthorizedMessage();
|
|
421
|
+
exit(1);
|
|
422
|
+
};
|
|
423
|
+
const handleError = (error) => {
|
|
424
|
+
var _error$response;
|
|
425
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
426
|
+
console.log(error.response.statusText);
|
|
427
|
+
consoleUnauthorizedMessage();
|
|
428
|
+
} else {
|
|
429
|
+
console.error(error);
|
|
520
430
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
431
|
+
return {};
|
|
432
|
+
};
|
|
433
|
+
const fetchAppBase = async (params) => {
|
|
434
|
+
var _params$url;
|
|
435
|
+
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
436
|
+
const headers = await getHeaders(params.headers);
|
|
437
|
+
const response = await axios({
|
|
438
|
+
...params,
|
|
439
|
+
url,
|
|
440
|
+
headers
|
|
441
|
+
});
|
|
442
|
+
return response.data;
|
|
443
|
+
};
|
|
444
|
+
const fetchAppList = async (appID) => {
|
|
445
|
+
return await fetchAppBase({
|
|
446
|
+
url: API.APP_LIST,
|
|
447
|
+
method: "GET",
|
|
448
|
+
queryMap: {
|
|
449
|
+
app_id: appID
|
|
525
450
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
451
|
+
}).catch(handleError);
|
|
452
|
+
};
|
|
453
|
+
const fetchTokenInfo = async () => {
|
|
454
|
+
return await fetchAppBase({
|
|
455
|
+
url: API.TOKEN_INFO,
|
|
456
|
+
method: "GET"
|
|
457
|
+
}).catch(handleError);
|
|
458
|
+
};
|
|
459
|
+
const fetchHostedToken = async (data) => {
|
|
460
|
+
return await fetchAppBase({
|
|
461
|
+
url: API.HOSTED_TOKEN,
|
|
462
|
+
method: "POST",
|
|
463
|
+
data
|
|
464
|
+
}).catch(handleError);
|
|
465
|
+
};
|
|
466
|
+
const fetchAppInstall = async (data) => {
|
|
467
|
+
var _appList$data$0$insta, _appList$data;
|
|
468
|
+
const appID = getAppManifestJSON().app.id;
|
|
469
|
+
const appList = await fetchAppList(appID);
|
|
470
|
+
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 : "";
|
|
471
|
+
const url = installationID ? API.APP_UPGRADE : API.APP_INSTALL;
|
|
472
|
+
return await fetchAppBase({
|
|
473
|
+
url,
|
|
474
|
+
method: "POST",
|
|
475
|
+
data
|
|
476
|
+
}).catch(handleError);
|
|
477
|
+
};
|
|
478
|
+
const fetchAppUninstall = async () => {
|
|
479
|
+
var _appList$data$0$insta2, _appList$data2;
|
|
480
|
+
const appID = getAppManifestJSON().app.id;
|
|
481
|
+
const appList = await fetchAppList(appID);
|
|
482
|
+
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 : "";
|
|
483
|
+
return await fetchAppBase({
|
|
484
|
+
url: API.APP_UNINSTALL,
|
|
485
|
+
method: "POST",
|
|
486
|
+
pathMap: {
|
|
487
|
+
installation_id: installationID
|
|
488
|
+
}
|
|
489
|
+
}).catch(handleError);
|
|
490
|
+
};
|
|
491
|
+
const fetchAppEnable = async () => {
|
|
492
|
+
var _appList$data$0$insta3, _appList$data3;
|
|
493
|
+
const appID = getAppManifestJSON().app.id;
|
|
494
|
+
const appList = await fetchAppList(appID);
|
|
495
|
+
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 : "";
|
|
496
|
+
return await fetchAppBase({
|
|
497
|
+
url: API.APP_ENABLE,
|
|
498
|
+
method: "POST",
|
|
499
|
+
pathMap: {
|
|
500
|
+
installation_id: installationID
|
|
501
|
+
}
|
|
502
|
+
}).catch(handleError);
|
|
503
|
+
};
|
|
504
|
+
const fetchAppDisable = async () => {
|
|
505
|
+
var _appList$data$0$insta4, _appList$data4;
|
|
506
|
+
const appID = getAppManifestJSON().app.id;
|
|
507
|
+
const appList = await fetchAppList(appID);
|
|
508
|
+
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 : "";
|
|
509
|
+
return await fetchAppBase({
|
|
510
|
+
url: API.APP_DISABLE,
|
|
511
|
+
method: "POST",
|
|
512
|
+
pathMap: {
|
|
513
|
+
installation_id: installationID
|
|
514
|
+
}
|
|
515
|
+
}).catch(handleError);
|
|
516
|
+
};
|
|
517
|
+
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
518
|
+
const minPortNumber = 1;
|
|
519
|
+
const maxPortNumber = 65535;
|
|
520
|
+
const normalize$9 = async (options) => {
|
|
521
|
+
const portInput = options.port;
|
|
522
|
+
if (portInput)
|
|
523
|
+
;
|
|
524
|
+
else {
|
|
525
|
+
return throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
526
|
+
}
|
|
527
|
+
const portString = String(portInput);
|
|
528
|
+
const portNumber = Number(portString);
|
|
529
|
+
if (isPortNumber.test(portString))
|
|
530
|
+
;
|
|
531
|
+
else {
|
|
532
|
+
return throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
533
|
+
}
|
|
534
|
+
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
535
|
+
return throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
536
|
+
}
|
|
537
|
+
const port = portString;
|
|
538
|
+
return {
|
|
539
|
+
port
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
|
|
543
|
+
class TunnelClient {
|
|
544
|
+
constructor(localPort, baseUrl, appID, hostedToken) {
|
|
545
|
+
let enableInternalManifestRoute = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
546
|
+
let replaceExisting = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
|
|
547
|
+
this.ws = null;
|
|
548
|
+
this.localPort = localPort;
|
|
549
|
+
this.baseUrl = baseUrl;
|
|
550
|
+
this.appID = appID;
|
|
551
|
+
this.hostedToken = hostedToken;
|
|
552
|
+
this.enableInternalManifestRoute = enableInternalManifestRoute;
|
|
553
|
+
this.replaceExisting = replaceExisting;
|
|
554
|
+
}
|
|
555
|
+
async connect() {
|
|
556
|
+
const proxyUrl = this.buildProxyUrl();
|
|
557
|
+
this.ws = new WebSocket(proxyUrl, {
|
|
558
|
+
headers: {
|
|
559
|
+
Authorization: `Bearer ${this.hostedToken}`
|
|
560
|
+
},
|
|
561
|
+
maxPayload: MAX_RELAY_BODY_BYTES
|
|
562
|
+
});
|
|
563
|
+
this.ws.on("message", async (data) => {
|
|
564
|
+
const message = this.parseMessage(data);
|
|
565
|
+
if (!message) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
await this.handleMessage(message);
|
|
569
|
+
});
|
|
570
|
+
this.ws.on("ping", (data) => {
|
|
571
|
+
var _this$ws;
|
|
572
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.pong(data);
|
|
573
|
+
});
|
|
574
|
+
this.ws.on("error", (error) => {
|
|
575
|
+
console.error("WebSocket error:", error);
|
|
576
|
+
});
|
|
577
|
+
return new Promise((resolve2, reject) => {
|
|
578
|
+
var _this$ws2, _this$ws3;
|
|
579
|
+
(_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.on("open", () => resolve2());
|
|
580
|
+
(_this$ws3 = this.ws) === null || _this$ws3 === void 0 || _this$ws3.on("error", reject);
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
close() {
|
|
584
|
+
var _this$ws4;
|
|
585
|
+
(_this$ws4 = this.ws) === null || _this$ws4 === void 0 || _this$ws4.close();
|
|
586
|
+
}
|
|
587
|
+
buildProxyUrl() {
|
|
588
|
+
const url = new URL("/platform/app/relay/", this.baseUrl);
|
|
589
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
590
|
+
url.searchParams.set("app_id", this.appID);
|
|
591
|
+
url.searchParams.set("replace_existing", String(this.replaceExisting));
|
|
592
|
+
return url.toString();
|
|
593
|
+
}
|
|
594
|
+
parseMessage(data) {
|
|
595
|
+
const buffer = this.toBuffer(data);
|
|
596
|
+
if (!buffer) {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
if (buffer.length >= 4) {
|
|
600
|
+
const binary = this.parseBinaryEnvelope(buffer);
|
|
601
|
+
if (binary) {
|
|
602
|
+
return binary;
|
|
603
|
+
}
|
|
531
604
|
}
|
|
532
605
|
return this.parseJSONEnvelope(buffer.toString());
|
|
533
606
|
}
|
|
@@ -536,7 +609,7 @@ class TunnelClient {
|
|
|
536
609
|
if (!request) {
|
|
537
610
|
return;
|
|
538
611
|
}
|
|
539
|
-
if (request.path ===
|
|
612
|
+
if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
|
|
540
613
|
const appManifest = getAppManifestJSON().app;
|
|
541
614
|
const baseURL = await buildTunnelUrl();
|
|
542
615
|
const reply = {
|
|
@@ -588,7 +661,13 @@ class TunnelClient {
|
|
|
588
661
|
if (payload.query) {
|
|
589
662
|
Object.entries(payload.query).forEach((_ref) => {
|
|
590
663
|
let [key, value] = _ref;
|
|
591
|
-
|
|
664
|
+
if (Array.isArray(value)) {
|
|
665
|
+
value.forEach((item) => {
|
|
666
|
+
url.searchParams.append(key, item);
|
|
667
|
+
});
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
url.searchParams.append(key, value);
|
|
592
671
|
});
|
|
593
672
|
}
|
|
594
673
|
const response = await axios.request({
|
|
@@ -597,7 +676,9 @@ class TunnelClient {
|
|
|
597
676
|
headers: payload.headers,
|
|
598
677
|
data: payload.body,
|
|
599
678
|
responseType: "arraybuffer",
|
|
600
|
-
validateStatus: () => true
|
|
679
|
+
validateStatus: () => true,
|
|
680
|
+
maxBodyLength: MAX_RELAY_BODY_BYTES,
|
|
681
|
+
maxContentLength: MAX_RELAY_BODY_BYTES
|
|
601
682
|
});
|
|
602
683
|
const responseBytes = Buffer.from(response.data);
|
|
603
684
|
return {
|
|
@@ -629,6 +710,9 @@ class TunnelClient {
|
|
|
629
710
|
var _envelope$payload;
|
|
630
711
|
const payload = (_envelope$payload = envelope.payload) !== null && _envelope$payload !== void 0 ? _envelope$payload : {};
|
|
631
712
|
const body = this.toBodyBuffer(payload.body);
|
|
713
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
714
|
+
throw new Error("relay body too large");
|
|
715
|
+
}
|
|
632
716
|
const metaPayload = {
|
|
633
717
|
...payload
|
|
634
718
|
};
|
|
@@ -671,7 +755,12 @@ class TunnelClient {
|
|
|
671
755
|
return envelope;
|
|
672
756
|
}
|
|
673
757
|
const body = buffer.subarray(4 + metaLength);
|
|
674
|
-
|
|
758
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
759
|
+
console.error("Binary tunnel body exceeds size limit");
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
const payload = envelope.payload;
|
|
763
|
+
payload.body = body;
|
|
675
764
|
return envelope;
|
|
676
765
|
} catch (error) {
|
|
677
766
|
console.error("Invalid binary tunnel message:", error);
|
|
@@ -703,60 +792,23 @@ class TunnelClient {
|
|
|
703
792
|
return null;
|
|
704
793
|
}
|
|
705
794
|
}
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}, "").slice(1);
|
|
714
|
-
};
|
|
715
|
-
const consoleUnauthorizedMessage = () => {
|
|
716
|
-
console.log("Not logged in");
|
|
717
|
-
console.log('Login with "ones login" command');
|
|
718
|
-
};
|
|
719
|
-
const getURL = async (path, pathMap, queryMap) => {
|
|
720
|
-
const base = await getRegionURL();
|
|
721
|
-
if (base) {
|
|
722
|
-
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
723
|
-
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
724
|
-
}
|
|
725
|
-
consoleUnauthorizedMessage();
|
|
726
|
-
exit(1);
|
|
727
|
-
};
|
|
728
|
-
const getHeaders = async (value) => {
|
|
729
|
-
const token = await getONESToken();
|
|
730
|
-
if (token) {
|
|
731
|
-
return merge({
|
|
732
|
-
Authorization: `Bearer ${token}`
|
|
733
|
-
}, value);
|
|
795
|
+
const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
|
|
796
|
+
const buildTunnelContext = async () => {
|
|
797
|
+
var _appManifestJSON$app$, _appManifestJSON$app;
|
|
798
|
+
const appManifestJSON = getAppManifestJSON();
|
|
799
|
+
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$ : "";
|
|
800
|
+
if (!appID) {
|
|
801
|
+
throw new Error("app id is empty");
|
|
734
802
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
const handleError = (error) => {
|
|
739
|
-
var _error$response;
|
|
740
|
-
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
741
|
-
console.log(error.response.statusText);
|
|
742
|
-
consoleUnauthorizedMessage();
|
|
743
|
-
} else {
|
|
744
|
-
console.error(error);
|
|
803
|
+
const regionURL = await getRegionURL();
|
|
804
|
+
if (!regionURL) {
|
|
805
|
+
throw new Error("region url is empty");
|
|
745
806
|
}
|
|
746
|
-
return {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
APP_LIST: "/platform/api/app/list",
|
|
752
|
-
APP_INSTALL: "/platform/api/app/install",
|
|
753
|
-
APP_UPGRADE: "/platform/api/app/upgrade",
|
|
754
|
-
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
755
|
-
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
756
|
-
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
757
|
-
};
|
|
758
|
-
const isRecord = (value) => {
|
|
759
|
-
return typeof value === "object" && value !== null;
|
|
807
|
+
return {
|
|
808
|
+
appManifestJSON,
|
|
809
|
+
appID,
|
|
810
|
+
regionURL
|
|
811
|
+
};
|
|
760
812
|
};
|
|
761
813
|
const getHostedTokenScopes = (ones2) => {
|
|
762
814
|
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
@@ -775,131 +827,6 @@ const getHostedTokenScopes = (ones2) => {
|
|
|
775
827
|
const getRelayScope = () => {
|
|
776
828
|
return HostedTokenScope.RELAY;
|
|
777
829
|
};
|
|
778
|
-
const getHostToken = async (baseUrl, userToken, appID, scopes) => {
|
|
779
|
-
const url = `${baseUrl.replace(/\/$/, "")}${API.HOSTED_TOKEN}`;
|
|
780
|
-
return axios.post(url, {
|
|
781
|
-
app_id: appID,
|
|
782
|
-
scopes
|
|
783
|
-
}, {
|
|
784
|
-
headers: {
|
|
785
|
-
Authorization: `Bearer ${userToken}`
|
|
786
|
-
}
|
|
787
|
-
}).then((resp) => {
|
|
788
|
-
const data = resp === null || resp === void 0 ? void 0 : resp.data;
|
|
789
|
-
const tokenFromData = (value) => {
|
|
790
|
-
if (isRecord(value) && isRecord(value.data)) {
|
|
791
|
-
const hosted_token = value.data.hosted_token;
|
|
792
|
-
if (typeof hosted_token === "string" && hosted_token.length > 0) {
|
|
793
|
-
return hosted_token;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
return null;
|
|
797
|
-
};
|
|
798
|
-
const token = tokenFromData(data);
|
|
799
|
-
if (token) {
|
|
800
|
-
return token;
|
|
801
|
-
}
|
|
802
|
-
return throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
803
|
-
}).catch((error) => {
|
|
804
|
-
handleError(error);
|
|
805
|
-
return throwError(ErrorCode.HOSTED_TOKEN_REQUEST_FAILED, i18n.t("error.hostedToken.requestFailed"));
|
|
806
|
-
});
|
|
807
|
-
};
|
|
808
|
-
const fetchAppBase = async (params) => {
|
|
809
|
-
var _params$url;
|
|
810
|
-
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
811
|
-
const headers = await getHeaders(params.headers);
|
|
812
|
-
const response = await axios({
|
|
813
|
-
...params,
|
|
814
|
-
url,
|
|
815
|
-
headers
|
|
816
|
-
});
|
|
817
|
-
return response.data;
|
|
818
|
-
};
|
|
819
|
-
const fetchAppList = async (appID) => {
|
|
820
|
-
return await fetchAppBase({
|
|
821
|
-
url: API.APP_LIST,
|
|
822
|
-
method: "GET",
|
|
823
|
-
queryMap: {
|
|
824
|
-
app_id: appID
|
|
825
|
-
}
|
|
826
|
-
}).catch(handleError);
|
|
827
|
-
};
|
|
828
|
-
const fetchTokenInfo = async () => {
|
|
829
|
-
return await fetchAppBase({
|
|
830
|
-
url: API.TOKEN_INFO,
|
|
831
|
-
method: "GET"
|
|
832
|
-
}).catch(handleError);
|
|
833
|
-
};
|
|
834
|
-
const fetchAppInstall = async (data) => {
|
|
835
|
-
var _appList$data$0$insta, _appList$data;
|
|
836
|
-
const appID = getAppManifestJSON().app.id;
|
|
837
|
-
const appList = await fetchAppList(appID);
|
|
838
|
-
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 : "";
|
|
839
|
-
const url = installationID ? API.APP_UPGRADE : API.APP_INSTALL;
|
|
840
|
-
return await fetchAppBase({
|
|
841
|
-
url,
|
|
842
|
-
method: "POST",
|
|
843
|
-
data
|
|
844
|
-
}).catch(handleError);
|
|
845
|
-
};
|
|
846
|
-
const fetchAppUninstall = async () => {
|
|
847
|
-
var _appList$data$0$insta2, _appList$data2;
|
|
848
|
-
const appID = getAppManifestJSON().app.id;
|
|
849
|
-
const appList = await fetchAppList(appID);
|
|
850
|
-
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 : "";
|
|
851
|
-
return await fetchAppBase({
|
|
852
|
-
url: API.APP_UNINSTALL,
|
|
853
|
-
method: "POST",
|
|
854
|
-
pathMap: {
|
|
855
|
-
installation_id: installationID
|
|
856
|
-
}
|
|
857
|
-
}).catch(handleError);
|
|
858
|
-
};
|
|
859
|
-
const fetchAppEnable = async () => {
|
|
860
|
-
var _appList$data$0$insta3, _appList$data3;
|
|
861
|
-
const appID = getAppManifestJSON().app.id;
|
|
862
|
-
const appList = await fetchAppList(appID);
|
|
863
|
-
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 : "";
|
|
864
|
-
return await fetchAppBase({
|
|
865
|
-
url: API.APP_ENABLE,
|
|
866
|
-
method: "POST",
|
|
867
|
-
pathMap: {
|
|
868
|
-
installation_id: installationID
|
|
869
|
-
}
|
|
870
|
-
}).catch(handleError);
|
|
871
|
-
};
|
|
872
|
-
const fetchAppDisable = async () => {
|
|
873
|
-
var _appList$data$0$insta4, _appList$data4;
|
|
874
|
-
const appID = getAppManifestJSON().app.id;
|
|
875
|
-
const appList = await fetchAppList(appID);
|
|
876
|
-
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 : "";
|
|
877
|
-
return await fetchAppBase({
|
|
878
|
-
url: API.APP_DISABLE,
|
|
879
|
-
method: "POST",
|
|
880
|
-
pathMap: {
|
|
881
|
-
installation_id: installationID
|
|
882
|
-
}
|
|
883
|
-
}).catch(handleError);
|
|
884
|
-
};
|
|
885
|
-
const ONES_CLI_MANIFEST_PATH = "/__ones_cli_manifest__";
|
|
886
|
-
const buildTunnelContext = async () => {
|
|
887
|
-
var _appManifestJSON$app$, _appManifestJSON$app;
|
|
888
|
-
const appManifestJSON = getAppManifestJSON();
|
|
889
|
-
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$ : "";
|
|
890
|
-
if (!appID) {
|
|
891
|
-
throw new Error("app id is empty");
|
|
892
|
-
}
|
|
893
|
-
const regionURL = await getRegionURL();
|
|
894
|
-
if (!regionURL) {
|
|
895
|
-
throw new Error("region url is empty");
|
|
896
|
-
}
|
|
897
|
-
return {
|
|
898
|
-
appManifestJSON,
|
|
899
|
-
appID,
|
|
900
|
-
regionURL
|
|
901
|
-
};
|
|
902
|
-
};
|
|
903
830
|
const buildTunnelUrl = async () => {
|
|
904
831
|
const {
|
|
905
832
|
appID,
|
|
@@ -908,12 +835,16 @@ const buildTunnelUrl = async () => {
|
|
|
908
835
|
const url = new URL(regionURL);
|
|
909
836
|
return `${url.protocol}//${url.host}/platform/app/relay/dispatch/${appID}`;
|
|
910
837
|
};
|
|
911
|
-
const invokeTunnel = async (port)
|
|
838
|
+
const invokeTunnel = async function(port) {
|
|
839
|
+
var _options$rebuildWhenE, _hostedTokenResponse$, _options$enableIntern;
|
|
840
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
912
841
|
const {
|
|
913
842
|
appManifestJSON,
|
|
914
843
|
appID,
|
|
915
844
|
regionURL
|
|
916
845
|
} = await buildTunnelContext();
|
|
846
|
+
const runnelUrl = await buildTunnelUrl();
|
|
847
|
+
const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
|
|
917
848
|
const onesToken = await getONESToken();
|
|
918
849
|
if (!onesToken) {
|
|
919
850
|
consoleUnauthorizedMessage();
|
|
@@ -921,11 +852,17 @@ const invokeTunnel = async (port) => {
|
|
|
921
852
|
}
|
|
922
853
|
const storageScopes = getHostedTokenScopes(appManifestJSON.ones);
|
|
923
854
|
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
924
|
-
const
|
|
855
|
+
const hostedTokenResponse = await fetchHostedToken({
|
|
856
|
+
app_id: appID,
|
|
857
|
+
scopes
|
|
858
|
+
});
|
|
859
|
+
const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
|
|
860
|
+
if (!hostedToken) {
|
|
861
|
+
return throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
862
|
+
}
|
|
925
863
|
process.env.ONES_HOSTED_TOKEN = hostedToken;
|
|
926
|
-
const client = new TunnelClient(port, regionURL, appID, hostedToken);
|
|
864
|
+
const client = new TunnelClient(port, regionURL, appID, hostedToken, (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true, rebuildWhenExists);
|
|
927
865
|
await client.connect();
|
|
928
|
-
const runnelUrl = await buildTunnelUrl();
|
|
929
866
|
console.log(`Relay endpoint: ${runnelUrl}`);
|
|
930
867
|
};
|
|
931
868
|
const tunnel = async function() {
|
|
@@ -935,9 +872,143 @@ const tunnel = async function() {
|
|
|
935
872
|
const {
|
|
936
873
|
options
|
|
937
874
|
} = getCommandOptions(args, tunnelCommandArguments);
|
|
938
|
-
const normalizedOptions = await normalize$
|
|
875
|
+
const normalizedOptions = await normalize$9(options);
|
|
939
876
|
await invokeTunnel(Number(normalizedOptions.port));
|
|
940
877
|
};
|
|
878
|
+
const normalize$8 = async (options) => {
|
|
879
|
+
noop(options);
|
|
880
|
+
return {};
|
|
881
|
+
};
|
|
882
|
+
const invokeInstall = async () => {
|
|
883
|
+
const runnelUrl = await buildTunnelUrl();
|
|
884
|
+
const result = await fetchAppInstall({
|
|
885
|
+
manifest_url: `${runnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`
|
|
886
|
+
});
|
|
887
|
+
return result;
|
|
888
|
+
};
|
|
889
|
+
const install = async function() {
|
|
890
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
891
|
+
args[_key] = arguments[_key];
|
|
892
|
+
}
|
|
893
|
+
const {
|
|
894
|
+
options
|
|
895
|
+
} = getCommandOptions(args, installCommandArguments);
|
|
896
|
+
const normalizedOptions = await normalize$8(options);
|
|
897
|
+
noop(normalizedOptions);
|
|
898
|
+
await invokeTunnel(getConfig().defaultPort.tunnel);
|
|
899
|
+
const result = await invokeInstall();
|
|
900
|
+
if (result.code === "OK") {
|
|
901
|
+
var _appList$data$0$insta, _appList$data;
|
|
902
|
+
console.log("App installed successfully!");
|
|
903
|
+
const appID = getAppManifestJSON().app.id;
|
|
904
|
+
const appList = await fetchAppList(appID);
|
|
905
|
+
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 : "";
|
|
906
|
+
if (installationID) {
|
|
907
|
+
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
908
|
+
const tokenInfo = await fetchTokenInfo();
|
|
909
|
+
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 : "";
|
|
910
|
+
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 : "";
|
|
911
|
+
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;
|
|
912
|
+
const baseURL = await getBaseURL();
|
|
913
|
+
if (isOrgVisible && orgUUID) {
|
|
914
|
+
const url = `${baseURL}/project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
915
|
+
console.log(`See App detail: ${url}`);
|
|
916
|
+
}
|
|
917
|
+
if (!isOrgVisible && teamUUID) {
|
|
918
|
+
const url = `${baseURL}/project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
919
|
+
console.log(`See App detail: ${url}`);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
} else {
|
|
923
|
+
console.error(result);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
927
|
+
InstallOptions2["AUTO"] = "auto";
|
|
928
|
+
InstallOptions2["TRUE"] = "true";
|
|
929
|
+
InstallOptions2["FALSE"] = "false";
|
|
930
|
+
return InstallOptions2;
|
|
931
|
+
})(InstallOptions || {});
|
|
932
|
+
const defaultInstall = InstallOptions.AUTO;
|
|
933
|
+
const normalize$7 = async (options) => {
|
|
934
|
+
var _options$install;
|
|
935
|
+
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
936
|
+
switch (true) {
|
|
937
|
+
case install2 === InstallOptions.AUTO:
|
|
938
|
+
break;
|
|
939
|
+
case Boolean(install2):
|
|
940
|
+
install2 = InstallOptions.TRUE;
|
|
941
|
+
break;
|
|
942
|
+
default:
|
|
943
|
+
install2 = InstallOptions.FALSE;
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
return {
|
|
947
|
+
install: install2
|
|
948
|
+
};
|
|
949
|
+
};
|
|
950
|
+
const dev = async function() {
|
|
951
|
+
var _appPackageJSON$scrip;
|
|
952
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
953
|
+
args[_key] = arguments[_key];
|
|
954
|
+
}
|
|
955
|
+
const {
|
|
956
|
+
options
|
|
957
|
+
} = getCommandOptions(args, devCommandArguments);
|
|
958
|
+
const normalizedOptions = await normalize$7(options);
|
|
959
|
+
const appPackageJSON = getAppPackageJSON();
|
|
960
|
+
const appManifestJSON = getAppManifestJSON();
|
|
961
|
+
const appRcJSON = getAppRcJSON();
|
|
962
|
+
noop(appManifestJSON);
|
|
963
|
+
noop(appRcJSON);
|
|
964
|
+
if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
|
|
965
|
+
return throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
966
|
+
}
|
|
967
|
+
const ONES_HOSTED_TOKEN = await getHostToken();
|
|
968
|
+
const port = getConfig().defaultPort.tunnel;
|
|
969
|
+
const cwd2 = getAppWorkspacePath();
|
|
970
|
+
const env2 = {
|
|
971
|
+
...process.env,
|
|
972
|
+
NODE_ENV: "development",
|
|
973
|
+
ONES_HOSTED_PORT: `${port}`,
|
|
974
|
+
ONES_HOSTED_TOKEN
|
|
975
|
+
};
|
|
976
|
+
const tunnelChild = spawn("ones", ["tunnel", String(port)], {
|
|
977
|
+
cwd: cwd2,
|
|
978
|
+
stdio: "inherit"
|
|
979
|
+
});
|
|
980
|
+
const devChild = spawn("npm", ["run", "dev"], {
|
|
981
|
+
cwd: cwd2,
|
|
982
|
+
stdio: "inherit",
|
|
983
|
+
env: env2
|
|
984
|
+
});
|
|
985
|
+
const cleanup = () => {
|
|
986
|
+
tunnelChild.kill();
|
|
987
|
+
devChild.kill();
|
|
988
|
+
};
|
|
989
|
+
const onSignal = () => {
|
|
990
|
+
cleanup();
|
|
991
|
+
process.exit(128 + 2);
|
|
992
|
+
};
|
|
993
|
+
process.on("SIGINT", onSignal);
|
|
994
|
+
process.on("SIGTERM", onSignal);
|
|
995
|
+
console.log(`Local: http://localhost:${port}`);
|
|
996
|
+
if (normalizedOptions.install === InstallOptions.TRUE) {
|
|
997
|
+
setTimeout(() => {
|
|
998
|
+
invokeInstall().catch((error) => {
|
|
999
|
+
console.error(error);
|
|
1000
|
+
});
|
|
1001
|
+
}, 2e3);
|
|
1002
|
+
}
|
|
1003
|
+
await new Promise((resolve2) => {
|
|
1004
|
+
devChild.on("exit", () => {
|
|
1005
|
+
cleanup();
|
|
1006
|
+
process.off("SIGINT", onSignal);
|
|
1007
|
+
process.off("SIGTERM", onSignal);
|
|
1008
|
+
resolve2();
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
};
|
|
941
1012
|
function createPromise() {
|
|
942
1013
|
let resolve2;
|
|
943
1014
|
let reject;
|
|
@@ -958,7 +1029,7 @@ const sleep = (number) => {
|
|
|
958
1029
|
};
|
|
959
1030
|
const isURL = /^https?:\/\//;
|
|
960
1031
|
const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
|
|
961
|
-
const normalize$
|
|
1032
|
+
const normalize$6 = async (options) => {
|
|
962
1033
|
const baseURLInput = options.baseURL;
|
|
963
1034
|
if (baseURLInput)
|
|
964
1035
|
;
|
|
@@ -995,7 +1066,7 @@ const login = async function() {
|
|
|
995
1066
|
const {
|
|
996
1067
|
options
|
|
997
1068
|
} = getCommandOptions(args, loginCommandArguments);
|
|
998
|
-
const normalizedOptions = await normalize$
|
|
1069
|
+
const normalizedOptions = await normalize$6(options);
|
|
999
1070
|
const base = normalizedOptions.baseURL;
|
|
1000
1071
|
const path = "project/oauth2.html";
|
|
1001
1072
|
const config2 = getConfig();
|
|
@@ -1079,7 +1150,7 @@ const login = async function() {
|
|
|
1079
1150
|
ora("Waiting for authorization...").start();
|
|
1080
1151
|
await open(url);
|
|
1081
1152
|
};
|
|
1082
|
-
const normalize$
|
|
1153
|
+
const normalize$5 = async (options) => {
|
|
1083
1154
|
noop(options);
|
|
1084
1155
|
return {};
|
|
1085
1156
|
};
|
|
@@ -1090,12 +1161,12 @@ const logout = async function() {
|
|
|
1090
1161
|
const {
|
|
1091
1162
|
options
|
|
1092
1163
|
} = getCommandOptions(args, logoutCommandArguments);
|
|
1093
|
-
const normalizedOptions = await normalize$
|
|
1164
|
+
const normalizedOptions = await normalize$5(options);
|
|
1094
1165
|
noop(normalizedOptions);
|
|
1095
1166
|
await setStore({});
|
|
1096
1167
|
console.log("Logged out successfully!");
|
|
1097
1168
|
};
|
|
1098
|
-
const normalize$
|
|
1169
|
+
const normalize$4 = async (options) => {
|
|
1099
1170
|
noop(options);
|
|
1100
1171
|
return {};
|
|
1101
1172
|
};
|
|
@@ -1107,7 +1178,7 @@ const whoami = async function() {
|
|
|
1107
1178
|
const {
|
|
1108
1179
|
options
|
|
1109
1180
|
} = getCommandOptions(args, whoamiCommandArguments);
|
|
1110
|
-
const normalizedOptions = await normalize$
|
|
1181
|
+
const normalizedOptions = await normalize$4(options);
|
|
1111
1182
|
noop(normalizedOptions);
|
|
1112
1183
|
const baseURL = await getBaseURL();
|
|
1113
1184
|
const tokenInfo = await fetchTokenInfo();
|
|
@@ -1120,54 +1191,6 @@ const whoami = async function() {
|
|
|
1120
1191
|
consoleUnauthorizedMessage();
|
|
1121
1192
|
}
|
|
1122
1193
|
};
|
|
1123
|
-
const normalize$4 = async (options) => {
|
|
1124
|
-
noop(options);
|
|
1125
|
-
return {};
|
|
1126
|
-
};
|
|
1127
|
-
const invokeInstall = async () => {
|
|
1128
|
-
const runnelUrl = await buildTunnelUrl();
|
|
1129
|
-
const result = await fetchAppInstall({
|
|
1130
|
-
manifest_url: `${runnelUrl}${ONES_CLI_MANIFEST_PATH}`
|
|
1131
|
-
});
|
|
1132
|
-
return result;
|
|
1133
|
-
};
|
|
1134
|
-
const install = async function() {
|
|
1135
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1136
|
-
args[_key] = arguments[_key];
|
|
1137
|
-
}
|
|
1138
|
-
const {
|
|
1139
|
-
options
|
|
1140
|
-
} = getCommandOptions(args, installCommandArguments);
|
|
1141
|
-
const normalizedOptions = await normalize$4(options);
|
|
1142
|
-
noop(normalizedOptions);
|
|
1143
|
-
await invokeTunnel(getConfig().defaultPort.tunnel);
|
|
1144
|
-
const result = await invokeInstall();
|
|
1145
|
-
if (result.code === "OK") {
|
|
1146
|
-
var _appList$data$0$insta, _appList$data;
|
|
1147
|
-
console.log("App installed successfully!");
|
|
1148
|
-
const appID = getAppManifestJSON().app.id;
|
|
1149
|
-
const appList = await fetchAppList(appID);
|
|
1150
|
-
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 : "";
|
|
1151
|
-
if (installationID) {
|
|
1152
|
-
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
1153
|
-
const tokenInfo = await fetchTokenInfo();
|
|
1154
|
-
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 : "";
|
|
1155
|
-
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 : "";
|
|
1156
|
-
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;
|
|
1157
|
-
const baseURL = await getBaseURL();
|
|
1158
|
-
if (isOrgVisible && orgUUID) {
|
|
1159
|
-
const url = `${baseURL}/project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
1160
|
-
console.log(`See App detail: ${url}`);
|
|
1161
|
-
}
|
|
1162
|
-
if (!isOrgVisible && teamUUID) {
|
|
1163
|
-
const url = `${baseURL}/project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
1164
|
-
console.log(`See App detail: ${url}`);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
} else {
|
|
1168
|
-
console.error(result);
|
|
1169
|
-
}
|
|
1170
|
-
};
|
|
1171
1194
|
const normalize$3 = async (options) => {
|
|
1172
1195
|
noop(options);
|
|
1173
1196
|
return {};
|
|
@@ -1291,7 +1314,11 @@ const $legacy = new Command("legacy").description(i18n.t("desc.legacy")).action(
|
|
|
1291
1314
|
addCommandUsage($legacy);
|
|
1292
1315
|
addCommandOutput($legacy);
|
|
1293
1316
|
const ones = new Command("ones");
|
|
1294
|
-
|
|
1317
|
+
const version = `${getPackageJSON().version}`;
|
|
1318
|
+
const env = `${version} Node/${process.version}`;
|
|
1319
|
+
ones.description(i18n.t("desc.ones", {
|
|
1320
|
+
env
|
|
1321
|
+
})).addCommand($create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
|
|
1295
1322
|
visibleCommands: (cmd) => {
|
|
1296
1323
|
const blackList = ["legacy"];
|
|
1297
1324
|
return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
|
|
@@ -1304,8 +1331,8 @@ addCommandOutput(ones);
|
|
|
1304
1331
|
const runCommandONES = async () => {
|
|
1305
1332
|
const command = ones;
|
|
1306
1333
|
setContext("command", command);
|
|
1307
|
-
const
|
|
1308
|
-
command.version(version);
|
|
1334
|
+
const version2 = `${getPackageJSON().version}`;
|
|
1335
|
+
command.version(version2, "-v, --version");
|
|
1309
1336
|
await command.parse();
|
|
1310
1337
|
};
|
|
1311
1338
|
export {
|