dt-common-device 3.0.9 → 3.0.11

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.
Files changed (144) hide show
  1. package/dist/config/config.d.ts +1 -2
  2. package/dist/config/config.js +4 -5
  3. package/dist/device/cloud/interface.d.ts +101 -0
  4. package/dist/device/cloud/interface.js +3 -0
  5. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
  6. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
  7. package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
  8. package/dist/device/cloud/services/Device.service.d.ts +39 -0
  9. package/dist/device/cloud/services/Device.service.js +9 -0
  10. package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
  11. package/dist/device/cloud/services/DeviceCloudService.js +59 -0
  12. package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
  13. package/dist/device/cloud/services/DeviceHub.service.js +6 -0
  14. package/dist/device/cloud/services/Hub.service.d.ts +25 -0
  15. package/dist/device/cloud/services/Hub.service.js +9 -0
  16. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
  17. package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
  18. package/dist/device/index.d.ts +4 -0
  19. package/dist/device/index.js +20 -0
  20. package/dist/device/local/events/EventHandler.js +6 -6
  21. package/dist/device/local/events/Events.d.ts +12 -33
  22. package/dist/device/local/events/Events.js +12 -33
  23. package/dist/device/local/interface.d.ts +0 -0
  24. package/dist/device/local/interface.js +1 -0
  25. package/dist/device/local/interfaces/IDevice.d.ts +1 -0
  26. package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
  27. package/dist/device/local/repository/Schedule.repository.js +6 -6
  28. package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
  29. package/dist/device/local/services/DeviceHub.service.js +40 -0
  30. package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
  31. package/dist/queue/entities/HybridHttpQueue.js +31 -119
  32. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
  33. package/dist/queue/interfaces/IJobResult.d.ts +1 -8
  34. package/dist/queue/interfaces/index.d.ts +0 -1
  35. package/dist/queue/interfaces/index.js +0 -1
  36. package/dist/queue/services/QueueService.d.ts +2 -12
  37. package/dist/queue/types/queue.types.d.ts +10 -29
  38. package/dist/queue/utils/jobUtils.d.ts +0 -3
  39. package/dist/queue/utils/jobUtils.js +0 -48
  40. package/dist/queue/utils/queueUtils.d.ts +7 -0
  41. package/dist/queue/utils/queueUtils.js +113 -4
  42. package/package.json +6 -1
  43. package/.eslintrc.js +0 -44
  44. package/dist/audit/AuditProperties.d.ts +0 -16
  45. package/dist/audit/AuditUtils.d.ts +0 -2
  46. package/dist/audit/AuditUtils.js +0 -36
  47. package/src/alerts/Alert.model.ts +0 -289
  48. package/src/alerts/Alert.repository.ts +0 -487
  49. package/src/alerts/Alert.service.ts +0 -711
  50. package/src/alerts/AlertBuilder.example.ts +0 -126
  51. package/src/alerts/AlertBuilder.ts +0 -208
  52. package/src/alerts/AlertService.example.ts +0 -232
  53. package/src/alerts/alert.types.ts +0 -64
  54. package/src/alerts/index.ts +0 -3
  55. package/src/audit/AuditProperties.ts +0 -16
  56. package/src/audit/AuditUtils.ts +0 -38
  57. package/src/config/config.ts +0 -202
  58. package/src/config/config.types.ts +0 -21
  59. package/src/connection/Connection.repository.ts +0 -52
  60. package/src/connection/Connection.service.ts +0 -39
  61. package/src/connection/IConnection.ts +0 -27
  62. package/src/connection/index.ts +0 -3
  63. package/src/constants/ConnectionProviders.ts +0 -11
  64. package/src/constants/Event.ts +0 -89
  65. package/src/constants/Service.ts +0 -17
  66. package/src/constants/index.ts +0 -3
  67. package/src/db/db.ts +0 -24
  68. package/src/db/index.ts +0 -2
  69. package/src/db/redis.ts +0 -20
  70. package/src/device/cloud/entities/CloudDevice.ts +0 -40
  71. package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
  72. package/src/device/cloud/entities/DeviceFactory.ts +0 -27
  73. package/src/device/cloud/entities/index.ts +0 -3
  74. package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
  75. package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
  76. package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
  77. package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
  78. package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
  79. package/src/device/cloud/interfaces/index.ts +0 -5
  80. package/src/device/local/interfaces/IDevice.ts +0 -61
  81. package/src/device/local/interfaces/IDtDevice.ts +0 -16
  82. package/src/device/local/interfaces/ISchedule.ts +0 -40
  83. package/src/device/local/interfaces/index.ts +0 -3
  84. package/src/device/local/repository/Device.repository.ts +0 -368
  85. package/src/device/local/repository/Hub.repository.ts +0 -107
  86. package/src/device/local/repository/Schedule.repository.ts +0 -72
  87. package/src/device/local/services/Device.service.ts +0 -436
  88. package/src/device/local/services/Hub.service.ts +0 -57
  89. package/src/device/local/services/Schedule.service.ts +0 -26
  90. package/src/device/local/services/index.ts +0 -3
  91. package/src/docs/Alert.model.md +0 -319
  92. package/src/docs/Alerts&IssuesModel.md +0 -312
  93. package/src/docs/Issue.model.md +0 -386
  94. package/src/docs/SECURITY.md +0 -67
  95. package/src/docs/TROUBLESHOOTING.md +0 -184
  96. package/src/events/BaseEventHandler.ts +0 -145
  97. package/src/events/BaseEventTransformer.ts +0 -97
  98. package/src/events/DeviceEventHandler.ts +0 -213
  99. package/src/events/DeviceEventTransformerFactory.ts +0 -77
  100. package/src/events/EventHandler.ts +0 -124
  101. package/src/events/EventHandlerOrchestrator.ts +0 -119
  102. package/src/events/EventProcessingService.ts +0 -248
  103. package/src/events/InternalEventSubscription.ts +0 -194
  104. package/src/events/index.ts +0 -9
  105. package/src/events/interfaces/DeviceEvent.ts +0 -56
  106. package/src/events/interfaces/IEventHandler.ts +0 -28
  107. package/src/events/interfaces/IEventTransformer.ts +0 -8
  108. package/src/events/interfaces/IInternalEvent.ts +0 -33
  109. package/src/events/interfaces/index.ts +0 -4
  110. package/src/index.ts +0 -43
  111. package/src/issues/Issue.model.ts +0 -350
  112. package/src/issues/Issue.repository.ts +0 -517
  113. package/src/issues/Issue.service.ts +0 -932
  114. package/src/issues/IssueBuilder.example.ts +0 -210
  115. package/src/issues/IssueBuilder.ts +0 -263
  116. package/src/issues/IssueService.example.ts +0 -310
  117. package/src/issues/index.ts +0 -2
  118. package/src/issues/issue.types.ts +0 -98
  119. package/src/property/IProperty.ts +0 -30
  120. package/src/property/Property.repository.ts +0 -53
  121. package/src/property/Property.service.ts +0 -38
  122. package/src/property/index.ts +0 -2
  123. package/src/queue/entities/HybridHttpQueue.ts +0 -274
  124. package/src/queue/entities/index.ts +0 -1
  125. package/src/queue/index.ts +0 -6
  126. package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
  127. package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
  128. package/src/queue/interfaces/IJobResult.ts +0 -15
  129. package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
  130. package/src/queue/interfaces/index.ts +0 -4
  131. package/src/queue/services/QueueService.ts +0 -40
  132. package/src/queue/services/index.ts +0 -1
  133. package/src/queue/types/http.types.ts +0 -23
  134. package/src/queue/types/index.ts +0 -2
  135. package/src/queue/types/queue.types.ts +0 -21
  136. package/src/queue/utils/index.ts +0 -3
  137. package/src/queue/utils/jobUtils.ts +0 -79
  138. package/src/queue/utils/queueUtils.ts +0 -84
  139. package/src/queue/utils/rateLimit.utils.ts +0 -131
  140. package/src/utils/http.utils.ts +0 -143
  141. package/src/utils/index.ts +0 -2
  142. package/src/utils/redis.utils.ts +0 -74
  143. package/tsconfig.json +0 -20
  144. /package/dist/{audit/AuditProperties.js → device/cloud/interfaces/IDevicesService.js} +0 -0
@@ -1,202 +0,0 @@
1
- import { initializeAudit } from "dt-audit-library";
2
- import { connectDatabase } from "../db/db";
3
- import dotenv from "dotenv";
4
- import { InternalEventSubscription } from "../events";
5
- import { validateServiceUrl } from "../utils/http.utils";
6
- import { IConfig, ILogger } from "./config.types";
7
-
8
- dotenv.config();
9
-
10
- let config: IConfig | null = null;
11
- let auditInitialized = false;
12
- let eventSubscription: InternalEventSubscription | null = null;
13
-
14
- export async function initialize(cfg: IConfig): Promise<void> {
15
- // Initialize config
16
- config = { ...cfg };
17
-
18
- // Validate service URLs if provided
19
- if (cfg.DEVICE_SERVICE && !validateServiceUrl(cfg.DEVICE_SERVICE)) {
20
- throw new Error(`Invalid DEVICE_SERVICE URL: ${cfg.DEVICE_SERVICE}`);
21
- }
22
- if (cfg.ADMIN_SERVICE && !validateServiceUrl(cfg.ADMIN_SERVICE)) {
23
- throw new Error(`Invalid ADMIN_SERVICE URL: ${cfg.ADMIN_SERVICE}`);
24
- }
25
- if (cfg.ACCESS_SERVICE && !validateServiceUrl(cfg.ACCESS_SERVICE)) {
26
- throw new Error(`Invalid ACCESS_SERVICE URL: ${cfg.ACCESS_SERVICE}`);
27
- }
28
- if (cfg.ENERGY_SERVICE && !validateServiceUrl(cfg.ENERGY_SERVICE)) {
29
- throw new Error(`Invalid ENERGY_SERVICE URL: ${cfg.ENERGY_SERVICE}`);
30
- }
31
-
32
- // Initialize internal event subscription if handler is provided
33
- if (cfg.INTERNAL_EVENT_HANDLER) {
34
- try {
35
- eventSubscription = new InternalEventSubscription(
36
- cfg.INTERNAL_EVENT_HANDLER
37
- );
38
- cfg.LOGGER.info("InternalEventSubscription initialized successfully");
39
- } catch (error) {
40
- cfg.LOGGER.error("Failed to initialize InternalEventSubscription", {
41
- error,
42
- });
43
- throw error;
44
- }
45
- }
46
-
47
- // Connect to databases
48
- try {
49
- await connectDatabase();
50
- cfg.LOGGER.info("Database connections established successfully");
51
- } catch (error) {
52
- cfg.LOGGER.error("Failed to connect to databases", { error });
53
- throw error;
54
- }
55
-
56
- // Subscribe to events if event subscription is available
57
- if (eventSubscription) {
58
- try {
59
- await eventSubscription.subscribe();
60
- cfg.LOGGER.info("Event subscription started successfully");
61
- } catch (error: any) {
62
- cfg.LOGGER.error(
63
- `Failed to start event subscription: ${
64
- error.message || error.toString()
65
- }`
66
- );
67
- // Don't throw here as the main setup should continue
68
- }
69
- }
70
-
71
- // Check if required env variables are set
72
- checkRequiredEnv();
73
-
74
- // Initialize audit
75
- ensureAuditInitialized();
76
-
77
- console.log("dt-common-device: Initialization completed successfully");
78
- }
79
-
80
- export function getConfig(): IConfig {
81
- if (!config) {
82
- throw new Error(
83
- "dt-common-device: Library not initialized. Call initialize() first."
84
- );
85
- }
86
- return config;
87
- }
88
-
89
- // Direct logger export for easier usage
90
- export function getLogger(): ILogger {
91
- return getConfig().LOGGER;
92
- }
93
-
94
- export function getEventSubscription(): InternalEventSubscription | null {
95
- return eventSubscription;
96
- }
97
-
98
- export function checkRequiredEnv() {
99
- const requiredEnv = [
100
- "AWS_SECRET_ACCESS_KEY",
101
- "AWS_REGION",
102
- "AWS_ACCESS_KEY_ID",
103
- "EVENT_BUS_NAME",
104
- "ADMIN_DB_URI",
105
- "MONGODB_URI",
106
- "REDIS_HOST",
107
- "REDIS_PORT",
108
- "POSTHOG_API_KEY",
109
- "POSTHOG_HOST",
110
- ];
111
- const missing = requiredEnv.filter((key) => !process.env[key]);
112
- if (missing.length > 0) {
113
- throw new Error(
114
- `Missing required AWS environment variables for dt-pub-sub: ${missing.join(
115
- ", "
116
- )}`
117
- );
118
- }
119
- }
120
-
121
- export function ensureAuditInitialized() {
122
- if (auditInitialized) return;
123
-
124
- const apiKey = process.env.POSTHOG_API_KEY;
125
- const host = process.env.POSTHOG_HOST;
126
-
127
- if (!apiKey || !host) {
128
- getConfig().LOGGER.error(
129
- "POSTHOG_API_KEY and POSTHOG_HOST must be set in environment variables"
130
- );
131
- throw new Error(
132
- "dt-common-device: POSTHOG_API_KEY and POSTHOG_HOST must be set in environment variables"
133
- );
134
- }
135
-
136
- initializeAudit(apiKey, host);
137
- auditInitialized = true;
138
- }
139
-
140
- /**
141
- * Returns the PostgreSQL DB URI from environment variables.
142
- * Throws an error if not set.
143
- */
144
- export function getPostgresDbUri(): string {
145
- const fullUri = process.env.ADMIN_DB_URI;
146
- if (!fullUri) {
147
- getConfig().LOGGER.error(
148
- "ADMIN_DB_URI must be set in environment variables or .env file"
149
- );
150
- throw new Error(
151
- "dt-common-device: ADMIN_DB_URI must be set in environment variables or .env file"
152
- );
153
- }
154
- return fullUri;
155
- }
156
-
157
- export function getMongoUri(): string {
158
- const fullUri = process.env.MONGODB_URI;
159
- if (!fullUri) {
160
- getConfig().LOGGER.error(
161
- "MONGODB_URI must be set in environment variables or .env file"
162
- );
163
- throw new Error(
164
- "dt-common-device: MONGODB_URI must be set in environment variables or .env file"
165
- );
166
- }
167
- return fullUri;
168
- }
169
-
170
- /**
171
- * Returns the Redis DB Host and port from environment variables.
172
- * Throws an error if not set.
173
- */
174
- export function getRedisDbHostAndPort(): { host: string; port: number } {
175
- const host = process.env.REDIS_HOST;
176
- const port = process.env.REDIS_PORT;
177
- if (!host || !port) {
178
- getConfig().LOGGER.error(
179
- "REDIS_HOST and REDIS_PORT must be set in environment variables"
180
- );
181
- throw new Error(
182
- "dt-common-device: REDIS_HOST and REDIS_PORT must be set in environment variables"
183
- );
184
- }
185
- return { host, port: Number(port) };
186
- }
187
-
188
- /**
189
- * Graceful shutdown function
190
- */
191
- export async function shutdown(): Promise<void> {
192
- if (eventSubscription) {
193
- try {
194
- await eventSubscription.unsubscribe();
195
- getConfig().LOGGER.info("Event subscription stopped successfully");
196
- } catch (error) {
197
- getConfig().LOGGER.error("Failed to stop event subscription", { error });
198
- }
199
- }
200
-
201
- getConfig().LOGGER.info("dt-common-device: Shutdown completed");
202
- }
@@ -1,21 +0,0 @@
1
- import { IInternalEvent } from "../events/interfaces/IInternalEvent";
2
-
3
- export interface ILogger {
4
- info(message: string, ...args: any[]): void;
5
- warn(message: string, ...args: any[]): void;
6
- error(message: string, ...args: any[]): void;
7
- }
8
-
9
- type AllowedSource = "ACCESS_SERVICE" | "ADMIN_SERVICE" | "ENERGY_SERVICE";
10
-
11
- export type IConfig = {
12
- SOURCE: AllowedSource;
13
- SQS_QUEUE_URL: string;
14
- DEVICE_SERVICE?: string;
15
- ADMIN_SERVICE?: string;
16
- ACCESS_SERVICE?: string;
17
- ENERGY_SERVICE?: string;
18
- INTERNAL_EVENT_HANDLER: IInternalEvent;
19
- LOGGER: ILogger;
20
- [key: string]: any;
21
- };
@@ -1,52 +0,0 @@
1
- import { getPostgresClient } from "../db";
2
- import { IConnection } from "./IConnection";
3
- import { Service } from "typedi";
4
-
5
- @Service()
6
- export class ConnectionRepository {
7
- private readonly pool;
8
- constructor() {
9
- this.pool = getPostgresClient();
10
- }
11
-
12
- async createConnection(data: Partial<IConnection>): Promise<IConnection> {
13
- const result = await this.pool.query(
14
- 'INSERT INTO dt_connections ("connectionName", "connectionRefId", "propertyId", "connectionProvider", "accessToken", "refreshToken", "clientId", "clientSecret", "isActive", "metaData") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *',
15
- [
16
- data.connectionName,
17
- data.connectionRefId,
18
- data.propertyId,
19
- data.connectionProvider,
20
- data.accessToken,
21
- data.refreshToken,
22
- data.clientId,
23
- data.clientSecret,
24
- data.isActive,
25
- data.metaData,
26
- ]
27
- );
28
- return result.rows[0];
29
- }
30
-
31
- async getConnectionById(connectionId: string): Promise<IConnection> {
32
- const result = await this.pool.query(
33
- "SELECT * FROM dt_connections WHERE id = $1",
34
- [connectionId]
35
- );
36
- return result.rows[0];
37
- }
38
-
39
- async updateConnection(connectionId: string, data: Partial<IConnection>) {
40
- // Build dynamic SET clause with quoted column names
41
- const setClause = Object.keys(data)
42
- .map((key, index) => `"${key}" = $${index + 2}`)
43
- .join(", ");
44
-
45
- const values = Object.values(data);
46
- const result = await this.pool.query(
47
- `UPDATE dt_connections SET ${setClause}, "updatedAt" = NOW() WHERE id = $1 RETURNING *`,
48
- [connectionId, ...values]
49
- );
50
- return result.rows[0];
51
- }
52
- }
@@ -1,39 +0,0 @@
1
- import { Container } from "typedi";
2
- import { ConnectionRepository } from "./Connection.repository";
3
- import { IConnection } from "./IConnection";
4
-
5
- export class LocalConnectionService {
6
- private readonly connectionRepository: ConnectionRepository;
7
- constructor() {
8
- this.connectionRepository = Container.get(ConnectionRepository);
9
- }
10
-
11
- async createConnection(data: Partial<IConnection>): Promise<IConnection> {
12
- if (
13
- !data.connectionName ||
14
- !data.connectionRefId ||
15
- !data.propertyId ||
16
- !data.connectionProvider
17
- ) {
18
- throw new Error("Missing required fields");
19
- }
20
- return await this.connectionRepository.createConnection(data);
21
- }
22
-
23
- async getConnection(connectionId: string): Promise<IConnection> {
24
- if (!connectionId) {
25
- throw new Error("Connection ID is required");
26
- }
27
- return await this.connectionRepository.getConnectionById(connectionId);
28
- }
29
-
30
- async updateConnection(
31
- connectionId: string,
32
- data: Partial<IConnection>
33
- ): Promise<IConnection> {
34
- if (!connectionId) {
35
- throw new Error("Connection ID is required");
36
- }
37
- return await this.connectionRepository.updateConnection(connectionId, data);
38
- }
39
- }
@@ -1,27 +0,0 @@
1
- export interface IConnection {
2
- id?: string;
3
- createdAt?: Date;
4
- updatedAt?: Date;
5
- isDeleted?: boolean;
6
- connectionName: string;
7
- connectionRefId: string;
8
- propertyId: string;
9
- connectionProvider: ConnectionProvider;
10
- accessToken?: string;
11
- refreshToken?: string;
12
- clientId?: string;
13
- clientSecret: string;
14
- isActive?: boolean;
15
- metaData?: any;
16
- }
17
-
18
- export enum ConnectionProvider {
19
- Smartthings = "Smartthings",
20
- SaltoKS = "SaltoKS",
21
- TTLock = "TTLock",
22
- Tuya = "Tuya",
23
- Schlage = "Schlage",
24
- YaleWifi = "YaleWifi",
25
- Sensibo = "Sensibo",
26
- Devicethread = "Devicethread",
27
- }
@@ -1,3 +0,0 @@
1
- export * from "./IConnection";
2
- export * from "./Connection.service";
3
-
@@ -1,11 +0,0 @@
1
- export const CONNECTION_PROVIDERS = {
2
- DEVICETHREAD: "Devicethread",
3
- SALTOKS: "SaltoKS",
4
- SCHLAGE: "Schlage",
5
- SENSIBO: "Sensibo",
6
- SMARTTHINGS: "Smartthings",
7
- TTLOCK: "TTLock",
8
- TUYA: "Tuya",
9
- VERDANT: "Verdant",
10
- YALEWIFI: "YaleWifi",
11
- } as const;
@@ -1,89 +0,0 @@
1
- export const DT_EVENT_TYPES = {
2
- DEVICE: {
3
- CREATE: {
4
- SUCCESS: "device.create.success",
5
- FAILED: "device.create.failed",
6
- },
7
- UPDATE: {
8
- SUCCESS: "device.update.success",
9
- FAILED: "device.update.failed",
10
- },
11
- DELETE: {
12
- SUCCESS: "device.delete.success",
13
- FAILED: "device.delete.failed",
14
- },
15
- STATE: {
16
- SET: "device.state.set",
17
- UNKNOWN: "device.state.unknown",
18
- UPDATED: "device.state.updated",
19
- CHANGED: "device.state.changed",
20
- },
21
- STATUS: {
22
- SET: "device.status.set",
23
- ONLINE: "device.status.online",
24
- OFFLINE: "device.status.offline",
25
- UNKNOWN: "device.status.unknown",
26
- UPDATED: "device.status.updated",
27
- CHANGED: "device.status.changed",
28
- },
29
- BATTERY: {
30
- SET: "device.battery.set",
31
- UNKNOWN: "device.battery.unknown",
32
- LOW: "device.battery.low",
33
- CRITICAL: "device.battery.critical",
34
- UPDATED: "device.battery.updated",
35
- CHANGED: "device.battery.changed",
36
- },
37
- META_DATA: {
38
- SET: "device.metaData.set",
39
- UPDATED: "device.metaData.updated",
40
- CHANGED: "device.metaData.changed",
41
- },
42
- EVENT: {
43
- RECEIVED: "device.event.received",
44
- REGISTERED: "device.event.registered",
45
- UNREGISTERED: "device.event.unregistered",
46
- PROCESSED: "device.event.processed",
47
- UNPROCESSED: "device.event.unprocessed",
48
- },
49
- WEBHOOK: {
50
- RECEIVED: "device.webhook.received",
51
- REGISTERED: "device.webhook.registered",
52
- UNREGISTERED: "device.webhook.unregistered",
53
- PROCESSED: "device.webhook.processed",
54
- UNPROCESSED: "device.webhook.unprocessed",
55
- },
56
- },
57
- CONNECTION: {
58
- CREATE: {
59
- SUCCESS: "connection.create.success",
60
- FAILED: "connection.create.failed",
61
- },
62
- UPDATE: {
63
- SUCCESS: "connection.update.success",
64
- FAILED: "connection.update.failed",
65
- },
66
- DELETE: {
67
- SUCCESS: "connection.delete.success",
68
- FAILED: "connection.delete.failed",
69
- },
70
- },
71
- PROPERTY: {
72
- CREATE: {
73
- SUCCESS: "property.create.success",
74
- FAILED: "property.create.failed",
75
- },
76
- UPDATE: {
77
- SUCCESS: "property.update.success",
78
- FAILED: "property.update.failed",
79
- },
80
- DELETE: {
81
- SUCCESS: "property.delete.success",
82
- FAILED: "property.delete.failed",
83
- },
84
- PREFERENCES: {
85
- UPDATED: "property.preferences.updated",
86
- CREATED: "property.preferences.created",
87
- },
88
- },
89
- };
@@ -1,17 +0,0 @@
1
- export const SERVICE_NAMES = {
2
- CLOUD: "smart-cloud",
3
- ACCESS: "smart-access",
4
- ENERGY: "smart-energy",
5
- SCHEDULE: "smart-schedule",
6
- DEVICE: "smart-device",
7
- } as const;
8
-
9
-
10
- export enum Source {
11
- USER = "user",
12
- CLOUD_EVENT = "cloud-event",
13
- CLOUD_WEBHOOK = "cloud-webhook",
14
- HEARTBEAT = "heartbeat",
15
- CODE_ACTION = "code-action",
16
- DEVICE_ACTION = "device-action",
17
- }
@@ -1,3 +0,0 @@
1
- export * from "./ConnectionProviders";
2
- export * from "./Event";
3
- export * from "./Service";
package/src/db/db.ts DELETED
@@ -1,24 +0,0 @@
1
- import { Pool } from "pg";
2
- import { getMongoUri, getPostgresDbUri } from "../config/config";
3
- import mongoose from "mongoose";
4
-
5
- export function getPostgresClient() {
6
- const URI = getPostgresDbUri();
7
- let pool: Pool | null = null;
8
- if (!pool) {
9
- pool = new Pool({
10
- connectionString: URI,
11
- });
12
- }
13
- return pool;
14
- }
15
-
16
- export const connectDatabase = async (): Promise<void> => {
17
- try {
18
- const URI = getMongoUri();
19
- await mongoose.connect(URI);
20
- console.log(`Connected to MongoDB at ${URI.split("/").at(-1)}`);
21
- } catch (error: any) {
22
- console.error("Error connecting to MongoDB:", error);
23
- }
24
- };
package/src/db/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./db";
2
- export * from "./redis";
package/src/db/redis.ts DELETED
@@ -1,20 +0,0 @@
1
- import { getRedisDbHostAndPort } from "../config/config";
2
- import Redis from "ioredis";
3
-
4
- let redisClient: Redis | null = null;
5
-
6
- //Singleton pattern to ensure only one Redis client instance is create only once and shared across the application
7
- export function getRedisClient() {
8
- if (!redisClient) {
9
- const { host, port } = getRedisDbHostAndPort();
10
- redisClient = new Redis({
11
- host,
12
- port,
13
- maxRetriesPerRequest: null,
14
- });
15
- redisClient.on("error", (error) => {
16
- console.error("Redis error:", error);
17
- });
18
- }
19
- return redisClient;
20
- }
@@ -1,40 +0,0 @@
1
- import { IDevice } from "../../local/interfaces";
2
- import { ICloudDevice } from "../interfaces/ICloudDevice";
3
- import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
4
- import { IConnection } from "../../../connection";
5
-
6
- export abstract class CloudDevice implements ICloudDevice {
7
- deviceId: string;
8
- localDevice?: IDevice;
9
- connection?: IConnection;
10
- cloudDeviceService: ICloudDeviceService;
11
-
12
- constructor(device: IDevice, cloudDeviceService: ICloudDeviceService) {
13
- this.deviceId = device.deviceId;
14
- this.localDevice = device;
15
- this.cloudDeviceService = cloudDeviceService;
16
- }
17
-
18
- async getDevice(
19
- connectionId: string,
20
- deviceId: string
21
- ): Promise<Record<string, any>> {
22
- throw new Error("Method not implemented in Super Class.");
23
- }
24
-
25
- async getBattery(deviceId: string): Promise<number | string> {
26
- throw new Error("Method not implemented in Super Class.");
27
- }
28
-
29
- async getState(deviceId: string): Promise<string> {
30
- throw new Error("Method not implemented in Super Class.");
31
- }
32
-
33
- async getStatus(connectionId: string, deviceId: string): Promise<string> {
34
- throw new Error("Method not implemented in Super Class.");
35
- }
36
-
37
- async toLocalDevice(): Promise<IDevice> {
38
- return {} as IDevice;
39
- }
40
- }
@@ -1,8 +0,0 @@
1
- import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
2
- import { IConnection } from "../../../connection";
3
-
4
- export class CloudDeviceService implements ICloudDeviceService {
5
- async getConnection(deviceId: string): Promise<IConnection> {
6
- throw new Error("Method not implemented.");
7
- }
8
- }
@@ -1,27 +0,0 @@
1
- import { IDevice } from "../../local/interfaces";
2
- import { LocalDeviceService } from "../../local/services/Device.service";
3
- import { IDeviceFactory } from "../interfaces/IDeviceFactory";
4
-
5
- export class DeviceFactory implements IDeviceFactory {
6
- private readonly localDeviceService: LocalDeviceService;
7
-
8
- constructor() {
9
- this.localDeviceService = new LocalDeviceService();
10
- }
11
-
12
- async getDevice(deviceId: string): Promise<IDevice> {
13
- try {
14
- return await this.localDeviceService.getDevice(deviceId);
15
- } catch (error) {
16
- // Log the error for debugging purposes
17
- console.error(`DeviceFactory: Failed to get device ${deviceId}:`, error);
18
-
19
- // Re-throw the error with additional context
20
- throw new Error(
21
- `DeviceFactory: Unable to retrieve device ${deviceId}. ${
22
- error instanceof Error ? error.message : "Unknown error occurred"
23
- }`
24
- );
25
- }
26
- }
27
- }
@@ -1,3 +0,0 @@
1
- export * from "./CloudDevice";
2
- export * from "./DeviceFactory";
3
- export * from "./CloudDeviceService";
@@ -1,14 +0,0 @@
1
- // CloudDevice interface
2
- import { ICloudDeviceService } from "./ICloudDeviceService";
3
-
4
- export interface ICloudDevice {
5
- deviceId: string;
6
- cloudDeviceService: ICloudDeviceService;
7
- getDevice(
8
- connectionId: string,
9
- deviceId: string
10
- ): Promise<Record<string, any>>;
11
- getBattery(deviceId: string): Promise<number | string>;
12
- getState(deviceId: string): Promise<string>;
13
- getStatus(connectionId: string, deviceId: string): Promise<string>;
14
- }
@@ -1,6 +0,0 @@
1
- // Interface for CloudDeviceService
2
- import { IConnection } from "../../../connection";
3
-
4
- export interface ICloudDeviceService {
5
- getConnection(deviceId: string): Promise<IConnection>;
6
- }
@@ -1,5 +0,0 @@
1
- import { IDevice } from "../../local/interfaces";
2
-
3
- export interface IDeviceFactory {
4
- getDevice(deviceId: string): Promise<IDevice>;
5
- }
@@ -1,5 +0,0 @@
1
- import { IDevice } from "../../local/interfaces";
2
-
3
- export interface IRawDataTransformer {
4
- transform(): Promise<IDevice>;
5
- }
@@ -1,19 +0,0 @@
1
- import { IConnection } from "../../../connection";
2
-
3
- export enum DeviceType {
4
- HUB = "HUB",
5
- LOCK = "LOCK",
6
- ELEVATOR_LOCK = "ELEVATOR LOCK",
7
- THERMOSTAT = "THERMOSTAT",
8
- TV = "TV",
9
- }
10
-
11
- export interface IRawDevice {
12
- deviceId?: string;
13
- deviceType: DeviceType;
14
- name?: string;
15
- connection: IConnection;
16
- propertyId: string;
17
- zoneId: string;
18
- [key: string]: any;
19
- }
@@ -1,5 +0,0 @@
1
- export * from "./ICloudDevice";
2
- export * from "./ICloudDeviceService";
3
- export * from "./IDeviceFactory";
4
- export * from "./IRawDataTransformer";
5
- export * from "./IRawDevice";