zcatalyst-cli 1.17.6 → 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 (124) hide show
  1. package/docs/commands/event/generate/job.toml +7 -0
  2. package/docs/commands/functions/shell.toml +4 -0
  3. package/docs/endpoints/lib/job-scheduling.toml +3 -0
  4. package/docs/internal/command.toml +5 -0
  5. package/docs/shell/dependencies/tunnel-server.toml +4 -0
  6. package/docs/shell/index.toml +7 -0
  7. package/lib/appsail-utils.js +3 -3
  8. package/lib/authentication/index.js +1 -0
  9. package/lib/command_needs/rc.js +1 -1
  10. package/lib/commands/appsail/add.js +1 -0
  11. package/lib/commands/client/setup.js +1 -0
  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 +98 -1
  17. package/lib/commands/index.js +1 -0
  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 +2 -8
  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 +15 -1
  27. package/lib/endpoints/lib/appsail.js +7 -1
  28. package/lib/endpoints/lib/job-scheduling.js +61 -0
  29. package/lib/endpoints/lib/sdk.js +2 -2
  30. package/lib/endpoints/lib/tunnel.js +66 -0
  31. package/lib/express_middlewares/logger.js +2 -4
  32. package/lib/fn-utils/lib/common.js +2 -3
  33. package/lib/fn-utils/lib/java.js +1 -1
  34. package/lib/fn-utils/lib/python.js +2 -2
  35. package/lib/fn-watcher.js +1 -1
  36. package/lib/init/dependencies/python/ensure-python.js +6 -8
  37. package/lib/init/features/appsail/index.js +14 -10
  38. package/lib/init/features/functions/index.js +4 -0
  39. package/lib/init/features/functions/languages/python.js +21 -5
  40. package/lib/internal/api.js +17 -1
  41. package/lib/internal/command.js +28 -5
  42. package/lib/port-resolver.js +1 -1
  43. package/lib/repl-server.js +9 -0
  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 +6 -3
  60. package/lib/shell/dependencies/http-functions.js +21 -8
  61. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +28 -32
  62. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  63. package/lib/shell/dependencies/invoker/bio/node.mjs +2 -2
  64. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +62 -13
  65. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  66. package/lib/shell/dependencies/invoker/cron/node.mjs +28 -24
  67. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +41 -6
  68. package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  69. package/lib/shell/dependencies/invoker/event/node.mjs +23 -9
  70. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +3 -3
  71. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  72. package/lib/shell/dependencies/invoker/integ/node.mjs +6 -6
  73. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +254 -0
  74. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  75. package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
  76. package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
  77. package/lib/shell/dependencies/local-function.js +399 -200
  78. package/lib/shell/dependencies/tunnel-server.js +173 -0
  79. package/lib/shell/index.js +62 -2
  80. package/lib/shell/prepare/languages/index.js +4 -4
  81. package/lib/shell/prepare/languages/java.js +1 -2
  82. package/lib/shell/prepare/languages/python.js +10 -16
  83. package/lib/throbber/index.js +6 -1
  84. package/lib/userConfig.js +7 -1
  85. package/lib/util_modules/config/index.js +1 -1
  86. package/lib/util_modules/config/lib/{appSail.js → appsail.js} +61 -9
  87. package/lib/util_modules/config/lib/client.js +6 -8
  88. package/lib/util_modules/config/lib/functions.js +6 -8
  89. package/lib/util_modules/constants/index.js +3 -1
  90. package/lib/util_modules/constants/lib/default.js +1 -1
  91. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  92. package/lib/util_modules/constants/lib/needed-scopes.js +61 -0
  93. package/lib/util_modules/constants/lib/placeholders.js +6 -0
  94. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  95. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  96. package/lib/util_modules/constants/lib/scopes.js +9 -1
  97. package/lib/util_modules/constants/lib/template.js +9 -4
  98. package/lib/util_modules/constants/lib/urls.js +16 -0
  99. package/lib/util_modules/fs/lib/async.js +7 -2
  100. package/lib/util_modules/fs/lib/sync.js +12 -1
  101. package/lib/util_modules/server.js +2 -4
  102. package/lib/winston.js +17 -11
  103. package/package.json +1 -1
  104. package/templates/event/job.json +30 -0
  105. package/templates/init/functions/java/job/.classpath +6 -0
  106. package/templates/init/functions/java/job/.project +17 -0
  107. package/templates/init/functions/java/job/catalyst-config.json +11 -0
  108. package/templates/init/functions/java/job/sample.java +34 -0
  109. package/templates/init/functions/node/aio/package.json +1 -1
  110. package/templates/init/functions/node/bio/package.json +1 -1
  111. package/templates/init/functions/node/cron/package.json +1 -1
  112. package/templates/init/functions/node/event/package.json +1 -1
  113. package/templates/init/functions/node/integ/cliq/package.json +1 -1
  114. package/templates/init/functions/node/integ/convokraft/package.json +1 -1
  115. package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
  116. package/templates/init/functions/node/{stream → job}/package.json +1 -1
  117. package/templates/init/functions/node/job/sample.js +28 -0
  118. package/templates/init/functions/node/job/types/job.d.ts +66 -0
  119. package/templates/init/functions/python/job/catalyst-config.json +11 -0
  120. package/templates/init/functions/python/job/requirements.txt +1 -0
  121. package/templates/init/functions/python/job/sample.py +23 -0
  122. package/templates/init.txt +13 -0
  123. package/lib/serve/server/lib/master.js +0 -317
  124. package/templates/init/functions/node/stream/sample.js +0 -15
@@ -1,317 +0,0 @@
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 http_1 = require("http");
17
- const error_1 = __importDefault(require("../../../error"));
18
- const apig_matcher_1 = __importDefault(require("../../../express_middlewares/apig-matcher"));
19
- const auth_checker_1 = __importDefault(require("../../../express_middlewares/auth-checker"));
20
- const authenticator_1 = __importDefault(require("../../../express_middlewares/authenticator"));
21
- const cookie_parser_1 = __importDefault(require("../../../express_middlewares/cookie-parser"));
22
- const error_handler_1 = __importDefault(require("../../../express_middlewares/error-handler"));
23
- const logger_1 = __importDefault(require("../../../express_middlewares/logger"));
24
- const project_1 = __importDefault(require("../../../express_middlewares/project"));
25
- const unknownReqProxy_1 = __importDefault(require("../../../express_middlewares/unknownReqProxy"));
26
- const url_rewriter_1 = __importDefault(require("../../../express_middlewares/url-rewriter"));
27
- const runtime_store_1 = __importDefault(require("../../../runtime-store"));
28
- const constants_1 = require("../../../util_modules/constants");
29
- const js_1 = require("../../../util_modules/js");
30
- const logger_2 = require("../../../util_modules/logger");
31
- const project_2 = require("../../../util_modules/project");
32
- const option_1 = require("../../../util_modules/option");
33
- const server_js_1 = require("../../../util_modules/server.js");
34
- const http_proxy_1 = require("http-proxy");
35
- const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
36
- const redirectByAuth = (req, res, redirectUrl) => {
37
- if (req.headers['x-zc-user-cred-token'] === undefined) {
38
- res.writeHead(302, { Location: redirectUrl });
39
- res.end();
40
- }
41
- else {
42
- res.writeHead(302, { Location: '/app/' });
43
- res.end();
44
- }
45
- };
46
- const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
47
- if (!req.url) {
48
- return;
49
- }
50
- if (req.url.startsWith('/oauthorize')) {
51
- const set = proxyRes.headers['set-cookie'];
52
- if (set) {
53
- const result = Array.isArray(set) ? set.map(removeSecure) : removeSecure(set);
54
- proxyRes.headers['set-cookie'] = result;
55
- }
56
- }
57
- else if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
58
- if (req.url.includes('/signin-redirect')) {
59
- if (systemRoutes === undefined) {
60
- redirectByAuth(req, res, '/app/local-redirect');
61
- return;
62
- }
63
- const sourceRedirectUrl = Object.keys(systemRoutes).find((sourceUrl) => {
64
- const methodByConfig = systemRoutes ? systemRoutes[sourceUrl] : undefined;
65
- if (methodByConfig) {
66
- return !!Object.values(methodByConfig).find((config) => {
67
- return config.name === 'Login Redirect';
68
- });
69
- }
70
- return false;
71
- });
72
- if (sourceRedirectUrl === undefined) {
73
- res.end('INVALID_URL');
74
- return;
75
- }
76
- redirectByAuth(req, res, sourceRedirectUrl);
77
- }
78
- else if (req.url.includes('/logout')) {
79
- const set = proxyRes.headers['set-cookie'];
80
- if (set) {
81
- const result = set.map((cookie) => cookie.replace(new RegExp('Domain=[\\S^;]*', 'g'), 'Domain=localhost;'));
82
- proxyRes.headers['set-cookie'] = result;
83
- }
84
- }
85
- }
86
- else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
87
- const set = proxyRes.headers['set-cookie'];
88
- set
89
- ? set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/')
90
- : ['IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/'];
91
- proxyRes.headers['set-cookie'] = set;
92
- }
93
- };
94
- function spinUpMaster(listenPort, otherServerDetails) {
95
- var _a;
96
- return __awaiter(this, void 0, void 0, function* () {
97
- const projectDetails = {
98
- id: (0, project_2.getProjectId)(),
99
- domain_prefix: (0, project_2.getDomainPrefix)(),
100
- domain: constants_1.ORIGIN.app.replace('https://', ''),
101
- key: (0, project_2.getDomainKey)(),
102
- env_name: (0, project_2.getEnvName)()
103
- };
104
- const rules = runtime_store_1.default.get('context.apig.local.config', -1);
105
- const customProxyUrl = (0, option_1.getOptionValue)('proxy');
106
- const app = (0, express_1.default)();
107
- let systemRoutes;
108
- const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
109
- app.use((0, logger_1.default)((_a = otherServerDetails.appSail) === null || _a === void 0 ? void 0 : _a.at(0)));
110
- app.use(cookie_parser_1.default);
111
- app.use((0, project_1.default)(projectDetails));
112
- app.use(authenticator_1.default);
113
- app.use(nonApigURL, (req, res) => {
114
- req.url = req.originalUrl;
115
- (0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
116
- });
117
- app.use('*/.catalyst%2Freload-script.js', (req, res) => {
118
- var _a;
119
- req.url = '/.catalyst%2Freload-script.js';
120
- (_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
121
- const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
122
- proxy.web(req, res, {
123
- target: appTarget,
124
- changeOrigin: true
125
- });
126
- });
127
- });
128
- if (rules !== -1) {
129
- for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
130
- const router = app.route(sourceURL);
131
- for (const [method, config] of Object.entries(methodByConfig)) {
132
- if (config.system) {
133
- if (systemRoutes === undefined) {
134
- systemRoutes = {};
135
- }
136
- js_1.JS.set(systemRoutes, [sourceURL, method], config);
137
- }
138
- router[method]((req, res, next) => {
139
- if (res.locals.apigRules === undefined) {
140
- res.locals.apigRules = [];
141
- }
142
- res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
143
- next();
144
- });
145
- }
146
- }
147
- app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
148
- }
149
- const proxy = (0, http_proxy_1.createProxyServer)({
150
- hostRewrite: `localhost:${listenPort}`,
151
- protocolRewrite: 'http'
152
- })
153
- .on('error', (err, req, res) => {
154
- if (res.writableEnded) {
155
- return;
156
- }
157
- if (res instanceof http_1.ServerResponse) {
158
- res.writeHead(502, { 'Content-Type': 'json' });
159
- }
160
- res.end(JSON.stringify({ error: 'unable to serve the request' }));
161
- console.log();
162
- console.log('Unable to reach the servers to serve the request: ', req.url);
163
- console.error(err);
164
- })
165
- .on('econnreset', (err, req, res, targetUrl) => {
166
- if (res.writableEnded) {
167
- return;
168
- }
169
- if (res instanceof http_1.ServerResponse) {
170
- res.writeHead(502, { 'Content-Type': 'json' });
171
- }
172
- res.end(JSON.stringify({ error: 'unable to serve the request. ECONNRESET.' }));
173
- console.log();
174
- console.log('Connection reset while trying to serve the request ', req.url);
175
- (0, logger_2.debug)('Connection reset from target URL : ', targetUrl);
176
- console.error(err);
177
- })
178
- .on('proxyRes', proxyResponseHandler(systemRoutes))
179
- .on('close', () => (0, logger_2.debug)('proxy closed'));
180
- const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
181
- Object.keys(otherServerDetails).forEach((targ) => {
182
- var _a, _b, _c, _d;
183
- switch (targ) {
184
- case 'client': {
185
- (_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
186
- const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
187
- app.use('/app', (req, res) => {
188
- const target = clientDetails.target;
189
- if (req.url === '/' && target.homepage.includes('/__catalyst')) {
190
- req.url = target.homepage;
191
- (0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
192
- }
193
- else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
194
- const isUrl = target.login_redirect.startsWith('/');
195
- if (isUrl) {
196
- res.redirect(target.login_redirect);
197
- }
198
- else {
199
- res.redirect('/app/' + target.login_redirect);
200
- }
201
- }
202
- else {
203
- proxy.web(req, res, {
204
- target: appTarget,
205
- changeOrigin: true
206
- });
207
- }
208
- });
209
- const appTargetUrl = new URL(appTarget);
210
- appTargetUrl.pathname = '';
211
- appTargetUrl.protocol = 'ws';
212
- app.addListener('upgrade', (...upgradeParam) => {
213
- proxy.ws(upgradeParam[0], upgradeParam[1], upgradeParam[2], {
214
- target: appTargetUrl.href,
215
- ws: true,
216
- changeOrigin: true
217
- });
218
- });
219
- });
220
- break;
221
- }
222
- case 'server': {
223
- (_b = otherServerDetails.server) === null || _b === void 0 ? void 0 : _b.forEach((serverDetail) => {
224
- var _a;
225
- app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
226
- proxy.web(req, res, {
227
- target: `http://127.0.0.1:${serverDetail.httpPort}`
228
- });
229
- });
230
- });
231
- break;
232
- }
233
- case 'functions': {
234
- (_c = otherServerDetails.functions) === null || _c === void 0 ? void 0 : _c.forEach((fnDetails) => {
235
- const fnTarget = fnDetails.target;
236
- app.use(`/server/${fnTarget.name}`, (req, res) => {
237
- proxy.web(req, res, {
238
- target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
239
- ? `/server/${fnTarget.name}/execute`
240
- : ''}`,
241
- ws: true
242
- });
243
- });
244
- app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
245
- proxy.web(req, res, {
246
- target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
247
- ? `/server/${fnTarget.name}/execute`
248
- : ''}`,
249
- ws: true
250
- });
251
- });
252
- if (fnTarget.id) {
253
- app.use(`/server/${fnTarget.id}`, (req, res) => {
254
- proxy.web(req, res, {
255
- target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
256
- ? `/server/${fnTarget.id}/execute`
257
- : ''}`,
258
- ws: true
259
- });
260
- });
261
- app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
262
- proxy.web(req, res, {
263
- target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
264
- ? `/server/${fnTarget.id}/execute`
265
- : ''}`,
266
- ws: true
267
- });
268
- });
269
- }
270
- });
271
- break;
272
- }
273
- case 'appSail': {
274
- (_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.forEach((appSailDetails) => {
275
- app.use('/', (req, res) => {
276
- var _a;
277
- if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/__catalyst/sdk/init.js')) {
278
- (0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
279
- }
280
- else {
281
- proxy.web(req, res, {
282
- target: `http://127.0.0.1:${appSailDetails.target.port
283
- .appsail}`,
284
- ws: true
285
- });
286
- }
287
- });
288
- });
289
- break;
290
- }
291
- default:
292
- throw new error_1.default('Unknown type provided to master server ' + targ, {
293
- exit: 2
294
- });
295
- }
296
- });
297
- app.use('/', (0, unknownReqProxy_1.default)(proxy, customProxyUrl));
298
- app.use(error_handler_1.default);
299
- const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
300
- if (proxy) {
301
- proxyDestroyer.destroy();
302
- }
303
- console.error(err);
304
- });
305
- const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
306
- expressServer.maxConnections = 100;
307
- process.on('SIGINT', () => expressDestroyer.destroy(false));
308
- expressServer.on('close', () => __awaiter(this, void 0, void 0, function* () {
309
- yield proxyDestroyer.destroy().catch((err) => (0, logger_2.debug)(err));
310
- }));
311
- expressServer.on('upgrade', (...upgradeParam) => {
312
- app.emit('upgrade', ...upgradeParam);
313
- });
314
- return expressServer;
315
- });
316
- }
317
- exports.default = spinUpMaster;
@@ -1,15 +0,0 @@
1
- module.exports = (inputStream, outputStream, context) => {
2
- console.log('Hello from {{_MAIN_}}');
3
-
4
- // inputStream.getContentType();
5
- // inputStream.getContentLength();
6
- // inputStream.getParameter('name');
7
-
8
- let response = 'stream response';
9
- outputStream.setContentType('text/plain');
10
- outputStream.setStatus(201);
11
- outputStream.setContentLength(response.length);
12
- outputStream.getStream().write(response);
13
-
14
- context.close();
15
- };