dt-common-device 4.0.7 → 5.0.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/dist/alerts/Alert.service.d.ts +1 -1
- package/dist/audit/AuditUtils.d.ts +26 -2
- package/dist/audit/AuditUtils.js +255 -32
- package/dist/audit/IAuditProperties.d.ts +32 -0
- package/dist/audit/IAuditProperties.js +13 -0
- package/dist/audit/PushAudit.d.ts +5 -0
- package/dist/audit/PushAudit.js +16 -0
- package/dist/audit/index.d.ts +2 -0
- package/dist/audit/index.js +18 -0
- package/dist/config/config.d.ts +10 -3
- package/dist/config/config.js +120 -47
- package/dist/config/config.types.d.ts +1 -8
- package/dist/config/constants.d.ts +49 -0
- package/dist/config/constants.js +64 -0
- package/dist/db/db.d.ts +2 -0
- package/dist/db/db.js +23 -1
- package/dist/entities/accessGroup/AccessGroup.repository.d.ts +5 -0
- package/dist/entities/accessGroup/AccessGroup.repository.js +72 -0
- package/dist/entities/accessGroup/AccessGroup.service.d.ts +5 -0
- package/dist/{device/local/repository/Connection.repository.js → entities/accessGroup/AccessGroup.service.js} +50 -37
- package/dist/entities/accessGroup/IAccessGroup.d.ts +14 -0
- package/dist/entities/accessGroup/index.d.ts +2 -0
- package/dist/entities/accessGroup/index.js +18 -0
- package/dist/{admin → entities/admin}/Admin.repository.js +4 -4
- package/dist/{connection → entities/connection}/Connection.repository.js +1 -1
- package/dist/{device → entities/device}/local/repository/Device.repository.d.ts +1 -0
- package/dist/{device → entities/device}/local/repository/Device.repository.js +20 -3
- package/dist/{device → entities/device}/local/repository/Hub.repository.js +3 -3
- package/dist/{device → entities/device}/local/repository/Schedule.repository.js +2 -2
- package/dist/{device → entities/device}/local/services/Device.service.d.ts +10 -9
- package/dist/{device → entities/device}/local/services/Device.service.js +10 -4
- package/dist/entities/guest/Guest.repository.d.ts +6 -0
- package/dist/entities/guest/Guest.repository.js +74 -0
- package/dist/entities/guest/Guest.service.d.ts +6 -0
- package/dist/entities/guest/Guest.service.js +104 -0
- package/dist/entities/guest/IGuest.d.ts +12 -0
- package/dist/entities/guest/index.d.ts +2 -0
- package/dist/entities/guest/index.js +18 -0
- package/dist/{property → entities/property}/Property.repository.js +1 -1
- package/dist/entities/schedules/ISchedule.d.ts +14 -0
- package/dist/entities/schedules/Schedule.repository.d.ts +6 -0
- package/dist/entities/schedules/Schedule.repository.js +74 -0
- package/dist/entities/schedules/Schedule.service.d.ts +6 -0
- package/dist/entities/schedules/Schedule.service.js +104 -0
- package/dist/entities/schedules/index.d.ts +2 -0
- package/dist/entities/schedules/index.js +18 -0
- package/dist/{user → entities/user}/User.repository.js +2 -2
- package/dist/{user → entities/user}/User.service.js +3 -0
- package/dist/entities/zone/IZone.d.ts +10 -0
- package/dist/entities/zone/Zone.repository.d.ts +6 -0
- package/dist/{device/local/repository/Property.repository.js → entities/zone/Zone.repository.js} +14 -32
- package/dist/entities/zone/Zone.service.d.ts +6 -0
- package/dist/entities/zone/Zone.service.js +104 -0
- package/dist/entities/zone/index.d.ts +2 -0
- package/dist/entities/zone/index.js +18 -0
- package/dist/events/BaseEventHandler.d.ts +3 -3
- package/dist/events/BaseEventHandler.js +1 -1
- package/dist/events/DeviceEventHandler.d.ts +1 -1
- package/dist/events/DeviceEventHandler.js +4 -3
- package/dist/events/EventHandler.d.ts +10 -9
- package/dist/events/EventHandler.js +50 -9
- package/dist/events/InternalEventSubscription.js +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.js +10 -8
- package/dist/issues/Issue.service.d.ts +1 -1
- package/dist/microservice/MicroServiceFactory.d.ts +1 -1
- package/dist/microservice/MicroServiceFactory.js +1 -1
- package/dist/utils/http.utils.d.ts +1 -2
- package/dist/utils/http.utils.js +5 -27
- package/package.json +1 -1
- package/dist/audit/AuditProperties.d.ts +0 -16
- package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
- package/dist/device/cloud/entities/CloudConnection.js +0 -6
- package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
- package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
- package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
- package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
- package/dist/device/cloud/interfaces/IHubService.js +0 -2
- package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
- package/dist/device/cloud/services/CloudDevice.service.js +0 -9
- package/dist/device/cloud/services/Connection.service.d.ts +0 -8
- package/dist/device/cloud/services/Connection.service.js +0 -6
- package/dist/device/cloud/services/index.d.ts +0 -2
- package/dist/device/cloud/services/index.js +0 -18
- package/dist/device/cloud/types.d.ts +0 -52
- package/dist/device/cloud/types.js +0 -15
- package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
- package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
- package/dist/device/local/entities/AlertBuilder.example.js +0 -117
- package/dist/device/local/entities/AlertBuilder.js +0 -179
- package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
- package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
- package/dist/device/local/entities/IssueBuilder.example.js +0 -196
- package/dist/device/local/entities/IssueBuilder.js +0 -237
- package/dist/device/local/entities/index.d.ts +0 -2
- package/dist/device/local/entities/index.js +0 -7
- package/dist/device/local/events/EventHandler.d.ts +0 -11
- package/dist/device/local/events/EventHandler.js +0 -86
- package/dist/device/local/events/Events.d.ts +0 -75
- package/dist/device/local/events/Events.js +0 -78
- package/dist/device/local/events/index.d.ts +0 -2
- package/dist/device/local/events/index.js +0 -7
- package/dist/device/local/handler/EventHandler.d.ts +0 -7
- package/dist/device/local/handler/EventHandler.js +0 -44
- package/dist/device/local/interfaces/IConnection.d.ts +0 -26
- package/dist/device/local/interfaces/IConnection.js +0 -14
- package/dist/device/local/interfaces/IHub.d.ts +0 -46
- package/dist/device/local/interfaces/IHub.js +0 -2
- package/dist/device/local/models/Alert.model.d.ts +0 -28
- package/dist/device/local/models/Alert.model.js +0 -222
- package/dist/device/local/models/Issue.model.d.ts +0 -28
- package/dist/device/local/models/Issue.model.js +0 -260
- package/dist/device/local/repository/Alert.repository.d.ts +0 -106
- package/dist/device/local/repository/Alert.repository.js +0 -374
- package/dist/device/local/repository/Connection.repository.d.ts +0 -8
- package/dist/device/local/repository/Issue.repository.d.ts +0 -113
- package/dist/device/local/repository/Issue.repository.js +0 -401
- package/dist/device/local/repository/Property.repository.d.ts +0 -8
- package/dist/device/local/services/Alert.service.d.ts +0 -137
- package/dist/device/local/services/Alert.service.js +0 -475
- package/dist/device/local/services/AlertService.example.d.ts +0 -55
- package/dist/device/local/services/AlertService.example.js +0 -148
- package/dist/device/local/services/Connection.service.d.ts +0 -8
- package/dist/device/local/services/Connection.service.js +0 -32
- package/dist/device/local/services/Issue.service.d.ts +0 -168
- package/dist/device/local/services/Issue.service.js +0 -642
- package/dist/device/local/services/IssueService.example.d.ts +0 -68
- package/dist/device/local/services/IssueService.example.js +0 -177
- package/dist/device/local/services/Property.service.d.ts +0 -8
- package/dist/device/local/services/Property.service.js +0 -36
- package/dist/property/IProperty.d.ts +0 -29
- package/dist/property/IProperty.js +0 -2
- package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
- package/dist/queue/interfaces/IHttpRequestJob.js +0 -2
- package/dist/types/alert.types.d.ts +0 -57
- package/dist/types/alert.types.js +0 -22
- package/dist/types/config.types.d.ts +0 -19
- package/dist/types/config.types.js +0 -2
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -19
- package/dist/types/issue.types.d.ts +0 -90
- package/dist/types/issue.types.js +0 -40
- package/dist/utils/http-utils.d.ts +0 -13
- package/dist/utils/http-utils.js +0 -117
- /package/dist/{audit/AuditProperties.js → entities/accessGroup/IAccessGroup.js} +0 -0
- /package/dist/{admin → entities/admin}/Admin.repository.d.ts +0 -0
- /package/dist/{admin → entities/admin}/Admin.service.d.ts +0 -0
- /package/dist/{admin → entities/admin}/Admin.service.js +0 -0
- /package/dist/{admin → entities/admin}/index.d.ts +0 -0
- /package/dist/{admin → entities/admin}/index.js +0 -0
- /package/dist/{connection → entities/connection}/Connection.repository.d.ts +0 -0
- /package/dist/{connection → entities/connection}/Connection.service.d.ts +0 -0
- /package/dist/{connection → entities/connection}/Connection.service.js +0 -0
- /package/dist/{connection → entities/connection}/IConnection.d.ts +0 -0
- /package/dist/{connection → entities/connection}/IConnection.js +0 -0
- /package/dist/{connection → entities/connection}/index.d.ts +0 -0
- /package/dist/{connection → entities/connection}/index.js +0 -0
- /package/dist/{device → entities/device}/cloud/entities/CloudDevice.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/entities/CloudDevice.js +0 -0
- /package/dist/{device → entities/device}/cloud/entities/CloudDeviceService.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/entities/CloudDeviceService.js +0 -0
- /package/dist/{device → entities/device}/cloud/entities/DeviceFactory.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/entities/DeviceFactory.js +0 -0
- /package/dist/{device → entities/device}/cloud/entities/index.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/entities/index.js +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/ICloudDevice.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/ICloudDevice.js +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/ICloudDeviceService.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/ICloudDeviceService.js +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/IDeviceFactory.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/IDeviceFactory.js +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/IRawDataTransformer.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/IRawDataTransformer.js +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/IRawDevice.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/IRawDevice.js +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/index.d.ts +0 -0
- /package/dist/{device → entities/device}/cloud/interfaces/index.js +0 -0
- /package/dist/{device → entities/device}/local/interfaces/IDevice.d.ts +0 -0
- /package/dist/{device → entities/device}/local/interfaces/IDevice.js +0 -0
- /package/dist/{device → entities/device}/local/interfaces/IDtDevice.d.ts +0 -0
- /package/dist/{device → entities/device}/local/interfaces/IDtDevice.js +0 -0
- /package/dist/{device → entities/device}/local/interfaces/ISchedule.d.ts +0 -0
- /package/dist/{device → entities/device}/local/interfaces/ISchedule.js +0 -0
- /package/dist/{device → entities/device}/local/interfaces/index.d.ts +0 -0
- /package/dist/{device → entities/device}/local/interfaces/index.js +0 -0
- /package/dist/{device → entities/device}/local/repository/Hub.repository.d.ts +0 -0
- /package/dist/{device → entities/device}/local/repository/Schedule.repository.d.ts +0 -0
- /package/dist/{device → entities/device}/local/services/Hub.service.d.ts +0 -0
- /package/dist/{device → entities/device}/local/services/Hub.service.js +0 -0
- /package/dist/{device → entities/device}/local/services/Schedule.service.d.ts +0 -0
- /package/dist/{device → entities/device}/local/services/Schedule.service.js +0 -0
- /package/dist/{device → entities/device}/local/services/index.d.ts +0 -0
- /package/dist/{device → entities/device}/local/services/index.js +0 -0
- /package/dist/{device/cloud/interfaces/ICloudConnection.js → entities/guest/IGuest.js} +0 -0
- /package/dist/{pms → entities/pms}/IPms.d.ts +0 -0
- /package/dist/{pms → entities/pms}/IPms.js +0 -0
- /package/dist/{pms → entities/pms}/index.d.ts +0 -0
- /package/dist/{pms → entities/pms}/index.js +0 -0
- /package/dist/{device/local/interfaces → entities/property}/IProperty.d.ts +0 -0
- /package/dist/{device/local/interfaces → entities/property}/IProperty.js +0 -0
- /package/dist/{property → entities/property}/Property.repository.d.ts +0 -0
- /package/dist/{property → entities/property}/Property.service.d.ts +0 -0
- /package/dist/{property → entities/property}/Property.service.js +0 -0
- /package/dist/{property → entities/property}/index.d.ts +0 -0
- /package/dist/{property → entities/property}/index.js +0 -0
- /package/dist/{device/cloud/interfaces/IConnectionService.js → entities/schedules/ISchedule.js} +0 -0
- /package/dist/{user → entities/user}/IUser.d.ts +0 -0
- /package/dist/{user → entities/user}/IUser.js +0 -0
- /package/dist/{user → entities/user}/User.repository.d.ts +0 -0
- /package/dist/{user → entities/user}/User.service.d.ts +0 -0
- /package/dist/{device/cloud/interfaces/IDeviceService.js → entities/zone/IZone.js} +0 -0
|
@@ -3,7 +3,7 @@ import { IAlertDocument } from "./Alert.model";
|
|
|
3
3
|
import { CreateAlertData, UpdateAlertData, AlertCategory, AlertSeverity, EntityType } from "./alert.types";
|
|
4
4
|
import { Source } from "../constants/Service";
|
|
5
5
|
import { AlertBuilder } from "./AlertBuilder";
|
|
6
|
-
import { IDevice } from "../device/local/interfaces";
|
|
6
|
+
import { IDevice } from "../entities/device/local/interfaces";
|
|
7
7
|
export declare class AlertService {
|
|
8
8
|
private readonly alertRepository;
|
|
9
9
|
constructor(alertRepository: AlertRepository);
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
1
|
+
import { IAuditProperties } from "./IAuditProperties";
|
|
2
|
+
export declare class AuditUtils {
|
|
3
|
+
private readonly redisUtils;
|
|
4
|
+
private readonly CACHE_TTL;
|
|
5
|
+
private readonly CACHE_PREFIX;
|
|
6
|
+
constructor();
|
|
7
|
+
private readonly AUDIT_FIELDS;
|
|
8
|
+
buildAuditProperties(input: IAuditProperties): Promise<IAuditProperties>;
|
|
9
|
+
private populateAuditFields;
|
|
10
|
+
/**
|
|
11
|
+
* Generic utility to get cached entity data from Redis using individual keys
|
|
12
|
+
*/
|
|
13
|
+
private getCachedEntityData;
|
|
14
|
+
/**
|
|
15
|
+
* Utility to calculate schedule duration in days
|
|
16
|
+
*/
|
|
17
|
+
private calculateScheduleDuration;
|
|
18
|
+
private getPropertyName;
|
|
19
|
+
private getPropertyIdFromDevice;
|
|
20
|
+
private getUserName;
|
|
21
|
+
private getGuestName;
|
|
22
|
+
private getDeviceName;
|
|
23
|
+
private getZoneName;
|
|
24
|
+
private getAccessGroupName;
|
|
25
|
+
private getScheduleDetails;
|
|
26
|
+
}
|
package/dist/audit/AuditUtils.js
CHANGED
|
@@ -1,36 +1,259 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"propertyName",
|
|
8
|
-
"userId",
|
|
9
|
-
"userName",
|
|
10
|
-
"deviceId",
|
|
11
|
-
"deviceName",
|
|
12
|
-
"zoneId",
|
|
13
|
-
"zoneName",
|
|
14
|
-
"accessGroupId",
|
|
15
|
-
"accessGroupName",
|
|
16
|
-
"scheduleId",
|
|
17
|
-
"scheduleName",
|
|
18
|
-
];
|
|
19
|
-
function buildAuditProperties(input) {
|
|
20
|
-
// Normalize keys to camelCase for matching
|
|
21
|
-
const normalized = { ...input };
|
|
22
|
-
// Build the audit object with all standard fields
|
|
23
|
-
const audit = {};
|
|
24
|
-
for (const field of AUDIT_FIELDS) {
|
|
25
|
-
// Try to find a matching key in input (case-insensitive)
|
|
26
|
-
const foundKey = Object.keys(normalized).find((k) => k.toLowerCase() === field.toLowerCase());
|
|
27
|
-
audit[field] = foundKey ? normalized[foundKey] : undefined;
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
7
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
19
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
20
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
21
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
22
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
23
|
+
var _, done = false;
|
|
24
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
25
|
+
var context = {};
|
|
26
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
27
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
28
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
29
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
30
|
+
if (kind === "accessor") {
|
|
31
|
+
if (result === void 0) continue;
|
|
32
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
33
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
34
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
35
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
36
|
+
}
|
|
37
|
+
else if (_ = accept(result)) {
|
|
38
|
+
if (kind === "field") initializers.unshift(_);
|
|
39
|
+
else descriptor[key] = _;
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
43
|
+
done = true;
|
|
44
|
+
};
|
|
45
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
46
|
+
var useValue = arguments.length > 2;
|
|
47
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
48
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
49
|
+
}
|
|
50
|
+
return useValue ? value : void 0;
|
|
51
|
+
};
|
|
52
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
53
|
+
var ownKeys = function(o) {
|
|
54
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
55
|
+
var ar = [];
|
|
56
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
57
|
+
return ar;
|
|
58
|
+
};
|
|
59
|
+
return ownKeys(o);
|
|
60
|
+
};
|
|
61
|
+
return function (mod) {
|
|
62
|
+
if (mod && mod.__esModule) return mod;
|
|
63
|
+
var result = {};
|
|
64
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
65
|
+
__setModuleDefault(result, mod);
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
})();
|
|
69
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
70
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
71
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
72
|
+
};
|
|
73
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
74
|
+
exports.AuditUtils = void 0;
|
|
75
|
+
const property_1 = require("../entities/property");
|
|
76
|
+
const redis_utils_1 = require("../utils/redis.utils");
|
|
77
|
+
const User_service_1 = require("../entities/user/User.service");
|
|
78
|
+
const services_1 = require("../entities/device/local/services");
|
|
79
|
+
const accessGroup_1 = require("../entities/accessGroup");
|
|
80
|
+
const zone_1 = require("../entities/zone");
|
|
81
|
+
const schedules_1 = require("../entities/schedules");
|
|
82
|
+
const guest_1 = require("../entities/guest");
|
|
83
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
84
|
+
let AuditUtils = (() => {
|
|
85
|
+
let _classDecorators = [(0, typedi_1.Service)()];
|
|
86
|
+
let _classDescriptor;
|
|
87
|
+
let _classExtraInitializers = [];
|
|
88
|
+
let _classThis;
|
|
89
|
+
var AuditUtils = _classThis = class {
|
|
90
|
+
constructor() {
|
|
91
|
+
this.CACHE_TTL = 24 * 60 * 60; // 24 hours in seconds
|
|
92
|
+
this.CACHE_PREFIX = "audit:entity";
|
|
93
|
+
this.AUDIT_FIELDS = [
|
|
94
|
+
"resource",
|
|
95
|
+
"propertyId",
|
|
96
|
+
"propertyName",
|
|
97
|
+
"userId",
|
|
98
|
+
"userName",
|
|
99
|
+
"guestId",
|
|
100
|
+
"guestName",
|
|
101
|
+
"deviceId",
|
|
102
|
+
"deviceName",
|
|
103
|
+
"zoneId",
|
|
104
|
+
"zoneName",
|
|
105
|
+
"accessGroupId",
|
|
106
|
+
"accessGroupName",
|
|
107
|
+
"scheduleId",
|
|
108
|
+
"scheduleStartDate",
|
|
109
|
+
"scheduleEndDate",
|
|
110
|
+
"scheduleDuration",
|
|
111
|
+
"scheduleSource",
|
|
112
|
+
"scheduleStatus",
|
|
113
|
+
"eventData",
|
|
114
|
+
];
|
|
115
|
+
this.redisUtils = new redis_utils_1.RedisUtils();
|
|
116
|
+
}
|
|
117
|
+
async buildAuditProperties(input) {
|
|
118
|
+
// Normalize keys to camelCase for matching
|
|
119
|
+
const normalized = { ...input };
|
|
120
|
+
// Build the audit object with all standard fields
|
|
121
|
+
const audit = {};
|
|
122
|
+
for (const field of this.AUDIT_FIELDS) {
|
|
123
|
+
// Try to find a matching key in input (case-insensitive)
|
|
124
|
+
const foundKey = Object.keys(normalized).find((k) => k.toLowerCase() === field.toLowerCase());
|
|
125
|
+
audit[field] = foundKey ? normalized[foundKey] : undefined;
|
|
126
|
+
}
|
|
127
|
+
// Merge in all other event-specific data (but don't overwrite audit fields)
|
|
128
|
+
for (const key of Object.keys(normalized)) {
|
|
129
|
+
if (!audit.hasOwnProperty(key)) {
|
|
130
|
+
audit[key] = normalized[key];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Util Function that will take all id Fields and get related information from database and add to audit
|
|
134
|
+
await this.populateAuditFields(audit);
|
|
135
|
+
return audit;
|
|
136
|
+
}
|
|
137
|
+
async populateAuditFields(audit) {
|
|
138
|
+
const { propertyId, propertyName, userId, userName, guestId, guestName, deviceId, deviceName, zoneId, zoneName, accessGroupId, accessGroupName, scheduleId, } = audit;
|
|
139
|
+
if (propertyId && !propertyName)
|
|
140
|
+
audit.propertyName = await this.getPropertyName(propertyId);
|
|
141
|
+
if (!propertyId && deviceId) {
|
|
142
|
+
audit.propertyId = await this.getPropertyIdFromDevice(deviceId);
|
|
143
|
+
audit.propertyName = await this.getPropertyName(audit.propertyId);
|
|
144
|
+
}
|
|
145
|
+
if (userId && !userName)
|
|
146
|
+
audit.userName = await this.getUserName(userId);
|
|
147
|
+
if (guestId && !guestName)
|
|
148
|
+
audit.guestName = await this.getGuestName(guestId);
|
|
149
|
+
if (deviceId && !deviceName)
|
|
150
|
+
audit.deviceName = await this.getDeviceName(deviceId);
|
|
151
|
+
if (zoneId && !zoneName)
|
|
152
|
+
audit.zoneName = await this.getZoneName(zoneId);
|
|
153
|
+
if (accessGroupId && !accessGroupName)
|
|
154
|
+
audit.accessGroupName = await this.getAccessGroupName(accessGroupId);
|
|
155
|
+
if (scheduleId) {
|
|
156
|
+
const { scheduleStartDate, scheduleEndDate, scheduleDuration, scheduleSource, scheduleStatus, } = await this.getScheduleDetails(scheduleId);
|
|
157
|
+
audit.scheduleStartDate = scheduleStartDate;
|
|
158
|
+
audit.scheduleEndDate = scheduleEndDate;
|
|
159
|
+
audit.scheduleDuration = scheduleDuration;
|
|
160
|
+
audit.scheduleSource = scheduleSource;
|
|
161
|
+
audit.scheduleStatus = scheduleStatus;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Generic utility to get cached entity data from Redis using individual keys
|
|
166
|
+
*/
|
|
167
|
+
async getCachedEntityData(entityType, entityId, fetchFunction) {
|
|
168
|
+
const cacheKey = `${this.CACHE_PREFIX}:${entityType}:${entityId}`;
|
|
169
|
+
// Try to get from cache first
|
|
170
|
+
const cachedData = await this.redisUtils.get(cacheKey);
|
|
171
|
+
if (cachedData) {
|
|
172
|
+
return JSON.parse(cachedData);
|
|
173
|
+
}
|
|
174
|
+
// If not in cache, fetch from database and cache it
|
|
175
|
+
const entityData = await fetchFunction();
|
|
176
|
+
await this.redisUtils.set(cacheKey, JSON.stringify(entityData), this.CACHE_TTL);
|
|
177
|
+
return entityData;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Utility to calculate schedule duration in days
|
|
181
|
+
*/
|
|
182
|
+
calculateScheduleDuration(startTime, endTime) {
|
|
183
|
+
const duration = new Date(endTime).getTime() - new Date(startTime).getTime();
|
|
184
|
+
return Math.ceil(duration / (1000 * 60 * 60 * 24));
|
|
185
|
+
}
|
|
186
|
+
async getPropertyName(propertyId) {
|
|
187
|
+
return this.getCachedEntityData("property", propertyId, async () => {
|
|
188
|
+
const property = await typedi_1.default.get(property_1.LocalPropertyService).getProperty(propertyId);
|
|
189
|
+
return property?.name || "";
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async getPropertyIdFromDevice(deviceId) {
|
|
193
|
+
const redisKey = `device:${deviceId}`;
|
|
194
|
+
const redisDevice = await this.redisUtils.hget(redisKey, "device");
|
|
195
|
+
if (redisDevice) {
|
|
196
|
+
return JSON.parse(redisDevice).propertyId;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
const device = await typedi_1.default.get(services_1.LocalDeviceService).getDevice(deviceId);
|
|
200
|
+
await this.redisUtils.hset(redisKey, "device", JSON.stringify(device));
|
|
201
|
+
await this.redisUtils.expire(redisKey, this.CACHE_TTL);
|
|
202
|
+
return device.propertyId;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async getUserName(userId) {
|
|
206
|
+
return this.getCachedEntityData("user", userId, async () => {
|
|
207
|
+
const user = await typedi_1.default.get(User_service_1.UserService).getUser(userId);
|
|
208
|
+
return `${user?.firstName || ""} ${user?.lastName || ""}`.trim();
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
async getGuestName(guestId) {
|
|
212
|
+
return this.getCachedEntityData("guest", guestId, async () => {
|
|
213
|
+
const guest = await typedi_1.default.get(guest_1.GuestService).getGuest(guestId);
|
|
214
|
+
return `${guest?.firstName || ""} ${guest?.lastName || ""}`.trim();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async getDeviceName(deviceId) {
|
|
218
|
+
return this.getCachedEntityData("device", deviceId, async () => {
|
|
219
|
+
const device = await typedi_1.default.get(services_1.LocalDeviceService).querySelect({ deviceId }, ["name"]);
|
|
220
|
+
return device?.name || "";
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async getZoneName(zoneId) {
|
|
224
|
+
return this.getCachedEntityData("zone", zoneId, async () => {
|
|
225
|
+
const zone = await typedi_1.default.get(zone_1.ZoneService).getZone(zoneId);
|
|
226
|
+
return zone?.name || "";
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async getAccessGroupName(accessGroupId) {
|
|
230
|
+
return this.getCachedEntityData("accessGroup", accessGroupId, async () => {
|
|
231
|
+
const accessGroup = await typedi_1.default.get(accessGroup_1.AccessGroupService).getAccessGroup(accessGroupId);
|
|
232
|
+
return accessGroup?.name || "";
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
async getScheduleDetails(scheduleId) {
|
|
236
|
+
return this.getCachedEntityData("schedule", scheduleId, async () => {
|
|
237
|
+
const schedule = await typedi_1.default.get(schedules_1.ScheduleService).getSchedule(scheduleId);
|
|
238
|
+
const scheduleDuration = this.calculateScheduleDuration(schedule.startTime, schedule.endTime);
|
|
239
|
+
return {
|
|
240
|
+
scheduleStartDate: schedule.startTime,
|
|
241
|
+
scheduleEndDate: schedule.endTime,
|
|
242
|
+
scheduleDuration,
|
|
243
|
+
scheduleSource: schedule.source,
|
|
244
|
+
scheduleStatus: schedule.status,
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
__setFunctionName(_classThis, "AuditUtils");
|
|
250
|
+
(() => {
|
|
251
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
252
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
253
|
+
AuditUtils = _classThis = _classDescriptor.value;
|
|
254
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
255
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
256
|
+
})();
|
|
257
|
+
return AuditUtils = _classThis;
|
|
258
|
+
})();
|
|
259
|
+
exports.AuditUtils = AuditUtils;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare enum Resource {
|
|
2
|
+
ORGANIZATION = "organization",
|
|
3
|
+
PROPERTY = "property",
|
|
4
|
+
ACCESS_GROUP = "accessGroup",
|
|
5
|
+
ZONE = "zone",
|
|
6
|
+
DEVICE = "device",
|
|
7
|
+
SCHEDULE = "schedule",
|
|
8
|
+
USER = "user"
|
|
9
|
+
}
|
|
10
|
+
export interface IAuditProperties {
|
|
11
|
+
resource: Resource;
|
|
12
|
+
propertyId: string;
|
|
13
|
+
propertyName?: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
userName?: string;
|
|
16
|
+
guestId?: string;
|
|
17
|
+
guestName?: string;
|
|
18
|
+
deviceId?: string;
|
|
19
|
+
deviceName?: string;
|
|
20
|
+
zoneId?: string;
|
|
21
|
+
zoneName?: string;
|
|
22
|
+
accessGroupId?: string;
|
|
23
|
+
accessGroupName?: string;
|
|
24
|
+
scheduleId?: string;
|
|
25
|
+
scheduleStartDate?: string;
|
|
26
|
+
scheduleEndDate?: string;
|
|
27
|
+
scheduleDuration?: number;
|
|
28
|
+
scheduleSource?: string;
|
|
29
|
+
scheduleStatus?: string;
|
|
30
|
+
eventData?: any;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Resource = void 0;
|
|
4
|
+
var Resource;
|
|
5
|
+
(function (Resource) {
|
|
6
|
+
Resource["ORGANIZATION"] = "organization";
|
|
7
|
+
Resource["PROPERTY"] = "property";
|
|
8
|
+
Resource["ACCESS_GROUP"] = "accessGroup";
|
|
9
|
+
Resource["ZONE"] = "zone";
|
|
10
|
+
Resource["DEVICE"] = "device";
|
|
11
|
+
Resource["SCHEDULE"] = "schedule";
|
|
12
|
+
Resource["USER"] = "user";
|
|
13
|
+
})(Resource || (exports.Resource = Resource = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pushAudit = pushAudit;
|
|
7
|
+
const dt_audit_library_1 = require("dt-audit-library");
|
|
8
|
+
const AuditUtils_1 = require("./AuditUtils");
|
|
9
|
+
const typedi_1 = __importDefault(require("typedi"));
|
|
10
|
+
async function pushAudit(data) {
|
|
11
|
+
const audit = await typedi_1.default.get(AuditUtils_1.AuditUtils).buildAuditProperties(data.auditData);
|
|
12
|
+
await (0, dt_audit_library_1.publishAudit)({
|
|
13
|
+
eventType: data.auditType,
|
|
14
|
+
properties: audit,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PushAudit"), exports);
|
|
18
|
+
__exportStar(require("./IAuditProperties"), exports);
|
package/dist/config/config.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { InternalEventSubscription } from "../events";
|
|
2
|
-
import { IConfig } from "./config.types";
|
|
2
|
+
import { IConfig, ILogger } from "./config.types";
|
|
3
3
|
export declare function initialize(cfg: IConfig): Promise<void>;
|
|
4
4
|
export declare function getConfig(): IConfig;
|
|
5
|
+
export declare function getDeviceServiceUrl(): string;
|
|
6
|
+
export declare function getAdminServiceUrl(): string;
|
|
7
|
+
export declare function getSqsQueueUrl(): string;
|
|
5
8
|
export declare function getEventSubscription(): InternalEventSubscription | null;
|
|
6
|
-
export declare function checkRequiredEnv(): void;
|
|
9
|
+
export declare function checkRequiredEnv(requiredEnvs: string[]): void;
|
|
7
10
|
export declare function ensureAuditInitialized(): void;
|
|
11
|
+
export declare function getLogger(): ILogger;
|
|
8
12
|
/**
|
|
9
13
|
* Returns the PostgreSQL DB URI from environment variables.
|
|
10
14
|
* Throws an error if not set.
|
|
11
15
|
*/
|
|
12
|
-
export declare function
|
|
16
|
+
export declare function getAdminPostgresDbUri(): string;
|
|
17
|
+
export declare function getAccessPostgresDbUri(): string;
|
|
18
|
+
export declare function getPmsPostgresDbUri(): string;
|
|
13
19
|
export declare function getMongoUri(): string;
|
|
20
|
+
export declare function getDTApiKey(): string;
|
|
14
21
|
/**
|
|
15
22
|
* Returns the Redis DB Host and port from environment variables.
|
|
16
23
|
* Throws an error if not set.
|