@kronos-integration/interceptor 10.2.38 → 10.3.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/README.md +9 -6
- package/package.json +16 -10
- package/src/interceptor.mjs +4 -0
- package/types/index.d.mts +6 -0
- package/types/interceptor.d.mts +58 -0
- package/types/limiting-interceptor.d.mts +23 -0
- package/types/logging-interceptor.d.mts +7 -0
- package/types/stats-collector-interceptor.d.mts +17 -0
- package/types/template-interceptor.d.mts +7 -0
- package/types/timeout-interceptor.d.mts +8 -0
- package/types/util.d.mts +7 -0
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/@kronos-integration/interceptor)
|
|
2
1
|
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
-
[](https://npmjs.org/package/@kronos-integration/interceptor)
|
|
2
|
+
[](https://typescriptlang.org)
|
|
5
3
|
[](https://github.com/Kronos-Integration/interceptor/issues)
|
|
6
4
|
[](https://actions-badge.atrox.dev/Kronos-Integration/interceptor/goto)
|
|
7
5
|
[](https://github.com/prettier/prettier)
|
|
@@ -30,6 +28,7 @@ const response = interceptor.receive(endpoint, arg1, arg2);
|
|
|
30
28
|
|
|
31
29
|
### Table of Contents
|
|
32
30
|
|
|
31
|
+
* [Endpoint](#endpoint)
|
|
33
32
|
* [Interceptor](#interceptor)
|
|
34
33
|
* [Parameters](#parameters)
|
|
35
34
|
* [type](#type)
|
|
@@ -61,6 +60,10 @@ const response = interceptor.receive(endpoint, arg1, arg2);
|
|
|
61
60
|
* [expand](#expand)
|
|
62
61
|
* [Parameters](#parameters-7)
|
|
63
62
|
|
|
63
|
+
## Endpoint
|
|
64
|
+
|
|
65
|
+
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
|
|
66
|
+
|
|
64
67
|
## Interceptor
|
|
65
68
|
|
|
66
69
|
Base interceptor. The base class for all the interceptors
|
|
@@ -117,11 +120,11 @@ and calls the trailing interceptor.
|
|
|
117
120
|
|
|
118
121
|
#### Parameters
|
|
119
122
|
|
|
120
|
-
* `endpoint` **Endpoint** 
|
|
123
|
+
* `endpoint` **[Endpoint](#endpoint)** 
|
|
121
124
|
* `next` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** 
|
|
122
125
|
* `args` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>** the request from the leading interceptor
|
|
123
126
|
|
|
124
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
127
|
+
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** 
|
|
125
128
|
|
|
126
129
|
### configurationAttributes
|
|
127
130
|
|
|
@@ -219,7 +222,7 @@ Rejects promise when it is not resolved within given timeout.
|
|
|
219
222
|
* `timeout` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** in miliseconds
|
|
220
223
|
* `source` **[Interceptor](#interceptor)** 
|
|
221
224
|
|
|
222
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
225
|
+
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** 
|
|
223
226
|
|
|
224
227
|
## expand
|
|
225
228
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/interceptor",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
7
7
|
},
|
|
8
|
+
"types": "./types/index.d.mts",
|
|
8
9
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
+
".": {
|
|
11
|
+
"default": "./src/index.mjs",
|
|
12
|
+
"types": "./types/index.d.mts"
|
|
13
|
+
}
|
|
10
14
|
},
|
|
11
15
|
"description": "intercepects / modifies requests as they pass between endpoints",
|
|
12
16
|
"keywords": [
|
|
@@ -24,27 +28,29 @@
|
|
|
24
28
|
],
|
|
25
29
|
"license": "BSD-2-Clause",
|
|
26
30
|
"scripts": {
|
|
27
|
-
"
|
|
31
|
+
"prepare": "node --run prepare:typescript",
|
|
32
|
+
"prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
|
|
33
|
+
"test": "node --run test:ava",
|
|
28
34
|
"test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
|
|
29
35
|
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
|
|
30
36
|
"docs": "documentation readme --section=API ./src/**/*.mjs",
|
|
31
|
-
"lint": "
|
|
37
|
+
"lint": "node --run lint:docs && node --run lint:typescript",
|
|
32
38
|
"lint:docs": "documentation lint ./src/**/*.mjs",
|
|
33
|
-
"lint:
|
|
39
|
+
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
34
40
|
},
|
|
35
41
|
"dependencies": {
|
|
36
42
|
"model-attributes": "^4.2.2"
|
|
37
43
|
},
|
|
38
44
|
"devDependencies": {
|
|
39
45
|
"@kronos-integration/test-interceptor": "^7.0.27",
|
|
40
|
-
"ava": "^6.1.
|
|
41
|
-
"c8": "^
|
|
46
|
+
"ava": "^6.1.3",
|
|
47
|
+
"c8": "^10.1.2",
|
|
42
48
|
"documentation": "^14.0.3",
|
|
43
|
-
"semantic-release": "^
|
|
44
|
-
"typescript": "^5.
|
|
49
|
+
"semantic-release": "^24.1.2",
|
|
50
|
+
"typescript": "^5.7.0-beta"
|
|
45
51
|
},
|
|
46
52
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
53
|
+
"node": ">=22.11.0"
|
|
48
54
|
},
|
|
49
55
|
"repository": {
|
|
50
56
|
"type": "git",
|
package/src/interceptor.mjs
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} Endpoint
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base interceptor. The base class for all the interceptors
|
|
6
|
+
* Calls configure() and reset().
|
|
7
|
+
* @param {Object} config The interceptor configuration object.
|
|
8
|
+
*/
|
|
9
|
+
export class Interceptor {
|
|
10
|
+
/**
|
|
11
|
+
* Meta description of the configuration
|
|
12
|
+
* @return {Object}
|
|
13
|
+
*/
|
|
14
|
+
static get configurationAttributes(): any;
|
|
15
|
+
constructor(config: any);
|
|
16
|
+
/**
|
|
17
|
+
* The instance method returning the type.
|
|
18
|
+
* Defaults to the constructors name (class name)
|
|
19
|
+
* @return {string}
|
|
20
|
+
*/
|
|
21
|
+
get type(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Meta description of the configuration.
|
|
24
|
+
* @return {Object}
|
|
25
|
+
*/
|
|
26
|
+
get configurationAttributes(): any;
|
|
27
|
+
/**
|
|
28
|
+
* Takes attribute values from config parameters
|
|
29
|
+
* and copies them over to the object.
|
|
30
|
+
* Copying is done according to configurationAttributes.
|
|
31
|
+
* Which means we loop over all configuration attributes
|
|
32
|
+
* and then for each attribute decide if we use the default, call
|
|
33
|
+
* a setter function or simply assign the attribute value.
|
|
34
|
+
* @param {Object} config
|
|
35
|
+
*/
|
|
36
|
+
configure(config: any): void;
|
|
37
|
+
toString(): string;
|
|
38
|
+
toJSON(): any;
|
|
39
|
+
/**
|
|
40
|
+
* Deliver the json representation.
|
|
41
|
+
* @return {Object} json representation
|
|
42
|
+
*/
|
|
43
|
+
toJSONWithOptions(options: any): any;
|
|
44
|
+
/**
|
|
45
|
+
* Forget all accumulated information.
|
|
46
|
+
*/
|
|
47
|
+
reset(): void;
|
|
48
|
+
/**
|
|
49
|
+
* The receive method. This method receives the request from the leading interceptor
|
|
50
|
+
* and calls the trailing interceptor.
|
|
51
|
+
* @param {Endpoint} endpoint
|
|
52
|
+
* @param {Function} next
|
|
53
|
+
* @param {any[]} args the request from the leading interceptor
|
|
54
|
+
* @return {Promise<any>}
|
|
55
|
+
*/
|
|
56
|
+
receive(endpoint: Endpoint, next: Function, ...args: any[]): Promise<any>;
|
|
57
|
+
}
|
|
58
|
+
export type Endpoint = any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Limits the number of concurrent requests.
|
|
3
|
+
* Requests can be delayed or rejected.
|
|
4
|
+
* Sample config:
|
|
5
|
+
* [
|
|
6
|
+
* { count: 20 },
|
|
7
|
+
* { count: 10, delay: 100 },
|
|
8
|
+
* { count: 5, delay: 10 }
|
|
9
|
+
* ]
|
|
10
|
+
* 1 - 4 : no delay
|
|
11
|
+
* 5 - 9 : 10ms delay
|
|
12
|
+
* 10 - 19 : 100ms delay
|
|
13
|
+
* 20 : reject
|
|
14
|
+
* default is to reject when more than 10 requests are on the way
|
|
15
|
+
*/
|
|
16
|
+
export class LimitingInterceptor extends Interceptor {
|
|
17
|
+
limits: any;
|
|
18
|
+
ongoingResponses: Set<any>;
|
|
19
|
+
ongoingRequests: number;
|
|
20
|
+
receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
|
|
21
|
+
_processRequest(next: any, ...args: any[]): any;
|
|
22
|
+
}
|
|
23
|
+
import { Interceptor } from "./interceptor.mjs";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interceptor to collect processing time, number of
|
|
3
|
+
* processed and failed requests.
|
|
4
|
+
*/
|
|
5
|
+
export class StatsCollectorInterceptor extends Interceptor {
|
|
6
|
+
get numberOfRequests(): any;
|
|
7
|
+
get numberOfFailedRequests(): any;
|
|
8
|
+
get maxRequestProcessingTime(): any;
|
|
9
|
+
get minRequestProcessingTime(): any;
|
|
10
|
+
get totalRequestProcessingTime(): any;
|
|
11
|
+
/**
|
|
12
|
+
* Logs the time the requests takes
|
|
13
|
+
*/
|
|
14
|
+
receive(endpoint: any, ...args: any[]): Promise<any>;
|
|
15
|
+
#private;
|
|
16
|
+
}
|
|
17
|
+
import { Interceptor } from './interceptor.mjs';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rejects a request if it does not resolve in a given time.
|
|
3
|
+
* @property {number} timeout
|
|
4
|
+
*/
|
|
5
|
+
export class TimeoutInterceptor extends Interceptor {
|
|
6
|
+
receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
import { Interceptor } from "./interceptor.mjs";
|