@sap/cli-core 2025.17.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 +6 -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 -2
- package/cache/secrets/SecretsStorageImpl.js +18 -22
- 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 +1 -1
- 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 +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +16 -20
- package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +1 -1
- 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 +56 -75
- 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 +41 -45
- 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 +1 -1
- package/constants.js +57 -63
- 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.js +16 -26
- package/utils/http/index.d.ts +1 -1
- package/utils/http/index.js +28 -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/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 2025.18.0
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- The CLI has been migrated to [EcmaScript Module (ESM)](https://nodejs.org/api/esm.html) syntax. As a result, support for Node.js versions 18 and 19 has been dropped, and Node.js 20 or later is now required. No APIs or other external properties of the CLI have been modified, so with a supported Node.js version, the CLI is expected to continue functioning as before.
|
|
13
|
+
|
|
8
14
|
## 2025.17.0
|
|
9
15
|
|
|
10
16
|
### Changed
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Command-Line Interface (CLI) Core Module.
|
|
4
4
|
|
|
5
|
-
[](https://nodejs.org/dist/latest-v20.x/docs/api/#) [](https://nodejs.org/dist/latest-v21.x/docs/api/#) [](https://nodejs.org/dist/latest-v22.x/docs/api/#) [](https://badge.fury.io/js/@sap%2Fcli-core)
|
|
6
6
|
|
|
7
7
|
## Content
|
|
8
8
|
|
package/cache/cache.js
CHANGED
|
@@ -1,82 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.getFiles = exports.cleanCache = exports.deleteFile = exports.writeFile = exports.readFile = exports.init = void 0;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const logger_1 = require("../logger");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const getLogger = () => (0, logger_1.get)("cache");
|
|
11
|
-
const init = async () => {
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { get } from "../logger/index.js";
|
|
3
|
+
import { getPath } from "./utils.js";
|
|
4
|
+
const getLogger = () => get("cache");
|
|
5
|
+
export const init = async () => {
|
|
12
6
|
const { trace } = getLogger();
|
|
13
7
|
try {
|
|
14
8
|
trace("initializing cache");
|
|
15
|
-
await
|
|
9
|
+
await fs.mkdir(getPath(), { recursive: true });
|
|
16
10
|
}
|
|
17
11
|
catch (err) {
|
|
18
12
|
trace("error while initializing cache", err.toString());
|
|
19
13
|
throw err;
|
|
20
14
|
}
|
|
21
15
|
};
|
|
22
|
-
|
|
23
|
-
const readFile = async (file) => {
|
|
16
|
+
export const readFile = async (file) => {
|
|
24
17
|
const { trace, debug } = getLogger();
|
|
25
18
|
try {
|
|
26
19
|
trace("reading file %s from cache", file);
|
|
27
|
-
return await
|
|
20
|
+
return await fs.readFile(getPath(file), "utf-8");
|
|
28
21
|
}
|
|
29
22
|
catch (err) {
|
|
30
23
|
debug("error while reading file %s from cache", file, err.toString());
|
|
31
24
|
throw err;
|
|
32
25
|
}
|
|
33
26
|
};
|
|
34
|
-
|
|
35
|
-
const writeFile = async (file, data) => {
|
|
27
|
+
export const writeFile = async (file, data) => {
|
|
36
28
|
const { trace, debug } = getLogger();
|
|
37
29
|
try {
|
|
38
30
|
trace("writing file %s to cache", file);
|
|
39
|
-
await
|
|
31
|
+
await fs.writeFile(getPath(file), data, "utf-8");
|
|
40
32
|
}
|
|
41
33
|
catch (err) {
|
|
42
34
|
debug("error while writing file %s to cache", file, err.toString());
|
|
43
35
|
throw err;
|
|
44
36
|
}
|
|
45
37
|
};
|
|
46
|
-
|
|
47
|
-
const deleteFile = async (file) => {
|
|
38
|
+
export const deleteFile = async (file) => {
|
|
48
39
|
const { trace, debug } = getLogger();
|
|
49
40
|
try {
|
|
50
41
|
trace("deleting file %s from cache", file);
|
|
51
|
-
await
|
|
42
|
+
await fs.remove(getPath(file));
|
|
52
43
|
}
|
|
53
44
|
catch (err) {
|
|
54
45
|
debug("error while deleting file %s from cache", file, err.toString());
|
|
55
46
|
throw err;
|
|
56
47
|
}
|
|
57
48
|
};
|
|
58
|
-
|
|
59
|
-
const cleanCache = async () => {
|
|
49
|
+
export const cleanCache = async () => {
|
|
60
50
|
const { trace, debug } = getLogger();
|
|
61
51
|
try {
|
|
62
52
|
trace("cleaning cache");
|
|
63
|
-
await
|
|
53
|
+
await fs.remove(getPath());
|
|
64
54
|
}
|
|
65
55
|
catch (err) {
|
|
66
56
|
debug("error while cleaning cache", err.toString());
|
|
67
57
|
throw err;
|
|
68
58
|
}
|
|
69
59
|
};
|
|
70
|
-
|
|
71
|
-
const getFiles = async () => {
|
|
60
|
+
export const getFiles = async () => {
|
|
72
61
|
const { trace, debug } = getLogger();
|
|
73
62
|
try {
|
|
74
63
|
trace("reading existing files");
|
|
75
|
-
return await
|
|
64
|
+
return await fs.readdir(getPath(), "utf-8");
|
|
76
65
|
}
|
|
77
66
|
catch (err) {
|
|
78
67
|
debug("error while reading existing files", err.toString());
|
|
79
68
|
throw err;
|
|
80
69
|
}
|
|
81
70
|
};
|
|
82
|
-
exports.getFiles = getFiles;
|
package/cache/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { readFile, init, cleanCache, deleteFile, writeFile, getFiles, } from "./cache";
|
|
2
|
-
export { getPath } from "./utils";
|
|
1
|
+
export { readFile, init, cleanCache, deleteFile, writeFile, getFiles, } from "./cache.js";
|
|
2
|
+
export { getPath } from "./utils.js";
|
package/cache/index.js
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getPath = exports.getFiles = exports.writeFile = exports.deleteFile = exports.cleanCache = exports.init = exports.readFile = void 0;
|
|
4
|
-
var cache_1 = require("./cache");
|
|
5
|
-
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return cache_1.readFile; } });
|
|
6
|
-
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return cache_1.init; } });
|
|
7
|
-
Object.defineProperty(exports, "cleanCache", { enumerable: true, get: function () { return cache_1.cleanCache; } });
|
|
8
|
-
Object.defineProperty(exports, "deleteFile", { enumerable: true, get: function () { return cache_1.deleteFile; } });
|
|
9
|
-
Object.defineProperty(exports, "writeFile", { enumerable: true, get: function () { return cache_1.writeFile; } });
|
|
10
|
-
Object.defineProperty(exports, "getFiles", { enumerable: true, get: function () { return cache_1.getFiles; } });
|
|
11
|
-
var utils_1 = require("./utils");
|
|
12
|
-
Object.defineProperty(exports, "getPath", { enumerable: true, get: function () { return utils_1.getPath; } });
|
|
1
|
+
export { readFile, init, cleanCache, deleteFile, writeFile, getFiles, } from "./cache.js";
|
|
2
|
+
export { getPath } from "./utils.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Secret } from "../../types";
|
|
2
|
-
import { SecretsStorage } from "./types";
|
|
1
|
+
import { Secret } from "../../types.js";
|
|
2
|
+
import { SecretsStorage } from "./types.js";
|
|
3
3
|
export declare class SecretsStorageImpl implements SecretsStorage {
|
|
4
4
|
private secrets;
|
|
5
5
|
private logger;
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const cache_1 = require("../cache");
|
|
9
|
-
const utils_2 = require("./utils");
|
|
10
|
-
class SecretsStorageImpl {
|
|
1
|
+
import { CACHE_SECRETS_FILE } from "../../constants.js";
|
|
2
|
+
import { get as getLogger } from "../../logger/index.js";
|
|
3
|
+
import { logVerbose } from "../../logger/utils.js";
|
|
4
|
+
import { ALLOWED_SECRET_TYPES } from "../../types.js";
|
|
5
|
+
import { deleteFile, readFile, writeFile } from "../cache.js";
|
|
6
|
+
import { getTenantUrl, isCustomClient, isSecretConsistent, updateUrls, } from "./utils.js";
|
|
7
|
+
export class SecretsStorageImpl {
|
|
11
8
|
secrets = [];
|
|
12
9
|
logger;
|
|
13
10
|
constructor() {
|
|
14
|
-
this.logger = (
|
|
11
|
+
this.logger = getLogger("SecretsStorageImpl");
|
|
15
12
|
}
|
|
16
13
|
async deleteAllSecrets() {
|
|
17
|
-
await
|
|
14
|
+
await deleteFile(CACHE_SECRETS_FILE);
|
|
18
15
|
this.secrets = [];
|
|
19
16
|
}
|
|
20
17
|
async recreateCalculatedValues() {
|
|
21
18
|
for (let i = 0; i < this.secrets.length; i++) {
|
|
22
19
|
this.secrets[i].id = i;
|
|
23
20
|
if (this.secrets[i].client_id) {
|
|
24
|
-
this.secrets[i].customClient =
|
|
21
|
+
this.secrets[i].customClient = isCustomClient(this.secrets[i].client_id);
|
|
25
22
|
// eslint-disable-next-line no-await-in-loop
|
|
26
23
|
await this.updateUrls(i);
|
|
27
24
|
}
|
|
@@ -32,7 +29,7 @@ class SecretsStorageImpl {
|
|
|
32
29
|
}
|
|
33
30
|
async initializeStorage() {
|
|
34
31
|
try {
|
|
35
|
-
this.secrets = JSON.parse(await
|
|
32
|
+
this.secrets = JSON.parse(await readFile(CACHE_SECRETS_FILE));
|
|
36
33
|
if (!Array.isArray(this.secrets)) {
|
|
37
34
|
this.logger.warn("secrets data is no array, initializing secrets to empty array");
|
|
38
35
|
this.secrets = [];
|
|
@@ -41,7 +38,7 @@ class SecretsStorageImpl {
|
|
|
41
38
|
await this.recreateCalculatedValues();
|
|
42
39
|
}
|
|
43
40
|
catch (err) {
|
|
44
|
-
|
|
41
|
+
logVerbose(this.logger, "The secrets file could not be read.");
|
|
45
42
|
this.logger.warn("failed to read or parse secrets file", err);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
@@ -49,7 +46,7 @@ class SecretsStorageImpl {
|
|
|
49
46
|
return this.getSecretById(await this.getDefaultSecretId());
|
|
50
47
|
}
|
|
51
48
|
async getDefaultSecretId() {
|
|
52
|
-
const tenantUrl =
|
|
49
|
+
const tenantUrl = getTenantUrl();
|
|
53
50
|
const { host } = new URL(tenantUrl);
|
|
54
51
|
const secret = this.secrets.find((s) => new URL(s.tenantUrl).host === host);
|
|
55
52
|
if (!secret) {
|
|
@@ -73,7 +70,7 @@ class SecretsStorageImpl {
|
|
|
73
70
|
this.secrets.splice(id, 1);
|
|
74
71
|
}
|
|
75
72
|
updateSecret(secret) {
|
|
76
|
-
const tenantUrl =
|
|
73
|
+
const tenantUrl = getTenantUrl();
|
|
77
74
|
let prevSecretIx = this.secrets.findIndex((s) => s.tenantUrl === tenantUrl);
|
|
78
75
|
let newSecret;
|
|
79
76
|
if (prevSecretIx > -1) {
|
|
@@ -99,7 +96,7 @@ class SecretsStorageImpl {
|
|
|
99
96
|
return prevSecretIx;
|
|
100
97
|
}
|
|
101
98
|
async updateUrls(secretIndex) {
|
|
102
|
-
this.secrets[secretIndex] = await
|
|
99
|
+
this.secrets[secretIndex] = await updateUrls(this.secrets[secretIndex]);
|
|
103
100
|
}
|
|
104
101
|
async storeSecret(secret) {
|
|
105
102
|
this.updateSecret(secret);
|
|
@@ -111,7 +108,7 @@ class SecretsStorageImpl {
|
|
|
111
108
|
}
|
|
112
109
|
removeInconsistentSecrets() {
|
|
113
110
|
this.secrets = this.secrets.filter((secret) => {
|
|
114
|
-
const consistent =
|
|
111
|
+
const consistent = isSecretConsistent(secret);
|
|
115
112
|
if (!consistent.consistent) {
|
|
116
113
|
this.logger.warn(`secret ${JSON.stringify(secret)} is not consistent and removed from cache. ${consistent.errors.join(". ")}`);
|
|
117
114
|
return false;
|
|
@@ -122,7 +119,7 @@ class SecretsStorageImpl {
|
|
|
122
119
|
removeUnknownPropertiesFromSecrets() {
|
|
123
120
|
this.secrets.forEach((secret) => {
|
|
124
121
|
Object.keys(secret).forEach((key) => {
|
|
125
|
-
if (!
|
|
122
|
+
if (!ALLOWED_SECRET_TYPES.includes(key)) {
|
|
126
123
|
// eslint-disable-next-line no-param-reassign
|
|
127
124
|
delete secret[key];
|
|
128
125
|
}
|
|
@@ -133,7 +130,7 @@ class SecretsStorageImpl {
|
|
|
133
130
|
try {
|
|
134
131
|
this.removeInconsistentSecrets();
|
|
135
132
|
this.removeUnknownPropertiesFromSecrets();
|
|
136
|
-
await
|
|
133
|
+
await writeFile(CACHE_SECRETS_FILE, JSON.stringify(this.secrets));
|
|
137
134
|
}
|
|
138
135
|
catch (err) {
|
|
139
136
|
this.logger.error("failed to synchronize secrets to storage", err);
|
|
@@ -143,4 +140,3 @@ class SecretsStorageImpl {
|
|
|
143
140
|
return this.secrets;
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
|
-
exports.SecretsStorageImpl = SecretsStorageImpl;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecretsStorageSingleton = void 0;
|
|
4
|
-
class SecretsStorageSingleton {
|
|
1
|
+
export class SecretsStorageSingleton {
|
|
5
2
|
static SINGLETON;
|
|
6
3
|
}
|
|
7
|
-
exports.SecretsStorageSingleton = SecretsStorageSingleton;
|
package/cache/secrets/types.d.ts
CHANGED
package/cache/secrets/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cache/secrets/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Secret } from "../../types";
|
|
1
|
+
import { Secret } from "../../types.js";
|
|
2
2
|
export declare const isCustomClient: (clientId?: string) => boolean;
|
|
3
3
|
export declare const getTenantUrl: () => string;
|
|
4
4
|
export declare function updateUrls(secret: Secret): Promise<Secret>;
|
package/cache/secrets/utils.js
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const config_1 = require("../../config");
|
|
7
|
-
const constants_1 = require("../../constants");
|
|
8
|
-
const types_1 = require("../../types");
|
|
9
|
-
const http_1 = require("../../utils/http");
|
|
10
|
-
const utils_1 = require("../../utils/utils");
|
|
1
|
+
import { get } from "../../config/index.js";
|
|
2
|
+
import { OPTION_HOST } from "../../constants.js";
|
|
3
|
+
import { GrantType } from "../../types.js";
|
|
4
|
+
import { fetch } from "../../utils/http/index.js";
|
|
5
|
+
import { isValidURL, removeQueryParametersFromUrl } from "../../utils/utils.js";
|
|
11
6
|
// Pre-delivered OAuth Client ID: 5a638330-5899-366e-ac00-ab62cc32dcda
|
|
12
7
|
// Custom OAuth Client ID: sb-00bb7bc2-cc32-423c-921c-2abdee11a29d!b49931|client!b3650
|
|
13
|
-
const isCustomClient = (clientId) => clientId ? clientId.startsWith("sb-") : true;
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const tenantUrl = config.tenantUrl ?? config.options[constants_1.OPTION_HOST.longName];
|
|
8
|
+
export const isCustomClient = (clientId) => clientId ? clientId.startsWith("sb-") : true;
|
|
9
|
+
export const getTenantUrl = () => {
|
|
10
|
+
const config = get();
|
|
11
|
+
const tenantUrl = config.tenantUrl ?? config.options[OPTION_HOST.longName];
|
|
18
12
|
if (!tenantUrl) {
|
|
19
13
|
throw new Error("no tenant url found");
|
|
20
14
|
}
|
|
21
15
|
return tenantUrl;
|
|
22
16
|
};
|
|
23
|
-
|
|
24
|
-
async function updateUrls(secret) {
|
|
17
|
+
export async function updateUrls(secret) {
|
|
25
18
|
if (secret.client_id) {
|
|
26
|
-
const config =
|
|
19
|
+
const config = get();
|
|
27
20
|
let oauth = {};
|
|
28
21
|
if (!secret.customClient &&
|
|
29
22
|
(!secret.authorization_url || !secret.token_url)) {
|
|
30
|
-
oauth = (await
|
|
23
|
+
oauth = (await fetch({
|
|
31
24
|
method: "GET",
|
|
32
25
|
url: `${config.tenantUrl}/oauth`,
|
|
33
26
|
})).data;
|
|
@@ -54,23 +47,23 @@ async function updateUrls(secret) {
|
|
|
54
47
|
throw new Error("invalid token url or authorization url");
|
|
55
48
|
}
|
|
56
49
|
// eslint-disable-next-line no-param-reassign
|
|
57
|
-
secret.authorization_url =
|
|
50
|
+
secret.authorization_url = removeQueryParametersFromUrl(authorizationUrl);
|
|
58
51
|
// eslint-disable-next-line no-param-reassign
|
|
59
|
-
secret.token_url =
|
|
52
|
+
secret.token_url = removeQueryParametersFromUrl(tokenUrl);
|
|
60
53
|
}
|
|
61
54
|
return secret;
|
|
62
55
|
}
|
|
63
|
-
function isSecretConsistent(secret) {
|
|
56
|
+
export function isSecretConsistent(secret) {
|
|
64
57
|
const errors = [];
|
|
65
|
-
if (!(
|
|
66
|
-
((secret.authorization_flow !==
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
if (!(isValidURL(secret.tenantUrl) ||
|
|
59
|
+
((secret.authorization_flow !== GrantType.authorization_code ||
|
|
60
|
+
isValidURL(secret.authorization_url)) &&
|
|
61
|
+
isValidURL(secret.token_url)))) {
|
|
69
62
|
errors.push("the secrets file is missing either property tenantUrl or properties authorization_url and token_url" +
|
|
70
63
|
" or the URLs are not valid");
|
|
71
64
|
}
|
|
72
65
|
if (!(secret.access_token ||
|
|
73
|
-
((secret.authorization_flow !==
|
|
66
|
+
((secret.authorization_flow !== GrantType.authorization_code ||
|
|
74
67
|
secret.refresh_token) &&
|
|
75
68
|
secret.client_id &&
|
|
76
69
|
secret.client_secret))) {
|
package/cache/utils.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.getPath = void 0;
|
|
7
|
-
const os_1 = require("os");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const core_1 = require("../config/core");
|
|
10
|
-
const utils_1 = require("../utils/utils");
|
|
11
|
-
const getPath = (...args) => {
|
|
1
|
+
import { homedir } from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { getPackageName } from "../config/core.js";
|
|
4
|
+
import { removeScopeFromPackageName } from "../utils/utils.js";
|
|
5
|
+
export const getPath = (...args) => {
|
|
12
6
|
const rootPath = process.env.CLI_LEGACY_CACHE_LOCATION === "true"
|
|
13
|
-
?
|
|
14
|
-
:
|
|
15
|
-
return
|
|
7
|
+
? import.meta.dirname
|
|
8
|
+
: path.join(homedir(), ".@sap", removeScopeFromPackageName(getPackageName()));
|
|
9
|
+
return path.join(rootPath, ".cache", ...args);
|
|
16
10
|
};
|
|
17
|
-
exports.getPath = getPath;
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const options_1 = require("../../../utils/options");
|
|
6
|
-
const handler_1 = require("../../handler");
|
|
1
|
+
import { cleanCache, deleteFile, getFiles } from "../../../cache/index.js";
|
|
2
|
+
import { DISCOVERY_DOCUMENT_PREFIX } from "../../../constants.js";
|
|
3
|
+
import { getOptionValueFromConfigGracefully } from "../../../utils/options.js";
|
|
4
|
+
import { createNextHandler, createParseArgumentsHandler, } from "../../handler/index.js";
|
|
7
5
|
const OPTION_PURGE_ALL = {
|
|
8
6
|
longName: "purge-all",
|
|
9
7
|
description: "clean the whole local CLI cache",
|
|
10
8
|
};
|
|
11
9
|
const cleanHandler = async () => async () => {
|
|
12
|
-
const purgeAll =
|
|
10
|
+
const purgeAll = getOptionValueFromConfigGracefully(OPTION_PURGE_ALL);
|
|
13
11
|
if (purgeAll) {
|
|
14
|
-
await
|
|
12
|
+
await cleanCache();
|
|
15
13
|
}
|
|
16
14
|
else {
|
|
17
|
-
const files = (await
|
|
18
|
-
await Promise.all(files.map(async (file) =>
|
|
15
|
+
const files = (await getFiles()).filter((file) => file.startsWith(DISCOVERY_DOCUMENT_PREFIX));
|
|
16
|
+
await Promise.all(files.map(async (file) => deleteFile(file)));
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
const cleanCommand = {
|
|
22
20
|
type: "command",
|
|
23
21
|
command: "clean",
|
|
24
22
|
description: "clean the local CLI cache",
|
|
25
|
-
handler:
|
|
23
|
+
handler: createNextHandler("command.config.cache.clean", createParseArgumentsHandler(), cleanHandler),
|
|
26
24
|
options: [OPTION_PURGE_ALL],
|
|
27
25
|
};
|
|
28
|
-
|
|
26
|
+
export default cleanCommand;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const clean_command_1 = __importDefault(require("./clean.command"));
|
|
7
|
-
const init_command_1 = __importDefault(require("./init.command"));
|
|
8
|
-
const show_command_1 = __importDefault(require("./show.command"));
|
|
1
|
+
import cleanCommand from "./clean.command.js";
|
|
2
|
+
import initCommand from "./init.command/index.js";
|
|
3
|
+
import showCommand from "./show.command.js";
|
|
9
4
|
const cacheCommand = {
|
|
10
5
|
type: "topCommand",
|
|
11
6
|
command: "cache",
|
|
12
7
|
description: "work with the local CLI cache",
|
|
13
|
-
subCommands: [
|
|
8
|
+
subCommands: [initCommand, cleanCommand, showCommand],
|
|
14
9
|
};
|
|
15
|
-
|
|
10
|
+
export default cacheCommand;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommanderHandler, LeafCommand } from "../../../../types";
|
|
1
|
+
import { CommanderHandler, LeafCommand } from "../../../../types.js";
|
|
2
2
|
export declare const init: () => Promise<CommanderHandler>;
|
|
3
3
|
declare const initCommand: LeafCommand;
|
|
4
4
|
export default initCommand;
|
|
@@ -1,71 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable no-await-in-loop */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const core_1 = require("../../../../config/core");
|
|
14
|
-
const ResultHandlerFactory_1 = require("../../../../result/ResultHandlerFactory");
|
|
15
|
-
const utils_1 = require("./utils");
|
|
16
|
-
const utils_2 = require("../../../handler/utils");
|
|
17
|
-
const logger_1 = require("../../../../logger");
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { getDiscoveryPaths } from "../../../../config/core.js";
|
|
4
|
+
import { get as getConfig, set as setConfig, } from "../../../../config/index.js";
|
|
5
|
+
import { AuthenticationMethod, OPTION_OUTPUT, VERSION, } from "../../../../constants.js";
|
|
6
|
+
import { addMetadata as addDiscoveryMetadata, clear, getPathToDiscoveryDocument, } from "../../../../discovery/index.js";
|
|
7
|
+
import { get } from "../../../../logger/index.js";
|
|
8
|
+
import { ResultHandlerFactory } from "../../../../result/ResultHandlerFactory.js";
|
|
9
|
+
import { createAuthenticationHandler, createFetchHandler, createMandatoryOptionsHandler, createNextHandler, createParseArgumentsHandler, } from "../../../handler/index.js";
|
|
10
|
+
import { getAuthenticationMethod } from "../../../handler/utils.js";
|
|
11
|
+
import { mergeDiscoveries } from "./utils.js";
|
|
18
12
|
const pre = () => {
|
|
19
|
-
(
|
|
13
|
+
setConfig({
|
|
20
14
|
doNotStoreResult: false,
|
|
21
15
|
doNotProcessResponseData: true,
|
|
22
16
|
});
|
|
23
17
|
};
|
|
24
18
|
const post = async (discovery) => {
|
|
25
|
-
const config = (
|
|
26
|
-
await (
|
|
19
|
+
const config = getConfig();
|
|
20
|
+
await addDiscoveryMetadata({
|
|
27
21
|
tenant: config.publicfqdn,
|
|
28
22
|
addedAt: new Date().getTime(),
|
|
29
23
|
});
|
|
30
|
-
|
|
24
|
+
clear();
|
|
31
25
|
const { options } = config;
|
|
32
|
-
delete options[
|
|
33
|
-
(
|
|
34
|
-
|
|
35
|
-
await
|
|
26
|
+
delete options[OPTION_OUTPUT.longName];
|
|
27
|
+
setConfig({ options });
|
|
28
|
+
ResultHandlerFactory.get().setResult(undefined);
|
|
29
|
+
await fs.writeFile(getPathToDiscoveryDocument(), JSON.stringify(discovery));
|
|
36
30
|
};
|
|
37
|
-
const init = async () => async () => {
|
|
31
|
+
export const init = async () => async () => {
|
|
38
32
|
pre();
|
|
39
|
-
const { output } =
|
|
33
|
+
const { output } = get("init.command");
|
|
40
34
|
const discovery = {
|
|
41
35
|
info: {
|
|
42
|
-
version:
|
|
43
|
-
"x-document-version":
|
|
36
|
+
version: VERSION,
|
|
37
|
+
"x-document-version": VERSION,
|
|
44
38
|
},
|
|
45
39
|
openapi: "3.0.3",
|
|
46
40
|
paths: {},
|
|
47
41
|
tags: [],
|
|
48
42
|
components: {},
|
|
49
43
|
};
|
|
50
|
-
const paths =
|
|
44
|
+
const paths = getDiscoveryPaths();
|
|
51
45
|
if (paths.length > 1 &&
|
|
52
|
-
|
|
46
|
+
getAuthenticationMethod() !== AuthenticationMethod.oauth) {
|
|
53
47
|
output("Only OAuth authentication is supported");
|
|
54
48
|
throw new Error("only oauth authentication is supported");
|
|
55
49
|
}
|
|
56
50
|
for (const path of paths) {
|
|
57
|
-
await (await
|
|
58
|
-
const newDiscovery =
|
|
59
|
-
|
|
51
|
+
await (await createFetchHandler("GET", path)({}))();
|
|
52
|
+
const newDiscovery = ResultHandlerFactory.get().getResult();
|
|
53
|
+
mergeDiscoveries(discovery, newDiscovery);
|
|
60
54
|
}
|
|
61
55
|
await post(discovery);
|
|
62
56
|
};
|
|
63
|
-
exports.init = init;
|
|
64
57
|
const initCommand = {
|
|
65
58
|
type: "command",
|
|
66
59
|
command: "init",
|
|
67
60
|
description: "initialize the local CLI cache",
|
|
68
61
|
options: [],
|
|
69
|
-
handler:
|
|
62
|
+
handler: createNextHandler("command.config.cache.init", createParseArgumentsHandler(), createMandatoryOptionsHandler(), createAuthenticationHandler(), init),
|
|
70
63
|
};
|
|
71
|
-
|
|
64
|
+
export default initCommand;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getLowerVersion = getLowerVersion;
|
|
7
|
-
exports.mergeDiscoveries = mergeDiscoveries;
|
|
8
|
-
const compare_versions_1 = require("compare-versions");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
function getLowerVersion(a, b) {
|
|
11
|
-
return [a, b].sort(compare_versions_1.compareVersions)[0];
|
|
1
|
+
import { compareVersions } from "compare-versions";
|
|
2
|
+
import { merge } from "lodash-es";
|
|
3
|
+
export function getLowerVersion(a, b) {
|
|
4
|
+
return [a, b].sort(compareVersions)[0];
|
|
12
5
|
}
|
|
13
|
-
function mergeDiscoveries(discovery, newDiscovery) {
|
|
14
|
-
|
|
6
|
+
export function mergeDiscoveries(discovery, newDiscovery) {
|
|
7
|
+
merge(discovery, newDiscovery);
|
|
15
8
|
// eslint-disable-next-line no-param-reassign
|
|
16
9
|
discovery.info.version = getLowerVersion(discovery.info.version, newDiscovery.info.version);
|
|
17
10
|
// eslint-disable-next-line no-param-reassign
|