dt-common-device 3.0.11 → 3.0.13

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.
@@ -5,6 +5,7 @@ export declare const SERVICE_NAMES: {
5
5
  readonly SCHEDULE: "smart-schedule";
6
6
  readonly DEVICE: "smart-device";
7
7
  };
8
+ export type SERVICE_NAME = typeof SERVICE_NAMES[keyof typeof SERVICE_NAMES];
8
9
  export declare enum Source {
9
10
  USER = "user",
10
11
  CLOUD_EVENT = "cloud-event",
@@ -58,7 +58,7 @@ let HybridHttpQueue = (() => {
58
58
  this.rateLimitConfigs = rateLimit_utils_1.RateLimitUtils.initializeRateLimitConfigs();
59
59
  }
60
60
  async addToQueue(connectionId, provider, url, method, options) {
61
- const queueKey = queueUtils_1.QueueUtils.getRequestQueueKey(connectionId, provider);
61
+ const queueKey = queueUtils_1.QueueUtils.getQueueKey(options.queueOptions?.microservice, connectionId, provider);
62
62
  // Calculate delay based on rate limit window
63
63
  const key = `rate_limit:${provider}:${connectionId}`;
64
64
  const config = this.rateLimitConfigs.get(provider);
@@ -1,11 +1,13 @@
1
+ import { IncomingHttpHeaders } from "http";
2
+ import { SERVICE_NAME } from "../../constants";
1
3
  export interface HttpCallOption {
2
- headers?: Record<string, string>;
4
+ headers?: IncomingHttpHeaders;
3
5
  body?: any;
4
6
  params?: Record<string, any>;
5
7
  queueOptions?: {
6
8
  connectionId: string;
7
9
  connectionProvider: string;
8
- microservice: string;
10
+ microservice: SERVICE_NAME;
9
11
  };
10
12
  }
11
13
  export interface HttpRequestOptions {
@@ -13,10 +15,10 @@ export interface HttpRequestOptions {
13
15
  url: string;
14
16
  body?: any;
15
17
  params?: Record<string, any>;
16
- headers?: Record<string, string>;
18
+ headers?: IncomingHttpHeaders;
17
19
  queueOptions?: {
18
20
  connectionId: string;
19
21
  connectionProvider: string;
20
- microservice: string;
22
+ microservice: SERVICE_NAME;
21
23
  };
22
24
  }
@@ -1,12 +1,14 @@
1
+ import { IncomingHttpHeaders } from "http";
2
+ import { SERVICE_NAME } from "../../constants";
1
3
  export interface RequestQueueOptions {
2
4
  method: string;
3
5
  url: string;
4
6
  body?: any;
5
7
  params?: Record<string, any>;
6
- headers?: Record<string, string>;
8
+ headers?: IncomingHttpHeaders;
7
9
  queueOptions?: {
8
10
  connectionId: string;
9
11
  connectionProvider: string;
10
- microservice: string;
12
+ microservice: SERVICE_NAME;
11
13
  };
12
14
  }
@@ -1,7 +1,8 @@
1
+ import { SERVICE_NAME } from "../../constants";
1
2
  export declare class JobUtils {
2
3
  static extractConnectionDetails(options: any): {
3
4
  connectionId: string;
4
5
  provider: string;
5
- microservice: string;
6
+ microservice: SERVICE_NAME;
6
7
  };
7
8
  }
@@ -111,10 +111,11 @@ class QueueUtils {
111
111
  timestamp: Date.now(),
112
112
  reason: "execution_error",
113
113
  errorMessage: error.message,
114
+ error: error,
114
115
  },
115
116
  });
116
117
  // Throw the error instead of returning it
117
- throw new Error(`HTTP request failed: ${error.message}`);
118
+ throw error;
118
119
  }
119
120
  }
120
121
  static async addJobToQueue(queueKey, jobData, delay, queues) {
@@ -1,6 +1,6 @@
1
1
  import { IRateLimitConfig } from "../interfaces";
2
2
  export declare class RateLimitUtils {
3
- private static redisClient;
3
+ private static readonly redisClient;
4
4
  static checkRateLimit(connectionId: string, provider: string, rateLimitConfigs: Map<string, IRateLimitConfig>): Promise<boolean>;
5
5
  static initializeRateLimitConfigs(): Map<string, IRateLimitConfig>;
6
6
  static isRateLimitAllowed(connectionId: string, provider: string, rateLimitConfigs: Map<string, IRateLimitConfig>): Promise<boolean>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RateLimitUtils = void 0;
4
4
  const redis_1 = require("../../db/redis");
5
5
  const config_1 = require("../../config/config");
6
+ const constants_1 = require("../../constants");
6
7
  class RateLimitUtils {
7
8
  static async checkRateLimit(connectionId, provider, rateLimitConfigs) {
8
9
  const config = rateLimitConfigs.get(provider);
@@ -32,10 +33,45 @@ class RateLimitUtils {
32
33
  static initializeRateLimitConfigs() {
33
34
  const configs = new Map();
34
35
  // Configure rate limits for different providers
35
- configs.set("Sensibo", {
36
+ configs.set(constants_1.CONNECTION_PROVIDERS.SENSIBO, {
36
37
  maxRequests: 5,
37
38
  windowMs: 60000,
38
- provider: "Sensibo",
39
+ provider: constants_1.CONNECTION_PROVIDERS.SENSIBO,
40
+ });
41
+ configs.set(constants_1.CONNECTION_PROVIDERS.TTLOCK, {
42
+ maxRequests: 5,
43
+ windowMs: 60000,
44
+ provider: constants_1.CONNECTION_PROVIDERS.TTLOCK,
45
+ });
46
+ configs.set(constants_1.CONNECTION_PROVIDERS.SCHLAGE, {
47
+ maxRequests: 5,
48
+ windowMs: 60000,
49
+ provider: constants_1.CONNECTION_PROVIDERS.SCHLAGE,
50
+ });
51
+ configs.set(constants_1.CONNECTION_PROVIDERS.SMARTTHINGS, {
52
+ maxRequests: 5,
53
+ windowMs: 60000,
54
+ provider: constants_1.CONNECTION_PROVIDERS.SMARTTHINGS,
55
+ });
56
+ configs.set(constants_1.CONNECTION_PROVIDERS.YALEWIFI, {
57
+ maxRequests: 5,
58
+ windowMs: 60000,
59
+ provider: constants_1.CONNECTION_PROVIDERS.YALEWIFI,
60
+ });
61
+ configs.set(constants_1.CONNECTION_PROVIDERS.TUYA, {
62
+ maxRequests: 5,
63
+ windowMs: 1000,
64
+ provider: constants_1.CONNECTION_PROVIDERS.TUYA,
65
+ });
66
+ configs.set(constants_1.CONNECTION_PROVIDERS.SALTOKS, {
67
+ maxRequests: 5,
68
+ windowMs: 60000,
69
+ provider: constants_1.CONNECTION_PROVIDERS.SALTOKS,
70
+ });
71
+ configs.set(constants_1.CONNECTION_PROVIDERS.VERDANT, {
72
+ maxRequests: 5,
73
+ windowMs: 60000,
74
+ provider: constants_1.CONNECTION_PROVIDERS.VERDANT,
39
75
  });
40
76
  return configs;
41
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [