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