zcatalyst-cli 1.25.3 → 1.26.1

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 (263) 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 +11 -8
  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 +20 -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 +23 -11
  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/util.d.ts +11 -0
  175. package/lib/serve/server/lib/appsail/util.js +69 -0
  176. package/lib/serve/server/lib/java/index.js +18 -7
  177. package/lib/serve/server/lib/master/appsail.js +3 -4
  178. package/lib/serve/server/lib/master/functions.js +1 -2
  179. package/lib/serve/server/lib/master/index.d.ts +0 -1
  180. package/lib/serve/server/lib/master/index.js +5 -5
  181. package/lib/serve/server/lib/master/slate.js +1 -2
  182. package/lib/serve/server/lib/master/unknown-req-proxy.js +5 -2
  183. package/lib/serve/server/lib/master/utils.d.ts +4 -8
  184. package/lib/serve/server/lib/master/utils.js +4 -6
  185. package/lib/serve/server/lib/master/web-client.js +1 -2
  186. package/lib/serve/server/lib/node/index.js +22 -11
  187. package/lib/serve/server/lib/node/server/browserlogic/utils/playwright-handler.js +1 -1
  188. package/lib/serve/server/lib/node/server/browserlogic/utils/puppeteer-handler.js +1 -1
  189. package/lib/serve/server/lib/node/server/browserlogic/utils/selenium-handler.js +2 -0
  190. package/lib/serve/server/lib/python/index.js +23 -14
  191. package/lib/serve/server/lib/slate/index.js +7 -0
  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 +25 -16
  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.d.ts +2 -1
  228. package/lib/util_modules/config/lib/slate.js +27 -13
  229. package/lib/util_modules/config-store.d.ts +1 -1
  230. package/lib/util_modules/config-store.js +30 -13
  231. package/lib/util_modules/constants/lib/apig-rules.d.ts +1 -1
  232. package/lib/util_modules/constants/lib/dc-type.js +3 -3
  233. package/lib/util_modules/constants/lib/placeholders.d.ts +1 -1
  234. package/lib/util_modules/constants/lib/placeholders.js +1 -1
  235. package/lib/util_modules/constants/lib/urls.js +2 -9
  236. package/lib/util_modules/container.js +23 -14
  237. package/lib/util_modules/dc.js +3 -4
  238. package/lib/util_modules/env.d.ts +3 -0
  239. package/lib/util_modules/env.js +64 -4
  240. package/lib/util_modules/event-emitter.d.ts +9 -0
  241. package/lib/util_modules/event-emitter.js +68 -0
  242. package/lib/util_modules/fs/index.js +17 -7
  243. package/lib/util_modules/fs/lib/async.d.ts +0 -4
  244. package/lib/util_modules/fs/lib/async.js +46 -46
  245. package/lib/util_modules/fs/lib/sync.d.ts +1 -3
  246. package/lib/util_modules/fs/lib/sync.js +40 -30
  247. package/lib/util_modules/logger/index.js +12 -12
  248. package/lib/util_modules/logger/utils.d.ts +0 -4
  249. package/lib/util_modules/logger/utils.js +1 -1
  250. package/lib/util_modules/logger/winston.js +2 -2
  251. package/lib/util_modules/option.js +5 -6
  252. package/lib/util_modules/project.js +22 -23
  253. package/lib/util_modules/runtime-store.d.ts +2 -2
  254. package/lib/util_modules/server.d.ts +1 -2
  255. package/lib/util_modules/server.js +54 -15
  256. package/lib/util_modules/shell.d.ts +0 -3
  257. package/lib/util_modules/shell.js +5 -6
  258. package/lib/util_modules/toml.js +2 -3
  259. package/package.json +13 -13
  260. package/templates/init/functions/java/event/sample.java +5 -2
  261. package/templates/web-socket.txt +1 -1
  262. /package/lib/docs/{commands/event/generate → event_generate}/index.toml +0 -0
  263. /package/templates/init/functions/java/integ/convokraft/{Sample.java → sample.java} +0 -0
@@ -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) {
@@ -38,7 +48,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
48
  const path_1 = require("path");
39
49
  const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
40
50
  const http_functions_1 = require("../../../../shell/dependencies/http-functions");
41
- const userConfig_1 = __importDefault(require("../../../../userConfig"));
42
51
  const constants_1 = require("../../../../util_modules/constants");
43
52
  const project_1 = require("../../../../util_modules/project");
44
53
  const shell_1 = require("../../../../util_modules/shell");
@@ -83,22 +92,22 @@ exports.default = (details) => __awaiter(void 0, void 0, void 0, function* () {
83
92
  }
84
93
  opts.unshift('-u');
85
94
  return new Promise((resolve, reject) => {
86
- var _a, _b;
87
- const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), opts, {
95
+ var _a, _b, _c, _d;
96
+ const child = (0, shell_1.spawn)(((_b = (_a = details.target) === null || _a === void 0 ? void 0 : _a.additionalInfo) === null || _b === void 0 ? void 0 : _b.binPath) || 'python', opts, {
88
97
  cwd: codeLocation,
89
98
  stdio: 'pipe',
90
99
  detached: true,
91
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_a = details.target) === null || _a === void 0 ? void 0 : _a.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, X_ZOHO_CATALYST_CODE_LOCATION: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: details.httpPort.toString(), CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
100
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_c = details.target) === null || _c === void 0 ? void 0 : _c.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, X_ZOHO_CATALYST_CODE_LOCATION: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: details.httpPort.toString(), CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
92
101
  }).RAW();
93
102
  child.on('spawn', () => __awaiter(void 0, void 0, void 0, function* () {
94
- var _c;
103
+ var _a;
95
104
  yield (0, http_functions_1.checkIfRuntimeServerRunning)(details.httpPort.toString());
96
105
  debugConfig &&
97
- (0, index_1.info)(`\nPython debugger for function ${(_c = details.target) === null || _c === void 0 ? void 0 : _c.name} listening on port: ${details.debugPort}`);
106
+ (0, index_1.info)(`\nPython debugger for function ${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name} listening on port: ${details.debugPort}`);
98
107
  resolve(child);
99
108
  }));
100
109
  const errData = [];
101
- (_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (chunk) => {
110
+ (_d = child.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (chunk) => {
102
111
  errData.push(chunk);
103
112
  });
104
113
  child.on('error', (err) => {
@@ -51,6 +51,13 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
51
51
  }
52
52
  else {
53
53
  const configFile = (0, path_1.join)(targetSlate.source, file_names_1.default.cli_config);
54
+ if (!(yield (0, async_1.fileExists)(configFile))) {
55
+ throw new error_1.default('cli-config.json file not found in source directory', {
56
+ exit: 1,
57
+ errorId: 'SERVE-SLATE-4',
58
+ arg: [targetSlate.source]
59
+ });
60
+ }
54
61
  const configJson = yield (0, async_1.readJSONFile)(configFile);
55
62
  const installDeps = (0, shell_1.spawn)('npm', ['install'], {
56
63
  cwd: targetSlate.source
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  export default function slateServer(httpPort: number, source: string, { homepage, enableWatch, notFoundPage }?: {
4
3
  homepage?: string;
@@ -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.default = slateServer;
15
16
  const express_1 = __importDefault(require("express"));
16
17
  const events_1 = require("events");
17
18
  const chokidar_1 = require("chokidar");
@@ -24,13 +25,14 @@ const ws_1 = require("ws");
24
25
  const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
25
26
  const ansi_colors_1 = require("ansi-colors");
26
27
  const server_js_1 = require("../../../../util_modules/server.js");
28
+ const env_1 = require("../../../../util_modules/env");
27
29
  function prepareScriptFile(dir, port) {
28
30
  return __awaiter(this, void 0, void 0, function* () {
29
31
  const scriptFile = yield index_js_1.ASYNC.readFile(constants_1.TEMPLATE.client.basic.socket);
30
32
  if (!scriptFile) {
31
33
  throw new error_1.default('Unable to read the script file', { exit: 2 });
32
34
  }
33
- const scriptReady = scriptFile.replace(new RegExp(constants_1.PLACEHOLDER.client.port, 'g'), port + '');
35
+ const scriptReady = scriptFile.replace(new RegExp(constants_1.PLACEHOLDER.client.domain, 'g'), (0, env_1.getLocalAccessDomain)(port, 'ws'));
34
36
  yield index_js_1.ASYNC.ensureDir(dir);
35
37
  const scriptFilePath = (0, path_1.join)(dir, 'reload-script.js');
36
38
  yield index_js_1.ASYNC.writeFile(scriptFilePath, scriptReady);
@@ -59,8 +61,8 @@ function reloadApp(event, path, liveSockets) {
59
61
  (0, logger_1.info)((0, ansi_colors_1.cyan)(`${event} detected in ${path} of the Web-Client.`));
60
62
  liveSockets.forEach((socket) => socket.send('reload'));
61
63
  }
62
- function slateServer(httpPort, source, { homepage = '/index.html', enableWatch = true, notFoundPage } = {}) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
+ function slateServer(httpPort_1, source_1) {
65
+ return __awaiter(this, arguments, void 0, function* (httpPort, source, { homepage = '/index.html', enableWatch = true, notFoundPage } = {}) {
64
66
  const eventListener = new events_1.EventEmitter();
65
67
  const catalystTempDir = (0, path_1.join)(source, '.catalyst');
66
68
  const socketServerPort = yield port_resolver_js_1.default.getFreePort(httpPort, 20, true);
@@ -191,4 +193,3 @@ function slateServer(httpPort, source, { homepage = '/index.html', enableWatch =
191
193
  return new Promise((res) => server.on('listening', () => res(eventListener)));
192
194
  });
193
195
  }
194
- exports.default = slateServer;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  export default function webClientServer(httpPort: number, source: string, { homepage, enableWatch, notFoundPage }?: {
4
3
  homepage?: string;
@@ -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.default = webClientServer;
15
16
  const express_1 = __importDefault(require("express"));
16
17
  const events_1 = require("events");
17
18
  const chokidar_1 = require("chokidar");
@@ -24,13 +25,14 @@ const ws_1 = require("ws");
24
25
  const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
25
26
  const ansi_colors_1 = require("ansi-colors");
26
27
  const server_js_1 = require("../../../../util_modules/server.js");
28
+ const env_1 = require("../../../../util_modules/env");
27
29
  function prepareScriptFile(dir, port) {
28
30
  return __awaiter(this, void 0, void 0, function* () {
29
31
  const scriptFile = yield index_js_3.ASYNC.readFile(index_js_1.TEMPLATE.client.basic.socket);
30
32
  if (!scriptFile) {
31
33
  throw new index_js_2.default('Unable to read the script file', { exit: 2 });
32
34
  }
33
- const scriptReady = scriptFile.replace(new RegExp(index_js_1.PLACEHOLDER.client.port, 'g'), port + '');
35
+ const scriptReady = scriptFile.replace(new RegExp(index_js_1.PLACEHOLDER.client.domain, 'g'), (0, env_1.getLocalAccessDomain)(port, 'ws'));
34
36
  yield index_js_3.ASYNC.ensureDir(dir);
35
37
  const scriptFilePath = (0, path_1.join)(dir, 'reload-script.js');
36
38
  yield index_js_3.ASYNC.writeFile(scriptFilePath, scriptReady);
@@ -59,8 +61,8 @@ function reloadApp(event, path, liveSockets) {
59
61
  (0, index_1.info)((0, ansi_colors_1.cyan)(`${event} detected in ${path} of the Web-Client.`));
60
62
  liveSockets.forEach((socket) => socket.send('reload'));
61
63
  }
62
- function webClientServer(httpPort, source, { homepage = 'index.html', enableWatch = true, notFoundPage } = {}) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
+ function webClientServer(httpPort_1, source_1) {
65
+ return __awaiter(this, arguments, void 0, function* (httpPort, source, { homepage = 'index.html', enableWatch = true, notFoundPage } = {}) {
64
66
  const eventListener = new events_1.EventEmitter();
65
67
  const catalystTempDir = (0, path_1.join)(source, '.catalyst');
66
68
  const socketServerPort = yield port_resolver_js_1.default.getFreePort(httpPort, 20, true);
@@ -191,4 +193,3 @@ function webClientServer(httpPort, source, { homepage = 'index.html', enableWatc
191
193
  return new Promise((res) => server.on('listening', () => res(eventListener)));
192
194
  });
193
195
  }
194
- exports.default = webClientServer;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import queue from 'better-queue';
4
2
  import { ChildProcess } from 'child_process';
5
3
  import express from 'express';
@@ -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;