@kronos-integration/interceptor 12.0.5 → 12.1.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 CHANGED
@@ -41,20 +41,23 @@ const response = interceptor.receive(endpoint, arg1, arg2);
41
41
  * [receive](#receive)
42
42
  * [Parameters](#parameters-3)
43
43
  * [attributes](#attributes-1)
44
+ * [IntervalInterceptor](#intervalinterceptor)
45
+ * [Properties](#properties)
46
+ * [name](#name)
44
47
  * [LimitingInterceptor](#limitinginterceptor)
45
48
  * [Parameters](#parameters-4)
46
- * [name](#name)
47
- * [LoggingInterceptor](#logginginterceptor)
48
49
  * [name](#name-1)
50
+ * [LoggingInterceptor](#logginginterceptor)
51
+ * [name](#name-2)
49
52
  * [StatsCollectorInterceptor](#statscollectorinterceptor)
50
53
  * [receive](#receive-1)
51
54
  * [Parameters](#parameters-5)
52
- * [name](#name-2)
53
- * [TemplateInterceptor](#templateinterceptor)
54
55
  * [name](#name-3)
55
- * [TimeoutInterceptor](#timeoutinterceptor)
56
- * [Properties](#properties)
56
+ * [TemplateInterceptor](#templateinterceptor)
57
57
  * [name](#name-4)
58
+ * [TimeoutInterceptor](#timeoutinterceptor)
59
+ * [Properties](#properties-1)
60
+ * [name](#name-5)
58
61
  * [rejectUnlessResolvedWithin](#rejectunlessresolvedwithin)
59
62
  * [Parameters](#parameters-6)
60
63
  * [expand](#expand)
@@ -132,6 +135,20 @@ Meta description of the configuration
132
135
 
133
136
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
134
137
 
138
+ ## IntervalInterceptor
139
+
140
+ **Extends Interceptor**
141
+
142
+ Only passes requests after inteval time has passed
143
+
144
+ ### Properties
145
+
146
+ * `interval` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** 
147
+
148
+ ### name
149
+
150
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'interval'
151
+
135
152
  ## LimitingInterceptor
136
153
 
137
154
  **Extends Interceptor**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronos-integration/interceptor",
3
- "version": "12.0.5",
3
+ "version": "12.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -39,7 +39,7 @@
39
39
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
40
40
  },
41
41
  "dependencies": {
42
- "pacc": "^4.2.1"
42
+ "pacc": "^4.4.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@kronos-integration/test-interceptor": "^7.0.30",
package/src/index.mjs CHANGED
@@ -2,5 +2,6 @@ export * from "./interceptor.mjs";
2
2
  export * from "./timeout-interceptor.mjs";
3
3
  export * from "./stats-collector-interceptor.mjs";
4
4
  export * from "./limiting-interceptor.mjs";
5
+ export * from "./interval-interceptor.mjs";
5
6
  export * from "./logging-interceptor.mjs";
6
7
  export * from "./template-interceptor.mjs";
@@ -0,0 +1,36 @@
1
+ import { prepareAttributesDefinitions, default_attribute } from "pacc";
2
+ import { Interceptor } from "./interceptor.mjs";
3
+
4
+ /**
5
+ * Only passes requests after inteval time has passed
6
+ * @property {number} interval
7
+ */
8
+ export class IntervalInterceptor extends Interceptor {
9
+ static attributes = prepareAttributesDefinitions(
10
+ {
11
+ interval: {
12
+ ...default_attribute,
13
+ description: "min interval between two requests",
14
+ default: 60000,
15
+ type: "duration"
16
+ }
17
+ },
18
+ Interceptor.attributes
19
+ );
20
+
21
+ /**
22
+ * @return {string} 'interval'
23
+ */
24
+ static get name() {
25
+ return "interval";
26
+ }
27
+
28
+ async receive(endpoint, next, ...args) {
29
+ const now = new Date();
30
+
31
+ if (!this.lastTime || now - this.lastTime > this.interval * 1000) {
32
+ this.lastTime = now;
33
+ return super.receive(endpoint, next, ...args);
34
+ }
35
+ }
36
+ }
@@ -1,4 +1,9 @@
1
- import { prepareAttributesDefinitions } from "pacc";
1
+ import {
2
+ prepareAttributesDefinitions,
3
+ object_attribute,
4
+ duration_attribute,
5
+ count_attribute
6
+ } from "pacc";
2
7
  import { Interceptor } from "./interceptor.mjs";
3
8
 
4
9
  /**
@@ -24,22 +29,26 @@ export class LimitingInterceptor extends Interceptor {
24
29
  return "request-limit";
25
30
  }
26
31
 
27
- static attributes = prepareAttributesDefinitions({
28
- limits: {
29
- default: [
30
- {
31
- count: 10
32
+ static attributes = prepareAttributesDefinitions(
33
+ {
34
+ limits: {
35
+ ...object_attribute,
36
+ default: [
37
+ {
38
+ count: 10
39
+ }
40
+ ],
41
+ attributes: {
42
+ count: { ...count_attribute, default: 10 },
43
+ delay: {
44
+ ...duration_attribute,
45
+ type: "duration"
46
+ }
32
47
  }
33
- ],
34
- count: {
35
- type: "unsigned-integer"
36
- },
37
- delay: {
38
- type: "duration"
39
48
  }
40
49
  },
41
- ...Interceptor.attributes
42
- });
50
+ Interceptor.attributes
51
+ );
43
52
 
44
53
  constructor(config) {
45
54
  super(config);
@@ -13,15 +13,17 @@ export class TemplateInterceptor extends Interceptor {
13
13
  return "template";
14
14
  }
15
15
 
16
- static attributes = prepareAttributesDefinitions({
17
- request: {
18
- ...default_attribute,
19
- type: "object",
20
- description: "request template",
21
- default: {}
16
+ static attributes = prepareAttributesDefinitions(
17
+ {
18
+ request: {
19
+ ...default_attribute,
20
+ type: "object",
21
+ description: "request template",
22
+ default: {}
23
+ }
22
24
  },
23
- ...Interceptor.attributes
24
- });
25
+ Interceptor.attributes
26
+ );
25
27
 
26
28
  async receive(endpoint, next, params) {
27
29
  return next(expand(this.request, params));
package/types/index.d.mts CHANGED
@@ -2,5 +2,6 @@ export * from "./interceptor.mjs";
2
2
  export * from "./timeout-interceptor.mjs";
3
3
  export * from "./stats-collector-interceptor.mjs";
4
4
  export * from "./limiting-interceptor.mjs";
5
+ export * from "./interval-interceptor.mjs";
5
6
  export * from "./logging-interceptor.mjs";
6
7
  export * from "./template-interceptor.mjs";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Only passes requests after inteval time has passed
3
+ * @property {number} interval
4
+ */
5
+ export class IntervalInterceptor extends Interceptor {
6
+ static attributes: any;
7
+ receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
8
+ lastTime: Date;
9
+ }
10
+ import { Interceptor } from "./interceptor.mjs";