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

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 (88) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/commands/ds/import.toml +5 -5
  3. package/docs/commands/zest/generate/index.toml +4 -0
  4. package/docs/serve/server/lib/appsail/index.toml +22 -1
  5. package/lib/authentication/login.js +8 -4
  6. package/lib/code-deck.js +7 -7
  7. package/lib/command_needs/rc.js +7 -7
  8. package/lib/commands/appsail/add.js +2 -2
  9. package/lib/commands/client/setup.js +1 -1
  10. package/lib/commands/codelib/install.js +6 -2
  11. package/lib/commands/ds/import.js +37 -21
  12. package/lib/commands/event/generate/index.js +14 -2
  13. package/lib/commands/functions/add.js +1 -1
  14. package/lib/commands/functions/setup.js +1 -1
  15. package/lib/commands/iac/export.js +5 -1
  16. package/lib/commands/iac/import.js +4 -1
  17. package/lib/commands/index.js +1 -0
  18. package/lib/commands/init.js +8 -1
  19. package/lib/commands/zest/generate/index.js +304 -0
  20. package/lib/deploy/features/appsail/index.js +25 -10
  21. package/lib/endpoints/index.js +17 -3
  22. package/lib/endpoints/lib/ds-bulk.js +1 -0
  23. package/lib/endpoints/lib/stratus.js +63 -0
  24. package/lib/endpoints/lib/tunnel.js +18 -0
  25. package/lib/endpoints/lib/zest.js +124 -0
  26. package/lib/event_generate/stratus.js +52 -0
  27. package/lib/fn-utils/lib/common.js +6 -1
  28. package/lib/iac/status/deploy.js +1 -5
  29. package/lib/init/features/appsail/index.js +34 -27
  30. package/lib/init/features/project.js +6 -15
  31. package/lib/internal/api.js +14 -6
  32. package/lib/internal/command.js +1 -1
  33. package/lib/prompt/index.js +5 -2
  34. package/lib/prompt/types/file-path.js +1 -1
  35. package/lib/prompt/types/search-box.js +281 -0
  36. package/lib/serve/features/appsail.js +1 -1
  37. package/lib/serve/server/index.js +44 -14
  38. package/lib/serve/server/lib/appsail/index.js +73 -13
  39. package/lib/serve/server/lib/appsail/start.js +9 -1
  40. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  41. package/lib/serve/server/lib/java/aio_server/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  42. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  43. package/lib/serve/server/lib/java/index.js +1 -1
  44. package/lib/serve/server/lib/master/appsail.js +3 -3
  45. package/lib/serve/server/lib/master/unknown-req-proxy.js +5 -2
  46. package/lib/serve/server/lib/master/utils.js +27 -15
  47. package/lib/serve/server/lib/node/index.js +1 -1
  48. package/lib/serve/server/lib/node/server/package-lock.json +12 -0
  49. package/lib/serve/server/lib/python/index.js +1 -1
  50. package/lib/shell/dependencies/http-functions.js +1 -1
  51. package/lib/shell/dependencies/invoker/bio/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  52. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  53. package/lib/shell/dependencies/invoker/cron/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  54. package/lib/shell/dependencies/invoker/event/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  55. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +15 -0
  56. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  57. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  58. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +15 -1
  59. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  60. package/lib/shell/dependencies/local-function.js +24 -23
  61. package/lib/shell/dependencies/tunnel-server.js +52 -23
  62. package/lib/shell/index.js +22 -28
  63. package/lib/util_modules/config/lib/appsail.js +10 -8
  64. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  65. package/lib/util_modules/constants/lib/event-action.js +1 -0
  66. package/lib/util_modules/constants/lib/event-source.js +1 -0
  67. package/lib/util_modules/constants/lib/placeholders.js +2 -1
  68. package/lib/util_modules/constants/lib/scopes.js +14 -3
  69. package/lib/util_modules/constants/lib/urls.js +8 -0
  70. package/lib/util_modules/fs/lib/async.js +7 -2
  71. package/package.json +4 -2
  72. package/templates/init/client/react/react_js/template/src/index.js +3 -3
  73. package/templates/init/client/react/react_ts/template/src/index.tsx +3 -3
  74. package/templates/init/client/react/react_ts/template.json +3 -3
  75. package/templates/init/functions/java/job/sample.java +1 -1
  76. package/templates/init/functions/node/aio/sample.js +7 -0
  77. package/templates/init/functions/node/bio/sample.js +5 -0
  78. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  79. package/templates/init/functions/node/cron/sample.js +5 -0
  80. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  81. package/templates/init/functions/node/event/sample.js +11 -8
  82. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  83. package/templates/init/functions/node/job/sample.js +0 -1
  84. package/templates/init/functions/node/job/types/job.d.ts +0 -4
  85. package/templates/init/functions/python/job/sample.py +0 -1
  86. package/templates/init.txt +2 -1
  87. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  88. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
@@ -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_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, 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();
@@ -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, 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)
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, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
58
58
  }).RAW();
59
59
  });
@@ -23,12 +23,12 @@ function addAppSailRoutes(app, details, proxy, unknownProxy) {
23
23
  req.url = req.originalUrl;
24
24
  unknownProxy(req, res);
25
25
  }));
26
- app.use('/baas/logout', (req, res) => {
26
+ app.use('/__catalyst', (req, res) => __awaiter(this, void 0, void 0, function* () {
27
27
  req.url = req.originalUrl;
28
28
  unknownProxy(req, res);
29
- });
29
+ }));
30
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) => {
31
+ app.use(['/accounts', '/oauthorize'], (req, res) => {
32
32
  if (req.url.includes('/appsail/logout_redirect')) {
33
33
  res.redirect(typeof req.query.service_url === 'string' ? req.query.service_url : '/');
34
34
  return;
@@ -9,7 +9,7 @@ exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
9
9
  if (req.url.length === 1 && req.url.startsWith('/')) {
10
10
  res.redirect('/app/');
11
11
  }
12
- else if (req.url.match(/accounts\/p\/[0-9]+\/clientidprequest/g)) {
12
+ else if (req.url.startsWith('/accounts') && req.url.endsWith('clientidprequest')) {
13
13
  res.redirect(308, `https://${req.headers['x-zc-project-domain']}${req.url}`);
14
14
  return;
15
15
  }
@@ -30,7 +30,7 @@ exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
30
30
  }
31
31
  else {
32
32
  const headers = {};
33
- if (req.url.match(/accounts\/p\/[0-9]+\/webclient\/v1\/captcha/g)) {
33
+ if (req.url.startsWith('/accounts') && req.url.endsWith('captcha')) {
34
34
  headers['origin'] = `https://${req.headers['x-zc-project-domain']}`;
35
35
  }
36
36
  if (req.url.includes('/__catalyst/auth/')) {
@@ -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
  });
@@ -20,10 +20,21 @@ const error_1 = __importDefault(require("../../../../error"));
20
20
  const project_1 = require("../../../../util_modules/project");
21
21
  const http_proxy_1 = require("http-proxy");
22
22
  const logger_1 = require("../../../../util_modules/logger");
23
+ const iam_cookies = [
24
+ 'ZD_CSRF_TOKEN',
25
+ '_iamadt_client',
26
+ '_iambdt_client',
27
+ '_zcsr_tmp',
28
+ 'iamcsr',
29
+ 'zalb',
30
+ 'stk',
31
+ 'JSESSIONID'
32
+ ];
33
+ const isIamCookie = (cookieStr) => iam_cookies.some((val) => cookieStr.startsWith(val));
23
34
  const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
24
35
  exports.removeSecure = removeSecure;
25
36
  const redirectByAuth = (req, res, redirectUrl) => {
26
- if (req.headers['x-zc-user-cred-token'] === undefined) {
37
+ if (req.headers['cookie'] !== undefined) {
27
38
  res.writeHead(302, { Location: redirectUrl });
28
39
  res.end();
29
40
  }
@@ -68,17 +79,16 @@ const createProxyServer = (port) => {
68
79
  };
69
80
  exports.createProxyServer = createProxyServer;
70
81
  const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redirect' }) => (proxyRes, req, res) => {
82
+ var _a, _b;
71
83
  if (!req.url) {
72
84
  return;
73
85
  }
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')) {
86
+ proxyRes.headers['set-cookie'] = (_a = proxyRes.headers['set-cookie']) === null || _a === void 0 ? void 0 : _a.map((cookie) => {
87
+ if (isIamCookie(cookie))
88
+ return (0, exports.removeSecure)(cookie);
89
+ return cookie;
90
+ });
91
+ if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
82
92
  if (req.url.includes('/signin-redirect')) {
83
93
  if (systemRoutes === undefined) {
84
94
  (0, exports.redirectByAuth)(req, res, signInRedirect);
@@ -108,11 +118,7 @@ const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redir
108
118
  }
109
119
  }
110
120
  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;
121
+ (_b = proxyRes.headers['set-cookie']) === null || _b === void 0 ? void 0 : _b.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/');
116
122
  }
117
123
  };
118
124
  exports.proxyResponseHandler = proxyResponseHandler;
@@ -121,7 +127,13 @@ const appsailInitJs = () => __awaiter(void 0, void 0, void 0, function* () {
121
127
  if (!initJsStr) {
122
128
  throw new error_1.default('Unable to read the init_js file', { exit: 2 });
123
129
  }
124
- const feed = [(0, project_1.getProjectId)(), (0, project_1.getDomainKey)(), constants_1.ORIGIN.iamPortal, (0, project_1.getEnvId)()];
130
+ const feed = [
131
+ (0, project_1.getProjectId)(),
132
+ (0, project_1.getDomainKey)(),
133
+ constants_1.ORIGIN.iamPortal,
134
+ (0, project_1.getEnvId)(),
135
+ `-development${constants_1.ORIGIN.stratusSuffix}`
136
+ ];
125
137
  Object.values(constants_1.PLACEHOLDER.init_js).forEach((holder, idx) => {
126
138
  initJsStr = initJsStr === null || initJsStr === void 0 ? void 0 : initJsStr.replace(new RegExp(holder, 'g'), feed[idx]);
127
139
  });
@@ -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, 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)
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, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
92
92
  }).RAW();
93
93
  });
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "catalyst-cli-node-runtime",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "catalyst-cli-node-runtime",
9
+ "version": "1.0.0"
10
+ }
11
+ }
12
+ }
@@ -36,7 +36,7 @@ exports.default = (details) => __awaiter(void 0, void 0, void 0, function* () {
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_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)
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_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, 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_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, 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());
@@ -117,7 +117,7 @@ class HttpFunctions {
117
117
  const slave = (0, shell_1.spawn)(opts.command, opts.options, {
118
118
  cwd: opts.pth,
119
119
  stdio: 'pipe',
120
- 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, CATALYST_PROJECT_TIMEZONE: (0, project_2.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, opts.envVars)
120
+ 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_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_2.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, opts.envVars)
121
121
  }).RAW();
122
122
  (_a = slave.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
123
123
  (0, logger_2.info)(Buffer.isBuffer(data) ? data.toString() : data);
@@ -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;
@@ -120,6 +123,7 @@ public class JavaintegInvoker {
120
123
  catalystConfig.put("project_key", project.get("x-zc-project-key").toString());
121
124
  catalystConfig.put("project_domain", project.get("x-zc-project-domain").toString());
122
125
  catalystConfig.put("environment", project.get("x-zc-environment").toString());
126
+
123
127
 
124
128
  ZCThreadLocal.putValue("CATALYST_CONFIG", catalystConfig.toString());
125
129
  }
@@ -231,6 +235,17 @@ public class JavaintegInvoker {
231
235
 
232
236
  Method runner = cls.getMethod("runner", ZCIntegRequest.class);
233
237
  ZCIntegResponse integResponse = null;
238
+
239
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
240
+ Timer executionTimer = new Timer(true);
241
+ executionTimer.schedule(new TimerTask() {
242
+ @Override
243
+ public void run() {
244
+ throwAndExit(new TimeoutException("function execution timeout"), 408, invokerDir);
245
+ }
246
+ }, 900000L); // 15 mins
247
+ }
248
+
234
249
  try {
235
250
  integResponse = (ZCIntegResponse) runner.invoke(cls.getDeclaredConstructor().newInstance(), integRequest);
236
251
  } 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) {