zcatalyst-cli 1.25.3 → 1.26.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 (262) hide show
  1. package/lib/api-timer.d.ts +0 -1
  2. package/lib/apig-utils.d.ts +1 -1
  3. package/lib/apig-utils.js +1 -1
  4. package/lib/appsail-utils.js +6 -7
  5. package/lib/archiver.d.ts +0 -4
  6. package/lib/archiver.js +21 -11
  7. package/lib/authentication/constants/auth.js +1 -1
  8. package/lib/authentication/credential.js +3 -3
  9. package/lib/authentication/index.js +25 -14
  10. package/lib/authentication/login.d.ts +0 -2
  11. package/lib/authentication/login.js +23 -10
  12. package/lib/bin/catalyst.js +17 -7
  13. package/lib/client-utils.d.ts +3 -3
  14. package/lib/client-utils.js +2 -2
  15. package/lib/client.js +19 -9
  16. package/lib/code-deck.d.ts +0 -2
  17. package/lib/code-deck.js +4 -4
  18. package/lib/command_needs/config.js +1 -1
  19. package/lib/command_needs/rc.js +5 -2
  20. package/lib/commands/appsail/add.js +17 -7
  21. package/lib/commands/client/setup.js +17 -7
  22. package/lib/commands/config/set.js +5 -3
  23. package/lib/commands/deploy/appsail.js +37 -14
  24. package/lib/commands/deploy/index.js +88 -66
  25. package/lib/commands/deploy/slate.js +37 -14
  26. package/lib/commands/event/generate/integ.js +18 -9
  27. package/lib/commands/functions/add.js +17 -7
  28. package/lib/commands/functions/execute.js +17 -7
  29. package/lib/commands/functions/setup.js +17 -7
  30. package/lib/commands/functions/shell.js +17 -7
  31. package/lib/commands/iac/import.js +18 -8
  32. package/lib/commands/iac/pack.js +17 -7
  33. package/lib/commands/iac/status.js +17 -7
  34. package/lib/commands/index.js +20 -12
  35. package/lib/commands/init.js +17 -7
  36. package/lib/commands/login.js +17 -7
  37. package/lib/commands/logout.js +17 -7
  38. package/lib/commands/project/list.js +17 -7
  39. package/lib/commands/project/use.js +1 -0
  40. package/lib/commands/pull.js +17 -7
  41. package/lib/commands/run.js +17 -7
  42. package/lib/commands/serve.js +17 -7
  43. package/lib/commands/signals/generate/index.js +1 -1
  44. package/lib/commands/slate/create.js +17 -7
  45. package/lib/commands/slate/link.js +17 -7
  46. package/lib/commands/token/generate.js +17 -7
  47. package/lib/commands/token/list.js +17 -7
  48. package/lib/commands/token/revoke.js +17 -7
  49. package/lib/commands/zest/generate/index.js +21 -11
  50. package/lib/deploy/features/appsail/index.js +2 -3
  51. package/lib/deploy/features/appsail/pack.d.ts +0 -1
  52. package/lib/deploy/features/appsail/pack.js +2 -3
  53. package/lib/deploy/features/appsail/utils.js +7 -8
  54. package/lib/deploy/features/functions/languages/index.js +3 -4
  55. package/lib/deploy/features/index.js +17 -7
  56. package/lib/deploy/features/slate.js +2 -3
  57. package/lib/deploy/index.js +2 -2
  58. package/lib/deploy/util.d.ts +2 -0
  59. package/lib/deploy/util.js +3 -1
  60. package/lib/docs/commands/signals/generate/generate.toml +19 -0
  61. package/lib/docs/commands/slate/unlink.toml +9 -0
  62. package/lib/docs/fn-utils/lib/node.toml +4 -0
  63. package/lib/docs/init/dependencies/python/ensure-python.toml +4 -0
  64. package/lib/docs/serve/server/lib/slate/index.toml +15 -0
  65. package/lib/docs/slate-utils.toml +9 -0
  66. package/lib/endpoints/index.d.ts +2 -1
  67. package/lib/endpoints/index.js +88 -79
  68. package/lib/endpoints/lib/apig.d.ts +0 -1
  69. package/lib/endpoints/lib/apig.js +2 -2
  70. package/lib/endpoints/lib/applogic.d.ts +0 -1
  71. package/lib/endpoints/lib/applogic.js +2 -2
  72. package/lib/endpoints/lib/appsail.d.ts +1 -4
  73. package/lib/endpoints/lib/appsail.js +7 -7
  74. package/lib/endpoints/lib/client.d.ts +0 -1
  75. package/lib/endpoints/lib/code-deck.js +1 -1
  76. package/lib/endpoints/lib/common.d.ts +0 -2
  77. package/lib/endpoints/lib/ds-bulk.js +2 -2
  78. package/lib/endpoints/lib/env.js +2 -2
  79. package/lib/endpoints/lib/filestore.d.ts +0 -1
  80. package/lib/endpoints/lib/functions.d.ts +0 -1
  81. package/lib/endpoints/lib/functions.js +2 -2
  82. package/lib/endpoints/lib/git-hub.d.ts +0 -2
  83. package/lib/endpoints/lib/iac.d.ts +0 -3
  84. package/lib/endpoints/lib/iac.js +2 -2
  85. package/lib/endpoints/lib/project.d.ts +0 -1
  86. package/lib/endpoints/lib/project.js +2 -2
  87. package/lib/endpoints/lib/sdk.d.ts +0 -2
  88. package/lib/endpoints/lib/sdk.js +1 -1
  89. package/lib/endpoints/lib/slate.d.ts +0 -1
  90. package/lib/endpoints/lib/stratus.d.ts +0 -1
  91. package/lib/endpoints/lib/user.d.ts +0 -2
  92. package/lib/endpoints/lib/user.js +2 -1
  93. package/lib/error/context-help.js +1 -1
  94. package/lib/error/index.js +2 -2
  95. package/lib/event_generate/cache.js +4 -4
  96. package/lib/event_generate/custom.js +1 -2
  97. package/lib/event_generate/datastore.js +4 -4
  98. package/lib/event_generate/filestore.js +4 -4
  99. package/lib/event_generate/github.js +2 -2
  100. package/lib/event_generate/index.js +19 -11
  101. package/lib/event_generate/stratus.js +2 -2
  102. package/lib/event_generate/user.js +2 -2
  103. package/lib/event_generate/webapp.js +2 -2
  104. package/lib/execute/caller.d.ts +0 -1
  105. package/lib/execute/caller.js +20 -7
  106. package/lib/execute/index.js +27 -4
  107. package/lib/execute-script.js +22 -13
  108. package/lib/express_middlewares/auth-checker.js +2 -3
  109. package/lib/express_middlewares/project.d.ts +1 -1
  110. package/lib/fn-utils/index.js +17 -7
  111. package/lib/fn-utils/lib/browserLogic.js +4 -5
  112. package/lib/fn-utils/lib/common.d.ts +0 -1
  113. package/lib/fn-utils/lib/common.js +25 -26
  114. package/lib/fn-utils/lib/integ.js +2 -3
  115. package/lib/fn-utils/lib/java/classpath.js +2 -3
  116. package/lib/fn-utils/lib/java/compile.js +4 -4
  117. package/lib/fn-utils/lib/java/ensure-java-userconfig.d.ts +10 -0
  118. package/lib/fn-utils/lib/java/ensure-java-userconfig.js +45 -23
  119. package/lib/fn-utils/lib/java/index.d.ts +0 -1
  120. package/lib/fn-utils/lib/java/index.js +11 -11
  121. package/lib/fn-utils/lib/java/keywords.js +2 -2
  122. package/lib/fn-utils/lib/node.d.ts +1 -1
  123. package/lib/fn-utils/lib/node.js +67 -15
  124. package/lib/fn-utils/lib/python.js +29 -19
  125. package/lib/iac/status/util/index.d.ts +1 -1
  126. package/lib/init/dependencies/npm-install.js +2 -2
  127. package/lib/init/dependencies/python/ensure-python.d.ts +2 -2
  128. package/lib/init/dependencies/python/ensure-python.js +65 -58
  129. package/lib/init/dependencies/python/pip-install.d.ts +3 -5
  130. package/lib/init/dependencies/python/pip-install.js +14 -53
  131. package/lib/init/features/appsail/utils.js +21 -12
  132. package/lib/init/features/client/index.js +18 -9
  133. package/lib/init/features/client/initializers/angular.js +17 -7
  134. package/lib/init/features/client/initializers/basic.js +17 -7
  135. package/lib/init/features/client/initializers/lyte.js +17 -7
  136. package/lib/init/features/client/initializers/react.js +17 -7
  137. package/lib/init/features/index.js +29 -20
  138. package/lib/init/features/project.js +5 -5
  139. package/lib/init/features/slate/index.js +19 -9
  140. package/lib/init/util/client.js +23 -13
  141. package/lib/init/util/common.js +5 -6
  142. package/lib/init/util/project.js +1 -1
  143. package/lib/internal/api.d.ts +0 -3
  144. package/lib/internal/api.js +19 -9
  145. package/lib/internal/command.js +18 -9
  146. package/lib/migration/global/1.25.0.d.ts +2 -0
  147. package/lib/migration/global/1.25.0.js +28 -0
  148. package/lib/migration/index.js +20 -12
  149. package/lib/option-filter.js +19 -10
  150. package/lib/optional-import.js +19 -10
  151. package/lib/plugin-loader.d.ts +0 -2
  152. package/lib/plugin-loader.js +18 -8
  153. package/lib/port-resolver.js +10 -10
  154. package/lib/prompt/index.d.ts +3 -3
  155. package/lib/prompt/index.js +17 -7
  156. package/lib/prompt/types/file-path.d.ts +0 -1
  157. package/lib/prompt/types/search-box.d.ts +0 -1
  158. package/lib/prompt/types/tree.d.ts +1 -2
  159. package/lib/prompt/types/tree.js +10 -10
  160. package/lib/prompt/types/with-description.d.ts +0 -1
  161. package/lib/pull/features/functions/index.js +71 -52
  162. package/lib/pull/features/functions/languages.js +3 -4
  163. package/lib/pull/features/index.js +17 -7
  164. package/lib/repl-server.d.ts +0 -1
  165. package/lib/repl-server.js +9 -1
  166. package/lib/serve/features/apig.js +7 -1
  167. package/lib/serve/features/appsail.d.ts +1 -0
  168. package/lib/serve/features/appsail.js +51 -7
  169. package/lib/serve/features/index.js +22 -13
  170. package/lib/serve/index.js +17 -7
  171. package/lib/serve/server/index.d.ts +0 -2
  172. package/lib/serve/server/index.js +26 -12
  173. package/lib/serve/server/lib/appsail/index.js +27 -34
  174. package/lib/serve/server/lib/appsail/start.js +12 -5
  175. package/lib/serve/server/lib/appsail/util.d.ts +11 -0
  176. package/lib/serve/server/lib/appsail/util.js +69 -0
  177. package/lib/serve/server/lib/java/index.js +18 -7
  178. package/lib/serve/server/lib/master/appsail.js +3 -4
  179. package/lib/serve/server/lib/master/functions.js +1 -2
  180. package/lib/serve/server/lib/master/index.d.ts +0 -1
  181. package/lib/serve/server/lib/master/index.js +5 -5
  182. package/lib/serve/server/lib/master/slate.js +1 -2
  183. package/lib/serve/server/lib/master/unknown-req-proxy.js +5 -2
  184. package/lib/serve/server/lib/master/utils.d.ts +4 -8
  185. package/lib/serve/server/lib/master/utils.js +4 -6
  186. package/lib/serve/server/lib/master/web-client.js +1 -2
  187. package/lib/serve/server/lib/node/index.js +22 -11
  188. package/lib/serve/server/lib/node/server/browserlogic/utils/playwright-handler.js +1 -1
  189. package/lib/serve/server/lib/node/server/browserlogic/utils/puppeteer-handler.js +1 -1
  190. package/lib/serve/server/lib/node/server/browserlogic/utils/selenium-handler.js +2 -0
  191. package/lib/serve/server/lib/python/index.js +23 -14
  192. package/lib/serve/server/lib/slate/static-server.d.ts +0 -1
  193. package/lib/serve/server/lib/slate/static-server.js +5 -4
  194. package/lib/serve/server/lib/web_client/server.d.ts +0 -1
  195. package/lib/serve/server/lib/web_client/server.js +5 -4
  196. package/lib/shell/dependencies/http-functions.d.ts +0 -2
  197. package/lib/shell/dependencies/http-functions.js +7 -7
  198. package/lib/shell/dependencies/non-http-function/fn-execution-handler.d.ts +0 -2
  199. package/lib/shell/dependencies/non-http-function/fn-execution-handler.js +55 -24
  200. package/lib/shell/dependencies/non-http-function/fn-handler.d.ts +3 -3
  201. package/lib/shell/dependencies/non-http-function/fn-handler.js +54 -20
  202. package/lib/shell/dependencies/non-http-function/node.js +4 -4
  203. package/lib/shell/dependencies/non-http-function/python.d.ts +1 -1
  204. package/lib/shell/dependencies/non-http-function/python.js +11 -13
  205. package/lib/shell/dependencies/non-http-function/slave-manager.d.ts +0 -2
  206. package/lib/shell/dependencies/non-http-function/slave-manager.js +11 -7
  207. package/lib/shell/dependencies/tunnel-server.js +4 -4
  208. package/lib/shell/index.js +50 -3
  209. package/lib/shell/prepare/index.js +4 -3
  210. package/lib/shell/prepare/languages/index.js +18 -9
  211. package/lib/shell/prepare/languages/node.js +29 -19
  212. package/lib/shell/prepare/languages/python.js +6 -12
  213. package/lib/signals/index.js +19 -11
  214. package/lib/slate-utils.js +2 -2
  215. package/lib/throbber/index.d.ts +1 -2
  216. package/lib/throbber/index.js +5 -2
  217. package/lib/throbber/utils.d.ts +0 -1
  218. package/lib/throbber/utils.js +4 -5
  219. package/lib/userConfig.d.ts +14 -0
  220. package/lib/userConfig.js +15 -1
  221. package/lib/util_modules/config/index.js +17 -7
  222. package/lib/util_modules/config/lib/apig.d.ts +1 -0
  223. package/lib/util_modules/config/lib/apig.js +10 -5
  224. package/lib/util_modules/config/lib/appsail.js +7 -7
  225. package/lib/util_modules/config/lib/client.js +5 -6
  226. package/lib/util_modules/config/lib/functions.js +5 -6
  227. package/lib/util_modules/config/lib/slate.js +5 -6
  228. package/lib/util_modules/config-store.d.ts +1 -1
  229. package/lib/util_modules/config-store.js +30 -13
  230. package/lib/util_modules/constants/lib/apig-rules.d.ts +1 -1
  231. package/lib/util_modules/constants/lib/dc-type.js +3 -3
  232. package/lib/util_modules/constants/lib/placeholders.d.ts +1 -1
  233. package/lib/util_modules/constants/lib/placeholders.js +1 -1
  234. package/lib/util_modules/constants/lib/urls.js +2 -9
  235. package/lib/util_modules/container.js +23 -14
  236. package/lib/util_modules/dc.js +3 -4
  237. package/lib/util_modules/env.d.ts +3 -0
  238. package/lib/util_modules/env.js +64 -4
  239. package/lib/util_modules/event-emitter.d.ts +9 -0
  240. package/lib/util_modules/event-emitter.js +68 -0
  241. package/lib/util_modules/fs/index.js +17 -7
  242. package/lib/util_modules/fs/lib/async.d.ts +0 -4
  243. package/lib/util_modules/fs/lib/async.js +46 -46
  244. package/lib/util_modules/fs/lib/sync.d.ts +1 -3
  245. package/lib/util_modules/fs/lib/sync.js +40 -30
  246. package/lib/util_modules/logger/index.js +12 -12
  247. package/lib/util_modules/logger/utils.d.ts +0 -4
  248. package/lib/util_modules/logger/utils.js +1 -1
  249. package/lib/util_modules/logger/winston.js +2 -2
  250. package/lib/util_modules/option.js +5 -6
  251. package/lib/util_modules/project.js +22 -23
  252. package/lib/util_modules/runtime-store.d.ts +2 -2
  253. package/lib/util_modules/server.d.ts +1 -2
  254. package/lib/util_modules/server.js +54 -15
  255. package/lib/util_modules/shell.d.ts +0 -3
  256. package/lib/util_modules/shell.js +5 -6
  257. package/lib/util_modules/toml.js +2 -3
  258. package/package.json +13 -13
  259. package/templates/init/functions/java/event/sample.java +5 -2
  260. package/templates/web-socket.txt +1 -1
  261. /package/lib/docs/{commands/event/generate → event_generate}/index.toml +0 -0
  262. /package/templates/init/functions/java/integ/convokraft/{Sample.java → sample.java} +0 -0
@@ -41,8 +41,8 @@ const port_resolver_1 = __importDefault(require("../../port-resolver"));
41
41
  const logUrl = (name, pthName, httpPort, masterPort) => {
42
42
  (0, index_1.labeled)(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
43
43
  };
44
- const checkIfRuntimeServerRunning = (port, itr = 0) => __awaiter(void 0, void 0, void 0, function* () {
45
- if (itr > 50) {
44
+ const checkIfRuntimeServerRunning = (port_1, ...args_1) => __awaiter(void 0, [port_1, ...args_1], void 0, function* (port, itr = 0) {
45
+ if (itr > 100) {
46
46
  throw new error_1.default('Unable to spin up python runtime server. Max retry reached', {
47
47
  exit: 2
48
48
  });
@@ -212,7 +212,7 @@ class HttpFunctions {
212
212
  this.app.use(authenticator_1.default);
213
213
  }
214
214
  const reqHandler = (fnTarget) => (request, response, next) => {
215
- var _a, _b, _c, _d;
215
+ var _a, _b, _c, _d, _e;
216
216
  const urlParts = new url_1.URL(request.originalUrl, request.protocol + '://' + request.get('host')).searchParams;
217
217
  const query = JSON.stringify(Object.fromEntries(urlParts.entries()));
218
218
  const slaveOptions = [];
@@ -250,7 +250,7 @@ class HttpFunctions {
250
250
  }));
251
251
  slaveOptions.push(JSON.stringify((0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)));
252
252
  slave = this.q.push({
253
- command: 'node',
253
+ command: ((_c = fnTarget.additionalInfo) === null || _c === void 0 ? void 0 : _c.binPath) || 'node',
254
254
  options: slaveOptions,
255
255
  pth: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, fnTarget.name),
256
256
  req: request,
@@ -259,7 +259,7 @@ class HttpFunctions {
259
259
  envVars: fnTarget.env_var
260
260
  });
261
261
  }
262
- else if ((_c = fnTarget.stack) === null || _c === void 0 ? void 0 : _c.startsWith(runtime_1.default.language.java.value)) {
262
+ else if ((_d = fnTarget.stack) === null || _d === void 0 ? void 0 : _d.startsWith(runtime_1.default.language.java.value)) {
263
263
  const invoker = fnTarget.type === constants_1.FN_TYPE.basic
264
264
  ? this.javaInvoker[fnTarget.type] + `/${fnTarget.stack}/JavabioInvoker`
265
265
  : this.javaInvoker[fnTarget.type];
@@ -292,7 +292,7 @@ class HttpFunctions {
292
292
  'x-zc-cookie': request.headers['x-zc-cookie'],
293
293
  'x-zc-user-type': request.headers['x-zc-user-type']
294
294
  }));
295
- const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)('java', (_d = fnTarget.additionalInfo) === null || _d === void 0 ? void 0 : _d.binPath);
295
+ const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)('java', (_e = fnTarget.additionalInfo) === null || _e === void 0 ? void 0 : _e.binPath);
296
296
  slave = this.q.push({
297
297
  command: spawnCommand,
298
298
  options: slaveOptions,
@@ -421,7 +421,7 @@ class HttpFunctions {
421
421
  });
422
422
  this.q.destroy(() => __awaiter(this, void 0, void 0, function* () {
423
423
  var _a;
424
- 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(); })));
424
+ 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(); })));
425
425
  yield ((_a = this.connDestroyer) === null || _a === void 0 ? void 0 : _a.destroy());
426
426
  res();
427
427
  }));
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { ChildProcess } from 'child_process';
4
2
  import { IFnTarget } from '../../../fn-utils/lib/common';
5
3
  import { IServerDetails } from '../../../serve/server';
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -60,8 +70,8 @@ class FnExecutionHandler extends fn_handler_1.FnHandler {
60
70
  super(serverDetails, localFnEvents);
61
71
  }
62
72
  execute(data, accessToken) {
63
- var _a, _b, _c, _d, _e;
64
73
  return __awaiter(this, void 0, void 0, function* () {
74
+ var _a, _b, _c, _d, _e;
65
75
  const projectRoot = (0, project_1.getProjectRoot)();
66
76
  const slaveFnTarget = {
67
77
  index: (_b = (_a = this.fn.target) === null || _a === void 0 ? void 0 : _a.index) === null || _b === void 0 ? void 0 : _b.replace((0, path_1.join)(projectRoot, constants_1.FOLDERNAME.functions, this.fn.target.name) + path_1.sep, ''),
@@ -70,6 +80,7 @@ class FnExecutionHandler extends fn_handler_1.FnHandler {
70
80
  switch (this.stack) {
71
81
  case 'node': {
72
82
  this.slave = (0, node_1.default)(this.fn, JSON.stringify(data), { slaveFnTarget, accessToken });
83
+ this.slave.once('spawn', () => utils_1.serverEvent.emit('connection'));
73
84
  break;
74
85
  }
75
86
  case 'java': {
@@ -80,11 +91,10 @@ class FnExecutionHandler extends fn_handler_1.FnHandler {
80
91
  slaveFnTarget,
81
92
  accessToken
82
93
  });
94
+ this.slave.once('spawn', () => utils_1.serverEvent.emit('connection'));
83
95
  break;
84
96
  }
85
97
  case 'python': {
86
- const pyFn = this.fn;
87
- this.slave = yield (0, python_1.default)(pyFn);
88
98
  const attachVsCodeDebugger = (port) => __awaiter(this, void 0, void 0, function* () {
89
99
  try {
90
100
  yield (0, server_1.isPortListening)(port, 25, env_1.isWindows ? 1000 : 500).catch((er) => (0, logger_1.debug)('error listening for port: ' + port, er));
@@ -103,27 +113,48 @@ class FnExecutionHandler extends fn_handler_1.FnHandler {
103
113
  return;
104
114
  }
105
115
  });
116
+ const pyFn = this.fn;
117
+ const debugConfig = (_d = pyFn.target.additionalInfo) === null || _d === void 0 ? void 0 : _d.debug;
118
+ const httpPort = yield port_resolver_1.default.getFreePort(constants_1.DEFAULT.serve_port.http[(_e = this.fn.target) === null || _e === void 0 ? void 0 : _e.type], 200);
119
+ if (pyFn.target.type === 'job') {
120
+ const jobServer = yield this.processFlowHandler(data, httpPort);
121
+ this.slave = yield (0, python_1.default)(pyFn, httpPort);
122
+ if (!(this.slave instanceof child_process_1.ChildProcess)) {
123
+ jobServer.kill();
124
+ throw new error_1.default('Slave not an instance of Child process', {
125
+ context: this.slave,
126
+ exit: 2
127
+ });
128
+ }
129
+ this.slave.once('exit', () => jobServer.kill());
130
+ this.slave.once('error', () => jobServer.kill());
131
+ if (debugConfig && env_1.isExtension) {
132
+ yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
133
+ var _a, _b;
134
+ (_a = this.slave) === null || _a === void 0 ? void 0 : _a.once('spawn', () => {
135
+ resolve();
136
+ });
137
+ (_b = this.slave) === null || _b === void 0 ? void 0 : _b.once('error', (er) => {
138
+ reject(er);
139
+ });
140
+ }));
141
+ yield attachVsCodeDebugger(debugConfig.port);
142
+ }
143
+ break;
144
+ }
145
+ this.slave = yield (0, python_1.default)(pyFn, httpPort);
106
146
  if (!(this.slave instanceof child_process_1.ChildProcess)) {
107
147
  throw new error_1.default('Slave not an instance of Child process', {
108
148
  context: this.slave,
109
149
  exit: 2
110
150
  });
111
151
  }
112
- const debugConfig = (_d = pyFn.target.additionalInfo) === null || _d === void 0 ? void 0 : _d.debug;
113
- if (this.fn.target.type === 'job') {
114
- if (debugConfig && env_1.isVsCode) {
115
- yield attachVsCodeDebugger(debugConfig.port);
116
- }
117
- const httpPort = yield port_resolver_1.default.getFreePort(constants_1.DEFAULT.serve_port.http[(_e = this.fn.target) === null || _e === void 0 ? void 0 : _e.type], 200);
118
- this.processFlowHandler(data, httpPort);
119
- break;
120
- }
121
152
  new Promise((resolve, reject) => {
122
153
  var _a;
123
154
  (_a = this.slave) === null || _a === void 0 ? void 0 : _a.once('spawn', () => __awaiter(this, void 0, void 0, function* () {
124
155
  try {
125
156
  if (debugConfig) {
126
- if (env_1.isVsCode) {
157
+ if (env_1.isExtension) {
127
158
  yield attachVsCodeDebugger(debugConfig.port);
128
159
  }
129
160
  else {
@@ -177,8 +208,8 @@ class FnExecutionHandler extends fn_handler_1.FnHandler {
177
208
  });
178
209
  }
179
210
  executeWithContainer(data, accessToken) {
180
- var _a, _b, _c, _d, _e;
181
211
  return __awaiter(this, void 0, void 0, function* () {
212
+ var _a, _b, _c, _d, _e;
182
213
  (0, logger_1.debug)('using container to serve the function: ' + ((_a = this.fn.target) === null || _a === void 0 ? void 0 : _a.name));
183
214
  const container = yield Promise.resolve().then(() => __importStar(require('@zcatalyst/container-plugin')));
184
215
  const httpPort = yield port_resolver_1.default.getFreePort(constants_1.DEFAULT.serve_port.http[(_b = this.fn.target) === null || _b === void 0 ? void 0 : _b.type], 200);
@@ -222,13 +253,13 @@ class FnExecutionHandler extends fn_handler_1.FnHandler {
222
253
  });
223
254
  pluginEvent.emit('start', this.fn);
224
255
  pluginEvent.once('ready', () => __awaiter(this, void 0, void 0, function* () {
225
- var _f, _g;
256
+ var _a, _b;
226
257
  try {
227
- if (((_f = this.fn.target) === null || _f === void 0 ? void 0 : _f.type) === 'job') {
258
+ if (((_a = this.fn.target) === null || _a === void 0 ? void 0 : _a.type) === 'job') {
228
259
  yield this.processFlowHandler(data, httpPort).finally(() => this.kill());
229
260
  return;
230
261
  }
231
- if (((_g = this.fn.target) === null || _g === void 0 ? void 0 : _g.type) === 'cron') {
262
+ if (((_b = this.fn.target) === null || _b === void 0 ? void 0 : _b.type) === 'cron') {
232
263
  const cronData = {
233
264
  project_details: {},
234
265
  cron_details: {},
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import EventEmitter from 'events';
4
2
  import { IFnTarget } from '../../../fn-utils/lib/common';
5
3
  import { IServerDetails } from '../../../serve/server';
@@ -18,7 +16,9 @@ export declare class FnHandler {
18
16
  constructor(fn: IServerDetails<IFnTarget>, localFnEvents: EventEmitter);
19
17
  writeResponse(response: string, status: number): void;
20
18
  responseProcessor(statusCode: number, message?: string): void;
21
- processFlowHandler(data: Record<string, unknown>, listenPort: number): Promise<void>;
19
+ processFlowHandler(data: Record<string, unknown>, listenPort: number): Promise<{
20
+ kill: () => void;
21
+ }>;
22
22
  fnRequestHandler({ httpPort, data, accessToken }: {
23
23
  httpPort: number;
24
24
  data?: Record<string, unknown>;
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.FnHandler = void 0;
16
- const child_process_1 = require("child_process");
17
16
  const fs_1 = require("../../../util_modules/fs");
18
17
  const constants_1 = require("../../../util_modules/constants");
19
18
  const http_1 = require("http");
@@ -22,6 +21,7 @@ const server_1 = require("../../../util_modules/server");
22
21
  const project_1 = require("../../../util_modules/project");
23
22
  const error_1 = __importDefault(require("../../../error"));
24
23
  const path_1 = require("path");
24
+ const utils_1 = require("@zcatalyst/container-plugin/out/utils");
25
25
  class FnHandler {
26
26
  constructor(fn, localFnEvents) {
27
27
  this.closed = false;
@@ -81,10 +81,15 @@ class FnHandler {
81
81
  processFlowHandler(data, listenPort) {
82
82
  return __awaiter(this, void 0, void 0, function* () {
83
83
  return new Promise((resolve, reject) => {
84
- var _a;
85
84
  const jobDetailsServer = new http_1.Server((serverReq, serverRes) => __awaiter(this, void 0, void 0, function* () {
86
- var _b, _c;
87
- if ((_b = serverReq.url) === null || _b === void 0 ? void 0 : _b.includes('data')) {
85
+ var _a, _b, _c;
86
+ (0, logger_1.debug)(`[JOB_SERVER] [${serverReq.method}] ${serverReq.url}`);
87
+ if ((_a = serverReq.url) === null || _a === void 0 ? void 0 : _a.includes('/ruok')) {
88
+ serverRes.writeHead(200);
89
+ serverRes.write('Iam Ok!');
90
+ serverRes.end();
91
+ }
92
+ else if ((_b = serverReq.url) === null || _b === void 0 ? void 0 : _b.includes('data')) {
88
93
  serverRes.writeHead(200);
89
94
  serverRes.write(JSON.stringify({
90
95
  data
@@ -101,29 +106,28 @@ class FnHandler {
101
106
  serverRes.writeHead(200);
102
107
  serverRes.write(JSON.stringify({}));
103
108
  serverRes.end();
104
- resolve();
105
- return;
106
109
  }
107
110
  else {
108
111
  (0, logger_1.debug)(`Invalid request: (${serverReq.method}) ${serverReq.url}`);
109
112
  this.writeResponse('INTERNAL_SERVER_ERROR', 500);
110
113
  reject(`Invalid request: (${serverReq.method}) ${serverReq.url}`);
111
- return;
112
114
  }
113
115
  }));
114
116
  const jobConnDestroyer = new server_1.ConnectionDestroyer(jobDetailsServer);
115
117
  jobDetailsServer.listen(listenPort, '127.0.0.1', () => {
116
- (0, logger_1.debug)('server listening on port :' + listenPort);
118
+ (0, logger_1.debug)('job server listening on port :' + listenPort);
119
+ resolve({
120
+ kill: () => {
121
+ jobConnDestroyer.destroy();
122
+ }
123
+ });
117
124
  });
118
125
  jobDetailsServer.on('error', reject);
119
- (_a = this.slave) === null || _a === void 0 ? void 0 : _a.once('exit', () => {
120
- jobConnDestroyer.destroy();
121
- });
122
126
  });
123
127
  });
124
128
  }
125
- fnRequestHandler({ httpPort, data = {}, accessToken }) {
126
- return __awaiter(this, void 0, void 0, function* () {
129
+ fnRequestHandler(_a) {
130
+ return __awaiter(this, arguments, void 0, function* ({ httpPort, data = {}, accessToken }) {
127
131
  data.project_details = Object.assign({ id: (0, project_1.getProjectId)(), project_name: (0, project_1.getProjectName)() }, (data.project_details || {}));
128
132
  const reqJson = JSON.stringify(data);
129
133
  return new Promise((resolve, reject) => {
@@ -176,9 +180,10 @@ class FnHandler {
176
180
  });
177
181
  }
178
182
  fnResponseHandler(code, sig) {
179
- var _a, _b, _c, _d, _e;
180
183
  return __awaiter(this, void 0, void 0, function* () {
184
+ var _a, _b, _c, _d, _e;
181
185
  if (code === 0) {
186
+ (0, logger_1.info)();
182
187
  (0, logger_1.info)(`[CLI] Function ${(_a = this.fn.target) === null || _a === void 0 ? void 0 : _a.name} execution complete`);
183
188
  (0, logger_1.info)();
184
189
  const response = yield fs_1.ASYNC.readFile(this.responseFile);
@@ -203,7 +208,9 @@ class FnHandler {
203
208
  case constants_1.FN_TYPE.event:
204
209
  (0, logger_1.info)(`[status - ${this.fn.target.name}] ${response || 'Unknown'}`);
205
210
  if (!response) {
211
+ (0, logger_1.info)();
206
212
  (0, logger_1.info)(`[CLI] Make sure to close the ${this.fn.target.name} (${this.fn.target.type}) function.`);
213
+ (0, logger_1.info)();
207
214
  }
208
215
  this.localFnEvents.emit('response', {
209
216
  status: meta.statusCode
@@ -221,10 +228,16 @@ class FnHandler {
221
228
  }
222
229
  }
223
230
  else {
224
- (code === 130 || sig === 'SIGINT') &&
231
+ if (code === 130 || sig === 'SIGINT') {
232
+ (0, logger_1.info)();
225
233
  (0, logger_1.info)(`[CLI] Function ${(_c = this.fn.target) === null || _c === void 0 ? void 0 : _c.name} interrupted`);
226
- (code === 143 || sig === 'SIGTERM' || sig === 'SIGQUIT' || sig === 'SIGKILL') &&
234
+ (0, logger_1.info)();
235
+ }
236
+ if (code === 143 || sig === 'SIGTERM' || sig === 'SIGQUIT' || sig === 'SIGKILL') {
237
+ (0, logger_1.info)();
227
238
  (0, logger_1.info)(`[CLI] Function ${(_d = this.fn.target) === null || _d === void 0 ? void 0 : _d.name} process killed`);
239
+ (0, logger_1.info)();
240
+ }
228
241
  this.localFnEvents.listenerCount('error') > 0 &&
229
242
  this.localFnEvents.emit('error', new error_1.default(`Function(${(_e = this.fn.target) === null || _e === void 0 ? void 0 : _e.name}) process exited with ${code ? 'status: ' + code : 'signal: ' + sig}`, {
230
243
  skipHelp: true
@@ -247,12 +260,33 @@ class FnHandler {
247
260
  });
248
261
  }
249
262
  kill() {
250
- if (!this.slave) {
263
+ var _a;
264
+ if (!this.slave || ((_a = this.slave) === null || _a === void 0 ? void 0 : _a.killed)) {
265
+ return;
266
+ }
267
+ (0, logger_1.info)();
268
+ (0, logger_1.info)('Terminating Function');
269
+ if (this.slave instanceof utils_1.ContainerEvents) {
270
+ this.slave.emit('close', this.fn);
251
271
  return;
252
272
  }
253
- this.slave instanceof child_process_1.ChildProcess
254
- ? !this.slave.killed && this.slave.kill('SIGTERM')
255
- : this.slave.emit('close', this.fn);
273
+ let isChildExited = false;
274
+ this.slave.kill('SIGTERM');
275
+ this.slave.once('exit', () => {
276
+ isChildExited = true;
277
+ });
278
+ setTimeout(() => {
279
+ if (!this.slave || this.slave instanceof utils_1.ContainerEvents) {
280
+ return;
281
+ }
282
+ if (!isChildExited) {
283
+ (0, logger_1.debug)(`Emitting SIGKILL to PID: ${this.slave.pid}`);
284
+ this.slave.kill('SIGKILL');
285
+ }
286
+ else {
287
+ (0, logger_1.debug)(`Fn child process kill confirmed PID: ${this.slave.pid}`);
288
+ }
289
+ }, 500);
256
290
  }
257
291
  }
258
292
  exports.FnHandler = FnHandler;
@@ -5,7 +5,7 @@ const project_1 = require("../../../util_modules/project");
5
5
  const constants_1 = require("../../../util_modules/constants");
6
6
  const path_1 = require("path");
7
7
  exports.default = (fn, data, { slaveFnTarget, accessToken }) => {
8
- var _a, _b, _c, _d;
8
+ var _a, _b, _c, _d, _e, _f;
9
9
  const slaveOptions = [];
10
10
  const nodeInvoker = (0, path_1.normalize)((0, path_1.join)(__dirname, '../invoker', (_a = fn.target) === null || _a === void 0 ? void 0 : _a.type, 'node.mjs'));
11
11
  if (fn.debugPort !== -1) {
@@ -28,9 +28,9 @@ exports.default = (fn, data, { slaveFnTarget, accessToken }) => {
28
28
  'x-zc-user-type': 'admin'
29
29
  }));
30
30
  slaveOptions.push(JSON.stringify((0, path_1.join)((0, project_1.getProjectRoot)(), constants_1.FOLDERNAME.build)));
31
- return (0, shell_1.spawn)('node', slaveOptions, {
32
- cwd: (_b = fn.target) === null || _b === void 0 ? void 0 : _b.build,
31
+ return (0, shell_1.spawn)(((_c = (_b = fn.target) === null || _b === void 0 ? void 0 : _b.additionalInfo) === null || _c === void 0 ? void 0 : _c.binPath) || 'node', slaveOptions, {
32
+ cwd: (_d = fn.target) === null || _d === void 0 ? void 0 : _d.build,
33
33
  stdio: 'pipe',
34
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_c = fn.target) === null || _c === void 0 ? void 0 : _c.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (_d = fn.target) === null || _d === void 0 ? void 0 : _d.env_var)
34
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_e = fn.target) === null || _e === void 0 ? void 0 : _e.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (_f = fn.target) === null || _f === void 0 ? void 0 : _f.env_var)
35
35
  }).RAW();
36
36
  };
@@ -1,5 +1,5 @@
1
1
  import { ChildProcess } from 'child_process';
2
2
  import { IServerDetails } from '../../../serve/server';
3
3
  import { IFnTarget, PythonFn } from '../../../fn-utils/lib/common';
4
- declare const _default: (fn: IServerDetails<IFnTarget<PythonFn>>) => Promise<ChildProcess>;
4
+ declare const _default: (fn: IServerDetails<IFnTarget<PythonFn>>, runTimePort: number) => Promise<ChildProcess>;
5
5
  export default _default;
@@ -16,32 +16,30 @@ const port_resolver_1 = __importDefault(require("../../../port-resolver"));
16
16
  const constants_1 = require("../../../util_modules/constants");
17
17
  const path_1 = require("path");
18
18
  const shell_1 = require("../../../util_modules/shell");
19
- const userConfig_1 = __importDefault(require("../../../userConfig"));
20
19
  const project_1 = require("../../../util_modules/project");
21
- const runtime_store_1 = __importDefault(require("../../../runtime-store"));
22
20
  const logger_1 = require("../../../util_modules/logger");
23
- exports.default = (fn) => __awaiter(void 0, void 0, void 0, function* () {
24
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
21
+ exports.default = (fn, runTimePort) => __awaiter(void 0, void 0, void 0, function* () {
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
25
23
  const slaveOptions = [];
26
24
  const stackVersion = (_b = (_a = fn.target) === null || _a === void 0 ? void 0 : _a.stack) === null || _b === void 0 ? void 0 : _b.replace('python_', '');
27
25
  const runtimesDir = constants_1.ENVPATH.runtimes.data;
28
- const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], constants_1.DEFAULT.serve_port.http[(_c = fn.target) === null || _c === void 0 ? void 0 : _c.type] + ''), 10);
29
- const runTimePort = yield port_resolver_1.default.getFreePort(httpPort, 20, false);
30
26
  fn.httpPort = runTimePort;
31
27
  slaveOptions.push((0, path_1.join)(runtimesDir, constants_1.RUNTIME.language.python.value, `zcatalyst_runtime_${stackVersion === null || stackVersion === void 0 ? void 0 : stackVersion.replace('_', '')}`, 'main.py'));
32
- const debugConfig = (_d = fn.target.additionalInfo) === null || _d === void 0 ? void 0 : _d.debug;
28
+ const debugConfig = (_c = fn.target.additionalInfo) === null || _c === void 0 ? void 0 : _c.debug;
33
29
  if (debugConfig) {
34
30
  const debugOpts = ['-m', debugConfig === null || debugConfig === void 0 ? void 0 : debugConfig.debugger, '--listen', debugConfig.port + ''];
35
- ((_e = fn.target) === null || _e === void 0 ? void 0 : _e.type) === constants_1.FN_TYPE.job && debugOpts.push('--wait-for-client');
31
+ ((_d = fn.target) === null || _d === void 0 ? void 0 : _d.type) === constants_1.FN_TYPE.job && debugOpts.push('--wait-for-client');
36
32
  slaveOptions.unshift(...debugOpts);
37
33
  }
38
34
  slaveOptions.unshift('-u');
39
- (0, logger_1.debug)(`Python Spawn command: ${userConfig_1.default.get(`python${stackVersion}.bin`)} ${slaveOptions.join(' ')}`);
40
- return (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), slaveOptions, {
41
- cwd: (_f = fn.target) === null || _f === void 0 ? void 0 : _f.build,
35
+ (0, logger_1.debug)(`Python Spawn command: ${((_e = fn.target.additionalInfo) === null || _e === void 0 ? void 0 : _e.binPath) || 'python'} ${slaveOptions.join(' ')}`);
36
+ (0, logger_1.debug)(`X_ZOHO_DATA_URL: http://localhost:${runTimePort}/data`);
37
+ (0, logger_1.debug)(`X_ZOHO_CALLBACK_URL: http://localhost:${runTimePort}/callback`);
38
+ return (0, shell_1.spawn)(((_f = fn.target.additionalInfo) === null || _f === void 0 ? void 0 : _f.binPath) || 'python', slaveOptions, {
39
+ cwd: (_g = fn.target) === null || _g === void 0 ? void 0 : _g.build,
42
40
  stdio: 'pipe',
43
- 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_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, X_ZOHO_CATALYST_RESOURCE_ID: (_g = fn.target) === null || _g === void 0 ? void 0 : _g.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, X_ZOHO_CATALYST_CODE_LOCATION: (_h = fn.target) === null || _h === void 0 ? void 0 : _h.build, X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Development', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[(_j = fn.target) === null || _j === void 0 ? void 0 : _j.type] }, (_k = fn.target) === null || _k === void 0 ? void 0 : _k.env_var)
41
+ 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_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, X_ZOHO_CATALYST_RESOURCE_ID: (_h = fn.target) === null || _h === void 0 ? void 0 : _h.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, X_ZOHO_CATALYST_CODE_LOCATION: (_j = fn.target) === null || _j === void 0 ? void 0 : _j.build, X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Development', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[(_k = fn.target) === null || _k === void 0 ? void 0 : _k.type] }, (_l = fn.target) === null || _l === void 0 ? void 0 : _l.env_var)
44
42
  })
45
43
  .RAW()
46
- .on('exit', () => port_resolver_1.default.freePort(httpPort));
44
+ .on('exit', () => port_resolver_1.default.freePort(runTimePort));
47
45
  });
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { ChildProcess } from 'child_process';
4
2
  import CatalystError from '../../../error';
5
3
  import { IServerDetails } from '../../../serve/server';
@@ -70,6 +70,10 @@ class SlaveManager extends fn_execution_handler_1.FnExecutionHandler {
70
70
  }
71
71
  break;
72
72
  }
73
+ case constants_1.FN_TYPE.integration: {
74
+ data.timestamp = Date.now();
75
+ break;
76
+ }
73
77
  }
74
78
  }
75
79
  else {
@@ -86,7 +90,7 @@ class SlaveManager extends fn_execution_handler_1.FnExecutionHandler {
86
90
  return new error_1.default('Invalid input: ' + e);
87
91
  }
88
92
  return (() => __awaiter(this, void 0, void 0, function* () {
89
- var _b, _c, _d, _e, _f, _g, _h, _j, _k;
93
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
90
94
  if (!this.fn.target) {
91
95
  throw new error_1.default('Invalid function target: ' + this.fn.target, {
92
96
  exit: 2
@@ -95,7 +99,7 @@ class SlaveManager extends fn_execution_handler_1.FnExecutionHandler {
95
99
  const accessToken = yield credential_1.default.getAccessToken();
96
100
  yield fs_1.ASYNC.ensureFile(this.responseFile, true);
97
101
  yield fs_1.ASYNC.ensureFile(this.metaFile, true);
98
- if (((_b = this.fn.target) === null || _b === void 0 ? void 0 : _b.type) === constants_1.FN_TYPE.job) {
102
+ if (((_a = this.fn.target) === null || _a === void 0 ? void 0 : _a.type) === constants_1.FN_TYPE.job) {
99
103
  if ('params' in data) {
100
104
  data.job_details = Object.assign({
101
105
  job_meta_details: {
@@ -106,7 +110,7 @@ class SlaveManager extends fn_execution_handler_1.FnExecutionHandler {
106
110
  }
107
111
  const jobData = data;
108
112
  const jobMetaDetails = {
109
- headers: Object.assign(Object.assign({}, (_d = (_c = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _c === void 0 ? void 0 : _c.job_meta_details) === null || _d === void 0 ? void 0 : _d.headers), {
113
+ headers: Object.assign(Object.assign({}, (_c = (_b = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _b === void 0 ? void 0 : _b.job_meta_details) === null || _c === void 0 ? void 0 : _c.headers), {
110
114
  'x-zc-projectid': (0, project_1.getProjectId)(),
111
115
  'x-zc-project-domain': (0, project_1.getDomainPrefix)() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
112
116
  'x-zc-project-key': (0, project_1.getDomainKey)(),
@@ -117,11 +121,11 @@ class SlaveManager extends fn_execution_handler_1.FnExecutionHandler {
117
121
  'x-zc-admin-cred-token': accessToken,
118
122
  'x-zc-user-type': 'admin'
119
123
  }),
120
- params: ((_f = (_e = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _e === void 0 ? void 0 : _e.job_meta_details) === null || _f === void 0 ? void 0 : _f.params) || {},
124
+ params: ((_e = (_d = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _d === void 0 ? void 0 : _d.job_meta_details) === null || _e === void 0 ? void 0 : _e.params) || {},
121
125
  jobpool_details: Object.assign({ type: 'Function', project_details: {
122
126
  project_name: (0, project_1.getProjectName)(),
123
127
  id: (0, project_1.getProjectId)()
124
- } }, (_h = (_g = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _g === void 0 ? void 0 : _g.job_meta_details) === null || _h === void 0 ? void 0 : _h.jobpool_details)
128
+ } }, (_g = (_f = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _f === void 0 ? void 0 : _f.job_meta_details) === null || _g === void 0 ? void 0 : _g.jobpool_details)
125
129
  };
126
130
  jobData.job_details = Object.assign(Object.assign({}, jobData.job_details), { capacity: jobData.capacity || {
127
131
  memory: '256'
@@ -142,10 +146,10 @@ class SlaveManager extends fn_execution_handler_1.FnExecutionHandler {
142
146
  exit: 2
143
147
  });
144
148
  }
145
- (_j = this.slave.stdout) === null || _j === void 0 ? void 0 : _j.on('data', (message) => {
149
+ (_h = this.slave.stdout) === null || _h === void 0 ? void 0 : _h.on('data', (message) => {
146
150
  process.stdout.write(message.toString());
147
151
  });
148
- (_k = this.slave.stderr) === null || _k === void 0 ? void 0 : _k.on('data', (message) => {
152
+ (_j = this.slave.stderr) === null || _j === void 0 ? void 0 : _j.on('data', (message) => {
149
153
  process.stderr.write(message.toString());
150
154
  });
151
155
  this.slave.on('error', (err) => {
@@ -53,8 +53,8 @@ class TunnelServer {
53
53
  }
54
54
  return false;
55
55
  }
56
- send(req, res, status = 200, data, contentType) {
57
- return __awaiter(this, void 0, void 0, function* () {
56
+ send(req_1, res_1) {
57
+ return __awaiter(this, arguments, void 0, function* (req, res, status = 200, data, contentType) {
58
58
  const body = req.body;
59
59
  if (this.isAsyncFn(body.function_details.function_type)) {
60
60
  const tunnelAPI = yield (0, endpoints_1.tunnelAPI)();
@@ -189,8 +189,8 @@ class TunnelServer {
189
189
  return this;
190
190
  }
191
191
  stopServer() {
192
- var _a;
193
192
  return __awaiter(this, void 0, void 0, function* () {
193
+ var _a;
194
194
  if (!__classPrivateFieldGet(this, _TunnelServer_server, "f")) {
195
195
  return;
196
196
  }
@@ -198,5 +198,5 @@ class TunnelServer {
198
198
  });
199
199
  }
200
200
  }
201
- exports.default = TunnelServer;
202
201
  _TunnelServer_contextMap = new WeakMap(), _TunnelServer_server = new WeakMap(), _TunnelServer_destroyer = new WeakMap(), _TunnelServer_repel = new WeakMap(), _TunnelServer_projectId = new WeakMap();
202
+ exports.default = TunnelServer;
@@ -1,4 +1,37 @@
1
1
  'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -29,16 +62,30 @@ const prepare_1 = __importDefault(require("./prepare"));
29
62
  const fn_watcher_1 = __importDefault(require("../fn-watcher"));
30
63
  const tunnel_server_1 = __importDefault(require("./dependencies/tunnel-server"));
31
64
  const endpoints_1 = require("../endpoints");
65
+ const child_process_1 = require("child_process");
66
+ const container_plugin_1 = require("@zcatalyst/container-plugin");
67
+ const userConfig_1 = __importStar(require("../userConfig"));
32
68
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
33
69
  var _a;
70
+ const shellPrompt = userConfig_1.default.get(userConfig_1.CONFIG_KEYS.functionsShell_prompt);
34
71
  const replServer = new repl_server_1.default({
35
- prompt: 'functions > ',
72
+ prompt: shellPrompt && typeof shellPrompt === 'string'
73
+ ? shellPrompt
74
+ : ansi_colors_1.bold.cyan('╭─ catalyst-functions-shell\n╰─> '),
36
75
  writer: (output) => {
37
76
  if (output !== undefined) {
38
77
  if (output instanceof Promise) {
39
78
  replServer.pause();
40
- output.finally(() => replServer.resume());
41
- return '[cli] Function has been invoked';
79
+ output.then((_res) => {
80
+ if (_res instanceof child_process_1.ChildProcess) {
81
+ _res.once('close', replServer.resume);
82
+ }
83
+ else if (_res instanceof container_plugin_1.ContainerEvents) {
84
+ _res.once('exit', replServer.resume);
85
+ _res.once('error', replServer.resume);
86
+ }
87
+ });
88
+ return '\n' + '[CLI] Function has been invoked' + '\n';
42
89
  }
43
90
  if (output instanceof Error) {
44
91
  return ansi_colors_1.bold.red('Error: ') + output.message;