zcatalyst-cli 1.15.0-beta.4 → 1.15.0-beta.6

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 (73) hide show
  1. package/lib/archiver.js +8 -3
  2. package/lib/client-utils.js +5 -1
  3. package/lib/commands/iac/pack.js +9 -8
  4. package/lib/deploy/features/appsail/index.js +15 -5
  5. package/lib/deploy/features/client.js +1 -1
  6. package/lib/deploy/features/functions/index.js +7 -4
  7. package/lib/endpoints/lib/applogic.js +14 -2
  8. package/lib/endpoints/lib/appsail.js +11 -2
  9. package/lib/endpoints/lib/client.js +11 -2
  10. package/lib/endpoints/lib/functions.js +14 -2
  11. package/lib/endpoints/lib/sdk.js +8 -5
  12. package/lib/express_middlewares/logger.js +6 -2
  13. package/lib/fn-utils/lib/common.js +78 -48
  14. package/lib/fn-utils/lib/integ.js +23 -13
  15. package/lib/fn-utils/lib/java.js +28 -29
  16. package/lib/fn-utils/lib/node.js +17 -1
  17. package/lib/fn-utils/lib/python.js +1 -1
  18. package/lib/init/features/appsail/index.js +2 -2
  19. package/lib/init/features/functions/index.js +10 -4
  20. package/lib/init/features/functions/languages/java.js +2 -17
  21. package/lib/init/features/functions/languages/node.js +2 -17
  22. package/lib/init/features/project.js +1 -1
  23. package/lib/internal/api.js +33 -8
  24. package/lib/option-filter.js +4 -4
  25. package/lib/port-resolver.js +24 -11
  26. package/lib/progress.js +3 -2
  27. package/lib/prompt/types/file-path.js +3 -1
  28. package/lib/serve/features/appsail.js +14 -3
  29. package/lib/serve/features/index.js +1 -1
  30. package/lib/serve/index.js +7 -2
  31. package/lib/serve/server/index.js +252 -92
  32. package/lib/serve/server/lib/appsail/index.js +19 -9
  33. package/lib/serve/server/lib/appsail/start.js +4 -15
  34. package/lib/serve/server/lib/master.js +10 -10
  35. package/lib/serve/server/lib/web_client/index.js +5 -5
  36. package/lib/shell/dependencies/http-functions.js +11 -15
  37. package/lib/shell/prepare/languages/java.js +9 -4
  38. package/lib/util_modules/constants/lib/default.js +4 -1
  39. package/lib/util_modules/constants/lib/integ.js +4 -2
  40. package/lib/util_modules/constants/lib/scopes.js +1 -0
  41. package/lib/util_modules/constants/lib/template.js +23 -20
  42. package/lib/util_modules/fs/lib/async.js +10 -9
  43. package/lib/util_modules/fs/lib/sync.js +5 -1
  44. package/package.json +1 -1
  45. package/templates/init/functions/java/aio/sample.java +14 -4
  46. package/templates/init/functions/java/integ/convokraft/.classpath +6 -0
  47. package/templates/init/functions/java/integ/convokraft/.project +17 -0
  48. package/templates/init/functions/java/integ/convokraft/ExecuteHandler.java +20 -0
  49. package/templates/init/functions/java/integ/convokraft/FailureHandler.java +20 -0
  50. package/templates/init/functions/java/integ/convokraft/FallbackHandler.java +13 -0
  51. package/templates/init/functions/java/integ/convokraft/PromptHandler.java +17 -0
  52. package/templates/init/functions/java/integ/convokraft/Sample.java +62 -0
  53. package/templates/init/functions/java/integ/convokraft/WelcomeHandler.java +22 -0
  54. package/templates/init/functions/java/integ/convokraft/catalyst-config.json +12 -0
  55. package/templates/init/functions/node/integ/convokraft/catalyst-config.json +12 -0
  56. package/templates/init/functions/node/integ/convokraft/execute.js +16 -0
  57. package/templates/init/functions/node/integ/convokraft/failure.js +10 -0
  58. package/templates/init/functions/node/integ/convokraft/fallback.js +11 -0
  59. package/templates/init/functions/node/integ/convokraft/integ-response.js +13 -0
  60. package/templates/init/functions/node/integ/convokraft/logger.js +9 -0
  61. package/templates/init/functions/node/integ/convokraft/package.json +10 -0
  62. package/templates/init/functions/node/integ/convokraft/prompt.js +19 -0
  63. package/templates/init/functions/node/integ/convokraft/sample.js +46 -0
  64. package/templates/init/functions/node/integ/convokraft/welcome.js +12 -0
  65. package/templates/init/functions/python/integ/cliq/catalyst-config.json +2 -1
  66. package/templates/init/functions/python/integ/convokraft/catalyst-config.json +12 -0
  67. package/templates/init/functions/python/integ/convokraft/execute_handler.py +17 -0
  68. package/templates/init/functions/python/integ/convokraft/failure_handler.py +15 -0
  69. package/templates/init/functions/python/integ/convokraft/fallback_handler.py +16 -0
  70. package/templates/init/functions/python/integ/convokraft/prompt_handler.py +18 -0
  71. package/templates/init/functions/python/integ/convokraft/requirements.txt +1 -0
  72. package/templates/init/functions/python/integ/convokraft/sample.py +36 -0
  73. package/templates/init/functions/python/integ/convokraft/welcome_handler.py +19 -0
@@ -32,6 +32,8 @@ const logger_2 = require("../../util_modules/logger");
32
32
  const project_2 = require("../../util_modules/project");
33
33
  const shell_1 = require("../../util_modules/shell");
34
34
  const request_1 = __importDefault(require("request"));
35
+ const option_1 = require("../../util_modules/option");
36
+ const server_1 = require("../../util_modules/server");
35
37
  const logUrl = (name, pthName, httpPort, masterPort) => {
36
38
  (0, logger_2.labeled)(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
37
39
  };
@@ -323,6 +325,9 @@ class HttpFunctions {
323
325
  (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
324
326
  }, 1000);
325
327
  });
328
+ if ((0, option_1.getCurrentCommand)() === 'functions:shell') {
329
+ logUrl(target.name, new url_1.URL(target.url).pathname, httpPort, masterPort);
330
+ }
326
331
  });
327
332
  if (this.repl !== undefined) {
328
333
  this.repl.showPrompt();
@@ -335,10 +340,8 @@ class HttpFunctions {
335
340
  start() {
336
341
  return __awaiter(this, void 0, void 0, function* () {
337
342
  const server = yield this._spinUpServer();
338
- server.on('connection', (socket) => {
339
- socket.unref();
340
- });
341
- HttpFunctions.server = server;
343
+ const connDestroyer = new server_1.ConnectionDestroyer(server);
344
+ this.connDestroyer = connDestroyer;
342
345
  return server;
343
346
  });
344
347
  }
@@ -349,20 +352,13 @@ class HttpFunctions {
349
352
  slave.kill('SIGINT');
350
353
  });
351
354
  this.q.destroy(() => __awaiter(this, void 0, void 0, function* () {
352
- yield Promise.all(this.targets.map((target) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.close(); })));
353
- if (HttpFunctions.server !== null) {
354
- HttpFunctions.server.close((err) => {
355
- (0, logger_2.debug)(err);
356
- res();
357
- });
358
- }
359
- else {
360
- res();
361
- }
355
+ var _a;
356
+ yield Promise.all(this.targets.map((target) => __awaiter(this, void 0, void 0, function* () { var _b; return (_b = target.watcher) === null || _b === void 0 ? void 0 : _b.close(); })));
357
+ yield ((_a = this.connDestroyer) === null || _a === void 0 ? void 0 : _a.destroy());
358
+ res();
362
359
  }));
363
360
  });
364
361
  });
365
362
  }
366
363
  }
367
- HttpFunctions.server = null;
368
364
  exports.default = HttpFunctions;
@@ -21,6 +21,7 @@ const constants_1 = require("../../../util_modules/constants");
21
21
  const fs_1 = require("../../../util_modules/fs");
22
22
  const fs_2 = require("fs");
23
23
  const throbber_1 = __importDefault(require("../../../throbber"));
24
+ const error_1 = __importDefault(require("../../../error"));
24
25
  exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
25
26
  if (targets === undefined || targets.length === 0) {
26
27
  return;
@@ -55,14 +56,18 @@ exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
55
56
  const javaInvoker = (0, path_1.join)(__dirname, '../../../serve/server/lib/java/aio_server/JavaaioServer.java');
56
57
  (0, java_1.ensureJavaInvoker)(javaServer, javaInvoker);
57
58
  const serverFiles = yield fs_1.ASYNC.walk((0, path_1.dirname)(javaServer));
58
- yield Promise.all(serverFiles.map((file) => {
59
- return fs_1.ASYNC.copyFile(file, (0, path_1.join)(targetBuildPath, (0, path_1.relative)((0, path_1.dirname)(javaServer), file.replace('lib' + path_1.sep, ''))), fs_2.constants.COPYFILE_EXCL).catch((err) => {
59
+ yield Promise.all(serverFiles.map((file) => __awaiter(void 0, void 0, void 0, function* () {
60
+ try {
61
+ return fs_1.ASYNC.copyFile(file.path, (0, path_1.join)(targetBuildPath, (0, path_1.relative)((0, path_1.dirname)(javaServer), file.path.replace('lib' + path_1.sep, ''))), fs_2.constants.COPYFILE_EXCL);
62
+ }
63
+ catch (e) {
64
+ const err = error_1.default.getErrorInstance(e).original;
60
65
  if (err.code !== 'EEXIST') {
61
66
  throbber.remove('function_serve_' + target.name);
62
67
  throw err;
63
68
  }
64
- });
65
- }));
69
+ }
70
+ })));
66
71
  }
67
72
  yield (0, common_1.copyModDirPerm)((0, path_1.join)(target.source, constants_1.FOLDERNAME.output), targetBuildPath, '555', {
68
73
  replace: false
@@ -12,10 +12,13 @@ exports.default = Object.freeze({
12
12
  serve_port: {
13
13
  http: {
14
14
  master: 3000,
15
+ appsail: {
16
+ master: 3000,
17
+ service: 3060
18
+ },
15
19
  advancedio: 3010,
16
20
  basicio: 3040,
17
21
  client: 3050,
18
- appsail: 3060,
19
22
  browser_logic: 3100
20
23
  },
21
24
  debug: {
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const services = {
4
- cliq: 'ZohoCliq'
4
+ cliq: 'ZohoCliq',
5
+ convokraft: 'Convokraft'
5
6
  };
6
7
  exports.default = Object.freeze({
7
8
  services,
8
9
  service_map: {
9
- [services.cliq]: 'cliq'
10
+ [services.cliq]: 'cliq',
11
+ [services.convokraft]: services.convokraft.toLowerCase()
10
12
  },
11
13
  java_dependencies: {
12
14
  [services.cliq]: 'catalyst_java_cliq_sdk'
@@ -47,6 +47,7 @@ exports.default = Object.freeze({
47
47
  notification_web: 'ZohoCatalyst.notifications.web',
48
48
  search_read: 'ZohoCatalyst.search.READ',
49
49
  zia: 'ZohoCatalyst.mlkit.READ',
50
+ zia_hub: 'ZiaHub.deployment.READ',
50
51
  circuits_execute: 'ZohoCatalyst.circuits.execute',
51
52
  circuits_exe_read: 'ZohoCatalyst.circuits.execution.READ',
52
53
  circuits_exe_delete: 'ZohoCatalyst.circuits.execution.DELETE',
@@ -26,39 +26,42 @@ exports.default = Object.freeze({
26
26
  },
27
27
  functions: {
28
28
  node: {
29
- bio: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'bio'),
30
- event: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'event'),
31
- cron: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'cron'),
32
- aio: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'aio'),
33
- integ: {
34
- [constants_1.INTEG.services.cliq.toLowerCase()]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'integ', 'cliq')
29
+ [constants_1.FN_TYPE.basic]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'bio'),
30
+ [constants_1.FN_TYPE.event]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'event'),
31
+ [constants_1.FN_TYPE.cron]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'cron'),
32
+ [constants_1.FN_TYPE.advanced]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'aio'),
33
+ [constants_1.FN_TYPE.integration]: {
34
+ [constants_1.INTEG.services.cliq]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'integ', 'cliq'),
35
+ [constants_1.INTEG.services.convokraft]: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'integ', 'convokraft')
35
36
  },
36
- browserlogic: {
37
+ [constants_1.FN_TYPE.browserLogic]: {
37
38
  playwright: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'browserlogic', 'playwright'),
38
39
  puppeteer: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'browserlogic', 'puppeteer'),
39
40
  selenium: (0, path_1.join)(FUNCTIONS_NODE_ROOT, 'browserlogic', 'selenium')
40
41
  }
41
42
  },
42
43
  java: {
43
- bio: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'bio'),
44
- event: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'event'),
45
- cron: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'cron'),
46
- aio: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'aio'),
47
- integ: {
48
- [constants_1.INTEG.services.cliq.toLowerCase()]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'integ', 'cliq')
44
+ [constants_1.FN_TYPE.basic]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'bio'),
45
+ [constants_1.FN_TYPE.event]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'event'),
46
+ [constants_1.FN_TYPE.cron]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'cron'),
47
+ [constants_1.FN_TYPE.advanced]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'aio'),
48
+ [constants_1.FN_TYPE.integration]: {
49
+ [constants_1.INTEG.services.cliq]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'integ', 'cliq'),
50
+ [constants_1.INTEG.services.convokraft]: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'integ', 'convokraft')
49
51
  },
50
- browserlogic: {
52
+ [constants_1.FN_TYPE.browserLogic]: {
51
53
  selenium: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'browserlogic', 'selenium'),
52
54
  playwright: (0, path_1.join)(FUNCTIONS_JAVA_ROOT, 'browserlogic', 'playwright')
53
55
  }
54
56
  },
55
57
  python: {
56
- bio: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'bio'),
57
- event: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'event'),
58
- cron: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'cron'),
59
- aio: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'aio'),
60
- integ: {
61
- [constants_1.INTEG.services.cliq]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'integ', 'cliq')
58
+ [constants_1.FN_TYPE.basic]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'bio'),
59
+ [constants_1.FN_TYPE.event]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'event'),
60
+ [constants_1.FN_TYPE.cron]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'cron'),
61
+ [constants_1.FN_TYPE.advanced]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'aio'),
62
+ [constants_1.FN_TYPE.integration]: {
63
+ [constants_1.INTEG.services.cliq]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'integ', 'cliq'),
64
+ [constants_1.INTEG.services.convokraft]: (0, path_1.join)(FUNCTIONS_PYTHON_ROOT, 'integ', 'convokraft')
62
65
  }
63
66
  }
64
67
  },
@@ -94,15 +94,16 @@ function walk(dir, { filter = {
94
94
  excludeDir: true
95
95
  }, depth = -1, includeDirPaths = false } = {}) {
96
96
  return __awaiter(this, void 0, void 0, function* () {
97
+ const stats = yield fs_extra_1.default.lstat(dir);
97
98
  if (depth === 0) {
98
- return includeDirPaths ? [dir] : [];
99
+ return includeDirPaths ? [{ path: dir, stats }] : [];
99
100
  }
100
- const isDir = yield fs_extra_1.default.stat(dir).then((stat) => stat.isDirectory());
101
+ const isDir = stats.isDirectory() && !stats.isSymbolicLink();
101
102
  const files = isDir ? yield fs_extra_1.default.readdir(dir) : [path_1.default.basename(dir)];
102
103
  const folderContentPromise = files.map((entry) => __awaiter(this, void 0, void 0, function* () {
103
104
  const entryPath = isDir ? path_1.default.join(dir, entry) : dir;
104
- const stats = yield fs_extra_1.default.stat(entryPath);
105
- const isEntryPthDir = stats.isDirectory();
105
+ const entryPathStats = yield fs_extra_1.default.lstat(entryPath);
106
+ const isEntryPthDir = entryPathStats.isDirectory() && !entryPathStats.isSymbolicLink();
106
107
  let excludeMatch = false;
107
108
  if (!(isEntryPthDir && !filter.excludeDir)) {
108
109
  for (const glob of filter.exclude || []) {
@@ -114,10 +115,10 @@ function walk(dir, { filter = {
114
115
  }
115
116
  return isEntryPthDir && depth !== 0
116
117
  ? walk(entryPath, { filter, depth: depth - 1, includeDirPaths })
117
- : [entryPath];
118
+ : [{ path: entryPath, stats: entryPathStats }];
118
119
  }));
119
120
  const folderContents = yield Promise.all(folderContentPromise);
120
- return folderContents.reduce((all, folderContent) => all.concat(folderContent), includeDirPaths ? [dir] : []);
121
+ return folderContents.reduce((all, folderContent) => all.concat(folderContent), includeDirPaths ? [{ path: dir, stats }] : []);
121
122
  });
122
123
  }
123
124
  exports.walk = walk;
@@ -193,7 +194,7 @@ const findAndReplace = (pth) => (templates, finalWords) => __awaiter(void 0, voi
193
194
  }
194
195
  const files = yield walk(pth);
195
196
  yield Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
196
- let content = yield readFile(file);
197
+ let content = yield readFile(file.path);
197
198
  if (content === undefined) {
198
199
  return Promise.resolve();
199
200
  }
@@ -205,7 +206,7 @@ const findAndReplace = (pth) => (templates, finalWords) => __awaiter(void 0, voi
205
206
  else {
206
207
  content = content.replace(new RegExp(templates, 'g'), finalWords);
207
208
  }
208
- return writeFile(file, content);
209
+ return writeFile(file.path, content);
209
210
  })));
210
211
  });
211
212
  exports.findAndReplace = findAndReplace;
@@ -239,7 +240,7 @@ function chmod(path, mode, { checkPath = true, recursive = false } = {}) {
239
240
  if (recursive && (yield dirExists(path))) {
240
241
  const paths = yield walk(path, { includeDirPaths: true, depth: 1 });
241
242
  paths.shift();
242
- yield Promise.all(paths.map((_path) => chmod(_path, mode, { recursive, checkPath })));
243
+ yield Promise.all(paths.map((_path) => chmod(_path.path, mode, { recursive, checkPath })));
243
244
  }
244
245
  return fs_extra_1.default.chmod(path, mode);
245
246
  });
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeJSONFile = exports.readJSONFile = exports.emptyDir = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteTempDir = exports.tempFile = exports.deleteDir = exports.isPathInside = exports.isPathOutside = exports.renameFile = exports.modifyFileName = exports.appendFile = exports.writeFile = exports.ensureFile = exports.ensureDir = exports.readFile = exports.deleteFile = exports.getAllFiles = exports.getAllDirs = exports.dirExists = exports.fileExists = exports.getReadStream = exports.getWriteStream = void 0;
6
+ exports.writeJSONFile = exports.readJSONFile = exports.emptyDir = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteTempDir = exports.tempFile = exports.deleteDir = exports.isPathInside = exports.isPathOutside = exports.renameFile = exports.modifyFileName = exports.appendFile = exports.writeFile = exports.ensureFile = exports.ensureDir = exports.readFile = exports.deleteFile = exports.getAllFiles = exports.getAllDirs = exports.dirExists = exports.fileExists = exports.readSymLink = exports.getReadStream = exports.getWriteStream = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -15,6 +15,10 @@ function getReadStream(pth) {
15
15
  return fs_extra_1.default.createReadStream(pth);
16
16
  }
17
17
  exports.getReadStream = getReadStream;
18
+ function readSymLink(pth) {
19
+ return fs_extra_1.default.readlinkSync(pth);
20
+ }
21
+ exports.readSymLink = readSymLink;
18
22
  function fileExists(pth) {
19
23
  try {
20
24
  const stats = fs_extra_1.default.statSync(pth);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcatalyst-cli",
3
- "version": "1.15.0-beta.4",
3
+ "version": "1.15.0-beta.6",
4
4
  "description": "Command Line Tool for CATALYST",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -12,15 +12,25 @@ public class {{_CLASS_}} implements CatalystAdvancedIOHandler {
12
12
  @Override
13
13
  public void runner(HttpServletRequest request, HttpServletResponse response) throws Exception {
14
14
  try {
15
- String name = (String) request.getParameter("name");
16
- LOGGER.log(Level.INFO, "Hello "+name);
17
- response.setStatus(200);
15
+ switch(request.getRequestURI()) {
16
+ case "/": {
17
+ String name = (String) request.getParameter("name");
18
+ LOGGER.log(Level.INFO, "Hello "+name);
19
+ response.setStatus(200);
20
+ response.getWriter().write("Hello from {{_CLASS_}}.java");
21
+ break;
22
+ }
23
+ default: {
24
+ response.setStatus(404);
25
+ response.getWriter().write("You might find the page you are looking for at \"/\" path");
26
+ }
27
+ }
18
28
  }
19
29
  catch(Exception e) {
20
30
  LOGGER.log(Level.SEVERE,"Exception in {{_CLASS_}}",e);
21
31
  response.setStatus(500);
32
+ response.getWriter().write("Internal server error");
22
33
  }
23
- response.getWriter().write("Hello From {{_CLASS_}}.java");
24
34
  }
25
35
 
26
36
  }
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <classpath>
3
+ <classpathentry including="**/*.java" kind="src" path="."/>
4
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
+ <classpathentry kind="output" path=".output"/>
6
+ </classpath>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>{{_NAME_}}</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.jdt.core.javabuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.eclipse.jdt.core.javanature</nature>
16
+ </natures>
17
+ </projectDescription>
@@ -0,0 +1,20 @@
1
+ import org.json.JSONObject;
2
+ import java.util.logging.Logger;
3
+
4
+ public class ExecuteHandler {
5
+ Logger LOGGER = Logger.getLogger(ExecuteHandler.class.getName());
6
+ public JSONObject handleExecuteRequest(JSONObject reqBody) throws Exception{
7
+ LOGGER.info("Execution Handler : : " + reqBody.get("todo") + " : : : : Action : : : "+reqBody.getJSONObject("action").get("namespace"));
8
+ JSONObject jsonResponse = new JSONObject();
9
+ String message = "Bot Execute handler response:";
10
+
11
+ // This is where Your Execution Logic will be written, The Request body will have the params. you can fetch them from reqBody.getJSONObject("params") .
12
+ // After computation set the RESPONSE as follows : jsonResponse.put("message", "Result of addition is " + result);.
13
+ // For example below code will add two numbers coming as params number1 and number2 and setting result
14
+ // JSONObject params = reqBody.getJSONObject("params");
15
+ // Long result = params.getLong("number1") + params.getLong("number2");
16
+ // message = message + " " + result;
17
+ jsonResponse.put("message", message);
18
+ return jsonResponse;
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import org.json.JSONObject;
2
+ import java.util.logging.Logger;
3
+
4
+ public class FailureHandler {
5
+ Logger LOGGER = Logger.getLogger(FailureHandler.class.getName());
6
+ public JSONObject handleFailureRequest(JSONObject reqBody) throws Exception{
7
+
8
+ // This is your Failure Response Handler. You need to write the Failure Response when the bot Fails during execution of the function. The way to return Failure message is to be returned is as follows :
9
+ // {
10
+ // "message", "Sorry, Something went wrong"
11
+ // }
12
+ // Sample code to set the same is available Below.
13
+
14
+
15
+ JSONObject jsonResponse = new JSONObject();
16
+ LOGGER.info("Failure Handler : : TODO : " + reqBody.get("todo"));
17
+ jsonResponse.put("message", "Sorry, Something went wrong");
18
+ return jsonResponse;
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import org.json.JSONObject;
2
+ import java.util.logging.Logger;
3
+
4
+ public class FallbackHandler {
5
+ Logger LOGGER = Logger.getLogger(FallbackHandler.class.getName());
6
+ public JSONObject handleFallbackRequest(JSONObject reqBody) throws Exception{
7
+ JSONObject jsonResponse = new JSONObject();
8
+ LOGGER.info("Fallback Handler : : TODO : "+ reqBody.get("todo"));
9
+ jsonResponse.put("message", "Fallback Response: Please define this question and try again");
10
+ jsonResponse.put("status", "handled");
11
+ return jsonResponse;
12
+ }
13
+ }
@@ -0,0 +1,17 @@
1
+ import org.json.JSONObject;
2
+ import java.util.logging.Logger;
3
+
4
+ public class PromptHandler {
5
+ Logger LOGGER = Logger.getLogger(PromptHandler.class.getName());
6
+
7
+ public JSONObject handlePromptRequest(JSONObject reqBody) throws Exception {
8
+ JSONObject jsonResponse = new JSONObject();
9
+ LOGGER.info("Prompt Handler : : TODO : " + reqBody.get("todo"));
10
+ if (reqBody.isNull("paramsToPrompt") || reqBody.getJSONArray("paramsToPrompt").length() == 0) {
11
+ jsonResponse.put("todo", "execute");
12
+ return jsonResponse;
13
+ }
14
+ jsonResponse.put("todo", "prompt");
15
+ return jsonResponse;
16
+ }
17
+ }
@@ -0,0 +1,62 @@
1
+ import java.util.logging.Logger;
2
+
3
+ import org.json.JSONObject;
4
+
5
+ import com.catalyst.integ.CatalystIntegFunctionHandler;
6
+ import com.catalyst.integ.ZCIntegRequest;
7
+ import com.catalyst.integ.ZCIntegResponse;
8
+
9
+ public class {{_CLASS_}} implements CatalystIntegFunctionHandler {
10
+ Logger LOGGER = Logger.getLogger({{_CLASS_}}.class.getName());
11
+ WelcomeHandler welcomeHandler = new WelcomeHandler();
12
+ PromptHandler promptHandler = new PromptHandler();
13
+ ExecuteHandler executeHandler = new ExecuteHandler();
14
+ FallbackHandler fallbackHandler = new FallbackHandler();
15
+ FailureHandler failureHandler = new FailureHandler();
16
+
17
+ @Override
18
+ public ZCIntegResponse runner(ZCIntegRequest req) throws Exception {
19
+ JSONObject jsonResponse = new JSONObject();
20
+ try {
21
+ JSONObject reqBody = req.getRequestBody();
22
+ String todo = (String) reqBody.get("todo");
23
+ LOGGER.info(" TODO request " + todo);
24
+ switch (todo) {
25
+ case "welcome": {
26
+ jsonResponse = welcomeHandler.handleWelcomeRequest(reqBody);
27
+ break;
28
+ }
29
+ case "prompt": {
30
+ jsonResponse = promptHandler.handlePromptRequest(reqBody);
31
+ break;
32
+ }
33
+ case "execute": {
34
+ jsonResponse = executeHandler.handleExecuteRequest(reqBody);
35
+ break;
36
+ }
37
+ case "fallback": {
38
+ jsonResponse = fallbackHandler.handleFallbackRequest(reqBody);
39
+ break;
40
+ }
41
+ case "failure": {
42
+ jsonResponse = failureHandler.handleFailureRequest(reqBody);
43
+ break;
44
+ }
45
+ default: {
46
+ LOGGER.info(" default action " + reqBody.toString());
47
+ jsonResponse.put("message", "Error Trying to parse your details");
48
+ }
49
+ }
50
+ } catch (Exception ex) {
51
+ LOGGER.severe("Exception while executing handler. " + ex.toString());
52
+ LOGGER.severe("REQUEST OBJECT ::: " + req);
53
+ jsonResponse.put("message", "Error Trying to parse your details");
54
+ }
55
+
56
+ ZCIntegResponse response = new ZCIntegResponse();
57
+ response.setResponseBody(jsonResponse);
58
+ response.setContentType("application/json");
59
+ response.setStatus(200);
60
+ return response;
61
+ }
62
+ }
@@ -0,0 +1,22 @@
1
+ import org.json.JSONObject;
2
+ import java.util.logging.Logger;
3
+
4
+ public class WelcomeHandler {
5
+ Logger LOGGER = Logger.getLogger(WelcomeHandler.class.getName());
6
+ public JSONObject handleWelcomeRequest(JSONObject reqBody) throws Exception{
7
+ LOGGER.info("Welcome Handler: : TODO : "+ reqBody.get("todo"));
8
+ // This is your Welcome message Handler. You need to write the default Welcome message your want your bot to greet its users. The way to return welcome message is as follows :
9
+ // {
10
+ // "welcome_response" : {
11
+ // "message", "Welcome to your Bot. Please ask your queries"
12
+ // }
13
+ // }
14
+ // Sample code to set the same is available Below.
15
+
16
+ JSONObject welcomeResponse = new JSONObject();
17
+ welcomeResponse.put("message", "Welcome to your Bot. Please ask your queries");
18
+ JSONObject jsonResponse = new JSONObject();
19
+ jsonResponse.put("welcome_response", welcomeResponse);
20
+ return jsonResponse;
21
+ }
22
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "deployment": {
3
+ "name": "{{_NAME_}}",
4
+ "stack": "{{_STACK_}}",
5
+ "type": "{{_TYPE_}}",
6
+ "env_variables": {},
7
+ "integration_config": {{__INTEG_CONFIG__}}
8
+ },
9
+ "execution": {
10
+ "main": "{{_CLASS_}}"
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "deployment": {
3
+ "name": "{{_NAME_}}",
4
+ "stack": "{{_STACK_}}",
5
+ "type": "{{_TYPE_}}",
6
+ "env_variables": {},
7
+ "integration_config": {{__INTEG_CONFIG__}}
8
+ },
9
+ "execution": {
10
+ "main": "{{_MAIN_}}"
11
+ }
12
+ }
@@ -0,0 +1,16 @@
1
+ import logger from "./logger.js";
2
+
3
+ // Handle the execute functionality
4
+ export default function handleExecute(request) {
5
+ logger.info('Handling execute request');
6
+ let result = "";
7
+ // This is where Your Execution Logic will be written, The Request body will have the params. you can fetch them from request.params
8
+ // After computation set the RESPONSE as follows : {"message": "Result of addition is " + result}.
9
+ // For example below code will add two numbers coming as params number1 and number2 and setting result
10
+ // const params = request.params;
11
+ // result = parseInt(params.number1) + parseInt(params.number2);
12
+
13
+ return {
14
+ "message": "Bot Response : " + result
15
+ };
16
+ }
@@ -0,0 +1,10 @@
1
+ import logger from "./logger.js";
2
+
3
+ // Handle the failure functionality
4
+ export default function handleFailure(request) {
5
+ logger.info('Handling failure request');
6
+
7
+ return {
8
+ "message": "Failure Response: Please define this question and try again"
9
+ };
10
+ }
@@ -0,0 +1,11 @@
1
+ import logger from "./logger.js";
2
+
3
+ // Handle the fallback functionality
4
+ export default function handleFallback(request) {
5
+ logger.info('Handling fallback request');
6
+
7
+ return {
8
+ "status" : "handled",
9
+ "message": "Fallback Response: Please define this question and try again"
10
+ };
11
+ }
@@ -0,0 +1,13 @@
1
+ export default class IntegResponse {
2
+ response;
3
+ constructor(res) {
4
+ this.response = res;
5
+ }
6
+ buildResponse() {
7
+ return {
8
+ status: 200,
9
+ contentType: 'application/json',
10
+ responseBody: JSON.stringify(this.response)
11
+ };
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ // Logger module for logging messages
2
+ export default {
3
+ info: function(message) {
4
+ console.log('INFO:', message);
5
+ },
6
+ error: function(message) {
7
+ console.error('ERROR:', message);
8
+ }
9
+ };
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "{{_NAME_}}",
3
+ "version": "1.0.0",
4
+ "main": "{{_MAIN_}}",
5
+ "author": "{{_AUTHOR_}}",
6
+ "type": "module",
7
+ "dependencies": {
8
+ "zcatalyst-sdk-node": "^2.1.0"
9
+ }
10
+ }
@@ -0,0 +1,19 @@
1
+ import logger from "./logger.js";
2
+
3
+ // Handle the failure functionality
4
+ export default function handlePrompt(request) {
5
+ logger.info('Handling Prompt request');
6
+ logger.info('Params : ' + JSON.stringify(request.params));
7
+ if(request.paramsToPrompt === undefined || request.paramsToPrompt.length === 0) {
8
+ //This section will move the Bot to Execute handler as all params to prompt is completed.
9
+ return {
10
+ "todo" : "execute"
11
+ };
12
+ }
13
+ //This section will let the Bot to filter each param using request.params.
14
+ //And the Previous Param that was prompted to user will be present in request.previousParam.name.
15
+ //We can write validation logics using that.
16
+ return {
17
+ "todo" : "prompt"
18
+ };
19
+ }