@sap/cli-core 2023.12.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 (179) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +44 -0
  3. package/README.md +13 -0
  4. package/assets/error.html +20 -0
  5. package/assets/success.html +20 -0
  6. package/cache/cache.d.ts +6 -0
  7. package/cache/cache.js +82 -0
  8. package/cache/index.d.ts +2 -0
  9. package/cache/index.js +12 -0
  10. package/cache/utils.d.ts +1 -0
  11. package/cache/utils.js +16 -0
  12. package/commands/cache.command/clean.command.d.ts +3 -0
  13. package/commands/cache.command/clean.command.js +15 -0
  14. package/commands/cache.command/index.d.ts +3 -0
  15. package/commands/cache.command/index.js +15 -0
  16. package/commands/cache.command/init.command.d.ts +3 -0
  17. package/commands/cache.command/init.command.js +36 -0
  18. package/commands/cache.command/show.command.d.ts +3 -0
  19. package/commands/cache.command/show.command.js +30 -0
  20. package/commands/handler/authentication/index.d.ts +2 -0
  21. package/commands/handler/authentication/index.js +21 -0
  22. package/commands/handler/authentication/oauth/index.d.ts +2 -0
  23. package/commands/handler/authentication/oauth/index.js +18 -0
  24. package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +2 -0
  25. package/commands/handler/authentication/oauth/secretsProvider/cache.js +19 -0
  26. package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +2 -0
  27. package/commands/handler/authentication/oauth/secretsProvider/file.js +25 -0
  28. package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +2 -0
  29. package/commands/handler/authentication/oauth/secretsProvider/index.js +10 -0
  30. package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +2 -0
  31. package/commands/handler/authentication/oauth/secretsProvider/options.js +30 -0
  32. package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +2 -0
  33. package/commands/handler/authentication/oauth/tokenProvider/getToken.js +88 -0
  34. package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +2 -0
  35. package/commands/handler/authentication/oauth/tokenProvider/index.js +11 -0
  36. package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +2 -0
  37. package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +15 -0
  38. package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +3 -0
  39. package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +35 -0
  40. package/commands/handler/authentication/oauth/tokenProvider/utils.d.ts +1 -0
  41. package/commands/handler/authentication/oauth/tokenProvider/utils.js +27 -0
  42. package/commands/handler/authentication/oauth/utils.d.ts +15 -0
  43. package/commands/handler/authentication/oauth/utils.js +58 -0
  44. package/commands/handler/authentication/passcode/function.d.ts +2 -0
  45. package/commands/handler/authentication/passcode/function.js +22 -0
  46. package/commands/handler/authentication/passcode/index.d.ts +2 -0
  47. package/commands/handler/authentication/passcode/index.js +19 -0
  48. package/commands/handler/authentication/passcode/input.d.ts +2 -0
  49. package/commands/handler/authentication/passcode/input.js +42 -0
  50. package/commands/handler/authentication/passcode/setPasscode.d.ts +2 -0
  51. package/commands/handler/authentication/passcode/setPasscode.js +16 -0
  52. package/commands/handler/authentication/passcode/types.d.ts +1 -0
  53. package/commands/handler/authentication/passcode/types.js +2 -0
  54. package/commands/handler/authentication/technicalJWT/cf.d.ts +4 -0
  55. package/commands/handler/authentication/technicalJWT/cf.js +133 -0
  56. package/commands/handler/authentication/technicalJWT/exec.d.ts +9 -0
  57. package/commands/handler/authentication/technicalJWT/exec.js +196 -0
  58. package/commands/handler/authentication/technicalJWT/index.d.ts +2 -0
  59. package/commands/handler/authentication/technicalJWT/index.js +15 -0
  60. package/commands/handler/authentication/technicalJWT/types.d.ts +2 -0
  61. package/commands/handler/authentication/technicalJWT/types.js +8 -0
  62. package/commands/handler/authentication/technicalJWT/utils.d.ts +1 -0
  63. package/commands/handler/authentication/technicalJWT/utils.js +70 -0
  64. package/commands/handler/authentication/utils.d.ts +3 -0
  65. package/commands/handler/authentication/utils.js +8 -0
  66. package/commands/handler/checkOptionsExistence.d.ts +2 -0
  67. package/commands/handler/checkOptionsExistence.js +17 -0
  68. package/commands/handler/error.d.ts +2 -0
  69. package/commands/handler/error.js +21 -0
  70. package/commands/handler/fail.d.ts +2 -0
  71. package/commands/handler/fail.js +10 -0
  72. package/commands/handler/fetch/fetch.d.ts +2 -0
  73. package/commands/handler/fetch/fetch.js +83 -0
  74. package/commands/handler/fetch/index.d.ts +2 -0
  75. package/commands/handler/fetch/index.js +25 -0
  76. package/commands/handler/fetch/utils.d.ts +14 -0
  77. package/commands/handler/fetch/utils.js +152 -0
  78. package/commands/handler/force.d.ts +2 -0
  79. package/commands/handler/force.js +35 -0
  80. package/commands/handler/index.d.ts +18 -0
  81. package/commands/handler/index.js +39 -0
  82. package/commands/handler/input/file.d.ts +2 -0
  83. package/commands/handler/input/file.js +34 -0
  84. package/commands/handler/input/index.d.ts +2 -0
  85. package/commands/handler/input/index.js +8 -0
  86. package/commands/handler/input/input.d.ts +2 -0
  87. package/commands/handler/input/input.js +44 -0
  88. package/commands/handler/mandatoryOptions.d.ts +2 -0
  89. package/commands/handler/mandatoryOptions.js +25 -0
  90. package/commands/handler/next.d.ts +2 -0
  91. package/commands/handler/next.js +19 -0
  92. package/commands/handler/options/env.d.ts +2 -0
  93. package/commands/handler/options/env.js +18 -0
  94. package/commands/handler/options/file.d.ts +2 -0
  95. package/commands/handler/options/file.js +21 -0
  96. package/commands/handler/options/index.d.ts +7 -0
  97. package/commands/handler/options/index.js +32 -0
  98. package/commands/handler/options/option.d.ts +2 -0
  99. package/commands/handler/options/option.js +20 -0
  100. package/commands/handler/options/pipe.d.ts +2 -0
  101. package/commands/handler/options/pipe.js +34 -0
  102. package/commands/handler/options/utils.d.ts +6 -0
  103. package/commands/handler/options/utils.js +63 -0
  104. package/commands/handler/or.d.ts +2 -0
  105. package/commands/handler/or.js +37 -0
  106. package/commands/handler/parseArguments.d.ts +4 -0
  107. package/commands/handler/parseArguments.js +22 -0
  108. package/commands/handler/resilient.d.ts +2 -0
  109. package/commands/handler/resilient.js +18 -0
  110. package/commands/handler/root/index.d.ts +2 -0
  111. package/commands/handler/root/index.js +18 -0
  112. package/commands/handler/stackTrace.d.ts +2 -0
  113. package/commands/handler/stackTrace.js +22 -0
  114. package/commands/handler/succeed.d.ts +2 -0
  115. package/commands/handler/succeed.js +9 -0
  116. package/commands/handler/utils.d.ts +7 -0
  117. package/commands/handler/utils.js +56 -0
  118. package/commands/host.command.d.ts +2 -0
  119. package/commands/host.command.js +68 -0
  120. package/commands/login.command.d.ts +3 -0
  121. package/commands/login.command.js +16 -0
  122. package/commands/logout.command.d.ts +3 -0
  123. package/commands/logout.command.js +21 -0
  124. package/commands/openAPI.command/index.d.ts +2 -0
  125. package/commands/openAPI.command/index.js +102 -0
  126. package/commands/openAPI.command/utils.d.ts +19 -0
  127. package/commands/openAPI.command/utils.js +334 -0
  128. package/commands/passcode.command.d.ts +2 -0
  129. package/commands/passcode.command.js +26 -0
  130. package/commands/secrets.command/index.d.ts +3 -0
  131. package/commands/secrets.command/index.js +13 -0
  132. package/commands/secrets.command/show.command.d.ts +3 -0
  133. package/commands/secrets.command/show.command.js +25 -0
  134. package/config/core.d.ts +10 -0
  135. package/config/core.js +23 -0
  136. package/config/index.d.ts +5 -0
  137. package/config/index.js +90 -0
  138. package/configureLoggers.d.ts +1 -0
  139. package/configureLoggers.js +11 -0
  140. package/constants.d.ts +43 -0
  141. package/constants.js +175 -0
  142. package/discovery/index.d.ts +10 -0
  143. package/discovery/index.js +142 -0
  144. package/discovery/utils.d.ts +7 -0
  145. package/discovery/utils.js +27 -0
  146. package/dwc/dwc.d.ts +10 -0
  147. package/dwc/dwc.js +180 -0
  148. package/dwc/run.d.ts +1 -0
  149. package/dwc/run.js +37 -0
  150. package/dwc/utils.d.ts +4 -0
  151. package/dwc/utils.js +37 -0
  152. package/index.d.ts +16 -0
  153. package/index.js +59 -0
  154. package/logger/index.d.ts +28 -0
  155. package/logger/index.js +63 -0
  156. package/module.d.ts +4 -0
  157. package/module.js +45 -0
  158. package/package.json +32 -0
  159. package/result/ResultHandlerFactory.d.ts +6 -0
  160. package/result/ResultHandlerFactory.js +12 -0
  161. package/result/ResultHandlerImpl.d.ts +6 -0
  162. package/result/ResultHandlerImpl.js +12 -0
  163. package/result/types.d.ts +4 -0
  164. package/result/types.js +2 -0
  165. package/schemas/discovery.json +347 -0
  166. package/settings/index.d.ts +4 -0
  167. package/settings/index.js +34 -0
  168. package/types.d.ts +182 -0
  169. package/types.js +67 -0
  170. package/utils/commands.d.ts +8 -0
  171. package/utils/commands.js +115 -0
  172. package/utils/http/index.d.ts +7 -0
  173. package/utils/http/index.js +69 -0
  174. package/utils/http/utils.d.ts +7 -0
  175. package/utils/http/utils.js +47 -0
  176. package/utils/options.d.ts +3 -0
  177. package/utils/options.js +25 -0
  178. package/utils/utils.d.ts +24 -0
  179. package/utils/utils.js +163 -0
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addCommands = void 0;
4
+ const config_1 = require("../config");
5
+ const core_1 = require("../config/core");
6
+ const constants_1 = require("../constants");
7
+ const logger_1 = require("../logger");
8
+ const commands_1 = require("../utils/commands");
9
+ const handler_1 = require("./handler");
10
+ const passcode = () => async () => {
11
+ const { output } = (0, logger_1.get)("commands.passcode");
12
+ const config = (0, config_1.get)();
13
+ output(config.passcodeUrl);
14
+ };
15
+ const passcodeCommand = {
16
+ type: "command",
17
+ command: "passcode-url",
18
+ description: "display the passcode url",
19
+ handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), passcode),
20
+ };
21
+ const addCommands = async (program) => {
22
+ if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
23
+ (0, commands_1.buildCommand)(program, passcodeCommand);
24
+ }
25
+ };
26
+ exports.addCommands = addCommands;
@@ -0,0 +1,3 @@
1
+ import { TopCommand } from "../../types";
2
+ declare const secretsCommand: TopCommand;
3
+ export default secretsCommand;
@@ -0,0 +1,13 @@
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 show_command_1 = __importDefault(require("./show.command"));
7
+ const secretsCommand = {
8
+ type: "topCommand",
9
+ command: "secrets",
10
+ description: "work with the locally stored secrets",
11
+ subCommands: [show_command_1.default],
12
+ };
13
+ exports.default = secretsCommand;
@@ -0,0 +1,3 @@
1
+ import { Command } from "../../types";
2
+ declare const showCommand: Command;
3
+ export default showCommand;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const logger_1 = require("../../logger");
4
+ const handler_1 = require("../handler");
5
+ const cache_1 = require("../handler/authentication/oauth/secretsProvider/cache");
6
+ const utils_1 = require("../handler/authentication/oauth/utils");
7
+ const showSecrets = () => async () => {
8
+ const { output, error } = (0, logger_1.get)("commands.secrets-show");
9
+ try {
10
+ const secrets = (0, utils_1.getSecrets)();
11
+ output(JSON.stringify(secrets, null, 2));
12
+ }
13
+ catch (err) {
14
+ error("failed to read secrets", err);
15
+ output("No secrets exist");
16
+ throw new Error("failed to read secrets");
17
+ }
18
+ };
19
+ const showCommand = {
20
+ type: "command",
21
+ command: "show",
22
+ description: "display locally stored secrets for interactive OAuth authentication",
23
+ handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), showSecrets),
24
+ };
25
+ exports.default = showCommand;
@@ -0,0 +1,10 @@
1
+ import { AuthenticationMethod } from "../constants";
2
+ export declare const getName: () => string;
3
+ export declare const getPackageName: () => string;
4
+ export declare const getDescription: () => string;
5
+ export declare const getDiscoveryPath: () => string;
6
+ export declare const getSapHelp: () => string;
7
+ export declare const getAuthenticationMethods: () => Array<AuthenticationMethod>;
8
+ export declare const getVersion: () => string;
9
+ export declare const isDeprecated: () => boolean;
10
+ export declare const getDeprecationMessage: () => string | undefined;
package/config/core.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDeprecationMessage = exports.isDeprecated = exports.getVersion = exports.getAuthenticationMethods = exports.getSapHelp = exports.getDiscoveryPath = exports.getDescription = exports.getPackageName = exports.getName = void 0;
4
+ const constants_1 = require("../constants");
5
+ const index_1 = require("./index");
6
+ const getName = () => (0, index_1.get)()[constants_1.CLI_NAME];
7
+ exports.getName = getName;
8
+ const getPackageName = () => (0, index_1.get)()[constants_1.CLI_PACKAGE_NAME];
9
+ exports.getPackageName = getPackageName;
10
+ const getDescription = () => (0, index_1.get)()[constants_1.CLI_DESCRIPTION];
11
+ exports.getDescription = getDescription;
12
+ const getDiscoveryPath = () => (0, index_1.get)()[constants_1.CLI_DISCOVERY_PATH];
13
+ exports.getDiscoveryPath = getDiscoveryPath;
14
+ const getSapHelp = () => (0, index_1.get)()[constants_1.CLI_SAP_HELP];
15
+ exports.getSapHelp = getSapHelp;
16
+ const getAuthenticationMethods = () => (0, index_1.get)()[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS];
17
+ exports.getAuthenticationMethods = getAuthenticationMethods;
18
+ const getVersion = () => (0, index_1.get)()[constants_1.CLI_VERSION];
19
+ exports.getVersion = getVersion;
20
+ const isDeprecated = () => (0, index_1.get)()[constants_1.CLI_DEPRECATED] || false;
21
+ exports.isDeprecated = isDeprecated;
22
+ const getDeprecationMessage = () => (0, index_1.get)()[constants_1.CLI_DEPRECATION_MESSAGE];
23
+ exports.getDeprecationMessage = getDeprecationMessage;
@@ -0,0 +1,5 @@
1
+ import { KeyValuePair } from "../types";
2
+ export declare const initialize: () => void;
3
+ export declare const setCustomConfig: () => void;
4
+ export declare const set: (c: KeyValuePair) => void;
5
+ export declare const get: () => KeyValuePair;
@@ -0,0 +1,90 @@
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");
12
+ const CUSTOM_HOST = "tenant.host";
13
+ const CUSTOM_PASSCODE_URL = "tenant.passcodeUrl";
14
+ const CUSTOM_PUBLIC_FQDN = "tenant.publicfqdn";
15
+ let config;
16
+ const CONFIGS_TO_KEEP = [
17
+ constants_1.CONFIG_PASSCODE_FUNCTION,
18
+ constants_1.CLI_DESCRIPTION,
19
+ constants_1.CLI_DISCOVERY_PATH,
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
+ ];
28
+ const initialize = () => {
29
+ const keep = {};
30
+ for (const keepConfig of CONFIGS_TO_KEEP) {
31
+ keep[keepConfig] = config?.[keepConfig];
32
+ }
33
+ config = {};
34
+ for (const keepConfig of CONFIGS_TO_KEEP) {
35
+ if (keep[keepConfig]) {
36
+ config[keepConfig] = keep[keepConfig];
37
+ }
38
+ }
39
+ };
40
+ exports.initialize = initialize;
41
+ (0, exports.initialize)();
42
+ const getLogger = () => (0, logger_1.get)("config");
43
+ const setCustomConfig = () => {
44
+ const { trace, debug } = getLogger();
45
+ debug("setting custom configuration");
46
+ const sources = config_1.default.util.getConfigSources();
47
+ trace("config.custom.getConfigSources", JSON.stringify(sources, null, 2));
48
+ trace("config.custom.NODE_CONFIG_DIR", config_1.default.util.getEnv("NODE_CONFIG_DIR"));
49
+ trace("config.custom.NODE_ENV", config_1.default.util.getEnv("NODE_ENV"));
50
+ trace("config.custom.NODE_CONFIG", JSON.stringify(config_1.default.util.getEnv("NODE_CONFIG"), null, 2));
51
+ trace("config.custom.HOSTNAME", config_1.default.util.getEnv("HOSTNAME"));
52
+ trace("config.custom.NODE_APP_INSTANCE", config_1.default.util.getEnv("NODE_APP_INSTANCE"));
53
+ if (config_1.default.has(CUSTOM_HOST)) {
54
+ config.host = config_1.default.get(CUSTOM_HOST);
55
+ config.hostSetFromCustomConfig = true;
56
+ }
57
+ if (config_1.default.has(CUSTOM_PASSCODE_URL)) {
58
+ config.passcodeUrl = config_1.default.get(CUSTOM_PASSCODE_URL);
59
+ }
60
+ if (config_1.default.has(CUSTOM_PUBLIC_FQDN)) {
61
+ config.publicfqdn = (0, utils_1.parseTenant)(config_1.default.get(CUSTOM_PUBLIC_FQDN));
62
+ }
63
+ };
64
+ exports.setCustomConfig = setCustomConfig;
65
+ (0, exports.setCustomConfig)();
66
+ const setTenant = (tenant) => {
67
+ const info = (0, utils_1.getInfoFromTenant)(tenant, config.verbose);
68
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
69
+ (0, exports.set)({ ...info, newTenant: tenant });
70
+ };
71
+ const set = (c) => {
72
+ const { trace } = getLogger();
73
+ const prev = JSON.parse(JSON.stringify(config));
74
+ if (c.tenant) {
75
+ setTenant(c.tenant);
76
+ }
77
+ else {
78
+ config = lodash_1.default.merge(config, c);
79
+ if (config.newTenant) {
80
+ config.tenant = config.newTenant;
81
+ delete config.newTenant;
82
+ }
83
+ if (!lodash_1.default.isEqual(prev, config)) {
84
+ trace("configuration changed. previous: %s, current: %s", JSON.stringify(prev), JSON.stringify(config));
85
+ }
86
+ }
87
+ };
88
+ exports.set = set;
89
+ const get = () => config;
90
+ exports.get = get;
@@ -0,0 +1 @@
1
+ export declare const configureLoggers: () => void;
@@ -0,0 +1,11 @@
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)({
6
+ logLevel: process.env.LOG_LEVEL
7
+ ? parseInt(process.env.LOG_LEVEL, 10)
8
+ : undefined,
9
+ loggers: process.env.LOGGERS ? new RegExp(process.env.LOGGERS) : undefined,
10
+ });
11
+ exports.configureLoggers = configureLoggers;
package/constants.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { Option } from "./types";
2
+ export declare const VERSION: string;
3
+ export declare const DISCOVERY_DOCUMENT_PREFIX = "discovery-";
4
+ export declare enum AuthenticationMethod {
5
+ oauth = "oauth",
6
+ passcode = "passcode"
7
+ }
8
+ export declare const CLI_NAME = "cli-name";
9
+ export declare const CLI_PACKAGE_NAME = "cli-package-name";
10
+ export declare const CLI_DESCRIPTION = "cli-description";
11
+ export declare const CLI_DISCOVERY_PATH = "cli-discovery-path";
12
+ export declare const CLI_SAP_HELP = "cli-sap-help";
13
+ export declare const CLI_VERSION = "cli-version";
14
+ export declare const CLI_DEPRECATED = "cli-deprecated";
15
+ export declare const CLI_DEPRECATION_MESSAGE = "cli-deprecation-message";
16
+ export declare const CLI_SUPPORTED_AUTHENTICATION_METHODS = "cli-supported-authentication-methods";
17
+ export declare const SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH: string[];
18
+ export declare const DISCOVERY_METADATA_PATH = "discovery-metadata.json";
19
+ export declare const X_CSRF_TOKEN = "x-csrf-token";
20
+ export declare const PATH_TO_SUCCESS_HTML: string;
21
+ export declare const PATH_TO_ERROR_HTML: string;
22
+ export declare const CACHE_SECRETS_FILE = "secrets.json";
23
+ export declare const OPTION_VERSION: Option;
24
+ export declare const OPTION_HELP: Option;
25
+ export declare const OPTION_HOST: Option;
26
+ export declare const OPTION_OUTPUT: Option;
27
+ export declare const OPTION_PRETTY: Option;
28
+ export declare const OPTION_VERBOSE: Option;
29
+ export declare const OPTION_FORCE: Option;
30
+ export declare const OPTION_CLIENT_ID: Option;
31
+ export declare const OPTION_CLIENT_SECRET: Option;
32
+ export declare const OPTION_AUTHORIZATION_URL: Option;
33
+ export declare const OPTION_TOKEN_URL: Option;
34
+ export declare const OPTION_ACCESS_TOKEN: Option;
35
+ export declare const OPTION_REFRESH_TOKEN: Option;
36
+ export declare const OPTION_EXPIRES_IN: Option;
37
+ export declare const OPTION_SECRETS_FILE: Option;
38
+ export declare const OPTION_CODE: Option;
39
+ export declare const OPTION_PASSCODE: Option;
40
+ export declare const CONFIG_PASSCODE_FUNCTION = "passcodeFunction";
41
+ export declare const OPTION_OPTIONS_FILE: Option;
42
+ export declare const OPTION_FILE_PATH: Option;
43
+ export declare const OPTION_INPUT: Option;
package/constants.js ADDED
@@ -0,0 +1,175 @@
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_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_PRETTY = exports.OPTION_OUTPUT = 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_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATH = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("./utils/utils");
9
+ exports.VERSION = (0, utils_1.getVersion)();
10
+ exports.DISCOVERY_DOCUMENT_PREFIX = "discovery-";
11
+ var AuthenticationMethod;
12
+ (function (AuthenticationMethod) {
13
+ AuthenticationMethod["oauth"] = "oauth";
14
+ AuthenticationMethod["passcode"] = "passcode";
15
+ })(AuthenticationMethod = exports.AuthenticationMethod || (exports.AuthenticationMethod = {}));
16
+ exports.CLI_NAME = "cli-name";
17
+ exports.CLI_PACKAGE_NAME = "cli-package-name";
18
+ exports.CLI_DESCRIPTION = "cli-description";
19
+ exports.CLI_DISCOVERY_PATH = "cli-discovery-path";
20
+ exports.CLI_SAP_HELP = "cli-sap-help";
21
+ exports.CLI_VERSION = "cli-version";
22
+ exports.CLI_DEPRECATED = "cli-deprecated";
23
+ exports.CLI_DEPRECATION_MESSAGE = "cli-deprecation-message";
24
+ exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = "cli-supported-authentication-methods";
25
+ exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = ["dwaas-core"];
26
+ exports.DISCOVERY_METADATA_PATH = "discovery-metadata.json";
27
+ exports.X_CSRF_TOKEN = "x-csrf-token";
28
+ exports.PATH_TO_SUCCESS_HTML = path_1.default.join(__dirname, "assets", "success.html");
29
+ exports.PATH_TO_ERROR_HTML = path_1.default.join(__dirname, "assets", "error.html");
30
+ exports.CACHE_SECRETS_FILE = "secrets.json";
31
+ exports.OPTION_VERSION = {
32
+ longName: "version",
33
+ description: "print version",
34
+ };
35
+ exports.OPTION_HELP = {
36
+ longName: "help",
37
+ description: "print help for a command",
38
+ args: [{ name: "command" }],
39
+ };
40
+ exports.OPTION_HOST = {
41
+ longName: "host",
42
+ description: "specifies the url where the tenant is hosted",
43
+ args: [{ name: "host" }],
44
+ prompts: {
45
+ message: "URL of the SAP Data Warehouse Cloud system to connect to:",
46
+ type: "text",
47
+ },
48
+ };
49
+ exports.OPTION_OUTPUT = {
50
+ longName: "output",
51
+ description: "specifies the file to store the output of the command",
52
+ args: [{ name: "output" }],
53
+ };
54
+ exports.OPTION_PRETTY = {
55
+ longName: "pretty",
56
+ description: "pretty-formats JSON responses",
57
+ };
58
+ exports.OPTION_VERBOSE = {
59
+ longName: "verbose",
60
+ description: "print detailed log information to console",
61
+ };
62
+ exports.OPTION_FORCE = {
63
+ longName: "force",
64
+ description: "force the command execution",
65
+ };
66
+ exports.OPTION_CLIENT_ID = {
67
+ longName: "client-id",
68
+ description: "client id for interactive oauth session authentication",
69
+ args: [{ name: "id" }],
70
+ prompts: {
71
+ type: "text",
72
+ message: `Please enter your client ID:`,
73
+ },
74
+ };
75
+ exports.OPTION_CLIENT_SECRET = {
76
+ longName: "client-secret",
77
+ description: "client secret for interactive oauth session authentication",
78
+ args: [{ name: "secret" }],
79
+ prompts: {
80
+ type: "password",
81
+ message: `Please enter your client secret:`,
82
+ },
83
+ };
84
+ exports.OPTION_AUTHORIZATION_URL = {
85
+ longName: "authorization-url",
86
+ description: "authorization url for interactive oauth session authentication",
87
+ args: [{ name: "url" }],
88
+ prompts: {
89
+ type: "text",
90
+ message: `Please enter your authorization URL:`,
91
+ },
92
+ };
93
+ exports.OPTION_TOKEN_URL = {
94
+ longName: "token-url",
95
+ description: "token url for interactive oauth session authentication",
96
+ args: [{ name: "url" }],
97
+ prompts: {
98
+ type: "text",
99
+ message: `Please enter your token URL:`,
100
+ },
101
+ };
102
+ exports.OPTION_ACCESS_TOKEN = {
103
+ longName: "access-token",
104
+ description: "access token for interactive oauth session authentication",
105
+ args: [{ name: "token" }],
106
+ prompts: {
107
+ type: "password",
108
+ message: `Please enter your access token:`,
109
+ },
110
+ };
111
+ exports.OPTION_REFRESH_TOKEN = {
112
+ longName: "refresh-token",
113
+ description: "refresh token for interactive oauth session authentication",
114
+ args: [{ name: "token" }],
115
+ prompts: {
116
+ type: "password",
117
+ message: `Please enter your refresh token:`,
118
+ },
119
+ };
120
+ exports.OPTION_EXPIRES_IN = {
121
+ longName: "expires-in",
122
+ description: "expires in information for interactive oauth session authentication",
123
+ args: [{ name: "expires" }],
124
+ prompts: {
125
+ type: "number",
126
+ message: `Please enter a value for expires in:`,
127
+ },
128
+ };
129
+ exports.OPTION_SECRETS_FILE = {
130
+ longName: "secrets-file",
131
+ description: "path to secrets file",
132
+ args: [{ name: "file" }],
133
+ prompts: {
134
+ type: "text",
135
+ message: `Please enter the path to the secrets file:`,
136
+ },
137
+ };
138
+ exports.OPTION_CODE = {
139
+ longName: "code",
140
+ description: "code for oauth token retrieval",
141
+ args: [{ name: "code" }],
142
+ prompts: {
143
+ type: "text",
144
+ message: `Please enter the code for retrieving the oauth access_token and refresh_token:`,
145
+ },
146
+ };
147
+ exports.OPTION_PASSCODE = {
148
+ longName: "passcode",
149
+ description: "passcode for interactive session authentication",
150
+ args: [{ name: "passcode" }],
151
+ };
152
+ exports.CONFIG_PASSCODE_FUNCTION = "passcodeFunction";
153
+ exports.OPTION_OPTIONS_FILE = {
154
+ longName: "options-file",
155
+ description: "path to options file",
156
+ args: [{ name: "file" }],
157
+ };
158
+ exports.OPTION_FILE_PATH = {
159
+ longName: "file-path",
160
+ description: "specifies the file to use as input for the command",
161
+ args: [{ name: "path" }],
162
+ prompts: {
163
+ message: "Path to input file:",
164
+ type: "text",
165
+ },
166
+ };
167
+ exports.OPTION_INPUT = {
168
+ longName: "input",
169
+ description: "specifies input as string to use for the command",
170
+ args: [{ name: "input" }],
171
+ prompts: {
172
+ message: "Input as string:",
173
+ type: "text",
174
+ },
175
+ };
@@ -0,0 +1,10 @@
1
+ import { Discovery, DiscoveryMetadata } from "../types";
2
+ export declare const getPathToDiscoveryDocument: () => string;
3
+ export declare const getMetadata: () => Promise<Array<DiscoveryMetadata>>;
4
+ export declare const addMetadata: ({ tenant, addedAt, }: DiscoveryMetadata) => Promise<void>;
5
+ export declare const clear: () => void;
6
+ export declare const init: () => Promise<Discovery>;
7
+ export declare const compareEtags: () => Promise<boolean>;
8
+ export declare const checkVersion: () => Promise<{
9
+ status: "UPTODATE" | "OUTDATED";
10
+ }>;
@@ -0,0 +1,142 @@
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");
17
+ let initialized = false;
18
+ let document;
19
+ let metadata;
20
+ const getDocumentName = () => {
21
+ const { trace } = getLogger();
22
+ const config = (0, config_1.get)();
23
+ const sha = (0, utils_2.sha256)(`${config.publicfqdn}${(0, core_1.getDiscoveryPath)()}`).replace(/[/\\]/g, "_");
24
+ const name = `${constants_1.DISCOVERY_DOCUMENT_PREFIX}${sha}.json`;
25
+ trace(`calculating document name for host ${config.host}, name ${name}`);
26
+ return name;
27
+ };
28
+ const getPathToDiscoveryDocument = () => (0, cache_1.getPath)(getDocumentName());
29
+ exports.getPathToDiscoveryDocument = getPathToDiscoveryDocument;
30
+ const initMetadata = async () => {
31
+ const { error } = getLogger();
32
+ if (!metadata) {
33
+ try {
34
+ metadata = JSON.parse(await (0, cache_1.readFile)(constants_1.DISCOVERY_METADATA_PATH));
35
+ }
36
+ catch (err) {
37
+ error("error while reading discovery metadata", err.stack);
38
+ metadata = [];
39
+ }
40
+ }
41
+ };
42
+ const getMetadata = async () => {
43
+ await initMetadata();
44
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45
+ return metadata;
46
+ };
47
+ exports.getMetadata = getMetadata;
48
+ const addMetadata = async ({ tenant, addedAt, }) => {
49
+ await initMetadata();
50
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
+ metadata = metadata.filter((t) => t.tenant !== tenant);
52
+ metadata.push({ tenant, addedAt });
53
+ await (0, cache_1.writeFile)(constants_1.DISCOVERY_METADATA_PATH, JSON.stringify(metadata));
54
+ };
55
+ exports.addMetadata = addMetadata;
56
+ const clear = () => {
57
+ initialized = false;
58
+ document = undefined;
59
+ metadata = undefined;
60
+ };
61
+ exports.clear = clear;
62
+ /* jscpd:ignore-start */
63
+ const init = async () => {
64
+ const { trace, error, debug } = getLogger();
65
+ if (initialized) {
66
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67
+ return document;
68
+ }
69
+ initialized = true;
70
+ /* jscpd:ignore-end */
71
+ let schema;
72
+ try {
73
+ trace("reading discovery document");
74
+ const file = await (0, cache_1.readFile)(getDocumentName());
75
+ document = JSON.parse(file);
76
+ }
77
+ catch (err) {
78
+ error("error while reading discovery document", err.stack);
79
+ throw err;
80
+ }
81
+ try {
82
+ trace("reading schema document");
83
+ try {
84
+ const file = await fs_extra_1.default.readFile(path_1.default.join(__dirname, "..", "..", "schemas", "discovery.json"), "utf-8");
85
+ schema = JSON.parse(file);
86
+ }
87
+ catch (err) {
88
+ debug("failed reading schema, trying again", err.stack);
89
+ // path changes after build
90
+ const file = await fs_extra_1.default.readFile(path_1.default.join(__dirname, "..", "schemas", "discovery.json"), "utf-8");
91
+ schema = JSON.parse(file);
92
+ }
93
+ }
94
+ catch (err) {
95
+ error("error while reading schema document", err.stack);
96
+ throw err;
97
+ }
98
+ debug("validating discovery document against schema");
99
+ const result = await (0, utils_1.validate)(schema, document);
100
+ if (result.result === "INVALID") {
101
+ error("discovery document contains invalid data", result.errors);
102
+ throw new Error("discovery document contains invalid data");
103
+ }
104
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
105
+ return document;
106
+ };
107
+ exports.init = init;
108
+ const compareEtags = async () => {
109
+ const { debug, error } = getLogger();
110
+ try {
111
+ const doc = await (0, exports.init)();
112
+ const config = (0, config_1.get)();
113
+ if (config.etag && doc) {
114
+ const etag = (0, utils_2.sha256)(JSON.stringify(doc));
115
+ if (config.etag === etag) {
116
+ debug("etags match: %s", config.etag);
117
+ return true;
118
+ }
119
+ debug("etags do not match. server: %s, client: %s", config.etag, etag);
120
+ return false;
121
+ }
122
+ debug("etag is not available");
123
+ }
124
+ catch (err) {
125
+ error("failed to compare etags", err.stack);
126
+ }
127
+ return true;
128
+ };
129
+ exports.compareEtags = compareEtags;
130
+ const checkVersion = async () => {
131
+ const { debug } = getLogger();
132
+ const doc = await (0, exports.init)();
133
+ const local = (0, utils_2.parseVersion)(constants_1.VERSION);
134
+ const server = (0, utils_2.parseVersion)(doc.info["x-document-version"]);
135
+ if (local.major < server.major ||
136
+ (local.major === server.major && local.minor < server.minor)) {
137
+ debug(`CLI is outdated (local: ${JSON.stringify(local)}, server: ${JSON.stringify(server)})`);
138
+ return { status: "OUTDATED" };
139
+ }
140
+ return { status: "UPTODATE" };
141
+ };
142
+ exports.checkVersion = checkVersion;
@@ -0,0 +1,7 @@
1
+ import { ErrorObject } from "ajv";
2
+ export declare const validate: (schema: string, data: unknown) => Promise<{
3
+ result: "VALID";
4
+ } | {
5
+ result: "INVALID";
6
+ errors: Array<Partial<ErrorObject>>;
7
+ }>;
@@ -0,0 +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.validate = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
+ const logger_1 = require("../logger");
9
+ const validate = async (schema, data) => {
10
+ const logger = (0, logger_1.get)("jsonschema");
11
+ try {
12
+ const ajv = new ajv_1.default({ logger });
13
+ // use await, see ajv.js.org/api.html#ajv-validate-schemaorref-object-string-data-any-boolean
14
+ await ajv.validate(schema, data);
15
+ return {
16
+ result: "VALID",
17
+ };
18
+ }
19
+ catch (err) {
20
+ logger.error("error while compiling schema or validating data", err.stack);
21
+ return {
22
+ result: "INVALID",
23
+ errors: err.errors,
24
+ };
25
+ }
26
+ };
27
+ exports.validate = validate;
package/dwc/dwc.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const init: () => Promise<void>;
2
+ export declare const executeCommand: (command?: string) => Promise<void>;
3
+ type Options = {
4
+ [option: string]: string;
5
+ };
6
+ type CommandObject = {
7
+ [command: string]: (options?: Options) => Promise<void>;
8
+ };
9
+ export declare const getCommands: (host?: string) => Promise<CommandObject>;
10
+ export {};