@kohost/api-client 3.0.0-beta.47 → 3.0.0-beta.50

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 (156) hide show
  1. package/dist/cjs/AMQPClient/index.js +290 -0
  2. package/dist/cjs/Commands/CheckInReservationCommand.js +19 -0
  3. package/dist/cjs/Commands/Command.js +34 -0
  4. package/dist/cjs/Commands/CreateImageUploadEndpointCommand.js +17 -0
  5. package/dist/cjs/Commands/CreateShortLinkCommand.js +20 -0
  6. package/dist/cjs/Commands/DiscoverReservationRoomTypeUpsellOptionsCommand.js +20 -0
  7. package/dist/cjs/Commands/DiscoverReservationsCommand.js +20 -0
  8. package/dist/cjs/Commands/DiscoverRoomTypesCommand.js +19 -0
  9. package/dist/cjs/Commands/DiscoverRoomsCommand.js +35 -0
  10. package/dist/cjs/Commands/DiscoverUsersCommand.js +19 -0
  11. package/dist/cjs/Commands/GetMobileKeyCommand.js +24 -0
  12. package/dist/cjs/Commands/GetProductsCommand.js +17 -0
  13. package/dist/cjs/Commands/OCRDocumentCommand.js +15 -0
  14. package/dist/cjs/Commands/SellProductsCommand.js +17 -0
  15. package/dist/cjs/Commands/SendEmailCommand.js +24 -0
  16. package/dist/cjs/Commands/SendSMSCommand.js +21 -0
  17. package/dist/cjs/Commands/SetAlarmCommand.js +17 -0
  18. package/dist/cjs/Commands/SetCourtesyCommand.js +17 -0
  19. package/dist/cjs/Commands/SetDimmerCommand.js +17 -0
  20. package/dist/cjs/Commands/SetLockCommand.js +17 -0
  21. package/dist/cjs/Commands/SetMediaCommand.js +17 -0
  22. package/dist/cjs/Commands/SetSceneCommand.js +17 -0
  23. package/dist/cjs/Commands/SetSwitchCommand.js +17 -0
  24. package/dist/cjs/Commands/SetThermostatCommand.js +17 -0
  25. package/dist/cjs/Commands/SetWindowCoveringCommand.js +17 -0
  26. package/dist/cjs/Commands/UpdateReservationCommand.js +19 -0
  27. package/dist/cjs/Commands/UpdateUserCommand.js +41 -0
  28. package/dist/cjs/Commands/UploadImageCommand.js +17 -0
  29. package/dist/cjs/Commands/index.js +55 -0
  30. package/dist/cjs/Errors/AppError.js +8 -0
  31. package/dist/cjs/Errors/AuthenticationError.js +9 -0
  32. package/dist/cjs/Errors/AuthorizationError.js +9 -0
  33. package/dist/cjs/Errors/DeviceCommError.js +9 -0
  34. package/dist/cjs/Errors/LoginError.js +9 -0
  35. package/dist/cjs/Errors/NotFoundError.js +9 -0
  36. package/dist/cjs/Errors/RequestError.js +9 -0
  37. package/dist/cjs/Errors/SystemCommError.js +9 -0
  38. package/dist/cjs/Errors/TokenExpiredError.js +9 -0
  39. package/dist/cjs/Errors/UnprocessableRequestError.js +9 -0
  40. package/dist/cjs/Errors/ValidationError.js +9 -0
  41. package/dist/cjs/Errors/index.js +15 -0
  42. package/dist/cjs/Events/ApplicationInUseEvent.js +17 -0
  43. package/dist/cjs/Events/ApplicationOutOfUseEvent.js +17 -0
  44. package/dist/cjs/Events/EmailEvent.js +18 -0
  45. package/dist/cjs/Events/Event.js +55 -0
  46. package/dist/cjs/Events/SMSEvent.js +18 -0
  47. package/dist/cjs/Events/SMSSentEvent.js +17 -0
  48. package/dist/cjs/Events/ShortLinkCreatedEvent.js +17 -0
  49. package/dist/cjs/Events/SystemCameraUpdatedEvent.js +17 -0
  50. package/dist/cjs/Events/SystemCourtesyUpdatedEvent.js +17 -0
  51. package/dist/cjs/Events/SystemDimmerUpdatedEvent.js +17 -0
  52. package/dist/cjs/Events/SystemGatewayUpdatedEvent.js +17 -0
  53. package/dist/cjs/Events/SystemLockUpdatedEvent.js +17 -0
  54. package/dist/cjs/Events/SystemMediaSourceUpdatedEvent.js +17 -0
  55. package/dist/cjs/Events/SystemMotionSensorUpdatedEvent.js +17 -0
  56. package/dist/cjs/Events/SystemProductUpdatedEvent.js +17 -0
  57. package/dist/cjs/Events/SystemReservationUpdatedEvent.js +17 -0
  58. package/dist/cjs/Events/SystemSceneControllerUpdatedEvent.js +17 -0
  59. package/dist/cjs/Events/SystemSpaceTypeUpdatedEvent.js +17 -0
  60. package/dist/cjs/Events/SystemSpaceUpdatedEvent.js +17 -0
  61. package/dist/cjs/Events/SystemSwitchUpdatedEvent.js +17 -0
  62. package/dist/cjs/Events/SystemThermostatUpdatedEvent.js +17 -0
  63. package/dist/cjs/Events/SystemUserUpdatedEvent.js +17 -0
  64. package/dist/cjs/Events/SystemWindowCoveringUpdatedEvent.js +17 -0
  65. package/dist/cjs/Events/index.js +50 -0
  66. package/dist/cjs/Models/Alarm.js +29 -0
  67. package/dist/cjs/Models/Camera.js +29 -0
  68. package/dist/cjs/Models/Courtesy.js +33 -0
  69. package/dist/cjs/Models/Credential.js +29 -0
  70. package/dist/cjs/Models/Dimmer.js +61 -0
  71. package/dist/cjs/Models/DiscoveredDevice.js +30 -0
  72. package/dist/cjs/Models/EmailMessage.js +29 -0
  73. package/dist/cjs/Models/EnergyReport.js +29 -0
  74. package/dist/cjs/Models/EnergyReportShard.js +29 -0
  75. package/dist/cjs/Models/Gateway.js +29 -0
  76. package/dist/cjs/Models/Identification.js +32 -0
  77. package/dist/cjs/Models/Kohost.js +96 -0
  78. package/dist/cjs/Models/Lock.js +33 -0
  79. package/dist/cjs/Models/MediaFile.js +41 -0
  80. package/dist/cjs/Models/MediaSource.js +29 -0
  81. package/dist/cjs/Models/MotionSensor.js +29 -0
  82. package/dist/cjs/Models/Organization.js +28 -0
  83. package/dist/cjs/Models/Product.js +29 -0
  84. package/dist/cjs/Models/Property.js +28 -0
  85. package/dist/cjs/Models/Reservation.js +98 -0
  86. package/dist/cjs/Models/Room.js +212 -0
  87. package/dist/cjs/Models/Scene.js +183 -0
  88. package/dist/cjs/Models/ShortLink.js +29 -0
  89. package/dist/cjs/Models/SmsMessage.js +29 -0
  90. package/dist/cjs/Models/Space.js +97 -0
  91. package/dist/cjs/Models/SpaceType.js +30 -0
  92. package/dist/cjs/Models/Switch.js +33 -0
  93. package/dist/cjs/Models/SystemUser.js +48 -0
  94. package/dist/cjs/Models/Thermostat.js +80 -0
  95. package/dist/cjs/Models/Ticket.js +105 -0
  96. package/dist/cjs/Models/User.js +73 -0
  97. package/dist/cjs/Models/WindowCovering.js +49 -0
  98. package/dist/cjs/Models/index.js +68 -0
  99. package/dist/cjs/{SocketIoClient.js → SocketIoClient/index.js} +19 -14
  100. package/dist/cjs/defs/deviceTypes.js +15 -0
  101. package/dist/cjs/defs/formalDeviceTypes.js +6 -0
  102. package/dist/cjs/defs/index.js +11 -0
  103. package/dist/cjs/index.js +23 -0
  104. package/dist/cjs/schemas/alarm.json +103 -0
  105. package/dist/cjs/schemas/camera.json +50 -0
  106. package/dist/cjs/schemas/courtesy.json +46 -0
  107. package/dist/cjs/schemas/credential.json +31 -0
  108. package/dist/cjs/schemas/definitions.json +191 -0
  109. package/dist/cjs/schemas/dimmer.json +43 -0
  110. package/dist/cjs/schemas/discoveredDevice.json +31 -0
  111. package/dist/cjs/schemas/emailMessage.json +71 -0
  112. package/dist/cjs/schemas/energyReport.json +86 -0
  113. package/dist/cjs/schemas/energyReportShard.json +75 -0
  114. package/dist/cjs/schemas/gateway.json +35 -0
  115. package/dist/cjs/schemas/identification.json +61 -0
  116. package/dist/cjs/schemas/lock.json +45 -0
  117. package/dist/cjs/schemas/mediaFile.json +67 -0
  118. package/dist/cjs/schemas/mediaSource.json +184 -0
  119. package/dist/cjs/schemas/motionSensor.json +32 -0
  120. package/dist/cjs/schemas/organization.json +36 -0
  121. package/dist/cjs/schemas/payment.json +47 -0
  122. package/dist/cjs/schemas/product.json +40 -0
  123. package/dist/cjs/schemas/property.json +246 -0
  124. package/dist/cjs/schemas/reservation.json +118 -0
  125. package/dist/cjs/schemas/room.json +98 -0
  126. package/dist/cjs/schemas/scene.json +121 -0
  127. package/dist/cjs/schemas/shortLink.json +30 -0
  128. package/dist/cjs/schemas/smsMessage.json +61 -0
  129. package/dist/cjs/schemas/space.json +120 -0
  130. package/dist/cjs/schemas/spaceType.json +30 -0
  131. package/dist/cjs/schemas/switch.json +42 -0
  132. package/dist/cjs/schemas/systemUser.json +95 -0
  133. package/dist/cjs/schemas/thermostat.json +153 -0
  134. package/dist/cjs/schemas/ticket.json +96 -0
  135. package/dist/cjs/schemas/user.json +152 -0
  136. package/dist/cjs/schemas/windowCovering.json +43 -0
  137. package/dist/cjs/utils/errorFactory.js +8 -0
  138. package/dist/cjs/utils/eventFactory.js +10 -0
  139. package/dist/cjs/utils/getDeviceTypes.js +7 -0
  140. package/dist/cjs/utils/getFormalDeviceType.js +5 -0
  141. package/dist/cjs/utils/index.js +11 -0
  142. package/dist/cjs/utils/schema.js +25 -0
  143. package/dist/esm/Models.js +451 -435
  144. package/dist/esm/Models.js.map +4 -4
  145. package/dist/esm/utils.js +7 -26
  146. package/dist/esm/utils.js.map +3 -3
  147. package/package.json +12 -7
  148. package/dist/cjs/AMQPClient.js +0 -462
  149. package/dist/cjs/Commands.js +0 -973
  150. package/dist/cjs/Errors.js +0 -209
  151. package/dist/cjs/Events.js +0 -578
  152. package/dist/cjs/Models.js +0 -4905
  153. package/dist/cjs/defs.js +0 -167
  154. package/dist/cjs/index.cjs.js +0 -6755
  155. package/dist/cjs/utils.js +0 -525
  156. /package/dist/cjs/{Client.js → Client/index.js} +0 -0
@@ -0,0 +1,290 @@
1
+ const Errors = require("../Errors");
2
+ const amqp = require("amqplib");
3
+ const crypto = require("crypto");
4
+ const isFatalError = require("amqplib/lib/connection").isFatalError;
5
+ const debug = require("debug")("kohost:amqp-client");
6
+
7
+ const HEADER_KEY_ORGANIZATION_ID = "X-Organization-Id";
8
+ const HEADER_KEY_PROPERTY_ID = "X-Property-Id";
9
+ const HEADER_KEY_DRIVER = "X-Driver";
10
+ const HEADER_KEY_COMMAND_NAME = "X-Command-Name";
11
+ const HEADER_KEY_EVENT_NAME = "X-Event-Name";
12
+
13
+ const exchanges = {
14
+ // routes commands based on `command-name` header and in many cases `property-id` header
15
+ Commands: {
16
+ name: "kohost.commands",
17
+ type: "headers",
18
+ options: {
19
+ durable: true,
20
+ },
21
+ },
22
+ // routes events based on routing keys
23
+ Events: {
24
+ name: "kohost.events",
25
+ type: "topic",
26
+ options: {
27
+ durable: true,
28
+ },
29
+ },
30
+ Direct: {
31
+ name: "kohost.direct",
32
+ type: "direct",
33
+ options: {
34
+ durable: true,
35
+ },
36
+ },
37
+ Replies: {
38
+ name: "kohost.replies",
39
+ type: "topic",
40
+ options: {
41
+ durable: true,
42
+ },
43
+ },
44
+ // dead letter exchange
45
+ dlx: {
46
+ name: "kohost.dlx",
47
+ type: "direct",
48
+ },
49
+ };
50
+
51
+ class KohostAMQPClient {
52
+ static get Message() {
53
+ return Message;
54
+ }
55
+
56
+ static get exchanges() {
57
+ return exchanges;
58
+ }
59
+ static generateCorrelationId() {
60
+ return crypto.randomUUID();
61
+ }
62
+
63
+ static validateMessage(message) {
64
+ if (!message) throw new Error("Message is required");
65
+ }
66
+
67
+ static parseError(err) {
68
+ let type;
69
+ let message;
70
+ let options = {};
71
+ if (err.message && err.type) {
72
+ const { message: errMessage, type: errType, ...rest } = err;
73
+ type = errType;
74
+ message = errMessage;
75
+ options = rest;
76
+ } else {
77
+ message = "Unknown Error";
78
+ }
79
+
80
+ debug("parseError", type, message, options);
81
+
82
+ switch (type) {
83
+ case "RequestError":
84
+ return new Errors.RequestError(message, options);
85
+
86
+ case "AuthenticationError":
87
+ return new Errors.AuthenticationError(message, options);
88
+
89
+ case "ValidationError":
90
+ return new Errors.ValidationError(message, options);
91
+
92
+ case "NotFoundError":
93
+ return new Errors.NotFoundError(message, options);
94
+
95
+ case "UnprocessableRequestError":
96
+ return new Errors.UnprocessableRequestError(message, options);
97
+
98
+ default:
99
+ return new Error(message, options);
100
+ }
101
+ }
102
+
103
+ static parseMessage(message) {
104
+ debug("parseMessage input %o", message);
105
+
106
+ let error = null;
107
+ let data = {};
108
+ let query = {};
109
+ let context = {};
110
+ let headers = {};
111
+
112
+ const isCommand = message?.properties?.type === "Command";
113
+ const isEvent = message?.properties?.type === "Event";
114
+
115
+ const messageHeaders = message?.properties?.headers || {};
116
+
117
+ const commandName = messageHeaders[HEADER_KEY_COMMAND_NAME] || null;
118
+ const eventName = messageHeaders[HEADER_KEY_EVENT_NAME] || null;
119
+
120
+ if (message.content) {
121
+ try {
122
+ const payload =
123
+ message.properties?.contentType === "application/json"
124
+ ? JSON.parse(message.content.toString())
125
+ : message.content.toString();
126
+ data = payload?.data || {};
127
+ error = payload?.error;
128
+ query = payload?.query || {};
129
+ context = payload?.context || {};
130
+ } catch (error) {
131
+ data = message.content.toString();
132
+ }
133
+ }
134
+
135
+ if (message?.properties?.headers) {
136
+ const orgHeader = message.properties.headers[HEADER_KEY_ORGANIZATION_ID];
137
+ const propertyHeader = message.properties.headers[HEADER_KEY_PROPERTY_ID];
138
+ const driverHeader = message.properties.headers[HEADER_KEY_DRIVER];
139
+
140
+ if (orgHeader) {
141
+ context.organizationId = orgHeader;
142
+ headers[HEADER_KEY_ORGANIZATION_ID] = orgHeader;
143
+ }
144
+
145
+ if (propertyHeader) {
146
+ context.propertyId = propertyHeader;
147
+ headers[HEADER_KEY_PROPERTY_ID] = propertyHeader;
148
+ }
149
+
150
+ if (driverHeader) {
151
+ context.driver = driverHeader;
152
+ headers[HEADER_KEY_DRIVER] = driverHeader;
153
+ }
154
+ }
155
+
156
+ const parsed = {};
157
+
158
+ if (error) parsed.error = this.parseError(error);
159
+
160
+ parsed.data = data;
161
+ parsed.query = query;
162
+ parsed.context = context;
163
+ parsed.headers = headers;
164
+
165
+ if (isEvent && eventName) parsed.event = eventName;
166
+ else if (isCommand && commandName) parsed.command = commandName;
167
+
168
+ debug("parseMessage parsed %o", parsed);
169
+
170
+ return parsed;
171
+ }
172
+
173
+ static getMessage(message) {
174
+ if (!message?.content) return null;
175
+ const payload = JSON.parse(message.content.toString());
176
+ const data = payload?.data;
177
+ return data;
178
+ }
179
+
180
+ static isFatalError(err) {
181
+ return isFatalError(err);
182
+ }
183
+
184
+ async createConnection(connection, options = {}) {
185
+ return await amqp.connect(connection, options);
186
+ }
187
+
188
+ static createMessage(content) {
189
+ return new Message(content);
190
+ }
191
+
192
+ async createChannel(connection) {
193
+ const channel = await connection.createChannel();
194
+ return channel;
195
+ }
196
+
197
+ async assertExchange(channel, { exchange, type, options }) {
198
+ return await channel.assertExchange(exchange, type, options);
199
+ }
200
+
201
+ async assertQueue(channel, { queue, options }) {
202
+ return await channel.assertQueue(queue, options);
203
+ }
204
+
205
+ async bindQueue(channel, { queue, exchange, routingKey, args }) {
206
+ return await channel.bindQueue(queue, exchange, routingKey, args);
207
+ }
208
+
209
+ async bindExchange(channel, { source, destination, routingKey, args }) {
210
+ return await channel.bindExchange(destination, source, routingKey, args);
211
+ }
212
+
213
+ async subscribeToQueue(channel, { queue, cb, options }) {
214
+ return await channel.consume(queue, cb, options);
215
+ }
216
+
217
+ publishToExchange(channel, { exchange, routingKey, content, options }) {
218
+ return channel.publish(exchange, routingKey, content, options);
219
+ }
220
+ }
221
+
222
+ class Message {
223
+ constructor(content) {
224
+ this.toExchange = null;
225
+ this.content = content;
226
+ this.options = {
227
+ contentType: "application/json",
228
+ };
229
+ this.routingKey = "";
230
+ }
231
+
232
+ get correlationId() {
233
+ return this.options.correlationId || null;
234
+ }
235
+
236
+ to({ exchange }) {
237
+ if (typeof exchange === "undefined")
238
+ throw new Error("Exchange is required");
239
+ this.toExchange = exchange;
240
+ return this;
241
+ }
242
+
243
+ withType(type) {
244
+ this.options.type = type;
245
+ return this;
246
+ }
247
+
248
+ withRoutingKey(routingKey) {
249
+ this.routingKey = routingKey;
250
+ return this;
251
+ }
252
+
253
+ withHeaders(headers) {
254
+ if (!this.options.headers) this.options.headers = {};
255
+ this.options.headers = { ...this.options.headers, ...headers };
256
+ return this;
257
+ }
258
+
259
+ withContext(context) {
260
+ for (let key in context) {
261
+ this.withHeaders({ [key]: context[key] });
262
+ }
263
+ return this;
264
+ }
265
+
266
+ withCorrelationId(correlationId) {
267
+ this.options.correlationId = correlationId;
268
+ return this;
269
+ }
270
+
271
+ withReplyTo(queue) {
272
+ this.options.replyTo = queue;
273
+ return this;
274
+ }
275
+
276
+ build() {
277
+ let content = this.content;
278
+ if (content.build && typeof content.build === "function")
279
+ content = content.build();
280
+
281
+ return {
282
+ exchange: this.toExchange,
283
+ content: Buffer.from(JSON.stringify(content)),
284
+ options: this.options,
285
+ routingKey: this.routingKey,
286
+ };
287
+ }
288
+ }
289
+
290
+ module.exports = KohostAMQPClient;
@@ -0,0 +1,19 @@
1
+ const Command = require("./Command");
2
+ const RequestError = require("../Errors/RequestError");
3
+
4
+ class CheckInReservationCommand extends Command {
5
+ constructor({ id }) {
6
+ if (!id) throw new RequestError("document type is required");
7
+ super({ id });
8
+ }
9
+
10
+ get name() {
11
+ return "CheckInReservation";
12
+ }
13
+
14
+ get routingKey() {
15
+ return `reservation.${this.data.id}.checkin`;
16
+ }
17
+ }
18
+
19
+ module.exports = CheckInReservationCommand;
@@ -0,0 +1,34 @@
1
+ class Command {
2
+ constructor(data) {
3
+ this.data = {};
4
+ if (!data) throw new Error("Command data is required");
5
+ if (typeof data !== "object")
6
+ throw new Error("Command data must be an object");
7
+
8
+ for (const key in data) {
9
+ this.data[key] = data[key];
10
+ }
11
+ }
12
+
13
+ get name() {
14
+ throw new Error("Command name is required");
15
+ }
16
+
17
+ get type() {
18
+ return "Command";
19
+ }
20
+
21
+ get routingKey() {
22
+ return "";
23
+ }
24
+
25
+ get exchange() {
26
+ return "Commands";
27
+ }
28
+
29
+ build() {
30
+ return { data: { ...this.data } };
31
+ }
32
+ }
33
+
34
+ module.exports = Command;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class CreateImageUploadEndpointCommand extends Command {
4
+ constructor({ id, expires, ...rest }) {
5
+ super({ id, expires, ...rest });
6
+ }
7
+
8
+ get name() {
9
+ return "CreateImageUploadEndpoint";
10
+ }
11
+
12
+ get routingKey() {
13
+ return "image.createUploadEndpoint";
14
+ }
15
+ }
16
+
17
+ module.exports = CreateImageUploadEndpointCommand;
@@ -0,0 +1,20 @@
1
+ const Command = require("./Command");
2
+ const RequestError = require("../Errors/RequestError");
3
+
4
+ class CreateShortLinkCommand extends Command {
5
+ constructor({ title, destination }) {
6
+ if (!title) throw new RequestError("title is required");
7
+ if (!destination) throw new RequestError("destination to is required");
8
+ super({ title, destination });
9
+ }
10
+
11
+ get name() {
12
+ return "CreateShortLink";
13
+ }
14
+
15
+ get routingKey() {
16
+ return "comm.shortlink.create";
17
+ }
18
+ }
19
+
20
+ module.exports = CreateShortLinkCommand;
@@ -0,0 +1,20 @@
1
+ const { RequestError } = require("../Errors");
2
+ const Command = require("./Command");
3
+
4
+ class DiscoverReservationRoomTypeUpsellOptionsCommand extends Command {
5
+ constructor(options) {
6
+ if (!options) throw new RequestError("options are required");
7
+ const { id, ...rest } = options;
8
+ super({ id, ...rest });
9
+ }
10
+
11
+ get name() {
12
+ return "DiscoverReservationRoomTypeUpsellOptions";
13
+ }
14
+
15
+ get routingKey() {
16
+ return "reservation.discoverRoomUpsells";
17
+ }
18
+ }
19
+
20
+ module.exports = DiscoverReservationRoomTypeUpsellOptionsCommand;
@@ -0,0 +1,20 @@
1
+ const { RequestError } = require("../Errors");
2
+ const Command = require("./Command");
3
+
4
+ class DiscoverReservationsCommand extends Command {
5
+ constructor(options) {
6
+ if (!options) throw new RequestError("options are required");
7
+ const { id, startDate, endDate, status, ...rest } = options;
8
+ super({ id, startDate, endDate, status, ...rest });
9
+ }
10
+
11
+ get name() {
12
+ return "DiscoverReservations";
13
+ }
14
+
15
+ get routingKey() {
16
+ return "reservation.discover";
17
+ }
18
+ }
19
+
20
+ module.exports = DiscoverReservationsCommand;
@@ -0,0 +1,19 @@
1
+ const Command = require("./Command");
2
+
3
+ class DiscoverRoomTypesCommand extends Command {
4
+ constructor({ id }) {
5
+ super({ id });
6
+ }
7
+
8
+ get name() {
9
+ return "DiscoverRoomTypes";
10
+ }
11
+
12
+ get routingKey() {
13
+ if (typeof this.data.id === "string") return `rooms.${this.data.id}.get`;
14
+ if (Array.isArray(this.data.id)) return "rooms.batch.get";
15
+ return "rooms.get";
16
+ }
17
+ }
18
+
19
+ module.exports = DiscoverRoomTypesCommand;
@@ -0,0 +1,35 @@
1
+ const Command = require("./Command");
2
+
3
+ class DiscoverRoomsCommand extends Command {
4
+ constructor({
5
+ id,
6
+ types,
7
+ startDate,
8
+ endDate,
9
+ serviceStatus,
10
+ housekeepingStatus,
11
+ ...rest
12
+ }) {
13
+ super({
14
+ id,
15
+ types,
16
+ startDate,
17
+ endDate,
18
+ serviceStatus,
19
+ housekeepingStatus,
20
+ ...rest,
21
+ });
22
+ }
23
+
24
+ get name() {
25
+ return "DiscoverRooms";
26
+ }
27
+
28
+ get routingKey() {
29
+ if (typeof this.data.id === "string") return `rooms.${this.data.id}.get`;
30
+ if (Array.isArray(this.data.id)) return "rooms.batch.get";
31
+ return "rooms.get";
32
+ }
33
+ }
34
+
35
+ module.exports = DiscoverRoomsCommand;
@@ -0,0 +1,19 @@
1
+ const Command = require("./Command");
2
+
3
+ class DiscoverUsersCommand extends Command {
4
+ constructor({ id }) {
5
+ super({ id });
6
+ }
7
+
8
+ get name() {
9
+ return "DiscoverUsers";
10
+ }
11
+
12
+ get routingKey() {
13
+ if (typeof this.data.id === "string") return `users.${this.data.id}.get`;
14
+ if (Array.isArray(this.data.id)) return "users.batch.get";
15
+ return "users.get";
16
+ }
17
+ }
18
+
19
+ module.exports = DiscoverUsersCommand;
@@ -0,0 +1,24 @@
1
+ const Command = require("./Command");
2
+
3
+ class GetMobileKeyCommand extends Command {
4
+ constructor({
5
+ id,
6
+ phone,
7
+ beginDateTime,
8
+ endDateTime,
9
+ keyToReplace,
10
+ ...rest
11
+ }) {
12
+ super({ id, phone, beginDateTime, endDateTime, keyToReplace, ...rest });
13
+ }
14
+
15
+ get name() {
16
+ return "GetMobileKey";
17
+ }
18
+
19
+ get routingKey() {
20
+ return `lock.${this.data.id}.set`;
21
+ }
22
+ }
23
+
24
+ module.exports = GetMobileKeyCommand;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class GetProductsCommand extends Command {
4
+ constructor({ id, externalSystemId, ...rest }) {
5
+ super({ id, externalSystemId, ...rest });
6
+ }
7
+
8
+ get name() {
9
+ return "GetProducts";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `product.${this.data.id}.get`;
14
+ }
15
+ }
16
+
17
+ module.exports = GetProductsCommand;
@@ -0,0 +1,15 @@
1
+ const Command = require("./Command");
2
+ const RequestError = require("../Errors/RequestError");
3
+
4
+ class OCRDocumentCommand extends Command {
5
+ constructor({ type, image }) {
6
+ if (!image) throw new RequestError("document image is required");
7
+ super({ type, image });
8
+ }
9
+
10
+ get name() {
11
+ return "OCRDocument";
12
+ }
13
+ }
14
+
15
+ module.exports = OCRDocumentCommand;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class SellProductsCommand extends Command {
4
+ constructor({ reservationId, userId, products, ...rest }) {
5
+ super({ reservationId, userId, products, ...rest });
6
+ }
7
+
8
+ get name() {
9
+ return "SellProducts";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `product.${this.data.id}.sell`;
14
+ }
15
+ }
16
+
17
+ module.exports = SellProductsCommand;
@@ -0,0 +1,24 @@
1
+ const Command = require("./Command");
2
+ const RequestError = require("../Errors/RequestError");
3
+
4
+ class SendEmailCommand extends Command {
5
+ constructor({ text, html, to, from, subject, ...rest }) {
6
+ if (!to) throw new RequestError("email to is required");
7
+ if (!from) throw new RequestError("email from is required");
8
+ if (!subject) throw new RequestError("email subject is required");
9
+ if (!text && !html)
10
+ throw new RequestError("email text or html is required");
11
+
12
+ super({ text, html, to, from, subject, ...rest });
13
+ }
14
+
15
+ get name() {
16
+ return "SendEmail";
17
+ }
18
+
19
+ get routingKey() {
20
+ return "comm.email.send";
21
+ }
22
+ }
23
+
24
+ module.exports = SendEmailCommand;
@@ -0,0 +1,21 @@
1
+ const Command = require("./Command");
2
+ const RequestError = require("../Errors/RequestError");
3
+
4
+ class SendSMSCommand extends Command {
5
+ constructor({ id, body, to, from, ...rest }) {
6
+ if (!body) throw new RequestError("sms body is required");
7
+ if (!to) throw new RequestError("sms to is required");
8
+ if (!from) throw new RequestError("sms from is required");
9
+ super({ id, body, to, from, ...rest });
10
+ }
11
+
12
+ get name() {
13
+ return "SendSMS";
14
+ }
15
+
16
+ get routingKey() {
17
+ return "comm.sms.send";
18
+ }
19
+ }
20
+
21
+ module.exports = SendSMSCommand;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class SetAlarmCommand extends Command {
4
+ constructor({ id, zones, areas }) {
5
+ super({ id, zones, areas });
6
+ }
7
+
8
+ get name() {
9
+ return "SetAlarm";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `alarm.${this.data.id}.set`;
14
+ }
15
+ }
16
+
17
+ module.exports = SetAlarmCommand;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class SetCourtesyCommand extends Command {
4
+ constructor({ id, state }) {
5
+ super({ id, state });
6
+ }
7
+
8
+ get name() {
9
+ return "SetCourtesy";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `courtesy.${this.data.id}.set`;
14
+ }
15
+ }
16
+
17
+ module.exports = SetCourtesyCommand;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class SetDimmerCommand extends Command {
4
+ constructor({ id, level }) {
5
+ super({ id, level });
6
+ }
7
+
8
+ get name() {
9
+ return "SetDimmer";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `dimmer.${this.data.id}.set`;
14
+ }
15
+ }
16
+
17
+ module.exports = SetDimmerCommand;
@@ -0,0 +1,17 @@
1
+ const Command = require("./Command");
2
+
3
+ class SetLockCommand extends Command {
4
+ constructor({ id, state }) {
5
+ super({ id, state });
6
+ }
7
+
8
+ get name() {
9
+ return "SetLock";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `lock.${this.data.id}.set`;
14
+ }
15
+ }
16
+
17
+ module.exports = SetLockCommand;