@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/config/core.js CHANGED
@@ -1,27 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGenericOptionsHelp = exports.getDeprecationMessage = exports.isDeprecated = exports.getVersion = exports.getAuthenticationMethods = exports.getSapHelp = exports.getDiscoveryPaths = exports.getDescription = exports.getPackageName = exports.getName = void 0;
4
1
  /* jscpd:ignore-start */
5
- const constants_1 = require("../constants");
2
+ import { CLI_DEPRECATED, CLI_DEPRECATION_MESSAGE, CLI_DESCRIPTION, CLI_DISCOVERY_PATHS, CLI_GENERIC_OPTIONS_HELP, CLI_NAME, CLI_PACKAGE_NAME, CLI_SAP_HELP, CLI_SUPPORTED_AUTHENTICATION_METHODS, CLI_VERSION, } from "../constants.js";
6
3
  /* jscpd:ignore-end */
7
- const index_1 = require("./index");
8
- const getName = () => (0, index_1.get)()[constants_1.CLI_NAME];
9
- exports.getName = getName;
10
- const getPackageName = () => (0, index_1.get)()[constants_1.CLI_PACKAGE_NAME];
11
- exports.getPackageName = getPackageName;
12
- const getDescription = () => (0, index_1.get)()[constants_1.CLI_DESCRIPTION];
13
- exports.getDescription = getDescription;
14
- const getDiscoveryPaths = () => (0, index_1.get)()[constants_1.CLI_DISCOVERY_PATHS];
15
- exports.getDiscoveryPaths = getDiscoveryPaths;
16
- const getSapHelp = () => (0, index_1.get)()[constants_1.CLI_SAP_HELP];
17
- exports.getSapHelp = getSapHelp;
18
- const getAuthenticationMethods = () => (0, index_1.get)()[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS];
19
- exports.getAuthenticationMethods = getAuthenticationMethods;
20
- const getVersion = () => (0, index_1.get)()[constants_1.CLI_VERSION];
21
- exports.getVersion = getVersion;
22
- const isDeprecated = () => (0, index_1.get)()[constants_1.CLI_DEPRECATED] || false;
23
- exports.isDeprecated = isDeprecated;
24
- const getDeprecationMessage = () => (0, index_1.get)()[constants_1.CLI_DEPRECATION_MESSAGE];
25
- exports.getDeprecationMessage = getDeprecationMessage;
26
- const getGenericOptionsHelp = () => (0, index_1.get)()[constants_1.CLI_GENERIC_OPTIONS_HELP];
27
- exports.getGenericOptionsHelp = getGenericOptionsHelp;
4
+ import { get } from "./index.js";
5
+ export const getName = () => get()[CLI_NAME];
6
+ export const getPackageName = () => get()[CLI_PACKAGE_NAME];
7
+ export const getDescription = () => get()[CLI_DESCRIPTION];
8
+ export const getDiscoveryPaths = () => get()[CLI_DISCOVERY_PATHS];
9
+ export const getSapHelp = () => get()[CLI_SAP_HELP];
10
+ export const getAuthenticationMethods = () => get()[CLI_SUPPORTED_AUTHENTICATION_METHODS];
11
+ export const getVersion = () => get()[CLI_VERSION];
12
+ export const isDeprecated = () => get()[CLI_DEPRECATED] || false;
13
+ export const getDeprecationMessage = () => get()[CLI_DEPRECATION_MESSAGE];
14
+ export const getGenericOptionsHelp = () => get()[CLI_GENERIC_OPTIONS_HELP];
package/config/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { KeyValuePair } from "../types";
1
+ import { KeyValuePair } from "../types.js";
2
2
  export declare const initialize: () => void;
3
3
  export declare const setCustomConfig: () => void;
4
4
  export declare const set: (c: KeyValuePair) => void;
package/config/index.js CHANGED
@@ -1,32 +1,27 @@
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.get = exports.set = exports.setCustomConfig = exports.initialize = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const config_1 = __importDefault(require("config"));
9
- const logger_1 = require("../logger");
10
- const utils_1 = require("../utils/utils");
11
- const constants_1 = require("../constants");
1
+ import { createRequire } from "module";
2
+ import { isEqual, merge } from "lodash-es";
3
+ import { get as getLoggerExt } from "../logger/index.js";
4
+ import { getInfoFromTenant, parseTenant } from "../utils/utils.js";
5
+ import { CLI_DEPRECATED, CLI_DEPRECATION_MESSAGE, CLI_DESCRIPTION, CLI_DISCOVERY_PATHS, CLI_GENERIC_OPTIONS_HELP, CLI_NAME, CLI_PACKAGE_NAME, CLI_SAP_HELP, CLI_SUPPORTED_AUTHENTICATION_METHODS, CLI_VERSION, CONFIG_PASSCODE_FUNCTION, } from "../constants.js";
12
6
  const CUSTOM_HOST = "tenant.host";
13
7
  const CUSTOM_PASSCODE_URL = "tenant.passcodeUrl";
14
8
  const CUSTOM_PUBLIC_FQDN = "tenant.publicfqdn";
9
+ const require = createRequire(import.meta.url);
15
10
  let config;
16
11
  const CONFIGS_TO_KEEP = [
17
- constants_1.CONFIG_PASSCODE_FUNCTION,
18
- constants_1.CLI_DESCRIPTION,
19
- constants_1.CLI_DISCOVERY_PATHS,
20
- constants_1.CLI_NAME,
21
- constants_1.CLI_PACKAGE_NAME,
22
- constants_1.CLI_SAP_HELP,
23
- constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS,
24
- constants_1.CLI_VERSION,
25
- constants_1.CLI_DEPRECATED,
26
- constants_1.CLI_DEPRECATION_MESSAGE,
27
- constants_1.CLI_GENERIC_OPTIONS_HELP,
12
+ CONFIG_PASSCODE_FUNCTION,
13
+ CLI_DESCRIPTION,
14
+ CLI_DISCOVERY_PATHS,
15
+ CLI_NAME,
16
+ CLI_PACKAGE_NAME,
17
+ CLI_SAP_HELP,
18
+ CLI_SUPPORTED_AUTHENTICATION_METHODS,
19
+ CLI_VERSION,
20
+ CLI_DEPRECATED,
21
+ CLI_DEPRECATION_MESSAGE,
22
+ CLI_GENERIC_OPTIONS_HELP,
28
23
  ];
29
- const initialize = () => {
24
+ export const initialize = () => {
30
25
  const keep = {};
31
26
  for (const keepConfig of CONFIGS_TO_KEEP) {
32
27
  keep[keepConfig] = config?.[keepConfig];
@@ -38,45 +33,48 @@ const initialize = () => {
38
33
  }
39
34
  }
40
35
  };
41
- exports.initialize = initialize;
42
- (0, exports.initialize)();
43
- const getLogger = () => (0, logger_1.get)("config");
44
- const setCustomConfig = () => {
36
+ initialize();
37
+ const getLogger = () => getLoggerExt("config");
38
+ export const setCustomConfig = () => {
39
+ if (process.env.SUPPRESS_NO_CONFIG_WARNING === undefined) {
40
+ process.env.SUPPRESS_NO_CONFIG_WARNING = "true";
41
+ }
42
+ // This has to be loaded via dynamic import to ensure that the env variable is set before the config is loaded.
43
+ const customConfig = require("config");
45
44
  const { trace, debug } = getLogger();
46
45
  debug("setting custom configuration");
47
- const sources = config_1.default.util.getConfigSources();
46
+ const sources = customConfig.util.getConfigSources();
48
47
  trace("config.custom.getConfigSources", JSON.stringify(sources, null, 2));
49
- trace("config.custom.NODE_CONFIG_DIR", config_1.default.util.getEnv("NODE_CONFIG_DIR"));
50
- trace("config.custom.NODE_ENV", config_1.default.util.getEnv("NODE_ENV"));
51
- trace("config.custom.NODE_CONFIG", JSON.stringify(config_1.default.util.getEnv("NODE_CONFIG"), null, 2));
52
- trace("config.custom.HOSTNAME", config_1.default.util.getEnv("HOSTNAME"));
53
- trace("config.custom.NODE_APP_INSTANCE", config_1.default.util.getEnv("NODE_APP_INSTANCE"));
54
- if (config_1.default.has(CUSTOM_HOST)) {
55
- config.host = config_1.default.get(CUSTOM_HOST);
48
+ trace("config.custom.NODE_CONFIG_DIR", customConfig.util.getEnv("NODE_CONFIG_DIR"));
49
+ trace("config.custom.NODE_ENV", customConfig.util.getEnv("NODE_ENV"));
50
+ trace("config.custom.NODE_CONFIG", JSON.stringify(customConfig.util.getEnv("NODE_CONFIG"), null, 2));
51
+ trace("config.custom.HOSTNAME", customConfig.util.getEnv("HOSTNAME"));
52
+ trace("config.custom.NODE_APP_INSTANCE", customConfig.util.getEnv("NODE_APP_INSTANCE"));
53
+ if (customConfig.has(CUSTOM_HOST)) {
54
+ config.host = customConfig.get(CUSTOM_HOST);
56
55
  config.hostSetFromCustomConfig = true;
57
56
  }
58
- if (config_1.default.has(CUSTOM_PASSCODE_URL)) {
59
- config.passcodeUrl = config_1.default.get(CUSTOM_PASSCODE_URL);
57
+ if (customConfig.has(CUSTOM_PASSCODE_URL)) {
58
+ config.passcodeUrl = customConfig.get(CUSTOM_PASSCODE_URL);
60
59
  }
61
- if (config_1.default.has(CUSTOM_PUBLIC_FQDN)) {
62
- config.publicfqdn = (0, utils_1.parseTenant)(config_1.default.get(CUSTOM_PUBLIC_FQDN));
60
+ if (customConfig.has(CUSTOM_PUBLIC_FQDN)) {
61
+ config.publicfqdn = parseTenant(customConfig.get(CUSTOM_PUBLIC_FQDN));
63
62
  }
64
63
  };
65
- exports.setCustomConfig = setCustomConfig;
66
- (0, exports.setCustomConfig)();
64
+ setCustomConfig();
67
65
  const setTenant = (tenant) => {
68
- const info = (0, utils_1.getInfoFromTenant)(tenant, config.verbose);
66
+ const info = getInfoFromTenant(tenant, config.verbose);
69
67
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
70
- (0, exports.set)({ ...info, newTenant: tenant });
68
+ set({ ...info, newTenant: tenant });
71
69
  };
72
- const set = (c) => {
70
+ export const set = (c) => {
73
71
  const { trace } = getLogger();
74
72
  const prev = JSON.parse(JSON.stringify(config));
75
73
  if (c.tenant) {
76
74
  setTenant(c.tenant);
77
75
  }
78
76
  else {
79
- config = lodash_1.default.merge(config, c);
77
+ config = merge(config, c);
80
78
  if (config.newTenant) {
81
79
  config.tenant = config.newTenant;
82
80
  delete config.newTenant;
@@ -84,11 +82,9 @@ const set = (c) => {
84
82
  if (c.data) {
85
83
  config.data = c.data;
86
84
  }
87
- if (!lodash_1.default.isEqual(prev, config)) {
85
+ if (!isEqual(prev, config)) {
88
86
  trace("configuration changed. previous: %s, current: %s", JSON.stringify(prev), JSON.stringify(config));
89
87
  }
90
88
  }
91
89
  };
92
- exports.set = set;
93
- const get = () => config;
94
- exports.get = get;
90
+ export const get = () => config;
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configureLoggers = void 0;
4
- const logger_1 = require("./logger");
5
- const configureLoggers = () => (0, logger_1.configure)({
1
+ import { configure } from "./logger/index.js";
2
+ export const configureLoggers = () => configure({
6
3
  logLevel: process.env.LOG_LEVEL
7
4
  ? parseInt(process.env.LOG_LEVEL, 10)
8
5
  : undefined,
9
6
  loggers: process.env.LOGGERS ? new RegExp(process.env.LOGGERS) : undefined,
10
7
  });
11
- exports.configureLoggers = configureLoggers;
package/constants.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SecureVersion } from "tls";
2
- import { Option } from "./types";
2
+ import { Option } from "./types.js";
3
3
  export declare const VERSION: string;
4
4
  export declare const DEFAULT_TLS_VERSION: SecureVersion;
5
5
  export type CoreConfiguration = {
package/constants.js CHANGED
@@ -1,51 +1,45 @@
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.OPTION_TLS_VERSION = exports.OPTION_AUTHORIZATION_FLOW = exports.OPTION_BROWSER = exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_OUTPUT_FILE_NAME = exports.X_DSP_API_DEPRECATED_PROPERTIES = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATHS = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.ROOT_COMMAND = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.DEFAULT_TLS_VERSION = exports.VERSION = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const types_1 = require("./types");
9
- const utils_1 = require("./utils/utils");
10
- exports.VERSION = (0, utils_1.getVersion)();
11
- exports.DEFAULT_TLS_VERSION = "TLSv1.2";
12
- exports.DISCOVERY_DOCUMENT_PREFIX = "discovery-";
13
- var AuthenticationMethod;
1
+ import path from "path";
2
+ import { GrantType } from "./types.js";
3
+ import { getVersion } from "./utils/utils.js";
4
+ export const VERSION = getVersion();
5
+ export const DEFAULT_TLS_VERSION = "TLSv1.2";
6
+ export const DISCOVERY_DOCUMENT_PREFIX = "discovery-";
7
+ export var AuthenticationMethod;
14
8
  (function (AuthenticationMethod) {
15
9
  AuthenticationMethod["oauth"] = "oauth";
16
10
  AuthenticationMethod["passcode"] = "passcode";
17
- })(AuthenticationMethod || (exports.AuthenticationMethod = AuthenticationMethod = {}));
18
- exports.ROOT_COMMAND = { name: () => "ROOT", parent: null };
19
- exports.CLI_NAME = "cli-name";
20
- exports.CLI_PACKAGE_NAME = "cli-package-name";
21
- exports.CLI_DESCRIPTION = "cli-description";
22
- exports.CLI_DISCOVERY_PATHS = "cli-discovery-paths";
23
- exports.CLI_SAP_HELP = "cli-sap-help";
24
- exports.CLI_VERSION = "cli-version";
25
- exports.CLI_DEPRECATED = "cli-deprecated";
26
- exports.CLI_DEPRECATION_MESSAGE = "cli-deprecation-message";
27
- exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = "cli-supported-authentication-methods";
28
- exports.CLI_GENERIC_OPTIONS_HELP = "cli-generic-options-help";
29
- exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = ["dwaas-core"];
30
- exports.DISCOVERY_METADATA_PATH = "discovery-metadata.json";
31
- exports.X_CSRF_TOKEN = "x-csrf-token";
32
- exports.X_DSP_API_DEPRECATED_PROPERTIES = "x-dsp-api-deprecated-properties";
33
- exports.X_OUTPUT_FILE_NAME = "x-sap-datasphere-cli-file-name";
34
- exports.PATH_TO_SUCCESS_HTML = path_1.default.join(__dirname, "assets", "success.html");
35
- exports.PATH_TO_ERROR_HTML = path_1.default.join(__dirname, "assets", "error.html");
36
- exports.CACHE_SECRETS_FILE = "secrets.json";
37
- exports.OPTION_VERSION = {
11
+ })(AuthenticationMethod || (AuthenticationMethod = {}));
12
+ export const ROOT_COMMAND = { name: () => "ROOT", parent: null };
13
+ export const CLI_NAME = "cli-name";
14
+ export const CLI_PACKAGE_NAME = "cli-package-name";
15
+ export const CLI_DESCRIPTION = "cli-description";
16
+ export const CLI_DISCOVERY_PATHS = "cli-discovery-paths";
17
+ export const CLI_SAP_HELP = "cli-sap-help";
18
+ export const CLI_VERSION = "cli-version";
19
+ export const CLI_DEPRECATED = "cli-deprecated";
20
+ export const CLI_DEPRECATION_MESSAGE = "cli-deprecation-message";
21
+ export const CLI_SUPPORTED_AUTHENTICATION_METHODS = "cli-supported-authentication-methods";
22
+ export const CLI_GENERIC_OPTIONS_HELP = "cli-generic-options-help";
23
+ export const SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = ["dwaas-core"];
24
+ export const DISCOVERY_METADATA_PATH = "discovery-metadata.json";
25
+ export const X_CSRF_TOKEN = "x-csrf-token";
26
+ export const X_DSP_API_DEPRECATED_PROPERTIES = "x-dsp-api-deprecated-properties";
27
+ export const X_OUTPUT_FILE_NAME = "x-sap-datasphere-cli-file-name";
28
+ export const PATH_TO_SUCCESS_HTML = path.join(import.meta.dirname, "assets", "success.html");
29
+ export const PATH_TO_ERROR_HTML = path.join(import.meta.dirname, "assets", "error.html");
30
+ export const CACHE_SECRETS_FILE = "secrets.json";
31
+ export const OPTION_VERSION = {
38
32
  longName: "version",
39
33
  description: "print version",
40
34
  hidden: true,
41
35
  };
42
- exports.OPTION_HELP = {
36
+ export const OPTION_HELP = {
43
37
  longName: "help",
44
38
  description: "print help for a command",
45
39
  args: [{ name: "command" }],
46
40
  hidden: true,
47
41
  };
48
- exports.OPTION_HOST = {
42
+ export const OPTION_HOST = {
49
43
  longName: "host",
50
44
  description: "specifies the url where the tenant is hosted",
51
45
  args: [{ name: "host" }],
@@ -55,7 +49,7 @@ exports.OPTION_HOST = {
55
49
  type: "text",
56
50
  },
57
51
  };
58
- exports.OPTION_LOGIN_ID = {
52
+ export const OPTION_LOGIN_ID = {
59
53
  longName: "login-id",
60
54
  description: "specifies the login ID",
61
55
  args: [{ name: "id" }],
@@ -66,27 +60,27 @@ exports.OPTION_LOGIN_ID = {
66
60
  type: "select",
67
61
  },
68
62
  };
69
- exports.OPTION_OUTPUT = {
63
+ export const OPTION_OUTPUT = {
70
64
  longName: "output",
71
65
  description: "specifies the file to store the output of the command",
72
66
  args: [{ name: "output", optional: true }],
73
67
  hidden: true,
74
68
  };
75
- exports.OPTION_NO_PRETTY = {
69
+ export const OPTION_NO_PRETTY = {
76
70
  longName: "no-pretty",
77
71
  description: "do not pretty-format JSON responses",
78
72
  hidden: true,
79
73
  };
80
- exports.OPTION_VERBOSE = {
74
+ export const OPTION_VERBOSE = {
81
75
  longName: "verbose",
82
76
  description: "print detailed log information to console",
83
77
  hidden: true,
84
78
  };
85
- exports.OPTION_FORCE = {
79
+ export const OPTION_FORCE = {
86
80
  longName: "force",
87
81
  description: "force the command execution",
88
82
  };
89
- exports.OPTION_CLIENT_ID = {
83
+ export const OPTION_CLIENT_ID = {
90
84
  longName: "client-id",
91
85
  description: "client id for interactive oauth session authentication",
92
86
  args: [{ name: "id" }],
@@ -96,7 +90,7 @@ exports.OPTION_CLIENT_ID = {
96
90
  message: `Please enter your client ID:`,
97
91
  },
98
92
  };
99
- exports.OPTION_CLIENT_SECRET = {
93
+ export const OPTION_CLIENT_SECRET = {
100
94
  longName: "client-secret",
101
95
  description: "client secret for interactive oauth session authentication",
102
96
  args: [{ name: "secret" }],
@@ -106,7 +100,7 @@ exports.OPTION_CLIENT_SECRET = {
106
100
  message: `Please enter your client secret:`,
107
101
  },
108
102
  };
109
- exports.OPTION_AUTHORIZATION_URL = {
103
+ export const OPTION_AUTHORIZATION_URL = {
110
104
  longName: "authorization-url",
111
105
  description: "authorization url for interactive oauth session authentication",
112
106
  args: [{ name: "url" }],
@@ -116,7 +110,7 @@ exports.OPTION_AUTHORIZATION_URL = {
116
110
  message: `Please enter your authorization URL:`,
117
111
  },
118
112
  };
119
- exports.OPTION_TOKEN_URL = {
113
+ export const OPTION_TOKEN_URL = {
120
114
  longName: "token-url",
121
115
  description: "token url for interactive oauth session authentication",
122
116
  args: [{ name: "url" }],
@@ -126,7 +120,7 @@ exports.OPTION_TOKEN_URL = {
126
120
  message: `Please enter your token URL:`,
127
121
  },
128
122
  };
129
- exports.OPTION_ACCESS_TOKEN = {
123
+ export const OPTION_ACCESS_TOKEN = {
130
124
  longName: "access-token",
131
125
  description: "access token for interactive oauth session authentication",
132
126
  args: [{ name: "token" }],
@@ -136,7 +130,7 @@ exports.OPTION_ACCESS_TOKEN = {
136
130
  message: `Please enter your access token:`,
137
131
  },
138
132
  };
139
- exports.OPTION_REFRESH_TOKEN = {
133
+ export const OPTION_REFRESH_TOKEN = {
140
134
  longName: "refresh-token",
141
135
  description: "refresh token for interactive oauth session authentication",
142
136
  args: [{ name: "token" }],
@@ -146,7 +140,7 @@ exports.OPTION_REFRESH_TOKEN = {
146
140
  message: `Please enter your refresh token:`,
147
141
  },
148
142
  };
149
- exports.OPTION_EXPIRES_IN = {
143
+ export const OPTION_EXPIRES_IN = {
150
144
  longName: "expires-in",
151
145
  description: "expires in information for interactive oauth session authentication",
152
146
  args: [{ name: "expires" }],
@@ -156,7 +150,7 @@ exports.OPTION_EXPIRES_IN = {
156
150
  message: `Please enter a value for expires in:`,
157
151
  },
158
152
  };
159
- exports.OPTION_SECRETS_FILE = {
153
+ export const OPTION_SECRETS_FILE = {
160
154
  longName: "secrets-file",
161
155
  description: "path to secrets file",
162
156
  args: [{ name: "file" }],
@@ -166,7 +160,7 @@ exports.OPTION_SECRETS_FILE = {
166
160
  message: `Please enter the path to the secrets file:`,
167
161
  },
168
162
  };
169
- exports.OPTION_CODE = {
163
+ export const OPTION_CODE = {
170
164
  longName: "code",
171
165
  description: "code for oauth token retrieval",
172
166
  args: [{ name: "code" }],
@@ -176,20 +170,20 @@ exports.OPTION_CODE = {
176
170
  message: `Please enter the code for retrieving the oauth access_token and refresh_token:`,
177
171
  },
178
172
  };
179
- exports.OPTION_PASSCODE = {
173
+ export const OPTION_PASSCODE = {
180
174
  longName: "passcode",
181
175
  description: "passcode for interactive session authentication",
182
176
  args: [{ name: "passcode" }],
183
177
  hidden: true,
184
178
  };
185
- exports.CONFIG_PASSCODE_FUNCTION = "passcodeFunction";
186
- exports.OPTION_OPTIONS_FILE = {
179
+ export const CONFIG_PASSCODE_FUNCTION = "passcodeFunction";
180
+ export const OPTION_OPTIONS_FILE = {
187
181
  longName: "options-file",
188
182
  description: "path to options file",
189
183
  args: [{ name: "file" }],
190
184
  hidden: true,
191
185
  };
192
- exports.OPTION_FILE_PATH = {
186
+ export const OPTION_FILE_PATH = {
193
187
  longName: "file-path",
194
188
  description: "specifies the file to use as input for the command",
195
189
  args: [{ name: "path" }],
@@ -198,7 +192,7 @@ exports.OPTION_FILE_PATH = {
198
192
  type: "text",
199
193
  },
200
194
  };
201
- exports.OPTION_INPUT = {
195
+ export const OPTION_INPUT = {
202
196
  longName: "input",
203
197
  description: "specifies input as string to use for the command",
204
198
  args: [{ name: "input" }],
@@ -207,7 +201,7 @@ exports.OPTION_INPUT = {
207
201
  type: "text",
208
202
  },
209
203
  };
210
- exports.OPTION_BROWSER = {
204
+ export const OPTION_BROWSER = {
211
205
  longName: "browser",
212
206
  description: "specifies the browser to open",
213
207
  args: [{ name: "browser" }],
@@ -216,23 +210,23 @@ exports.OPTION_BROWSER = {
216
210
  type: "select",
217
211
  },
218
212
  };
219
- exports.OPTION_AUTHORIZATION_FLOW = {
213
+ export const OPTION_AUTHORIZATION_FLOW = {
220
214
  longName: "authorization-flow",
221
215
  description: "specifies the authorization flow to use",
222
216
  args: [{ name: "authorization-flow" }],
223
217
  choices: [
224
- types_1.GrantType.authorization_code,
225
- types_1.GrantType.client_credentials,
218
+ GrantType.authorization_code,
219
+ GrantType.client_credentials,
226
220
  ],
227
- default: types_1.GrantType.authorization_code,
221
+ default: GrantType.authorization_code,
228
222
  required: true,
229
223
  hidden: true,
230
224
  };
231
- exports.OPTION_TLS_VERSION = {
225
+ export const OPTION_TLS_VERSION = {
232
226
  longName: "tls-version",
233
227
  description: "specifies the TLS version to use for HTTPS connections",
234
228
  args: [{ name: "version" }],
235
- choices: [exports.DEFAULT_TLS_VERSION, "TLSv1.3"],
236
- default: exports.DEFAULT_TLS_VERSION,
229
+ choices: [DEFAULT_TLS_VERSION, "TLSv1.3"],
230
+ default: DEFAULT_TLS_VERSION,
237
231
  hidden: true,
238
232
  };
@@ -1,4 +1,4 @@
1
- import { Discovery, DiscoveryMetadata } from "../types";
1
+ import { Discovery, DiscoveryMetadata } from "../types.js";
2
2
  export declare const getPathToDiscoveryDocument: () => string;
3
3
  export declare const getMetadata: () => Promise<Array<DiscoveryMetadata>>;
4
4
  export declare const addMetadata: ({ tenant, addedAt, }: Omit<DiscoveryMetadata, "hash">) => Promise<void>;
@@ -1,40 +1,33 @@
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.checkVersion = exports.compareEtags = exports.init = exports.clear = exports.addMetadata = exports.getMetadata = exports.getPathToDiscoveryDocument = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const cache_1 = require("../cache");
10
- const utils_1 = require("./utils");
11
- const utils_2 = require("../utils/utils");
12
- const logger_1 = require("../logger");
13
- const config_1 = require("../config");
14
- const constants_1 = require("../constants");
15
- const core_1 = require("../config/core");
16
- const getLogger = () => (0, logger_1.get)("discovery");
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ import { getPath, readFile as readFileFromCache, writeFile as writeFileToCache, } from "../cache/index.js";
4
+ import { getDiscoveryPaths, getVersion } from "../config/core.js";
5
+ import { get as getConfig } from "../config/index.js";
6
+ import { DISCOVERY_DOCUMENT_PREFIX, DISCOVERY_METADATA_PATH, } from "../constants.js";
7
+ import { get } from "../logger/index.js";
8
+ import { parseVersion, sha256 } from "../utils/utils.js";
9
+ import { validate } from "./utils.js";
10
+ const getLogger = () => get("discovery");
17
11
  let initialized = false;
18
12
  let document;
19
13
  let metadata;
20
14
  function getHash(tenant) {
21
- return (0, utils_2.sha256)(`${tenant}${JSON.stringify((0, core_1.getDiscoveryPaths)())}`).replace(/[/\\]/g, "_");
15
+ return sha256(`${tenant}${JSON.stringify(getDiscoveryPaths())}`).replace(/[/\\]/g, "_");
22
16
  }
23
17
  const getDocumentName = () => {
24
18
  const { trace } = getLogger();
25
- const config = (0, config_1.get)();
19
+ const config = getConfig();
26
20
  const hash = getHash(config.publicfqdn);
27
- const name = `${constants_1.DISCOVERY_DOCUMENT_PREFIX}${hash}.json`;
21
+ const name = `${DISCOVERY_DOCUMENT_PREFIX}${hash}.json`;
28
22
  trace(`calculating document name for host ${config.host}, name ${name}`);
29
23
  return name;
30
24
  };
31
- const getPathToDiscoveryDocument = () => (0, cache_1.getPath)(getDocumentName());
32
- exports.getPathToDiscoveryDocument = getPathToDiscoveryDocument;
25
+ export const getPathToDiscoveryDocument = () => getPath(getDocumentName());
33
26
  const initMetadata = async () => {
34
27
  const { error } = getLogger();
35
28
  if (!metadata) {
36
29
  try {
37
- metadata = JSON.parse(await (0, cache_1.readFile)(constants_1.DISCOVERY_METADATA_PATH));
30
+ metadata = JSON.parse(await readFileFromCache(DISCOVERY_METADATA_PATH));
38
31
  }
39
32
  catch (err) {
40
33
  error("error while reading discovery metadata", err.stack);
@@ -42,27 +35,24 @@ const initMetadata = async () => {
42
35
  }
43
36
  }
44
37
  };
45
- const getMetadata = async () => {
38
+ export const getMetadata = async () => {
46
39
  await initMetadata();
47
40
  return metadata;
48
41
  };
49
- exports.getMetadata = getMetadata;
50
- const addMetadata = async ({ tenant, addedAt, }) => {
42
+ export const addMetadata = async ({ tenant, addedAt, }) => {
51
43
  await initMetadata();
52
44
  metadata = metadata.filter((t) => t.tenant !== tenant);
53
45
  const hash = getHash(tenant);
54
46
  metadata.push({ tenant, addedAt, hash });
55
- await (0, cache_1.writeFile)(constants_1.DISCOVERY_METADATA_PATH, JSON.stringify(metadata));
47
+ await writeFileToCache(DISCOVERY_METADATA_PATH, JSON.stringify(metadata));
56
48
  };
57
- exports.addMetadata = addMetadata;
58
- const clear = () => {
49
+ export const clear = () => {
59
50
  initialized = false;
60
51
  document = undefined;
61
52
  metadata = undefined;
62
53
  };
63
- exports.clear = clear;
64
54
  /* jscpd:ignore-start */
65
- const init = async () => {
55
+ export const init = async () => {
66
56
  const { trace, error, debug } = getLogger();
67
57
  if (initialized) {
68
58
  return document;
@@ -72,7 +62,7 @@ const init = async () => {
72
62
  let schema;
73
63
  try {
74
64
  trace("reading discovery document");
75
- const file = await (0, cache_1.readFile)(getDocumentName());
65
+ const file = await readFileFromCache(getDocumentName());
76
66
  document = JSON.parse(file);
77
67
  }
78
68
  catch (err) {
@@ -82,13 +72,13 @@ const init = async () => {
82
72
  try {
83
73
  trace("reading schema document");
84
74
  try {
85
- const file = await fs_extra_1.default.readFile(path_1.default.join(__dirname, "..", "..", "schemas", "discovery.json"), "utf-8");
75
+ const file = await fs.readFile(path.join(import.meta.dirname, "..", "..", "schemas", "discovery.json"), "utf-8");
86
76
  schema = JSON.parse(file);
87
77
  }
88
78
  catch (err) {
89
79
  debug("failed reading schema, trying again", err.stack);
90
80
  // path changes after build
91
- const file = await fs_extra_1.default.readFile(path_1.default.join(__dirname, "..", "schemas", "discovery.json"), "utf-8");
81
+ const file = await fs.readFile(path.join(import.meta.dirname, "..", "schemas", "discovery.json"), "utf-8");
92
82
  schema = JSON.parse(file);
93
83
  }
94
84
  }
@@ -97,21 +87,20 @@ const init = async () => {
97
87
  throw err;
98
88
  }
99
89
  debug("validating discovery document against schema");
100
- const result = await (0, utils_1.validate)(schema, document);
90
+ const result = await validate(schema, document);
101
91
  if (result.result === "INVALID") {
102
92
  error("discovery document contains invalid data", result.errors);
103
93
  throw new Error("discovery document contains invalid data");
104
94
  }
105
95
  return document;
106
96
  };
107
- exports.init = init;
108
- const compareEtags = async () => {
97
+ export const compareEtags = async () => {
109
98
  const { debug, error } = getLogger();
110
99
  try {
111
- const doc = await (0, exports.init)();
112
- const config = (0, config_1.get)();
100
+ const doc = await init();
101
+ const config = getConfig();
113
102
  if (config.etag && doc) {
114
- const etag = (0, utils_2.sha256)(JSON.stringify(doc));
103
+ const etag = sha256(JSON.stringify(doc));
115
104
  if (config.etag === etag) {
116
105
  debug("etags match: %s", config.etag);
117
106
  return true;
@@ -126,12 +115,11 @@ const compareEtags = async () => {
126
115
  }
127
116
  return true;
128
117
  };
129
- exports.compareEtags = compareEtags;
130
- const checkVersion = async () => {
118
+ export const checkVersion = async () => {
131
119
  const { debug } = getLogger();
132
- const doc = await (0, exports.init)();
133
- const local = (0, utils_2.parseVersion)((0, core_1.getVersion)());
134
- const server = (0, utils_2.parseVersion)(doc.info["x-document-version"]);
120
+ const doc = await init();
121
+ const local = parseVersion(getVersion());
122
+ const server = parseVersion(doc.info["x-document-version"]);
135
123
  if (local.major < server.major ||
136
124
  (local.major === server.major && local.minor < server.minor)) {
137
125
  debug(`CLI is outdated (local: ${JSON.stringify(local)}, server: ${JSON.stringify(server)})`);
@@ -139,4 +127,3 @@ const checkVersion = async () => {
139
127
  }
140
128
  return { status: "UPTODATE" };
141
129
  };
142
- exports.checkVersion = checkVersion;