@kronos-integration/interceptor 12.0.4 → 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.4",
3
+ "version": "12.1.0",
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.1.0"
42
+ "pacc": "^4.2.1"
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
+ }
@@ -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);
@@ -1,5 +1,5 @@
1
1
  import { Interceptor } from "./interceptor.mjs";
2
- import { prepareAttributesDefinitions } from "pacc";
2
+ import { prepareAttributesDefinitions, default_attribute } from "pacc";
3
3
  import { expand } from "./util.mjs";
4
4
 
5
5
  /**
@@ -13,14 +13,17 @@ export class TemplateInterceptor extends Interceptor {
13
13
  return "template";
14
14
  }
15
15
 
16
- static attributes = prepareAttributesDefinitions({
17
- request: {
18
- description: "request template",
19
- default: {},
20
- type: "object"
16
+ static attributes = prepareAttributesDefinitions(
17
+ {
18
+ request: {
19
+ ...default_attribute,
20
+ type: "object",
21
+ description: "request template",
22
+ default: {}
23
+ }
21
24
  },
22
- ...Interceptor.attributes
23
- });
25
+ Interceptor.attributes
26
+ );
24
27
 
25
28
  async receive(endpoint, next, params) {
26
29
  return next(expand(this.request, params));
@@ -1,4 +1,4 @@
1
- import { prepareAttributesDefinitions } from "pacc";
1
+ import { prepareAttributesDefinitions, default_attribute } from "pacc";
2
2
  import { Interceptor } from "./interceptor.mjs";
3
3
 
4
4
  /**
@@ -8,6 +8,7 @@ import { Interceptor } from "./interceptor.mjs";
8
8
  export class TimeoutInterceptor extends Interceptor {
9
9
  static attributes = prepareAttributesDefinitions({
10
10
  timeout: {
11
+ ...default_attribute,
11
12
  description: "request timeout",
12
13
  default: 1,
13
14
  type: "duration"
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";