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
@@ -46,13 +46,14 @@ exports.default = new command_1.default('apig:status')
46
46
  report = (yield api.getScheduleReport(previousOpt));
47
47
  }
48
48
  catch (e) {
49
- if (e.status && e.status === 404) {
49
+ const err = error_1.default.getErrorInstance(e);
50
+ if (err.status && err.status === 404) {
50
51
  throw new error_1.default('There is no report available.', {
51
52
  exit: 0,
52
53
  errorId: 'STAT-1'
53
54
  });
54
55
  }
55
- throw e;
56
+ throw err;
56
57
  }
57
58
  const spinner = 'API Gateway Upsert';
58
59
  const throbber = throbber_1.default.getInstance();
@@ -192,13 +193,14 @@ exports.default = new command_1.default('apig:status')
192
193
  report = (yield api.getScheduleReport(false));
193
194
  }
194
195
  catch (ex) {
195
- if (ex.status && ex.status === 404) {
196
+ const err = error_1.default.getErrorInstance(ex);
197
+ if (err.status && err.status === 404) {
196
198
  report = (yield api.getScheduleReport(true));
197
199
  }
198
200
  else {
199
201
  throbber.stopAll();
200
202
  needIteration = false;
201
- reject(ex);
203
+ reject(err);
202
204
  }
203
205
  }
204
206
  }
@@ -87,10 +87,9 @@ exports.default = new command_1.default('client:delete [client_version]')
87
87
  localDel.version = version;
88
88
  }
89
89
  catch (error) {
90
- logger_1.debug('Failed to read ' +
91
- constants_1.FILENAME.client.package_json +
92
- ' Reason: ' +
93
- error.message);
90
+ const err = error_1.default.getErrorInstance(error);
91
+ err.exit = 2;
92
+ logger_1.debug('Failed to read ' + constants_1.FILENAME.client.package_json + ' Reason: ' + err.message);
94
93
  }
95
94
  if (clientVersion !== undefined && clientVersion !== localDel.version) {
96
95
  throw new error_1.default('version unavailable in local', {
@@ -37,7 +37,7 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
37
37
  const constants_1 = require("../../util_modules/constants");
38
38
  const logger_1 = require("../../util_modules/logger");
39
39
  exports.default = new command_1.default('client:setup')
40
- .description('Set up the client directory in your project directory')
40
+ .description('Set up and configure the client directory in your project directory')
41
41
  .needs('auth', [constants_1.SCOPE.webapp])
42
42
  .needs('config')
43
43
  .needs('rc')
@@ -49,7 +49,9 @@ exports.default = new command_1.default('deploy')
49
49
  const optionFilter = yield Promise.resolve().then(() => __importStar(require('../option-filter')));
50
50
  optionFilter.filterTargets();
51
51
  yield (yield Promise.resolve().then(() => __importStar(require('../deploy')))).default();
52
- const deployTargets = runtime_store_1.default.get('payload.targets', []).filter((deploytarget) => {
52
+ const deployTargets = runtime_store_1.default
53
+ .get('payload.targets', [])
54
+ .filter((deploytarget) => {
53
55
  if (!runtime_store_1.default.get('payload.' + deploytarget + '.deploy', false)) {
54
56
  logger_1.info();
55
57
  logger_1.labeled(deploytarget, 'deploy skipped').ERROR();
@@ -69,7 +69,9 @@ exports.default = new command_1.default('ds:export [table]')
69
69
  const allGlobalOpts = runtime_store_1.default.get('opts.globalOpts', {});
70
70
  const optsArr = Object.keys(allGlobalOpts).reduce((arr, key) => {
71
71
  arr.push('--' + key);
72
- arr.push(allGlobalOpts[key]);
72
+ if (allGlobalOpts[key]) {
73
+ arr.push(allGlobalOpts[key]);
74
+ }
73
75
  return arr;
74
76
  }, (env === 'Production' ? ['--production'] : []));
75
77
  shell_1.spawn('catalyst', ['ds:status', 'export', readResponse.job_id + '', ...optsArr], {
@@ -82,7 +82,9 @@ exports.default = new command_1.default('ds:import [file]')
82
82
  const allGlobalOpts = runtime_store_1.default.get('opts.globalOpts', {});
83
83
  const optsArr = Object.keys(allGlobalOpts).reduce((arr, key) => {
84
84
  arr.push('--' + key);
85
- arr.push(allGlobalOpts[key]);
85
+ if (allGlobalOpts[key]) {
86
+ arr.push(allGlobalOpts[key]);
87
+ }
86
88
  return arr;
87
89
  }, (env === 'Production' ? ['--production'] : []));
88
90
  shell_1.spawn('catalyst', ['ds:status', 'import', writeResponse.job_id + '', ...optsArr], {
@@ -24,6 +24,149 @@ const constants_1 = require("../../util_modules/constants");
24
24
  const fs_1 = require("../../util_modules/fs");
25
25
  const logger_1 = require("../../util_modules/logger");
26
26
  const option_1 = require("../../util_modules/option");
27
+ const getSpinnerTxt = (mainTable, finalReport) => {
28
+ var _a, _b, _c, _d;
29
+ const spaceRpt = ' '.repeat(35);
30
+ let spinnerTxt = '\n' + spaceRpt;
31
+ spinnerTxt += mainTable
32
+ .toString()
33
+ .split('\n')
34
+ .join('\n' + spaceRpt);
35
+ spinnerTxt += '\n';
36
+ if (finalReport === undefined) {
37
+ return spinnerTxt;
38
+ }
39
+ if (finalReport.status === 'Completed') {
40
+ spinnerTxt += ansi_colors_1.green(((_a = finalReport.results) === null || _a === void 0 ? void 0 : _a.description) + '');
41
+ if (((_b = finalReport.results) === null || _b === void 0 ? void 0 : _b.download_url) !== undefined) {
42
+ spinnerTxt += '\n';
43
+ spinnerTxt += ansi_colors_1.bold(`Download URL : ${(_c = finalReport.results) === null || _c === void 0 ? void 0 : _c.download_url}`);
44
+ }
45
+ }
46
+ else {
47
+ spinnerTxt += ansi_colors_1.red(ansi_colors_1.bold('Reason : ') + ((_d = finalReport.results) === null || _d === void 0 ? void 0 : _d.description));
48
+ }
49
+ return spinnerTxt;
50
+ };
51
+ const spinnerFn = (jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi, displayOpr, action) => (resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
52
+ if (jobId === undefined) {
53
+ reject('Job Id cannot be empty!');
54
+ return;
55
+ }
56
+ let needIteration = true;
57
+ const reportTable = new cli_table_1.default();
58
+ Object.keys(cumulativeStatus).forEach((table) => {
59
+ const initialCount = reportTable.length;
60
+ let tableRowCount = reportTable.length;
61
+ ['insert', 'update', 'upsert', 'read'].forEach((statusAct) => {
62
+ const operationObj = cumulativeStatus[table][statusAct];
63
+ if (operationObj !== null && operationObj !== undefined) {
64
+ let operationRowCount = 0;
65
+ if (operationObj.rows_processed !== undefined &&
66
+ operationObj.rows_processed >= 0) {
67
+ reportTable[tableRowCount++] = [
68
+ 'Processed',
69
+ operationObj.rows_processed + ''
70
+ ];
71
+ operationRowCount++;
72
+ }
73
+ if (operationObj.fail_count !== undefined && operationObj.fail_count >= 0) {
74
+ reportTable[tableRowCount++] = ['Failure', operationObj.fail_count + ''];
75
+ operationRowCount++;
76
+ }
77
+ if (operationRowCount > 0) {
78
+ reportTable[tableRowCount - operationRowCount].unshift({
79
+ hAlign: 'center',
80
+ vAlign: 'center',
81
+ rowSpan: operationRowCount,
82
+ content: statusAct.toUpperCase()
83
+ });
84
+ }
85
+ }
86
+ });
87
+ if (tableRowCount > 0) {
88
+ reportTable[initialCount].unshift({
89
+ hAlign: 'center',
90
+ vAlign: 'center',
91
+ rowSpan: tableRowCount,
92
+ content: ansi_colors_1.cyan.bold(table)
93
+ });
94
+ }
95
+ });
96
+ switch (dsReport.status) {
97
+ case 'In-Progress':
98
+ if (reportTable.length === 0) {
99
+ reportTable.unshift([
100
+ { hAlign: 'center', content: ansi_colors_1.yellow.bold('Yet to start') }
101
+ ]);
102
+ }
103
+ else {
104
+ reportTable.unshift([
105
+ {
106
+ hAlign: 'center',
107
+ colSpan: 4,
108
+ content: ansi_colors_1.cyan.bold('In-Progress')
109
+ }
110
+ ]);
111
+ }
112
+ break;
113
+ case 'Completed':
114
+ reportTable.unshift([
115
+ {
116
+ hAlign: 'center',
117
+ colSpan: 4,
118
+ content: ansi_colors_1.green.bold(displayOpr + ' Job Completed')
119
+ }
120
+ ]);
121
+ dsReport = (yield bulkApi.getReport(action, jobId));
122
+ throbber.succeed(spinner, {
123
+ text: getSpinnerTxt(reportTable, dsReport)
124
+ });
125
+ needIteration = false;
126
+ resolve();
127
+ break;
128
+ case 'Failed':
129
+ reportTable.unshift([
130
+ {
131
+ hAlign: 'center',
132
+ content: ansi_colors_1.red.bold(displayOpr + ' Job Failed!')
133
+ }
134
+ ]);
135
+ dsReport = (yield bulkApi.getReport(action, jobId));
136
+ throbber.fail(spinner, {
137
+ text: getSpinnerTxt(reportTable, dsReport)
138
+ });
139
+ needIteration = false;
140
+ resolve();
141
+ break;
142
+ default:
143
+ needIteration = false;
144
+ reject(new error_1.default('unknown state received', { exit: 2 }));
145
+ break;
146
+ }
147
+ if (dsReport.status === 'In-Progress') {
148
+ throbber.update(spinner, {
149
+ text: getSpinnerTxt(reportTable) + 'Press CTRL + C to exit listening to the status'
150
+ });
151
+ try {
152
+ cumulativeStatus = (yield bulkApi.getStatus(action, jobId));
153
+ if (Object.keys(cumulativeStatus).length === 0) {
154
+ dsReport = (yield bulkApi.getReport(action, jobId));
155
+ if (dsReport.status === 'Completed') {
156
+ cumulativeStatus = (yield bulkApi.getStatus(action, jobId, true));
157
+ }
158
+ }
159
+ }
160
+ catch (ex) {
161
+ throbber.stopAll();
162
+ needIteration = false;
163
+ reject(ex);
164
+ }
165
+ }
166
+ if (needIteration) {
167
+ setTimeout(() => spinnerFn(jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi, displayOpr, action)(resolve, reject), 2000);
168
+ }
169
+ });
27
170
  exports.default = new command_1.default('ds:status <operation> [jobid]')
28
171
  .description('Display the job status of a Data Store import or export operation')
29
172
  .option('--production', 'flag for pointing to production environment.')
@@ -70,7 +213,7 @@ exports.default = new command_1.default('ds:status <operation> [jobid]')
70
213
  if (jobId === undefined) {
71
214
  throw new error_1.default('Job ID is empty!', { exit: 2 });
72
215
  }
73
- let dsReport = (yield bulkApi.getReport(action, jobId).catch((err) => {
216
+ const dsReport = (yield bulkApi.getReport(action, jobId).catch((err) => {
74
217
  if (err.status === 404) {
75
218
  throw new error_1.default('No jobs found for the given id', {
76
219
  exit: 1,
@@ -88,154 +231,7 @@ exports.default = new command_1.default('ds:status <operation> [jobid]')
88
231
  const spinner = 'DS bulk ' + operation;
89
232
  const throbber = throbber_1.default.getInstance();
90
233
  throbber.add(spinner);
91
- const getSpinnerTxt = (mainTable, finalReport) => {
92
- var _a, _b, _c, _d;
93
- const spaceRpt = ' '.repeat(35);
94
- let spinnerTxt = '\n' + spaceRpt;
95
- spinnerTxt += mainTable
96
- .toString()
97
- .split('\n')
98
- .join('\n' + spaceRpt);
99
- spinnerTxt += '\n';
100
- if (finalReport === undefined) {
101
- return spinnerTxt;
102
- }
103
- if (finalReport.status === 'Completed') {
104
- spinnerTxt += ansi_colors_1.green(((_a = finalReport.results) === null || _a === void 0 ? void 0 : _a.description) + '');
105
- if (((_b = finalReport.results) === null || _b === void 0 ? void 0 : _b.download_url) !== undefined) {
106
- spinnerTxt += '\n';
107
- spinnerTxt += ansi_colors_1.bold(`Download URL : ${(_c = finalReport.results) === null || _c === void 0 ? void 0 : _c.download_url}`);
108
- }
109
- }
110
- else {
111
- spinnerTxt += ansi_colors_1.red(ansi_colors_1.bold('Reason : ') + ((_d = finalReport.results) === null || _d === void 0 ? void 0 : _d.description));
112
- }
113
- return spinnerTxt;
114
- };
115
- const spinnerFn = (resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
116
- if (jobId === undefined) {
117
- reject('Job Id cannot be empty!');
118
- return;
119
- }
120
- let needIteration = true;
121
- const reportTable = new cli_table_1.default();
122
- Object.keys(cumulativeStatus).forEach((table) => {
123
- const initialCount = reportTable.length;
124
- let tableRowCount = reportTable.length;
125
- ['insert', 'update', 'upsert', 'read'].forEach((statusAct) => {
126
- const operationObj = cumulativeStatus[table][statusAct];
127
- if (operationObj !== null && operationObj !== undefined) {
128
- let operationRowCount = 0;
129
- if (operationObj.rows_processed !== undefined &&
130
- operationObj.rows_processed >= 0) {
131
- reportTable[tableRowCount++] = [
132
- 'Processed',
133
- operationObj.rows_processed + ''
134
- ];
135
- operationRowCount++;
136
- }
137
- if (operationObj.fail_count !== undefined && operationObj.fail_count >= 0) {
138
- reportTable[tableRowCount++] = [
139
- 'Failure',
140
- operationObj.fail_count + ''
141
- ];
142
- operationRowCount++;
143
- }
144
- if (operationRowCount > 0) {
145
- reportTable[tableRowCount - operationRowCount].unshift({
146
- hAlign: 'center',
147
- vAlign: 'center',
148
- rowSpan: operationRowCount,
149
- content: statusAct.toUpperCase()
150
- });
151
- }
152
- }
153
- });
154
- if (tableRowCount > 0) {
155
- reportTable[initialCount].unshift({
156
- hAlign: 'center',
157
- vAlign: 'center',
158
- rowSpan: tableRowCount,
159
- content: ansi_colors_1.cyan.bold(table)
160
- });
161
- }
162
- });
163
- switch (dsReport.status) {
164
- case 'In-Progress':
165
- if (reportTable.length === 0) {
166
- reportTable.unshift([
167
- { hAlign: 'center', content: ansi_colors_1.yellow.bold('Yet to start') }
168
- ]);
169
- }
170
- else {
171
- reportTable.unshift([
172
- {
173
- hAlign: 'center',
174
- colSpan: 4,
175
- content: ansi_colors_1.cyan.bold('In-Progress')
176
- }
177
- ]);
178
- }
179
- break;
180
- case 'Completed':
181
- reportTable.unshift([
182
- {
183
- hAlign: 'center',
184
- colSpan: 4,
185
- content: ansi_colors_1.green.bold(displayOpr + ' Job Completed')
186
- }
187
- ]);
188
- dsReport = (yield bulkApi.getReport(action, jobId));
189
- throbber.succeed(spinner, {
190
- text: getSpinnerTxt(reportTable, dsReport)
191
- });
192
- needIteration = false;
193
- resolve();
194
- break;
195
- case 'Failed':
196
- reportTable.unshift([
197
- {
198
- hAlign: 'center',
199
- content: ansi_colors_1.red.bold(displayOpr + ' Job Failed!')
200
- }
201
- ]);
202
- dsReport = (yield bulkApi.getReport(action, jobId));
203
- throbber.fail(spinner, {
204
- text: getSpinnerTxt(reportTable, dsReport)
205
- });
206
- needIteration = false;
207
- resolve();
208
- break;
209
- default:
210
- needIteration = false;
211
- reject(new error_1.default('unknown state received', { exit: 2 }));
212
- break;
213
- }
214
- if (dsReport.status === 'In-Progress') {
215
- throbber.update(spinner, {
216
- text: getSpinnerTxt(reportTable) +
217
- 'Press CTRL + C to exit listening to the status'
218
- });
219
- try {
220
- cumulativeStatus = (yield bulkApi.getStatus(action, jobId));
221
- if (Object.keys(cumulativeStatus).length === 0) {
222
- dsReport = (yield bulkApi.getReport(action, jobId));
223
- if (dsReport.status === 'Completed') {
224
- cumulativeStatus = (yield bulkApi.getStatus(action, jobId, true));
225
- }
226
- }
227
- }
228
- catch (ex) {
229
- throbber.stopAll();
230
- needIteration = false;
231
- reject(ex);
232
- }
233
- }
234
- if (needIteration) {
235
- setTimeout(() => spinnerFn(resolve, reject), 2000);
236
- }
237
- });
238
- yield new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () { return spinnerFn(resolve, reject); }));
234
+ yield new Promise(spinnerFn(jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi, displayOpr, action));
239
235
  if (dsReport.results && dsReport.results.download_url) {
240
236
  const ans = yield prompt_1.default.ask(prompt_1.default.question('download', 'Do you like to download the report of this job to your cmd execution directory?', { type: 'confirm', defaultAns: false }));
241
237
  if (ans.download) {
@@ -49,14 +49,8 @@ exports.default = new command_1.default('event:generate <source> <action>')
49
49
  .needs('rc')
50
50
  .needs('auth')
51
51
  .action(function generate(source, action) {
52
- var _a;
53
52
  return __awaiter(this, void 0, void 0, function* () {
54
- const args = (_a = this.client) === null || _a === void 0 ? void 0 : _a.cli.parseOptions(process.argv);
55
- let unknownArgs = args.unknown;
56
- if (unknownArgs === undefined) {
57
- logger_1.debug('No unknownArgs supplied');
58
- unknownArgs = [];
59
- }
53
+ const unknownArgs = option_1.getUnknownOpts([]);
60
54
  if (unknownArgs.length % 2 !== 0) {
61
55
  throw new error_1.default('Unknown options are not provided as key value pairs', {
62
56
  exit: 1,
@@ -89,8 +83,8 @@ exports.default = new command_1.default('event:generate <source> <action>')
89
83
  if (currentIndex % 2 === 0) {
90
84
  if (!currentValue.startsWith('--') &&
91
85
  currentValue !== '-e' &&
92
- currentValue !== '-rid') {
93
- const knownArgs = args.operands.slice(2).join(' ');
86
+ currentValue !== '-rid' &&
87
+ currentValue !== '--verbose') {
94
88
  const fault = unknownArgs === null || unknownArgs === void 0 ? void 0 : unknownArgs.map((arg) => {
95
89
  if (arg === currentValue) {
96
90
  return ansi_colors_1.red(arg);
@@ -100,10 +94,7 @@ exports.default = new command_1.default('event:generate <source> <action>')
100
94
  throw new error_1.default('Invalid option format detected', {
101
95
  exit: 1,
102
96
  errorId: 'IDX-3',
103
- arg: [
104
- ansi_colors_1.bold('[catalyst ' + knownArgs + ' ' + fault + ']'),
105
- ansi_colors_1.bold('--<option> <value>')
106
- ]
97
+ arg: [ansi_colors_1.italic(fault), ansi_colors_1.bold('--<option> <value>')]
107
98
  });
108
99
  }
109
100
  previousValue[currentValue.slice(2)] = optionArr[currentIndex + 1];
@@ -20,7 +20,7 @@ const ansi_colors_1 = require("ansi-colors");
20
20
  const prompt_1 = __importDefault(require("../../prompt"));
21
21
  const common_1 = require("../../fn-utils/lib/common");
22
22
  exports.default = new command_1.default('functions:config [function_name_or_id]')
23
- .description('Configure the memory allocation of a function in your project')
23
+ .description('Perform advanced configurations such as memory allocation on a function in your project')
24
24
  .option('--memory <value>', 'use this option to configure the memory for the function. ex: --memory 128')
25
25
  .needs('auth', [constants_1.SCOPE.functions])
26
26
  .needs('config')
@@ -37,7 +37,7 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
37
37
  const constants_1 = require("../../util_modules/constants");
38
38
  const logger_1 = require("../../util_modules/logger");
39
39
  exports.default = new command_1.default('functions:setup')
40
- .description('Set up the function directory in your project directory')
40
+ .description('Set up and configure the function directory in your project directory')
41
41
  .needs('auth', [constants_1.SCOPE.functions])
42
42
  .needs('config')
43
43
  .needs('rc')
@@ -5,33 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ansi_colors_1 = require("ansi-colors");
7
7
  const command_1 = __importDefault(require("../internal/command"));
8
- const fs_1 = require("../util_modules/fs");
9
- const constants_1 = require("../util_modules/constants");
10
8
  const logger_1 = require("../util_modules/logger");
11
- const option_1 = require("../util_modules/option");
12
- const project_1 = require("../util_modules/project");
13
9
  exports.default = new command_1.default('help [command]')
14
- .description('Display the command reference or help for a specific command')
10
+ .description('Display help information')
15
11
  .action(function help(commandName) {
16
12
  var _a, _b, _c;
17
- if (option_1.getOptionValue('info', false)) {
18
- const helpPth = project_1.resolveProjectPath(constants_1.FILENAME.command_log);
19
- const rawHelp = fs_1.SYNC.readFile(helpPth);
20
- if (rawHelp === undefined) {
21
- logger_1.info('No recent logs');
22
- return;
23
- }
24
- const logHelp = JSON.parse(rawHelp);
25
- const helpMsg = ansi_colors_1.bold('\nCOMMAND : ') +
26
- logHelp.command +
27
- ansi_colors_1.bold('\nEXECUTION : ') +
28
- logHelp.status +
29
- '\n' +
30
- (logHelp.help !== undefined ? '\n' + logHelp.help.join('\n') : '');
31
- logger_1.info(helpMsg);
32
- logger_1.info(`If you couldn't find the needed help here, feel free to reach us through ${ansi_colors_1.bold.underline('support@zohocatalyst.com')}`);
33
- return;
34
- }
35
13
  if (commandName === undefined) {
36
14
  (_a = this.client) === null || _a === void 0 ? void 0 : _a.cli.outputHelp();
37
15
  logger_1.info();
@@ -0,0 +1,85 @@
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 endpoints_1 = require("../../endpoints");
16
+ const iac_1 = __importDefault(require("../../endpoints/lib/iac"));
17
+ const error_1 = __importDefault(require("../../error"));
18
+ const command_1 = __importDefault(require("../../internal/command"));
19
+ const prompt_1 = __importDefault(require("../../prompt"));
20
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
21
+ const constants_1 = require("../../util_modules/constants");
22
+ const env_1 = require("../../util_modules/env");
23
+ const logger_1 = require("../../util_modules/logger");
24
+ const option_1 = require("../../util_modules/option");
25
+ const project_1 = require("../../util_modules/project");
26
+ const shell_1 = require("../../util_modules/shell");
27
+ const getExportProjectId = () => __awaiter(void 0, void 0, void 0, function* () {
28
+ const projectId = project_1.getProjectId(null);
29
+ if (projectId !== null) {
30
+ return projectId;
31
+ }
32
+ const allProjects = (yield (yield endpoints_1.projectAPI()).getAllProjects());
33
+ if (allProjects.length === 0) {
34
+ throw new error_1.default('No projects found', {
35
+ exit: 0,
36
+ errorId: 'PROJ-USE-1'
37
+ });
38
+ }
39
+ if (allProjects.length === 1) {
40
+ logger_1.message('only one project found in remote, using that');
41
+ return allProjects[0].id;
42
+ }
43
+ const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Which project do you wish to export ? ', {
44
+ type: 'list',
45
+ choices: allProjects.map((project) => {
46
+ return prompt_1.default.choice(project.project_name, {
47
+ value: project.id,
48
+ short: project.project_name
49
+ });
50
+ })
51
+ }));
52
+ return projectAns.project;
53
+ });
54
+ exports.default = new command_1.default('iac:export')
55
+ .description('Create a zip file out of existing project in console')
56
+ .option('--production', 'flag for pointing to production environment')
57
+ .needs('auth', [constants_1.SCOPE.project_export_read, constants_1.SCOPE.project_export_create])
58
+ .needs('config', { optional: true })
59
+ .needs('rc', { optional: true })
60
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
61
+ const env = option_1.getOptionValue('production', false) ? 'Production' : 'Development';
62
+ const projectId = yield getExportProjectId();
63
+ const bundleResp = yield new iac_1.default(projectId, { env }).bundle(constants_1.IAC.template_format.json);
64
+ logger_1.info();
65
+ logger_1.success(`Successfully scheduled export job for project "${project_1.getProjectName(projectId)}" with jobid "${bundleResp.id}"`);
66
+ if (env_1.isPrimaryShell()) {
67
+ const exitListeners = process.listeners('exit');
68
+ process.removeAllListeners('exit');
69
+ const allGlobalOpts = runtime_store_1.default.get('opts.globalOpts', {});
70
+ const optsArr = Object.keys(allGlobalOpts).reduce((arr, key) => {
71
+ arr.push('--' + key);
72
+ if (allGlobalOpts[key]) {
73
+ arr.push(allGlobalOpts[key]);
74
+ }
75
+ return arr;
76
+ }, (env === 'Production' ? ['--production'] : []));
77
+ shell_1.spawn('catalyst', ['iac:status', 'export', ...optsArr], {
78
+ shell: true,
79
+ stdio: 'inherit'
80
+ }).SYNC();
81
+ (exitListeners || []).forEach((listner) => {
82
+ process.addListener('exit', listner);
83
+ });
84
+ }
85
+ }));