zcatalyst-cli 1.18.0-beta.2 → 1.18.0-beta.4
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/serve/server/lib/appsail/index.toml +22 -1
- package/lib/endpoints/lib/tunnel.js +18 -0
- package/lib/init/features/appsail/index.js +2 -1
- package/lib/serve/features/appsail.js +1 -1
- package/lib/serve/server/index.js +44 -14
- package/lib/serve/server/lib/appsail/index.js +65 -9
- package/lib/serve/server/lib/appsail/start.js +9 -1
- package/lib/serve/server/lib/master/appsail.js +3 -3
- package/lib/serve/server/lib/master/unknown-req-proxy.js +3 -0
- package/lib/serve/server/lib/master/utils.js +19 -13
- package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +1 -1
- package/lib/shell/dependencies/local-function.js +24 -23
- package/lib/shell/dependencies/tunnel-server.js +52 -23
- package/lib/shell/index.js +22 -28
- package/lib/util_modules/config/lib/appsail.js +5 -1
- package/package.json +2 -1
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
[SERVE-APPSAIL-1]
|
|
2
|
-
context = '''The provided build path
|
|
2
|
+
context = '''The provided build path ${arg[0]} for the AppSail ${arg[1]} does not exists.'''
|
|
3
3
|
aid = '''Please provide a valid build path'''
|
|
4
4
|
link = ''
|
|
5
|
+
|
|
6
|
+
[SERVE-APPSAIL-2]
|
|
7
|
+
context = '''The build path resolved from the provided relative path "${arg[0]}" does not exists.
|
|
8
|
+
Source path : ${arg[1]}
|
|
9
|
+
Build path : ${arg[2]}
|
|
10
|
+
Resolved Path : ${arg[3]}'''
|
|
11
|
+
aid = '''Please provide a valid relative path as build path'''
|
|
12
|
+
link = ''
|
|
13
|
+
|
|
14
|
+
[SERVE-APPSAIL-3]
|
|
15
|
+
context = '''Unable to start the ${arg[0]} AppSail server with the below parameters.
|
|
16
|
+
Command : ${arg[1]}
|
|
17
|
+
Build path : ${arg[2]}
|
|
18
|
+
Runtime : ${arg[3]}'''
|
|
19
|
+
aid = '''Please fix the errors if any'''
|
|
20
|
+
link = ''
|
|
21
|
+
|
|
22
|
+
[SERVE-APPSAIL-4]
|
|
23
|
+
context = '''Invalid AppSail Stack/Runtime for AppSail ${arg[0]}: ${arg[1]}'''
|
|
24
|
+
aid = '''Please use a supported Stack/Runtime from the below list: \n${arg[2]}'''
|
|
25
|
+
link = ''
|
|
@@ -62,5 +62,23 @@ class TunnelAPI {
|
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
+
tunnelCallback(status, details, data) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/tunneling/callback`, {
|
|
68
|
+
body: {
|
|
69
|
+
status,
|
|
70
|
+
content: Object.assign({}, details),
|
|
71
|
+
data
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (res.status >= 200 && res.status <= 299) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
(0, logger_1.debug)(`tunnel callback response from server ::: status=${res.status} ::: body=${res.body}`);
|
|
78
|
+
throw new error_1.default('Server Error: Unexpected Response from server.', {
|
|
79
|
+
exit: 2
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
65
83
|
}
|
|
66
84
|
exports.default = TunnelAPI;
|
|
@@ -196,7 +196,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
196
196
|
stack: appSailStack.runtime,
|
|
197
197
|
env_variables: {},
|
|
198
198
|
memory: _appSailConfig.memory || 256,
|
|
199
|
-
scripts: _appSailConfig.scripts || {}
|
|
199
|
+
scripts: _appSailConfig.scripts || {},
|
|
200
|
+
raw: {}
|
|
200
201
|
};
|
|
201
202
|
if (appSailStack.lang === 'java') {
|
|
202
203
|
const platform = yield prompt_1.default.ask(prompt_1.default.question('value', 'Please choose a platform for your AppSail: ', {
|
|
@@ -41,7 +41,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
41
41
|
name: targ.name + '_proxy',
|
|
42
42
|
server: 'service'
|
|
43
43
|
});
|
|
44
|
-
return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
|
|
44
|
+
return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort }, trigger: { kill: false } });
|
|
45
45
|
})));
|
|
46
46
|
runtime_store_1.default.set('context.appsail.targets', filledTargets);
|
|
47
47
|
});
|
|
@@ -302,6 +302,11 @@ class Server {
|
|
|
302
302
|
var _a;
|
|
303
303
|
switch (targType) {
|
|
304
304
|
case 'functions': {
|
|
305
|
+
const headersDisplayed = {
|
|
306
|
+
bio: false,
|
|
307
|
+
aio: false,
|
|
308
|
+
blo: false
|
|
309
|
+
};
|
|
305
310
|
Object.entries(logTarg).forEach((x) => {
|
|
306
311
|
const [_targType, _logTarg] = x;
|
|
307
312
|
if (_logTarg.targs.length === 0) {
|
|
@@ -310,48 +315,66 @@ class Server {
|
|
|
310
315
|
loggedEntries++;
|
|
311
316
|
switch (_targType) {
|
|
312
317
|
case 'bio': {
|
|
313
|
-
(0, logger_1.info)();
|
|
314
|
-
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> BasicIO <<<<<<<<<<<<<< '));
|
|
315
318
|
_logTarg.targs.forEach((t) => {
|
|
316
|
-
var _a;
|
|
319
|
+
var _a, _b;
|
|
317
320
|
const target = t;
|
|
318
|
-
if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.
|
|
321
|
+
if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (!((_b = target.target) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
319
325
|
throw new error_1.default('Target URL not found', {
|
|
320
326
|
exit: 2
|
|
321
327
|
});
|
|
322
328
|
}
|
|
329
|
+
if (headersDisplayed.bio === false) {
|
|
330
|
+
(0, logger_1.info)();
|
|
331
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> BasicIO <<<<<<<<<<<<<< '));
|
|
332
|
+
headersDisplayed.bio = true;
|
|
333
|
+
}
|
|
323
334
|
bioLogUrl(target, masterPort, _logTarg.nameMaxLength);
|
|
324
335
|
});
|
|
325
336
|
(0, logger_1.info)();
|
|
326
337
|
break;
|
|
327
338
|
}
|
|
328
339
|
case 'aio': {
|
|
329
|
-
(0, logger_1.info)();
|
|
330
|
-
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>> AdvancedIO <<<<<<<<<<<< '));
|
|
331
340
|
_logTarg.targs.forEach((t) => {
|
|
332
|
-
var _a;
|
|
341
|
+
var _a, _b;
|
|
333
342
|
const _target = t;
|
|
334
|
-
if (!((_a = _target.target) === null || _a === void 0 ? void 0 : _a.
|
|
343
|
+
if (!((_a = _target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (!((_b = _target.target) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
335
347
|
throw new error_1.default('Target URL not found', {
|
|
336
348
|
exit: 2
|
|
337
349
|
});
|
|
338
350
|
}
|
|
351
|
+
if (headersDisplayed.aio === false) {
|
|
352
|
+
(0, logger_1.info)();
|
|
353
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>> AdvancedIO <<<<<<<<<<<< '));
|
|
354
|
+
headersDisplayed.aio = true;
|
|
355
|
+
}
|
|
339
356
|
aioLogUrl(_target, masterPort, _logTarg.nameMaxLength);
|
|
340
357
|
});
|
|
341
358
|
(0, logger_1.info)();
|
|
342
359
|
break;
|
|
343
360
|
}
|
|
344
361
|
case 'browserlogic': {
|
|
345
|
-
(0, logger_1.info)();
|
|
346
|
-
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>> BrowserLogic <<<<<<<<<<< '));
|
|
347
362
|
_logTarg.targs.forEach((t) => {
|
|
348
|
-
var _a;
|
|
363
|
+
var _a, _b;
|
|
349
364
|
const target = t;
|
|
350
|
-
if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.
|
|
365
|
+
if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (!((_b = target.target) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
351
369
|
throw new error_1.default('Target URL not found', {
|
|
352
370
|
exit: 2
|
|
353
371
|
});
|
|
354
372
|
}
|
|
373
|
+
if (headersDisplayed.blo === false) {
|
|
374
|
+
(0, logger_1.info)();
|
|
375
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>> BrowserLogic <<<<<<<<<<< '));
|
|
376
|
+
headersDisplayed.blo = true;
|
|
377
|
+
}
|
|
355
378
|
bioLogUrl(target, masterPort, _logTarg.nameMaxLength);
|
|
356
379
|
});
|
|
357
380
|
(0, logger_1.info)();
|
|
@@ -367,10 +390,17 @@ class Server {
|
|
|
367
390
|
return;
|
|
368
391
|
}
|
|
369
392
|
loggedEntries++;
|
|
370
|
-
|
|
371
|
-
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
|
|
393
|
+
let isHeaderDisplayed = false;
|
|
372
394
|
_logTarg.targs.forEach((t) => {
|
|
373
395
|
const targetSail = t.target;
|
|
396
|
+
if (!targetSail.validity.valid) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (isHeaderDisplayed === false) {
|
|
400
|
+
(0, logger_1.info)();
|
|
401
|
+
(0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
|
|
402
|
+
isHeaderDisplayed = true;
|
|
403
|
+
}
|
|
374
404
|
const targName = targetSail.name + '';
|
|
375
405
|
(0, logger_1.labeled)(targName +
|
|
376
406
|
' '.repeat((_logTarg.nameMaxLength || targName.length) - targName.length), `http://localhost:${targetSail.port.proxy}`).MESSAGE();
|
|
@@ -24,6 +24,8 @@ const archiver_1 = __importDefault(require("../../../../archiver"));
|
|
|
24
24
|
const option_1 = require("../../../../util_modules/option");
|
|
25
25
|
const execute_script_1 = require("../../../../execute-script");
|
|
26
26
|
const master_1 = __importDefault(require("../master"));
|
|
27
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
28
|
+
const common_1 = require("../../../../init/util/common");
|
|
27
29
|
function executeHook(script, name, moduleSource) {
|
|
28
30
|
if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
|
|
29
31
|
(0, logger_1.debug)(`skipping ${name} hook`);
|
|
@@ -37,14 +39,18 @@ const startAppSail = (port, opts) => {
|
|
|
37
39
|
if (opts.command) {
|
|
38
40
|
_opts.push('-c', opts.command);
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
const child = (0, shell_1.spawn)('node', _opts, {
|
|
41
43
|
cwd: opts.target,
|
|
42
44
|
stdio: 'pipe',
|
|
43
|
-
env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
|
|
45
|
+
env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
|
|
44
46
|
}).RAW();
|
|
47
|
+
return new Promise((_res, _rej) => {
|
|
48
|
+
child.on('spawn', () => _res(child));
|
|
49
|
+
child.on('error', (reason) => _rej(reason));
|
|
50
|
+
});
|
|
45
51
|
};
|
|
46
52
|
exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
var _a, _b, _c, _d;
|
|
53
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
48
54
|
let child;
|
|
49
55
|
const targetSail = serverDetails.target;
|
|
50
56
|
if (!targetSail || !targetSail.config) {
|
|
@@ -55,9 +61,28 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
55
61
|
}
|
|
56
62
|
const buildPath = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path;
|
|
57
63
|
const target = (yield fs_1.ASYNC.fileExists(buildPath)) ? (0, path_1.dirname)(buildPath) : buildPath;
|
|
64
|
+
if (!(yield fs_1.ASYNC.isPathExists(target))) {
|
|
65
|
+
if ((0, path_1.isAbsolute)(((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.raw.build_path) || '')) {
|
|
66
|
+
throw new error_1.default('The given AppSail build path does not exists', {
|
|
67
|
+
exit: 1,
|
|
68
|
+
errorId: 'SERVE-APPSAIL-1',
|
|
69
|
+
arg: [ansi_colors_1.italic.underline.red(target), (0, ansi_colors_1.bold)(targetSail.name)]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
throw new error_1.default('The given AppSail build path does not exists: ' + targetSail.name, {
|
|
73
|
+
exit: 1,
|
|
74
|
+
errorId: 'SERVE-APPSAIL-2',
|
|
75
|
+
arg: [
|
|
76
|
+
(0, ansi_colors_1.underline)(((_d = targetSail.config) === null || _d === void 0 ? void 0 : _d.raw.build_path) || ''),
|
|
77
|
+
ansi_colors_1.italic.underline(targetSail.config.raw.source_path || ''),
|
|
78
|
+
ansi_colors_1.italic.underline(((_e = targetSail.config) === null || _e === void 0 ? void 0 : _e.raw.build_path) || ''),
|
|
79
|
+
ansi_colors_1.italic.underline(target)
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
58
83
|
switch (true) {
|
|
59
84
|
case targetSail.config.stack.startsWith('node'): {
|
|
60
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
85
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
61
86
|
type: 'nodejs',
|
|
62
87
|
target,
|
|
63
88
|
command: targetSail.config.command,
|
|
@@ -68,7 +93,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
68
93
|
break;
|
|
69
94
|
}
|
|
70
95
|
case targetSail.config.stack.startsWith('python'): {
|
|
71
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
96
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
72
97
|
type: 'python',
|
|
73
98
|
target,
|
|
74
99
|
command: targetSail.config.command,
|
|
@@ -100,7 +125,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
100
125
|
}
|
|
101
126
|
}
|
|
102
127
|
const jettyCommand = `java -jar "${(0, path_1.join)(jettyPath, 'start.jar')}" -Djetty.deploy.monitoredPath="${(0, project_1.resolveProjectPath)(target)}" -Djetty.http.port=${targetSail.port.appsail}`;
|
|
103
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
128
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
104
129
|
target,
|
|
105
130
|
type: 'war',
|
|
106
131
|
command: jettyCommand,
|
|
@@ -110,7 +135,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
110
135
|
});
|
|
111
136
|
break;
|
|
112
137
|
}
|
|
113
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
138
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
114
139
|
target,
|
|
115
140
|
command: targetSail.config.command,
|
|
116
141
|
type: 'javase',
|
|
@@ -121,7 +146,16 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
121
146
|
break;
|
|
122
147
|
}
|
|
123
148
|
default: {
|
|
124
|
-
|
|
149
|
+
const appSailRuntime = yield (0, common_1.getRuntimeDetails)();
|
|
150
|
+
throw new error_1.default('Invalid AppSail stack', {
|
|
151
|
+
exit: 1,
|
|
152
|
+
errorId: 'SERVE-APPSAIL-4',
|
|
153
|
+
arg: [
|
|
154
|
+
(0, ansi_colors_1.bold)(targetSail.name),
|
|
155
|
+
ansi_colors_1.bold.red(targetSail.config.stack),
|
|
156
|
+
appSailRuntime.runtimes.map((val) => (0, ansi_colors_1.bold)(`* ${val}`)).join('\n')
|
|
157
|
+
]
|
|
158
|
+
});
|
|
125
159
|
}
|
|
126
160
|
}
|
|
127
161
|
const masterServe = yield (0, master_1.default)(targetSail.port.proxy, {
|
|
@@ -134,7 +168,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
134
168
|
}
|
|
135
169
|
});
|
|
136
170
|
});
|
|
137
|
-
if ((
|
|
171
|
+
if ((_g = (_f = targetSail.config) === null || _f === void 0 ? void 0 : _f.scripts) === null || _g === void 0 ? void 0 : _g.postserve) {
|
|
138
172
|
child.once('exit', () => {
|
|
139
173
|
var _a, _b, _c;
|
|
140
174
|
if (!((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.scripts)) {
|
|
@@ -143,5 +177,27 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
143
177
|
executeHook((_c = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.scripts) === null || _c === void 0 ? void 0 : _c.postserve, `AppSail [POSTSERVE] [${targetSail.name}]`, targetSail.source);
|
|
144
178
|
});
|
|
145
179
|
}
|
|
180
|
+
process.on('SIGINT', () => {
|
|
181
|
+
targetSail.trigger.kill = true;
|
|
182
|
+
});
|
|
183
|
+
child.once('exit', (code) => {
|
|
184
|
+
var _a, _b, _c;
|
|
185
|
+
if (code === 150) {
|
|
186
|
+
targetSail.validity = {
|
|
187
|
+
valid: false,
|
|
188
|
+
reason: 'Unable to start the AppSail'
|
|
189
|
+
};
|
|
190
|
+
throw new error_1.default('Unable to start the AppSail', {
|
|
191
|
+
exit: 1,
|
|
192
|
+
errorId: 'SERVE-APPSAIL-3',
|
|
193
|
+
arg: [
|
|
194
|
+
(0, ansi_colors_1.bold)(targetSail.name),
|
|
195
|
+
((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.command) || '',
|
|
196
|
+
(0, ansi_colors_1.underline)(((_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path) || ''),
|
|
197
|
+
((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.stack) || ''
|
|
198
|
+
]
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
146
202
|
return child;
|
|
147
203
|
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
|
|
4
|
+
// exit codes
|
|
5
|
+
// 150 - start up command failure
|
|
6
|
+
|
|
3
7
|
const EXEC_SYNC = require('child_process').execSync;
|
|
4
8
|
|
|
5
9
|
const WAR = 'war';
|
|
@@ -58,7 +62,11 @@ function main() {
|
|
|
58
62
|
throw new Error(`invalid runtime type: ${CMD_ARGS.rtType}`);
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
try {
|
|
66
|
+
EXEC_SYNC(command.toString(), { stdio: 'inherit', cwd });
|
|
67
|
+
} catch (er) {
|
|
68
|
+
process.exit(150);
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
main();
|
|
@@ -23,12 +23,12 @@ function addAppSailRoutes(app, details, proxy, unknownProxy) {
|
|
|
23
23
|
req.url = req.originalUrl;
|
|
24
24
|
unknownProxy(req, res);
|
|
25
25
|
}));
|
|
26
|
-
app.use('/
|
|
26
|
+
app.use('/__catalyst', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
req.url = req.originalUrl;
|
|
28
28
|
unknownProxy(req, res);
|
|
29
|
-
});
|
|
29
|
+
}));
|
|
30
30
|
((_b = (_a = details.target) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.catalyst_auth) === true &&
|
|
31
|
-
app.use(['/
|
|
31
|
+
app.use(['/accounts', '/oauthorize'], (req, res) => {
|
|
32
32
|
if (req.url.includes('/appsail/logout_redirect')) {
|
|
33
33
|
res.redirect(typeof req.query.service_url === 'string' ? req.query.service_url : '/');
|
|
34
34
|
return;
|
|
@@ -39,6 +39,9 @@ exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
|
|
|
39
39
|
proxyInstance.web(req, res, {
|
|
40
40
|
target: `https://${req.headers['x-zc-project-domain']}`,
|
|
41
41
|
changeOrigin: true,
|
|
42
|
+
cookieDomainRewrite: {
|
|
43
|
+
[req.headers['x-zc-project-domain'] + '']: 'localhost'
|
|
44
|
+
},
|
|
42
45
|
ws: true,
|
|
43
46
|
headers
|
|
44
47
|
});
|
|
@@ -20,6 +20,17 @@ const error_1 = __importDefault(require("../../../../error"));
|
|
|
20
20
|
const project_1 = require("../../../../util_modules/project");
|
|
21
21
|
const http_proxy_1 = require("http-proxy");
|
|
22
22
|
const logger_1 = require("../../../../util_modules/logger");
|
|
23
|
+
const iam_cookies = [
|
|
24
|
+
'ZD_CSRF_TOKEN',
|
|
25
|
+
'_iamadt_client',
|
|
26
|
+
'_iambdt_client',
|
|
27
|
+
'_zcsr_tmp',
|
|
28
|
+
'iamcsr',
|
|
29
|
+
'zalb',
|
|
30
|
+
'stk',
|
|
31
|
+
'JSESSIONID'
|
|
32
|
+
];
|
|
33
|
+
const isIamCookie = (cookieStr) => iam_cookies.some((val) => cookieStr.startsWith(val));
|
|
23
34
|
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
24
35
|
exports.removeSecure = removeSecure;
|
|
25
36
|
const redirectByAuth = (req, res, redirectUrl) => {
|
|
@@ -68,17 +79,16 @@ const createProxyServer = (port) => {
|
|
|
68
79
|
};
|
|
69
80
|
exports.createProxyServer = createProxyServer;
|
|
70
81
|
const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redirect' }) => (proxyRes, req, res) => {
|
|
82
|
+
var _a, _b;
|
|
71
83
|
if (!req.url) {
|
|
72
84
|
return;
|
|
73
85
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
else if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
|
|
86
|
+
proxyRes.headers['set-cookie'] = (_a = proxyRes.headers['set-cookie']) === null || _a === void 0 ? void 0 : _a.map((cookie) => {
|
|
87
|
+
if (isIamCookie(cookie))
|
|
88
|
+
return (0, exports.removeSecure)(cookie);
|
|
89
|
+
return cookie;
|
|
90
|
+
});
|
|
91
|
+
if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
|
|
82
92
|
if (req.url.includes('/signin-redirect')) {
|
|
83
93
|
if (systemRoutes === undefined) {
|
|
84
94
|
(0, exports.redirectByAuth)(req, res, signInRedirect);
|
|
@@ -108,11 +118,7 @@ const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redir
|
|
|
108
118
|
}
|
|
109
119
|
}
|
|
110
120
|
else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
|
|
111
|
-
|
|
112
|
-
set
|
|
113
|
-
? set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/')
|
|
114
|
-
: ['IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/'];
|
|
115
|
-
proxyRes.headers['set-cookie'] = set;
|
|
121
|
+
(_b = proxyRes.headers['set-cookie']) === null || _b === void 0 ? void 0 : _b.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/');
|
|
116
122
|
}
|
|
117
123
|
};
|
|
118
124
|
exports.proxyResponseHandler = proxyResponseHandler;
|
|
@@ -217,7 +217,7 @@ public class JavajobInvoker {
|
|
|
217
217
|
JSONObject jobMetaDetails = jobDetails.getJSONObject("job_meta_details");
|
|
218
218
|
JSONObject jobpoolDetails = jobMetaDetails.getJSONObject("jobpool_details");
|
|
219
219
|
JSONObject projectDetails = jobpoolDetails.getJSONObject("project_details");
|
|
220
|
-
JSONObject capacity =
|
|
220
|
+
JSONObject capacity = userData.getJSONObject("capacity");
|
|
221
221
|
JSONObject params = jobMetaDetails.getJSONObject("params");
|
|
222
222
|
|
|
223
223
|
defaultJob.setJobDetails(jobDetails != null ? (JSONObject) jobDetails : new JSONObject());
|
|
@@ -97,7 +97,7 @@ class LocalFunction {
|
|
|
97
97
|
return new error_1.default('Invalid input');
|
|
98
98
|
}
|
|
99
99
|
return (() => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
100
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
101
101
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
102
102
|
const accessToken = yield credential_1.default.getAccessToken();
|
|
103
103
|
const slaveOptions = [];
|
|
@@ -105,9 +105,9 @@ class LocalFunction {
|
|
|
105
105
|
yield fs_1.ASYNC.ensureFile(this.responseFile, true);
|
|
106
106
|
yield fs_1.ASYNC.ensureFile(this.metaFile, true);
|
|
107
107
|
if (this.target.type === constants_1.FN_TYPE.job) {
|
|
108
|
-
const
|
|
108
|
+
const jobData = data;
|
|
109
109
|
const jobMetaDetails = {
|
|
110
|
-
headers: Object.assign(Object.assign({}, (_a =
|
|
110
|
+
headers: Object.assign(Object.assign({}, (_b = (_a = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _a === void 0 ? void 0 : _a.job_meta_details) === null || _b === void 0 ? void 0 : _b.headers), {
|
|
111
111
|
'x-zc-projectid': (0, project_1.getProjectId)(),
|
|
112
112
|
'x-zc-project-domain': (0, project_1.getDomainPrefix)() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
|
|
113
113
|
'x-zc-project-key': (0, project_1.getDomainKey)(),
|
|
@@ -118,8 +118,8 @@ class LocalFunction {
|
|
|
118
118
|
'x-zc-admin-cred-token': accessToken,
|
|
119
119
|
'x-zc-user-type': 'admin'
|
|
120
120
|
}),
|
|
121
|
-
params: ((
|
|
122
|
-
jobpool_details: ((
|
|
121
|
+
params: ((_d = (_c = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _c === void 0 ? void 0 : _c.job_meta_details) === null || _d === void 0 ? void 0 : _d.params) || {},
|
|
122
|
+
jobpool_details: ((_f = (_e = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _e === void 0 ? void 0 : _e.job_meta_details) === null || _f === void 0 ? void 0 : _f.jobpool_details) || {
|
|
123
123
|
type: 'Function',
|
|
124
124
|
project_details: {
|
|
125
125
|
project_name: (0, project_1.getProjectName)(),
|
|
@@ -127,14 +127,14 @@ class LocalFunction {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
jobData.job_details = Object.assign(Object.assign({}, jobData.job_details), { job_meta_details: jobMetaDetails });
|
|
131
|
+
jobData.capacity = jobData.capacity || {
|
|
132
132
|
memory: '256'
|
|
133
133
|
};
|
|
134
|
-
data =
|
|
134
|
+
data = jobData;
|
|
135
135
|
}
|
|
136
136
|
const slaveFnTarget = { index: this.target.index, name: this.target.name };
|
|
137
|
-
if ((
|
|
137
|
+
if ((_g = this.target.stack) === null || _g === void 0 ? void 0 : _g.startsWith(runtime_1.default.language.node.value)) {
|
|
138
138
|
if (debugPort !== null) {
|
|
139
139
|
slaveOptions.push('--inspect-brk=' + debugPort);
|
|
140
140
|
}
|
|
@@ -158,10 +158,10 @@ class LocalFunction {
|
|
|
158
158
|
this.slave = (0, shell_1.spawn)('node', slaveOptions, {
|
|
159
159
|
cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
|
|
160
160
|
stdio: 'pipe',
|
|
161
|
-
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (
|
|
161
|
+
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_h = this.target) === null || _h === void 0 ? void 0 : _h.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
|
|
162
162
|
}).RAW();
|
|
163
163
|
}
|
|
164
|
-
else if ((
|
|
164
|
+
else if ((_j = this.target.stack) === null || _j === void 0 ? void 0 : _j.startsWith(runtime_1.default.language.java.value)) {
|
|
165
165
|
const javaInvokerDir = (0, path_1.parse)(this.javaInvoker).dir;
|
|
166
166
|
slaveOptions.push('-cp');
|
|
167
167
|
slaveOptions.push(javaInvokerDir +
|
|
@@ -196,11 +196,11 @@ class LocalFunction {
|
|
|
196
196
|
this.slave = (0, shell_1.spawn)(spawnCommand, slaveOptions, {
|
|
197
197
|
cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
|
|
198
198
|
stdio: 'pipe',
|
|
199
|
-
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (
|
|
199
|
+
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_k = this.target) === null || _k === void 0 ? void 0 : _k.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
|
|
200
200
|
}).RAW();
|
|
201
201
|
}
|
|
202
|
-
else if ((
|
|
203
|
-
const stackVersion = (
|
|
202
|
+
else if ((_l = this.target.stack) === null || _l === void 0 ? void 0 : _l.startsWith(runtime_1.default.language.python.value)) {
|
|
203
|
+
const stackVersion = (_m = this.target.stack) === null || _m === void 0 ? void 0 : _m.replace('python_', '');
|
|
204
204
|
const runtimesDir = constants_1.ENVPATH.runtimes.data;
|
|
205
205
|
const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
|
|
206
206
|
const runTimePort = yield port_resolver_1.default.getFreePort(httpPort, 20, false);
|
|
@@ -211,10 +211,10 @@ class LocalFunction {
|
|
|
211
211
|
this.slave = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), slaveOptions, {
|
|
212
212
|
cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
|
|
213
213
|
stdio: 'pipe',
|
|
214
|
-
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (
|
|
214
|
+
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_o = this.target) === null || _o === void 0 ? void 0 : _o.id, X_ZOHO_CATALYST_CODE_LOCATION: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Local', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[this.target.type] }, this.target.env_var)
|
|
215
215
|
}).RAW();
|
|
216
216
|
this.slave.once('spawn', () => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
var
|
|
217
|
+
var _r;
|
|
218
218
|
const jsonData = data;
|
|
219
219
|
jsonData.timestamp = Date.now();
|
|
220
220
|
const writeResponse = (response, status) => {
|
|
@@ -223,15 +223,15 @@ class LocalFunction {
|
|
|
223
223
|
};
|
|
224
224
|
if (this.target.type === constants_1.FN_TYPE.job) {
|
|
225
225
|
const jobDetailsServer = new http_1.Server((serverReq, serverRes) => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
-
var
|
|
227
|
-
if ((
|
|
226
|
+
var _s, _t, _u;
|
|
227
|
+
if ((_s = serverReq.url) === null || _s === void 0 ? void 0 : _s.includes('data')) {
|
|
228
228
|
serverRes.writeHead(200);
|
|
229
229
|
serverRes.write(JSON.stringify({
|
|
230
230
|
data: jsonData
|
|
231
231
|
}));
|
|
232
232
|
serverRes.end();
|
|
233
233
|
}
|
|
234
|
-
else if ((
|
|
234
|
+
else if ((_t = serverReq.url) === null || _t === void 0 ? void 0 : _t.includes('callback')) {
|
|
235
235
|
const reqData = yield new Promise((resolve) => {
|
|
236
236
|
const data = [];
|
|
237
237
|
serverReq.on('data', (chunk) => data.push(chunk));
|
|
@@ -262,7 +262,7 @@ class LocalFunction {
|
|
|
262
262
|
else {
|
|
263
263
|
(0, logger_1.debug)(`Invalid request: (${serverReq.method}) ${serverReq.url}`);
|
|
264
264
|
writeResponse('INTERNAL_SERVER_ERROR', 500);
|
|
265
|
-
(
|
|
265
|
+
(_u = this.slave) === null || _u === void 0 ? void 0 : _u.kill('SIGINT');
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
}));
|
|
@@ -270,7 +270,7 @@ class LocalFunction {
|
|
|
270
270
|
jobDetailsServer.listen(runTimePort, () => {
|
|
271
271
|
(0, logger_1.debug)('server listening on port :' + runTimePort);
|
|
272
272
|
});
|
|
273
|
-
(
|
|
273
|
+
(_r = this.slave) === null || _r === void 0 ? void 0 : _r.once('exit', () => {
|
|
274
274
|
jobConnDestroyer.destroy();
|
|
275
275
|
});
|
|
276
276
|
return;
|
|
@@ -347,11 +347,11 @@ class LocalFunction {
|
|
|
347
347
|
exit: 2
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
|
-
(
|
|
350
|
+
(_p = this.slave.stdout) === null || _p === void 0 ? void 0 : _p.on('data', (message) => {
|
|
351
351
|
(0, shell_1.clearLine)(process.stdout);
|
|
352
352
|
(0, logger_1.info)(message.toString());
|
|
353
353
|
});
|
|
354
|
-
(
|
|
354
|
+
(_q = this.slave.stderr) === null || _q === void 0 ? void 0 : _q.on('data', (message) => {
|
|
355
355
|
const errorStr = js_1.JS.trim(message.toString());
|
|
356
356
|
(0, shell_1.clearLine)(process.stdout);
|
|
357
357
|
(0, logger_1.info)(errorStr);
|
|
@@ -379,6 +379,7 @@ class LocalFunction {
|
|
|
379
379
|
});
|
|
380
380
|
break;
|
|
381
381
|
case constants_1.FN_TYPE.cron:
|
|
382
|
+
case constants_1.FN_TYPE.job:
|
|
382
383
|
case constants_1.FN_TYPE.event:
|
|
383
384
|
(0, logger_1.info)(`[status - ${this.target.name}] ${response || 'Unknown'}`);
|
|
384
385
|
if (!response) {
|
|
@@ -33,6 +33,7 @@ const server_1 = require("../../util_modules/server");
|
|
|
33
33
|
const ansi_colors_1 = require("ansi-colors");
|
|
34
34
|
const util_1 = require("util");
|
|
35
35
|
const project_1 = require("../../util_modules/project");
|
|
36
|
+
const endpoints_1 = require("../../endpoints");
|
|
36
37
|
class TunnelServer {
|
|
37
38
|
constructor(repel) {
|
|
38
39
|
_TunnelServer_contextMap.set(this, {});
|
|
@@ -42,6 +43,29 @@ class TunnelServer {
|
|
|
42
43
|
_TunnelServer_projectId.set(this, (0, project_1.getProjectId)());
|
|
43
44
|
__classPrivateFieldSet(this, _TunnelServer_repel, repel, "f");
|
|
44
45
|
}
|
|
46
|
+
isAsyncFn(fnType) {
|
|
47
|
+
switch (fnType) {
|
|
48
|
+
case 'cron':
|
|
49
|
+
case 'event':
|
|
50
|
+
case 'job': {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
send(req, res, status = 200, data, contentType) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const body = req.body;
|
|
59
|
+
if (this.isAsyncFn(body.function_details.function_type)) {
|
|
60
|
+
const tunnelAPI = yield (0, endpoints_1.tunnelAPI)();
|
|
61
|
+
yield tunnelAPI.tunnelCallback(status, body.default, data);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
contentType && res.contentType(contentType);
|
|
65
|
+
res.status(status);
|
|
66
|
+
res.send(data);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
45
69
|
startServer() {
|
|
46
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
71
|
const tunnelPortOpt = Number.parseInt(runtime_store_1.default.get('context.port.tunnel'));
|
|
@@ -59,23 +83,33 @@ class TunnelServer {
|
|
|
59
83
|
const app = (0, express_1.default)();
|
|
60
84
|
app.use(express_1.default.json());
|
|
61
85
|
app.all('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
if (req.method !== 'POST') {
|
|
87
|
+
res.status(200);
|
|
88
|
+
res.send();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const body = req.body;
|
|
92
|
+
if (!body.function_details ||
|
|
93
|
+
!body.function_data ||
|
|
94
|
+
(body.function_details.function_type !== 'integration' && !body.default)) {
|
|
95
|
+
res.status(400);
|
|
96
|
+
res.send();
|
|
97
|
+
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
98
|
+
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid tunnel request: ' + (0, util_1.inspect)(body));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (this.isAsyncFn(body.function_details.function_type)) {
|
|
102
|
+
res.status(200);
|
|
103
|
+
res.send();
|
|
104
|
+
}
|
|
62
105
|
try {
|
|
63
|
-
const body = req.body;
|
|
64
|
-
if (!body.function_details || !body.function_data) {
|
|
65
|
-
res.status(400);
|
|
66
|
-
res.send();
|
|
67
|
-
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
68
|
-
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid tunnel request: ' + (0, util_1.inspect)(body));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
106
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
72
107
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write((0, ansi_colors_1.bold)(`Received tunnel request from ${body.function_details.function_name}(${body.function_details.function_id})`));
|
|
73
108
|
const target = body.function_details.function_id in __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")
|
|
74
109
|
? __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")[body.function_details.function_id]
|
|
75
|
-
: (() => {
|
|
110
|
+
: yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
76
111
|
if (__classPrivateFieldGet(this, _TunnelServer_projectId, "f") !== body.function_details.project_id) {
|
|
77
|
-
|
|
78
|
-
res.send();
|
|
112
|
+
yield this.send(req, res, 403);
|
|
79
113
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
80
114
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid access: the tunnel is trying to access the functions from a different project');
|
|
81
115
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
@@ -87,15 +121,14 @@ class TunnelServer {
|
|
|
87
121
|
if (namedFn) {
|
|
88
122
|
return namedFn;
|
|
89
123
|
}
|
|
90
|
-
|
|
91
|
-
res.send();
|
|
124
|
+
yield this.send(req, res, 404);
|
|
92
125
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
93
126
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write(`The tunneled function ${(0, ansi_colors_1.bold)(body.function_details.function_name)} is not present in local project directory`);
|
|
94
127
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
|
|
95
128
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write('[STATUS]');
|
|
96
129
|
__classPrivateFieldGet(this, _TunnelServer_repel, "f").write('NOT_FOUND');
|
|
97
130
|
return;
|
|
98
|
-
}).bind(this)();
|
|
131
|
+
})).bind(this)();
|
|
99
132
|
if (!target) {
|
|
100
133
|
return;
|
|
101
134
|
}
|
|
@@ -103,11 +136,10 @@ class TunnelServer {
|
|
|
103
136
|
? JSON.parse(body.function_data)
|
|
104
137
|
: body.function_data;
|
|
105
138
|
target.call(false)(fnData);
|
|
106
|
-
const errorHandler = (e) => {
|
|
107
|
-
|
|
108
|
-
res.send();
|
|
139
|
+
const errorHandler = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
yield this.send(req, res, 500);
|
|
109
141
|
(0, logger_1.debug)('Target error: ' + e);
|
|
110
|
-
};
|
|
142
|
+
});
|
|
111
143
|
target.once('error', errorHandler);
|
|
112
144
|
const response = yield new Promise((resolve, reject) => {
|
|
113
145
|
target.once('response', (response) => {
|
|
@@ -118,13 +150,10 @@ class TunnelServer {
|
|
|
118
150
|
resolve(response);
|
|
119
151
|
});
|
|
120
152
|
});
|
|
121
|
-
|
|
122
|
-
res.status(response.status || 200);
|
|
123
|
-
res.send(response.responseBody);
|
|
153
|
+
yield this.send(req, res, response.status, response.responseBody, response.ContentType);
|
|
124
154
|
}
|
|
125
155
|
catch (e) {
|
|
126
|
-
|
|
127
|
-
res.send();
|
|
156
|
+
yield this.send(req, res, 500);
|
|
128
157
|
(0, logger_1.debug)(e);
|
|
129
158
|
}
|
|
130
159
|
}));
|
package/lib/shell/index.js
CHANGED
|
@@ -49,35 +49,29 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
49
49
|
const httpServer = new http_functions_1.default({ repl: replServer });
|
|
50
50
|
const tunnelServer = new tunnel_server_1.default(replServer);
|
|
51
51
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(0, logger_js_1.warning)(
|
|
65
|
-
target.name +
|
|
66
|
-
'] is not a valid one reason : ' +
|
|
67
|
-
target.failure_reason);
|
|
68
|
-
Array.isArray(target.compilationError) &&
|
|
69
|
-
target.compilationError.forEach((er) => (0, logger_js_1.error)(er));
|
|
70
|
-
Array.isArray(target.compilationWarning) &&
|
|
71
|
-
target.compilationWarning.forEach((warn) => (0, logger_js_1.warning)(warn));
|
|
72
|
-
}
|
|
73
|
-
return target.valid;
|
|
74
|
-
});
|
|
75
|
-
if (targets.length === 0) {
|
|
76
|
-
throw new error_1.default('No functions are ready for serving', {
|
|
77
|
-
exit: 0,
|
|
78
|
-
errorId: 'SHELL-IDX-1'
|
|
79
|
-
});
|
|
52
|
+
yield (0, prepare_1.default)([constants_1.FN_TYPE.basic, constants_1.FN_TYPE.cron, constants_1.FN_TYPE.event, constants_1.FN_TYPE.integration, constants_1.FN_TYPE.job]);
|
|
53
|
+
const targets = runtime_store_1.default
|
|
54
|
+
.get('context.functions.targets', [])
|
|
55
|
+
.filter((target) => {
|
|
56
|
+
if (!target.valid) {
|
|
57
|
+
(0, logger_js_1.warning)('target [' +
|
|
58
|
+
target.name +
|
|
59
|
+
'] is not a valid one reason : ' +
|
|
60
|
+
target.failure_reason);
|
|
61
|
+
Array.isArray(target.compilationError) &&
|
|
62
|
+
target.compilationError.forEach((er) => (0, logger_js_1.error)(er));
|
|
63
|
+
Array.isArray(target.compilationWarning) &&
|
|
64
|
+
target.compilationWarning.forEach((warn) => (0, logger_js_1.warning)(warn));
|
|
80
65
|
}
|
|
66
|
+
return target.valid;
|
|
67
|
+
});
|
|
68
|
+
if (targets.length === 0) {
|
|
69
|
+
throw new error_1.default('No functions are ready for serving', {
|
|
70
|
+
exit: 0,
|
|
71
|
+
errorId: 'SHELL-IDX-1'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
81
75
|
replServer.start();
|
|
82
76
|
yield tunnelServer.startServer();
|
|
83
77
|
const tunnelUrl = runtime_store_1.default.get('context.fn_shell.enable_tunnel', undefined);
|
|
@@ -26,6 +26,8 @@ function validateConfig(source, configJson) {
|
|
|
26
26
|
reason: 'Config file is empty'
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
+
const sourcePath = (0, path_1.join)((0, project_1.getProjectRoot)(), source);
|
|
30
|
+
configJson.raw.source_path = sourcePath;
|
|
29
31
|
if (configJson.buildPath || configJson.build_path) {
|
|
30
32
|
const buildPath = configJson.build_path || configJson.buildPath;
|
|
31
33
|
if (!buildPath) {
|
|
@@ -34,8 +36,9 @@ function validateConfig(source, configJson) {
|
|
|
34
36
|
reason: 'Build Path not present'
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
|
-
const absolutePath = (0, path_1.isAbsolute)(buildPath) ? buildPath : (0, path_1.resolve)(
|
|
39
|
+
const absolutePath = (0, path_1.isAbsolute)(buildPath) ? buildPath : (0, path_1.resolve)(sourcePath, buildPath);
|
|
38
40
|
configJson.build_path = absolutePath;
|
|
41
|
+
configJson.raw.build_path = buildPath;
|
|
39
42
|
}
|
|
40
43
|
if (configJson.catalyst_auth === true) {
|
|
41
44
|
if (configJson.login_redirect === undefined) {
|
|
@@ -121,6 +124,7 @@ function getAllTargetDetails(throwErr = true) {
|
|
|
121
124
|
resArr.push(new Promise((res) => __awaiter(this, void 0, void 0, function* () {
|
|
122
125
|
try {
|
|
123
126
|
const configJson = yield fs_1.ASYNC.readJSONFile(catalystConfigPth);
|
|
127
|
+
configJson && (configJson.raw = {});
|
|
124
128
|
const validity = validateConfig(target.source, configJson);
|
|
125
129
|
return res(Object.assign({ config: configJson, validity }, target));
|
|
126
130
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcatalyst-cli",
|
|
3
|
-
"version": "1.18.0-beta.
|
|
3
|
+
"version": "1.18.0-beta.4",
|
|
4
4
|
"description": "Command Line Tool for CATALYST",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"build:watch": "gulp watch",
|
|
95
95
|
"clean": "gulp cleanup",
|
|
96
96
|
"test:unit": "jest --config jest.config.js",
|
|
97
|
+
"lint:nofix": "eslint --ext .ts src/ --color",
|
|
97
98
|
"lint:src": "eslint --ext .ts src/ --fix --color",
|
|
98
99
|
"lint:unit": "eslint --ext .js,.ts test/ --fix --color",
|
|
99
100
|
"lint": "run-p lint:src lint:unit",
|