@sap/cli-core 2023.23.0 → 2023.25.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 +59 -0
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +2 -2
- package/commands/handler/fetch/utils.d.ts +8 -1
- package/commands/handler/fetch/utils.js +21 -5
- package/commands/login.command.js +10 -0
- package/commands/logout.command.js +0 -1
- package/commands/utils.d.ts +1 -0
- package/commands/utils.js +6 -1
- package/constants.d.ts +3 -0
- package/constants.js +13 -2
- package/dwc/run.js +1 -0
- package/dwc/utils.d.ts +1 -0
- package/dwc/utils.js +12 -1
- package/package.json +5 -3
- package/types.d.ts +3 -0
- package/utils/http/index.js +13 -1
- package/utils/openUtils.d.ts +3 -0
- package/utils/openUtils.js +23 -0
- package/utils/utils.d.ts +1 -3
- package/utils/utils.js +7 -15
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,65 @@ 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.25.0
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- A check for the correct node version environment when using the CLI. In case the node version does not satisfy the minimum node version required by the CLI to function correctly, a warning is printed to the console.
|
|
13
|
+
|
|
14
|
+
- When printing the help information for the `login` command, the list of options now includes the login-specific options such as `--authorization-url` and `--token-url`. Previously the help showed the following options:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
<CLI> login --help
|
|
18
|
+
Usage: <CLI> login [options]
|
|
19
|
+
log in to your account using interactive OAuth authentication
|
|
20
|
+
Options:
|
|
21
|
+
-H, --host <host> specifies the url where the tenant is hosted (optional)
|
|
22
|
+
-h, --help display help for command
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
With this version, the help looks like this:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
<CLI> login --help
|
|
29
|
+
Usage: <CLI> login [options]
|
|
30
|
+
log in to your account using interactive OAuth authentication
|
|
31
|
+
Options:
|
|
32
|
+
-H, --host <host> specifies the url where the tenant is hosted (optional)
|
|
33
|
+
-A, --authorization-url <url> authorization url for interactive oauth session authentication (optional)
|
|
34
|
+
-t, --token-url <url> token url for interactive oauth session authentication (optional)
|
|
35
|
+
-c, --client-id <id> client id for interactive oauth session authentication (optional)
|
|
36
|
+
-C, --client-secret <secret> client secret for interactive oauth session authentication (optional)
|
|
37
|
+
-a, --access-token <token> access token for interactive oauth session authentication (optional)
|
|
38
|
+
-b, --code <code> code for oauth token retrieval (optional)
|
|
39
|
+
-r, --refresh-token <token> refresh token for interactive oauth session authentication (optional)
|
|
40
|
+
-s, --secrets-file <file> path to secrets file (optional)
|
|
41
|
+
-h, --help display help for command
|
|
42
|
+
Only command-specific options are listed here. To learn more about available generic options, visit https://tinyurl.com/yck8vv4w
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Added the option `--browser <browser>` to the login command. Users can now choose explicitly which browser to open when logging in to a tenant. By default the system's default browser is used.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- The HTTPS proxy support introduced with `2023.24.0` did not respect the underlying `axios` module configuration need to disable the native proxy handling by passing `proxy: false` to the request configuration.
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
- Previously, when running the `logout` command but no secrets existed anymore, the command would fail with exit code 1 and an error message. Now, when running the `logout` command but there are no secrets to logout from, the command fails silently.
|
|
54
|
+
|
|
55
|
+
## 2023.24.0
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- The defined HTTP protocol was not applied to calculated authorization URL and token URL. No matter which HTTP protocol (`http` or `https`) was used, the automatically calculated authorization URL and token URL always used the `https` protocol.
|
|
60
|
+
|
|
61
|
+
### Added
|
|
62
|
+
|
|
63
|
+
- HTTPS proxy support via environment variable `https_proxy`. When using an HTTPS proxy to communicate with the public internet, you can configure the environment variable `https_proxy`. The CLI uses the value from the environment variable to establish a correct connection to the HTTPS proxy.
|
|
64
|
+
|
|
65
|
+
- Support for response header `x-sap-datasphere-cli-file-name`. When the user adds option `--output` and provides a path to a file location, this value is always used to store the response data, no matter whether response header `x-sap-datasphere-cli-file-name` is present. If the user adds option `--output` without providing a path to a file location and the response header `x-sap-datasphere-cli-file-name` is present, the response data is stored in the location mentioned in `x-sap-datasphere-cli-file-name`. In all other cases, the response data is printed to the console.
|
|
66
|
+
|
|
8
67
|
## 2023.23.0
|
|
9
68
|
|
|
10
69
|
### Fixed
|
|
@@ -8,8 +8,8 @@ const utils_1 = require("../utils");
|
|
|
8
8
|
const setAuthorization_1 = require("./setAuthorization");
|
|
9
9
|
const constants_1 = require("../../../../../constants");
|
|
10
10
|
const options_1 = require("../../../../../utils/options");
|
|
11
|
-
const utils_2 = require("../../../../../utils/utils");
|
|
12
11
|
const SecretsStorageSingleton_1 = require("../../../../../cache/secrets/SecretsStorageSingleton");
|
|
12
|
+
const openUtils_1 = require("../../../../../utils/openUtils");
|
|
13
13
|
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.utils.refreshToken");
|
|
14
14
|
const refreshToken = async (forceRefresh = false) => {
|
|
15
15
|
const { info: logInfo, debug } = getLogger();
|
|
@@ -90,7 +90,7 @@ const getCode = async (authorizeUrl, clientId) => {
|
|
|
90
90
|
debug("failed to retrieve code from options", err);
|
|
91
91
|
return (await Promise.all([
|
|
92
92
|
(0, exports.retrieveCode)(),
|
|
93
|
-
(0,
|
|
93
|
+
(0, openUtils_1.openUrlInBrowser)(authorizeUrl, {
|
|
94
94
|
response_type: "code",
|
|
95
95
|
client_id: clientId,
|
|
96
96
|
}),
|
|
@@ -8,7 +8,14 @@ export declare const buildParameters: (path: string, parameterMappings?: Paramet
|
|
|
8
8
|
headers: KeyValuePair;
|
|
9
9
|
body: any;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* If --output is present: Return value of --output if defined, otherwise take value from outputPath.
|
|
13
|
+
* If --output is not present, print response to console
|
|
14
|
+
* @param outputPath Optional path defined by server
|
|
15
|
+
* @returns Path to output file
|
|
16
|
+
*/
|
|
17
|
+
export declare function getOutputFileName(outputPath?: string): string;
|
|
18
|
+
export declare const handleResponseData: (data: any, outputPath?: string) => Promise<void>;
|
|
12
19
|
export declare const handleResponse: (data: any, headers?: RawAxiosResponseHeaders | AxiosResponseHeaders) => Promise<void>;
|
|
13
20
|
export declare const configRequiresBody: (method: HTTPMethod) => boolean;
|
|
14
21
|
export declare const buildHttpConfig: (method: HTTPMethod, path: string, parameterMappings?: ParameterMappings) => HTTPConfig;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildHttpConfig = exports.configRequiresBody = exports.handleResponse = exports.handleResponseData = exports.buildParameters = exports.removeLeadingPathSegmentForPasscode = exports.checkConfiguration = void 0;
|
|
6
|
+
exports.buildHttpConfig = exports.configRequiresBody = exports.handleResponse = exports.handleResponseData = exports.getOutputFileName = exports.buildParameters = exports.removeLeadingPathSegmentForPasscode = exports.checkConfiguration = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -103,7 +103,22 @@ const buildParameters = (path, parameterMappings) => {
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
exports.buildParameters = buildParameters;
|
|
106
|
-
|
|
106
|
+
/**
|
|
107
|
+
* If --output is present: Return value of --output if defined, otherwise take value from outputPath.
|
|
108
|
+
* If --output is not present, print response to console
|
|
109
|
+
* @param outputPath Optional path defined by server
|
|
110
|
+
* @returns Path to output file
|
|
111
|
+
*/
|
|
112
|
+
function getOutputFileName(outputPath = "") {
|
|
113
|
+
const config = (0, config_1.get)();
|
|
114
|
+
if (typeof config.options[constants_1.OPTION_OUTPUT.longName] === "boolean" &&
|
|
115
|
+
config.options[constants_1.OPTION_OUTPUT.longName]) {
|
|
116
|
+
return outputPath;
|
|
117
|
+
}
|
|
118
|
+
return config.options[constants_1.OPTION_OUTPUT.longName];
|
|
119
|
+
}
|
|
120
|
+
exports.getOutputFileName = getOutputFileName;
|
|
121
|
+
const handleResponseData = async (data, outputPath) => {
|
|
107
122
|
const config = (0, config_1.get)();
|
|
108
123
|
if (!config.doNotStoreResult) {
|
|
109
124
|
ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(data);
|
|
@@ -112,8 +127,9 @@ const handleResponseData = async (data) => {
|
|
|
112
127
|
const formatted = config.options.pretty
|
|
113
128
|
? JSON.stringify(data, null, 2)
|
|
114
129
|
: JSON.stringify(data);
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
const outputFileName = getOutputFileName(outputPath);
|
|
131
|
+
if (outputFileName) {
|
|
132
|
+
await fs_extra_1.default.writeFile(outputFileName, formatted);
|
|
117
133
|
}
|
|
118
134
|
else {
|
|
119
135
|
output(formatted);
|
|
@@ -125,7 +141,7 @@ const handleResponse = async (data, headers) => {
|
|
|
125
141
|
(0, config_1.set)({ [constants_1.X_CSRF_TOKEN]: headers[constants_1.X_CSRF_TOKEN] });
|
|
126
142
|
}
|
|
127
143
|
else if (data) {
|
|
128
|
-
await (0, exports.handleResponseData)(data);
|
|
144
|
+
await (0, exports.handleResponseData)(data, headers?.[constants_1.X_OUTPUT_FILE_NAME]);
|
|
129
145
|
}
|
|
130
146
|
};
|
|
131
147
|
exports.handleResponse = handleResponse;
|
|
@@ -8,6 +8,7 @@ const init_command_1 = require("./config.command/cache.command/init.command");
|
|
|
8
8
|
const utils_1 = require("../cache/secrets/utils");
|
|
9
9
|
const utils_2 = require("../logger/utils");
|
|
10
10
|
const utils_3 = require("../utils/utils");
|
|
11
|
+
const utils_4 = require("./utils");
|
|
11
12
|
const getLogger = () => (0, logger_1.get)("commands.login");
|
|
12
13
|
const verifyHost = async () => async () => {
|
|
13
14
|
const logger = getLogger();
|
|
@@ -41,6 +42,15 @@ const loginCommand = {
|
|
|
41
42
|
{ ...constants_1.OPTION_HOST, hidden: false, required: true },
|
|
42
43
|
constants_1.OPTION_VERBOSE,
|
|
43
44
|
constants_1.OPTION_OPTIONS_FILE,
|
|
45
|
+
{ ...constants_1.OPTION_AUTHORIZATION_URL, hidden: false },
|
|
46
|
+
{ ...constants_1.OPTION_TOKEN_URL, hidden: false },
|
|
47
|
+
{ ...constants_1.OPTION_CLIENT_ID, hidden: false },
|
|
48
|
+
{ ...constants_1.OPTION_CLIENT_SECRET, hidden: false },
|
|
49
|
+
{ ...constants_1.OPTION_ACCESS_TOKEN, hidden: false },
|
|
50
|
+
{ ...constants_1.OPTION_CODE, hidden: false },
|
|
51
|
+
{ ...constants_1.OPTION_REFRESH_TOKEN, hidden: false },
|
|
52
|
+
{ ...constants_1.OPTION_SECRETS_FILE, hidden: false },
|
|
53
|
+
{ ...constants_1.OPTION_BROWSER, choices: utils_4.getBrowserChoices },
|
|
44
54
|
]), (0, handler_1.createMandatoryOptionsHandler)(), verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
|
|
45
55
|
};
|
|
46
56
|
exports.default = loginCommand;
|
|
@@ -16,7 +16,6 @@ const handler = async () => async () => {
|
|
|
16
16
|
const logger = (0, logger_1.get)("commands.logout");
|
|
17
17
|
logger.error("failed to delete secrets file from cache", err);
|
|
18
18
|
(0, utils_1.logVerbose)(logger, err.message);
|
|
19
|
-
throw new Error("failed to delete secrets file from cache");
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
21
|
const logoutCommand = {
|
package/commands/utils.d.ts
CHANGED
package/commands/utils.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getChoices = void 0;
|
|
3
|
+
exports.getBrowserChoices = exports.getChoices = void 0;
|
|
4
|
+
const open_1 = require("open");
|
|
4
5
|
const SecretsStorageSingleton_1 = require("../cache/secrets/SecretsStorageSingleton");
|
|
5
6
|
const getChoices = async () => {
|
|
6
7
|
return SecretsStorageSingleton_1.SecretsStorageSingleton.SINGLETON.getAllSecrets().map((secret) => secret.id.toString(10));
|
|
7
8
|
};
|
|
8
9
|
exports.getChoices = getChoices;
|
|
10
|
+
const getBrowserChoices = async () => {
|
|
11
|
+
return Object.keys(open_1.apps);
|
|
12
|
+
};
|
|
13
|
+
exports.getBrowserChoices = getBrowserChoices;
|
package/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare enum AuthenticationMethod {
|
|
|
5
5
|
oauth = "oauth",
|
|
6
6
|
passcode = "passcode"
|
|
7
7
|
}
|
|
8
|
+
export declare const DEFAULT_BROWSER = "browser";
|
|
8
9
|
export declare const CLI_NAME = "cli-name";
|
|
9
10
|
export declare const CLI_PACKAGE_NAME = "cli-package-name";
|
|
10
11
|
export declare const CLI_DESCRIPTION = "cli-description";
|
|
@@ -18,6 +19,7 @@ export declare const CLI_GENERIC_OPTIONS_HELP = "cli-generic-options-help";
|
|
|
18
19
|
export declare const SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH: string[];
|
|
19
20
|
export declare const DISCOVERY_METADATA_PATH = "discovery-metadata.json";
|
|
20
21
|
export declare const X_CSRF_TOKEN = "x-csrf-token";
|
|
22
|
+
export declare const X_OUTPUT_FILE_NAME = "x-sap-datasphere-cli-file-name";
|
|
21
23
|
export declare const PATH_TO_SUCCESS_HTML: string;
|
|
22
24
|
export declare const PATH_TO_ERROR_HTML: string;
|
|
23
25
|
export declare const CACHE_SECRETS_FILE = "secrets.json";
|
|
@@ -43,3 +45,4 @@ export declare const CONFIG_PASSCODE_FUNCTION = "passcodeFunction";
|
|
|
43
45
|
export declare const OPTION_OPTIONS_FILE: Option;
|
|
44
46
|
export declare const OPTION_FILE_PATH: Option;
|
|
45
47
|
export declare const OPTION_INPUT: Option;
|
|
48
|
+
export declare const OPTION_BROWSER: Option;
|
package/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATH = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
|
|
6
|
+
exports.OPTION_BROWSER = exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_OUTPUT_FILE_NAME = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATH = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.DEFAULT_BROWSER = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_1 = require("./utils/utils");
|
|
9
9
|
exports.VERSION = (0, utils_1.getVersion)();
|
|
@@ -13,6 +13,7 @@ var AuthenticationMethod;
|
|
|
13
13
|
AuthenticationMethod["oauth"] = "oauth";
|
|
14
14
|
AuthenticationMethod["passcode"] = "passcode";
|
|
15
15
|
})(AuthenticationMethod || (exports.AuthenticationMethod = AuthenticationMethod = {}));
|
|
16
|
+
exports.DEFAULT_BROWSER = "browser";
|
|
16
17
|
exports.CLI_NAME = "cli-name";
|
|
17
18
|
exports.CLI_PACKAGE_NAME = "cli-package-name";
|
|
18
19
|
exports.CLI_DESCRIPTION = "cli-description";
|
|
@@ -26,6 +27,7 @@ exports.CLI_GENERIC_OPTIONS_HELP = "cli-generic-options-help";
|
|
|
26
27
|
exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = ["dwaas-core"];
|
|
27
28
|
exports.DISCOVERY_METADATA_PATH = "discovery-metadata.json";
|
|
28
29
|
exports.X_CSRF_TOKEN = "x-csrf-token";
|
|
30
|
+
exports.X_OUTPUT_FILE_NAME = "x-sap-datasphere-cli-file-name";
|
|
29
31
|
exports.PATH_TO_SUCCESS_HTML = path_1.default.join(__dirname, "assets", "success.html");
|
|
30
32
|
exports.PATH_TO_ERROR_HTML = path_1.default.join(__dirname, "assets", "error.html");
|
|
31
33
|
exports.CACHE_SECRETS_FILE = "secrets.json";
|
|
@@ -64,7 +66,7 @@ exports.OPTION_LOGIN_ID = {
|
|
|
64
66
|
exports.OPTION_OUTPUT = {
|
|
65
67
|
longName: "output",
|
|
66
68
|
description: "specifies the file to store the output of the command",
|
|
67
|
-
args: [{ name: "output" }],
|
|
69
|
+
args: [{ name: "output", optional: true }],
|
|
68
70
|
hidden: true,
|
|
69
71
|
};
|
|
70
72
|
exports.OPTION_NO_PRETTY = {
|
|
@@ -202,3 +204,12 @@ exports.OPTION_INPUT = {
|
|
|
202
204
|
type: "text",
|
|
203
205
|
},
|
|
204
206
|
};
|
|
207
|
+
exports.OPTION_BROWSER = {
|
|
208
|
+
longName: "browser",
|
|
209
|
+
description: "specifies the browser to open",
|
|
210
|
+
args: [{ name: "browser" }],
|
|
211
|
+
prompts: {
|
|
212
|
+
message: "Select your browser:",
|
|
213
|
+
type: "select",
|
|
214
|
+
},
|
|
215
|
+
};
|
package/dwc/run.js
CHANGED
package/dwc/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { Option } from "../types";
|
|
3
3
|
export declare const addCommandsFromFolder: (pathToFolder: string, program: Command) => Promise<void>;
|
|
4
|
+
export declare function verifyNodeVersion(): void;
|
|
4
5
|
export declare const checkVersion: () => Promise<void>;
|
|
5
6
|
export declare const compareEtags: () => Promise<void>;
|
|
6
7
|
export declare const getOptionValueFromArgv: ({ longName }: Option) => string;
|
package/dwc/utils.js
CHANGED
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getOptionValueFromArgv = exports.compareEtags = exports.checkVersion = exports.addCommandsFromFolder = void 0;
|
|
6
|
+
exports.getOptionValueFromArgv = exports.compareEtags = exports.checkVersion = exports.verifyNodeVersion = exports.addCommandsFromFolder = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const compare_versions_1 = require("compare-versions");
|
|
9
10
|
const logger_1 = require("../logger");
|
|
10
11
|
const discovery_1 = require("../discovery");
|
|
11
12
|
const commands_1 = require("../utils/commands");
|
|
@@ -38,6 +39,16 @@ const addCommandsFromFolder = async (pathToFolder, program) => {
|
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
41
|
exports.addCommandsFromFolder = addCommandsFromFolder;
|
|
42
|
+
function verifyNodeVersion() {
|
|
43
|
+
const { output } = getLogger();
|
|
44
|
+
const { node } = (0, utils_1.getEngines)();
|
|
45
|
+
const version = process.version.replace("v", "").trim();
|
|
46
|
+
if (!(0, compare_versions_1.satisfies)(version, node)) {
|
|
47
|
+
output(`WARNING: the current node version ${version} does not satisfy the required node version ${node}.` +
|
|
48
|
+
` The CLI might not behave as expected. Please make sure to install a matching node version.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.verifyNodeVersion = verifyNodeVersion;
|
|
41
52
|
const checkVersion = async () => {
|
|
42
53
|
const { output, error } = getLogger();
|
|
43
54
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap/cli-core",
|
|
3
|
-
"version": "2023.
|
|
3
|
+
"version": "2023.25.0",
|
|
4
4
|
"description": "Command-Line Interface (CLI) Core Module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "SAP SE",
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"ajv": "8.12.0",
|
|
21
|
-
"axios": "1.
|
|
22
|
-
"commander": "11.
|
|
21
|
+
"axios": "1.6.0",
|
|
22
|
+
"commander": "11.1.0",
|
|
23
|
+
"compare-versions": "6.1.0",
|
|
23
24
|
"config": "3.3.9",
|
|
24
25
|
"dotenv": "16.3.1",
|
|
25
26
|
"fs-extra": "11.1.1",
|
|
26
27
|
"https": "1.0.0",
|
|
28
|
+
"https-proxy-agent": "7.0.2",
|
|
27
29
|
"lodash": "4.17.21",
|
|
28
30
|
"open": "8.4.2",
|
|
29
31
|
"path": "0.12.7",
|
package/types.d.ts
CHANGED
package/utils/http/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fetch = exports.DEFAULTS = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
8
9
|
const config_1 = require("../../config");
|
|
9
10
|
const logger_1 = require("../../logger");
|
|
10
11
|
const constants_1 = require("../../constants");
|
|
@@ -13,10 +14,11 @@ const core_1 = require("../../config/core");
|
|
|
13
14
|
exports.DEFAULTS = {
|
|
14
15
|
maxBodyLength: -1,
|
|
15
16
|
maxContentLength: -1,
|
|
16
|
-
maxRedirects: 0, // must be set to 0 because maxBodyLength: -1 won't work otherwise, see github.com/axios/axios/issues/4263
|
|
17
|
+
maxRedirects: 0, // must be set to 0 because maxBodyLength: -1 won't work otherwise, see github.com/axios/axios/issues/4263,
|
|
17
18
|
};
|
|
18
19
|
const HEADERS_ETAG = "x-sap-cli-core-discovery-etag";
|
|
19
20
|
const getLogger = () => (0, logger_1.get)("http");
|
|
21
|
+
const HTTPS_PROXY = process.env.https_proxy ?? process.env.HTTPS_PROXY;
|
|
20
22
|
const setEtag = (headers) => {
|
|
21
23
|
const { debug } = getLogger();
|
|
22
24
|
if (headers?.[HEADERS_ETAG]) {
|
|
@@ -38,7 +40,17 @@ const fetch = async (config) => {
|
|
|
38
40
|
output("%s %s", config.method.toUpperCase(), config.url);
|
|
39
41
|
}
|
|
40
42
|
debug("http config: %s", JSON.stringify(config));
|
|
43
|
+
const httpsAgent = HTTPS_PROXY ? new https_proxy_agent_1.HttpsProxyAgent(HTTPS_PROXY) : null;
|
|
44
|
+
if (httpsAgent && cnfg.verbose) {
|
|
45
|
+
output(`using https proxy agent for https proxy`);
|
|
46
|
+
debug(`using https proxy agent for https proxy ${HTTPS_PROXY}`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
debug("no https proxy defined via environment variable https_proxy");
|
|
50
|
+
}
|
|
41
51
|
const res = await (0, axios_1.default)({
|
|
52
|
+
httpsAgent,
|
|
53
|
+
proxy: false,
|
|
42
54
|
...config,
|
|
43
55
|
...exports.DEFAULTS,
|
|
44
56
|
headers: {
|
|
@@ -0,0 +1,23 @@
|
|
|
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.openUrlInBrowser = void 0;
|
|
7
|
+
const open_1 = __importDefault(require("open"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const options_1 = require("./options");
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
const getLogger = () => (0, logger_1.get)("utils.open");
|
|
12
|
+
const openUrlInBrowser = async (url, queryParameters = {}) => {
|
|
13
|
+
const browser = (0, options_1.getOptionValueFromConfig)(constants_1.OPTION_BROWSER, constants_1.DEFAULT_BROWSER);
|
|
14
|
+
const u = new URL(url);
|
|
15
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
16
|
+
u.searchParams.append(key, value);
|
|
17
|
+
}
|
|
18
|
+
const urlString = u.toString();
|
|
19
|
+
const { debug } = getLogger();
|
|
20
|
+
debug(`open browser ${browser} at ${urlString}`);
|
|
21
|
+
await (0, open_1.default)(urlString, { app: { name: browser } });
|
|
22
|
+
};
|
|
23
|
+
exports.openUrlInBrowser = openUrlInBrowser;
|
package/utils/utils.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare const getVersion: (cwd?: string) => string;
|
|
|
10
10
|
export declare const getName: (cwd?: string) => string;
|
|
11
11
|
export declare const getPackageName: (cwd?: string) => string;
|
|
12
12
|
export declare const getDescription: (cwd?: string) => string;
|
|
13
|
+
export declare const getEngines: (cwd?: string) => PackageJson["engines"];
|
|
13
14
|
export declare const getBin: (cwd?: string) => string;
|
|
14
15
|
export declare const removeScopeFromPackageName: (packageName: string) => string;
|
|
15
16
|
export declare const parseTenant: (tenant: string) => string;
|
|
@@ -24,6 +25,3 @@ export declare const getInfoFromTenant: (tenant: string, verbose: boolean, print
|
|
|
24
25
|
export declare function removeQueryParametersFromUrl(sUrl: string): string;
|
|
25
26
|
export declare const sha256: (string: string) => string;
|
|
26
27
|
export declare const toConstantCase: (string: string) => string;
|
|
27
|
-
export declare const openUrlInBrowser: (url: string, queryParameters?: {
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
}) => Promise<void>;
|
package/utils/utils.js
CHANGED
|
@@ -26,11 +26,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.toConstantCase = exports.sha256 = exports.removeQueryParametersFromUrl = exports.getInfoFromTenant = exports.parseTenant = exports.removeScopeFromPackageName = exports.getBin = exports.getEngines = exports.getDescription = exports.getPackageName = exports.getName = exports.getVersion = exports.readPackageJson = exports.requireFile = exports.parseVersion = exports.buildOptionName = void 0;
|
|
30
30
|
const crypto = __importStar(require("crypto"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const lodash_1 = require("lodash");
|
|
33
|
-
const open_1 = __importDefault(require("open"));
|
|
34
33
|
const logger_1 = require("../logger");
|
|
35
34
|
const commands_1 = require("./commands");
|
|
36
35
|
let pgk;
|
|
@@ -92,6 +91,10 @@ const getDescription = (cwd = "") => {
|
|
|
92
91
|
return (0, exports.readPackageJson)(cwd, true).description;
|
|
93
92
|
};
|
|
94
93
|
exports.getDescription = getDescription;
|
|
94
|
+
const getEngines = (cwd = "") => {
|
|
95
|
+
return (0, exports.readPackageJson)(cwd, true).engines;
|
|
96
|
+
};
|
|
97
|
+
exports.getEngines = getEngines;
|
|
95
98
|
const getBin = (cwd = "") => {
|
|
96
99
|
const keys = Object.keys((0, exports.readPackageJson)(cwd, true).bin || {});
|
|
97
100
|
if (keys.length === 0) {
|
|
@@ -148,8 +151,8 @@ const getInfoFromTenant = (tenant, verbose, printOutput = true) => {
|
|
|
148
151
|
host: `${protocol}//dwaas-core.sac${region}.cfapps.orca.net.sap`,
|
|
149
152
|
publicfqdn: parsedTenant,
|
|
150
153
|
passcodeUrl: `https://${hostname}.authentication.${region}.hana.ondemand.com/passcode`,
|
|
151
|
-
authorizationUrl:
|
|
152
|
-
tokenUrl:
|
|
154
|
+
authorizationUrl: `${protocol}//${hostname}.authentication.${region}.hana.ondemand.com/oauth/authorize`,
|
|
155
|
+
tokenUrl: `${protocol}//${hostname}.authentication.${region}.hana.ondemand.com/oauth/token`,
|
|
153
156
|
tenantUrl: `${protocol}//${parsedTenant}`,
|
|
154
157
|
};
|
|
155
158
|
};
|
|
@@ -165,14 +168,3 @@ crypto.createHash("sha256").update(string).digest("base64");
|
|
|
165
168
|
exports.sha256 = sha256;
|
|
166
169
|
const toConstantCase = (string) => (0, lodash_1.upperCase)(string).replace(/ /g, "_");
|
|
167
170
|
exports.toConstantCase = toConstantCase;
|
|
168
|
-
const openUrlInBrowser = async (url, queryParameters = {}) => {
|
|
169
|
-
const u = new URL(url);
|
|
170
|
-
for (const [key, value] of Object.entries(queryParameters)) {
|
|
171
|
-
u.searchParams.append(key, value);
|
|
172
|
-
}
|
|
173
|
-
const urlString = u.toString();
|
|
174
|
-
const { debug } = getLogger();
|
|
175
|
-
debug(`open browser at ${urlString}`);
|
|
176
|
-
await (0, open_1.default)(urlString);
|
|
177
|
-
};
|
|
178
|
-
exports.openUrlInBrowser = openUrlInBrowser;
|