@kronos-integration/interceptor 12.0.5 → 12.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronos-integration/interceptor",
3
- "version": "12.0.5",
3
+ "version": "12.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
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
+ }
@@ -24,22 +24,24 @@ export class LimitingInterceptor extends Interceptor {
24
24
  return "request-limit";
25
25
  }
26
26
 
27
- static attributes = prepareAttributesDefinitions({
28
- limits: {
29
- default: [
30
- {
31
- count: 10
27
+ static attributes = prepareAttributesDefinitions(
28
+ {
29
+ limits: {
30
+ default: [
31
+ {
32
+ count: 10
33
+ }
34
+ ],
35
+ count: {
36
+ type: "unsigned-integer"
37
+ },
38
+ delay: {
39
+ type: "duration"
32
40
  }
33
- ],
34
- count: {
35
- type: "unsigned-integer"
36
- },
37
- delay: {
38
- type: "duration"
39
41
  }
40
42
  },
41
- ...Interceptor.attributes
42
- });
43
+ Interceptor.attributes
44
+ );
43
45
 
44
46
  constructor(config) {
45
47
  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";