getta 0.3.0 → 0.4.1
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/CHANGELOG.md +12 -0
- package/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/production.analysis.txt +19 -19
- package/lib/main/constants.js +6 -2
- package/lib/main/main.js +134 -55
- package/lib/module/constants.js +3 -1
- package/lib/module/main.js +137 -56
- package/lib/types/constants.d.ts +2 -0
- package/lib/types/constants.d.ts.map +1 -1
- package/lib/types/main.d.ts +7 -4
- package/lib/types/main.d.ts.map +1 -1
- package/lib/types/types.d.ts +8 -1
- package/lib/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +3 -0
- package/src/main.test.ts +7 -6
- package/src/main.ts +121 -51
- package/src/types.ts +11 -1
package/lib/module/main.js
CHANGED
|
@@ -3,7 +3,7 @@ import _merge from "lodash/merge";
|
|
|
3
3
|
import _castArray from "lodash/castArray";
|
|
4
4
|
import "core-js/modules/es.promise.js";
|
|
5
5
|
import md5 from "md5";
|
|
6
|
-
import { CACHE_CONTROL_HEADER, DEFAULT_BODY_PARSER, DEFAULT_FETCH_TIMEOUT, DEFAULT_HEADERS, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES, DEFAULT_PATH_TEMPLATE_REGEX, DEFAULT_RATE_LIMIT, DEFAULT_REQUEST_RETRY_WAIT, DELETE_METHOD, ETAG_HEADER, FETCH_METHODS, FETCH_TIMEOUT_ERROR, GET_METHOD, IF_NONE_MATCH_HEADER, INVALID_FETCH_METHOD_ERROR, JSON_FORMAT, LOCATION_HEADER, MAX_REDIRECTS_EXCEEDED_ERROR, MAX_RETRIES_EXCEEDED_ERROR, MISSING_BASE_PATH_ERROR, NOT_FOUND_STATUS_CODE, NOT_MODIFIED_STATUS_CODE, OPTIONAL_PATH_TEMPLATE_REGEX, POST_METHOD, PUT_METHOD, REDIRECTION_REPSONSE, RESOURCE_NOT_FOUND_ERROR, SERVER_ERROR_REPSONSE } from "./constants";
|
|
6
|
+
import { CACHE_CONTROL_HEADER, DEFAULT_BODY_PARSER, DEFAULT_FETCH_TIMEOUT, DEFAULT_HEADERS, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES, DEFAULT_PATH_TEMPLATE_REGEX, DEFAULT_RATE_LIMIT, DEFAULT_REQUEST_RETRY_WAIT, DELETE_METHOD, ETAG_HEADER, FETCH_METHODS, FETCH_TIMEOUT_ERROR, GET_METHOD, IF_NONE_MATCH_HEADER, INVALID_FETCH_METHOD_ERROR, JSON_FORMAT, LOCATION_HEADER, MAX_REDIRECTS_EXCEEDED_ERROR, MAX_RETRIES_EXCEEDED_ERROR, MISSING_BASE_PATH_ERROR, NOT_FOUND_STATUS_CODE, NOT_MODIFIED_STATUS_CODE, OPTIONAL_PATH_TEMPLATE_REGEX, POST_METHOD, PUT_METHOD, REDIRECTION_REPSONSE, REQUEST_SENT, RESOURCE_NOT_FOUND_ERROR, RESPONSE_RECEIVED, SERVER_ERROR_REPSONSE } from "./constants";
|
|
7
7
|
import buildEndpoint from "./helpers/build-endpoint";
|
|
8
8
|
import defaultPathTemplateCallback from "./helpers/default-path-template-callback";
|
|
9
9
|
import delay from "./helpers/delay";
|
|
@@ -23,6 +23,8 @@ export class Getta {
|
|
|
23
23
|
|
|
24
24
|
_defineProperty(this, "_headers", void 0);
|
|
25
25
|
|
|
26
|
+
_defineProperty(this, "_log", void 0);
|
|
27
|
+
|
|
26
28
|
_defineProperty(this, "_maxRedirects", void 0);
|
|
27
29
|
|
|
28
30
|
_defineProperty(this, "_maxRetries", void 0);
|
|
@@ -33,6 +35,8 @@ export class Getta {
|
|
|
33
35
|
|
|
34
36
|
_defineProperty(this, "_pathTemplateRegExp", void 0);
|
|
35
37
|
|
|
38
|
+
_defineProperty(this, "_performance", void 0);
|
|
39
|
+
|
|
36
40
|
_defineProperty(this, "_queryParams", void 0);
|
|
37
41
|
|
|
38
42
|
_defineProperty(this, "_rateLimitCount", 0);
|
|
@@ -59,11 +63,13 @@ export class Getta {
|
|
|
59
63
|
enableConditionalRequests = true,
|
|
60
64
|
fetchTimeout = DEFAULT_FETCH_TIMEOUT,
|
|
61
65
|
headers,
|
|
66
|
+
log,
|
|
62
67
|
maxRedirects = DEFAULT_MAX_REDIRECTS,
|
|
63
68
|
maxRetries = DEFAULT_MAX_RETRIES,
|
|
64
69
|
optionalPathTemplateRegExp = OPTIONAL_PATH_TEMPLATE_REGEX,
|
|
65
70
|
pathTemplateCallback = defaultPathTemplateCallback,
|
|
66
71
|
pathTemplateRegExp = DEFAULT_PATH_TEMPLATE_REGEX,
|
|
72
|
+
performance,
|
|
67
73
|
queryParams = {},
|
|
68
74
|
rateLimitPerSecond = DEFAULT_RATE_LIMIT,
|
|
69
75
|
requestRetryWait = DEFAULT_REQUEST_RETRY_WAIT,
|
|
@@ -82,11 +88,13 @@ export class Getta {
|
|
|
82
88
|
this._headers = { ...DEFAULT_HEADERS,
|
|
83
89
|
...(headers || {})
|
|
84
90
|
};
|
|
91
|
+
this._log = log;
|
|
85
92
|
this._maxRedirects = maxRedirects;
|
|
86
93
|
this._maxRetries = maxRetries;
|
|
87
94
|
this._optionalPathTemplateRegExp = optionalPathTemplateRegExp;
|
|
88
95
|
this._pathTemplateCallback = pathTemplateCallback;
|
|
89
96
|
this._pathTemplateRegExp = pathTemplateRegExp;
|
|
97
|
+
this._performance = performance;
|
|
90
98
|
this._queryParams = queryParams;
|
|
91
99
|
this._rateLimitPerSecond = rateLimitPerSecond;
|
|
92
100
|
this._requestRetryWait = requestRetryWait;
|
|
@@ -111,29 +119,29 @@ export class Getta {
|
|
|
111
119
|
} = {}) => this[requestMethod !== null && requestMethod !== void 0 ? requestMethod : method](path, _merge({}, rest, requestRest));
|
|
112
120
|
}
|
|
113
121
|
|
|
114
|
-
async delete(path, options = {}) {
|
|
115
|
-
return this._delete(path, options);
|
|
122
|
+
async delete(path, options = {}, context) {
|
|
123
|
+
return this._delete(path, options, context);
|
|
116
124
|
}
|
|
117
125
|
|
|
118
|
-
async get(path, options = {}) {
|
|
119
|
-
return this._get(path, options);
|
|
126
|
+
async get(path, options = {}, context) {
|
|
127
|
+
return this._get(path, options, context);
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
async post(path, options) {
|
|
130
|
+
async post(path, options, context) {
|
|
123
131
|
return this._request(path, { ...options,
|
|
124
132
|
method: POST_METHOD
|
|
125
|
-
});
|
|
133
|
+
}, context);
|
|
126
134
|
}
|
|
127
135
|
|
|
128
|
-
async put(path, options) {
|
|
136
|
+
async put(path, options, context) {
|
|
129
137
|
return this._request(path, { ...options,
|
|
130
138
|
method: PUT_METHOD
|
|
131
|
-
});
|
|
139
|
+
}, context);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
|
-
_addRequestToRateLimitedQueue(endpoint, options) {
|
|
142
|
+
_addRequestToRateLimitedQueue(endpoint, options, context) {
|
|
135
143
|
return new Promise(resolve => {
|
|
136
|
-
this._rateLimitedRequestQueue.push([resolve, endpoint, options]);
|
|
144
|
+
this._rateLimitedRequestQueue.push([resolve, endpoint, options, context]);
|
|
137
145
|
});
|
|
138
146
|
}
|
|
139
147
|
|
|
@@ -184,7 +192,7 @@ export class Getta {
|
|
|
184
192
|
pathTemplateData,
|
|
185
193
|
queryParams = {},
|
|
186
194
|
...rest
|
|
187
|
-
}) {
|
|
195
|
+
}, context) {
|
|
188
196
|
const endpoint = buildEndpoint(this._basePath, path, {
|
|
189
197
|
optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,
|
|
190
198
|
pathTemplateCallback: this._pathTemplateCallback,
|
|
@@ -207,15 +215,18 @@ export class Getta {
|
|
|
207
215
|
},
|
|
208
216
|
method: DELETE_METHOD,
|
|
209
217
|
...rest
|
|
210
|
-
});
|
|
218
|
+
}, context);
|
|
211
219
|
}
|
|
212
220
|
|
|
213
|
-
async _fetch(endpoint, {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
...rest
|
|
217
|
-
}) {
|
|
221
|
+
async _fetch(endpoint, options, context = {}) {
|
|
222
|
+
context.startTime = this._performance.now();
|
|
223
|
+
|
|
218
224
|
try {
|
|
225
|
+
const {
|
|
226
|
+
redirects,
|
|
227
|
+
retries,
|
|
228
|
+
...rest
|
|
229
|
+
} = options;
|
|
219
230
|
return new Promise(async (resolve, reject) => {
|
|
220
231
|
const fetchTimer = setTimeout(() => {
|
|
221
232
|
reject(new Error(`${FETCH_TIMEOUT_ERROR} ${this._fetchTimeout}ms.`));
|
|
@@ -224,14 +235,27 @@ export class Getta {
|
|
|
224
235
|
this._rateLimit();
|
|
225
236
|
|
|
226
237
|
if (!(this._rateLimitCount < this._rateLimitPerSecond)) {
|
|
227
|
-
resolve(await this._addRequestToRateLimitedQueue(endpoint,
|
|
228
|
-
redirects,
|
|
229
|
-
retries,
|
|
230
|
-
...rest
|
|
231
|
-
}));
|
|
238
|
+
resolve(await this._addRequestToRateLimitedQueue(endpoint, options, context));
|
|
232
239
|
return;
|
|
233
240
|
}
|
|
234
241
|
|
|
242
|
+
if (!redirects && !retries) {
|
|
243
|
+
var _this$_log;
|
|
244
|
+
|
|
245
|
+
(_this$_log = this._log) === null || _this$_log === void 0 ? void 0 : _this$_log.call(this, REQUEST_SENT, {
|
|
246
|
+
context: {
|
|
247
|
+
redirects,
|
|
248
|
+
retries,
|
|
249
|
+
url: endpoint,
|
|
250
|
+
...rest,
|
|
251
|
+
...context
|
|
252
|
+
},
|
|
253
|
+
stats: {
|
|
254
|
+
startTime: context.startTime
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
235
259
|
const res = await fetch(endpoint, rest);
|
|
236
260
|
clearTimeout(fetchTimer);
|
|
237
261
|
const {
|
|
@@ -241,19 +265,19 @@ export class Getta {
|
|
|
241
265
|
const responseGroup = getResponseGroup(status);
|
|
242
266
|
|
|
243
267
|
if (responseGroup === REDIRECTION_REPSONSE && headers.get(LOCATION_HEADER)) {
|
|
244
|
-
resolve(await this._fetchRedirectHandler(headers.get(LOCATION_HEADER), {
|
|
268
|
+
resolve(await this._fetchRedirectHandler(res, headers.get(LOCATION_HEADER), {
|
|
245
269
|
redirects,
|
|
246
270
|
status,
|
|
247
271
|
...rest
|
|
248
|
-
}));
|
|
272
|
+
}, context));
|
|
249
273
|
return;
|
|
250
274
|
}
|
|
251
275
|
|
|
252
276
|
if (responseGroup === SERVER_ERROR_REPSONSE) {
|
|
253
|
-
resolve(await this._fetchRetryHandler(endpoint, {
|
|
277
|
+
resolve(await this._fetchRetryHandler(res, endpoint, {
|
|
254
278
|
retries,
|
|
255
279
|
...rest
|
|
256
|
-
}));
|
|
280
|
+
}, context));
|
|
257
281
|
return;
|
|
258
282
|
}
|
|
259
283
|
|
|
@@ -261,55 +285,68 @@ export class Getta {
|
|
|
261
285
|
|
|
262
286
|
try {
|
|
263
287
|
fetchRes.data = res.body ? this._bodyParser(await res[this._streamReader]()) : undefined;
|
|
288
|
+
|
|
289
|
+
this._logResponse(fetchRes, endpoint, options, context);
|
|
290
|
+
|
|
264
291
|
resolve(fetchRes);
|
|
265
292
|
} catch (e) {
|
|
266
293
|
reject([e, new Error(`Unable to ${rest.method} ${endpoint} due to previous error`)]);
|
|
267
294
|
}
|
|
268
295
|
});
|
|
269
296
|
} catch (error) {
|
|
270
|
-
const
|
|
297
|
+
const fetchRes = {
|
|
271
298
|
errors: _castArray(error)
|
|
272
299
|
};
|
|
273
|
-
|
|
300
|
+
|
|
301
|
+
this._logResponse(fetchRes, endpoint, options, context);
|
|
302
|
+
|
|
303
|
+
return fetchRes;
|
|
274
304
|
}
|
|
275
305
|
}
|
|
276
306
|
|
|
277
|
-
async _fetchRedirectHandler(endpoint, {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
307
|
+
async _fetchRedirectHandler(res, endpoint, options, context) {
|
|
308
|
+
const {
|
|
309
|
+
method,
|
|
310
|
+
redirects = 1,
|
|
311
|
+
status,
|
|
312
|
+
...rest
|
|
313
|
+
} = options;
|
|
314
|
+
|
|
283
315
|
if (redirects === this._maxRedirects) {
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
316
|
+
const fetchRes = res;
|
|
317
|
+
fetchRes.errors = [new Error(`${MAX_REDIRECTS_EXCEEDED_ERROR} ${this._maxRedirects}.`)];
|
|
318
|
+
|
|
319
|
+
this._logResponse(fetchRes, endpoint, options, context);
|
|
320
|
+
|
|
321
|
+
return fetchRes;
|
|
288
322
|
}
|
|
289
323
|
|
|
290
|
-
redirects += 1;
|
|
291
324
|
const redirectMethod = status === 303 ? GET_METHOD : method;
|
|
292
325
|
return this._fetch(endpoint, {
|
|
293
326
|
method: redirectMethod,
|
|
294
|
-
redirects,
|
|
327
|
+
redirects: redirects + 1,
|
|
295
328
|
...rest
|
|
296
329
|
});
|
|
297
330
|
}
|
|
298
331
|
|
|
299
|
-
async _fetchRetryHandler(endpoint, {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
332
|
+
async _fetchRetryHandler(res, endpoint, options, context) {
|
|
333
|
+
const {
|
|
334
|
+
retries = 1,
|
|
335
|
+
...rest
|
|
336
|
+
} = options;
|
|
337
|
+
|
|
303
338
|
if (retries === this._maxRetries) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
339
|
+
const fetchRes = res;
|
|
340
|
+
fetchRes.errors = [new Error(`${MAX_RETRIES_EXCEEDED_ERROR} ${this._maxRetries}.`)];
|
|
341
|
+
|
|
342
|
+
this._logResponse(fetchRes, endpoint, options, context);
|
|
343
|
+
|
|
344
|
+
return fetchRes;
|
|
307
345
|
}
|
|
308
346
|
|
|
309
|
-
retries += 1;
|
|
310
347
|
await delay(this._requestRetryWait);
|
|
311
348
|
return this._fetch(endpoint, {
|
|
312
|
-
retries,
|
|
349
|
+
retries: retries + 1,
|
|
313
350
|
...rest
|
|
314
351
|
});
|
|
315
352
|
}
|
|
@@ -318,7 +355,7 @@ export class Getta {
|
|
|
318
355
|
headers = {},
|
|
319
356
|
pathTemplateData,
|
|
320
357
|
queryParams = {}
|
|
321
|
-
}) {
|
|
358
|
+
}, context) {
|
|
322
359
|
const endpoint = buildEndpoint(this._basePath, path, {
|
|
323
360
|
optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,
|
|
324
361
|
pathTemplateCallback: this._pathTemplateCallback,
|
|
@@ -357,7 +394,7 @@ export class Getta {
|
|
|
357
394
|
...headers
|
|
358
395
|
},
|
|
359
396
|
method: GET_METHOD
|
|
360
|
-
}));
|
|
397
|
+
}, context));
|
|
361
398
|
}
|
|
362
399
|
|
|
363
400
|
async _getResolve(requestHash, res) {
|
|
@@ -399,6 +436,50 @@ export class Getta {
|
|
|
399
436
|
return res;
|
|
400
437
|
}
|
|
401
438
|
|
|
439
|
+
_logResponse(res, endpoint, options, context) {
|
|
440
|
+
var _this$_log2;
|
|
441
|
+
|
|
442
|
+
const {
|
|
443
|
+
data,
|
|
444
|
+
errors,
|
|
445
|
+
headers,
|
|
446
|
+
status
|
|
447
|
+
} = res;
|
|
448
|
+
const {
|
|
449
|
+
redirects,
|
|
450
|
+
retries
|
|
451
|
+
} = options;
|
|
452
|
+
const {
|
|
453
|
+
startTime,
|
|
454
|
+
...otherContext
|
|
455
|
+
} = context;
|
|
456
|
+
|
|
457
|
+
const endTime = this._performance.now();
|
|
458
|
+
|
|
459
|
+
const duration = endTime - startTime;
|
|
460
|
+
(_this$_log2 = this._log) === null || _this$_log2 === void 0 ? void 0 : _this$_log2.call(this, RESPONSE_RECEIVED, {
|
|
461
|
+
context: {
|
|
462
|
+
body: data ? {
|
|
463
|
+
data
|
|
464
|
+
} : {
|
|
465
|
+
errors: errors !== null && errors !== void 0 ? errors : []
|
|
466
|
+
},
|
|
467
|
+
headers,
|
|
468
|
+
method: options.method,
|
|
469
|
+
redirects,
|
|
470
|
+
retries,
|
|
471
|
+
status,
|
|
472
|
+
url: endpoint,
|
|
473
|
+
...otherContext
|
|
474
|
+
},
|
|
475
|
+
stats: {
|
|
476
|
+
duration,
|
|
477
|
+
endTime,
|
|
478
|
+
startTime
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
402
483
|
_rateLimit() {
|
|
403
484
|
if (!this._rateLimitTimer) {
|
|
404
485
|
this._rateLimitTimer = setTimeout(() => {
|
|
@@ -415,8 +496,8 @@ export class Getta {
|
|
|
415
496
|
}
|
|
416
497
|
|
|
417
498
|
_releaseRateLimitedRequestQueue() {
|
|
418
|
-
this._rateLimitedRequestQueue.forEach(async ([resolve, endpoint, options]) => {
|
|
419
|
-
resolve(await this._fetch(endpoint, options));
|
|
499
|
+
this._rateLimitedRequestQueue.forEach(async ([resolve, endpoint, options, context]) => {
|
|
500
|
+
resolve(await this._fetch(endpoint, options, context));
|
|
420
501
|
});
|
|
421
502
|
|
|
422
503
|
this._rateLimitedRequestQueue = [];
|
|
@@ -429,7 +510,7 @@ export class Getta {
|
|
|
429
510
|
pathTemplateData,
|
|
430
511
|
queryParams,
|
|
431
512
|
...rest
|
|
432
|
-
}) {
|
|
513
|
+
}, context) {
|
|
433
514
|
const endpoint = buildEndpoint(this._basePath, path, {
|
|
434
515
|
optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,
|
|
435
516
|
pathTemplateCallback: this._pathTemplateCallback,
|
|
@@ -446,7 +527,7 @@ export class Getta {
|
|
|
446
527
|
},
|
|
447
528
|
method,
|
|
448
529
|
...rest
|
|
449
|
-
});
|
|
530
|
+
}, context);
|
|
450
531
|
}
|
|
451
532
|
|
|
452
533
|
_resolvePendingRequests(requestHash, responseData) {
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -45,4 +45,6 @@ export declare const ETAG_HEADER: "ETag";
|
|
|
45
45
|
export declare const LOCATION_HEADER: "Location";
|
|
46
46
|
export declare const IF_NONE_MATCH_HEADER: "If-None-Match";
|
|
47
47
|
export declare const CACHE_CONTROL_HEADER: "Cache-Control";
|
|
48
|
+
export declare const REQUEST_SENT: "request_sent";
|
|
49
|
+
export declare const RESPONSE_RECEIVED: "response_received";
|
|
48
50
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,eAAO,MAAM,mBAAmB,eAAyB,CAAC;AAC1D,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,gBAAgB,YAAsB,CAAC;AACpD,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,WAAW,QAAkB,CAAC;AAE3C,eAAO,MAAM,cAAc;;;;;;CAM1B,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,WAAW,gBAAS,CAAC;AAC/D,eAAO,MAAM,qBAAqB,MAAgB,CAAC;AACnD,eAAO,MAAM,eAAe;;CAAyC,CAAC;AACtE,eAAO,MAAM,qBAAqB,GAAa,CAAC;AAChD,eAAO,MAAM,mBAAmB,GAAa,CAAC;AAC9C,eAAO,MAAM,2BAA2B,QAAmD,CAAC;AAC5F,eAAO,MAAM,4BAA4B,QAAyB,CAAC;AACnE,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,eAAO,MAAM,uBAAuB,gGACV,CAAC;AAE3B,eAAO,MAAM,4BAA4B,mEAAmE,CAAC;AAE7G,eAAO,MAAM,0BAA0B,iEAAiE,CAAC;AAEzG,eAAO,MAAM,0BAA0B,6EAA6E,CAAC;AAErH,eAAO,MAAM,wBAAwB,iDAAiD,CAAC;AAEvF,eAAO,MAAM,mBAAmB,+DAA+D,CAAC;AAEhG,eAAO,MAAM,UAAU,OAAiB,CAAC;AACzC,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,UAAU,OAAiB,CAAC;AACzC,eAAO,MA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CAAC;AACrC,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,eAAO,MAAM,uBAAuB,gGACV,CAAC;AAE3B,eAAO,MAAM,4BAA4B,mEAAmE,CAAC;AAE7G,eAAO,MAAM,0BAA0B,iEAAiE,CAAC;AAEzG,eAAO,MAAM,0BAA0B,6EAA6E,CAAC;AAErH,eAAO,MAAM,wBAAwB,iDAAiD,CAAC;AAEvF,eAAO,MAAM,mBAAmB,+DAA+D,CAAC;AAEhG,eAAO,MAAM,UAAU,OAAiB,CAAC;AACzC,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,UAAU,OAAiB,CAAC;AACzC,eAAO,MAAM,aAAa,UAAoB,CAAC;AAE/C,eAAO,MAAM,aAAa,uCAAuD,CAAC;AAElF,eAAO,MAAM,oBAAoB,eAAyB,CAAC;AAC3D,eAAO,MAAM,mBAAmB,cAAwB,CAAC;AACzD,eAAO,MAAM,oBAAoB,eAAyB,CAAC;AAC3D,eAAO,MAAM,qBAAqB,eAAyB,CAAC;AAC5D,eAAO,MAAM,qBAAqB,eAAyB,CAAC;AAE5D,eAAO,MAAM,wBAAwB,KAAe,CAAC;AACrD,eAAO,MAAM,qBAAqB,KAAe,CAAC;AAElD,eAAO,MAAM,aAAa,UAAoB,CAAC;AAC/C,eAAO,MAAM,WAAW,QAAkB,CAAC;AAC3C,eAAO,MAAM,eAAe,YAAsB,CAAC;AACnD,eAAO,MAAM,oBAAoB,iBAA2B,CAAC;AAC7D,eAAO,MAAM,oBAAoB,iBAA2B,CAAC;AAE7D,eAAO,MAAM,YAAY,gBAA0B,CAAC;AACpD,eAAO,MAAM,iBAAiB,qBAA+B,CAAC"}
|
package/lib/types/main.d.ts
CHANGED
|
@@ -9,11 +9,13 @@ export declare class Getta {
|
|
|
9
9
|
private _conditionalRequestsEnabled;
|
|
10
10
|
private _fetchTimeout;
|
|
11
11
|
private _headers;
|
|
12
|
+
private _log;
|
|
12
13
|
private _maxRedirects;
|
|
13
14
|
private _maxRetries;
|
|
14
15
|
private _optionalPathTemplateRegExp;
|
|
15
16
|
private _pathTemplateCallback;
|
|
16
17
|
private _pathTemplateRegExp;
|
|
18
|
+
private _performance;
|
|
17
19
|
private _queryParams;
|
|
18
20
|
private _rateLimitCount;
|
|
19
21
|
private _rateLimitedRequestQueue;
|
|
@@ -25,13 +27,13 @@ export declare class Getta {
|
|
|
25
27
|
constructor(options: ConstructorOptions);
|
|
26
28
|
get cache(): Cachemap | undefined;
|
|
27
29
|
createShortcut(name: string, path: string, { method, ...rest }: Required<RequestOptions, "method">): void;
|
|
28
|
-
delete(path: string, options?: Omit<RequestOptions, "method"
|
|
29
|
-
get(path: string, options?: Omit<RequestOptions, "method"
|
|
30
|
+
delete(path: string, options?: Omit<RequestOptions, "method">, context?: PlainObject): Promise<FetchResponse<PlainObject>>;
|
|
31
|
+
get(path: string, options?: Omit<RequestOptions, "method">, context?: PlainObject): Promise<FetchResponse<PlainObject> | {
|
|
30
32
|
data: PlainObject | undefined;
|
|
31
33
|
headers: Headers;
|
|
32
34
|
}>;
|
|
33
|
-
post(path: string, options: Omit<Required<RequestOptions, "body">, "method"
|
|
34
|
-
put(path: string, options: Omit<Required<RequestOptions, "body">, "methood"
|
|
35
|
+
post(path: string, options: Omit<Required<RequestOptions, "body">, "method">, context?: PlainObject): Promise<FetchResponse<PlainObject>>;
|
|
36
|
+
put(path: string, options: Omit<Required<RequestOptions, "body">, "methood">, context?: PlainObject): Promise<FetchResponse<PlainObject>>;
|
|
35
37
|
private _addRequestToRateLimitedQueue;
|
|
36
38
|
private _cacheEntryDelete;
|
|
37
39
|
private _cacheEntryGet;
|
|
@@ -43,6 +45,7 @@ export declare class Getta {
|
|
|
43
45
|
private _fetchRetryHandler;
|
|
44
46
|
private _get;
|
|
45
47
|
private _getResolve;
|
|
48
|
+
private _logResponse;
|
|
46
49
|
private _rateLimit;
|
|
47
50
|
private _releaseRateLimitedRequestQueue;
|
|
48
51
|
private _request;
|
package/lib/types/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,QAA0B,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAQ,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAIjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,QAA0B,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAQ,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAIjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAuCzC,OAAO,EACL,kBAAkB,EAGlB,aAAa,EAMb,cAAc,EAGd,kBAAkB,EAClB,SAAS,EAEV,MAAM,SAAS,CAAC;AAEjB,qBAAa,KAAK;IAChB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,MAAM,CAAC,CAAW;IAC1B,OAAO,CAAC,2BAA2B,CAAU;IAC7C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,2BAA2B,CAAS;IAC5C,OAAO,CAAC,qBAAqB,CAAuB;IACpD,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,wBAAwB,CAAoB;IACpD,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,eAAe,CA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AAO,EAAE,kBAAkB,EAAE,SAAS,CAAC,EAAE,SAAS,iCAS5G"}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -13,11 +13,13 @@ export interface ConstructorOptions {
|
|
|
13
13
|
enableConditionalRequests?: boolean;
|
|
14
14
|
fetchTimeout?: number;
|
|
15
15
|
headers?: StringObject;
|
|
16
|
+
log?: Log;
|
|
16
17
|
maxRedirects?: number;
|
|
17
18
|
maxRetries?: number;
|
|
18
19
|
optionalPathTemplateRegExp?: RegExp;
|
|
19
20
|
pathTemplateCallback?: PathTemplateCallback;
|
|
20
21
|
pathTemplateRegExp?: RegExp;
|
|
22
|
+
performance: Performance;
|
|
21
23
|
queryParams?: PlainObject;
|
|
22
24
|
rateLimitPerSecond?: number;
|
|
23
25
|
requestRetryWait?: number;
|
|
@@ -35,6 +37,11 @@ export interface FetchResponse<Resource = PlainObject> extends ResponseDataWithE
|
|
|
35
37
|
export interface FetchRedirectHandlerOptions extends FetchOptions {
|
|
36
38
|
status: number;
|
|
37
39
|
}
|
|
40
|
+
export declare type Log = (message: string, data: PlainObject, logLevel?: LogLevel) => void;
|
|
41
|
+
export declare type LogLevel = "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
42
|
+
export interface Performance {
|
|
43
|
+
now(): number;
|
|
44
|
+
}
|
|
38
45
|
export interface RequestOptions {
|
|
39
46
|
body?: BodyInit;
|
|
40
47
|
headers?: StringObject;
|
|
@@ -42,7 +49,7 @@ export interface RequestOptions {
|
|
|
42
49
|
pathTemplateData?: StringObject;
|
|
43
50
|
queryParams?: PlainObject;
|
|
44
51
|
}
|
|
45
|
-
export declare type RequestQueue = [(value: FetchResponse) => void, string, FetchOptions][];
|
|
52
|
+
export declare type RequestQueue = [(value: FetchResponse) => void, string, FetchOptions, PlainObject][];
|
|
46
53
|
export interface ResponseDataWithErrors<Resource = PlainObject> {
|
|
47
54
|
data?: Resource;
|
|
48
55
|
errors?: Error[];
|
package/lib/types/types.d.ts.map
CHANGED
|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json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -58,3 +58,6 @@ export const ETAG_HEADER = "ETag" as const;
|
|
|
58
58
|
export const LOCATION_HEADER = "Location" as const;
|
|
59
59
|
export const IF_NONE_MATCH_HEADER = "If-None-Match" as const;
|
|
60
60
|
export const CACHE_CONTROL_HEADER = "Cache-Control" as const;
|
|
61
|
+
|
|
62
|
+
export const REQUEST_SENT = "request_sent" as const;
|
|
63
|
+
export const RESPONSE_RECEIVED = "response_received" as const;
|
package/src/main.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StringObject } from "@repodog/types";
|
|
2
2
|
import fetchMock, { MockRequest } from "fetch-mock";
|
|
3
3
|
import md5 from "md5";
|
|
4
|
+
import { performance } from "perf_hooks";
|
|
4
5
|
import { PRD_136_7317 } from "./__tests__/data";
|
|
5
6
|
import {
|
|
6
7
|
basePath,
|
|
@@ -33,7 +34,7 @@ import { ResponseDataWithErrors, ShortcutProperties } from "./types";
|
|
|
33
34
|
describe("Getta", () => {
|
|
34
35
|
describe("constructor", () => {
|
|
35
36
|
it("SHOULD return an instance of the Getta class", () => {
|
|
36
|
-
const restClient = createRestClient({ basePath, cache: getCache() });
|
|
37
|
+
const restClient = createRestClient({ basePath, cache: getCache(), performance });
|
|
37
38
|
expect(restClient).toBeInstanceOf(Getta);
|
|
38
39
|
});
|
|
39
40
|
});
|
|
@@ -44,7 +45,7 @@ describe("Getta", () => {
|
|
|
44
45
|
|
|
45
46
|
beforeAll(() => {
|
|
46
47
|
restClient = createRestClient<"getProduct">(
|
|
47
|
-
{ basePath, cache: getCache() },
|
|
48
|
+
{ basePath, cache: getCache(), performance },
|
|
48
49
|
{
|
|
49
50
|
getProduct: [
|
|
50
51
|
defaultPath,
|
|
@@ -397,7 +398,7 @@ describe("Getta", () => {
|
|
|
397
398
|
|
|
398
399
|
beforeAll(() => {
|
|
399
400
|
restClient = createRestClient<"postProduct">(
|
|
400
|
-
{ basePath, cache: getCache() },
|
|
401
|
+
{ basePath, cache: getCache(), performance },
|
|
401
402
|
{
|
|
402
403
|
postProduct: [
|
|
403
404
|
defaultPath,
|
|
@@ -483,7 +484,7 @@ describe("Getta", () => {
|
|
|
483
484
|
|
|
484
485
|
beforeAll(() => {
|
|
485
486
|
restClient = createRestClient<"deleteProduct">(
|
|
486
|
-
{ basePath, cache: getCache() },
|
|
487
|
+
{ basePath, cache: getCache(), performance },
|
|
487
488
|
{
|
|
488
489
|
deleteProduct: [
|
|
489
490
|
defaultPath,
|
|
@@ -589,7 +590,7 @@ describe("Getta", () => {
|
|
|
589
590
|
|
|
590
591
|
beforeAll(() => {
|
|
591
592
|
restClient = createRestClient<"putProduct">(
|
|
592
|
-
{ basePath, cache: getCache() },
|
|
593
|
+
{ basePath, cache: getCache(), performance },
|
|
593
594
|
{
|
|
594
595
|
putProduct: [
|
|
595
596
|
defaultPath,
|
|
@@ -662,7 +663,7 @@ describe("Getta", () => {
|
|
|
662
663
|
let restClient: Getta;
|
|
663
664
|
|
|
664
665
|
beforeAll(() => {
|
|
665
|
-
restClient = createRestClient({ basePath });
|
|
666
|
+
restClient = createRestClient({ basePath, performance });
|
|
666
667
|
});
|
|
667
668
|
|
|
668
669
|
describe("WHEN the number of requests per second exceeds rateLimitPerSecond", () => {
|