@sap-ux/backend-proxy-middleware 0.7.20 → 0.7.22

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/README.md CHANGED
@@ -16,8 +16,9 @@ It can be used either with the `ui5 serve` or the `fiori run` commands.
16
16
  | `pathReplace` | `string` optional | If provided then the path will be replaced with this value before forwarding |
17
17
  | `client` | `string` optional | sap-client parameter |
18
18
  | `scp` | `boolean` optional | If set to true the proxy will execute the required OAuth routine for the ABAP environment on SAP BTP |
19
- | `apiHub` | `boolean` optional | If set to true then the proxy will connect to the SAP API Business Hub
20
- | `proxy` | `string` optional | If set then it will override the proxy settings from node.
19
+ | `apiHub` | `boolean` optional | If set to true then the proxy will connect to the SAP API Business Hub |
20
+ | `proxy` | `string` optional | If set then it will override the proxy settings from node. |
21
+ | `authenticationType` | `string` optional | Authentication mechanism to be used in VSCode. Currently supported: "ReentranceTicket" |
21
22
 
22
23
  Additional optional experimental property `bsp` (type `string`): The BSP property is only needed for the FLP Embedded Flow. The property refers to the BSP Application Name. In that case, we need to redirect the manifest.appdescr request to the local manifest.json in order to overwrite the deployed application with the local one.
23
24
 
@@ -96,7 +96,7 @@ export declare function enhanceConfigsForDestination(proxyOptions: Options & {
96
96
  */
97
97
  export declare function enhanceConfigForSystem(proxyOptions: Options & {
98
98
  headers: object;
99
- }, system: BackendSystem, oAuthRequired: boolean | undefined, tokenChangedCallback: (refreshToken?: string) => void): Promise<void>;
99
+ }, system: BackendSystem | undefined, oAuthRequired: boolean | undefined, tokenChangedCallback: (refreshToken?: string) => void): Promise<void>;
100
100
  /**
101
101
  * Generate options for the proxy middleware based on the input.
102
102
  *
@@ -241,7 +241,7 @@ exports.enhanceConfigsForDestination = enhanceConfigsForDestination;
241
241
  function enhanceConfigForSystem(proxyOptions, system, oAuthRequired, tokenChangedCallback) {
242
242
  return __awaiter(this, void 0, void 0, function* () {
243
243
  if (oAuthRequired) {
244
- if (system.serviceKeys) {
244
+ if (system === null || system === void 0 ? void 0 : system.serviceKeys) {
245
245
  const provider = (0, axios_extension_1.createForAbapOnCloud)({
246
246
  environment: axios_extension_1.AbapCloudEnvironment.Standalone,
247
247
  service: system.serviceKeys,
@@ -255,16 +255,19 @@ function enhanceConfigForSystem(proxyOptions, system, oAuthRequired, tokenChange
255
255
  throw new Error('Cannot connect to ABAP Environment on BTP without service keys.');
256
256
  }
257
257
  }
258
- else if (system.authenticationType === store_1.AuthenticationType.ReentranceTicket) {
258
+ else if ((system === null || system === void 0 ? void 0 : system.authenticationType) === store_1.AuthenticationType.ReentranceTicket) {
259
259
  const provider = (0, axios_extension_1.createForAbapOnCloud)({
260
+ ignoreCertErrors: proxyOptions.secure === false,
260
261
  environment: axios_extension_1.AbapCloudEnvironment.EmbeddedSteampunk,
261
262
  url: system.url
262
263
  });
263
264
  // sending a request to the backend to get cookies
264
- yield provider.getAtoInfo();
265
- proxyOptions.headers['cookie'] = provider.cookies.toString();
265
+ const ato = yield provider.getAtoInfo();
266
+ if (ato) {
267
+ proxyOptions.headers['cookie'] = provider.cookies.toString();
268
+ }
266
269
  }
267
- else if (system.username && system.password) {
270
+ else if ((system === null || system === void 0 ? void 0 : system.username) && system.password) {
268
271
  proxyOptions.auth = `${system.username}:${system.password}`;
269
272
  }
270
273
  });
@@ -279,7 +282,7 @@ exports.enhanceConfigForSystem = enhanceConfigForSystem;
279
282
  * @returns options for the http-proxy-middleware
280
283
  */
281
284
  function generateProxyMiddlewareOptions(backend, options = {}, logger = new logger_1.ToolsLogger()) {
282
- var _a;
285
+ var _a, _b;
283
286
  return __awaiter(this, void 0, void 0, function* () {
284
287
  // add required options
285
288
  const proxyOptions = Object.assign(Object.assign(Object.assign({ headers: {} }, exports.ProxyEventHandlers), { onError: (err, req, res, target) => {
@@ -303,22 +306,24 @@ function generateProxyMiddlewareOptions(backend, options = {}, logger = new logg
303
306
  // check if system credentials are stored in the store
304
307
  try {
305
308
  const systemStore = yield (0, store_1.getService)({ logger, entityName: 'system' });
306
- const system = yield systemStore.read(new store_1.BackendSystemKey({ url: localBackend.url, client: localBackend.client }));
307
- if (system) {
308
- yield enhanceConfigForSystem(proxyOptions, system, backend.scp, (refreshToken, accessToken) => {
309
- if (refreshToken) {
310
- logger.info('Updating refresh token for: ' + localBackend.url);
311
- systemStore.write(Object.assign(Object.assign({}, system), { refreshToken })).catch((error) => logger.error(error));
312
- }
313
- if (accessToken) {
314
- logger.info('Setting access token');
315
- proxyOptions.headers['authorization'] = `bearer ${accessToken}`;
316
- }
317
- else {
318
- logger.warn('Setting of access token failed.');
319
- }
320
- });
321
- }
309
+ const system = (_b = (yield systemStore.read(new store_1.BackendSystemKey({ url: localBackend.url, client: localBackend.client })))) !== null && _b !== void 0 ? _b : {
310
+ name: '<unknown>',
311
+ url: localBackend.url,
312
+ authenticationType: localBackend.authenticationType
313
+ };
314
+ yield enhanceConfigForSystem(proxyOptions, system, backend.scp, (refreshToken, accessToken) => {
315
+ if (refreshToken) {
316
+ logger.info('Updating refresh token for: ' + localBackend.url);
317
+ systemStore.write(Object.assign(Object.assign({}, system), { refreshToken })).catch((error) => logger.error(error));
318
+ }
319
+ if (accessToken) {
320
+ logger.info('Setting access token');
321
+ proxyOptions.headers['authorization'] = `bearer ${accessToken}`;
322
+ }
323
+ else {
324
+ logger.warn('Setting of access token failed.');
325
+ }
326
+ });
322
327
  }
323
328
  catch (error) {
324
329
  logger.warn('Accessing the credentials store failed.');
@@ -1,3 +1,4 @@
1
+ import type { AuthenticationType } from '@sap-ux/store';
1
2
  import type { Options } from 'http-proxy-middleware';
2
3
  export interface BaseBackendConfig {
3
4
  /**
@@ -16,6 +17,10 @@ export interface BaseBackendConfig {
16
17
  * If set to true the proxy will execute the required OAuth routine for the ABAP environment on SAP BTP
17
18
  */
18
19
  scp?: boolean;
20
+ /**
21
+ * Authentication mechanism to be used. Currently supported: "ReentranceTicket"
22
+ */
23
+ authenticationType?: AuthenticationType;
19
24
  /**
20
25
  * If set to true then the proxy will connect to the SAP API Business Hub
21
26
  */
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%3Abackend-proxy-middleware"
11
11
  },
12
- "version": "0.7.20",
12
+ "version": "0.7.22",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "i18next": "20.6.1",
29
29
  "prompts": "2.4.2",
30
30
  "proxy-from-env": "1.1.0",
31
- "@sap-ux/axios-extension": "1.11.4",
31
+ "@sap-ux/axios-extension": "1.11.6",
32
32
  "@sap-ux/btp-utils": "0.14.3",
33
33
  "@sap-ux/logger": "0.5.1",
34
34
  "@sap-ux/store": "0.5.0"