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.
- package/dist/constants/Service.d.ts +1 -0
- package/dist/queue/entities/HybridHttpQueue.js +1 -1
- package/dist/queue/types/http.types.d.ts +6 -4
- package/dist/queue/types/queue.types.d.ts +4 -2
- package/dist/queue/utils/jobUtils.d.ts +2 -1
- package/dist/queue/utils/queueUtils.js +2 -1
- package/dist/queue/utils/rateLimit.utils.d.ts +1 -1
- package/dist/queue/utils/rateLimit.utils.js +38 -2
- package/package.json +1 -1
|
@@ -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.
|
|
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?:
|
|
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:
|
|
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?:
|
|
18
|
+
headers?: IncomingHttpHeaders;
|
|
17
19
|
queueOptions?: {
|
|
18
20
|
connectionId: string;
|
|
19
21
|
connectionProvider: string;
|
|
20
|
-
microservice:
|
|
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?:
|
|
8
|
+
headers?: IncomingHttpHeaders;
|
|
7
9
|
queueOptions?: {
|
|
8
10
|
connectionId: string;
|
|
9
11
|
connectionProvider: string;
|
|
10
|
-
microservice:
|
|
12
|
+
microservice: SERVICE_NAME;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
@@ -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
|
|
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(
|
|
36
|
+
configs.set(constants_1.CONNECTION_PROVIDERS.SENSIBO, {
|
|
36
37
|
maxRequests: 5,
|
|
37
38
|
windowMs: 60000,
|
|
38
|
-
provider:
|
|
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
|
}
|