zcatalyst-cli 1.18.0-beta.0 → 1.18.0-beta.1

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.
Files changed (115) hide show
  1. package/docs/commands/event/generate/job.toml +7 -0
  2. package/docs/endpoints/lib/job-scheduling.toml +3 -0
  3. package/docs/internal/command.toml +5 -0
  4. package/lib/appsail-utils.js +4 -10
  5. package/lib/authentication/index.js +1 -0
  6. package/lib/bin/catalyst.js +1 -1
  7. package/lib/command_needs/rc.js +1 -1
  8. package/lib/commands/appsail/add.js +1 -0
  9. package/lib/commands/client/setup.js +1 -0
  10. package/lib/commands/event/generate/index.js +2 -1
  11. package/lib/commands/event/generate/integ.js +2 -1
  12. package/lib/commands/event/generate/job.js +82 -0
  13. package/lib/commands/functions/add.js +1 -0
  14. package/lib/commands/functions/delete.js +2 -4
  15. package/lib/commands/functions/setup.js +1 -0
  16. package/lib/commands/functions/shell.js +1 -0
  17. package/lib/commands/index.js +3 -1
  18. package/lib/commands/init.js +2 -6
  19. package/lib/commands/login.js +1 -0
  20. package/lib/commands/logout.js +1 -0
  21. package/lib/commands/pull.js +1 -0
  22. package/lib/commands/serve.js +1 -1
  23. package/lib/commands/whoami.js +1 -0
  24. package/lib/deploy/features/appsail/index.js +19 -17
  25. package/lib/deploy/features/appsail/utils.js +4 -5
  26. package/lib/endpoints/index.js +8 -1
  27. package/lib/endpoints/lib/appsail.js +7 -1
  28. package/lib/endpoints/lib/job-scheduling.js +61 -0
  29. package/lib/express_middlewares/logger.js +2 -4
  30. package/lib/fn-utils/lib/common.js +2 -3
  31. package/lib/fn-utils/lib/java.js +1 -1
  32. package/lib/fn-utils/lib/python.js +2 -2
  33. package/lib/fn-watcher.js +1 -1
  34. package/lib/init/dependencies/python/ensure-python.js +6 -8
  35. package/lib/init/features/appsail/index.js +14 -10
  36. package/lib/init/features/client/index.js +2 -1
  37. package/lib/init/features/functions/index.js +4 -0
  38. package/lib/init/features/functions/languages/python.js +21 -5
  39. package/lib/internal/api.js +12 -1
  40. package/lib/internal/command.js +30 -6
  41. package/lib/migration/index.js +4 -2
  42. package/lib/optional-import.js +3 -2
  43. package/lib/prompt/types/tree.js +3 -3
  44. package/lib/serve/features/appsail.js +2 -3
  45. package/lib/serve/index.js +1 -2
  46. package/lib/serve/server/index.js +8 -9
  47. package/lib/serve/server/lib/appsail/index.js +24 -34
  48. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  49. package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  50. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  51. package/lib/serve/server/lib/java/index.js +2 -2
  52. package/lib/serve/server/lib/master/appsail.js +53 -0
  53. package/lib/serve/server/lib/master/functions.js +34 -0
  54. package/lib/serve/server/lib/master/index.js +155 -0
  55. package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
  56. package/lib/serve/server/lib/master/utils.js +130 -0
  57. package/lib/serve/server/lib/master/web-client.js +39 -0
  58. package/lib/serve/server/lib/node/index.js +3 -3
  59. package/lib/serve/server/lib/python/index.js +3 -3
  60. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  61. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  62. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +2 -1
  63. package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  64. package/lib/shell/dependencies/invoker/event/node.mjs +1 -0
  65. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  66. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +254 -0
  67. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  68. package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
  69. package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
  70. package/lib/shell/dependencies/local-function.js +121 -13
  71. package/lib/shell/index.js +7 -1
  72. package/lib/shell/prepare/languages/index.js +4 -4
  73. package/lib/shell/prepare/languages/java.js +1 -2
  74. package/lib/shell/prepare/languages/python.js +10 -16
  75. package/lib/throbber/index.js +6 -1
  76. package/lib/userConfig.js +7 -1
  77. package/lib/util_modules/config/index.js +1 -1
  78. package/lib/util_modules/config/lib/{appSail.js → appsail.js} +61 -9
  79. package/lib/util_modules/config/lib/client.js +6 -8
  80. package/lib/util_modules/config/lib/functions.js +6 -8
  81. package/lib/util_modules/constants/lib/default.js +9 -9
  82. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  83. package/lib/util_modules/constants/lib/needed-scopes.js +53 -44
  84. package/lib/util_modules/constants/lib/placeholders.js +6 -0
  85. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  86. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  87. package/lib/util_modules/constants/lib/scopes.js +5 -1
  88. package/lib/util_modules/constants/lib/template.js +9 -4
  89. package/lib/util_modules/constants/lib/urls.js +8 -0
  90. package/lib/util_modules/fs/lib/async.js +7 -2
  91. package/lib/util_modules/fs/lib/sync.js +12 -1
  92. package/lib/util_modules/server.js +2 -4
  93. package/lib/winston.js +17 -11
  94. package/package.json +1 -1
  95. package/templates/event/job.json +30 -0
  96. package/templates/init/functions/java/job/.classpath +6 -0
  97. package/templates/init/functions/java/job/.project +17 -0
  98. package/templates/init/functions/java/job/catalyst-config.json +11 -0
  99. package/templates/init/functions/java/job/sample.java +34 -0
  100. package/templates/init/functions/node/aio/package.json +1 -1
  101. package/templates/init/functions/node/bio/package.json +1 -1
  102. package/templates/init/functions/node/cron/package.json +1 -1
  103. package/templates/init/functions/node/event/package.json +1 -1
  104. package/templates/init/functions/node/integ/cliq/package.json +1 -1
  105. package/templates/init/functions/node/integ/convokraft/package.json +1 -1
  106. package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
  107. package/templates/init/functions/node/{stream → job}/package.json +1 -1
  108. package/templates/init/functions/node/job/sample.js +28 -0
  109. package/templates/init/functions/node/job/types/job.d.ts +66 -0
  110. package/templates/init/functions/python/job/catalyst-config.json +11 -0
  111. package/templates/init/functions/python/job/requirements.txt +1 -0
  112. package/templates/init/functions/python/job/sample.py +23 -0
  113. package/templates/init.txt +13 -0
  114. package/lib/serve/server/lib/master.js +0 -326
  115. package/templates/init/functions/node/stream/sample.js +0 -15
@@ -23,7 +23,7 @@ const logger_1 = require("../../../../util_modules/logger");
23
23
  const project_1 = require("../../../../util_modules/project");
24
24
  const shell_1 = require("../../../../util_modules/shell");
25
25
  exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
26
- var _a, _b, _c, _d, _e;
26
+ var _a, _b, _c, _d, _e, _f;
27
27
  const projectRoot = runtime_store_1.default.get('project.root');
28
28
  const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
29
29
  const targetDir = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
@@ -54,6 +54,6 @@ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, fun
54
54
  return (0, shell_1.spawn)(spawnCommand, opts, {
55
55
  cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
56
56
  stdio: 'pipe',
57
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, 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)
57
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_f = details.target) === null || _f === void 0 ? void 0 : _f.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
58
58
  }).RAW();
59
59
  });
@@ -0,0 +1,53 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addAppSailRoutes = void 0;
13
+ const utils_1 = require("./utils");
14
+ function addAppSailRoutes(app, details, proxy, unknownProxy) {
15
+ var _a, _b;
16
+ app.use('/__catalyst/sdk/init.js', (req, res) => __awaiter(this, void 0, void 0, function* () {
17
+ const initJs = yield (0, utils_1.appsailInitJs)();
18
+ const _write = res.write;
19
+ res.write = () => {
20
+ res.setHeader('Content-Length', initJs.length);
21
+ return _write.call(res, initJs, 'utf-8');
22
+ };
23
+ req.url = req.originalUrl;
24
+ unknownProxy(req, res);
25
+ }));
26
+ app.use('/baas/logout', (req, res) => {
27
+ req.url = req.originalUrl;
28
+ unknownProxy(req, res);
29
+ });
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(['/__catalyst', '/accounts', '/oauthorize'], (req, res) => {
32
+ if (req.url.includes('/appsail/logout_redirect')) {
33
+ res.redirect(typeof req.query.service_url === 'string' ? req.query.service_url : '/');
34
+ return;
35
+ }
36
+ req.url = req.originalUrl;
37
+ unknownProxy(req, res);
38
+ });
39
+ app.use('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
40
+ var _c, _d;
41
+ if (req.header('catalyst-component') === 'true') {
42
+ ((_d = (_c = details.target) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.catalyst_auth) === true
43
+ ? unknownProxy(req, res)
44
+ : res.sendStatus(400);
45
+ return;
46
+ }
47
+ proxy.web(req, res, {
48
+ target: `http://127.0.0.1:${details.target.port.appsail}`,
49
+ ws: true
50
+ });
51
+ }));
52
+ }
53
+ exports.addAppSailRoutes = addAppSailRoutes;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addFnRoutes = void 0;
4
+ const constants_1 = require("../../../../util_modules/constants");
5
+ function addFnRoutes(app, details, proxy) {
6
+ const fnTarget = details.target;
7
+ app.use(`/server/${fnTarget.name}`, (req, res) => {
8
+ proxy.web(req, res, {
9
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.name}/execute` : ''}`,
10
+ ws: true
11
+ });
12
+ });
13
+ app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
14
+ proxy.web(req, res, {
15
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.name}/execute` : ''}`,
16
+ ws: true
17
+ });
18
+ });
19
+ if (fnTarget.id) {
20
+ app.use(`/server/${fnTarget.id}`, (req, res) => {
21
+ proxy.web(req, res, {
22
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.id}/execute` : ''}`,
23
+ ws: true
24
+ });
25
+ });
26
+ app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
27
+ proxy.web(req, res, {
28
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.id}/execute` : ''}`,
29
+ ws: true
30
+ });
31
+ });
32
+ }
33
+ }
34
+ exports.addFnRoutes = addFnRoutes;
@@ -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;
@@ -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("../runtime-store"));
7
- const logger_1 = require("../util_modules/logger");
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
- const masterPort = runtime_store_1.default.get('context.port.http.master', 3000);
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 _g = details.target, { ['watcher']: _ } = _g, serialisableTarget = __rest(_g, ['watcher']);
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
- (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
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) => {
@@ -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
@@ -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
  */