zcatalyst-cli 1.15.0-beta.3 → 1.15.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.
Files changed (121) hide show
  1. package/lib/appsail-utils.js +84 -0
  2. package/lib/archiver.js +18 -1
  3. package/lib/code-deck.js +114 -0
  4. package/lib/command_needs/rc.js +7 -6
  5. package/lib/commands/appsail/add.js +55 -0
  6. package/lib/commands/codelib/install.js +143 -0
  7. package/lib/commands/config/set.js +1 -1
  8. package/lib/commands/deploy/appsail.js +62 -0
  9. package/lib/commands/{deploy.js → deploy/index.js} +20 -14
  10. package/lib/commands/iac/pack.js +3 -3
  11. package/lib/commands/index.js +2 -0
  12. package/lib/commands/init.js +5 -1
  13. package/lib/commands/pull.js +1 -1
  14. package/lib/commands/serve.js +1 -1
  15. package/lib/commands/whoami.js +2 -1
  16. package/lib/deploy/features/appsail/index.js +246 -0
  17. package/lib/deploy/features/appsail/utils.js +91 -0
  18. package/lib/deploy/features/functions/index.js +12 -10
  19. package/lib/deploy/features/index.js +3 -0
  20. package/lib/deploy/index.js +3 -3
  21. package/lib/endpoints/index.js +22 -1
  22. package/lib/endpoints/lib/appsail.js +98 -0
  23. package/lib/endpoints/lib/code-deck.js +71 -0
  24. package/lib/endpoints/lib/common.js +8 -5
  25. package/lib/endpoints/lib/git-hub.js +148 -0
  26. package/lib/endpoints/lib/iac.js +15 -0
  27. package/lib/endpoints/lib/sdk.js +4 -1
  28. package/lib/execute-script.js +35 -27
  29. package/lib/fn-utils/lib/browserLogic.js +17 -20
  30. package/lib/fn-utils/lib/common.js +3 -4
  31. package/lib/fn-utils/lib/integ.js +3 -3
  32. package/lib/fn-utils/lib/java.js +7 -1
  33. package/lib/fn-watcher.js +3 -0
  34. package/lib/iac/status/deploy.js +26 -4
  35. package/lib/iac/status/util/index.js +3 -0
  36. package/lib/init/dependencies/python/ensure-python.js +2 -2
  37. package/lib/init/dependencies/python/pip-install.js +4 -4
  38. package/lib/init/features/appsail/index.js +213 -0
  39. package/lib/init/features/functions/index.js +5 -72
  40. package/lib/init/features/functions/languages/java.js +7 -3
  41. package/lib/init/features/functions/languages/node.js +9 -7
  42. package/lib/init/features/functions/languages/python.js +1 -1
  43. package/lib/init/features/index.js +28 -12
  44. package/lib/init/features/project.js +3 -3
  45. package/lib/init/index.js +1 -1
  46. package/lib/init/util/common.js +103 -0
  47. package/lib/internal/api.js +5 -5
  48. package/lib/internal/command.js +26 -3
  49. package/lib/option-filter.js +40 -21
  50. package/lib/prompt/index.js +5 -0
  51. package/lib/prompt/types/file-path.js +4 -1
  52. package/lib/prompt/types/tree.js +297 -0
  53. package/lib/pull/features/functions/index.js +70 -47
  54. package/lib/serve/features/appsail.js +37 -0
  55. package/lib/serve/features/index.js +8 -1
  56. package/lib/serve/index.js +23 -6
  57. package/lib/serve/server/index.js +111 -233
  58. package/lib/serve/server/lib/appsail/index.js +134 -0
  59. package/lib/serve/server/lib/appsail/start.js +75 -0
  60. package/lib/serve/server/lib/java/index.js +54 -0
  61. package/lib/serve/server/lib/master.js +84 -60
  62. package/lib/serve/server/lib/node/index.js +85 -74
  63. package/lib/serve/server/lib/node/server/index.js +77 -0
  64. package/lib/serve/server/lib/python/index.js +46 -0
  65. package/lib/serve/server/lib/web_client/index.js +33 -0
  66. package/lib/serve/server/lib/web_client/server.js +3 -0
  67. package/lib/shell/dependencies/http-functions.js +7 -7
  68. package/lib/shell/dependencies/local-function.js +6 -6
  69. package/lib/shell/prepare/index.js +1 -1
  70. package/lib/shell/prepare/languages/index.js +3 -3
  71. package/lib/shell/prepare/languages/java.js +2 -2
  72. package/lib/util_modules/config/index.js +3 -1
  73. package/lib/util_modules/config/lib/appSail.js +89 -0
  74. package/lib/util_modules/constants/index.js +3 -1
  75. package/lib/util_modules/constants/lib/default.js +4 -2
  76. package/lib/util_modules/constants/lib/file-names.js +4 -1
  77. package/lib/util_modules/constants/lib/runtime.js +12 -3
  78. package/lib/util_modules/constants/lib/scopes.js +4 -0
  79. package/lib/util_modules/constants/lib/template.js +23 -20
  80. package/lib/util_modules/constants/lib/urls.js +5 -0
  81. package/lib/util_modules/context-help.js +3 -0
  82. package/lib/util_modules/fs/lib/async.js +10 -3
  83. package/lib/util_modules/fs/lib/sync.js +2 -2
  84. package/lib/util_modules/js.js +4 -0
  85. package/lib/util_modules/project.js +2 -2
  86. package/lib/util_modules/server.js +2 -1
  87. package/package.json +1 -1
  88. package/scripts/postInstall.js +27 -18
  89. package/templates/init/functions/java/browserLogic/playwright/sample.java +1 -1
  90. package/templates/init/functions/java/browserLogic/selenium/sample.java +1 -1
  91. package/templates/init/functions/node/browserlogic/playwright/sample.js +1 -1
  92. package/templates/init/functions/node/browserlogic/puppeteer/sample.js +1 -1
  93. package/templates/init/functions/node/browserlogic/selenium/sample.js +1 -1
  94. package/templates/init/functions/python/aio/requirements.txt +1 -1
  95. package/templates/init/functions/python/bio/requirements.txt +1 -1
  96. package/templates/init/functions/python/cron/requirements.txt +1 -1
  97. package/templates/init/functions/python/event/requirements.txt +1 -1
  98. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -1
  99. /package/lib/serve/server/lib/java/{JavaaioServer.java → aio_server/JavaaioServer.java} +0 -0
  100. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  101. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/catalyst-function-sdk-1.0.0.jar +0 -0
  102. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/catalyst-java-runtime-1.0.0.jar +0 -0
  103. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/gradle-wrapper.jar +0 -0
  104. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-http-9.3.24.v20180605.jar +0 -0
  105. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-io-9.3.24.v20180605.jar +0 -0
  106. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-security-9.3.24.v20180605.jar +0 -0
  107. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-server-9.3.24.v20180605.jar +0 -0
  108. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-servlet-9.3.24.v20180605.jar +0 -0
  109. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/jetty-util-9.3.24.v20180605.jar +0 -0
  110. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/org.json.jar +0 -0
  111. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/servlet-api-3.1.jar +0 -0
  112. /package/lib/serve/server/lib/java/{lib → aio_server/lib}/zip4j-2.5.0.jar +0 -0
  113. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/browserlogic-playwright.js +0 -0
  114. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/browserlogic-puppeteer.js +0 -0
  115. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/browserlogic-selenium.js +0 -0
  116. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/index.js +0 -0
  117. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/deferred_promise.js +0 -0
  118. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/playwright-handler.js +0 -0
  119. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/puppeteer-handler.js +0 -0
  120. /package/lib/serve/server/lib/node/{browserlogic → server/browserlogic}/utils/selenium-handler.js +0 -0
  121. /package/lib/serve/server/lib/node/{package.json → server/package.json} +0 -0
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ const EXEC_SYNC = require('child_process').execSync;
4
+
5
+ const WAR = 'war';
6
+ const JAVASE = 'javase';
7
+ const NODEJS = 'nodejs';
8
+ const PYTHON = 'python';
9
+
10
+ // const WAR_DEFAULT = "";
11
+ const JAVASE_DEFAULT = 'java Main';
12
+ const NODEJS_DEFAULT = 'node main.js';
13
+ const PYTHON_DEFAULT = 'python main.py';
14
+
15
+ function parseCmdArg() {
16
+ const args = {};
17
+
18
+ for (let i = 0; i < process.argv.length; i++) {
19
+ switch (process.argv[i]) {
20
+ case '-t':
21
+ case '--type':
22
+ args.rtType = process.argv[i + 1];
23
+ break;
24
+ case '-c':
25
+ case '--command':
26
+ args.command = process.argv.slice(i + 1);
27
+ break;
28
+ default:
29
+ break;
30
+ }
31
+ }
32
+
33
+ return args;
34
+ }
35
+
36
+ function getWarCommand(command) {
37
+ if (process.env.JAVA_OPTS) {
38
+ command += ` ${process.env.JAVA_OPTS}`;
39
+ }
40
+
41
+ const DRYRUN_OUTPUT = EXEC_SYNC(command.toString(), {
42
+ stdio: 'pipe',
43
+ cwd: process.env.JETTY_BASE
44
+ }).toString();
45
+ return `java ${DRYRUN_OUTPUT}`;
46
+ }
47
+
48
+ function main() {
49
+ const CMD_ARGS = parseCmdArg();
50
+
51
+ let command = '';
52
+ switch (CMD_ARGS.rtType) {
53
+ case WAR:
54
+ if (!CMD_ARGS.command) {
55
+ throw new Error(`command not found`);
56
+ }
57
+ command = getWarCommand(CMD_ARGS.command);
58
+ break;
59
+ case JAVASE:
60
+ command = CMD_ARGS.command || JAVASE_DEFAULT;
61
+ break;
62
+ case NODEJS:
63
+ command = CMD_ARGS.command || NODEJS_DEFAULT;
64
+ break;
65
+ case PYTHON:
66
+ command = CMD_ARGS.command || PYTHON_DEFAULT;
67
+ break;
68
+ default:
69
+ throw new Error(`invalid runtime type: ${CMD_ARGS.rtType}`);
70
+ }
71
+
72
+ EXEC_SYNC(command.toString(), { stdio: 'inherit' });
73
+ }
74
+
75
+ main();
@@ -0,0 +1,54 @@
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 path_1 = require("path");
16
+ const fn_utils_1 = require("../../../../fn-utils");
17
+ const plugin_loader_1 = __importDefault(require("../../../../plugin-loader"));
18
+ const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
19
+ const constants_1 = require("../../../../util_modules/constants");
20
+ const logger_1 = require("../../../../util_modules/logger");
21
+ const project_1 = require("../../../../util_modules/project");
22
+ const shell_1 = require("../../../../util_modules/shell");
23
+ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
24
+ var _a, _b, _c;
25
+ const cwd = runtime_store_1.default.get('cwd');
26
+ const javaServer = (0, path_1.join)(cwd, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
27
+ const targetDir = (0, path_1.join)(cwd, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
28
+ const label = `${details.type}[${(_b = details.target) === null || _b === void 0 ? void 0 : _b.name}]`;
29
+ const opts = [
30
+ '-cp',
31
+ (0, path_1.join)(targetDir, '*') + fn_utils_1.fnUtils.java.classPathSep + targetDir + path_1.sep,
32
+ `-DCATALYST_FUNCTION_TYPE=${constants_1.REMOTE_REF.functions.type[details.target.type]}`
33
+ ];
34
+ if (details.debugPort !== -1) {
35
+ (0, logger_1.labeled)(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
36
+ opts.push('-Xdebug');
37
+ opts.push('-Xrunjdwp:transport=dt_socket,address=' + details.debugPort + ',server=y,suspend=y');
38
+ }
39
+ opts.push((0, path_1.basename)(javaServer));
40
+ opts.push(details.httpPort + '');
41
+ const targetSource = (_c = details.target) === null || _c === void 0 ? void 0 : _c.source;
42
+ const configType = details.type === 'server' ? 'functions' : details.type;
43
+ const servePlugin = yield (0, plugin_loader_1.default)(configType, 'start', targetSource).catch((err) => (0, logger_1.debug)(err));
44
+ if (typeof servePlugin === 'function') {
45
+ const event = servePlugin(details, masterPort);
46
+ (0, logger_1.labeled)(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
47
+ return event;
48
+ }
49
+ return (0, shell_1.spawn)('java', opts, {
50
+ cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(cwd, (0, path_1.join)(cwd, constants_1.FOLDERNAME.build)),
51
+ stdio: 'pipe',
52
+ 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)
53
+ }).RAW();
54
+ });
@@ -152,88 +152,112 @@ function spinUpMaster(listenPort, otherServerDetails) {
152
152
  .on('proxyRes', proxyResponseHandler(systemRoutes))
153
153
  .on('close', () => (0, logger_2.debug)('proxy closed'));
154
154
  const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
155
- otherServerDetails.forEach((serverDetail) => {
156
- var _a;
157
- switch (serverDetail.type) {
158
- case 'client':
159
- const appTarget = `http://127.0.0.1:${serverDetail.httpPort}/app/`;
160
- app.use('/app', (req, res) => {
161
- const target = serverDetail.target;
162
- if (req.url === '/' && target.homepage.includes('/__catalyst')) {
163
- req.url = target.homepage;
164
- (0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
165
- }
166
- else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
167
- const isUrl = target.login_redirect.startsWith('/');
168
- if (isUrl) {
169
- res.redirect(target.login_redirect);
155
+ Object.keys(otherServerDetails).forEach((targ) => {
156
+ switch (targ) {
157
+ case 'client': {
158
+ otherServerDetails.client.forEach((clientDetails) => {
159
+ const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
160
+ app.use('/app', (req, res) => {
161
+ const target = clientDetails.target;
162
+ if (req.url === '/' && target.homepage.includes('/__catalyst')) {
163
+ req.url = target.homepage;
164
+ (0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
165
+ }
166
+ else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
167
+ const isUrl = target.login_redirect.startsWith('/');
168
+ if (isUrl) {
169
+ res.redirect(target.login_redirect);
170
+ }
171
+ else {
172
+ res.redirect('/app/' + target.login_redirect);
173
+ }
170
174
  }
171
175
  else {
172
- res.redirect('/app/' + target.login_redirect);
176
+ proxy.web(req, res, {
177
+ target: appTarget,
178
+ changeOrigin: true
179
+ });
173
180
  }
174
- }
175
- else {
176
- proxy.web(req, res, {
177
- target: appTarget,
181
+ });
182
+ const appTargetUrl = new URL(appTarget);
183
+ appTargetUrl.pathname = '';
184
+ appTargetUrl.protocol = 'ws';
185
+ app.addListener('upgrade', (...upgradeParam) => {
186
+ proxy.ws(upgradeParam[0], upgradeParam[1], upgradeParam[2], {
187
+ target: appTargetUrl.href,
188
+ ws: true,
178
189
  changeOrigin: true
179
190
  });
180
- }
181
- });
182
- const appTargetUrl = new URL(appTarget);
183
- appTargetUrl.pathname = '';
184
- appTargetUrl.protocol = 'ws';
185
- app.addListener('upgrade', (...upgradeParam) => {
186
- proxy.ws(upgradeParam[0], upgradeParam[1], upgradeParam[2], {
187
- target: appTargetUrl.href,
188
- ws: true,
189
- changeOrigin: true
190
191
  });
191
192
  });
192
193
  break;
193
- case 'server':
194
- app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
195
- proxy.web(req, res, {
196
- target: `http://127.0.0.1:${serverDetail.httpPort}`
194
+ }
195
+ case 'server': {
196
+ otherServerDetails.server.forEach((serverDetail) => {
197
+ var _a;
198
+ app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
199
+ proxy.web(req, res, {
200
+ target: `http://127.0.0.1:${serverDetail.httpPort}`
201
+ });
197
202
  });
198
203
  });
199
204
  break;
200
- case 'functions':
201
- const fnTarget = serverDetail.target;
202
- app.use(`/server/${fnTarget.name}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`, (req, res) => {
203
- proxy.web(req, res, {
204
- target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.name}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
205
- ws: true
206
- });
207
- });
208
- app.use('/baas/v1/project/:projectId/function/' +
209
- fnTarget.name +
210
- (fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''), (req, res) => {
211
- proxy.web(req, res, {
212
- target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.name}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
213
- ws: true
205
+ }
206
+ case 'functions': {
207
+ otherServerDetails.functions.forEach((fnDetails) => {
208
+ const fnTarget = fnDetails.target;
209
+ app.use(`/server/${fnTarget.name}`, (req, res) => {
210
+ proxy.web(req, res, {
211
+ target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
212
+ ? `/server/${fnTarget.name}/execute`
213
+ : ''}`,
214
+ ws: true
215
+ });
214
216
  });
215
- });
216
- if (fnTarget.id) {
217
- app.use('/server/' +
218
- fnTarget.id +
219
- (fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''), (req, res) => {
217
+ app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
220
218
  proxy.web(req, res, {
221
- target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.id}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
219
+ target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
220
+ ? `/server/${fnTarget.name}/execute`
221
+ : ''}`,
222
222
  ws: true
223
223
  });
224
224
  });
225
- app.use('/baas/v1/project/:projectId/function/' +
226
- fnTarget.id +
227
- (fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''), (req, res) => {
225
+ if (fnTarget.id) {
226
+ app.use(`/server/${fnTarget.id}`, (req, res) => {
227
+ proxy.web(req, res, {
228
+ target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
229
+ ? `/server/${fnTarget.id}/execute`
230
+ : ''}`,
231
+ ws: true
232
+ });
233
+ });
234
+ app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
235
+ proxy.web(req, res, {
236
+ target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
237
+ ? `/server/${fnTarget.id}/execute`
238
+ : ''}`,
239
+ ws: true
240
+ });
241
+ });
242
+ }
243
+ });
244
+ break;
245
+ }
246
+ case 'appSail': {
247
+ otherServerDetails.appSail.forEach((appSailDetails) => {
248
+ var _a;
249
+ app.use('/appsail/' +
250
+ ((_a = appSailDetails.target.appSail) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
228
251
  proxy.web(req, res, {
229
- target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.id}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
252
+ target: `http://127.0.0.1:${appSailDetails.target.port}`,
230
253
  ws: true
231
254
  });
232
255
  });
233
- }
256
+ });
234
257
  break;
258
+ }
235
259
  default:
236
- throw new error_1.default('Unknown type provided to master server ' + serverDetail.type, {
260
+ throw new error_1.default('Unknown type provided to master server ' + targ, {
237
261
  exit: 2
238
262
  });
239
263
  }
@@ -1,75 +1,86 @@
1
- 'use strict';
2
-
3
- import express from 'express';
4
- import { inspect } from 'util';
5
- import { pathToFileURL } from 'url';
6
-
7
- const args = process.argv.slice(2);
8
- const listenPort = parseInt(args[0], 10);
9
- const fnDetails = JSON.parse(args[1]);
10
-
11
- const app = express();
12
-
13
- const targetName = fnDetails.name;
14
- const index = pathToFileURL(fnDetails.index);
15
- const type = fnDetails.type;
16
-
17
- app.all('/server/:fnId/execute', async (req, res) => {
18
- try {
19
- if (index === undefined) {
20
- throw new Error(`index of ${type} function is undefined`);
21
- }
22
- if (type !== 'browserlogic') {
23
- throw new Error('Invalid URL pattern for the functions type: ' + type);
24
- }
25
- const userModule = await import(index);
26
- const browserLogic = await import('./browserlogic/index.js');
27
- const browserModule = await browserLogic.default(userModule);
28
- const fnParams = await browserModule.constructFunctionParameters(
29
- req,
30
- res,
31
- fnDetails.source
32
- );
33
- try {
34
- await browserModule.logic(...fnParams);
35
- } catch (err) {
36
- browserModule.close(...fnParams);
37
- }
38
- } catch (er) {
39
- const errorString = inspect(er);
40
- // eslint-disable-next-line no-console
41
- console.error('[' + targetName + '] ' + errorString);
42
- res.writeHead(500);
43
- res.end(errorString);
44
- }
45
- });
46
-
47
- app.all('/*', async (req, res) => {
48
- try {
49
- if (index === undefined) {
50
- throw new Error(`index of ${type} function is undefined`);
51
- }
52
- const userModule = await import(index);
53
- if (type !== 'aio') {
54
- throw new Error('Invalid URL pattern for the functions type: ' + type);
55
- }
56
- if (!('default' in userModule)) {
57
- throw new Error('Could not find any default export');
58
- }
59
- if (typeof userModule.default !== 'function') {
60
- throw new Error('The default export is not a function');
61
- }
62
- await userModule.default(req, res);
63
- } catch (e) {
64
- const errorString = inspect(e);
65
- // eslint-disable-next-line no-console
66
- console.error('[' + targetName + '] ' + errorString);
67
- res.writeHead(500);
68
- res.end(errorString);
69
- }
70
- });
71
-
72
- app.listen(listenPort).on('error', (err) => {
73
- // eslint-disable-next-line no-console
74
- console.error(err);
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 __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const ansi_colors_1 = require("ansi-colors");
27
+ const path_1 = require("path");
28
+ const stream_1 = require("stream");
29
+ const error_1 = __importDefault(require("../../../../error"));
30
+ const plugin_loader_1 = __importDefault(require("../../../../plugin-loader"));
31
+ const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
32
+ const constants_1 = require("../../../../util_modules/constants");
33
+ const logger_1 = require("../../../../util_modules/logger");
34
+ const project_1 = require("../../../../util_modules/project");
35
+ const shell_1 = require("../../../../util_modules/shell");
36
+ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
37
+ var _a, _b;
38
+ const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
39
+ const _c = details.target, { ['watcher']: _ } = _c, serialisableTarget = __rest(_c, ['watcher']);
40
+ const cwd = runtime_store_1.default.get('cwd');
41
+ serialisableTarget.index = serialisableTarget.index
42
+ ? serialisableTarget.index.replace(cwd, (0, path_1.join)(cwd, constants_1.FOLDERNAME.build))
43
+ : undefined;
44
+ const opts = [
45
+ (0, path_1.join)(__dirname, 'server'),
46
+ details.httpPort + '',
47
+ JSON.stringify(serialisableTarget)
48
+ ];
49
+ if (details.debugPort !== -1) {
50
+ (0, logger_1.labeled)(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
51
+ opts.unshift('--inspect=' + details.debugPort);
52
+ }
53
+ const targetSource = (_b = details.target) === null || _b === void 0 ? void 0 : _b.source;
54
+ const servePlugin = yield (0, plugin_loader_1.default)('functions', 'start', targetSource).catch((err) => (0, logger_1.debug)(err));
55
+ if (typeof servePlugin === 'function') {
56
+ const logStreamPlugin = yield (0, plugin_loader_1.default)('functions', 'logs', targetSource).catch((err) => (0, logger_1.debug)(err));
57
+ if (typeof logStreamPlugin === 'function') {
58
+ const stream = yield logStreamPlugin();
59
+ if (stream instanceof stream_1.Stream) {
60
+ const streamLogFn = (chunk) => (0, logger_1.log)('info', chunk.toString(), true);
61
+ stream.on('data', streamLogFn);
62
+ }
63
+ }
64
+ const event = servePlugin(details, masterPort).catch((e) => {
65
+ var _a;
66
+ const err = error_1.default.getErrorInstance(e, {
67
+ fileName: __filename,
68
+ skipHelp: false
69
+ });
70
+ err.errorId = 'SERVE-IDX-1';
71
+ err.arg = [
72
+ 'functions',
73
+ (0, ansi_colors_1.bold)(((_a = details.target.plugins) === null || _a === void 0 ? void 0 : _a.start)[targetSource] || 'start'),
74
+ (0, ansi_colors_1.bold)('Error: ') + ansi_colors_1.italic.red(err.message)
75
+ ];
76
+ throw err;
77
+ });
78
+ (0, logger_1.labeled)(label, `Plugin : "${runtime_store_1.default.get(`context.functions.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
79
+ return event;
80
+ }
81
+ return (0, shell_1.spawn)('node', opts, {
82
+ cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(cwd, (0, path_1.join)(cwd, constants_1.FOLDERNAME.build)),
83
+ stdio: 'pipe',
84
+ 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)
85
+ }).RAW();
75
86
  });
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ import express from 'express';
4
+ import { inspect } from 'util';
5
+ import { pathToFileURL } from 'url';
6
+
7
+ const args = process.argv.slice(2);
8
+ const listenPort = parseInt(args[0], 10);
9
+ const fnDetails = JSON.parse(args[1]);
10
+
11
+ const app = express();
12
+
13
+ const targetName = fnDetails.name;
14
+ const index = pathToFileURL(fnDetails.index);
15
+ const type = fnDetails.type;
16
+
17
+ const aioHandler = async (req, res) => {
18
+ try {
19
+ if (index === undefined) {
20
+ throw new Error(`index of ${type} function is undefined`);
21
+ }
22
+ const userModule = await import(index);
23
+ if (type !== 'aio') {
24
+ throw new Error('Invalid URL pattern for the functions type: ' + type);
25
+ }
26
+ if (!('default' in userModule)) {
27
+ throw new Error('Could not find any default export');
28
+ }
29
+ if (typeof userModule.default !== 'function') {
30
+ throw new Error('The default export is not a function');
31
+ }
32
+ await userModule.default(req, res);
33
+ } catch (e) {
34
+ const errorString = inspect(e);
35
+ // eslint-disable-next-line no-console
36
+ console.error('[' + targetName + '] ' + errorString);
37
+ res.writeHead(500);
38
+ res.end(errorString);
39
+ }
40
+ };
41
+
42
+ const browserLogicHandler = async (req, res) => {
43
+ try {
44
+ if (index === undefined) {
45
+ throw new Error(`index of ${type} function is undefined`);
46
+ }
47
+ if (type !== 'browserlogic') {
48
+ throw new Error('Invalid URL pattern for the functions type: ' + type);
49
+ }
50
+ const userModule = await import(index);
51
+ const browserLogic = await import('./browserlogic/index.js');
52
+ const browserModule = await browserLogic.default(userModule);
53
+ const fnParams = await browserModule.constructFunctionParameters(
54
+ req,
55
+ res,
56
+ fnDetails.source
57
+ );
58
+ try {
59
+ await browserModule.logic(...fnParams);
60
+ } catch (err) {
61
+ browserModule.close(...fnParams);
62
+ }
63
+ } catch (er) {
64
+ const errorString = inspect(er);
65
+ // eslint-disable-next-line no-console
66
+ console.error('[' + targetName + '] ' + errorString);
67
+ res.writeHead(500);
68
+ res.end(errorString);
69
+ }
70
+ };
71
+
72
+ app.use('/', type === 'browserlogic' ? browserLogicHandler : aioHandler);
73
+
74
+ app.listen(listenPort).on('error', (err) => {
75
+ // eslint-disable-next-line no-console
76
+ console.error(err);
77
+ });
@@ -0,0 +1,46 @@
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 path_1 = require("path");
16
+ const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
17
+ const http_functions_1 = require("../../../../shell/dependencies/http-functions");
18
+ const userConfig_1 = __importDefault(require("../../../../userConfig"));
19
+ const constants_1 = require("../../../../util_modules/constants");
20
+ const project_1 = require("../../../../util_modules/project");
21
+ const shell_1 = require("../../../../util_modules/shell");
22
+ const logger_1 = require("../../../../util_modules/logger");
23
+ const util_1 = require("util");
24
+ exports.default = (details) => __awaiter(void 0, void 0, void 0, function* () {
25
+ var _a, _b;
26
+ const projectRoot = runtime_store_1.default.get('project.root');
27
+ const opts = ['-u', 'main.py'];
28
+ const targetSource = (_a = details.target) === null || _a === void 0 ? void 0 : _a.source;
29
+ const runtimesDir = constants_1.ENVPATH.runtimes.data;
30
+ const stackVersion = (_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.replace('python_', '');
31
+ return new Promise((res) => {
32
+ const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), opts, {
33
+ cwd: (0, path_1.join)(runtimesDir, constants_1.RUNTIME.language.python.value, `zcatalyst_runtime_${stackVersion === null || stackVersion === void 0 ? void 0 : stackVersion.replace('_', '')}`),
34
+ stdio: 'pipe',
35
+ 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)
36
+ }).RAW();
37
+ child.on('spawn', () => __awaiter(void 0, void 0, void 0, function* () {
38
+ yield (0, http_functions_1.checkIfRuntimeServerRunning)(details.httpPort.toString());
39
+ }));
40
+ child.on('error', (err) => {
41
+ (0, logger_1.debug)('Python Child spawn error');
42
+ (0, logger_1.debug)((0, util_1.inspect)(err));
43
+ });
44
+ res(child);
45
+ });
46
+ });
@@ -15,9 +15,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const open_1 = __importDefault(require("open"));
16
16
  const logger_1 = require("../../../../util_modules/logger");
17
17
  const server_js_1 = __importDefault(require("./server.js"));
18
+ const plugin_loader_1 = __importDefault(require("../../../../plugin-loader"));
19
+ const stream_1 = require("stream");
20
+ const error_1 = __importDefault(require("../../../../error"));
21
+ const ansi_colors_1 = require("ansi-colors");
22
+ const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
18
23
  exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
19
24
  var _a;
20
25
  const target = details.target;
26
+ const servePlugin = yield (0, plugin_loader_1.default)('client', 'start', target.source).catch((err) => (0, logger_1.debug)(err));
27
+ if (typeof servePlugin === 'function') {
28
+ process.env.X_CATALYST_WEBAPP_PATH = target.source;
29
+ const logStreamPlugin = yield (0, plugin_loader_1.default)('client', 'logs', target.source).catch((err) => (0, logger_1.debug)(err));
30
+ if (typeof logStreamPlugin === 'function') {
31
+ const stream = yield logStreamPlugin();
32
+ if (stream instanceof stream_1.Stream) {
33
+ const streamLogFn = (chunk) => (0, logger_1.log)('info', chunk.toString(), true);
34
+ stream.on('data', streamLogFn);
35
+ }
36
+ }
37
+ const event = servePlugin(details, masterPort).catch((e) => {
38
+ var _a;
39
+ const err = error_1.default.getErrorInstance(e, {
40
+ fileName: __filename,
41
+ skipHelp: false
42
+ });
43
+ err.errorId = 'SERVE-IDX-1';
44
+ err.arg = [
45
+ 'client',
46
+ (0, ansi_colors_1.bold)(((_a = target.plugins) === null || _a === void 0 ? void 0 : _a.start)[target.source] || 'start'),
47
+ (0, ansi_colors_1.bold)('Error: ') + ansi_colors_1.italic.red(err.message)
48
+ ];
49
+ throw err;
50
+ });
51
+ (0, logger_1.labeled)(`Client[${target.name}]`, `Plugin : "${runtime_store_1.default.get(`context.client.plugins.start${target.source ? '.' + target.source : ''}`)}" is used for ${details.type} serve`).MESSAGE();
52
+ return event;
53
+ }
21
54
  const clientListener = yield (0, server_js_1.default)(details.httpPort, target.source, {
22
55
  homepage: target.homepage,
23
56
  enableWatch: ((_a = target.opts) === null || _a === void 0 ? void 0 : _a.watch) || false,