@kontent-ai/core-sdk 10.3.1 → 10.5.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.
Files changed (39) hide show
  1. package/.npmignore +14 -14
  2. package/LICENSE.md +9 -9
  3. package/README.md +30 -30
  4. package/dist/cjs/http/http.functions.js +3 -1
  5. package/dist/cjs/http/http.functions.js.map +1 -1
  6. package/dist/cjs/sdk-info.generated.js +1 -1
  7. package/dist/es6/http/http.functions.js +3 -1
  8. package/dist/es6/http/http.functions.js.map +1 -1
  9. package/dist/es6/sdk-info.generated.js +1 -1
  10. package/dist/esnext/http/http.functions.js +3 -1
  11. package/dist/esnext/http/http.functions.js.map +1 -1
  12. package/dist/esnext/sdk-info.generated.js +1 -1
  13. package/dist/umd/kontent-core.umd.js +35 -9
  14. package/dist/umd/kontent-core.umd.js.map +1 -1
  15. package/dist/umd/kontent-core.umd.min.js +1 -1
  16. package/dist/umd/kontent-core.umd.min.js.map +1 -1
  17. package/dist/umd/report.json +1 -1
  18. package/dist/umd/report.min.json +1 -1
  19. package/dist/umd/stats.json +450 -450
  20. package/dist/umd/stats.min.json +859 -859
  21. package/lib/helpers/header.helper.ts +23 -23
  22. package/lib/helpers/headers-helper.ts +15 -15
  23. package/lib/helpers/index.ts +4 -4
  24. package/lib/helpers/retry-helper.ts +204 -204
  25. package/lib/helpers/url.helper.ts +26 -26
  26. package/lib/http/http.debugger.ts +21 -21
  27. package/lib/http/http.functions.ts +314 -312
  28. package/lib/http/http.models.ts +83 -83
  29. package/lib/http/http.service.ts +91 -91
  30. package/lib/http/ihttp.service.ts +20 -20
  31. package/lib/http/index.ts +6 -6
  32. package/lib/http/test-http.service.ts +70 -70
  33. package/lib/index.ts +4 -4
  34. package/lib/models/index.ts +3 -3
  35. package/lib/models/isdk-info.ts +15 -15
  36. package/lib/models/parameters.ts +25 -25
  37. package/lib/models/url.models.ts +3 -3
  38. package/lib/sdk-info.generated.ts +1 -1
  39. package/package.json +88 -88
@@ -1,312 +1,314 @@
1
- import axios, { AxiosInstance, Canceler, CancelToken } from 'axios';
2
- import { extractHeadersFromAxiosResponse } from '../helpers/headers-helper';
3
-
4
- import { httpDebugger } from './http.debugger';
5
- import {
6
- IHttpCancelRequestToken,
7
- IHeader,
8
- IHttpDeleteQueryCall,
9
- IHttpGetQueryCall,
10
- IHttpPatchQueryCall,
11
- IHttpPostQueryCall,
12
- IHttpPutQueryCall,
13
- IHttpQueryOptions,
14
- IResponse,
15
- IRetryStrategyOptions
16
- } from './http.models';
17
- import { retryHelper } from '../helpers/retry-helper';
18
-
19
- export interface IHttpFunctionsConfig {
20
- logErrorsToConsole: boolean;
21
- }
22
-
23
- export async function getWithRetryAsync<TRawData>(
24
- instance: AxiosInstance,
25
- call: IHttpGetQueryCall,
26
- functionsConfig: IHttpFunctionsConfig,
27
- options?: IHttpQueryOptions<CancelToken>
28
- ): Promise<IResponse<TRawData>> {
29
- const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
30
-
31
- return await runWithRetryAsync<TRawData>({
32
- retryAttempt: 0,
33
- url: call.url,
34
- retryStrategy: retryStrategyOptions,
35
- functionsConfig: functionsConfig,
36
- call: async (retryAttempt) => {
37
- httpDebugger.debugStartHttpRequest();
38
-
39
- const axiosResponse = await instance.get<TRawData>(call.url, {
40
- headers: getHeadersJson(options?.headers ?? [], false),
41
- responseType: options?.responseType,
42
- cancelToken: options?.cancelToken?.token
43
- });
44
-
45
- const response: IResponse<TRawData> = {
46
- data: axiosResponse.data,
47
- rawResponse: axiosResponse,
48
- headers: extractHeadersFromAxiosResponse(axiosResponse),
49
- status: axiosResponse.status,
50
- retryStrategy: {
51
- options: retryStrategyOptions,
52
- retryAttempts: retryAttempt
53
- }
54
- };
55
-
56
- httpDebugger.debugSuccessHttpRequest();
57
- return response;
58
- }
59
- });
60
- }
61
-
62
- export async function postWithRetryAsync<TRawData>(
63
- instance: AxiosInstance,
64
- call: IHttpPostQueryCall,
65
- functionsConfig: IHttpFunctionsConfig,
66
- options?: IHttpQueryOptions<CancelToken>
67
- ): Promise<IResponse<TRawData>> {
68
- const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
69
-
70
- return await runWithRetryAsync<TRawData>({
71
- retryAttempt: 0,
72
- url: call.url,
73
- retryStrategy: retryStrategyOptions,
74
- functionsConfig: functionsConfig,
75
- call: async (retryAttempt) => {
76
- httpDebugger.debugStartHttpRequest();
77
-
78
- const axiosResponse = await instance.post<TRawData>(call.url, call.body, {
79
- headers: getHeadersJson(options?.headers ?? [], false),
80
- responseType: options?.responseType,
81
- // required for uploading large files
82
- // https://github.com/axios/axios/issues/1362
83
- maxContentLength: 'Infinity' as any,
84
- maxBodyLength: 'Infinity' as any,
85
- cancelToken: options?.cancelToken?.token
86
- });
87
-
88
- const response: IResponse<TRawData> = {
89
- data: axiosResponse.data,
90
- rawResponse: axiosResponse,
91
- headers: extractHeadersFromAxiosResponse(axiosResponse),
92
- status: axiosResponse.status,
93
- retryStrategy: {
94
- options: retryStrategyOptions,
95
- retryAttempts: retryAttempt
96
- }
97
- };
98
-
99
- httpDebugger.debugSuccessHttpRequest();
100
- return response;
101
- }
102
- });
103
- }
104
-
105
- export async function putWithRetryAsync<TRawData>(
106
- instance: AxiosInstance,
107
- call: IHttpPutQueryCall,
108
- functionsConfig: IHttpFunctionsConfig,
109
- options?: IHttpQueryOptions<CancelToken>
110
- ): Promise<IResponse<TRawData>> {
111
- const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
112
-
113
- return await runWithRetryAsync<TRawData>({
114
- retryAttempt: 0,
115
- url: call.url,
116
- retryStrategy: retryStrategyOptions,
117
- functionsConfig: functionsConfig,
118
- call: async (retryAttempt) => {
119
- httpDebugger.debugStartHttpRequest();
120
-
121
- const axiosResponse = await instance.put<TRawData>(call.url, call.body, {
122
- headers: getHeadersJson(options?.headers ?? [], false),
123
- responseType: options?.responseType,
124
- // required for uploading large files
125
- // https://github.com/axios/axios/issues/1362
126
- maxContentLength: 'Infinity' as any,
127
- maxBodyLength: 'Infinity' as any,
128
- cancelToken: options?.cancelToken?.token
129
- });
130
-
131
- const response: IResponse<TRawData> = {
132
- data: axiosResponse.data,
133
- rawResponse: axiosResponse,
134
- headers: extractHeadersFromAxiosResponse(axiosResponse),
135
- status: axiosResponse.status,
136
- retryStrategy: {
137
- options: retryStrategyOptions,
138
- retryAttempts: retryAttempt
139
- }
140
- };
141
-
142
- httpDebugger.debugSuccessHttpRequest();
143
- return response;
144
- }
145
- });
146
- }
147
-
148
- export async function patchWithRetryAsync<TRawData>(
149
- instance: AxiosInstance,
150
- call: IHttpPatchQueryCall,
151
- functionsConfig: IHttpFunctionsConfig,
152
- options?: IHttpQueryOptions<CancelToken>
153
- ): Promise<IResponse<TRawData>> {
154
- const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
155
-
156
- return await runWithRetryAsync<TRawData>({
157
- retryAttempt: 0,
158
- url: call.url,
159
- retryStrategy: retryStrategyOptions,
160
- functionsConfig: functionsConfig,
161
- call: async (retryAttempt) => {
162
- httpDebugger.debugStartHttpRequest();
163
-
164
- const axiosResponse = await instance.patch<TRawData>(call.url, call.body, {
165
- headers: getHeadersJson(options?.headers ?? [], false),
166
- responseType: options?.responseType,
167
- // required for uploading large files
168
- // https://github.com/axios/axios/issues/1362
169
- maxContentLength: 'Infinity' as any,
170
- maxBodyLength: 'Infinity' as any,
171
- cancelToken: options?.cancelToken?.token
172
- });
173
-
174
- const response: IResponse<TRawData> = {
175
- data: axiosResponse.data,
176
- rawResponse: axiosResponse,
177
- headers: extractHeadersFromAxiosResponse(axiosResponse),
178
- status: axiosResponse.status,
179
- retryStrategy: {
180
- options: retryStrategyOptions,
181
- retryAttempts: retryAttempt
182
- }
183
- };
184
-
185
- httpDebugger.debugSuccessHttpRequest();
186
- return response;
187
- }
188
- });
189
- }
190
-
191
- export async function deleteWithRetryAsync<TRawData>(
192
- instance: AxiosInstance,
193
- call: IHttpDeleteQueryCall,
194
- functionsConfig: IHttpFunctionsConfig,
195
- options?: IHttpQueryOptions<CancelToken>
196
- ): Promise<IResponse<TRawData>> {
197
- const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
198
-
199
- return await runWithRetryAsync<TRawData>({
200
- retryAttempt: 0,
201
- url: call.url,
202
- retryStrategy: retryStrategyOptions,
203
- functionsConfig: functionsConfig,
204
- call: async (retryAttempt) => {
205
- httpDebugger.debugStartHttpRequest();
206
-
207
- const axiosResponse = await instance.delete<TRawData>(call.url, {
208
- headers: getHeadersJson(options?.headers ?? [], false),
209
- responseType: options?.responseType,
210
- // required for uploading large files
211
- // https://github.com/axios/axios/issues/1362
212
- maxContentLength: 'Infinity' as any,
213
- maxBodyLength: 'Infinity' as any,
214
- cancelToken: options?.cancelToken?.token
215
- });
216
-
217
- const response: IResponse<TRawData> = {
218
- data: axiosResponse.data,
219
- rawResponse: axiosResponse,
220
- headers: extractHeadersFromAxiosResponse(axiosResponse),
221
- status: axiosResponse.status,
222
- retryStrategy: {
223
- options: retryStrategyOptions,
224
- retryAttempts: retryAttempt
225
- }
226
- };
227
-
228
- httpDebugger.debugSuccessHttpRequest();
229
- return response;
230
- }
231
- });
232
- }
233
-
234
- export function createCancelToken(): IHttpCancelRequestToken<CancelToken> {
235
- let canceler: Canceler;
236
-
237
- const token = new axios.CancelToken((c) => {
238
- // An executor function receives a cancel function as a parameter
239
- canceler = c;
240
- });
241
-
242
- return {
243
- cancel: (cancelMessage) =>
244
- canceler(`${retryHelper.requestCancelledMessagePrefix}: ${cancelMessage ?? 'User cancel'}`),
245
- token: token
246
- };
247
- }
248
-
249
- async function runWithRetryAsync<TRawData>(data: {
250
- url: string;
251
- retryAttempt: number;
252
- call: (retryAttempt: number) => Promise<IResponse<TRawData>>;
253
- retryStrategy: IRetryStrategyOptions;
254
- functionsConfig: IHttpFunctionsConfig;
255
- }): Promise<IResponse<TRawData>> {
256
- try {
257
- return await data.call(data.retryAttempt);
258
- } catch (error) {
259
- const retryResult = retryHelper.getRetryErrorResult({
260
- error: error,
261
- retryAttempt: data.retryAttempt,
262
- retryStrategy: data.retryStrategy
263
- });
264
-
265
- if (retryResult.canRetry) {
266
- httpDebugger.debugRetryHttpRequest();
267
-
268
- // wait time before retrying
269
- await new Promise((resolve) => setTimeout(resolve, retryResult.retryInMs));
270
-
271
- // retry request
272
- console.warn(
273
- `Retry attempt '${data.retryAttempt + 1}' from a maximum of '${
274
- retryResult.maxRetries
275
- }' retries. Request url: '${data.url}'`
276
- );
277
-
278
- return await runWithRetryAsync({
279
- call: data.call,
280
- retryStrategy: data.retryStrategy,
281
- retryAttempt: data.retryAttempt + 1,
282
- url: data.url,
283
- functionsConfig: data.functionsConfig
284
- });
285
- }
286
-
287
- if (data.functionsConfig.logErrorsToConsole) {
288
- console.error(`Executing '${data.url}' failed. Request was retried '${data.retryAttempt}' times. `, error);
289
- }
290
-
291
- throw error;
292
- }
293
- }
294
-
295
- function getHeadersJson(headers: IHeader[], addContentTypeHeader: boolean): { [header: string]: string } {
296
- const headerJson: { [header: string]: string } = {};
297
-
298
- headers.forEach((header) => {
299
- headerJson[header.header] = header.value;
300
- });
301
-
302
- if (addContentTypeHeader) {
303
- // add default content type header if not present
304
- const contentTypeHeader = headers.find((m) => m.header.toLowerCase() === 'Content-Type'.toLowerCase());
305
-
306
- if (!contentTypeHeader) {
307
- headerJson['Content-Type'] = 'application/json';
308
- }
309
- }
310
-
311
- return headerJson;
312
- }
1
+ import axios, { AxiosInstance, Canceler, CancelToken } from 'axios';
2
+ import { extractHeadersFromAxiosResponse } from '../helpers/headers-helper';
3
+
4
+ import { httpDebugger } from './http.debugger';
5
+ import {
6
+ IHttpCancelRequestToken,
7
+ IHeader,
8
+ IHttpDeleteQueryCall,
9
+ IHttpGetQueryCall,
10
+ IHttpPatchQueryCall,
11
+ IHttpPostQueryCall,
12
+ IHttpPutQueryCall,
13
+ IHttpQueryOptions,
14
+ IResponse,
15
+ IRetryStrategyOptions
16
+ } from './http.models';
17
+ import { retryHelper } from '../helpers/retry-helper';
18
+
19
+ export interface IHttpFunctionsConfig {
20
+ logErrorsToConsole: boolean;
21
+ }
22
+
23
+ export async function getWithRetryAsync<TRawData>(
24
+ instance: AxiosInstance,
25
+ call: IHttpGetQueryCall,
26
+ functionsConfig: IHttpFunctionsConfig,
27
+ options?: IHttpQueryOptions<CancelToken>
28
+ ): Promise<IResponse<TRawData>> {
29
+ const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
30
+
31
+ return await runWithRetryAsync<TRawData>({
32
+ retryAttempt: 0,
33
+ url: call.url,
34
+ retryStrategy: retryStrategyOptions,
35
+ functionsConfig: functionsConfig,
36
+ call: async (retryAttempt) => {
37
+ httpDebugger.debugStartHttpRequest();
38
+
39
+ const axiosResponse = await instance.get<TRawData>(call.url, {
40
+ headers: getHeadersJson(options?.headers ?? [], false),
41
+ responseType: options?.responseType,
42
+ cancelToken: options?.cancelToken?.token
43
+ });
44
+
45
+ const response: IResponse<TRawData> = {
46
+ data: axiosResponse.data,
47
+ rawResponse: axiosResponse,
48
+ headers: extractHeadersFromAxiosResponse(axiosResponse),
49
+ status: axiosResponse.status,
50
+ retryStrategy: {
51
+ options: retryStrategyOptions,
52
+ retryAttempts: retryAttempt
53
+ }
54
+ };
55
+
56
+ httpDebugger.debugSuccessHttpRequest();
57
+ return response;
58
+ }
59
+ });
60
+ }
61
+
62
+ export async function postWithRetryAsync<TRawData>(
63
+ instance: AxiosInstance,
64
+ call: IHttpPostQueryCall,
65
+ functionsConfig: IHttpFunctionsConfig,
66
+ options?: IHttpQueryOptions<CancelToken>
67
+ ): Promise<IResponse<TRawData>> {
68
+ const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
69
+
70
+ return await runWithRetryAsync<TRawData>({
71
+ retryAttempt: 0,
72
+ url: call.url,
73
+ retryStrategy: retryStrategyOptions,
74
+ functionsConfig: functionsConfig,
75
+ call: async (retryAttempt) => {
76
+ httpDebugger.debugStartHttpRequest();
77
+
78
+ const axiosResponse = await instance.post<TRawData>(call.url, call.body, {
79
+ headers: getHeadersJson(options?.headers ?? [], false),
80
+ responseType: options?.responseType,
81
+ // required for uploading large files
82
+ // https://github.com/axios/axios/issues/1362
83
+ maxContentLength: 'Infinity' as any,
84
+ maxBodyLength: 'Infinity' as any,
85
+ cancelToken: options?.cancelToken?.token
86
+ });
87
+
88
+ const response: IResponse<TRawData> = {
89
+ data: axiosResponse.data,
90
+ rawResponse: axiosResponse,
91
+ headers: extractHeadersFromAxiosResponse(axiosResponse),
92
+ status: axiosResponse.status,
93
+ retryStrategy: {
94
+ options: retryStrategyOptions,
95
+ retryAttempts: retryAttempt
96
+ }
97
+ };
98
+
99
+ httpDebugger.debugSuccessHttpRequest();
100
+ return response;
101
+ }
102
+ });
103
+ }
104
+
105
+ export async function putWithRetryAsync<TRawData>(
106
+ instance: AxiosInstance,
107
+ call: IHttpPutQueryCall,
108
+ functionsConfig: IHttpFunctionsConfig,
109
+ options?: IHttpQueryOptions<CancelToken>
110
+ ): Promise<IResponse<TRawData>> {
111
+ const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
112
+
113
+ return await runWithRetryAsync<TRawData>({
114
+ retryAttempt: 0,
115
+ url: call.url,
116
+ retryStrategy: retryStrategyOptions,
117
+ functionsConfig: functionsConfig,
118
+ call: async (retryAttempt) => {
119
+ httpDebugger.debugStartHttpRequest();
120
+
121
+ const axiosResponse = await instance.put<TRawData>(call.url, call.body, {
122
+ headers: getHeadersJson(options?.headers ?? [], false),
123
+ responseType: options?.responseType,
124
+ // required for uploading large files
125
+ // https://github.com/axios/axios/issues/1362
126
+ maxContentLength: 'Infinity' as any,
127
+ maxBodyLength: 'Infinity' as any,
128
+ cancelToken: options?.cancelToken?.token
129
+ });
130
+
131
+ const response: IResponse<TRawData> = {
132
+ data: axiosResponse.data,
133
+ rawResponse: axiosResponse,
134
+ headers: extractHeadersFromAxiosResponse(axiosResponse),
135
+ status: axiosResponse.status,
136
+ retryStrategy: {
137
+ options: retryStrategyOptions,
138
+ retryAttempts: retryAttempt
139
+ }
140
+ };
141
+
142
+ httpDebugger.debugSuccessHttpRequest();
143
+ return response;
144
+ }
145
+ });
146
+ }
147
+
148
+ export async function patchWithRetryAsync<TRawData>(
149
+ instance: AxiosInstance,
150
+ call: IHttpPatchQueryCall,
151
+ functionsConfig: IHttpFunctionsConfig,
152
+ options?: IHttpQueryOptions<CancelToken>
153
+ ): Promise<IResponse<TRawData>> {
154
+ const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
155
+
156
+ return await runWithRetryAsync<TRawData>({
157
+ retryAttempt: 0,
158
+ url: call.url,
159
+ retryStrategy: retryStrategyOptions,
160
+ functionsConfig: functionsConfig,
161
+ call: async (retryAttempt) => {
162
+ httpDebugger.debugStartHttpRequest();
163
+
164
+ const axiosResponse = await instance.patch<TRawData>(call.url, call.body, {
165
+ headers: getHeadersJson(options?.headers ?? [], false),
166
+ responseType: options?.responseType,
167
+ // required for uploading large files
168
+ // https://github.com/axios/axios/issues/1362
169
+ maxContentLength: 'Infinity' as any,
170
+ maxBodyLength: 'Infinity' as any,
171
+ cancelToken: options?.cancelToken?.token
172
+ });
173
+
174
+ const response: IResponse<TRawData> = {
175
+ data: axiosResponse.data,
176
+ rawResponse: axiosResponse,
177
+ headers: extractHeadersFromAxiosResponse(axiosResponse),
178
+ status: axiosResponse.status,
179
+ retryStrategy: {
180
+ options: retryStrategyOptions,
181
+ retryAttempts: retryAttempt
182
+ }
183
+ };
184
+
185
+ httpDebugger.debugSuccessHttpRequest();
186
+ return response;
187
+ }
188
+ });
189
+ }
190
+
191
+ export async function deleteWithRetryAsync<TRawData>(
192
+ instance: AxiosInstance,
193
+ call: IHttpDeleteQueryCall,
194
+ functionsConfig: IHttpFunctionsConfig,
195
+ options?: IHttpQueryOptions<CancelToken>
196
+ ): Promise<IResponse<TRawData>> {
197
+ const retryStrategyOptions = options?.retryStrategy ?? retryHelper.defaultRetryStrategy;
198
+
199
+ return await runWithRetryAsync<TRawData>({
200
+ retryAttempt: 0,
201
+ url: call.url,
202
+ retryStrategy: retryStrategyOptions,
203
+ functionsConfig: functionsConfig,
204
+ call: async (retryAttempt) => {
205
+ httpDebugger.debugStartHttpRequest();
206
+
207
+ const axiosResponse = await instance.delete<TRawData>(call.url, {
208
+ headers: getHeadersJson(options?.headers ?? [], false),
209
+ responseType: options?.responseType,
210
+ // required for uploading large files
211
+ // https://github.com/axios/axios/issues/1362
212
+ maxContentLength: 'Infinity' as any,
213
+ maxBodyLength: 'Infinity' as any,
214
+ cancelToken: options?.cancelToken?.token
215
+ });
216
+
217
+ const response: IResponse<TRawData> = {
218
+ data: axiosResponse.data,
219
+ rawResponse: axiosResponse,
220
+ headers: extractHeadersFromAxiosResponse(axiosResponse),
221
+ status: axiosResponse.status,
222
+ retryStrategy: {
223
+ options: retryStrategyOptions,
224
+ retryAttempts: retryAttempt
225
+ }
226
+ };
227
+
228
+ httpDebugger.debugSuccessHttpRequest();
229
+ return response;
230
+ }
231
+ });
232
+ }
233
+
234
+ export function createCancelToken(): IHttpCancelRequestToken<CancelToken> {
235
+ let canceler: Canceler;
236
+
237
+ const token = new axios.CancelToken((c) => {
238
+ // An executor function receives a cancel function as a parameter
239
+ canceler = c;
240
+ });
241
+
242
+ return {
243
+ cancel: (cancelMessage) =>
244
+ canceler(`${retryHelper.requestCancelledMessagePrefix}: ${cancelMessage ?? 'User cancel'}`),
245
+ token: token
246
+ };
247
+ }
248
+
249
+ async function runWithRetryAsync<TRawData>(data: {
250
+ url: string;
251
+ retryAttempt: number;
252
+ call: (retryAttempt: number) => Promise<IResponse<TRawData>>;
253
+ retryStrategy: IRetryStrategyOptions;
254
+ functionsConfig: IHttpFunctionsConfig;
255
+ }): Promise<IResponse<TRawData>> {
256
+ try {
257
+ return await data.call(data.retryAttempt);
258
+ } catch (error) {
259
+ const retryResult = retryHelper.getRetryErrorResult({
260
+ error: error,
261
+ retryAttempt: data.retryAttempt,
262
+ retryStrategy: data.retryStrategy
263
+ });
264
+
265
+ if (retryResult.canRetry) {
266
+ httpDebugger.debugRetryHttpRequest();
267
+
268
+ // wait time before retrying
269
+ await new Promise((resolve) => setTimeout(resolve, retryResult.retryInMs));
270
+
271
+ if (data.functionsConfig.logErrorsToConsole) {
272
+ console.warn(
273
+ `Retry attempt '${data.retryAttempt + 1}' from a maximum of '${
274
+ retryResult.maxRetries
275
+ }' retries. Request url: '${data.url}'`
276
+ );
277
+ }
278
+
279
+ // retry request
280
+ return await runWithRetryAsync({
281
+ call: data.call,
282
+ retryStrategy: data.retryStrategy,
283
+ retryAttempt: data.retryAttempt + 1,
284
+ url: data.url,
285
+ functionsConfig: data.functionsConfig
286
+ });
287
+ }
288
+
289
+ if (data.functionsConfig.logErrorsToConsole) {
290
+ console.error(`Executing '${data.url}' failed. Request was retried '${data.retryAttempt}' times. `, error);
291
+ }
292
+
293
+ throw error;
294
+ }
295
+ }
296
+
297
+ function getHeadersJson(headers: IHeader[], addContentTypeHeader: boolean): { [header: string]: string } {
298
+ const headerJson: { [header: string]: string } = {};
299
+
300
+ headers.forEach((header) => {
301
+ headerJson[header.header] = header.value;
302
+ });
303
+
304
+ if (addContentTypeHeader) {
305
+ // add default content type header if not present
306
+ const contentTypeHeader = headers.find((m) => m.header.toLowerCase() === 'Content-Type'.toLowerCase());
307
+
308
+ if (!contentTypeHeader) {
309
+ headerJson['Content-Type'] = 'application/json';
310
+ }
311
+ }
312
+
313
+ return headerJson;
314
+ }