@sap-ux/axios-extension 1.17.6 → 1.17.7
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.
|
@@ -49,17 +49,18 @@ class V4CatalogService extends base_1.CatalogService {
|
|
|
49
49
|
? V4_RECOMMENDED_ENTITYSET
|
|
50
50
|
: V4_CLASSIC_ENTITYSET;
|
|
51
51
|
}
|
|
52
|
-
const params =
|
|
53
|
-
$count
|
|
54
|
-
$expand
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
const params = new URLSearchParams([
|
|
53
|
+
['$count', 'true'],
|
|
54
|
+
['$expand', `DefaultSystem($expand=${this.entitySet})`]
|
|
55
|
+
]);
|
|
56
|
+
const response = await this.get('/ServiceGroups', { params }, true);
|
|
57
|
+
let serviceGroupResponseOdata = response.odata();
|
|
58
|
+
const serviceGroups = serviceGroupResponseOdata.value;
|
|
59
|
+
// Page by using the backends nextLink search parameters for the next request
|
|
60
|
+
while (serviceGroupResponseOdata['@odata.nextLink']) {
|
|
61
|
+
const nextLink = new URL(serviceGroupResponseOdata['@odata.nextLink'], this.defaults.baseURL);
|
|
62
|
+
serviceGroupResponseOdata = (await this.get('/ServiceGroups', { params: nextLink.searchParams }, true)).odata();
|
|
63
|
+
serviceGroups.push(...serviceGroupResponseOdata.value);
|
|
63
64
|
}
|
|
64
65
|
// check if the service responded with an odata error
|
|
65
66
|
if (odata_request_error_1.ODataRequestError.containsError(serviceGroups)) {
|
|
@@ -55,8 +55,9 @@ export declare class ODataService extends Axios implements ODataServiceExtension
|
|
|
55
55
|
*
|
|
56
56
|
* @param url relative url to the service
|
|
57
57
|
* @param config additional axios request config
|
|
58
|
+
* @param includeV4ControlData include the control information that is not part of the odata value but may be required e.g. `@odata.nextLink`
|
|
58
59
|
* @returns a response enhanced with an OData parse method
|
|
59
60
|
*/
|
|
60
|
-
get<T = any, R = ODataResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D
|
|
61
|
+
get<T = any, R = ODataResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, includeV4ControlData?: boolean): Promise<R>;
|
|
61
62
|
}
|
|
62
63
|
//# sourceMappingURL=odata-service.d.ts.map
|
|
@@ -13,9 +13,10 @@ var ODataVersion;
|
|
|
13
13
|
/**
|
|
14
14
|
* Parse a JSON based OData response and extract the content from the OData structure.
|
|
15
15
|
*
|
|
16
|
+
* @param includeV4ControlData unless specified only the value of the parsed v4 odata response is returned, otherwise all additional data is included e.g. `@odata.nextLink`
|
|
16
17
|
* @returns an object of the provided type
|
|
17
18
|
*/
|
|
18
|
-
function parseODataResponse() {
|
|
19
|
+
function parseODataResponse(includeV4ControlData = false) {
|
|
19
20
|
const data = this.data ? JSON.parse(this.data) : {};
|
|
20
21
|
if (data.d) {
|
|
21
22
|
// v2
|
|
@@ -26,7 +27,7 @@ function parseODataResponse() {
|
|
|
26
27
|
return data.d;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
else if (data['@odata.context']) {
|
|
30
|
+
else if (!includeV4ControlData && data['@odata.context']) {
|
|
30
31
|
// v4
|
|
31
32
|
if (data.value) {
|
|
32
33
|
return data.value;
|
|
@@ -82,19 +83,26 @@ class ODataService extends axios_1.Axios {
|
|
|
82
83
|
*
|
|
83
84
|
* @param url relative url to the service
|
|
84
85
|
* @param config additional axios request config
|
|
86
|
+
* @param includeV4ControlData include the control information that is not part of the odata value but may be required e.g. `@odata.nextLink`
|
|
85
87
|
* @returns a response enhanced with an OData parse method
|
|
86
88
|
*/
|
|
87
|
-
async get(url, config = {}) {
|
|
88
|
-
//
|
|
89
|
-
if (config.params
|
|
89
|
+
async get(url, config = {}, includeV4ControlData = false) {
|
|
90
|
+
// AxiosRequestConfig `params` property supports plain object or URLSearchParams
|
|
91
|
+
if (config.params instanceof URLSearchParams && !config.params.has('$format') && !config.headers?.Accept) {
|
|
92
|
+
config.params.set('$format', 'json');
|
|
93
|
+
config.headers = config.headers ?? {};
|
|
94
|
+
config.headers.Accept = 'application/json';
|
|
95
|
+
}
|
|
96
|
+
else if (config.params?.['$format'] === undefined && !config.headers?.Accept) {
|
|
90
97
|
config.params = config.params ?? {};
|
|
91
98
|
config.params['$format'] = 'json';
|
|
92
99
|
config.headers = config.headers ?? {};
|
|
93
100
|
config.headers.Accept = 'application/json';
|
|
94
101
|
}
|
|
95
102
|
const response = await super.get(url, config);
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
const contentType = response.headers['content-type'] ?? response.headers['Content-Type'];
|
|
104
|
+
if (response.data && (contentType?.includes('application/json') || config.params?.['$format'] === 'json')) {
|
|
105
|
+
response.odata = parseODataResponse.bind(response, includeV4ControlData);
|
|
98
106
|
}
|
|
99
107
|
return response;
|
|
100
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/axios-extension",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.7",
|
|
4
4
|
"description": "Extension of the Axios module adding convenience methods to interact with SAP systems especially with OData services.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"nock": "13.4.0",
|
|
35
35
|
"supertest": "6.3.3",
|
|
36
36
|
"@types/proxy-from-env": "1.0.1",
|
|
37
|
-
"@sap-ux/project-access": "1.28.
|
|
37
|
+
"@sap-ux/project-access": "1.28.9"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"dist",
|