zcatalyst-cli 1.13.2 → 1.14.0

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 (162) hide show
  1. package/docs/client-utils.toml +6 -1
  2. package/docs/commands/ds/import.toml +5 -0
  3. package/docs/fn-utils/lib/python.toml +4 -0
  4. package/docs/init/dependencies/python/ensure-python.toml +12 -0
  5. package/docs/init/dependencies/python/pip-install.toml +4 -0
  6. package/docs/serve/index.toml +5 -0
  7. package/lib/authentication/login.js +2 -1
  8. package/lib/cli_table/index.js +26 -2
  9. package/lib/cli_table/src/cell.js +359 -267
  10. package/lib/cli_table/src/layout-manager.js +231 -209
  11. package/lib/cli_table/src/table.js +76 -60
  12. package/lib/cli_table/src/utils.js +259 -224
  13. package/lib/client-utils.js +18 -4
  14. package/lib/command_needs/rc.js +57 -8
  15. package/lib/commands/config/delete.js +23 -0
  16. package/lib/commands/config/get.js +23 -0
  17. package/lib/commands/config/list.js +23 -0
  18. package/lib/commands/config/set.js +29 -0
  19. package/lib/commands/console/cache.js +31 -1
  20. package/lib/commands/console/queue.js +31 -1
  21. package/lib/commands/console/zcql.js +27 -1
  22. package/lib/commands/ds/export.js +2 -2
  23. package/lib/commands/ds/import.js +25 -5
  24. package/lib/commands/ds/status.js +2 -2
  25. package/lib/commands/iac/export.js +1 -1
  26. package/lib/commands/iac/import.js +1 -1
  27. package/lib/commands/iac/pack.js +16 -5
  28. package/lib/commands/iac/status.js +1 -1
  29. package/lib/commands/index.js +4 -0
  30. package/lib/commands/project/list.js +1 -1
  31. package/lib/commands/project/use.js +1 -1
  32. package/lib/deploy/features/client.js +2 -2
  33. package/lib/deploy/features/functions/index.js +13 -3
  34. package/lib/deploy/features/functions/languages/index.js +19 -2
  35. package/lib/endpoints/index.js +12 -5
  36. package/lib/endpoints/lib/env.js +5 -2
  37. package/lib/endpoints/lib/functions.js +30 -0
  38. package/lib/endpoints/lib/org.js +35 -0
  39. package/lib/endpoints/lib/project.js +7 -3
  40. package/lib/express_middlewares/unknownReqProxy.js +4 -1
  41. package/lib/fn-utils/index.js +2 -0
  42. package/lib/fn-utils/lib/common.js +68 -7
  43. package/lib/fn-utils/lib/integ.js +15 -11
  44. package/lib/fn-utils/lib/java.js +7 -3
  45. package/lib/fn-utils/lib/python.js +121 -0
  46. package/lib/fn-watcher.js +10 -2
  47. package/lib/index.js +2 -1
  48. package/lib/init/dependencies/python/ensure-python.js +151 -0
  49. package/lib/init/dependencies/python/pip-install.js +175 -0
  50. package/lib/init/features/functions/index.js +50 -29
  51. package/lib/init/features/functions/languages/index.js +3 -1
  52. package/lib/init/features/functions/languages/python.js +115 -0
  53. package/lib/init/features/index.js +2 -2
  54. package/lib/init/features/project.js +26 -6
  55. package/lib/init/util/project.js +2 -2
  56. package/lib/internal/api.js +2 -0
  57. package/lib/internal/command.js +1 -1
  58. package/lib/internal/rc.js +2 -0
  59. package/lib/port-resolver.js +4 -3
  60. package/lib/prompt/types/file-path.js +1 -1
  61. package/lib/pull/features/functions/index.js +35 -2
  62. package/lib/pull/features/functions/languages.js +8 -1
  63. package/lib/readLineUtils.js +37 -1
  64. package/lib/readline/features/cache.js +175 -1
  65. package/lib/readline/features/index.js +7 -1
  66. package/lib/readline/features/queue.js +209 -1
  67. package/lib/readline/features/zcql.js +237 -1
  68. package/lib/readline/index.js +30 -1
  69. package/lib/serve/index.js +48 -7
  70. package/lib/serve/server/index.js +118 -44
  71. package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  72. package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  73. package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  74. package/lib/serve/server/lib/master.js +18 -5
  75. package/lib/serve/server/lib/node.mjs +41 -0
  76. package/lib/serve/server/lib/web_client/index.js +7 -3
  77. package/lib/serve/server/lib/web_client/server.js +31 -15
  78. package/lib/shell/dependencies/http-functions.js +57 -21
  79. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
  80. package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
  81. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  82. package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
  83. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
  84. package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
  85. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
  86. package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
  87. package/lib/shell/dependencies/local-function.js +74 -22
  88. package/lib/shell/index.js +11 -2
  89. package/lib/shell/prepare/index.js +21 -0
  90. package/lib/shell/prepare/languages/index.js +8 -2
  91. package/lib/shell/prepare/languages/java.js +39 -2
  92. package/lib/shell/prepare/languages/node.js +21 -2
  93. package/lib/shell/prepare/languages/python.js +65 -0
  94. package/lib/throbber/index.js +3 -1
  95. package/lib/userConfig.js +48 -0
  96. package/lib/util_modules/constants/index.js +3 -1
  97. package/lib/util_modules/constants/lib/apig-rules.js +8 -0
  98. package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
  99. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  100. package/lib/util_modules/constants/lib/default.js +2 -2
  101. package/lib/util_modules/constants/lib/env-path.js +12 -0
  102. package/lib/util_modules/constants/lib/file-names.js +4 -1
  103. package/lib/util_modules/constants/lib/folder-names.js +3 -1
  104. package/lib/util_modules/constants/lib/placeholders.js +6 -1
  105. package/lib/util_modules/constants/lib/runtime.js +2 -1
  106. package/lib/util_modules/constants/lib/scopes.js +1 -0
  107. package/lib/util_modules/constants/lib/template.js +9 -0
  108. package/lib/util_modules/constants/lib/urls.js +2 -6
  109. package/lib/util_modules/context-help.js +2 -0
  110. package/lib/util_modules/fs/lib/async.js +35 -11
  111. package/lib/util_modules/project.js +20 -1
  112. package/package.json +2 -1
  113. package/templates/init/functions/java/aio/catalyst-config.json +3 -2
  114. package/templates/init/functions/java/bio/catalyst-config.json +3 -2
  115. package/templates/init/functions/java/cron/catalyst-config.json +3 -2
  116. package/templates/init/functions/java/event/catalyst-config.json +3 -2
  117. package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
  118. package/templates/init/functions/node/aio/catalyst-config.json +3 -2
  119. package/templates/init/functions/node/bio/catalyst-config.json +3 -2
  120. package/templates/init/functions/node/cron/catalyst-config.json +3 -2
  121. package/templates/init/functions/node/event/catalyst-config.json +3 -2
  122. package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
  123. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
  124. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
  125. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
  126. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
  127. package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
  128. package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
  129. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
  130. package/templates/init/functions/node/integ/cliq/sample.js +4 -4
  131. package/templates/init/functions/python/aio/catalyst-config.json +11 -0
  132. package/templates/init/functions/python/aio/requirements.txt +1 -0
  133. package/templates/init/functions/python/aio/sample.py +26 -0
  134. package/templates/init/functions/python/bio/catalyst-config.json +11 -0
  135. package/templates/init/functions/python/bio/requirements.txt +1 -0
  136. package/templates/init/functions/python/bio/sample.py +6 -0
  137. package/templates/init/functions/python/cron/catalyst-config.json +11 -0
  138. package/templates/init/functions/python/cron/requirements.txt +1 -0
  139. package/templates/init/functions/python/cron/sample.py +18 -0
  140. package/templates/init/functions/python/event/catalyst-config.json +11 -0
  141. package/templates/init/functions/python/event/requirements.txt +1 -0
  142. package/templates/init/functions/python/event/sample.py +21 -0
  143. package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
  144. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
  145. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
  146. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
  147. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
  148. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
  149. package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
  150. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
  151. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
  152. package/templates/init/functions/python/integ/cliq/sample.py +21 -0
  153. package/lib/serve/server/lib/node.js +0 -62
  154. package/lib/shell/dependencies/invoker/bio/node.js +0 -80
  155. package/lib/shell/dependencies/invoker/cron/node.js +0 -54
  156. package/lib/shell/dependencies/invoker/event/node.js +0 -56
  157. package/lib/shell/dependencies/invoker/integ/node.js +0 -79
  158. package/templates/.DS_Store +0 -0
  159. package/templates/init/.DS_Store +0 -0
  160. package/templates/init/client/.DS_Store +0 -0
  161. package/templates/init/client/react/.DS_Store +0 -0
  162. package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.checkIfRuntimeServerRunning = void 0;
15
16
  const better_queue_1 = __importDefault(require("better-queue"));
16
17
  const express_1 = __importDefault(require("express"));
17
18
  const path_1 = require("path");
@@ -30,23 +31,57 @@ const js_1 = require("../../util_modules/js");
30
31
  const logger_2 = require("../../util_modules/logger");
31
32
  const project_2 = require("../../util_modules/project");
32
33
  const shell_1 = require("../../util_modules/shell");
34
+ const request_1 = __importDefault(require("request"));
33
35
  const logUrl = (name, pthName, httpPort, masterPort) => {
34
36
  (0, logger_2.labeled)(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
35
37
  };
38
+ const checkIfRuntimeServerRunning = (port, itr = 0) => __awaiter(void 0, void 0, void 0, function* () {
39
+ if (itr > 50) {
40
+ throw new error_1.default('unable to spin up python runtime server', {
41
+ exit: 2
42
+ });
43
+ }
44
+ return new Promise((res) => {
45
+ request_1.default
46
+ .get(`http://127.0.0.1:${port}/ruok`, {
47
+ headers: {
48
+ 'x-zoho-catalyst-internal': 'true'
49
+ }
50
+ })
51
+ .on('response', (_response) => {
52
+ res(true);
53
+ })
54
+ .on('error', (error) => __awaiter(void 0, void 0, void 0, function* () {
55
+ const incommingError = error_1.default.getErrorInstance(error).original;
56
+ if (incommingError.code === 'ECONNREFUSED' ||
57
+ incommingError.code === 'ECONNRESET') {
58
+ yield js_1.JS.sleep(100);
59
+ yield (0, exports.checkIfRuntimeServerRunning)(port, ++itr).then((x) => res(x));
60
+ }
61
+ else {
62
+ throw new error_1.default('unable to spin up python runtime server', {
63
+ exit: 2
64
+ });
65
+ }
66
+ }));
67
+ });
68
+ });
69
+ exports.checkIfRuntimeServerRunning = checkIfRuntimeServerRunning;
36
70
  class HttpFunctions {
37
71
  constructor({ repl, primary = true } = {}) {
72
+ const projectRoot = runtime_store_1.default.get('project.root');
38
73
  this.repl = repl;
39
74
  this.app = (0, express_1.default)();
40
75
  this.app.locals.primary = primary;
41
76
  this.nodeInvoker = {
42
- [constants_1.FN_TYPE.basic]: (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', constants_1.FN_TYPE.basic, 'node.js'))
77
+ [constants_1.FN_TYPE.basic]: (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', constants_1.FN_TYPE.basic, 'node.mjs'))
43
78
  };
44
79
  this.javaInvoker = {
45
- [constants_1.FN_TYPE.basic]: (0, path_1.join)(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'Java' + constants_1.FN_TYPE.basic + 'Invoker')
80
+ [constants_1.FN_TYPE.basic]: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'Java' + constants_1.FN_TYPE.basic + 'Invoker')
46
81
  };
47
- this.requestFile = (0, path_1.join)(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_req_body');
48
- this.responseFile = (0, path_1.join)(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_res_body');
49
- this.metaFile = (0, path_1.join)(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_meta.json');
82
+ this.requestFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_req_body');
83
+ this.responseFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_res_body');
84
+ this.metaFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_meta.json');
50
85
  this.runningSlaves = [];
51
86
  this.targets = [];
52
87
  this.q = new better_queue_1.default((opts, cb) => {
@@ -65,12 +100,7 @@ class HttpFunctions {
65
100
  const slave = (0, shell_1.spawn)(opts.command, opts.options, {
66
101
  cwd: opts.pth,
67
102
  stdio: 'pipe',
68
- env: {
69
- X_ZOHO_CATALYST_IS_LOCAL: 'true',
70
- X_ZOHO_CATALYST_FUNCTION_LOADED: 'true',
71
- X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
72
- X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
73
- }
103
+ 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)
74
104
  }).RAW();
75
105
  (_a = slave.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
76
106
  (0, logger_2.info)(Buffer.isBuffer(data) ? data.toString() : data);
@@ -136,6 +166,7 @@ class HttpFunctions {
136
166
  const query = JSON.stringify(Object.fromEntries(urlParts.entries()));
137
167
  const slaveOptions = [];
138
168
  let slave = null;
169
+ const projectRoot = runtime_store_1.default.get('project.root');
139
170
  if (fnTarget.type === undefined) {
140
171
  throw new error_1.default('Function target type is not defined', {
141
172
  exit: 2
@@ -162,13 +193,14 @@ class HttpFunctions {
162
193
  'x-zc-cookie': request.headers['x-zc-cookie'],
163
194
  'x-zc-user-type': request.headers['x-zc-user-type']
164
195
  }));
165
- slaveOptions.push(JSON.stringify((0, path_1.join)(runtime_store_1.default.get('cwd'), '.build')));
196
+ slaveOptions.push(JSON.stringify((0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)));
166
197
  slave = this.q.push({
167
198
  command: 'node',
168
199
  options: slaveOptions,
169
- pth: fnTarget.source,
200
+ pth: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, fnTarget.name),
170
201
  req: request,
171
- id: fnTarget.name
202
+ id: fnTarget.name,
203
+ envVars: fnTarget.env_var
172
204
  });
173
205
  }
174
206
  else if ((_b = fnTarget.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java)) {
@@ -204,9 +236,10 @@ class HttpFunctions {
204
236
  slave = this.q.push({
205
237
  command: 'java',
206
238
  options: slaveOptions,
207
- pth: fnTarget.source,
239
+ pth: (0, path_1.join)(runtime_store_1.default.get('project.root'), constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, fnTarget.name),
208
240
  req: request,
209
- id: fnTarget.name
241
+ id: fnTarget.name,
242
+ envVars: fnTarget.env_var
210
243
  });
211
244
  }
212
245
  if (slave === null) {
@@ -243,12 +276,17 @@ class HttpFunctions {
243
276
  const masterPort = runtime_store_1.default.get(`context.port.http.master`, -1);
244
277
  const fnTargets = runtime_store_1.default.get('context.functions.targets', []);
245
278
  fnTargets
246
- .filter((t) => t.url !== undefined && t.type === constants_1.FN_TYPE.basic)
279
+ .filter((t) => {
280
+ var _a;
281
+ return t.url !== undefined &&
282
+ t.type === constants_1.FN_TYPE.basic &&
283
+ !((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python));
284
+ })
247
285
  .map((t) => {
248
286
  this.targets.push(t);
249
287
  return js_1.JS.omit(t, ['zip_stream', 'watcher', 'localFn']);
250
288
  })
251
- .forEach((t) => {
289
+ .forEach((t) => __awaiter(this, void 0, void 0, function* () {
252
290
  var _a;
253
291
  if ((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
254
292
  fn_utils_1.fnUtils.java.ensureJavaInvoker(this.javaInvoker[t.type], (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', t.type, 'java', 'Java' + t.type + 'Invoker.java')));
@@ -256,7 +294,6 @@ class HttpFunctions {
256
294
  const pthName = new url_1.URL(t.url).pathname;
257
295
  if (pthName !== null) {
258
296
  this.app.use(pthName, reqHandler(t));
259
- logUrl(t.name, pthName, httpPort, masterPort);
260
297
  }
261
298
  if (t.url_with_id !== undefined) {
262
299
  const pathWithId = new url_1.URL(t.url_with_id).pathname;
@@ -264,7 +301,7 @@ class HttpFunctions {
264
301
  this.app.use(pathWithId, reqHandler(t));
265
302
  }
266
303
  }
267
- });
304
+ }));
268
305
  return new Promise((res) => {
269
306
  const server = this.app.listen(httpPort, () => {
270
307
  this.targets.forEach((target) => {
@@ -298,7 +335,6 @@ class HttpFunctions {
298
335
  start() {
299
336
  return __awaiter(this, void 0, void 0, function* () {
300
337
  const server = yield this._spinUpServer();
301
- (0, logger_2.info)();
302
338
  server.on('connection', (socket) => {
303
339
  socket.unref();
304
340
  });
@@ -222,12 +222,11 @@ public class JavabioInvoker {
222
222
  HashMap<String, Object> target = jsonToMap(args[1]);
223
223
  String fnExeName = (String) target.get("index");
224
224
  String fnName = (String) target.get("name");
225
- String fnExePath = Paths.get(invokerDir, "..", fnName).normalize().toString();
225
+ String fnExePath = Paths.get(invokerDir, "..", "functions", fnName).normalize().toString();
226
226
 
227
227
  HashMap<String, Object> queryData = jsonToMap(args[2]);
228
228
  HashMap<String, Object> projectData = jsonToMap(args[3]);
229
229
  HashMap<String, Object> authData = jsonToMap(args[4]);
230
-
231
230
  File[] jarFiles = new File(fnExePath).listFiles(new FilenameFilter() {
232
231
  @Override
233
232
  public boolean accept(File dir, String name) {
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ import * as util from 'util';
4
+ import * as path from 'path';
5
+ import * as fs from 'fs';
6
+ import { pathToFileURL } from 'url';
7
+
8
+ const args = process.argv.slice(2);
9
+ const target = JSON.parse(args[0]);
10
+ const userData = JSON.parse(args[1]);
11
+ const projectJson = JSON.parse(args[2]);
12
+ const authJson = JSON.parse(args[3]);
13
+ const buildDir = JSON.parse(args[4]);
14
+
15
+ const requestFile = path.join(buildDir, '.catalyst', 'user_req_body');
16
+ const responseFile = path.join(buildDir, '.catalyst', 'user_res_body');
17
+ const metaFile = path.join(buildDir, '.catalyst', 'user_meta.json');
18
+
19
+ const writeToFile = (respJson, metaJson) => {
20
+ const respStr = JSON.stringify(respJson);
21
+ fs.writeFileSync(responseFile, respStr);
22
+ metaJson.response['Content-Type'] = 'application/json';
23
+ metaJson.response['Content-Length'] = respStr.length;
24
+ fs.writeFileSync(metaFile, JSON.stringify(metaJson));
25
+ };
26
+
27
+ let body = {};
28
+ let finalResponse = '';
29
+
30
+ let userStatus = 200;
31
+ if (fs.existsSync(requestFile)) {
32
+ const content = fs.readFileSync(requestFile);
33
+ try {
34
+ body = JSON.parse(content.toString());
35
+ } catch (err) {
36
+ body = {};
37
+ }
38
+ }
39
+
40
+ const endTime = 30 * 1000 + Date.now();
41
+
42
+ const context = {
43
+ catalystHeaders: Object.assign(projectJson, authJson),
44
+ getMaxExecutionTimeMs: () => 30 * 1000, // 30 sec
45
+ getRemainingExecutionTimeMs: () => endTime - Date.now(),
46
+ close: () => {
47
+ writeToFile(
48
+ {
49
+ output: finalResponse
50
+ },
51
+ { response: { statusCode: userStatus } }
52
+ );
53
+ process.exit(0);
54
+ },
55
+ // eslint-disable-next-line no-console
56
+ log: (...params) => console.log(...params)
57
+ };
58
+ const basicIO = {
59
+ write: (VALUE) => {
60
+ if (!typeof VALUE === 'string') {
61
+ // eslint-disable-next-line no-console
62
+ console.error(`Expected string but ${typeof VALUE} found!.`);
63
+ } else {
64
+ const res = VALUE.substring(0, 1 * 1024);
65
+ // eslint-disable-next-line no-console
66
+ console.log(res);
67
+ finalResponse += res;
68
+ }
69
+ },
70
+ getArgument: (KEY) => userData[KEY] || body[KEY],
71
+ getAllArguments: () => (userData && Object.keys(userData).length > 0 ? userData : body),
72
+ /**
73
+ * @deprecated use get getArgument instead.
74
+ */
75
+ getParameter: (KEY) => {
76
+ // eslint-disable-next-line no-console
77
+ console.error(
78
+ 'CatalystDeprecationWarning: basicIO.getParameter() is deprecated due to usability issues. Please use basicIO.getArgument() method instead.'
79
+ );
80
+ return basicIO.getArgument(KEY);
81
+ },
82
+ /**
83
+ * @deprecated use get getAllArgument instead.
84
+ */
85
+ getAllParameters: () => {
86
+ // eslint-disable-next-line no-console
87
+ console.error(
88
+ 'CatalystDeprecationWarning: basicIO.getAllParameters() is deprecated due to usability issues. Please use basicIO.getAllArgument() method instead.'
89
+ );
90
+ return basicIO.getAllArgument();
91
+ },
92
+ setStatus: (status) => {
93
+ userStatus = status;
94
+ }
95
+ };
96
+
97
+ import(pathToFileURL(target.index))
98
+ .then((module) => {
99
+ try {
100
+ if (!('default' in module)) {
101
+ throw new Error('Could not find any default export');
102
+ }
103
+ if (typeof module.default !== 'function') {
104
+ throw new Error('The default export is not a function');
105
+ }
106
+ module.default(context, basicIO);
107
+ } catch (e) {
108
+ // eslint-disable-next-line no-console
109
+ console.error(e);
110
+ writeToFile(
111
+ {
112
+ error: util.inspect(e)
113
+ },
114
+ { response: { statusCode: 500 } }
115
+ );
116
+ process.exit(2);
117
+ }
118
+ })
119
+ .catch((e) => {
120
+ // eslint-disable-next-line no-console
121
+ console.error(e);
122
+ writeToFile({
123
+ error: util.inspect(e),
124
+ response: { statusCode: 500 }
125
+ });
126
+ process.exit(2);
127
+ });
@@ -196,7 +196,7 @@ public class JavacronInvoker {
196
196
  HashMap<String, Object> target = jsonToMap(args[1]);
197
197
  String fnExeName = (String) target.get("index");
198
198
  String fnName = (String) target.get("name");
199
- String fnExePath = Paths.get(invokerDir, "..", fnName).normalize().toString();
199
+ String fnExePath = Paths.get(invokerDir, "..", "functions", fnName).normalize().toString();
200
200
 
201
201
  HashMap<String, Object> queryData = jsonToMap(args[2]);
202
202
  HashMap<String, Object> projectData = jsonToMap(args[3]);
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ import * as path from 'path';
4
+ import * as fs from 'fs';
5
+ import { pathToFileURL } from 'url';
6
+
7
+ const args = process.argv.slice(2);
8
+ const target = JSON.parse(args[0]);
9
+ const userData = JSON.parse(args[1]);
10
+ const projectJson = JSON.parse(args[2]);
11
+ const authJson = JSON.parse(args[3]);
12
+ const buildDir = JSON.parse(args[4]);
13
+
14
+ const requestFile = path.join(buildDir, '.catalyst', 'user_req_body');
15
+ const responseFile = path.join(buildDir, '.catalyst', 'user_res_body');
16
+
17
+ const writeToFile = (resp) => {
18
+ fs.writeFileSync(responseFile, resp);
19
+ };
20
+
21
+ let body = {};
22
+
23
+ if (fs.existsSync(requestFile)) {
24
+ const content = fs.readFileSync(requestFile);
25
+ try {
26
+ body = JSON.parse(content.toString());
27
+ } catch (err) {
28
+ body = {};
29
+ }
30
+ }
31
+
32
+ const endTime = 15 * 60 * 1000 + Date.now();
33
+
34
+ const context = {
35
+ catalystHeaders: Object.assign(projectJson, authJson),
36
+ getMaxExecutionTimeMs: () => 15 * 60 * 1000, // 15 mins
37
+ getRemainingExecutionTimeMs: () => endTime - Date.now(),
38
+ closeWithSuccess: () => {
39
+ writeToFile('SUCCESS');
40
+ process.exit(0);
41
+ },
42
+ closeWithFailure: () => {
43
+ writeToFile('FAILURE');
44
+ process.exit(0);
45
+ }
46
+ };
47
+ const cronReq = {
48
+ getCronParam: (KEY) => userData[KEY] || body[KEY],
49
+ getAllCronParam: () => (userData && Object.keys(userData).length > 0 ? userData : body),
50
+ getRemainingExecutionCount: () => -1,
51
+ getCronDetails: () => null,
52
+ getProjectDetails: () => projectJson
53
+ };
54
+
55
+ import(pathToFileURL(target.index))
56
+ .then((module) => {
57
+ try {
58
+ if (!('default' in module)) {
59
+ throw new Error('Could not find any default export');
60
+ }
61
+ if (typeof module.default !== 'function') {
62
+ throw new Error('The default export is not a function');
63
+ }
64
+ module.default(cronReq, context);
65
+ } catch (e) {
66
+ // eslint-disable-next-line no-console
67
+ console.error(e);
68
+ writeToFile(
69
+ {
70
+ error: inspect(e)
71
+ },
72
+ { response: { statusCode: 500 } }
73
+ );
74
+ process.exit(2);
75
+ }
76
+ })
77
+ .catch((e) => {
78
+ // eslint-disable-next-line no-console
79
+ console.error(e);
80
+ writeToFile(
81
+ {
82
+ error: inspect(e)
83
+ },
84
+ { response: { statusCode: 500 } }
85
+ );
86
+ process.exit(2);
87
+ });
@@ -196,7 +196,7 @@ public class JavaeventInvoker {
196
196
  HashMap<String, Object> target = jsonToMap(args[1]);
197
197
  String fnExeName = (String) target.get("index");
198
198
  String fnName = (String) target.get("name");
199
- String fnExePath = Paths.get(invokerDir, "..", fnName).normalize().toString();
199
+ String fnExePath = Paths.get(invokerDir, "..", "functions", fnName).normalize().toString();
200
200
 
201
201
  HashMap<String, Object> queryData = jsonToMap(args[2]);
202
202
  HashMap<String, Object> projectData = jsonToMap(args[3]);
@@ -242,8 +242,8 @@ public class JavaeventInvoker {
242
242
  defaultEvent.setData(userData.get("data"));
243
243
  defaultEvent.setProjectDetails(projectDetails == "null" ? null : new JSONObject(projectDetails));
244
244
  defaultEvent.setSource(String.valueOf(userData.get("source")));
245
- defaultEvent.setSourceEntityId(sourceId == null ? null : Long.valueOf(sourceId));
246
- defaultEvent.setTime(eventTime == null ? null : Long.valueOf(eventTime));
245
+ defaultEvent.setSourceEntityId(sourceId == "null" ? null : Long.valueOf(sourceId));
246
+ defaultEvent.setTime(eventTime == "null" ? null : Long.valueOf(eventTime));
247
247
 
248
248
  EventRequest eventRequest = defaultEvent;
249
249
 
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ import * as path from 'path';
4
+ import * as fs from 'fs';
5
+ import { pathToFileURL } from 'url';
6
+
7
+ const args = process.argv.slice(2);
8
+ const target = JSON.parse(args[0]);
9
+ const userData = JSON.parse(args[1]);
10
+ const projectJson = JSON.parse(args[2]);
11
+ const authJson = JSON.parse(args[3]);
12
+ const buildDir = JSON.parse(args[4]);
13
+
14
+ const responseFile = path.join(buildDir, '.catalyst', 'user_res_body');
15
+
16
+ const writeToFile = (resp) => {
17
+ fs.writeFileSync(responseFile, resp);
18
+ };
19
+
20
+ const endTime = 15 * 60 * 1000 + Date.now();
21
+
22
+ const context = {
23
+ catalystHeaders: Object.assign(projectJson, authJson),
24
+ getMaxExecutionTimeMs: () => 15 * 60 * 1000, // 15 mins
25
+ getRemainingExecutionTimeMs: () => endTime - Date.now(),
26
+ closeWithSuccess: () => {
27
+ writeToFile('SUCCESS');
28
+ process.exit(0);
29
+ },
30
+ closeWithFailure: () => {
31
+ writeToFile('FAILURE');
32
+ process.exit(0);
33
+ }
34
+ };
35
+ const eventReq = {
36
+ data: userData.data,
37
+ time: userData.event_time,
38
+ getData: () => userData.data,
39
+ getTime: () => userData.event_time,
40
+ getAction: () => userData.action,
41
+ getSource: () => userData.source,
42
+ getSourceEntityId: () => userData.source_entity_id,
43
+ getEventBusDetails: () => userData.event_bus_details,
44
+ getProjectDetails: () => userData.project_details,
45
+ /**
46
+ * @deprecated use individual get methods.
47
+ */
48
+ getSourceDetails: () => {
49
+ // eslint-disable-next-line no-console
50
+ console.error(
51
+ 'CatalystDeprecationWarning: eventReq.getSourceDetails() is deprecated due to usability issues. Please use individual get methods instead.'
52
+ );
53
+ return {
54
+ action: userData.action,
55
+ type: userData.source,
56
+ entityId: userData.source_entity_id,
57
+ getBusDetails: () => userData.event_bus_details
58
+ };
59
+ }
60
+ };
61
+
62
+ import(pathToFileURL(target.index))
63
+ .then((module) => {
64
+ try {
65
+ if (!('default' in module)) {
66
+ throw new Error('Could not find any default export');
67
+ }
68
+ if (typeof module.default !== 'function') {
69
+ throw new Error('The default export is not a function');
70
+ }
71
+ module.default(eventReq, context);
72
+ } catch (e) {
73
+ // eslint-disable-next-line no-console
74
+ console.error(e);
75
+ writeToFile('FAILURE');
76
+ process.exit(2);
77
+ }
78
+ })
79
+ .catch((e) => {
80
+ // eslint-disable-next-line no-console
81
+ console.error(e);
82
+ writeToFile('FAILURE');
83
+ process.exit(2);
84
+ });
@@ -172,7 +172,7 @@ public class JavaintegInvoker {
172
172
  HashMap<String, Object> target = jsonToMap(args[1]);
173
173
  String fnExeName = (String) target.get("index");
174
174
  String fnName = (String) target.get("name");
175
- String fnExePath = Paths.get(invokerDir, "..", fnName).normalize().toString();
175
+ String fnExePath = Paths.get(invokerDir, "..", "functions", fnName).normalize().toString();
176
176
 
177
177
  Path configJsonPath = Paths.get(fnExePath, "catalyst-config.json");
178
178
 
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ import { inspect } from 'util';
4
+ import { join } from 'path';
5
+ import { writeFileSync } from 'fs';
6
+ import { pathToFileURL } from 'url';
7
+
8
+ const args = process.argv.slice(2);
9
+ const target = JSON.parse(args[0]);
10
+
11
+ const data = JSON.parse(args[1]);
12
+ const projectJson = JSON.parse(args[2]);
13
+ const authJson = JSON.parse(args[3]);
14
+ const buildDir = JSON.parse(args[4]);
15
+
16
+ const responseFile = join(buildDir, '.catalyst', 'user_res_body');
17
+
18
+ const writeAndExit = (resp, exitCode = 0) => {
19
+ writeFileSync(responseFile, JSON.stringify(resp));
20
+ process.exit(exitCode);
21
+ };
22
+
23
+ const integrationRequest = data || {};
24
+
25
+ integrationRequest.catalystHeaders = Object.assign(projectJson, authJson);
26
+ integrationRequest.timestamp = Date.now();
27
+
28
+ const integrationResponse = {
29
+ end: (response) => {
30
+ if (response === undefined) {
31
+ return writeAndExit({ Status: 204 });
32
+ }
33
+
34
+ if (
35
+ response.constructor.name !== 'IntegResponse' ||
36
+ response.buildResponse === undefined ||
37
+ typeof response.buildResponse !== 'function'
38
+ ) {
39
+ // eslint-disable-next-line no-console
40
+ console.error('Invalid response object: ', response);
41
+ return writeAndExit({ Status: 500 }, 2);
42
+ }
43
+
44
+ const clean_response = response.buildResponse();
45
+ if (
46
+ clean_response === undefined ||
47
+ clean_response.status === undefined ||
48
+ typeof clean_response.status !== 'number' ||
49
+ clean_response.contentType === undefined ||
50
+ typeof clean_response.contentType !== 'string' ||
51
+ clean_response.responseBody === undefined
52
+ ) {
53
+ // eslint-disable-next-line no-console
54
+ console.error(
55
+ "Invalid value returned from function 'buildResponse()': ",
56
+ clean_response
57
+ );
58
+ return writeAndExit({ Status: 500 }, 2);
59
+ }
60
+ return writeAndExit({
61
+ Status: clean_response.status,
62
+ ContentType: clean_response.contentType,
63
+ responseBody: clean_response.responseBody
64
+ });
65
+ }
66
+ };
67
+
68
+ import(pathToFileURL(target.index))
69
+ .then((module) => {
70
+ try {
71
+ if (!('default' in module)) {
72
+ throw new Error('Could not find any default export');
73
+ }
74
+ if (typeof module.default !== 'function') {
75
+ throw new Error('The default export is not a function');
76
+ }
77
+ module.default(integrationRequest, integrationResponse);
78
+ } catch (e) {
79
+ // eslint-disable-next-line no-console
80
+ console.error(e);
81
+ writeAndExit({ error: inspect(e) }, 2);
82
+ }
83
+ })
84
+ .catch((e) => {
85
+ // eslint-disable-next-line no-console
86
+ console.error(e);
87
+ writeAndExit({ error: inspect(e) }, 2);
88
+ });