@sap/cli-core 2023.14.0 → 2023.18.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 +179 -2
- package/README.md +1 -1
- package/cache/secrets/SecretsStorageImpl.d.ts +22 -0
- package/cache/secrets/SecretsStorageImpl.js +147 -0
- package/cache/secrets/SecretsStorageSingleton.d.ts +4 -0
- package/cache/secrets/SecretsStorageSingleton.js +7 -0
- package/cache/secrets/types.d.ts +11 -0
- package/cache/secrets/types.js +2 -0
- package/cache/secrets/utils.d.ts +2 -0
- package/cache/secrets/utils.js +18 -0
- package/commands/{cache.command → config.command/cache.command}/clean.command.d.ts +1 -1
- package/commands/{cache.command → config.command/cache.command}/clean.command.js +3 -3
- package/commands/{cache.command → config.command/cache.command}/index.d.ts +1 -1
- package/commands/config.command/cache.command/init.command.d.ts +4 -0
- package/commands/{cache.command → config.command/cache.command}/init.command.js +15 -8
- package/commands/{cache.command → config.command/cache.command}/show.command.d.ts +1 -1
- package/commands/{cache.command → config.command/cache.command}/show.command.js +4 -4
- package/commands/{host.command.d.ts → config.command/host.command.d.ts} +1 -1
- package/commands/{host.command.js → config.command/host.command.js} +12 -12
- package/commands/config.command/index.d.ts +2 -0
- package/commands/config.command/index.js +19 -0
- package/commands/{passcode.command.d.ts → config.command/passcode.command.d.ts} +1 -1
- package/commands/{passcode.command.js → config.command/passcode.command.js} +8 -8
- package/commands/{secrets.command → config.command/secrets.command}/index.d.ts +1 -1
- package/commands/{secrets.command → config.command/secrets.command}/index.js +2 -1
- package/commands/config.command/secrets.command/reset.command.d.ts +3 -0
- package/commands/config.command/secrets.command/reset.command.js +17 -0
- package/commands/{secrets.command → config.command/secrets.command}/show.command.d.ts +1 -1
- package/commands/{secrets.command → config.command/secrets.command}/show.command.js +14 -7
- package/commands/handler/authentication/oauth/secretsProvider/cache.js +4 -5
- package/commands/handler/authentication/oauth/secretsProvider/file.js +3 -3
- package/commands/handler/authentication/oauth/secretsProvider/options.js +12 -6
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +5 -61
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +4 -4
- package/commands/handler/authentication/oauth/tokenProvider/utils.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +77 -4
- package/commands/handler/authentication/oauth/utils.d.ts +0 -4
- package/commands/handler/authentication/oauth/utils.js +13 -27
- package/commands/handler/authentication/passcode/function.js +1 -1
- package/commands/handler/authentication/passcode/input.js +2 -2
- package/commands/handler/authentication/passcode/setPasscode.js +1 -1
- package/commands/handler/authentication/technicalJWT/index.js +2 -2
- package/commands/handler/checkOptionsExistence.js +1 -1
- package/commands/handler/error.js +2 -2
- package/commands/handler/fail.js +1 -1
- package/commands/handler/fetch/fetch.js +1 -1
- package/commands/handler/fetch/utils.js +1 -1
- package/commands/handler/input/file.js +1 -1
- package/commands/handler/input/input.js +2 -2
- package/commands/handler/mandatoryOptions.js +1 -1
- package/commands/handler/next.js +3 -2
- package/commands/handler/options/env.js +1 -2
- package/commands/handler/options/file.js +1 -1
- package/commands/handler/options/index.js +5 -4
- package/commands/handler/options/option.js +1 -1
- package/commands/handler/options/pipe.js +1 -1
- package/commands/handler/options/utils.d.ts +1 -1
- package/commands/handler/options/utils.js +11 -4
- package/commands/handler/or.js +3 -2
- package/commands/handler/parseArguments.js +1 -1
- package/commands/handler/resilient.js +2 -2
- package/commands/handler/root/index.js +2 -2
- package/commands/handler/stackTrace.js +2 -2
- package/commands/handler/succeed.js +1 -1
- package/commands/login.command.js +34 -4
- package/commands/logout.command.js +16 -6
- package/commands/openAPI.command/index.js +3 -8
- package/commands/openAPI.command/utils.js +4 -13
- package/commands/utils.d.ts +2 -0
- package/commands/utils.js +8 -0
- package/config/core.d.ts +1 -0
- package/config/core.js +5 -1
- package/config/index.js +1 -0
- package/constants.d.ts +3 -1
- package/constants.js +34 -5
- package/discovery/index.js +0 -4
- package/dwc/dwc.js +15 -26
- package/dwc/run.js +2 -0
- package/dwc/utils.d.ts +2 -0
- package/dwc/utils.js +34 -2
- package/index.d.ts +2 -1
- package/index.js +4 -1
- package/logger/index.d.ts +1 -10
- package/logger/types.d.ts +10 -0
- package/logger/types.js +2 -0
- package/logger/utils.d.ts +2 -0
- package/logger/utils.js +12 -0
- package/package.json +7 -6
- package/result/ResultHandlerFactory.js +1 -0
- package/result/ResultHandlerImpl.js +1 -0
- package/types.d.ts +9 -3
- package/utils/commands.d.ts +2 -2
- package/utils/commands.js +23 -11
- package/utils/http/index.js +0 -1
- package/utils/utils.d.ts +5 -1
- package/utils/utils.js +15 -4
- package/commands/cache.command/init.command.d.ts +0 -3
- /package/commands/{cache.command → config.command/cache.command}/index.js +0 -0
package/dwc/dwc.js
CHANGED
|
@@ -8,7 +8,6 @@ if (process.env.SUPPRESS_NO_CONFIG_WARNING === undefined) {
|
|
|
8
8
|
process.env.SUPPRESS_NO_CONFIG_WARNING = "true";
|
|
9
9
|
}
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
11
|
const logger_1 = require("../logger");
|
|
13
12
|
const constants_1 = require("../constants");
|
|
14
13
|
const cache_1 = require("../cache");
|
|
@@ -21,6 +20,8 @@ const utils_2 = require("../commands/handler/options/utils");
|
|
|
21
20
|
const core_1 = require("../config/core");
|
|
22
21
|
const ResultHandlerImpl_1 = require("../result/ResultHandlerImpl");
|
|
23
22
|
const ResultHandlerFactory_1 = require("../result/ResultHandlerFactory");
|
|
23
|
+
const SecretsStorageImpl_1 = require("../cache/secrets/SecretsStorageImpl");
|
|
24
|
+
const SecretsStorageSingleton_1 = require("../cache/secrets/SecretsStorageSingleton");
|
|
24
25
|
let program;
|
|
25
26
|
let initialized = false;
|
|
26
27
|
const getLogger = () => (0, logger_1.get)("dwc.dwc");
|
|
@@ -95,8 +96,13 @@ const initCacheTolerant = async () => {
|
|
|
95
96
|
const registerMandatoryOptions = () => {
|
|
96
97
|
MANDATORY_OPTIONS.forEach((option) => (0, commands_1.registerLongName)(option.longName));
|
|
97
98
|
};
|
|
99
|
+
async function setupSecretsStorage() {
|
|
100
|
+
const instance = new SecretsStorageImpl_1.SecretsStorageImpl();
|
|
101
|
+
await instance.initializeStorage();
|
|
102
|
+
SecretsStorageSingleton_1.SecretsStorageSingleton.SINGLETON = instance;
|
|
103
|
+
}
|
|
98
104
|
const init = async () => {
|
|
99
|
-
const {
|
|
105
|
+
const { debug } = getLogger();
|
|
100
106
|
if (initialized) {
|
|
101
107
|
return;
|
|
102
108
|
}
|
|
@@ -107,36 +113,19 @@ const init = async () => {
|
|
|
107
113
|
await setHost();
|
|
108
114
|
await setTenant();
|
|
109
115
|
await initCacheTolerant();
|
|
116
|
+
await setupSecretsStorage();
|
|
110
117
|
program = (0, commands_1.createCommand)();
|
|
111
118
|
program.version((0, core_1.getVersion)(), "-v, --version", "output the current version");
|
|
112
119
|
program.description((0, config_1.get)()[constants_1.CLI_DESCRIPTION]);
|
|
113
|
-
program.showHelpAfterError(`Did you initialize the CLI by running ${(0, config_1.get)()[constants_1.CLI_NAME]} cache init
|
|
120
|
+
program.showHelpAfterError(`Did you initialize the CLI by running ${(0, config_1.get)()[constants_1.CLI_NAME]} config cache init --host "<Server_URL>"?` +
|
|
114
121
|
` Add --help, -h or go to ${(0, config_1.get)()[constants_1.CLI_SAP_HELP]} for additional information.`);
|
|
115
|
-
program.addOption((0, commands_1.buildOption)(constants_1.OPTION_HOST));
|
|
116
|
-
program.addOption((0, commands_1.buildOption)(constants_1.OPTION_OPTIONS_FILE));
|
|
122
|
+
program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_HOST));
|
|
123
|
+
program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_OPTIONS_FILE));
|
|
117
124
|
program.configureHelp({ sortSubcommands: true });
|
|
125
|
+
program.addHelpText("afterAll", `Only command-specific options are listed here. To learn more about available generic options,` +
|
|
126
|
+
` visit ${(0, core_1.getGenericOptionsHelp)()}`);
|
|
118
127
|
const commandsPath = path_1.default.join(__dirname, "..", "commands");
|
|
119
|
-
|
|
120
|
-
encoding: "utf-8",
|
|
121
|
-
withFileTypes: false,
|
|
122
|
-
})).filter((f) => f.includes(".command") && !f.endsWith(".d.ts"))) {
|
|
123
|
-
try {
|
|
124
|
-
// eslint-disable-next-line
|
|
125
|
-
const content = require(path_1.default.join(commandsPath, file));
|
|
126
|
-
if (content.addCommands) {
|
|
127
|
-
debug("adding commands from file %s.addCommands", file);
|
|
128
|
-
// eslint-disable-next-line
|
|
129
|
-
await content.addCommands(program);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
debug("adding command from file %s.default", file);
|
|
133
|
-
(0, commands_1.buildCommand)(program, content.default);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
error("error while adding command from file %s:", file, err.stack);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
128
|
+
await (0, utils_1.addCommandsFromFolder)(commandsPath, program);
|
|
140
129
|
debug("cli initialized");
|
|
141
130
|
};
|
|
142
131
|
exports.init = init;
|
package/dwc/run.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.run = void 0;
|
|
4
|
+
const SecretsStorageSingleton_1 = require("../cache/secrets/SecretsStorageSingleton");
|
|
4
5
|
const core_1 = require("../config/core");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
const dwc_1 = require("./dwc");
|
|
@@ -29,6 +30,7 @@ const run = async () => {
|
|
|
29
30
|
"WARNING: This package has been deprecated. Please consult the README or CHANGELOG for more information.";
|
|
30
31
|
output(message);
|
|
31
32
|
}
|
|
33
|
+
await SecretsStorageSingleton_1.SecretsStorageSingleton.SINGLETON.synchronizeSecretsToStorage();
|
|
32
34
|
if (exitCode > 0) {
|
|
33
35
|
process.exit(exitCode);
|
|
34
36
|
}
|
package/dwc/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
1
2
|
import { Option } from "../types";
|
|
3
|
+
export declare const addCommandsFromFolder: (pathToFolder: string, program: Command) => Promise<void>;
|
|
2
4
|
export declare const checkVersion: () => Promise<void>;
|
|
3
5
|
export declare const compareEtags: () => Promise<void>;
|
|
4
6
|
export declare const getOptionValueFromArgv: ({ longName }: Option) => string;
|
package/dwc/utils.js
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOptionValueFromArgv = exports.compareEtags = exports.checkVersion = void 0;
|
|
6
|
+
exports.getOptionValueFromArgv = exports.compareEtags = exports.checkVersion = exports.addCommandsFromFolder = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
4
9
|
const logger_1 = require("../logger");
|
|
5
10
|
const discovery_1 = require("../discovery");
|
|
6
11
|
const commands_1 = require("../utils/commands");
|
|
7
12
|
const core_1 = require("../config/core");
|
|
13
|
+
const utils_1 = require("../utils/utils");
|
|
8
14
|
const getLogger = () => (0, logger_1.get)("dwc.utils");
|
|
15
|
+
const addCommandsFromFolder = async (pathToFolder, program) => {
|
|
16
|
+
const { error, debug } = getLogger();
|
|
17
|
+
for (const file of (await fs_extra_1.default.readdir(pathToFolder, {
|
|
18
|
+
encoding: "utf-8",
|
|
19
|
+
withFileTypes: false,
|
|
20
|
+
})).filter((f) => f.includes(".command") && !f.endsWith(".d.ts"))) {
|
|
21
|
+
try {
|
|
22
|
+
// eslint-disable-next-line
|
|
23
|
+
const content = require(path_1.default.join(pathToFolder, file));
|
|
24
|
+
if (content.addCommands) {
|
|
25
|
+
debug("adding commands from file %s.addCommands", file);
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
await content.addCommands(program);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
debug("adding command from file %s.default", file);
|
|
31
|
+
// eslint-disable-next-line no-await-in-loop
|
|
32
|
+
await (0, commands_1.buildCommand)(program, content.default);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
error("error while adding command from file %s:", file, err.stack);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.addCommandsFromFolder = addCommandsFromFolder;
|
|
9
41
|
const checkVersion = async () => {
|
|
10
42
|
const { output, error } = getLogger();
|
|
11
43
|
try {
|
|
@@ -22,7 +54,7 @@ exports.checkVersion = checkVersion;
|
|
|
22
54
|
const compareEtags = async () => {
|
|
23
55
|
if (!(await (0, discovery_1.compareEtags)())) {
|
|
24
56
|
const { output } = getLogger();
|
|
25
|
-
output(`Your local CLI cache is outdated. Run '
|
|
57
|
+
output(`Your local CLI cache is outdated. Run '${(0, utils_1.getBin)()} config cache init' to update`);
|
|
26
58
|
}
|
|
27
59
|
};
|
|
28
60
|
exports.compareEtags = compareEtags;
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { run } from "./dwc/run";
|
|
|
3
3
|
export { configure, getCommands } from "./module";
|
|
4
4
|
export { AuthenticationMethod };
|
|
5
5
|
export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils";
|
|
6
|
-
export declare const configureCoreModule: ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods, version, deprecated, deprecationMessage, }: {
|
|
6
|
+
export declare const configureCoreModule: ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods, version, genericOptionsHelp, deprecated, deprecationMessage, }: {
|
|
7
7
|
name: string;
|
|
8
8
|
packageName: string;
|
|
9
9
|
discoveryPath: string;
|
|
@@ -11,6 +11,7 @@ export declare const configureCoreModule: ({ name, packageName, discoveryPath, d
|
|
|
11
11
|
sapHelpLink: string;
|
|
12
12
|
authenticationMethods?: AuthenticationMethod[] | undefined;
|
|
13
13
|
version: string;
|
|
14
|
+
genericOptionsHelp: string;
|
|
14
15
|
deprecated?: boolean | undefined;
|
|
15
16
|
deprecationMessage?: string | undefined;
|
|
16
17
|
}) => void;
|
package/index.js
CHANGED
|
@@ -30,8 +30,10 @@ const configureLoggers_1 = require("./configureLoggers");
|
|
|
30
30
|
dotenv.config();
|
|
31
31
|
(0, configureLoggers_1.configureLoggers)();
|
|
32
32
|
const config_1 = require("./config");
|
|
33
|
+
/* jscpd:ignore-start */
|
|
33
34
|
const constants_1 = require("./constants");
|
|
34
35
|
Object.defineProperty(exports, "AuthenticationMethod", { enumerable: true, get: function () { return constants_1.AuthenticationMethod; } });
|
|
36
|
+
/* jscpd:ignore-end */
|
|
35
37
|
var run_1 = require("./dwc/run");
|
|
36
38
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } });
|
|
37
39
|
var module_1 = require("./module");
|
|
@@ -43,7 +45,7 @@ Object.defineProperty(exports, "getBin", { enumerable: true, get: function () {
|
|
|
43
45
|
Object.defineProperty(exports, "getDescription", { enumerable: true, get: function () { return utils_1.getDescription; } });
|
|
44
46
|
Object.defineProperty(exports, "getName", { enumerable: true, get: function () { return utils_1.getName; } });
|
|
45
47
|
Object.defineProperty(exports, "getPackageName", { enumerable: true, get: function () { return utils_1.getPackageName; } });
|
|
46
|
-
const configureCoreModule = ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, deprecated = false, deprecationMessage, }) => {
|
|
48
|
+
const configureCoreModule = ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, genericOptionsHelp, deprecated = false, deprecationMessage, }) => {
|
|
47
49
|
(0, config_1.set)({
|
|
48
50
|
[constants_1.CLI_NAME]: name,
|
|
49
51
|
[constants_1.CLI_PACKAGE_NAME]: packageName,
|
|
@@ -54,6 +56,7 @@ const configureCoreModule = ({ name, packageName, discoveryPath, description, sa
|
|
|
54
56
|
[constants_1.CLI_VERSION]: version,
|
|
55
57
|
[constants_1.CLI_DEPRECATED]: deprecated,
|
|
56
58
|
[constants_1.CLI_DEPRECATION_MESSAGE]: deprecationMessage,
|
|
59
|
+
[constants_1.CLI_GENERIC_OPTIONS_HELP]: genericOptionsHelp,
|
|
57
60
|
});
|
|
58
61
|
};
|
|
59
62
|
exports.configureCoreModule = configureCoreModule;
|
package/logger/index.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { LogLevel } from "../types";
|
|
2
|
-
|
|
3
|
-
export type Logger = {
|
|
4
|
-
output: Method;
|
|
5
|
-
error: Method;
|
|
6
|
-
warn: Method;
|
|
7
|
-
info: Method;
|
|
8
|
-
log: Method;
|
|
9
|
-
debug: Method;
|
|
10
|
-
trace: Method;
|
|
11
|
-
};
|
|
2
|
+
import { Logger, Method } from "./types";
|
|
12
3
|
type CustomLogger = {
|
|
13
4
|
output?: Method;
|
|
14
5
|
error?: Method;
|
package/logger/types.js
ADDED
package/logger/utils.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logVerbose = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const options_1 = require("../utils/options");
|
|
6
|
+
const logVerbose = (logger, ...args) => {
|
|
7
|
+
const verbose = (0, options_1.getOptionValueFromConfigGracefully)(constants_1.OPTION_VERBOSE);
|
|
8
|
+
if (verbose) {
|
|
9
|
+
logger.output(...args);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.logVerbose = logVerbose;
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap/cli-core",
|
|
3
|
-
"version": "2023.
|
|
3
|
+
"version": "2023.18.0",
|
|
4
4
|
"description": "Command-Line Interface (CLI) Core Module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "SAP SE",
|
|
7
7
|
"homepage": "https://www.sap.com",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "^
|
|
11
|
-
"npm": "^
|
|
10
|
+
"node": "^18",
|
|
11
|
+
"npm": "^9"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"cli",
|
|
15
|
-
"sap
|
|
15
|
+
"sap",
|
|
16
|
+
"sap datasphere",
|
|
16
17
|
"cli-core"
|
|
17
18
|
],
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"ajv": "8.12.0",
|
|
20
21
|
"axios": "1.4.0",
|
|
21
|
-
"commander": "
|
|
22
|
+
"commander": "11.0.0",
|
|
22
23
|
"config": "3.3.9",
|
|
23
|
-
"dotenv": "16.1
|
|
24
|
+
"dotenv": "16.3.1",
|
|
24
25
|
"fs-extra": "11.1.1",
|
|
25
26
|
"https": "1.0.0",
|
|
26
27
|
"lodash": "4.17.21",
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Method as HTTPMethod, AxiosRequestConfig as HTTPConfig, AxiosResponse as HTTPResponse } from "axios";
|
|
2
2
|
import { Command as CommandType } from "commander";
|
|
3
|
-
export type
|
|
3
|
+
export type Secret = {
|
|
4
|
+
id: number;
|
|
5
|
+
tenantUrl: string;
|
|
6
|
+
customClient: boolean;
|
|
4
7
|
client_id: string;
|
|
5
8
|
client_secret: string;
|
|
6
9
|
access_token: string;
|
|
@@ -134,16 +137,19 @@ export type DiscoveryMetadata = {
|
|
|
134
137
|
export type KeyValuePair = {
|
|
135
138
|
[key: string]: any;
|
|
136
139
|
};
|
|
140
|
+
export type ChoicesFunction = () => Promise<Array<string>>;
|
|
141
|
+
export type Choices = Array<string>;
|
|
137
142
|
export type Option = {
|
|
138
143
|
longName: string;
|
|
139
144
|
description: string;
|
|
140
145
|
default?: string;
|
|
141
146
|
required?: boolean;
|
|
142
|
-
choices?:
|
|
147
|
+
choices?: Choices | ChoicesFunction;
|
|
143
148
|
args?: Array<{
|
|
144
149
|
name: string;
|
|
145
150
|
optional?: boolean;
|
|
146
151
|
}>;
|
|
152
|
+
hidden?: boolean;
|
|
147
153
|
prompts?: {
|
|
148
154
|
initial?: any;
|
|
149
155
|
message: string | (() => string);
|
|
@@ -157,7 +163,7 @@ export type HandlerProps = {
|
|
|
157
163
|
options: KeyValuePair;
|
|
158
164
|
};
|
|
159
165
|
export type CommanderHandler = (...args: any[]) => void | Promise<void>;
|
|
160
|
-
export type Handler = (command: CommandType) => CommanderHandler
|
|
166
|
+
export type Handler = (command: CommandType) => Promise<CommanderHandler>;
|
|
161
167
|
export type CommandsArgument = {
|
|
162
168
|
argument: string;
|
|
163
169
|
description: string;
|
package/utils/commands.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare const createCommand: (name?: string) => Command;
|
|
|
4
4
|
export declare const getShortFlagForLongName: (longName: string) => string;
|
|
5
5
|
export declare const isOptionAlreadyRegistered: ({ longName }: OptionType, command: Command) => boolean;
|
|
6
6
|
export declare const registerLongName: (longName: string) => string;
|
|
7
|
-
export declare const buildOption: ({ longName, description, choices, required, default: defaultValue, args, }: OptionType) => Option
|
|
8
|
-
export declare const buildCommand: (topCommand: commander.Command, command: CommandType) =>
|
|
7
|
+
export declare const buildOption: ({ longName, description, choices, required, default: defaultValue, args, hidden, }: OptionType) => Promise<Option>;
|
|
8
|
+
export declare const buildCommand: (topCommand: commander.Command, command: CommandType) => Promise<commander.Command>;
|
package/utils/commands.js
CHANGED
|
@@ -44,9 +44,8 @@ const getShortFlagForLongName = (longName) => {
|
|
|
44
44
|
};
|
|
45
45
|
exports.getShortFlagForLongName = getShortFlagForLongName;
|
|
46
46
|
const isOptionAlreadyRegistered = ({ longName }, command) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return opts.includes(longName);
|
|
47
|
+
const opts = command.options?.map((o) => o.long?.replace("--", ""));
|
|
48
|
+
return !!opts?.includes(longName);
|
|
50
49
|
};
|
|
51
50
|
exports.isOptionAlreadyRegistered = isOptionAlreadyRegistered;
|
|
52
51
|
const registerLongName = (longName) => {
|
|
@@ -70,7 +69,7 @@ const registerLongName = (longName) => {
|
|
|
70
69
|
}
|
|
71
70
|
};
|
|
72
71
|
exports.registerLongName = registerLongName;
|
|
73
|
-
const buildOption = ({ longName, description, choices, required, default: defaultValue, args, }) => {
|
|
72
|
+
const buildOption = async ({ longName, description, choices, required, default: defaultValue, args, hidden, }) => {
|
|
74
73
|
const mandatory = !!required;
|
|
75
74
|
const shortFlag = (0, exports.registerLongName)(longName);
|
|
76
75
|
let newDescr = description;
|
|
@@ -82,14 +81,19 @@ const buildOption = ({ longName, description, choices, required, default: defaul
|
|
|
82
81
|
: "";
|
|
83
82
|
const option = new commander_1.Option(`-${shortFlag}, --${longName}${argStr}`, newDescr)
|
|
84
83
|
.makeOptionMandatory(mandatory)
|
|
85
|
-
.default(defaultValue)
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
.default(defaultValue)
|
|
85
|
+
.hideHelp(!!hidden);
|
|
86
|
+
let choicesArr = [];
|
|
87
|
+
if (choices) {
|
|
88
|
+
choicesArr = typeof choices === "function" ? await choices() : choices;
|
|
89
|
+
}
|
|
90
|
+
if (choicesArr.length > 0) {
|
|
91
|
+
option.choices(choicesArr);
|
|
88
92
|
}
|
|
89
93
|
return option;
|
|
90
94
|
};
|
|
91
95
|
exports.buildOption = buildOption;
|
|
92
|
-
const buildCommand = (topCommand, command) => {
|
|
96
|
+
const buildCommand = async (topCommand, command) => {
|
|
93
97
|
[]
|
|
94
98
|
.concat([command], command.type === "topCommand" ? command.subCommands : [])
|
|
95
99
|
.forEach((c) => checkCommand(c));
|
|
@@ -97,10 +101,16 @@ const buildCommand = (topCommand, command) => {
|
|
|
97
101
|
const comm = (0, exports.createCommand)(name);
|
|
98
102
|
comm.description(description);
|
|
99
103
|
comm.enablePositionalOptions();
|
|
100
|
-
|
|
104
|
+
for (const option of options || []) {
|
|
105
|
+
// eslint-disable-next-line no-await-in-loop
|
|
106
|
+
comm.addOption(await (0, exports.buildOption)(option));
|
|
107
|
+
}
|
|
101
108
|
if (command.type === "topCommand") {
|
|
102
109
|
const { subCommands } = command;
|
|
103
|
-
|
|
110
|
+
for (const subCommand of subCommands) {
|
|
111
|
+
// eslint-disable-next-line no-await-in-loop
|
|
112
|
+
await (0, exports.buildCommand)(comm, subCommand);
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
else {
|
|
106
116
|
// command.type === "command"
|
|
@@ -108,8 +118,10 @@ const buildCommand = (topCommand, command) => {
|
|
|
108
118
|
if (args) {
|
|
109
119
|
args.forEach((a) => comm.argument(`<${a.argument}>`, a.description));
|
|
110
120
|
}
|
|
111
|
-
|
|
121
|
+
const rootHandler = await (0, root_1.create)(handler, `Failed to ${command.description}`)(comm);
|
|
122
|
+
comm.action(rootHandler);
|
|
112
123
|
}
|
|
113
124
|
topCommand.addCommand(comm);
|
|
125
|
+
return comm;
|
|
114
126
|
};
|
|
115
127
|
exports.buildCommand = buildCommand;
|
package/utils/http/index.js
CHANGED
|
@@ -35,7 +35,6 @@ const fetch = async (config) => {
|
|
|
35
35
|
const { debug, trace, error, output } = getLogger();
|
|
36
36
|
try {
|
|
37
37
|
if (cnfg.verbose) {
|
|
38
|
-
// eslint-disable-next-line
|
|
39
38
|
output("%s %s", config.method.toUpperCase(), config.url);
|
|
40
39
|
}
|
|
41
40
|
debug("http config: %s", JSON.stringify(config));
|
package/utils/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PackageJson } from "../types";
|
|
1
|
+
import { Option, PackageJson } from "../types";
|
|
2
|
+
export declare function buildOptionName(option: Option): string;
|
|
2
3
|
export declare const parseVersion: (version: string) => {
|
|
3
4
|
major: number;
|
|
4
5
|
minor: number;
|
|
@@ -17,7 +18,10 @@ export declare const getInfoFromTenant: (tenant: string, verbose: boolean, print
|
|
|
17
18
|
publicfqdn: string;
|
|
18
19
|
passcodeUrl: string;
|
|
19
20
|
tenantUrl: string;
|
|
21
|
+
authorizationUrl: string;
|
|
22
|
+
tokenUrl: string;
|
|
20
23
|
};
|
|
24
|
+
export declare function removeQueryParametersFromUrl(sUrl: string): string;
|
|
21
25
|
export declare const sha256: (string: string) => string;
|
|
22
26
|
export declare const toConstantCase: (string: string) => string;
|
|
23
27
|
export declare const openUrlInBrowser: (url: string, queryParameters?: {
|
package/utils/utils.js
CHANGED
|
@@ -26,15 +26,21 @@ 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.openUrlInBrowser = exports.toConstantCase = exports.sha256 = exports.getInfoFromTenant = exports.parseTenant = exports.removeScopeFromPackageName = exports.getBin = exports.getDescription = exports.getPackageName = exports.getName = exports.getVersion = exports.readPackageJson = exports.requireFile = exports.parseVersion = void 0;
|
|
29
|
+
exports.openUrlInBrowser = exports.toConstantCase = exports.sha256 = exports.removeQueryParametersFromUrl = exports.getInfoFromTenant = exports.parseTenant = exports.removeScopeFromPackageName = exports.getBin = 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
33
|
const open_1 = __importDefault(require("open"));
|
|
34
34
|
const logger_1 = require("../logger");
|
|
35
|
+
const commands_1 = require("./commands");
|
|
35
36
|
let pgk;
|
|
36
37
|
const getLogger = () => (0, logger_1.get)("utils.utils");
|
|
37
38
|
const REGEX_HTTPS = /http(s)*:\/\//;
|
|
39
|
+
function buildOptionName(option) {
|
|
40
|
+
const shortFlag = (0, commands_1.getShortFlagForLongName)(option.longName);
|
|
41
|
+
return `-${shortFlag}, --${option.longName}`;
|
|
42
|
+
}
|
|
43
|
+
exports.buildOptionName = buildOptionName;
|
|
38
44
|
const parseVersion = (version) => {
|
|
39
45
|
const segments = version.split(".");
|
|
40
46
|
return { major: parseInt(segments[0], 10), minor: parseInt(segments[1], 10) };
|
|
@@ -94,9 +100,7 @@ const getBin = (cwd = "") => {
|
|
|
94
100
|
return keys[0];
|
|
95
101
|
};
|
|
96
102
|
exports.getBin = getBin;
|
|
97
|
-
const removeScopeFromPackageName = (packageName) =>
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
99
|
-
packageName.split("/").pop();
|
|
103
|
+
const removeScopeFromPackageName = (packageName) => packageName.split("/").pop();
|
|
100
104
|
exports.removeScopeFromPackageName = removeScopeFromPackageName;
|
|
101
105
|
const removeProtocol = (tenant) => tenant.replace(REGEX_HTTPS, "");
|
|
102
106
|
const parseTenant = (tenant) => {
|
|
@@ -144,10 +148,17 @@ const getInfoFromTenant = (tenant, verbose, printOutput = true) => {
|
|
|
144
148
|
host: `${protocol}//dwaas-core.sac${region}.cfapps.orca.net.sap`,
|
|
145
149
|
publicfqdn: parsedTenant,
|
|
146
150
|
passcodeUrl: `https://${hostname}.authentication.${region}.hana.ondemand.com/passcode`,
|
|
151
|
+
authorizationUrl: `https://${hostname}.authentication.${region}.hana.ondemand.com/oauth/authorize`,
|
|
152
|
+
tokenUrl: `https://${hostname}.authentication.${region}.hana.ondemand.com/oauth/token`,
|
|
147
153
|
tenantUrl: `${protocol}//${parsedTenant}`,
|
|
148
154
|
};
|
|
149
155
|
};
|
|
150
156
|
exports.getInfoFromTenant = getInfoFromTenant;
|
|
157
|
+
function removeQueryParametersFromUrl(sUrl) {
|
|
158
|
+
const url = new URL(sUrl);
|
|
159
|
+
return `${url.protocol}//${url.host}${url.pathname}`;
|
|
160
|
+
}
|
|
161
|
+
exports.removeQueryParametersFromUrl = removeQueryParametersFromUrl;
|
|
151
162
|
const sha256 = (string) =>
|
|
152
163
|
// NOSONAR actually sha256 (or SHA-256) is considered secure according to SonarQube
|
|
153
164
|
crypto.createHash("sha256").update(string).digest("base64");
|
|
File without changes
|