@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.
- package/README.md +0 -0
- package/dist/arrays/index.d.ts +0 -0
- package/dist/arrays/index.d.ts.map +0 -0
- package/dist/arrays/index.js +0 -0
- package/dist/arrays/index.js.map +0 -0
- package/dist/arrays/subGroups.d.ts +0 -0
- package/dist/arrays/subGroups.d.ts.map +0 -0
- package/dist/arrays/subGroups.js +20 -125
- package/dist/arrays/subGroups.js.map +1 -1
- package/dist/communication/http/httpClient.d.ts +0 -0
- package/dist/communication/http/httpClient.d.ts.map +1 -1
- package/dist/communication/http/httpClient.js +206 -311
- package/dist/communication/http/httpClient.js.map +1 -1
- package/dist/communication/http/index.d.ts +0 -0
- package/dist/communication/http/index.d.ts.map +0 -0
- package/dist/communication/http/index.js +0 -0
- package/dist/communication/http/index.js.map +0 -0
- package/dist/communication/index.d.ts +0 -0
- package/dist/communication/index.d.ts.map +0 -0
- package/dist/communication/index.js +0 -0
- package/dist/communication/index.js.map +0 -0
- package/dist/dateTime/getUTCDate.d.ts +0 -0
- package/dist/dateTime/getUTCDate.d.ts.map +0 -0
- package/dist/dateTime/getUTCDate.js +4 -4
- package/dist/dateTime/getUTCDate.js.map +1 -1
- package/dist/dateTime/index.d.ts +0 -0
- package/dist/dateTime/index.d.ts.map +0 -0
- package/dist/dateTime/index.js +0 -0
- package/dist/dateTime/index.js.map +0 -0
- package/dist/geo/bboxUtils.d.ts +0 -0
- package/dist/geo/bboxUtils.d.ts.map +0 -0
- package/dist/geo/bboxUtils.js +24 -24
- package/dist/geo/bboxUtils.js.map +1 -1
- package/dist/geo/geoConvertor.d.ts +0 -0
- package/dist/geo/geoConvertor.d.ts.map +0 -0
- package/dist/geo/geoConvertor.js +13 -15
- package/dist/geo/geoConvertor.js.map +1 -1
- package/dist/geo/geoHash.d.ts +0 -0
- package/dist/geo/geoHash.d.ts.map +0 -0
- package/dist/geo/geoHash.js +65 -205
- package/dist/geo/geoHash.js.map +1 -1
- package/dist/geo/geoIntersection.d.ts +0 -0
- package/dist/geo/geoIntersection.d.ts.map +0 -0
- package/dist/geo/geoIntersection.js +14 -14
- package/dist/geo/geoIntersection.js.map +1 -1
- package/dist/geo/index.d.ts +0 -0
- package/dist/geo/index.d.ts.map +0 -0
- package/dist/geo/index.js +0 -0
- package/dist/geo/index.js.map +0 -0
- package/dist/geo/tileBatcher.d.ts +0 -0
- package/dist/geo/tileBatcher.d.ts.map +0 -0
- package/dist/geo/tileBatcher.js +65 -161
- package/dist/geo/tileBatcher.js.map +1 -1
- package/dist/geo/tileRanger.d.ts +0 -0
- package/dist/geo/tileRanger.d.ts.map +0 -0
- package/dist/geo/tileRanger.js +165 -316
- package/dist/geo/tileRanger.js.map +1 -1
- package/dist/geo/tiles.d.ts +0 -0
- package/dist/geo/tiles.d.ts.map +0 -0
- package/dist/geo/tiles.js +29 -56
- package/dist/geo/tiles.js.map +1 -1
- package/dist/geo/tilesGenerator.d.ts +0 -0
- package/dist/geo/tilesGenerator.d.ts.map +0 -0
- package/dist/geo/tilesGenerator.js +11 -105
- package/dist/geo/tilesGenerator.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/models/enums/gdal/dataType.d.ts +0 -0
- package/dist/models/enums/gdal/dataType.d.ts.map +0 -0
- package/dist/models/enums/gdal/dataType.js +0 -0
- package/dist/models/enums/gdal/dataType.js.map +0 -0
- package/dist/models/enums/gdal/index.d.ts +0 -0
- package/dist/models/enums/gdal/index.d.ts.map +0 -0
- package/dist/models/enums/gdal/index.js +0 -0
- package/dist/models/enums/gdal/index.js.map +0 -0
- package/dist/models/enums/gdal/resamplingMethod.d.ts +0 -0
- package/dist/models/enums/gdal/resamplingMethod.d.ts.map +0 -0
- package/dist/models/enums/gdal/resamplingMethod.js +0 -0
- package/dist/models/enums/gdal/resamplingMethod.js.map +0 -0
- package/dist/models/enums/geo/index.d.ts +0 -0
- package/dist/models/enums/geo/index.d.ts.map +0 -0
- package/dist/models/enums/geo/index.js +0 -0
- package/dist/models/enums/geo/index.js.map +0 -0
- package/dist/models/enums/geo/tileOrigin.d.ts +0 -0
- package/dist/models/enums/geo/tileOrigin.d.ts.map +0 -0
- package/dist/models/enums/geo/tileOrigin.js +0 -0
- package/dist/models/enums/geo/tileOrigin.js.map +0 -0
- package/dist/models/enums/index.d.ts +0 -0
- package/dist/models/enums/index.d.ts.map +0 -0
- package/dist/models/enums/index.js +0 -0
- package/dist/models/enums/index.js.map +0 -0
- package/dist/models/index.d.ts +0 -0
- package/dist/models/index.d.ts.map +0 -0
- package/dist/models/index.js +0 -0
- package/dist/models/index.js.map +0 -0
- package/dist/models/interfaces/geo/iPoint.d.ts +0 -0
- package/dist/models/interfaces/geo/iPoint.d.ts.map +0 -0
- package/dist/models/interfaces/geo/iPoint.js +0 -0
- package/dist/models/interfaces/geo/iPoint.js.map +0 -0
- package/dist/models/interfaces/geo/iTile.d.ts +0 -0
- package/dist/models/interfaces/geo/iTile.d.ts.map +0 -0
- package/dist/models/interfaces/geo/iTile.js +0 -0
- package/dist/models/interfaces/geo/iTile.js.map +0 -0
- package/dist/models/interfaces/geo/index.d.ts +0 -0
- package/dist/models/interfaces/geo/index.d.ts.map +0 -0
- package/dist/models/interfaces/geo/index.js +0 -0
- package/dist/models/interfaces/geo/index.js.map +0 -0
- package/dist/models/interfaces/index.d.ts +0 -0
- package/dist/models/interfaces/index.d.ts.map +0 -0
- package/dist/models/interfaces/index.js +0 -0
- package/dist/models/interfaces/index.js.map +0 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/timeout.d.ts +3 -0
- package/dist/utils/timeout.d.ts.map +1 -1
- package/dist/utils/timeout.js +18 -43
- package/dist/utils/timeout.js.map +1 -1
- 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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
51
|
+
const axiosRetryConfig = retryConfig
|
|
97
52
|
? this.parseConfig(retryConfig)
|
|
98
53
|
: {
|
|
99
54
|
retries: 0,
|
|
100
55
|
};
|
|
101
|
-
|
|
102
|
-
axiosRetryConfig.retryDelay =
|
|
103
|
-
|
|
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:
|
|
107
|
-
msg:
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
206
|
+
const reqConfig = retryConfig ? { ...this.axiosOptions, 'axios-retry': retryConfig } : { ...this.axiosOptions };
|
|
322
207
|
if (queryParams !== undefined) {
|
|
323
|
-
reqConfig.params = reqConfig.params !== undefined ?
|
|
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 ?
|
|
214
|
+
reqConfig.headers = reqConfig.headers !== undefined ? { ...reqConfig.headers, ...headers } : headers;
|
|
330
215
|
}
|
|
331
216
|
return reqConfig;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
|
341
|
-
url
|
|
342
|
-
body
|
|
224
|
+
err,
|
|
225
|
+
url,
|
|
226
|
+
body,
|
|
343
227
|
targetService: this.targetService,
|
|
344
|
-
msg:
|
|
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
|
|
353
|
-
url
|
|
354
|
-
body
|
|
236
|
+
err,
|
|
237
|
+
url,
|
|
238
|
+
body,
|
|
355
239
|
targetService: this.targetService,
|
|
356
|
-
msg:
|
|
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
|
|
365
|
-
url
|
|
366
|
-
body
|
|
248
|
+
err,
|
|
249
|
+
url,
|
|
250
|
+
body,
|
|
367
251
|
targetService: this.targetService,
|
|
368
|
-
msg:
|
|
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
|
|
377
|
-
url
|
|
378
|
-
body
|
|
260
|
+
err,
|
|
261
|
+
url,
|
|
262
|
+
body,
|
|
379
263
|
targetService: this.targetService,
|
|
380
|
-
msg:
|
|
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
|
|
389
|
-
url
|
|
390
|
-
body
|
|
272
|
+
err,
|
|
273
|
+
url,
|
|
274
|
+
body,
|
|
391
275
|
targetService: this.targetService,
|
|
392
|
-
msg:
|
|
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
|
|
400
|
-
url
|
|
401
|
-
body
|
|
295
|
+
err,
|
|
296
|
+
url,
|
|
297
|
+
body,
|
|
402
298
|
targetService: this.targetService,
|
|
403
|
-
msg:
|
|
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
|
-
|
|
410
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
433
|
-
}());
|
|
327
|
+
}
|
|
328
|
+
}
|
|
434
329
|
exports.HttpClient = HttpClient;
|
|
435
330
|
//# sourceMappingURL=httpClient.js.map
|