zcatalyst-cli 1.7.1 → 1.9.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 (179) hide show
  1. package/README.md +31 -10
  2. package/docs/apig-utils.toml +69 -0
  3. package/docs/authentication/index.toml +15 -0
  4. package/docs/authentication/login.toml +14 -0
  5. package/docs/client-utils.toml +24 -0
  6. package/docs/command_needs/auth.toml +4 -0
  7. package/docs/command_needs/rc.toml +24 -0
  8. package/docs/commands/apig/disable.toml +4 -0
  9. package/docs/commands/apig/enable.toml +4 -0
  10. package/docs/commands/apig/status.toml +4 -0
  11. package/docs/commands/client/delete.toml +34 -0
  12. package/docs/commands/ds/export.toml +4 -0
  13. package/docs/commands/ds/import.toml +15 -0
  14. package/docs/commands/ds/status.toml +9 -0
  15. package/docs/commands/event/generate/index.toml +29 -0
  16. package/docs/commands/event/generate/integ.toml +4 -0
  17. package/docs/commands/functions/config.toml +11 -0
  18. package/docs/commands/functions/delete.toml +29 -0
  19. package/docs/commands/project/use.toml +9 -0
  20. package/docs/dc.toml +4 -0
  21. package/docs/deploy/features/apig.toml +4 -0
  22. package/docs/deploy/features/functions/index.toml +4 -0
  23. package/docs/event_generate/cache.toml +4 -0
  24. package/docs/event_generate/custom.toml +4 -0
  25. package/docs/event_generate/datastore.toml +4 -0
  26. package/docs/event_generate/filestore.toml +4 -0
  27. package/docs/event_generate/integration/cliq.toml +9 -0
  28. package/docs/execute-script.toml +19 -0
  29. package/docs/fn-utils/lib/common.toml +25 -0
  30. package/docs/fn-utils/lib/java.toml +34 -0
  31. package/docs/fn-utils/lib/node.toml +4 -0
  32. package/docs/init/index.toml +4 -0
  33. package/docs/internal/command.toml +4 -0
  34. package/docs/internal/config.toml +9 -0
  35. package/docs/internal/credential.toml +14 -0
  36. package/docs/option-filter.toml +45 -0
  37. package/docs/port-resolver.toml +9 -0
  38. package/docs/pull/index.toml +4 -0
  39. package/docs/serve/index.toml +4 -0
  40. package/docs/shell/index.toml +4 -0
  41. package/docs/util_modules/project.toml +9 -0
  42. package/lib/apig-utils.js +133 -43
  43. package/lib/archiver.js +4 -2
  44. package/lib/authentication/index.js +44 -9
  45. package/lib/authentication/login.js +51 -8
  46. package/lib/bin/catalyst.js +14 -7
  47. package/lib/client-utils.js +47 -14
  48. package/lib/client.js +1 -1
  49. package/lib/command_needs/auth.js +5 -3
  50. package/lib/command_needs/rc.js +35 -13
  51. package/lib/commands/apig/disable.js +8 -3
  52. package/lib/commands/apig/enable.js +8 -3
  53. package/lib/commands/apig/status.js +29 -9
  54. package/lib/commands/client/delete.js +65 -26
  55. package/lib/commands/client/setup.js +2 -2
  56. package/lib/commands/deploy.js +2 -2
  57. package/lib/commands/ds/export.js +16 -8
  58. package/lib/commands/ds/import.js +20 -14
  59. package/lib/commands/ds/status.js +22 -11
  60. package/lib/commands/event/generate/index.js +62 -12
  61. package/lib/commands/event/generate/integ.js +7 -3
  62. package/lib/commands/functions/add.js +2 -2
  63. package/lib/commands/functions/config.js +11 -3
  64. package/lib/commands/functions/delete.js +36 -13
  65. package/lib/commands/functions/setup.js +2 -2
  66. package/lib/commands/functions/shell.js +2 -2
  67. package/lib/commands/help.js +1 -1
  68. package/lib/commands/index.js +2 -3
  69. package/lib/commands/init.js +4 -4
  70. package/lib/commands/login.js +2 -2
  71. package/lib/commands/logout.js +2 -2
  72. package/lib/commands/project/list.js +2 -2
  73. package/lib/commands/project/reset.js +1 -1
  74. package/lib/commands/project/use.js +18 -2
  75. package/lib/commands/pull.js +5 -5
  76. package/lib/commands/run.js +2 -2
  77. package/lib/commands/serve.js +7 -6
  78. package/lib/commands/token/generate.js +2 -2
  79. package/lib/commands/token/list.js +2 -2
  80. package/lib/commands/token/revoke.js +2 -2
  81. package/lib/commands/whoami.js +1 -1
  82. package/lib/dc.js +11 -1
  83. package/lib/deploy/features/apig.js +33 -33
  84. package/lib/deploy/features/client.js +12 -19
  85. package/lib/deploy/features/functions/index.js +14 -4
  86. package/lib/deploy/features/index.js +1 -1
  87. package/lib/deploy/index.js +2 -9
  88. package/lib/endpoints/index.js +5 -2
  89. package/lib/endpoints/lib/apig.js +15 -5
  90. package/lib/endpoints/lib/applogic.js +12 -4
  91. package/lib/endpoints/lib/cache.js +9 -3
  92. package/lib/endpoints/lib/catalyst-details.js +37 -0
  93. package/lib/endpoints/lib/client.js +15 -5
  94. package/lib/endpoints/lib/datastore.js +6 -2
  95. package/lib/endpoints/lib/ds-bulk.js +15 -5
  96. package/lib/endpoints/lib/env.js +3 -1
  97. package/lib/endpoints/lib/event-bus.js +3 -1
  98. package/lib/endpoints/lib/filestore.js +6 -2
  99. package/lib/endpoints/lib/functions.js +12 -4
  100. package/lib/endpoints/lib/project.js +9 -3
  101. package/lib/endpoints/lib/queue.js +9 -3
  102. package/lib/endpoints/lib/sdk.js +3 -1
  103. package/lib/endpoints/lib/zcql.js +3 -1
  104. package/lib/error.js +18 -0
  105. package/lib/errorOut.js +10 -7
  106. package/lib/event_generate/cache.js +9 -1
  107. package/lib/event_generate/custom.js +6 -1
  108. package/lib/event_generate/datastore.js +12 -2
  109. package/lib/event_generate/filestore.js +9 -1
  110. package/lib/event_generate/integration/cliq.js +10 -2
  111. package/lib/execute-script.js +35 -6
  112. package/lib/express_middlewares/unknownReqProxy.js +18 -7
  113. package/lib/fn-utils/index.js +1 -1
  114. package/lib/fn-utils/lib/common.js +95 -17
  115. package/lib/fn-utils/lib/integ.js +4 -3
  116. package/lib/fn-utils/lib/java.js +49 -13
  117. package/lib/fn-utils/lib/node.js +15 -6
  118. package/lib/fn-watcher.js +67 -0
  119. package/lib/index.js +13 -12
  120. package/lib/init/dependencies/package-json.js +3 -1
  121. package/lib/init/features/functions/index.js +41 -29
  122. package/lib/init/features/functions/languages/java.js +5 -4
  123. package/lib/init/features/functions/languages/node.js +6 -5
  124. package/lib/init/features/index.js +8 -4
  125. package/lib/init/index.js +10 -3
  126. package/lib/internal/api.js +9 -9
  127. package/lib/internal/command.js +19 -14
  128. package/lib/internal/config.js +15 -15
  129. package/lib/internal/credential.js +33 -7
  130. package/lib/internal/rc.js +18 -10
  131. package/lib/migration/global/1.4.0.js +4 -2
  132. package/lib/migration/global/1.6.2.js +4 -2
  133. package/lib/migration/index.js +1 -1
  134. package/lib/option-filter.js +79 -22
  135. package/lib/optional-import.js +1 -1
  136. package/lib/plugin-loader.js +1 -1
  137. package/lib/port-resolver.js +23 -3
  138. package/lib/prompt.js +1 -1
  139. package/lib/pull/features/functions/index.js +7 -7
  140. package/lib/pull/features/index.js +1 -1
  141. package/lib/pull/index.js +10 -3
  142. package/lib/repl-server.js +9 -5
  143. package/lib/serve/features/index.js +11 -2
  144. package/lib/serve/index.js +19 -9
  145. package/lib/serve/server/index.js +137 -60
  146. package/lib/serve/server/lib/client.js +1 -1
  147. package/lib/serve/server/lib/master.js +16 -3
  148. package/lib/serve/server/lib/node.js +1 -1
  149. package/lib/shell/dependencies/http-functions.js +120 -90
  150. package/lib/shell/dependencies/invoker/integ/node.js +1 -1
  151. package/lib/shell/dependencies/local-function.js +86 -119
  152. package/lib/shell/index.js +10 -10
  153. package/lib/shell/prepare/index.js +1 -4
  154. package/lib/shell/prepare/languages/index.js +15 -4
  155. package/lib/track.js +4 -1
  156. package/lib/util_modules/config/index.js +1 -1
  157. package/lib/util_modules/config/lib/apig.js +3 -3
  158. package/lib/util_modules/config/lib/client.js +3 -3
  159. package/lib/util_modules/config/lib/functions.js +5 -5
  160. package/lib/util_modules/constants/index.js +22 -20
  161. package/lib/util_modules/constants/lib/regex.js +3 -2
  162. package/lib/util_modules/constants/lib/runtime.js +9 -0
  163. package/lib/util_modules/contextHelp.js +63 -123
  164. package/lib/util_modules/fs/index.js +1 -1
  165. package/lib/util_modules/fs/lib/async.js +19 -2
  166. package/lib/util_modules/fs/lib/sync.js +13 -1
  167. package/lib/util_modules/logger.js +12 -20
  168. package/lib/util_modules/option.js +1 -13
  169. package/lib/util_modules/project.js +75 -26
  170. package/lib/util_modules/shell.js +8 -2
  171. package/package.json +45 -45
  172. package/scripts/postInstall.js +31 -0
  173. package/lib/cjson.js +0 -20
  174. package/lib/log-error.js +0 -18
  175. package/lib/util_modules/big-json.js +0 -16
  176. package/lib/util_modules/constants/lib/stack.js +0 -6
  177. package/templates/init/functions/.DS_Store +0 -0
  178. package/templates/init/functions/node/.DS_Store +0 -0
  179. package/templates/init/functions/node/integ/.DS_Store +0 -0
@@ -0,0 +1,45 @@
1
+ [OPT-FILTER-1]
2
+ context = '''The ${arg[0]} option cannot contain duplicate targets.'''
3
+ aid = '''Please remove the duplicate target from the option input. \n${arg[1]}'''
4
+ link = ''
5
+
6
+ [OPT-FILTER-2]
7
+ context = '''Invalid target ${arg[0]} provided with the option ${arg[1]}.'''
8
+ aid = '''Please provide a valid target, The valid targets are: \n${arg[2]}'''
9
+ link = ''
10
+
11
+ [OPT-FILTER-3]
12
+ context = '''The target ${arg[0]} is specified with and without a filter for the ${arg[1]} option.'''
13
+ aid = '''Please use the targets either with a filter or without a filter and not both together. \n${arg[2]}'''
14
+ link = ''
15
+
16
+ [OPT-FILTER-4]
17
+ context = '''Cannot specify both the ${arg[0]} option and the ${arg[1]} option in the same command.'''
18
+ aid = '''Use only one of the above options at a time to select you targets.'''
19
+ link = ''
20
+
21
+ [OPT-FILTER-5]
22
+ context = '''The target Client cannot be debugged.'''
23
+ aid = '''Please remove the target Client from the --debug option and execute the command.'''
24
+ link = ''
25
+
26
+ [OPT-FILTER-6]
27
+ context = '''The input for the ${arg[0]} option is in an invalid format: ${arg[1]}'''
28
+ aid = '''Please use only these valid formats to specify the targets: \n${arg[2]}\n${arg[3]}'''
29
+ link = ''
30
+
31
+ [OPT-FILTER-7]
32
+ context = '''The input of the ${arg[0]} option for target ${arg[1]} is in an invalid format: ${arg[2]}'''
33
+ aid = '''Please use only the ${arg[3]} format, to specify your ${arg[1]} targets with the ${arg[0]} option.
34
+ example: --debug advancedio:aio_fn:8001'''
35
+ link = ''
36
+
37
+ [OPT-FILTER-8]
38
+ context = '''Could not understand the targets.'''
39
+ aid = '''Please ensure that ${arg[0]}'''
40
+ link = ''
41
+
42
+ [OPT-FILTER-9]
43
+ context = '''The API Gateway cannot be served seperately in local.'''
44
+ aid = '''Please include atleast one other component like functions or client along with the APIG to serve the APIG in local.'''
45
+ link = ''
@@ -0,0 +1,9 @@
1
+ [PORT-RESOLVER-1]
2
+ context = '''The port ${arg[0]} requested for the ${arg[1]} of ${arg[2]}(${arg[3]}) is not available.'''
3
+ aid = '''Please provide a different port with the ${arg[4]} option.'''
4
+
5
+
6
+ [PORT-RESOLVER-2]
7
+ context = '''No ports in the range ${arg[0]} to ${arg[1]} is free.'''
8
+ aid = '''Please specify a port out of the above range with the ${arg[2]} option.'''
9
+ link = 'https://www.zoho.com/catalyst/help/cli-serve.html#Options'
@@ -0,0 +1,4 @@
1
+ [PULL-1]
2
+ context = '''The value ${arg[0]} supplied with the command is not a valid Catalyst feature.'''
3
+ aid = '''The valid features are: \n${arg[1]}'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-pull.html#Pull_Directly'
@@ -0,0 +1,4 @@
1
+ [SERVE-1]
2
+ context = '''No valid components to serve!'''
3
+ aid = '''Please rectify the above errors, if any and try once again.'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-serve.html'
@@ -0,0 +1,4 @@
1
+ [SHELL-IDX-1]
2
+ context = '''No valid functions to Serve!'''
3
+ aid = '''Please rectify the above errors, if any and try once again.'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-functions.html#Shell'
@@ -0,0 +1,9 @@
1
+ [PROJ-1]
2
+ context = '''The "${arg[0]}" file is missing in the project root directory.'''
3
+ aid = '''Please initialize the project using the ${arg[1]} command.'''
4
+ link = 'https://www.zoho.com/catalyst/help/cli-init.html'
5
+
6
+ [PROJ-2]
7
+ context = '''Unable to get the ${arg[0]}'''
8
+ aid = '''Please initialize the project using the ${arg[1]} command'''
9
+ link = 'https://www.zoho.com/catalyst/help/cli-init.html'
package/lib/apig-utils.js CHANGED
@@ -40,17 +40,24 @@ const project_1 = require("./util_modules/project");
40
40
  exports.apigUtils = {
41
41
  validate: () => __awaiter(void 0, void 0, void 0, function* () {
42
42
  const ruleFile = project_1.resolveProjectPath(config_1.apigConfig.rules());
43
- const sourceFileExists = yield fs_1.ASYNC.fileExists(ruleFile);
44
- if (!sourceFileExists) {
45
- throw new error_1.default(ansi_colors_1.bold('"' + ruleFile + '"') +
46
- ' file was not found. Please create it or specify a different name in ' +
47
- constants_1.FILENAME.config, { exit: 1 });
48
- }
49
- const ruleArrayContent = yield fs_1.ASYNC.readFile(ruleFile);
50
- if (ruleArrayContent === undefined) {
51
- throw new error_1.default('Unable to read api gateway rules', { exit: 1 });
43
+ const ruleArr = (yield fs_1.ASYNC.readJSONFile(ruleFile, {
44
+ checkpath: true,
45
+ throws: true
46
+ }).catch((err) => {
47
+ throw new error_1.default('Unable to read ' + ruleFile + ' file.', {
48
+ exit: 1,
49
+ errorId: 'APIG-UTILS-1',
50
+ arg: [ansi_colors_1.bold(ruleFile), ansi_colors_1.italic.red(err)],
51
+ original: err
52
+ });
53
+ }));
54
+ if (ruleArr === undefined) {
55
+ throw new error_1.default(ruleFile + ' file not found' + constants_1.FILENAME.config, {
56
+ exit: 1,
57
+ errorId: 'APIG-UTILS-2',
58
+ arg: [ansi_colors_1.bold.red(ruleFile), ansi_colors_1.bold(constants_1.FILENAME.config)]
59
+ });
52
60
  }
53
- const ruleArr = JSON.parse(ruleArrayContent);
54
61
  let localRuleArr = [];
55
62
  let redirectPath;
56
63
  try {
@@ -72,27 +79,47 @@ exports.apigUtils = {
72
79
  localRuleArr = ruleArr.map((rule, index) => {
73
80
  var _a, _b;
74
81
  if (rule.name === undefined || rule.name === null) {
75
- throw new error_1.default(`Name for API Gateway rule is mandatory. Kindly add a valid rule to proceed`, { exit: 1 });
82
+ throw new error_1.default('Name for an APIG rule is missing', {
83
+ exit: 1,
84
+ errorId: 'APIG-UTILS-3',
85
+ arg: [ansi_colors_1.italic.red(JSON.stringify(rule, null, ' '))]
86
+ });
76
87
  }
77
88
  if (namesArr.includes(rule.name)) {
78
- throw new error_1.default(rule.name +
79
- ' is found to be duplicate in APIG rule config json. Kindly change the name and try again', { exit: 1 });
89
+ throw new error_1.default('Duplicate APIG rule detected', {
90
+ exit: 1,
91
+ errorId: 'APIG-UTILS-4',
92
+ arg: [ansi_colors_1.bold.red(rule.name)]
93
+ });
80
94
  }
81
95
  namesArr.push(rule.name);
82
96
  if (rule.source_endpoint === undefined || rule.source_endpoint === null) {
83
- throw new error_1.default(`Kindly add source_endpoint for ${rule.name} and try again`, { exit: 1 });
97
+ throw new error_1.default('source_endpoint missing for rule ' + rule.name, {
98
+ exit: 1,
99
+ errorId: 'APIG-UTILS-5',
100
+ arg: [ansi_colors_1.bold.red(rule.name), ansi_colors_1.bold('source_endpoint')]
101
+ });
84
102
  }
85
103
  if (rule.method === undefined || rule.method === null) {
86
- throw new error_1.default(`Kindly add method for ${rule.name} and try again`, {
87
- exit: 1
104
+ throw new error_1.default('method missing for rule ' + rule.name, {
105
+ exit: 1,
106
+ errorId: 'APIG-UTILS-5',
107
+ arg: [ansi_colors_1.bold.red(rule.name), ansi_colors_1.bold('method')]
88
108
  });
89
109
  }
90
110
  if (sourceUrlByConfig[rule.source_endpoint] !== undefined &&
91
111
  sourceUrlByConfig[rule.source_endpoint][rule.method] !== undefined) {
92
- throw new error_1.default(rule.name +
93
- ' is found to have duplicate "source_endpoint" as ' +
94
- sourceUrlByConfig[rule.source_endpoint][rule.method] +
95
- ' in APIG rule config json. Kindly change source and try again', { exit: 1 });
112
+ const duplicateRuleName = sourceUrlByConfig[rule.source_endpoint][rule.method] || '';
113
+ throw new error_1.default(rule.name + 'has duplicate "source_endpoint" as ' + duplicateRuleName, {
114
+ exit: 1,
115
+ errorId: 'APIG-UTILS-6',
116
+ arg: [
117
+ ansi_colors_1.bold(rule.name),
118
+ ansi_colors_1.bold('source_endpoint'),
119
+ ansi_colors_1.italic.red(rule.source_endpoint),
120
+ ansi_colors_1.bold(duplicateRuleName)
121
+ ]
122
+ });
96
123
  }
97
124
  if (sourceUrlByConfig[rule.source_endpoint] === undefined) {
98
125
  sourceUrlByConfig[rule.source_endpoint] = {};
@@ -100,13 +127,12 @@ exports.apigUtils = {
100
127
  sourceUrlByConfig[rule.source_endpoint][rule.method] = rule.name;
101
128
  if (rule.name === 'Login Redirect') {
102
129
  const homepage = runtime_store_1.default.get('context.client.homepage');
103
- if (redirectPath === undefined) {
104
- if (homepage === undefined) {
105
- throw new error_1.default('Login Redirect rule cannot be verified since client package is not valid', { exit: 1 });
106
- }
107
- else {
108
- redirectPath = '/app/' + homepage;
109
- }
130
+ const clientValidity = runtime_store_1.default.get('context.client.valid', false);
131
+ if (!clientValidity || (redirectPath === undefined && homepage === undefined)) {
132
+ throw new error_1.default('Login Redirect rule cannot be verified since client package is not valid', { exit: 1, errorId: 'APIG-UTILS-7', arg: [ansi_colors_1.bold(rule.name)] });
133
+ }
134
+ else if (!redirectPath) {
135
+ redirectPath = '/app/' + homepage;
110
136
  }
111
137
  redirectIdx = index;
112
138
  runtime_store_1.default.set('context.client.login_redirect', rule.source_endpoint);
@@ -126,7 +152,11 @@ exports.apigUtils = {
126
152
  }
127
153
  if (rule.target === 'client' || ((_b = rule.target_endpoint) === null || _b === void 0 ? void 0 : _b.startsWith('/app/'))) {
128
154
  if (rule.authentication !== undefined && rule.authentication !== null) {
129
- throw new error_1.default('client target cannot have authentication, for rule name : ' + rule.name, { exit: 1 });
155
+ throw new error_1.default('client target cannot have authentication, for rule name : ' + rule.name, {
156
+ exit: 1,
157
+ errorId: 'APIG-UTILS-8',
158
+ arg: [ansi_colors_1.bold(rule.name), ansi_colors_1.italic.red('"authentication"')]
159
+ });
130
160
  }
131
161
  }
132
162
  const { created_by, created_time, modified_by, modified_time, api_id } = rule, remaining = __rest(rule, ["created_by", "created_time", "modified_by", "modified_time", "api_id"]);
@@ -164,22 +194,37 @@ exports.apigUtils = {
164
194
  if (part.startsWith('{')) {
165
195
  const regexParts = part.slice(1, -1).split(':');
166
196
  try {
167
- new RegExp(regexParts[1]);
197
+ rule.name, new RegExp(regexParts[1]);
168
198
  }
169
199
  catch (regexError) {
170
- throw new error_1.default('source url provided for apig rule "' +
200
+ throw new error_1.default('source_endpoint provided for apig rule "' +
171
201
  rule.name +
172
202
  '" is not valid', {
173
203
  exit: 1,
174
- original: regexError
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
+ ]
175
212
  });
176
213
  }
177
214
  if (regexParts[1].includes('^') || regexParts[1].includes('$')) {
178
- throw new error_1.default('source url provided for apig rule "' +
215
+ throw new error_1.default('source_endpoint provided for apig rule "' +
179
216
  rule.name +
180
217
  '" is not valid. ' +
181
218
  'Url should not contain ^ or $ symbols', {
182
- exit: 1
219
+ exit: 1,
220
+ errorId: 'APIG-UTILS-10',
221
+ arg: [
222
+ ansi_colors_1.bold('source_endpoint'),
223
+ ansi_colors_1.bold(rule.name),
224
+ ansi_colors_1.italic(source_endpoint.replace(part, ansi_colors_1.red(part))),
225
+ ansi_colors_1.bold('Error: ') +
226
+ ansi_colors_1.italic.red('Regular Expression(s) in the source_endpoint should not contain ^ or $ symbols')
227
+ ]
183
228
  });
184
229
  }
185
230
  if (regexParts[1].includes('.*') && currentIdx !== allParts.length - 1) {
@@ -187,7 +232,16 @@ exports.apigUtils = {
187
232
  rule.name +
188
233
  '" is not valid. ' +
189
234
  'Url should not contain wildcard character in the mid of path', {
190
- exit: 1
235
+ exit: 1,
236
+ errorId: 'APIG-UTILS-10',
237
+ arg: [
238
+ ansi_colors_1.bold('source_endpoint'),
239
+ ansi_colors_1.bold(rule.name),
240
+ ansi_colors_1.italic(source_endpoint.replace(part, ansi_colors_1.red(part))),
241
+ ansi_colors_1.bold('Error: ') +
242
+ ansi_colors_1.italic.red('Regular Expression(s) in the source_endpoint with the wildcard character(.*)' +
243
+ ' is only allowed to be present at the last section of the endpoint')
244
+ ]
191
245
  });
192
246
  }
193
247
  let actualRegex = regexParts[1];
@@ -202,17 +256,26 @@ exports.apigUtils = {
202
256
  })
203
257
  .join('/');
204
258
  if (!otherProps.system && otherProps.name === 'Login Redirect') {
205
- throw new error_1.default('Login Redirect is a system reserved name. Kindly use some other name or define it as system value', { exit: 1 });
259
+ throw new error_1.default('Login Redirect is a system reserved name. Please define it as system value', { exit: 2 });
206
260
  }
207
261
  if (otherProps.target_endpoint === undefined) {
208
262
  switch (otherProps.target) {
209
263
  case 'client':
210
264
  case 'advancedio':
211
- throw new error_1.default('"target_endpoint" is mandatory, for rule name : ' + otherProps.name, { exit: 1 });
265
+ throw new error_1.default('"target_endpoint"(mandatory) is missing, for rule name : ' +
266
+ otherProps.name, {
267
+ exit: 1,
268
+ errorId: 'APIG-UTILS-11',
269
+ arg: [ansi_colors_1.bold(otherProps.name), ansi_colors_1.bold('target_endpoint')]
270
+ });
212
271
  case 'basicio':
213
272
  if (otherProps.target_id === undefined) {
214
273
  throw new error_1.default('If target is function "target_id" is mandatory, for rule name : ' +
215
- otherProps.name, { exit: 1 });
274
+ otherProps.name, {
275
+ exit: 1,
276
+ errorId: 'APIG-UTILS-11',
277
+ arg: [ansi_colors_1.bold(otherProps.name), ansi_colors_1.bold('target_id')]
278
+ });
216
279
  }
217
280
  const generatedUrl = fn_utils_1.fnUtils.common.generateUrlForTarget({
218
281
  name: otherProps.target_id,
@@ -221,16 +284,36 @@ exports.apigUtils = {
221
284
  valid: true
222
285
  });
223
286
  if (generatedUrl === undefined) {
224
- throw new error_1.default('"type" provided for function is not a valid one. Please specify if basicio or advancedio, for rule name : ' +
225
- otherProps.name, { exit: 1 });
287
+ throw new error_1.default('"target" provided for function is not a valid one. Please specify if basicio or advancedio, for rule name : ' +
288
+ otherProps.name, { exit: 2 });
226
289
  }
227
290
  otherProps.target_endpoint =
228
291
  '/' +
229
292
  generatedUrl.replace('https://', '').split('/').slice(1).join('/');
230
293
  break;
231
294
  default:
232
- throw new error_1.default('target_endpoint and target cannot both be undefined kindly define atleast one, for rule name : ' +
233
- otherProps.name, { exit: 1 });
295
+ if (otherProps.target === undefined) {
296
+ throw new error_1.default('target_endpoint and target both are undefined for rule name : ' +
297
+ otherProps.name, {
298
+ exit: 1,
299
+ errorId: 'APIG-UTILS-12',
300
+ arg: [
301
+ ansi_colors_1.bold(otherProps.name),
302
+ ansi_colors_1.bold('target_endpoint'),
303
+ ansi_colors_1.bold('target')
304
+ ]
305
+ });
306
+ }
307
+ throw new error_1.default('invalid target in APIG rule: ' + otherProps.name, {
308
+ exit: 1,
309
+ errorId: 'APIG-UTILS-13',
310
+ arg: [
311
+ ansi_colors_1.bold('target'),
312
+ ansi_colors_1.italic.red(otherProps.target),
313
+ ansi_colors_1.bold(otherProps.name),
314
+ ansi_colors_1.bold(['* client', '* advancedio', '* basicio'].join('\n'))
315
+ ]
316
+ });
234
317
  }
235
318
  }
236
319
  if (!otherProps.target_endpoint.startsWith('/baas/') &&
@@ -238,8 +321,15 @@ exports.apigUtils = {
238
321
  !otherProps.target_endpoint.startsWith('/server/') &&
239
322
  !otherProps.target_endpoint.startsWith('/oauthorize') &&
240
323
  !otherProps.target_endpoint.startsWith('/__catalyst/')) {
241
- throw new error_1.default('target_endpoint is not recognized. Please provide a catalyst url, for rule name : ' +
242
- otherProps.name, { exit: 1 });
324
+ throw new error_1.default('target_endpoint is not recognized for rule name : ' + otherProps.name, {
325
+ exit: 1,
326
+ errorId: 'APIG-UTILS-14',
327
+ arg: [
328
+ ansi_colors_1.bold('target_endpoint'),
329
+ ansi_colors_1.italic.red(otherProps.target_endpoint),
330
+ ansi_colors_1.bold(otherProps.name)
331
+ ]
332
+ });
243
333
  }
244
334
  if (method === 'ANY') {
245
335
  js_1.JS.set(localConfig, [sourceUrl, 'all'], otherProps);
package/lib/archiver.js CHANGED
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
@@ -123,7 +123,9 @@ class Archiver {
123
123
  }));
124
124
  }
125
125
  if (fromFileObj.length === 0) {
126
- throw new error_1.default('Unable to extract zip, FileObj is null', { exit: 2 });
126
+ throw new error_1.default('Unable to extract zip, FileObj is null', {
127
+ exit: 2
128
+ });
127
129
  }
128
130
  while (fromFileObj.length > 0) {
129
131
  const limit = fromFileObj.length < 20 ? fromFileObj.length : 20;
@@ -1,4 +1,23 @@
1
1
  'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -13,7 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
32
  };
14
33
  Object.defineProperty(exports, "__esModule", { value: true });
15
34
  exports.logout = exports.login = exports.revoke = exports.list = exports.create = void 0;
16
- const ansi_colors_1 = __importDefault(require("ansi-colors"));
35
+ const ansi_colors_1 = __importStar(require("ansi-colors"));
17
36
  const moment_1 = __importDefault(require("moment"));
18
37
  const config_store_1 = __importDefault(require("../config-store"));
19
38
  const dc_1 = require("../dc");
@@ -41,9 +60,11 @@ exports.create = create;
41
60
  function list() {
42
61
  const tokens = config_store_1.default.get(`${dc_1.getActiveDC()}.tokens`, null);
43
62
  if (tokens === null || Object.keys(tokens).length === 0) {
44
- throw new error_1.default('No tokens found, please run ' +
45
- ansi_colors_1.default.bold('catalyst token:generate') +
46
- ' in order to create one', { exit: 1 });
63
+ throw new error_1.default('No tokens found', {
64
+ exit: 0,
65
+ errorId: 'IDX-1',
66
+ arg: [ansi_colors_1.bold('catalyst token:generate')]
67
+ });
47
68
  }
48
69
  const tableData = [];
49
70
  for (const tokenId in tokens) {
@@ -65,9 +86,16 @@ function revoke(id) {
65
86
  const tokens = config_store_1.default.get(`${dc_1.getActiveDC()}.tokens`, {});
66
87
  const tokenKey = Object.keys(tokens).find((key) => key === id);
67
88
  if (tokenKey === undefined) {
68
- throw new error_1.default('Unable to retrive token, please run ' +
69
- ansi_colors_1.default.bold('catalyst token:list') +
70
- ' and provide one valid id from that list', { exit: 1 });
89
+ const allTokenKeys = Object.keys(tokens);
90
+ throw new error_1.default('Unable to retrive token', {
91
+ exit: 1,
92
+ errorId: 'IDX-2',
93
+ arg: [
94
+ id,
95
+ allTokenKeys.length > 0 ? '* ' + allTokenKeys.join('\n* ') : 'None',
96
+ ansi_colors_1.bold('catalyst token:list')
97
+ ]
98
+ });
71
99
  }
72
100
  const credential = credential_1.default.init(tokens[tokenKey]);
73
101
  return new revoke_1.default(credential, 'tokens.' + id).init();
@@ -83,7 +111,10 @@ function login() {
83
111
  logger_1.message('No need to login. Already logged as: ' + ansi_colors_1.default.cyan.bold(user.Email));
84
112
  return;
85
113
  }
86
- const ans = yield prompt_1.default.ask(prompt_1.default.question('collectUsage', 'Allow Catalyst to collect CLI error reporting information?', { type: 'confirm', defaultAns: true }), prompt_1.default.question('dc', 'Select the datacenter to which you have access: ', {
114
+ const ans = yield prompt_1.default.ask(prompt_1.default.question('collectUsage', 'Allow Catalyst to collect CLI error reporting information?', {
115
+ type: 'confirm',
116
+ defaultAns: true
117
+ }), prompt_1.default.question('dc', 'Select the datacenter to which you have access: ', {
87
118
  type: 'list',
88
119
  choices: Object.keys(constants_1.DC_TYPE).map((dc) => {
89
120
  const dcObj = constants_1.DC_TYPE[dc];
@@ -114,7 +145,11 @@ function logout() {
114
145
  const activeDC = dc_1.getActiveDC();
115
146
  const tokenObj = config_store_1.default.get(`${activeDC}.credential`, null);
116
147
  if (tokenObj === null) {
117
- throw new error_1.default('No need to logout, not logged in yet. Please run ' + ansi_colors_1.default.bold('catalyst login'), { exit: 1 });
148
+ throw new error_1.default('Not logged in', {
149
+ exit: 0,
150
+ errorId: 'IDX-3',
151
+ arg: [ansi_colors_1.bold('catalyst login')]
152
+ });
118
153
  }
119
154
  const user = config_store_1.default.get(`${activeDC}.user`, null);
120
155
  const ans = user === null
@@ -28,6 +28,7 @@ const constants_1 = require("../util_modules/constants");
28
28
  const fs_1 = require("../util_modules/fs");
29
29
  const js_1 = require("../util_modules/js");
30
30
  const logger_1 = require("../util_modules/logger");
31
+ const option_1 = require("../util_modules/option");
31
32
  class Login {
32
33
  constructor(localhost = true, user = true) {
33
34
  this.localhost = localhost;
@@ -67,7 +68,8 @@ class Login {
67
68
  }
68
69
  _getTokenFromAuthorizationCode(code, callbackUrl) {
69
70
  return __awaiter(this, void 0, void 0, function* () {
70
- const authCodeResponse = yield new api_1.default().post('/oauth/v2/token', {
71
+ const authCodeResponse = yield new api_1.default()
72
+ .post('/oauth/v2/token', {
71
73
  origin: constants_1.ORIGIN.auth,
72
74
  qs: {
73
75
  code,
@@ -80,6 +82,12 @@ class Login {
80
82
  skipQuery: true
81
83
  },
82
84
  authNeeded: false
85
+ })
86
+ .catch((err) => {
87
+ throw new error_1.default('Error when getting the token from authorization code', {
88
+ exit: 2,
89
+ original: err
90
+ });
83
91
  });
84
92
  if (!js_1.JS.hasIn(authCodeResponse, 'body.access_token') ||
85
93
  !js_1.JS.hasIn(authCodeResponse, 'body.refresh_token')) {
@@ -100,7 +108,8 @@ class Login {
100
108
  }
101
109
  _getTokenFromDeviceCode(code, retryCount = 0) {
102
110
  return __awaiter(this, void 0, void 0, function* () {
103
- const deviceCodeResponse = yield new api_1.default().post('/oauth/v3/device/token', {
111
+ const deviceCodeResponse = yield new api_1.default()
112
+ .post('/oauth/v3/device/token', {
104
113
  origin: constants_1.ORIGIN.auth,
105
114
  qs: {
106
115
  client_id: constants_1.AUTH.mobile.id,
@@ -113,6 +122,12 @@ class Login {
113
122
  skipQuery: true
114
123
  },
115
124
  authNeeded: false
125
+ })
126
+ .catch((err) => {
127
+ throw new error_1.default('Error when getting access token from device code', {
128
+ exit: 2,
129
+ original: err
130
+ });
116
131
  });
117
132
  if (!js_1.JS.hasIn(deviceCodeResponse, 'body.access_token') ||
118
133
  !js_1.JS.hasIn(deviceCodeResponse, 'body.refresh_token')) {
@@ -123,7 +138,19 @@ class Login {
123
138
  JSON.stringify(deviceCodeResponse.body));
124
139
  logger_1.debug('> polling <');
125
140
  if (++retryCount > 30) {
126
- throw new error_1.default('Unable to get refresh_token from code. Kindly try again.', { exit: 1 });
141
+ if (option_1.getCurrentCommand() === 'login') {
142
+ throw new error_1.default('Unable to get refresh_token from code', {
143
+ exit: 0,
144
+ errorId: 'LOGIN-1'
145
+ });
146
+ }
147
+ else {
148
+ throw new error_1.default('Unable to get refresh_token from code', {
149
+ exit: 1,
150
+ errorId: 'LOGIN-2',
151
+ arg: [ansi_colors_1.bold('catalyst token:generate')]
152
+ });
153
+ }
127
154
  }
128
155
  yield js_1.JS.sleep(2000);
129
156
  return this._getTokenFromDeviceCode(code, retryCount);
@@ -152,9 +179,16 @@ class Login {
152
179
  if (!this.user) {
153
180
  return undefined;
154
181
  }
155
- const userInfoResponse = yield new api_1.default().get('/oauth/user/info', {
182
+ const userInfoResponse = yield new api_1.default()
183
+ .get('/oauth/user/info', {
156
184
  origin: constants_1.ORIGIN.auth,
157
185
  authNeeded: true
186
+ })
187
+ .catch((err) => {
188
+ throw new error_1.default('Error when trying to get the user details', {
189
+ exit: 2,
190
+ original: err
191
+ });
158
192
  });
159
193
  if (!js_1.JS.hasIn(userInfoResponse, 'body.Email') && !js_1.JS.hasIn(userInfoResponse, 'body.ZUID')) {
160
194
  logger_1.debug('User Details Fetch Error:\n' +
@@ -175,7 +209,8 @@ class Login {
175
209
  this.salt = 'm';
176
210
  const throbber = throbber_1.default.getInstance();
177
211
  const throbberName = 'authentication';
178
- const deviceCodeResponse = yield new api_1.default().post('/oauth/v3/device/code', {
212
+ const deviceCodeResponse = yield new api_1.default()
213
+ .post('/oauth/v3/device/code', {
179
214
  origin: constants_1.ORIGIN.auth,
180
215
  qs: {
181
216
  client_id: constants_1.AUTH.mobile.id,
@@ -185,6 +220,12 @@ class Login {
185
220
  prompt: 'consent'
186
221
  },
187
222
  authNeeded: false
223
+ })
224
+ .catch((err) => {
225
+ throw new error_1.default('Error when getting code from zoho', {
226
+ exit: 2,
227
+ original: err
228
+ });
188
229
  });
189
230
  if (!js_1.JS.hasIn(deviceCodeResponse, 'body.user_code') ||
190
231
  !js_1.JS.hasIn(deviceCodeResponse, 'body.device_code')) {
@@ -193,8 +234,10 @@ class Login {
193
234
  deviceCodeResponse.status +
194
235
  ', Body: ' +
195
236
  JSON.stringify(deviceCodeResponse.body));
196
- throw new error_1.default('Unable to get code from zoho. Kindly check your credentials and try again. \n' +
197
- 'If the problem persists contact support@zohocatalyst.com');
237
+ throw new error_1.default('Unable to get code from zoho', {
238
+ exit: 1,
239
+ errorId: 'LOGIN-3'
240
+ });
198
241
  }
199
242
  logger_1.info();
200
243
  logger_1.info('Visit this URL on any device: \n');
@@ -205,7 +248,7 @@ class Login {
205
248
  ' and click verify to continue.');
206
249
  const deviceCode = js_1.JS.get(deviceCodeResponse, 'body.device_code');
207
250
  yield js_1.JS.sleep(10000);
208
- throbber.add(throbberName, { text: 'checking if the code has been enterted' });
251
+ throbber.add(throbberName, { text: 'checking if the code has been entered' });
209
252
  try {
210
253
  const result = yield this._getTokenFromDeviceCode(deviceCode);
211
254
  js_1.JS.set(result, 'token', this.salt + '_' + result.refresh_token);