@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
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const utils_4 = require("./handler/options/utils");
|
|
15
|
-
const getLogger = () => (0, logger_1.get)("commands.login");
|
|
16
|
-
const verifyHost = async () => async () => {
|
|
1
|
+
import { SecretsStorageSingleton } from "../cache/secrets/SecretsStorageSingleton.js";
|
|
2
|
+
import { getTenantUrl } from "../cache/secrets/utils.js";
|
|
3
|
+
import { OPTION_ACCESS_TOKEN, OPTION_AUTHORIZATION_FLOW, OPTION_AUTHORIZATION_URL, OPTION_BROWSER, OPTION_CLIENT_ID, OPTION_CLIENT_SECRET, OPTION_CODE, OPTION_HOST, OPTION_OPTIONS_FILE, OPTION_REFRESH_TOKEN, OPTION_SECRETS_FILE, OPTION_TLS_VERSION, OPTION_TOKEN_URL, OPTION_VERBOSE, ROOT_COMMAND, } from "../constants.js";
|
|
4
|
+
import { get } from "../logger/index.js";
|
|
5
|
+
import { logVerbose } from "../logger/utils.js";
|
|
6
|
+
import { getDefaultBrowser, getSupportedBrowsers } from "../utils/openUtils.js";
|
|
7
|
+
import { getOptionValueFromConfig } from "../utils/options.js";
|
|
8
|
+
import { buildOptionName } from "../utils/utils.js";
|
|
9
|
+
import { init } from "./config.command/cache.command/init.command/index.js";
|
|
10
|
+
import { createMandatoryOptionsHandler, createNextHandler, createOauthHandler, createOptionsHandler, createOrHandler, createParseArgumentsHandler, } from "./handler/index.js";
|
|
11
|
+
import { promptForValue } from "./handler/options/utils.js";
|
|
12
|
+
const getLogger = () => get("commands.login");
|
|
13
|
+
export const verifyHost = async () => async () => {
|
|
17
14
|
const logger = getLogger();
|
|
18
15
|
try {
|
|
19
|
-
const url =
|
|
16
|
+
const url = getTenantUrl();
|
|
20
17
|
logger.debug(`url defined as ${url}`);
|
|
21
18
|
}
|
|
22
19
|
catch (err) {
|
|
23
20
|
logger.error("tenant URL not defined. use option -H, --host");
|
|
24
|
-
|
|
21
|
+
logVerbose(logger, "specify the tenant URL using option --host");
|
|
25
22
|
throw new Error("tenant URL not defined. use option -H, --host");
|
|
26
23
|
}
|
|
27
24
|
};
|
|
28
|
-
exports.verifyHost = verifyHost;
|
|
29
25
|
const confirmSecretsOverwrite = async (tenantUrl) => {
|
|
30
|
-
const promptResponse = await
|
|
26
|
+
const promptResponse = await promptForValue({
|
|
31
27
|
prompts: {
|
|
32
28
|
type: "confirm",
|
|
33
29
|
message: `Secret for tenant ${tenantUrl} already exists. Do you want to overwrite it?`,
|
|
@@ -42,37 +38,42 @@ const initializeCache = async () => async () => {
|
|
|
42
38
|
const { warn, info } = getLogger();
|
|
43
39
|
info("initializing cache after successful login");
|
|
44
40
|
try {
|
|
45
|
-
|
|
46
|
-
await (await
|
|
41
|
+
getOptionValueFromConfig(OPTION_HOST);
|
|
42
|
+
await (await init())();
|
|
47
43
|
}
|
|
48
44
|
catch (err) {
|
|
49
|
-
warn(`option ${
|
|
45
|
+
warn(`option ${buildOptionName(ROOT_COMMAND, OPTION_HOST)} not defined, skipping cache init`);
|
|
50
46
|
}
|
|
51
47
|
};
|
|
52
48
|
const fetchSupportedBrowsers = async () => {
|
|
53
|
-
const list = await
|
|
49
|
+
const list = await getSupportedBrowsers();
|
|
54
50
|
return list.map(({ name }) => name);
|
|
55
51
|
};
|
|
56
52
|
const saveSecrets = async () => async () => {
|
|
57
|
-
await
|
|
53
|
+
await SecretsStorageSingleton.SINGLETON.synchronizeSecretsToStorage();
|
|
58
54
|
};
|
|
59
|
-
const
|
|
55
|
+
const warnIfSecretExistsInCache = async () => {
|
|
60
56
|
return async () => {
|
|
61
57
|
const logger = getLogger();
|
|
62
|
-
const tenantUrl =
|
|
63
|
-
const secretsStorage =
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
const tenantUrl = getTenantUrl();
|
|
59
|
+
const secretsStorage = SecretsStorageSingleton.SINGLETON;
|
|
60
|
+
// Default secret is from cache since secrets file and options aren't loaded yet
|
|
61
|
+
const cachedSecret = await secretsStorage.getDefaultSecret();
|
|
62
|
+
if (cachedSecret) {
|
|
66
63
|
const shouldOverwrite = await confirmSecretsOverwrite(tenantUrl);
|
|
67
64
|
logger.debug(`user response for overwriting secrets for tenant ${tenantUrl}: ${shouldOverwrite}`);
|
|
68
65
|
if (!shouldOverwrite) {
|
|
69
66
|
const message = `Aborted: Secret for tenant ${tenantUrl} already exists and will not be overwritten.`;
|
|
70
67
|
logger.warn(message);
|
|
71
|
-
//
|
|
68
|
+
// Stop proceeding with the login process as a secret for the tenant already exists
|
|
72
69
|
return;
|
|
73
70
|
}
|
|
71
|
+
logger.info(`Overwriting existing secret for tenant ${tenantUrl}. Proceeding with login.`);
|
|
72
|
+
// Remove the cached secret to allow the new one to be created
|
|
73
|
+
secretsStorage.deleteSecretById(cachedSecret.id);
|
|
74
|
+
logger.debug(`Existing secret for tenant ${tenantUrl} has been removed.`);
|
|
74
75
|
}
|
|
75
|
-
throw new Error(`
|
|
76
|
+
throw new Error(`Login secret for tenant ${tenantUrl} must be loaded.`);
|
|
76
77
|
};
|
|
77
78
|
};
|
|
78
79
|
const loginCommand = {
|
|
@@ -80,24 +81,25 @@ const loginCommand = {
|
|
|
80
81
|
command: "login",
|
|
81
82
|
description: "log in to your account using interactive OAuth authentication",
|
|
82
83
|
options: [],
|
|
83
|
-
handler:
|
|
84
|
-
{ ...
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{ ...
|
|
88
|
-
{ ...
|
|
89
|
-
{ ...
|
|
90
|
-
{ ...
|
|
91
|
-
{ ...
|
|
92
|
-
{ ...
|
|
93
|
-
{ ...
|
|
94
|
-
{ ...
|
|
84
|
+
handler: createNextHandler("login.command", createParseArgumentsHandler(), createOptionsHandler([
|
|
85
|
+
{ ...OPTION_HOST, hidden: false, required: true },
|
|
86
|
+
OPTION_VERBOSE,
|
|
87
|
+
OPTION_OPTIONS_FILE,
|
|
88
|
+
{ ...OPTION_AUTHORIZATION_URL, hidden: false },
|
|
89
|
+
{ ...OPTION_TOKEN_URL, hidden: false },
|
|
90
|
+
{ ...OPTION_CLIENT_ID, hidden: false },
|
|
91
|
+
{ ...OPTION_CLIENT_SECRET, hidden: false },
|
|
92
|
+
{ ...OPTION_ACCESS_TOKEN, hidden: false },
|
|
93
|
+
{ ...OPTION_CODE, hidden: false },
|
|
94
|
+
{ ...OPTION_REFRESH_TOKEN, hidden: false },
|
|
95
|
+
{ ...OPTION_SECRETS_FILE, hidden: false },
|
|
96
|
+
{ ...OPTION_TLS_VERSION, hidden: false },
|
|
95
97
|
{
|
|
96
|
-
...
|
|
98
|
+
...OPTION_BROWSER,
|
|
97
99
|
choices: fetchSupportedBrowsers,
|
|
98
|
-
default:
|
|
100
|
+
default: getDefaultBrowser,
|
|
99
101
|
},
|
|
100
|
-
{ ...
|
|
101
|
-
]),
|
|
102
|
+
{ ...OPTION_AUTHORIZATION_FLOW, hidden: false },
|
|
103
|
+
]), createMandatoryOptionsHandler(), verifyHost, createOrHandler("commands.login", warnIfSecretExistsInCache, createNextHandler("commands.login", createOauthHandler(), initializeCache, saveSecrets))),
|
|
102
104
|
};
|
|
103
|
-
|
|
105
|
+
export default loginCommand;
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const utils_1 = require("../logger/utils");
|
|
9
|
-
const utils_2 = require("./utils");
|
|
1
|
+
import { SecretsStorageSingleton } from "../cache/secrets/SecretsStorageSingleton.js";
|
|
2
|
+
import { OPTION_LOGIN_ID, OPTION_VERBOSE } from "../constants.js";
|
|
3
|
+
import { get as getLogger } from "../logger/index.js";
|
|
4
|
+
import { get as getConfig } from "../config/index.js";
|
|
5
|
+
import { createNextHandler, createOptionsHandler, createParseArgumentsHandler, } from "./handler/index.js";
|
|
6
|
+
import { logVerbose } from "../logger/utils.js";
|
|
7
|
+
import { getChoices } from "./utils.js";
|
|
10
8
|
const handler = async () => async () => {
|
|
11
9
|
try {
|
|
12
|
-
const config = (
|
|
13
|
-
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
SecretsStorageSingleton.SINGLETON.deleteSecretById(config.options[OPTION_LOGIN_ID.longName]);
|
|
14
12
|
}
|
|
15
13
|
catch (err) {
|
|
16
|
-
const logger = (
|
|
14
|
+
const logger = getLogger("commands.logout");
|
|
17
15
|
logger.error("failed to delete secrets file from cache", err);
|
|
18
|
-
|
|
16
|
+
logVerbose(logger, err.message);
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
const logoutCommand = {
|
|
22
20
|
type: "command",
|
|
23
21
|
command: "logout",
|
|
24
22
|
description: "log out from your account",
|
|
25
|
-
handler:
|
|
26
|
-
{ ...
|
|
27
|
-
|
|
23
|
+
handler: createNextHandler("logout.command", createParseArgumentsHandler(), createOptionsHandler([
|
|
24
|
+
{ ...OPTION_LOGIN_ID, choices: getChoices },
|
|
25
|
+
OPTION_VERBOSE,
|
|
28
26
|
]), handler),
|
|
29
27
|
};
|
|
30
|
-
|
|
28
|
+
export default logoutCommand;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AddCommands } from "../../types";
|
|
1
|
+
import { AddCommands } from "../../types.js";
|
|
2
2
|
export declare const addCommands: AddCommands;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const commands_1 = require("../../utils/commands");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const getLogger = () => (0, logger_1.get)("commands.openAPI");
|
|
1
|
+
import { init } from "../../discovery/index.js";
|
|
2
|
+
import { get } from "../../logger/index.js";
|
|
3
|
+
import { OPTION_HOST } from "../../constants.js";
|
|
4
|
+
import { createFetchHandler, createMandatoryOptionsHandler, createNextHandler, createParseArgumentsHandler, createAuthenticationHandler, createOptionsHandler, } from "../handler/index.js";
|
|
5
|
+
import { buildCommand } from "../../utils/commands.js";
|
|
6
|
+
import { getDescriptionForCommand, getSchema, handleDeprecationNotice, handleForceOption, handleParameters, handleReadPathHandler, handleRequestBody, handleResponses, updatePath, } from "./utils.js";
|
|
7
|
+
const getLogger = () => get("commands.openAPI");
|
|
11
8
|
const getCommandDescription = (document, segments, index) => {
|
|
12
9
|
const segment = segments
|
|
13
10
|
.slice(0, index + 1)
|
|
@@ -26,7 +23,7 @@ const addCommandToArray = (document, commands, segments, index) => {
|
|
|
26
23
|
description: getCommandDescription(document, segments, index),
|
|
27
24
|
command: segment,
|
|
28
25
|
subCommands: [],
|
|
29
|
-
options: [
|
|
26
|
+
options: [OPTION_HOST],
|
|
30
27
|
};
|
|
31
28
|
commands.push(command);
|
|
32
29
|
return addCommandToArray(document, command.subCommands, segments, index + 1);
|
|
@@ -45,12 +42,12 @@ const addCommandToArray = (document, commands, segments, index) => {
|
|
|
45
42
|
};
|
|
46
43
|
const setHandler = (command, method, path, parameterMappings, readPathResponseHandler, ...handler) => {
|
|
47
44
|
// eslint-disable-next-line no-param-reassign
|
|
48
|
-
command.handler =
|
|
45
|
+
command.handler = createNextHandler("openAPI.command", createParseArgumentsHandler(), createMandatoryOptionsHandler(), createAuthenticationHandler(), ...handler, createFetchHandler(method, path, parameterMappings, readPathResponseHandler));
|
|
49
46
|
};
|
|
50
|
-
const addCommands = async (program) => {
|
|
47
|
+
export const addCommands = async (program) => {
|
|
51
48
|
const { error, debug, trace } = getLogger();
|
|
52
49
|
try {
|
|
53
|
-
const doc = await
|
|
50
|
+
const doc = await init();
|
|
54
51
|
const commands = [];
|
|
55
52
|
for (const path of Object.keys(doc.paths)) {
|
|
56
53
|
const pathItem = doc.paths[path];
|
|
@@ -63,14 +60,14 @@ const addCommands = async (program) => {
|
|
|
63
60
|
const cmd = addCommandToArray(doc, commands, operation.operationId.split(" "), 0);
|
|
64
61
|
remove = cmd.remove;
|
|
65
62
|
const { command } = cmd;
|
|
66
|
-
command.description =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const readPathResponseHandler =
|
|
73
|
-
setHandler(command, method,
|
|
63
|
+
command.description = getDescriptionForCommand(command, operation);
|
|
64
|
+
handleRequestBody(operation, handler, doc, parameterMappings, command);
|
|
65
|
+
handleForceOption(operation, handler);
|
|
66
|
+
handleResponses(operation, command);
|
|
67
|
+
handleParameters(operation, doc, parameterMappings, command, getSchema(pathItem.parameters || [], doc));
|
|
68
|
+
handleDeprecationNotice(operation, command);
|
|
69
|
+
const readPathResponseHandler = handleReadPathHandler(doc, operation);
|
|
70
|
+
setHandler(command, method, updatePath(doc, path), parameterMappings, readPathResponseHandler, ...[createOptionsHandler(command.options), ...handler]);
|
|
74
71
|
delete command.options;
|
|
75
72
|
}
|
|
76
73
|
catch (err) {
|
|
@@ -83,7 +80,7 @@ const addCommands = async (program) => {
|
|
|
83
80
|
trace("adding command %s", JSON.stringify(command));
|
|
84
81
|
try {
|
|
85
82
|
// eslint-disable-next-line no-await-in-loop
|
|
86
|
-
await
|
|
83
|
+
await buildCommand(program, command);
|
|
87
84
|
}
|
|
88
85
|
catch (err) {
|
|
89
86
|
error("error while adding command %s", JSON.stringify(command, null, 2), err.stack);
|
|
@@ -95,4 +92,3 @@ const addCommands = async (program) => {
|
|
|
95
92
|
throw err;
|
|
96
93
|
}
|
|
97
94
|
};
|
|
98
|
-
exports.addCommands = addCommands;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, Discovery, Handler, In, JSONReference, JSONSchema, Operation, Option, ParameterMappings, Parameters, ResponsePostProcessor } from "../../types";
|
|
1
|
+
import { Command, Discovery, Handler, In, JSONReference, JSONSchema, Operation, Option, ParameterMappings, Parameters, ResponsePostProcessor } from "../../types.js";
|
|
2
2
|
type ExtendedType = {
|
|
3
3
|
allowEmptyValue?: boolean;
|
|
4
4
|
required?: boolean;
|
|
@@ -1,75 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.handleDeprecationNotice = exports.handleParameters = exports.handleResponses = exports.handleForceOption = exports.handleRequestBody = exports.buildOptionFromType = exports.addOptionToCommand = exports.getSchema = exports.getDescriptionForCommand = exports.handleReadPathHandler = exports.getSegments = exports.writeParameter = exports.isPathParameter = exports.updatePath = void 0;
|
|
37
|
-
const lodash_1 = __importStar(require("lodash"));
|
|
38
|
-
const constants_1 = require("../../constants");
|
|
39
|
-
const logger_1 = require("../../logger");
|
|
40
|
-
const utils_1 = require("../../utils/utils");
|
|
41
|
-
const config_1 = require("../../config");
|
|
42
|
-
const handler_1 = require("../handler");
|
|
43
|
-
const ResultHandlerFactory_1 = require("../../result/ResultHandlerFactory");
|
|
44
|
-
const getLogger = () => (0, logger_1.get)("commands.openAPI.utils");
|
|
45
|
-
const updatePath = (doc, path) => {
|
|
46
|
-
const version = (0, utils_1.parseVersion)(doc.info.version);
|
|
1
|
+
import { kebabCase, get } from "lodash-es";
|
|
2
|
+
import { CLI_NAME, OPTION_OUTPUT, OPTION_NO_PRETTY, X_CSRF_TOKEN, } from "../../constants.js";
|
|
3
|
+
import { get as loggerGet } from "../../logger/index.js";
|
|
4
|
+
import { parseVersion } from "../../utils/utils.js";
|
|
5
|
+
import { get as getConfig } from "../../config/index.js";
|
|
6
|
+
import { createForceHandler, createInputHandler } from "../handler/index.js";
|
|
7
|
+
import { ResultHandlerFactory } from "../../result/ResultHandlerFactory.js";
|
|
8
|
+
const getLogger = () => loggerGet("commands.openAPI.utils");
|
|
9
|
+
export const updatePath = (doc, path) => {
|
|
10
|
+
const version = parseVersion(doc.info.version);
|
|
47
11
|
if (version.major < 2023) {
|
|
48
12
|
return `/dwaas-core${path}`;
|
|
49
13
|
}
|
|
50
14
|
return path;
|
|
51
15
|
};
|
|
52
|
-
|
|
53
|
-
const isPathParameter = (segment) => /^{.*}$/.test(segment);
|
|
54
|
-
exports.isPathParameter = isPathParameter;
|
|
16
|
+
export const isPathParameter = (segment) => /^{.*}$/.test(segment);
|
|
55
17
|
function getParameterName(parameter) {
|
|
56
|
-
return `--${
|
|
18
|
+
return `--${kebabCase(parameter.slice(1, -1))}`;
|
|
57
19
|
}
|
|
58
|
-
const writeParameter = (parameter, value) => `${getParameterName(parameter)} ${value}`;
|
|
59
|
-
|
|
60
|
-
const getSegments = (value) => {
|
|
20
|
+
export const writeParameter = (parameter, value) => `${getParameterName(parameter)} ${value}`;
|
|
21
|
+
export const getSegments = (value) => {
|
|
61
22
|
const segments = value.split("/");
|
|
62
23
|
return segments.filter((segment) => {
|
|
63
24
|
const s = segment.trim();
|
|
64
25
|
return s !== "" && s !== "marketplace";
|
|
65
26
|
});
|
|
66
27
|
};
|
|
67
|
-
exports.getSegments = getSegments;
|
|
68
28
|
const handleParameter = (params, pathSegment, locationSegment) => {
|
|
69
|
-
if (
|
|
29
|
+
if (isPathParameter(pathSegment)) {
|
|
70
30
|
return params
|
|
71
|
-
? `${params} ${
|
|
72
|
-
:
|
|
31
|
+
? `${params} ${writeParameter(pathSegment, locationSegment)}`
|
|
32
|
+
: writeParameter(pathSegment, locationSegment);
|
|
73
33
|
}
|
|
74
34
|
return params;
|
|
75
35
|
};
|
|
@@ -81,14 +41,14 @@ const getPathItem = (doc, operation, path) => {
|
|
|
81
41
|
throw new Error(`path ${operation["x-read-path"]} does not support GET operation`);
|
|
82
42
|
};
|
|
83
43
|
function handleOptions(options, option, value) {
|
|
84
|
-
if (
|
|
44
|
+
if (isPathParameter(option)) {
|
|
85
45
|
return { ...options, [getParameterName(option)]: value };
|
|
86
46
|
}
|
|
87
47
|
return options;
|
|
88
48
|
}
|
|
89
49
|
const outputReadCommand = (doc, operation, response, path) => {
|
|
90
|
-
const locationSegments =
|
|
91
|
-
const pathSegments =
|
|
50
|
+
const locationSegments = getSegments(response.headers.location);
|
|
51
|
+
const pathSegments = getSegments(path);
|
|
92
52
|
let params = "";
|
|
93
53
|
let options = {};
|
|
94
54
|
for (let i = 0; i < pathSegments.length; i++) {
|
|
@@ -96,12 +56,12 @@ const outputReadCommand = (doc, operation, response, path) => {
|
|
|
96
56
|
options = handleOptions(options, pathSegments[i], locationSegments[i]);
|
|
97
57
|
}
|
|
98
58
|
const pathItem = getPathItem(doc, operation, path);
|
|
99
|
-
|
|
59
|
+
ResultHandlerFactory.get().setResult({
|
|
100
60
|
command: pathItem.get.operationId,
|
|
101
61
|
options,
|
|
102
62
|
});
|
|
103
63
|
const { output } = getLogger();
|
|
104
|
-
output(`Use ${(
|
|
64
|
+
output(`Use ${getConfig()[CLI_NAME]} ${pathItem.get.operationId} ${params} to retrieve the entity you just created`);
|
|
105
65
|
};
|
|
106
66
|
const readPathHandlerFunction = (doc, operation, path) => async (response) => {
|
|
107
67
|
const { debug } = getLogger();
|
|
@@ -115,16 +75,14 @@ const readPathHandlerFunction = (doc, operation, path) => async (response) => {
|
|
|
115
75
|
const dummyFunction = async () => {
|
|
116
76
|
// This is intentional
|
|
117
77
|
};
|
|
118
|
-
const handleReadPathHandler = (doc, operation) => {
|
|
78
|
+
export const handleReadPathHandler = (doc, operation) => {
|
|
119
79
|
const path = operation["x-read-path"];
|
|
120
80
|
if (path) {
|
|
121
81
|
return readPathHandlerFunction(doc, operation, path);
|
|
122
82
|
}
|
|
123
83
|
return dummyFunction;
|
|
124
84
|
};
|
|
125
|
-
|
|
126
|
-
const getDescriptionForCommand = (command, operation) => command.description || operation.description || operation.summary || "";
|
|
127
|
-
exports.getDescriptionForCommand = getDescriptionForCommand;
|
|
85
|
+
export const getDescriptionForCommand = (command, operation) => command.description || operation.description || operation.summary || "";
|
|
128
86
|
const getReferenceFromDocument = (reference, document) => {
|
|
129
87
|
const { trace } = getLogger();
|
|
130
88
|
const segments = reference.$ref.split("/");
|
|
@@ -137,21 +95,20 @@ const getReferenceFromDocument = (reference, document) => {
|
|
|
137
95
|
.slice(1)
|
|
138
96
|
.reduce((prev, curr) => (prev !== "" ? `${prev}.${curr}` : curr), "");
|
|
139
97
|
trace("reading reference %s, path %s", reference.$ref, path);
|
|
140
|
-
return
|
|
98
|
+
return get(document, path);
|
|
141
99
|
};
|
|
142
|
-
const getSchema = (obj, doc) => {
|
|
100
|
+
export const getSchema = (obj, doc) => {
|
|
143
101
|
if (obj.$ref) {
|
|
144
102
|
return getReferenceFromDocument(obj, doc);
|
|
145
103
|
}
|
|
146
104
|
return obj;
|
|
147
105
|
};
|
|
148
|
-
exports.getSchema = getSchema;
|
|
149
106
|
const getKeysFromSchema = (schema, doc, key = "", required = false) => {
|
|
150
107
|
const { trace } = getLogger();
|
|
151
108
|
trace(`retrieving keys for key ${key} from schema ${JSON.stringify(schema)}`);
|
|
152
109
|
if (schema.$ref) {
|
|
153
110
|
// eslint-disable-next-line no-param-reassign
|
|
154
|
-
schema =
|
|
111
|
+
schema = getSchema(schema, doc);
|
|
155
112
|
}
|
|
156
113
|
if (schema.type === "object" && schema.properties) {
|
|
157
114
|
let keys = [];
|
|
@@ -171,7 +128,7 @@ const flattenType = (type, doc) => {
|
|
|
171
128
|
return result;
|
|
172
129
|
}
|
|
173
130
|
if (type.$ref) {
|
|
174
|
-
const schema =
|
|
131
|
+
const schema = getSchema(type, doc);
|
|
175
132
|
return flattenType({
|
|
176
133
|
...schema,
|
|
177
134
|
allowEmptyValue: type.allowEmptyValue,
|
|
@@ -183,12 +140,11 @@ const flattenType = (type, doc) => {
|
|
|
183
140
|
}
|
|
184
141
|
return [type];
|
|
185
142
|
};
|
|
186
|
-
const addOptionToCommand = (option, options) => {
|
|
143
|
+
export const addOptionToCommand = (option, options) => {
|
|
187
144
|
const { trace } = getLogger();
|
|
188
145
|
options.push(option);
|
|
189
146
|
trace("added option %s", JSON.stringify(option));
|
|
190
147
|
};
|
|
191
|
-
exports.addOptionToCommand = addOptionToCommand;
|
|
192
148
|
const checkTypes = (types) => {
|
|
193
149
|
for (const t of types) {
|
|
194
150
|
if (types.length > 1 && t.enum?.length === 1) {
|
|
@@ -210,7 +166,7 @@ const initParams = (types) => {
|
|
|
210
166
|
return params;
|
|
211
167
|
};
|
|
212
168
|
const handleOptionName = (name, params, description) => {
|
|
213
|
-
let optionName =
|
|
169
|
+
let optionName = kebabCase(name);
|
|
214
170
|
let def;
|
|
215
171
|
let newDescription = description;
|
|
216
172
|
if (params.default !== undefined) {
|
|
@@ -259,10 +215,10 @@ const buildOption = (commandName, longName, types, params, description, def) =>
|
|
|
259
215
|
const handleOption = (commandName, name, params, types, options, description) => {
|
|
260
216
|
const { optionName, def, description: newDescription, } = handleOptionName(name, params, description);
|
|
261
217
|
const option = buildOption(commandName, optionName, types, params, newDescription, def);
|
|
262
|
-
|
|
218
|
+
addOptionToCommand(option, options);
|
|
263
219
|
};
|
|
264
|
-
const requiresUserInput = (name) => name !==
|
|
265
|
-
const buildOptionFromType = (commandName, doc, parameterIn, name, type, parameterMappings, options, description) => {
|
|
220
|
+
const requiresUserInput = (name) => name !== X_CSRF_TOKEN;
|
|
221
|
+
export const buildOptionFromType = (commandName, doc, parameterIn, name, type, parameterMappings, options, description) => {
|
|
266
222
|
try {
|
|
267
223
|
const types = flattenType(type, doc);
|
|
268
224
|
checkTypes(types);
|
|
@@ -283,7 +239,7 @@ const buildOptionFromType = (commandName, doc, parameterIn, name, type, paramete
|
|
|
283
239
|
name,
|
|
284
240
|
source: {
|
|
285
241
|
type: "option",
|
|
286
|
-
name:
|
|
242
|
+
name: kebabCase(name),
|
|
287
243
|
dataType: params.booleanAvailable ? "boolean" : "string", // we don't care whether it's a string or number, it simply must not be boolean in this case
|
|
288
244
|
},
|
|
289
245
|
});
|
|
@@ -299,45 +255,41 @@ const buildOptionFromType = (commandName, doc, parameterIn, name, type, paramete
|
|
|
299
255
|
}
|
|
300
256
|
}
|
|
301
257
|
};
|
|
302
|
-
|
|
303
|
-
const handleRequestBody = (operation, handler, doc, parameterMappings, command) => {
|
|
258
|
+
export const handleRequestBody = (operation, handler, doc, parameterMappings, command) => {
|
|
304
259
|
if (operation["x-requestbody-fileonly"]) {
|
|
305
|
-
handler.push(
|
|
260
|
+
handler.push(createInputHandler());
|
|
306
261
|
}
|
|
307
262
|
else if (operation.requestBody) {
|
|
308
|
-
const schema =
|
|
263
|
+
const schema = getSchema(Object.values(operation.requestBody.content)[0].schema, doc);
|
|
309
264
|
const keys = getKeysFromSchema(schema, doc);
|
|
310
265
|
keys.forEach((key) => {
|
|
311
266
|
if (key.schema.oneOf) {
|
|
312
267
|
throw new Error("invalid request body parameter resolution, oneOf not supported");
|
|
313
268
|
}
|
|
314
|
-
|
|
269
|
+
buildOptionFromType(command.command, doc, "body", key.key, {
|
|
315
270
|
...key.schema,
|
|
316
271
|
required: key.required,
|
|
317
272
|
}, parameterMappings, command.options, key.schema.description);
|
|
318
273
|
});
|
|
319
274
|
}
|
|
320
275
|
};
|
|
321
|
-
|
|
322
|
-
const handleForceOption = (operation, handler) => {
|
|
276
|
+
export const handleForceOption = (operation, handler) => {
|
|
323
277
|
if (operation["x-user-to-confirm"]) {
|
|
324
|
-
handler.push(
|
|
278
|
+
handler.push(createForceHandler(operation["x-user-to-confirm"]));
|
|
325
279
|
}
|
|
326
280
|
};
|
|
327
|
-
|
|
328
|
-
const handleResponses = (operation, command) => {
|
|
281
|
+
export const handleResponses = (operation, command) => {
|
|
329
282
|
if (operation.responses?.[200]) {
|
|
330
|
-
|
|
283
|
+
addOptionToCommand(OPTION_OUTPUT, command.options);
|
|
331
284
|
}
|
|
332
|
-
|
|
285
|
+
addOptionToCommand(OPTION_NO_PRETTY, command.options);
|
|
333
286
|
};
|
|
334
|
-
|
|
335
|
-
const handleParameters = (operation, doc, parameterMappings, command, topLevelParameters = []) => {
|
|
287
|
+
export const handleParameters = (operation, doc, parameterMappings, command, topLevelParameters = []) => {
|
|
336
288
|
const { error } = getLogger();
|
|
337
289
|
(operation.parameters || []).concat(topLevelParameters).forEach((p) => {
|
|
338
290
|
try {
|
|
339
|
-
const parameter =
|
|
340
|
-
|
|
291
|
+
const parameter = getSchema(p, doc);
|
|
292
|
+
buildOptionFromType(command.command, doc, parameter.in, parameter.name, {
|
|
341
293
|
...parameter.schema,
|
|
342
294
|
allowEmptyValue: parameter.allowEmptyValue,
|
|
343
295
|
required: parameter.required,
|
|
@@ -348,8 +300,7 @@ const handleParameters = (operation, doc, parameterMappings, command, topLevelPa
|
|
|
348
300
|
}
|
|
349
301
|
});
|
|
350
302
|
};
|
|
351
|
-
|
|
352
|
-
const handleDeprecationNotice = (operation, command) => {
|
|
303
|
+
export const handleDeprecationNotice = (operation, command) => {
|
|
353
304
|
if (operation.deprecated && command.type === "command") {
|
|
354
305
|
// eslint-disable-next-line no-param-reassign
|
|
355
306
|
command.deprecationInfo = {
|
|
@@ -361,4 +312,3 @@ const handleDeprecationNotice = (operation, command) => {
|
|
|
361
312
|
};
|
|
362
313
|
}
|
|
363
314
|
};
|
|
364
|
-
exports.handleDeprecationNotice = handleDeprecationNotice;
|
package/commands/utils.d.ts
CHANGED
package/commands/utils.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const openUtils_1 = require("../utils/openUtils");
|
|
6
|
-
const getChoices = async () => {
|
|
7
|
-
return SecretsStorageSingleton_1.SecretsStorageSingleton.SINGLETON.getAllSecrets().map((secret) => secret.id.toString(10));
|
|
1
|
+
import { SecretsStorageSingleton } from "../cache/secrets/SecretsStorageSingleton.js";
|
|
2
|
+
import { getSupportedBrowsers } from "../utils/openUtils.js";
|
|
3
|
+
export const getChoices = async () => {
|
|
4
|
+
return SecretsStorageSingleton.SINGLETON.getAllSecrets().map((secret) => secret.id.toString(10));
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const list = await (0, openUtils_1.getSupportedBrowsers)();
|
|
6
|
+
export const getBrowserChoices = async () => {
|
|
7
|
+
const list = await getSupportedBrowsers();
|
|
12
8
|
return list.map(({ name }) => name);
|
|
13
9
|
};
|
|
14
|
-
exports.getBrowserChoices = getBrowserChoices;
|
package/config/core.d.ts
CHANGED