zcatalyst-cli 1.18.0-beta.0 → 1.18.0-beta.2
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/command_needs/rc.toml +8 -8
- package/docs/commands/event/generate/job.toml +7 -0
- package/docs/endpoints/lib/job-scheduling.toml +3 -0
- package/docs/internal/command.toml +5 -0
- package/lib/appsail-utils.js +4 -10
- package/lib/authentication/index.js +1 -0
- package/lib/bin/catalyst.js +1 -1
- package/lib/command_needs/rc.js +8 -8
- package/lib/commands/appsail/add.js +2 -1
- package/lib/commands/client/setup.js +2 -1
- package/lib/commands/codelib/install.js +5 -2
- package/lib/commands/event/generate/index.js +2 -1
- package/lib/commands/event/generate/integ.js +2 -1
- package/lib/commands/event/generate/job.js +82 -0
- package/lib/commands/functions/add.js +2 -1
- package/lib/commands/functions/delete.js +2 -4
- package/lib/commands/functions/setup.js +2 -1
- package/lib/commands/functions/shell.js +1 -0
- package/lib/commands/index.js +3 -1
- package/lib/commands/init.js +10 -7
- package/lib/commands/login.js +1 -0
- package/lib/commands/logout.js +1 -0
- package/lib/commands/pull.js +1 -0
- package/lib/commands/serve.js +1 -1
- package/lib/commands/whoami.js +1 -0
- package/lib/deploy/features/appsail/index.js +42 -25
- package/lib/deploy/features/appsail/utils.js +4 -5
- package/lib/endpoints/index.js +10 -3
- package/lib/endpoints/lib/appsail.js +7 -1
- package/lib/endpoints/lib/job-scheduling.js +61 -0
- package/lib/express_middlewares/logger.js +2 -4
- package/lib/fn-utils/lib/common.js +2 -3
- package/lib/fn-utils/lib/java.js +1 -1
- package/lib/fn-utils/lib/python.js +2 -2
- package/lib/fn-watcher.js +1 -1
- package/lib/init/dependencies/python/ensure-python.js +6 -8
- package/lib/init/features/appsail/index.js +36 -26
- package/lib/init/features/client/index.js +2 -1
- package/lib/init/features/functions/index.js +4 -0
- package/lib/init/features/functions/languages/python.js +21 -5
- package/lib/init/features/project.js +5 -15
- package/lib/internal/api.js +25 -6
- package/lib/internal/command.js +30 -6
- package/lib/migration/index.js +4 -2
- package/lib/optional-import.js +3 -2
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/prompt/types/tree.js +3 -3
- package/lib/serve/features/appsail.js +2 -3
- package/lib/serve/index.js +1 -2
- package/lib/serve/server/index.js +8 -9
- package/lib/serve/server/lib/appsail/index.js +29 -35
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/index.js +2 -2
- package/lib/serve/server/lib/master/appsail.js +53 -0
- package/lib/serve/server/lib/master/functions.js +34 -0
- package/lib/serve/server/lib/master/index.js +155 -0
- package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
- package/lib/serve/server/lib/master/utils.js +130 -0
- package/lib/serve/server/lib/master/web-client.js +39 -0
- package/lib/serve/server/lib/node/index.js +3 -3
- package/lib/serve/server/lib/python/index.js +3 -3
- package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +2 -1
- package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/node.mjs +1 -0
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +14 -0
- package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
- package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +268 -0
- package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
- package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
- package/lib/shell/dependencies/local-function.js +121 -13
- package/lib/shell/index.js +7 -1
- package/lib/shell/prepare/languages/index.js +4 -4
- package/lib/shell/prepare/languages/java.js +1 -2
- package/lib/shell/prepare/languages/python.js +10 -16
- package/lib/throbber/index.js +6 -1
- package/lib/userConfig.js +7 -1
- package/lib/util_modules/config/index.js +1 -1
- package/lib/util_modules/config/lib/{appSail.js → appsail.js} +60 -10
- package/lib/util_modules/config/lib/client.js +6 -8
- package/lib/util_modules/config/lib/functions.js +6 -8
- package/lib/util_modules/constants/lib/default.js +9 -9
- package/lib/util_modules/constants/lib/fn-type.js +2 -1
- package/lib/util_modules/constants/lib/needed-scopes.js +53 -44
- package/lib/util_modules/constants/lib/placeholders.js +6 -0
- package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
- package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +5 -1
- package/lib/util_modules/constants/lib/template.js +9 -4
- package/lib/util_modules/constants/lib/urls.js +8 -0
- package/lib/util_modules/fs/lib/async.js +14 -4
- package/lib/util_modules/fs/lib/sync.js +12 -1
- package/lib/util_modules/server.js +2 -4
- package/lib/winston.js +17 -11
- package/package.json +1 -1
- package/templates/event/job.json +30 -0
- package/templates/init/functions/java/job/.classpath +6 -0
- package/templates/init/functions/java/job/.project +17 -0
- package/templates/init/functions/java/job/catalyst-config.json +11 -0
- package/templates/init/functions/java/job/sample.java +34 -0
- package/templates/init/functions/node/aio/package.json +1 -1
- package/templates/init/functions/node/aio/sample.js +7 -0
- package/templates/init/functions/node/bio/package.json +1 -1
- package/templates/init/functions/node/bio/sample.js +5 -0
- package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
- package/templates/init/functions/node/cron/package.json +1 -1
- package/templates/init/functions/node/cron/sample.js +5 -0
- package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
- package/templates/init/functions/node/event/package.json +1 -1
- package/templates/init/functions/node/event/sample.js +11 -8
- package/templates/init/functions/node/event/types/event.d.ts +82 -0
- package/templates/init/functions/node/integ/cliq/package.json +1 -1
- package/templates/init/functions/node/integ/convokraft/package.json +1 -1
- package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
- package/templates/init/functions/node/{stream → job}/package.json +1 -1
- package/templates/init/functions/node/job/sample.js +27 -0
- package/templates/init/functions/node/job/types/job.d.ts +62 -0
- package/templates/init/functions/python/job/catalyst-config.json +11 -0
- package/templates/init/functions/python/job/requirements.txt +1 -0
- package/templates/init/functions/python/job/sample.py +22 -0
- package/templates/init.txt +13 -0
- package/lib/serve/server/lib/master.js +0 -326
- package/templates/init/functions/node/stream/sample.js +0 -15
|
@@ -0,0 +1,155 @@
|
|
|
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 express_1 = __importDefault(require("express"));
|
|
16
|
+
const error_1 = __importDefault(require("../../../../error"));
|
|
17
|
+
const apig_matcher_1 = __importDefault(require("../../../../express_middlewares/apig-matcher"));
|
|
18
|
+
const auth_checker_1 = __importDefault(require("../../../../express_middlewares/auth-checker"));
|
|
19
|
+
const authenticator_1 = __importDefault(require("../../../../express_middlewares/authenticator"));
|
|
20
|
+
const cookie_parser_1 = __importDefault(require("../../../../express_middlewares/cookie-parser"));
|
|
21
|
+
const error_handler_1 = __importDefault(require("../../../../express_middlewares/error-handler"));
|
|
22
|
+
const logger_1 = __importDefault(require("../../../../express_middlewares/logger"));
|
|
23
|
+
const project_1 = __importDefault(require("../../../../express_middlewares/project"));
|
|
24
|
+
const unknown_req_proxy_1 = __importDefault(require("./unknown-req-proxy"));
|
|
25
|
+
const url_rewriter_1 = __importDefault(require("../../../../express_middlewares/url-rewriter"));
|
|
26
|
+
const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
|
|
27
|
+
const constants_1 = require("../../../../util_modules/constants");
|
|
28
|
+
const js_1 = require("../../../../util_modules/js");
|
|
29
|
+
const logger_2 = require("../../../../util_modules/logger");
|
|
30
|
+
const project_2 = require("../../../../util_modules/project");
|
|
31
|
+
const option_1 = require("../../../../util_modules/option");
|
|
32
|
+
const server_js_1 = require("../../../../util_modules/server.js");
|
|
33
|
+
const utils_1 = require("./utils");
|
|
34
|
+
const appsail_1 = require("./appsail");
|
|
35
|
+
const web_client_1 = require("./web-client");
|
|
36
|
+
const functions_1 = require("./functions");
|
|
37
|
+
function spinUpMaster(listenPort, { otherServerDetails, appSailDetails }) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if ((otherServerDetails && appSailDetails) || (!otherServerDetails && !appSailDetails)) {
|
|
41
|
+
throw new error_1.default('Either functions/client or AppSail is need to start the master server. But both cannot use the same master', { exit: 2 });
|
|
42
|
+
}
|
|
43
|
+
const projectDetails = {
|
|
44
|
+
id: (0, project_2.getProjectId)(),
|
|
45
|
+
domain_prefix: (0, project_2.getDomainPrefix)(),
|
|
46
|
+
domain: constants_1.ORIGIN.app.replace('https://', ''),
|
|
47
|
+
key: (0, project_2.getDomainKey)(),
|
|
48
|
+
env_name: (0, project_2.getEnvName)()
|
|
49
|
+
};
|
|
50
|
+
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
51
|
+
const customProxyUrl = (0, option_1.getOptionValue)('proxy');
|
|
52
|
+
const app = (0, express_1.default)();
|
|
53
|
+
let systemRoutes;
|
|
54
|
+
const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
|
|
55
|
+
app.use((0, logger_1.default)(appSailDetails));
|
|
56
|
+
app.use(cookie_parser_1.default);
|
|
57
|
+
app.use((0, project_1.default)(projectDetails));
|
|
58
|
+
app.use(authenticator_1.default);
|
|
59
|
+
!appSailDetails &&
|
|
60
|
+
app.use(nonApigURL, (req, res) => {
|
|
61
|
+
req.url = req.originalUrl;
|
|
62
|
+
unknownProxy(req, res);
|
|
63
|
+
});
|
|
64
|
+
!appSailDetails &&
|
|
65
|
+
app.use('*/.catalyst%2Freload-script.js', (req, res) => {
|
|
66
|
+
var _a;
|
|
67
|
+
req.url = '/.catalyst%2Freload-script.js';
|
|
68
|
+
(_a = otherServerDetails === null || otherServerDetails === void 0 ? void 0 : otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
69
|
+
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
70
|
+
proxy.web(req, res, {
|
|
71
|
+
target: appTarget,
|
|
72
|
+
changeOrigin: true
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
if (rules !== -1 && !appSailDetails) {
|
|
77
|
+
for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
|
|
78
|
+
const router = app.route(sourceURL);
|
|
79
|
+
for (const [method, config] of Object.entries(methodByConfig)) {
|
|
80
|
+
if (config.system) {
|
|
81
|
+
if (systemRoutes === undefined) {
|
|
82
|
+
systemRoutes = {};
|
|
83
|
+
}
|
|
84
|
+
js_1.JS.set(systemRoutes, [sourceURL, method], config);
|
|
85
|
+
}
|
|
86
|
+
router[method]((req, res, next) => {
|
|
87
|
+
if (res.locals.apigRules === undefined) {
|
|
88
|
+
res.locals.apigRules = [];
|
|
89
|
+
}
|
|
90
|
+
res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
|
|
91
|
+
next();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
|
|
96
|
+
}
|
|
97
|
+
const proxy = (0, utils_1.createProxyServer)(listenPort);
|
|
98
|
+
appSailDetails && ((_b = (_a = appSailDetails.target) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.catalyst_auth) === true
|
|
99
|
+
? proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({
|
|
100
|
+
signInRedirect: appSailDetails.target.config.login_redirect || '/'
|
|
101
|
+
}))
|
|
102
|
+
: proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({ systemRoutes }));
|
|
103
|
+
const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
|
|
104
|
+
const unknownProxy = (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl);
|
|
105
|
+
otherServerDetails &&
|
|
106
|
+
Object.keys(otherServerDetails).forEach((targ) => {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
switch (targ) {
|
|
109
|
+
case 'client': {
|
|
110
|
+
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => (0, web_client_1.addWebClientRoutes)(app, clientDetails, proxy, unknownProxy));
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case 'server': {
|
|
114
|
+
(_b = otherServerDetails.server) === null || _b === void 0 ? void 0 : _b.forEach((serverDetail) => {
|
|
115
|
+
var _a;
|
|
116
|
+
app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
|
|
117
|
+
proxy.web(req, res, {
|
|
118
|
+
target: `http://127.0.0.1:${serverDetail.httpPort}`
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case 'functions': {
|
|
125
|
+
(_c = otherServerDetails.functions) === null || _c === void 0 ? void 0 : _c.forEach((fnDetails) => (0, functions_1.addFnRoutes)(app, fnDetails, proxy));
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
default:
|
|
129
|
+
throw new error_1.default('Unknown type provided to master server ' + targ, {
|
|
130
|
+
exit: 2
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
appSailDetails && (0, appsail_1.addAppSailRoutes)(app, appSailDetails, proxy, unknownProxy);
|
|
135
|
+
app.use('/', (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl));
|
|
136
|
+
app.use(error_handler_1.default);
|
|
137
|
+
const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
138
|
+
if (proxy) {
|
|
139
|
+
proxyDestroyer.destroy();
|
|
140
|
+
}
|
|
141
|
+
console.error(err);
|
|
142
|
+
});
|
|
143
|
+
const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
|
|
144
|
+
expressServer.maxConnections = 100;
|
|
145
|
+
process.on('SIGINT', () => expressDestroyer.destroy(false));
|
|
146
|
+
expressServer.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
yield proxyDestroyer.destroy().catch((err) => (0, logger_2.debug)(err));
|
|
148
|
+
}));
|
|
149
|
+
expressServer.on('upgrade', (...upgradeParam) => {
|
|
150
|
+
app.emit('upgrade', ...upgradeParam);
|
|
151
|
+
});
|
|
152
|
+
return expressServer;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
exports.default = spinUpMaster;
|
package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js}
RENAMED
|
@@ -3,9 +3,9 @@ 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
|
-
const runtime_store_1 = __importDefault(require("
|
|
7
|
-
const logger_1 = require("
|
|
8
|
-
exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
|
|
6
|
+
const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
|
|
7
|
+
const logger_1 = require("../../../../util_modules/logger");
|
|
8
|
+
exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
|
|
9
9
|
if (req.url.length === 1 && req.url.startsWith('/')) {
|
|
10
10
|
res.redirect('/app/');
|
|
11
11
|
}
|
|
@@ -34,16 +34,13 @@ exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
|
|
|
34
34
|
headers['origin'] = `https://${req.headers['x-zc-project-domain']}`;
|
|
35
35
|
}
|
|
36
36
|
if (req.url.includes('/__catalyst/auth/')) {
|
|
37
|
-
|
|
38
|
-
headers['catalyst-redirect-domain'] = `http://localhost:${masterPort}`;
|
|
37
|
+
headers['catalyst-redirect-domain'] = `http://localhost:${masterPort || 3000}`;
|
|
39
38
|
}
|
|
40
39
|
proxyInstance.web(req, res, {
|
|
41
40
|
target: `https://${req.headers['x-zc-project-domain']}`,
|
|
42
41
|
changeOrigin: true,
|
|
43
42
|
ws: true,
|
|
44
43
|
headers
|
|
45
|
-
}, (err) => {
|
|
46
|
-
(0, logger_1.debug)('Unknown proxy error: ', err);
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
};
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
exports.appsailInitJs = exports.proxyResponseHandler = exports.createProxyServer = exports.redirectByAuth = exports.removeSecure = void 0;
|
|
16
|
+
const http_1 = require("http");
|
|
17
|
+
const constants_1 = require("../../../../util_modules/constants");
|
|
18
|
+
const fs_1 = require("../../../../util_modules/fs");
|
|
19
|
+
const error_1 = __importDefault(require("../../../../error"));
|
|
20
|
+
const project_1 = require("../../../../util_modules/project");
|
|
21
|
+
const http_proxy_1 = require("http-proxy");
|
|
22
|
+
const logger_1 = require("../../../../util_modules/logger");
|
|
23
|
+
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
24
|
+
exports.removeSecure = removeSecure;
|
|
25
|
+
const redirectByAuth = (req, res, redirectUrl) => {
|
|
26
|
+
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
27
|
+
res.writeHead(302, { Location: redirectUrl });
|
|
28
|
+
res.end();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
res.writeHead(302, { Location: '/app/' });
|
|
32
|
+
res.end();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.redirectByAuth = redirectByAuth;
|
|
36
|
+
const createProxyServer = (port) => {
|
|
37
|
+
const proxy = (0, http_proxy_1.createProxyServer)({
|
|
38
|
+
hostRewrite: `localhost:${port}`,
|
|
39
|
+
protocolRewrite: 'http'
|
|
40
|
+
})
|
|
41
|
+
.on('error', (err, req, res) => {
|
|
42
|
+
if (res.writableEnded) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (res instanceof http_1.ServerResponse) {
|
|
46
|
+
res.writeHead(502, { 'Content-Type': 'json' });
|
|
47
|
+
}
|
|
48
|
+
res.end(JSON.stringify({ error: 'unable to serve the request' }));
|
|
49
|
+
console.log();
|
|
50
|
+
console.log('Unable to reach the servers to serve the request: ', req.url);
|
|
51
|
+
console.error(err);
|
|
52
|
+
})
|
|
53
|
+
.on('econnreset', (err, req, res, targetUrl) => {
|
|
54
|
+
if (res.writableEnded) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (res instanceof http_1.ServerResponse) {
|
|
58
|
+
res.writeHead(502, { 'Content-Type': 'json' });
|
|
59
|
+
}
|
|
60
|
+
res.end(JSON.stringify({ error: 'unable to serve the request. ECONNRESET.' }));
|
|
61
|
+
console.log();
|
|
62
|
+
console.log('Connection reset while trying to serve the request ', req.url);
|
|
63
|
+
(0, logger_1.debug)('Connection reset from target URL : ', targetUrl);
|
|
64
|
+
console.error(err);
|
|
65
|
+
})
|
|
66
|
+
.on('close', () => (0, logger_1.debug)('proxy closed'));
|
|
67
|
+
return proxy;
|
|
68
|
+
};
|
|
69
|
+
exports.createProxyServer = createProxyServer;
|
|
70
|
+
const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redirect' }) => (proxyRes, req, res) => {
|
|
71
|
+
if (!req.url) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (req.url.startsWith('/oauthorize')) {
|
|
75
|
+
const set = proxyRes.headers['set-cookie'];
|
|
76
|
+
if (set) {
|
|
77
|
+
const result = Array.isArray(set) ? set.map(exports.removeSecure) : (0, exports.removeSecure)(set);
|
|
78
|
+
proxyRes.headers['set-cookie'] = result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
|
|
82
|
+
if (req.url.includes('/signin-redirect')) {
|
|
83
|
+
if (systemRoutes === undefined) {
|
|
84
|
+
(0, exports.redirectByAuth)(req, res, signInRedirect);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const sourceRedirectUrl = Object.keys(systemRoutes).find((sourceUrl) => {
|
|
88
|
+
const methodByConfig = systemRoutes ? systemRoutes[sourceUrl] : undefined;
|
|
89
|
+
if (methodByConfig) {
|
|
90
|
+
return !!Object.values(methodByConfig).find((config) => {
|
|
91
|
+
return config.name === 'Login Redirect';
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
if (sourceRedirectUrl === undefined) {
|
|
97
|
+
res.end('INVALID_URL');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
(0, exports.redirectByAuth)(req, res, sourceRedirectUrl);
|
|
101
|
+
}
|
|
102
|
+
else if (req.url.includes('/logout')) {
|
|
103
|
+
const set = proxyRes.headers['set-cookie'];
|
|
104
|
+
if (set) {
|
|
105
|
+
const result = set.map((cookie) => cookie.replace(new RegExp('Domain=[\\S^;]*', 'g'), 'Domain=localhost;'));
|
|
106
|
+
proxyRes.headers['set-cookie'] = result;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
|
|
111
|
+
const set = proxyRes.headers['set-cookie'];
|
|
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;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.proxyResponseHandler = proxyResponseHandler;
|
|
119
|
+
const appsailInitJs = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
let initJsStr = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.init_js);
|
|
121
|
+
if (!initJsStr) {
|
|
122
|
+
throw new error_1.default('Unable to read the init_js file', { exit: 2 });
|
|
123
|
+
}
|
|
124
|
+
const feed = [(0, project_1.getProjectId)(), (0, project_1.getDomainKey)(), constants_1.ORIGIN.iamPortal, (0, project_1.getEnvId)()];
|
|
125
|
+
Object.values(constants_1.PLACEHOLDER.init_js).forEach((holder, idx) => {
|
|
126
|
+
initJsStr = initJsStr === null || initJsStr === void 0 ? void 0 : initJsStr.replace(new RegExp(holder, 'g'), feed[idx]);
|
|
127
|
+
});
|
|
128
|
+
return initJsStr;
|
|
129
|
+
});
|
|
130
|
+
exports.appsailInitJs = appsailInitJs;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addWebClientRoutes = void 0;
|
|
4
|
+
function addWebClientRoutes(app, details, proxy, unknownProxy) {
|
|
5
|
+
const appTarget = `http://127.0.0.1:${details.httpPort}/app/`;
|
|
6
|
+
app.use('/app', (req, res) => {
|
|
7
|
+
const target = details.target;
|
|
8
|
+
if (req.url === '/' && target.homepage.includes('/__catalyst')) {
|
|
9
|
+
req.url = target.homepage;
|
|
10
|
+
unknownProxy(req, res);
|
|
11
|
+
}
|
|
12
|
+
else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
|
|
13
|
+
const isUrl = target.login_redirect.startsWith('/');
|
|
14
|
+
if (isUrl) {
|
|
15
|
+
res.redirect(target.login_redirect);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
res.redirect('/app/' + target.login_redirect);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
proxy.web(req, res, {
|
|
23
|
+
target: appTarget,
|
|
24
|
+
changeOrigin: true
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const appTargetUrl = new URL(appTarget);
|
|
29
|
+
appTargetUrl.pathname = '';
|
|
30
|
+
appTargetUrl.protocol = 'ws';
|
|
31
|
+
app.addListener('upgrade', (...upgradeParam) => {
|
|
32
|
+
proxy.ws(upgradeParam[0], upgradeParam[1], upgradeParam[2], {
|
|
33
|
+
target: appTargetUrl.href,
|
|
34
|
+
ws: true,
|
|
35
|
+
changeOrigin: true
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.addWebClientRoutes = addWebClientRoutes;
|
|
@@ -34,9 +34,9 @@ const logger_1 = require("../../../../util_modules/logger");
|
|
|
34
34
|
const project_1 = require("../../../../util_modules/project");
|
|
35
35
|
const shell_1 = require("../../../../util_modules/shell");
|
|
36
36
|
exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
var _a, _b, _c, _d, _e, _f;
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
38
38
|
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
39
|
-
const
|
|
39
|
+
const _h = details.target, { ['watcher']: _ } = _h, serialisableTarget = __rest(_h, ['watcher']);
|
|
40
40
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
41
41
|
serialisableTarget.index = serialisableTarget.index
|
|
42
42
|
? serialisableTarget.index.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build))
|
|
@@ -88,6 +88,6 @@ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, fun
|
|
|
88
88
|
return (0, shell_1.spawn)('node', opts, {
|
|
89
89
|
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
90
90
|
stdio: 'pipe',
|
|
91
|
-
env: Object.assign({ NODE_PATH: targetSource + path_1.sep + 'node_modules', 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, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
91
|
+
env: Object.assign({ NODE_PATH: targetSource + path_1.sep + 'node_modules', 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: (_g = details.target) === null || _g === void 0 ? void 0 : _g.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
92
92
|
}).RAW();
|
|
93
93
|
});
|
|
@@ -32,17 +32,17 @@ exports.default = (details) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
32
32
|
(0, path_1.join)(runtimesDir, constants_1.RUNTIME.language.python.value, `zcatalyst_runtime_${stackVersion === null || stackVersion === void 0 ? void 0 : stackVersion.replace('_', '')}`, 'main.py')
|
|
33
33
|
];
|
|
34
34
|
return new Promise((resolve, reject) => {
|
|
35
|
-
var _a;
|
|
35
|
+
var _a, _b;
|
|
36
36
|
const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), opts, {
|
|
37
37
|
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
38
38
|
stdio: 'pipe',
|
|
39
|
-
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_CODE_LOCATION: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: details.httpPort.toString(), CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
39
|
+
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: (_a = details.target) === null || _a === void 0 ? void 0 : _a.id, X_ZOHO_CATALYST_CODE_LOCATION: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: details.httpPort.toString(), CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
40
40
|
}).RAW();
|
|
41
41
|
child.on('spawn', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
42
|
yield (0, http_functions_1.checkIfRuntimeServerRunning)(details.httpPort.toString());
|
|
43
43
|
}));
|
|
44
44
|
const errData = [];
|
|
45
|
-
(
|
|
45
|
+
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (chunk) => {
|
|
46
46
|
errData.push(chunk);
|
|
47
47
|
});
|
|
48
48
|
child.on('error', (err) => {
|
|
Binary file
|
|
@@ -276,7 +276,7 @@ public class JavacronInvoker {
|
|
|
276
276
|
Method runner = cls.getMethod("handleCronExecute", CronRequest.class, Context.class);
|
|
277
277
|
CRON_STATUS cronStatus = null;
|
|
278
278
|
|
|
279
|
-
if(System.getenv("DEBUG").equals("false")) {
|
|
279
|
+
if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
|
|
280
280
|
Timer executionTimer = new Timer(true);
|
|
281
281
|
executionTimer.schedule(new TimerTask() {
|
|
282
282
|
@Override
|
|
Binary file
|
|
@@ -259,6 +259,7 @@ public class JavaeventInvoker {
|
|
|
259
259
|
defaultEvent.setSource(String.valueOf(userData.get("source")));
|
|
260
260
|
defaultEvent.setSourceEntityId(sourceId == "null" ? null : Long.valueOf(sourceId));
|
|
261
261
|
defaultEvent.setTime(eventTime == "null" ? null : Long.valueOf(eventTime));
|
|
262
|
+
defaultEvent.setRawData(userData);
|
|
262
263
|
|
|
263
264
|
EventRequest eventRequest = defaultEvent;
|
|
264
265
|
|
|
@@ -268,7 +269,7 @@ public class JavaeventInvoker {
|
|
|
268
269
|
Method runner = cls.getMethod("handleEvent", EventRequest.class, Context.class);
|
|
269
270
|
EVENT_STATUS eventStatus = null;
|
|
270
271
|
|
|
271
|
-
if(System.getenv("DEBUG").equals("false")) {
|
|
272
|
+
if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
|
|
272
273
|
Timer executionTimer = new Timer(true);
|
|
273
274
|
executionTimer.schedule(new TimerTask() {
|
|
274
275
|
@Override
|
|
Binary file
|
|
@@ -55,6 +55,7 @@ const eventReq = {
|
|
|
55
55
|
getSourceEntityId: () => userData.source_entity_id,
|
|
56
56
|
getEventBusDetails: () => userData.event_bus_details,
|
|
57
57
|
getProjectDetails: () => userData.project_details,
|
|
58
|
+
getRawData: () => userData,
|
|
58
59
|
/**
|
|
59
60
|
* @deprecated use individual get methods.
|
|
60
61
|
*/
|
|
@@ -14,6 +14,9 @@ import java.nio.file.Path;
|
|
|
14
14
|
import java.nio.file.Paths;
|
|
15
15
|
import java.util.HashMap;
|
|
16
16
|
import java.util.Iterator;
|
|
17
|
+
import java.util.Timer;
|
|
18
|
+
import java.util.TimerTask;
|
|
19
|
+
import java.util.concurrent.TimeoutException;
|
|
17
20
|
import java.util.logging.Handler;
|
|
18
21
|
import java.util.logging.LogManager;
|
|
19
22
|
import java.util.logging.LogRecord;
|
|
@@ -231,6 +234,17 @@ public class JavaintegInvoker {
|
|
|
231
234
|
|
|
232
235
|
Method runner = cls.getMethod("runner", ZCIntegRequest.class);
|
|
233
236
|
ZCIntegResponse integResponse = null;
|
|
237
|
+
|
|
238
|
+
if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
|
|
239
|
+
Timer executionTimer = new Timer(true);
|
|
240
|
+
executionTimer.schedule(new TimerTask() {
|
|
241
|
+
@Override
|
|
242
|
+
public void run() {
|
|
243
|
+
throwAndExit(new TimeoutException("function execution timeout"), 408, invokerDir);
|
|
244
|
+
}
|
|
245
|
+
}, 900000L); // 15 mins
|
|
246
|
+
}
|
|
247
|
+
|
|
234
248
|
try {
|
|
235
249
|
integResponse = (ZCIntegResponse) runner.invoke(cls.getDeclaredConstructor().newInstance(), integRequest);
|
|
236
250
|
} catch (Exception e) {
|
|
Binary file
|
|
@@ -20,6 +20,19 @@ const writeAndExit = (resp) => {
|
|
|
20
20
|
process.exit(0);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* execution timeout of 15 minutes
|
|
25
|
+
*/
|
|
26
|
+
const timeout = 15 * 60 * 1000;
|
|
27
|
+
// const endTime = timeout + Date.now();
|
|
28
|
+
|
|
29
|
+
// exit on timeout
|
|
30
|
+
process.env.DEBUG === 'false' &&
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
writeToFile('TIMEOUT', 408);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}, timeout);
|
|
35
|
+
|
|
23
36
|
const integrationRequest = data || {};
|
|
24
37
|
|
|
25
38
|
integrationRequest.catalystHeaders = Object.assign(projectJson, authJson);
|