@vroskus/library-api 1.0.17 → 1.0.19
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/dist/index.d.ts +9 -15
- package/dist/index.js +28 -11
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -3,20 +3,8 @@ import AxiosMockAdapter from 'axios-mock-adapter';
|
|
|
3
3
|
import type { $Config, $RequestContext, $ResponseContext } from './types';
|
|
4
4
|
export * from './types';
|
|
5
5
|
type $RequestContextListener = (arg0: $RequestContext) => void;
|
|
6
|
-
type $SetRequestContextListenerParams = {
|
|
7
|
-
listener: $RequestContextListener;
|
|
8
|
-
};
|
|
9
|
-
type $SetRequestContextListenerResponse = void;
|
|
10
6
|
type $ResponseContextListener = (arg0: $ResponseContext) => void;
|
|
11
|
-
type $SetResponseContextListenerParams = {
|
|
12
|
-
listener: $ResponseContextListener;
|
|
13
|
-
};
|
|
14
|
-
type $SetResponseContextListenerResponse = void;
|
|
15
7
|
type $UnauthenticatedHandler = () => unknown;
|
|
16
|
-
type $SetUnauthenticatedHandlerParams = {
|
|
17
|
-
handler: $UnauthenticatedHandler;
|
|
18
|
-
};
|
|
19
|
-
type $SetUnauthenticatedHandlerResponse = void;
|
|
20
8
|
declare class ApiService<C extends $Config> {
|
|
21
9
|
connection: AxiosInstance;
|
|
22
10
|
unauthenticatedHandler: $UnauthenticatedHandler;
|
|
@@ -25,9 +13,15 @@ declare class ApiService<C extends $Config> {
|
|
|
25
13
|
mock: AxiosMockAdapter | null;
|
|
26
14
|
path: (arg0: string) => RegExp | string;
|
|
27
15
|
constructor({ apiUrl, timeout, }: C);
|
|
28
|
-
setUnauthenticatedHandler({ handler, }:
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
setUnauthenticatedHandler({ handler, }: {
|
|
17
|
+
handler: $UnauthenticatedHandler;
|
|
18
|
+
}): void;
|
|
19
|
+
setRequestContextListener({ listener, }: {
|
|
20
|
+
listener: $RequestContextListener;
|
|
21
|
+
}): void;
|
|
22
|
+
setResponseContextListener({ listener, }: {
|
|
23
|
+
listener: $ResponseContextListener;
|
|
24
|
+
}): void;
|
|
31
25
|
pushRequestContext(config: AxiosRequestConfig<unknown>, requestId: string): void;
|
|
32
26
|
pushResponseContext(response: AxiosResponse<unknown>): void;
|
|
33
27
|
initMock(mockSetup: (mock: AxiosMockAdapter) => void): void;
|
package/dist/index.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
37
|
};
|
|
@@ -34,6 +44,11 @@ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
|
|
|
34
44
|
const lodash_1 = __importDefault(require("lodash"));
|
|
35
45
|
const uuid_1 = require("uuid");
|
|
36
46
|
__exportStar(require("./types"), exports);
|
|
47
|
+
const unauthenticatedStatus = 401;
|
|
48
|
+
const defaultRetryDelay = 3000;
|
|
49
|
+
const defaultRetryQuantity = 3;
|
|
50
|
+
const defaultRetryIncrementor = 1;
|
|
51
|
+
const zeroValue = 0;
|
|
37
52
|
class ApiService {
|
|
38
53
|
constructor({ apiUrl, timeout, }) {
|
|
39
54
|
const connectionConfig = {
|
|
@@ -51,7 +66,7 @@ class ApiService {
|
|
|
51
66
|
this.responseContextListener = () => { };
|
|
52
67
|
this.connection.interceptors.response.use((response) => response, (error) => {
|
|
53
68
|
const status = lodash_1.default.get(error, 'response.status');
|
|
54
|
-
if (status ===
|
|
69
|
+
if (status === unauthenticatedStatus) {
|
|
55
70
|
this.unauthenticatedHandler();
|
|
56
71
|
}
|
|
57
72
|
return Promise.reject(error);
|
|
@@ -70,13 +85,15 @@ class ApiService {
|
|
|
70
85
|
const message = lodash_1.default.get(error, 'message');
|
|
71
86
|
const config = lodash_1.default.get(error, 'config');
|
|
72
87
|
if (config
|
|
73
|
-
&& config.retryQty !==
|
|
88
|
+
&& config.retryQty !== zeroValue
|
|
74
89
|
&& ['Network Error', 'timeout'].some((e) => message.includes(e))) {
|
|
75
|
-
config.retryQty = typeof config.retryQty === 'undefined'
|
|
90
|
+
config.retryQty = typeof config.retryQty === 'undefined'
|
|
91
|
+
? defaultRetryQuantity
|
|
92
|
+
: config.retryQty - defaultRetryIncrementor;
|
|
76
93
|
const delayRetryRequest = new Promise((resolve) => {
|
|
77
94
|
setTimeout(() => {
|
|
78
95
|
resolve(null);
|
|
79
|
-
}, config.retryDelay ||
|
|
96
|
+
}, config.retryDelay || defaultRetryDelay);
|
|
80
97
|
});
|
|
81
98
|
return delayRetryRequest.then(() => this.connection.request(config));
|
|
82
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vroskus/library-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "Api",
|
|
5
5
|
"author": "Vilius Roškus <vilius@regattas.eu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,21 +22,21 @@
|
|
|
22
22
|
"test:e2e:post": "jest-coverage-thresholds-bumper"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"axios": "^1.7.
|
|
26
|
-
"axios-mock-adapter": "^2.
|
|
25
|
+
"axios": "^1.7.9",
|
|
26
|
+
"axios-mock-adapter": "^2.1.0",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
|
-
"uuid": "^
|
|
28
|
+
"uuid": "^11.0.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/jest": "^29.5.
|
|
32
|
-
"@types/lodash": "^4.17.
|
|
33
|
-
"@types/node": "^22.
|
|
31
|
+
"@types/jest": "^29.5.14",
|
|
32
|
+
"@types/lodash": "^4.17.13",
|
|
33
|
+
"@types/node": "^22.10.2",
|
|
34
34
|
"@types/query-string": "^6.3.0",
|
|
35
|
-
"@vroskus/eslint-config": "^1.0.
|
|
35
|
+
"@vroskus/eslint-config": "^1.0.21",
|
|
36
36
|
"jest": "^29.7.0",
|
|
37
37
|
"jest-coverage-thresholds-bumper": "^1.1.0",
|
|
38
|
-
"ts-jest": "^29.2.
|
|
39
|
-
"typescript": "^5.
|
|
38
|
+
"ts-jest": "^29.2.5",
|
|
39
|
+
"typescript": "^5.7.2"
|
|
40
40
|
},
|
|
41
41
|
"jest": {
|
|
42
42
|
"preset": "ts-jest",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
],
|
|
52
52
|
"coverageThreshold": {
|
|
53
53
|
"global": {
|
|
54
|
-
"branches":
|
|
55
|
-
"functions":
|
|
56
|
-
"lines":
|
|
57
|
-
"statements": 65.
|
|
54
|
+
"branches": 51.35,
|
|
55
|
+
"functions": 50,
|
|
56
|
+
"lines": 68.75,
|
|
57
|
+
"statements": 65.76
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|