dt-common-device 3.1.0 → 3.1.2
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/admin/Admin.repository.d.ts +7 -0
- package/dist/admin/Admin.repository.js +182 -0
- package/dist/admin/Admin.service.d.ts +5 -0
- package/dist/admin/Admin.service.js +17 -0
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.js +17 -0
- package/dist/config/config.js +4 -0
- package/dist/config/config.types.d.ts +2 -0
- package/dist/constants/ConnectionProviders.d.ts +1 -0
- package/dist/constants/ConnectionProviders.js +1 -0
- package/dist/device/cloud/entities/DeviceFactory.js +73 -14
- package/dist/device/local/services/Device.service.js +294 -239
- package/dist/device/local/services/Hub.service.js +92 -38
- package/dist/events/BaseEventHandler.js +6 -1
- package/dist/events/DeviceEventHandler.js +6 -1
- package/dist/events/EventHandler.js +158 -104
- package/dist/events/EventProcessingService.js +8 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/microservice/MicroServiceFactory.d.ts +1 -1
- package/dist/microservice/MicroServiceFactory.js +5 -3
- package/dist/property/Property.service.js +86 -27
- package/dist/queue/services/QueueService.js +6 -1
- package/dist/queue/utils/rateLimit.utils.js +13 -8
- package/dist/utils/http.utils.d.ts +2 -0
- package/dist/utils/http.utils.js +30 -0
- package/package.json +1 -1
|
@@ -1,36 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
2
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
44
|
exports.LocalPropertyService = void 0;
|
|
4
45
|
const Property_repository_1 = require("./Property.repository");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
46
|
+
const typedi_1 = __importDefault(require("typedi"));
|
|
47
|
+
const typedi_2 = require("typedi");
|
|
48
|
+
let LocalPropertyService = (() => {
|
|
49
|
+
let _classDecorators = [(0, typedi_2.Service)()];
|
|
50
|
+
let _classDescriptor;
|
|
51
|
+
let _classExtraInitializers = [];
|
|
52
|
+
let _classThis;
|
|
53
|
+
var LocalPropertyService = _classThis = class {
|
|
54
|
+
constructor() {
|
|
55
|
+
// Use dependency injection instead of creating new instance
|
|
56
|
+
this.propertyRepository = typedi_1.default.get(Property_repository_1.PropertyRepository);
|
|
12
57
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
58
|
+
async getPropertyPreferences(propertyId) {
|
|
59
|
+
if (!propertyId) {
|
|
60
|
+
throw new Error("Property ID is required");
|
|
61
|
+
}
|
|
62
|
+
return await this.propertyRepository.getPropertyPreferences(propertyId);
|
|
18
63
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
64
|
+
async getProperty(propertyId) {
|
|
65
|
+
if (!propertyId) {
|
|
66
|
+
throw new Error("Property ID is required");
|
|
67
|
+
}
|
|
68
|
+
return await this.propertyRepository.getProperty(propertyId);
|
|
24
69
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
70
|
+
async getPropertyTimeZone(propertyId) {
|
|
71
|
+
if (!propertyId) {
|
|
72
|
+
throw new Error("Property ID is required");
|
|
73
|
+
}
|
|
74
|
+
const property = await this.propertyRepository.getProperty(propertyId);
|
|
75
|
+
if (!property) {
|
|
76
|
+
throw new Error("Property not found");
|
|
77
|
+
}
|
|
78
|
+
return property.timezone;
|
|
28
79
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
80
|
+
async getAllProperties() {
|
|
81
|
+
const properties = await this.propertyRepository.getAllProperties();
|
|
82
|
+
return properties;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
__setFunctionName(_classThis, "LocalPropertyService");
|
|
86
|
+
(() => {
|
|
87
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
88
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
89
|
+
LocalPropertyService = _classThis = _classDescriptor.value;
|
|
90
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
91
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
92
|
+
})();
|
|
93
|
+
return LocalPropertyService = _classThis;
|
|
94
|
+
})();
|
|
36
95
|
exports.LocalPropertyService = LocalPropertyService;
|
|
@@ -37,10 +37,14 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
37
37
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
38
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
39
|
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
40
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
44
|
exports.QueueService = void 0;
|
|
42
45
|
const typedi_1 = require("typedi");
|
|
43
46
|
const HybridHttpQueue_1 = require("../entities/HybridHttpQueue");
|
|
47
|
+
const typedi_2 = __importDefault(require("typedi"));
|
|
44
48
|
let QueueService = (() => {
|
|
45
49
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
46
50
|
let _classDescriptor;
|
|
@@ -48,7 +52,8 @@ let QueueService = (() => {
|
|
|
48
52
|
let _classThis;
|
|
49
53
|
var QueueService = _classThis = class {
|
|
50
54
|
constructor() {
|
|
51
|
-
|
|
55
|
+
// Use dependency injection instead of creating new instance
|
|
56
|
+
this.hybridQueue = typedi_2.default.get(HybridHttpQueue_1.HybridHttpQueue);
|
|
52
57
|
}
|
|
53
58
|
async request(options) {
|
|
54
59
|
return this.hybridQueue.request(options);
|
|
@@ -34,23 +34,28 @@ class RateLimitUtils {
|
|
|
34
34
|
const configs = new Map();
|
|
35
35
|
// Configure rate limits for different providers
|
|
36
36
|
configs.set(constants_1.CONNECTION_PROVIDERS.SENSIBO, {
|
|
37
|
-
maxRequests:
|
|
38
|
-
windowMs:
|
|
37
|
+
maxRequests: 10,
|
|
38
|
+
windowMs: 10000, // 10 seconds
|
|
39
39
|
provider: constants_1.CONNECTION_PROVIDERS.SENSIBO,
|
|
40
40
|
});
|
|
41
|
+
configs.set(constants_1.CONNECTION_PROVIDERS.CLOUDBEDS, {
|
|
42
|
+
maxRequests: 10,
|
|
43
|
+
windowMs: 10000, // 10 seconds
|
|
44
|
+
provider: constants_1.CONNECTION_PROVIDERS.CLOUDBEDS,
|
|
45
|
+
});
|
|
41
46
|
configs.set(constants_1.CONNECTION_PROVIDERS.TTLOCK, {
|
|
42
|
-
maxRequests:
|
|
43
|
-
windowMs: 60000,
|
|
47
|
+
maxRequests: 15,
|
|
48
|
+
windowMs: 60000, // 1 minute
|
|
44
49
|
provider: constants_1.CONNECTION_PROVIDERS.TTLOCK,
|
|
45
50
|
});
|
|
46
51
|
configs.set(constants_1.CONNECTION_PROVIDERS.SCHLAGE, {
|
|
47
|
-
maxRequests:
|
|
48
|
-
windowMs: 60000,
|
|
52
|
+
maxRequests: 120,
|
|
53
|
+
windowMs: 60000, // 1 minute
|
|
49
54
|
provider: constants_1.CONNECTION_PROVIDERS.SCHLAGE,
|
|
50
55
|
});
|
|
51
56
|
configs.set(constants_1.CONNECTION_PROVIDERS.SMARTTHINGS, {
|
|
52
|
-
maxRequests:
|
|
53
|
-
windowMs: 60000,
|
|
57
|
+
maxRequests: 250,
|
|
58
|
+
windowMs: 60000, // 1 minute
|
|
54
59
|
provider: constants_1.CONNECTION_PROVIDERS.SMARTTHINGS,
|
|
55
60
|
});
|
|
56
61
|
configs.set(constants_1.CONNECTION_PROVIDERS.YALEWIFI, {
|
|
@@ -7,6 +7,8 @@ export declare function validateServiceUrl(url: string): boolean;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function createAxiosInstance(baseURL?: string): import("axios").AxiosInstance;
|
|
9
9
|
export declare function getDeviceServiceAxiosInstance(): any;
|
|
10
|
+
export declare function getAccessServiceAxiosInstance(): any;
|
|
11
|
+
export declare function getCloudServiceAxiosInstance(): any;
|
|
10
12
|
/**
|
|
11
13
|
* Retry function for failed HTTP requests
|
|
12
14
|
*/
|
package/dist/utils/http.utils.js
CHANGED
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.validateServiceUrl = validateServiceUrl;
|
|
7
7
|
exports.createAxiosInstance = createAxiosInstance;
|
|
8
8
|
exports.getDeviceServiceAxiosInstance = getDeviceServiceAxiosInstance;
|
|
9
|
+
exports.getAccessServiceAxiosInstance = getAccessServiceAxiosInstance;
|
|
10
|
+
exports.getCloudServiceAxiosInstance = getCloudServiceAxiosInstance;
|
|
9
11
|
exports.retryRequest = retryRequest;
|
|
10
12
|
const config_1 = require("../config/config");
|
|
11
13
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -89,6 +91,34 @@ function getDeviceServiceAxiosInstance() {
|
|
|
89
91
|
}
|
|
90
92
|
return deviceServiceAxiosInstance;
|
|
91
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Centralized axios instance for access service
|
|
96
|
+
*/
|
|
97
|
+
let accessServiceAxiosInstance = null;
|
|
98
|
+
function getAccessServiceAxiosInstance() {
|
|
99
|
+
if (!accessServiceAxiosInstance) {
|
|
100
|
+
const { ACCESS_SERVICE } = (0, config_1.getConfig)();
|
|
101
|
+
if (!ACCESS_SERVICE) {
|
|
102
|
+
throw new Error("ACCESS_SERVICE is not configured. Call initialize() first with ACCESS_SERVICE.");
|
|
103
|
+
}
|
|
104
|
+
accessServiceAxiosInstance = createAxiosInstance(ACCESS_SERVICE);
|
|
105
|
+
}
|
|
106
|
+
return accessServiceAxiosInstance;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Centralized axios instance for cloud service (smart-cloud)
|
|
110
|
+
*/
|
|
111
|
+
let cloudServiceAxiosInstance = null;
|
|
112
|
+
function getCloudServiceAxiosInstance() {
|
|
113
|
+
const { ADMIN_SERVICE } = (0, config_1.getConfig)();
|
|
114
|
+
if (!cloudServiceAxiosInstance) {
|
|
115
|
+
if (!ADMIN_SERVICE) {
|
|
116
|
+
throw new Error("ADMIN_SERVICE is not configured. Call initialize() first with ADMIN_SERVICE.");
|
|
117
|
+
}
|
|
118
|
+
cloudServiceAxiosInstance = createAxiosInstance(ADMIN_SERVICE);
|
|
119
|
+
}
|
|
120
|
+
return cloudServiceAxiosInstance;
|
|
121
|
+
}
|
|
92
122
|
/**
|
|
93
123
|
* Retry function for failed HTTP requests
|
|
94
124
|
*/
|