@sap-ux/axios-extension 1.0.3 → 1.1.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.
@@ -12,6 +12,10 @@ import { AdtService } from './adt-catalog/services';
12
12
  export declare class AbapServiceProvider extends ServiceProvider {
13
13
  s4Cloud: boolean | undefined;
14
14
  protected atoSettings: AtoSettings;
15
+ /**
16
+ * Maintain the public facing URL which is required for destination related flows
17
+ */
18
+ protected _publicUrl: string;
15
19
  /**
16
20
  * Get the name of the currently logged in user. This is the basic implementation that could be overwritten by subclasses.
17
21
  * The function returns a promise because it may be required to fetch the information from the backend.
@@ -31,6 +35,18 @@ export declare class AbapServiceProvider extends ServiceProvider {
31
35
  * @returns ABAP Transport Organizer settings
32
36
  */
33
37
  getAtoInfo(): Promise<AtoSettings>;
38
+ /**
39
+ * Set the public facing URL, typically used for a destination related flows.
40
+ *
41
+ * @param host
42
+ */
43
+ set publicUrl(host: string);
44
+ /**
45
+ * Retrieve the public facing URL, default to Axios base URL if not configured.
46
+ *
47
+ * @returns string Axios baseUrl if public URL is not configured by a destination
48
+ */
49
+ get publicUrl(): string;
34
50
  /**
35
51
  * Detect if the given configuration points to an S/4HANA Cloud system.
36
52
  *
@@ -74,7 +90,7 @@ export declare class AbapServiceProvider extends ServiceProvider {
74
90
  *
75
91
  * @example
76
92
  * ```ts
77
- * const transportRequestSerivce = abapServiceProvider.getAdtService<TransportRequestService>(TransportRequestService);
93
+ * const transportRequestService = abapServiceProvider.getAdtService<TransportRequestService>(TransportRequestService);
78
94
  * ```
79
95
  * @param adtServiceSubclass Subclass of class AdtService, type is specified by using AdtService class constructor signature.
80
96
  * @returns Subclass type of class AdtService
@@ -69,6 +69,22 @@ class AbapServiceProvider extends service_provider_1.ServiceProvider {
69
69
  return this.atoSettings;
70
70
  });
71
71
  }
72
+ /**
73
+ * Set the public facing URL, typically used for a destination related flows.
74
+ *
75
+ * @param host
76
+ */
77
+ set publicUrl(host) {
78
+ this._publicUrl = host;
79
+ }
80
+ /**
81
+ * Retrieve the public facing URL, default to Axios base URL if not configured.
82
+ *
83
+ * @returns string Axios baseUrl if public URL is not configured by a destination
84
+ */
85
+ get publicUrl() {
86
+ return this._publicUrl || this.defaults.baseURL;
87
+ }
72
88
  /**
73
89
  * Detect if the given configuration points to an S/4HANA Cloud system.
74
90
  *
@@ -171,7 +187,7 @@ class AbapServiceProvider extends service_provider_1.ServiceProvider {
171
187
  *
172
188
  * @example
173
189
  * ```ts
174
- * const transportRequestSerivce = abapServiceProvider.getAdtService<TransportRequestService>(TransportRequestService);
190
+ * const transportRequestService = abapServiceProvider.getAdtService<TransportRequestService>(TransportRequestService);
175
191
  * ```
176
192
  * @param adtServiceSubclass Subclass of class AdtService, type is specified by using AdtService class constructor signature.
177
193
  * @returns Subclass type of class AdtService
@@ -67,12 +67,15 @@ export declare const abapUrlReplaceMap: Map<RegExp, string>;
67
67
  */
68
68
  export declare class Ui5AbapRepositoryService extends ODataService {
69
69
  static readonly PATH = "/sap/opu/odata/UI5/ABAP_REPOSITORY_SRV";
70
+ private readonly publicUrl;
70
71
  /**
71
72
  * Extension of the base constructor to set preferred response format if not provided by caller.
72
73
  *
73
- * @param config optional base configuration for Axios
74
+ * @param config optional base configuration for Axios appended with optional fields
74
75
  */
75
- constructor(config?: AxiosRequestConfig);
76
+ constructor(config?: AxiosRequestConfig & {
77
+ publicUrl?: string;
78
+ });
76
79
  /**
77
80
  * Get information about a deployed application. Returns undefined if the application cannot be found.
78
81
  *
@@ -42,7 +42,7 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
42
42
  /**
43
43
  * Extension of the base constructor to set preferred response format if not provided by caller.
44
44
  *
45
- * @param config optional base configuration for Axios
45
+ * @param config optional base configuration for Axios appended with optional fields
46
46
  */
47
47
  constructor(config) {
48
48
  var _a, _b;
@@ -51,6 +51,7 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
51
51
  // @see https://axios-http.com/docs/config_defaults
52
52
  config.headers['Accept'] = (_b = config.headers['Accept']) !== null && _b !== void 0 ? _b : 'application/json,application/xml,text/plain,*/*';
53
53
  super(config);
54
+ this.publicUrl = config.publicUrl || this.defaults.baseURL;
54
55
  }
55
56
  /**
56
57
  * Get information about a deployed application. Returns undefined if the application cannot be found.
@@ -65,6 +66,7 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
65
66
  return response.odata();
66
67
  }
67
68
  catch (error) {
69
+ this.log.debug(`Retrieving application ${app}, error found ${error}`);
68
70
  return undefined;
69
71
  }
70
72
  });
@@ -146,7 +148,7 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
146
148
  * @returns url to be used in the browser.
147
149
  */
148
150
  getAbapFrontendUrl() {
149
- const url = new URL(this.defaults.baseURL);
151
+ const url = new URL(this.publicUrl);
150
152
  exports.abapUrlReplaceMap.forEach((value, key) => {
151
153
  url.hostname = url.hostname.replace(key, value);
152
154
  });
@@ -205,8 +207,8 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
205
207
  return (`<entry xmlns="http://www.w3.org/2005/Atom"` +
206
208
  ` xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"` +
207
209
  ` xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"` +
208
- ` xml:base="${this.defaults.baseURL}">` +
209
- ` <id>${this.defaults.baseURL}/Repositories('${escapedName}')</id>` +
210
+ ` xml:base="${this.publicUrl}">` +
211
+ ` <id>${this.publicUrl}/Repositories('${escapedName}')</id>` +
210
212
  ` <title type="text">Repositories('${escapedName}')</title>` +
211
213
  ` <updated>${time}</updated>` +
212
214
  ` <category term="/UI5/ABAP_REPOSITORY_SRV.Repository" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>` +
@@ -313,8 +315,17 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
313
315
  var _a;
314
316
  this.log.error(error.message);
315
317
  if ((0, odata_request_error_1.isAxiosError)(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)) {
316
- if (error.response.data['error']) {
317
- (0, message_1.prettyPrintError)({ error: error.response.data['error'], host, log: this.log });
318
+ let responseData = error.response.data;
319
+ if (typeof error.response.data === 'string') {
320
+ try {
321
+ responseData = JSON.parse(error.response.data);
322
+ }
323
+ catch (_b) {
324
+ // Not much we can do!
325
+ }
326
+ }
327
+ if (responseData === null || responseData === void 0 ? void 0 : responseData['error']) {
328
+ (0, message_1.prettyPrintError)({ error: responseData['error'], host, log: this.log });
318
329
  }
319
330
  else {
320
331
  this.log.error(error.response.data);
@@ -44,12 +44,18 @@ export declare class ServiceProvider extends Axios implements ServiceProviderExt
44
44
  */
45
45
  protected generateServiceConfig(path: string): AxiosRequestConfig;
46
46
  /**
47
- * Create a service instance for the given path and service class.
47
+ * Create a service instance for the given path, service class and public URL.
48
48
  *
49
49
  * @param path path of the service relative to the service provider
50
50
  * @param ServiceClass class type to be used to create an instance
51
51
  * @returns a service instance
52
52
  */
53
53
  protected createService<T extends Service>(path: string, ServiceClass: any): T;
54
+ /**
55
+ * Retrieve the public URL exposing the ABAP UI application.
56
+ *
57
+ * @returns string Axios Base URL
58
+ */
59
+ protected get publicUrl(): string;
54
60
  }
55
61
  //# sourceMappingURL=service-provider.d.ts.map
@@ -39,18 +39,26 @@ class ServiceProvider extends axios_1.Axios {
39
39
  return Object.assign(Object.assign({}, config), { baseURL: this.defaults.baseURL + path, headers: (_b = (_a = this.defaults.headers) === null || _a === void 0 ? void 0 : _a.common) !== null && _b !== void 0 ? _b : {} });
40
40
  }
41
41
  /**
42
- * Create a service instance for the given path and service class.
42
+ * Create a service instance for the given path, service class and public URL.
43
43
  *
44
44
  * @param path path of the service relative to the service provider
45
45
  * @param ServiceClass class type to be used to create an instance
46
46
  * @returns a service instance
47
47
  */
48
48
  createService(path, ServiceClass) {
49
- const service = new ServiceClass(this.generateServiceConfig(path));
49
+ const service = new ServiceClass(Object.assign(Object.assign({}, this.generateServiceConfig(path)), { publicUrl: this.publicUrl }));
50
50
  service.log = this.log;
51
51
  service.interceptors = this.interceptors;
52
52
  return service;
53
53
  }
54
+ /**
55
+ * Retrieve the public URL exposing the ABAP UI application.
56
+ *
57
+ * @returns string Axios Base URL
58
+ */
59
+ get publicUrl() {
60
+ return this.defaults.baseURL;
61
+ }
54
62
  }
55
63
  exports.ServiceProvider = ServiceProvider;
56
64
  //# sourceMappingURL=service-provider.js.map
package/dist/factory.js CHANGED
@@ -157,6 +157,8 @@ function createForDestination(options, destination, destinationServiceInstance)
157
157
  let provider;
158
158
  if ((0, btp_utils_1.isAbapSystem)(destination)) {
159
159
  provider = createInstance(abap_1.AbapServiceProvider, providerConfig);
160
+ // For an ABAP destination flow, need to show the destination host URL property instead of the BAS host URL i.e. https://mydest.dest
161
+ provider.publicUrl = destination.Host;
160
162
  }
161
163
  else {
162
164
  provider = createInstance(service_provider_1.ServiceProvider, providerConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/axios-extension",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Extension of the Axios module adding convinience methods to interact with SAP systems especially with OData services.",
5
5
  "repository": {
6
6
  "type": "git",