@sap/cli-core 2024.3.0 → 2024.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +1 -1
  3. package/commands/config.command/cache.command/{init.command.d.ts → init.command/index.d.ts} +1 -1
  4. package/commands/config.command/cache.command/init.command/index.js +71 -0
  5. package/commands/config.command/cache.command/init.command/utils.d.ts +3 -0
  6. package/commands/config.command/cache.command/init.command/utils.js +20 -0
  7. package/commands/config.command/cache.command/show.command.js +1 -1
  8. package/commands/config.command/host.command.js +1 -1
  9. package/commands/config.command/passcode.command.js +1 -1
  10. package/commands/config.command/secrets.command/reset.command.js +1 -1
  11. package/commands/config.command/secrets.command/show.command.js +1 -1
  12. package/commands/handler/authentication/index.js +2 -2
  13. package/commands/handler/authentication/oauth/index.js +1 -1
  14. package/commands/handler/authentication/oauth/secretsProvider/file.js +1 -1
  15. package/commands/handler/authentication/oauth/secretsProvider/index.js +1 -1
  16. package/commands/handler/authentication/oauth/secretsProvider/options.js +1 -1
  17. package/commands/handler/authentication/oauth/tokenProvider/getToken.js +1 -1
  18. package/commands/handler/authentication/oauth/tokenProvider/index.js +1 -1
  19. package/commands/handler/authentication/passcode/index.js +1 -1
  20. package/commands/handler/authentication/technicalJWT/index.js +1 -1
  21. package/commands/handler/fetch/index.js +1 -1
  22. package/commands/handler/fetch/utils.js +3 -0
  23. package/commands/handler/input/file.js +1 -1
  24. package/commands/handler/input/index.js +1 -1
  25. package/commands/handler/input/input.js +1 -1
  26. package/commands/handler/mandatoryOptions.js +1 -1
  27. package/commands/handler/next.d.ts +1 -1
  28. package/commands/handler/next.js +8 -2
  29. package/commands/handler/options/index.js +2 -2
  30. package/commands/handler/options/utils.js +2 -1
  31. package/commands/handler/or.d.ts +1 -1
  32. package/commands/handler/or.js +8 -3
  33. package/commands/handler/utils.d.ts +1 -0
  34. package/commands/handler/utils.js +3 -2
  35. package/commands/login.command.d.ts +2 -1
  36. package/commands/login.command.js +5 -3
  37. package/commands/logout.command.js +1 -1
  38. package/commands/openAPI.command/index.js +1 -1
  39. package/commands/openAPI.command/utils.js +17 -1
  40. package/config/core.d.ts +1 -1
  41. package/config/core.js +3 -3
  42. package/config/index.js +1 -1
  43. package/constants.d.ts +14 -1
  44. package/constants.js +25 -2
  45. package/discovery/index.js +1 -1
  46. package/dwc/dwc.js +13 -8
  47. package/dwc/utils.d.ts +1 -1
  48. package/dwc/utils.js +4 -4
  49. package/index.d.ts +2 -2
  50. package/index.js +2 -2
  51. package/package.json +6 -6
  52. package/types.d.ts +1 -0
  53. package/utils/commands.d.ts +4 -3
  54. package/utils/commands.js +43 -31
  55. package/utils/utils.d.ts +1 -1
  56. package/utils/utils.js +2 -2
  57. package/commands/config.command/cache.command/init.command.js +0 -43
package/CHANGELOG.md CHANGED
@@ -5,6 +5,70 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2024.5.0
9
+
10
+ ### Fixed
11
+
12
+ - Fixed an issue with parsing the discovery document if more than 52 distinct options are defined. Now, the short flags are calculated per command. This allows for having up to 52 options per command. However, the same option used across different commands might not share the same short flag depending on other available options for the commands. It is recommended to always use the option's long name as the long name remains stable.
13
+
14
+ ## 2024.4.0
15
+
16
+ ### Added
17
+
18
+ - Support for Node versions `18`, `19`, `20`, `21`.
19
+
20
+ - When using the CLI as a [As a Node.js module dependency](README.md#as-a-nodejs-module-dependency) and running a command which creates an entity where the CLI would print the command to retrieve the result when running the command to create the entity in the terminal, for example:
21
+
22
+ ```bash
23
+ <cli> spaces create -H https://mytenant.eu10.hcs.cloud.sap/ -f ./MY_SPACE.json
24
+ Use <cli> spaces read --space-id MY_SPACE to retrieve the entity you just created
25
+ ```
26
+
27
+ the CLI now returns the command to execute as an object:
28
+
29
+ ```bash
30
+ const retrieveCommand = await commands["spaces create"]({
31
+ "--file-path": "MY_SPACE.json",
32
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
33
+ });
34
+
35
+ console.log(retrieveCommand);
36
+ // {
37
+ // command: "spaces read",
38
+ // options: {
39
+ // "--space-id": "MY_SPACE"
40
+ // },
41
+ // }
42
+ ```
43
+
44
+ You can use the returned response to immediately issue the command to read the entity:
45
+
46
+ ```bash
47
+ const retrieveCommand = await commands["spaces create"]({
48
+ "--file-path": "MY_SPACE.json",
49
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
50
+ });
51
+
52
+ const response = await commands[retrieveCommand.command]({
53
+ ...retrieveCommand.options,
54
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
55
+ });
56
+
57
+ console.log(response);
58
+ // {
59
+ // MY_SPACE: {
60
+ // version: "1.0.4",
61
+ // ...
62
+ // }
63
+ // }
64
+ ```
65
+
66
+ - The CLI core module now supports retrieving the discovery documents from multiple endpoints for the same tenant. This allows you to define a list of endpoints from which the discovery documents should be retrieved. Multiple services, reachable through the same tenant, can expose their own, distinct discovery documents. There is no need to have a single service expose the full document for the tenant. The retrieved discovery documents are merged into a single document. All commands are shown to the user, not distinguished by endpoint or service. Only OAuth authentication is supported when specifying multiple endpoints.
67
+
68
+ ### Fixed
69
+
70
+ - When the host is globally configured via the command `<cli> config host set <host>`, any other host specified via option `-H, --host` was ignored when running a command. This often led to confusion when users specify the host explicitly via option `-H, --host`, but are not aware that the host was globally configured, too. Now, option `-H, --host` always takes precedence over the globally configured host.
71
+
8
72
  ## 2024.2.0
9
73
 
10
74
  ### Changed
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Command-Line Interface (CLI) Core Module.
4
4
 
5
- [![Node Version](https://img.shields.io/badge/node-20.10.0-brightgreen)](https://nodejs.org/dist/latest-v20.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](https://badge.fury.io/js/@sap%2Fcli-core)
5
+ [![Node Version](https://img.shields.io/badge/node-18.xx.x-brightgreen)](https://nodejs.org/dist/latest-v18.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-19.xx.x-brightgreen)](https://nodejs.org/dist/latest-v19.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-20.xx.x-brightgreen)](https://nodejs.org/dist/latest-v20.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-21.xx.x-brightgreen)](https://nodejs.org/dist/latest-v21.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](https://badge.fury.io/js/@sap%2Fcli-core)
6
6
 
7
7
  ## Content
8
8
 
@@ -1,4 +1,4 @@
1
- import { CommanderHandler, LeafCommand } from "../../../types";
1
+ import { CommanderHandler, LeafCommand } from "../../../../types";
2
2
  export declare const init: () => Promise<CommanderHandler>;
3
3
  declare const initCommand: LeafCommand;
4
4
  export default initCommand;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /* eslint-disable no-await-in-loop */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.init = void 0;
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const constants_1 = require("../../../../constants");
10
+ const discovery_1 = require("../../../../discovery");
11
+ const handler_1 = require("../../../handler");
12
+ const config_1 = require("../../../../config");
13
+ const core_1 = require("../../../../config/core");
14
+ const ResultHandlerFactory_1 = require("../../../../result/ResultHandlerFactory");
15
+ const utils_1 = require("./utils");
16
+ const utils_2 = require("../../../handler/utils");
17
+ const logger_1 = require("../../../../logger");
18
+ const pre = () => {
19
+ (0, config_1.set)({
20
+ doNotStoreResult: false,
21
+ doNotProcessResponseData: true,
22
+ });
23
+ };
24
+ const post = async (discovery) => {
25
+ const config = (0, config_1.get)();
26
+ await (0, discovery_1.addMetadata)({
27
+ tenant: config.publicfqdn,
28
+ addedAt: new Date().getTime(),
29
+ });
30
+ (0, discovery_1.clear)();
31
+ const { options } = config;
32
+ delete options[constants_1.OPTION_OUTPUT.longName];
33
+ (0, config_1.set)({ options });
34
+ ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(undefined);
35
+ await fs_extra_1.default.writeFile((0, discovery_1.getPathToDiscoveryDocument)(), JSON.stringify(discovery));
36
+ };
37
+ const init = async () => async () => {
38
+ pre();
39
+ const { output } = (0, logger_1.get)("init.command");
40
+ const discovery = {
41
+ info: {
42
+ version: constants_1.VERSION,
43
+ "x-document-version": constants_1.VERSION,
44
+ },
45
+ openapi: "3.0.3",
46
+ paths: {},
47
+ tags: [],
48
+ components: {},
49
+ };
50
+ const paths = (0, core_1.getDiscoveryPaths)();
51
+ if (paths.length > 1 &&
52
+ (0, utils_2.getAuthenticationMethod)() !== constants_1.AuthenticationMethod.oauth) {
53
+ output("Only OAuth authentication is supported");
54
+ throw new Error("only oauth authentication is supported");
55
+ }
56
+ for (const path of paths) {
57
+ await (await (0, handler_1.createFetchHandler)("GET", path)({}))();
58
+ const newDiscovery = ResultHandlerFactory_1.ResultHandlerFactory.get().getResult();
59
+ (0, utils_1.mergeDiscoveries)(discovery, newDiscovery);
60
+ }
61
+ await post(discovery);
62
+ };
63
+ exports.init = init;
64
+ const initCommand = {
65
+ type: "command",
66
+ command: "init",
67
+ description: "initialize the local CLI cache",
68
+ options: [],
69
+ handler: (0, handler_1.createNextHandler)("command.config.cache.init", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
70
+ };
71
+ exports.default = initCommand;
@@ -0,0 +1,3 @@
1
+ import { Discovery } from "../../../../types";
2
+ export declare function getLowerVersion(a: string, b: string): string;
3
+ export declare function mergeDiscoveries(discovery: Discovery, newDiscovery: Discovery): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.mergeDiscoveries = exports.getLowerVersion = void 0;
7
+ const compare_versions_1 = require("compare-versions");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ function getLowerVersion(a, b) {
10
+ return [a, b].sort(compare_versions_1.compareVersions)[0];
11
+ }
12
+ exports.getLowerVersion = getLowerVersion;
13
+ function mergeDiscoveries(discovery, newDiscovery) {
14
+ lodash_1.default.merge(discovery, newDiscovery);
15
+ // eslint-disable-next-line no-param-reassign
16
+ discovery.info.version = getLowerVersion(discovery.info.version, newDiscovery.info.version);
17
+ // eslint-disable-next-line no-param-reassign
18
+ discovery.info["x-document-version"] = getLowerVersion(discovery.info["x-document-version"], newDiscovery.info["x-document-version"]);
19
+ }
20
+ exports.mergeDiscoveries = mergeDiscoveries;
@@ -25,6 +25,6 @@ const showCommand = {
25
25
  type: "command",
26
26
  command: "show",
27
27
  description: "display local CLI cache entries",
28
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), show),
28
+ handler: (0, handler_1.createNextHandler)("command.config.cache.show", (0, handler_1.createParseArgumentsHandler)(), show),
29
29
  };
30
30
  exports.default = showCommand;
@@ -48,7 +48,7 @@ const addCommands = async (program) => {
48
48
  command: "set",
49
49
  description: "set global host",
50
50
  args: [{ argument: "host", description: "global host" }],
51
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)([{ argument: "host" }]), set),
51
+ handler: (0, handler_1.createNextHandler)("command.config.host.set", (0, handler_1.createParseArgumentsHandler)([{ argument: "host" }]), set),
52
52
  },
53
53
  {
54
54
  type: "command",
@@ -16,7 +16,7 @@ const passcodeCommand = {
16
16
  type: "command",
17
17
  command: "passcode-url",
18
18
  description: "display the passcode url",
19
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), passcode),
19
+ handler: (0, handler_1.createNextHandler)("commands.config.passcode-url", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), passcode),
20
20
  };
21
21
  const addCommands = async (program) => {
22
22
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
@@ -12,6 +12,6 @@ const resetCommand = {
12
12
  type: "command",
13
13
  command: "reset",
14
14
  description: "remove all locally stored secrets for interactive OAuth authentication",
15
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), removeSecrets),
15
+ handler: (0, handler_1.createNextHandler)("commands.config.secrets.reset", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), removeSecrets),
16
16
  };
17
17
  exports.default = resetCommand;
@@ -27,6 +27,6 @@ const showCommand = {
27
27
  type: "command",
28
28
  command: "show",
29
29
  description: "display locally stored secrets for interactive OAuth authentication",
30
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), showSecrets),
30
+ handler: (0, handler_1.createNextHandler)("commands.config.secrets.show", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), showSecrets),
31
31
  };
32
32
  exports.default = showCommand;
@@ -16,6 +16,6 @@ const core_1 = require("../../../config/core");
16
16
  const succeed_1 = require("../succeed");
17
17
  exports.create = process.env.SUPPORT === "true"
18
18
  ? technicalJWT_1.create
19
- : () => (0, next_1.create)((0, resilient_1.create)((0, next_1.create)((0, cache_1.create)(), (0, refreshToken_1.create)())), (0, options_1.create)(constants_1.OPTION_CLIENT_ID), (0, options_1.create)(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, options_1.create)(constants_1.OPTION_REFRESH_TOKEN), (0, options_1.create)(constants_1.OPTION_CODE), (0, options_1.create)(constants_1.OPTION_TOKEN_URL), (0, options_1.create)(constants_1.OPTION_AUTHORIZATION_URL), (0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)
19
+ : () => (0, next_1.create)("commands.handler.authentication", (0, resilient_1.create)((0, next_1.create)("commands.handler.authentication$oauth", (0, cache_1.create)(), (0, refreshToken_1.create)())), (0, options_1.create)(constants_1.OPTION_CLIENT_ID), (0, options_1.create)(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, options_1.create)(constants_1.OPTION_REFRESH_TOKEN), (0, options_1.create)(constants_1.OPTION_CODE), (0, options_1.create)(constants_1.OPTION_TOKEN_URL), (0, options_1.create)(constants_1.OPTION_AUTHORIZATION_URL), (0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)
20
20
  ? (0, options_1.create)(constants_1.OPTION_PASSCODE)
21
- : (0, succeed_1.create)(), (0, options_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)((0, setAuthorization_1.create)(), (0, passcode_1.create)(), (0, oauth_1.create)()));
21
+ : (0, succeed_1.create)(), (0, options_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)("commands.handler.authentication$handler", (0, setAuthorization_1.create)(), (0, passcode_1.create)(), (0, oauth_1.create)()));
@@ -11,7 +11,7 @@ const constants_1 = require("../../../../constants");
11
11
  const core_1 = require("../../../../config/core");
12
12
  const create = () => {
13
13
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.oauth)) {
14
- return (0, error_1.create)("failed to handle OAuth authorization", (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_PASSCODE), (0, secretsProvider_1.create)(), (0, tokenProvider_1.create)()));
14
+ return (0, error_1.create)("failed to handle OAuth authorization", (0, next_1.create)("commands.handler.authentication.oauth", (0, checkOptionsExistence_1.create)(constants_1.OPTION_PASSCODE), (0, secretsProvider_1.create)(), (0, tokenProvider_1.create)()));
15
15
  }
16
16
  return (0, fail_1.create)();
17
17
  };
@@ -21,5 +21,5 @@ const handler = async () => async () => {
21
21
  throw err;
22
22
  }
23
23
  };
24
- const create = () => (0, next_1.create)((0, options_2.create)([constants_1.OPTION_SECRETS_FILE]), handler);
24
+ const create = () => (0, next_1.create)("commands.handler.authentication.oauth.secretsProvider.file", (0, options_2.create)([constants_1.OPTION_SECRETS_FILE]), handler);
25
25
  exports.create = create;
@@ -6,5 +6,5 @@ const error_1 = require("../../../error");
6
6
  const options_1 = require("./options");
7
7
  const file_1 = require("./file");
8
8
  const cache_1 = require("./cache");
9
- const create = () => (0, error_1.create)("Failed to read secrets from cache, file or options", (0, or_1.create)((0, cache_1.create)(), (0, file_1.create)(), (0, options_1.create)()));
9
+ const create = () => (0, error_1.create)("Failed to read secrets from cache, file or options", (0, or_1.create)("commands.handler.authentication.oauth.secretsProvider", (0, cache_1.create)(), (0, file_1.create)(), (0, options_1.create)()));
10
10
  exports.create = create;
@@ -27,7 +27,7 @@ const pre = async () => async () => {
27
27
  const { info } = getLogger();
28
28
  info("reading secrets from options");
29
29
  };
30
- const create = () => (0, next_1.create)(pre, (0, or_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN, false), (0, next_1.create)(createOptHandler(constants_1.OPTION_CLIENT_ID), createOptHandler(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)([
30
+ const create = () => (0, next_1.create)("handler.authentication.oauth.secretsProvider.options$outer", pre, (0, or_1.create)("commands.handler.authentication.oauth.secretsProvider.options", (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN, false), (0, next_1.create)("handler.authentication.oauth.secretsProvider.options$inner", createOptHandler(constants_1.OPTION_CLIENT_ID), createOptHandler(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)([
31
31
  constants_1.OPTION_AUTHORIZATION_URL,
32
32
  constants_1.OPTION_TOKEN_URL,
33
33
  constants_1.OPTION_REFRESH_TOKEN,
@@ -28,5 +28,5 @@ const handler = async () => async () => {
28
28
  throw new Error("access token not available");
29
29
  }
30
30
  };
31
- const create = () => (0, next_1.create)((0, options_1.create)(constants_1.OPTION_CODE), handler);
31
+ const create = () => (0, next_1.create)("commands.handler.authentication.oauth.tokenProvider.getToken", (0, options_1.create)(constants_1.OPTION_CODE), handler);
32
32
  exports.create = create;
@@ -7,5 +7,5 @@ const or_1 = require("../../../or");
7
7
  const refreshToken_1 = require("./refreshToken");
8
8
  const setAuthorization_1 = require("./setAuthorization");
9
9
  const getToken_1 = require("./getToken");
10
- const create = () => (0, error_1.create)("failed to handle token", (0, next_1.create)((0, or_1.create)((0, getToken_1.create)(), (0, refreshToken_1.create)(true)), (0, setAuthorization_1.create)()));
10
+ const create = () => (0, error_1.create)("failed to handle token", (0, next_1.create)("commands.handler.authentication.oauth.tokenProvider", (0, or_1.create)("commands.handler.authentication.oauth.tokenProvider", (0, getToken_1.create)(), (0, refreshToken_1.create)(true)), (0, setAuthorization_1.create)()));
11
11
  exports.create = create;
@@ -12,7 +12,7 @@ const constants_1 = require("../../../../constants");
12
12
  const core_1 = require("../../../../config/core");
13
13
  const create = () => {
14
14
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
15
- return (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_CLIENT_ID), (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, checkOptionsExistence_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)((0, function_1.create)(), (0, input_1.create)()), (0, setPasscode_1.create)());
15
+ return (0, next_1.create)("commands.handler.authentication.passcode", (0, checkOptionsExistence_1.create)(constants_1.OPTION_CLIENT_ID), (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, checkOptionsExistence_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)("commands.handler.authentication.passcode$value", (0, function_1.create)(), (0, input_1.create)()), (0, setPasscode_1.create)());
16
16
  }
17
17
  return (0, fail_1.create)();
18
18
  };
@@ -6,7 +6,7 @@ const commands_1 = require("../../../../utils/commands");
6
6
  const types_1 = require("./types");
7
7
  const utils_1 = require("./utils");
8
8
  const create = () => async (command) => {
9
- command.addOption(await (0, commands_1.buildOption)(types_1.OPTION_SECRET));
9
+ command.addOption(await (0, commands_1.buildOption)(command.name(), types_1.OPTION_SECRET));
10
10
  return async () => {
11
11
  const token = await (0, utils_1.getTechnicalJwt)();
12
12
  (0, config_1.set)({ authorization: { Authorization: `Bearer ${token}` } });
@@ -18,7 +18,7 @@ const createCsrfTokenFetchHandler = (path, parameterMappings) => (0, fetch_1.cre
18
18
  const create = (method, path, parameterMappings, responsePostProcessor) => {
19
19
  /* jscpd:ignore-end */
20
20
  if (requiresCsrfToken(parameterMappings)) {
21
- return (0, next_1.create)(createCsrfTokenFetchHandler(path, parameterMappings), (0, fetch_1.create)(method, path, parameterMappings, responsePostProcessor));
21
+ return (0, next_1.create)("commands.handler.fetch", createCsrfTokenFetchHandler(path, parameterMappings), (0, fetch_1.create)(method, path, parameterMappings, responsePostProcessor));
22
22
  }
23
23
  return (0, fetch_1.create)(method, path, parameterMappings, responsePostProcessor);
24
24
  };
@@ -123,6 +123,9 @@ const handleResponseData = async (data, outputPath) => {
123
123
  if (!config.doNotStoreResult) {
124
124
  ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(data);
125
125
  }
126
+ if (config.doNotProcessResponseData) {
127
+ return;
128
+ }
126
129
  const { output } = (0, logger_1.get)("handler.fetch");
127
130
  const formatted = config.options.pretty
128
131
  ? JSON.stringify(data, null, 2)
@@ -30,5 +30,5 @@ const readBodyFromFile = async () => async () => {
30
30
  throw err;
31
31
  }
32
32
  };
33
- const create = () => (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_INPUT), (0, options_1.create)(constants_1.OPTION_FILE_PATH, { readEnv: true, readFile: true, readOptions: true }, true, true), readBodyFromFile);
33
+ const create = () => (0, next_1.create)("file.input.handler", (0, checkOptionsExistence_1.create)(constants_1.OPTION_INPUT), (0, options_1.create)(constants_1.OPTION_FILE_PATH, { readEnv: true, readFile: true, readOptions: true }, true, true), readBodyFromFile);
34
34
  exports.create = create;
@@ -4,5 +4,5 @@ exports.create = void 0;
4
4
  const or_1 = require("../or");
5
5
  const input_1 = require("./input");
6
6
  const file_1 = require("./file");
7
- const create = () => (0, or_1.create)((0, file_1.create)(), (0, input_1.create)());
7
+ const create = () => (0, or_1.create)("commands.handler.input", (0, file_1.create)(), (0, input_1.create)());
8
8
  exports.create = create;
@@ -10,7 +10,7 @@ const constants_1 = require("../../../constants");
10
10
  const logger_1 = require("../../../logger");
11
11
  const commands_1 = require("../../../utils/commands");
12
12
  const create = () => async (command) => {
13
- command.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_INPUT));
13
+ command.addOption(await (0, commands_1.buildOption)(command.name(), constants_1.OPTION_INPUT));
14
14
  return async () => {
15
15
  const config = (0, config_1.get)();
16
16
  const { debug } = (0, logger_1.get)("handler.input.input");
@@ -21,5 +21,5 @@ const post = async () => async () => {
21
21
  }
22
22
  }
23
23
  };
24
- const create = () => (0, next_1.create)((0, options_1.create)(MANDATORY_OPTIONS), post);
24
+ const create = () => (0, next_1.create)("mandatoryOptions.handler", (0, options_1.create)(MANDATORY_OPTIONS), post);
25
25
  exports.create = create;
@@ -1,2 +1,2 @@
1
1
  import { Handler } from "../../types";
2
- export declare const create: (...handlers: Array<Handler>) => Handler;
2
+ export declare const create: (origin: string, ...handlers: Array<Handler>) => Handler;
@@ -2,19 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
4
  const stackTrace_1 = require("./stackTrace");
5
- const nextHandler = (...handlers) => async (command) => {
5
+ const logger_1 = require("../../logger");
6
+ function getLogger(origin) {
7
+ return (0, logger_1.get)(`commands.handler.next:${origin}`);
8
+ }
9
+ const nextHandler = (origin, ...handlers) => async (command) => {
10
+ getLogger(origin).trace(`next:${origin}: preparing handlers`);
6
11
  const commandHandlers = [];
7
12
  for (const handler of handlers) {
8
13
  // eslint-disable-next-line no-await-in-loop
9
14
  commandHandlers.push(await handler(command));
10
15
  }
11
16
  return async (...args) => {
17
+ getLogger(origin).trace(`next:${origin}: processing handlers`);
12
18
  for (const handler of commandHandlers) {
13
19
  // eslint-disable-next-line
14
20
  await handler(...args);
15
21
  }
16
22
  };
17
23
  };
18
- const create = (...handlers) => (0, stackTrace_1.create)(nextHandler(...handlers));
24
+ const create = (origin, ...handlers) => (0, stackTrace_1.create)(nextHandler(origin, ...handlers));
19
25
  exports.create = create;
20
26
  /* jscpd:ignore-end */
@@ -11,7 +11,7 @@ const option_1 = require("./option");
11
11
  const succeed_1 = require("../succeed");
12
12
  const fail_1 = require("../fail");
13
13
  const env_1 = require("./env");
14
- const createHandler = (use, option, handler) => (0, next_1.create)((0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
14
+ const createHandler = (use, option, handler) => (0, next_1.create)("commands.handler.options", (0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
15
15
  const create = (options, { readEnv, readFile, readOptions } = {
16
16
  readEnv: true,
17
17
  readFile: true,
@@ -21,7 +21,7 @@ const create = (options, { readEnv, readFile, readOptions } = {
21
21
  await (0, utils_1.checkOptions)(intOptions, command);
22
22
  return async () => {
23
23
  for (const option of intOptions) {
24
- const handler = (0, or_1.create)((0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)(createHandler(readEnv, option, (0, env_1.create)(option)), createHandler(readFile, option, (0, file_1.create)(option)), createHandler(readOptions, option, (0, option_1.create)(option, promptAlways))), throwIfHandlersFailed
24
+ const handler = (0, or_1.create)("commands.handler.options$outer", (0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)("commands.handler.options$inner", createHandler(readEnv, option, (0, env_1.create)(option)), createHandler(readFile, option, (0, file_1.create)(option)), createHandler(readOptions, option, (0, option_1.create)(option, promptAlways))), throwIfHandlersFailed
25
25
  ? (0, fail_1.create)()
26
26
  : (0, succeed_1.create)());
27
27
  await (await handler(command))();
@@ -13,8 +13,9 @@ const checkOptions = async (options, command) => {
13
13
  const intOptions = Array.isArray(options) ? options : [options];
14
14
  for (const option of intOptions) {
15
15
  if (!(0, commands_1.isOptionAlreadyRegistered)(option, command)) {
16
+ command.addOption(
16
17
  // eslint-disable-next-line no-await-in-loop
17
- command.addOption(await (0, commands_1.buildOption)({ ...option, required: false }));
18
+ await (0, commands_1.buildOption)(command.name(), { ...option, required: false }));
18
19
  }
19
20
  }
20
21
  };
@@ -1,2 +1,2 @@
1
1
  import { Handler } from "../../types";
2
- export declare const create: (...handlers: Array<Handler>) => Handler;
2
+ export declare const create: (origin: string, ...handlers: Array<Handler>) => Handler;
@@ -2,17 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
4
  const logger_1 = require("../../logger");
5
- const getLogger = () => (0, logger_1.get)("commands.handlers.or");
6
- const create = (...handlers) => {
5
+ function getLogger(origin) {
6
+ return (0, logger_1.get)(`commands.handler.or:${origin}`);
7
+ }
8
+ const create = (origin, ...handlers) => {
7
9
  const { stack } = new Error();
8
10
  return async (command) => {
11
+ const { trace } = getLogger(origin);
12
+ trace(`or:${origin}: preparing handlers`);
9
13
  const commandHandlers = [];
10
14
  for (const handler of handlers) {
11
15
  // eslint-disable-next-line no-await-in-loop
12
16
  commandHandlers.push(await handler(command));
13
17
  }
14
18
  return async (...args) => {
15
- const { debug, trace } = getLogger();
19
+ const { debug } = getLogger(origin);
20
+ trace(`or:${origin}: processing handlers`);
16
21
  let handlerFailed = false;
17
22
  for (const handler of commandHandlers) {
18
23
  handlerFailed = false;
@@ -1,5 +1,6 @@
1
1
  import { AuthenticationMethod } from "../../constants";
2
2
  export declare const getBooleanOption: (value: unknown) => boolean;
3
+ export declare const replaceLeadingTrailingSingleQuotes: (value: string) => string;
3
4
  export declare const parseOption: (value: string) => string;
4
5
  export declare const setAuthenticationMethod: (authenticationMethod: AuthenticationMethod) => void;
5
6
  export declare const getAuthenticationMethod: () => AuthenticationMethod;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTargetHost = exports.setTargetHost = exports.getAuthenticationMethod = exports.setAuthenticationMethod = exports.parseOption = exports.getBooleanOption = void 0;
3
+ exports.getTargetHost = exports.setTargetHost = exports.getAuthenticationMethod = exports.setAuthenticationMethod = exports.parseOption = exports.replaceLeadingTrailingSingleQuotes = exports.getBooleanOption = void 0;
4
4
  const logger_1 = require("../../logger");
5
5
  const config_1 = require("../../config");
6
6
  const constants_1 = require("../../constants");
@@ -24,13 +24,14 @@ const replaceLeadingTrailingSingleQuotes = (value) => {
24
24
  }
25
25
  return value;
26
26
  };
27
+ exports.replaceLeadingTrailingSingleQuotes = replaceLeadingTrailingSingleQuotes;
27
28
  const parseOption = (value) => {
28
29
  if (typeof value !== "string") {
29
30
  return value;
30
31
  }
31
32
  let v = value.trim();
32
33
  v = decodeURIComponentInt(v);
33
- v = replaceLeadingTrailingSingleQuotes(v);
34
+ v = (0, exports.replaceLeadingTrailingSingleQuotes)(v);
34
35
  return v;
35
36
  };
36
37
  exports.parseOption = parseOption;
@@ -1,3 +1,4 @@
1
- import { LeafCommand } from "../types";
1
+ import { CommanderHandler, LeafCommand } from "../types";
2
+ export declare const verifyHost: () => Promise<CommanderHandler>;
2
3
  declare const loginCommand: LeafCommand;
3
4
  export default loginCommand;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyHost = void 0;
3
4
  const handler_1 = require("./handler");
4
5
  const constants_1 = require("../constants");
5
6
  const logger_1 = require("../logger");
@@ -23,6 +24,7 @@ const verifyHost = async () => async () => {
23
24
  throw new Error("tenant URL not defined. use option -H, --host");
24
25
  }
25
26
  };
27
+ exports.verifyHost = verifyHost;
26
28
  const initializeCache = async () => async () => {
27
29
  const { warn, info } = getLogger();
28
30
  info("initializing cache after successful login");
@@ -31,7 +33,7 @@ const initializeCache = async () => async () => {
31
33
  await (await (0, init_command_1.init)())();
32
34
  }
33
35
  catch (err) {
34
- warn(`option ${(0, utils_3.buildOptionName)(constants_1.OPTION_HOST)} not defined, skipping cache init`);
36
+ warn(`option ${(0, utils_3.buildOptionName)(constants_1.ROOT_COMMAND_NAME, constants_1.OPTION_HOST)} not defined, skipping cache init`);
35
37
  }
36
38
  };
37
39
  const loginCommand = {
@@ -39,7 +41,7 @@ const loginCommand = {
39
41
  command: "login",
40
42
  description: "log in to your account using interactive OAuth authentication",
41
43
  options: [],
42
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
44
+ handler: (0, handler_1.createNextHandler)("login.command", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
43
45
  { ...constants_1.OPTION_HOST, hidden: false, required: true },
44
46
  constants_1.OPTION_VERBOSE,
45
47
  constants_1.OPTION_OPTIONS_FILE,
@@ -56,6 +58,6 @@ const loginCommand = {
56
58
  choices: utils_4.getBrowserChoices,
57
59
  default: openUtils_1.getDefaultBrowser,
58
60
  },
59
- ]), (0, handler_1.createMandatoryOptionsHandler)(), verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
61
+ ]), (0, handler_1.createMandatoryOptionsHandler)(), exports.verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
60
62
  };
61
63
  exports.default = loginCommand;
@@ -22,7 +22,7 @@ const logoutCommand = {
22
22
  type: "command",
23
23
  command: "logout",
24
24
  description: "log out from your account",
25
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
25
+ handler: (0, handler_1.createNextHandler)("logout.command", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
26
26
  { ...constants_1.OPTION_LOGIN_ID, choices: utils_2.getChoices },
27
27
  constants_1.OPTION_VERBOSE,
28
28
  ]), handler),
@@ -45,7 +45,7 @@ const addCommandToArray = (document, commands, segments, index) => {
45
45
  };
46
46
  const setHandler = (command, method, path, parameterMappings, readPathResponseHandler, ...handler) => {
47
47
  // eslint-disable-next-line
48
- command.handler = (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), ...handler, (0, handler_1.createFetchHandler)(method, path, parameterMappings, readPathResponseHandler));
48
+ command.handler = (0, handler_1.createNextHandler)("openAPI.command", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), ...handler, (0, handler_1.createFetchHandler)(method, path, parameterMappings, readPathResponseHandler));
49
49
  };
50
50
  const addCommands = async (program) => {
51
51
  const { error, debug, trace } = getLogger();