@sap-ux/axios-extension 1.0.1 → 1.0.3

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.adoc CHANGED
@@ -27,11 +27,11 @@ The generic OData service simplifies the access to the service metadata as well
27
27
  #### Catalog Service
28
28
  Simplified consumption of the SAP catalog service useful for fetching annotations.
29
29
 
30
- #### ABAP UI5 Respository Service
30
+ #### ABAP UI5 Repository Service
31
31
  Allows deployment of applications to the UI5 ABAP Repository as well as checking deployed applications.
32
32
 
33
33
  #### App Index Service
34
- A class respresenting the app index service allowing to search applications deployed on an ABAP system.
34
+ A class representing the app index service allowing to search applications deployed on an ABAP system.
35
35
 
36
36
  #### Layered Repository Service
37
37
  Allows deployment of adaptation projects.
@@ -64,8 +64,8 @@ const provider = createForAbap({
64
64
  baseURL: 'https://sap.example',
65
65
  params: { 'sap-client': client }
66
66
  });
67
- const transportRequestSerivce = provider.getAdtService<TransportRequestService>(TransportRequestService);
68
- const newTrNumber = await transportRequestSerivce.createTransportRequest({
67
+ const transportRequestService = provider.getAdtService<TransportRequestService>(TransportRequestService);
68
+ const newTrNumber = await transportRequestService.createTransportRequest({
69
69
  packageName: 'Z_PACKAGE',
70
70
  ui5AppName: 'zappname',
71
71
  description: 'A new transport request number for deployment'
@@ -101,8 +101,8 @@ class AbapServiceProvider extends service_provider_1.ServiceProvider {
101
101
  */
102
102
  getAdtCatalogService() {
103
103
  if (!this.services[adt_catalog_service_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH]) {
104
- const adtCatalogSerivce = this.createService(adt_catalog_service_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH, adt_catalog_service_1.AdtCatalogService);
105
- this.services[adt_catalog_service_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH] = adtCatalogSerivce;
104
+ const adtCatalogService = this.createService(adt_catalog_service_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH, adt_catalog_service_1.AdtCatalogService);
105
+ this.services[adt_catalog_service_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH] = adtCatalogService;
106
106
  }
107
107
  return this.services[adt_catalog_service_1.AdtCatalogService.ADT_DISCOVERY_SERVICE_PATH];
108
108
  }
@@ -181,8 +181,8 @@ class AbapServiceProvider extends service_provider_1.ServiceProvider {
181
181
  const subclassName = adtServiceSubclass.name;
182
182
  if (!this.services[subclassName]) {
183
183
  // Retrieve ADT schema for the specific input AdtService subclass
184
- const adtCatalogSerivce = this.getAdtCatalogService();
185
- const adtSchema = yield adtCatalogSerivce.getServiceDefinition(adtServiceSubclass.getAdtCatagory());
184
+ const adtCatalogService = this.getAdtCatalogService();
185
+ const adtSchema = yield adtCatalogService.getServiceDefinition(adtServiceSubclass.getAdtCatagory());
186
186
  // No ADT schema available neither locally nor from service query.
187
187
  if (!adtSchema) {
188
188
  return null;
@@ -7,7 +7,7 @@ export interface App {
7
7
  }
8
8
  export type AppIndex = Partial<App>[];
9
9
  /**
10
- * A class respresenting the app index service allowing to search applications deployed on an ABAP system.
10
+ * A class representing the app index service allowing to search applications deployed on an ABAP system.
11
11
  */
12
12
  export declare abstract class AppIndexService extends Axios implements Service {
13
13
  static readonly PATH = "/sap/bc/ui2/app_index";
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AppIndexService = void 0;
13
13
  const axios_1 = require("axios");
14
14
  /**
15
- * A class respresenting the app index service allowing to search applications deployed on an ABAP system.
15
+ * A class representing the app index service allowing to search applications deployed on an ABAP system.
16
16
  */
17
17
  class AppIndexService extends axios_1.Axios {
18
18
  /**
@@ -80,15 +80,24 @@ class V2CatalogService extends base_1.CatalogService {
80
80
  */
81
81
  findService({ title, path }) {
82
82
  return __awaiter(this, void 0, void 0, function* () {
83
+ let version = 1;
83
84
  if (!title) {
84
- title = path.replace(/\/$/, '').split('/').pop().toUpperCase();
85
+ const titleWithParameters = path.replace(/\/$/, '').split('/').pop().split(';');
86
+ title = titleWithParameters[0].toUpperCase();
85
87
  if (!title) {
86
88
  throw new Error(`Cannot determine service title from path: ${path}`);
87
89
  }
90
+ const segParams = titleWithParameters.slice(1);
91
+ segParams.forEach((parameter) => {
92
+ const [key, value] = parameter.split('=');
93
+ if (key === 'v') {
94
+ version = parseInt(value, 10);
95
+ }
96
+ });
88
97
  }
89
98
  const params = {
90
99
  $format: 'json',
91
- $filter: `Title eq '${title}'`
100
+ $filter: `Title eq '${title}' and TechnicalServiceVersion eq ${version}`
92
101
  };
93
102
  const response = yield this.get(`/${this.entitySet}`, { params });
94
103
  const services = response.odata();
@@ -2,6 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prettyPrintTimeInMs = exports.prettyPrintError = exports.prettyPrintMessage = void 0;
4
4
  const url_1 = require("url");
5
+ /**
6
+ *
7
+ * @param severity
8
+ * @param msg
9
+ * @param log
10
+ * @param error
11
+ */
12
+ function logLevel(severity, msg, log, error = false) {
13
+ if (severity) {
14
+ severity = severity.toLowerCase();
15
+ if (severity === 'success') {
16
+ log.info(msg);
17
+ }
18
+ else {
19
+ if (severity === 'warning') {
20
+ severity = 'warn';
21
+ }
22
+ log[severity](msg);
23
+ }
24
+ }
25
+ else {
26
+ error ? log.error(msg) : log.info(msg);
27
+ }
28
+ }
5
29
  /**
6
30
  * Log a Gateway response.
7
31
  *
@@ -57,7 +81,7 @@ function prettyPrintError({ error, log, host }) {
57
81
  if (error.innererror) {
58
82
  (error.innererror.errordetails || []).forEach((entry) => {
59
83
  if (!entry.message.startsWith('<![CDATA')) {
60
- log.error(entry.message);
84
+ logLevel(entry.severity, entry.message, log, true);
61
85
  }
62
86
  logFullURL({ host, path: error['longtext_url'], log });
63
87
  });
@@ -88,16 +88,16 @@ export declare class Ui5AbapRepositoryService extends ODataService {
88
88
  * @param config.bsp BSP configuration
89
89
  * @param config.testMode if set to true, all requests will be sent, the service checks them, but no actual deployment will happen
90
90
  * @param config.safeMode if set then the SafeMode url parameter will be set. SafeMode is by default active, to activate provide false
91
- * @returns the Axios response object for futher processing
91
+ * @returns the Axios response object for further processing
92
92
  */
93
93
  deploy({ archive, bsp, testMode, safeMode }: DeployConfig): Promise<AxiosResponse>;
94
94
  /**
95
95
  * Undeploy an existing app.
96
96
  *
97
- * @param config undeployment config
97
+ * @param config undeploy config
98
98
  * @param config.bsp BSP configuration
99
99
  * @param config.testMode if set to true, all requests will be sent, the service checks them, but no actual deployment will happen
100
- * @returns the Axios response object for futher processing or undefined if no request is sent
100
+ * @returns the Axios response object for further processing or undefined if no request is sent
101
101
  */
102
102
  undeploy({ bsp, testMode }: UndeployConfig): Promise<AxiosResponse | undefined>;
103
103
  /**
@@ -111,8 +111,8 @@ export declare class Ui5AbapRepositoryService extends ODataService {
111
111
  *
112
112
  * @param transport optional transport request id
113
113
  * @param testMode optional url parameter to enable test mode
114
- * @param safeMode optional url paramater to disable the safe model (safemode=false)
115
- * @returns the Axios response object for futher processing
114
+ * @param safeMode optional url parameter to disable the safe model (safemode=false)
115
+ * @returns the Axios response object for further processing
116
116
  */
117
117
  protected createConfig(transport?: string, testMode?: boolean, safeMode?: boolean): AxiosRequestConfig;
118
118
  /**
@@ -133,16 +133,16 @@ export declare class Ui5AbapRepositoryService extends ODataService {
133
133
  * @param payload request payload
134
134
  * @param config additional request config
135
135
  * @param tryCount number of attempted deploys (sometimes a repo request fails with a known timeout issue, so we retry)
136
- * @returns the Axios response object for futher processing
136
+ * @returns the Axios response object for further processing
137
137
  */
138
138
  protected updateRepoRequest(isExisting: boolean, appName: string, payload: string, config: AxiosRequestConfig, tryCount?: number): Promise<AxiosResponse | undefined>;
139
139
  /**
140
- * Send a request to the backed to delete an application.
140
+ * Send a request to the backend to delete an application.
141
141
  *
142
142
  * @param appName application name
143
143
  * @param config additional request config
144
144
  * @param tryCount number of attempted deploys (sometimes a repo request fails with a known timeout issue, so we retry)
145
- * @returns the Axios response object for futher processing
145
+ * @returns the Axios response object for further processing
146
146
  */
147
147
  protected deleteRepoRequest(appName: string, config: AxiosRequestConfig, tryCount?: number): Promise<AxiosResponse>;
148
148
  /**
@@ -77,7 +77,7 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
77
77
  * @param config.bsp BSP configuration
78
78
  * @param config.testMode if set to true, all requests will be sent, the service checks them, but no actual deployment will happen
79
79
  * @param config.safeMode if set then the SafeMode url parameter will be set. SafeMode is by default active, to activate provide false
80
- * @returns the Axios response object for futher processing
80
+ * @returns the Axios response object for further processing
81
81
  */
82
82
  deploy({ archive, bsp, testMode = false, safeMode }) {
83
83
  var _a, _b;
@@ -110,10 +110,10 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
110
110
  /**
111
111
  * Undeploy an existing app.
112
112
  *
113
- * @param config undeployment config
113
+ * @param config undeploy config
114
114
  * @param config.bsp BSP configuration
115
115
  * @param config.testMode if set to true, all requests will be sent, the service checks them, but no actual deployment will happen
116
- * @returns the Axios response object for futher processing or undefined if no request is sent
116
+ * @returns the Axios response object for further processing or undefined if no request is sent
117
117
  */
118
118
  undeploy({ bsp, testMode = false }) {
119
119
  var _a;
@@ -157,8 +157,8 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
157
157
  *
158
158
  * @param transport optional transport request id
159
159
  * @param testMode optional url parameter to enable test mode
160
- * @param safeMode optional url paramater to disable the safe model (safemode=false)
161
- * @returns the Axios response object for futher processing
160
+ * @param safeMode optional url parameter to disable the safe model (safemode=false)
161
+ * @returns the Axios response object for further processing
162
162
  */
163
163
  createConfig(transport, testMode, safeMode) {
164
164
  const headers = {
@@ -230,10 +230,10 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
230
230
  * @param payload request payload
231
231
  * @param config additional request config
232
232
  * @param tryCount number of attempted deploys (sometimes a repo request fails with a known timeout issue, so we retry)
233
- * @returns the Axios response object for futher processing
233
+ * @returns the Axios response object for further processing
234
234
  */
235
235
  updateRepoRequest(isExisting, appName, payload, config, tryCount = 1) {
236
- var _a;
236
+ var _a, _b;
237
237
  return __awaiter(this, void 0, void 0, function* () {
238
238
  try {
239
239
  // Was the app deployed after the first failed attempt?
@@ -246,6 +246,7 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
246
246
  return Promise.resolve(undefined);
247
247
  }
248
248
  else {
249
+ this.log.info(`${appName} found on target system: ${isExisting}`);
249
250
  const response = isExisting
250
251
  ? yield this.put(`/Repositories('${encodeURIComponent(appName)}')`, payload, config)
251
252
  : yield this.post('/Repositories', payload, config);
@@ -260,6 +261,10 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
260
261
  }
261
262
  return this.updateRepoRequest(isExisting, appName, payload, config, tryCount + 1);
262
263
  }
264
+ else if ((_b = config === null || config === void 0 ? void 0 : config.params) === null || _b === void 0 ? void 0 : _b.TestMode) {
265
+ // TestMode returns HTTP 403 but includes details of the uploaded files and request
266
+ return error.response;
267
+ }
263
268
  else {
264
269
  throw error;
265
270
  }
@@ -267,12 +272,12 @@ class Ui5AbapRepositoryService extends odata_service_1.ODataService {
267
272
  });
268
273
  }
269
274
  /**
270
- * Send a request to the backed to delete an application.
275
+ * Send a request to the backend to delete an application.
271
276
  *
272
277
  * @param appName application name
273
278
  * @param config additional request config
274
279
  * @param tryCount number of attempted deploys (sometimes a repo request fails with a known timeout issue, so we retry)
275
- * @returns the Axios response object for futher processing
280
+ * @returns the Axios response object for further processing
276
281
  */
277
282
  deleteRepoRequest(appName, config, tryCount = 1) {
278
283
  var _a;
@@ -114,7 +114,7 @@ function isHtmlLoginForm(response) {
114
114
  }
115
115
  /**
116
116
  * @param contentTypeHeader contents of Content-Type header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type)
117
- * @param responseData data receievd in HTTP response. This is used to infer the Content-Type, if the header is missing or ambiguous
117
+ * @param responseData data received in HTTP response. This is used to infer the Content-Type, if the header is missing or ambiguous
118
118
  * @returns content type
119
119
  */
120
120
  function getContentType(contentTypeHeader, responseData) {
@@ -164,11 +164,14 @@ function attachConnectionHandler(provider) {
164
164
  return response;
165
165
  }
166
166
  }, (error) => {
167
- var _a, _b;
167
+ var _a;
168
168
  // remember xsrf token if provided even on error
169
- if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b[CSRF.ResponseHeaderName]) {
170
- provider.defaults.headers.common[CSRF.RequestHeaderName] =
171
- error.response.headers[CSRF.ResponseHeaderName];
169
+ if (error.response) {
170
+ if ((_a = error.response.headers) === null || _a === void 0 ? void 0 : _a[CSRF.ResponseHeaderName]) {
171
+ provider.defaults.headers.common[CSRF.RequestHeaderName] =
172
+ error.response.headers[CSRF.ResponseHeaderName];
173
+ }
174
+ provider.cookies.setCookies(error.response);
172
175
  }
173
176
  throw error;
174
177
  });
package/dist/factory.js CHANGED
@@ -47,7 +47,7 @@ function createInstance(ProviderType, config) {
47
47
  delete providerConfig.ignoreCertErrors;
48
48
  providerConfig.withCredentials = (providerConfig === null || providerConfig === void 0 ? void 0 : providerConfig.auth) && Object.keys(providerConfig.auth).length > 0;
49
49
  /**
50
- * Make axios throw an error for 4xx errors as well.
50
+ * Make axios throw an error for 4xx errors.
51
51
  *
52
52
  * @param status - http response status
53
53
  * @returns success (true) or error (false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/axios-extension",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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",