@map-colonies/mc-utils 3.0.0 → 3.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.
Files changed (122) hide show
  1. package/README.md +0 -0
  2. package/dist/arrays/index.d.ts +0 -0
  3. package/dist/arrays/index.d.ts.map +0 -0
  4. package/dist/arrays/index.js +0 -0
  5. package/dist/arrays/index.js.map +0 -0
  6. package/dist/arrays/subGroups.d.ts +0 -0
  7. package/dist/arrays/subGroups.d.ts.map +0 -0
  8. package/dist/arrays/subGroups.js +20 -125
  9. package/dist/arrays/subGroups.js.map +1 -1
  10. package/dist/communication/http/httpClient.d.ts +0 -0
  11. package/dist/communication/http/httpClient.d.ts.map +1 -1
  12. package/dist/communication/http/httpClient.js +206 -311
  13. package/dist/communication/http/httpClient.js.map +1 -1
  14. package/dist/communication/http/index.d.ts +0 -0
  15. package/dist/communication/http/index.d.ts.map +0 -0
  16. package/dist/communication/http/index.js +0 -0
  17. package/dist/communication/http/index.js.map +0 -0
  18. package/dist/communication/index.d.ts +0 -0
  19. package/dist/communication/index.d.ts.map +0 -0
  20. package/dist/communication/index.js +0 -0
  21. package/dist/communication/index.js.map +0 -0
  22. package/dist/dateTime/getUTCDate.d.ts +0 -0
  23. package/dist/dateTime/getUTCDate.d.ts.map +0 -0
  24. package/dist/dateTime/getUTCDate.js +4 -4
  25. package/dist/dateTime/getUTCDate.js.map +1 -1
  26. package/dist/dateTime/index.d.ts +0 -0
  27. package/dist/dateTime/index.d.ts.map +0 -0
  28. package/dist/dateTime/index.js +0 -0
  29. package/dist/dateTime/index.js.map +0 -0
  30. package/dist/geo/bboxUtils.d.ts +0 -0
  31. package/dist/geo/bboxUtils.d.ts.map +0 -0
  32. package/dist/geo/bboxUtils.js +24 -24
  33. package/dist/geo/bboxUtils.js.map +1 -1
  34. package/dist/geo/geoConvertor.d.ts +0 -0
  35. package/dist/geo/geoConvertor.d.ts.map +0 -0
  36. package/dist/geo/geoConvertor.js +13 -15
  37. package/dist/geo/geoConvertor.js.map +1 -1
  38. package/dist/geo/geoHash.d.ts +0 -0
  39. package/dist/geo/geoHash.d.ts.map +0 -0
  40. package/dist/geo/geoHash.js +65 -205
  41. package/dist/geo/geoHash.js.map +1 -1
  42. package/dist/geo/geoIntersection.d.ts +0 -0
  43. package/dist/geo/geoIntersection.d.ts.map +0 -0
  44. package/dist/geo/geoIntersection.js +14 -14
  45. package/dist/geo/geoIntersection.js.map +1 -1
  46. package/dist/geo/index.d.ts +0 -0
  47. package/dist/geo/index.d.ts.map +0 -0
  48. package/dist/geo/index.js +0 -0
  49. package/dist/geo/index.js.map +0 -0
  50. package/dist/geo/tileBatcher.d.ts +0 -0
  51. package/dist/geo/tileBatcher.d.ts.map +0 -0
  52. package/dist/geo/tileBatcher.js +65 -161
  53. package/dist/geo/tileBatcher.js.map +1 -1
  54. package/dist/geo/tileRanger.d.ts +0 -0
  55. package/dist/geo/tileRanger.d.ts.map +0 -0
  56. package/dist/geo/tileRanger.js +165 -316
  57. package/dist/geo/tileRanger.js.map +1 -1
  58. package/dist/geo/tiles.d.ts +0 -0
  59. package/dist/geo/tiles.d.ts.map +0 -0
  60. package/dist/geo/tiles.js +29 -56
  61. package/dist/geo/tiles.js.map +1 -1
  62. package/dist/geo/tilesGenerator.d.ts +0 -0
  63. package/dist/geo/tilesGenerator.d.ts.map +0 -0
  64. package/dist/geo/tilesGenerator.js +11 -105
  65. package/dist/geo/tilesGenerator.js.map +1 -1
  66. package/dist/index.d.ts +1 -0
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +1 -0
  69. package/dist/index.js.map +1 -1
  70. package/dist/models/enums/gdal/dataType.d.ts +0 -0
  71. package/dist/models/enums/gdal/dataType.d.ts.map +0 -0
  72. package/dist/models/enums/gdal/dataType.js +0 -0
  73. package/dist/models/enums/gdal/dataType.js.map +0 -0
  74. package/dist/models/enums/gdal/index.d.ts +0 -0
  75. package/dist/models/enums/gdal/index.d.ts.map +0 -0
  76. package/dist/models/enums/gdal/index.js +0 -0
  77. package/dist/models/enums/gdal/index.js.map +0 -0
  78. package/dist/models/enums/gdal/resamplingMethod.d.ts +0 -0
  79. package/dist/models/enums/gdal/resamplingMethod.d.ts.map +0 -0
  80. package/dist/models/enums/gdal/resamplingMethod.js +0 -0
  81. package/dist/models/enums/gdal/resamplingMethod.js.map +0 -0
  82. package/dist/models/enums/geo/index.d.ts +0 -0
  83. package/dist/models/enums/geo/index.d.ts.map +0 -0
  84. package/dist/models/enums/geo/index.js +0 -0
  85. package/dist/models/enums/geo/index.js.map +0 -0
  86. package/dist/models/enums/geo/tileOrigin.d.ts +0 -0
  87. package/dist/models/enums/geo/tileOrigin.d.ts.map +0 -0
  88. package/dist/models/enums/geo/tileOrigin.js +0 -0
  89. package/dist/models/enums/geo/tileOrigin.js.map +0 -0
  90. package/dist/models/enums/index.d.ts +0 -0
  91. package/dist/models/enums/index.d.ts.map +0 -0
  92. package/dist/models/enums/index.js +0 -0
  93. package/dist/models/enums/index.js.map +0 -0
  94. package/dist/models/index.d.ts +0 -0
  95. package/dist/models/index.d.ts.map +0 -0
  96. package/dist/models/index.js +0 -0
  97. package/dist/models/index.js.map +0 -0
  98. package/dist/models/interfaces/geo/iPoint.d.ts +0 -0
  99. package/dist/models/interfaces/geo/iPoint.d.ts.map +0 -0
  100. package/dist/models/interfaces/geo/iPoint.js +0 -0
  101. package/dist/models/interfaces/geo/iPoint.js.map +0 -0
  102. package/dist/models/interfaces/geo/iTile.d.ts +0 -0
  103. package/dist/models/interfaces/geo/iTile.d.ts.map +0 -0
  104. package/dist/models/interfaces/geo/iTile.js +0 -0
  105. package/dist/models/interfaces/geo/iTile.js.map +0 -0
  106. package/dist/models/interfaces/geo/index.d.ts +0 -0
  107. package/dist/models/interfaces/geo/index.d.ts.map +0 -0
  108. package/dist/models/interfaces/geo/index.js +0 -0
  109. package/dist/models/interfaces/geo/index.js.map +0 -0
  110. package/dist/models/interfaces/index.d.ts +0 -0
  111. package/dist/models/interfaces/index.d.ts.map +0 -0
  112. package/dist/models/interfaces/index.js +0 -0
  113. package/dist/models/interfaces/index.js.map +0 -0
  114. package/dist/utils/index.d.ts +2 -0
  115. package/dist/utils/index.d.ts.map +1 -0
  116. package/dist/utils/index.js +18 -0
  117. package/dist/utils/index.js.map +1 -0
  118. package/dist/utils/timeout.d.ts +3 -0
  119. package/dist/utils/timeout.d.ts.map +1 -1
  120. package/dist/utils/timeout.js +18 -43
  121. package/dist/utils/timeout.js.map +1 -1
  122. package/package.json +2 -2
@@ -1,15 +1,4 @@
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
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -33,315 +22,210 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
22
  __setModuleDefault(result, mod);
34
23
  return result;
35
24
  };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (_) try {
52
- 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;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
73
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
27
  };
75
28
  Object.defineProperty(exports, "__esModule", { value: true });
76
29
  exports.HttpClient = void 0;
77
- var axios_1 = __importDefault(require("axios"));
78
- var http_status_codes_1 = __importDefault(require("http-status-codes"));
79
- var axios_retry_1 = __importStar(require("axios-retry"));
80
- var lodash_1 = require("lodash");
81
- var error_types_1 = require("@map-colonies/error-types");
82
- var HttpClient = /** @class */ (function () {
83
- function HttpClient(logger, baseUrl, targetService, retryConfig, disableDebugLogs) {
84
- if (targetService === void 0) { targetService = ''; }
85
- if (disableDebugLogs === void 0) { disableDebugLogs = false; }
86
- var _this = this;
87
- var _a;
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) {
88
44
  this.logger = logger;
89
45
  this.baseUrl = baseUrl;
90
46
  this.targetService = targetService;
91
47
  this.retryConfig = retryConfig;
92
48
  this.disableDebugLogs = disableDebugLogs;
93
- this.axiosOptions = {};
94
49
  this.axiosClient = axios_1.default.create();
95
50
  this.axiosOptions.baseURL = baseUrl;
96
- var axiosRetryConfig = retryConfig
51
+ const axiosRetryConfig = retryConfig
97
52
  ? this.parseConfig(retryConfig)
98
53
  : {
99
54
  retries: 0,
100
55
  };
101
- var delayFunc = (_a = axiosRetryConfig.retryDelay) !== null && _a !== void 0 ? _a : (function () { return 0; });
102
- axiosRetryConfig.retryDelay = function (retryCount, error) {
103
- _this.logger.error({
56
+ const delayFunc = axiosRetryConfig.retryDelay ?? (() => 0);
57
+ axiosRetryConfig.retryDelay = (retryCount, error) => {
58
+ this.logger.error({
104
59
  err: error,
105
60
  retries: retryCount,
106
- targetService: _this.targetService,
107
- msg: "error from ".concat(_this.targetService, "."),
61
+ targetService: this.targetService,
62
+ msg: `error from ${this.targetService}.`,
108
63
  msgError: error.message,
109
64
  });
110
65
  return delayFunc(retryCount, error);
111
66
  };
112
67
  (0, axios_retry_1.default)(this.axiosClient, axiosRetryConfig);
113
68
  }
114
- HttpClient.prototype.get = function (url, queryParams, retryConfig, auth, headers) {
115
- return __awaiter(this, void 0, void 0, function () {
116
- var reqConfig, res, err_1, error;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0:
120
- _a.trys.push([0, 2, , 3]);
121
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
122
- if (!this.disableDebugLogs) {
123
- this.logger.debug({
124
- reqConfig: reqConfig,
125
- url: url,
126
- targetService: this.targetService,
127
- msg: "Send GET message to ".concat(this.targetService, "."),
128
- });
129
- }
130
- return [4 /*yield*/, this.axiosClient.get(url, reqConfig)];
131
- case 1:
132
- res = _a.sent();
133
- return [2 /*return*/, res.data];
134
- case 2:
135
- err_1 = _a.sent();
136
- error = this.wrapError(url, err_1);
137
- throw error;
138
- case 3: return [2 /*return*/];
139
- }
140
- });
141
- });
142
- };
143
- HttpClient.prototype.post = function (url, body, queryParams, retryConfig, auth, headers) {
144
- return __awaiter(this, void 0, void 0, function () {
145
- var reqConfig, res, err_2, error;
146
- return __generator(this, function (_a) {
147
- switch (_a.label) {
148
- case 0:
149
- _a.trys.push([0, 2, , 3]);
150
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
151
- if (!this.disableDebugLogs) {
152
- this.logger.debug({
153
- reqConfig: reqConfig,
154
- url: url,
155
- body: body,
156
- targetService: this.targetService,
157
- msg: "Send POST message to ".concat(this.targetService, "."),
158
- });
159
- }
160
- return [4 /*yield*/, this.axiosClient.post(url, body, reqConfig)];
161
- case 1:
162
- res = _a.sent();
163
- return [2 /*return*/, res.data];
164
- case 2:
165
- err_2 = _a.sent();
166
- error = this.wrapError(url, err_2, body);
167
- throw error;
168
- case 3: return [2 /*return*/];
169
- }
170
- });
171
- });
172
- };
173
- HttpClient.prototype.put = function (url, body, queryParams, retryConfig, auth, headers) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- var reqConfig, res, err_3, error;
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0:
179
- _a.trys.push([0, 2, , 3]);
180
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
181
- if (!this.disableDebugLogs) {
182
- this.logger.debug({
183
- reqConfig: reqConfig,
184
- url: url,
185
- body: body,
186
- targetService: this.targetService,
187
- msg: "Send PUT message to ".concat(this.targetService, "."),
188
- });
189
- }
190
- return [4 /*yield*/, this.axiosClient.put(url, body, reqConfig)];
191
- case 1:
192
- res = _a.sent();
193
- return [2 /*return*/, res.data];
194
- case 2:
195
- err_3 = _a.sent();
196
- error = this.wrapError(url, err_3, body);
197
- throw error;
198
- case 3: return [2 /*return*/];
199
- }
200
- });
201
- });
202
- };
203
- HttpClient.prototype.delete = function (url, queryParams, retryConfig, auth, headers) {
204
- return __awaiter(this, void 0, void 0, function () {
205
- var reqConfig, res, err_4, error;
206
- return __generator(this, function (_a) {
207
- switch (_a.label) {
208
- case 0:
209
- _a.trys.push([0, 2, , 3]);
210
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
211
- if (!this.disableDebugLogs) {
212
- this.logger.debug({
213
- reqConfig: reqConfig,
214
- url: url,
215
- targetService: this.targetService,
216
- msg: "Send DELTE message to ".concat(this.targetService, "."),
217
- });
218
- }
219
- return [4 /*yield*/, this.axiosClient.delete(url, reqConfig)];
220
- case 1:
221
- res = _a.sent();
222
- return [2 /*return*/, res.data];
223
- case 2:
224
- err_4 = _a.sent();
225
- error = this.wrapError(url, err_4);
226
- throw error;
227
- case 3: return [2 /*return*/];
228
- }
229
- });
230
- });
231
- };
232
- HttpClient.prototype.head = function (url, queryParams, retryConfig, auth, headers) {
233
- return __awaiter(this, void 0, void 0, function () {
234
- var reqConfig, res, err_5, error;
235
- return __generator(this, function (_a) {
236
- switch (_a.label) {
237
- case 0:
238
- _a.trys.push([0, 2, , 3]);
239
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
240
- if (!this.disableDebugLogs) {
241
- this.logger.debug({
242
- reqConfig: reqConfig,
243
- url: url,
244
- targetService: this.targetService,
245
- msg: "Send HEAD message to ".concat(this.targetService, "."),
246
- });
247
- }
248
- return [4 /*yield*/, this.axiosClient.head(url, reqConfig)];
249
- case 1:
250
- res = _a.sent();
251
- return [2 /*return*/, res.data];
252
- case 2:
253
- err_5 = _a.sent();
254
- error = this.wrapError(url, err_5);
255
- throw error;
256
- case 3: return [2 /*return*/];
257
- }
258
- });
259
- });
260
- };
261
- HttpClient.prototype.options = function (url, queryParams, retryConfig, auth, headers) {
262
- return __awaiter(this, void 0, void 0, function () {
263
- var reqConfig, res, err_6, error;
264
- return __generator(this, function (_a) {
265
- switch (_a.label) {
266
- case 0:
267
- _a.trys.push([0, 2, , 3]);
268
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
269
- if (!this.disableDebugLogs) {
270
- this.logger.debug({
271
- reqConfig: reqConfig,
272
- url: url,
273
- targetService: this.targetService,
274
- msg: "Send OPTIONS message to ".concat(this.targetService, "."),
275
- });
276
- }
277
- return [4 /*yield*/, this.axiosClient.options(url, reqConfig)];
278
- case 1:
279
- res = _a.sent();
280
- return [2 /*return*/, res.data];
281
- case 2:
282
- err_6 = _a.sent();
283
- error = this.wrapError(url, err_6);
284
- throw error;
285
- case 3: return [2 /*return*/];
286
- }
287
- });
288
- });
289
- };
290
- HttpClient.prototype.patch = function (url, body, queryParams, retryConfig, auth, headers) {
291
- return __awaiter(this, void 0, void 0, function () {
292
- var reqConfig, res, err_7, error;
293
- return __generator(this, function (_a) {
294
- switch (_a.label) {
295
- case 0:
296
- _a.trys.push([0, 2, , 3]);
297
- reqConfig = this.getRequestConfig(retryConfig, queryParams, auth, headers);
298
- if (!this.disableDebugLogs) {
299
- this.logger.debug({
300
- reqConfig: reqConfig,
301
- url: url,
302
- targetService: this.targetService,
303
- msg: "Send PATCH message to ".concat(this.targetService, "."),
304
- });
305
- }
306
- return [4 /*yield*/, this.axiosClient.patch(url, body, reqConfig)];
307
- case 1:
308
- res = _a.sent();
309
- return [2 /*return*/, res.data];
310
- case 2:
311
- err_7 = _a.sent();
312
- error = this.wrapError(url, err_7);
313
- throw error;
314
- case 3: return [2 /*return*/];
315
- }
316
- });
317
- });
318
- };
319
- HttpClient.prototype.getRequestConfig = function (retryConfig, queryParams, auth, headers) {
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) {
320
205
  // eslint-disable-next-line @typescript-eslint/naming-convention
321
- var reqConfig = retryConfig ? __assign(__assign({}, this.axiosOptions), { 'axios-retry': retryConfig }) : __assign({}, this.axiosOptions);
206
+ const reqConfig = retryConfig ? { ...this.axiosOptions, 'axios-retry': retryConfig } : { ...this.axiosOptions };
322
207
  if (queryParams !== undefined) {
323
- reqConfig.params = reqConfig.params !== undefined ? __assign(__assign({}, reqConfig.params), queryParams) : queryParams;
208
+ reqConfig.params = reqConfig.params !== undefined ? { ...reqConfig.params, ...queryParams } : queryParams;
324
209
  }
325
210
  if (auth !== undefined) {
326
211
  reqConfig.auth = auth;
327
212
  }
328
213
  if (headers !== undefined) {
329
- reqConfig.headers = reqConfig.headers !== undefined ? __assign(__assign({}, reqConfig.headers), headers) : headers;
214
+ reqConfig.headers = reqConfig.headers !== undefined ? { ...reqConfig.headers, ...headers } : headers;
330
215
  }
331
216
  return reqConfig;
332
- };
333
- HttpClient.prototype.wrapError = function (url, err, body) {
334
- var _a;
335
- var message = (0, lodash_1.get)(err, 'response.data.message', undefined);
336
- switch ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) {
217
+ }
218
+ wrapError(url, err, body) {
219
+ const message = (0, lodash_1.get)(err, 'response.data.message', undefined);
220
+ switch (err.response?.status) {
337
221
  case http_status_codes_1.default.BAD_REQUEST:
338
222
  if (!this.disableDebugLogs) {
339
223
  this.logger.debug({
340
- err: err,
341
- url: url,
342
- body: body,
224
+ err,
225
+ url,
226
+ body,
343
227
  targetService: this.targetService,
344
- msg: "invalid request error recieved from service ".concat(this.targetService, "."),
228
+ msg: `invalid request error recieved from service ${this.targetService}.`,
345
229
  msgError: err.message,
346
230
  });
347
231
  }
@@ -349,11 +233,11 @@ var HttpClient = /** @class */ (function () {
349
233
  case http_status_codes_1.default.NOT_FOUND:
350
234
  if (!this.disableDebugLogs) {
351
235
  this.logger.debug({
352
- err: err,
353
- url: url,
354
- body: body,
236
+ err,
237
+ url,
238
+ body,
355
239
  targetService: this.targetService,
356
- msg: "not found error recieved from service ".concat(this.targetService, "."),
240
+ msg: `not found error recieved from service ${this.targetService}.`,
357
241
  msgError: err.message,
358
242
  });
359
243
  }
@@ -361,11 +245,11 @@ var HttpClient = /** @class */ (function () {
361
245
  case http_status_codes_1.default.CONFLICT:
362
246
  if (!this.disableDebugLogs) {
363
247
  this.logger.debug({
364
- err: err,
365
- url: url,
366
- body: body,
248
+ err,
249
+ url,
250
+ body,
367
251
  targetService: this.targetService,
368
- msg: "conflict error recieved from service ".concat(this.targetService, "."),
252
+ msg: `conflict error recieved from service ${this.targetService}.`,
369
253
  msgError: err.message,
370
254
  });
371
255
  }
@@ -373,11 +257,11 @@ var HttpClient = /** @class */ (function () {
373
257
  case http_status_codes_1.default.FORBIDDEN:
374
258
  if (!this.disableDebugLogs) {
375
259
  this.logger.debug({
376
- err: err,
377
- url: url,
378
- body: body,
260
+ err,
261
+ url,
262
+ body,
379
263
  targetService: this.targetService,
380
- msg: "forbidden error recieved from service ".concat(this.targetService, "."),
264
+ msg: `forbidden error recieved from service ${this.targetService}.`,
381
265
  msgError: err.message,
382
266
  });
383
267
  }
@@ -385,38 +269,50 @@ var HttpClient = /** @class */ (function () {
385
269
  case http_status_codes_1.default.UNAUTHORIZED:
386
270
  if (!this.disableDebugLogs) {
387
271
  this.logger.debug({
388
- err: err,
389
- url: url,
390
- body: body,
272
+ err,
273
+ url,
274
+ body,
391
275
  targetService: this.targetService,
392
- msg: "unauthorized error recieved from service ".concat(this.targetService, "."),
276
+ msg: `unauthorized error recieved from service ${this.targetService}.`,
393
277
  msgError: err.message,
394
278
  });
395
279
  }
396
280
  throw 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 recieved from service ${this.targetService}.`,
289
+ msgError: err.message,
290
+ });
291
+ }
292
+ throw new error_types_1.MethodNotAllowedError(err, message);
397
293
  default:
398
294
  this.logger.error({
399
- err: err,
400
- url: url,
401
- body: body,
295
+ err,
296
+ url,
297
+ body,
402
298
  targetService: this.targetService,
403
- msg: "Internal Server Error recieved from service ".concat(this.targetService, "."),
299
+ msg: `Internal Server Error recieved from service ${this.targetService}.`,
404
300
  msgError: err.message,
405
301
  });
406
302
  return new error_types_1.InternalServerError(err);
407
303
  }
408
- };
409
- HttpClient.prototype.parseConfig = function (config) {
410
- var retries = config.attempts - 1;
304
+ }
305
+ parseConfig(config) {
306
+ const retries = config.attempts - 1;
411
307
  if (retries < 0) {
412
308
  throw new Error('invalid retry configuration: attempts must be positive');
413
309
  }
414
- var delay;
310
+ let delay;
415
311
  if (config.delay === 'exponential') {
416
312
  delay = axios_retry_1.exponentialDelay;
417
313
  }
418
314
  else if (typeof config.delay === 'number') {
419
- delay = function () {
315
+ delay = () => {
420
316
  return config.delay;
421
317
  };
422
318
  }
@@ -428,8 +324,7 @@ var HttpClient = /** @class */ (function () {
428
324
  retryDelay: delay,
429
325
  shouldResetTimeout: config.shouldResetTimeout,
430
326
  };
431
- };
432
- return HttpClient;
433
- }());
327
+ }
328
+ }
434
329
  exports.HttpClient = HttpClient;
435
330
  //# sourceMappingURL=httpClient.js.map