@sap/cli-core 2025.16.0 → 2025.19.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 +20 -0
- package/README.md +1 -1
- package/cache/cache.js +16 -28
- package/cache/index.d.ts +2 -2
- package/cache/index.js +2 -12
- package/cache/secrets/SecretsStorageImpl.d.ts +2 -3
- package/cache/secrets/SecretsStorageImpl.js +18 -25
- package/cache/secrets/SecretsStorageSingleton.d.ts +1 -1
- package/cache/secrets/SecretsStorageSingleton.js +1 -5
- package/cache/secrets/types.d.ts +1 -1
- package/cache/secrets/types.js +1 -2
- package/cache/secrets/utils.d.ts +1 -1
- package/cache/secrets/utils.js +20 -27
- package/cache/utils.js +8 -15
- package/commands/config.command/cache.command/clean.command.d.ts +1 -1
- package/commands/config.command/cache.command/clean.command.js +10 -12
- package/commands/config.command/cache.command/index.d.ts +1 -1
- package/commands/config.command/cache.command/index.js +5 -10
- package/commands/config.command/cache.command/init.command/index.d.ts +1 -1
- package/commands/config.command/cache.command/init.command/index.js +29 -36
- package/commands/config.command/cache.command/init.command/utils.d.ts +1 -1
- package/commands/config.command/cache.command/init.command/utils.js +6 -13
- package/commands/config.command/cache.command/show.command.d.ts +1 -1
- package/commands/config.command/cache.command/show.command.js +7 -9
- package/commands/config.command/host.command.d.ts +1 -1
- package/commands/config.command/host.command.js +19 -23
- package/commands/config.command/index.d.ts +1 -1
- package/commands/config.command/index.js +5 -45
- package/commands/config.command/passcode.command.d.ts +1 -1
- package/commands/config.command/passcode.command.js +12 -16
- package/commands/config.command/secrets.command/check.command.d.ts +1 -2
- package/commands/config.command/secrets.command/check.command.js +10 -14
- package/commands/config.command/secrets.command/index.d.ts +1 -1
- package/commands/config.command/secrets.command/index.js +6 -11
- package/commands/config.command/secrets.command/refresh.command.d.ts +1 -1
- package/commands/config.command/secrets.command/refresh.command.js +5 -7
- package/commands/config.command/secrets.command/reset.command.d.ts +1 -1
- package/commands/config.command/secrets.command/reset.command.js +6 -8
- package/commands/config.command/secrets.command/show.command.d.ts +1 -1
- package/commands/config.command/secrets.command/show.command.js +8 -10
- package/commands/handler/authentication/index.d.ts +1 -1
- package/commands/handler/authentication/index.js +18 -21
- package/commands/handler/authentication/oauth/index.d.ts +2 -2
- package/commands/handler/authentication/oauth/index.js +13 -16
- package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/cache.js +5 -9
- package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/file.js +20 -25
- package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/index.js +6 -10
- package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/options.js +25 -29
- package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +2 -2
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +18 -23
- package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +2 -2
- package/commands/handler/authentication/oauth/tokenProvider/index.js +7 -11
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +5 -9
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +19 -24
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +30 -36
- package/commands/handler/authentication/oauth/utils.d.ts +1 -1
- package/commands/handler/authentication/oauth/utils.js +15 -24
- package/commands/handler/authentication/passcode/function.d.ts +1 -1
- package/commands/handler/authentication/passcode/function.js +11 -13
- package/commands/handler/authentication/passcode/index.d.ts +1 -1
- package/commands/handler/authentication/passcode/index.js +14 -17
- package/commands/handler/authentication/passcode/input.d.ts +1 -1
- package/commands/handler/authentication/passcode/input.js +13 -20
- package/commands/handler/authentication/passcode/setPasscode.d.ts +1 -1
- package/commands/handler/authentication/passcode/setPasscode.js +9 -13
- package/commands/handler/authentication/passcode/types.js +1 -2
- package/commands/handler/authentication/technicalJWT/cf.js +9 -11
- package/commands/handler/authentication/technicalJWT/exec.d.ts +5 -6
- package/commands/handler/authentication/technicalJWT/exec.js +15 -19
- package/commands/handler/authentication/technicalJWT/index.d.ts +1 -1
- package/commands/handler/authentication/technicalJWT/index.js +8 -12
- package/commands/handler/authentication/technicalJWT/types.d.ts +1 -1
- package/commands/handler/authentication/technicalJWT/types.js +1 -4
- package/commands/handler/authentication/technicalJWT/utils.js +20 -27
- package/commands/handler/authentication/utils.js +3 -7
- package/commands/handler/checkOptionsExistence.d.ts +1 -1
- package/commands/handler/checkOptionsExistence.js +5 -9
- package/commands/handler/error.d.ts +1 -1
- package/commands/handler/error.js +4 -8
- package/commands/handler/fail.d.ts +1 -1
- package/commands/handler/fail.js +3 -7
- package/commands/handler/fetch/fetch.d.ts +1 -1
- package/commands/handler/fetch/fetch.js +26 -27
- package/commands/handler/fetch/index.d.ts +1 -1
- package/commands/handler/fetch/index.js +10 -14
- package/commands/handler/fetch/utils.d.ts +2 -2
- package/commands/handler/fetch/utils.js +55 -74
- package/commands/handler/force.d.ts +1 -1
- package/commands/handler/force.js +8 -15
- package/commands/handler/index.d.ts +18 -18
- package/commands/handler/index.js +18 -39
- package/commands/handler/input/file.d.ts +1 -1
- package/commands/handler/input/file.js +22 -29
- package/commands/handler/input/index.d.ts +1 -1
- package/commands/handler/input/index.js +4 -8
- package/commands/handler/input/input.d.ts +1 -1
- package/commands/handler/input/input.js +16 -23
- package/commands/handler/mandatoryOptions.d.ts +1 -1
- package/commands/handler/mandatoryOptions.js +13 -17
- package/commands/handler/next.d.ts +1 -1
- package/commands/handler/next.js +4 -8
- package/commands/handler/options/env.d.ts +1 -1
- package/commands/handler/options/env.js +8 -12
- package/commands/handler/options/file.d.ts +1 -1
- package/commands/handler/options/file.js +8 -12
- package/commands/handler/options/index.d.ts +1 -1
- package/commands/handler/options/index.js +15 -19
- package/commands/handler/options/option.d.ts +1 -1
- package/commands/handler/options/option.js +12 -13
- package/commands/handler/options/utils.d.ts +4 -2
- package/commands/handler/options/utils.js +18 -26
- package/commands/handler/or.d.ts +1 -1
- package/commands/handler/or.js +3 -7
- package/commands/handler/parseArguments.d.ts +1 -1
- package/commands/handler/parseArguments.js +11 -15
- package/commands/handler/resilient.d.ts +1 -1
- package/commands/handler/resilient.js +3 -7
- package/commands/handler/root/index.d.ts +1 -1
- package/commands/handler/root/index.js +3 -7
- package/commands/handler/stackTrace.d.ts +1 -1
- package/commands/handler/stackTrace.js +3 -7
- package/commands/handler/succeed.d.ts +1 -1
- package/commands/handler/succeed.js +3 -7
- package/commands/handler/utils.d.ts +1 -1
- package/commands/handler/utils.js +17 -27
- package/commands/login.command.d.ts +1 -1
- package/commands/login.command.js +51 -49
- package/commands/logout.command.d.ts +1 -1
- package/commands/logout.command.js +15 -17
- package/commands/openAPI.command/index.d.ts +1 -1
- package/commands/openAPI.command/index.js +20 -24
- package/commands/openAPI.command/utils.d.ts +1 -1
- package/commands/openAPI.command/utils.js +47 -97
- package/commands/utils.d.ts +1 -1
- package/commands/utils.js +6 -11
- package/config/core.d.ts +1 -1
- package/config/core.js +12 -25
- package/config/index.d.ts +1 -1
- package/config/index.js +45 -49
- package/configureLoggers.js +2 -6
- package/constants.d.ts +4 -1
- package/constants.js +62 -59
- package/discovery/index.d.ts +1 -1
- package/discovery/index.js +32 -45
- package/discovery/utils.js +5 -12
- package/dwc/dwc.js +63 -76
- package/dwc/run.js +15 -19
- package/dwc/utils.d.ts +1 -1
- package/dwc/utils.js +42 -38
- package/index.d.ts +4 -4
- package/index.js +22 -68
- package/logger/index.d.ts +2 -2
- package/logger/index.js +17 -22
- package/logger/types.js +1 -2
- package/logger/utils.d.ts +1 -1
- package/logger/utils.js +4 -8
- package/module.d.ts +3 -3
- package/module.js +10 -48
- package/package.json +9 -7
- package/result/ResultHandlerFactory.d.ts +1 -1
- package/result/ResultHandlerFactory.js +1 -5
- package/result/ResultHandlerImpl.d.ts +1 -1
- package/result/ResultHandlerImpl.js +1 -5
- package/result/types.js +1 -2
- package/settings/index.d.ts +1 -1
- package/settings/index.js +11 -17
- package/types.d.ts +1 -1
- package/types.js +6 -9
- package/utils/commands.d.ts +3 -3
- package/utils/commands.js +23 -36
- package/utils/http/httpsAgent.d.ts +6 -0
- package/utils/http/httpsAgent.js +44 -0
- package/utils/http/index.d.ts +1 -1
- package/utils/http/index.js +31 -35
- package/utils/http/utils.d.ts +1 -1
- package/utils/http/utils.js +4 -9
- package/utils/openUtils.js +8 -14
- package/utils/options.d.ts +1 -1
- package/utils/options.js +5 -10
- package/utils/utils.d.ts +2 -2
- package/utils/utils.js +42 -94
package/logger/utils.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const options_1 = require("../utils/options");
|
|
6
|
-
const logVerbose = (logger, ...args) => {
|
|
7
|
-
const verbose = (0, options_1.getOptionValueFromConfigGracefully)(constants_1.OPTION_VERBOSE);
|
|
1
|
+
import { OPTION_VERBOSE } from "../constants.js";
|
|
2
|
+
import { getOptionValueFromConfigGracefully } from "../utils/options.js";
|
|
3
|
+
export const logVerbose = (logger, ...args) => {
|
|
4
|
+
const verbose = getOptionValueFromConfigGracefully(OPTION_VERBOSE);
|
|
8
5
|
if (verbose) {
|
|
9
6
|
logger.output(...args);
|
|
10
7
|
}
|
|
11
8
|
};
|
|
12
|
-
exports.logVerbose = logVerbose;
|
package/module.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PasscodeFunction } from "./commands/handler/authentication/passcode/types";
|
|
2
|
-
import { Configuration as LoggerConfiguration } from "./logger";
|
|
3
|
-
export { getCommands } from "./dwc/dwc";
|
|
1
|
+
import { PasscodeFunction } from "./commands/handler/authentication/passcode/types.js";
|
|
2
|
+
import { Configuration as LoggerConfiguration } from "./logger/index.js";
|
|
3
|
+
export { getCommands } from "./dwc/dwc.js";
|
|
4
4
|
export declare const configure: (logger?: LoggerConfiguration, passcodeFunction?: PasscodeFunction) => void;
|
package/module.js
CHANGED
|
@@ -1,57 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable import/first */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.configure = exports.getCommands = void 0;
|
|
38
|
-
const dotenv = __importStar(require("dotenv"));
|
|
39
|
-
const configureLoggers_1 = require("./configureLoggers");
|
|
2
|
+
import * as dotenv from "dotenv";
|
|
3
|
+
import { configureLoggers } from "./configureLoggers.js";
|
|
40
4
|
dotenv.config({
|
|
41
5
|
quiet: true, // default is false, but we want to avoid logging to the stdout
|
|
42
6
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const configure = (logger, passcodeFunction) => {
|
|
7
|
+
configureLoggers();
|
|
8
|
+
import { set } from "./config/index.js";
|
|
9
|
+
import { CONFIG_PASSCODE_FUNCTION } from "./constants.js";
|
|
10
|
+
import { configure as configureLogger, } from "./logger/index.js";
|
|
11
|
+
export { getCommands } from "./dwc/dwc.js";
|
|
12
|
+
export const configure = (logger, passcodeFunction) => {
|
|
50
13
|
if (logger) {
|
|
51
|
-
(
|
|
14
|
+
configureLogger(logger);
|
|
52
15
|
}
|
|
53
16
|
if (passcodeFunction) {
|
|
54
|
-
|
|
17
|
+
set({ [CONFIG_PASSCODE_FUNCTION]: passcodeFunction });
|
|
55
18
|
}
|
|
56
19
|
};
|
|
57
|
-
exports.configure = configure;
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap/cli-core",
|
|
3
|
-
"version": "2025.
|
|
3
|
+
"version": "2025.19.0",
|
|
4
4
|
"description": "Command-Line Interface (CLI) Core Module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "SAP SE",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"homepage": "https://www.sap.com",
|
|
8
9
|
"main": "index.js",
|
|
9
10
|
"engines": {
|
|
10
|
-
"node": "^
|
|
11
|
+
"node": "^20 || ^21 || ^22",
|
|
11
12
|
"npm": "^9 || ^10"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
@@ -18,16 +19,17 @@
|
|
|
18
19
|
],
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"ajv": "8.17.1",
|
|
21
|
-
"axios": "1.
|
|
22
|
+
"axios": "1.11.0",
|
|
22
23
|
"commander": "12.1.0",
|
|
23
24
|
"compare-versions": "6.1.1",
|
|
24
|
-
"config": "4.
|
|
25
|
-
"dotenv": "17.2.
|
|
25
|
+
"config": "4.1.1",
|
|
26
|
+
"dotenv": "17.2.1",
|
|
26
27
|
"form-data": "4.0.4",
|
|
27
|
-
"fs-extra": "11.3.
|
|
28
|
+
"fs-extra": "11.3.1",
|
|
28
29
|
"https": "1.0.0",
|
|
29
30
|
"https-proxy-agent": "7.0.6",
|
|
30
|
-
"
|
|
31
|
+
"jszip": "3.10.1",
|
|
32
|
+
"lodash-es": "4.17.21",
|
|
31
33
|
"open": "10.2.0",
|
|
32
34
|
"path": "0.12.7",
|
|
33
35
|
"prompts": "2.4.2",
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResultHandlerFactory = void 0;
|
|
4
|
-
class ResultHandlerFactory {
|
|
1
|
+
export class ResultHandlerFactory {
|
|
5
2
|
static INSTANCE;
|
|
6
3
|
static get() {
|
|
7
4
|
return ResultHandlerFactory.INSTANCE;
|
|
@@ -10,4 +7,3 @@ class ResultHandlerFactory {
|
|
|
10
7
|
ResultHandlerFactory.INSTANCE = instance;
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
exports.ResultHandlerFactory = ResultHandlerFactory;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResultHandlerImpl = void 0;
|
|
4
|
-
class ResultHandlerImpl {
|
|
1
|
+
export class ResultHandlerImpl {
|
|
5
2
|
data;
|
|
6
3
|
setResult(data) {
|
|
7
4
|
this.data = data;
|
|
@@ -10,4 +7,3 @@ class ResultHandlerImpl {
|
|
|
10
7
|
return this.data;
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
exports.ResultHandlerImpl = ResultHandlerImpl;
|
package/result/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/settings/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeyValuePair } from "../types";
|
|
1
|
+
import { KeyValuePair } from "../types.js";
|
|
2
2
|
export declare const get: () => Promise<KeyValuePair>;
|
|
3
3
|
export declare const set: (key: string, value: string) => Promise<void>;
|
|
4
4
|
export declare const remove: (key: string) => Promise<void>;
|
package/settings/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.remove = exports.set = exports.get = void 0;
|
|
4
|
-
const cache_1 = require("../cache");
|
|
5
|
-
const logger_1 = require("../logger");
|
|
1
|
+
import { readFile, writeFile } from "../cache/index.js";
|
|
2
|
+
import { get as getLoggerOrig } from "../logger/index.js";
|
|
6
3
|
const SETTINGS_FILE = "settings.json";
|
|
7
|
-
const getLogger = () => (
|
|
8
|
-
const get = async () => {
|
|
4
|
+
const getLogger = () => getLoggerOrig("settings");
|
|
5
|
+
export const get = async () => {
|
|
9
6
|
try {
|
|
10
|
-
return JSON.parse(await
|
|
7
|
+
return JSON.parse(await readFile(SETTINGS_FILE));
|
|
11
8
|
}
|
|
12
9
|
catch (err) {
|
|
13
10
|
const { debug } = getLogger();
|
|
@@ -15,20 +12,17 @@ const get = async () => {
|
|
|
15
12
|
return {};
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const settings = await (0, exports.get)();
|
|
15
|
+
export const set = async (key, value) => {
|
|
16
|
+
const settings = await get();
|
|
21
17
|
settings[key] = value;
|
|
22
|
-
await
|
|
18
|
+
await writeFile(SETTINGS_FILE, JSON.stringify(settings));
|
|
23
19
|
const { debug } = getLogger();
|
|
24
20
|
debug(`updated key ${key}, value ${value}`);
|
|
25
21
|
};
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const settings = await (0, exports.get)();
|
|
22
|
+
export const remove = async (key) => {
|
|
23
|
+
const settings = await get();
|
|
29
24
|
delete settings[key];
|
|
30
|
-
await
|
|
25
|
+
await writeFile(SETTINGS_FILE, JSON.stringify(settings));
|
|
31
26
|
const { debug } = getLogger();
|
|
32
27
|
debug(`removed key ${key}`);
|
|
33
28
|
};
|
|
34
|
-
exports.remove = remove;
|
package/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type Secret = {
|
|
|
19
19
|
authorization_flow: GrantType;
|
|
20
20
|
};
|
|
21
21
|
export declare const ALLOWED_SECRET_TYPES: string[];
|
|
22
|
-
export { HTTPMethod, HTTPConfig, HTTPResponse };
|
|
22
|
+
export type { HTTPMethod, HTTPConfig, HTTPResponse };
|
|
23
23
|
export type In = "query" | "body" | "header" | "path";
|
|
24
24
|
export type DataType = "boolean" | "string" | "number";
|
|
25
25
|
export type ParameterMapping = {
|
package/types.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GrantType = exports.CHARACTERS = exports.LogLevel = exports.ALLOWED_SECRET_TYPES = void 0;
|
|
4
1
|
// unfortunately there does not seem to be a good solution to automatically
|
|
5
2
|
// create the below array from a statically defined type. Thus, the array must
|
|
6
3
|
// always be kept in sync with the type Secret defined above.
|
|
7
|
-
|
|
4
|
+
export const ALLOWED_SECRET_TYPES = [
|
|
8
5
|
"id",
|
|
9
6
|
"tenantUrl",
|
|
10
7
|
"customClient",
|
|
@@ -22,7 +19,7 @@ exports.ALLOWED_SECRET_TYPES = [
|
|
|
22
19
|
"id_token",
|
|
23
20
|
"authorization_flow",
|
|
24
21
|
];
|
|
25
|
-
var LogLevel;
|
|
22
|
+
export var LogLevel;
|
|
26
23
|
(function (LogLevel) {
|
|
27
24
|
LogLevel[LogLevel["INACTIVE"] = 1] = "INACTIVE";
|
|
28
25
|
LogLevel[LogLevel["ERROR"] = 2] = "ERROR";
|
|
@@ -30,9 +27,9 @@ var LogLevel;
|
|
|
30
27
|
LogLevel[LogLevel["INFO"] = 4] = "INFO";
|
|
31
28
|
LogLevel[LogLevel["DEBUG"] = 5] = "DEBUG";
|
|
32
29
|
LogLevel[LogLevel["TRACE"] = 6] = "TRACE";
|
|
33
|
-
})(LogLevel || (
|
|
30
|
+
})(LogLevel || (LogLevel = {}));
|
|
34
31
|
/* jscpd:ignore-start */
|
|
35
|
-
|
|
32
|
+
export const CHARACTERS = [
|
|
36
33
|
"a",
|
|
37
34
|
"b",
|
|
38
35
|
"c",
|
|
@@ -86,9 +83,9 @@ exports.CHARACTERS = [
|
|
|
86
83
|
"Y",
|
|
87
84
|
"Z",
|
|
88
85
|
];
|
|
89
|
-
var GrantType;
|
|
86
|
+
export var GrantType;
|
|
90
87
|
(function (GrantType) {
|
|
91
88
|
GrantType["authorization_code"] = "authorization_code";
|
|
92
89
|
GrantType["client_credentials"] = "client_credentials";
|
|
93
90
|
GrantType["refresh_token"] = "refresh_token";
|
|
94
|
-
})(GrantType || (
|
|
91
|
+
})(GrantType || (GrantType = {}));
|
package/utils/commands.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Command as CommandType, Option as OptionType } from "../types";
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
|
+
import { Command as CommandType, Option as OptionType } from "../types.js";
|
|
3
3
|
export declare const createCommand: (name?: string) => Command;
|
|
4
4
|
export declare function getAbsoluteCommandName(command: Command): string;
|
|
5
5
|
export declare const getShortFlagForLongName: (command: Command, option: OptionType) => string;
|
|
6
6
|
export declare const isOptionAlreadyRegistered: ({ longName }: OptionType, command: Command) => boolean;
|
|
7
7
|
export declare const registerLongName: (command: Command, option: OptionType) => string;
|
|
8
8
|
export declare const buildOption: (command: Command, option: OptionType) => Promise<Option>;
|
|
9
|
-
export declare const buildCommand: (topCommand:
|
|
9
|
+
export declare const buildCommand: (topCommand: Command, command: CommandType) => Promise<Command>;
|
package/utils/commands.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.buildCommand = exports.buildOption = exports.registerLongName = exports.isOptionAlreadyRegistered = exports.getShortFlagForLongName = exports.createCommand = void 0;
|
|
7
|
-
exports.getAbsoluteCommandName = getAbsoluteCommandName;
|
|
8
|
-
const commander_1 = require("commander");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const types_1 = require("../types");
|
|
11
|
-
const root_1 = require("../commands/handler/root");
|
|
12
|
-
const logger_1 = require("../logger");
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
|
+
import { uniq } from "lodash-es";
|
|
3
|
+
import { CHARACTERS, } from "../types.js";
|
|
4
|
+
import { create as createRootHandler } from "../commands/handler/root/index.js";
|
|
5
|
+
import { get } from "../logger/index.js";
|
|
13
6
|
const registeredOptions = {};
|
|
14
|
-
const getLogger = () =>
|
|
7
|
+
const getLogger = () => get("utils.commands");
|
|
15
8
|
const checkEmpty = (name, value) => {
|
|
16
9
|
if (value.trim() === "") {
|
|
17
10
|
throw new Error(`missing value for parameter ${name}`);
|
|
@@ -29,23 +22,22 @@ const checkCommand = (command) => {
|
|
|
29
22
|
throw err;
|
|
30
23
|
}
|
|
31
24
|
};
|
|
32
|
-
const createCommand = (name) => {
|
|
25
|
+
export const createCommand = (name) => {
|
|
33
26
|
const { output } = getLogger();
|
|
34
|
-
const command = new
|
|
27
|
+
const command = new Command(name);
|
|
35
28
|
command.enablePositionalOptions();
|
|
36
29
|
command.exitOverride();
|
|
37
30
|
command.configureOutput({ writeErr: output, writeOut: output });
|
|
38
31
|
command.allowUnknownOption();
|
|
39
32
|
return command;
|
|
40
33
|
};
|
|
41
|
-
|
|
42
|
-
function getAbsoluteCommandName(command) {
|
|
34
|
+
export function getAbsoluteCommandName(command) {
|
|
43
35
|
if (!command.parent) {
|
|
44
36
|
return command.name();
|
|
45
37
|
}
|
|
46
38
|
return `${getAbsoluteCommandName(command.parent)}.${command.name()}`;
|
|
47
39
|
}
|
|
48
|
-
const getShortFlagForLongName = (command, option) => {
|
|
40
|
+
export const getShortFlagForLongName = (command, option) => {
|
|
49
41
|
const commandName = getAbsoluteCommandName(command);
|
|
50
42
|
for (const s of Object.keys(registeredOptions[commandName] ?? {})) {
|
|
51
43
|
if (registeredOptions[commandName][s] === option.longName) {
|
|
@@ -54,12 +46,10 @@ const getShortFlagForLongName = (command, option) => {
|
|
|
54
46
|
}
|
|
55
47
|
throw new Error(`no short flag registered for command ${commandName}, long name ${option.longName}`);
|
|
56
48
|
};
|
|
57
|
-
|
|
58
|
-
const isOptionAlreadyRegistered = ({ longName }, command) => {
|
|
49
|
+
export const isOptionAlreadyRegistered = ({ longName }, command) => {
|
|
59
50
|
const opts = command.options?.map((o) => o.long?.replace("--", ""));
|
|
60
51
|
return !!opts?.includes(longName);
|
|
61
52
|
};
|
|
62
|
-
exports.isOptionAlreadyRegistered = isOptionAlreadyRegistered;
|
|
63
53
|
function shortFlagFromAnyCommand(optionLongName) {
|
|
64
54
|
let shortFlag;
|
|
65
55
|
Object.keys(registeredOptions).find((c) => {
|
|
@@ -69,7 +59,7 @@ function shortFlagFromAnyCommand(optionLongName) {
|
|
|
69
59
|
return shortFlag;
|
|
70
60
|
}
|
|
71
61
|
function removeUsedShortFlags(possibleShortFlags) {
|
|
72
|
-
const usedShortFlags =
|
|
62
|
+
const usedShortFlags = uniq(Object.keys(registeredOptions).reduce((p1, c1) => {
|
|
73
63
|
return p1.concat(Object.keys(registeredOptions[c1]));
|
|
74
64
|
}, []));
|
|
75
65
|
return possibleShortFlags.filter((s) => !usedShortFlags.includes(s));
|
|
@@ -80,12 +70,12 @@ const getInitialShortFlagOptions = (option) => {
|
|
|
80
70
|
option.longName[0].toUpperCase() === option.longName[0]
|
|
81
71
|
? option.longName[0].toLowerCase()
|
|
82
72
|
: option.longName[0].toUpperCase(),
|
|
83
|
-
...
|
|
73
|
+
...CHARACTERS,
|
|
84
74
|
];
|
|
85
75
|
};
|
|
86
|
-
const registerLongName = (command, option) => {
|
|
76
|
+
export const registerLongName = (command, option) => {
|
|
87
77
|
try {
|
|
88
|
-
return
|
|
78
|
+
return getShortFlagForLongName(command, option);
|
|
89
79
|
}
|
|
90
80
|
catch (err) {
|
|
91
81
|
let possibleShortFlags = getInitialShortFlagOptions(option);
|
|
@@ -110,10 +100,9 @@ const registerLongName = (command, option) => {
|
|
|
110
100
|
throw new Error(`no short flag found for name ${option.longName}, command ${commandName}`);
|
|
111
101
|
}
|
|
112
102
|
};
|
|
113
|
-
|
|
114
|
-
const buildOption = async (command, option) => {
|
|
103
|
+
export const buildOption = async (command, option) => {
|
|
115
104
|
const mandatory = !!option.required;
|
|
116
|
-
const shortFlag =
|
|
105
|
+
const shortFlag = registerLongName(command, option);
|
|
117
106
|
let newDescr = option.description;
|
|
118
107
|
if (!mandatory) {
|
|
119
108
|
newDescr = newDescr ? `${newDescr} (optional)` : "(optional)";
|
|
@@ -121,7 +110,7 @@ const buildOption = async (command, option) => {
|
|
|
121
110
|
const argStr = option.args
|
|
122
111
|
? option.args.reduce((p, c) => (c.optional ? `${p} [${c.name}]` : `${p} <${c.name}>`), "")
|
|
123
112
|
: "";
|
|
124
|
-
const cOption = new
|
|
113
|
+
const cOption = new Option(`-${shortFlag}, --${option.longName}${argStr}`, newDescr)
|
|
125
114
|
.makeOptionMandatory(mandatory)
|
|
126
115
|
.hideHelp(!!option.hidden);
|
|
127
116
|
if (option.default) {
|
|
@@ -142,25 +131,24 @@ const buildOption = async (command, option) => {
|
|
|
142
131
|
}
|
|
143
132
|
return cOption;
|
|
144
133
|
};
|
|
145
|
-
|
|
146
|
-
const buildCommand = async (topCommand, command) => {
|
|
134
|
+
export const buildCommand = async (topCommand, command) => {
|
|
147
135
|
[]
|
|
148
136
|
.concat([command], command.type === "topCommand" ? command.subCommands : [])
|
|
149
137
|
.forEach((c) => checkCommand(c));
|
|
150
138
|
const { command: name, description, options } = command;
|
|
151
|
-
const comm =
|
|
139
|
+
const comm = createCommand(name);
|
|
152
140
|
topCommand.addCommand(comm);
|
|
153
141
|
comm.description(description);
|
|
154
142
|
comm.enablePositionalOptions();
|
|
155
143
|
for (const option of options ?? []) {
|
|
156
144
|
// eslint-disable-next-line no-await-in-loop
|
|
157
|
-
comm.addOption(await
|
|
145
|
+
comm.addOption(await buildOption(comm, option));
|
|
158
146
|
}
|
|
159
147
|
if (command.type === "topCommand") {
|
|
160
148
|
const { subCommands } = command;
|
|
161
149
|
for (const subCommand of subCommands) {
|
|
162
150
|
// eslint-disable-next-line no-await-in-loop
|
|
163
|
-
await
|
|
151
|
+
await buildCommand(comm, subCommand);
|
|
164
152
|
}
|
|
165
153
|
}
|
|
166
154
|
else {
|
|
@@ -169,9 +157,8 @@ const buildCommand = async (topCommand, command) => {
|
|
|
169
157
|
if (args) {
|
|
170
158
|
args.forEach((a) => comm.argument(`<${a.argument}>`, a.description));
|
|
171
159
|
}
|
|
172
|
-
const rootHandler = await (
|
|
160
|
+
const rootHandler = await createRootHandler(command, `Failed to ${command.description}`)(comm);
|
|
173
161
|
comm.action(rootHandler);
|
|
174
162
|
}
|
|
175
163
|
return comm;
|
|
176
164
|
};
|
|
177
|
-
exports.buildCommand = buildCommand;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import https from "https";
|
|
2
|
+
import tls from "tls";
|
|
3
|
+
export declare const getTlsVersion: () => tls.SecureVersion;
|
|
4
|
+
export declare const isLegacyTlsDetectionEnabled: () => boolean;
|
|
5
|
+
export declare const createTlsAgentOptions: () => https.AgentOptions;
|
|
6
|
+
export declare const createHttpsAgent: (proxy?: string) => https.Agent;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import https from "https";
|
|
2
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
3
|
+
import { DEFAULT_TLS_VERSION, OPTION_TLS_VERSION } from "../../constants.js";
|
|
4
|
+
import { get } from "../../logger/index.js";
|
|
5
|
+
import { getOptionValueFromConfig } from "../options.js";
|
|
6
|
+
const getLogger = () => get("http");
|
|
7
|
+
export const getTlsVersion = () => {
|
|
8
|
+
return getOptionValueFromConfig(OPTION_TLS_VERSION, DEFAULT_TLS_VERSION);
|
|
9
|
+
};
|
|
10
|
+
export const isLegacyTlsDetectionEnabled = () => {
|
|
11
|
+
return process.env.CLI_LEGACY_TLS_DETECTION === "true";
|
|
12
|
+
};
|
|
13
|
+
export const createTlsAgentOptions = () => {
|
|
14
|
+
const { debug } = getLogger();
|
|
15
|
+
if (isLegacyTlsDetectionEnabled()) {
|
|
16
|
+
debug("using legacy TLS detection - letting Node.js decide default TLS version");
|
|
17
|
+
return {
|
|
18
|
+
rejectUnauthorized: true,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const tlsVersion = getTlsVersion();
|
|
22
|
+
debug(`configuring HTTPS agent with TLS version: ${tlsVersion}`);
|
|
23
|
+
const agentOptions = {
|
|
24
|
+
minVersion: tlsVersion,
|
|
25
|
+
maxVersion: tlsVersion,
|
|
26
|
+
rejectUnauthorized: true,
|
|
27
|
+
};
|
|
28
|
+
debug("HTTPS agent options:", JSON.stringify(agentOptions, null, 2));
|
|
29
|
+
return agentOptions;
|
|
30
|
+
};
|
|
31
|
+
export const createHttpsAgent = (proxy) => {
|
|
32
|
+
const { debug } = getLogger();
|
|
33
|
+
const agentOptions = createTlsAgentOptions();
|
|
34
|
+
let agent;
|
|
35
|
+
if (proxy) {
|
|
36
|
+
agent = new HttpsProxyAgent(proxy, agentOptions);
|
|
37
|
+
debug(`created HttpsProxyAgent with proxy: ${proxy}`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
agent = new https.Agent(agentOptions);
|
|
41
|
+
debug("created https.Agent with TLS configuration");
|
|
42
|
+
}
|
|
43
|
+
return agent;
|
|
44
|
+
};
|
package/utils/http/index.d.ts
CHANGED
package/utils/http/index.js
CHANGED
|
@@ -1,67 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const logger_1 = require("../../logger");
|
|
11
|
-
const constants_1 = require("../../constants");
|
|
12
|
-
const utils_1 = require("./utils");
|
|
13
|
-
const core_1 = require("../../config/core");
|
|
14
|
-
const utils_2 = require("../../logger/utils");
|
|
15
|
-
exports.DEFAULTS = {
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { getPackageName, getVersion } from "../../config/core.js";
|
|
3
|
+
import { get as getConfig, set as setConfig } from "../../config/index.js";
|
|
4
|
+
import { X_CSRF_TOKEN } from "../../constants.js";
|
|
5
|
+
import { get } from "../../logger/index.js";
|
|
6
|
+
import { logVerbose } from "../../logger/utils.js";
|
|
7
|
+
import { createHttpsAgent, getTlsVersion, isLegacyTlsDetectionEnabled, } from "./httpsAgent.js";
|
|
8
|
+
import { printCorrelationId, printError } from "./utils.js";
|
|
9
|
+
export const DEFAULTS = {
|
|
16
10
|
maxBodyLength: -1,
|
|
17
11
|
maxContentLength: -1,
|
|
18
12
|
maxRedirects: 0, // must be set to 0 because maxBodyLength: -1 won't work otherwise, see github.com/axios/axios/issues/4263,
|
|
19
13
|
};
|
|
20
14
|
const HEADERS_ETAG = "x-sap-cli-core-discovery-etag";
|
|
21
|
-
const getLogger = () =>
|
|
22
|
-
const HTTPS_PROXY = process.env.https_proxy ?? process.env.HTTPS_PROXY;
|
|
15
|
+
const getLogger = () => get("http");
|
|
23
16
|
const setEtag = (headers) => {
|
|
24
17
|
const { debug } = getLogger();
|
|
25
18
|
if (headers?.[HEADERS_ETAG]) {
|
|
26
|
-
(
|
|
19
|
+
setConfig({ etag: headers[HEADERS_ETAG] });
|
|
27
20
|
}
|
|
28
21
|
else {
|
|
29
22
|
debug("header %s is not available", HEADERS_ETAG);
|
|
30
23
|
}
|
|
31
24
|
};
|
|
32
25
|
const getCsrfTokenFromConfig = () => {
|
|
33
|
-
const cnfg = (
|
|
34
|
-
return cnfg[
|
|
26
|
+
const cnfg = getConfig();
|
|
27
|
+
return cnfg[X_CSRF_TOKEN] ? { [X_CSRF_TOKEN]: cnfg[X_CSRF_TOKEN] } : {};
|
|
35
28
|
};
|
|
36
|
-
const fetch = async (config) => {
|
|
37
|
-
const cnfg = (
|
|
29
|
+
export const fetch = async (config) => {
|
|
30
|
+
const cnfg = getConfig();
|
|
38
31
|
const logger = getLogger();
|
|
39
|
-
const { debug,
|
|
32
|
+
const { debug, trace, error } = logger;
|
|
40
33
|
try {
|
|
41
|
-
|
|
34
|
+
logVerbose(logger, "%s %s", config.method.toUpperCase(), config.url);
|
|
42
35
|
debug("http config: %s", JSON.stringify(config));
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const HTTPS_PROXY = process.env.https_proxy ?? process.env.HTTPS_PROXY;
|
|
37
|
+
const httpsAgent = createHttpsAgent(HTTPS_PROXY);
|
|
38
|
+
if (HTTPS_PROXY) {
|
|
39
|
+
logVerbose(logger, "using https proxy agent for https proxy");
|
|
46
40
|
debug(`using https proxy agent for https proxy ${HTTPS_PROXY}`);
|
|
47
41
|
}
|
|
48
42
|
else {
|
|
49
43
|
debug("no https proxy defined via environment variable https_proxy");
|
|
50
44
|
}
|
|
51
|
-
const
|
|
45
|
+
const tlsVersion = getTlsVersion();
|
|
46
|
+
const useLegacyTls = isLegacyTlsDetectionEnabled();
|
|
47
|
+
debug(`TLS configuration - version: ${tlsVersion}, legacy detection: ${useLegacyTls}`);
|
|
48
|
+
const res = await axios({
|
|
52
49
|
httpsAgent,
|
|
53
50
|
proxy: false,
|
|
54
51
|
...config,
|
|
55
|
-
...
|
|
52
|
+
...DEFAULTS,
|
|
56
53
|
headers: {
|
|
57
54
|
...getCsrfTokenFromConfig(),
|
|
58
55
|
...config.headers,
|
|
59
|
-
"User-Agent": `${
|
|
56
|
+
"User-Agent": `${getPackageName()}+${getVersion()}`,
|
|
60
57
|
},
|
|
61
58
|
});
|
|
62
59
|
if (cnfg.verbose) {
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
logVerbose(logger, "%d %s", res.status, res.statusText);
|
|
61
|
+
printCorrelationId(res);
|
|
65
62
|
}
|
|
66
63
|
trace("response", res);
|
|
67
64
|
setEtag(res.headers);
|
|
@@ -70,11 +67,10 @@ const fetch = async (config) => {
|
|
|
70
67
|
catch (err) {
|
|
71
68
|
error("error while executing http request", err.toString(), err.response);
|
|
72
69
|
if (cnfg.verbose) {
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
printError(err);
|
|
71
|
+
printCorrelationId(err.response);
|
|
75
72
|
}
|
|
76
73
|
setEtag(err.response?.headers);
|
|
77
74
|
throw err;
|
|
78
75
|
}
|
|
79
76
|
};
|
|
80
|
-
exports.fetch = fetch;
|
package/utils/http/utils.d.ts
CHANGED