@sap/cli-core 2023.18.0 → 2023.23.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,40 @@ 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
+ ## 2023.23.0
9
+
10
+ ### Fixed
11
+
12
+ - Trailing single quotes (`'`) were removed from option values even though there was no leading single quote. This version contains a fix that trailing single quotes are only removed if there is a leading single quote.
13
+
14
+ Trailing single quote is not removed: `some 'value'` stays `some 'value'`.
15
+
16
+ Trailing single quote is removed: `'some value'` becomes `some value`.
17
+
18
+ - The help output did not mention the correct CLI name. Instead the output showed the name 'terminal'.
19
+
20
+ ```javascript
21
+ Usage: terminal [options] [command]
22
+
23
+ Command-Line Interface for <product name>.
24
+ ...
25
+ ```
26
+
27
+ Since this version, the name is shown correctly.
28
+
29
+ ```javascript
30
+ Usage: <cli> [options] [command]
31
+
32
+ Command-Line Interface for <product name>.
33
+ ...
34
+ ```
35
+
36
+ ## 2023.19.0
37
+
38
+ ### Fixed
39
+
40
+ - Logging in failed if required information such as the client ID or client secret were provided via interactive input prompt. When the information were provided using a secrets file or via options, the login worked as expected.
41
+
8
42
  ## 2023.18.0
9
43
 
10
44
  ### Added
@@ -49,9 +49,10 @@ class SecretsStorageImpl {
49
49
  }
50
50
  async getDefaultSecretId() {
51
51
  const tenantUrl = (0, utils_2.getTenantUrl)();
52
- const secret = this.secrets.find((s) => new URL(s.tenantUrl).host === new URL(tenantUrl).host);
52
+ const { host } = new URL(tenantUrl);
53
+ const secret = this.secrets.find((s) => new URL(s.tenantUrl).host === host);
53
54
  if (!secret) {
54
- throw new Error("Method not implemented.");
55
+ throw new Error(`No secret found for host ${host}`);
55
56
  }
56
57
  return secret.id;
57
58
  }
@@ -95,7 +96,8 @@ class SecretsStorageImpl {
95
96
  if (secret.client_id) {
96
97
  const config = (0, config_1.get)();
97
98
  let oauth = {};
98
- if (!secret.customClient) {
99
+ if (!secret.customClient &&
100
+ (!secret.authorization_url || !secret.token_url)) {
99
101
  oauth = (await (0, http_1.fetch)({
100
102
  method: "GET",
101
103
  url: `${config.tenantUrl}/oauth`,
@@ -119,6 +121,9 @@ class SecretsStorageImpl {
119
121
  tokenUrl = config.tokenUrl;
120
122
  }
121
123
  }
124
+ if (!tokenUrl || !authorizationUrl) {
125
+ throw new Error("invalid token url or authorization url");
126
+ }
122
127
  this.secrets[secretIndex].authorization_url =
123
128
  (0, utils_1.removeQueryParametersFromUrl)(authorizationUrl);
124
129
  this.secrets[secretIndex].token_url = (0, utils_1.removeQueryParametersFromUrl)(tokenUrl);
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getTechnicalJwt = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
7
  const path_1 = __importDefault(require("path"));
9
8
  const url_1 = require("url");
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
10
  const config_1 = require("../../../../config");
11
11
  const logger_1 = require("../../../../logger");
12
12
  const http_1 = require("../../../../utils/http");
@@ -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, readPipe: true }, true, true), readBodyFromFile);
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);
34
34
  exports.create = create;
@@ -1,6 +1,5 @@
1
1
  import { Handler, Option } from "../../../types";
2
- export declare const create: (options: Array<Option> | Option, { readPipe, readEnv, readFile, readOptions }?: {
3
- readPipe: boolean;
2
+ export declare const create: (options: Array<Option> | Option, { readEnv, readFile, readOptions }?: {
4
3
  readEnv: boolean;
5
4
  readFile: boolean;
6
5
  readOptions: boolean;
@@ -6,15 +6,13 @@ const utils_1 = require("./utils");
6
6
  const or_1 = require("../or");
7
7
  const next_1 = require("../next");
8
8
  const checkOptionsExistence_1 = require("../checkOptionsExistence");
9
- const pipe_1 = require("./pipe");
10
9
  const file_1 = require("./file");
11
10
  const option_1 = require("./option");
12
11
  const succeed_1 = require("../succeed");
13
12
  const fail_1 = require("../fail");
14
13
  const env_1 = require("./env");
15
14
  const createHandler = (use, option, handler) => (0, next_1.create)((0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
16
- const create = (options, { readPipe, readEnv, readFile, readOptions } = {
17
- readPipe: true,
15
+ const create = (options, { readEnv, readFile, readOptions } = {
18
16
  readEnv: true,
19
17
  readFile: true,
20
18
  readOptions: true,
@@ -23,7 +21,7 @@ const create = (options, { readPipe, readEnv, readFile, readOptions } = {
23
21
  await (0, utils_1.checkOptions)(intOptions, command);
24
22
  return async () => {
25
23
  for (const option of intOptions) {
26
- const handler = (0, or_1.create)((0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)(createHandler(readPipe, option, (0, pipe_1.create)(option)), 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)((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
27
25
  ? (0, fail_1.create)()
28
26
  : (0, succeed_1.create)());
29
27
  await (await handler(command))();
@@ -4,6 +4,7 @@ exports.getTargetHost = exports.setTargetHost = exports.getAuthenticationMethod
4
4
  const logger_1 = require("../../logger");
5
5
  const config_1 = require("../../config");
6
6
  const constants_1 = require("../../constants");
7
+ const REGEX_LEADING_TRAILING_SINGLE_QUOTE = /^'.*'$/;
7
8
  const getLogger = () => (0, logger_1.get)("commands.handler.utils");
8
9
  const getBooleanOption = (value) => !!value;
9
10
  exports.getBooleanOption = getBooleanOption;
@@ -17,7 +18,12 @@ const decodeURIComponentInt = (value) => {
17
18
  throw err;
18
19
  }
19
20
  };
20
- const replaceLeadingTrailingSingleQuotes = (value) => value.replace(/^'/, "").replace(/'$/, "");
21
+ const replaceLeadingTrailingSingleQuotes = (value) => {
22
+ if (REGEX_LEADING_TRAILING_SINGLE_QUOTE.test(value)) {
23
+ return value.replace(/^'/, "").replace(/'$/, "");
24
+ }
25
+ return value;
26
+ };
21
27
  const parseOption = (value) => {
22
28
  if (typeof value !== "string") {
23
29
  return value;
@@ -41,6 +41,6 @@ const loginCommand = {
41
41
  { ...constants_1.OPTION_HOST, hidden: false, required: true },
42
42
  constants_1.OPTION_VERBOSE,
43
43
  constants_1.OPTION_OPTIONS_FILE,
44
- ]), verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
44
+ ]), (0, handler_1.createMandatoryOptionsHandler)(), verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
45
45
  };
46
46
  exports.default = loginCommand;
package/dwc/dwc.js CHANGED
@@ -7,6 +7,7 @@ exports.getCommands = exports.executeCommand = exports.init = void 0;
7
7
  if (process.env.SUPPRESS_NO_CONFIG_WARNING === undefined) {
8
8
  process.env.SUPPRESS_NO_CONFIG_WARNING = "true";
9
9
  }
10
+ /* eslint-disable import/first */
10
11
  const path_1 = __importDefault(require("path"));
11
12
  const logger_1 = require("../logger");
12
13
  const constants_1 = require("../constants");
@@ -114,11 +115,15 @@ const init = async () => {
114
115
  await setTenant();
115
116
  await initCacheTolerant();
116
117
  await setupSecretsStorage();
118
+ const cliName = (0, config_1.get)()[constants_1.CLI_NAME];
117
119
  program = (0, commands_1.createCommand)();
120
+ program.name(cliName);
118
121
  program.version((0, core_1.getVersion)(), "-v, --version", "output the current version");
119
122
  program.description((0, config_1.get)()[constants_1.CLI_DESCRIPTION]);
120
- program.showHelpAfterError(`Did you initialize the CLI by running ${(0, config_1.get)()[constants_1.CLI_NAME]} config cache init --host "<Server_URL>"?` +
121
- ` Add --help, -h or go to ${(0, config_1.get)()[constants_1.CLI_SAP_HELP]} for additional information.`);
123
+ program.showHelpAfterError(`Make sure to always define the host using the --host option or by running ${cliName}` +
124
+ ` config host set "<Server_URL>". Did you initialize the CLI by running ${cliName} config` +
125
+ ` cache init --host "<Server_URL>"?` +
126
+ ` Add option --help, -h or go to ${(0, config_1.get)()[constants_1.CLI_SAP_HELP]} for additional information.`);
122
127
  program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_HOST));
123
128
  program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_OPTIONS_FILE));
124
129
  program.configureHelp({ sortSubcommands: true });
package/dwc/utils.js CHANGED
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOptionValueFromArgv = exports.compareEtags = exports.checkVersion = exports.addCommandsFromFolder = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
7
  const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const logger_1 = require("../logger");
10
10
  const discovery_1 = require("../discovery");
11
11
  const commands_1 = require("../utils/commands");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cli-core",
3
- "version": "2023.18.0",
3
+ "version": "2023.23.0",
4
4
  "description": "Command-Line Interface (CLI) Core Module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "SAP SE",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "ajv": "8.12.0",
21
- "axios": "1.4.0",
21
+ "axios": "1.5.1",
22
22
  "commander": "11.0.0",
23
23
  "config": "3.3.9",
24
24
  "dotenv": "16.3.1",
@@ -1,2 +0,0 @@
1
- import { Handler, Option } from "../../../types";
2
- export declare const create: (option: Option) => Handler;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.create = void 0;
4
- const fs_extra_1 = require("fs-extra");
5
- const logger_1 = require("../../../logger");
6
- const utils_1 = require("./utils");
7
- const getLogger = () => (0, logger_1.get)("commands.handler.options.pipe");
8
- let data;
9
- const getDataFromPipe = () => {
10
- if (data === undefined) {
11
- try {
12
- data = JSON.parse((0, fs_extra_1.readFileSync)(0, "utf-8"));
13
- }
14
- catch (err) {
15
- const { error } = getLogger();
16
- error("failed to read from pipe", err);
17
- data = null;
18
- return getDataFromPipe();
19
- }
20
- }
21
- else if (data === null) {
22
- throw new Error("no data received from pipe");
23
- }
24
- return data;
25
- };
26
- /* jscpd:ignore-start */
27
- const create = (option) => async () => async () => {
28
- const { debug } = getLogger();
29
- /* jscpd:ignore-end */
30
- debug(`reading option ${option.longName} from pipe`);
31
- const options = getDataFromPipe();
32
- (0, utils_1.setOption)(option, options[option.longName]);
33
- };
34
- exports.create = create;