@kohost/api-client 1.0.0-alpha.3 → 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.
@@ -0,0 +1,21 @@
1
+ const Command = require("./Command");
2
+
3
+ class SetAlarmCommand extends Command {
4
+ constructor({ id }) {
5
+ super({ id });
6
+ }
7
+
8
+ get name() {
9
+ return "DiscoverUsers";
10
+ }
11
+
12
+ get routingKey() {
13
+ return `users.${this.data.id}.get`;
14
+ }
15
+
16
+ get replyTo() {
17
+ return "system.response.users";
18
+ }
19
+ }
20
+
21
+ module.exports = SetAlarmCommand;
package/commands/index.js CHANGED
@@ -6,6 +6,9 @@ const SetLockCommand = require("./SetLockCommand");
6
6
  const SetSceneControllerCommand = require("./SetSceneControllerCommand");
7
7
  const SetWindowCoveringCommand = require("./SetWindowCoveringCommand");
8
8
  const SetCourtesyCommand = require("./SetCourtesyCommand");
9
+
10
+ const DiscoverUsersCommand = require("./DiscoverUsersCommand");
11
+
9
12
  const VerifyDocumentCommand = require("./VerifyDocumentCommand");
10
13
 
11
14
  module.exports = {
@@ -18,4 +21,5 @@ module.exports = {
18
21
  SetWindowCoveringCommand,
19
22
  SetCourtesyCommand,
20
23
  VerifyDocumentCommand,
24
+ DiscoverUsersCommand,
21
25
  };
@@ -4,11 +4,11 @@ module.exports = function handleResponseSuccess(response) {
4
4
  response.pagination = response.data.pagination;
5
5
  response.data = response.data.data;
6
6
  }
7
- if (response.headers[this.authTokenHeaderKey]) {
7
+ if (!this.isBrowser && response.headers[this.authTokenHeaderKey]) {
8
8
  this.authToken = response.headers[this.authTokenHeaderKey];
9
9
  }
10
10
 
11
- if (response.headers[this.refreshTokenHeaderKey]) {
11
+ if (!this.isBrowser && response.headers[this.refreshTokenHeaderKey]) {
12
12
  this.refreshToken = response.headers[this.refreshTokenHeaderKey];
13
13
  }
14
14
  return response;
package/http/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const { EventEmitter } = require("events");
2
- const axios = require("axios");
3
2
  const defs = require("../defs").http;
4
3
  const handleResponseError = require("./handleResponseError");
5
4
  const handleResponseSuccess = require("./handleResponseSuccess");
@@ -30,13 +29,21 @@ function useCaseMethodFactory(Client) {
30
29
  */
31
30
 
32
31
  //eslint-disable-next-line no-inner-declarations
33
- function UseCase(options) {
34
- if (!options) options = {};
32
+ function UseCase(requestData, options = {}) {
33
+ if (!this._init) {
34
+ // wait a second for the client to initialize
35
+ return new Promise((resolve) => {
36
+ setTimeout(() => {
37
+ resolve(UseCase.call(this, requestData));
38
+ }, 500);
39
+ });
40
+ }
41
+ if (!requestData) requestData = {};
35
42
 
36
43
  // get parameters from path
37
44
  const pathParams = path.match(/:[a-zA-Z0-9]+/g);
38
45
 
39
- const { data, params, query, headers } = options;
46
+ const { data, params, query, headers } = requestData;
40
47
 
41
48
  // replace path parameters with values from params
42
49
  let url = path;
@@ -60,6 +67,7 @@ function useCaseMethodFactory(Client) {
60
67
  const config = {
61
68
  method: method.toLowerCase(),
62
69
  url: url,
70
+ ...options,
63
71
  };
64
72
 
65
73
  if (data) config.data = data;
@@ -94,26 +102,35 @@ class KohostApiClient extends EventEmitter {
94
102
  if (!options.tenantId) throw new Error("options.tenant is required");
95
103
  this.options = options;
96
104
  // eslint-disable-next-line no-undef
97
- this.isBrower = typeof window !== "undefined";
98
- this._http = axios.create({
99
- baseURL: options.url,
100
- responseType: "json",
101
- headers: {
102
- "Content-Type": "application/json",
103
- Accept: "application/json",
104
- [defs.tenantHeader]: options.tenantId,
105
- ...options.headers,
106
- },
107
- });
108
-
109
- this._http.interceptors.response.use(
110
- handleResponseSuccess.bind(this),
111
- handleResponseError.bind(this)
112
- );
113
-
114
- this._http.interceptors.request.use((config) => {
115
- config.headers[defs.authTokenHeader] = this.authToken;
116
- return config;
105
+ this.isBrowser = typeof window !== "undefined";
106
+ this._init = false;
107
+
108
+ import("axios").then((axiosModule) => {
109
+ const axios = axiosModule.default;
110
+ this._http = axios.create({
111
+ baseURL: options.url,
112
+ responseType: "json",
113
+ withCredentials: true,
114
+ headers: {
115
+ "Content-Type": "application/json",
116
+ Accept: "application/json",
117
+ [defs.tenantHeader]: options.tenantId,
118
+ ...options.headers,
119
+ },
120
+ });
121
+
122
+ this._http.interceptors.response.use(
123
+ handleResponseSuccess.bind(this),
124
+ handleResponseError.bind(this)
125
+ );
126
+
127
+ this._http.interceptors.request.use((config) => {
128
+ if (!this.isBrowser) {
129
+ config.headers[defs.authTokenHeader] = this.authToken;
130
+ }
131
+ return config;
132
+ });
133
+ this._init = true;
117
134
  });
118
135
  }
119
136
 
@@ -130,13 +147,7 @@ class KohostApiClient extends EventEmitter {
130
147
  }
131
148
 
132
149
  get authToken() {
133
- if (this.isBrower) {
134
- // get token from localStorage
135
- // eslint-disable-next-line no-undef
136
- return window.localStorage.getItem(this.lsTokenKey);
137
- } else {
138
- return this._authToken;
139
- }
150
+ return this._authToken;
140
151
  }
141
152
 
142
153
  /*
@@ -145,12 +156,7 @@ class KohostApiClient extends EventEmitter {
145
156
  */
146
157
 
147
158
  set authToken(token) {
148
- if (this.isBrower) {
149
- // eslint-disable-next-line no-undef
150
- window.localStorage.setItem(this.lsTokenKey, token);
151
- } else {
152
- this._authToken = token;
153
- }
159
+ this._authToken = token;
154
160
  }
155
161
  }
156
162
 
package/index.js CHANGED
@@ -15,8 +15,8 @@ const Kohost = {
15
15
  defs,
16
16
  Client: HttpClient,
17
17
  utils: {
18
- getFormalDeviceType,
19
- getDeviceTypes,
18
+ getFormalDeviceType: getFormalDeviceType,
19
+ getDeviceTypes: getDeviceTypes,
20
20
  },
21
21
  };
22
22
 
package/package.json CHANGED
@@ -1,17 +1,9 @@
1
1
  {
2
- "dependencies": {
3
- "ajv": "^8.11.0",
4
- "ajv-formats": "^2.1.1",
5
- "axios": "^1.0.0",
6
- "lodash.clonedeep": "^4.5.0",
7
- "lodash.findlast": "^4.6.0",
8
- "lodash.sortby": "^4.7.0",
9
- "nanoid": "^3.3.4"
10
- },
11
2
  "name": "@kohost/api-client",
12
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
13
4
  "description": "API client for Kohost utils",
14
5
  "main": "index.js",
6
+ "module": "index.js",
15
7
  "scripts": {
16
8
  "test": "jest",
17
9
  "test:watch": "jest --watchAll",
@@ -30,6 +22,15 @@
30
22
  "lint-staged": "^13.0.3",
31
23
  "prettier": "^2.5.1"
32
24
  },
25
+ "dependencies": {
26
+ "ajv": "^8.11.0",
27
+ "ajv-formats": "^2.1.1",
28
+ "axios": "^1.0.0",
29
+ "lodash.clonedeep": "^4.5.0",
30
+ "lodash.findlast": "^4.6.0",
31
+ "lodash.sortby": "^4.7.0",
32
+ "nanoid": "^3.3.4"
33
+ },
33
34
  "lint-staged": {
34
35
  "*.js": "eslint --cache --fix",
35
36
  "*.{js,css,md,json}": "prettier --write"
@@ -45,6 +45,126 @@
45
45
  "longitude": {
46
46
  "type": "number"
47
47
  },
48
+ "appManifest": {
49
+ "type": "object",
50
+
51
+ "properties": {
52
+ "name": {
53
+ "type": "string"
54
+ },
55
+ "short_name": {
56
+ "type": "string"
57
+ },
58
+ "scope": {
59
+ "type": "string"
60
+ },
61
+ "start_url": {
62
+ "type": "string"
63
+ },
64
+ "themeColor": {
65
+ "type": "string"
66
+ },
67
+ "backgroundColor": {
68
+ "type": "string"
69
+ },
70
+ "display": {
71
+ "type": "string",
72
+ "enum": ["fullscreen", "standalone", "minimal-ui", "browser"],
73
+ "default": "fullscreen"
74
+ },
75
+ "orientation": {
76
+ "type": "string",
77
+ "enum": ["portrait", "landscape"],
78
+ "default": "portrait"
79
+ },
80
+ "splash": {
81
+ "type": "object",
82
+ "properties": {
83
+ "src": {
84
+ "type": "string"
85
+ },
86
+ "type": {
87
+ "type": "string"
88
+ },
89
+ "sizes": {
90
+ "type": "string"
91
+ }
92
+ }
93
+ },
94
+ "icons": {
95
+ "type": "array",
96
+ "items": {
97
+ "type": "object",
98
+ "properties": {
99
+ "src": {
100
+ "type": "string"
101
+ },
102
+ "sizes": {
103
+ "type": "string"
104
+ },
105
+ "type": {
106
+ "type": "string"
107
+ }
108
+ }
109
+ }
110
+ },
111
+ "logo": {
112
+ "type": "object",
113
+ "properties": {
114
+ "src": {
115
+ "type": "string"
116
+ },
117
+ "type": {
118
+ "type": "string"
119
+ },
120
+ "sizes": {
121
+ "type": "string"
122
+ }
123
+ }
124
+ }
125
+ },
126
+ "default": {
127
+ "name": "Kohost",
128
+ "short_name": "Kohost",
129
+ "start_url": "/",
130
+ "scope": "/",
131
+ "display": "fullscreen",
132
+ "orientation": "portrait",
133
+ "theme_color": "#1d1f22",
134
+ "background_color": "#1d1f22",
135
+ "icons": [
136
+ {
137
+ "src": "https://cdn.kohost.app/defaultIcon.png",
138
+ "sizes": "512x512",
139
+ "type": "image/png"
140
+ }
141
+ ],
142
+ "splash": {
143
+ "src": "https://cdn.kohost.app/defaultSplash.jpg",
144
+ "sizes": "1500x800",
145
+ "type": "image/jpg"
146
+ },
147
+ "logo": {
148
+ "src": "https://cdn.kohost.app/defaultLogo.png",
149
+ "sizes": "300x75",
150
+ "type": "image/png"
151
+ }
152
+ }
153
+ },
154
+ "appFeatures": {
155
+ "type": "object",
156
+ "properties": {
157
+ "RoomControl": {},
158
+ "CheckIn": {},
159
+ "CheckOut": {},
160
+ "Concierge": {},
161
+ "Elevator": {}
162
+ },
163
+ "additionalProperties": false,
164
+ "default": {
165
+ "RoomControl": {}
166
+ }
167
+ },
48
168
  "credentials": {
49
169
  "type": "object",
50
170
  "additionalProperties": true
@@ -31,12 +31,12 @@
31
31
  "type": "string"
32
32
  },
33
33
  "checkInDateTime": {
34
- "type": "string",
34
+ "type": ["string", "object"],
35
35
  "format": "date-time"
36
36
  },
37
37
  "checkOutDateTime": {
38
- "type": "string",
39
- "format": "date-time"
38
+ "type": ["string", "object"],
39
+ "format": "date-time"
40
40
  },
41
41
  "adultCount": {
42
42
  "type": "number",
package/schemas/user.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "default": "user"
14
14
  },
15
15
  "active": {
16
- "type": "boolean",
16
+ "type": "boolean",
17
17
  "default": true
18
18
  },
19
19
  "firstName": {
@@ -23,11 +23,11 @@
23
23
  "type": "string"
24
24
  },
25
25
  "phone": {
26
- "type": "string",
27
- "pattern": "^\\+?[0-9]{1,14}$"
26
+ "type": ["string", "null"],
27
+ "pattern": "^\\+?[0-9]{1,14}$"
28
28
  },
29
29
  "email": {
30
- "type": "string",
30
+ "type": ["string", "null"],
31
31
  "format": "email"
32
32
  },
33
33
  "hashedPassword": {
@@ -62,20 +62,20 @@
62
62
  }
63
63
  },
64
64
  "identifications": {
65
- "type":"array",
65
+ "type": "array",
66
66
  "items": {
67
67
  "$ref": "https://api.kohost.app/schemas/v3/identification.json"
68
68
  }
69
- },
69
+ },
70
70
  "payments": {
71
- "type":"array",
71
+ "type": "array",
72
72
  "items": {
73
73
  "$ref": "https://api.kohost.app/schemas/v3/payment.json"
74
74
  }
75
75
  },
76
76
  "preferences": {
77
77
  "type": "object",
78
- "additionalProperties": false,
78
+ "additionalProperties": false,
79
79
  "properties": {
80
80
  "notifications": {
81
81
  "type": "array",
@@ -110,7 +110,7 @@
110
110
  "type": ["number", "null"]
111
111
  }
112
112
  }
113
- },
113
+ },
114
114
  "createdAt": {
115
115
  "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
116
116
  },
@@ -0,0 +1,28 @@
1
+ const User = require("../../../models/user");
2
+
3
+ const valid = {
4
+ firstName: "Ian",
5
+ lastName: "Rogers",
6
+ active: true,
7
+ type: "user",
8
+ email: "a3@bc.com",
9
+ phone: "+15555555555",
10
+ roles: ["Guest"],
11
+ };
12
+
13
+ test("does not throw error if invalid name provided ", () => {
14
+ const data = { ...valid };
15
+ expect(() => new User(data)).not.toThrow();
16
+ });
17
+
18
+ test("allows email to be empty", () => {
19
+ const data = { ...valid };
20
+ delete data.email;
21
+ expect(() => new User(data)).not.toThrow();
22
+ });
23
+
24
+ test("allows phone to be empty", () => {
25
+ const data = { ...valid };
26
+ delete data.phone;
27
+ expect(() => new User(data)).not.toThrow();
28
+ });
@@ -156,56 +156,56 @@
156
156
  }
157
157
  ],
158
158
  [
159
- "ListGroups",
159
+ "ListSpaces",
160
160
  {
161
161
  "http": {
162
162
  "method": "GET",
163
- "path": "/groups"
163
+ "path": "/spaces"
164
164
  }
165
165
  }
166
166
  ],
167
167
  [
168
- "CreateGroup",
168
+ "CreateSpace",
169
169
  {
170
170
  "http": {
171
171
  "method": "POST",
172
- "path": "/groups"
172
+ "path": "/spaces"
173
173
  }
174
174
  }
175
175
  ],
176
176
  [
177
- "DescribeGroup",
177
+ "DescribeSpace",
178
178
  {
179
179
  "http": {
180
180
  "method": "GET",
181
- "path": "/groups/:id"
181
+ "path": "/spaces/:id"
182
182
  }
183
183
  }
184
184
  ],
185
185
  [
186
- "DeleteGroup",
186
+ "DeleteSpace",
187
187
  {
188
188
  "http": {
189
189
  "method": "DELETE",
190
- "path": "/groups/:id"
190
+ "path": "/spaces/:id"
191
191
  }
192
192
  }
193
193
  ],
194
194
  [
195
- "UpdateGroup",
195
+ "UpdateSpace",
196
196
  {
197
197
  "http": {
198
198
  "method": "PUT",
199
- "path": "/groups/:id"
199
+ "path": "/spaces/:id"
200
200
  }
201
201
  }
202
202
  ],
203
203
  [
204
- "CreateRoomInGroup",
204
+ "CreateRoomInSpace",
205
205
  {
206
206
  "http": {
207
207
  "method": "POST",
208
- "path": "/groups/:groupId/rooms"
208
+ "path": "/spaces/:id/rooms"
209
209
  }
210
210
  }
211
211
  ],
@@ -299,6 +299,15 @@
299
299
  }
300
300
  }
301
301
  ],
302
+ [
303
+ "SetLocks",
304
+ {
305
+ "http": {
306
+ "method": "POST",
307
+ "path": "/rooms/:roomId/locks/:id"
308
+ }
309
+ }
310
+ ],
302
311
  [
303
312
  "CreateCamera",
304
313
  {
@@ -344,6 +353,15 @@
344
353
  }
345
354
  }
346
355
  ],
356
+ [
357
+ "SetCameras",
358
+ {
359
+ "http": {
360
+ "method": "POST",
361
+ "path": "/rooms/:roomId/cameras/:id"
362
+ }
363
+ }
364
+ ],
347
365
  [
348
366
  "CreateCourtesy",
349
367
  {
@@ -389,6 +407,15 @@
389
407
  }
390
408
  }
391
409
  ],
410
+ [
411
+ "SetCourtesy",
412
+ {
413
+ "http": {
414
+ "method": "POST",
415
+ "path": "/rooms/:roomId/courtesy/:id"
416
+ }
417
+ }
418
+ ],
392
419
  [
393
420
  "CreateDimmer",
394
421
  {
@@ -524,6 +551,15 @@
524
551
  }
525
552
  }
526
553
  ],
554
+ [
555
+ "SetSwitches",
556
+ {
557
+ "http": {
558
+ "method": "POST",
559
+ "path": "/rooms/:roomId/switches/:id"
560
+ }
561
+ }
562
+ ],
527
563
  [
528
564
  "CreateSceneController",
529
565
  {
@@ -569,6 +605,15 @@
569
605
  }
570
606
  }
571
607
  ],
608
+ [
609
+ "SetSceneControllers",
610
+ {
611
+ "http": {
612
+ "method": "POST",
613
+ "path": "/rooms/:roomId/sceneControllers/:id"
614
+ }
615
+ }
616
+ ],
572
617
  [
573
618
  "CreateSource",
574
619
  {
@@ -614,6 +659,15 @@
614
659
  }
615
660
  }
616
661
  ],
662
+ [
663
+ "SetSources",
664
+ {
665
+ "http": {
666
+ "method": "POST",
667
+ "path": "/rooms/:roomId/sources/:id"
668
+ }
669
+ }
670
+ ],
617
671
  [
618
672
  "CreateThermostat",
619
673
  {
@@ -659,6 +713,15 @@
659
713
  }
660
714
  }
661
715
  ],
716
+ [
717
+ "SetThermostats",
718
+ {
719
+ "http": {
720
+ "method": "POST",
721
+ "path": "/rooms/:roomId/thermostats/:id"
722
+ }
723
+ }
724
+ ],
662
725
  [
663
726
  "CreateWindowCovering",
664
727
  {
@@ -704,6 +767,15 @@
704
767
  }
705
768
  }
706
769
  ],
770
+ [
771
+ "SetWindowCoverings",
772
+ {
773
+ "http": {
774
+ "method": "POST",
775
+ "path": "/rooms/:roomId/windowCoverings/:id"
776
+ }
777
+ }
778
+ ],
707
779
  [
708
780
  "AddScenesToRoom",
709
781
  {
@@ -804,7 +876,7 @@
804
876
  }
805
877
  ],
806
878
  [
807
- "ScheduleGroupEcoScenes",
879
+ "ScheduleSpaceEcoScenes",
808
880
  {
809
881
  "http": false
810
882
  }
@@ -898,5 +970,129 @@
898
970
  "path": "/integrations/:id/deviceMap"
899
971
  }
900
972
  }
973
+ ],
974
+ [
975
+ "DescribeIntegration",
976
+ {
977
+ "http": {
978
+ "method": "GET",
979
+ "path": "/integrations/:id"
980
+ }
981
+ }
982
+ ],
983
+ [
984
+ "DeleteIntegration",
985
+ {
986
+ "http": {
987
+ "method": "GET",
988
+ "path": "/integrations/:id"
989
+ }
990
+ }
991
+ ],
992
+ [
993
+ "ListIntegrations",
994
+ {
995
+ "http": {
996
+ "method": "GET",
997
+ "path": "/integrations/"
998
+ }
999
+ }
1000
+ ],
1001
+ [
1002
+ "UpsertSystemDevice",
1003
+ {
1004
+ "http": false
1005
+ }
1006
+ ],
1007
+ [
1008
+ "UpsertSystemReservation",
1009
+ {
1010
+ "http": false
1011
+ }
1012
+ ],
1013
+ [
1014
+ "UpsertSystemSpace",
1015
+ {
1016
+ "http": false
1017
+ }
1018
+ ],
1019
+ [
1020
+ "UpsertSystemUser",
1021
+ {
1022
+ "http": false
1023
+ }
1024
+ ],
1025
+ [
1026
+ "CreateReservation",
1027
+ {
1028
+ "http": {
1029
+ "method": "POST",
1030
+ "path": "/reservations"
1031
+ }
1032
+ }
1033
+ ],
1034
+ [
1035
+ "DeleteReservation",
1036
+ {
1037
+ "http": {
1038
+ "method": "DELETE",
1039
+ "path": "/reservations/:id"
1040
+ }
1041
+ }
1042
+ ],
1043
+ [
1044
+ "ListReservations",
1045
+ {
1046
+ "http": {
1047
+ "method": "GET",
1048
+ "path": "/reservations"
1049
+ }
1050
+ }
1051
+ ],
1052
+ [
1053
+ "ListMyReservations",
1054
+ {
1055
+ "http": {
1056
+ "method": "GET",
1057
+ "path": "/reservations/mine"
1058
+ }
1059
+ }
1060
+ ],
1061
+ [
1062
+ "UpdateReservation",
1063
+ {
1064
+ "http": {
1065
+ "method": "PUT",
1066
+ "path": "/reservations/:id"
1067
+ }
1068
+ }
1069
+ ],
1070
+ [
1071
+ "DescribeReservation",
1072
+ {
1073
+ "http": {
1074
+ "method": "GET",
1075
+ "path": "/reservations/:id"
1076
+ }
1077
+ }
1078
+ ],
1079
+ [
1080
+ "VerifyDocument",
1081
+ {
1082
+ "http": {
1083
+ "method": "POST",
1084
+ "path": "/documents/verify",
1085
+ "maxSize": "2mb"
1086
+ }
1087
+ }
1088
+ ],
1089
+ [
1090
+ "DescribeMyProperty",
1091
+ {
1092
+ "http": {
1093
+ "method": "GET",
1094
+ "path": "/properties/mine"
1095
+ }
1096
+ }
901
1097
  ]
902
1098
  ]
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
+ });