@sap/cli-core 2024.3.0 → 2024.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,64 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2024.4.0
9
+
10
+ ### Added
11
+
12
+ - Support for Node versions `18`, `19`, `20`, `21`.
13
+
14
+ - When using the CLI as a [As a Node.js module dependency](README.md#as-a-nodejs-module-dependency) and running a command which creates an entity where the CLI would print the command to retrieve the result when running the command to create the entity in the terminal, for example:
15
+
16
+ ```bash
17
+ <cli> spaces create -H https://mytenant.eu10.hcs.cloud.sap/ -f ./MY_SPACE.json
18
+ Use <cli> spaces read --space-id MY_SPACE to retrieve the entity you just created
19
+ ```
20
+
21
+ the CLI now returns the command to execute as an object:
22
+
23
+ ```bash
24
+ const retrieveCommand = await commands["spaces create"]({
25
+ "--file-path": "MY_SPACE.json",
26
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
27
+ });
28
+
29
+ console.log(retrieveCommand);
30
+ // {
31
+ // command: "spaces read",
32
+ // options: {
33
+ // "--space-id": "MY_SPACE"
34
+ // },
35
+ // }
36
+ ```
37
+
38
+ You can use the returned response to immediately issue the command to read the entity:
39
+
40
+ ```bash
41
+ const retrieveCommand = await commands["spaces create"]({
42
+ "--file-path": "MY_SPACE.json",
43
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
44
+ });
45
+
46
+ const response = await commands[retrieveCommand.command]({
47
+ ...retrieveCommand.options,
48
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
49
+ });
50
+
51
+ console.log(response);
52
+ // {
53
+ // MY_SPACE: {
54
+ // version: "1.0.4",
55
+ // ...
56
+ // }
57
+ // }
58
+ ```
59
+
60
+ - The CLI core module now supports retrieving the discovery documents from multiple endpoints for the same tenant. This allows you to define a list of endpoints from which the discovery documents should be retrieved. Multiple services, reachable through the same tenant, can expose their own, distinct discovery documents. There is no need to have a single service expose the full document for the tenant. The retrieved discovery documents are merged into a single document. All commands are shown to the user, not distinguished by endpoint or service. Only OAuth authentication is supported when specifying multiple endpoints.
61
+
62
+ ### Fixed
63
+
64
+ - When the host is globally configured via the command `<cli> config host set <host>`, any other host specified via option `-H, --host` was ignored when running a command. This often led to confusion when users specify the host explicitly via option `-H, --host`, but are not aware that the host was globally configured, too. Now, option `-H, --host` always takes precedence over the globally configured host.
65
+
8
66
  ## 2024.2.0
9
67
 
10
68
  ### Changed
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Command-Line Interface (CLI) Core Module.
4
4
 
5
- [![Node Version](https://img.shields.io/badge/node-20.10.0-brightgreen)](https://nodejs.org/dist/latest-v20.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](https://badge.fury.io/js/@sap%2Fcli-core)
5
+ [![Node Version](https://img.shields.io/badge/node-18.xx.x-brightgreen)](https://nodejs.org/dist/latest-v18.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-19.xx.x-brightgreen)](https://nodejs.org/dist/latest-v19.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-20.xx.x-brightgreen)](https://nodejs.org/dist/latest-v20.x/docs/api/#) [![Node Version](https://img.shields.io/badge/node-21.xx.x-brightgreen)](https://nodejs.org/dist/latest-v21.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](https://badge.fury.io/js/@sap%2Fcli-core)
6
6
 
7
7
  ## Content
8
8
 
@@ -1,4 +1,4 @@
1
- import { CommanderHandler, LeafCommand } from "../../../types";
1
+ import { CommanderHandler, LeafCommand } from "../../../../types";
2
2
  export declare const init: () => Promise<CommanderHandler>;
3
3
  declare const initCommand: LeafCommand;
4
4
  export default initCommand;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /* eslint-disable no-await-in-loop */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.init = void 0;
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const constants_1 = require("../../../../constants");
10
+ const discovery_1 = require("../../../../discovery");
11
+ const handler_1 = require("../../../handler");
12
+ const config_1 = require("../../../../config");
13
+ const core_1 = require("../../../../config/core");
14
+ const ResultHandlerFactory_1 = require("../../../../result/ResultHandlerFactory");
15
+ const utils_1 = require("./utils");
16
+ const utils_2 = require("../../../handler/utils");
17
+ const logger_1 = require("../../../../logger");
18
+ const pre = () => {
19
+ (0, config_1.set)({
20
+ doNotStoreResult: false,
21
+ doNotProcessResponseData: true,
22
+ });
23
+ };
24
+ const post = async (discovery) => {
25
+ const config = (0, config_1.get)();
26
+ await (0, discovery_1.addMetadata)({
27
+ tenant: config.publicfqdn,
28
+ addedAt: new Date().getTime(),
29
+ });
30
+ (0, discovery_1.clear)();
31
+ const { options } = config;
32
+ delete options[constants_1.OPTION_OUTPUT.longName];
33
+ (0, config_1.set)({ options });
34
+ ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(undefined);
35
+ await fs_extra_1.default.writeFile((0, discovery_1.getPathToDiscoveryDocument)(), JSON.stringify(discovery));
36
+ };
37
+ const init = async () => async () => {
38
+ pre();
39
+ const { output } = (0, logger_1.get)("init.command");
40
+ const discovery = {
41
+ info: {
42
+ version: constants_1.VERSION,
43
+ "x-document-version": constants_1.VERSION,
44
+ },
45
+ openapi: "3.0.3",
46
+ paths: {},
47
+ tags: [],
48
+ components: {},
49
+ };
50
+ const paths = (0, core_1.getDiscoveryPaths)();
51
+ if (paths.length > 1 &&
52
+ (0, utils_2.getAuthenticationMethod)() !== constants_1.AuthenticationMethod.oauth) {
53
+ output("Only OAuth authentication is supported");
54
+ throw new Error("only oauth authentication is supported");
55
+ }
56
+ for (const path of paths) {
57
+ await (await (0, handler_1.createFetchHandler)("GET", path)({}))();
58
+ const newDiscovery = ResultHandlerFactory_1.ResultHandlerFactory.get().getResult();
59
+ (0, utils_1.mergeDiscoveries)(discovery, newDiscovery);
60
+ }
61
+ await post(discovery);
62
+ };
63
+ exports.init = init;
64
+ const initCommand = {
65
+ type: "command",
66
+ command: "init",
67
+ description: "initialize the local CLI cache",
68
+ options: [],
69
+ handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
70
+ };
71
+ exports.default = initCommand;
@@ -0,0 +1,3 @@
1
+ import { Discovery } from "../../../../types";
2
+ export declare function getLowerVersion(a: string, b: string): string;
3
+ export declare function mergeDiscoveries(discovery: Discovery, newDiscovery: Discovery): void;
@@ -0,0 +1,20 @@
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.mergeDiscoveries = exports.getLowerVersion = void 0;
7
+ const compare_versions_1 = require("compare-versions");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ function getLowerVersion(a, b) {
10
+ return [a, b].sort(compare_versions_1.compareVersions)[0];
11
+ }
12
+ exports.getLowerVersion = getLowerVersion;
13
+ function mergeDiscoveries(discovery, newDiscovery) {
14
+ lodash_1.default.merge(discovery, newDiscovery);
15
+ // eslint-disable-next-line no-param-reassign
16
+ discovery.info.version = getLowerVersion(discovery.info.version, newDiscovery.info.version);
17
+ // eslint-disable-next-line no-param-reassign
18
+ discovery.info["x-document-version"] = getLowerVersion(discovery.info["x-document-version"], newDiscovery.info["x-document-version"]);
19
+ }
20
+ exports.mergeDiscoveries = mergeDiscoveries;
@@ -123,6 +123,9 @@ const handleResponseData = async (data, outputPath) => {
123
123
  if (!config.doNotStoreResult) {
124
124
  ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(data);
125
125
  }
126
+ if (config.doNotProcessResponseData) {
127
+ return;
128
+ }
126
129
  const { output } = (0, logger_1.get)("handler.fetch");
127
130
  const formatted = config.options.pretty
128
131
  ? JSON.stringify(data, null, 2)
@@ -30,6 +30,7 @@ const logger_1 = require("../../logger");
30
30
  const utils_1 = require("../../utils/utils");
31
31
  const config_1 = require("../../config");
32
32
  const handler_1 = require("../handler");
33
+ const ResultHandlerFactory_1 = require("../../result/ResultHandlerFactory");
33
34
  const getLogger = () => (0, logger_1.get)("commands.openAPI.utils");
34
35
  const updatePath = (doc, path) => {
35
36
  const version = (0, utils_1.parseVersion)(doc.info.version);
@@ -41,7 +42,10 @@ const updatePath = (doc, path) => {
41
42
  exports.updatePath = updatePath;
42
43
  const isPathParameter = (segment) => /^{.*}$/.test(segment);
43
44
  exports.isPathParameter = isPathParameter;
44
- const writeParameter = (parameter, value) => `--${(0, lodash_1.kebabCase)(parameter.slice(1, -1))} ${value}`;
45
+ function getParameterName(parameter) {
46
+ return `--${(0, lodash_1.kebabCase)(parameter.slice(1, -1))}`;
47
+ }
48
+ const writeParameter = (parameter, value) => `${getParameterName(parameter)} ${value}`;
45
49
  exports.writeParameter = writeParameter;
46
50
  const getSegments = (value) => {
47
51
  const segments = value.split("/");
@@ -66,14 +70,26 @@ const getPathItem = (doc, operation, path) => {
66
70
  }
67
71
  throw new Error(`path ${operation["x-read-path"]} does not support GET operation`);
68
72
  };
73
+ function handleOptions(options, option, value) {
74
+ if ((0, exports.isPathParameter)(option)) {
75
+ return { ...options, [getParameterName(option)]: value };
76
+ }
77
+ return options;
78
+ }
69
79
  const outputReadCommand = (doc, operation, response, path) => {
70
80
  const locationSegments = (0, exports.getSegments)(response.headers.location);
71
81
  const pathSegments = (0, exports.getSegments)(path);
72
82
  let params = "";
83
+ let options = {};
73
84
  for (let i = 0; i < pathSegments.length; i++) {
74
85
  params = handleParameter(params, pathSegments[i], locationSegments[i]);
86
+ options = handleOptions(options, pathSegments[i], locationSegments[i]);
75
87
  }
76
88
  const pathItem = getPathItem(doc, operation, path);
89
+ ResultHandlerFactory_1.ResultHandlerFactory.get().setResult({
90
+ command: pathItem.get.operationId,
91
+ options,
92
+ });
77
93
  const { output } = getLogger();
78
94
  output(`Use ${(0, config_1.get)()[constants_1.CLI_NAME]} ${pathItem.get.operationId} ${params} to retrieve the entity you just created`);
79
95
  };
package/config/core.d.ts CHANGED
@@ -2,7 +2,7 @@ import { AuthenticationMethod } from "../constants";
2
2
  export declare const getName: () => string;
3
3
  export declare const getPackageName: () => string;
4
4
  export declare const getDescription: () => string;
5
- export declare const getDiscoveryPath: () => string;
5
+ export declare const getDiscoveryPaths: () => Array<string>;
6
6
  export declare const getSapHelp: () => string;
7
7
  export declare const getAuthenticationMethods: () => Array<AuthenticationMethod>;
8
8
  export declare const getVersion: () => string;
package/config/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGenericOptionsHelp = exports.getDeprecationMessage = exports.isDeprecated = exports.getVersion = exports.getAuthenticationMethods = exports.getSapHelp = exports.getDiscoveryPath = exports.getDescription = exports.getPackageName = exports.getName = void 0;
3
+ exports.getGenericOptionsHelp = exports.getDeprecationMessage = exports.isDeprecated = exports.getVersion = exports.getAuthenticationMethods = exports.getSapHelp = exports.getDiscoveryPaths = exports.getDescription = exports.getPackageName = exports.getName = void 0;
4
4
  /* jscpd:ignore-start */
5
5
  const constants_1 = require("../constants");
6
6
  /* jscpd:ignore-end */
@@ -11,8 +11,8 @@ const getPackageName = () => (0, index_1.get)()[constants_1.CLI_PACKAGE_NAME];
11
11
  exports.getPackageName = getPackageName;
12
12
  const getDescription = () => (0, index_1.get)()[constants_1.CLI_DESCRIPTION];
13
13
  exports.getDescription = getDescription;
14
- const getDiscoveryPath = () => (0, index_1.get)()[constants_1.CLI_DISCOVERY_PATH];
15
- exports.getDiscoveryPath = getDiscoveryPath;
14
+ const getDiscoveryPaths = () => (0, index_1.get)()[constants_1.CLI_DISCOVERY_PATHS];
15
+ exports.getDiscoveryPaths = getDiscoveryPaths;
16
16
  const getSapHelp = () => (0, index_1.get)()[constants_1.CLI_SAP_HELP];
17
17
  exports.getSapHelp = getSapHelp;
18
18
  const getAuthenticationMethods = () => (0, index_1.get)()[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS];
package/config/index.js CHANGED
@@ -16,7 +16,7 @@ let config;
16
16
  const CONFIGS_TO_KEEP = [
17
17
  constants_1.CONFIG_PASSCODE_FUNCTION,
18
18
  constants_1.CLI_DESCRIPTION,
19
- constants_1.CLI_DISCOVERY_PATH,
19
+ constants_1.CLI_DISCOVERY_PATHS,
20
20
  constants_1.CLI_NAME,
21
21
  constants_1.CLI_PACKAGE_NAME,
22
22
  constants_1.CLI_SAP_HELP,
package/constants.d.ts CHANGED
@@ -1,5 +1,17 @@
1
1
  import { Option } from "./types";
2
2
  export declare const VERSION: string;
3
+ export type CoreConfiguration = {
4
+ getName: () => string;
5
+ getPackageName: () => string;
6
+ getDescription: () => string;
7
+ getDiscoveryPaths: () => Array<string>;
8
+ getSapHelp: () => string;
9
+ getAuthenticationMethods: () => Array<AuthenticationMethod>;
10
+ getVersion: () => string;
11
+ isDeprecated: () => boolean;
12
+ getDeprecationMessage: () => string;
13
+ getGenericOptionsHelp: () => string;
14
+ };
3
15
  export declare const DISCOVERY_DOCUMENT_PREFIX = "discovery-";
4
16
  export declare enum AuthenticationMethod {
5
17
  oauth = "oauth",
@@ -8,7 +20,7 @@ export declare enum AuthenticationMethod {
8
20
  export declare const CLI_NAME = "cli-name";
9
21
  export declare const CLI_PACKAGE_NAME = "cli-package-name";
10
22
  export declare const CLI_DESCRIPTION = "cli-description";
11
- export declare const CLI_DISCOVERY_PATH = "cli-discovery-path";
23
+ export declare const CLI_DISCOVERY_PATHS = "cli-discovery-paths";
12
24
  export declare const CLI_SAP_HELP = "cli-sap-help";
13
25
  export declare const CLI_VERSION = "cli-version";
14
26
  export declare const CLI_DEPRECATED = "cli-deprecated";
package/constants.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- 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_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_PATH = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
6
+ 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_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.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const utils_1 = require("./utils/utils");
9
9
  exports.VERSION = (0, utils_1.getVersion)();
@@ -16,7 +16,7 @@ var AuthenticationMethod;
16
16
  exports.CLI_NAME = "cli-name";
17
17
  exports.CLI_PACKAGE_NAME = "cli-package-name";
18
18
  exports.CLI_DESCRIPTION = "cli-description";
19
- exports.CLI_DISCOVERY_PATH = "cli-discovery-path";
19
+ exports.CLI_DISCOVERY_PATHS = "cli-discovery-paths";
20
20
  exports.CLI_SAP_HELP = "cli-sap-help";
21
21
  exports.CLI_VERSION = "cli-version";
22
22
  exports.CLI_DEPRECATED = "cli-deprecated";
@@ -20,7 +20,7 @@ let metadata;
20
20
  const getDocumentName = () => {
21
21
  const { trace } = getLogger();
22
22
  const config = (0, config_1.get)();
23
- const sha = (0, utils_2.sha256)(`${config.publicfqdn}${(0, core_1.getDiscoveryPath)()}`).replace(/[/\\]/g, "_");
23
+ const sha = (0, utils_2.sha256)(`${config.publicfqdn}${JSON.stringify((0, core_1.getDiscoveryPaths)())}`).replace(/[/\\]/g, "_");
24
24
  const name = `${constants_1.DISCOVERY_DOCUMENT_PREFIX}${sha}.json`;
25
25
  trace(`calculating document name for host ${config.host}, name ${name}`);
26
26
  return name;
package/dwc/dwc.js CHANGED
@@ -73,7 +73,11 @@ const setTenant = async () => {
73
73
  try {
74
74
  // eslint-disable-next-line no-await-in-loop
75
75
  const host = await func();
76
- (0, config_1.set)({ tenant: host });
76
+ (0, config_1.set)({
77
+ tenant: host,
78
+ options: { ...config.options, [constants_1.OPTION_HOST.longName]: host },
79
+ });
80
+ break;
77
81
  }
78
82
  catch (err) {
79
83
  trace(`failed to ${name}`, err);
package/index.d.ts CHANGED
@@ -3,10 +3,10 @@ export { run } from "./dwc/run";
3
3
  export { configure, getCommands } from "./module";
4
4
  export { AuthenticationMethod };
5
5
  export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils";
6
- export declare const configureCoreModule: ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods, version, genericOptionsHelp, deprecated, deprecationMessage, }: {
6
+ export declare const configureCoreModule: ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods, version, genericOptionsHelp, deprecated, deprecationMessage, }: {
7
7
  name: string;
8
8
  packageName: string;
9
- discoveryPath: string;
9
+ discoveryPaths: Array<string>;
10
10
  description: string;
11
11
  sapHelpLink: string;
12
12
  authenticationMethods?: AuthenticationMethod[] | undefined;
package/index.js CHANGED
@@ -45,12 +45,12 @@ Object.defineProperty(exports, "getBin", { enumerable: true, get: function () {
45
45
  Object.defineProperty(exports, "getDescription", { enumerable: true, get: function () { return utils_1.getDescription; } });
46
46
  Object.defineProperty(exports, "getName", { enumerable: true, get: function () { return utils_1.getName; } });
47
47
  Object.defineProperty(exports, "getPackageName", { enumerable: true, get: function () { return utils_1.getPackageName; } });
48
- const configureCoreModule = ({ name, packageName, discoveryPath, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, genericOptionsHelp, deprecated = false, deprecationMessage, }) => {
48
+ const configureCoreModule = ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, genericOptionsHelp, deprecated = false, deprecationMessage, }) => {
49
49
  (0, config_1.set)({
50
50
  [constants_1.CLI_NAME]: name,
51
51
  [constants_1.CLI_PACKAGE_NAME]: packageName,
52
52
  [constants_1.CLI_DESCRIPTION]: description,
53
- [constants_1.CLI_DISCOVERY_PATH]: discoveryPath,
53
+ [constants_1.CLI_DISCOVERY_PATHS]: discoveryPaths,
54
54
  [constants_1.CLI_SAP_HELP]: sapHelpLink,
55
55
  [constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS]: authenticationMethods,
56
56
  [constants_1.CLI_VERSION]: version,
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@sap/cli-core",
3
- "version": "2024.3.0",
3
+ "version": "2024.4.0",
4
4
  "description": "Command-Line Interface (CLI) Core Module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "SAP SE",
7
7
  "homepage": "https://www.sap.com",
8
8
  "main": "index.js",
9
9
  "engines": {
10
- "node": "^20",
11
- "npm": "^10"
10
+ "node": "^18 || ^19 || ^20 || ^21",
11
+ "npm": "^9 || ^10"
12
12
  },
13
13
  "keywords": [
14
14
  "cli",
@@ -18,10 +18,10 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "ajv": "8.12.0",
21
- "axios": "1.6.4",
21
+ "axios": "1.6.5",
22
22
  "commander": "11.1.0",
23
23
  "compare-versions": "6.1.0",
24
- "config": "3.3.9",
24
+ "config": "3.3.10",
25
25
  "dotenv": "16.3.1",
26
26
  "fs-extra": "11.2.0",
27
27
  "https": "1.0.0",
package/utils/commands.js CHANGED
@@ -104,7 +104,7 @@ const buildCommand = async (topCommand, command) => {
104
104
  const comm = (0, exports.createCommand)(name);
105
105
  comm.description(description);
106
106
  comm.enablePositionalOptions();
107
- for (const option of options || []) {
107
+ for (const option of options ?? []) {
108
108
  // eslint-disable-next-line no-await-in-loop
109
109
  comm.addOption(await (0, exports.buildOption)(option));
110
110
  }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.init = void 0;
4
- const constants_1 = require("../../../constants");
5
- const discovery_1 = require("../../../discovery");
6
- const handler_1 = require("../../handler");
7
- const config_1 = require("../../../config");
8
- const core_1 = require("../../../config/core");
9
- const pre = () => {
10
- const config = (0, config_1.get)();
11
- (0, config_1.set)({
12
- options: {
13
- ...config.options,
14
- [constants_1.OPTION_OUTPUT.longName]: (0, discovery_1.getPathToDiscoveryDocument)(),
15
- },
16
- doNotStoreResult: true,
17
- });
18
- };
19
- const post = async () => {
20
- const config = (0, config_1.get)();
21
- await (0, discovery_1.addMetadata)({
22
- tenant: config.publicfqdn,
23
- addedAt: new Date().getTime(),
24
- });
25
- (0, discovery_1.clear)();
26
- const { options } = config;
27
- delete options[constants_1.OPTION_OUTPUT.longName];
28
- (0, config_1.set)({ options });
29
- };
30
- const init = async () => async () => {
31
- pre();
32
- await (await (0, handler_1.createFetchHandler)("GET", (0, core_1.getDiscoveryPath)())({}))();
33
- await post();
34
- };
35
- exports.init = init;
36
- const initCommand = {
37
- type: "command",
38
- command: "init",
39
- description: "initialize the local CLI cache",
40
- options: [],
41
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
42
- };
43
- exports.default = initCommand;