zcatalyst-cli 1.9.1 → 1.11.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 (189) hide show
  1. package/README.md +3 -3
  2. package/docs/.DS_Store +0 -0
  3. package/docs/client-utils.toml +5 -0
  4. package/docs/command_needs/auth.toml +5 -0
  5. package/docs/commands/iac/export.toml +4 -0
  6. package/docs/commands/iac/import.toml +4 -0
  7. package/docs/commands/iac/status.toml +4 -0
  8. package/docs/commands/project/use.toml +6 -0
  9. package/docs/iac/status/bundle.toml +4 -0
  10. package/docs/plugin-loader.toml +4 -0
  11. package/docs/serve/server/index.toml +4 -0
  12. package/docs/serve/server/lib/web_client/server.toml +4 -0
  13. package/lib/api-timer.js +81 -0
  14. package/lib/apig-utils.js +17 -14
  15. package/lib/archiver.js +83 -45
  16. package/lib/authentication/login.js +4 -2
  17. package/lib/bin/catalyst.js +0 -1
  18. package/lib/client-utils.js +28 -26
  19. package/lib/client.js +0 -3
  20. package/lib/command_needs/auth.js +12 -3
  21. package/lib/command_needs/rc.js +12 -7
  22. package/lib/commands/apig/status.js +6 -4
  23. package/lib/commands/client/delete.js +3 -4
  24. package/lib/commands/client/setup.js +1 -1
  25. package/lib/commands/deploy.js +3 -1
  26. package/lib/commands/ds/export.js +3 -1
  27. package/lib/commands/ds/import.js +3 -1
  28. package/lib/commands/ds/status.js +145 -149
  29. package/lib/commands/event/generate/index.js +4 -13
  30. package/lib/commands/functions/config.js +1 -1
  31. package/lib/commands/functions/setup.js +1 -1
  32. package/lib/commands/help.js +1 -23
  33. package/lib/commands/iac/export.js +85 -0
  34. package/lib/commands/iac/import.js +210 -0
  35. package/lib/commands/iac/pack.js +129 -0
  36. package/lib/commands/iac/status.js +63 -0
  37. package/lib/commands/index.js +4 -0
  38. package/lib/commands/init.js +34 -27
  39. package/lib/commands/project/list.js +10 -6
  40. package/lib/commands/project/use.js +42 -25
  41. package/lib/commands/pull.js +1 -1
  42. package/lib/commands/serve.js +2 -1
  43. package/lib/deploy/features/functions/index.js +2 -1
  44. package/lib/deploy/index.js +3 -1
  45. package/lib/endpoints/lib/iac.js +134 -0
  46. package/lib/endpoints/lib/sdk.js +2 -2
  47. package/lib/error.js +33 -3
  48. package/lib/errorOut.js +4 -3
  49. package/lib/fn-utils/lib/common.js +37 -16
  50. package/lib/fn-utils/lib/java.js +7 -9
  51. package/lib/fn-utils/lib/node.js +7 -1
  52. package/lib/iac/status/bundle.js +82 -0
  53. package/lib/iac/status/deploy.js +74 -0
  54. package/lib/iac/status/util/index.js +26 -0
  55. package/lib/index.js +8 -14
  56. package/lib/init/dependencies/npm-install.js +2 -9
  57. package/lib/init/features/client/index.js +47 -0
  58. package/lib/init/features/client/initializers/angular.js +106 -0
  59. package/lib/init/features/client/initializers/basic.js +50 -0
  60. package/lib/init/features/client/initializers/lyte.js +61 -0
  61. package/lib/init/features/client/initializers/react.js +77 -0
  62. package/lib/init/features/functions/languages/java.js +2 -5
  63. package/lib/init/features/functions/languages/node.js +5 -6
  64. package/lib/init/features/index.js +18 -6
  65. package/lib/init/features/project.js +72 -34
  66. package/lib/init/util/client.js +96 -0
  67. package/lib/init/util/functions.js +20 -0
  68. package/lib/init/util/project.js +35 -0
  69. package/lib/internal/api.js +6 -9
  70. package/lib/internal/command.js +6 -3
  71. package/lib/internal/config.js +7 -4
  72. package/lib/migration/index.js +10 -6
  73. package/lib/option-filter.js +4 -1
  74. package/lib/optional-import.js +11 -25
  75. package/lib/plugin-loader.js +8 -2
  76. package/lib/port-resolver.js +20 -16
  77. package/lib/prompt/index.js +92 -0
  78. package/lib/prompt/types/file-path.js +95 -0
  79. package/lib/pull/features/client.js +1 -1
  80. package/lib/pull/features/functions/index.js +5 -7
  81. package/lib/pull/index.js +4 -1
  82. package/lib/serve/features/index.js +3 -1
  83. package/lib/serve/index.js +6 -1
  84. package/lib/serve/server/index.js +52 -8
  85. package/lib/serve/server/lib/master.js +24 -12
  86. package/lib/serve/server/lib/web_client/index.js +30 -0
  87. package/lib/serve/server/lib/web_client/server.js +171 -0
  88. package/lib/shell/dependencies/http-functions.js +1 -1
  89. package/lib/shell/index.js +3 -1
  90. package/lib/track.js +3 -1
  91. package/lib/util_modules/char.js +1 -1
  92. package/lib/util_modules/config/lib/apig.js +2 -1
  93. package/lib/util_modules/constants/index.js +5 -1
  94. package/lib/util_modules/constants/lib/file-names.js +2 -1
  95. package/lib/util_modules/constants/lib/iac.js +8 -0
  96. package/lib/util_modules/constants/lib/placeholders.js +1 -0
  97. package/lib/util_modules/constants/lib/plugin.js +28 -0
  98. package/lib/util_modules/constants/lib/regex.js +2 -1
  99. package/lib/util_modules/constants/lib/scopes.js +5 -0
  100. package/lib/util_modules/constants/lib/template.js +11 -1
  101. package/lib/util_modules/constants/lib/urls.js +12 -4
  102. package/lib/util_modules/constants/project.js +6 -0
  103. package/lib/util_modules/{contextHelp.js → context-help.js} +5 -1
  104. package/lib/util_modules/env.js +14 -16
  105. package/lib/util_modules/fs/lib/async.js +29 -22
  106. package/lib/util_modules/fs/utils.js +8 -0
  107. package/lib/util_modules/global-space.js +99 -0
  108. package/lib/util_modules/js.js +6 -0
  109. package/lib/util_modules/option.js +5 -1
  110. package/lib/util_modules/parser/toml.js +5 -1
  111. package/lib/util_modules/project.js +3 -0
  112. package/lib/util_modules/shell.js +9 -8
  113. package/lib/winston.js +1 -1
  114. package/package.json +11 -5
  115. package/templates/.DS_Store +0 -0
  116. package/templates/iacSuccess.html +391 -0
  117. package/templates/init/.DS_Store +0 -0
  118. package/templates/init/client/.DS_Store +0 -0
  119. package/templates/init/client/{client-package.json → basic/client-package.json} +0 -0
  120. package/templates/init/client/{index.html → basic/index.html} +0 -0
  121. package/templates/init/client/{main.css → basic/main.css} +0 -0
  122. package/templates/init/client/{main.js → basic/main.js} +0 -0
  123. package/templates/init/client/lyte/build/build.js +301 -0
  124. package/templates/init/client/lyte/build/scripts/cliDownloadScript.js +54 -0
  125. package/templates/init/client/lyte/client-package.json +5 -0
  126. package/templates/init/client/lyte/components/javascript/welcome-comp.js +13 -0
  127. package/templates/init/client/lyte/components/styles/welcome-comp.css +0 -0
  128. package/templates/init/client/lyte/components/templates/welcome-comp.html +8 -0
  129. package/templates/init/client/lyte/data-store/adapters/.gitkeep +0 -0
  130. package/templates/init/client/lyte/data-store/models/.gitkeep +0 -0
  131. package/templates/init/client/lyte/data-store/serializers/.gitkeep +0 -0
  132. package/templates/init/client/lyte/index.html +17 -0
  133. package/templates/init/client/lyte/package.json +12 -0
  134. package/templates/init/client/lyte/router.js +14 -0
  135. package/templates/init/client/lyte/routes/index.js +54 -0
  136. package/templates/init/client/react/.DS_Store +0 -0
  137. package/templates/init/client/react/react_js/package.json +11 -0
  138. package/templates/init/client/react/react_js/template/README.md +70 -0
  139. package/templates/init/client/react/react_js/template/client-package.json +5 -0
  140. package/templates/init/client/react/react_js/template/gitignore +23 -0
  141. package/templates/init/client/react/react_js/template/public/favicon.ico +0 -0
  142. package/templates/init/client/react/react_js/template/public/index.html +43 -0
  143. package/templates/init/client/react/react_js/template/public/logo192.png +0 -0
  144. package/templates/init/client/react/react_js/template/public/logo512.png +0 -0
  145. package/templates/init/client/react/react_js/template/public/manifest.json +25 -0
  146. package/templates/init/client/react/react_js/template/public/robots.txt +3 -0
  147. package/templates/init/client/react/react_js/template/src/App.css +38 -0
  148. package/templates/init/client/react/react_js/template/src/App.js +25 -0
  149. package/templates/init/client/react/react_js/template/src/App.test.js +8 -0
  150. package/templates/init/client/react/react_js/template/src/index.css +13 -0
  151. package/templates/init/client/react/react_js/template/src/index.js +17 -0
  152. package/templates/init/client/react/react_js/template/src/logo.svg +1 -0
  153. package/templates/init/client/react/react_js/template/src/reportWebVitals.js +13 -0
  154. package/templates/init/client/react/react_js/template/src/setupTests.js +5 -0
  155. package/templates/init/client/react/react_js/template.json +13 -0
  156. package/templates/init/client/react/react_ts/package.json +11 -0
  157. package/templates/init/client/react/react_ts/template/README.md +46 -0
  158. package/templates/init/client/react/react_ts/template/client-package.json +5 -0
  159. package/templates/init/client/react/react_ts/template/gitignore +23 -0
  160. package/templates/init/client/react/react_ts/template/public/favicon.ico +0 -0
  161. package/templates/init/client/react/react_ts/template/public/index.html +43 -0
  162. package/templates/init/client/react/react_ts/template/public/logo192.png +0 -0
  163. package/templates/init/client/react/react_ts/template/public/logo512.png +0 -0
  164. package/templates/init/client/react/react_ts/template/public/manifest.json +25 -0
  165. package/templates/init/client/react/react_ts/template/public/robots.txt +3 -0
  166. package/templates/init/client/react/react_ts/template/src/App.css +38 -0
  167. package/templates/init/client/react/react_ts/template/src/App.test.tsx +9 -0
  168. package/templates/init/client/react/react_ts/template/src/App.tsx +26 -0
  169. package/templates/init/client/react/react_ts/template/src/index.css +13 -0
  170. package/templates/init/client/react/react_ts/template/src/index.tsx +17 -0
  171. package/templates/init/client/react/react_ts/template/src/logo.svg +1 -0
  172. package/templates/init/client/react/react_ts/template/src/reportWebVitals.ts +15 -0
  173. package/templates/init/client/react/react_ts/template/src/setupTests.ts +5 -0
  174. package/templates/init/client/react/react_ts/template.json +18 -0
  175. package/templates/init/functions/java/integ/cliq/com/handlers/BotHandler.java +94 -109
  176. package/templates/init/functions/java/integ/cliq/com/handlers/CommandHandler.java +20 -27
  177. package/templates/init/functions/java/integ/cliq/com/handlers/FunctionHandler.java +143 -112
  178. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationHandler.java +4 -7
  179. package/templates/init/functions/java/integ/cliq/com/handlers/InstallationValidator.java +4 -7
  180. package/templates/init/functions/java/integ/cliq/com/handlers/MessageActionHandler.java +10 -12
  181. package/templates/init/functions/java/integ/cliq/com/handlers/WidgetHandler.java +100 -66
  182. package/templates/init/functions/java/integ/cliq/sample.java +5 -7
  183. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +0 -1
  184. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +46 -0
  185. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +31 -0
  186. package/templates/web-socket.txt +21 -0
  187. package/lib/init/features/client.js +0 -51
  188. package/lib/prompt.js +0 -49
  189. package/lib/serve/server/lib/client.js +0 -30
@@ -18,23 +18,24 @@ const error_1 = __importDefault(require("../../error"));
18
18
  const command_1 = __importDefault(require("../../internal/command"));
19
19
  const prompt_1 = __importDefault(require("../../prompt"));
20
20
  const constants_1 = require("../../util_modules/constants");
21
+ const project_1 = __importDefault(require("../../util_modules/constants/project"));
21
22
  const js_1 = require("../../util_modules/js");
22
23
  const logger_1 = require("../../util_modules/logger");
23
- const project_1 = require("../../util_modules/project");
24
+ const project_2 = require("../../util_modules/project");
25
+ const makeActive = (currentProjectId, optedProject) => __awaiter(void 0, void 0, void 0, function* () {
26
+ yield project_2.upsertProject(optedProject, {
27
+ active: true,
28
+ base: js_1.JS.isNull(currentProjectId)
29
+ });
30
+ logger_1.success('Successfully made project active');
31
+ });
24
32
  exports.default = new command_1.default('project:use [name_or_project_id]')
25
33
  .description('Set an active Catalyst project for your working directory')
26
34
  .needs('auth', [constants_1.SCOPE.projects])
27
35
  .needs('config', { optional: true, resolveOnNotFound: true })
28
36
  .needs('rc', { optional: true, resolveOnNotFound: true })
29
37
  .action((newActive) => __awaiter(void 0, void 0, void 0, function* () {
30
- const currentProjectId = project_1.getProjectId(null);
31
- const makeActive = (optedProject) => __awaiter(void 0, void 0, void 0, function* () {
32
- yield project_1.upsertProject(optedProject, {
33
- active: true,
34
- base: js_1.JS.isNull(currentProjectId)
35
- });
36
- logger_1.success('Successfully made project active');
37
- });
38
+ const currentProjectId = project_2.getProjectId(null);
38
39
  const allProjects = (yield (yield endpoints_1.projectAPI()).getAllProjects().catch(() => {
39
40
  throw new error_1.default('Unable to get projects', {
40
41
  exit: 2
@@ -48,13 +49,27 @@ exports.default = new command_1.default('project:use [name_or_project_id]')
48
49
  }
49
50
  if (allProjects.length === 1) {
50
51
  logger_1.message('only one project found in remote, ignoring user input and making it as active');
51
- return makeActive(allProjects[0]);
52
+ return makeActive(currentProjectId, allProjects[0]);
52
53
  }
53
- const transformedProjects = allProjects.map((project) => project_1.transformProject(project));
54
+ const transformedProjects = allProjects.map(project_2.transformProject);
54
55
  if (newActive !== undefined) {
55
56
  const optedProject = parseInt(newActive, 10)
56
57
  ? transformedProjects.find((proj) => proj.id + '' === newActive)
57
58
  : transformedProjects.find((proj) => proj.name === newActive);
59
+ if ((optedProject === null || optedProject === void 0 ? void 0 : optedProject.type) && !project_1.default.accepted_types.includes(optedProject.type)) {
60
+ throw new error_1.default('provided project cannot be used since its not live', {
61
+ exit: 1,
62
+ errorId: 'PROJ-USE-3',
63
+ arg: [
64
+ ansi_colors_1.bold(newActive),
65
+ ansi_colors_1.bold(allProjects
66
+ .filter((proj) => proj.project_type &&
67
+ project_1.default.accepted_types.includes(proj.project_type))
68
+ .map((project) => '* ' + project.project_name)
69
+ .join('\n'))
70
+ ]
71
+ });
72
+ }
58
73
  if (optedProject === undefined) {
59
74
  throw new error_1.default('provided project does not match any project in remote', {
60
75
  exit: 1,
@@ -65,20 +80,22 @@ exports.default = new command_1.default('project:use [name_or_project_id]')
65
80
  ]
66
81
  });
67
82
  }
68
- return makeActive(optedProject);
83
+ return makeActive(currentProjectId, optedProject);
69
84
  }
70
- else {
71
- const choices = transformedProjects.map((project) => {
72
- return prompt_1.default.choice(project.name, {
73
- value: project,
74
- short: project.name,
75
- disabled: currentProjectId === project.id + '' ? 'currently active project' : false
76
- });
85
+ const choices = transformedProjects.map((project) => {
86
+ return prompt_1.default.choice(project.name, {
87
+ value: project,
88
+ short: project.name,
89
+ disabled: currentProjectId === project.id + ''
90
+ ? 'currently active project'
91
+ : project.type && !project_1.default.accepted_types.includes(project.type)
92
+ ? project.type
93
+ : false
77
94
  });
78
- const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Which project do you wish to make active ? ', {
79
- type: 'list',
80
- choices
81
- }));
82
- return makeActive(projectAns.project);
83
- }
95
+ });
96
+ const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Which project do you wish to make active ? ', {
97
+ type: 'list',
98
+ choices
99
+ }));
100
+ return makeActive(currentProjectId, projectAns.project);
84
101
  }));
@@ -72,7 +72,7 @@ exports.default = new command_1.default('pull [feature]')
72
72
  ansi_colors_1.bold(runtime_store_1.default.get('project.root')) +
73
73
  '\n' +
74
74
  warningText);
75
- const ans = env_1.isWindows()
75
+ const ans = env_1.isWindows
76
76
  ? yield prompt_1.default.ask(prompt_1.default.question('confirmation', 'Are you ready to proceed?', {
77
77
  type: 'confirm'
78
78
  }))
@@ -41,9 +41,10 @@ exports.default = new command_1.default('serve')
41
41
  .option('--proxy <url>', 'proxy url to proxy any unknown request to the given url ' +
42
42
  '(e.g. "http://localhost:8080")')
43
43
  .option('--only <targets>', 'only serve specified, comma-separated targets (e.g. "client,functions:f1")')
44
- .option('--watch', 'watch for file and directory changes and enable hot reload')
44
+ .option('--no-watch', 'disable watching the files for changes')
45
45
  .option('--except <targets>', 'serve all targets except specified (e.g. "client")')
46
46
  .option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
47
+ .option('--no-open', 'disable opening the client automatically when served')
47
48
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.webapp])
48
49
  .needs('config')
49
50
  .needs('rc')
@@ -70,7 +70,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
70
70
  target.id = resp.id + '';
71
71
  fn_utils_1.fnUtils.common.generateUrlForTarget(target);
72
72
  }
73
- catch (err) {
73
+ catch (e) {
74
+ const err = error_1.default.getErrorInstance(e);
74
75
  logger_1.debug(err.stack);
75
76
  target.valid = false;
76
77
  target.failure_reason = err.message;
@@ -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
+ const error_1 = __importDefault(require("../error"));
15
16
  const runtime_store_1 = __importDefault(require("../runtime-store"));
16
17
  const logger_1 = require("../util_modules/logger");
17
18
  const features_1 = __importDefault(require("./features"));
@@ -31,7 +32,8 @@ function deploy() {
31
32
  runtime_store_1.default.set('payload.targets', runtime_store_1.default.get('payload.targets', []).concat(currentTarget));
32
33
  yield featureModule();
33
34
  }
34
- catch (error) {
35
+ catch (e) {
36
+ const error = error_1.default.getErrorInstance(e);
35
37
  logger_1.debug(`${currentTarget} deploy unsuccessful, reason : ${error.stack}`);
36
38
  logger_1.labeled(currentTarget, error.message).WARN();
37
39
  }
@@ -0,0 +1,134 @@
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
+ const project_1 = require("../../util_modules/project");
19
+ class IacAPI {
20
+ constructor(projectId, opts) {
21
+ this.opts = opts || { env: project_1.getEnvName() };
22
+ this.projectId = projectId || project_1.getProjectId('');
23
+ }
24
+ deploy(projectName, format, file, schedule = false) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const res = yield new api_1.default(this.opts).post('/baas/v1/project/import', {
27
+ formData: {
28
+ project_name: projectName,
29
+ template_format: format,
30
+ code: file,
31
+ schedule: schedule.toString()
32
+ },
33
+ json: false
34
+ });
35
+ if (res.body && res.body.data) {
36
+ return res.body.data;
37
+ }
38
+ logger_1.debug('deploy response from server : ' + JSON.stringify(res.body));
39
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
40
+ });
41
+ }
42
+ bundle(format) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/export`, {
45
+ body: {
46
+ template_format: format
47
+ },
48
+ json: true
49
+ });
50
+ if (res.body && res.body.data) {
51
+ return res.body.data;
52
+ }
53
+ logger_1.debug('bundle response from server : ' + JSON.stringify(res.body));
54
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
55
+ });
56
+ }
57
+ bundleStatus() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/export/status`);
60
+ if (res.body && res.body.data) {
61
+ return res.body.data;
62
+ }
63
+ logger_1.debug('bundle status response from server : ' + JSON.stringify(res.body));
64
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
65
+ });
66
+ }
67
+ bundleDownload() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/export/download`, {
70
+ json: false,
71
+ encoding: null,
72
+ log: {
73
+ progress: {
74
+ title: 'Project ZIP'
75
+ }
76
+ }
77
+ });
78
+ if (res.body) {
79
+ return res.body;
80
+ }
81
+ logger_1.debug('bundle status response from server : ' + JSON.stringify(res.body));
82
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
83
+ });
84
+ }
85
+ allDeploys() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/import`);
88
+ if (res.body && res.body.data) {
89
+ return res.body.data;
90
+ }
91
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
92
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
93
+ });
94
+ }
95
+ deployStatus(importId) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/import/${importId}`);
98
+ if (res.body && res.body.data) {
99
+ return res.body.data;
100
+ }
101
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
102
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
103
+ });
104
+ }
105
+ deployDelete(importId) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const res = yield new api_1.default(this.opts).delete(`/baas/v1/project/import/${importId}`);
108
+ if (res.body && res.body.data) {
109
+ return res.body.data;
110
+ }
111
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
112
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
113
+ });
114
+ }
115
+ deployDownload(importId) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/import/${importId}/download`, {
118
+ json: false,
119
+ encoding: null,
120
+ log: {
121
+ progress: {
122
+ title: 'Staged project archive'
123
+ }
124
+ }
125
+ });
126
+ if (res.body) {
127
+ return res.body;
128
+ }
129
+ logger_1.debug('export response from server : ' + JSON.stringify(res.body));
130
+ throw new error_1.default('Server Error: Unexpected Response from server.', { exit: 2 });
131
+ });
132
+ }
133
+ }
134
+ exports.default = IacAPI;
@@ -31,10 +31,10 @@ class SDK {
31
31
  if (targetSDK === undefined || targetUrl === undefined) {
32
32
  throw new error_1.default('SDK target missing', { exit: 2 });
33
33
  }
34
- const res = yield new api_1.default(this.opts).get(`/catalyst/downloads/sdk/java/${targetUrl}_latest.zip`, {
34
+ const res = yield new api_1.default(this.opts).get(`/downloads/sdk/java/${targetUrl}_latest.zip`, {
35
35
  json: false,
36
36
  encoding: null,
37
- origin: constants_1.ORIGIN.zoho,
37
+ origin: constants_1.ORIGIN.catalystStatic,
38
38
  log: {
39
39
  progress: {
40
40
  title: targetSDK.replace(new RegExp('_', 'g'), '-')
package/lib/error.js CHANGED
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const util_1 = require("util");
6
7
  const runtime_store_1 = __importDefault(require("./runtime-store"));
7
8
  const default_1 = __importDefault(require("./util_modules/constants/lib/default"));
8
9
  class CatalystError extends Error {
9
10
  constructor(message, options = {}) {
10
- var _a;
11
+ var _a, _b;
11
12
  super(message);
12
13
  this.name = default_1.default.catalystError;
13
14
  this.status = options.status || 500;
@@ -23,13 +24,42 @@ class CatalystError extends Error {
23
24
  this.fileName =
24
25
  options.fileName === undefined && stackArr[1] !== undefined
25
26
  ? stackArr[1].replace(/\.[^.]+$/, '').replace(/^[^(]+\(/, '')
26
- : options.fileName;
27
- runtime_store_1.default.set('log.' + this.fileName, runtime_store_1.default.get('log.' + this.fileName, []).concat(this));
27
+ : (_b = options.fileName) === null || _b === void 0 ? void 0 : _b.replace(/\.[^.]+$/, '');
28
+ runtime_store_1.default.set(`[log]["${this.fileName}"]`, runtime_store_1.default.get(`[log]["${this.fileName}"]`, []).concat(this));
28
29
  }
29
30
  }
30
31
  catch (e) {
31
32
  runtime_store_1.default.set('log.faultyError', runtime_store_1.default.get('log.faultyError', []).concat(this));
32
33
  }
33
34
  }
35
+ static getErrorInstance(unknownError, { message, skipHelp, fileName } = {}) {
36
+ if (unknownError instanceof CatalystError) {
37
+ if (message) {
38
+ unknownError.message = message;
39
+ }
40
+ return unknownError;
41
+ }
42
+ if (unknownError instanceof Error) {
43
+ return new CatalystError(message || unknownError.message, {
44
+ original: unknownError,
45
+ skipHelp: skipHelp === undefined ? true : skipHelp,
46
+ fileName
47
+ });
48
+ }
49
+ const newError = new CatalystError(message || 'Malformed error', {
50
+ original: util_1.inspect(unknownError),
51
+ skipHelp: skipHelp === undefined ? true : skipHelp
52
+ });
53
+ if ('message' in unknownError) {
54
+ newError.message = unknownError.message;
55
+ }
56
+ if ('stack' in unknownError) {
57
+ newError.stack = unknownError.stack;
58
+ }
59
+ if ('name' in unknownError) {
60
+ newError.name = unknownError.name;
61
+ }
62
+ return newError;
63
+ }
34
64
  }
35
65
  exports.default = CatalystError;
package/lib/errorOut.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const logger_1 = require("./util_modules/logger");
7
7
  const error_1 = __importDefault(require("./error"));
8
8
  const constants_1 = require("./util_modules/constants");
9
- const contextHelp_1 = __importDefault(require("./util_modules/contextHelp"));
9
+ const context_help_1 = __importDefault(require("./util_modules/context-help"));
10
10
  exports.default = (error, status) => {
11
11
  if (typeof error === 'string') {
12
12
  error = new error_1.default('An unexpected error has occurred.', {
@@ -23,10 +23,11 @@ exports.default = (error, status) => {
23
23
  });
24
24
  }
25
25
  try {
26
- contextHelp_1.default();
26
+ const exitCode = context_help_1.default();
27
+ process.exitCode = typeof exitCode === 'number' ? exitCode : 2;
27
28
  }
28
29
  catch (err) {
29
30
  logger_1.debug('HELP ERROR: ' + err.stack);
31
+ process.exitCode = 2;
30
32
  }
31
- process.exitCode = error ? error.exit : 2;
32
33
  };
@@ -124,10 +124,9 @@ exports.validate = validate;
124
124
  function refineTargets(rawTargets, mapRemoteFn = true) {
125
125
  return __awaiter(this, void 0, void 0, function* () {
126
126
  let remoteFnIdMap = {};
127
- let runtimeDetails = { runtimes: [] };
127
+ let runtimeDetails = runtime_store_1.default.get('context.catalyst.runtime', { runtimes: [] });
128
128
  if (mapRemoteFn) {
129
129
  const fnAPI = yield endpoints_1.functionsAPI();
130
- runtimeDetails = runtime_store_1.default.get('context.catalyst.runtime');
131
130
  let allRemoteFns = [];
132
131
  [allRemoteFns, runtimeDetails] = yield Promise.all([
133
132
  fnAPI.getAllFunctions(),
@@ -145,6 +144,7 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
145
144
  }, remoteFnIdMap);
146
145
  }
147
146
  return Promise.all(rawTargets.map((fnPath) => __awaiter(this, void 0, void 0, function* () {
147
+ fnPath = project_1.resolveProjectPath(fnPath);
148
148
  const catalystJsonPth = path_1.join(fnPath, constants_1.FILENAME.catalyst_config);
149
149
  const catalystJson = yield fs_1.ASYNC.readJSONFile(catalystJsonPth, {
150
150
  checkpath: true,
@@ -158,23 +158,24 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
158
158
  failure_reason: 'there is no valid ' + constants_1.FILENAME.catalyst_config + ' file present'
159
159
  };
160
160
  }
161
- const validatePlugin = yield plugin_loader_1.default('functions', 'validate', fnPath);
162
- if (validatePlugin !== undefined) {
161
+ const validatePlugin = yield plugin_loader_1.default('functions', 'validate', fnPath).catch((err) => logger_1.debug(err));
162
+ if (typeof validatePlugin === 'function') {
163
163
  try {
164
164
  yield validatePlugin(option_1.getCurrentCommand(), fnPath, runtime_store_1.default, catalystJson);
165
165
  }
166
166
  catch (e) {
167
- throw new error_1.default(e, {
167
+ throw new error_1.default(e.message, {
168
168
  exit: 1,
169
169
  errorId: 'COMMON-4',
170
170
  original: e,
171
- arg: ['validating', e]
171
+ arg: ['validating', e.toString()]
172
172
  });
173
173
  }
174
174
  }
175
175
  const fnName = js_1.JS.get(catalystJson, 'deployment.name');
176
176
  const userStack = js_1.JS.get(catalystJson, 'deployment.stack');
177
- if (!userStack || !runtimeDetails.runtimes.includes(userStack)) {
177
+ if (!userStack ||
178
+ (runtimeDetails.runtimes.length > 0 && !runtimeDetails.runtimes.includes(userStack))) {
178
179
  return {
179
180
  name: path_1.basename(fnPath),
180
181
  source: fnPath,
@@ -248,8 +249,8 @@ function pack(target) {
248
249
  return __awaiter(this, void 0, void 0, function* () {
249
250
  try {
250
251
  let source = target.source;
251
- const buildPlugin = yield plugin_loader_1.default('functions', 'build', source);
252
- if (buildPlugin !== undefined) {
252
+ const buildPlugin = yield plugin_loader_1.default('functions', 'build', source).catch((err) => logger_1.debug(err));
253
+ if (typeof buildPlugin === 'function') {
253
254
  try {
254
255
  logger_1.message(`Plugin : "${runtime_store_1.default.get(`context.functions.plugins.build.${source}`)}" is used for functions deploy`);
255
256
  const outputDir = yield buildPlugin(source, runtime_store_1.default);
@@ -259,11 +260,11 @@ function pack(target) {
259
260
  source = outputDir;
260
261
  }
261
262
  catch (e) {
262
- throw new error_1.default(e, {
263
+ throw new error_1.default(e.message, {
263
264
  exit: 1,
264
265
  errorId: 'COMMON-4',
265
266
  original: e,
266
- arg: ['building', e]
267
+ arg: ['building', e.toString()]
267
268
  });
268
269
  }
269
270
  }
@@ -276,8 +277,8 @@ function pack(target) {
276
277
  });
277
278
  }
278
279
  else {
279
- const ignore = config_1.functionsConfig.ignore(source);
280
- const files = yield fs_1.ASYNC.walk(source, ignore);
280
+ const exclude = config_1.functionsConfig.ignore(source);
281
+ const files = yield fs_1.ASYNC.walk(source, { exclude });
281
282
  files.forEach((file) => {
282
283
  zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
283
284
  });
@@ -289,7 +290,7 @@ function pack(target) {
289
290
  }
290
291
  catch (err) {
291
292
  target.valid = false;
292
- target.failure_reason = err;
293
+ target.failure_reason = err.message;
293
294
  }
294
295
  });
295
296
  }
@@ -368,6 +369,26 @@ function resolveAllFnPorts(targets, idx = 0) {
368
369
  });
369
370
  }
370
371
  exports.resolveAllFnPorts = resolveAllFnPorts;
372
+ function fnDirDelete(conf) {
373
+ return __awaiter(this, void 0, void 0, function* () {
374
+ const fnSource = conf.get('functions.source', false);
375
+ if (!fnSource) {
376
+ logger_1.debug('Unable to get the functions source directory');
377
+ return;
378
+ }
379
+ const fnDir = project_1.resolveProjectPath(fnSource);
380
+ const dirContents = yield fs_1.ASYNC.walk(fnDir);
381
+ const delFnDir = yield prompt_1.default.ask(prompt_1.default.question('delDir', `All the Catalyst functions configured in the ${constants_1.FILENAME.config} file has been deleted.\n Would you like to delete the ${fnSource} directory too ?`, {
382
+ type: 'confirm',
383
+ when: () => dirContents.length > 0
384
+ }));
385
+ if (delFnDir.delDir === undefined ||
386
+ (typeof delFnDir.delDir === 'boolean' && delFnDir.delDir)) {
387
+ yield fs_1.ASYNC.deleteDir(fnDir);
388
+ }
389
+ return conf.unset('functions');
390
+ });
391
+ }
371
392
  function deleteFunctionLocal(path) {
372
393
  return __awaiter(this, void 0, void 0, function* () {
373
394
  const isDirectory = yield fs_1.ASYNC.dirExists(path);
@@ -376,7 +397,7 @@ function deleteFunctionLocal(path) {
376
397
  yield fs_1.ASYNC.deleteDir(path);
377
398
  }
378
399
  const fnTargets = conf.get('functions.targets').filter((fn) => (typeof fn === 'string' ? !path.endsWith(fn) : !path.endsWith(fn.source)));
379
- conf.set('functions.targets', fnTargets);
400
+ fnTargets.length === 0 ? yield fnDirDelete(conf) : conf.set('functions.targets', fnTargets);
380
401
  return conf.syncSave();
381
402
  });
382
403
  }
@@ -396,7 +417,7 @@ function getSDK(fnType, dest, stack, options = {}) {
396
417
  }
397
418
  yield new archiver_1.default()
398
419
  .load(sdkZip)
399
- .extract(new RegExp(`catalyst-${stack}`), dest, { isFolder: true })
420
+ .extract(dest, new RegExp(`catalyst-${stack}`), { ignoreInitial: true })
400
421
  .finalize();
401
422
  });
402
423
  }
@@ -82,7 +82,7 @@ const keyWords = [
82
82
  'volatile',
83
83
  'while'
84
84
  ];
85
- exports.classPathSep = env_1.isWindows() ? ';' : ':';
85
+ exports.classPathSep = env_1.isWindows ? ';' : ':';
86
86
  function containsKeyWord(name) {
87
87
  return keyWords.some((keyWord) => {
88
88
  if (name === keyWord ||
@@ -115,7 +115,7 @@ 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(path_1.dirname(libPth), ['**/.output']);
118
+ const files = yield fs_1.ASYNC.walk(path_1.dirname(libPth), { exclude: ['**/.output'] });
119
119
  const result = yield xml2js_1.default.parseStringPromise(content);
120
120
  const classPathEntries = js_1.JS.chain(files)
121
121
  .filter((jarPth) => path_1.extname(jarPth) === '.jar')
@@ -208,7 +208,7 @@ function compileTarget(target) {
208
208
  yield fs_1.ASYNC.ensureDir(outputFolder);
209
209
  yield fs_1.ASYNC.emptyDir(outputFolder);
210
210
  const ignore = config_1.functionsConfig.ignore(targetSource);
211
- const allFiles = yield fs_1.ASYNC.walk(targetSource, ['**/.output', ...ignore]);
211
+ const allFiles = yield fs_1.ASYNC.walk(targetSource, { exclude: ['**/.output', ...ignore] });
212
212
  const cleanUpFiles = [...allFiles];
213
213
  while (allFiles.length > 0) {
214
214
  const limit = allFiles.length < 20 ? allFiles.length : 20;
@@ -216,8 +216,7 @@ function compileTarget(target) {
216
216
  const targetPth = file.includes(path_1.sep + 'lib' + path_1.sep)
217
217
  ? file.replace(targetSource + path_1.sep + 'lib', '')
218
218
  : file.replace(targetSource, '');
219
- const target = path_1.join(outputFolder, targetPth);
220
- return fs_1.ASYNC.copyFile(file, target);
219
+ return fs_1.ASYNC.copyFile(file, path_1.join(outputFolder, targetPth));
221
220
  }));
222
221
  }
223
222
  yield Promise.all(entries.map((file) => {
@@ -234,11 +233,11 @@ function compileTarget(target) {
234
233
  }));
235
234
  const currentCommand = option_1.getCurrentCommand();
236
235
  switch (currentCommand) {
237
- case 'pull': {
236
+ case 'pull':
237
+ case 'init':
238
238
  yield cleanUp(cleanUpFiles);
239
239
  break;
240
- }
241
- case 'deploy': {
240
+ case 'deploy':
242
241
  const classPath = path_1.join(outputFolder, constants_1.FILENAME.functions.java_classpath);
243
242
  if (yield fs_1.ASYNC.fileExists(classPath)) {
244
243
  const classPathFile = yield fs_1.ASYNC.readFile(classPath);
@@ -247,7 +246,6 @@ function compileTarget(target) {
247
246
  }
248
247
  }
249
248
  break;
250
- }
251
249
  }
252
250
  });
253
251
  }
@@ -19,6 +19,7 @@ const error_1 = __importDefault(require("../../error"));
19
19
  const constants_1 = require("../../util_modules/constants");
20
20
  const fs_1 = require("../../util_modules/fs");
21
21
  const js_1 = require("../../util_modules/js");
22
+ const shell_1 = require("../../util_modules/shell");
22
23
  function validate(targets, idx) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
25
  if (targets.length < idx + 1) {
@@ -47,10 +48,15 @@ function validate(targets, idx) {
47
48
  ]
48
49
  });
49
50
  }
51
+ const nodeModuleExists = yield fs_1.ASYNC.dirExists(path_1.join(currentTarget.source, constants_1.FILENAME.node_modules));
52
+ if (!nodeModuleExists) {
53
+ yield shell_1.spawn('npm', ['install'], { cwd: currentTarget.source }).ASYNC();
54
+ }
50
55
  currentTarget.valid = true;
51
56
  return validate(targets, ++idx);
52
57
  }
53
- catch (err) {
58
+ catch (e) {
59
+ const err = error_1.default.getErrorInstance(e);
54
60
  currentTarget.valid = false;
55
61
  currentTarget.failure_reason = err.message;
56
62
  return validate(targets, ++idx);