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

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 (51) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/serve/server/lib/appsail/index.toml +22 -1
  3. package/lib/command_needs/rc.js +7 -7
  4. package/lib/commands/appsail/add.js +1 -1
  5. package/lib/commands/client/setup.js +1 -1
  6. package/lib/commands/codelib/install.js +5 -2
  7. package/lib/commands/event/generate/index.js +1 -2
  8. package/lib/commands/event/generate/integ.js +1 -2
  9. package/lib/commands/functions/add.js +1 -1
  10. package/lib/commands/functions/setup.js +1 -1
  11. package/lib/commands/index.js +1 -2
  12. package/lib/commands/init.js +8 -1
  13. package/lib/deploy/features/appsail/index.js +25 -10
  14. package/lib/endpoints/index.js +2 -2
  15. package/lib/endpoints/lib/tunnel.js +18 -0
  16. package/lib/init/features/appsail/index.js +34 -27
  17. package/lib/init/features/client/index.js +1 -2
  18. package/lib/init/features/project.js +5 -15
  19. package/lib/internal/api.js +13 -5
  20. package/lib/internal/command.js +1 -2
  21. package/lib/migration/index.js +2 -4
  22. package/lib/optional-import.js +2 -3
  23. package/lib/prompt/types/file-path.js +1 -1
  24. package/lib/prompt/types/tree.js +3 -3
  25. package/lib/serve/features/appsail.js +1 -1
  26. package/lib/serve/server/index.js +44 -14
  27. package/lib/serve/server/lib/appsail/index.js +73 -13
  28. package/lib/serve/server/lib/appsail/start.js +9 -1
  29. package/lib/serve/server/lib/master/unknown-req-proxy.js +3 -0
  30. package/lib/serve/server/lib/master/utils.js +6 -6
  31. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  32. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +14 -0
  33. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  34. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +15 -1
  35. package/lib/shell/dependencies/local-function.js +24 -23
  36. package/lib/shell/dependencies/tunnel-server.js +52 -23
  37. package/lib/shell/index.js +22 -28
  38. package/lib/util_modules/config/lib/appsail.js +10 -8
  39. package/lib/util_modules/fs/lib/async.js +7 -2
  40. package/package.json +1 -1
  41. package/templates/init/functions/java/job/sample.java +1 -1
  42. package/templates/init/functions/node/aio/sample.js +7 -0
  43. package/templates/init/functions/node/bio/sample.js +5 -0
  44. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  45. package/templates/init/functions/node/cron/sample.js +5 -0
  46. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  47. package/templates/init/functions/node/event/sample.js +11 -8
  48. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  49. package/templates/init/functions/node/job/sample.js +0 -1
  50. package/templates/init/functions/node/job/types/job.d.ts +0 -4
  51. package/templates/init/functions/python/job/sample.py +0 -1
@@ -26,9 +26,6 @@ var ETreeState;
26
26
  ETreeState[ETreeState["EXPANDED"] = 3] = "EXPANDED";
27
27
  })(ETreeState || (ETreeState = {}));
28
28
  class TreeNode {
29
- get indent() {
30
- return this.level * 2;
31
- }
32
29
  constructor(root) {
33
30
  _TreeNode_instances.add(this);
34
31
  this.open = false;
@@ -39,6 +36,9 @@ class TreeNode {
39
36
  this.level = 1;
40
37
  this.root = root;
41
38
  }
39
+ get indent() {
40
+ return this.level * 2;
41
+ }
42
42
  addNode(node) {
43
43
  if (node instanceof TreeNode) {
44
44
  this.leaves.push(node);
@@ -41,7 +41,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
41
41
  name: targ.name + '_proxy',
42
42
  server: 'service'
43
43
  });
44
- return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
44
+ return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort }, trigger: { kill: false } });
45
45
  })));
46
46
  runtime_store_1.default.set('context.appsail.targets', filledTargets);
47
47
  });
@@ -302,6 +302,11 @@ class Server {
302
302
  var _a;
303
303
  switch (targType) {
304
304
  case 'functions': {
305
+ const headersDisplayed = {
306
+ bio: false,
307
+ aio: false,
308
+ blo: false
309
+ };
305
310
  Object.entries(logTarg).forEach((x) => {
306
311
  const [_targType, _logTarg] = x;
307
312
  if (_logTarg.targs.length === 0) {
@@ -310,48 +315,66 @@ class Server {
310
315
  loggedEntries++;
311
316
  switch (_targType) {
312
317
  case 'bio': {
313
- (0, logger_1.info)();
314
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> BasicIO <<<<<<<<<<<<<< '));
315
318
  _logTarg.targs.forEach((t) => {
316
- var _a;
319
+ var _a, _b;
317
320
  const target = t;
318
- if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.url)) {
321
+ if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
322
+ return;
323
+ }
324
+ if (!((_b = target.target) === null || _b === void 0 ? void 0 : _b.url)) {
319
325
  throw new error_1.default('Target URL not found', {
320
326
  exit: 2
321
327
  });
322
328
  }
329
+ if (headersDisplayed.bio === false) {
330
+ (0, logger_1.info)();
331
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> BasicIO <<<<<<<<<<<<<< '));
332
+ headersDisplayed.bio = true;
333
+ }
323
334
  bioLogUrl(target, masterPort, _logTarg.nameMaxLength);
324
335
  });
325
336
  (0, logger_1.info)();
326
337
  break;
327
338
  }
328
339
  case 'aio': {
329
- (0, logger_1.info)();
330
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>> AdvancedIO <<<<<<<<<<<< '));
331
340
  _logTarg.targs.forEach((t) => {
332
- var _a;
341
+ var _a, _b;
333
342
  const _target = t;
334
- if (!((_a = _target.target) === null || _a === void 0 ? void 0 : _a.url)) {
343
+ if (!((_a = _target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
344
+ return;
345
+ }
346
+ if (!((_b = _target.target) === null || _b === void 0 ? void 0 : _b.url)) {
335
347
  throw new error_1.default('Target URL not found', {
336
348
  exit: 2
337
349
  });
338
350
  }
351
+ if (headersDisplayed.aio === false) {
352
+ (0, logger_1.info)();
353
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>> AdvancedIO <<<<<<<<<<<< '));
354
+ headersDisplayed.aio = true;
355
+ }
339
356
  aioLogUrl(_target, masterPort, _logTarg.nameMaxLength);
340
357
  });
341
358
  (0, logger_1.info)();
342
359
  break;
343
360
  }
344
361
  case 'browserlogic': {
345
- (0, logger_1.info)();
346
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>> BrowserLogic <<<<<<<<<<< '));
347
362
  _logTarg.targs.forEach((t) => {
348
- var _a;
363
+ var _a, _b;
349
364
  const target = t;
350
- if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.url)) {
365
+ if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
366
+ return;
367
+ }
368
+ if (!((_b = target.target) === null || _b === void 0 ? void 0 : _b.url)) {
351
369
  throw new error_1.default('Target URL not found', {
352
370
  exit: 2
353
371
  });
354
372
  }
373
+ if (headersDisplayed.blo === false) {
374
+ (0, logger_1.info)();
375
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>> BrowserLogic <<<<<<<<<<< '));
376
+ headersDisplayed.blo = true;
377
+ }
355
378
  bioLogUrl(target, masterPort, _logTarg.nameMaxLength);
356
379
  });
357
380
  (0, logger_1.info)();
@@ -367,10 +390,17 @@ class Server {
367
390
  return;
368
391
  }
369
392
  loggedEntries++;
370
- (0, logger_1.info)();
371
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
393
+ let isHeaderDisplayed = false;
372
394
  _logTarg.targs.forEach((t) => {
373
395
  const targetSail = t.target;
396
+ if (!targetSail.validity.valid) {
397
+ return;
398
+ }
399
+ if (isHeaderDisplayed === false) {
400
+ (0, logger_1.info)();
401
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
402
+ isHeaderDisplayed = true;
403
+ }
374
404
  const targName = targetSail.name + '';
375
405
  (0, logger_1.labeled)(targName +
376
406
  ' '.repeat((_logTarg.nameMaxLength || targName.length) - targName.length), `http://localhost:${targetSail.port.proxy}`).MESSAGE();
@@ -24,6 +24,8 @@ const archiver_1 = __importDefault(require("../../../../archiver"));
24
24
  const option_1 = require("../../../../util_modules/option");
25
25
  const execute_script_1 = require("../../../../execute-script");
26
26
  const master_1 = __importDefault(require("../master"));
27
+ const ansi_colors_1 = require("ansi-colors");
28
+ const common_1 = require("../../../../init/util/common");
27
29
  function executeHook(script, name, moduleSource) {
28
30
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
29
31
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -37,14 +39,18 @@ const startAppSail = (port, opts) => {
37
39
  if (opts.command) {
38
40
  _opts.push('-c', opts.command);
39
41
  }
40
- return (0, shell_1.spawn)('node', _opts, {
42
+ const child = (0, shell_1.spawn)('node', _opts, {
41
43
  cwd: opts.target,
42
44
  stdio: 'pipe',
43
- env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
45
+ env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
44
46
  }).RAW();
47
+ return new Promise((_res, _rej) => {
48
+ child.on('spawn', () => _res(child));
49
+ child.on('error', (reason) => _rej(reason));
50
+ });
45
51
  };
46
52
  exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
47
- var _a, _b, _c, _d;
53
+ var _a, _b, _c, _d, _e, _f, _g;
48
54
  let child;
49
55
  const targetSail = serverDetails.target;
50
56
  if (!targetSail || !targetSail.config) {
@@ -55,24 +61,45 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
55
61
  }
56
62
  const buildPath = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path;
57
63
  const target = (yield fs_1.ASYNC.fileExists(buildPath)) ? (0, path_1.dirname)(buildPath) : buildPath;
64
+ if (!(yield fs_1.ASYNC.isPathExists(target))) {
65
+ if ((0, path_1.isAbsolute)(((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.raw.build_path) || '')) {
66
+ throw new error_1.default('The given AppSail build path does not exists', {
67
+ exit: 1,
68
+ errorId: 'SERVE-APPSAIL-1',
69
+ arg: [ansi_colors_1.italic.underline.red(target), (0, ansi_colors_1.bold)(targetSail.name)]
70
+ });
71
+ }
72
+ throw new error_1.default('The given AppSail build path does not exists: ' + targetSail.name, {
73
+ exit: 1,
74
+ errorId: 'SERVE-APPSAIL-2',
75
+ arg: [
76
+ (0, ansi_colors_1.underline)(((_d = targetSail.config) === null || _d === void 0 ? void 0 : _d.raw.build_path) || ''),
77
+ ansi_colors_1.italic.underline(targetSail.config.raw.source_path || ''),
78
+ ansi_colors_1.italic.underline(((_e = targetSail.config) === null || _e === void 0 ? void 0 : _e.raw.build_path) || ''),
79
+ ansi_colors_1.italic.underline(target)
80
+ ]
81
+ });
82
+ }
58
83
  switch (true) {
59
84
  case targetSail.config.stack.startsWith('node'): {
60
- child = startAppSail(targetSail.port.appsail, {
85
+ child = yield startAppSail(targetSail.port.appsail, {
61
86
  type: 'nodejs',
62
87
  target,
63
88
  command: targetSail.config.command,
64
89
  memory: targetSail.config.memory || 256,
65
- env: targetSail.config.env_variables
90
+ env: targetSail.config.env_variables,
91
+ name: targetSail.name
66
92
  });
67
93
  break;
68
94
  }
69
95
  case targetSail.config.stack.startsWith('python'): {
70
- child = startAppSail(targetSail.port.appsail, {
96
+ child = yield startAppSail(targetSail.port.appsail, {
71
97
  type: 'python',
72
98
  target,
73
99
  command: targetSail.config.command,
74
100
  memory: targetSail.config.memory || 256,
75
- env: targetSail.config.env_variables
101
+ env: targetSail.config.env_variables,
102
+ name: targetSail.name
76
103
  });
77
104
  break;
78
105
  }
@@ -98,26 +125,37 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
98
125
  }
99
126
  }
100
127
  const jettyCommand = `java -jar "${(0, path_1.join)(jettyPath, 'start.jar')}" -Djetty.deploy.monitoredPath="${(0, project_1.resolveProjectPath)(target)}" -Djetty.http.port=${targetSail.port.appsail}`;
101
- child = startAppSail(targetSail.port.appsail, {
128
+ child = yield startAppSail(targetSail.port.appsail, {
102
129
  target,
103
130
  type: 'war',
104
131
  command: jettyCommand,
105
132
  memory: targetSail.config.memory || 256,
106
- env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.config.env_variables)
133
+ env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.config.env_variables),
134
+ name: targetSail.name
107
135
  });
108
136
  break;
109
137
  }
110
- child = startAppSail(targetSail.port.appsail, {
138
+ child = yield startAppSail(targetSail.port.appsail, {
111
139
  target,
112
140
  command: targetSail.config.command,
113
141
  type: 'javase',
114
142
  memory: targetSail.config.memory || 256,
115
- env: targetSail.config.env_variables
143
+ env: targetSail.config.env_variables,
144
+ name: targetSail.name
116
145
  });
117
146
  break;
118
147
  }
119
148
  default: {
120
- throw new error_1.default('Invalid AppSail stack');
149
+ const appSailRuntime = yield (0, common_1.getRuntimeDetails)();
150
+ throw new error_1.default('Invalid AppSail stack', {
151
+ exit: 1,
152
+ errorId: 'SERVE-APPSAIL-4',
153
+ arg: [
154
+ (0, ansi_colors_1.bold)(targetSail.name),
155
+ ansi_colors_1.bold.red(targetSail.config.stack),
156
+ appSailRuntime.runtimes.map((val) => (0, ansi_colors_1.bold)(`* ${val}`)).join('\n')
157
+ ]
158
+ });
121
159
  }
122
160
  }
123
161
  const masterServe = yield (0, master_1.default)(targetSail.port.proxy, {
@@ -130,7 +168,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
130
168
  }
131
169
  });
132
170
  });
133
- if ((_d = (_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.scripts) === null || _d === void 0 ? void 0 : _d.postserve) {
171
+ if ((_g = (_f = targetSail.config) === null || _f === void 0 ? void 0 : _f.scripts) === null || _g === void 0 ? void 0 : _g.postserve) {
134
172
  child.once('exit', () => {
135
173
  var _a, _b, _c;
136
174
  if (!((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.scripts)) {
@@ -139,5 +177,27 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
139
177
  executeHook((_c = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.scripts) === null || _c === void 0 ? void 0 : _c.postserve, `AppSail [POSTSERVE] [${targetSail.name}]`, targetSail.source);
140
178
  });
141
179
  }
180
+ process.on('SIGINT', () => {
181
+ targetSail.trigger.kill = true;
182
+ });
183
+ child.once('exit', (code) => {
184
+ var _a, _b, _c;
185
+ if (code === 150) {
186
+ targetSail.validity = {
187
+ valid: false,
188
+ reason: 'Unable to start the AppSail'
189
+ };
190
+ throw new error_1.default('Unable to start the AppSail', {
191
+ exit: 1,
192
+ errorId: 'SERVE-APPSAIL-3',
193
+ arg: [
194
+ (0, ansi_colors_1.bold)(targetSail.name),
195
+ ((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.command) || '',
196
+ (0, ansi_colors_1.underline)(((_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path) || ''),
197
+ ((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.stack) || ''
198
+ ]
199
+ });
200
+ }
201
+ });
142
202
  return child;
143
203
  });
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable @typescript-eslint/no-var-requires */
3
+
4
+ // exit codes
5
+ // 150 - start up command failure
6
+
3
7
  const EXEC_SYNC = require('child_process').execSync;
4
8
 
5
9
  const WAR = 'war';
@@ -58,7 +62,11 @@ function main() {
58
62
  throw new Error(`invalid runtime type: ${CMD_ARGS.rtType}`);
59
63
  }
60
64
 
61
- EXEC_SYNC(command.toString(), { stdio: 'inherit', cwd });
65
+ try {
66
+ EXEC_SYNC(command.toString(), { stdio: 'inherit', cwd });
67
+ } catch (er) {
68
+ process.exit(150);
69
+ }
62
70
  }
63
71
 
64
72
  main();
@@ -39,6 +39,9 @@ exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
39
39
  proxyInstance.web(req, res, {
40
40
  target: `https://${req.headers['x-zc-project-domain']}`,
41
41
  changeOrigin: true,
42
+ cookieDomainRewrite: {
43
+ [req.headers['x-zc-project-domain'] + '']: 'localhost'
44
+ },
42
45
  ws: true,
43
46
  headers
44
47
  });
@@ -107,12 +107,12 @@ const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redir
107
107
  }
108
108
  }
109
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;
110
+ else if (req.url.startsWith('/accounts')) {
111
+ const set = proxyRes.headers['set-cookie'] || [];
112
+ if (req.url.includes('/signin')) {
113
+ set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/');
114
+ }
115
+ proxyRes.headers['set-cookie'] = set.map(exports.removeSecure);
116
116
  }
117
117
  };
118
118
  exports.proxyResponseHandler = proxyResponseHandler;
@@ -276,7 +276,7 @@ public class JavacronInvoker {
276
276
  Method runner = cls.getMethod("handleCronExecute", CronRequest.class, Context.class);
277
277
  CRON_STATUS cronStatus = null;
278
278
 
279
- if(System.getenv("DEBUG").equals("false")) {
279
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
280
280
  Timer executionTimer = new Timer(true);
281
281
  executionTimer.schedule(new TimerTask() {
282
282
  @Override
@@ -14,6 +14,9 @@ import java.nio.file.Path;
14
14
  import java.nio.file.Paths;
15
15
  import java.util.HashMap;
16
16
  import java.util.Iterator;
17
+ import java.util.Timer;
18
+ import java.util.TimerTask;
19
+ import java.util.concurrent.TimeoutException;
17
20
  import java.util.logging.Handler;
18
21
  import java.util.logging.LogManager;
19
22
  import java.util.logging.LogRecord;
@@ -231,6 +234,17 @@ public class JavaintegInvoker {
231
234
 
232
235
  Method runner = cls.getMethod("runner", ZCIntegRequest.class);
233
236
  ZCIntegResponse integResponse = null;
237
+
238
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
239
+ Timer executionTimer = new Timer(true);
240
+ executionTimer.schedule(new TimerTask() {
241
+ @Override
242
+ public void run() {
243
+ throwAndExit(new TimeoutException("function execution timeout"), 408, invokerDir);
244
+ }
245
+ }, 900000L); // 15 mins
246
+ }
247
+
234
248
  try {
235
249
  integResponse = (ZCIntegResponse) runner.invoke(cls.getDeclaredConstructor().newInstance(), integRequest);
236
250
  } catch (Exception e) {
@@ -20,6 +20,19 @@ const writeAndExit = (resp) => {
20
20
  process.exit(0);
21
21
  };
22
22
 
23
+ /**
24
+ * execution timeout of 15 minutes
25
+ */
26
+ const timeout = 15 * 60 * 1000;
27
+ // const endTime = timeout + Date.now();
28
+
29
+ // exit on timeout
30
+ process.env.DEBUG === 'false' &&
31
+ setTimeout(() => {
32
+ writeToFile('TIMEOUT', 408);
33
+ process.exit(0);
34
+ }, timeout);
35
+
23
36
  const integrationRequest = data || {};
24
37
 
25
38
  integrationRequest.catalystHeaders = Object.assign(projectJson, authJson);
@@ -10,6 +10,9 @@ import java.net.URLClassLoader;
10
10
  import java.nio.file.Paths;
11
11
  import java.util.HashMap;
12
12
  import java.util.Iterator;
13
+ import java.util.Timer;
14
+ import java.util.TimerTask;
15
+ import java.util.concurrent.TimeoutException;
13
16
  import java.util.logging.Handler;
14
17
  import java.util.logging.LogManager;
15
18
  import java.util.logging.LogRecord;
@@ -214,7 +217,7 @@ public class JavajobInvoker {
214
217
  JSONObject jobMetaDetails = jobDetails.getJSONObject("job_meta_details");
215
218
  JSONObject jobpoolDetails = jobMetaDetails.getJSONObject("jobpool_details");
216
219
  JSONObject projectDetails = jobpoolDetails.getJSONObject("project_details");
217
- JSONObject capacity = jobDetails.getJSONObject("capacity");
220
+ JSONObject capacity = userData.getJSONObject("capacity");
218
221
  JSONObject params = jobMetaDetails.getJSONObject("params");
219
222
 
220
223
  defaultJob.setJobDetails(jobDetails != null ? (JSONObject) jobDetails : new JSONObject());
@@ -233,6 +236,17 @@ public class JavajobInvoker {
233
236
 
234
237
  Method runner = cls.getMethod("handleJobExecute", JobRequest.class, Context.class);
235
238
  JOB_STATUS jobStatus = null;
239
+
240
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
241
+ Timer executionTimer = new Timer(true);
242
+ executionTimer.schedule(new TimerTask() {
243
+ @Override
244
+ public void run() {
245
+ throwAndExit(new TimeoutException("function execution timeout"), 408, invokerDir);
246
+ }
247
+ }, defaultContext.getMaxExecutionTimeMs());
248
+ }
249
+
236
250
  try {
237
251
  jobStatus = (JOB_STATUS) runner.invoke(cls.getDeclaredConstructor().newInstance(), jobRequest, context);
238
252
  } catch (Exception e) {
@@ -97,7 +97,7 @@ class LocalFunction {
97
97
  return new error_1.default('Invalid input');
98
98
  }
99
99
  return (() => __awaiter(this, void 0, void 0, function* () {
100
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
100
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
101
101
  const projectRoot = runtime_store_1.default.get('project.root');
102
102
  const accessToken = yield credential_1.default.getAccessToken();
103
103
  const slaveOptions = [];
@@ -105,9 +105,9 @@ class LocalFunction {
105
105
  yield fs_1.ASYNC.ensureFile(this.responseFile, true);
106
106
  yield fs_1.ASYNC.ensureFile(this.metaFile, true);
107
107
  if (this.target.type === constants_1.FN_TYPE.job) {
108
- const jobDetails = data;
108
+ const jobData = data;
109
109
  const jobMetaDetails = {
110
- headers: Object.assign(Object.assign({}, (_a = jobDetails.job_meta_details) === null || _a === void 0 ? void 0 : _a.headers), {
110
+ headers: Object.assign(Object.assign({}, (_b = (_a = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _a === void 0 ? void 0 : _a.job_meta_details) === null || _b === void 0 ? void 0 : _b.headers), {
111
111
  'x-zc-projectid': (0, project_1.getProjectId)(),
112
112
  'x-zc-project-domain': (0, project_1.getDomainPrefix)() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
113
113
  'x-zc-project-key': (0, project_1.getDomainKey)(),
@@ -118,8 +118,8 @@ class LocalFunction {
118
118
  'x-zc-admin-cred-token': accessToken,
119
119
  'x-zc-user-type': 'admin'
120
120
  }),
121
- params: ((_b = jobDetails.job_meta_details) === null || _b === void 0 ? void 0 : _b.params) || {},
122
- jobpool_details: ((_c = jobDetails.job_meta_details) === null || _c === void 0 ? void 0 : _c.jobpool_details) || {
121
+ params: ((_d = (_c = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _c === void 0 ? void 0 : _c.job_meta_details) === null || _d === void 0 ? void 0 : _d.params) || {},
122
+ jobpool_details: ((_f = (_e = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _e === void 0 ? void 0 : _e.job_meta_details) === null || _f === void 0 ? void 0 : _f.jobpool_details) || {
123
123
  type: 'Function',
124
124
  project_details: {
125
125
  project_name: (0, project_1.getProjectName)(),
@@ -127,14 +127,14 @@ class LocalFunction {
127
127
  }
128
128
  }
129
129
  };
130
- jobDetails.job_meta_details = jobMetaDetails;
131
- jobDetails.capacity = jobDetails.capacity || {
130
+ jobData.job_details = Object.assign(Object.assign({}, jobData.job_details), { job_meta_details: jobMetaDetails });
131
+ jobData.capacity = jobData.capacity || {
132
132
  memory: '256'
133
133
  };
134
- data = jobDetails;
134
+ data = jobData;
135
135
  }
136
136
  const slaveFnTarget = { index: this.target.index, name: this.target.name };
137
- if ((_d = this.target.stack) === null || _d === void 0 ? void 0 : _d.startsWith(runtime_1.default.language.node.value)) {
137
+ if ((_g = this.target.stack) === null || _g === void 0 ? void 0 : _g.startsWith(runtime_1.default.language.node.value)) {
138
138
  if (debugPort !== null) {
139
139
  slaveOptions.push('--inspect-brk=' + debugPort);
140
140
  }
@@ -158,10 +158,10 @@ class LocalFunction {
158
158
  this.slave = (0, shell_1.spawn)('node', slaveOptions, {
159
159
  cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
160
160
  stdio: 'pipe',
161
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_e = this.target) === null || _e === void 0 ? void 0 : _e.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
161
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_h = this.target) === null || _h === void 0 ? void 0 : _h.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
162
162
  }).RAW();
163
163
  }
164
- else if ((_f = this.target.stack) === null || _f === void 0 ? void 0 : _f.startsWith(runtime_1.default.language.java.value)) {
164
+ else if ((_j = this.target.stack) === null || _j === void 0 ? void 0 : _j.startsWith(runtime_1.default.language.java.value)) {
165
165
  const javaInvokerDir = (0, path_1.parse)(this.javaInvoker).dir;
166
166
  slaveOptions.push('-cp');
167
167
  slaveOptions.push(javaInvokerDir +
@@ -196,11 +196,11 @@ class LocalFunction {
196
196
  this.slave = (0, shell_1.spawn)(spawnCommand, slaveOptions, {
197
197
  cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
198
198
  stdio: 'pipe',
199
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_g = this.target) === null || _g === void 0 ? void 0 : _g.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
199
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_k = this.target) === null || _k === void 0 ? void 0 : _k.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
200
200
  }).RAW();
201
201
  }
202
- else if ((_h = this.target.stack) === null || _h === void 0 ? void 0 : _h.startsWith(runtime_1.default.language.python.value)) {
203
- const stackVersion = (_j = this.target.stack) === null || _j === void 0 ? void 0 : _j.replace('python_', '');
202
+ else if ((_l = this.target.stack) === null || _l === void 0 ? void 0 : _l.startsWith(runtime_1.default.language.python.value)) {
203
+ const stackVersion = (_m = this.target.stack) === null || _m === void 0 ? void 0 : _m.replace('python_', '');
204
204
  const runtimesDir = constants_1.ENVPATH.runtimes.data;
205
205
  const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
206
206
  const runTimePort = yield port_resolver_1.default.getFreePort(httpPort, 20, false);
@@ -211,10 +211,10 @@ class LocalFunction {
211
211
  this.slave = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), slaveOptions, {
212
212
  cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
213
213
  stdio: 'pipe',
214
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_k = this.target) === null || _k === void 0 ? void 0 : _k.id, X_ZOHO_CATALYST_CODE_LOCATION: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Local', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[this.target.type] }, this.target.env_var)
214
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_o = this.target) === null || _o === void 0 ? void 0 : _o.id, X_ZOHO_CATALYST_CODE_LOCATION: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Local', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[this.target.type] }, this.target.env_var)
215
215
  }).RAW();
216
216
  this.slave.once('spawn', () => __awaiter(this, void 0, void 0, function* () {
217
- var _o;
217
+ var _r;
218
218
  const jsonData = data;
219
219
  jsonData.timestamp = Date.now();
220
220
  const writeResponse = (response, status) => {
@@ -223,15 +223,15 @@ class LocalFunction {
223
223
  };
224
224
  if (this.target.type === constants_1.FN_TYPE.job) {
225
225
  const jobDetailsServer = new http_1.Server((serverReq, serverRes) => __awaiter(this, void 0, void 0, function* () {
226
- var _p, _q, _r;
227
- if ((_p = serverReq.url) === null || _p === void 0 ? void 0 : _p.includes('data')) {
226
+ var _s, _t, _u;
227
+ if ((_s = serverReq.url) === null || _s === void 0 ? void 0 : _s.includes('data')) {
228
228
  serverRes.writeHead(200);
229
229
  serverRes.write(JSON.stringify({
230
230
  data: jsonData
231
231
  }));
232
232
  serverRes.end();
233
233
  }
234
- else if ((_q = serverReq.url) === null || _q === void 0 ? void 0 : _q.includes('callback')) {
234
+ else if ((_t = serverReq.url) === null || _t === void 0 ? void 0 : _t.includes('callback')) {
235
235
  const reqData = yield new Promise((resolve) => {
236
236
  const data = [];
237
237
  serverReq.on('data', (chunk) => data.push(chunk));
@@ -262,7 +262,7 @@ class LocalFunction {
262
262
  else {
263
263
  (0, logger_1.debug)(`Invalid request: (${serverReq.method}) ${serverReq.url}`);
264
264
  writeResponse('INTERNAL_SERVER_ERROR', 500);
265
- (_r = this.slave) === null || _r === void 0 ? void 0 : _r.kill('SIGINT');
265
+ (_u = this.slave) === null || _u === void 0 ? void 0 : _u.kill('SIGINT');
266
266
  return;
267
267
  }
268
268
  }));
@@ -270,7 +270,7 @@ class LocalFunction {
270
270
  jobDetailsServer.listen(runTimePort, () => {
271
271
  (0, logger_1.debug)('server listening on port :' + runTimePort);
272
272
  });
273
- (_o = this.slave) === null || _o === void 0 ? void 0 : _o.once('exit', () => {
273
+ (_r = this.slave) === null || _r === void 0 ? void 0 : _r.once('exit', () => {
274
274
  jobConnDestroyer.destroy();
275
275
  });
276
276
  return;
@@ -347,11 +347,11 @@ class LocalFunction {
347
347
  exit: 2
348
348
  });
349
349
  }
350
- (_l = this.slave.stdout) === null || _l === void 0 ? void 0 : _l.on('data', (message) => {
350
+ (_p = this.slave.stdout) === null || _p === void 0 ? void 0 : _p.on('data', (message) => {
351
351
  (0, shell_1.clearLine)(process.stdout);
352
352
  (0, logger_1.info)(message.toString());
353
353
  });
354
- (_m = this.slave.stderr) === null || _m === void 0 ? void 0 : _m.on('data', (message) => {
354
+ (_q = this.slave.stderr) === null || _q === void 0 ? void 0 : _q.on('data', (message) => {
355
355
  const errorStr = js_1.JS.trim(message.toString());
356
356
  (0, shell_1.clearLine)(process.stdout);
357
357
  (0, logger_1.info)(errorStr);
@@ -379,6 +379,7 @@ class LocalFunction {
379
379
  });
380
380
  break;
381
381
  case constants_1.FN_TYPE.cron:
382
+ case constants_1.FN_TYPE.job:
382
383
  case constants_1.FN_TYPE.event:
383
384
  (0, logger_1.info)(`[status - ${this.target.name}] ${response || 'Unknown'}`);
384
385
  if (!response) {