@sap-cloud-sdk/openapi 2.0.0-20211112070725.0 → 2.0.0-20211112143400.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.
|
@@ -1,68 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
3
|
exports.OpenApiRequestBuilder = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
4
|
+
const util_1 = require("@sap-cloud-sdk/util");
|
|
5
|
+
const connectivity_1 = require("@sap-cloud-sdk/connectivity");
|
|
6
|
+
const http_client_1 = require("@sap-cloud-sdk/http-client");
|
|
54
7
|
/**
|
|
55
8
|
* Request builder for OpenAPI requests.
|
|
56
9
|
* @typeParam ResponseT - Type of the response for the request.
|
|
57
10
|
*/
|
|
58
|
-
|
|
11
|
+
class OpenApiRequestBuilder {
|
|
59
12
|
/**
|
|
60
13
|
* Create an instance of `OpenApiRequestBuilder`.
|
|
61
14
|
* @param method - HTTP method of the request to be built.
|
|
62
15
|
* @param pathPattern - Path for the request containing path parameter references as in the OpenAPI specification.
|
|
63
16
|
* @param parameters - Query parameters and or body to pass to the request.
|
|
64
17
|
*/
|
|
65
|
-
|
|
18
|
+
constructor(method, pathPattern, parameters) {
|
|
66
19
|
this.method = method;
|
|
67
20
|
this.pathPattern = pathPattern;
|
|
68
21
|
this.parameters = parameters;
|
|
@@ -70,22 +23,20 @@ var OpenApiRequestBuilder = /** @class */ (function () {
|
|
|
70
23
|
this.customRequestConfiguration = {};
|
|
71
24
|
this._fetchCsrfToken = true;
|
|
72
25
|
}
|
|
73
|
-
|
|
26
|
+
static isPlaceholder(pathPart) {
|
|
74
27
|
return /^\{.+\}$/.test(pathPart);
|
|
75
|
-
}
|
|
28
|
+
}
|
|
76
29
|
/**
|
|
77
30
|
* Add custom headers to the request. If a header field with the given name already exists it is overwritten.
|
|
78
31
|
* @param headers - Key-value pairs denoting additional custom headers.
|
|
79
32
|
* @returns The request builder itself, to facilitate method chaining.
|
|
80
33
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var key = _a[0], value = _a[1];
|
|
85
|
-
_this.customHeaders[key.toLowerCase()] = value;
|
|
34
|
+
addCustomHeaders(headers) {
|
|
35
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
36
|
+
this.customHeaders[key.toLowerCase()] = value;
|
|
86
37
|
});
|
|
87
38
|
return this;
|
|
88
|
-
}
|
|
39
|
+
}
|
|
89
40
|
/**
|
|
90
41
|
* Add custom request configuration to the request. Typically, this is used when specifying response type for downloading files.
|
|
91
42
|
* If the custom request configuration contains keys in this list [[defaultDisallowedKeys]], they will be removed.
|
|
@@ -93,91 +44,76 @@ var OpenApiRequestBuilder = /** @class */ (function () {
|
|
|
93
44
|
* @param requestConfiguration - Key-value pairs denoting additional custom request configuration options to be set in the request.
|
|
94
45
|
* @returns The request builder itself, to facilitate method chaining.
|
|
95
46
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var key = _a[0], value = _a[1];
|
|
100
|
-
_this.customRequestConfiguration[key] = value;
|
|
47
|
+
addCustomRequestConfiguration(requestConfiguration) {
|
|
48
|
+
Object.entries(requestConfiguration).forEach(([key, value]) => {
|
|
49
|
+
this.customRequestConfiguration[key] = value;
|
|
101
50
|
});
|
|
102
51
|
return this;
|
|
103
|
-
}
|
|
52
|
+
}
|
|
104
53
|
/**
|
|
105
54
|
* Skip fetching csrf token for this request, which is typically useful when the csrf token is not required.
|
|
106
55
|
* @returns The request builder itself, to facilitate method chaining.
|
|
107
56
|
*/
|
|
108
|
-
|
|
57
|
+
skipCsrfTokenFetching() {
|
|
109
58
|
this._fetchCsrfToken = false;
|
|
110
59
|
return this;
|
|
111
|
-
}
|
|
60
|
+
}
|
|
112
61
|
/**
|
|
113
62
|
* Execute request and get a raw HttpResponse, including all information about the HTTP response.
|
|
114
63
|
* This especially comes in handy, when you need to access the headers or status code of the response.
|
|
115
64
|
* @param destination - Destination or DestinationFetchOptions to execute the request against.
|
|
116
65
|
* @returns A promise resolving to an HttpResponse.
|
|
117
66
|
*/
|
|
118
|
-
|
|
67
|
+
async executeRaw(destination) {
|
|
119
68
|
var _a, _b;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
};
|
|
69
|
+
const fetchCsrfToken = this._fetchCsrfToken &&
|
|
70
|
+
['post', 'put', 'patch', 'delete'].includes(this.method.toLowerCase());
|
|
71
|
+
const resolvedDestination = await (0, connectivity_1.useOrFetchDestination)(destination);
|
|
72
|
+
if ((0, util_1.isNullish)(destination)) {
|
|
73
|
+
throw Error((0, connectivity_1.noDestinationErrorMessage)(destination));
|
|
74
|
+
}
|
|
75
|
+
return (0, http_client_1.executeHttpRequest)(resolvedDestination, {
|
|
76
|
+
...(0, http_client_1.filterCustomRequestConfig)(this.customRequestConfiguration),
|
|
77
|
+
method: this.method,
|
|
78
|
+
url: this.getPath(),
|
|
79
|
+
headers: this.customHeaders,
|
|
80
|
+
params: (_a = this.parameters) === null || _a === void 0 ? void 0 : _a.queryParameters,
|
|
81
|
+
data: (_b = this.parameters) === null || _b === void 0 ? void 0 : _b.body
|
|
82
|
+
},
|
|
83
|
+
// TODO: Remove this in v 2.0, when this becomes true becomes the default
|
|
84
|
+
{ fetchCsrfToken });
|
|
85
|
+
}
|
|
140
86
|
/**
|
|
141
87
|
* Execute request and get the response data. Use this to conveniently access the data of a service without technical information about the response.
|
|
142
88
|
* @param destination - Destination or DestinationFetchOptions to execute the request against.
|
|
143
89
|
* @returns A promise resolving to the requested return type.
|
|
144
90
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (isAxiosResponse(response)) {
|
|
154
|
-
return [2 /*return*/, response.data];
|
|
155
|
-
}
|
|
156
|
-
throw new Error('Could not access response data. Response was not an axios response.');
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
OpenApiRequestBuilder.prototype.getPath = function () {
|
|
91
|
+
async execute(destination) {
|
|
92
|
+
const response = await this.executeRaw(destination);
|
|
93
|
+
if (isAxiosResponse(response)) {
|
|
94
|
+
return response.data;
|
|
95
|
+
}
|
|
96
|
+
throw new Error('Could not access response data. Response was not an axios response.');
|
|
97
|
+
}
|
|
98
|
+
getPath() {
|
|
162
99
|
var _a;
|
|
163
|
-
|
|
164
|
-
|
|
100
|
+
const pathParameters = ((_a = this.parameters) === null || _a === void 0 ? void 0 : _a.pathParameters) || {};
|
|
101
|
+
const pathParts = this.pathPattern.split('/');
|
|
165
102
|
return pathParts
|
|
166
|
-
.map(
|
|
103
|
+
.map(part => {
|
|
167
104
|
if (OpenApiRequestBuilder.isPlaceholder(part)) {
|
|
168
|
-
|
|
169
|
-
|
|
105
|
+
const paramName = part.slice(1, -1);
|
|
106
|
+
const paramValue = pathParameters[paramName];
|
|
170
107
|
if (!paramValue) {
|
|
171
|
-
throw new Error(
|
|
108
|
+
throw new Error(`Cannot execute request, no path parameter provided for '${paramName}'.`);
|
|
172
109
|
}
|
|
173
110
|
return encodeURIComponent(paramValue);
|
|
174
111
|
}
|
|
175
112
|
return part;
|
|
176
113
|
})
|
|
177
114
|
.join('/');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
181
117
|
exports.OpenApiRequestBuilder = OpenApiRequestBuilder;
|
|
182
118
|
function isAxiosResponse(val) {
|
|
183
119
|
return 'data' in val;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-request-builder.js","sourceRoot":"","sources":["../src/openapi-request-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openapi-request-builder.js","sourceRoot":"","sources":["../src/openapi-request-builder.ts"],"names":[],"mappings":";;;AAEA,8CAAgD;AAChD,8DAKqC;AACrC,4DAKoC;AAEpC;;;GAGG;AACH,MAAa,qBAAqB;IAShC;;;;;OAKG;IACH,YACS,MAAc,EACb,WAAmB,EACnB,UAAqC;QAFtC,WAAM,GAAN,MAAM,CAAQ;QACb,gBAAW,GAAX,WAAW,CAAQ;QACnB,eAAU,GAAV,UAAU,CAA2B;QAbvC,kBAAa,GAA2B,EAAE,CAAC;QAC3C,+BAA0B,GAA2B,EAAE,CAAC;QACxD,oBAAe,GAAG,IAAI,CAAC;IAY5B,CAAC;IAlBI,MAAM,CAAC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C,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AA/HD,sDA+HC;AASD,SAAS,eAAe,CAAC,GAAQ;IAC/B,OAAO,MAAM,IAAI,GAAG,CAAC;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-cloud-sdk/openapi",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-20211112143400.0+ba75a92c",
|
|
4
4
|
"description": "SAP Cloud SDK for JavaScript openapi",
|
|
5
5
|
"homepage": "https://sap.github.io/cloud-sdk/docs/js/overview-cloud-sdk-for-javascript",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"check:dependencies": "depcheck ."
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@sap-cloud-sdk/analytics": "^2.0.0-
|
|
36
|
-
"@sap-cloud-sdk/connectivity": "^2.0.0-
|
|
37
|
-
"@sap-cloud-sdk/http-client": "^2.0.0-
|
|
38
|
-
"@sap-cloud-sdk/util": "^2.0.0-
|
|
35
|
+
"@sap-cloud-sdk/analytics": "^2.0.0-20211112143400.0+ba75a92c",
|
|
36
|
+
"@sap-cloud-sdk/connectivity": "^2.0.0-20211112143400.0+ba75a92c",
|
|
37
|
+
"@sap-cloud-sdk/http-client": "^2.0.0-20211112143400.0+ba75a92c",
|
|
38
|
+
"@sap-cloud-sdk/util": "^2.0.0-20211112143400.0+ba75a92c",
|
|
39
39
|
"axios": "^0.24.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"nock": "^13.0.11"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "ba75a92cd3151982e2e49fbac778941bcd967b23"
|
|
45
45
|
}
|