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
package/README.md CHANGED
@@ -86,12 +86,12 @@ Command | Description
86
86
  **ds:import** | Bulk write records to a table in the Catalyst Data Store.
87
87
  **ds:export** | Bulk read records from a table in the Catalyst Data Store.
88
88
  **ds:status** | Display the job status of a Data Store import or export operation.
89
- **client:setup** | Set up the client directory in your project directory.
89
+ **client:setup** | Set up and configure the client directory in your project directory.
90
90
  **client:delete** | Delete a version of the client from the remote console or the local directory.
91
- **functions:setup** | Set up the function directory in your project directory.
91
+ **functions:setup** | Set up and configure the function directory in your project directory.
92
92
  **functions:add** | Add a function of the required stack to the function directory.
93
93
  **functions:shell** | Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions.
94
- **functions:config** | Configure the memory allocation of a function in your project.
94
+ **functions:config** | Perform advanced configurations such as memory allocation on a function in your project.
95
95
  **functions:delete** | Delete a function from the remote console or the local directory.
96
96
  **event:generate \| generate:event** | Generate sample payloads from different components or custom event sources to test Event functions.
97
97
  **event:generate:integ** | Generate sample payloads for the required integration service to test Integration functions.
package/docs/.DS_Store ADDED
Binary file
@@ -22,3 +22,8 @@ link = 'https://www.zoho.com/catalyst/help/project-directory-structure.html#Clie
22
22
  context = '''Error when ${arg[0]} the Client with the ${arg[1]} plugin.'''
23
23
  aid = '''Please rectify the below error to continue. \n${arg[2]}'''
24
24
  link = ''
25
+
26
+ [CLIENT-UTILS-6]
27
+ context = '''Client Setup Skipped: Since the consent to overwrite the existing directory was not given.'''
28
+ aid = '''Existing directory: ${arg[0]}'''
29
+ link = ''
@@ -2,3 +2,8 @@
2
2
  context = '''Oops! It looks like you haven't logged in yet'''
3
3
  aid = '''Please use the ${arg[0]} command to log in, or provide auth token via ${arg[1]} param'''
4
4
  link = 'https://www.zoho.com/catalyst/help/cli-login.html'
5
+
6
+ [AUTH-2]
7
+ context = '''Oops! It looks like there is a scope missing for running this command'''
8
+ aid = '''Please use the ${arg[0]} command to re-login'''
9
+ link = 'https://www.zoho.com/catalyst/help/cli-login.html'
@@ -0,0 +1,4 @@
1
+ [PROJ-USE-1]
2
+ context = '''Oops! It looks like you haven't created your first Catalyst project yet'''
3
+ aid = '''Please visit the below link to get started with your first catalyst project'''
4
+ link = 'https://www.zoho.com/catalyst/help/catalyst-console.html#Projects'
@@ -0,0 +1,4 @@
1
+ [I-1]
2
+ context = '''No project template found in the zip provided.'''
3
+ aid = '''Project template should be placed at the root level of the zip.'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html'
@@ -0,0 +1,4 @@
1
+ [S-1]
2
+ context = '''The operation "${arg[0]}" provided by you is not supported.'''
3
+ aid = '''Supported operations are "import" and "export". Usage Example: "catalyst iac:status import"'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html'
@@ -7,3 +7,9 @@ link = 'https://www.zoho.com/catalyst/help/catalyst-console.html#Projects'
7
7
  context = '''The project ${arg[0]} does not exist in the Catalyst remote console.'''
8
8
  aid = '''Please specify only the projects from this list : \n${arg[1]}'''
9
9
  link = 'https://www.zoho.com/catalyst/help/cli-projects.html#Use'
10
+
11
+ [PROJ-USE-3]
12
+ context = '''The project ${arg[0]} is not live and is possibily still in import phase.'''
13
+ aid = '''Please specify only the projects from this list : \n${arg[1]}'''
14
+ link = 'https://www.zoho.com/catalyst/help/cli-projects.html#Use'
15
+
@@ -0,0 +1,4 @@
1
+ [B-1]
2
+ context = '''No export project available in server.'''
3
+ aid = '''To start exporting a project use "catalyst iac:export"'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html'
@@ -0,0 +1,4 @@
1
+ [PLG-LDR-1]
2
+ context = '''The ${arg[0]} plugin configured to ${arg[1]} the ${arg[2]} is not found.'''
3
+ aid = '''Please install the ${arg[0]} plugin either locally or globally to ${arg[1]} the ${arg[2]}.'''
4
+ link = ''
@@ -0,0 +1,4 @@
1
+ [SERVE-IDX-1]
2
+ context = '''Error when serving the ${arg[0]} with the ${arg[1]} plugin.'''
3
+ aid = '''Please rectify the below error to serve the ${arg[0]}: \n${arg[2]}'''
4
+ link = ''
@@ -0,0 +1,4 @@
1
+ [WEB-CLIENT-SERVER-1]
2
+ context = '''The file provided as homepage(${arg[0]}) for the web-client is not found inside the client source directory.'''
3
+ aid = '''Please provide a valid file as the web-client homepage'''
4
+ link = ''
@@ -0,0 +1,81 @@
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 events_1 = __importDefault(require("events"));
16
+ const error_1 = __importDefault(require("./error"));
17
+ class APITimer extends events_1.default {
18
+ constructor(apiFn, frequency, errorTolerance) {
19
+ super();
20
+ this.apiFn = apiFn;
21
+ this.frequency = frequency || 5000;
22
+ this.interval = null;
23
+ this.execCount = 0;
24
+ this.maxErrors = errorTolerance || 10;
25
+ this.errorCount = 0;
26
+ this.ended = false;
27
+ }
28
+ emit(eventName, ...args) {
29
+ if (this.ended || this.listenerCount(eventName) <= 0) {
30
+ return false;
31
+ }
32
+ return super.emit(eventName, ...args);
33
+ }
34
+ waitForEnd() {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return new Promise((res, rej) => {
37
+ this.on('end', (e, data) => {
38
+ if (e) {
39
+ rej(e);
40
+ return;
41
+ }
42
+ res(data);
43
+ });
44
+ });
45
+ });
46
+ }
47
+ fire() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (this.ended) {
50
+ this.end();
51
+ }
52
+ try {
53
+ const data = yield this.apiFn();
54
+ this.emit('data', data, ++this.execCount);
55
+ }
56
+ catch (e) {
57
+ this.emit('error', e, ++this.errorCount);
58
+ const err = error_1.default.getErrorInstance(e);
59
+ if (this.errorCount >= this.maxErrors) {
60
+ this.end(err);
61
+ }
62
+ }
63
+ });
64
+ }
65
+ start() {
66
+ this.fire();
67
+ this.interval = setInterval(this.fire.bind(this), this.frequency);
68
+ return this;
69
+ }
70
+ end(e, data) {
71
+ if (this.interval) {
72
+ clearInterval(this.interval);
73
+ this.execCount = 0;
74
+ this.errorCount = 0;
75
+ this.interval = null;
76
+ }
77
+ this.emit('end', e, data);
78
+ this.ended = true;
79
+ }
80
+ }
81
+ exports.default = APITimer;
package/lib/apig-utils.js CHANGED
@@ -25,6 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.apigUtils = void 0;
27
27
  const ansi_colors_1 = require("ansi-colors");
28
+ const util_1 = require("util");
28
29
  const client_utils_1 = require("./client-utils");
29
30
  const error_1 = __importDefault(require("./error"));
30
31
  const execute_script_1 = __importDefault(require("./execute-script"));
@@ -64,14 +65,14 @@ exports.apigUtils = {
64
65
  yield client_utils_1.clientUtils.validate();
65
66
  const homepage = runtime_store_1.default.get('context.client.homepage', 'index.html');
66
67
  const loginRedirect = runtime_store_1.default.get('context.client.login_redirect', homepage);
67
- if (loginRedirect) {
68
+ if (typeof loginRedirect === 'string') {
68
69
  redirectPath = loginRedirect.startsWith('/')
69
70
  ? loginRedirect
70
71
  : '/app/' + loginRedirect;
71
72
  }
72
73
  }
73
74
  catch (e) {
74
- logger_1.debug(e.message);
75
+ logger_1.debug(error_1.default.getErrorInstance(e).message);
75
76
  }
76
77
  let redirectIdx = -1;
77
78
  const namesArr = [];
@@ -197,19 +198,21 @@ exports.apigUtils = {
197
198
  rule.name, new RegExp(regexParts[1]);
198
199
  }
199
200
  catch (regexError) {
200
- throw new error_1.default('source_endpoint provided for apig rule "' +
201
- rule.name +
202
- '" is not valid', {
203
- exit: 1,
204
- original: regexError,
205
- errorId: 'APIG-UTILS-9',
206
- arg: [
207
- ansi_colors_1.bold('source_endpoint'),
208
- ansi_colors_1.bold(rule.name),
209
- ansi_colors_1.italic(source_endpoint.replace(part, ansi_colors_1.red(part))),
210
- ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(regexError)
211
- ]
201
+ const err = error_1.default.getErrorInstance(regexError, {
202
+ message: 'source_endpoint provided for apig rule "' +
203
+ rule.name +
204
+ '" is not valid',
205
+ skipHelp: false,
206
+ fileName: __filename
212
207
  });
208
+ err.errorId = 'APIG-UTILS-9';
209
+ err.arg = [
210
+ ansi_colors_1.bold('source_endpoint'),
211
+ ansi_colors_1.bold(rule.name),
212
+ ansi_colors_1.italic(source_endpoint.replace(part, ansi_colors_1.red(part))),
213
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(util_1.inspect(regexError))
214
+ ];
215
+ throw err;
213
216
  }
214
217
  if (regexParts[1].includes('^') || regexParts[1].includes('$')) {
215
218
  throw new error_1.default('source_endpoint provided for apig rule "' +
package/lib/archiver.js CHANGED
@@ -43,27 +43,38 @@ class Archiver {
43
43
  this.promiseArr = [];
44
44
  }
45
45
  load(content, { createFolders = true } = {}) {
46
- if (Buffer.isBuffer(content) || js_1.JS.isString(content)) {
47
- this.content = content;
48
- }
49
- else {
46
+ if (!Buffer.isBuffer(content) && !js_1.JS.isString(content)) {
50
47
  throw new error_1.default('Unable to parse zip content, content should be either a string or buffer', { exit: 2 });
51
48
  }
49
+ this.content = content;
52
50
  this.jszip = jszip_1.loadAsync(content, { createFolders });
53
51
  return this;
54
52
  }
55
- _writeFolder(folder, to) {
53
+ _writeFolder(folder, to, recursive = false, ignoreInitial = false) {
56
54
  return __awaiter(this, void 0, void 0, function* () {
57
- const allFilePromise = [];
58
- folder.forEach((relPath, file) => {
59
- if (!file.dir) {
60
- const relDir = path_1.dirname(relPath);
61
- allFilePromise.push(fs_1.ASYNC.ensureDir(path_1.join(to, relDir)).then(() => {
62
- return this._writeFile(file, path_1.join(to, relDir));
63
- }));
64
- }
65
- });
66
- return Promise.all(allFilePromise);
55
+ return this._writeAllFile(folder.filter((_relPath, file) => !file.dir), to, recursive, ignoreInitial);
56
+ });
57
+ }
58
+ _writeAllFile(files, to, recursive = false, ignoreInitial = false) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ while (files.length > 0) {
61
+ const limit = files.length < Archiver.maxWriteLimit ? files.length : Archiver.maxWriteLimit;
62
+ yield Promise.all(files.splice(0, limit).map((file) => __awaiter(this, void 0, void 0, function* () {
63
+ const filePath = path_1.join(to, path_1.dirname(ignoreInitial ? file.name.substr(file.name.indexOf('/') + 1) : file.name));
64
+ yield fs_1.ASYNC.ensureDir(filePath);
65
+ if (file.name.endsWith('.zip') && recursive) {
66
+ const zipContent = yield file.async('nodebuffer');
67
+ return new Archiver()
68
+ .load(zipContent)
69
+ .extract(path_1.join(filePath, path_1.basename(file.name).replace('.zip', '')), '/', {
70
+ recursive,
71
+ ignoreInitial
72
+ })
73
+ .finalize();
74
+ }
75
+ return this._writeFile(file, filePath);
76
+ })));
77
+ }
67
78
  });
68
79
  }
69
80
  _writeFile(file, to) {
@@ -76,35 +87,51 @@ class Archiver {
76
87
  });
77
88
  });
78
89
  }
79
- extract(from, to, { isFolder = false }) {
80
- this.promiseArr.push(this.jszip.then((zip) => __awaiter(this, void 0, void 0, function* () {
90
+ readFile(relPath) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const actualZip = yield this.jszip;
93
+ const fileObjArr = [];
94
+ if (typeof relPath === 'string') {
95
+ const fileObj = actualZip.file(relPath);
96
+ if (fileObj) {
97
+ fileObjArr.push(fileObj);
98
+ }
99
+ }
100
+ else {
101
+ fileObjArr.push(...actualZip.file(relPath));
102
+ }
103
+ if (fileObjArr.length === 0) {
104
+ return;
105
+ }
106
+ return fileObjArr[0].async('string');
107
+ });
108
+ }
109
+ extract(to, from = '/', { isFolder = true, recursive = false, ignoreInitial = false } = {}) {
110
+ const extractPromise = this.jszip.then((zip) => __awaiter(this, void 0, void 0, function* () {
81
111
  if (isFolder) {
82
- const fromFolderObj = [];
112
+ let folder = null;
83
113
  if (typeof from === 'string') {
84
- if (from === '/') {
85
- fromFolderObj.push(zip);
86
- }
87
- else {
88
- const folder = zip.folder(from);
89
- if (folder) {
90
- fromFolderObj.push(folder);
91
- }
92
- }
114
+ folder = from === '/' ? zip : zip.folder(from);
93
115
  }
94
116
  else {
95
117
  const folderObjects = zip.folder(from);
96
- folderObjects.forEach((folder) => {
97
- if (folder) {
98
- fromFolderObj.push(zip.folder(folder.name));
118
+ if (folderObjects.length > 0) {
119
+ folder = zip.folder(folderObjects[0].name);
120
+ if (folderObjects.length > 1) {
121
+ folderObjects.forEach((folderObj) => {
122
+ if (folder !== null && folderObj.name.length > folder.name.length) {
123
+ folder = zip.folder(folderObj.name);
124
+ }
125
+ });
99
126
  }
100
- });
127
+ }
101
128
  }
102
- if (fromFolderObj.length === 0) {
129
+ if (!folder) {
103
130
  throw new error_1.default('Unable to extract zip, FolderObj is null', {
104
131
  exit: 2
105
132
  });
106
133
  }
107
- yield Promise.all(fromFolderObj.map((obj) => this._writeFolder(obj, to)));
134
+ yield this._writeFolder(folder, to, recursive, ignoreInitial);
108
135
  return true;
109
136
  }
110
137
  const fromFileObj = [];
@@ -115,28 +142,21 @@ class Archiver {
115
142
  }
116
143
  }
117
144
  else {
118
- fromFileObj.push(...zip.file(from).filter((fileObj) => {
119
- if (fileObj) {
120
- return true;
121
- }
122
- return false;
123
- }));
145
+ fromFileObj.concat(zip.file(from));
124
146
  }
125
147
  if (fromFileObj.length === 0) {
126
148
  throw new error_1.default('Unable to extract zip, FileObj is null', {
127
149
  exit: 2
128
150
  });
129
151
  }
130
- while (fromFileObj.length > 0) {
131
- const limit = fromFileObj.length < 20 ? fromFileObj.length : 20;
132
- yield Promise.all(fromFileObj.splice(0, limit).map((obj) => this._writeFile(obj, to)));
133
- }
152
+ yield this._writeAllFile(fromFileObj, to, recursive, ignoreInitial);
134
153
  return true;
135
- })));
154
+ }));
155
+ this.promiseArr.push(extractPromise);
136
156
  return this;
137
157
  }
138
158
  getUnixPath(pth) {
139
- return js_1.JS.join(js_1.JS.split(pth, path_1.sep), '/');
159
+ return pth.split(path_1.sep).join('/');
140
160
  }
141
161
  add(pth, content, { createFolders = true } = {}) {
142
162
  this.promiseArr.push(this.jszip.then((zip) => {
@@ -189,6 +209,23 @@ class Archiver {
189
209
  });
190
210
  yield fs_1.ASYNC.writeFile(tempFilePath, content);
191
211
  return fs_1.SYNC.getReadStream(tempFilePath);
212
+ }),
213
+ writeZip: (pth) => __awaiter(this, void 0, void 0, function* () {
214
+ const zip = yield this.jszip;
215
+ const content = yield zip.generateAsync({
216
+ type: 'nodebuffer',
217
+ compression: 'DEFLATE',
218
+ compressionOptions: {
219
+ level: 9
220
+ }
221
+ });
222
+ if (pth.endsWith('.zip')) {
223
+ pth = path_1.join(path_1.dirname(pth), this.name + '.zip');
224
+ }
225
+ if (path_1.parse(pth).ext === '') {
226
+ pth = path_1.join(pth, this.name + '.zip');
227
+ }
228
+ yield fs_1.ASYNC.writeFile(pth, content);
192
229
  })
193
230
  };
194
231
  }
@@ -199,4 +236,5 @@ class Archiver {
199
236
  });
200
237
  }
201
238
  }
239
+ Archiver.maxWriteLimit = 50;
202
240
  exports.default = Archiver;
@@ -287,9 +287,11 @@ class Login {
287
287
  processReq = false;
288
288
  res.writeHead(404);
289
289
  res.end();
290
+ return;
290
291
  }
291
292
  reqCount += 1;
292
- const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`).searchParams;
293
+ const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`)
294
+ .searchParams;
293
295
  const code = queryParamsObj !== undefined && queryParamsObj.get('code');
294
296
  const location = queryParamsObj !== undefined && queryParamsObj.get('location');
295
297
  if (processReq && typeof code === 'string') {
@@ -335,7 +337,7 @@ class Login {
335
337
  server.close();
336
338
  reject(new error_1.default('Server crashed with error.\n', {
337
339
  exit: 2,
338
- original: e
340
+ original: error_1.default.getErrorInstance(e)
339
341
  }));
340
342
  }
341
343
  }));
@@ -82,7 +82,6 @@ process.on('exit', (code) => {
82
82
  pkg,
83
83
  updateCheckInterval: 1000 * 60 * 15
84
84
  }).notify({ defer: false, isGlobal: true });
85
- errorOut_1.default();
86
85
  });
87
86
  process.on('uncaughtException', (err) => {
88
87
  errorOut_1.default(err);
@@ -28,8 +28,8 @@ const logger_1 = require("./util_modules/logger");
28
28
  const option_1 = require("./util_modules/option");
29
29
  const project_1 = require("./util_modules/project");
30
30
  exports.clientUtils = {
31
- validate: () => __awaiter(void 0, void 0, void 0, function* () {
32
- const sourceDir = project_1.resolveProjectPath(config_1.clientConfig.source());
31
+ validate: (source) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const sourceDir = source || project_1.resolveProjectPath(config_1.clientConfig.source());
33
33
  const packageJsonFile = path_1.join(sourceDir, constants_1.FILENAME.client.package_json);
34
34
  const sourceDirExists = yield fs_1.ASYNC.dirExists(sourceDir);
35
35
  if (!sourceDirExists) {
@@ -71,8 +71,8 @@ exports.clientUtils = {
71
71
  runtime_store_1.default.set('context.client.source', sourceDir);
72
72
  runtime_store_1.default.set('context.client.login_redirect', loginRedirect || homepage);
73
73
  runtime_store_1.default.set('context.client.package_json', packageJsonFile);
74
- const validatePlugin = yield plugin_loader_1.default('client', 'validate');
75
- if (validatePlugin === undefined) {
74
+ const validatePlugin = yield plugin_loader_1.default('client', 'validate').catch((err) => logger_1.debug(err));
75
+ if (typeof validatePlugin !== 'function') {
76
76
  runtime_store_1.default.set('context.client.valid', true);
77
77
  return packageJson;
78
78
  }
@@ -80,16 +80,17 @@ exports.clientUtils = {
80
80
  yield validatePlugin(option_1.getCurrentCommand(), sourceDir, runtime_store_1.default, packageJson);
81
81
  }
82
82
  catch (e) {
83
- throw new error_1.default(e, {
84
- exit: 1,
85
- errorId: 'CLIENT-UTILS-5',
86
- original: e,
87
- arg: [
88
- 'validating',
89
- ansi_colors_1.bold(config_1.clientConfig.plugin('validate') || 'unknown'),
90
- ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(e.message)
91
- ]
83
+ const err = error_1.default.getErrorInstance(e, {
84
+ skipHelp: false,
85
+ fileName: __filename
92
86
  });
87
+ err.errorId = 'CLIENT-UTILS-5';
88
+ err.arg = [
89
+ 'validating',
90
+ ansi_colors_1.bold(config_1.clientConfig.plugin('validate') || 'unknown'),
91
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(err.message)
92
+ ];
93
+ throw err;
93
94
  }
94
95
  runtime_store_1.default.set('context.client.valid', true);
95
96
  return packageJson;
@@ -107,8 +108,8 @@ exports.clientUtils = {
107
108
  },
108
109
  pack: () => __awaiter(void 0, void 0, void 0, function* () {
109
110
  let source = project_1.resolveProjectPath(config_1.clientConfig.source());
110
- const buildPlugin = yield plugin_loader_1.default('client', 'build');
111
- if (buildPlugin !== undefined) {
111
+ const buildPlugin = yield plugin_loader_1.default('client', 'build').catch((err) => logger_1.debug(err));
112
+ if (typeof buildPlugin === 'function') {
112
113
  try {
113
114
  logger_1.message(`Plugin : "${runtime_store_1.default.get(`context.client.plugins.build`)}" is used for client deploy`);
114
115
  const outputDir = yield buildPlugin(source, runtime_store_1.default);
@@ -118,20 +119,21 @@ exports.clientUtils = {
118
119
  source = outputDir;
119
120
  }
120
121
  catch (e) {
121
- throw new error_1.default(e, {
122
- exit: 1,
123
- errorId: 'CLIENT-UTILS-5',
124
- original: e,
125
- arg: [
126
- 'building',
127
- ansi_colors_1.bold(config_1.clientConfig.plugin('build') || 'unknown'),
128
- ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(e.message)
129
- ]
122
+ const err = error_1.default.getErrorInstance(e, {
123
+ skipHelp: false,
124
+ fileName: __filename
130
125
  });
126
+ err.errorId = 'CLIENT-UTILS-5';
127
+ err.arg = [
128
+ 'building',
129
+ ansi_colors_1.bold(config_1.clientConfig.plugin('build') || 'unknown'),
130
+ ansi_colors_1.bold('Error: ') + ansi_colors_1.italic.red(err.message)
131
+ ];
132
+ throw err;
131
133
  }
132
134
  }
133
- const ignore = config_1.clientConfig.ignore(source);
134
- const files = yield fs_1.ASYNC.walk(source, ignore);
135
+ const exclude = config_1.clientConfig.ignore(source);
136
+ const files = yield fs_1.ASYNC.walk(source, { exclude });
135
137
  const zip = new archiver_1.default();
136
138
  files.forEach((file) => {
137
139
  zip.add(file.replace(source + path_1.sep, ''), fs_1.SYNC.getReadStream(file));
package/lib/client.js CHANGED
@@ -46,8 +46,5 @@ class Client {
46
46
  return cmd.name();
47
47
  });
48
48
  }
49
- onUnknownCommand(actionFn) {
50
- this.cli.action(actionFn);
51
- }
52
49
  }
53
50
  exports.Client = Client;
@@ -41,9 +41,18 @@ exports.default = (inScopes = []) => {
41
41
  });
42
42
  }
43
43
  logger_1.debug(`> authorizing via ${tokenObj.option} option`);
44
- const commandScopes = [constants_1.SCOPE.projects, ...inScopes].filter((value, index, self) => self.indexOf(value) === index);
45
- logger_1.debug('> command requires scopes: ' + JSON.stringify([constants_1.SCOPE.projects].concat(inScopes || [])));
46
- runtime_store_1.default.set('auth_scopes', commandScopes);
44
+ const existingScopes = config_store_1.default.get(`${activeDC}.scopes`, []);
45
+ const requiredScopes = [constants_1.SCOPE.projects, ...inScopes];
46
+ logger_1.debug('> command requires scopes: ' + JSON.stringify(requiredScopes));
47
+ const hasAllScope = requiredScopes.every((scope) => existingScopes.includes(scope));
48
+ if (!tokenObj.temp && !env_1.isCI && !hasAllScope) {
49
+ throw new error_1.default('Re-login required due to missing scopes!!', {
50
+ exit: 0,
51
+ errorId: 'AUTH-2',
52
+ arg: [ansi_colors_1.bold('catalyst login --force')]
53
+ });
54
+ }
55
+ runtime_store_1.default.set('auth_scopes', requiredScopes);
47
56
  runtime_store_1.default.set('user', config_store_1.default.get(`${activeDC}.user`, null));
48
57
  runtime_store_1.default.set('credential', credential_1.default.init(tokenObj.token, tokenObj.temp));
49
58
  };
@@ -18,16 +18,17 @@ const error_1 = __importDefault(require("../error"));
18
18
  const rc_1 = __importDefault(require("../internal/rc"));
19
19
  const runtime_store_1 = __importDefault(require("../runtime-store"));
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
24
  const option_1 = require("../util_modules/option");
24
- const project_1 = require("../util_modules/project");
25
+ const project_2 = require("../util_modules/project");
25
26
  exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __awaiter(void 0, void 0, void 0, function* () {
26
27
  const projectOpt = option_1.getGlobalOptionValue('project', null);
27
28
  const projectApi = yield endpoints_1.projectAPI();
28
29
  const envApi = yield endpoints_1.envAPI();
29
30
  const convertProjectToProperties = (project) => {
30
- project = project_1.transformProject(project);
31
+ project = project_2.transformProject(project);
31
32
  runtime_store_1.default.set('project.name', project.name);
32
33
  runtime_store_1.default.set('project.id', project.id + '');
33
34
  runtime_store_1.default.set('project.domain', project.domain);
@@ -39,7 +40,7 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
39
40
  exit: 2
40
41
  });
41
42
  }
42
- runtime_store_1.default.set('project.env', project_1.transformEnv(envObj));
43
+ runtime_store_1.default.set('project.env', project_2.transformEnv(envObj));
43
44
  };
44
45
  let ignoreRC = false;
45
46
  if (projectOpt !== null) {
@@ -60,7 +61,11 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
60
61
  arg: [
61
62
  ansi_colors_1.bold(projectOpt),
62
63
  ansi_colors_1.bold('--project'),
63
- ansi_colors_1.bold(projectArr.map((project) => '* ' + project.project_name).join('\n'))
64
+ ansi_colors_1.bold(projectArr
65
+ .filter((proj) => proj.project_type &&
66
+ project_1.default.accepted_types.includes(proj.project_type))
67
+ .map((project) => '* ' + project.project_name)
68
+ .join('\n'))
64
69
  ]
65
70
  });
66
71
  }
@@ -146,7 +151,7 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
146
151
  logger_1.message('cleaning up ' +
147
152
  constants_1.FILENAME.rc +
148
153
  ' since the current active project for this folder is not found in remote');
149
- yield project_1.removeProject(finalProjectObj.id + '');
154
+ yield project_2.removeProject(finalProjectObj.id + '');
150
155
  if (resolveOnNotFound) {
151
156
  finalProjectObj = undefined;
152
157
  return;
@@ -170,8 +175,8 @@ exports.default = ({ optional = false, resolveOnNotFound = false } = {}) => __aw
170
175
  exit: 2
171
176
  });
172
177
  }
173
- finalEnvObj = project_1.transformEnv(envObj);
174
- yield project_1.upsertEnv(finalProjectObj.id + '', envObj, {
178
+ finalEnvObj = project_2.transformEnv(envObj);
179
+ yield project_2.upsertEnv(finalProjectObj.id + '', envObj, {
175
180
  active: true,
176
181
  base: js_1.JS.isEmpty(defaultRCEnv)
177
182
  });