@sap/cli-core 2023.25.0 → 2024.2.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,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2024.2.0
9
+
10
+ ### Changed
11
+
12
+ - The required version of `npm` changes from `^9` to `^10`.
13
+
14
+ ## 2024.1.0
15
+
16
+ ### Fixed
17
+
18
+ - The `--browser` option introduced with version `2023.25.0` did not apply the default correctly in case the option `--browser` was not explicitly specified.
19
+
8
20
  ## 2023.25.0
9
21
 
10
22
  ### Added
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Command-Line Interface (CLI) Core Module.
4
4
 
5
- [![Node Version](https://img.shields.io/badge/node-18.15.0-brightgreen)](https://nodejs.org/dist/latest-v18.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fcli-core.svg)](https://badge.fury.io/js/@sap%2Fcli-core)
5
+ [![Node Version](https://img.shields.io/badge/node-20.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)
6
6
 
7
7
  ## Content
8
8
 
@@ -9,6 +9,7 @@ const utils_1 = require("../cache/secrets/utils");
9
9
  const utils_2 = require("../logger/utils");
10
10
  const utils_3 = require("../utils/utils");
11
11
  const utils_4 = require("./utils");
12
+ const openUtils_1 = require("../utils/openUtils");
12
13
  const getLogger = () => (0, logger_1.get)("commands.login");
13
14
  const verifyHost = async () => async () => {
14
15
  const logger = getLogger();
@@ -50,7 +51,11 @@ const loginCommand = {
50
51
  { ...constants_1.OPTION_CODE, hidden: false },
51
52
  { ...constants_1.OPTION_REFRESH_TOKEN, hidden: false },
52
53
  { ...constants_1.OPTION_SECRETS_FILE, hidden: false },
53
- { ...constants_1.OPTION_BROWSER, choices: utils_4.getBrowserChoices },
54
+ {
55
+ ...constants_1.OPTION_BROWSER,
56
+ choices: utils_4.getBrowserChoices,
57
+ default: openUtils_1.getDefaultBrowser,
58
+ },
54
59
  ]), (0, handler_1.createMandatoryOptionsHandler)(), verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
55
60
  };
56
61
  exports.default = loginCommand;
package/constants.d.ts CHANGED
@@ -5,7 +5,6 @@ export declare enum AuthenticationMethod {
5
5
  oauth = "oauth",
6
6
  passcode = "passcode"
7
7
  }
8
- export declare const DEFAULT_BROWSER = "browser";
9
8
  export declare const CLI_NAME = "cli-name";
10
9
  export declare const CLI_PACKAGE_NAME = "cli-package-name";
11
10
  export declare const CLI_DESCRIPTION = "cli-description";
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.DEFAULT_BROWSER = 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_PATH = 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)();
@@ -13,7 +13,6 @@ var AuthenticationMethod;
13
13
  AuthenticationMethod["oauth"] = "oauth";
14
14
  AuthenticationMethod["passcode"] = "passcode";
15
15
  })(AuthenticationMethod || (exports.AuthenticationMethod = AuthenticationMethod = {}));
16
- exports.DEFAULT_BROWSER = "browser";
17
16
  exports.CLI_NAME = "cli-name";
18
17
  exports.CLI_PACKAGE_NAME = "cli-package-name";
19
18
  exports.CLI_DESCRIPTION = "cli-description";
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@sap/cli-core",
3
- "version": "2023.25.0",
3
+ "version": "2024.2.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": "^18",
11
- "npm": "^9"
10
+ "node": "^20",
11
+ "npm": "^10"
12
12
  },
13
13
  "keywords": [
14
14
  "cli",
@@ -18,12 +18,12 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "ajv": "8.12.0",
21
- "axios": "1.6.0",
21
+ "axios": "1.6.2",
22
22
  "commander": "11.1.0",
23
23
  "compare-versions": "6.1.0",
24
24
  "config": "3.3.9",
25
25
  "dotenv": "16.3.1",
26
- "fs-extra": "11.1.1",
26
+ "fs-extra": "11.2.0",
27
27
  "https": "1.0.0",
28
28
  "https-proxy-agent": "7.0.2",
29
29
  "lodash": "4.17.21",
package/types.d.ts CHANGED
@@ -140,12 +140,13 @@ export type DiscoveryMetadata = {
140
140
  export type KeyValuePair = {
141
141
  [key: string]: any;
142
142
  };
143
+ export type DefaultFunction = () => Promise<string>;
143
144
  export type ChoicesFunction = () => Promise<Array<string>>;
144
145
  export type Choices = Array<string>;
145
146
  export type Option = {
146
147
  longName: string;
147
148
  description: string;
148
- default?: string;
149
+ default?: string | DefaultFunction;
149
150
  required?: boolean;
150
151
  choices?: Choices | ChoicesFunction;
151
152
  args?: Array<{
package/utils/commands.js CHANGED
@@ -81,8 +81,11 @@ const buildOption = async ({ longName, description, choices, required, default:
81
81
  : "";
82
82
  const option = new commander_1.Option(`-${shortFlag}, --${longName}${argStr}`, newDescr)
83
83
  .makeOptionMandatory(mandatory)
84
- .default(defaultValue)
85
84
  .hideHelp(!!hidden);
85
+ if (defaultValue) {
86
+ const defaultStr = typeof defaultValue === "function" ? await defaultValue() : defaultValue;
87
+ option.default(defaultStr);
88
+ }
86
89
  let choicesArr = [];
87
90
  if (choices) {
88
91
  choicesArr = typeof choices === "function" ? await choices() : choices;
@@ -1,3 +1,10 @@
1
+ import { AppName } from "open";
2
+ export type Browser = {
3
+ name: AppName;
4
+ app: string;
5
+ };
6
+ export declare function getSupportedBrowsers(): Array<Browser>;
7
+ export declare function getDefaultBrowser(): Promise<string>;
1
8
  export declare const openUrlInBrowser: (url: string, queryParameters?: {
2
9
  [key: string]: string;
3
10
  }) => Promise<void>;
@@ -1,16 +1,51 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.openUrlInBrowser = void 0;
7
- const open_1 = __importDefault(require("open"));
26
+ exports.openUrlInBrowser = exports.getDefaultBrowser = exports.getSupportedBrowsers = void 0;
27
+ const open_1 = __importStar(require("open"));
8
28
  const constants_1 = require("../constants");
9
29
  const options_1 = require("./options");
10
30
  const logger_1 = require("../logger");
11
31
  const getLogger = () => (0, logger_1.get)("utils.open");
32
+ function getSupportedBrowsers() {
33
+ return Object.entries(open_1.apps).map(([key, value]) => ({
34
+ name: key,
35
+ app: value,
36
+ }));
37
+ }
38
+ exports.getSupportedBrowsers = getSupportedBrowsers;
39
+ async function getDefaultBrowser() {
40
+ return getSupportedBrowsers()[0].name;
41
+ }
42
+ exports.getDefaultBrowser = getDefaultBrowser;
43
+ async function getBrowser() {
44
+ const browser = (0, options_1.getOptionValueFromConfig)(constants_1.OPTION_BROWSER, await getDefaultBrowser());
45
+ return open_1.apps[browser];
46
+ }
12
47
  const openUrlInBrowser = async (url, queryParameters = {}) => {
13
- const browser = (0, options_1.getOptionValueFromConfig)(constants_1.OPTION_BROWSER, constants_1.DEFAULT_BROWSER);
48
+ const browser = await getBrowser();
14
49
  const u = new URL(url);
15
50
  for (const [key, value] of Object.entries(queryParameters)) {
16
51
  u.searchParams.append(key, value);