@sap-ux/system-access 0.3.27 → 0.3.29

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.
@@ -1,13 +1,20 @@
1
1
  import type { Logger } from '@sap-ux/logger';
2
- import type { AbapTarget, UrlAbapTarget } from '../types';
2
+ import type { AbapTarget, DestinationAbapTarget, UrlAbapTarget } from '../types';
3
3
  import type { AbapServiceProvider, AxiosRequestConfig, ProviderConfiguration } from '@sap-ux/axios-extension';
4
4
  /**
5
- * Check if it is a url or destination target.
5
+ * Check if it is a url target.
6
6
  *
7
7
  * @param target target configuration
8
- * @returns true is it is a UrlAbapTarget
8
+ * @returns true if it is a UrlAbapTarget
9
9
  */
10
10
  export declare function isUrlTarget(target: AbapTarget): target is UrlAbapTarget;
11
+ /**
12
+ * Check if it is a destination target.
13
+ *
14
+ * @param target target configuration
15
+ * @returns true if it is a DestinationAbapTarget
16
+ */
17
+ export declare function isDestinationTarget(target: AbapTarget): target is DestinationAbapTarget;
11
18
  /**
12
19
  * Create an instance of an ABAP service provider connected to the given target configuration.
13
20
  *
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.createAbapServiceProvider = exports.isUrlTarget = void 0;
15
+ exports.createAbapServiceProvider = exports.isDestinationTarget = exports.isUrlTarget = void 0;
16
16
  const axios_extension_1 = require("@sap-ux/axios-extension");
17
17
  const credentials_1 = require("./credentials");
18
18
  const btp_utils_1 = require("@sap-ux/btp-utils");
@@ -21,15 +21,25 @@ const prompts_2 = __importDefault(require("prompts"));
21
21
  const fs_1 = require("fs");
22
22
  const store_1 = require("@sap-ux/store");
23
23
  /**
24
- * Check if it is a url or destination target.
24
+ * Check if it is a url target.
25
25
  *
26
26
  * @param target target configuration
27
- * @returns true is it is a UrlAbapTarget
27
+ * @returns true if it is a UrlAbapTarget
28
28
  */
29
29
  function isUrlTarget(target) {
30
30
  return target.url !== undefined;
31
31
  }
32
32
  exports.isUrlTarget = isUrlTarget;
33
+ /**
34
+ * Check if it is a destination target.
35
+ *
36
+ * @param target target configuration
37
+ * @returns true if it is a DestinationAbapTarget
38
+ */
39
+ function isDestinationTarget(target) {
40
+ return target.destination !== undefined;
41
+ }
42
+ exports.isDestinationTarget = isDestinationTarget;
33
43
  /**
34
44
  * Enhance axios options and create a service provider instance for an ABAP Cloud system.
35
45
  *
@@ -102,6 +112,43 @@ function createAbapOnPremServiceProvider(options, target, prompt, logger) {
102
112
  return (0, axios_extension_1.createForAbap)(options);
103
113
  });
104
114
  }
115
+ /**
116
+ * Enhance axios options and create a service provider instance for a destination.
117
+ *
118
+ * @param options predefined axios options
119
+ * @param target url target configuration
120
+ * @param prompt - prompt the user for missing information
121
+ * @returns an ABAPServiceProvider instance
122
+ */
123
+ function createAbapDestinationServiceProvider(options, target, prompt) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ // Need additional properties to determine the type of destination we are dealing with
126
+ const destinations = yield (0, btp_utils_1.listDestinations)();
127
+ const destination = destinations === null || destinations === void 0 ? void 0 : destinations[target.destination];
128
+ if (!destination) {
129
+ throw new Error(`Destination ${target.destination} not found on subaccount`);
130
+ }
131
+ const provider = (0, axios_extension_1.createForDestination)(options, destination);
132
+ // if prompting is enabled, check if the destination works or basic auth is required
133
+ if (prompt) {
134
+ const id = provider.interceptors.response.use(undefined, (error) => __awaiter(this, void 0, void 0, function* () {
135
+ var _a;
136
+ provider.interceptors.response.eject(id);
137
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
138
+ const credentials = yield (0, credentials_1.getCredentialsWithPrompts)();
139
+ provider.defaults.auth = credentials;
140
+ process.env.FIORI_TOOLS_USER = credentials.username;
141
+ process.env.FIORI_TOOLS_PASSWORD = credentials.password;
142
+ return provider.request(error.config);
143
+ }
144
+ else {
145
+ throw error;
146
+ }
147
+ }));
148
+ }
149
+ return provider;
150
+ });
151
+ }
105
152
  /**
106
153
  * Create an instance of an ABAP service provider connected to the given target configuration.
107
154
  *
@@ -116,15 +163,9 @@ function createAbapServiceProvider(target, requestOptions, prompt, logger) {
116
163
  return __awaiter(this, void 0, void 0, function* () {
117
164
  let provider;
118
165
  const options = Object.assign({ params: (_a = target.params) !== null && _a !== void 0 ? _a : {} }, requestOptions);
119
- // Destination only supported on Business Application studio
120
- if ((0, btp_utils_1.isAppStudio)() && target.destination) {
121
- // Need additional properties to determine the type of destination we are dealing with
122
- const destinations = yield (0, btp_utils_1.listDestinations)();
123
- const destination = destinations === null || destinations === void 0 ? void 0 : destinations[target.destination];
124
- if (!destination) {
125
- throw new Error(`Destination ${target.destination} not found on subaccount`);
126
- }
127
- provider = (0, axios_extension_1.createForDestination)(options, destination);
166
+ // Destination only supported in Business Application Studio
167
+ if ((0, btp_utils_1.isAppStudio)() && isDestinationTarget(target)) {
168
+ provider = yield createAbapDestinationServiceProvider(options, target, prompt);
128
169
  }
129
170
  else if (isUrlTarget(target)) {
130
171
  if (target.scp) {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Asystem-access"
11
11
  },
12
- "version": "0.3.27",
12
+ "version": "0.3.29",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -23,15 +23,16 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "prompts": "2.4.2",
26
- "@sap-ux/axios-extension": "1.12.3",
26
+ "@sap-ux/axios-extension": "1.12.4",
27
27
  "@sap-ux/btp-utils": "0.14.4",
28
28
  "@sap-ux/logger": "0.5.1",
29
29
  "@sap-ux/store": "0.5.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/prompts": "2.4.4",
33
+ "nock": "13.4.0",
33
34
  "rimraf": "5.0.5",
34
- "@sap-ux/project-access": "1.19.14"
35
+ "@sap-ux/project-access": "1.20.0"
35
36
  },
36
37
  "engines": {
37
38
  "node": ">=18.x"