@kontent-ai/core-sdk 10.1.1 → 10.2.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.
- package/dist/cjs/helpers/header.helper.d.ts +13 -13
- package/dist/cjs/helpers/header.helper.js +22 -22
- package/dist/cjs/helpers/headers-helper.d.ts +3 -3
- package/dist/cjs/helpers/headers-helper.js +14 -14
- package/dist/cjs/helpers/index.d.ts +4 -5
- package/dist/cjs/helpers/index.js +20 -21
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/helpers/retry-helper.d.ts +37 -37
- package/dist/cjs/helpers/retry-helper.js +148 -148
- package/dist/cjs/helpers/url.helper.d.ts +10 -10
- package/dist/cjs/helpers/url.helper.js +26 -26
- package/dist/cjs/http/http.debugger.d.ts +6 -6
- package/dist/cjs/http/http.debugger.js +22 -22
- package/dist/cjs/http/http.functions.d.ts +11 -11
- package/dist/cjs/http/http.functions.js +260 -260
- package/dist/cjs/http/http.models.d.ts +73 -73
- package/dist/cjs/http/http.models.js +2 -2
- package/dist/cjs/http/http.service.d.ts +19 -19
- package/dist/cjs/http/http.service.js +56 -56
- package/dist/cjs/http/ihttp.service.d.ts +9 -9
- package/dist/cjs/http/ihttp.service.js +2 -2
- package/dist/cjs/http/index.d.ts +6 -6
- package/dist/cjs/http/index.js +22 -22
- package/dist/cjs/http/test-http.service.d.ts +17 -17
- package/dist/cjs/http/test-http.service.js +44 -44
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +20 -20
- package/dist/cjs/models/index.d.ts +3 -3
- package/dist/cjs/models/index.js +19 -19
- package/dist/cjs/models/isdk-info.d.ts +14 -14
- package/dist/cjs/models/isdk-info.js +2 -2
- package/dist/cjs/models/parameters.d.ts +16 -16
- package/dist/cjs/models/parameters.js +28 -28
- package/dist/cjs/models/parameters.js.map +1 -1
- package/dist/cjs/models/url.models.d.ts +3 -3
- package/dist/cjs/models/url.models.js +2 -2
- package/dist/cjs/sdk-info.generated.d.ts +2 -2
- package/dist/cjs/sdk-info.generated.js +8 -8
- package/dist/es6/helpers/header.helper.d.ts +13 -13
- package/dist/es6/helpers/header.helper.js +18 -18
- package/dist/es6/helpers/headers-helper.d.ts +3 -3
- package/dist/es6/helpers/headers-helper.js +10 -10
- package/dist/es6/helpers/index.d.ts +4 -5
- package/dist/es6/helpers/index.js +4 -5
- package/dist/es6/helpers/index.js.map +1 -1
- package/dist/es6/helpers/retry-helper.d.ts +37 -37
- package/dist/es6/helpers/retry-helper.js +144 -144
- package/dist/es6/helpers/url.helper.d.ts +10 -10
- package/dist/es6/helpers/url.helper.js +22 -22
- package/dist/es6/http/http.debugger.d.ts +6 -6
- package/dist/es6/http/http.debugger.js +18 -18
- package/dist/es6/http/http.functions.d.ts +11 -11
- package/dist/es6/http/http.functions.js +251 -251
- package/dist/es6/http/http.models.d.ts +73 -73
- package/dist/es6/http/http.models.js +1 -1
- package/dist/es6/http/http.service.d.ts +19 -19
- package/dist/es6/http/http.service.js +52 -52
- package/dist/es6/http/ihttp.service.d.ts +9 -9
- package/dist/es6/http/ihttp.service.js +1 -1
- package/dist/es6/http/index.d.ts +6 -6
- package/dist/es6/http/index.js +6 -6
- package/dist/es6/http/test-http.service.d.ts +17 -17
- package/dist/es6/http/test-http.service.js +40 -40
- package/dist/es6/index.d.ts +3 -3
- package/dist/es6/index.js +4 -4
- package/dist/es6/models/index.d.ts +3 -3
- package/dist/es6/models/index.js +3 -3
- package/dist/es6/models/isdk-info.d.ts +14 -14
- package/dist/es6/models/isdk-info.js +1 -1
- package/dist/es6/models/parameters.d.ts +16 -16
- package/dist/es6/models/parameters.js +25 -25
- package/dist/es6/models/url.models.d.ts +3 -3
- package/dist/es6/models/url.models.js +1 -1
- package/dist/es6/sdk-info.generated.d.ts +2 -2
- package/dist/es6/sdk-info.generated.js +5 -5
- package/dist/esnext/helpers/header.helper.d.ts +13 -13
- package/dist/esnext/helpers/header.helper.js +18 -18
- package/dist/esnext/helpers/headers-helper.d.ts +3 -3
- package/dist/esnext/helpers/headers-helper.js +10 -10
- package/dist/esnext/helpers/index.d.ts +4 -5
- package/dist/esnext/helpers/index.js +4 -5
- package/dist/esnext/helpers/index.js.map +1 -1
- package/dist/esnext/helpers/retry-helper.d.ts +37 -37
- package/dist/esnext/helpers/retry-helper.js +144 -144
- package/dist/esnext/helpers/url.helper.d.ts +10 -10
- package/dist/esnext/helpers/url.helper.js +22 -22
- package/dist/esnext/http/http.debugger.d.ts +6 -6
- package/dist/esnext/http/http.debugger.js +18 -18
- package/dist/esnext/http/http.functions.d.ts +11 -11
- package/dist/esnext/http/http.functions.js +251 -251
- package/dist/esnext/http/http.models.d.ts +73 -73
- package/dist/esnext/http/http.models.js +1 -1
- package/dist/esnext/http/http.service.d.ts +19 -19
- package/dist/esnext/http/http.service.js +52 -52
- package/dist/esnext/http/ihttp.service.d.ts +9 -9
- package/dist/esnext/http/ihttp.service.js +1 -1
- package/dist/esnext/http/index.d.ts +6 -6
- package/dist/esnext/http/index.js +6 -6
- package/dist/esnext/http/test-http.service.d.ts +17 -17
- package/dist/esnext/http/test-http.service.js +40 -40
- package/dist/esnext/index.d.ts +3 -3
- package/dist/esnext/index.js +4 -4
- package/dist/esnext/models/index.d.ts +3 -3
- package/dist/esnext/models/index.js +3 -3
- package/dist/esnext/models/isdk-info.d.ts +14 -14
- package/dist/esnext/models/isdk-info.js +1 -1
- package/dist/esnext/models/parameters.d.ts +16 -16
- package/dist/esnext/models/parameters.js +25 -25
- package/dist/esnext/models/url.models.d.ts +3 -3
- package/dist/esnext/models/url.models.js +1 -1
- package/dist/esnext/sdk-info.generated.d.ts +2 -2
- package/dist/esnext/sdk-info.generated.js +5 -5
- package/dist/umd/kontent-core.umd.js +3431 -2740
- package/dist/umd/kontent-core.umd.js.map +1 -1
- package/dist/umd/kontent-core.umd.min.js +1 -1
- package/dist/umd/kontent-core.umd.min.js.map +1 -1
- package/dist/umd/report.json +1 -1
- package/dist/umd/report.min.json +1 -1
- package/dist/umd/stats.json +1185 -8545
- package/dist/umd/stats.min.json +1192 -8684
- package/lib/helpers/index.ts +0 -1
- package/lib/sdk-info.generated.ts +1 -1
- package/package.json +26 -25
- package/dist/cjs/helpers/enum.helper.d.ts +0 -8
- package/dist/cjs/helpers/enum.helper.js +0 -54
- package/dist/cjs/helpers/enum.helper.js.map +0 -1
- package/dist/es6/helpers/enum.helper.d.ts +0 -8
- package/dist/es6/helpers/enum.helper.js +0 -50
- package/dist/es6/helpers/enum.helper.js.map +0 -1
- package/dist/esnext/helpers/enum.helper.d.ts +0 -8
- package/dist/esnext/helpers/enum.helper.js +0 -50
- package/dist/esnext/helpers/enum.helper.js.map +0 -1
- package/lib/helpers/enum.helper.ts +0 -63
|
@@ -1,252 +1,252 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from 'axios';
|
|
11
|
-
import { extractHeadersFromAxiosResponse } from '../helpers/headers-helper';
|
|
12
|
-
import { httpDebugger } from './http.debugger';
|
|
13
|
-
import { retryHelper } from '../helpers/retry-helper';
|
|
14
|
-
export function getWithRetryAsync(instance, call, functionsConfig, options) {
|
|
15
|
-
var _a;
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
18
|
-
return yield runWithRetryAsync({
|
|
19
|
-
retryAttempt: 0,
|
|
20
|
-
url: call.url,
|
|
21
|
-
retryStrategy: retryStrategyOptions,
|
|
22
|
-
functionsConfig: functionsConfig,
|
|
23
|
-
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _b, _c;
|
|
25
|
-
httpDebugger.debugStartHttpRequest();
|
|
26
|
-
const axiosResponse = yield instance.get(call.url, {
|
|
27
|
-
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
28
|
-
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
29
|
-
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
30
|
-
});
|
|
31
|
-
const response = {
|
|
32
|
-
data: axiosResponse.data,
|
|
33
|
-
rawResponse: axiosResponse,
|
|
34
|
-
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
35
|
-
status: axiosResponse.status,
|
|
36
|
-
retryStrategy: {
|
|
37
|
-
options: retryStrategyOptions,
|
|
38
|
-
retryAttempts: retryAttempt
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
httpDebugger.debugSuccessHttpRequest();
|
|
42
|
-
return response;
|
|
43
|
-
})
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
export function postWithRetryAsync(instance, call, functionsConfig, options) {
|
|
48
|
-
var _a;
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
51
|
-
return yield runWithRetryAsync({
|
|
52
|
-
retryAttempt: 0,
|
|
53
|
-
url: call.url,
|
|
54
|
-
retryStrategy: retryStrategyOptions,
|
|
55
|
-
functionsConfig: functionsConfig,
|
|
56
|
-
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
var _b, _c;
|
|
58
|
-
httpDebugger.debugStartHttpRequest();
|
|
59
|
-
const axiosResponse = yield instance.post(call.url, call.body, {
|
|
60
|
-
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
61
|
-
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
62
|
-
// required for uploading large files
|
|
63
|
-
// https://github.com/axios/axios/issues/1362
|
|
64
|
-
maxContentLength: 'Infinity',
|
|
65
|
-
maxBodyLength: 'Infinity',
|
|
66
|
-
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
67
|
-
});
|
|
68
|
-
const response = {
|
|
69
|
-
data: axiosResponse.data,
|
|
70
|
-
rawResponse: axiosResponse,
|
|
71
|
-
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
72
|
-
status: axiosResponse.status,
|
|
73
|
-
retryStrategy: {
|
|
74
|
-
options: retryStrategyOptions,
|
|
75
|
-
retryAttempts: retryAttempt
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
httpDebugger.debugSuccessHttpRequest();
|
|
79
|
-
return response;
|
|
80
|
-
})
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
export function putWithRetryAsync(instance, call, functionsConfig, options) {
|
|
85
|
-
var _a;
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
88
|
-
return yield runWithRetryAsync({
|
|
89
|
-
retryAttempt: 0,
|
|
90
|
-
url: call.url,
|
|
91
|
-
retryStrategy: retryStrategyOptions,
|
|
92
|
-
functionsConfig: functionsConfig,
|
|
93
|
-
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
var _b, _c;
|
|
95
|
-
httpDebugger.debugStartHttpRequest();
|
|
96
|
-
const axiosResponse = yield instance.put(call.url, call.body, {
|
|
97
|
-
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
98
|
-
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
99
|
-
// required for uploading large files
|
|
100
|
-
// https://github.com/axios/axios/issues/1362
|
|
101
|
-
maxContentLength: 'Infinity',
|
|
102
|
-
maxBodyLength: 'Infinity',
|
|
103
|
-
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
104
|
-
});
|
|
105
|
-
const response = {
|
|
106
|
-
data: axiosResponse.data,
|
|
107
|
-
rawResponse: axiosResponse,
|
|
108
|
-
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
109
|
-
status: axiosResponse.status,
|
|
110
|
-
retryStrategy: {
|
|
111
|
-
options: retryStrategyOptions,
|
|
112
|
-
retryAttempts: retryAttempt
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
httpDebugger.debugSuccessHttpRequest();
|
|
116
|
-
return response;
|
|
117
|
-
})
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
export function patchWithRetryAsync(instance, call, functionsConfig, options) {
|
|
122
|
-
var _a;
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
125
|
-
return yield runWithRetryAsync({
|
|
126
|
-
retryAttempt: 0,
|
|
127
|
-
url: call.url,
|
|
128
|
-
retryStrategy: retryStrategyOptions,
|
|
129
|
-
functionsConfig: functionsConfig,
|
|
130
|
-
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
var _b, _c;
|
|
132
|
-
httpDebugger.debugStartHttpRequest();
|
|
133
|
-
const axiosResponse = yield instance.patch(call.url, call.body, {
|
|
134
|
-
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
135
|
-
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
136
|
-
// required for uploading large files
|
|
137
|
-
// https://github.com/axios/axios/issues/1362
|
|
138
|
-
maxContentLength: 'Infinity',
|
|
139
|
-
maxBodyLength: 'Infinity',
|
|
140
|
-
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
141
|
-
});
|
|
142
|
-
const response = {
|
|
143
|
-
data: axiosResponse.data,
|
|
144
|
-
rawResponse: axiosResponse,
|
|
145
|
-
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
146
|
-
status: axiosResponse.status,
|
|
147
|
-
retryStrategy: {
|
|
148
|
-
options: retryStrategyOptions,
|
|
149
|
-
retryAttempts: retryAttempt
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
httpDebugger.debugSuccessHttpRequest();
|
|
153
|
-
return response;
|
|
154
|
-
})
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
export function deleteWithRetryAsync(instance, call, functionsConfig, options) {
|
|
159
|
-
var _a;
|
|
160
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
162
|
-
return yield runWithRetryAsync({
|
|
163
|
-
retryAttempt: 0,
|
|
164
|
-
url: call.url,
|
|
165
|
-
retryStrategy: retryStrategyOptions,
|
|
166
|
-
functionsConfig: functionsConfig,
|
|
167
|
-
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
var _b, _c;
|
|
169
|
-
httpDebugger.debugStartHttpRequest();
|
|
170
|
-
const axiosResponse = yield instance.delete(call.url, {
|
|
171
|
-
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
172
|
-
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
173
|
-
// required for uploading large files
|
|
174
|
-
// https://github.com/axios/axios/issues/1362
|
|
175
|
-
maxContentLength: 'Infinity',
|
|
176
|
-
maxBodyLength: 'Infinity',
|
|
177
|
-
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
178
|
-
});
|
|
179
|
-
const response = {
|
|
180
|
-
data: axiosResponse.data,
|
|
181
|
-
rawResponse: axiosResponse,
|
|
182
|
-
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
183
|
-
status: axiosResponse.status,
|
|
184
|
-
retryStrategy: {
|
|
185
|
-
options: retryStrategyOptions,
|
|
186
|
-
retryAttempts: retryAttempt
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
httpDebugger.debugSuccessHttpRequest();
|
|
190
|
-
return response;
|
|
191
|
-
})
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
export function createCancelToken() {
|
|
196
|
-
let canceler;
|
|
197
|
-
const token = new axios.CancelToken((c) => {
|
|
198
|
-
// An executor function receives a cancel function as a parameter
|
|
199
|
-
canceler = c;
|
|
200
|
-
});
|
|
201
|
-
return {
|
|
202
|
-
cancel: (cancelMessage) => canceler(`${retryHelper.requestCancelledMessagePrefix}: ${cancelMessage !== null && cancelMessage !== void 0 ? cancelMessage : 'User cancel'}`),
|
|
203
|
-
token: token
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function runWithRetryAsync(data) {
|
|
207
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
-
try {
|
|
209
|
-
return yield data.call(data.retryAttempt);
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
const retryResult = retryHelper.getRetryErrorResult({
|
|
213
|
-
error: error,
|
|
214
|
-
retryAttempt: data.retryAttempt,
|
|
215
|
-
retryStrategy: data.retryStrategy
|
|
216
|
-
});
|
|
217
|
-
if (retryResult.canRetry) {
|
|
218
|
-
httpDebugger.debugRetryHttpRequest();
|
|
219
|
-
// wait time before retrying
|
|
220
|
-
yield new Promise((resolve) => setTimeout(resolve, retryResult.retryInMs));
|
|
221
|
-
// retry request
|
|
222
|
-
console.warn(`Retry attempt '${data.retryAttempt + 1}' from a maximum of '${retryResult.maxRetries}' retries. Request url: '${data.url}'`);
|
|
223
|
-
return yield runWithRetryAsync({
|
|
224
|
-
call: data.call,
|
|
225
|
-
retryStrategy: data.retryStrategy,
|
|
226
|
-
retryAttempt: data.retryAttempt + 1,
|
|
227
|
-
url: data.url,
|
|
228
|
-
functionsConfig: data.functionsConfig
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (data.functionsConfig.logErrorsToConsole) {
|
|
232
|
-
console.error(`Executing '${data.url}' failed. Request was retried '${data.retryAttempt}' times. `, error);
|
|
233
|
-
}
|
|
234
|
-
throw error;
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
function getHeadersJson(headers, addContentTypeHeader) {
|
|
239
|
-
const headerJson = {};
|
|
240
|
-
headers.forEach((header) => {
|
|
241
|
-
headerJson[header.header] = header.value;
|
|
242
|
-
});
|
|
243
|
-
if (addContentTypeHeader) {
|
|
244
|
-
// add default content type header if not present
|
|
245
|
-
const contentTypeHeader = headers.find((m) => m.header.toLowerCase() === 'Content-Type'.toLowerCase());
|
|
246
|
-
if (!contentTypeHeader) {
|
|
247
|
-
headerJson['Content-Type'] = 'application/json';
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return headerJson;
|
|
251
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import axios from 'axios';
|
|
11
|
+
import { extractHeadersFromAxiosResponse } from '../helpers/headers-helper';
|
|
12
|
+
import { httpDebugger } from './http.debugger';
|
|
13
|
+
import { retryHelper } from '../helpers/retry-helper';
|
|
14
|
+
export function getWithRetryAsync(instance, call, functionsConfig, options) {
|
|
15
|
+
var _a;
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
18
|
+
return yield runWithRetryAsync({
|
|
19
|
+
retryAttempt: 0,
|
|
20
|
+
url: call.url,
|
|
21
|
+
retryStrategy: retryStrategyOptions,
|
|
22
|
+
functionsConfig: functionsConfig,
|
|
23
|
+
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _b, _c;
|
|
25
|
+
httpDebugger.debugStartHttpRequest();
|
|
26
|
+
const axiosResponse = yield instance.get(call.url, {
|
|
27
|
+
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
28
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
29
|
+
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
30
|
+
});
|
|
31
|
+
const response = {
|
|
32
|
+
data: axiosResponse.data,
|
|
33
|
+
rawResponse: axiosResponse,
|
|
34
|
+
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
35
|
+
status: axiosResponse.status,
|
|
36
|
+
retryStrategy: {
|
|
37
|
+
options: retryStrategyOptions,
|
|
38
|
+
retryAttempts: retryAttempt
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
httpDebugger.debugSuccessHttpRequest();
|
|
42
|
+
return response;
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function postWithRetryAsync(instance, call, functionsConfig, options) {
|
|
48
|
+
var _a;
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
51
|
+
return yield runWithRetryAsync({
|
|
52
|
+
retryAttempt: 0,
|
|
53
|
+
url: call.url,
|
|
54
|
+
retryStrategy: retryStrategyOptions,
|
|
55
|
+
functionsConfig: functionsConfig,
|
|
56
|
+
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _b, _c;
|
|
58
|
+
httpDebugger.debugStartHttpRequest();
|
|
59
|
+
const axiosResponse = yield instance.post(call.url, call.body, {
|
|
60
|
+
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
61
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
62
|
+
// required for uploading large files
|
|
63
|
+
// https://github.com/axios/axios/issues/1362
|
|
64
|
+
maxContentLength: 'Infinity',
|
|
65
|
+
maxBodyLength: 'Infinity',
|
|
66
|
+
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
67
|
+
});
|
|
68
|
+
const response = {
|
|
69
|
+
data: axiosResponse.data,
|
|
70
|
+
rawResponse: axiosResponse,
|
|
71
|
+
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
72
|
+
status: axiosResponse.status,
|
|
73
|
+
retryStrategy: {
|
|
74
|
+
options: retryStrategyOptions,
|
|
75
|
+
retryAttempts: retryAttempt
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
httpDebugger.debugSuccessHttpRequest();
|
|
79
|
+
return response;
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export function putWithRetryAsync(instance, call, functionsConfig, options) {
|
|
85
|
+
var _a;
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
88
|
+
return yield runWithRetryAsync({
|
|
89
|
+
retryAttempt: 0,
|
|
90
|
+
url: call.url,
|
|
91
|
+
retryStrategy: retryStrategyOptions,
|
|
92
|
+
functionsConfig: functionsConfig,
|
|
93
|
+
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
var _b, _c;
|
|
95
|
+
httpDebugger.debugStartHttpRequest();
|
|
96
|
+
const axiosResponse = yield instance.put(call.url, call.body, {
|
|
97
|
+
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
98
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
99
|
+
// required for uploading large files
|
|
100
|
+
// https://github.com/axios/axios/issues/1362
|
|
101
|
+
maxContentLength: 'Infinity',
|
|
102
|
+
maxBodyLength: 'Infinity',
|
|
103
|
+
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
104
|
+
});
|
|
105
|
+
const response = {
|
|
106
|
+
data: axiosResponse.data,
|
|
107
|
+
rawResponse: axiosResponse,
|
|
108
|
+
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
109
|
+
status: axiosResponse.status,
|
|
110
|
+
retryStrategy: {
|
|
111
|
+
options: retryStrategyOptions,
|
|
112
|
+
retryAttempts: retryAttempt
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
httpDebugger.debugSuccessHttpRequest();
|
|
116
|
+
return response;
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export function patchWithRetryAsync(instance, call, functionsConfig, options) {
|
|
122
|
+
var _a;
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
125
|
+
return yield runWithRetryAsync({
|
|
126
|
+
retryAttempt: 0,
|
|
127
|
+
url: call.url,
|
|
128
|
+
retryStrategy: retryStrategyOptions,
|
|
129
|
+
functionsConfig: functionsConfig,
|
|
130
|
+
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
var _b, _c;
|
|
132
|
+
httpDebugger.debugStartHttpRequest();
|
|
133
|
+
const axiosResponse = yield instance.patch(call.url, call.body, {
|
|
134
|
+
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
135
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
136
|
+
// required for uploading large files
|
|
137
|
+
// https://github.com/axios/axios/issues/1362
|
|
138
|
+
maxContentLength: 'Infinity',
|
|
139
|
+
maxBodyLength: 'Infinity',
|
|
140
|
+
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
141
|
+
});
|
|
142
|
+
const response = {
|
|
143
|
+
data: axiosResponse.data,
|
|
144
|
+
rawResponse: axiosResponse,
|
|
145
|
+
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
146
|
+
status: axiosResponse.status,
|
|
147
|
+
retryStrategy: {
|
|
148
|
+
options: retryStrategyOptions,
|
|
149
|
+
retryAttempts: retryAttempt
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
httpDebugger.debugSuccessHttpRequest();
|
|
153
|
+
return response;
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export function deleteWithRetryAsync(instance, call, functionsConfig, options) {
|
|
159
|
+
var _a;
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const retryStrategyOptions = (_a = options === null || options === void 0 ? void 0 : options.retryStrategy) !== null && _a !== void 0 ? _a : retryHelper.defaultRetryStrategy;
|
|
162
|
+
return yield runWithRetryAsync({
|
|
163
|
+
retryAttempt: 0,
|
|
164
|
+
url: call.url,
|
|
165
|
+
retryStrategy: retryStrategyOptions,
|
|
166
|
+
functionsConfig: functionsConfig,
|
|
167
|
+
call: (retryAttempt) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
var _b, _c;
|
|
169
|
+
httpDebugger.debugStartHttpRequest();
|
|
170
|
+
const axiosResponse = yield instance.delete(call.url, {
|
|
171
|
+
headers: getHeadersJson((_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : [], false),
|
|
172
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
173
|
+
// required for uploading large files
|
|
174
|
+
// https://github.com/axios/axios/issues/1362
|
|
175
|
+
maxContentLength: 'Infinity',
|
|
176
|
+
maxBodyLength: 'Infinity',
|
|
177
|
+
cancelToken: (_c = options === null || options === void 0 ? void 0 : options.cancelToken) === null || _c === void 0 ? void 0 : _c.token
|
|
178
|
+
});
|
|
179
|
+
const response = {
|
|
180
|
+
data: axiosResponse.data,
|
|
181
|
+
rawResponse: axiosResponse,
|
|
182
|
+
headers: extractHeadersFromAxiosResponse(axiosResponse),
|
|
183
|
+
status: axiosResponse.status,
|
|
184
|
+
retryStrategy: {
|
|
185
|
+
options: retryStrategyOptions,
|
|
186
|
+
retryAttempts: retryAttempt
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
httpDebugger.debugSuccessHttpRequest();
|
|
190
|
+
return response;
|
|
191
|
+
})
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
export function createCancelToken() {
|
|
196
|
+
let canceler;
|
|
197
|
+
const token = new axios.CancelToken((c) => {
|
|
198
|
+
// An executor function receives a cancel function as a parameter
|
|
199
|
+
canceler = c;
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
cancel: (cancelMessage) => canceler(`${retryHelper.requestCancelledMessagePrefix}: ${cancelMessage !== null && cancelMessage !== void 0 ? cancelMessage : 'User cancel'}`),
|
|
203
|
+
token: token
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function runWithRetryAsync(data) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
try {
|
|
209
|
+
return yield data.call(data.retryAttempt);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
const retryResult = retryHelper.getRetryErrorResult({
|
|
213
|
+
error: error,
|
|
214
|
+
retryAttempt: data.retryAttempt,
|
|
215
|
+
retryStrategy: data.retryStrategy
|
|
216
|
+
});
|
|
217
|
+
if (retryResult.canRetry) {
|
|
218
|
+
httpDebugger.debugRetryHttpRequest();
|
|
219
|
+
// wait time before retrying
|
|
220
|
+
yield new Promise((resolve) => setTimeout(resolve, retryResult.retryInMs));
|
|
221
|
+
// retry request
|
|
222
|
+
console.warn(`Retry attempt '${data.retryAttempt + 1}' from a maximum of '${retryResult.maxRetries}' retries. Request url: '${data.url}'`);
|
|
223
|
+
return yield runWithRetryAsync({
|
|
224
|
+
call: data.call,
|
|
225
|
+
retryStrategy: data.retryStrategy,
|
|
226
|
+
retryAttempt: data.retryAttempt + 1,
|
|
227
|
+
url: data.url,
|
|
228
|
+
functionsConfig: data.functionsConfig
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (data.functionsConfig.logErrorsToConsole) {
|
|
232
|
+
console.error(`Executing '${data.url}' failed. Request was retried '${data.retryAttempt}' times. `, error);
|
|
233
|
+
}
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function getHeadersJson(headers, addContentTypeHeader) {
|
|
239
|
+
const headerJson = {};
|
|
240
|
+
headers.forEach((header) => {
|
|
241
|
+
headerJson[header.header] = header.value;
|
|
242
|
+
});
|
|
243
|
+
if (addContentTypeHeader) {
|
|
244
|
+
// add default content type header if not present
|
|
245
|
+
const contentTypeHeader = headers.find((m) => m.header.toLowerCase() === 'Content-Type'.toLowerCase());
|
|
246
|
+
if (!contentTypeHeader) {
|
|
247
|
+
headerJson['Content-Type'] = 'application/json';
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return headerJson;
|
|
251
|
+
}
|
|
252
252
|
//# sourceMappingURL=http.functions.js.map
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { ResponseType } from 'axios';
|
|
2
|
-
export interface IResponseRetryStrategyResult {
|
|
3
|
-
options: IRetryStrategyOptions;
|
|
4
|
-
retryAttempts: number;
|
|
5
|
-
}
|
|
6
|
-
export interface IResponse<TRawData> {
|
|
7
|
-
data: TRawData;
|
|
8
|
-
headers: IHeader[];
|
|
9
|
-
rawResponse: any;
|
|
10
|
-
status: number;
|
|
11
|
-
retryStrategy: IResponseRetryStrategyResult;
|
|
12
|
-
}
|
|
13
|
-
export interface IRetryStrategyOptions {
|
|
14
|
-
/**
|
|
15
|
-
* back-off interval between retries
|
|
16
|
-
*/
|
|
17
|
-
deltaBackoffMs?: number;
|
|
18
|
-
/**
|
|
19
|
-
* Maximum allowed number of attempts
|
|
20
|
-
*/
|
|
21
|
-
maxAttempts?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Indicates if jitter is added to retry
|
|
24
|
-
*/
|
|
25
|
-
addJitter?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Determines if error can be retried. There are errors that are never retried
|
|
28
|
-
* such as when request is cancelled or the response status is 404 and so on...
|
|
29
|
-
*/
|
|
30
|
-
canRetryError?: (error: any) => boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface IHttpQueryCall {
|
|
33
|
-
url: string;
|
|
34
|
-
}
|
|
35
|
-
export interface IHttpPostQueryCall extends IHttpQueryCall {
|
|
36
|
-
body: any;
|
|
37
|
-
}
|
|
38
|
-
export interface IHttpPutQueryCall extends IHttpQueryCall {
|
|
39
|
-
body: any;
|
|
40
|
-
}
|
|
41
|
-
export interface IHttpPatchQueryCall extends IHttpQueryCall {
|
|
42
|
-
body: any;
|
|
43
|
-
}
|
|
44
|
-
export interface IHttpDeleteQueryCall extends IHttpQueryCall {
|
|
45
|
-
}
|
|
46
|
-
export interface IHttpGetQueryCall extends IHttpQueryCall {
|
|
47
|
-
}
|
|
48
|
-
export interface IHttpCancelRequestToken<TCancelToken> {
|
|
49
|
-
token: TCancelToken;
|
|
50
|
-
cancel: (cancelMessage?: string) => void;
|
|
51
|
-
}
|
|
52
|
-
export interface IHttpQueryOptions<TCancelToken> {
|
|
53
|
-
/**
|
|
54
|
-
* retry strategy
|
|
55
|
-
*/
|
|
56
|
-
retryStrategy?: IRetryStrategyOptions;
|
|
57
|
-
/**
|
|
58
|
-
* Request headers
|
|
59
|
-
*/
|
|
60
|
-
headers?: IHeader[];
|
|
61
|
-
/**
|
|
62
|
-
* Response type
|
|
63
|
-
*/
|
|
64
|
-
responseType?: ResponseType;
|
|
65
|
-
/**
|
|
66
|
-
* Cancel token
|
|
67
|
-
*/
|
|
68
|
-
cancelToken?: IHttpCancelRequestToken<TCancelToken>;
|
|
69
|
-
}
|
|
70
|
-
export interface IHeader {
|
|
71
|
-
header: string;
|
|
72
|
-
value: string;
|
|
73
|
-
}
|
|
1
|
+
import { ResponseType } from 'axios';
|
|
2
|
+
export interface IResponseRetryStrategyResult {
|
|
3
|
+
options: IRetryStrategyOptions;
|
|
4
|
+
retryAttempts: number;
|
|
5
|
+
}
|
|
6
|
+
export interface IResponse<TRawData> {
|
|
7
|
+
data: TRawData;
|
|
8
|
+
headers: IHeader[];
|
|
9
|
+
rawResponse: any;
|
|
10
|
+
status: number;
|
|
11
|
+
retryStrategy: IResponseRetryStrategyResult;
|
|
12
|
+
}
|
|
13
|
+
export interface IRetryStrategyOptions {
|
|
14
|
+
/**
|
|
15
|
+
* back-off interval between retries
|
|
16
|
+
*/
|
|
17
|
+
deltaBackoffMs?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum allowed number of attempts
|
|
20
|
+
*/
|
|
21
|
+
maxAttempts?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Indicates if jitter is added to retry
|
|
24
|
+
*/
|
|
25
|
+
addJitter?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Determines if error can be retried. There are errors that are never retried
|
|
28
|
+
* such as when request is cancelled or the response status is 404 and so on...
|
|
29
|
+
*/
|
|
30
|
+
canRetryError?: (error: any) => boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface IHttpQueryCall {
|
|
33
|
+
url: string;
|
|
34
|
+
}
|
|
35
|
+
export interface IHttpPostQueryCall extends IHttpQueryCall {
|
|
36
|
+
body: any;
|
|
37
|
+
}
|
|
38
|
+
export interface IHttpPutQueryCall extends IHttpQueryCall {
|
|
39
|
+
body: any;
|
|
40
|
+
}
|
|
41
|
+
export interface IHttpPatchQueryCall extends IHttpQueryCall {
|
|
42
|
+
body: any;
|
|
43
|
+
}
|
|
44
|
+
export interface IHttpDeleteQueryCall extends IHttpQueryCall {
|
|
45
|
+
}
|
|
46
|
+
export interface IHttpGetQueryCall extends IHttpQueryCall {
|
|
47
|
+
}
|
|
48
|
+
export interface IHttpCancelRequestToken<TCancelToken> {
|
|
49
|
+
token: TCancelToken;
|
|
50
|
+
cancel: (cancelMessage?: string) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface IHttpQueryOptions<TCancelToken> {
|
|
53
|
+
/**
|
|
54
|
+
* retry strategy
|
|
55
|
+
*/
|
|
56
|
+
retryStrategy?: IRetryStrategyOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Request headers
|
|
59
|
+
*/
|
|
60
|
+
headers?: IHeader[];
|
|
61
|
+
/**
|
|
62
|
+
* Response type
|
|
63
|
+
*/
|
|
64
|
+
responseType?: ResponseType;
|
|
65
|
+
/**
|
|
66
|
+
* Cancel token
|
|
67
|
+
*/
|
|
68
|
+
cancelToken?: IHttpCancelRequestToken<TCancelToken>;
|
|
69
|
+
}
|
|
70
|
+
export interface IHeader {
|
|
71
|
+
header: string;
|
|
72
|
+
value: string;
|
|
73
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=http.models.js.map
|