@map-colonies/mc-utils 3.1.0 → 3.3.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 (64) hide show
  1. package/README.md +67 -67
  2. package/dist/arrays/index.d.ts +1 -1
  3. package/dist/arrays/index.js +17 -17
  4. package/dist/arrays/subGroups.d.ts +8 -8
  5. package/dist/arrays/subGroups.js +33 -33
  6. package/dist/communication/http/httpClient.d.ts +29 -29
  7. package/dist/communication/http/httpClient.d.ts.map +1 -1
  8. package/dist/communication/http/httpClient.js +353 -317
  9. package/dist/communication/http/httpClient.js.map +1 -1
  10. package/dist/communication/http/index.d.ts +1 -1
  11. package/dist/communication/http/index.js +17 -17
  12. package/dist/communication/index.d.ts +1 -1
  13. package/dist/communication/index.js +17 -17
  14. package/dist/dateTime/getUTCDate.d.ts +1 -1
  15. package/dist/dateTime/getUTCDate.js +10 -10
  16. package/dist/dateTime/index.d.ts +1 -1
  17. package/dist/dateTime/index.js +17 -17
  18. package/dist/geo/bboxUtils.d.ts +23 -23
  19. package/dist/geo/bboxUtils.js +89 -89
  20. package/dist/geo/geoConvertor.d.ts +18 -18
  21. package/dist/geo/geoConvertor.js +49 -49
  22. package/dist/geo/geoHash.d.ts +24 -24
  23. package/dist/geo/geoHash.js +134 -134
  24. package/dist/geo/geoIntersection.d.ts +19 -19
  25. package/dist/geo/geoIntersection.js +70 -70
  26. package/dist/geo/index.d.ts +8 -8
  27. package/dist/geo/index.js +24 -24
  28. package/dist/geo/tileBatcher.d.ts +8 -8
  29. package/dist/geo/tileBatcher.js +97 -97
  30. package/dist/geo/tileRanger.d.ts +46 -46
  31. package/dist/geo/tileRanger.js +232 -232
  32. package/dist/geo/tiles.d.ts +82 -82
  33. package/dist/geo/tiles.js +219 -219
  34. package/dist/geo/tilesGenerator.d.ts +2 -2
  35. package/dist/geo/tilesGenerator.js +17 -17
  36. package/dist/index.d.ts +6 -6
  37. package/dist/index.js +22 -22
  38. package/dist/models/enums/gdal/dataType.d.ts +16 -16
  39. package/dist/models/enums/gdal/dataType.js +20 -20
  40. package/dist/models/enums/gdal/index.d.ts +2 -2
  41. package/dist/models/enums/gdal/index.js +18 -18
  42. package/dist/models/enums/gdal/resamplingMethod.d.ts +16 -16
  43. package/dist/models/enums/gdal/resamplingMethod.js +20 -20
  44. package/dist/models/enums/geo/index.d.ts +1 -1
  45. package/dist/models/enums/geo/index.js +17 -17
  46. package/dist/models/enums/geo/tileOrigin.d.ts +7 -7
  47. package/dist/models/enums/geo/tileOrigin.js +11 -11
  48. package/dist/models/enums/index.d.ts +2 -2
  49. package/dist/models/enums/index.js +18 -18
  50. package/dist/models/index.d.ts +2 -2
  51. package/dist/models/index.js +18 -18
  52. package/dist/models/interfaces/geo/iPoint.d.ts +7 -7
  53. package/dist/models/interfaces/geo/iPoint.js +2 -2
  54. package/dist/models/interfaces/geo/iTile.d.ts +15 -15
  55. package/dist/models/interfaces/geo/iTile.js +2 -2
  56. package/dist/models/interfaces/geo/index.d.ts +2 -2
  57. package/dist/models/interfaces/geo/index.js +18 -18
  58. package/dist/models/interfaces/index.d.ts +1 -1
  59. package/dist/models/interfaces/index.js +17 -17
  60. package/dist/utils/index.d.ts +1 -1
  61. package/dist/utils/index.js +17 -17
  62. package/dist/utils/timeout.d.ts +4 -4
  63. package/dist/utils/timeout.js +22 -22
  64. package/package.json +79 -79
@@ -1,318 +1,354 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.HttpClient = void 0;
30
- const axios_1 = __importDefault(require("axios"));
31
- const http_status_codes_1 = __importDefault(require("http-status-codes"));
32
- const axios_retry_1 = __importStar(require("axios-retry"));
33
- const lodash_1 = require("lodash");
34
- const error_types_1 = require("@map-colonies/error-types");
35
- class HttpClient {
36
- logger;
37
- baseUrl;
38
- targetService;
39
- retryConfig;
40
- disableDebugLogs;
41
- axiosOptions = {};
42
- axiosClient;
43
- constructor(logger, baseUrl, targetService = '', retryConfig, disableDebugLogs = false) {
44
- this.logger = logger;
45
- this.baseUrl = baseUrl;
46
- this.targetService = targetService;
47
- this.retryConfig = retryConfig;
48
- this.disableDebugLogs = disableDebugLogs;
49
- this.axiosClient = axios_1.default.create();
50
- this.axiosOptions.baseURL = baseUrl;
51
- const axiosRetryConfig = retryConfig
52
- ? this.parseConfig(retryConfig)
53
- : {
54
- retries: 0,
55
- };
56
- const delayFunc = axiosRetryConfig.retryDelay ?? (() => 0);
57
- axiosRetryConfig.retryDelay = (retryCount, error) => {
58
- this.logger.error({
59
- err: error,
60
- retries: retryCount,
61
- targetService: this.targetService,
62
- msg: `error from ${this.targetService}.`,
63
- msgError: error.message,
64
- });
65
- return delayFunc(retryCount, error);
66
- };
67
- (0, axios_retry_1.default)(this.axiosClient, axiosRetryConfig);
68
- }
69
- async get(url, queryParams, retryConfig, auth, headers) {
70
- try {
71
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
72
- if (!this.disableDebugLogs) {
73
- this.logger.debug({
74
- reqConfig,
75
- url,
76
- targetService: this.targetService,
77
- msg: `Send GET message to ${this.targetService}.`,
78
- });
79
- }
80
- const res = await this.axiosClient.get(url, reqConfig);
81
- return res.data;
82
- }
83
- catch (err) {
84
- const error = this.wrapError(url, err);
85
- throw error;
86
- }
87
- }
88
- async post(url, body, queryParams, retryConfig, auth, headers) {
89
- try {
90
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
91
- if (!this.disableDebugLogs) {
92
- this.logger.debug({
93
- reqConfig,
94
- url,
95
- body,
96
- targetService: this.targetService,
97
- msg: `Send POST message to ${this.targetService}.`,
98
- });
99
- }
100
- const res = await this.axiosClient.post(url, body, reqConfig);
101
- return res.data;
102
- }
103
- catch (err) {
104
- const error = this.wrapError(url, err, body);
105
- throw error;
106
- }
107
- }
108
- async put(url, body, queryParams, retryConfig, auth, headers) {
109
- try {
110
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
111
- if (!this.disableDebugLogs) {
112
- this.logger.debug({
113
- reqConfig,
114
- url,
115
- body,
116
- targetService: this.targetService,
117
- msg: `Send PUT message to ${this.targetService}.`,
118
- });
119
- }
120
- const res = await this.axiosClient.put(url, body, reqConfig);
121
- return res.data;
122
- }
123
- catch (err) {
124
- const error = this.wrapError(url, err, body);
125
- throw error;
126
- }
127
- }
128
- async delete(url, queryParams, retryConfig, auth, headers) {
129
- try {
130
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
131
- if (!this.disableDebugLogs) {
132
- this.logger.debug({
133
- reqConfig,
134
- url,
135
- targetService: this.targetService,
136
- msg: `Send DELTE message to ${this.targetService}.`,
137
- });
138
- }
139
- const res = await this.axiosClient.delete(url, reqConfig);
140
- return res.data;
141
- }
142
- catch (err) {
143
- const error = this.wrapError(url, err);
144
- throw error;
145
- }
146
- }
147
- async head(url, queryParams, retryConfig, auth, headers) {
148
- try {
149
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
150
- if (!this.disableDebugLogs) {
151
- this.logger.debug({
152
- reqConfig,
153
- url,
154
- targetService: this.targetService,
155
- msg: `Send HEAD message to ${this.targetService}.`,
156
- });
157
- }
158
- const res = await this.axiosClient.head(url, reqConfig);
159
- return res.data;
160
- }
161
- catch (err) {
162
- const error = this.wrapError(url, err);
163
- throw error;
164
- }
165
- }
166
- async options(url, queryParams, retryConfig, auth, headers) {
167
- try {
168
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
169
- if (!this.disableDebugLogs) {
170
- this.logger.debug({
171
- reqConfig,
172
- url,
173
- targetService: this.targetService,
174
- msg: `Send OPTIONS message to ${this.targetService}.`,
175
- });
176
- }
177
- const res = await this.axiosClient.options(url, reqConfig);
178
- return res.data;
179
- }
180
- catch (err) {
181
- const error = this.wrapError(url, err);
182
- throw error;
183
- }
184
- }
185
- async patch(url, body, queryParams, retryConfig, auth, headers) {
186
- try {
187
- const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
188
- if (!this.disableDebugLogs) {
189
- this.logger.debug({
190
- reqConfig,
191
- url,
192
- targetService: this.targetService,
193
- msg: `Send PATCH message to ${this.targetService}.`,
194
- });
195
- }
196
- const res = await this.axiosClient.patch(url, body, reqConfig);
197
- return res.data;
198
- }
199
- catch (err) {
200
- const error = this.wrapError(url, err);
201
- throw error;
202
- }
203
- }
204
- getRequestConfig(retryConfig, queryParams, auth, headers) {
205
- // eslint-disable-next-line @typescript-eslint/naming-convention
206
- const reqConfig = retryConfig ? { ...this.axiosOptions, 'axios-retry': retryConfig } : { ...this.axiosOptions };
207
- if (queryParams !== undefined) {
208
- reqConfig.params = reqConfig.params !== undefined ? { ...reqConfig.params, ...queryParams } : queryParams;
209
- }
210
- if (auth !== undefined) {
211
- reqConfig.auth = auth;
212
- }
213
- if (headers !== undefined) {
214
- reqConfig.headers = reqConfig.headers !== undefined ? { ...reqConfig.headers, ...headers } : headers;
215
- }
216
- return reqConfig;
217
- }
218
- wrapError(url, err, body) {
219
- const message = (0, lodash_1.get)(err, 'response.data.message', undefined);
220
- switch (err.response?.status) {
221
- case http_status_codes_1.default.BAD_REQUEST:
222
- if (!this.disableDebugLogs) {
223
- this.logger.debug({
224
- err,
225
- url,
226
- body,
227
- targetService: this.targetService,
228
- msg: `invalid request error recieved from service ${this.targetService}.`,
229
- msgError: err.message,
230
- });
231
- }
232
- return new error_types_1.BadRequestError(err, message);
233
- case http_status_codes_1.default.NOT_FOUND:
234
- if (!this.disableDebugLogs) {
235
- this.logger.debug({
236
- err,
237
- url,
238
- body,
239
- targetService: this.targetService,
240
- msg: `not found error recieved from service ${this.targetService}.`,
241
- msgError: err.message,
242
- });
243
- }
244
- return new error_types_1.NotFoundError(err, message);
245
- case http_status_codes_1.default.CONFLICT:
246
- if (!this.disableDebugLogs) {
247
- this.logger.debug({
248
- err,
249
- url,
250
- body,
251
- targetService: this.targetService,
252
- msg: `conflict error recieved from service ${this.targetService}.`,
253
- msgError: err.message,
254
- });
255
- }
256
- return new error_types_1.ConflictError(err, message);
257
- case http_status_codes_1.default.FORBIDDEN:
258
- if (!this.disableDebugLogs) {
259
- this.logger.debug({
260
- err,
261
- url,
262
- body,
263
- targetService: this.targetService,
264
- msg: `forbidden error recieved from service ${this.targetService}.`,
265
- msgError: err.message,
266
- });
267
- }
268
- throw new error_types_1.ForbiddenError(err, message);
269
- case http_status_codes_1.default.UNAUTHORIZED:
270
- if (!this.disableDebugLogs) {
271
- this.logger.debug({
272
- err,
273
- url,
274
- body,
275
- targetService: this.targetService,
276
- msg: `unauthorized error recieved from service ${this.targetService}.`,
277
- msgError: err.message,
278
- });
279
- }
280
- throw new error_types_1.UnauthorizedError(err, message);
281
- default:
282
- this.logger.error({
283
- err,
284
- url,
285
- body,
286
- targetService: this.targetService,
287
- msg: `Internal Server Error recieved from service ${this.targetService}.`,
288
- msgError: err.message,
289
- });
290
- return new error_types_1.InternalServerError(err);
291
- }
292
- }
293
- parseConfig(config) {
294
- const retries = config.attempts - 1;
295
- if (retries < 0) {
296
- throw new Error('invalid retry configuration: attempts must be positive');
297
- }
298
- let delay;
299
- if (config.delay === 'exponential') {
300
- delay = axios_retry_1.exponentialDelay;
301
- }
302
- else if (typeof config.delay === 'number') {
303
- delay = () => {
304
- return config.delay;
305
- };
306
- }
307
- else {
308
- throw new Error('invalid retry configuration: delay must be "exponential" or number');
309
- }
310
- return {
311
- retries: retries,
312
- retryDelay: delay,
313
- shouldResetTimeout: config.shouldResetTimeout,
314
- };
315
- }
316
- }
317
- exports.HttpClient = HttpClient;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.HttpClient = void 0;
30
+ const axios_1 = __importDefault(require("axios"));
31
+ const http_status_codes_1 = __importDefault(require("http-status-codes"));
32
+ const axios_retry_1 = __importStar(require("axios-retry"));
33
+ const lodash_1 = require("lodash");
34
+ const error_types_1 = require("@map-colonies/error-types");
35
+ class HttpClient {
36
+ logger;
37
+ baseUrl;
38
+ targetService;
39
+ retryConfig;
40
+ disableDebugLogs;
41
+ axiosOptions = {};
42
+ axiosClient;
43
+ constructor(logger, baseUrl, targetService = '', retryConfig, disableDebugLogs = false) {
44
+ this.logger = logger;
45
+ this.baseUrl = baseUrl;
46
+ this.targetService = targetService;
47
+ this.retryConfig = retryConfig;
48
+ this.disableDebugLogs = disableDebugLogs;
49
+ this.axiosClient = axios_1.default.create();
50
+ this.axiosOptions.baseURL = baseUrl;
51
+ const axiosRetryConfig = retryConfig
52
+ ? this.parseConfig(retryConfig)
53
+ : {
54
+ retries: 0,
55
+ };
56
+ const delayFunc = axiosRetryConfig.retryDelay ?? (() => 0);
57
+ axiosRetryConfig.retryDelay = (retryCount, error) => {
58
+ this.logger.error({
59
+ err: error,
60
+ retries: retryCount,
61
+ targetService: this.targetService,
62
+ msg: `error from ${this.targetService}.`,
63
+ msgError: error.message,
64
+ });
65
+ return delayFunc(retryCount, error);
66
+ };
67
+ (0, axios_retry_1.default)(this.axiosClient, axiosRetryConfig);
68
+ }
69
+ async get(url, queryParams, retryConfig, auth, headers) {
70
+ try {
71
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
72
+ if (!this.disableDebugLogs) {
73
+ this.logger.debug({
74
+ reqConfig,
75
+ url,
76
+ targetService: this.targetService,
77
+ msg: `Send GET message to ${this.targetService}.`,
78
+ });
79
+ }
80
+ const res = await this.axiosClient.get(url, reqConfig);
81
+ return res.data;
82
+ }
83
+ catch (err) {
84
+ const error = this.wrapError(url, err);
85
+ throw error;
86
+ }
87
+ }
88
+ async post(url, body, queryParams, retryConfig, auth, headers) {
89
+ try {
90
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
91
+ if (!this.disableDebugLogs) {
92
+ this.logger.debug({
93
+ reqConfig,
94
+ url,
95
+ body,
96
+ targetService: this.targetService,
97
+ msg: `Send POST message to ${this.targetService}.`,
98
+ });
99
+ }
100
+ const res = await this.axiosClient.post(url, body, reqConfig);
101
+ return res.data;
102
+ }
103
+ catch (err) {
104
+ const error = this.wrapError(url, err, body);
105
+ throw error;
106
+ }
107
+ }
108
+ async put(url, body, queryParams, retryConfig, auth, headers) {
109
+ try {
110
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
111
+ if (!this.disableDebugLogs) {
112
+ this.logger.debug({
113
+ reqConfig,
114
+ url,
115
+ body,
116
+ targetService: this.targetService,
117
+ msg: `Send PUT message to ${this.targetService}.`,
118
+ });
119
+ }
120
+ const res = await this.axiosClient.put(url, body, reqConfig);
121
+ return res.data;
122
+ }
123
+ catch (err) {
124
+ const error = this.wrapError(url, err, body);
125
+ throw error;
126
+ }
127
+ }
128
+ async delete(url, queryParams, retryConfig, auth, headers) {
129
+ try {
130
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
131
+ if (!this.disableDebugLogs) {
132
+ this.logger.debug({
133
+ reqConfig,
134
+ url,
135
+ targetService: this.targetService,
136
+ msg: `Send DELTE message to ${this.targetService}.`,
137
+ });
138
+ }
139
+ const res = await this.axiosClient.delete(url, reqConfig);
140
+ return res.data;
141
+ }
142
+ catch (err) {
143
+ const error = this.wrapError(url, err);
144
+ throw error;
145
+ }
146
+ }
147
+ async head(url, queryParams, retryConfig, auth, headers) {
148
+ try {
149
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
150
+ if (!this.disableDebugLogs) {
151
+ this.logger.debug({
152
+ reqConfig,
153
+ url,
154
+ targetService: this.targetService,
155
+ msg: `Send HEAD message to ${this.targetService}.`,
156
+ });
157
+ }
158
+ const res = await this.axiosClient.head(url, reqConfig);
159
+ return res.data;
160
+ }
161
+ catch (err) {
162
+ const error = this.wrapError(url, err);
163
+ throw error;
164
+ }
165
+ }
166
+ async options(url, queryParams, retryConfig, auth, headers) {
167
+ try {
168
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
169
+ if (!this.disableDebugLogs) {
170
+ this.logger.debug({
171
+ reqConfig,
172
+ url,
173
+ targetService: this.targetService,
174
+ msg: `Send OPTIONS message to ${this.targetService}.`,
175
+ });
176
+ }
177
+ const res = await this.axiosClient.options(url, reqConfig);
178
+ return res.data;
179
+ }
180
+ catch (err) {
181
+ const error = this.wrapError(url, err);
182
+ throw error;
183
+ }
184
+ }
185
+ async patch(url, body, queryParams, retryConfig, auth, headers) {
186
+ try {
187
+ const reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
188
+ if (!this.disableDebugLogs) {
189
+ this.logger.debug({
190
+ reqConfig,
191
+ url,
192
+ targetService: this.targetService,
193
+ msg: `Send PATCH message to ${this.targetService}.`,
194
+ });
195
+ }
196
+ const res = await this.axiosClient.patch(url, body, reqConfig);
197
+ return res.data;
198
+ }
199
+ catch (err) {
200
+ const error = this.wrapError(url, err);
201
+ throw error;
202
+ }
203
+ }
204
+ getRequestConfig(retryConfig, queryParams, auth, headers) {
205
+ // eslint-disable-next-line @typescript-eslint/naming-convention
206
+ const reqConfig = retryConfig ? { ...this.axiosOptions, 'axios-retry': retryConfig } : { ...this.axiosOptions };
207
+ if (queryParams !== undefined) {
208
+ reqConfig.params = reqConfig.params !== undefined ? { ...reqConfig.params, ...queryParams } : queryParams;
209
+ }
210
+ if (auth !== undefined) {
211
+ reqConfig.auth = auth;
212
+ }
213
+ if (headers !== undefined) {
214
+ reqConfig.headers = reqConfig.headers !== undefined ? { ...reqConfig.headers, ...headers } : headers;
215
+ }
216
+ return reqConfig;
217
+ }
218
+ wrapError(url, err, body) {
219
+ const message = (0, lodash_1.get)(err, 'response.data.message', undefined);
220
+ switch (err.response?.status) {
221
+ case http_status_codes_1.default.BAD_REQUEST:
222
+ if (!this.disableDebugLogs) {
223
+ this.logger.debug({
224
+ err,
225
+ url,
226
+ body,
227
+ targetService: this.targetService,
228
+ msg: `invalid request error received from service ${this.targetService}.`,
229
+ msgError: err.message,
230
+ });
231
+ }
232
+ return new error_types_1.BadRequestError(err, message);
233
+ case http_status_codes_1.default.NOT_FOUND:
234
+ if (!this.disableDebugLogs) {
235
+ this.logger.debug({
236
+ err,
237
+ url,
238
+ body,
239
+ targetService: this.targetService,
240
+ msg: `not found error received from service ${this.targetService}.`,
241
+ msgError: err.message,
242
+ });
243
+ }
244
+ return new error_types_1.NotFoundError(err, message);
245
+ case http_status_codes_1.default.CONFLICT:
246
+ if (!this.disableDebugLogs) {
247
+ this.logger.debug({
248
+ err,
249
+ url,
250
+ body,
251
+ targetService: this.targetService,
252
+ msg: `conflict error received from service ${this.targetService}.`,
253
+ msgError: err.message,
254
+ });
255
+ }
256
+ return new error_types_1.ConflictError(err, message);
257
+ case http_status_codes_1.default.FORBIDDEN:
258
+ if (!this.disableDebugLogs) {
259
+ this.logger.debug({
260
+ err,
261
+ url,
262
+ body,
263
+ targetService: this.targetService,
264
+ msg: `forbidden error received from service ${this.targetService}.`,
265
+ msgError: err.message,
266
+ });
267
+ }
268
+ return new error_types_1.ForbiddenError(err, message);
269
+ case http_status_codes_1.default.UNAUTHORIZED:
270
+ if (!this.disableDebugLogs) {
271
+ this.logger.debug({
272
+ err,
273
+ url,
274
+ body,
275
+ targetService: this.targetService,
276
+ msg: `unauthorized error received from service ${this.targetService}.`,
277
+ msgError: err.message,
278
+ });
279
+ }
280
+ return new error_types_1.UnauthorizedError(err, message);
281
+ case http_status_codes_1.default.METHOD_NOT_ALLOWED:
282
+ if (!this.disableDebugLogs) {
283
+ this.logger.debug({
284
+ err,
285
+ url,
286
+ body,
287
+ targetService: this.targetService,
288
+ msg: `method not allowed error received from service ${this.targetService}.`,
289
+ msgError: err.message,
290
+ });
291
+ }
292
+ return new error_types_1.MethodNotAllowedError(err, message);
293
+ case http_status_codes_1.default.REQUEST_TOO_LONG:
294
+ if (!this.disableDebugLogs) {
295
+ this.logger.debug({
296
+ err,
297
+ url,
298
+ body,
299
+ targetService: this.targetService,
300
+ msg: `content too large error received from service ${this.targetService}.`,
301
+ msgError: err.message,
302
+ });
303
+ }
304
+ return new error_types_1.ContentTooLarge(err, message);
305
+ case http_status_codes_1.default.TOO_MANY_REQUESTS:
306
+ if (!this.disableDebugLogs) {
307
+ this.logger.debug({
308
+ err,
309
+ url,
310
+ body,
311
+ targetService: this.targetService,
312
+ msg: `too many requests error received from service ${this.targetService}.`,
313
+ msgError: err.message,
314
+ });
315
+ }
316
+ return new error_types_1.TooManyRequestsError(err, message);
317
+ default:
318
+ this.logger.error({
319
+ err,
320
+ url,
321
+ body,
322
+ targetService: this.targetService,
323
+ msg: `Internal Server Error received from service ${this.targetService}.`,
324
+ msgError: err.message,
325
+ });
326
+ return new error_types_1.InternalServerError(err);
327
+ }
328
+ }
329
+ parseConfig(config) {
330
+ const retries = config.attempts - 1;
331
+ if (retries < 0) {
332
+ throw new Error('invalid retry configuration: attempts must be positive');
333
+ }
334
+ let delay;
335
+ if (config.delay === 'exponential') {
336
+ delay = axios_retry_1.exponentialDelay;
337
+ }
338
+ else if (typeof config.delay === 'number') {
339
+ delay = () => {
340
+ return config.delay;
341
+ };
342
+ }
343
+ else {
344
+ throw new Error('invalid retry configuration: delay must be "exponential" or number');
345
+ }
346
+ return {
347
+ retries: retries,
348
+ retryDelay: delay,
349
+ shouldResetTimeout: config.shouldResetTimeout,
350
+ };
351
+ }
352
+ }
353
+ exports.HttpClient = HttpClient;
318
354
  //# sourceMappingURL=httpClient.js.map