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
@@ -13,12 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ansi_colors_1 = require("ansi-colors");
16
+ const catalyst_details_1 = __importDefault(require("../../../endpoints/lib/catalyst-details"));
16
17
  const integ_1 = require("../../../fn-utils/lib/integ");
17
18
  const prompt_1 = __importDefault(require("../../../prompt"));
18
19
  const runtime_store_1 = __importDefault(require("../../../runtime-store"));
20
+ const char_1 = require("../../../util_modules/char");
19
21
  const constants_1 = require("../../../util_modules/constants");
20
22
  const fs_1 = require("../../../util_modules/fs");
21
- 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
25
  const project_1 = require("../../../util_modules/project");
@@ -46,7 +47,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
46
47
  }
47
48
  yield fs_1.ASYNC.deleteDir(functionsDirPath).catch();
48
49
  }
49
- const fnTypeAns = yield prompt_1.default.ask(prompt_1.default.question('type', 'which type of function do you like to create?', {
50
+ const catalystDetailsAPI = new catalyst_details_1.default();
51
+ const runtimeDetailsPromise = catalystDetailsAPI.getDetails('runtime');
52
+ const fnTypeAns = yield prompt_1.default.ask(prompt_1.default.question('type', 'Which type of function do you like to create?', {
50
53
  type: 'list',
51
54
  choices: [
52
55
  prompt_1.default.choice('BasicIO', {
@@ -75,37 +78,46 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
75
78
  if (fnTypeAns.type === constants_1.FN_TYPE.integration) {
76
79
  yield integ_1.integHelper();
77
80
  }
78
- const choices = js_1.JS.map(languages_1.default, (value, key) => {
79
- switch (key) {
80
- case 'node':
81
- key = constants_1.STACK.node10;
82
- break;
83
- case 'java':
84
- key = constants_1.STACK.java8;
85
- break;
86
- default:
87
- break;
81
+ const runtimeDetails = (yield runtimeDetailsPromise);
82
+ const runtimeChoices = runtimeDetails.runtimes.reduce((acc, value) => {
83
+ const langArr = value.match(/[a-zA-Z]+/g);
84
+ if (langArr === null || languages_1.default[langArr[0]] === undefined) {
85
+ logger_1.debug('Language cannot be identified hence skipping');
86
+ return acc;
88
87
  }
89
- return prompt_1.default.choice(key, { value, short: key });
90
- });
91
- const stackAns = yield prompt_1.default.ask(prompt_1.default.question('stack', 'Which stack do you prefer to write your function?', {
92
- type: 'list',
93
- choices,
94
- validate: (ansArr) => {
95
- if (js_1.JS.isEmpty(ansArr)) {
96
- return ('Must select at least one stack.\n' +
97
- '(Press ' +
98
- ansi_colors_1.cyan('<return>') +
99
- ' to select, ');
88
+ const lang = languages_1.default[langArr[0]];
89
+ let displayValue = value;
90
+ let disabled = false;
91
+ if (runtimeDetails.eol_runtimes && runtimeDetails.eol_runtimes[value]) {
92
+ switch (runtimeDetails.eol_runtimes[value]) {
93
+ case 1:
94
+ displayValue += ` (${char_1.CHAR.info} This runtime has reached its EOL)`;
95
+ break;
96
+ case 2:
97
+ displayValue += ` (${char_1.CHAR.warning} Only updates are allowed in this runtime)`;
98
+ disabled = true;
99
+ break;
100
+ case 3:
101
+ displayValue += ` (${char_1.CHAR.error} This runtime is no longer supported)`;
102
+ disabled = true;
103
+ break;
104
+ default:
105
+ logger_1.debug('unknown eol_runtime value ' + runtimeDetails.eol_runtimes[value]);
106
+ return acc;
100
107
  }
101
- return true;
102
- },
108
+ }
109
+ acc.push(prompt_1.default.choice(displayValue, { value: lang(value), short: value, disabled }));
110
+ return acc;
111
+ }, []);
112
+ const runtimeAns = yield prompt_1.default.ask(prompt_1.default.question('runtime', 'Which runtime do you prefer to write your function?', {
113
+ type: 'list',
114
+ choices: runtimeChoices,
103
115
  when: () => {
104
- return choices.length > 1;
116
+ return runtimeChoices.length > 1;
105
117
  }
106
118
  }));
107
- if (stackAns.stack === undefined) {
108
- return languages_1.default.node();
119
+ if (runtimeAns === undefined || runtimeAns.runtime === undefined) {
120
+ return languages_1.default.node('node14')();
109
121
  }
110
- return stackAns.stack();
122
+ return runtimeAns.runtime();
111
123
  });
@@ -23,7 +23,8 @@ const logger_1 = require("../../../../util_modules/logger");
23
23
  const js_1 = require("../../../../util_modules/js");
24
24
  const integ_1 = require("../../../../fn-utils/lib/integ");
25
25
  const common_1 = require("../../../../fn-utils/lib/common");
26
- exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
27
+ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
27
28
  const fnType = runtime_store_1.default.get('context.functions.type');
28
29
  const fnDirPath = path_1.join(runtime_store_1.default.get('context.functions.dir_path'));
29
30
  yield fs_1.ASYNC.ensureDir(fnDirPath);
@@ -65,7 +66,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
65
66
  ? js_1.JS.get(constants_1.TEMPLATE.functions.java[fnType], service)
66
67
  : constants_1.TEMPLATE.functions.java[fnType];
67
68
  if (fnType === constants_1.FN_TYPE.integration) {
68
- yield integ_1.copyIntegHandlers(templatePath, targetPath, constants_1.STACK.java8);
69
+ yield integ_1.copyIntegHandlers(templatePath, targetPath, runtime_1.default.language.java);
69
70
  }
70
71
  else {
71
72
  yield fs_1.ASYNC.copyDir(templatePath, targetPath);
@@ -73,7 +74,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
73
74
  yield fs_1.ASYNC.findAndReplace(targetPath)([constants_1.PLACEHOLDER.functions.java_class, constants_1.PLACEHOLDER.functions.java_name], [functionAns.class, functionAns.name]);
74
75
  const integ_config = runtime_store_1.default.get('context.functions.integration.config', '');
75
76
  yield fn_utils_1.fnUtils.common.findAndReplaceConfigProps(targetPath, {
76
- stack: constants_1.STACK.java8,
77
+ stack,
77
78
  type: fnType,
78
79
  integ_config
79
80
  });
@@ -85,7 +86,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
85
86
  const userFnLibPath = path_1.join(fnDirPath, functionAns.name, constants_1.FOLDERNAME.java_fn_lib);
86
87
  yield fn_utils_1.fnUtils.java.rewriteClasspath(userFnClassPath, userFnLibPath);
87
88
  runtime_store_1.default.set('payload.functions.source', targetPath);
88
- runtime_store_1.default.set('payload.functions.stack', constants_1.STACK.java8);
89
+ runtime_store_1.default.set('payload.functions.stack', stack);
89
90
  runtime_store_1.default.set('payload.functions.name', functionAns.name);
90
91
  runtime_store_1.default.set('payload.functions.class', functionAns.class);
91
92
  runtime_store_1.default.set('payload.functions.type', fnType);
@@ -24,7 +24,8 @@ const fs_1 = require("../../../../util_modules/fs");
24
24
  const logger_1 = require("../../../../util_modules/logger");
25
25
  const js_1 = require("../../../../util_modules/js");
26
26
  const integ_1 = require("../../../../fn-utils/lib/integ");
27
- exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
27
+ const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
28
+ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
28
29
  const fnType = runtime_store_1.default.get('context.functions.type');
29
30
  const service = runtime_store_1.default.get('context.functions.integration.service', '');
30
31
  const templatePath = fnType === constants_1.FN_TYPE.integration
@@ -49,7 +50,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
49
50
  }
50
51
  yield fs_1.ASYNC.deleteDir(targetPath).catch();
51
52
  if (fnType === constants_1.FN_TYPE.integration) {
52
- yield integ_1.copyIntegHandlers(templatePath, targetPath, constants_1.STACK.node10);
53
+ yield integ_1.copyIntegHandlers(templatePath, targetPath, runtime_1.default.language.nodejs);
53
54
  }
54
55
  else {
55
56
  yield fs_1.ASYNC.copyDir(templatePath, targetPath);
@@ -59,18 +60,18 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
59
60
  const replaceArr = [];
60
61
  Object.keys(constants_1.PLACEHOLDER.functions.node_package).forEach((key) => {
61
62
  placeholderArr.push(constants_1.PLACEHOLDER.functions.node_package[key]);
62
- replaceArr.push(finalJson[key]);
63
+ replaceArr.push(key === 'name' ? finalJson[key].toLowerCase() : finalJson[key]);
63
64
  });
64
65
  yield fs_1.ASYNC.findAndReplace(targetPath)(placeholderArr, replaceArr);
65
66
  const integ_config = runtime_store_1.default.get('context.functions.integration.config', '');
66
67
  yield fn_utils_1.fnUtils.common.findAndReplaceConfigProps(targetPath, {
67
- stack: constants_1.STACK.node10,
68
+ stack,
68
69
  type: fnType,
69
70
  integ_config
70
71
  });
71
72
  yield npm_install_1.default(targetPath);
72
73
  runtime_store_1.default.set('payload.functions.source', targetPath);
73
- runtime_store_1.default.set('payload.functions.stack', constants_1.STACK.node10);
74
+ runtime_store_1.default.set('payload.functions.stack', stack);
74
75
  runtime_store_1.default.set('payload.functions.name', finalJson.name);
75
76
  runtime_store_1.default.set('payload.functions.main', finalJson.main);
76
77
  runtime_store_1.default.set('payload.functions.type', fnType);
@@ -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
  };
@@ -37,6 +37,7 @@ const path_1 = require("path");
37
37
  const error_1 = __importDefault(require("../../error"));
38
38
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
39
39
  const constants_1 = require("../../util_modules/constants");
40
+ const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
40
41
  const js_1 = require("../../util_modules/js");
41
42
  const logger_1 = require("../../util_modules/logger");
42
43
  const project_1 = require("../../util_modules/project");
@@ -67,24 +68,27 @@ function setFnConfig(featureName, add) {
67
68
  featureContextArr = [featureContext];
68
69
  }
69
70
  if (featureContextArr === null) {
70
- throw new error_1.default('No context given to populate catalyst.json', { exit: 2 });
71
+ throw new error_1.default('No context given to populate catalyst.json', {
72
+ exit: 2
73
+ });
71
74
  }
72
75
  const config = runtime_store_1.default.get('config');
73
76
  featureContextArr.forEach((context) => {
77
+ var _a, _b;
74
78
  const targetSourceDir = featureName === 'functions' ? path_1.dirname(context.source) : path_1.basename(context.source);
75
79
  const targetSource = path_1.relative(project_1.getProjectRoot(), targetSourceDir);
76
80
  switch (featureName) {
77
81
  case 'functions':
78
82
  if (!add) {
79
83
  config.set(featureName + '.targets', [context.name]);
80
- config.set(featureName + '.ignore', context.stack === constants_1.STACK.java8 ? ['.output'] : []);
84
+ config.set(featureName + '.ignore', ((_a = context.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) ? ['.output'] : []);
81
85
  config.set(featureName + '.source', targetSource);
82
86
  return;
83
87
  }
84
88
  const targetArr = config.get(featureName + '.targets', []);
85
89
  config.set(featureName + '.targets', js_1.JS.uniq(targetArr.concat([context.name])));
86
90
  const ignoreArr = config.get(featureName + '.ignore', []);
87
- config.set(featureName + '.ignore', context.stack === constants_1.STACK.java8
91
+ config.set(featureName + '.ignore', ((_b = context.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java))
88
92
  ? js_1.JS.uniq(ignoreArr.concat(['.output']))
89
93
  : ignoreArr);
90
94
  if (config.get(featureName + '.source') !== targetSource) {
package/lib/init/index.js CHANGED
@@ -26,9 +26,16 @@ function init() {
26
26
  }
27
27
  const feature = featureList.shift();
28
28
  if (!Object.keys(features_1.default).includes(feature)) {
29
- throw new error_1.default(ansi_colors_1.bold(feature) +
30
- ' is not a valid feature. Must be one of ' +
31
- js_1.JS.without(js_1.JS.keys(features_1.default), 'project').join(','), { exit: 1 });
29
+ throw new error_1.default('invalid feature for init', {
30
+ exit: 1,
31
+ errorId: 'INIT-IDX-1',
32
+ arg: [
33
+ ansi_colors_1.bold.red(feature),
34
+ ansi_colors_1.bold(Object.keys(features_1.default)
35
+ .map((feat) => '* ' + feat)
36
+ .join('\n'))
37
+ ]
38
+ });
32
39
  }
33
40
  const MODULE = features_1.default[feature];
34
41
  logger_1.info(ansi_colors_1.bold('\n' + ansi_colors_1.white('===> ') + js_1.JS.capitalize(feature) + ' Setup'));
@@ -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
  };
@@ -39,7 +39,6 @@ const runtime_store_1 = __importDefault(require("../runtime-store"));
39
39
  const constants_1 = require("../util_modules/constants");
40
40
  const js_1 = require("../util_modules/js");
41
41
  const logger_1 = require("../util_modules/logger");
42
- const big_json_1 = require("../util_modules/big-json");
43
42
  class API {
44
43
  constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {} } = {}) {
45
44
  this.requestOpts = {
@@ -47,6 +46,7 @@ class API {
47
46
  method: 'GET',
48
47
  json: true,
49
48
  headers: {
49
+ Accept: 'application/vnd.catalyst.v2+json',
50
50
  'User-Agent': runtime_store_1.default.get('context.cli.package.name') +
51
51
  '/' +
52
52
  runtime_store_1.default.get('context.cli.package.version'),
@@ -62,14 +62,14 @@ class API {
62
62
  }
63
63
  _logReq() {
64
64
  let qs = this.requestOpts.qs
65
- ? '\nQuery params: ' + big_json_1.bigJSON.stringify(this.requestOpts.qs)
65
+ ? '\nQuery params: ' + JSON.stringify(this.requestOpts.qs)
66
66
  : '';
67
67
  qs = this.logOpts.skipQuery === true ? '\n<request query omitted>' : qs;
68
68
  let body = this.requestOpts.body
69
- ? '\nRequest Body: ' + big_json_1.bigJSON.stringify(this.requestOpts.body)
69
+ ? '\nRequest Body: ' + JSON.stringify(this.requestOpts.body)
70
70
  : '';
71
71
  body += this.requestOpts.form
72
- ? '\nRequest Form: ' + big_json_1.bigJSON.stringify(this.requestOpts.form)
72
+ ? '\nRequest Form: ' + JSON.stringify(this.requestOpts.form)
73
73
  : '';
74
74
  body = this.logOpts.skipReqBody === true ? '\n<request body omitted>' : body;
75
75
  logger_1.debug('>>>> HTTP REQUEST : ' +
@@ -86,7 +86,7 @@ class API {
86
86
  resp.statusCode +
87
87
  '\n' +
88
88
  'Response Headers: ' +
89
- big_json_1.bigJSON.stringify(resp.headers) +
89
+ JSON.stringify(resp.headers) +
90
90
  '\n');
91
91
  if (!js_1.JS.isUndefined(resp.timings)) {
92
92
  logger_1.debug('TOTAL TIME TAKEN : ' + Number(resp.timings.end.toFixed(3)) + ' ms\n');
@@ -113,14 +113,14 @@ class API {
113
113
  const rawResponseData = rawResponse.length > 0 ? Buffer.concat(rawResponse) : undefined;
114
114
  if (rawResponseData && js_1.JS.includes(resp.headers['content-type'], 'json')) {
115
115
  try {
116
- body = big_json_1.bigJSON.parse(rawResponseData.toString());
116
+ body = JSON.parse(rawResponseData.toString());
117
117
  }
118
118
  catch (e) {
119
119
  logger_1.debug('API Parsing Error: ' + e.message);
120
120
  }
121
121
  }
122
122
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
123
- logger_1.debug('Response Body : ' + big_json_1.bigJSON.stringify(resp.body) + '\n');
123
+ logger_1.debug('Response Body : ' + JSON.stringify(resp.body) + '\n');
124
124
  if (!this.resolveOnHTTPError) {
125
125
  throw errorResponse_1.default(resp, body);
126
126
  }
@@ -129,7 +129,7 @@ class API {
129
129
  status: resp.statusCode,
130
130
  response: resp,
131
131
  body: js_1.JS.includes(resp.headers['content-type'], 'json') && typeof body === 'string'
132
- ? big_json_1.bigJSON.parse(body)
132
+ ? JSON.parse(body)
133
133
  : body
134
134
  };
135
135
  }
@@ -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
  };
@@ -33,7 +33,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const ansi_colors_1 = require("ansi-colors");
35
35
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
36
- const util_1 = require("util");
37
36
  const error_1 = __importDefault(require("../error"));
38
37
  const errorOut_1 = __importDefault(require("../errorOut"));
39
38
  const migration_1 = __importDefault(require("../migration"));
@@ -117,31 +116,36 @@ class Command {
117
116
  const runner = this.runner();
118
117
  const start = Date.now();
119
118
  const argCount = cmd._args.length;
120
- if (programArgs.length - 1 > argCount && !this.allowUnknownOptions) {
121
- return errorOut_1.default(new error_1.default('Too many arguments. Run ' +
122
- ansi_colors_1.bold('catalyst help ' + cmd._name) +
123
- ' for usage instructions', { exit: 1 }));
119
+ if (programArgs.slice(-1)[0].args.length > argCount &&
120
+ !this.allowUnknownOptions) {
121
+ return errorOut_1.default(new error_1.default('Too many arguments', {
122
+ exit: 1,
123
+ errorId: 'CMD-1',
124
+ arg: [ansi_colors_1.bold(cmd.name()), ansi_colors_1.bold('catalyst help ' + cmd.name())]
125
+ }));
124
126
  }
125
127
  try {
126
128
  yield runner.apply(this, programArgs);
127
129
  const duration = Date.now() - start;
128
130
  yield track_1.default(this.cmdName, 'success', duration);
129
- process.nextTick(() => process.exit(0));
131
+ process.exitCode = 0;
130
132
  }
131
133
  catch (err) {
132
134
  const duration = Date.now() - start;
133
135
  const errorEvent = err.exit === 1 ? 'Error (User)' : 'Error (Unexpected)';
134
136
  const preppedMessage = strip_ansi_1.default(err.message || '');
135
137
  yield track_1.default(errorEvent, preppedMessage, duration);
136
- errorOut_1.default(err);
138
+ return errorOut_1.default(err);
137
139
  }
138
140
  }));
139
141
  return cmd;
140
142
  }
141
- _prepare() {
143
+ _prepare(cmd) {
144
+ var _a;
145
+ const globalopts = ((_a = cmd.parent) === null || _a === void 0 ? void 0 : _a.opts()) || {};
142
146
  Command.globalOpts.forEach((opts) => {
143
- const optsValue = option_1.getInheritedOption(opts, null);
144
- if (optsValue === null) {
147
+ const optsValue = globalopts[opts];
148
+ if (optsValue === undefined) {
145
149
  return;
146
150
  }
147
151
  if (js_1.JS.indexOf(this.optIgnores, opts) > -1) {
@@ -162,13 +166,14 @@ class Command {
162
166
  if (args.length === 0) {
163
167
  args.push({});
164
168
  }
165
- runtime_store_1.default.set('opts', js_1.JS.last(args));
166
- this._prepare();
169
+ const [opts, command] = args.slice(-2);
170
+ runtime_store_1.default.set('opts', Object.assign({ _name: command.name() }, opts));
171
+ this._prepare(command);
167
172
  try {
168
173
  yield migration_1.default(runtime_store_1.default.get('context.cli.package.version'));
169
174
  }
170
175
  catch (e) {
171
- logger_1.debug(util_1.inspect(e));
176
+ logger_1.debug(e);
172
177
  }
173
178
  yield Promise.all(js_1.JS.map(this.beforeRunners, (before) => __awaiter(this, void 0, void 0, function* () {
174
179
  const beforeModule = (yield Promise.resolve().then(() => __importStar(require('../command_needs/' + before.fn)))).default;
@@ -12,8 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const ansi_colors_1 = require("ansi-colors");
15
16
  const path_1 = require("path");
16
- const cjson_1 = __importDefault(require("../cjson"));
17
17
  const error_1 = __importDefault(require("../error"));
18
18
  const constants_1 = require("../util_modules/constants");
19
19
  const fs_1 = require("../util_modules/fs");
@@ -55,32 +55,32 @@ class Config {
55
55
  set loaded(load) {
56
56
  this.isLoaded = load;
57
57
  }
58
- static loadConfigFile(configPath) {
59
- const data = cjson_1.default(configPath);
60
- const config = new Config(configPath, data);
61
- config.loaded = true;
62
- return config;
63
- }
64
58
  static load(canIgnore) {
65
59
  return __awaiter(this, void 0, void 0, function* () {
66
60
  const pd = project_1.getProjectRoot();
67
61
  try {
68
- if (yield fs_1.ASYNC.fileExists(path_1.join(pd, constants_1.FILENAME.config))) {
69
- return this.loadConfigFile(path_1.join(pd, constants_1.FILENAME.config));
62
+ const configPath = path_1.join(pd, constants_1.FILENAME.config);
63
+ const data = yield fs_1.ASYNC.readJSONFile(configPath, { checkpath: true });
64
+ if (data !== undefined) {
65
+ const config = new Config(configPath, data);
66
+ config.loaded = true;
67
+ return config;
70
68
  }
71
69
  }
72
70
  catch (e) {
73
- throw new error_1.default('There was an error loading ' + constants_1.FILENAME.config + ' :\n\n' + e.message, {
74
- exit: 1
71
+ throw new error_1.default('There was an error loading a file', {
72
+ exit: 1,
73
+ errorId: 'CONFIG-1',
74
+ arg: [ansi_colors_1.bold(constants_1.FILENAME.config), e.message]
75
75
  });
76
76
  }
77
77
  if (canIgnore) {
78
78
  return new Config(path_1.join(pd, constants_1.FILENAME.config));
79
79
  }
80
- throw new error_1.default('Not in a Catalyst app directory (could not locate ' +
81
- constants_1.FILENAME.config +
82
- ') run catalyst init', {
83
- exit: 1
80
+ throw new error_1.default('Not in a Catalyst app directory', {
81
+ exit: 1,
82
+ errorId: 'CONFIG-2',
83
+ arg: [ansi_colors_1.bold(constants_1.FILENAME.config), ansi_colors_1.bold('catalyst init'), pd]
84
84
  });
85
85
  });
86
86
  }
@@ -22,13 +22,25 @@ const api_1 = __importDefault(require("./api"));
22
22
  const crypt_1 = __importDefault(require("./crypt"));
23
23
  const util_1 = require("util");
24
24
  const dc_1 = require("../dc");
25
+ const option_1 = require("../util_modules/option");
25
26
  class Credential {
26
27
  constructor(tokenObj) {
27
28
  if (tokenObj.token === undefined ||
28
29
  js_1.JS.isEmpty(tokenObj.token) ||
29
30
  tokenObj.token.slice(1, 2) !== '_') {
30
- throw new error_1.default('Invalid token passed for authentication. If you havent used --token option. kindly relogin with ' +
31
- ansi_colors_1.bold('catalyst login --force'));
31
+ const tokenOption = option_1.getGlobalOptionValue('token');
32
+ if (tokenOption) {
33
+ throw new error_1.default('Invalid token passed for authentication.', {
34
+ exit: 1,
35
+ errorId: 'CRED-1',
36
+ arg: [tokenOption, ansi_colors_1.bold('--token')]
37
+ });
38
+ }
39
+ throw new error_1.default('Invalid token for authentication', {
40
+ exit: 0,
41
+ errorId: 'CRED-2',
42
+ arg: [ansi_colors_1.bold('catalyst login --force')]
43
+ });
32
44
  }
33
45
  this.cToken = tokenObj.token;
34
46
  this.cTime = tokenObj.created_time;
@@ -110,7 +122,8 @@ class Credential {
110
122
  var _a, _b;
111
123
  return __awaiter(this, void 0, void 0, function* () {
112
124
  logger_1.debug('> refreshing access token <');
113
- const res = yield new api_1.default({ authNeeded: false }).post('/oauth/v2/token', {
125
+ const res = yield new api_1.default({ authNeeded: false })
126
+ .post('/oauth/v2/token', {
114
127
  origin: constants_1.ORIGIN.auth,
115
128
  form: {
116
129
  refresh_token: this.rToken,
@@ -121,11 +134,20 @@ class Credential {
121
134
  log: {
122
135
  skipReqBody: true
123
136
  }
137
+ })
138
+ .catch((err) => {
139
+ throw new error_1.default('Error when refreshing the access token', {
140
+ exit: 2,
141
+ original: err
142
+ });
124
143
  });
125
144
  if (!js_1.JS.isString(res.body.access_token)) {
126
- throw new error_1.default('unable to refresh access token. Kindly use ' +
127
- ansi_colors_1.bold('catalyst login --force') +
128
- ' to re-authenticate.', { original: util_1.inspect(res.body), exit: 2 });
145
+ throw new error_1.default('unable to refresh access token.', {
146
+ original: util_1.inspect(res.body),
147
+ exit: 0,
148
+ errorId: 'CRED-2',
149
+ arg: [ansi_colors_1.bold('catalyst login --force')]
150
+ });
129
151
  }
130
152
  this._rebuildTokenCache(res);
131
153
  return Credential.credentialObject;
@@ -191,7 +213,11 @@ class Credential {
191
213
  return __awaiter(this, void 0, void 0, function* () {
192
214
  if (Credential.globalSelf === null) {
193
215
  if (Credential.oneTimeToken === null) {
194
- throw new error_1.default('Authentication required, kindly login with ' + ansi_colors_1.bold('catalyst login'));
216
+ throw new error_1.default('Authentication required', {
217
+ exit: 0,
218
+ errorId: 'CRED-3',
219
+ arg: [ansi_colors_1.bold('catalyst login')]
220
+ });
195
221
  }
196
222
  return Credential.oneTimeToken;
197
223
  }
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const path_1 = require("path");
16
- const cjson_1 = __importDefault(require("../cjson"));
17
16
  const error_1 = __importDefault(require("../error"));
18
17
  const constants_1 = require("../util_modules/constants");
19
18
  const fs_1 = require("../util_modules/fs");
@@ -47,7 +46,9 @@ class RC {
47
46
  associateEnv(projectId, env, { base = false, active = false }) {
48
47
  const projectObj = this.getProjectById(projectId);
49
48
  if (projectObj === undefined) {
50
- throw new error_1.default('Unable to find project in RC file with project ID : ' + projectId);
49
+ throw new error_1.default('Unable to find project in RC file with project ID : ' + projectId, {
50
+ exit: 2
51
+ });
51
52
  }
52
53
  if (base && this.defaultProject !== undefined) {
53
54
  if (!js_1.JS.isEqual(this.defaultProject, projectObj)) {
@@ -68,7 +69,12 @@ class RC {
68
69
  let lastIdx = js_1.JS.size(envArr);
69
70
  let envIdx = -1;
70
71
  if (existingEnvArr.length !== 1) {
71
- envArr.push({ idx: ++lastIdx, id: env.id + '', name: env.name, type: env.type });
72
+ envArr.push({
73
+ idx: ++lastIdx,
74
+ id: env.id + '',
75
+ name: env.name,
76
+ type: env.type
77
+ });
72
78
  envIdx = lastIdx;
73
79
  }
74
80
  else {
@@ -92,7 +98,9 @@ class RC {
92
98
  removeEnv(projectId, envId) {
93
99
  const projectObj = this.getProjectById(projectId);
94
100
  if (projectObj === undefined) {
95
- throw new error_1.default('Unable to find project in RC file with project ID : ' + projectId, { exit: 2 });
101
+ throw new error_1.default('Unable to find project in RC file with project ID : ' + projectId, {
102
+ exit: 2
103
+ });
96
104
  }
97
105
  const envArr = js_1.JS.get(projectObj, 'env', []);
98
106
  const removedEnvArr = js_1.JS.remove(envArr, (obj) => obj.id + '' === envId + '');
@@ -254,13 +262,13 @@ class RC {
254
262
  }
255
263
  static loadFile(rcpath) {
256
264
  return __awaiter(this, void 0, void 0, function* () {
257
- if (yield fs_1.ASYNC.fileExists(rcpath)) {
258
- const data = cjson_1.default(rcpath);
259
- const rc = new RC(rcpath, data);
260
- rc.loaded = true;
261
- return rc;
265
+ const data = yield fs_1.ASYNC.readJSONFile(rcpath, { checkpath: true });
266
+ if (data === undefined) {
267
+ return new RC(rcpath);
262
268
  }
263
- return new RC(rcpath);
269
+ const rc = new RC(rcpath, data);
270
+ rc.loaded = true;
271
+ return rc;
264
272
  });
265
273
  }
266
274
  static load() {
@@ -6,10 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.migrate = exports.isRequire = void 0;
7
7
  const config_store_1 = __importDefault(require("../../config-store"));
8
8
  const constants_1 = require("../../util_modules/constants");
9
- exports.isRequire = () => {
9
+ const isRequire = () => {
10
10
  return config_store_1.default.has('credential');
11
11
  };
12
- exports.migrate = () => {
12
+ exports.isRequire = isRequire;
13
+ const migrate = () => {
13
14
  const backup = Object.assign({}, config_store_1.default.store);
14
15
  const dcObj = {
15
16
  [constants_1.DC_TYPE.us.value]: backup,
@@ -17,3 +18,4 @@ exports.migrate = () => {
17
18
  };
18
19
  config_store_1.default.store = dcObj;
19
20
  };
21
+ exports.migrate = migrate;
@@ -8,10 +8,11 @@ const ansi_colors_1 = require("ansi-colors");
8
8
  const config_store_1 = __importDefault(require("../../config-store"));
9
9
  const constants_1 = require("../../util_modules/constants");
10
10
  const logger_1 = require("../../util_modules/logger");
11
- exports.isRequire = () => {
11
+ const isRequire = () => {
12
12
  return config_store_1.default.has('active_dc') || config_store_1.default.has(constants_1.DEFAULT.dc);
13
13
  };
14
- exports.migrate = () => {
14
+ exports.isRequire = isRequire;
15
+ const migrate = () => {
15
16
  const activeDc = config_store_1.default.get('active_dc', constants_1.DEFAULT.dc);
16
17
  const usage = config_store_1.default.get(`${activeDc}.usage`, false);
17
18
  config_store_1.default.set('usage', usage);
@@ -26,3 +27,4 @@ exports.migrate = () => {
26
27
  'The usage statistics collection will be done based on the consent provided with the login.');
27
28
  logger_1.info();
28
29
  };
30
+ exports.migrate = migrate;