@kohost/api-client 0.6.5-alpha.4 → 0.6.5-alpha.5
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/package.json +4 -1
- package/bitbucket-pipelines.yml +0 -24
- package/src/client.js +0 -263
- package/src/interceptors.js +0 -71
- package/src/methods/Admin.js +0 -3
- package/src/methods/Auth.js +0 -149
- package/src/methods/Commands.js +0 -12
- package/src/methods/Concierge.js +0 -50
- package/src/methods/Controller.js +0 -3
- package/src/methods/Group.js +0 -49
- package/src/methods/Guest.js +0 -25
- package/src/methods/HotelRoom.js +0 -88
- package/src/methods/Image.js +0 -14
- package/src/methods/Integrations.js +0 -56
- package/src/methods/Light.js +0 -5
- package/src/methods/Lock.js +0 -5
- package/src/methods/Manager.js +0 -3
- package/src/methods/Manifest.js +0 -11
- package/src/methods/Media.js +0 -28
- package/src/methods/Notifications.js +0 -18
- package/src/methods/Privacy.js +0 -5
- package/src/methods/Reports.js +0 -18
- package/src/methods/Room.js +0 -102
- package/src/methods/Settings.js +0 -16
- package/src/methods/Shade.js +0 -5
- package/src/methods/Source.js +0 -45
- package/src/methods/Structure.js +0 -20
- package/src/methods/Subscriptions.js +0 -21
- package/src/methods/Thermostat.js +0 -5
- package/src/methods/User.js +0 -72
- package/src/utils/generate.js +0 -156
- package/webpack.config.js +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kohost/api-client",
|
|
3
|
-
"version": "0.6.5-alpha.
|
|
3
|
+
"version": "0.6.5-alpha.5",
|
|
4
4
|
"description": "HTTP client to interact with Kohost APIs",
|
|
5
5
|
"main": "dist/bundle.node.js",
|
|
6
6
|
"module": "dist/bundle.js",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"kohost",
|
|
22
22
|
"api"
|
|
23
23
|
],
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/*.js"
|
|
26
|
+
],
|
|
24
27
|
"author": "Ian Rogers",
|
|
25
28
|
"license": "ISC",
|
|
26
29
|
"dependencies": {
|
package/bitbucket-pipelines.yml
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
image: node:12.14.1
|
|
2
|
-
|
|
3
|
-
pipelines:
|
|
4
|
-
pull-requests:
|
|
5
|
-
"**":
|
|
6
|
-
- step:
|
|
7
|
-
name: Install dependencies and build
|
|
8
|
-
caches:
|
|
9
|
-
- node
|
|
10
|
-
script:
|
|
11
|
-
- npm install
|
|
12
|
-
- npm run build
|
|
13
|
-
branches:
|
|
14
|
-
master:
|
|
15
|
-
- step:
|
|
16
|
-
name: Build and publish to NPM
|
|
17
|
-
caches:
|
|
18
|
-
- node
|
|
19
|
-
script:
|
|
20
|
-
- npm install
|
|
21
|
-
- npm run prepare
|
|
22
|
-
- pipe: atlassian/npm-publish:0.2.6
|
|
23
|
-
variables:
|
|
24
|
-
NPM_TOKEN: $NPM_TOKEN
|
package/src/client.js
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import merge from "lodash/merge";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import interceptors from "./interceptors";
|
|
4
|
-
import Admin from "./methods/Admin";
|
|
5
|
-
import Auth from "./methods/Auth";
|
|
6
|
-
import Concierge from "./methods/Concierge";
|
|
7
|
-
import Controllers from "./methods/Controller";
|
|
8
|
-
import Commands from "./methods/Commands";
|
|
9
|
-
import Group from "./methods/Group";
|
|
10
|
-
import Guest from "./methods/Guest";
|
|
11
|
-
import HotelRoom from "./methods/HotelRoom";
|
|
12
|
-
import Integrations from "./methods/Integrations";
|
|
13
|
-
import Image from "./methods/Image";
|
|
14
|
-
import Light from "./methods/Light";
|
|
15
|
-
import Privacy from "./methods/Privacy";
|
|
16
|
-
import Lock from "./methods/Lock";
|
|
17
|
-
import Manager from "./methods/Manager";
|
|
18
|
-
import Manifest from "./methods/Manifest";
|
|
19
|
-
import Media from "./methods/Media";
|
|
20
|
-
import Notifications from "./methods/Notifications";
|
|
21
|
-
import Reports from "./methods/Reports";
|
|
22
|
-
import Room from "./methods/Room";
|
|
23
|
-
import Settings from "./methods/Settings";
|
|
24
|
-
import Shade from "./methods/Shade";
|
|
25
|
-
import Source from "./methods/Source";
|
|
26
|
-
import Structure from "./methods/Structure";
|
|
27
|
-
import Subscriptions from "./methods/Subscriptions";
|
|
28
|
-
import Thermostat from "./methods/Thermostat";
|
|
29
|
-
import User from "./methods/User";
|
|
30
|
-
|
|
31
|
-
class KohostAPIClient {
|
|
32
|
-
constructor(url) {
|
|
33
|
-
this.config = {
|
|
34
|
-
url: url,
|
|
35
|
-
version: 2,
|
|
36
|
-
lsAuthTokenKey: "x-auth-token",
|
|
37
|
-
lsRefreshTokenKey: "x-refresh-token",
|
|
38
|
-
lsUserKey: "current-user",
|
|
39
|
-
clientId: undefined,
|
|
40
|
-
secretKey: undefined,
|
|
41
|
-
autoRefreshTokens: true,
|
|
42
|
-
tenant: null,
|
|
43
|
-
onNewToken: function () {},
|
|
44
|
-
onLoginRequired: function () {
|
|
45
|
-
throw new Error("API Client - login required");
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
this.isBrowser = typeof window !== "undefined";
|
|
49
|
-
this.authTokenKey = "x-auth-token";
|
|
50
|
-
this.refreshTokenKey = "x-refresh-token";
|
|
51
|
-
this.http = undefined;
|
|
52
|
-
this.authToken = "";
|
|
53
|
-
this.currentUser = undefined;
|
|
54
|
-
this.logger = console;
|
|
55
|
-
// bind methods
|
|
56
|
-
this.config.update = this.updateConfig.bind(this);
|
|
57
|
-
this.handleHTTPResponseError = interceptors.handleHTTPError.bind(this);
|
|
58
|
-
this.handleHTTPResponseSuccess = interceptors.handleHTTPResponse.bind(this);
|
|
59
|
-
this.handleHTTPRequestConfig = interceptors.handleGenerateConfig.bind(this);
|
|
60
|
-
|
|
61
|
-
this.Admin = this.bindMethods(Admin);
|
|
62
|
-
this.Auth = this.bindMethods(Auth);
|
|
63
|
-
|
|
64
|
-
this.Guest = this.bindMethods(Guest);
|
|
65
|
-
this.User = this.bindMethods(User);
|
|
66
|
-
|
|
67
|
-
this.Group = this.bindMethods(Group);
|
|
68
|
-
this.Group.Integrations = this.bindMethods(Group.Integrations);
|
|
69
|
-
this.Group.Room = this.bindMethods(Group.Room);
|
|
70
|
-
this.Group.Room.Light = this.bindMethods(Group.Room.Light);
|
|
71
|
-
this.Group.Room.Shade = this.bindMethods(Group.Room.Shade);
|
|
72
|
-
this.Group.Room.Thermostat = this.bindMethods(Group.Room.Thermostat);
|
|
73
|
-
this.Group.Room.Media = this.bindMethods(Group.Room.Media);
|
|
74
|
-
this.Group.Room.Privacy = this.bindMethods(Group.Room.Privacy);
|
|
75
|
-
this.Group.Room.Security = this.bindMethods(Group.Room.Security);
|
|
76
|
-
this.Group.Room.Security.Locks = this.bindMethods(
|
|
77
|
-
Group.Room.Security.Locks
|
|
78
|
-
);
|
|
79
|
-
this.Group.Room.Security.Cameras = this.bindMethods(
|
|
80
|
-
Group.Room.Security.Cameras
|
|
81
|
-
);
|
|
82
|
-
this.Group.Room.Security.Alarms = this.bindMethods(
|
|
83
|
-
Group.Room.Security.Alarms
|
|
84
|
-
);
|
|
85
|
-
this.HotelRoom = this.bindMethods(HotelRoom);
|
|
86
|
-
|
|
87
|
-
this.HotelRoom.Room = this.bindMethods(HotelRoom.Room);
|
|
88
|
-
this.HotelRoom.Guest = this.bindMethods(HotelRoom.Guest);
|
|
89
|
-
this.HotelRoom.Alarms = this.bindMethods(HotelRoom.Alarms);
|
|
90
|
-
this.HotelRoom.Scenes = this.bindMethods(HotelRoom.Scenes);
|
|
91
|
-
this.HotelRoom.Integrations = this.bindMethods(HotelRoom.Integrations);
|
|
92
|
-
|
|
93
|
-
this.Room = this.bindMethods(Room);
|
|
94
|
-
this.Room.Light = this.bindMethods(Light);
|
|
95
|
-
this.Room.Shade = this.bindMethods(Shade);
|
|
96
|
-
this.Room.Thermostat = this.bindMethods(Thermostat);
|
|
97
|
-
this.Room.Lock = this.bindMethods(Lock);
|
|
98
|
-
this.Room.Privacy = this.bindMethods(Privacy);
|
|
99
|
-
this.Room.Scenes = this.bindMethods(Room.Scenes);
|
|
100
|
-
this.Room.Media = this.bindMethods(Room.Media);
|
|
101
|
-
this.Room.Security = this.bindMethods(Room.Security);
|
|
102
|
-
this.Room.Security.Locks = this.bindMethods(Room.Security.Locks);
|
|
103
|
-
this.Room.Security.Cameras = this.bindMethods(Room.Security.Cameras);
|
|
104
|
-
|
|
105
|
-
this.Settings = this.bindMethods(Settings);
|
|
106
|
-
this.Subscriptions = this.bindMethods(Subscriptions);
|
|
107
|
-
this.Reports = this.bindMethods(Reports);
|
|
108
|
-
this.Controllers = this.bindMethods(Controllers);
|
|
109
|
-
|
|
110
|
-
this.Integrations = this.bindMethods(Integrations);
|
|
111
|
-
this.Integrations.Types = this.bindMethods(Integrations.Types);
|
|
112
|
-
this.Integrations.RoomMap = this.bindMethods(Integrations.RoomMap);
|
|
113
|
-
this.Integrations.Metadata = this.bindMethods(Integrations.Metadata);
|
|
114
|
-
this.Integrations.DeviceMap = this.bindMethods(Integrations.DeviceMap);
|
|
115
|
-
this.Concierge = this.bindMethods(Concierge);
|
|
116
|
-
this.Commands = this.bindMethods(Commands);
|
|
117
|
-
this.Image = this.bindMethods(Image);
|
|
118
|
-
this.Source = this.bindMethods(Source);
|
|
119
|
-
this.Source.browse = this.bindMethods(Source.browse);
|
|
120
|
-
this.Source.browse.genres = this.bindMethods(Source.browse.genres);
|
|
121
|
-
this.Source.browse.stations = this.bindMethods(Source.browse.stations);
|
|
122
|
-
this.Structure = this.bindMethods(Structure);
|
|
123
|
-
this.Structure.Images = this.bindMethods(Image);
|
|
124
|
-
this.Media = this.bindMethods(Media);
|
|
125
|
-
this.Manifest = this.bindMethods(Manifest);
|
|
126
|
-
this.Manager = this.bindMethods(Manager);
|
|
127
|
-
|
|
128
|
-
this.Notifications = this.bindMethods(Notifications);
|
|
129
|
-
|
|
130
|
-
this.createHTTPClient();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
bindMethods(funcObject) {
|
|
134
|
-
const bindMethod = (func) => {
|
|
135
|
-
return func.bind(this);
|
|
136
|
-
};
|
|
137
|
-
const boundMethods = {};
|
|
138
|
-
Object.keys(funcObject).forEach((method) => {
|
|
139
|
-
if (typeof funcObject[method] !== "function") return;
|
|
140
|
-
boundMethods[method] = bindMethod(funcObject[method]);
|
|
141
|
-
});
|
|
142
|
-
return boundMethods;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
updateConfig(config) {
|
|
146
|
-
this.config = merge(this.config, config);
|
|
147
|
-
this.createHTTPClient();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
createHTTPClient() {
|
|
151
|
-
this.http = axios.create({
|
|
152
|
-
baseURL: this.config.url,
|
|
153
|
-
headers: {
|
|
154
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
155
|
-
"x-tenant-id": this.config.tenant,
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
this.http.interceptors.response.use(
|
|
160
|
-
this.handleHTTPResponseSuccess,
|
|
161
|
-
this.handleHTTPResponseError
|
|
162
|
-
);
|
|
163
|
-
this.http.interceptors.request.use(this.handleHTTPRequestConfig, null);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
getItem(key) {
|
|
167
|
-
if (this.isBrowser) {
|
|
168
|
-
try {
|
|
169
|
-
return JSON.parse(localStorage.getItem(key));
|
|
170
|
-
} catch (error) {
|
|
171
|
-
return localStorage.getItem(key);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
saveItem(key, data) {
|
|
177
|
-
if (this.isBrowser) {
|
|
178
|
-
if (typeof data === "object") data = JSON.stringify(data);
|
|
179
|
-
localStorage.setItem(key, data);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
removeItem(key) {
|
|
184
|
-
if (this.isBrowser) {
|
|
185
|
-
localStorage.removeItem(key);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
setAuthToken(token) {
|
|
190
|
-
this.authToken = token;
|
|
191
|
-
this.saveItem(this.config.lsAuthTokenKey, token);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
setRefreshToken(token) {
|
|
195
|
-
this.refreshToken = token;
|
|
196
|
-
this.saveItem(this.config.lsRefreshTokenKey, token);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
setCurrentUser(user) {
|
|
200
|
-
this.currentUser = user;
|
|
201
|
-
this.saveItem(this.config.lsUserKey, user);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
getAuthToken() {
|
|
205
|
-
if (this.isBrowser) return this.getItem(this.config.lsAuthTokenKey);
|
|
206
|
-
return this.authToken;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
getRefreshToken() {
|
|
210
|
-
if (this.isBrowser) return this.getItem(this.config.lsRefreshTokenKey);
|
|
211
|
-
return this.refreshToken;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
getCurrentUser() {
|
|
215
|
-
if (this.isBrowser) return this.getItem(this.config.lsUserKey);
|
|
216
|
-
return this.currentUser;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
handleLoginRequired() {
|
|
220
|
-
return this.config.onLoginRequired();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
handleNewToken(token) {
|
|
224
|
-
return this.config.onNewToken(token);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
handleLogAndNotifyError(error) {
|
|
228
|
-
this.logger.log(error);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
get(url, options = {}) {
|
|
232
|
-
return this.http.get(url, options);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
post(url, body, options = {}) {
|
|
236
|
-
return this.http.post(url, body, options);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
put(url, body, options = {}) {
|
|
240
|
-
return this.http.put(url, body, options);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
delete(url, body, options = {}) {
|
|
244
|
-
options.data = body;
|
|
245
|
-
return this.http.delete(url, options);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
uploadFile(url, formData, uploadHandler = function () {}) {
|
|
249
|
-
return this.http({
|
|
250
|
-
method: "POST",
|
|
251
|
-
url,
|
|
252
|
-
data: formData,
|
|
253
|
-
onUploadProgress: uploadHandler,
|
|
254
|
-
headers: {
|
|
255
|
-
"Content-Type": `multipart/form-data; boundary=${formData._boundary}`,
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const API = new KohostAPIClient();
|
|
262
|
-
|
|
263
|
-
export default API;
|
package/src/interceptors.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
function handleHTTPError(error) {
|
|
2
|
-
const { config: originalReq } = error;
|
|
3
|
-
if (!error.response) return Promise.reject(error);
|
|
4
|
-
const { status, data } = error.response;
|
|
5
|
-
const errorCode = data && data.error && data.error.code;
|
|
6
|
-
const errorMessage = data && data.error && data.error.message;
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
const expectedError = status >= 400 && status < 500;
|
|
10
|
-
if (!expectedError) this.handleLogAndNotifyError(error);
|
|
11
|
-
|
|
12
|
-
if (errorMessage && errorMessage === "Login Required") {
|
|
13
|
-
this.handleLoginRequired();
|
|
14
|
-
return Promise.reject(error);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// prettier-ignore
|
|
18
|
-
const newTokensNeeded = expectedError && errorCode === 1004 && status === 401
|
|
19
|
-
|
|
20
|
-
if (status === 401 && !newTokensNeeded) {
|
|
21
|
-
return Promise.reject(error);
|
|
22
|
-
}
|
|
23
|
-
if (status === 400 && errorCode === 1010) {
|
|
24
|
-
this.handleLoginRequired();
|
|
25
|
-
return Promise.reject(error);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (newTokensNeeded) {
|
|
29
|
-
return this.Auth.requestNewTokens().then((response) => {
|
|
30
|
-
// update headers with the new tokens
|
|
31
|
-
if (
|
|
32
|
-
response &&
|
|
33
|
-
response.headers &&
|
|
34
|
-
response.headers[this.authTokenKey]
|
|
35
|
-
) {
|
|
36
|
-
const newToken = response.headers[this.authTokenKey];
|
|
37
|
-
originalReq.headers[this.authTokenKey] = newToken;
|
|
38
|
-
this.handleNewToken(newToken);
|
|
39
|
-
return this.http(originalReq);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
} catch (error) {
|
|
44
|
-
this.handleLogAndNotifyError(error);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return Promise.reject(error);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function handleHTTPResponse(response) {
|
|
51
|
-
if (response && response.data && response.data.data) {
|
|
52
|
-
response.query = response.data.query;
|
|
53
|
-
response.pagination = response.data.pagination;
|
|
54
|
-
response.data = response.data.data;
|
|
55
|
-
}
|
|
56
|
-
return response;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function handleGenerateConfig(config) {
|
|
60
|
-
if (this.config.secretKey && this.config.clientId) {
|
|
61
|
-
config.headers["clientId"] = this.config.clientId;
|
|
62
|
-
config.headers["secretKey"] = this.config.secretKey;
|
|
63
|
-
} else config.headers[this.authTokenKey] = this.getAuthToken();
|
|
64
|
-
return config;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default {
|
|
68
|
-
handleHTTPError,
|
|
69
|
-
handleHTTPResponse,
|
|
70
|
-
handleGenerateConfig,
|
|
71
|
-
};
|
package/src/methods/Admin.js
DELETED
package/src/methods/Auth.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
const base = "/auth";
|
|
2
|
-
|
|
3
|
-
function setTokensFromResponse(response) {
|
|
4
|
-
if (response && response.headers) {
|
|
5
|
-
const authToken = response.headers[this.authTokenKey];
|
|
6
|
-
const refreshToken = response.headers[this.refreshTokenKey];
|
|
7
|
-
if (authToken) this.setAuthToken(authToken);
|
|
8
|
-
if (refreshToken) this.setRefreshToken(refreshToken);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function requestNewTokens() {
|
|
13
|
-
const setTokens = setTokensFromResponse.bind(this);
|
|
14
|
-
if (!this.getRefreshToken()) return this.handleLoginRequired();
|
|
15
|
-
return this.post(
|
|
16
|
-
`${base}/token`,
|
|
17
|
-
{},
|
|
18
|
-
{
|
|
19
|
-
headers: {
|
|
20
|
-
[this.refreshTokenKey]: this.getRefreshToken(),
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
).then((response) => {
|
|
24
|
-
setTokens(response);
|
|
25
|
-
return response;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function loginUser(email, password) {
|
|
30
|
-
const setTokens = setTokensFromResponse.bind(this);
|
|
31
|
-
const url = `${base}/user`;
|
|
32
|
-
return this.post(url, { email: email.toLowerCase(), password }).then(
|
|
33
|
-
(response) => {
|
|
34
|
-
setTokens(response);
|
|
35
|
-
const user = response && response.data && response.data[0];
|
|
36
|
-
if (user) this.setCurrentUser(user);
|
|
37
|
-
return response;
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function loginGuest(lastName, roomNumber, phone) {
|
|
43
|
-
const setTokens = setTokensFromResponse.bind(this);
|
|
44
|
-
const url = `${base}/guest`;
|
|
45
|
-
return this.post(url, { lastName, roomNumber, phone }).then((response) => {
|
|
46
|
-
setTokens(response);
|
|
47
|
-
const user = response && response.data && response.data[0];
|
|
48
|
-
if (user) this.setCurrentUser(user);
|
|
49
|
-
return response;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function resetPassword(userID, password, token) {
|
|
54
|
-
const url = base + `/${userID}/set-password`;
|
|
55
|
-
let options = {};
|
|
56
|
-
if (token) {
|
|
57
|
-
options.headers = {
|
|
58
|
-
"x-reset-token": token,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return this.post(url, { password }, options).then((response) => {
|
|
63
|
-
if (response.status >= 400 && response.status <= 500) {
|
|
64
|
-
body.error = response.data.error;
|
|
65
|
-
return body;
|
|
66
|
-
} else {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function verifyToken(token) {
|
|
73
|
-
const url = base + `/verifyToken`;
|
|
74
|
-
return this.post(url, { token }).then((response) => {
|
|
75
|
-
if (response.status >= 400 && response.status <= 500) {
|
|
76
|
-
body.error = response.data.error;
|
|
77
|
-
return body;
|
|
78
|
-
} else {
|
|
79
|
-
return response;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function sendResetPasswordLink(userId) {
|
|
85
|
-
const url = base + `/${userId}/sendResetPasswordLink`;
|
|
86
|
-
return this.post(url, {}).then((response) => {
|
|
87
|
-
if (response.status >= 400 && response.status <= 500) {
|
|
88
|
-
body.error = response.data.error;
|
|
89
|
-
return body;
|
|
90
|
-
} else {
|
|
91
|
-
return response;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function forgotPassword(email) {
|
|
97
|
-
const url = `/users/forgot-password`;
|
|
98
|
-
return this.post(url, { email }).then((response) => {
|
|
99
|
-
if (response.status >= 400 && response.status <= 500) {
|
|
100
|
-
body.error = response.data.error;
|
|
101
|
-
return body;
|
|
102
|
-
} else {
|
|
103
|
-
return response;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getNewControllerAuthToken(authKey, controllerId) {
|
|
109
|
-
const setTokens = setTokensFromResponse.bind(this);
|
|
110
|
-
const url = `${base}/controller`;
|
|
111
|
-
|
|
112
|
-
return this.post(url, { authKey, controllerId })
|
|
113
|
-
.then((response) => {
|
|
114
|
-
if (response.status >= 400 && response.status <= 500) {
|
|
115
|
-
body.error = response.data.error;
|
|
116
|
-
return body;
|
|
117
|
-
} else {
|
|
118
|
-
setTokens(response);
|
|
119
|
-
return response;
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
.catch((error) => {
|
|
123
|
-
console.log("error", error);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function logout() {
|
|
128
|
-
this.setAuthToken(null);
|
|
129
|
-
this.setRefreshToken(null);
|
|
130
|
-
this.setCurrentUser(null);
|
|
131
|
-
this.removeItem(this.config.lsAuthTokenKey);
|
|
132
|
-
this.removeItem(this.config.lsRefreshTokenKey);
|
|
133
|
-
this.removeItem(this.config.lsUserKey);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const Auth = {
|
|
137
|
-
requestNewTokens,
|
|
138
|
-
loginUser,
|
|
139
|
-
loginGuest,
|
|
140
|
-
resetPassword,
|
|
141
|
-
verifyToken,
|
|
142
|
-
sendResetPasswordLink,
|
|
143
|
-
forgotPassword,
|
|
144
|
-
getNewControllerAuthToken,
|
|
145
|
-
logout,
|
|
146
|
-
setTokensFromResponse,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export default Auth;
|
package/src/methods/Commands.js
DELETED
package/src/methods/Concierge.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import generateFunctions from "../utils/generate";
|
|
2
|
-
|
|
3
|
-
const base = "/concierge";
|
|
4
|
-
|
|
5
|
-
function getTickets(body) {
|
|
6
|
-
const url = `${base}/tickets`;
|
|
7
|
-
return this.get(url, body);
|
|
8
|
-
}
|
|
9
|
-
function createTicket(body) {
|
|
10
|
-
const url = `${base}/tickets`;
|
|
11
|
-
return this.post(url, body);
|
|
12
|
-
}
|
|
13
|
-
function getPendingTickets(body) {
|
|
14
|
-
const url = `${base}/tickets/pending`;
|
|
15
|
-
return this.post(url, body);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function closeTickets(body) {
|
|
19
|
-
const url = `${base}/tickets/close`;
|
|
20
|
-
return this.post(url, body);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function updateTicket(ticketId,body) {
|
|
24
|
-
const url = `${base}/tickets/${ticketId}`;
|
|
25
|
-
return this.put(url, body);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function markAsRead(ticketId,body) {
|
|
29
|
-
const url = `${base}/tickets/${ticketId}/read`;
|
|
30
|
-
return this.post(url, body);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function postMessage(ticketId,body) {
|
|
34
|
-
const url = `${base}/tickets/${ticketId}/message`;
|
|
35
|
-
return this.post(url, body);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const Concierge = generateFunctions(base);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Concierge.getTickets = getTickets;
|
|
43
|
-
Concierge.createTicket = createTicket;
|
|
44
|
-
Concierge.getPendingTickets = getPendingTickets;
|
|
45
|
-
Concierge.closeTickets = closeTickets;
|
|
46
|
-
Concierge.updateTicket = updateTicket;
|
|
47
|
-
Concierge.markAsRead = markAsRead;
|
|
48
|
-
Concierge.postMessage = postMessage;
|
|
49
|
-
|
|
50
|
-
export default Concierge;
|
package/src/methods/Group.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import generateFunctions, {
|
|
2
|
-
generateGroupRoomFunctions,
|
|
3
|
-
generateGroupDeviceFunctions,
|
|
4
|
-
} from "../utils/generate";
|
|
5
|
-
|
|
6
|
-
const base = "/groups";
|
|
7
|
-
const Group = generateFunctions(base);
|
|
8
|
-
|
|
9
|
-
Group.Room = generateGroupRoomFunctions();
|
|
10
|
-
Group.Room.Light = generateGroupDeviceFunctions("lights");
|
|
11
|
-
Group.Room.Shade = generateGroupDeviceFunctions("shades");
|
|
12
|
-
Group.Room.Thermostat = generateGroupDeviceFunctions("thermostats");
|
|
13
|
-
Group.Room.Privacy = generateGroupDeviceFunctions("privacy");
|
|
14
|
-
Group.Room.Media = {
|
|
15
|
-
get: function (groupId, roomId) {
|
|
16
|
-
const url = `${base}/${groupId}/rooms/${roomId}/media`;
|
|
17
|
-
return this.get(url);
|
|
18
|
-
},
|
|
19
|
-
update: function (groupId, roomId, body) {
|
|
20
|
-
const url = `${base}/${groupId}/rooms/${roomId}/media`;
|
|
21
|
-
return this.put(url, body);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
Group.Room.Security = {
|
|
25
|
-
get: function (groupId, roomId) {
|
|
26
|
-
const url = `${base}/${groupId}/rooms/${roomId}/security`;
|
|
27
|
-
return this.get(url);
|
|
28
|
-
},
|
|
29
|
-
Locks: generateGroupDeviceFunctions("security/locks"),
|
|
30
|
-
Cameras: generateGroupDeviceFunctions("security/cameras"),
|
|
31
|
-
Alarms: generateGroupDeviceFunctions("security/alarms"),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
Group.Integrations = {
|
|
35
|
-
getAll: function (groupId) {
|
|
36
|
-
const url = `${base}/${groupId}/integrations`;
|
|
37
|
-
return this.get(url);
|
|
38
|
-
},
|
|
39
|
-
add: function (groupId, body) {
|
|
40
|
-
const url = `${base}/${groupId}/integrations`;
|
|
41
|
-
return this.post(url, body);
|
|
42
|
-
},
|
|
43
|
-
delete: function (groupId, integrationId) {
|
|
44
|
-
const url = `${base}/${groupId}/integrations/${integrationId}`;
|
|
45
|
-
return this.delete(url);
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default Group;
|
package/src/methods/Guest.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import generateFunctions from "../utils/generate";
|
|
2
|
-
|
|
3
|
-
const base = "/guests";
|
|
4
|
-
|
|
5
|
-
function checkInGuest(id, body) {
|
|
6
|
-
const url = `${base}/${id}/checkin`;
|
|
7
|
-
return this.post(url, body);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function checkOutGuest(id, body) {
|
|
11
|
-
const url = `${base}/${id}/checkout`;
|
|
12
|
-
return this.post(url, body);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function invite(id) {
|
|
16
|
-
const url = `${base}/${id}/invite`;
|
|
17
|
-
return this.post(url);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const Guest = generateFunctions(base);
|
|
21
|
-
Guest.checkIn = checkInGuest;
|
|
22
|
-
Guest.checkOut = checkOutGuest;
|
|
23
|
-
Guest.invite = invite;
|
|
24
|
-
|
|
25
|
-
export default Guest;
|