zcatalyst-cli 1.17.5 → 1.18.0-beta.0
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/docs/commands/functions/shell.toml +4 -0
- package/docs/endpoints/lib/env.toml +3 -0
- package/docs/shell/dependencies/tunnel-server.toml +4 -0
- package/docs/shell/index.toml +7 -0
- package/lib/appsail-utils.js +7 -1
- package/lib/commands/functions/shell.js +97 -1
- package/lib/commands/serve.js +1 -1
- package/lib/endpoints/index.js +8 -1
- package/lib/endpoints/lib/env.js +20 -2
- package/lib/endpoints/lib/sdk.js +2 -2
- package/lib/endpoints/lib/tunnel.js +66 -0
- package/lib/internal/api.js +5 -0
- package/lib/port-resolver.js +1 -1
- package/lib/repl-server.js +9 -0
- package/lib/serve/server/lib/master.js +18 -9
- package/lib/serve/server/lib/python/index.js +3 -0
- package/lib/shell/dependencies/http-functions.js +21 -8
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +28 -32
- package/lib/shell/dependencies/invoker/bio/node.mjs +2 -2
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +62 -13
- package/lib/shell/dependencies/invoker/cron/node.mjs +28 -24
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +40 -6
- package/lib/shell/dependencies/invoker/event/node.mjs +22 -9
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +3 -3
- package/lib/shell/dependencies/invoker/integ/node.mjs +6 -6
- package/lib/shell/dependencies/local-function.js +290 -199
- package/lib/shell/dependencies/tunnel-server.js +173 -0
- package/lib/shell/index.js +55 -1
- package/lib/util_modules/constants/index.js +3 -1
- package/lib/util_modules/constants/lib/needed-scopes.js +52 -0
- package/lib/util_modules/constants/lib/scopes.js +5 -0
- package/lib/util_modules/constants/lib/urls.js +8 -0
- package/package.json +3 -3
package/docs/shell/index.toml
CHANGED
|
@@ -2,3 +2,10 @@
|
|
|
2
2
|
context = '''No valid functions to Serve!'''
|
|
3
3
|
aid = '''Please rectify the above errors, if any and try once again.'''
|
|
4
4
|
link = 'https://www.zoho.com/catalyst/help/cli-functions.html#Shell'
|
|
5
|
+
|
|
6
|
+
[SHELL-IDX-2]
|
|
7
|
+
context = '''Cannot enable Tunneling from ZCatalyst CLI.
|
|
8
|
+
Reason: ${arg[0]}
|
|
9
|
+
Error Code: ${arg[1]}'''
|
|
10
|
+
aid = '''Please rectify the above errors and try once again.'''
|
|
11
|
+
link = 'https://www.zoho.com/catalyst/help/cli-functions.html#Shell'
|
package/lib/appsail-utils.js
CHANGED
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateAppSail = exports.filterTargets = void 0;
|
|
6
|
+
exports.getDomainPrefix = exports.validateAppSail = exports.filterTargets = void 0;
|
|
7
7
|
const ansi_colors_1 = require("ansi-colors");
|
|
8
8
|
const error_1 = __importDefault(require("./error"));
|
|
9
9
|
const constants_1 = require("./util_modules/constants");
|
|
10
10
|
const logger_1 = require("./util_modules/logger");
|
|
11
11
|
const option_1 = require("./util_modules/option");
|
|
12
|
+
const project_1 = require("./util_modules/project");
|
|
12
13
|
function getAppSailFilters(targetStr) {
|
|
13
14
|
return targetStr.split(',').reduce((filterArr, target) => {
|
|
14
15
|
const opts = target.split(':');
|
|
@@ -82,3 +83,8 @@ function validateAppSail(targDetails) {
|
|
|
82
83
|
return targDetails;
|
|
83
84
|
}
|
|
84
85
|
exports.validateAppSail = validateAppSail;
|
|
86
|
+
function getDomainPrefix(targetDetail) {
|
|
87
|
+
var _a;
|
|
88
|
+
return `${(_a = targetDetail.appSail) === null || _a === void 0 ? void 0 : _a.name}-${(0, project_1.getDomainKey)()}.development`;
|
|
89
|
+
}
|
|
90
|
+
exports.getDomainPrefix = getDomainPrefix;
|
|
@@ -35,22 +35,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
39
|
+
const endpoints_1 = require("../../endpoints");
|
|
40
|
+
const error_1 = __importDefault(require("../../error"));
|
|
38
41
|
const command_1 = __importDefault(require("../../internal/command"));
|
|
42
|
+
const prompt_1 = __importDefault(require("../../prompt"));
|
|
39
43
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
40
44
|
const constants_1 = require("../../util_modules/constants");
|
|
45
|
+
const logger_1 = require("../../util_modules/logger");
|
|
41
46
|
const option_1 = require("../../util_modules/option");
|
|
47
|
+
const project_1 = require("../../util_modules/project");
|
|
42
48
|
exports.default = new command_1.default('functions:shell')
|
|
43
49
|
.description('Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions')
|
|
44
50
|
.option('--http [port]', 'enables http mode for the basicIO functions and start server at specified port' +
|
|
45
51
|
`(default: ${constants_1.DEFAULT.serve_port.http.basicio})`)
|
|
46
52
|
.option('--debug [port]', 'the functions are invoked from local environment enabling debugging options on provided port.' +
|
|
47
53
|
`(default: ${constants_1.DEFAULT.serve_port.debug.basicio})`)
|
|
54
|
+
.option('--tunnel <port>', 'start tunneling functions at the specified port')
|
|
55
|
+
.option('--enable-tunnel [tunnel-url]', 'enable tunneling for this particular command execution')
|
|
48
56
|
.option('--ignore-scripts', 'ignore the pre and post lifecycle scripts')
|
|
49
57
|
.option('--watch', 'watch for file and directory changes and enable hot reload' +
|
|
50
58
|
'\n' +
|
|
51
59
|
'(deprecated: The watch mode will be enabled by default. To disable watch mode use the --no-watch option)')
|
|
52
60
|
.option('--no-watch', 'disable watching the files for changes')
|
|
53
|
-
.needs('auth',
|
|
61
|
+
.needs('auth', constants_1.NEEDED_SCOPES.SERVE)
|
|
54
62
|
.needs('config')
|
|
55
63
|
.needs('rc')
|
|
56
64
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -62,5 +70,93 @@ exports.default = new command_1.default('functions:shell')
|
|
|
62
70
|
if (debugOpt && typeof debugOpt !== 'boolean') {
|
|
63
71
|
runtime_store_1.default.set('context.port.debug.bio', debugOpt);
|
|
64
72
|
}
|
|
73
|
+
const tunnelOpt = (0, option_1.getOptionValue)('tunnel', false);
|
|
74
|
+
if (tunnelOpt && typeof tunnelOpt !== 'boolean') {
|
|
75
|
+
runtime_store_1.default.set('context.port.tunnel', tunnelOpt);
|
|
76
|
+
}
|
|
77
|
+
const enableTunnelOpt = (0, option_1.getOptionValue)('enableTunnel', false);
|
|
78
|
+
if (!tunnelOpt && enableTunnelOpt) {
|
|
79
|
+
throw new error_1.default('Invalid Command. Use --enable-tunnel option with the -—tunnel option.', { exit: 1 });
|
|
80
|
+
}
|
|
81
|
+
if (enableTunnelOpt) {
|
|
82
|
+
const _tunnelAPI = yield (0, endpoints_1.tunnelAPI)();
|
|
83
|
+
const tunnelDetails = yield _tunnelAPI.getTunnel().catch((er) => {
|
|
84
|
+
const _er = error_1.default.getErrorInstance(er);
|
|
85
|
+
if (_er.status === 404) {
|
|
86
|
+
throw new error_1.default('Tunneling not configured', {
|
|
87
|
+
exit: 1,
|
|
88
|
+
errorId: 'FSHELL-1',
|
|
89
|
+
arg: [
|
|
90
|
+
(0, ansi_colors_1.bold)(`${(0, project_1.getProjectName)()}(${(0, project_1.getProjectId)()})`),
|
|
91
|
+
ansi_colors_1.italic.underline(`${constants_1.ORIGIN.console}/baas/${(0, project_1.getEnvId)()}/project/${(0, project_1.getProjectId)()}/Development#/settings/project/tunneling`)
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
throw _er;
|
|
96
|
+
});
|
|
97
|
+
if (tunnelDetails.tunnel_status === 'Disabled') {
|
|
98
|
+
runtime_store_1.default.set('context.fn_shell.enable_tunnel', enableTunnelOpt);
|
|
99
|
+
(0, logger_1.info)();
|
|
100
|
+
(0, logger_1.info)((0, ansi_colors_1.yellow)('Tunneling will be disabled at the end of this command execution'));
|
|
101
|
+
(0, logger_1.info)();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
(0, logger_1.info)();
|
|
105
|
+
(0, logger_1.info)(`Tunneling is already enabled for the project ${(0, ansi_colors_1.bold)((0, project_1.getProjectName)())}(${(0, project_1.getProjectId)()}) with the configurations below:`);
|
|
106
|
+
(0, logger_1.info)();
|
|
107
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)('Tunneling URL: ') + ansi_colors_1.italic.underline(tunnelDetails.tunnel_url));
|
|
108
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)('Tunneled functions: '));
|
|
109
|
+
tunnelDetails.function_details.forEach((fn) => {
|
|
110
|
+
(0, logger_1.info)('* ' + fn.name);
|
|
111
|
+
});
|
|
112
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)('Enabled by: ') + (0, ansi_colors_1.italic)(tunnelDetails.created_by.email_id));
|
|
113
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)('Enabled on: ') + tunnelDetails.enabled_time);
|
|
114
|
+
(0, logger_1.info)();
|
|
115
|
+
if (typeof enableTunnelOpt === 'boolean') {
|
|
116
|
+
const continueAsIs = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to continue ?', {
|
|
117
|
+
type: 'list',
|
|
118
|
+
choices: [
|
|
119
|
+
prompt_1.default.choice('continue', { value: true, short: 'continue' }),
|
|
120
|
+
prompt_1.default.choice('abort', { value: false, short: 'aborted' })
|
|
121
|
+
]
|
|
122
|
+
}));
|
|
123
|
+
if (continueAsIs.consent === false) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
(0, logger_1.info)();
|
|
127
|
+
(0, logger_1.info)('Ignoring `--enable-tunnel` option since tunneling is already enabled');
|
|
128
|
+
(0, logger_1.info)();
|
|
129
|
+
}
|
|
130
|
+
else if (enableTunnelOpt !== tunnelDetails.tunnel_url) {
|
|
131
|
+
(0, logger_1.info)('Tunneling has already been enabled with a different tunneling URL.');
|
|
132
|
+
(0, logger_1.info)('Do you wish to update the tunnel request with the tunneling URL entered in the --enable-tunnel option?');
|
|
133
|
+
(0, logger_1.info)();
|
|
134
|
+
(0, logger_1.info)((0, ansi_colors_1.red)('- ' + tunnelDetails.tunnel_url));
|
|
135
|
+
(0, logger_1.info)((0, ansi_colors_1.green)('+ ' + enableTunnelOpt));
|
|
136
|
+
(0, logger_1.info)();
|
|
137
|
+
const updateCont = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to update and continue', {
|
|
138
|
+
type: 'list',
|
|
139
|
+
choices: [
|
|
140
|
+
prompt_1.default.choice('continue', { value: true, short: 'continue' }),
|
|
141
|
+
prompt_1.default.choice('abort', { value: false, short: 'aborted' })
|
|
142
|
+
]
|
|
143
|
+
}));
|
|
144
|
+
if (updateCont.consent === false) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
yield (yield (0, endpoints_1.tunnelAPI)()).disableTunnel();
|
|
148
|
+
runtime_store_1.default.set('context.fn_shell.enable_tunnel', enableTunnelOpt);
|
|
149
|
+
(0, logger_1.info)();
|
|
150
|
+
(0, logger_1.info)((0, ansi_colors_1.yellow)('Tunneling will be disabled at the end of this command execution'));
|
|
151
|
+
(0, logger_1.info)();
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
(0, logger_1.info)();
|
|
155
|
+
(0, logger_1.info)('Ignoring `--enable-tunnel` option since a tunnel already exists with the same tunnel url provided: ' +
|
|
156
|
+
ansi_colors_1.italic.underline(enableTunnelOpt));
|
|
157
|
+
(0, logger_1.info)();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
65
161
|
return (yield Promise.resolve().then(() => __importStar(require('../../shell')))).default();
|
|
66
162
|
}));
|
package/lib/commands/serve.js
CHANGED
|
@@ -49,7 +49,7 @@ exports.default = new command_1.default('serve')
|
|
|
49
49
|
.option('--except <targets>', 'serve all targets except specified (e.g. "client")')
|
|
50
50
|
.option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
|
|
51
51
|
.option('--no-open', 'disable opening the client automatically when served')
|
|
52
|
-
.needs('auth',
|
|
52
|
+
.needs('auth', constants_1.NEEDED_SCOPES.SERVE)
|
|
53
53
|
.needs('config')
|
|
54
54
|
.needs('rc')
|
|
55
55
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
package/lib/endpoints/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.commonAPI = exports.codeDeck = exports.gitHubAPI = exports.appSailAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
|
|
35
|
+
exports.tunnelAPI = exports.commonAPI = exports.codeDeck = exports.gitHubAPI = exports.appSailAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
|
|
36
36
|
const project_1 = require("../util_modules/project");
|
|
37
37
|
function orgAPI({ auth = true } = {}) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -177,3 +177,10 @@ function commonAPI() {
|
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
179
|
exports.commonAPI = commonAPI;
|
|
180
|
+
function tunnelAPI({ auth = true, projectId = (0, project_1.getProjectId)() } = {}) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const tunnel = (yield Promise.resolve().then(() => __importStar(require('./lib/tunnel')))).default;
|
|
183
|
+
return new tunnel(projectId, { authNeeded: auth });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
exports.tunnelAPI = tunnelAPI;
|
package/lib/endpoints/lib/env.js
CHANGED
|
@@ -12,19 +12,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
15
16
|
const error_1 = __importDefault(require("../../error"));
|
|
16
17
|
const api_1 = __importDefault(require("../../internal/api"));
|
|
18
|
+
const constants_1 = require("../../util_modules/constants");
|
|
17
19
|
const logger_1 = require("../../util_modules/logger");
|
|
18
20
|
class Env {
|
|
19
21
|
constructor(opts, org) {
|
|
20
22
|
this.opts = opts;
|
|
21
23
|
this.opts.envId = org;
|
|
22
24
|
}
|
|
23
|
-
getEnvs(projectId) {
|
|
25
|
+
getEnvs(projectId, throwErr = true) {
|
|
24
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
27
|
const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId + '/environment');
|
|
26
28
|
if (res.body && res.body.data) {
|
|
27
|
-
|
|
29
|
+
const data = res.body.data;
|
|
30
|
+
if (throwErr) {
|
|
31
|
+
const devEnv = data.find((env) => env.env_name === constants_1.DEFAULT.env_name);
|
|
32
|
+
if ((devEnv === null || devEnv === void 0 ? void 0 : devEnv.env_status) === 'Blocked') {
|
|
33
|
+
throw new error_1.default('Environment blocked', {
|
|
34
|
+
exit: 1,
|
|
35
|
+
errorId: 'ENV-1',
|
|
36
|
+
arg: [
|
|
37
|
+
(0, ansi_colors_1.bold)(constants_1.DEFAULT.env_name),
|
|
38
|
+
(0, ansi_colors_1.bold)(projectId),
|
|
39
|
+
ansi_colors_1.bold.red('blocked'),
|
|
40
|
+
ansi_colors_1.italic.underline('support@zohocatalyst.com')
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return data;
|
|
28
46
|
}
|
|
29
47
|
(0, logger_1.debug)('get environment response from server : ' + JSON.stringify(res.body));
|
|
30
48
|
throw new error_1.default('Server Error: Unexpected Response from server.', {
|
package/lib/endpoints/lib/sdk.js
CHANGED
|
@@ -29,10 +29,10 @@ class SDK {
|
|
|
29
29
|
if (service === constants_1.INTEG.services.cliq) {
|
|
30
30
|
return `/downloads/sdk/java/${constants_1.INTEG.service_map[service]}/${constants_1.INTEG.java_dependencies[service]}_latest.zip`;
|
|
31
31
|
}
|
|
32
|
-
return '/downloads/sdk/java/
|
|
32
|
+
return '/downloads/sdk/java/catalyst_java_sdk_beta.zip';
|
|
33
33
|
}
|
|
34
34
|
default: {
|
|
35
|
-
return '/downloads/sdk/java/
|
|
35
|
+
return '/downloads/sdk/java/catalyst_java_sdk_beta.zip';
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const error_1 = __importDefault(require("../../error"));
|
|
16
|
+
const api_1 = __importDefault(require("../../internal/api"));
|
|
17
|
+
const logger_1 = require("../../util_modules/logger");
|
|
18
|
+
class TunnelAPI {
|
|
19
|
+
constructor(projectId, opts) {
|
|
20
|
+
this.projectId = projectId;
|
|
21
|
+
this.opts = opts;
|
|
22
|
+
}
|
|
23
|
+
getTunnel() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/tunneling`);
|
|
26
|
+
if (res.body && res.body.data) {
|
|
27
|
+
return res.body.data;
|
|
28
|
+
}
|
|
29
|
+
(0, logger_1.debug)('get tunnel response from server : ' + res.body);
|
|
30
|
+
throw new error_1.default('Server Error: Unexpected Response from server.', {
|
|
31
|
+
exit: 2
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
enableTunnel(tunnelUrl) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const qs = {};
|
|
38
|
+
if (tunnelUrl) {
|
|
39
|
+
qs.tunnel_url = tunnelUrl;
|
|
40
|
+
}
|
|
41
|
+
const res = yield new api_1.default(this.opts).patch(`/baas/v1/project/${this.projectId}/tunneling`, {
|
|
42
|
+
qs
|
|
43
|
+
});
|
|
44
|
+
if (res.body && res.body.data) {
|
|
45
|
+
return res.body.data;
|
|
46
|
+
}
|
|
47
|
+
(0, logger_1.debug)('enable tunnel response from server : ' + res.body);
|
|
48
|
+
throw new error_1.default('Server Error: Unexpected Response from server.', {
|
|
49
|
+
exit: 2
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
disableTunnel() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const res = yield new api_1.default(this.opts).patch(`/baas/v1/project/${this.projectId}/tunneling`);
|
|
56
|
+
if (res.body && res.body.data) {
|
|
57
|
+
return res.body.data;
|
|
58
|
+
}
|
|
59
|
+
(0, logger_1.debug)('disable tunnel response from server : ' + res.body);
|
|
60
|
+
throw new error_1.default('Server Error: Unexpected Response from server.', {
|
|
61
|
+
exit: 2
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.default = TunnelAPI;
|
package/lib/internal/api.js
CHANGED
package/lib/port-resolver.js
CHANGED
|
@@ -33,7 +33,7 @@ const featureRef = {
|
|
|
33
33
|
browserlogic: 'browser_logic'
|
|
34
34
|
};
|
|
35
35
|
class PortResolver {
|
|
36
|
-
static getFreePort(startPort, searchSpan, dupCheck) {
|
|
36
|
+
static getFreePort(startPort, searchSpan = 0, dupCheck = false) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
if (searchSpan < 0) {
|
|
39
39
|
throw new Error('unable to find port. searchSpan has reached the bottom line');
|
package/lib/repl-server.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const repl_1 = require("repl");
|
|
7
7
|
const util_1 = require("util");
|
|
8
8
|
const error_1 = __importDefault(require("./error"));
|
|
9
|
+
const logger_1 = require("./util_modules/logger");
|
|
9
10
|
const stdin = process.stdin;
|
|
10
11
|
const ASCII_ETX_CODE = 0x03;
|
|
11
12
|
class Repl {
|
|
@@ -108,5 +109,13 @@ class Repl {
|
|
|
108
109
|
});
|
|
109
110
|
});
|
|
110
111
|
}
|
|
112
|
+
write(str = '') {
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
if (((_a = this.server) === null || _a === void 0 ? void 0 : _a.getCursorPos().cols) !== this.prompt.length) {
|
|
115
|
+
(_b = this.server) === null || _b === void 0 ? void 0 : _b.prompt();
|
|
116
|
+
}
|
|
117
|
+
(0, logger_1.info)(str);
|
|
118
|
+
(_c = this.server) === null || _c === void 0 ? void 0 : _c.prompt();
|
|
119
|
+
}
|
|
111
120
|
}
|
|
112
121
|
exports.default = Repl;
|
|
@@ -32,6 +32,7 @@ const project_2 = require("../../../util_modules/project");
|
|
|
32
32
|
const option_1 = require("../../../util_modules/option");
|
|
33
33
|
const server_js_1 = require("../../../util_modules/server.js");
|
|
34
34
|
const http_proxy_1 = require("http-proxy");
|
|
35
|
+
const appsail_utils_1 = require("../../../appsail-utils");
|
|
35
36
|
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
36
37
|
const redirectByAuth = (req, res, redirectUrl) => {
|
|
37
38
|
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
@@ -92,21 +93,29 @@ const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
|
|
|
92
93
|
}
|
|
93
94
|
};
|
|
94
95
|
function spinUpMaster(listenPort, otherServerDetails) {
|
|
95
|
-
var _a;
|
|
96
|
+
var _a, _b, _c, _d;
|
|
96
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
const projectDetails =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
const projectDetails = ((_b = (_a = otherServerDetails.appSail) === null || _a === void 0 ? void 0 : _a.at(0)) === null || _b === void 0 ? void 0 : _b.target) !== undefined
|
|
99
|
+
? {
|
|
100
|
+
id: (0, project_2.getProjectId)(),
|
|
101
|
+
domain_prefix: (0, appsail_utils_1.getDomainPrefix)((_c = otherServerDetails.appSail.at(0)) === null || _c === void 0 ? void 0 : _c.target),
|
|
102
|
+
domain: constants_1.ORIGIN.appSailDomain.replace('https://', ''),
|
|
103
|
+
key: (0, project_2.getDomainKey)(),
|
|
104
|
+
env_name: (0, project_2.getEnvName)()
|
|
105
|
+
}
|
|
106
|
+
: {
|
|
107
|
+
id: (0, project_2.getProjectId)(),
|
|
108
|
+
domain_prefix: (0, project_2.getDomainPrefix)(),
|
|
109
|
+
domain: constants_1.ORIGIN.app.replace('https://', ''),
|
|
110
|
+
key: (0, project_2.getDomainKey)(),
|
|
111
|
+
env_name: (0, project_2.getEnvName)()
|
|
112
|
+
};
|
|
104
113
|
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
105
114
|
const customProxyUrl = (0, option_1.getOptionValue)('proxy');
|
|
106
115
|
const app = (0, express_1.default)();
|
|
107
116
|
let systemRoutes;
|
|
108
117
|
const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
|
|
109
|
-
app.use((0, logger_1.default)((
|
|
118
|
+
app.use((0, logger_1.default)((_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.at(0)));
|
|
110
119
|
app.use(cookie_parser_1.default);
|
|
111
120
|
app.use((0, project_1.default)(projectDetails));
|
|
112
121
|
app.use(authenticator_1.default);
|
|
@@ -41,7 +41,7 @@ const logUrl = (name, pthName, httpPort, masterPort) => {
|
|
|
41
41
|
};
|
|
42
42
|
const checkIfRuntimeServerRunning = (port, itr = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
if (itr > 50) {
|
|
44
|
-
throw new error_1.default('
|
|
44
|
+
throw new error_1.default('Unable to spin up python runtime server. Max retry reached', {
|
|
45
45
|
exit: 2
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -52,18 +52,31 @@ const checkIfRuntimeServerRunning = (port, itr = 0) => __awaiter(void 0, void 0,
|
|
|
52
52
|
'x-zoho-catalyst-internal': 'true'
|
|
53
53
|
}
|
|
54
54
|
})
|
|
55
|
-
.on('response', (_response) => {
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
.on('response', (_response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
(0, logger_2.debug)(`ruok response: ${_response.statusCode}: ${_response.statusMessage}`);
|
|
57
|
+
if (_response.statusCode === 200) {
|
|
58
|
+
res(true);
|
|
59
|
+
}
|
|
60
|
+
else if (_response.statusCode === 503) {
|
|
61
|
+
yield js_1.JS.sleep(100);
|
|
62
|
+
yield (0, exports.checkIfRuntimeServerRunning)(port, ++itr).then((x) => res(x));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
yield js_1.JS.sleep(500);
|
|
66
|
+
throw new error_1.default('Unable to spin up python runtime server. StatusCode: ' +
|
|
67
|
+
_response.statusCode, {
|
|
68
|
+
exit: 2
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}))
|
|
58
72
|
.on('error', (error) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
incommingError.code === 'ECONNRESET') {
|
|
73
|
+
const incomingError = error_1.default.getErrorInstance(error).original;
|
|
74
|
+
if (incomingError.code === 'ECONNREFUSED' || incomingError.code === 'ECONNRESET') {
|
|
62
75
|
yield js_1.JS.sleep(100);
|
|
63
76
|
yield (0, exports.checkIfRuntimeServerRunning)(port, ++itr).then((x) => res(x));
|
|
64
77
|
}
|
|
65
78
|
else {
|
|
66
|
-
throw new error_1.default('
|
|
79
|
+
throw new error_1.default('Unable to spin up python runtime server. ErrorCode: ' + incomingError.code, {
|
|
67
80
|
exit: 2
|
|
68
81
|
});
|
|
69
82
|
}
|
|
@@ -90,44 +90,48 @@ public class JavabioInvoker {
|
|
|
90
90
|
return map;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
private static void writeResponse(JSONObject responseJson,
|
|
93
|
+
private static void writeResponse(JSONObject responseJson, Integer status, String invokerDir) throws Exception {
|
|
94
|
+
// write response data
|
|
94
95
|
String responseFilePath = Paths.get(invokerDir, "../user_res_body").toString();
|
|
95
|
-
|
|
96
|
+
|
|
96
97
|
BufferedWriter responseWriter = new BufferedWriter(new FileWriter(responseFilePath));
|
|
97
98
|
String responseStr = responseJson.toString();
|
|
98
99
|
responseWriter.write(responseStr);
|
|
99
100
|
responseWriter.close();
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
JSONObject metaResp = ((JSONObject) metaJson.get("response"));
|
|
104
|
-
metaResp.put("Content-Type", "application/json");
|
|
105
|
-
metaResp.put("Content-Length", responseStr.length());
|
|
102
|
+
// write response meta
|
|
103
|
+
String metaFilePath = Paths.get(invokerDir, "../user_meta.json").toString();
|
|
106
104
|
|
|
107
|
-
metaWriter
|
|
105
|
+
BufferedWriter metaWriter = new BufferedWriter(new FileWriter(metaFilePath));
|
|
106
|
+
JSONObject metaJson = new JSONObject();
|
|
107
|
+
metaJson.put("statusCode", status);
|
|
108
|
+
metaJson.put("Content-Type", "application/json");
|
|
109
|
+
metaJson.put("Content-Length", responseStr.length());
|
|
110
|
+
metaWriter.write(new JSONObject().put("response", metaJson).toString());
|
|
108
111
|
metaWriter.close();
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
private static void throwAndExit(Exception err, int exitCode, String invokerDir) {
|
|
112
115
|
try {
|
|
113
116
|
String sStackTrace = getStackTraceAsString(err); // stack trace as a string
|
|
114
|
-
if (exitCode
|
|
115
|
-
|
|
117
|
+
if (exitCode == 532) {
|
|
118
|
+
writeResponse(new JSONObject() {
|
|
116
119
|
{
|
|
117
120
|
put("error", sStackTrace);
|
|
118
121
|
}
|
|
119
|
-
};
|
|
120
|
-
|
|
122
|
+
}, exitCode, invokerDir);
|
|
123
|
+
} else if (exitCode == 500) {
|
|
124
|
+
writeResponse(new JSONObject() {
|
|
121
125
|
{
|
|
122
|
-
put("
|
|
123
|
-
{
|
|
124
|
-
put("statusCode", 500);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
126
|
+
put("error", sStackTrace);
|
|
127
127
|
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
writeResponse(
|
|
128
|
+
}, 500, invokerDir);
|
|
129
|
+
} else if (exitCode == 408) {
|
|
130
|
+
writeResponse(new JSONObject() {
|
|
131
|
+
{
|
|
132
|
+
put("error", sStackTrace);
|
|
133
|
+
}
|
|
134
|
+
}, exitCode, invokerDir);
|
|
131
135
|
}
|
|
132
136
|
System.out.println(sStackTrace);
|
|
133
137
|
} catch (Exception e) {
|
|
@@ -267,7 +271,7 @@ public class JavabioInvoker {
|
|
|
267
271
|
try {
|
|
268
272
|
runner.invoke(cls.getDeclaredConstructor().newInstance(), context, basicIO);
|
|
269
273
|
} catch (Exception e) {
|
|
270
|
-
throwAndExit(e,
|
|
274
|
+
throwAndExit(e, 532, invokerDir);
|
|
271
275
|
}
|
|
272
276
|
|
|
273
277
|
JSONObject responseJson = new JSONObject() {
|
|
@@ -275,19 +279,11 @@ public class JavabioInvoker {
|
|
|
275
279
|
put("output", defaultBasic.getBuilder().toString());
|
|
276
280
|
}
|
|
277
281
|
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
put("response", new JSONObject() {
|
|
281
|
-
{
|
|
282
|
-
put("statusCode", defaultBasic.getStatus() == null ? 200 : defaultBasic.getStatus());
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
writeResponse(responseJson, metaJson, invokerDir);
|
|
282
|
+
|
|
283
|
+
writeResponse(responseJson, defaultBasic.getStatus() == null ? 200 : defaultBasic.getStatus(), invokerDir);
|
|
288
284
|
System.exit(0);
|
|
289
285
|
} catch (Exception e) {
|
|
290
|
-
throwAndExit(e,
|
|
286
|
+
throwAndExit(e, 500, invokerDir);
|
|
291
287
|
}
|
|
292
288
|
}
|
|
293
289
|
}
|
|
@@ -113,7 +113,7 @@ import(pathToFileURL(target.index))
|
|
|
113
113
|
},
|
|
114
114
|
{ response: { statusCode: 500 } }
|
|
115
115
|
);
|
|
116
|
-
process.exit(
|
|
116
|
+
process.exit(0);
|
|
117
117
|
}
|
|
118
118
|
})
|
|
119
119
|
.catch((e) => {
|
|
@@ -123,5 +123,5 @@ import(pathToFileURL(target.index))
|
|
|
123
123
|
error: util.inspect(e),
|
|
124
124
|
response: { statusCode: 500 }
|
|
125
125
|
});
|
|
126
|
-
process.exit(
|
|
126
|
+
process.exit(0);
|
|
127
127
|
});
|