@kohost/api-client 3.0.0-beta.8 → 3.0.0-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -0
- package/dist/cjs/AMQPClient/index.js +296 -0
- package/dist/cjs/{Client.js → Client/index.js} +1535 -586
- package/dist/cjs/Commands/CheckInReservationCommand.js +19 -0
- package/dist/cjs/Commands/Command.js +34 -0
- package/dist/cjs/Commands/CreateImageUploadEndpointCommand.js +17 -0
- package/dist/cjs/Commands/CreateShortLinkCommand.js +20 -0
- package/dist/cjs/Commands/DiscoverCategoriesCommand.js +20 -0
- package/dist/cjs/Commands/DiscoverReservationSpaceCategoryAvailabilitiesCommand.js +20 -0
- package/dist/cjs/Commands/DiscoverReservationsCommand.js +20 -0
- package/dist/cjs/Commands/DiscoverRoomsCommand.js +37 -0
- package/dist/cjs/Commands/DiscoverUsersCommand.js +19 -0
- package/dist/cjs/Commands/GetMobileKeyCommand.js +24 -0
- package/dist/cjs/Commands/GetProductsCommand.js +17 -0
- package/dist/cjs/Commands/OCRDocumentCommand.js +15 -0
- package/dist/cjs/Commands/SellProductsCommand.js +17 -0
- package/dist/cjs/Commands/SendEmailCommand.js +24 -0
- package/dist/cjs/Commands/SendSMSCommand.js +21 -0
- package/dist/cjs/Commands/SetAlarmCommand.js +17 -0
- package/dist/cjs/Commands/SetCourtesyCommand.js +17 -0
- package/dist/cjs/Commands/SetDimmerCommand.js +17 -0
- package/dist/cjs/Commands/SetLockCommand.js +17 -0
- package/dist/cjs/Commands/SetMediaCommand.js +17 -0
- package/dist/cjs/Commands/SetSceneCommand.js +17 -0
- package/dist/cjs/Commands/SetSwitchCommand.js +17 -0
- package/dist/cjs/Commands/SetThermostatCommand.js +17 -0
- package/dist/cjs/Commands/SetWindowCoveringCommand.js +17 -0
- package/dist/cjs/Commands/UpdateReservationCommand.js +19 -0
- package/dist/cjs/Commands/UpdateUserCommand.js +41 -0
- package/dist/cjs/Commands/UploadImageCommand.js +17 -0
- package/dist/cjs/Commands/index.js +55 -0
- package/dist/cjs/Errors/AppError.js +8 -0
- package/dist/cjs/Errors/AuthenticationError.js +9 -0
- package/dist/cjs/Errors/AuthorizationError.js +9 -0
- package/dist/cjs/Errors/ConflictError.js +9 -0
- package/dist/cjs/Errors/DeviceCommError.js +9 -0
- package/dist/cjs/Errors/LoginError.js +9 -0
- package/dist/cjs/Errors/NotFoundError.js +9 -0
- package/dist/cjs/Errors/RequestError.js +9 -0
- package/dist/cjs/Errors/SystemCommError.js +9 -0
- package/dist/cjs/Errors/TokenExpiredError.js +9 -0
- package/dist/cjs/Errors/UnprocessableRequestError.js +9 -0
- package/dist/cjs/Errors/ValidationError.js +9 -0
- package/dist/cjs/Errors/index.js +16 -0
- package/dist/cjs/Events/ApplicationInUseEvent.js +21 -0
- package/dist/cjs/Events/ApplicationOutOfUseEvent.js +21 -0
- package/dist/cjs/Events/EmailEvent.js +18 -0
- package/dist/cjs/Events/Event.js +55 -0
- package/dist/cjs/Events/SMSEvent.js +18 -0
- package/dist/cjs/Events/SMSSentEvent.js +17 -0
- package/dist/cjs/Events/SceneSetEvent.js +17 -0
- package/dist/cjs/Events/ShortLinkCreatedEvent.js +17 -0
- package/dist/cjs/Events/SystemAlarmUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemCameraUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemCategoryUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemCourtesyUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemCredentialUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemDimmerUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemEntityDeletedEvent.js +17 -0
- package/dist/cjs/Events/SystemGatewayUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemLockUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemMediaSourceUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemMotionSensorUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemOrganizationUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemProductUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemPropertyUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemReservationUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemSceneControllerUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemSpaceUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemSwitchUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemThermostatUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemUserUpdatedEvent.js +17 -0
- package/dist/cjs/Events/SystemWindowCoveringUpdatedEvent.js +17 -0
- package/dist/cjs/Events/index.js +65 -0
- package/dist/cjs/Models/Alarm.js +35 -0
- package/dist/cjs/Models/Camera.js +35 -0
- package/dist/cjs/Models/Category.js +36 -0
- package/dist/cjs/Models/Courtesy.js +39 -0
- package/dist/cjs/Models/Credential.js +35 -0
- package/dist/cjs/Models/Dimmer.js +61 -0
- package/dist/cjs/Models/DiscoveredDevice.js +36 -0
- package/dist/cjs/Models/EmailMessage.js +35 -0
- package/dist/cjs/Models/EnergyReport.js +35 -0
- package/dist/cjs/Models/EnergyReportShard.js +35 -0
- package/dist/cjs/Models/Gateway.js +35 -0
- package/dist/cjs/Models/Identification.js +38 -0
- package/dist/cjs/Models/Kohost.js +96 -0
- package/dist/cjs/Models/Lock.js +39 -0
- package/dist/cjs/Models/MediaFile.js +48 -0
- package/dist/cjs/Models/MediaSource.js +35 -0
- package/dist/cjs/Models/MotionSensor.js +35 -0
- package/dist/cjs/Models/Notification.js +34 -0
- package/dist/cjs/Models/Order.js +97 -0
- package/dist/cjs/Models/Organization.js +34 -0
- package/dist/cjs/Models/Product.js +35 -0
- package/dist/cjs/Models/Property.js +34 -0
- package/dist/cjs/Models/Reservation.js +114 -0
- package/dist/cjs/Models/Room.js +218 -0
- package/dist/cjs/Models/Scene.js +169 -0
- package/dist/cjs/Models/ShortLink.js +35 -0
- package/dist/cjs/Models/SmsMessage.js +35 -0
- package/dist/cjs/Models/Space.js +97 -0
- package/dist/cjs/Models/Switch.js +39 -0
- package/dist/cjs/Models/SystemUser.js +55 -0
- package/dist/cjs/Models/Thermostat.js +86 -0
- package/dist/cjs/Models/Ticket.js +112 -0
- package/dist/cjs/Models/User.js +115 -0
- package/dist/cjs/Models/WindowCovering.js +55 -0
- package/dist/cjs/Models/index.js +72 -0
- package/dist/cjs/SocketIoClient/index.js +74 -0
- package/dist/cjs/defs/deviceTypes.js +15 -0
- package/dist/cjs/defs/formalDeviceTypes.js +6 -0
- package/dist/cjs/defs/index.js +11 -0
- package/dist/cjs/{index.cjs.js → index.js} +7 -1
- package/dist/cjs/schemas/AlarmSchema.d.ts +152 -0
- package/dist/cjs/schemas/CameraSchema.d.ts +143 -0
- package/dist/cjs/schemas/CategorySchema.d.ts +82 -0
- package/dist/cjs/schemas/CourtesySchema.d.ts +142 -0
- package/dist/cjs/schemas/CredentialSchema.d.ts +52 -0
- package/dist/cjs/schemas/DefinitionsSchema.d.ts +10 -0
- package/dist/cjs/schemas/DimmerSchema.d.ts +142 -0
- package/dist/cjs/schemas/DiscoveredDeviceSchema.d.ts +39 -0
- package/dist/cjs/schemas/EmailMessageSchema.d.ts +49 -0
- package/dist/cjs/schemas/EnergyReportSchema.d.ts +57 -0
- package/dist/cjs/schemas/EnergyReportShardSchema.d.ts +61 -0
- package/dist/cjs/schemas/GatewaySchema.d.ts +139 -0
- package/dist/cjs/schemas/IdentificationSchema.d.ts +45 -0
- package/dist/cjs/schemas/LockSchema.d.ts +142 -0
- package/dist/cjs/schemas/MediaFileSchema.d.ts +43 -0
- package/dist/cjs/schemas/MediaSourceSchema.d.ts +238 -0
- package/dist/cjs/schemas/MotionSensorSchema.d.ts +137 -0
- package/dist/cjs/schemas/NotificationSchema.d.ts +54 -0
- package/dist/cjs/schemas/OrderSchema.d.ts +91 -0
- package/dist/cjs/schemas/OrganizationSchema.d.ts +34 -0
- package/dist/cjs/schemas/PaymentSchema.d.ts +33 -0
- package/dist/cjs/schemas/ProductSchema.d.ts +66 -0
- package/dist/cjs/schemas/PropertySchema.d.ts +144 -0
- package/dist/cjs/schemas/ReservationSchema.d.ts +118 -0
- package/dist/cjs/schemas/RoomSchema.d.ts +1076 -0
- package/dist/cjs/schemas/SceneSchema.d.ts +57 -0
- package/dist/cjs/schemas/ShortLinkSchema.d.ts +20 -0
- package/dist/cjs/schemas/SmsMessageSchema.d.ts +40 -0
- package/dist/cjs/schemas/SpaceSchema.d.ts +69 -0
- package/dist/cjs/schemas/SwitchSchema.d.ts +142 -0
- package/dist/cjs/schemas/SystemUserSchema.d.ts +193 -0
- package/dist/cjs/schemas/ThermostatSchema.d.ts +172 -0
- package/dist/cjs/schemas/TicketSchema.d.ts +88 -0
- package/dist/cjs/schemas/UserSchema.d.ts +286 -0
- package/dist/cjs/schemas/WindowCoveringSchema.d.ts +141 -0
- package/dist/cjs/schemas/alarm.json +81 -0
- package/dist/cjs/schemas/camera.json +50 -0
- package/dist/cjs/schemas/category.json +42 -0
- package/dist/cjs/schemas/courtesy.json +48 -0
- package/dist/cjs/schemas/credential.json +44 -0
- package/dist/cjs/schemas/definitions.json +218 -0
- package/dist/cjs/schemas/dimmer.json +45 -0
- package/dist/cjs/schemas/discoveredDevice.json +31 -0
- package/dist/cjs/schemas/emailMessage.json +71 -0
- package/dist/cjs/schemas/energyReport.json +86 -0
- package/dist/cjs/schemas/energyReportShard.json +75 -0
- package/dist/cjs/schemas/gateway.json +34 -0
- package/dist/cjs/schemas/identification.json +61 -0
- package/dist/cjs/schemas/lock.json +44 -0
- package/dist/cjs/schemas/mediaFile.json +70 -0
- package/dist/cjs/schemas/mediaSource.json +187 -0
- package/dist/cjs/schemas/motionSensor.json +32 -0
- package/dist/cjs/schemas/notification.json +29 -0
- package/dist/cjs/schemas/order.json +182 -0
- package/dist/cjs/schemas/organization.json +40 -0
- package/dist/cjs/schemas/payment.json +47 -0
- package/dist/cjs/schemas/product.json +41 -0
- package/dist/cjs/schemas/property.json +347 -0
- package/dist/cjs/schemas/reservation.json +137 -0
- package/dist/cjs/schemas/room.json +98 -0
- package/dist/cjs/schemas/scene.json +121 -0
- package/dist/cjs/schemas/shortLink.json +30 -0
- package/dist/cjs/schemas/smsMessage.json +61 -0
- package/dist/cjs/schemas/space.json +129 -0
- package/dist/cjs/schemas/switch.json +44 -0
- package/dist/cjs/schemas/systemUser.json +98 -0
- package/dist/cjs/schemas/thermostat.json +150 -0
- package/dist/cjs/schemas/ticket.json +141 -0
- package/dist/cjs/schemas/user.json +170 -0
- package/dist/cjs/schemas/windowCovering.json +42 -0
- package/dist/cjs/utils/errorFactory.js +8 -0
- package/dist/cjs/utils/eventFactory.js +10 -0
- package/dist/cjs/utils/getDeviceTypes.js +7 -0
- package/dist/cjs/utils/getFormalDeviceType.js +5 -0
- package/dist/cjs/utils/index.js +11 -0
- package/dist/cjs/utils/schema.js +25 -0
- package/dist/esm/Client.js +1632 -627
- package/dist/esm/Client.js.map +4 -4
- package/dist/esm/Commands.js +493 -116
- package/dist/esm/Commands.js.map +3 -3
- package/dist/esm/Errors.js +73 -22
- package/dist/esm/Errors.js.map +3 -3
- package/dist/esm/Events.js +414 -73
- package/dist/esm/Events.js.map +3 -3
- package/dist/esm/Models.js +3418 -1271
- package/dist/esm/Models.js.map +4 -4
- package/dist/esm/SocketIoClient.js +4846 -0
- package/dist/esm/SocketIoClient.js.map +7 -0
- package/dist/esm/defs.js +146 -101
- package/dist/esm/defs.js.map +4 -4
- package/dist/esm/index.js +17 -10
- package/dist/esm/utils.js +446 -73
- package/dist/esm/utils.js.map +3 -3
- package/dist/useCases/AdminUpdateCustomer.js +1 -1
- package/dist/useCases/AssignSpaceToReservation.js +32 -0
- package/dist/useCases/{AdminCreateProperty.js → BatchNotifyCheckIn.js} +2 -2
- package/dist/useCases/{AdminCreateCustomer.js → CreateCateory.js} +2 -2
- package/dist/useCases/CreateImageUploadEndpoint.js +32 -0
- package/dist/useCases/{DeleteIntegration.js → CreateMediaSource.js} +4 -4
- package/dist/useCases/{AdminListCustomers.js → CreateOrganization.js} +3 -3
- package/dist/useCases/{AdminLoginUser.js → CreateProperty.js} +2 -2
- package/dist/useCases/DeleteCategory.js +32 -0
- package/dist/useCases/DeleteMediaFile.js +32 -0
- package/dist/useCases/DeleteMediaSource.js +32 -0
- package/dist/useCases/{ListIntegrations.js → DescribeCategory.js} +3 -3
- package/dist/useCases/{DeleteSource.js → DescribeLockCredential.js} +3 -3
- package/dist/useCases/{AdminListAdminUsers.js → DescribeMediaSource.js} +3 -3
- package/dist/useCases/DescribeMyAccessCredentials.js +32 -0
- package/dist/useCases/{AdminCreateAdminUser.js → DescribeOrganization.js} +4 -4
- package/dist/useCases/{DescribeIntegration.js → DescribeProduct.js} +2 -2
- package/dist/useCases/{AdminDescribeCustomer.js → DescribeProperty.js} +2 -2
- package/dist/useCases/DescribeReservationEarlyCheckInProducts.js +32 -0
- package/dist/useCases/DescribeReservationLateCheckOutProducts.js +32 -0
- package/dist/useCases/{AdminDescribeProperty.js → DescribeReservationRoomUpgrades.js} +2 -2
- package/dist/useCases/ListCategories.js +32 -0
- package/dist/useCases/ListMediaSources.js +32 -0
- package/dist/useCases/{CreateSource.js → ListMyOrders.js} +4 -4
- package/dist/useCases/{AdminListProperties.js → ListMyTickets.js} +2 -2
- package/dist/useCases/ListOrders.js +32 -0
- package/dist/useCases/{AdminRefreshToken.js → ListOrganizations.js} +3 -3
- package/dist/useCases/ListProperties.js +32 -0
- package/dist/useCases/ListScenes.js +32 -0
- package/dist/useCases/ListTeam.js +32 -0
- package/dist/useCases/ListUserOrders.js +32 -0
- package/dist/useCases/ListUserSpaces.js +32 -0
- package/dist/useCases/LogoutUser.js +32 -0
- package/dist/useCases/PurchaseReservationEarlyCheckInProducts.js +32 -0
- package/dist/useCases/PurchaseReservationLateCheckOutProducts.js +32 -0
- package/dist/useCases/{CreateIntegrationDeviceMapEntry.js → PurchaseReservationRoomUpgrades.js} +2 -2
- package/dist/useCases/RequestLoginLink.js +1 -1
- package/dist/useCases/{CreateIntegration.js → RequestMyKeyToken.js} +2 -2
- package/dist/useCases/RequestPWAToken.js +32 -0
- package/dist/useCases/SendCheckInSMS.js +32 -0
- package/dist/useCases/{SetSource.js → SetDimmer.js} +2 -2
- package/dist/useCases/{DescribeSource.js → SetMediaSource.js} +3 -3
- package/dist/useCases/{UpdateSource.js → SetRoomScene.js} +3 -3
- package/dist/useCases/SetSpaceScene.js +32 -0
- package/dist/useCases/TipUser.js +32 -0
- package/dist/useCases/{AdminUpdateProperty.js → UpdateCategory.js} +2 -2
- package/dist/useCases/{UpdateIntegration.js → UpdateMediaSource.js} +3 -3
- package/dist/useCases/UpdateProperty.js +32 -0
- package/dist/useCases/UpdateReservationExpectedArrivalTime.js +32 -0
- package/dist/useCases/{ListSources.js → UploadImage.js} +4 -4
- package/package.json +36 -10
- package/dist/cjs/Commands.js +0 -616
- package/dist/cjs/Errors.js +0 -176
- package/dist/cjs/Events.js +0 -387
- package/dist/cjs/Models.js +0 -3612
- package/dist/cjs/defs.js +0 -178
- package/dist/cjs/utils.js +0 -250
- package/dist/useCases/AdminRequestLoginLink.js +0 -32
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Create the User Model
|
|
2
|
+
const schemas = require("../utils/schema");
|
|
3
|
+
const schema = require("../schemas/user.json");
|
|
4
|
+
const paymentSchema = require("../schemas/payment.json");
|
|
5
|
+
const Kohost = require("./Kohost");
|
|
6
|
+
const MediaFile = require("./MediaFile");
|
|
7
|
+
const Reservation = require("./Reservation");
|
|
8
|
+
const Identification = require("./Identification");
|
|
9
|
+
|
|
10
|
+
const { nanoid } = require("nanoid/async");
|
|
11
|
+
|
|
12
|
+
schemas.add(paymentSchema);
|
|
13
|
+
schemas.add(schema);
|
|
14
|
+
|
|
15
|
+
const validator = schemas.compile(schema);
|
|
16
|
+
|
|
17
|
+
class User extends Kohost {
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {import("../schemas/UserSchema").User} UserType
|
|
20
|
+
* Create a User instance.
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param {UserType} user - The user object of type User.
|
|
23
|
+
*/
|
|
24
|
+
constructor(user) {
|
|
25
|
+
if (user.photo) user.photo = new MediaFile(user.photo);
|
|
26
|
+
if (user.reservations)
|
|
27
|
+
user.reservations = user.reservations.map((res) => new Reservation(res));
|
|
28
|
+
if (user.identifications)
|
|
29
|
+
user.identifications = user.identifications.map(
|
|
30
|
+
(id) => new Identification(id)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
super(user);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static validatePhone(phoneNumber) {
|
|
37
|
+
const regex = /^\+?[1-9]\d{1,14}$/;
|
|
38
|
+
return regex.test(phoneNumber);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static validateEmail(email) {
|
|
42
|
+
//eslint-disable-next-line no-useless-escape
|
|
43
|
+
const regex =
|
|
44
|
+
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
45
|
+
return regex.test(email);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static async generatePassword(len = 16) {
|
|
49
|
+
return await nanoid(len);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Object.defineProperty(User.prototype, "schema", {
|
|
54
|
+
value: schema,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
Object.defineProperty(User.prototype, "validator", {
|
|
58
|
+
get: function () {
|
|
59
|
+
return validator;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
Object.defineProperty(User, "validProperties", {
|
|
64
|
+
value: Object.keys(schema.properties),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
Object.defineProperty(User.prototype, "fullName", {
|
|
68
|
+
get: function () {
|
|
69
|
+
return `${this.firstName} ${this.lastName}`;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
Object.defineProperty(User.prototype, "roles", {
|
|
74
|
+
get: function () {
|
|
75
|
+
const roles = new Set();
|
|
76
|
+
if (this.permissions) {
|
|
77
|
+
for (const permission of this.permissions) {
|
|
78
|
+
roles.add(permission.role);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return Array.from(roles);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
Object.defineProperty(User.prototype, "isSuperAdmin", {
|
|
86
|
+
get: function () {
|
|
87
|
+
return this.roles.includes("SuperAdmin");
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
Object.defineProperty(User.prototype, "isAdmin", {
|
|
92
|
+
get: function () {
|
|
93
|
+
return this.roles.includes("Admin") || this.roles.includes("Administrator");
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
Object.defineProperty(User.prototype, "isManager", {
|
|
98
|
+
get: function () {
|
|
99
|
+
return this.roles.includes("Manager");
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
Object.defineProperty(User.prototype, "isUser", {
|
|
104
|
+
get: function () {
|
|
105
|
+
return this.roles.includes("User");
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
Object.defineProperty(User.prototype, "isGuest", {
|
|
110
|
+
get: function () {
|
|
111
|
+
return this.roles.includes("Guest");
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
module.exports = User;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Create the WindowCovering Model
|
|
2
|
+
const schemas = require("../utils/schema");
|
|
3
|
+
const schema = require("../schemas/windowCovering.json");
|
|
4
|
+
const Kohost = require("./Kohost");
|
|
5
|
+
|
|
6
|
+
schemas.add(schema);
|
|
7
|
+
const validator = schemas.compile(schema);
|
|
8
|
+
|
|
9
|
+
class WindowCovering extends Kohost {
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import("../schemas/WindowCoveringSchema").WindowCovering} WindowCoveringType
|
|
12
|
+
* Create a WindowCovering instance.
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {WindowCoveringType} windowCovering - The windowCovering object of type WindowCovering.
|
|
15
|
+
*/
|
|
16
|
+
constructor(windowCovering) {
|
|
17
|
+
super(windowCovering);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static getActionDelta(old, _new) {
|
|
21
|
+
const delta = {};
|
|
22
|
+
for (const action in _new) {
|
|
23
|
+
if (this.actionProperties?.includes(action)) {
|
|
24
|
+
if (action === "position") {
|
|
25
|
+
const oldPos = old[action];
|
|
26
|
+
const newPos = _new[action];
|
|
27
|
+
delta[action] = newPos - oldPos / 100;
|
|
28
|
+
} else if (old[action] !== _new[action]) {
|
|
29
|
+
delta[action] = 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return delta;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(WindowCovering.prototype, "schema", {
|
|
38
|
+
value: schema,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(WindowCovering.prototype, "validator", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return validator;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
Object.defineProperty(WindowCovering, "validProperties", {
|
|
48
|
+
value: Object.keys(schema.properties),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
Object.defineProperty(WindowCovering, "actionProperties", {
|
|
52
|
+
value: ["position"],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
module.exports = WindowCovering;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const Reservation = require("./Reservation");
|
|
2
|
+
const MediaFile = require("./MediaFile");
|
|
3
|
+
const Switch = require("./Switch");
|
|
4
|
+
const Alarm = require("./Alarm");
|
|
5
|
+
const Dimmer = require("./Dimmer");
|
|
6
|
+
const Lock = require("./Lock");
|
|
7
|
+
const Thermostat = require("./Thermostat");
|
|
8
|
+
const WindowCovering = require("./WindowCovering");
|
|
9
|
+
const Identification = require("./Identification");
|
|
10
|
+
const User = require("./User");
|
|
11
|
+
const SystemUser = require("./SystemUser");
|
|
12
|
+
const Courtesy = require("./Courtesy");
|
|
13
|
+
const Camera = require("./Camera");
|
|
14
|
+
const MotionSensor = require("./MotionSensor");
|
|
15
|
+
const MediaSource = require("./MediaSource");
|
|
16
|
+
const Room = require("./Room");
|
|
17
|
+
|
|
18
|
+
const Space = require("./Space");
|
|
19
|
+
const Category = require("./Category");
|
|
20
|
+
|
|
21
|
+
const Ticket = require("./Ticket");
|
|
22
|
+
const Scene = require("./Scene");
|
|
23
|
+
const Gateway = require("./Gateway");
|
|
24
|
+
const Product = require("./Product");
|
|
25
|
+
const Order = require("./Order");
|
|
26
|
+
const DiscoveredDevice = require("./DiscoveredDevice");
|
|
27
|
+
const Credential = require("./Credential");
|
|
28
|
+
const ShortLink = require("./ShortLink");
|
|
29
|
+
const EnergyReportShard = require("./EnergyReportShard");
|
|
30
|
+
const EnergyReport = require("./EnergyReport");
|
|
31
|
+
const SMSMessage = require("./SmsMessage");
|
|
32
|
+
const EmailMessage = require("./EmailMessage");
|
|
33
|
+
const Notification = require("./Notification");
|
|
34
|
+
|
|
35
|
+
const Property = require("./Property");
|
|
36
|
+
const Organization = require("./Organization");
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
Organization,
|
|
40
|
+
Property,
|
|
41
|
+
MediaFile,
|
|
42
|
+
Gateway,
|
|
43
|
+
Switch,
|
|
44
|
+
Alarm,
|
|
45
|
+
Dimmer,
|
|
46
|
+
Lock,
|
|
47
|
+
Courtesy,
|
|
48
|
+
Camera,
|
|
49
|
+
MotionSensor,
|
|
50
|
+
Thermostat,
|
|
51
|
+
WindowCovering,
|
|
52
|
+
MediaSource,
|
|
53
|
+
Identification,
|
|
54
|
+
Product,
|
|
55
|
+
User,
|
|
56
|
+
SystemUser,
|
|
57
|
+
Room,
|
|
58
|
+
Space,
|
|
59
|
+
Category,
|
|
60
|
+
Ticket,
|
|
61
|
+
Scene,
|
|
62
|
+
DiscoveredDevice,
|
|
63
|
+
Reservation,
|
|
64
|
+
Credential,
|
|
65
|
+
ShortLink,
|
|
66
|
+
EnergyReportShard,
|
|
67
|
+
EnergyReport,
|
|
68
|
+
SMSMessage,
|
|
69
|
+
EmailMessage,
|
|
70
|
+
Order,
|
|
71
|
+
Notification,
|
|
72
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const io = require("socket.io-client");
|
|
2
|
+
const { EventEmitter } = require("events");
|
|
3
|
+
|
|
4
|
+
module.exports = class SocketIoClient extends EventEmitter {
|
|
5
|
+
constructor(config = { url: null, propertyId: null, options: {} }) {
|
|
6
|
+
super();
|
|
7
|
+
if (!config.url) throw new Error("Websocket URL / endpoint not provided");
|
|
8
|
+
if (!config.propertyId) throw new Error("Property ID not provided");
|
|
9
|
+
this.url = config.url;
|
|
10
|
+
this.propertyId = config.propertyId;
|
|
11
|
+
this.options = {
|
|
12
|
+
autoConnect: false,
|
|
13
|
+
forceNew: false,
|
|
14
|
+
reconnection: true,
|
|
15
|
+
reconnectionAttempts: Infinity,
|
|
16
|
+
reconnectionDelay: 1000,
|
|
17
|
+
withCredentials: true,
|
|
18
|
+
transports: ["websocket", "polling"],
|
|
19
|
+
upgrade: true,
|
|
20
|
+
...config.options,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.socket = io(this.url, this.options);
|
|
24
|
+
|
|
25
|
+
this.socket.on("connect", () => {
|
|
26
|
+
this.emit("connect", this.socket);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
this.socket.on("disconnect", (reason) => {
|
|
30
|
+
this.emit("disconnect", reason);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.socket.on("reconnect_attempt", (data) => {
|
|
34
|
+
this.emit("reconnect_attempt", data);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this.socket.on("connect_error", (error) => {
|
|
38
|
+
this.emit("connect_error", error);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get connected() {
|
|
43
|
+
return this.socket?.connected || false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get disconnected() {
|
|
47
|
+
return this.socket?.disconnected || false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
connect() {
|
|
51
|
+
this.socket.connect();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
disconnect() {
|
|
55
|
+
this.socket.disconnect();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
reconnect() {
|
|
59
|
+
this.disconnect();
|
|
60
|
+
this.connect();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
subscribe(event, callback) {
|
|
64
|
+
this.socket.on(event, callback);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
unsubscribe(event, callback) {
|
|
68
|
+
this.socket.off(event, callback);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
send(event, { data = {}, query = {}, ...rest }) {
|
|
72
|
+
this.socket.emit(event, { data, query, ...rest });
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const deviceTypes = require("./deviceTypes");
|
|
2
|
+
const formalDeviceTypes = require("./formalDeviceTypes");
|
|
3
|
+
const { defs: httpDefs } = require("../Client");
|
|
4
|
+
|
|
5
|
+
const defs = {
|
|
6
|
+
http: httpDefs,
|
|
7
|
+
deviceTypes,
|
|
8
|
+
formalDeviceTypes,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = defs;
|
|
@@ -5,13 +5,19 @@ const Events = require("./Events");
|
|
|
5
5
|
const defs = require("./defs");
|
|
6
6
|
const utils = require("./utils");
|
|
7
7
|
const Client = require("./Client");
|
|
8
|
+
const SocketIoClient = require("./SocketIoClient");
|
|
9
|
+
const AMQPClient = require("./AMQPClient");
|
|
10
|
+
|
|
8
11
|
const Kohost = {
|
|
9
12
|
Models,
|
|
10
13
|
Errors,
|
|
11
14
|
Commands,
|
|
12
15
|
Events,
|
|
13
16
|
Client,
|
|
17
|
+
SocketIoClient,
|
|
18
|
+
AMQPClient,
|
|
14
19
|
defs,
|
|
15
|
-
utils
|
|
20
|
+
utils: utils,
|
|
16
21
|
};
|
|
22
|
+
|
|
17
23
|
module.exports = Kohost;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type SupportedNotifications = (
|
|
9
|
+
| "button 1"
|
|
10
|
+
| "button 2"
|
|
11
|
+
| "button 3"
|
|
12
|
+
| "button 4"
|
|
13
|
+
| "button 5"
|
|
14
|
+
| "idle"
|
|
15
|
+
| "powerHasBeedApplied"
|
|
16
|
+
| "acMainsDisconnected"
|
|
17
|
+
| "acMainsReconnected"
|
|
18
|
+
| "replaceBatterySoon"
|
|
19
|
+
| "replaceBatteryNow"
|
|
20
|
+
| "hardwareFailure"
|
|
21
|
+
| "softwareFailure"
|
|
22
|
+
| "hardwareFailureWithCode"
|
|
23
|
+
| "softwareFailureWithCode"
|
|
24
|
+
| "motionDetection"
|
|
25
|
+
| "airFilterNeedsCleaned"
|
|
26
|
+
| "smokeDetected"
|
|
27
|
+
| "outsideSafeTemperatureRange"
|
|
28
|
+
| "outsideSafeHumidityRange"
|
|
29
|
+
)[];
|
|
30
|
+
export type Notification = {
|
|
31
|
+
name?:
|
|
32
|
+
| "button 1"
|
|
33
|
+
| "button 2"
|
|
34
|
+
| "button 3"
|
|
35
|
+
| "button 4"
|
|
36
|
+
| "button 5"
|
|
37
|
+
| "idle"
|
|
38
|
+
| "powerHasBeedApplied"
|
|
39
|
+
| "acMainsDisconnected"
|
|
40
|
+
| "acMainsReconnected"
|
|
41
|
+
| "replaceBatterySoon"
|
|
42
|
+
| "replaceBatteryNow"
|
|
43
|
+
| "hardwareFailure"
|
|
44
|
+
| "softwareFailure"
|
|
45
|
+
| "hardwareFailureWithCode"
|
|
46
|
+
| "softwareFailureWithCode"
|
|
47
|
+
| "motionDetection"
|
|
48
|
+
| "airFilterNeedsCleaned"
|
|
49
|
+
| "smokeDetected"
|
|
50
|
+
| "outsideSafeTemperatureRange"
|
|
51
|
+
| "outsideSafeHumidityRange";
|
|
52
|
+
timestamp?: number;
|
|
53
|
+
description?: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
} & ({
|
|
56
|
+
name?:
|
|
57
|
+
| "button 1"
|
|
58
|
+
| "button 2"
|
|
59
|
+
| "button 3"
|
|
60
|
+
| "button 4"
|
|
61
|
+
| "button 5"
|
|
62
|
+
| "idle"
|
|
63
|
+
| "powerHasBeedApplied"
|
|
64
|
+
| "acMainsDisconnected"
|
|
65
|
+
| "acMainsReconnected"
|
|
66
|
+
| "replaceBatterySoon"
|
|
67
|
+
| "replaceBatteryNow"
|
|
68
|
+
| "hardwareFailure"
|
|
69
|
+
| "softwareFailure"
|
|
70
|
+
| "hardwareFailureWithCode"
|
|
71
|
+
| "softwareFailureWithCode"
|
|
72
|
+
| "motionDetection"
|
|
73
|
+
| "airFilterNeedsCleaned"
|
|
74
|
+
| "smokeDetected"
|
|
75
|
+
| "outsideSafeTemperatureRange"
|
|
76
|
+
| "outsideSafeHumidityRange";
|
|
77
|
+
timestamp?: number;
|
|
78
|
+
description?: string;
|
|
79
|
+
[k: string]: unknown;
|
|
80
|
+
} | null);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Any smart alarm system
|
|
84
|
+
*/
|
|
85
|
+
export interface Alarm {
|
|
86
|
+
id: string;
|
|
87
|
+
name?: string;
|
|
88
|
+
offline?: boolean;
|
|
89
|
+
type:
|
|
90
|
+
| "alarm"
|
|
91
|
+
| "dimmer"
|
|
92
|
+
| "switch"
|
|
93
|
+
| "motionSensor"
|
|
94
|
+
| "windowCovering"
|
|
95
|
+
| "camera"
|
|
96
|
+
| "mediaSource"
|
|
97
|
+
| "thermostat"
|
|
98
|
+
| "lock"
|
|
99
|
+
| "courtesy"
|
|
100
|
+
| "gateway"
|
|
101
|
+
| "tv"
|
|
102
|
+
| "dvr"
|
|
103
|
+
| "appleTv"
|
|
104
|
+
| "discPlayer"
|
|
105
|
+
| "mediaPlayer"
|
|
106
|
+
| "uncontrolledDevice";
|
|
107
|
+
systemId?: string;
|
|
108
|
+
supportedNotifications?: SupportedNotifications;
|
|
109
|
+
notification?: Notification;
|
|
110
|
+
driver:
|
|
111
|
+
| "aws-kinesis"
|
|
112
|
+
| "butler"
|
|
113
|
+
| "crestron"
|
|
114
|
+
| "dmp"
|
|
115
|
+
| "dormakaba"
|
|
116
|
+
| "dsc"
|
|
117
|
+
| "ecobee"
|
|
118
|
+
| "igor"
|
|
119
|
+
| "inncom"
|
|
120
|
+
| "kohost-k7"
|
|
121
|
+
| "kohost-pms"
|
|
122
|
+
| "lg"
|
|
123
|
+
| "lirc"
|
|
124
|
+
| "mews"
|
|
125
|
+
| "mht"
|
|
126
|
+
| "paxton"
|
|
127
|
+
| "pelican-wireless"
|
|
128
|
+
| "rebrandly"
|
|
129
|
+
| "salto"
|
|
130
|
+
| "salto-irn"
|
|
131
|
+
| "se"
|
|
132
|
+
| "sendgrid"
|
|
133
|
+
| "stay-n-touch"
|
|
134
|
+
| "twilio"
|
|
135
|
+
| "cloudflare-images"
|
|
136
|
+
| "cloudflare-stream"
|
|
137
|
+
| "insperia-privacy";
|
|
138
|
+
areas: {
|
|
139
|
+
number?: number;
|
|
140
|
+
name?: string;
|
|
141
|
+
securityMode?: "arming" | "disarming" | "armed" | "disarmed" | "alarm" | null;
|
|
142
|
+
readyToArm?: boolean | null;
|
|
143
|
+
}[];
|
|
144
|
+
zones: {
|
|
145
|
+
number?: number;
|
|
146
|
+
name?: string;
|
|
147
|
+
secure?: boolean;
|
|
148
|
+
bypassed?: boolean | null;
|
|
149
|
+
}[];
|
|
150
|
+
watts?: number;
|
|
151
|
+
[k: string]: unknown;
|
|
152
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type SupportedNotifications = (
|
|
9
|
+
| "button 1"
|
|
10
|
+
| "button 2"
|
|
11
|
+
| "button 3"
|
|
12
|
+
| "button 4"
|
|
13
|
+
| "button 5"
|
|
14
|
+
| "idle"
|
|
15
|
+
| "powerHasBeedApplied"
|
|
16
|
+
| "acMainsDisconnected"
|
|
17
|
+
| "acMainsReconnected"
|
|
18
|
+
| "replaceBatterySoon"
|
|
19
|
+
| "replaceBatteryNow"
|
|
20
|
+
| "hardwareFailure"
|
|
21
|
+
| "softwareFailure"
|
|
22
|
+
| "hardwareFailureWithCode"
|
|
23
|
+
| "softwareFailureWithCode"
|
|
24
|
+
| "motionDetection"
|
|
25
|
+
| "airFilterNeedsCleaned"
|
|
26
|
+
| "smokeDetected"
|
|
27
|
+
| "outsideSafeTemperatureRange"
|
|
28
|
+
| "outsideSafeHumidityRange"
|
|
29
|
+
)[];
|
|
30
|
+
export type Notification = {
|
|
31
|
+
name?:
|
|
32
|
+
| "button 1"
|
|
33
|
+
| "button 2"
|
|
34
|
+
| "button 3"
|
|
35
|
+
| "button 4"
|
|
36
|
+
| "button 5"
|
|
37
|
+
| "idle"
|
|
38
|
+
| "powerHasBeedApplied"
|
|
39
|
+
| "acMainsDisconnected"
|
|
40
|
+
| "acMainsReconnected"
|
|
41
|
+
| "replaceBatterySoon"
|
|
42
|
+
| "replaceBatteryNow"
|
|
43
|
+
| "hardwareFailure"
|
|
44
|
+
| "softwareFailure"
|
|
45
|
+
| "hardwareFailureWithCode"
|
|
46
|
+
| "softwareFailureWithCode"
|
|
47
|
+
| "motionDetection"
|
|
48
|
+
| "airFilterNeedsCleaned"
|
|
49
|
+
| "smokeDetected"
|
|
50
|
+
| "outsideSafeTemperatureRange"
|
|
51
|
+
| "outsideSafeHumidityRange";
|
|
52
|
+
timestamp?: number;
|
|
53
|
+
description?: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
} & ({
|
|
56
|
+
name?:
|
|
57
|
+
| "button 1"
|
|
58
|
+
| "button 2"
|
|
59
|
+
| "button 3"
|
|
60
|
+
| "button 4"
|
|
61
|
+
| "button 5"
|
|
62
|
+
| "idle"
|
|
63
|
+
| "powerHasBeedApplied"
|
|
64
|
+
| "acMainsDisconnected"
|
|
65
|
+
| "acMainsReconnected"
|
|
66
|
+
| "replaceBatterySoon"
|
|
67
|
+
| "replaceBatteryNow"
|
|
68
|
+
| "hardwareFailure"
|
|
69
|
+
| "softwareFailure"
|
|
70
|
+
| "hardwareFailureWithCode"
|
|
71
|
+
| "softwareFailureWithCode"
|
|
72
|
+
| "motionDetection"
|
|
73
|
+
| "airFilterNeedsCleaned"
|
|
74
|
+
| "smokeDetected"
|
|
75
|
+
| "outsideSafeTemperatureRange"
|
|
76
|
+
| "outsideSafeHumidityRange";
|
|
77
|
+
timestamp?: number;
|
|
78
|
+
description?: string;
|
|
79
|
+
[k: string]: unknown;
|
|
80
|
+
} | null);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Any smart camera
|
|
84
|
+
*/
|
|
85
|
+
export interface Camera {
|
|
86
|
+
id: string;
|
|
87
|
+
name?: string;
|
|
88
|
+
type:
|
|
89
|
+
| "alarm"
|
|
90
|
+
| "dimmer"
|
|
91
|
+
| "switch"
|
|
92
|
+
| "motionSensor"
|
|
93
|
+
| "windowCovering"
|
|
94
|
+
| "camera"
|
|
95
|
+
| "mediaSource"
|
|
96
|
+
| "thermostat"
|
|
97
|
+
| "lock"
|
|
98
|
+
| "courtesy"
|
|
99
|
+
| "gateway"
|
|
100
|
+
| "tv"
|
|
101
|
+
| "dvr"
|
|
102
|
+
| "appleTv"
|
|
103
|
+
| "discPlayer"
|
|
104
|
+
| "mediaPlayer"
|
|
105
|
+
| "uncontrolledDevice";
|
|
106
|
+
supportedNotifications?: SupportedNotifications;
|
|
107
|
+
notification?: Notification;
|
|
108
|
+
driver:
|
|
109
|
+
| "aws-kinesis"
|
|
110
|
+
| "butler"
|
|
111
|
+
| "crestron"
|
|
112
|
+
| "dmp"
|
|
113
|
+
| "dormakaba"
|
|
114
|
+
| "dsc"
|
|
115
|
+
| "ecobee"
|
|
116
|
+
| "igor"
|
|
117
|
+
| "inncom"
|
|
118
|
+
| "kohost-k7"
|
|
119
|
+
| "kohost-pms"
|
|
120
|
+
| "lg"
|
|
121
|
+
| "lirc"
|
|
122
|
+
| "mews"
|
|
123
|
+
| "mht"
|
|
124
|
+
| "paxton"
|
|
125
|
+
| "pelican-wireless"
|
|
126
|
+
| "rebrandly"
|
|
127
|
+
| "salto"
|
|
128
|
+
| "salto-irn"
|
|
129
|
+
| "se"
|
|
130
|
+
| "sendgrid"
|
|
131
|
+
| "stay-n-touch"
|
|
132
|
+
| "twilio"
|
|
133
|
+
| "cloudflare-images"
|
|
134
|
+
| "cloudflare-stream"
|
|
135
|
+
| "insperia-privacy";
|
|
136
|
+
liveStreams: {
|
|
137
|
+
iframe?: string | null;
|
|
138
|
+
hls?: string | null;
|
|
139
|
+
webRTC?: string | null;
|
|
140
|
+
};
|
|
141
|
+
systemId?: string;
|
|
142
|
+
watts?: number;
|
|
143
|
+
}
|