@sap/cli-core 2025.17.0 → 2025.20.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.
Files changed (186) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/cache/cache.js +16 -28
  4. package/cache/index.d.ts +2 -2
  5. package/cache/index.js +2 -12
  6. package/cache/secrets/SecretsStorageImpl.d.ts +2 -2
  7. package/cache/secrets/SecretsStorageImpl.js +18 -22
  8. package/cache/secrets/SecretsStorageSingleton.d.ts +1 -1
  9. package/cache/secrets/SecretsStorageSingleton.js +1 -5
  10. package/cache/secrets/types.d.ts +1 -1
  11. package/cache/secrets/types.js +1 -2
  12. package/cache/secrets/utils.d.ts +1 -1
  13. package/cache/secrets/utils.js +20 -27
  14. package/cache/utils.js +8 -15
  15. package/commands/config.command/cache.command/clean.command.d.ts +1 -1
  16. package/commands/config.command/cache.command/clean.command.js +10 -12
  17. package/commands/config.command/cache.command/index.d.ts +1 -1
  18. package/commands/config.command/cache.command/index.js +5 -10
  19. package/commands/config.command/cache.command/init.command/index.d.ts +1 -1
  20. package/commands/config.command/cache.command/init.command/index.js +29 -36
  21. package/commands/config.command/cache.command/init.command/utils.d.ts +1 -1
  22. package/commands/config.command/cache.command/init.command/utils.js +6 -13
  23. package/commands/config.command/cache.command/show.command.d.ts +1 -1
  24. package/commands/config.command/cache.command/show.command.js +7 -9
  25. package/commands/config.command/host.command.d.ts +1 -1
  26. package/commands/config.command/host.command.js +19 -23
  27. package/commands/config.command/index.d.ts +1 -1
  28. package/commands/config.command/index.js +5 -45
  29. package/commands/config.command/passcode.command.d.ts +1 -1
  30. package/commands/config.command/passcode.command.js +12 -16
  31. package/commands/config.command/secrets.command/check.command.d.ts +1 -2
  32. package/commands/config.command/secrets.command/check.command.js +10 -14
  33. package/commands/config.command/secrets.command/index.d.ts +1 -1
  34. package/commands/config.command/secrets.command/index.js +6 -11
  35. package/commands/config.command/secrets.command/refresh.command.d.ts +1 -1
  36. package/commands/config.command/secrets.command/refresh.command.js +5 -7
  37. package/commands/config.command/secrets.command/reset.command.d.ts +1 -1
  38. package/commands/config.command/secrets.command/reset.command.js +6 -8
  39. package/commands/config.command/secrets.command/show.command.d.ts +1 -1
  40. package/commands/config.command/secrets.command/show.command.js +8 -10
  41. package/commands/handler/authentication/index.d.ts +1 -1
  42. package/commands/handler/authentication/index.js +18 -21
  43. package/commands/handler/authentication/oauth/index.d.ts +1 -1
  44. package/commands/handler/authentication/oauth/index.js +13 -16
  45. package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +1 -1
  46. package/commands/handler/authentication/oauth/secretsProvider/cache.js +5 -9
  47. package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +1 -1
  48. package/commands/handler/authentication/oauth/secretsProvider/file.js +20 -25
  49. package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +1 -1
  50. package/commands/handler/authentication/oauth/secretsProvider/index.js +6 -10
  51. package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +1 -1
  52. package/commands/handler/authentication/oauth/secretsProvider/options.js +25 -29
  53. package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +1 -1
  54. package/commands/handler/authentication/oauth/tokenProvider/getToken.js +16 -20
  55. package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +1 -1
  56. package/commands/handler/authentication/oauth/tokenProvider/index.js +7 -11
  57. package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +1 -1
  58. package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +5 -9
  59. package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +1 -1
  60. package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +19 -24
  61. package/commands/handler/authentication/oauth/tokenProvider/utils.js +30 -36
  62. package/commands/handler/authentication/oauth/utils.d.ts +1 -1
  63. package/commands/handler/authentication/oauth/utils.js +15 -24
  64. package/commands/handler/authentication/passcode/function.d.ts +1 -1
  65. package/commands/handler/authentication/passcode/function.js +11 -13
  66. package/commands/handler/authentication/passcode/index.d.ts +1 -1
  67. package/commands/handler/authentication/passcode/index.js +14 -17
  68. package/commands/handler/authentication/passcode/input.d.ts +1 -1
  69. package/commands/handler/authentication/passcode/input.js +13 -20
  70. package/commands/handler/authentication/passcode/setPasscode.d.ts +1 -1
  71. package/commands/handler/authentication/passcode/setPasscode.js +9 -13
  72. package/commands/handler/authentication/passcode/types.js +1 -2
  73. package/commands/handler/authentication/technicalJWT/cf.js +9 -11
  74. package/commands/handler/authentication/technicalJWT/exec.d.ts +5 -6
  75. package/commands/handler/authentication/technicalJWT/exec.js +15 -19
  76. package/commands/handler/authentication/technicalJWT/index.d.ts +1 -1
  77. package/commands/handler/authentication/technicalJWT/index.js +8 -12
  78. package/commands/handler/authentication/technicalJWT/types.d.ts +1 -1
  79. package/commands/handler/authentication/technicalJWT/types.js +1 -4
  80. package/commands/handler/authentication/technicalJWT/utils.js +20 -27
  81. package/commands/handler/authentication/utils.js +3 -7
  82. package/commands/handler/checkOptionsExistence.d.ts +1 -1
  83. package/commands/handler/checkOptionsExistence.js +5 -9
  84. package/commands/handler/error.d.ts +1 -1
  85. package/commands/handler/error.js +4 -8
  86. package/commands/handler/fail.d.ts +1 -1
  87. package/commands/handler/fail.js +3 -7
  88. package/commands/handler/fetch/fetch.d.ts +1 -1
  89. package/commands/handler/fetch/fetch.js +26 -27
  90. package/commands/handler/fetch/index.d.ts +1 -1
  91. package/commands/handler/fetch/index.js +10 -14
  92. package/commands/handler/fetch/utils.d.ts +2 -2
  93. package/commands/handler/fetch/utils.js +56 -75
  94. package/commands/handler/force.d.ts +1 -1
  95. package/commands/handler/force.js +8 -15
  96. package/commands/handler/index.d.ts +18 -18
  97. package/commands/handler/index.js +18 -39
  98. package/commands/handler/input/file.d.ts +1 -1
  99. package/commands/handler/input/file.js +22 -29
  100. package/commands/handler/input/index.d.ts +1 -1
  101. package/commands/handler/input/index.js +4 -8
  102. package/commands/handler/input/input.d.ts +1 -1
  103. package/commands/handler/input/input.js +16 -23
  104. package/commands/handler/mandatoryOptions.d.ts +1 -1
  105. package/commands/handler/mandatoryOptions.js +13 -17
  106. package/commands/handler/next.d.ts +1 -1
  107. package/commands/handler/next.js +4 -8
  108. package/commands/handler/options/env.d.ts +1 -1
  109. package/commands/handler/options/env.js +8 -12
  110. package/commands/handler/options/file.d.ts +1 -1
  111. package/commands/handler/options/file.js +8 -12
  112. package/commands/handler/options/index.d.ts +1 -1
  113. package/commands/handler/options/index.js +15 -19
  114. package/commands/handler/options/option.d.ts +1 -1
  115. package/commands/handler/options/option.js +12 -13
  116. package/commands/handler/options/utils.d.ts +4 -2
  117. package/commands/handler/options/utils.js +18 -26
  118. package/commands/handler/or.d.ts +1 -1
  119. package/commands/handler/or.js +3 -7
  120. package/commands/handler/parseArguments.d.ts +1 -1
  121. package/commands/handler/parseArguments.js +11 -15
  122. package/commands/handler/resilient.d.ts +1 -1
  123. package/commands/handler/resilient.js +3 -7
  124. package/commands/handler/root/index.d.ts +1 -1
  125. package/commands/handler/root/index.js +3 -7
  126. package/commands/handler/stackTrace.d.ts +1 -1
  127. package/commands/handler/stackTrace.js +3 -7
  128. package/commands/handler/succeed.d.ts +1 -1
  129. package/commands/handler/succeed.js +3 -7
  130. package/commands/handler/utils.d.ts +1 -1
  131. package/commands/handler/utils.js +17 -27
  132. package/commands/login.command.d.ts +1 -1
  133. package/commands/login.command.js +41 -45
  134. package/commands/logout.command.d.ts +1 -1
  135. package/commands/logout.command.js +15 -17
  136. package/commands/openAPI.command/index.d.ts +1 -1
  137. package/commands/openAPI.command/index.js +20 -24
  138. package/commands/openAPI.command/utils.d.ts +1 -1
  139. package/commands/openAPI.command/utils.js +47 -97
  140. package/commands/utils.d.ts +1 -1
  141. package/commands/utils.js +6 -11
  142. package/config/core.d.ts +1 -1
  143. package/config/core.js +12 -25
  144. package/config/index.d.ts +1 -1
  145. package/config/index.js +45 -49
  146. package/configureLoggers.js +2 -6
  147. package/constants.d.ts +1 -1
  148. package/constants.js +57 -63
  149. package/discovery/index.d.ts +1 -1
  150. package/discovery/index.js +32 -45
  151. package/discovery/utils.js +5 -12
  152. package/dwc/dwc.js +63 -76
  153. package/dwc/run.js +15 -19
  154. package/dwc/utils.d.ts +1 -1
  155. package/dwc/utils.js +43 -38
  156. package/index.d.ts +4 -4
  157. package/index.js +22 -68
  158. package/logger/index.d.ts +2 -2
  159. package/logger/index.js +17 -22
  160. package/logger/types.js +1 -2
  161. package/logger/utils.d.ts +1 -1
  162. package/logger/utils.js +4 -8
  163. package/module.d.ts +3 -3
  164. package/module.js +10 -48
  165. package/package.json +9 -7
  166. package/result/ResultHandlerFactory.d.ts +1 -1
  167. package/result/ResultHandlerFactory.js +1 -5
  168. package/result/ResultHandlerImpl.d.ts +1 -1
  169. package/result/ResultHandlerImpl.js +1 -5
  170. package/result/types.js +1 -2
  171. package/settings/index.d.ts +1 -1
  172. package/settings/index.js +11 -17
  173. package/types.d.ts +1 -1
  174. package/types.js +6 -9
  175. package/utils/commands.d.ts +3 -3
  176. package/utils/commands.js +23 -36
  177. package/utils/http/httpsAgent.js +16 -26
  178. package/utils/http/index.d.ts +1 -1
  179. package/utils/http/index.js +28 -35
  180. package/utils/http/utils.d.ts +1 -1
  181. package/utils/http/utils.js +4 -9
  182. package/utils/openUtils.js +8 -14
  183. package/utils/options.d.ts +1 -1
  184. package/utils/options.js +5 -10
  185. package/utils/utils.d.ts +2 -2
  186. package/utils/utils.js +42 -94
package/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ 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.20.0
9
+
10
+ ### Fixed
11
+
12
+ - Fixed ESM dynamic import issues on Windows by converting file paths to proper file URLs using `pathToFileURL()`.
13
+
14
+ ## 2025.18.0
15
+
16
+ ### Changed
17
+
18
+ - 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.
19
+
8
20
  ## 2025.17.0
9
21
 
10
22
  ### Changed
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Command-Line Interface (CLI) Core Module.
4
4
 
5
- [![Node Version](https://img.shields.io/badge/node-18.xx.x-brightgreen)](https://nodejs.org/dist/latest-v18.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-19.xx.x-brightgreen)](https://nodejs.org/dist/latest-v19.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-20.xx.x-brightgreen)](https://nodejs.org/dist/latest-v20.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-21.xx.x-brightgreen)](https://nodejs.org/dist/latest-v21.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-22.xx.x-brightgreen)](https://nodejs.org/dist/latest-v22.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](https://badge.fury.io/js/@sap%2Fcli-core)
5
+ [![Node Version](https://img.shields.io/badge/node-20.xx.x-brightgreen)](https://nodejs.org/dist/latest-v20.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-21.xx.x-brightgreen)](https://nodejs.org/dist/latest-v21.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-22.xx.x-brightgreen)](https://nodejs.org/dist/latest-v22.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.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 fs_extra_1.default.mkdir((0, utils_1.getPath)(), { recursive: true });
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
- exports.init = init;
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 fs_extra_1.default.readFile((0, utils_1.getPath)(file), "utf-8");
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
- exports.readFile = readFile;
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 fs_extra_1.default.writeFile((0, utils_1.getPath)(file), data, "utf-8");
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
- exports.writeFile = writeFile;
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 fs_extra_1.default.remove((0, utils_1.getPath)(file));
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
- exports.deleteFile = deleteFile;
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 fs_extra_1.default.remove((0, utils_1.getPath)());
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
- exports.cleanCache = cleanCache;
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 fs_extra_1.default.readdir((0, utils_1.getPath)(), "utf-8");
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SecretsStorageImpl = void 0;
4
- const constants_1 = require("../../constants");
5
- const logger_1 = require("../../logger");
6
- const utils_1 = require("../../logger/utils");
7
- const types_1 = require("../../types");
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 = (0, logger_1.get)("SecretsStorageImpl");
11
+ this.logger = getLogger("SecretsStorageImpl");
15
12
  }
16
13
  async deleteAllSecrets() {
17
- await (0, cache_1.deleteFile)(constants_1.CACHE_SECRETS_FILE);
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 = (0, utils_2.isCustomClient)(this.secrets[i].client_id);
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 (0, cache_1.readFile)(constants_1.CACHE_SECRETS_FILE));
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
- (0, utils_1.logVerbose)(this.logger, "The secrets file could not be read.");
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 = (0, utils_2.getTenantUrl)();
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 = (0, utils_2.getTenantUrl)();
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 (0, utils_2.updateUrls)(this.secrets[secretIndex]);
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 = (0, utils_2.isSecretConsistent)(secret);
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 (!types_1.ALLOWED_SECRET_TYPES.includes(key)) {
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 (0, cache_1.writeFile)(constants_1.CACHE_SECRETS_FILE, JSON.stringify(this.secrets));
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,4 +1,4 @@
1
- import { SecretsStorage } from "./types";
1
+ import { SecretsStorage } from "./types.js";
2
2
  export declare class SecretsStorageSingleton {
3
3
  static SINGLETON: SecretsStorage;
4
4
  }
@@ -1,7 +1,3 @@
1
- "use strict";
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;
@@ -1,4 +1,4 @@
1
- import { Secret } from "../../types";
1
+ import { Secret } from "../../types.js";
2
2
  export interface SecretsStorage {
3
3
  getDefaultSecretId(): Promise<number>;
4
4
  getDefaultSecret(): Promise<Readonly<Secret>>;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -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>;
@@ -1,33 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTenantUrl = exports.isCustomClient = void 0;
4
- exports.updateUrls = updateUrls;
5
- exports.isSecretConsistent = isSecretConsistent;
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
- exports.isCustomClient = isCustomClient;
15
- const getTenantUrl = () => {
16
- const config = (0, config_1.get)();
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
- exports.getTenantUrl = getTenantUrl;
24
- async function updateUrls(secret) {
17
+ export async function updateUrls(secret) {
25
18
  if (secret.client_id) {
26
- const config = (0, config_1.get)();
19
+ const config = get();
27
20
  let oauth = {};
28
21
  if (!secret.customClient &&
29
22
  (!secret.authorization_url || !secret.token_url)) {
30
- oauth = (await (0, http_1.fetch)({
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 = (0, utils_1.removeQueryParametersFromUrl)(authorizationUrl);
50
+ secret.authorization_url = removeQueryParametersFromUrl(authorizationUrl);
58
51
  // eslint-disable-next-line no-param-reassign
59
- secret.token_url = (0, utils_1.removeQueryParametersFromUrl)(tokenUrl);
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 (!((0, utils_1.isValidURL)(secret.tenantUrl) ||
66
- ((secret.authorization_flow !== types_1.GrantType.authorization_code ||
67
- (0, utils_1.isValidURL)(secret.authorization_url)) &&
68
- (0, utils_1.isValidURL)(secret.token_url)))) {
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 !== types_1.GrantType.authorization_code ||
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.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
- ? __dirname
14
- : path_1.default.join((0, os_1.homedir)(), ".@sap", (0, utils_1.removeScopeFromPackageName)((0, core_1.getPackageName)()));
15
- return path_1.default.join(rootPath, ".cache", ...args);
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,3 +1,3 @@
1
- import { Command } from "../../../types";
1
+ import { Command } from "../../../types.js";
2
2
  declare const cleanCommand: Command;
3
3
  export default cleanCommand;
@@ -1,28 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cache_1 = require("../../../cache");
4
- const constants_1 = require("../../../constants");
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 = (0, options_1.getOptionValueFromConfigGracefully)(OPTION_PURGE_ALL);
10
+ const purgeAll = getOptionValueFromConfigGracefully(OPTION_PURGE_ALL);
13
11
  if (purgeAll) {
14
- await (0, cache_1.cleanCache)();
12
+ await cleanCache();
15
13
  }
16
14
  else {
17
- const files = (await (0, cache_1.getFiles)()).filter((file) => file.startsWith(constants_1.DISCOVERY_DOCUMENT_PREFIX));
18
- await Promise.all(files.map(async (file) => (0, cache_1.deleteFile)(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: (0, handler_1.createNextHandler)("command.config.cache.clean", (0, handler_1.createParseArgumentsHandler)(), cleanHandler),
23
+ handler: createNextHandler("command.config.cache.clean", createParseArgumentsHandler(), cleanHandler),
26
24
  options: [OPTION_PURGE_ALL],
27
25
  };
28
- exports.default = cleanCommand;
26
+ export default cleanCommand;
@@ -1,3 +1,3 @@
1
- import { TopCommand } from "../../../types";
1
+ import { TopCommand } from "../../../types.js";
2
2
  declare const cacheCommand: TopCommand;
3
3
  export default cacheCommand;
@@ -1,15 +1,10 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- 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: [init_command_1.default, clean_command_1.default, show_command_1.default],
8
+ subCommands: [initCommand, cleanCommand, showCommand],
14
9
  };
15
- exports.default = cacheCommand;
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.init = void 0;
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const constants_1 = require("../../../../constants");
10
- const discovery_1 = require("../../../../discovery");
11
- const handler_1 = require("../../../handler");
12
- const config_1 = require("../../../../config");
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
- (0, config_1.set)({
13
+ setConfig({
20
14
  doNotStoreResult: false,
21
15
  doNotProcessResponseData: true,
22
16
  });
23
17
  };
24
18
  const post = async (discovery) => {
25
- const config = (0, config_1.get)();
26
- await (0, discovery_1.addMetadata)({
19
+ const config = getConfig();
20
+ await addDiscoveryMetadata({
27
21
  tenant: config.publicfqdn,
28
22
  addedAt: new Date().getTime(),
29
23
  });
30
- (0, discovery_1.clear)();
24
+ clear();
31
25
  const { options } = config;
32
- delete options[constants_1.OPTION_OUTPUT.longName];
33
- (0, config_1.set)({ options });
34
- ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(undefined);
35
- await fs_extra_1.default.writeFile((0, discovery_1.getPathToDiscoveryDocument)(), JSON.stringify(discovery));
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 } = (0, logger_1.get)("init.command");
33
+ const { output } = get("init.command");
40
34
  const discovery = {
41
35
  info: {
42
- version: constants_1.VERSION,
43
- "x-document-version": constants_1.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 = (0, core_1.getDiscoveryPaths)();
44
+ const paths = getDiscoveryPaths();
51
45
  if (paths.length > 1 &&
52
- (0, utils_2.getAuthenticationMethod)() !== constants_1.AuthenticationMethod.oauth) {
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 (0, handler_1.createFetchHandler)("GET", path)({}))();
58
- const newDiscovery = ResultHandlerFactory_1.ResultHandlerFactory.get().getResult();
59
- (0, utils_1.mergeDiscoveries)(discovery, newDiscovery);
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: (0, handler_1.createNextHandler)("command.config.cache.init", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
62
+ handler: createNextHandler("command.config.cache.init", createParseArgumentsHandler(), createMandatoryOptionsHandler(), createAuthenticationHandler(), init),
70
63
  };
71
- exports.default = initCommand;
64
+ export default initCommand;
@@ -1,3 +1,3 @@
1
- import { Discovery } from "../../../../types";
1
+ import { Discovery } from "../../../../types.js";
2
2
  export declare function getLowerVersion(a: string, b: string): string;
3
3
  export declare function mergeDiscoveries(discovery: Discovery, newDiscovery: Discovery): void;
@@ -1,17 +1,10 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.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
- lodash_1.default.merge(discovery, newDiscovery);
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