zcatalyst-cli 1.13.3 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/docs/client-utils.toml +6 -1
  2. package/docs/commands/ds/import.toml +5 -0
  3. package/docs/fn-utils/lib/python.toml +4 -0
  4. package/docs/init/dependencies/python/ensure-python.toml +12 -0
  5. package/docs/init/dependencies/python/pip-install.toml +4 -0
  6. package/docs/serve/index.toml +5 -0
  7. package/lib/authentication/login.js +2 -1
  8. package/lib/cli_table/index.js +26 -2
  9. package/lib/cli_table/src/cell.js +359 -267
  10. package/lib/cli_table/src/layout-manager.js +231 -209
  11. package/lib/cli_table/src/table.js +76 -60
  12. package/lib/cli_table/src/utils.js +259 -224
  13. package/lib/client-utils.js +18 -4
  14. package/lib/command_needs/rc.js +57 -8
  15. package/lib/commands/config/delete.js +23 -0
  16. package/lib/commands/config/get.js +23 -0
  17. package/lib/commands/config/list.js +23 -0
  18. package/lib/commands/config/set.js +29 -0
  19. package/lib/commands/console/cache.js +31 -1
  20. package/lib/commands/console/queue.js +31 -1
  21. package/lib/commands/console/zcql.js +27 -1
  22. package/lib/commands/ds/export.js +2 -2
  23. package/lib/commands/ds/import.js +25 -5
  24. package/lib/commands/ds/status.js +2 -2
  25. package/lib/commands/iac/export.js +1 -1
  26. package/lib/commands/iac/import.js +1 -1
  27. package/lib/commands/iac/pack.js +16 -5
  28. package/lib/commands/iac/status.js +1 -1
  29. package/lib/commands/index.js +4 -0
  30. package/lib/commands/project/list.js +1 -1
  31. package/lib/commands/project/use.js +1 -1
  32. package/lib/deploy/features/client.js +2 -2
  33. package/lib/deploy/features/functions/index.js +13 -3
  34. package/lib/deploy/features/functions/languages/index.js +19 -2
  35. package/lib/endpoints/index.js +12 -5
  36. package/lib/endpoints/lib/env.js +5 -2
  37. package/lib/endpoints/lib/functions.js +30 -0
  38. package/lib/endpoints/lib/org.js +35 -0
  39. package/lib/endpoints/lib/project.js +7 -3
  40. package/lib/express_middlewares/unknownReqProxy.js +4 -1
  41. package/lib/fn-utils/index.js +2 -0
  42. package/lib/fn-utils/lib/common.js +68 -7
  43. package/lib/fn-utils/lib/integ.js +15 -11
  44. package/lib/fn-utils/lib/java.js +7 -3
  45. package/lib/fn-utils/lib/python.js +121 -0
  46. package/lib/fn-watcher.js +10 -2
  47. package/lib/index.js +2 -1
  48. package/lib/init/dependencies/python/ensure-python.js +151 -0
  49. package/lib/init/dependencies/python/pip-install.js +175 -0
  50. package/lib/init/features/functions/index.js +50 -29
  51. package/lib/init/features/functions/languages/index.js +3 -1
  52. package/lib/init/features/functions/languages/python.js +115 -0
  53. package/lib/init/features/index.js +2 -2
  54. package/lib/init/features/project.js +26 -6
  55. package/lib/init/util/project.js +2 -2
  56. package/lib/internal/api.js +2 -0
  57. package/lib/internal/command.js +1 -1
  58. package/lib/internal/rc.js +2 -0
  59. package/lib/port-resolver.js +4 -3
  60. package/lib/prompt/types/file-path.js +1 -1
  61. package/lib/pull/features/functions/index.js +35 -2
  62. package/lib/pull/features/functions/languages.js +8 -1
  63. package/lib/readLineUtils.js +37 -1
  64. package/lib/readline/features/cache.js +175 -1
  65. package/lib/readline/features/index.js +7 -1
  66. package/lib/readline/features/queue.js +209 -1
  67. package/lib/readline/features/zcql.js +237 -1
  68. package/lib/readline/index.js +30 -1
  69. package/lib/serve/index.js +48 -7
  70. package/lib/serve/server/index.js +118 -44
  71. package/lib/serve/server/lib/master.js +18 -5
  72. package/lib/serve/server/lib/node.mjs +41 -0
  73. package/lib/serve/server/lib/web_client/index.js +7 -3
  74. package/lib/serve/server/lib/web_client/server.js +31 -15
  75. package/lib/shell/dependencies/http-functions.js +57 -21
  76. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
  77. package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
  78. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  79. package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
  80. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
  81. package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
  82. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
  83. package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
  84. package/lib/shell/dependencies/local-function.js +74 -22
  85. package/lib/shell/index.js +11 -2
  86. package/lib/shell/prepare/index.js +21 -0
  87. package/lib/shell/prepare/languages/index.js +8 -2
  88. package/lib/shell/prepare/languages/java.js +39 -2
  89. package/lib/shell/prepare/languages/node.js +21 -2
  90. package/lib/shell/prepare/languages/python.js +65 -0
  91. package/lib/throbber/index.js +3 -1
  92. package/lib/userConfig.js +48 -0
  93. package/lib/util_modules/constants/index.js +3 -1
  94. package/lib/util_modules/constants/lib/apig-rules.js +8 -0
  95. package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
  96. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  97. package/lib/util_modules/constants/lib/default.js +2 -2
  98. package/lib/util_modules/constants/lib/env-path.js +12 -0
  99. package/lib/util_modules/constants/lib/file-names.js +4 -1
  100. package/lib/util_modules/constants/lib/folder-names.js +3 -1
  101. package/lib/util_modules/constants/lib/placeholders.js +6 -1
  102. package/lib/util_modules/constants/lib/runtime.js +2 -1
  103. package/lib/util_modules/constants/lib/scopes.js +1 -0
  104. package/lib/util_modules/constants/lib/template.js +9 -0
  105. package/lib/util_modules/constants/lib/urls.js +2 -6
  106. package/lib/util_modules/context-help.js +2 -0
  107. package/lib/util_modules/fs/lib/async.js +35 -11
  108. package/lib/util_modules/project.js +20 -1
  109. package/package.json +2 -1
  110. package/templates/init/functions/java/aio/catalyst-config.json +3 -2
  111. package/templates/init/functions/java/bio/catalyst-config.json +3 -2
  112. package/templates/init/functions/java/cron/catalyst-config.json +3 -2
  113. package/templates/init/functions/java/event/catalyst-config.json +3 -2
  114. package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
  115. package/templates/init/functions/node/aio/catalyst-config.json +3 -2
  116. package/templates/init/functions/node/bio/catalyst-config.json +3 -2
  117. package/templates/init/functions/node/cron/catalyst-config.json +3 -2
  118. package/templates/init/functions/node/event/catalyst-config.json +3 -2
  119. package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
  120. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
  121. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
  122. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
  123. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
  124. package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
  125. package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
  126. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
  127. package/templates/init/functions/node/integ/cliq/sample.js +4 -4
  128. package/templates/init/functions/python/aio/catalyst-config.json +11 -0
  129. package/templates/init/functions/python/aio/requirements.txt +1 -0
  130. package/templates/init/functions/python/aio/sample.py +26 -0
  131. package/templates/init/functions/python/bio/catalyst-config.json +11 -0
  132. package/templates/init/functions/python/bio/requirements.txt +1 -0
  133. package/templates/init/functions/python/bio/sample.py +6 -0
  134. package/templates/init/functions/python/cron/catalyst-config.json +11 -0
  135. package/templates/init/functions/python/cron/requirements.txt +1 -0
  136. package/templates/init/functions/python/cron/sample.py +18 -0
  137. package/templates/init/functions/python/event/catalyst-config.json +11 -0
  138. package/templates/init/functions/python/event/requirements.txt +1 -0
  139. package/templates/init/functions/python/event/sample.py +21 -0
  140. package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
  141. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
  142. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
  143. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
  144. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
  145. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
  146. package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
  147. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
  148. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
  149. package/templates/init/functions/python/integ/cliq/sample.py +21 -0
  150. package/lib/serve/server/lib/node.js +0 -62
  151. package/lib/shell/dependencies/invoker/bio/node.js +0 -80
  152. package/lib/shell/dependencies/invoker/cron/node.js +0 -54
  153. package/lib/shell/dependencies/invoker/event/node.js +0 -56
  154. package/lib/shell/dependencies/invoker/integ/node.js +0 -79
  155. package/templates/.DS_Store +0 -0
  156. package/templates/init/.DS_Store +0 -0
  157. package/templates/init/client/.DS_Store +0 -0
  158. package/templates/init/client/react/.DS_Store +0 -0
  159. package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
@@ -16,12 +16,15 @@ const error_1 = __importDefault(require("../../error"));
16
16
  const api_1 = __importDefault(require("../../internal/api"));
17
17
  const logger_1 = require("../../util_modules/logger");
18
18
  class Env {
19
- constructor(opts) {
19
+ constructor(opts, org) {
20
20
  this.opts = opts;
21
+ this.envId = org;
21
22
  }
22
23
  getEnvs(projectId) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId + '/environment');
25
+ const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId + '/environment', {
26
+ envId: this.envId
27
+ });
25
28
  if (res.body && res.body.data) {
26
29
  return res.body.data;
27
30
  }
@@ -43,6 +43,36 @@ class Functions {
43
43
  });
44
44
  });
45
45
  }
46
+ getFunction(fnId) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/function/${fnId}`);
49
+ if (res.body && res.body.data) {
50
+ return res.body.data;
51
+ }
52
+ (0, logger_1.debug)('Get function response from server : ' + res.body);
53
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
54
+ exit: 2
55
+ });
56
+ });
57
+ }
58
+ updateConfig(functionId, env) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/function/${functionId}/configuration`, {
61
+ body: {
62
+ environment: {
63
+ variables: env
64
+ }
65
+ }
66
+ });
67
+ if (res.body && res.body.data) {
68
+ return res.body.data;
69
+ }
70
+ (0, logger_1.debug)('Update configuration response from server : ' + res.body);
71
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
72
+ exit: 2
73
+ });
74
+ });
75
+ }
46
76
  deploy(sourceFsStream, { stack, name, type, memory }) {
47
77
  return __awaiter(this, void 0, void 0, function* () {
48
78
  const formData = {
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const error_1 = __importDefault(require("../../error"));
16
+ const api_1 = __importDefault(require("../../internal/api"));
17
+ const logger_1 = require("../../util_modules/logger");
18
+ class OrgAPI {
19
+ constructor(opts) {
20
+ this.opts = opts;
21
+ }
22
+ getAllOrgs() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const res = yield new api_1.default(this.opts).get('/baas/v1/orgs');
25
+ if (res.body && res.body.data) {
26
+ return res.body.data;
27
+ }
28
+ (0, logger_1.debug)('get all orgs response from server : ' + res.body);
29
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
30
+ exit: 2
31
+ });
32
+ });
33
+ }
34
+ }
35
+ exports.default = OrgAPI;
@@ -16,12 +16,15 @@ const error_1 = __importDefault(require("../../error"));
16
16
  const api_1 = __importDefault(require("../../internal/api"));
17
17
  const logger_1 = require("../../util_modules/logger");
18
18
  class ProjectAPI {
19
- constructor(opts) {
19
+ constructor(opts, org) {
20
20
  this.opts = opts;
21
+ this.envId = org;
21
22
  }
22
23
  getProject(projectId) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId);
25
+ const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId, {
26
+ envId: this.envId
27
+ });
25
28
  if (res.body && res.body.data) {
26
29
  return res.body.data;
27
30
  }
@@ -33,7 +36,7 @@ class ProjectAPI {
33
36
  }
34
37
  getAllProjects() {
35
38
  return __awaiter(this, void 0, void 0, function* () {
36
- const res = yield new api_1.default(this.opts).get('/baas/v1/project');
39
+ const res = yield new api_1.default(this.opts).get('/baas/v1/project', { envId: this.envId });
37
40
  if (res.body && res.body.data) {
38
41
  return res.body.data;
39
42
  }
@@ -46,6 +49,7 @@ class ProjectAPI {
46
49
  createProject(name) {
47
50
  return __awaiter(this, void 0, void 0, function* () {
48
51
  const res = yield new api_1.default(this.opts).post('/baas/v1/project', {
52
+ envId: this.envId,
49
53
  body: {
50
54
  project_name: name
51
55
  }
@@ -28,7 +28,10 @@ exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
28
28
  proxyInstance.web(req, res, {
29
29
  target: `https://${req.headers['x-zc-project-domain']}`,
30
30
  changeOrigin: true,
31
- ws: true
31
+ ws: true,
32
+ headers: req.url.match(/accounts\/p\/[0-9]+\/webclient\/v1\/captcha/g)
33
+ ? { origin: `https://${req.headers['x-zc-project-domain']}` }
34
+ : undefined
32
35
  });
33
36
  }
34
37
  };
@@ -27,8 +27,10 @@ exports.fnUtils = void 0;
27
27
  const common = __importStar(require("./lib/common"));
28
28
  const java = __importStar(require("./lib/java"));
29
29
  const node = __importStar(require("./lib/node"));
30
+ const python = __importStar(require("./lib/python"));
30
31
  exports.fnUtils = {
31
32
  node,
32
33
  java,
34
+ python,
33
35
  common
34
36
  };
@@ -12,7 +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.updateFnConfig = exports.getSDK = exports.deleteFunctionLocal = exports.resolveAllFnPorts = exports.findAndReplaceConfigProps = exports.generateUrlForTarget = exports.pack = exports.executeHook = exports.refineTargets = exports.validate = void 0;
15
+ exports.copyModDirPerm = exports.updateFnConfig = exports.getSDK = exports.deleteFunctionLocal = exports.resolveAllFnPorts = exports.findAndReplaceConfigProps = exports.generateUrlForTarget = exports.pack = exports.executeHook = exports.refineTargets = exports.validate = void 0;
16
16
  const ansi_colors_1 = require("ansi-colors");
17
17
  const path_1 = require("path");
18
18
  const archiver_1 = __importDefault(require("../../archiver"));
@@ -32,6 +32,9 @@ const js_1 = require("../../util_modules/js");
32
32
  const logger_1 = require("../../util_modules/logger");
33
33
  const option_1 = require("../../util_modules/option");
34
34
  const project_1 = require("../../util_modules/project");
35
+ const fs_2 = require("fs");
36
+ const os_1 = require("os");
37
+ const pip_install_1 = require("../../init/dependencies/python/pip-install");
35
38
  function validate() {
36
39
  return __awaiter(this, void 0, void 0, function* () {
37
40
  const sourceDir = (0, project_1.resolveProjectPath)(config_1.functionsConfig.source());
@@ -222,7 +225,8 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
222
225
  index: js_1.JS.get(catalystJson, 'execution.main'),
223
226
  source: fnPath,
224
227
  valid: true,
225
- integ_config: js_1.JS.get(catalystJson, 'deployment.integration_config')
228
+ integ_config: js_1.JS.get(catalystJson, 'deployment.integration_config'),
229
+ env_var: refineEnvVariables(js_1.JS.get(catalystJson, 'deployment.env_variables'))
226
230
  };
227
231
  if (mapRemoteFn && remoteFnIdMap[fnTarget.name] !== undefined) {
228
232
  fnTarget.id = remoteFnIdMap[fnTarget.name];
@@ -232,6 +236,13 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
232
236
  });
233
237
  }
234
238
  exports.refineTargets = refineTargets;
239
+ function refineEnvVariables(vars) {
240
+ return Object.entries(vars || {}).reduce((envObj, curEntry) => {
241
+ envObj[curEntry[0]] =
242
+ typeof curEntry[1] === 'object' ? JSON.stringify(curEntry[1]) : curEntry[1];
243
+ return envObj;
244
+ }, {});
245
+ }
235
246
  function executeHook({ prefix, command }) {
236
247
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
237
248
  (0, logger_1.debug)(`skipping ${prefix + command} hook`);
@@ -245,7 +256,7 @@ function executeHook({ prefix, command }) {
245
256
  }
246
257
  exports.executeHook = executeHook;
247
258
  function pack(target) {
248
- var _a;
259
+ var _a, _b;
249
260
  return __awaiter(this, void 0, void 0, function* () {
250
261
  try {
251
262
  let source = target.source;
@@ -270,7 +281,7 @@ function pack(target) {
270
281
  }
271
282
  const zip = new archiver_1.default(target.name);
272
283
  if ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
273
- const outputFolder = (0, path_1.join)(source, '.output');
284
+ const outputFolder = (0, path_1.join)(source, constants_1.FOLDERNAME.output);
274
285
  const outputFiles = yield fs_1.ASYNC.walk(outputFolder);
275
286
  outputFiles.forEach((file) => {
276
287
  zip.add(file.replace(outputFolder + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
@@ -278,11 +289,25 @@ function pack(target) {
278
289
  }
279
290
  else {
280
291
  const exclude = config_1.functionsConfig.ignore(source);
281
- const files = yield fs_1.ASYNC.walk(source, { exclude });
292
+ const files = yield fs_1.ASYNC.walk(source, { filter: { exclude, excludeDir: true } });
282
293
  files.forEach((file) => {
283
294
  zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
284
295
  });
285
296
  }
297
+ if ((_b = target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.python)) {
298
+ const reqFile = (0, path_1.join)(target.source, constants_1.FILENAME.functions.python_requirements);
299
+ const requirementsExists = yield fs_1.ASYNC.readFile(reqFile);
300
+ if (requirementsExists) {
301
+ const tmpDir = (0, path_1.join)((0, os_1.tmpdir)(), '.catalyst', 'python', target.name + Date.now().toString());
302
+ yield fs_1.ASYNC.ensureDir(tmpDir);
303
+ yield fs_1.ASYNC.emptyDir(tmpDir);
304
+ yield (0, pip_install_1.installRequirements)(reqFile, tmpDir, target.stack.replace('python_', ''), true);
305
+ const files = yield fs_1.ASYNC.walk(tmpDir);
306
+ files.forEach((file) => {
307
+ zip.add(file.replace(tmpDir + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
308
+ });
309
+ }
310
+ }
286
311
  const finalizer = yield zip.finalize();
287
312
  const zipFsStream = yield finalizer.fsStream();
288
313
  target.valid = true;
@@ -324,6 +349,7 @@ function findAndReplaceConfigProps(dir, { stack, type, integ_config }) {
324
349
  }
325
350
  exports.findAndReplaceConfigProps = findAndReplaceConfigProps;
326
351
  function resolveAllFnPorts(targets, idx = 0) {
352
+ var _a;
327
353
  return __awaiter(this, void 0, void 0, function* () {
328
354
  if (targets.length < idx + 1) {
329
355
  return;
@@ -337,7 +363,9 @@ function resolveAllFnPorts(targets, idx = 0) {
337
363
  let debugPort = -1;
338
364
  switch ((0, option_1.getCurrentCommand)()) {
339
365
  case 'serve':
340
- httpPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'http', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced);
366
+ const isPyBio = currentTargetType === constants_1.FN_TYPE.basic &&
367
+ ((_a = currentTarget.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python));
368
+ httpPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'http', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced, isPyBio);
341
369
  runtime_store_1.default.set('context.port.http.functions.' + currentTarget.name, httpPort);
342
370
  const debugOptValue = (0, option_1.getOptionValue)('debug', false);
343
371
  if (debugOptValue &&
@@ -347,7 +375,7 @@ function resolveAllFnPorts(targets, idx = 0) {
347
375
  debugPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'debug', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced);
348
376
  runtime_store_1.default.set('context.port.debug.functions.' + currentTarget.name, debugPort);
349
377
  }
350
- if (currentTargetType === constants_1.FN_TYPE.basic) {
378
+ if (currentTargetType === constants_1.FN_TYPE.basic && !isPyBio) {
351
379
  runtime_store_1.default.set('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], httpPort);
352
380
  runtime_store_1.default.set('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], debugPort);
353
381
  }
@@ -478,3 +506,36 @@ function updateFnConfig(target) {
478
506
  });
479
507
  }
480
508
  exports.updateFnConfig = updateFnConfig;
509
+ function copyModDirPerm(src, dest, perm, { replace = true } = {}) {
510
+ return __awaiter(this, void 0, void 0, function* () {
511
+ const srcContents = yield fs_1.ASYNC.walk(src, { includeDirPaths: true, depth: 1 });
512
+ srcContents.shift();
513
+ yield Promise.all(srcContents.map((content) => {
514
+ return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
515
+ try {
516
+ const isDir = yield fs_1.ASYNC.dirExists(content);
517
+ if (isDir) {
518
+ const destFolder = (0, path_1.join)(dest, (0, path_1.basename)(content));
519
+ yield fs_1.ASYNC.ensureDir(destFolder);
520
+ yield copyModDirPerm(content, destFolder, perm);
521
+ return res();
522
+ }
523
+ const destFile = (0, path_1.join)(dest, (0, path_1.basename)(content));
524
+ yield fs_1.ASYNC.copyFile(content, destFile, replace ? fs_2.constants.COPYFILE_FICLONE : fs_2.constants.COPYFILE_EXCL).catch((err) => {
525
+ if (!replace && err.code === 'EEXIST') {
526
+ return;
527
+ }
528
+ throw err;
529
+ });
530
+ yield fs_1.ASYNC.chmod(destFile, perm);
531
+ return res();
532
+ }
533
+ catch (e) {
534
+ rej(e);
535
+ }
536
+ }));
537
+ }));
538
+ return fs_1.ASYNC.chmod(dest, perm);
539
+ });
540
+ }
541
+ exports.copyModDirPerm = copyModDirPerm;
@@ -79,34 +79,38 @@ function copyIntegHandlers(templatePath, targetPath, lang) {
79
79
  case constants_1.INTEG.services.cliq:
80
80
  const handlers = runtime_store_1.default.get('context.function.integration.cliq.handlers', []);
81
81
  if (lang === runtime_1.default.language.nodejs) {
82
- const filePaths = constants_1.CLIQ.node_template_contents_initial_copy.map((path) => {
83
- return (0, path_1.join)(templatePath, path);
84
- });
82
+ const filePaths = constants_1.CLIQ.node_template_contents_initial_copy.map((path) => (0, path_1.join)(templatePath, path));
85
83
  yield fs_1.ASYNC.copyFiles(filePaths, targetPath);
86
84
  const integHandlerConfig = {};
87
85
  const handlerPaths = handlers.map((handler) => {
88
- integHandlerConfig[handler] =
89
- constants_1.CLIQ.node_handlers_path + constants_1.CLIQ.node_handler_file_mapping[handler];
86
+ integHandlerConfig[handler] = (0, path_1.join)(constants_1.CLIQ.node_handlers_path, constants_1.CLIQ.node_handler_file_mapping[handler]);
90
87
  return (0, path_1.join)(templatePath, constants_1.CLIQ.node_handlers_template_dir, constants_1.CLIQ.node_handler_file_mapping[handler]);
91
88
  });
92
89
  yield fs_1.ASYNC.copyFiles(handlerPaths, (0, path_1.join)(targetPath, constants_1.CLIQ.node_handlers_template_dir));
93
90
  integ_config.handlers = integHandlerConfig;
94
91
  }
95
92
  else if (lang === runtime_1.default.language.java) {
96
- const filePaths = constants_1.CLIQ.java_template_contents_initial_copy.map((path) => {
97
- return (0, path_1.join)(templatePath, path);
98
- });
93
+ const filePaths = constants_1.CLIQ.java_template_contents_initial_copy.map((path) => (0, path_1.join)(templatePath, path));
99
94
  yield fs_1.ASYNC.copyFiles(filePaths, targetPath);
100
95
  const integHandlerConfig = {};
101
96
  const handlerPaths = handlers.map((handler) => {
102
- integHandlerConfig[handler] =
103
- constants_1.CLIQ.java_handlers_path +
104
- constants_1.CLIQ.java_handler_file_mapping[handler].replace('.java', '');
97
+ integHandlerConfig[handler] = (0, path_1.join)(constants_1.CLIQ.java_handlers_path, constants_1.CLIQ.java_handler_file_mapping[handler].replace('.java', ''));
105
98
  return (0, path_1.join)(templatePath, constants_1.CLIQ.java_handlers_template_dir, constants_1.CLIQ.java_handler_file_mapping[handler]);
106
99
  });
107
100
  yield fs_1.ASYNC.copyFiles(handlerPaths, (0, path_1.join)(targetPath, constants_1.CLIQ.java_handlers_template_dir));
108
101
  integ_config.handlers = integHandlerConfig;
109
102
  }
103
+ else if (lang === runtime_1.default.language.python) {
104
+ const filePaths = constants_1.CLIQ.python_template_contents_initial_copy.map((path) => (0, path_1.join)(templatePath, path));
105
+ yield fs_1.ASYNC.copyFiles(filePaths, targetPath);
106
+ const integHandlerConfig = {};
107
+ const handlerPaths = handlers.map((handler) => {
108
+ integHandlerConfig[handler] = (0, path_1.join)(constants_1.CLIQ.python_handlers_path, constants_1.CLIQ.python_handler_file_mapping[handler]);
109
+ return (0, path_1.join)(templatePath, constants_1.CLIQ.python_handlers_template_dir, constants_1.CLIQ.python_handler_file_mapping[handler]);
110
+ });
111
+ yield fs_1.ASYNC.copyFiles(handlerPaths, (0, path_1.join)(targetPath, constants_1.CLIQ.python_handlers_template_dir));
112
+ integ_config.handlers = integHandlerConfig;
113
+ }
110
114
  break;
111
115
  default:
112
116
  break;
@@ -115,7 +115,9 @@ function rewriteClasspath(pth, libPth) {
115
115
  if (content === undefined) {
116
116
  throw new error_1.default('Content of ' + pth + ' is not defined', { exit: 2 });
117
117
  }
118
- const files = yield fs_1.ASYNC.walk((0, path_1.dirname)(libPth), { exclude: ['**/.output'] });
118
+ const files = yield fs_1.ASYNC.walk((0, path_1.dirname)(libPth), {
119
+ filter: { exclude: ['**/.output'], excludeDir: true }
120
+ });
119
121
  const result = yield xml2js_1.default.parseStringPromise(content);
120
122
  const classPathEntries = js_1.JS.chain(files)
121
123
  .filter((jarPth) => (0, path_1.extname)(jarPth) === '.jar')
@@ -195,7 +197,7 @@ function compileTarget(target) {
195
197
  var _a;
196
198
  return __awaiter(this, void 0, void 0, function* () {
197
199
  const targetSource = target.source;
198
- const outputFolder = (0, path_1.join)(targetSource, '.output');
200
+ const outputFolder = (0, path_1.join)(targetSource, constants_1.FOLDERNAME.output);
199
201
  const integ = target.integ_config;
200
202
  const entries = [(0, path_1.join)(targetSource, ((_a = target.index) === null || _a === void 0 ? void 0 : _a.replace(/\./g, path_1.sep)) + '.java')];
201
203
  if (integ && integ.length > 0) {
@@ -209,7 +211,9 @@ function compileTarget(target) {
209
211
  yield fs_1.ASYNC.ensureDir(outputFolder);
210
212
  yield fs_1.ASYNC.emptyDir(outputFolder);
211
213
  const ignore = config_1.functionsConfig.ignore(targetSource);
212
- const allFiles = yield fs_1.ASYNC.walk(targetSource, { exclude: ['**/.output', ...ignore] });
214
+ const allFiles = yield fs_1.ASYNC.walk(targetSource, {
215
+ filter: { exclude: ['**/.output', ...ignore], excludeDir: true }
216
+ });
213
217
  const cleanUpFiles = [...allFiles];
214
218
  while (allFiles.length > 0) {
215
219
  const limit = allFiles.length < 20 ? allFiles.length : 20;
@@ -0,0 +1,121 @@
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 (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
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.removeRequirements = exports.validate = void 0;
39
+ const ansi_colors_1 = require("ansi-colors");
40
+ const os_1 = require("os");
41
+ const path_1 = __importStar(require("path"));
42
+ const error_1 = __importDefault(require("../../error"));
43
+ const ensure_python_1 = require("../../init/dependencies/python/ensure-python");
44
+ const pip_install_1 = require("../../init/dependencies/python/pip-install");
45
+ const constants_1 = require("../../util_modules/constants");
46
+ const fs_1 = require("../../util_modules/fs");
47
+ const js_1 = require("../../util_modules/js");
48
+ const validationResults = {};
49
+ function validate(targets, idx) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (targets.length < idx + 1) {
52
+ return;
53
+ }
54
+ const currentTarget = targets[idx];
55
+ const stack = currentTarget.stack;
56
+ try {
57
+ if (!stack) {
58
+ throw new error_1.default('unknown function stack', {
59
+ exit: 1
60
+ });
61
+ }
62
+ const catalystFile = (0, path_1.join)(currentTarget.source, constants_1.FILENAME.catalyst_config);
63
+ const data = yield fs_1.ASYNC.readJSONFile(catalystFile, { checkpath: true });
64
+ if (data === undefined) {
65
+ throw new error_1.default('no ' + constants_1.FILENAME.catalyst_config + ' file found', {
66
+ exit: 1
67
+ });
68
+ }
69
+ const indexFile = (0, path_1.join)(currentTarget.source, js_1.JS.get(data, 'execution.main', 'main.py'));
70
+ currentTarget.index = indexFile;
71
+ const indexFileExists = yield fs_1.ASYNC.fileExists(indexFile);
72
+ if (!indexFileExists) {
73
+ throw new error_1.default('Entry point file does not exists', {
74
+ errorId: 'PYTHON-1',
75
+ exit: 1,
76
+ arg: [
77
+ (0, ansi_colors_1.bold)(currentTarget.index || 'undefined'),
78
+ (0, ansi_colors_1.bold)(constants_1.FILENAME.catalyst_config),
79
+ (0, ansi_colors_1.bold)(currentTarget.name)
80
+ ]
81
+ });
82
+ }
83
+ if (!(stack in validationResults)) {
84
+ yield (0, ensure_python_1.ensurePythonWithPip)(stack.replace('python_', '').replace('_', '.'));
85
+ validationResults[stack] = { valid: true };
86
+ }
87
+ if (!validationResults[stack]['valid']) {
88
+ currentTarget.valid = validationResults[stack]['valid'];
89
+ currentTarget.failure_reason = validationResults[stack]['message'];
90
+ }
91
+ else {
92
+ currentTarget.valid = true;
93
+ }
94
+ return validate(targets, ++idx);
95
+ }
96
+ catch (e) {
97
+ const err = error_1.default.getErrorInstance(e);
98
+ currentTarget.valid = false;
99
+ currentTarget.failure_reason = err.message;
100
+ if (stack) {
101
+ validationResults[stack] = { valid: false, message: err.message };
102
+ }
103
+ return validate(targets, ++idx);
104
+ }
105
+ });
106
+ }
107
+ exports.validate = validate;
108
+ function removeRequirements(reqFile, target) {
109
+ var _a;
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const tmpDir = (0, path_1.join)((0, os_1.tmpdir)(), '.catalyst', 'python', Date.now().toString());
112
+ yield fs_1.ASYNC.ensureDir(tmpDir);
113
+ yield fs_1.ASYNC.emptyDir(tmpDir);
114
+ yield (0, pip_install_1.installRequirements)(reqFile, tmpDir, (_a = target.stack) === null || _a === void 0 ? void 0 : _a.replace('python_', ''), true);
115
+ const files = yield fs_1.ASYNC.walk(tmpDir, { depth: 1, includeDirPaths: true });
116
+ yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
117
+ yield fs_1.ASYNC.deleteFile((0, path_1.join)(target.source, path_1.default.basename(file)));
118
+ })));
119
+ });
120
+ }
121
+ exports.removeRequirements = removeRequirements;
package/lib/fn-watcher.js CHANGED
@@ -8,16 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  const chokidar_1 = require("chokidar");
16
+ const path_1 = require("path");
17
+ const runtime_store_1 = __importDefault(require("./runtime-store"));
13
18
  const languages_1 = require("./shell/prepare/languages");
19
+ const constants_1 = require("./util_modules/constants");
20
+ const fs_1 = require("./util_modules/fs");
14
21
  const logger_1 = require("./util_modules/logger");
15
22
  exports.default = (target) => __awaiter(void 0, void 0, void 0, function* () {
16
23
  return new Promise((res) => {
17
24
  let paused = false;
18
25
  let latestEvent;
19
26
  const watcher = (0, chokidar_1.watch)(target.source, {
20
- ignored: [/(^|[\/\\])\../, 'node_modules/**/*', '/**/*.jar'],
27
+ ignored: [/(^|[\/\\])\../, 'node_modules/**/*', '/**/*.jar', 'catalyst-debug.log'],
21
28
  cwd: target.source,
22
29
  ignoreInitial: true
23
30
  });
@@ -31,7 +38,8 @@ exports.default = (target) => __awaiter(void 0, void 0, void 0, function* () {
31
38
  watcher.emit('preparing');
32
39
  target.failure_reason = undefined;
33
40
  target.valid = true;
34
- yield (0, languages_1.prepareFunctions)([target]);
41
+ yield fs_1.ASYNC.chmod((0, path_1.join)(runtime_store_1.default.get('project.root'), constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, target.name), '755', { recursive: true });
42
+ yield (0, languages_1.prepareFunctions)([target], latestEvent);
35
43
  if (currentLatestEvent.at === latestEvent.at) {
36
44
  latestEvent = undefined;
37
45
  }
package/lib/index.js CHANGED
@@ -16,7 +16,8 @@ program.description(description);
16
16
  program.version(version, '-v, --version', 'Print the Catalyst CLI version number');
17
17
  program.option('-p, --project <name|project_id>', 'Specify the Catalyst project to be used for a command');
18
18
  program.option('--token <token>', 'Supply an authentication token for a command');
19
- program.option('--dc <us|eu|in>', 'Supply a data center for a command');
19
+ program.option('--dc <us|eu|in|au>', 'Supply a data center for a command');
20
+ program.option('--org <org_id>', 'Supply a Org ID to be used for a command');
20
21
  program.option('--verbose', 'Change the log level to verbose for debugging purposes');
21
22
  program.helpOption('-h, --help', 'Display help for a Catalyst command');
22
23
  program.showSuggestionAfterError();