@kronos-integration/interceptor 13.4.6 → 13.5.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/package.json +3 -3
- package/src/interceptor.mjs +30 -18
- package/src/interval-interceptor.mjs +14 -12
- package/src/limiting-interceptor.mjs +25 -23
- package/src/logging-interceptor.mjs +8 -1
- package/src/monitoring-interceptor.mjs +18 -15
- package/src/stats-collector-interceptor.mjs +5 -0
- package/src/template-interceptor.mjs +19 -12
- package/src/timeout-interceptor.mjs +13 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/interceptor",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.5.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"lint:docs": "documentation lint ./src**/*.mjs"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"pacc": "^
|
|
38
|
+
"pacc": "^14.0.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@kronos-integration/test-interceptor": "^7.2.
|
|
41
|
+
"@kronos-integration/test-interceptor": "^7.2.6",
|
|
42
42
|
"ava": "^8.0.1",
|
|
43
43
|
"c8": "^12.0.0",
|
|
44
44
|
"documentation": "^14.0.3",
|
package/src/interceptor.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
addType,
|
|
3
|
+
setAttributes,
|
|
4
|
+
extract,
|
|
5
|
+
type_attribute,
|
|
6
|
+
SCOPE_RUNTIME
|
|
7
|
+
} from "pacc";
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* @typedef {Object} Endpoint
|
|
@@ -14,10 +20,16 @@ export class Interceptor {
|
|
|
14
20
|
* Meta description of the configuration
|
|
15
21
|
* @return {Object}
|
|
16
22
|
*/
|
|
17
|
-
static attributes = {
|
|
23
|
+
static attributes = {
|
|
24
|
+
type: type_attribute
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static {
|
|
28
|
+
addType(this);
|
|
29
|
+
}
|
|
18
30
|
|
|
19
31
|
/**
|
|
20
|
-
*
|
|
32
|
+
*
|
|
21
33
|
* @param {Object} [config]
|
|
22
34
|
*/
|
|
23
35
|
constructor(config) {
|
|
@@ -70,22 +82,22 @@ export class Interceptor {
|
|
|
70
82
|
* @return {Object} json representation
|
|
71
83
|
*/
|
|
72
84
|
toJSONWithOptions(options) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
return extract(this, {
|
|
86
|
+
externalNames: true,
|
|
87
|
+
filter: attribute => {
|
|
88
|
+
if (attribute.scope === SCOPE_RUNTIME) {
|
|
89
|
+
return options.includeRuntimeInfo;
|
|
90
|
+
}
|
|
91
|
+
if (attribute.name === "type") {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
78
94
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
type: this.type,
|
|
87
|
-
...atts
|
|
88
|
-
};
|
|
95
|
+
return (
|
|
96
|
+
options.includeConfig &&
|
|
97
|
+
(options.includePrivate || !attribute.private)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addType, duration_ms_attribute } from "pacc";
|
|
2
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -6,17 +6,15 @@ import { Interceptor } from "./interceptor.mjs";
|
|
|
6
6
|
* @property {number} interval
|
|
7
7
|
*/
|
|
8
8
|
export class IntervalInterceptor extends Interceptor {
|
|
9
|
-
static attributes =
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Interceptor.attributes
|
|
19
|
-
);
|
|
9
|
+
static attributes = {
|
|
10
|
+
interval: {
|
|
11
|
+
...duration_ms_attribute,
|
|
12
|
+
writable: true,
|
|
13
|
+
name: "interval",
|
|
14
|
+
description: "min interval between two requests",
|
|
15
|
+
default: "60s"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* @return {string} 'interval'
|
|
@@ -25,6 +23,10 @@ export class IntervalInterceptor extends Interceptor {
|
|
|
25
23
|
return "interval";
|
|
26
24
|
}
|
|
27
25
|
|
|
26
|
+
static {
|
|
27
|
+
addType(this);
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
async receive(endpoint, next, ...args) {
|
|
29
31
|
const now = new Date();
|
|
30
32
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
object_attribute,
|
|
2
|
+
addType,
|
|
4
3
|
duration_ms_attribute,
|
|
5
|
-
|
|
4
|
+
count_attribute_writable,
|
|
5
|
+
default_collection_attribute_writable
|
|
6
6
|
} from "pacc";
|
|
7
7
|
import { Interceptor } from "./interceptor.mjs";
|
|
8
8
|
|
|
@@ -29,39 +29,41 @@ export class LimitingInterceptor extends Interceptor {
|
|
|
29
29
|
return "request-limit";
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static attributes =
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
attributes: {
|
|
43
|
-
count: count_attribute,
|
|
44
|
-
delay: { ...duration_ms_attribute, name: "delay" }
|
|
32
|
+
static attributes = {
|
|
33
|
+
limits: {
|
|
34
|
+
...default_collection_attribute_writable,
|
|
35
|
+
//...object_attribute,
|
|
36
|
+
name: "limits",
|
|
37
|
+
default: [
|
|
38
|
+
{
|
|
39
|
+
count: 10
|
|
45
40
|
}
|
|
41
|
+
],
|
|
42
|
+
attributes: {
|
|
43
|
+
count: count_attribute_writable,
|
|
44
|
+
delay: { ...duration_ms_attribute, name: "delay" }
|
|
46
45
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static {
|
|
50
|
+
addType(this);
|
|
51
|
+
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
*
|
|
53
55
|
* @param {Object?} config
|
|
54
56
|
*/
|
|
55
|
-
constructor(config) {
|
|
57
|
+
/*constructor(config) {
|
|
56
58
|
super(config);
|
|
57
59
|
this.limits = config?.limits || this.attributes.limits.default;
|
|
58
|
-
}
|
|
60
|
+
}*/
|
|
59
61
|
|
|
60
|
-
toJSON() {
|
|
62
|
+
/*toJSON() {
|
|
61
63
|
const json = super.toJSON();
|
|
62
64
|
json.limits = this.limits;
|
|
63
65
|
return json;
|
|
64
|
-
}
|
|
66
|
+
}*/
|
|
65
67
|
|
|
66
68
|
reset() {
|
|
67
69
|
this.ongoingResponses = new Set();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addType } from "pacc";
|
|
1
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -11,13 +12,19 @@ export class LoggingInterceptor extends Interceptor {
|
|
|
11
12
|
return "logging";
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
static {
|
|
16
|
+
addType(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
async receive(endpoint, next, ...args) {
|
|
15
20
|
const logger = endpoint.owner;
|
|
16
21
|
logger.info(`${endpoint.identifier}: > ${JSON.stringify([...args])}`);
|
|
17
22
|
|
|
18
23
|
try {
|
|
19
24
|
const result = await next(...args);
|
|
20
|
-
logger.info(
|
|
25
|
+
logger.info(
|
|
26
|
+
`${endpoint.identifier}: < ${result === undefined ? "" : result}`
|
|
27
|
+
);
|
|
21
28
|
return result;
|
|
22
29
|
} catch (e) {
|
|
23
30
|
logger.error(`${endpoint.identifier}: ${e}`);
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addType, duration_ms_attribute } from "pacc";
|
|
2
2
|
import { Interceptor } from "@kronos-integration/interceptor";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
export class MonitoringInterceptor extends Interceptor {
|
|
8
|
-
static attributes =
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
settingPeriod: {
|
|
16
|
-
...duration_ms_attribute,
|
|
17
|
-
name: "settingPeriod",
|
|
18
|
-
default: "300s"
|
|
19
|
-
}
|
|
8
|
+
static attributes = {
|
|
9
|
+
gracePeriod: {
|
|
10
|
+
...duration_ms_attribute,
|
|
11
|
+
writable: true,
|
|
12
|
+
name: "gracePeriod",
|
|
13
|
+
default: "120s"
|
|
20
14
|
},
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
settingPeriod: {
|
|
16
|
+
...duration_ms_attribute,
|
|
17
|
+
writable: true,
|
|
18
|
+
name: "settingPeriod",
|
|
19
|
+
default: "300s"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* @return {string} 'monitor'
|
|
@@ -28,6 +27,10 @@ export class MonitoringInterceptor extends Interceptor {
|
|
|
28
27
|
return "monitor";
|
|
29
28
|
}
|
|
30
29
|
|
|
30
|
+
static {
|
|
31
|
+
addType(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
31
34
|
reset() {
|
|
32
35
|
this.endpointStates = new Map();
|
|
33
36
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addType } from "pacc";
|
|
1
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -12,6 +13,10 @@ export class StatsCollectorInterceptor extends Interceptor {
|
|
|
12
13
|
return "collect-request-stats";
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
static {
|
|
17
|
+
addType(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
reset() {
|
|
16
21
|
this.numberOfRequests = 0;
|
|
17
22
|
this.numberOfFailedRequests = 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { addType, expand, object_attribute_writable } from "pacc";
|
|
1
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
2
|
-
import { expand, prepareAttributesDefinitions, object_attribute } from "pacc";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Map params into requests.
|
|
@@ -12,17 +12,24 @@ export class TemplateInterceptor extends Interceptor {
|
|
|
12
12
|
return "template";
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
static attributes =
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
static attributes = {
|
|
16
|
+
request: {
|
|
17
|
+
...object_attribute_writable,
|
|
18
|
+
name: "request",
|
|
19
|
+
description: "request template",
|
|
20
|
+
default: {}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
static {
|
|
25
|
+
addType(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toJSONWithOptions(options) {
|
|
29
|
+
const json = super.toJSONWithOptions(options);
|
|
30
|
+
json.request = this.request;
|
|
31
|
+
return json;
|
|
32
|
+
}
|
|
26
33
|
|
|
27
34
|
async receive(endpoint, next, params) {
|
|
28
35
|
return next(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addType, duration_ms_attribute } from "pacc";
|
|
2
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -6,16 +6,14 @@ import { Interceptor } from "./interceptor.mjs";
|
|
|
6
6
|
* @property {number} timeout
|
|
7
7
|
*/
|
|
8
8
|
export class TimeoutInterceptor extends Interceptor {
|
|
9
|
-
static attributes =
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Interceptor.attributes
|
|
18
|
-
);
|
|
9
|
+
static attributes = {
|
|
10
|
+
timeout: {
|
|
11
|
+
...duration_ms_attribute,
|
|
12
|
+
writable: true,
|
|
13
|
+
description: "request timeout",
|
|
14
|
+
default: "100000"
|
|
15
|
+
}
|
|
16
|
+
};
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
19
|
* @return {string} 'timeout'
|
|
@@ -24,6 +22,10 @@ export class TimeoutInterceptor extends Interceptor {
|
|
|
24
22
|
return "timeout";
|
|
25
23
|
}
|
|
26
24
|
|
|
25
|
+
static {
|
|
26
|
+
addType(this);
|
|
27
|
+
}
|
|
28
|
+
|
|
27
29
|
receive(endpoint, next, ...args) {
|
|
28
30
|
return rejectUnlessResolvedWithin(next(...args), this.timeout, this);
|
|
29
31
|
}
|