@kohost/api-client 1.0.0-alpha.2 → 1.0.0-alpha.4
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/.eslintrc.js +10 -0
- package/bitbucket-pipelines.yml +39 -0
- package/commands/Command.js +38 -0
- package/commands/DiscoverUsersCommand.js +21 -0
- package/commands/SetAlarmCommand.js +21 -0
- package/commands/SetCourtesyCommand.js +21 -0
- package/commands/SetDimmerCommand.js +21 -0
- package/commands/SetLockCommand.js +21 -0
- package/commands/SetSceneControllerCommand.js +21 -0
- package/commands/SetSwitchCommand.js +21 -0
- package/commands/SetThermostatCommand.js +21 -0
- package/commands/SetWindowCoveringCommand.js +21 -0
- package/commands/VerifyDocumentCommand.js +24 -0
- package/commands/index.js +25 -0
- package/defs/deviceTypes.js +15 -0
- package/defs/formalDeviceTypes.js +6 -0
- package/defs/http.js +7 -0
- package/defs/index.js +11 -0
- package/errors/AppError.js +8 -0
- package/errors/AuthenticationError.js +9 -0
- package/errors/AuthorizationError.js +9 -0
- package/errors/DeviceCommError.js +9 -0
- package/errors/LoginError.js +9 -0
- package/errors/NotFoundError.js +9 -0
- package/errors/RequestError.js +9 -0
- package/errors/SystemCommError.js +9 -0
- package/errors/TokenExpiredError.js +9 -0
- package/errors/UnprocessableRequestError.js +9 -0
- package/errors/ValidationError.js +9 -0
- package/errors/index.js +15 -0
- package/events/Event.js +33 -0
- package/events/SystemCameraUpdatedEvent.js +17 -0
- package/events/SystemCourtesyUpdatedEvent.js +17 -0
- package/events/SystemDimmerUpdatedEvent.js +17 -0
- package/events/SystemLockUpdatedEvent.js +17 -0
- package/events/SystemReservationUpdatedEvent.js +17 -0
- package/events/SystemSceneControllerUpdatedEvent.js +17 -0
- package/events/SystemSourceUpdatedEvent.js +17 -0
- package/events/SystemSpaceUpdatedEvent.js +17 -0
- package/events/SystemSwitchUpdatedEvent.js +17 -0
- package/events/SystemThermostatUpdatedEvent.js +17 -0
- package/events/SystemUserUpdatedEvent.js +17 -0
- package/events/SystemWindowCoveringUpdatedEvent.js +17 -0
- package/events/index.js +28 -0
- package/http/handleResponseError.js +53 -0
- package/http/handleResponseSuccess.js +15 -0
- package/http/index.js +165 -0
- package/index.js +19 -2
- package/models/acl.js +29 -0
- package/models/admin/customer.js +28 -0
- package/models/admin/property.js +28 -0
- package/models/alarm.js +25 -3
- package/models/application.js +28 -0
- package/models/camera.js +29 -0
- package/models/courtesy.js +29 -3
- package/models/dimmer.js +45 -3
- package/models/discoveredDevice.js +30 -0
- package/models/gateway.js +33 -3
- package/models/index.js +38 -1
- package/models/integration.js +76 -0
- package/models/iotGateway.js +29 -0
- package/models/kohost.js +95 -0
- package/models/lock.js +29 -3
- package/models/mediaSource.js +29 -0
- package/models/motionSensor.js +29 -0
- package/models/reservation.js +36 -0
- package/models/room.js +185 -0
- package/models/scene.js +28 -0
- package/models/sceneController.js +24 -5
- package/models/space.js +99 -0
- package/models/switch.js +29 -3
- package/models/thermostat.js +71 -31
- package/models/ticket.js +91 -0
- package/models/user.js +58 -0
- package/models/windowCovering.js +44 -5
- package/package.json +30 -7
- package/prepare.js +4 -0
- package/schemas/acl.json +111 -0
- package/schemas/admin/customer.json +32 -0
- package/schemas/admin/property.json +174 -0
- package/schemas/alarm.json +5 -5
- package/schemas/application.json +24 -0
- package/schemas/camera.json +41 -0
- package/schemas/courtesy.json +5 -6
- package/schemas/definitions/common.json +21 -0
- package/schemas/definitions/device.json +21 -3
- package/schemas/dimmer.json +8 -5
- package/schemas/discoveredDevice.json +43 -0
- package/schemas/gateway.json +45 -13
- package/schemas/identification.json +35 -0
- package/schemas/integration.json +94 -0
- package/schemas/iotGateway.json +29 -0
- package/schemas/lock.json +8 -5
- package/schemas/mediaSource.json +151 -0
- package/schemas/motionSensor.json +26 -0
- package/schemas/payment.json +38 -0
- package/schemas/reservation.json +66 -0
- package/schemas/room.json +138 -0
- package/schemas/scene.json +118 -0
- package/schemas/sceneController.json +9 -9
- package/schemas/space.json +111 -0
- package/schemas/switch.json +8 -5
- package/schemas/thermostat.json +19 -10
- package/schemas/ticket.json +82 -0
- package/schemas/user.json +124 -0
- package/schemas/windowCovering.json +8 -5
- package/tests/unit/models/space.test.js +31 -0
- package/tests/unit/models/thermostat.test.js +146 -0
- package/tests/unit/models/user.test.js +28 -0
- package/useCases/http.json +1098 -0
- package/utils/getDeviceTypes.js +7 -0
- package/utils/getFormalDeviceType.js +5 -0
- package/utils/schema.js +28 -0
- package/vite.config.js +22 -0
- package/utils/compiler.js +0 -40
package/utils/schema.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const Ajv = require("ajv");
|
|
2
|
+
const ajv = new Ajv({
|
|
3
|
+
allErrors: true,
|
|
4
|
+
useDefaults: true,
|
|
5
|
+
strict: false,
|
|
6
|
+
allowMatchingProperties: true,
|
|
7
|
+
allowUnionTypes: true,
|
|
8
|
+
strictRequired: false,
|
|
9
|
+
});
|
|
10
|
+
const addFormats = require("ajv-formats");
|
|
11
|
+
|
|
12
|
+
const commonDefs = require("../schemas/definitions/common.json");
|
|
13
|
+
const deviceDefs = require("../schemas/definitions/device.json");
|
|
14
|
+
|
|
15
|
+
addFormats(ajv);
|
|
16
|
+
|
|
17
|
+
ajv.addSchema(commonDefs);
|
|
18
|
+
|
|
19
|
+
ajv.addSchema(deviceDefs);
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
add: function add(schema) {
|
|
23
|
+
ajv.addSchema(schema);
|
|
24
|
+
},
|
|
25
|
+
compile: function compile(schema) {
|
|
26
|
+
return ajv.compile(schema);
|
|
27
|
+
},
|
|
28
|
+
};
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @type {import('vite').UserConfig} */
|
|
2
|
+
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { defineConfig } from "vite";
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
build: {
|
|
8
|
+
lib: {
|
|
9
|
+
// Could also be a dictionary or array of multiple entry points
|
|
10
|
+
entry: resolve(__dirname, "index.js"),
|
|
11
|
+
name: "Kohost",
|
|
12
|
+
// the proper extensions will be added
|
|
13
|
+
fileName: "kohost",
|
|
14
|
+
},
|
|
15
|
+
// commonjsOptions: {
|
|
16
|
+
// include: "**/*.js",
|
|
17
|
+
// transformMixedEsModules: true,
|
|
18
|
+
// esmExternals: true,
|
|
19
|
+
// requireReturnsDefault: false,
|
|
20
|
+
// },
|
|
21
|
+
},
|
|
22
|
+
});
|
package/utils/compiler.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const Ajv = require("ajv");
|
|
2
|
-
const ajv = new Ajv({ allErrors: true });
|
|
3
|
-
|
|
4
|
-
// load definitions
|
|
5
|
-
const deviceSchema = require("../schemas/definitions/device.json");
|
|
6
|
-
|
|
7
|
-
ajv.addSchema(deviceSchema);
|
|
8
|
-
|
|
9
|
-
function createModel({ schema, name, methods = [] }) {
|
|
10
|
-
const validator = ajv.compile(schema);
|
|
11
|
-
class Model {
|
|
12
|
-
constructor(data) {
|
|
13
|
-
// apply schema properties to the class
|
|
14
|
-
this.validate(data);
|
|
15
|
-
Object.keys(validator.schema.properties).forEach((key) => {
|
|
16
|
-
if (data[key] !== undefined) this[key] = data[key];
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
validate(data) {
|
|
21
|
-
const valid = this._validator(data);
|
|
22
|
-
if (!valid)
|
|
23
|
-
throw new Error(`Invalid ${name}`, { cause: this._validator.errors });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// change the name of the class
|
|
28
|
-
Object.defineProperty(Model, "name", { value: name });
|
|
29
|
-
Model.prototype._validator = validator;
|
|
30
|
-
Model.prototype.schema = schema;
|
|
31
|
-
methods.forEach((method) => {
|
|
32
|
-
const methodName = method.name;
|
|
33
|
-
Model.prototype[methodName] = method;
|
|
34
|
-
});
|
|
35
|
-
return Model;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = {
|
|
39
|
-
createModel,
|
|
40
|
-
};
|