zcatalyst-cli 1.9.0 → 1.11.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 (190) hide show
  1. package/README.md +29 -29
  2. package/docs/client-utils.toml +5 -0
  3. package/docs/command_needs/auth.toml +5 -0
  4. package/docs/commands/iac/export.toml +4 -0
  5. package/docs/commands/iac/import.toml +4 -0
  6. package/docs/commands/iac/status.toml +4 -0
  7. package/docs/commands/project/use.toml +6 -0
  8. package/docs/iac/status/bundle.toml +4 -0
  9. package/docs/plugin-loader.toml +4 -0
  10. package/docs/serve/server/index.toml +4 -0
  11. package/docs/serve/server/lib/web_client/server.toml +4 -0
  12. package/lib/api-timer.js +81 -0
  13. package/lib/apig-utils.js +17 -14
  14. package/lib/archiver.js +83 -45
  15. package/lib/authentication/login.js +4 -2
  16. package/lib/bin/catalyst.js +0 -1
  17. package/lib/client-utils.js +55 -26
  18. package/lib/client.js +0 -3
  19. package/lib/command_needs/auth.js +12 -3
  20. package/lib/command_needs/rc.js +12 -7
  21. package/lib/commands/apig/disable.js +1 -1
  22. package/lib/commands/apig/enable.js +1 -1
  23. package/lib/commands/apig/status.js +7 -5
  24. package/lib/commands/client/delete.js +4 -5
  25. package/lib/commands/client/setup.js +1 -1
  26. package/lib/commands/deploy.js +4 -2
  27. package/lib/commands/ds/export.js +4 -2
  28. package/lib/commands/ds/import.js +4 -2
  29. package/lib/commands/ds/status.js +146 -150
  30. package/lib/commands/event/generate/index.js +5 -14
  31. package/lib/commands/event/generate/integ.js +1 -1
  32. package/lib/commands/functions/add.js +1 -1
  33. package/lib/commands/functions/config.js +1 -1
  34. package/lib/commands/functions/delete.js +1 -1
  35. package/lib/commands/functions/setup.js +1 -1
  36. package/lib/commands/functions/shell.js +1 -1
  37. package/lib/commands/help.js +0 -22
  38. package/lib/commands/iac/export.js +85 -0
  39. package/lib/commands/iac/import.js +189 -0
  40. package/lib/commands/iac/pack.js +129 -0
  41. package/lib/commands/iac/status.js +63 -0
  42. package/lib/commands/index.js +4 -0
  43. package/lib/commands/init.js +35 -28
  44. package/lib/commands/login.js +1 -1
  45. package/lib/commands/logout.js +1 -1
  46. package/lib/commands/project/list.js +11 -7
  47. package/lib/commands/project/reset.js +1 -1
  48. package/lib/commands/project/use.js +42 -25
  49. package/lib/commands/pull.js +2 -2
  50. package/lib/commands/run.js +1 -1
  51. package/lib/commands/serve.js +3 -2
  52. package/lib/commands/token/generate.js +1 -1
  53. package/lib/commands/token/list.js +1 -1
  54. package/lib/commands/token/revoke.js +1 -1
  55. package/lib/commands/whoami.js +1 -1
  56. package/lib/deploy/features/functions/index.js +2 -1
  57. package/lib/deploy/index.js +3 -1
  58. package/lib/endpoints/lib/iac.js +134 -0
  59. package/lib/error.js +33 -3
  60. package/lib/errorOut.js +4 -3
  61. package/lib/fn-utils/lib/common.js +37 -16
  62. package/lib/fn-utils/lib/java.js +7 -9
  63. package/lib/fn-utils/lib/node.js +7 -1
  64. package/lib/iac/status/bundle.js +82 -0
  65. package/lib/iac/status/deploy.js +74 -0
  66. package/lib/iac/status/util/index.js +26 -0
  67. package/lib/index.js +13 -19
  68. package/lib/init/dependencies/npm-install.js +2 -9
  69. package/lib/init/features/client/index.js +47 -0
  70. package/lib/init/features/client/initializers/angular.js +88 -0
  71. package/lib/init/features/client/initializers/basic.js +27 -0
  72. package/lib/init/features/client/initializers/lyte.js +44 -0
  73. package/lib/init/features/client/initializers/react.js +53 -0
  74. package/lib/init/features/functions/languages/java.js +2 -5
  75. package/lib/init/features/functions/languages/node.js +5 -6
  76. package/lib/init/features/index.js +18 -6
  77. package/lib/init/features/project.js +72 -34
  78. package/lib/init/util/client.js +12 -0
  79. package/lib/init/util/functions.js +20 -0
  80. package/lib/init/util/project.js +35 -0
  81. package/lib/internal/api.js +6 -9
  82. package/lib/internal/command.js +6 -3
  83. package/lib/internal/config.js +7 -4
  84. package/lib/migration/index.js +10 -6
  85. package/lib/option-filter.js +4 -1
  86. package/lib/optional-import.js +11 -25
  87. package/lib/plugin-loader.js +8 -2
  88. package/lib/port-resolver.js +20 -16
  89. package/lib/prompt/index.js +92 -0
  90. package/lib/prompt/types/file-path.js +95 -0
  91. package/lib/pull/features/client.js +1 -1
  92. package/lib/pull/features/functions/index.js +5 -7
  93. package/lib/pull/index.js +4 -1
  94. package/lib/serve/features/index.js +3 -1
  95. package/lib/serve/index.js +6 -1
  96. package/lib/serve/server/index.js +74 -29
  97. package/lib/serve/server/lib/master.js +28 -12
  98. package/lib/serve/server/lib/web_client/index.js +30 -0
  99. package/lib/serve/server/lib/web_client/server.js +171 -0
  100. package/lib/serve/server/lib/web_client/utils.js +10 -0
  101. package/lib/shell/dependencies/http-functions.js +1 -1
  102. package/lib/shell/index.js +3 -1
  103. package/lib/track.js +3 -1
  104. package/lib/util_modules/char.js +1 -1
  105. package/lib/util_modules/config/lib/apig.js +2 -1
  106. package/lib/util_modules/constants/index.js +5 -1
  107. package/lib/util_modules/constants/lib/file-names.js +2 -1
  108. package/lib/util_modules/constants/lib/iac.js +8 -0
  109. package/lib/util_modules/constants/lib/placeholders.js +3 -1
  110. package/lib/util_modules/constants/lib/plugin.js +28 -0
  111. package/lib/util_modules/constants/lib/regex.js +2 -1
  112. package/lib/util_modules/constants/lib/scopes.js +5 -0
  113. package/lib/util_modules/constants/lib/template.js +11 -1
  114. package/lib/util_modules/constants/lib/urls.js +8 -0
  115. package/lib/util_modules/constants/project.js +6 -0
  116. package/lib/util_modules/{contextHelp.js → context-help.js} +5 -1
  117. package/lib/util_modules/env.js +14 -16
  118. package/lib/util_modules/fs/index.js +9 -1
  119. package/lib/util_modules/fs/lib/async.js +29 -22
  120. package/lib/util_modules/global-space.js +99 -0
  121. package/lib/util_modules/js.js +6 -0
  122. package/lib/util_modules/option.js +5 -1
  123. package/lib/util_modules/parser/toml.js +5 -1
  124. package/lib/util_modules/project.js +3 -0
  125. package/lib/util_modules/shell.js +9 -8
  126. package/lib/winston.js +1 -1
  127. package/package.json +11 -5
  128. package/templates/iacSuccess.html +391 -0
  129. package/templates/init/.DS_Store +0 -0
  130. package/templates/init/client/.DS_Store +0 -0
  131. package/templates/init/client/{client-package.json → basic/client-package.json} +0 -0
  132. package/templates/init/client/{index.html → basic/index.html} +0 -0
  133. package/templates/init/client/{main.css → basic/main.css} +0 -0
  134. package/templates/init/client/{main.js → basic/main.js} +0 -0
  135. package/templates/init/client/lyte/build/build.js +301 -0
  136. package/templates/init/client/lyte/build/scripts/cliDownloadScript.js +54 -0
  137. package/templates/init/client/lyte/client-package.json +5 -0
  138. package/templates/init/client/lyte/components/javascript/welcome-comp.js +13 -0
  139. package/templates/init/client/lyte/components/styles/welcome-comp.css +0 -0
  140. package/templates/init/client/lyte/components/templates/welcome-comp.html +8 -0
  141. package/templates/init/client/lyte/data-store/adapters/.gitkeep +0 -0
  142. package/templates/init/client/lyte/data-store/models/.gitkeep +0 -0
  143. package/templates/init/client/lyte/data-store/serializers/.gitkeep +0 -0
  144. package/templates/init/client/lyte/index.html +17 -0
  145. package/templates/init/client/lyte/package.json +12 -0
  146. package/templates/init/client/lyte/router.js +14 -0
  147. package/templates/init/client/lyte/routes/index.js +54 -0
  148. package/templates/init/client/react/.DS_Store +0 -0
  149. package/templates/init/client/react/react_js/package.json +11 -0
  150. package/templates/init/client/react/react_js/template/README.md +70 -0
  151. package/templates/init/client/react/react_js/template/client-package.json +5 -0
  152. package/templates/init/client/react/react_js/template/gitignore +23 -0
  153. package/templates/init/client/react/react_js/template/public/favicon.ico +0 -0
  154. package/templates/init/client/react/react_js/template/public/index.html +43 -0
  155. package/templates/init/client/react/react_js/template/public/logo192.png +0 -0
  156. package/templates/init/client/react/react_js/template/public/logo512.png +0 -0
  157. package/templates/init/client/react/react_js/template/public/manifest.json +25 -0
  158. package/templates/init/client/react/react_js/template/public/robots.txt +3 -0
  159. package/templates/init/client/react/react_js/template/src/App.css +38 -0
  160. package/templates/init/client/react/react_js/template/src/App.js +25 -0
  161. package/templates/init/client/react/react_js/template/src/App.test.js +8 -0
  162. package/templates/init/client/react/react_js/template/src/index.css +13 -0
  163. package/templates/init/client/react/react_js/template/src/index.js +17 -0
  164. package/templates/init/client/react/react_js/template/src/logo.svg +1 -0
  165. package/templates/init/client/react/react_js/template/src/reportWebVitals.js +13 -0
  166. package/templates/init/client/react/react_js/template/src/setupTests.js +5 -0
  167. package/templates/init/client/react/react_js/template.json +13 -0
  168. package/templates/init/client/react/react_ts/package.json +11 -0
  169. package/templates/init/client/react/react_ts/template/README.md +46 -0
  170. package/templates/init/client/react/react_ts/template/client-package.json +5 -0
  171. package/templates/init/client/react/react_ts/template/gitignore +23 -0
  172. package/templates/init/client/react/react_ts/template/public/favicon.ico +0 -0
  173. package/templates/init/client/react/react_ts/template/public/index.html +43 -0
  174. package/templates/init/client/react/react_ts/template/public/logo192.png +0 -0
  175. package/templates/init/client/react/react_ts/template/public/logo512.png +0 -0
  176. package/templates/init/client/react/react_ts/template/public/manifest.json +25 -0
  177. package/templates/init/client/react/react_ts/template/public/robots.txt +3 -0
  178. package/templates/init/client/react/react_ts/template/src/App.css +38 -0
  179. package/templates/init/client/react/react_ts/template/src/App.test.tsx +9 -0
  180. package/templates/init/client/react/react_ts/template/src/App.tsx +26 -0
  181. package/templates/init/client/react/react_ts/template/src/index.css +13 -0
  182. package/templates/init/client/react/react_ts/template/src/index.tsx +17 -0
  183. package/templates/init/client/react/react_ts/template/src/logo.svg +1 -0
  184. package/templates/init/client/react/react_ts/template/src/reportWebVitals.ts +15 -0
  185. package/templates/init/client/react/react_ts/template/src/setupTests.ts +5 -0
  186. package/templates/init/client/react/react_ts/template.json +18 -0
  187. package/templates/web-socket.txt +21 -0
  188. package/lib/init/features/client.js +0 -51
  189. package/lib/prompt.js +0 -49
  190. package/lib/serve/server/lib/client.js +0 -30
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../internal/command"));
35
35
  exports.default = new command_1.default('logout')
36
- .description('Log the CLI out of your Zoho Catalyst account')
36
+ .description('Log the CLI out of your Catalyst account')
37
37
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
38
38
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication')));
39
39
  return auth.logout();
@@ -35,10 +35,11 @@ const ansi_colors_1 = require("ansi-colors");
35
35
  const endpoints_1 = require("../../endpoints");
36
36
  const command_1 = __importDefault(require("../../internal/command"));
37
37
  const constants_1 = require("../../util_modules/constants");
38
+ const project_1 = __importDefault(require("../../util_modules/constants/project"));
38
39
  const logger_1 = require("../../util_modules/logger");
39
- const project_1 = require("../../util_modules/project");
40
+ const project_2 = require("../../util_modules/project");
40
41
  exports.default = new command_1.default('project:list')
41
- .description('List the Catalyst projects you have access to')
42
+ .description('List all the Catalyst projects you have access to')
42
43
  .needs('auth', [constants_1.SCOPE.projects])
43
44
  .needs('config', { optional: true, resolveOnNotFound: true })
44
45
  .needs('rc', { optional: true })
@@ -55,19 +56,22 @@ exports.default = new command_1.default('project:list')
55
56
  { hAlign: 'center', content: ansi_colors_1.red.bold('Project Name') },
56
57
  { hAlign: 'center', content: ansi_colors_1.red.bold('Project ID') }
57
58
  ]);
58
- const activeProjectId = project_1.getProjectId(null);
59
- const defaultProjectId = project_1.getDefaultProjectId(null);
59
+ const activeProjectId = project_2.getProjectId(null);
60
+ const defaultProjectId = project_2.getDefaultProjectId(null);
60
61
  projects.forEach((project) => {
61
62
  let displayId = project.id + '';
62
63
  let displayName = project.project_name;
63
- let enhance = null;
64
+ let enhance = '';
64
65
  if (activeProjectId === displayId) {
65
66
  enhance = ' (active)';
66
67
  }
67
68
  if (defaultProjectId === displayId) {
68
- enhance = enhance === null ? ' (base)' : enhance + ' (base)';
69
+ enhance += ' (base)';
69
70
  }
70
- if (enhance !== null) {
71
+ if (project.project_type && !project_1.default.accepted_types.includes(project.project_type)) {
72
+ enhance += `(${project.project_type})`;
73
+ }
74
+ if (enhance !== '') {
71
75
  displayName = ansi_colors_1.cyan(displayName + enhance);
72
76
  displayId = ansi_colors_1.cyan(displayId + '');
73
77
  }
@@ -17,7 +17,7 @@ const constants_1 = require("../../util_modules/constants");
17
17
  const logger_1 = require("../../util_modules/logger");
18
18
  const project_1 = require("../../util_modules/project");
19
19
  exports.default = new command_1.default('project:reset')
20
- .description('Clear an active selection of project and reset to base project')
20
+ .description('Clear an active project selection and reset to the base project')
21
21
  .needs('auth', [constants_1.SCOPE.projects])
22
22
  .needs('config', { optional: true, resolveOnNotFound: true })
23
23
  .needs('rc')
@@ -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
  }));
@@ -42,7 +42,7 @@ const fs_1 = require("../util_modules/fs");
42
42
  const js_1 = require("../util_modules/js");
43
43
  const logger_1 = require("../util_modules/logger");
44
44
  exports.default = new command_1.default('pull [feature]')
45
- .description('Pull an existing project from Catalyst')
45
+ .description('Pull resources of your project from the remote console to the local directory')
46
46
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.webapp])
47
47
  .needs('config', { optional: true })
48
48
  .needs('rc')
@@ -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
  }))
@@ -38,7 +38,7 @@ const constants_1 = require("../util_modules/constants");
38
38
  const logger_1 = require("../util_modules/logger");
39
39
  exports.default = new command_1.default('run-script [command]')
40
40
  .alias('run')
41
- .description('run a particular command script')
41
+ .description('Run a particular command script defined in catalyst.json')
42
42
  .needs('auth')
43
43
  .needs('config')
44
44
  .needs('rc', { optional: true, resolveOnNotFound: true })
@@ -34,16 +34,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../internal/command"));
35
35
  const constants_1 = require("../util_modules/constants");
36
36
  exports.default = new command_1.default('serve')
37
- .description('Serve your code for local testing without affecting the production')
37
+ .description('Serve Basic I/O and Advanced I/O functions, and the client, to test them locally')
38
38
  .option('--http <port>', 'start the server at specified port ')
39
39
  .option('--debug <type:port>', 'the functions are invoked from local environment enabling debugging options on provided ports ' +
40
40
  `(example: advancedio:<name>:${constants_1.DEFAULT.serve_port.debug.advancedio},basicio:${constants_1.DEFAULT.serve_port.debug.basicio})`)
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')
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../../internal/command"));
35
35
  const logger_1 = require("../../util_modules/logger");
36
36
  exports.default = new command_1.default('token:generate')
37
- .description('Create a CLI token in order to use in CI systems')
37
+ .description('Generate a token to authenticate accessing the CLI from a remote system')
38
38
  .option('--current', 'prints out the existing token used by this CLI')
39
39
  .needs('auth')
40
40
  .ignore(['token'])
@@ -35,7 +35,7 @@ const ansi_colors_1 = require("ansi-colors");
35
35
  const command_1 = __importDefault(require("../../internal/command"));
36
36
  const logger_1 = require("../../util_modules/logger");
37
37
  exports.default = new command_1.default('token:list')
38
- .description('List all the available tokens created from this cli')
38
+ .description('List all the available tokens generated in this CLI')
39
39
  .ignore(['token'])
40
40
  .needs('auth')
41
41
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../../internal/command"));
35
35
  const logger_1 = require("../../util_modules/logger");
36
36
  exports.default = new command_1.default('token:revoke <id>')
37
- .description('Revoke the token created from this CLI')
37
+ .description('Revoke a token generated in this CLI')
38
38
  .needs('auth')
39
39
  .ignore(['token'])
40
40
  .action((input) => __awaiter(void 0, void 0, void 0, function* () {
@@ -18,7 +18,7 @@ const dc_1 = require("../dc");
18
18
  const command_1 = __importDefault(require("../internal/command"));
19
19
  const logger_1 = require("../util_modules/logger");
20
20
  exports.default = new command_1.default('whoami')
21
- .description('prints out the current logged in user email id')
21
+ .description('Print the email address of the user currently logged in')
22
22
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
23
23
  const activeDC = dc_1.getActiveDC();
24
24
  const user = config_store_1.default.get(`${activeDC}.user`);
@@ -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;
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
  }