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.
Files changed (211) hide show
  1. package/dist/alerts/Alert.service.d.ts +1 -1
  2. package/dist/audit/AuditUtils.d.ts +26 -2
  3. package/dist/audit/AuditUtils.js +255 -32
  4. package/dist/audit/IAuditProperties.d.ts +32 -0
  5. package/dist/audit/IAuditProperties.js +13 -0
  6. package/dist/audit/PushAudit.d.ts +5 -0
  7. package/dist/audit/PushAudit.js +16 -0
  8. package/dist/audit/index.d.ts +2 -0
  9. package/dist/audit/index.js +18 -0
  10. package/dist/config/config.d.ts +10 -3
  11. package/dist/config/config.js +120 -47
  12. package/dist/config/config.types.d.ts +1 -8
  13. package/dist/config/constants.d.ts +49 -0
  14. package/dist/config/constants.js +64 -0
  15. package/dist/db/db.d.ts +2 -0
  16. package/dist/db/db.js +23 -1
  17. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +5 -0
  18. package/dist/entities/accessGroup/AccessGroup.repository.js +72 -0
  19. package/dist/entities/accessGroup/AccessGroup.service.d.ts +5 -0
  20. package/dist/{device/local/repository/Connection.repository.js → entities/accessGroup/AccessGroup.service.js} +50 -37
  21. package/dist/entities/accessGroup/IAccessGroup.d.ts +14 -0
  22. package/dist/entities/accessGroup/index.d.ts +2 -0
  23. package/dist/entities/accessGroup/index.js +18 -0
  24. package/dist/{admin → entities/admin}/Admin.repository.js +4 -4
  25. package/dist/{connection → entities/connection}/Connection.repository.js +1 -1
  26. package/dist/{device → entities/device}/local/repository/Device.repository.d.ts +1 -0
  27. package/dist/{device → entities/device}/local/repository/Device.repository.js +20 -3
  28. package/dist/{device → entities/device}/local/repository/Hub.repository.js +3 -3
  29. package/dist/{device → entities/device}/local/repository/Schedule.repository.js +2 -2
  30. package/dist/{device → entities/device}/local/services/Device.service.d.ts +10 -9
  31. package/dist/{device → entities/device}/local/services/Device.service.js +10 -4
  32. package/dist/entities/guest/Guest.repository.d.ts +6 -0
  33. package/dist/entities/guest/Guest.repository.js +74 -0
  34. package/dist/entities/guest/Guest.service.d.ts +6 -0
  35. package/dist/entities/guest/Guest.service.js +104 -0
  36. package/dist/entities/guest/IGuest.d.ts +12 -0
  37. package/dist/entities/guest/index.d.ts +2 -0
  38. package/dist/entities/guest/index.js +18 -0
  39. package/dist/{property → entities/property}/Property.repository.js +1 -1
  40. package/dist/entities/schedules/ISchedule.d.ts +14 -0
  41. package/dist/entities/schedules/Schedule.repository.d.ts +6 -0
  42. package/dist/entities/schedules/Schedule.repository.js +74 -0
  43. package/dist/entities/schedules/Schedule.service.d.ts +6 -0
  44. package/dist/entities/schedules/Schedule.service.js +104 -0
  45. package/dist/entities/schedules/index.d.ts +2 -0
  46. package/dist/entities/schedules/index.js +18 -0
  47. package/dist/{user → entities/user}/User.repository.js +2 -2
  48. package/dist/{user → entities/user}/User.service.js +3 -0
  49. package/dist/entities/zone/IZone.d.ts +10 -0
  50. package/dist/entities/zone/Zone.repository.d.ts +6 -0
  51. package/dist/{device/local/repository/Property.repository.js → entities/zone/Zone.repository.js} +14 -32
  52. package/dist/entities/zone/Zone.service.d.ts +6 -0
  53. package/dist/entities/zone/Zone.service.js +104 -0
  54. package/dist/entities/zone/index.d.ts +2 -0
  55. package/dist/entities/zone/index.js +18 -0
  56. package/dist/events/BaseEventHandler.d.ts +3 -3
  57. package/dist/events/BaseEventHandler.js +1 -1
  58. package/dist/events/DeviceEventHandler.d.ts +1 -1
  59. package/dist/events/DeviceEventHandler.js +4 -3
  60. package/dist/events/EventHandler.d.ts +10 -9
  61. package/dist/events/EventHandler.js +50 -9
  62. package/dist/events/InternalEventSubscription.js +1 -1
  63. package/dist/index.d.ts +9 -8
  64. package/dist/index.js +10 -8
  65. package/dist/issues/Issue.service.d.ts +1 -1
  66. package/dist/microservice/MicroServiceFactory.d.ts +1 -1
  67. package/dist/microservice/MicroServiceFactory.js +1 -1
  68. package/dist/utils/http.utils.d.ts +1 -2
  69. package/dist/utils/http.utils.js +5 -27
  70. package/package.json +1 -1
  71. package/dist/audit/AuditProperties.d.ts +0 -16
  72. package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
  73. package/dist/device/cloud/entities/CloudConnection.js +0 -6
  74. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
  75. package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
  76. package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
  77. package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
  78. package/dist/device/cloud/interfaces/IHubService.js +0 -2
  79. package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
  80. package/dist/device/cloud/services/CloudDevice.service.js +0 -9
  81. package/dist/device/cloud/services/Connection.service.d.ts +0 -8
  82. package/dist/device/cloud/services/Connection.service.js +0 -6
  83. package/dist/device/cloud/services/index.d.ts +0 -2
  84. package/dist/device/cloud/services/index.js +0 -18
  85. package/dist/device/cloud/types.d.ts +0 -52
  86. package/dist/device/cloud/types.js +0 -15
  87. package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
  88. package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
  89. package/dist/device/local/entities/AlertBuilder.example.js +0 -117
  90. package/dist/device/local/entities/AlertBuilder.js +0 -179
  91. package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
  92. package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
  93. package/dist/device/local/entities/IssueBuilder.example.js +0 -196
  94. package/dist/device/local/entities/IssueBuilder.js +0 -237
  95. package/dist/device/local/entities/index.d.ts +0 -2
  96. package/dist/device/local/entities/index.js +0 -7
  97. package/dist/device/local/events/EventHandler.d.ts +0 -11
  98. package/dist/device/local/events/EventHandler.js +0 -86
  99. package/dist/device/local/events/Events.d.ts +0 -75
  100. package/dist/device/local/events/Events.js +0 -78
  101. package/dist/device/local/events/index.d.ts +0 -2
  102. package/dist/device/local/events/index.js +0 -7
  103. package/dist/device/local/handler/EventHandler.d.ts +0 -7
  104. package/dist/device/local/handler/EventHandler.js +0 -44
  105. package/dist/device/local/interfaces/IConnection.d.ts +0 -26
  106. package/dist/device/local/interfaces/IConnection.js +0 -14
  107. package/dist/device/local/interfaces/IHub.d.ts +0 -46
  108. package/dist/device/local/interfaces/IHub.js +0 -2
  109. package/dist/device/local/models/Alert.model.d.ts +0 -28
  110. package/dist/device/local/models/Alert.model.js +0 -222
  111. package/dist/device/local/models/Issue.model.d.ts +0 -28
  112. package/dist/device/local/models/Issue.model.js +0 -260
  113. package/dist/device/local/repository/Alert.repository.d.ts +0 -106
  114. package/dist/device/local/repository/Alert.repository.js +0 -374
  115. package/dist/device/local/repository/Connection.repository.d.ts +0 -8
  116. package/dist/device/local/repository/Issue.repository.d.ts +0 -113
  117. package/dist/device/local/repository/Issue.repository.js +0 -401
  118. package/dist/device/local/repository/Property.repository.d.ts +0 -8
  119. package/dist/device/local/services/Alert.service.d.ts +0 -137
  120. package/dist/device/local/services/Alert.service.js +0 -475
  121. package/dist/device/local/services/AlertService.example.d.ts +0 -55
  122. package/dist/device/local/services/AlertService.example.js +0 -148
  123. package/dist/device/local/services/Connection.service.d.ts +0 -8
  124. package/dist/device/local/services/Connection.service.js +0 -32
  125. package/dist/device/local/services/Issue.service.d.ts +0 -168
  126. package/dist/device/local/services/Issue.service.js +0 -642
  127. package/dist/device/local/services/IssueService.example.d.ts +0 -68
  128. package/dist/device/local/services/IssueService.example.js +0 -177
  129. package/dist/device/local/services/Property.service.d.ts +0 -8
  130. package/dist/device/local/services/Property.service.js +0 -36
  131. package/dist/property/IProperty.d.ts +0 -29
  132. package/dist/property/IProperty.js +0 -2
  133. package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
  134. package/dist/queue/interfaces/IHttpRequestJob.js +0 -2
  135. package/dist/types/alert.types.d.ts +0 -57
  136. package/dist/types/alert.types.js +0 -22
  137. package/dist/types/config.types.d.ts +0 -19
  138. package/dist/types/config.types.js +0 -2
  139. package/dist/types/index.d.ts +0 -3
  140. package/dist/types/index.js +0 -19
  141. package/dist/types/issue.types.d.ts +0 -90
  142. package/dist/types/issue.types.js +0 -40
  143. package/dist/utils/http-utils.d.ts +0 -13
  144. package/dist/utils/http-utils.js +0 -117
  145. /package/dist/{audit/AuditProperties.js → entities/accessGroup/IAccessGroup.js} +0 -0
  146. /package/dist/{admin → entities/admin}/Admin.repository.d.ts +0 -0
  147. /package/dist/{admin → entities/admin}/Admin.service.d.ts +0 -0
  148. /package/dist/{admin → entities/admin}/Admin.service.js +0 -0
  149. /package/dist/{admin → entities/admin}/index.d.ts +0 -0
  150. /package/dist/{admin → entities/admin}/index.js +0 -0
  151. /package/dist/{connection → entities/connection}/Connection.repository.d.ts +0 -0
  152. /package/dist/{connection → entities/connection}/Connection.service.d.ts +0 -0
  153. /package/dist/{connection → entities/connection}/Connection.service.js +0 -0
  154. /package/dist/{connection → entities/connection}/IConnection.d.ts +0 -0
  155. /package/dist/{connection → entities/connection}/IConnection.js +0 -0
  156. /package/dist/{connection → entities/connection}/index.d.ts +0 -0
  157. /package/dist/{connection → entities/connection}/index.js +0 -0
  158. /package/dist/{device → entities/device}/cloud/entities/CloudDevice.d.ts +0 -0
  159. /package/dist/{device → entities/device}/cloud/entities/CloudDevice.js +0 -0
  160. /package/dist/{device → entities/device}/cloud/entities/CloudDeviceService.d.ts +0 -0
  161. /package/dist/{device → entities/device}/cloud/entities/CloudDeviceService.js +0 -0
  162. /package/dist/{device → entities/device}/cloud/entities/DeviceFactory.d.ts +0 -0
  163. /package/dist/{device → entities/device}/cloud/entities/DeviceFactory.js +0 -0
  164. /package/dist/{device → entities/device}/cloud/entities/index.d.ts +0 -0
  165. /package/dist/{device → entities/device}/cloud/entities/index.js +0 -0
  166. /package/dist/{device → entities/device}/cloud/interfaces/ICloudDevice.d.ts +0 -0
  167. /package/dist/{device → entities/device}/cloud/interfaces/ICloudDevice.js +0 -0
  168. /package/dist/{device → entities/device}/cloud/interfaces/ICloudDeviceService.d.ts +0 -0
  169. /package/dist/{device → entities/device}/cloud/interfaces/ICloudDeviceService.js +0 -0
  170. /package/dist/{device → entities/device}/cloud/interfaces/IDeviceFactory.d.ts +0 -0
  171. /package/dist/{device → entities/device}/cloud/interfaces/IDeviceFactory.js +0 -0
  172. /package/dist/{device → entities/device}/cloud/interfaces/IRawDataTransformer.d.ts +0 -0
  173. /package/dist/{device → entities/device}/cloud/interfaces/IRawDataTransformer.js +0 -0
  174. /package/dist/{device → entities/device}/cloud/interfaces/IRawDevice.d.ts +0 -0
  175. /package/dist/{device → entities/device}/cloud/interfaces/IRawDevice.js +0 -0
  176. /package/dist/{device → entities/device}/cloud/interfaces/index.d.ts +0 -0
  177. /package/dist/{device → entities/device}/cloud/interfaces/index.js +0 -0
  178. /package/dist/{device → entities/device}/local/interfaces/IDevice.d.ts +0 -0
  179. /package/dist/{device → entities/device}/local/interfaces/IDevice.js +0 -0
  180. /package/dist/{device → entities/device}/local/interfaces/IDtDevice.d.ts +0 -0
  181. /package/dist/{device → entities/device}/local/interfaces/IDtDevice.js +0 -0
  182. /package/dist/{device → entities/device}/local/interfaces/ISchedule.d.ts +0 -0
  183. /package/dist/{device → entities/device}/local/interfaces/ISchedule.js +0 -0
  184. /package/dist/{device → entities/device}/local/interfaces/index.d.ts +0 -0
  185. /package/dist/{device → entities/device}/local/interfaces/index.js +0 -0
  186. /package/dist/{device → entities/device}/local/repository/Hub.repository.d.ts +0 -0
  187. /package/dist/{device → entities/device}/local/repository/Schedule.repository.d.ts +0 -0
  188. /package/dist/{device → entities/device}/local/services/Hub.service.d.ts +0 -0
  189. /package/dist/{device → entities/device}/local/services/Hub.service.js +0 -0
  190. /package/dist/{device → entities/device}/local/services/Schedule.service.d.ts +0 -0
  191. /package/dist/{device → entities/device}/local/services/Schedule.service.js +0 -0
  192. /package/dist/{device → entities/device}/local/services/index.d.ts +0 -0
  193. /package/dist/{device → entities/device}/local/services/index.js +0 -0
  194. /package/dist/{device/cloud/interfaces/ICloudConnection.js → entities/guest/IGuest.js} +0 -0
  195. /package/dist/{pms → entities/pms}/IPms.d.ts +0 -0
  196. /package/dist/{pms → entities/pms}/IPms.js +0 -0
  197. /package/dist/{pms → entities/pms}/index.d.ts +0 -0
  198. /package/dist/{pms → entities/pms}/index.js +0 -0
  199. /package/dist/{device/local/interfaces → entities/property}/IProperty.d.ts +0 -0
  200. /package/dist/{device/local/interfaces → entities/property}/IProperty.js +0 -0
  201. /package/dist/{property → entities/property}/Property.repository.d.ts +0 -0
  202. /package/dist/{property → entities/property}/Property.service.d.ts +0 -0
  203. /package/dist/{property → entities/property}/Property.service.js +0 -0
  204. /package/dist/{property → entities/property}/index.d.ts +0 -0
  205. /package/dist/{property → entities/property}/index.js +0 -0
  206. /package/dist/{device/cloud/interfaces/IConnectionService.js → entities/schedules/ISchedule.js} +0 -0
  207. /package/dist/{user → entities/user}/IUser.d.ts +0 -0
  208. /package/dist/{user → entities/user}/IUser.js +0 -0
  209. /package/dist/{user → entities/user}/User.repository.d.ts +0 -0
  210. /package/dist/{user → entities/user}/User.service.d.ts +0 -0
  211. /package/dist/{device/cloud/interfaces/IDeviceService.js → entities/zone/IZone.js} +0 -0
@@ -5,50 +5,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.initialize = initialize;
7
7
  exports.getConfig = getConfig;
8
+ exports.getDeviceServiceUrl = getDeviceServiceUrl;
9
+ exports.getAdminServiceUrl = getAdminServiceUrl;
10
+ exports.getSqsQueueUrl = getSqsQueueUrl;
8
11
  exports.getEventSubscription = getEventSubscription;
9
12
  exports.checkRequiredEnv = checkRequiredEnv;
10
13
  exports.ensureAuditInitialized = ensureAuditInitialized;
11
- exports.getPostgresDbUri = getPostgresDbUri;
14
+ exports.getLogger = getLogger;
15
+ exports.getAdminPostgresDbUri = getAdminPostgresDbUri;
16
+ exports.getAccessPostgresDbUri = getAccessPostgresDbUri;
17
+ exports.getPmsPostgresDbUri = getPmsPostgresDbUri;
12
18
  exports.getMongoUri = getMongoUri;
19
+ exports.getDTApiKey = getDTApiKey;
13
20
  exports.getRedisDbHostAndPort = getRedisDbHostAndPort;
14
21
  exports.shutdown = shutdown;
15
22
  const dt_audit_library_1 = require("dt-audit-library");
16
23
  const db_1 = require("../db/db");
17
24
  const dotenv_1 = __importDefault(require("dotenv"));
18
25
  const events_1 = require("../events");
19
- const http_utils_1 = require("../utils/http.utils");
26
+ const constants_1 = require("./constants");
20
27
  dotenv_1.default.config();
21
28
  let config = null;
22
29
  let auditInitialized = false;
23
30
  let eventSubscription = null;
31
+ let db_keys = null;
24
32
  async function initialize(cfg) {
33
+ // Check if required env variables are set
34
+ checkRequiredEnv(constants_1.CONFIG_KEYS.REQUIRED.envs);
25
35
  // Initialize config
26
36
  config = { ...cfg };
27
- // Validate service URLs if provided
28
- if (cfg.DEVICE_SERVICE && !(0, http_utils_1.validateServiceUrl)(cfg.DEVICE_SERVICE)) {
29
- throw new Error(`Invalid DEVICE_SERVICE URL: ${cfg.DEVICE_SERVICE}`);
30
- }
31
- if (cfg.ADMIN_SERVICE && !(0, http_utils_1.validateServiceUrl)(cfg.ADMIN_SERVICE)) {
32
- throw new Error(`Invalid ADMIN_SERVICE URL: ${cfg.ADMIN_SERVICE}`);
37
+ if (cfg.SOURCE === "ACCESS_SERVICE") {
38
+ db_keys = constants_1.CONFIG_KEYS.ACCESS.db_keys;
39
+ await validateAccessConfig(cfg);
33
40
  }
34
- if (cfg.ACCESS_SERVICE && !(0, http_utils_1.validateServiceUrl)(cfg.ACCESS_SERVICE)) {
35
- throw new Error(`Invalid ACCESS_SERVICE URL: ${cfg.ACCESS_SERVICE}`);
41
+ if (cfg.SOURCE === "SCHEDULE_SERVICE") {
42
+ db_keys = constants_1.CONFIG_KEYS.SCHEDULE.db_keys;
43
+ await validateScheduleConfig(cfg);
36
44
  }
37
- if (cfg.ENERGY_SERVICE && !(0, http_utils_1.validateServiceUrl)(cfg.ENERGY_SERVICE)) {
38
- throw new Error(`Invalid ENERGY_SERVICE URL: ${cfg.ENERGY_SERVICE}`);
45
+ if (cfg.SOURCE === "ENERGY_SERVICE") {
46
+ db_keys = constants_1.CONFIG_KEYS.ENERGY.db_keys;
47
+ await validateEnergyConfig(cfg);
39
48
  }
40
- // Initialize internal event subscription if handler is provided
41
- if (cfg.INTERNAL_EVENT_HANDLER) {
42
- try {
43
- eventSubscription = new events_1.InternalEventSubscription(cfg.INTERNAL_EVENT_HANDLER);
44
- cfg.LOGGER.info("InternalEventSubscription initialized successfully");
45
- }
46
- catch (error) {
47
- cfg.LOGGER.error("Failed to initialize InternalEventSubscription", {
48
- error,
49
- });
50
- throw error;
51
- }
49
+ if (cfg.SOURCE === "REMOTE_SERVICE") {
50
+ db_keys = constants_1.CONFIG_KEYS.REMOTE.db_keys;
51
+ await validateRemoteConfig(cfg);
52
52
  }
53
53
  // Connect to databases
54
54
  try {
@@ -70,37 +70,86 @@ async function initialize(cfg) {
70
70
  // Don't throw here as the main setup should continue
71
71
  }
72
72
  }
73
- // Check if required env variables are set
74
- checkRequiredEnv();
75
73
  // Initialize audit
76
74
  ensureAuditInitialized();
77
75
  console.log("dt-common-device: Initialization completed successfully");
78
76
  }
77
+ async function validateInternalEventHandler(cfg) {
78
+ // Initialize internal event subscription if handler is provided
79
+ if (cfg.INTERNAL_EVENT_HANDLER) {
80
+ try {
81
+ eventSubscription = new events_1.InternalEventSubscription(cfg.INTERNAL_EVENT_HANDLER);
82
+ cfg.LOGGER.info("InternalEventSubscription initialized successfully");
83
+ }
84
+ catch (error) {
85
+ cfg.LOGGER.error("Failed to initialize InternalEventSubscription", {
86
+ error,
87
+ });
88
+ throw error;
89
+ }
90
+ }
91
+ }
92
+ async function validateAccessConfig(cfg) {
93
+ checkRequiredEnv(constants_1.CONFIG_KEYS.ACCESS.env);
94
+ if (constants_1.CONFIG_KEYS.ACCESS.INTERNAL_EVENT_HANDLER) {
95
+ await validateInternalEventHandler(cfg);
96
+ }
97
+ }
98
+ async function validateEnergyConfig(cfg) {
99
+ checkRequiredEnv(constants_1.CONFIG_KEYS.ENERGY.env);
100
+ if (constants_1.CONFIG_KEYS.ENERGY.INTERNAL_EVENT_HANDLER) {
101
+ await validateInternalEventHandler(cfg);
102
+ }
103
+ }
104
+ async function validateRemoteConfig(cfg) {
105
+ checkRequiredEnv(constants_1.CONFIG_KEYS.REMOTE.env);
106
+ if (constants_1.CONFIG_KEYS.REMOTE.INTERNAL_EVENT_HANDLER) {
107
+ await validateInternalEventHandler(cfg);
108
+ }
109
+ }
110
+ async function validateScheduleConfig(cfg) {
111
+ checkRequiredEnv(constants_1.CONFIG_KEYS.SCHEDULE.env);
112
+ if (constants_1.CONFIG_KEYS.SCHEDULE.INTERNAL_EVENT_HANDLER) {
113
+ await validateInternalEventHandler(cfg);
114
+ }
115
+ }
79
116
  function getConfig() {
80
117
  if (!config) {
81
118
  throw new Error("dt-common-device: Library not initialized. Call initialize() first.");
82
119
  }
83
120
  return config;
84
121
  }
122
+ function getDeviceServiceUrl() {
123
+ const deviceServiceUrl = process.env.DEVICE_SERVICE;
124
+ if (!deviceServiceUrl) {
125
+ getConfig().LOGGER.error("DEVICE_SERVICE must be set in environment variables");
126
+ throw new Error("dt-common-device: DEVICE_SERVICE must be set in environment variables");
127
+ }
128
+ return deviceServiceUrl;
129
+ }
130
+ function getAdminServiceUrl() {
131
+ const adminServiceUrl = process.env.ADMIN_SERVICE;
132
+ if (!adminServiceUrl) {
133
+ getConfig().LOGGER.error("ADMIN_SERVICE must be set in environment variables");
134
+ throw new Error("dt-common-device: ADMIN_SERVICE must be set in environment variables");
135
+ }
136
+ return adminServiceUrl;
137
+ }
138
+ function getSqsQueueUrl() {
139
+ const sqsQueueUrl = process.env.AWS_SQS_URL;
140
+ if (!sqsQueueUrl) {
141
+ getConfig().LOGGER.error("AWS_SQS_URL must be set in environment variables");
142
+ throw new Error("dt-common-device: AWS_SQS_URL must be set in environment variables");
143
+ }
144
+ return sqsQueueUrl;
145
+ }
85
146
  function getEventSubscription() {
86
147
  return eventSubscription;
87
148
  }
88
- function checkRequiredEnv() {
89
- const requiredEnv = [
90
- "AWS_SECRET_ACCESS_KEY",
91
- "AWS_REGION",
92
- "AWS_ACCESS_KEY_ID",
93
- "EVENT_BUS_NAME",
94
- "ADMIN_DB_URI",
95
- "MONGODB_URI",
96
- "REDIS_HOST",
97
- "REDIS_PORT",
98
- "POSTHOG_API_KEY",
99
- "POSTHOG_HOST",
100
- ];
101
- const missing = requiredEnv.filter((key) => !process.env[key]);
149
+ function checkRequiredEnv(requiredEnvs) {
150
+ const missing = requiredEnvs.filter((key) => !process.env[key]);
102
151
  if (missing.length > 0) {
103
- throw new Error(`Missing required AWS environment variables for dt-pub-sub: ${missing.join(", ")}`);
152
+ throw new Error(`Missing required environment variables: ${missing.join(", ")}`);
104
153
  }
105
154
  }
106
155
  function ensureAuditInitialized() {
@@ -115,22 +164,38 @@ function ensureAuditInitialized() {
115
164
  (0, dt_audit_library_1.initializeAudit)(apiKey, host);
116
165
  auditInitialized = true;
117
166
  }
118
- // // Direct logger export for easier usage
119
- // export function getLogger(): ILogger {
120
- // return getConfig().LOGGER;
121
- // }
167
+ // Direct logger export for easier usage
168
+ function getLogger() {
169
+ return getConfig().LOGGER;
170
+ }
122
171
  /**
123
172
  * Returns the PostgreSQL DB URI from environment variables.
124
173
  * Throws an error if not set.
125
174
  */
126
- function getPostgresDbUri() {
127
- const fullUri = process.env.ADMIN_DB_URI;
175
+ function getAdminPostgresDbUri() {
176
+ const fullUri = process.env[db_keys.admin];
128
177
  if (!fullUri) {
129
178
  getConfig().LOGGER.error("ADMIN_DB_URI must be set in environment variables or .env file");
130
179
  throw new Error("dt-common-device: ADMIN_DB_URI must be set in environment variables or .env file");
131
180
  }
132
181
  return fullUri;
133
182
  }
183
+ function getAccessPostgresDbUri() {
184
+ const fullUri = process.env[db_keys.access];
185
+ if (!fullUri) {
186
+ getConfig().LOGGER.error("ACCESS_DB_URI must be set in environment variables or .env file");
187
+ throw new Error("dt-common-device: ACCESS_DB_URI must be set in environment variables or .env file");
188
+ }
189
+ return fullUri;
190
+ }
191
+ function getPmsPostgresDbUri() {
192
+ const fullUri = process.env[db_keys.pms];
193
+ if (!fullUri) {
194
+ getConfig().LOGGER.error("PMS_DB_URI must be set in environment variables or .env file");
195
+ throw new Error("dt-common-device: PMS_DB_URI must be set in environment variables or .env file");
196
+ }
197
+ return fullUri;
198
+ }
134
199
  function getMongoUri() {
135
200
  const fullUri = process.env.MONGODB_URI;
136
201
  if (!fullUri) {
@@ -139,6 +204,14 @@ function getMongoUri() {
139
204
  }
140
205
  return fullUri;
141
206
  }
207
+ function getDTApiKey() {
208
+ const apiKey = process.env.DT_API_KEY;
209
+ if (!apiKey) {
210
+ getConfig().LOGGER.error("DT_API_KEY must be set in environment variables");
211
+ throw new Error("dt-common-device: DT_API_KEY must be set in environment variables");
212
+ }
213
+ return apiKey;
214
+ }
142
215
  /**
143
216
  * Returns the Redis DB Host and port from environment variables.
144
217
  * Throws an error if not set.
@@ -7,15 +7,8 @@ export interface ILogger {
7
7
  type AllowedSource = "ACCESS_SERVICE" | "ADMIN_SERVICE" | "ENERGY_SERVICE" | "REMOTE_SERVICE" | "SCHEDULE_SERVICE";
8
8
  export type IConfig = {
9
9
  SOURCE: AllowedSource;
10
- SQS_QUEUE_URL: string;
11
- DEVICE_SERVICE?: string;
12
- ADMIN_SERVICE?: string;
13
- ACCESS_SERVICE?: string;
14
- ENERGY_SERVICE?: string;
15
- REMOTE_SERVICE?: string;
16
- INTERNAL_EVENT_HANDLER: IInternalEvent;
10
+ INTERNAL_EVENT_HANDLER?: IInternalEvent;
17
11
  LOGGER: ILogger;
18
- CLOUD_SERVICE_API_KEY?: string;
19
12
  [key: string]: any;
20
13
  };
21
14
  export {};
@@ -0,0 +1,49 @@
1
+ export declare const CONFIG_KEYS: {
2
+ REQUIRED: {
3
+ envs: string[];
4
+ };
5
+ ACCESS: {
6
+ env: string[];
7
+ INTERNAL_EVENT_HANDLER: boolean;
8
+ db_keys: {
9
+ base: string;
10
+ admin: string;
11
+ pms: string;
12
+ };
13
+ };
14
+ ADMIN: {
15
+ env: string[];
16
+ INTERNAL_EVENT_HANDLER: boolean;
17
+ db_keys: {
18
+ base: string;
19
+ access: string;
20
+ pms: string;
21
+ };
22
+ };
23
+ ENERGY: {
24
+ env: string[];
25
+ INTERNAL_EVENT_HANDLER: boolean;
26
+ db_keys: {
27
+ base: string;
28
+ admin: string;
29
+ pms: string;
30
+ };
31
+ };
32
+ REMOTE: {
33
+ env: string[];
34
+ INTERNAL_EVENT_HANDLER: boolean;
35
+ db_keys: {
36
+ admin: string;
37
+ pms: string;
38
+ access: string;
39
+ };
40
+ };
41
+ SCHEDULE: {
42
+ env: string[];
43
+ INTERNAL_EVENT_HANDLER: boolean;
44
+ db_keys: {
45
+ admin: string;
46
+ access: string;
47
+ };
48
+ };
49
+ };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_KEYS = void 0;
4
+ exports.CONFIG_KEYS = {
5
+ REQUIRED: {
6
+ envs: [
7
+ "AWS_SECRET_ACCESS_KEY",
8
+ "AWS_REGION",
9
+ "AWS_ACCESS_KEY_ID",
10
+ "EVENT_BUS_NAME",
11
+ "MONGODB_URI",
12
+ "REDIS_HOST",
13
+ "REDIS_PORT",
14
+ "POSTHOG_API_KEY",
15
+ "POSTHOG_HOST",
16
+ "DEVICE_SERVICE",
17
+ "DT_API_KEY"
18
+ ],
19
+ },
20
+ ACCESS: {
21
+ env: ["ADMIN_DB_URI", "PMS_DB_URI"],
22
+ INTERNAL_EVENT_HANDLER: true,
23
+ db_keys: {
24
+ base: "DATABASE_URL",
25
+ admin: "ADMIN_DB_URI",
26
+ pms: "PMS_DB_URI",
27
+ },
28
+ },
29
+ ADMIN: {
30
+ env: ["ACCESS_DB_URI", "PMS_DB_URI"],
31
+ INTERNAL_EVENT_HANDLER: false,
32
+ db_keys: {
33
+ base: "DATABASE_URL",
34
+ access: "ACCESS_DB_URI",
35
+ pms: "PMS_DB_URI",
36
+ },
37
+ },
38
+ ENERGY: {
39
+ env: ["ADMIN_DB_URI", "PMS_DB_URI"],
40
+ INTERNAL_EVENT_HANDLER: true,
41
+ db_keys: {
42
+ base: "DATABASE_URL",
43
+ admin: "ADMIN_DB_URI",
44
+ pms: "PMS_DB_URI",
45
+ },
46
+ },
47
+ REMOTE: {
48
+ env: ["ADMIN_DB_URI", "PMS_DB_URI", "ACCESS_DB_URI"],
49
+ INTERNAL_EVENT_HANDLER: false,
50
+ db_keys: {
51
+ admin: "ADMIN_DB_URI",
52
+ pms: "PMS_DB_URI",
53
+ access: "ACCESS_DB_URI",
54
+ },
55
+ },
56
+ SCHEDULE: {
57
+ env: ["ADMIN_DB_URI", "ACCESS_DB_URI"],
58
+ INTERNAL_EVENT_HANDLER: true,
59
+ db_keys: {
60
+ admin: "ADMIN_DB_URI",
61
+ access: "ACCESS_DB_URI",
62
+ },
63
+ },
64
+ };
package/dist/db/db.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { Pool } from "pg";
2
2
  export declare function getPostgresClient(): Pool;
3
+ export declare function getAccessPostgresClient(): Pool;
4
+ export declare function getPmsPostgresClient(): Pool;
3
5
  export declare const connectDatabase: () => Promise<void>;
package/dist/db/db.js CHANGED
@@ -5,11 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.connectDatabase = void 0;
7
7
  exports.getPostgresClient = getPostgresClient;
8
+ exports.getAccessPostgresClient = getAccessPostgresClient;
9
+ exports.getPmsPostgresClient = getPmsPostgresClient;
8
10
  const pg_1 = require("pg");
9
11
  const config_1 = require("../config/config");
10
12
  const mongoose_1 = __importDefault(require("mongoose"));
11
13
  function getPostgresClient() {
12
- const URI = (0, config_1.getPostgresDbUri)();
14
+ const URI = (0, config_1.getAdminPostgresDbUri)();
15
+ let pool = null;
16
+ if (!pool) {
17
+ pool = new pg_1.Pool({
18
+ connectionString: URI,
19
+ });
20
+ }
21
+ return pool;
22
+ }
23
+ function getAccessPostgresClient() {
24
+ const URI = (0, config_1.getAccessPostgresDbUri)();
25
+ let pool = null;
26
+ if (!pool) {
27
+ pool = new pg_1.Pool({
28
+ connectionString: URI,
29
+ });
30
+ }
31
+ return pool;
32
+ }
33
+ function getPmsPostgresClient() {
34
+ const URI = (0, config_1.getPmsPostgresDbUri)();
13
35
  let pool = null;
14
36
  if (!pool) {
15
37
  pool = new pg_1.Pool({
@@ -0,0 +1,5 @@
1
+ export declare class AccessGroupRepository {
2
+ private readonly postgres;
3
+ constructor();
4
+ getAccessGroup(accessGroupId: string): Promise<any>;
5
+ }
@@ -0,0 +1,72 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.AccessGroupRepository = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const db_1 = require("../../db");
44
+ let AccessGroupRepository = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ var AccessGroupRepository = _classThis = class {
50
+ constructor() {
51
+ this.postgres = (0, db_1.getPostgresClient)();
52
+ }
53
+ async getAccessGroup(accessGroupId) {
54
+ const query = `
55
+ SELECT * FROM dt_collections
56
+ WHERE "id" = $1
57
+ `;
58
+ const result = await this.postgres.query(query, [accessGroupId]);
59
+ return result.rows[0];
60
+ }
61
+ };
62
+ __setFunctionName(_classThis, "AccessGroupRepository");
63
+ (() => {
64
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
65
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
66
+ AccessGroupRepository = _classThis = _classDescriptor.value;
67
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
68
+ __runInitializers(_classThis, _classExtraInitializers);
69
+ })();
70
+ return AccessGroupRepository = _classThis;
71
+ })();
72
+ exports.AccessGroupRepository = AccessGroupRepository;
@@ -0,0 +1,5 @@
1
+ export declare class AccessGroupService {
2
+ private readonly accessGroupRepository;
3
+ constructor();
4
+ getAccessGroup(accessGroupId: string): Promise<any>;
5
+ }
@@ -1,4 +1,20 @@
1
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 __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
+ });
2
18
  var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
19
  function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
20
  var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
@@ -33,60 +49,57 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
49
  }
34
50
  return useValue ? value : void 0;
35
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
+ })();
36
69
  var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
70
  if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
71
  return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
72
  };
40
73
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.ConnectionRepository = void 0;
42
- const db_1 = require("../../../db");
43
- const typedi_1 = require("typedi");
44
- let ConnectionRepository = (() => {
74
+ exports.AccessGroupService = void 0;
75
+ const typedi_1 = __importStar(require("typedi"));
76
+ const AccessGroup_repository_1 = require("./AccessGroup.repository");
77
+ let AccessGroupService = (() => {
45
78
  let _classDecorators = [(0, typedi_1.Service)()];
46
79
  let _classDescriptor;
47
80
  let _classExtraInitializers = [];
48
81
  let _classThis;
49
- var ConnectionRepository = _classThis = class {
82
+ var AccessGroupService = _classThis = class {
50
83
  constructor() {
51
- this.pool = (0, db_1.getPostgresClient)();
52
- }
53
- async createConnection(data) {
54
- const result = await this.pool.query('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 *', [
55
- data.connectionName,
56
- data.connectionRefId,
57
- data.propertyId,
58
- data.connectionProvider,
59
- data.accessToken,
60
- data.refreshToken,
61
- data.clientId,
62
- data.clientSecret,
63
- data.isActive,
64
- data.metaData,
65
- ]);
66
- return result.rows[0];
67
- }
68
- async getConnectionById(connectionId) {
69
- const result = await this.pool.query("SELECT * FROM dt_connections WHERE id = $1", [connectionId]);
70
- return result.rows[0];
84
+ this.accessGroupRepository = typedi_1.default.get(AccessGroup_repository_1.AccessGroupRepository);
71
85
  }
72
- async updateConnection(connectionId, data) {
73
- // Build dynamic SET clause with quoted column names
74
- const setClause = Object.keys(data)
75
- .map((key, index) => `"${key}" = $${index + 2}`)
76
- .join(", ");
77
- const values = Object.values(data);
78
- const result = await this.pool.query(`UPDATE dt_connections SET ${setClause}, "updatedAt" = NOW() WHERE id = $1 RETURNING *`, [connectionId, ...values]);
79
- return result.rows[0];
86
+ async getAccessGroup(accessGroupId) {
87
+ if (!accessGroupId) {
88
+ throw new Error("Access Group ID is required");
89
+ }
90
+ return await this.accessGroupRepository.getAccessGroup(accessGroupId);
80
91
  }
81
92
  };
82
- __setFunctionName(_classThis, "ConnectionRepository");
93
+ __setFunctionName(_classThis, "AccessGroupService");
83
94
  (() => {
84
95
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
85
96
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
86
- ConnectionRepository = _classThis = _classDescriptor.value;
97
+ AccessGroupService = _classThis = _classDescriptor.value;
87
98
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
88
99
  __runInitializers(_classThis, _classExtraInitializers);
89
100
  })();
90
- return ConnectionRepository = _classThis;
101
+ return AccessGroupService = _classThis;
91
102
  })();
92
- exports.ConnectionRepository = ConnectionRepository;
103
+ exports.AccessGroupService = AccessGroupService;
104
+ // Accessgroup.getAccessGroup(accessGroupId)
105
+ // GetAccessGroup()
@@ -0,0 +1,14 @@
1
+ export interface IAccessGroup {
2
+ id: string;
3
+ propertyId: string;
4
+ name: string;
5
+ displayName: string;
6
+ type: string;
7
+ externalId?: string;
8
+ refId?: string;
9
+ isDeleted: boolean;
10
+ createdBy: string;
11
+ createdAt: Date;
12
+ updatedAt: Date;
13
+ accessibleBy: string[];
14
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./AccessGroup.service";
2
+ export * from "./IAccessGroup";
@@ -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("./AccessGroup.service"), exports);
18
+ __exportStar(require("./IAccessGroup"), exports);