@kohost/api-client 3.0.0-beta.7 → 3.0.0-beta.71

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 (264) hide show
  1. package/README.md +71 -0
  2. package/dist/cjs/AMQPClient/index.js +298 -0
  3. package/dist/cjs/{Client.js → Client/index.js} +1535 -586
  4. package/dist/cjs/Commands/CheckInReservationCommand.js +19 -0
  5. package/dist/cjs/Commands/Command.js +34 -0
  6. package/dist/cjs/Commands/CreateImageUploadEndpointCommand.js +17 -0
  7. package/dist/cjs/Commands/CreateShortLinkCommand.js +20 -0
  8. package/dist/cjs/Commands/DiscoverCategoriesCommand.js +20 -0
  9. package/dist/cjs/Commands/DiscoverReservationSpaceCategoryAvailabilitiesCommand.js +20 -0
  10. package/dist/cjs/Commands/DiscoverReservationsCommand.js +20 -0
  11. package/dist/cjs/Commands/DiscoverRoomsCommand.js +37 -0
  12. package/dist/cjs/Commands/DiscoverUsersCommand.js +19 -0
  13. package/dist/cjs/Commands/GetMobileKeyCommand.js +24 -0
  14. package/dist/cjs/Commands/GetProductsCommand.js +17 -0
  15. package/dist/cjs/Commands/OCRDocumentCommand.js +15 -0
  16. package/dist/cjs/Commands/SellProductsCommand.js +17 -0
  17. package/dist/cjs/Commands/SendEmailCommand.js +24 -0
  18. package/dist/cjs/Commands/SendSMSCommand.js +21 -0
  19. package/dist/cjs/Commands/SetAlarmCommand.js +17 -0
  20. package/dist/cjs/Commands/SetCourtesyCommand.js +17 -0
  21. package/dist/cjs/Commands/SetDimmerCommand.js +17 -0
  22. package/dist/cjs/Commands/SetLockCommand.js +17 -0
  23. package/dist/cjs/Commands/SetMediaCommand.js +17 -0
  24. package/dist/cjs/Commands/SetSceneCommand.js +17 -0
  25. package/dist/cjs/Commands/SetSwitchCommand.js +17 -0
  26. package/dist/cjs/Commands/SetThermostatCommand.js +17 -0
  27. package/dist/cjs/Commands/SetWindowCoveringCommand.js +17 -0
  28. package/dist/cjs/Commands/UpdateReservationCommand.js +19 -0
  29. package/dist/cjs/Commands/UpdateUserCommand.js +41 -0
  30. package/dist/cjs/Commands/UploadImageCommand.js +17 -0
  31. package/dist/cjs/Commands/index.js +55 -0
  32. package/dist/cjs/Errors/AppError.js +8 -0
  33. package/dist/cjs/Errors/AuthenticationError.js +9 -0
  34. package/dist/cjs/Errors/AuthorizationError.js +9 -0
  35. package/dist/cjs/Errors/ConflictError.js +9 -0
  36. package/dist/cjs/Errors/DeviceCommError.js +9 -0
  37. package/dist/cjs/Errors/LoginError.js +9 -0
  38. package/dist/cjs/Errors/NotFoundError.js +9 -0
  39. package/dist/cjs/Errors/RequestError.js +9 -0
  40. package/dist/cjs/Errors/SystemCommError.js +9 -0
  41. package/dist/cjs/Errors/TokenExpiredError.js +9 -0
  42. package/dist/cjs/Errors/UnprocessableRequestError.js +9 -0
  43. package/dist/cjs/Errors/ValidationError.js +9 -0
  44. package/dist/cjs/Errors/index.js +16 -0
  45. package/dist/cjs/Events/ApplicationInUseEvent.js +21 -0
  46. package/dist/cjs/Events/ApplicationOutOfUseEvent.js +21 -0
  47. package/dist/cjs/Events/EmailEvent.js +18 -0
  48. package/dist/cjs/Events/Event.js +55 -0
  49. package/dist/cjs/Events/SMSEvent.js +18 -0
  50. package/dist/cjs/Events/SMSSentEvent.js +17 -0
  51. package/dist/cjs/Events/SceneSetEvent.js +17 -0
  52. package/dist/cjs/Events/ShortLinkCreatedEvent.js +17 -0
  53. package/dist/cjs/Events/SystemAlarmUpdatedEvent.js +17 -0
  54. package/dist/cjs/Events/SystemCameraUpdatedEvent.js +17 -0
  55. package/dist/cjs/Events/SystemCategoryUpdatedEvent.js +17 -0
  56. package/dist/cjs/Events/SystemCourtesyUpdatedEvent.js +17 -0
  57. package/dist/cjs/Events/SystemDimmerUpdatedEvent.js +17 -0
  58. package/dist/cjs/Events/SystemEntityDeletedEvent.js +17 -0
  59. package/dist/cjs/Events/SystemGatewayUpdatedEvent.js +17 -0
  60. package/dist/cjs/Events/SystemLockUpdatedEvent.js +17 -0
  61. package/dist/cjs/Events/SystemMediaSourceUpdatedEvent.js +17 -0
  62. package/dist/cjs/Events/SystemMotionSensorUpdatedEvent.js +17 -0
  63. package/dist/cjs/Events/SystemOrganizationUpdatedEvent.js +17 -0
  64. package/dist/cjs/Events/SystemProductUpdatedEvent.js +17 -0
  65. package/dist/cjs/Events/SystemPropertyUpdatedEvent.js +17 -0
  66. package/dist/cjs/Events/SystemReservationUpdatedEvent.js +17 -0
  67. package/dist/cjs/Events/SystemSceneControllerUpdatedEvent.js +17 -0
  68. package/dist/cjs/Events/SystemSpaceUpdatedEvent.js +17 -0
  69. package/dist/cjs/Events/SystemSwitchUpdatedEvent.js +17 -0
  70. package/dist/cjs/Events/SystemThermostatUpdatedEvent.js +17 -0
  71. package/dist/cjs/Events/SystemUserUpdatedEvent.js +17 -0
  72. package/dist/cjs/Events/SystemWindowCoveringUpdatedEvent.js +17 -0
  73. package/dist/cjs/Events/index.js +63 -0
  74. package/dist/cjs/Models/Alarm.js +35 -0
  75. package/dist/cjs/Models/Camera.js +35 -0
  76. package/dist/cjs/Models/Category.js +36 -0
  77. package/dist/cjs/Models/Courtesy.js +39 -0
  78. package/dist/cjs/Models/Credential.js +35 -0
  79. package/dist/cjs/Models/Dimmer.js +61 -0
  80. package/dist/cjs/Models/DiscoveredDevice.js +36 -0
  81. package/dist/cjs/Models/EmailMessage.js +35 -0
  82. package/dist/cjs/Models/EnergyReport.js +35 -0
  83. package/dist/cjs/Models/EnergyReportShard.js +35 -0
  84. package/dist/cjs/Models/Gateway.js +35 -0
  85. package/dist/cjs/Models/Identification.js +38 -0
  86. package/dist/cjs/Models/Kohost.js +96 -0
  87. package/dist/cjs/Models/Lock.js +39 -0
  88. package/dist/cjs/Models/MediaFile.js +48 -0
  89. package/dist/cjs/Models/MediaSource.js +35 -0
  90. package/dist/cjs/Models/MotionSensor.js +35 -0
  91. package/dist/cjs/Models/Notification.js +34 -0
  92. package/dist/cjs/Models/Order.js +97 -0
  93. package/dist/cjs/Models/Organization.js +34 -0
  94. package/dist/cjs/Models/Product.js +35 -0
  95. package/dist/cjs/Models/Property.js +34 -0
  96. package/dist/cjs/Models/Reservation.js +114 -0
  97. package/dist/cjs/Models/Room.js +218 -0
  98. package/dist/cjs/Models/Scene.js +169 -0
  99. package/dist/cjs/Models/ShortLink.js +35 -0
  100. package/dist/cjs/Models/SmsMessage.js +35 -0
  101. package/dist/cjs/Models/Space.js +97 -0
  102. package/dist/cjs/Models/Switch.js +39 -0
  103. package/dist/cjs/Models/SystemUser.js +55 -0
  104. package/dist/cjs/Models/Thermostat.js +86 -0
  105. package/dist/cjs/Models/Ticket.js +112 -0
  106. package/dist/cjs/Models/User.js +115 -0
  107. package/dist/cjs/Models/WindowCovering.js +55 -0
  108. package/dist/cjs/Models/index.js +72 -0
  109. package/dist/cjs/SocketIoClient/index.js +74 -0
  110. package/dist/cjs/defs/deviceTypes.js +15 -0
  111. package/dist/cjs/defs/formalDeviceTypes.js +6 -0
  112. package/dist/cjs/defs/index.js +11 -0
  113. package/dist/cjs/{index.cjs.js → index.js} +7 -1
  114. package/dist/cjs/schemas/AlarmSchema.d.ts +151 -0
  115. package/dist/cjs/schemas/CameraSchema.d.ts +142 -0
  116. package/dist/cjs/schemas/CategorySchema.d.ts +81 -0
  117. package/dist/cjs/schemas/CourtesySchema.d.ts +141 -0
  118. package/dist/cjs/schemas/CredentialSchema.d.ts +21 -0
  119. package/dist/cjs/schemas/DefinitionsSchema.d.ts +10 -0
  120. package/dist/cjs/schemas/DimmerSchema.d.ts +141 -0
  121. package/dist/cjs/schemas/DiscoveredDeviceSchema.d.ts +39 -0
  122. package/dist/cjs/schemas/EmailMessageSchema.d.ts +49 -0
  123. package/dist/cjs/schemas/EnergyReportSchema.d.ts +57 -0
  124. package/dist/cjs/schemas/EnergyReportShardSchema.d.ts +61 -0
  125. package/dist/cjs/schemas/GatewaySchema.d.ts +138 -0
  126. package/dist/cjs/schemas/IdentificationSchema.d.ts +45 -0
  127. package/dist/cjs/schemas/LockSchema.d.ts +141 -0
  128. package/dist/cjs/schemas/MediaFileSchema.d.ts +43 -0
  129. package/dist/cjs/schemas/MediaSourceSchema.d.ts +237 -0
  130. package/dist/cjs/schemas/MotionSensorSchema.d.ts +136 -0
  131. package/dist/cjs/schemas/NotificationSchema.d.ts +54 -0
  132. package/dist/cjs/schemas/OrderSchema.d.ts +91 -0
  133. package/dist/cjs/schemas/OrganizationSchema.d.ts +34 -0
  134. package/dist/cjs/schemas/PaymentSchema.d.ts +33 -0
  135. package/dist/cjs/schemas/ProductSchema.d.ts +65 -0
  136. package/dist/cjs/schemas/PropertySchema.d.ts +38 -0
  137. package/dist/cjs/schemas/ReservationSchema.d.ts +112 -0
  138. package/dist/cjs/schemas/RoomSchema.d.ts +1066 -0
  139. package/dist/cjs/schemas/SceneSchema.d.ts +57 -0
  140. package/dist/cjs/schemas/ShortLinkSchema.d.ts +20 -0
  141. package/dist/cjs/schemas/SmsMessageSchema.d.ts +40 -0
  142. package/dist/cjs/schemas/SpaceSchema.d.ts +58 -0
  143. package/dist/cjs/schemas/SwitchSchema.d.ts +141 -0
  144. package/dist/cjs/schemas/SystemUserSchema.d.ts +192 -0
  145. package/dist/cjs/schemas/ThermostatSchema.d.ts +171 -0
  146. package/dist/cjs/schemas/TicketSchema.d.ts +88 -0
  147. package/dist/cjs/schemas/UserSchema.d.ts +280 -0
  148. package/dist/cjs/schemas/WindowCoveringSchema.d.ts +140 -0
  149. package/dist/cjs/schemas/alarm.json +81 -0
  150. package/dist/cjs/schemas/camera.json +50 -0
  151. package/dist/cjs/schemas/category.json +42 -0
  152. package/dist/cjs/schemas/courtesy.json +48 -0
  153. package/dist/cjs/schemas/credential.json +37 -0
  154. package/dist/cjs/schemas/definitions.json +217 -0
  155. package/dist/cjs/schemas/dimmer.json +45 -0
  156. package/dist/cjs/schemas/discoveredDevice.json +31 -0
  157. package/dist/cjs/schemas/emailMessage.json +71 -0
  158. package/dist/cjs/schemas/energyReport.json +86 -0
  159. package/dist/cjs/schemas/energyReportShard.json +75 -0
  160. package/dist/cjs/schemas/gateway.json +34 -0
  161. package/dist/cjs/schemas/identification.json +61 -0
  162. package/dist/cjs/schemas/lock.json +44 -0
  163. package/dist/cjs/schemas/mediaFile.json +70 -0
  164. package/dist/cjs/schemas/mediaSource.json +187 -0
  165. package/dist/cjs/schemas/motionSensor.json +32 -0
  166. package/dist/cjs/schemas/notification.json +29 -0
  167. package/dist/cjs/schemas/order.json +182 -0
  168. package/dist/cjs/schemas/organization.json +40 -0
  169. package/dist/cjs/schemas/payment.json +47 -0
  170. package/dist/cjs/schemas/product.json +41 -0
  171. package/dist/cjs/schemas/property.json +333 -0
  172. package/dist/cjs/schemas/reservation.json +130 -0
  173. package/dist/cjs/schemas/room.json +98 -0
  174. package/dist/cjs/schemas/scene.json +121 -0
  175. package/dist/cjs/schemas/shortLink.json +30 -0
  176. package/dist/cjs/schemas/smsMessage.json +61 -0
  177. package/dist/cjs/schemas/space.json +118 -0
  178. package/dist/cjs/schemas/switch.json +44 -0
  179. package/dist/cjs/schemas/systemUser.json +98 -0
  180. package/dist/cjs/schemas/thermostat.json +150 -0
  181. package/dist/cjs/schemas/ticket.json +141 -0
  182. package/dist/cjs/schemas/user.json +170 -0
  183. package/dist/cjs/schemas/windowCovering.json +42 -0
  184. package/dist/cjs/utils/errorFactory.js +8 -0
  185. package/dist/cjs/utils/eventFactory.js +10 -0
  186. package/dist/cjs/utils/getDeviceTypes.js +7 -0
  187. package/dist/cjs/utils/getFormalDeviceType.js +5 -0
  188. package/dist/cjs/utils/index.js +11 -0
  189. package/dist/cjs/utils/schema.js +25 -0
  190. package/dist/esm/Client.js +1632 -627
  191. package/dist/esm/Client.js.map +4 -4
  192. package/dist/esm/Commands.js +521 -113
  193. package/dist/esm/Commands.js.map +3 -3
  194. package/dist/esm/Errors.js +73 -22
  195. package/dist/esm/Errors.js.map +3 -3
  196. package/dist/esm/Events.js +390 -73
  197. package/dist/esm/Events.js.map +3 -3
  198. package/dist/esm/Models.js +3292 -1186
  199. package/dist/esm/Models.js.map +4 -4
  200. package/dist/esm/SocketIoClient.js +4846 -0
  201. package/dist/esm/SocketIoClient.js.map +7 -0
  202. package/dist/esm/defs.js +146 -101
  203. package/dist/esm/defs.js.map +4 -4
  204. package/dist/esm/index.js +17 -10
  205. package/dist/esm/utils.js +445 -73
  206. package/dist/esm/utils.js.map +3 -3
  207. package/dist/useCases/AdminUpdateCustomer.js +1 -1
  208. package/dist/useCases/AssignSpaceToReservation.js +32 -0
  209. package/dist/useCases/{AdminCreateProperty.js → BatchNotifyCheckIn.js} +2 -2
  210. package/dist/useCases/{AdminCreateCustomer.js → CreateCateory.js} +2 -2
  211. package/dist/useCases/CreateImageUploadEndpoint.js +32 -0
  212. package/dist/useCases/{DeleteIntegration.js → CreateMediaSource.js} +4 -4
  213. package/dist/useCases/{AdminListCustomers.js → CreateOrganization.js} +3 -3
  214. package/dist/useCases/{AdminLoginUser.js → CreateProperty.js} +2 -2
  215. package/dist/useCases/DeleteCategory.js +32 -0
  216. package/dist/useCases/DeleteMediaFile.js +32 -0
  217. package/dist/useCases/DeleteMediaSource.js +32 -0
  218. package/dist/useCases/{ListIntegrations.js → DescribeCategory.js} +3 -3
  219. package/dist/useCases/{DeleteSource.js → DescribeLockCredential.js} +3 -3
  220. package/dist/useCases/{AdminListAdminUsers.js → DescribeMediaSource.js} +3 -3
  221. package/dist/useCases/DescribeMyAccessCredentials.js +32 -0
  222. package/dist/useCases/{AdminCreateAdminUser.js → DescribeOrganization.js} +4 -4
  223. package/dist/useCases/{DescribeIntegration.js → DescribeProduct.js} +2 -2
  224. package/dist/useCases/{AdminDescribeCustomer.js → DescribeProperty.js} +2 -2
  225. package/dist/useCases/DescribeReservationEarlyCheckInProducts.js +32 -0
  226. package/dist/useCases/DescribeReservationLateCheckOutProducts.js +32 -0
  227. package/dist/useCases/{AdminDescribeProperty.js → DescribeReservationRoomUpgrades.js} +2 -2
  228. package/dist/useCases/ListCategories.js +32 -0
  229. package/dist/useCases/ListMediaSources.js +32 -0
  230. package/dist/useCases/{CreateSource.js → ListMyOrders.js} +4 -4
  231. package/dist/useCases/{AdminListProperties.js → ListMyTickets.js} +2 -2
  232. package/dist/useCases/ListOrders.js +32 -0
  233. package/dist/useCases/{AdminRefreshToken.js → ListOrganizations.js} +3 -3
  234. package/dist/useCases/ListProperties.js +32 -0
  235. package/dist/useCases/ListScenes.js +32 -0
  236. package/dist/useCases/ListTeam.js +32 -0
  237. package/dist/useCases/ListUserOrders.js +32 -0
  238. package/dist/useCases/ListUserSpaces.js +32 -0
  239. package/dist/useCases/LogoutUser.js +32 -0
  240. package/dist/useCases/PurchaseReservationEarlyCheckInProducts.js +32 -0
  241. package/dist/useCases/PurchaseReservationLateCheckOutProducts.js +32 -0
  242. package/dist/useCases/{CreateIntegrationDeviceMapEntry.js → PurchaseReservationRoomUpgrades.js} +2 -2
  243. package/dist/useCases/RequestLoginLink.js +1 -1
  244. package/dist/useCases/{CreateIntegration.js → RequestMyKeyToken.js} +2 -2
  245. package/dist/useCases/RequestPWAToken.js +32 -0
  246. package/dist/useCases/SendCheckInSMS.js +32 -0
  247. package/dist/useCases/{SetSource.js → SetDimmer.js} +2 -2
  248. package/dist/useCases/{DescribeSource.js → SetMediaSource.js} +3 -3
  249. package/dist/useCases/{UpdateSource.js → SetRoomScene.js} +3 -3
  250. package/dist/useCases/SetSpaceScene.js +32 -0
  251. package/dist/useCases/TipUser.js +32 -0
  252. package/dist/useCases/{AdminUpdateProperty.js → UpdateCategory.js} +2 -2
  253. package/dist/useCases/{UpdateIntegration.js → UpdateMediaSource.js} +3 -3
  254. package/dist/useCases/UpdateProperty.js +32 -0
  255. package/dist/useCases/UpdateReservationExpectedArrivalTime.js +32 -0
  256. package/dist/useCases/{ListSources.js → UploadImage.js} +4 -4
  257. package/package.json +36 -10
  258. package/dist/cjs/Commands.js +0 -585
  259. package/dist/cjs/Errors.js +0 -176
  260. package/dist/cjs/Events.js +0 -387
  261. package/dist/cjs/Models.js +0 -3612
  262. package/dist/cjs/defs.js +0 -178
  263. package/dist/cjs/utils.js +0 -250
  264. package/dist/useCases/AdminRequestLoginLink.js +0 -32
@@ -0,0 +1,63 @@
1
+ const SystemGatewayUpdatedEvent = require("./SystemGatewayUpdatedEvent");
2
+ const SystemThermostatUpdatedEvent = require("./SystemThermostatUpdatedEvent");
3
+ const SystemDimmerUpdatedEvent = require("./SystemDimmerUpdatedEvent");
4
+ const SystemSwitchUpdatedEvent = require("./SystemSwitchUpdatedEvent");
5
+ const SystemLockUpdatedEvent = require("./SystemLockUpdatedEvent");
6
+ const SystemCameraUpdatedEvent = require("./SystemCameraUpdatedEvent");
7
+ const SystemSceneControllerUpdatedEvent = require("./SystemSceneControllerUpdatedEvent");
8
+ const SystemWindowCoveringUpdatedEvent = require("./SystemWindowCoveringUpdatedEvent");
9
+ const SystemMediaSourceUpdatedEvent = require("./SystemMediaSourceUpdatedEvent");
10
+ const SystemCourtesyUpdatedEvent = require("./SystemCourtesyUpdatedEvent");
11
+ const SystemAlarmUpdatedEvent = require("./SystemAlarmUpdatedEvent");
12
+ const SystemMotionSensorUpdatedEvent = require("./SystemMotionSensorUpdatedEvent");
13
+ const SystemPropertyUpdatedEvent = require("./SystemPropertyUpdatedEvent");
14
+ const SystemOrganizationUpdatedEvent = require("./SystemOrganizationUpdatedEvent");
15
+
16
+ const SceneSetEvent = require("./SceneSetEvent");
17
+
18
+ const SystemUserUpdatedEvent = require("./SystemUserUpdatedEvent");
19
+ const SystemSpaceUpdatedEvent = require("./SystemSpaceUpdatedEvent");
20
+ const SystemCategoryUpdatedEvent = require("./SystemCategoryUpdatedEvent");
21
+ const SystemProductUpdatedEvent = require("./SystemProductUpdatedEvent");
22
+
23
+ const SystemReservationUpdatedEvent = require("./SystemReservationUpdatedEvent");
24
+
25
+ const SMSEvent = require("./SMSEvent");
26
+ const EmailEvent = require("./EmailEvent");
27
+ const ShortLinkCreatedEvent = require("./ShortLinkCreatedEvent");
28
+
29
+ const ApplicationInUseEvent = require("./ApplicationInUseEvent");
30
+ const ApplicationOutOfUseEvent = require("./ApplicationOutOfUseEvent");
31
+
32
+ // Delete Events
33
+ const SystemEntityDeletedEvent = require("./SystemEntityDeletedEvent");
34
+
35
+
36
+ module.exports = {
37
+ SystemAlarmUpdatedEvent,
38
+ SystemGatewayUpdatedEvent,
39
+ SystemThermostatUpdatedEvent,
40
+ SystemDimmerUpdatedEvent,
41
+ SystemSwitchUpdatedEvent,
42
+ SystemLockUpdatedEvent,
43
+ SystemCameraUpdatedEvent,
44
+ SystemSceneControllerUpdatedEvent,
45
+ SystemWindowCoveringUpdatedEvent,
46
+ SystemMediaSourceUpdatedEvent,
47
+ SystemMotionSensorUpdatedEvent,
48
+ SystemCourtesyUpdatedEvent,
49
+ SystemUserUpdatedEvent,
50
+ SystemSpaceUpdatedEvent,
51
+ SystemCategoryUpdatedEvent,
52
+ SystemProductUpdatedEvent,
53
+ SystemPropertyUpdatedEvent,
54
+ SystemOrganizationUpdatedEvent,
55
+ SystemReservationUpdatedEvent,
56
+ SystemEntityDeletedEvent,
57
+ SceneSetEvent,
58
+ SMSEvent,
59
+ EmailEvent,
60
+ ShortLinkCreatedEvent,
61
+ ApplicationInUseEvent,
62
+ ApplicationOutOfUseEvent,
63
+ };
@@ -0,0 +1,35 @@
1
+ // create the Alarm Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/alarm.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Alarm extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/AlarmSchema").Alarm} AlarmType
12
+ * Create a Alarm instance.
13
+ * @constructor
14
+ * @param {AlarmType} alarm - The alarm object of type Alarm.
15
+ */
16
+ constructor(alarm) {
17
+ super(alarm);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Alarm.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Alarm.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Alarm, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = Alarm;
@@ -0,0 +1,35 @@
1
+ // create the Camera Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/camera.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Camera extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/CameraSchema").Camera} CameraType
12
+ * Create a Camera instance.
13
+ * @constructor
14
+ * @param {CameraType} camera - The camera object of type Camera.
15
+ */
16
+ constructor(camera) {
17
+ super(camera);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Camera.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Camera.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Camera, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = Camera;
@@ -0,0 +1,36 @@
1
+ // Create the Category Model
2
+ // Originally used for hotel room category e.g. Double Queen
3
+ const schemas = require("../utils/schema");
4
+ const schema = require("../schemas/category.json");
5
+ const Kohost = require("./Kohost");
6
+
7
+ schemas.add(schema);
8
+ const validator = schemas.compile(schema);
9
+
10
+ class Category extends Kohost {
11
+ /**
12
+ * @typedef {import("../schemas/CategorySchema").Category} CategoryType
13
+ * Create a Category instance.
14
+ * @constructor
15
+ * @param {CategoryType} category - The category object of type SpaceType.
16
+ */
17
+ constructor(category) {
18
+ super(category);
19
+ }
20
+ }
21
+
22
+ Object.defineProperty(Category.prototype, "schema", {
23
+ value: schema,
24
+ });
25
+
26
+ Object.defineProperty(Category.prototype, "validator", {
27
+ get: function () {
28
+ return validator;
29
+ },
30
+ });
31
+
32
+ Object.defineProperty(Category, "validProperties", {
33
+ value: Object.keys(schema.properties),
34
+ });
35
+
36
+ module.exports = Category;
@@ -0,0 +1,39 @@
1
+ // create the Courtesy Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/courtesy.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Courtesy extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/CourtesySchema").Courtesy} CourtesyType
12
+ * Create a Courtesy instance.
13
+ * @constructor
14
+ * @param {CourtesyType} courtesy - The courtesy object of type Courtesy.
15
+ */
16
+ constructor(courtesy) {
17
+ super(courtesy);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Courtesy.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Courtesy.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Courtesy, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ Object.defineProperty(Courtesy, "actionProperties", {
36
+ value: ["state"],
37
+ });
38
+
39
+ module.exports = Courtesy;
@@ -0,0 +1,35 @@
1
+ // create the Credential Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/credential.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Credential extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/CredentialSchema").Credential} CredentialType
12
+ * Create a Credential instance.
13
+ * @constructor
14
+ * @param {CredentialType} credential - The credential object of type Credential.
15
+ */
16
+ constructor(credential) {
17
+ super(credential);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Credential.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Credential.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Credential, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = Credential;
@@ -0,0 +1,61 @@
1
+ // Create the Dimmer Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/dimmer.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ /**
10
+ * Represents a Dimmer device.
11
+ * @class
12
+ * @extends Kohost
13
+ */
14
+
15
+ class Dimmer extends Kohost {
16
+ /**
17
+ * @typedef {import("../schemas/DimmerSchema").Dimmer} DimmerType
18
+ * Create a Dimmer instance.
19
+ * @constructor
20
+ * @param {DimmerType} dimmer - The dimmer object of type Dimmer.
21
+ */
22
+ constructor(dimmer) {
23
+ super(dimmer);
24
+ }
25
+
26
+ static getActionDelta(old, _new) {
27
+ const delta = {};
28
+ for (const action in _new) {
29
+ if (this.actionProperties?.includes(action)) {
30
+ if (action === "level") {
31
+ const oldLevel = old[action];
32
+ const newLevel = _new[action];
33
+ delta[action] = newLevel - oldLevel / 100;
34
+ } else {
35
+ delta[action] = 1;
36
+ }
37
+ }
38
+ }
39
+ return delta;
40
+ }
41
+ }
42
+
43
+ Object.defineProperty(Dimmer.prototype, "schema", {
44
+ value: schema,
45
+ });
46
+
47
+ Object.defineProperty(Dimmer.prototype, "validator", {
48
+ get: function () {
49
+ return validator;
50
+ },
51
+ });
52
+
53
+ Object.defineProperty(Dimmer, "validProperties", {
54
+ value: Object.keys(schema.properties),
55
+ });
56
+
57
+ Object.defineProperty(Dimmer, "actionProperties", {
58
+ value: ["level"],
59
+ });
60
+
61
+ module.exports = Dimmer;
@@ -0,0 +1,36 @@
1
+ // Create the Discovered Device Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/discoveredDevice.json");
4
+
5
+ const Kohost = require("./Kohost");
6
+
7
+ schemas.add(schema);
8
+ const validator = schemas.compile(schema);
9
+
10
+ class DiscoveredDevice extends Kohost {
11
+ /**
12
+ * @typedef {import("../schemas/DiscoveredDeviceSchema").DiscoveredDevice} DiscoveredDeviceType
13
+ * Create a DiscoveredDevice instance.
14
+ * @constructor
15
+ * @param {DiscoveredDeviceType} device - The dd object of type DiscoveredDevice.
16
+ */
17
+ constructor(device) {
18
+ super(device);
19
+ }
20
+ }
21
+
22
+ Object.defineProperty(DiscoveredDevice.prototype, "schema", {
23
+ value: schema,
24
+ });
25
+
26
+ Object.defineProperty(DiscoveredDevice.prototype, "validator", {
27
+ get: function () {
28
+ return validator;
29
+ },
30
+ });
31
+
32
+ Object.defineProperty(DiscoveredDevice, "validProperties", {
33
+ value: Object.keys(schema.properties),
34
+ });
35
+
36
+ module.exports = DiscoveredDevice;
@@ -0,0 +1,35 @@
1
+ // Create the SMS Message Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/emailMessage.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class EmailMessage extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/EmailMessageSchema").EmailMessage} EmailMessageType
12
+ * Create a EmailMessage instance.
13
+ * @constructor
14
+ * @param {EmailMessageType} message - The message object of type EmailMessage.
15
+ */
16
+ constructor(message) {
17
+ super(message);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(EmailMessage.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(EmailMessage.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(EmailMessage, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = EmailMessage;
@@ -0,0 +1,35 @@
1
+ // create the energyReportDaily Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/energyReport.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class EnergyReport extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/EnergyReportSchema").EnergyReport} EnergyReportType
12
+ * Create a EnergyReport instance.
13
+ * @constructor
14
+ * @param {EnergyReportType} energyReport - The energyReport object of type EnergyReport.
15
+ */
16
+ constructor(energyReport) {
17
+ super(energyReport);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(EnergyReport.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(EnergyReport.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(EnergyReport, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = EnergyReport;
@@ -0,0 +1,35 @@
1
+ // create the energyReportShard Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/energyReportShard.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class EnergyReportShard extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/EnergyReportShardSchema").EnergyReportShard} EnergyReportShardType
12
+ * Create a EnergyReportShard instance.
13
+ * @constructor
14
+ * @param {EnergyReportShardType} energyReportShard - The energyReportShard object of type EnergyReportShard.
15
+ */
16
+ constructor(energyReportShard) {
17
+ super(energyReportShard);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(EnergyReportShard.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(EnergyReportShard.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(EnergyReportShard, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = EnergyReportShard;
@@ -0,0 +1,35 @@
1
+ // Create the Gateway Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/gateway.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Gateway extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/GatewaySchema").Gateway} GatewayType
12
+ * Create a Gateway instance.
13
+ * @constructor
14
+ * @param {GatewayType} gateway - The gateway object of type Gateway.
15
+ */
16
+ constructor(gateway) {
17
+ super(gateway);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Gateway.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Gateway.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Gateway, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ module.exports = Gateway;
@@ -0,0 +1,38 @@
1
+ const schemas = require("../utils/schema");
2
+ const schema = require("../schemas/identification.json");
3
+ const Kohost = require("./Kohost");
4
+
5
+ schemas.add(schema);
6
+ const validator = schemas.compile(schema);
7
+
8
+ class Identification extends Kohost {
9
+ /**
10
+ * @typedef {import("../schemas/IdentificationSchema").Identification} IdentificationType
11
+ * Create a Identification instance.
12
+ * @constructor
13
+ * @param {IdentificationType} identification - The identification object of type Identification.
14
+ */
15
+ constructor(identification) {
16
+ super(identification);
17
+ }
18
+
19
+ get isExpired() {
20
+ return new Date(this.expires) < new Date();
21
+ }
22
+ }
23
+
24
+ Object.defineProperty(Identification.prototype, "schema", {
25
+ value: schema,
26
+ });
27
+
28
+ Object.defineProperty(Identification.prototype, "validator", {
29
+ get: function () {
30
+ return validator;
31
+ },
32
+ });
33
+
34
+ Object.defineProperty(Identification, "validProperties", {
35
+ value: Object.keys(schema.properties),
36
+ });
37
+
38
+ module.exports = Identification;
@@ -0,0 +1,96 @@
1
+ const { ValidationError } = require("../Errors");
2
+ const { customAlphabet: generate } = require("nanoid");
3
+
4
+ class Kohost {
5
+ constructor(data) {
6
+ if (!this.schema) {
7
+ throw new Error("Schema is not defined");
8
+ }
9
+
10
+ if (!this.validator) {
11
+ throw new Error("Validator is not defined");
12
+ }
13
+
14
+ const isNew = data?.id ? false : true;
15
+
16
+ this.#_setId(data);
17
+ this.#_validate(data);
18
+ this.#_setProperties(data);
19
+ this.#_setTimestamps(isNew);
20
+ }
21
+
22
+ static get validProperties() {
23
+ throw new Error("validProperties is not defined");
24
+ }
25
+
26
+ get schemaProperties() {
27
+ return Object.keys(this.validator.schema.properties);
28
+ }
29
+
30
+ #_setId(data) {
31
+ if (data._id) data.id = data._id;
32
+ if (!data.id) {
33
+ data.id = this.constructor.generateId();
34
+ }
35
+ delete data._id;
36
+ }
37
+
38
+ #_setProperties(data) {
39
+ this.schemaProperties.forEach((key) => {
40
+ if (data[key] !== undefined) this[key] = data[key];
41
+ });
42
+ }
43
+
44
+ #_setTimestamps(isNew) {
45
+ const now = new Date();
46
+ if (
47
+ isNew &&
48
+ this.schemaProperties.includes("createdAt") &&
49
+ !this.createdAt
50
+ ) {
51
+ this.createdAt = now;
52
+ }
53
+ }
54
+
55
+ #_validate(data) {
56
+ const valid = this.validator(data);
57
+ if (!valid) {
58
+ throw new ValidationError(`Invalid ${this.constructor.name}`, {
59
+ cause: this.validator.errors,
60
+ });
61
+ }
62
+ }
63
+
64
+ static generateId() {
65
+ const length = 8;
66
+ const characters =
67
+ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
68
+ const id = generate(characters, length)();
69
+ return id;
70
+ }
71
+
72
+ static getActionDelta(old, _new) {
73
+ const delta = {};
74
+ for (const action in _new) {
75
+ if (this.actionProperties?.includes(action)) {
76
+ if (old[action] !== _new[action]) {
77
+ delta[action] = 1;
78
+ }
79
+ }
80
+ }
81
+ return delta;
82
+ }
83
+
84
+ toObject() {
85
+ const obj = { ...this };
86
+ // delete keys if they are not valid properties
87
+ Object.keys(obj).forEach((key) => {
88
+ if (!this.constructor.validProperties.includes(key)) {
89
+ delete obj[key];
90
+ }
91
+ });
92
+ return obj;
93
+ }
94
+ }
95
+
96
+ module.exports = Kohost;
@@ -0,0 +1,39 @@
1
+ // Create the Lock Model
2
+ const schemas = require("../utils/schema");
3
+ const schema = require("../schemas/lock.json");
4
+ const Kohost = require("./Kohost");
5
+
6
+ schemas.add(schema);
7
+ const validator = schemas.compile(schema);
8
+
9
+ class Lock extends Kohost {
10
+ /**
11
+ * @typedef {import("../schemas/LockSchema").Lock} LockType
12
+ * Create a Lock instance.
13
+ * @constructor
14
+ * @param {LockType} lock - The lock object of type Lock.
15
+ */
16
+ constructor(lock) {
17
+ super(lock);
18
+ }
19
+ }
20
+
21
+ Object.defineProperty(Lock.prototype, "schema", {
22
+ value: schema,
23
+ });
24
+
25
+ Object.defineProperty(Lock.prototype, "validator", {
26
+ get: function () {
27
+ return validator;
28
+ },
29
+ });
30
+
31
+ Object.defineProperty(Lock, "validProperties", {
32
+ value: Object.keys(schema.properties),
33
+ });
34
+
35
+ Object.defineProperty(Lock, "actionProperties", {
36
+ value: ["state"],
37
+ });
38
+
39
+ module.exports = Lock;