@kohost/api-client 0.6.5-alpha.4 → 0.7.0

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.
@@ -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
- };
@@ -1,3 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- export default generateFunctions("/admins");
@@ -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;
@@ -1,12 +0,0 @@
1
- let base = "/commands";
2
-
3
- function post(body) {
4
- const url = base;
5
- return this.post(url, body);
6
- }
7
-
8
- const command = {
9
- post,
10
- };
11
-
12
- export default command;
@@ -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;
@@ -1,3 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- export default generateFunctions("/controllers");
@@ -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;
@@ -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;
@@ -1,88 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- const base = "/hotel-rooms";
4
- const HotelRoom = generateFunctions(base);
5
-
6
- HotelRoom.Room = {
7
- getAll: function getRooms(hotelRoomId) {
8
- const url = `${base}/${hotelRoomId}/rooms`;
9
- return this.get(url);
10
- },
11
- add: function addRoom(hotelRoomId, body) {
12
- const url = `${base}/${hotelRoomId}/rooms`;
13
- return this.post(url, body);
14
- },
15
- delete: function deleteRooms(hotelRoomId, body) {
16
- const url = `${base}/${hotelRoomId}/rooms`;
17
- return this.delete(url, body);
18
- },
19
- };
20
- HotelRoom.Guest = {
21
- getAll: function getGuests(hotelRoomId) {
22
- const url = `${base}/${hotelRoomId}/guests`;
23
- return this.get(url);
24
- },
25
- };
26
-
27
- HotelRoom.Scenes = {
28
- getAll: function (roomId) {
29
- const url = `${base}/${roomId}/scenes`;
30
- return this.get(url);
31
- },
32
- get: function (roomId, id) {
33
- const url = `${base}/${roomId}/scenes/${id}`;
34
- return this.get(url);
35
- },
36
- trigger: function (roomId, id) {
37
- const url = `${base}/${roomId}/scenes/${id}/trigger`;
38
- return this.post(url, {});
39
- },
40
- update: function (roomId, id, body) {
41
- const url = `${base}/${roomId}/scenes/${id}`;
42
- return this.put(url, body);
43
- },
44
- add: function (roomId, body) {
45
- const url = `${base}/${roomId}/scenes`;
46
- return this.post(url, body);
47
- },
48
- delete: function (roomId, id) {
49
- const url = `${base}/${roomId}/scenes/${id}`;
50
- return this.delete(url);
51
- },
52
- };
53
-
54
- HotelRoom.Integrations = {
55
- getAll: function (roomId) {
56
- const url = `${base}/${roomId}/integrations`;
57
- return this.get(url);
58
- },
59
- add: function (roomId, body) {
60
- const url = `${base}/${roomId}/integrations`;
61
- return this.post(url, body);
62
- },
63
- delete: function (roomId, id) {
64
- const url = `${base}/${roomId}/integrations/${id}`;
65
- return this.delete(url);
66
- },
67
- };
68
-
69
- HotelRoom.Alarms = {
70
- getAll: function (roomId) {
71
- const url = `${base}/${roomId}/alarms`;
72
- return this.get(url);
73
- },
74
- get: function (roomId, id) {
75
- const url = `${base}/${roomId}/alarms/${id}`;
76
- return this.get(url);
77
- },
78
- add: function (roomId, body) {
79
- const url = `${base}/${roomId}/alarms`;
80
- return this.post(url, body);
81
- },
82
- delete: function (roomId, id) {
83
- const url = `${base}/${roomId}/alarms/${id}`;
84
- return this.delete(url);
85
- },
86
- };
87
-
88
- export default HotelRoom;
@@ -1,14 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- const images = generateFunctions("structure/images");
4
-
5
- async function uploadImage(formData, callbackFn) {
6
- return await this.uploadFile(
7
- "/structure/images/upload",
8
- formData,
9
- callbackFn
10
- );
11
- }
12
-
13
- images.uploadImage = uploadImage;
14
- export default images;
@@ -1,56 +0,0 @@
1
- let base = "/integrations";
2
-
3
- const Integrations = {
4
- getAll: function () {
5
- return this.get(base);
6
- },
7
- get: function (id) {
8
- const url = `${base}/${id}`;
9
- return this.get(url);
10
- },
11
- update: function (id, body) {
12
- const url = `${base}/${id}`;
13
- return this.put(url, body);
14
- },
15
- add: function (body) {
16
- return this.post(base, body);
17
- },
18
- };
19
-
20
- const types = {
21
- getAll: function () {
22
- return this.get(`${base}/types`);
23
- },
24
- };
25
-
26
- const deviceMap = {
27
- add: function (integrationId, data) {
28
- return this.post(`${base}/${integrationId}/deviceMap`, data);
29
- },
30
- delete: function (integrationId, data) {
31
- return this.delete(`${base}/${integrationId}/deviceMap`, data);
32
- },
33
- };
34
-
35
- const roomMap = {
36
- add: function (integrationId, data) {
37
- return this.post(`${base}/${integrationId}/roomMap`, data);
38
- },
39
- delete: function (integrationId, data) {
40
- return this.delete(`${base}/${integrationId}/roomMap`, data);
41
- },
42
- };
43
-
44
- const metadata = {
45
- update: function (integrationId, body) {
46
- const url = `${base}/${integrationId}/metadata`;
47
- return this.post(url, body);
48
- },
49
- };
50
-
51
- Integrations.Types = types;
52
- Integrations.RoomMap = roomMap;
53
- Integrations.Metadata = metadata;
54
- Integrations.DeviceMap = deviceMap;
55
-
56
- export default Integrations;
@@ -1,5 +0,0 @@
1
- import { generateDeviceFunctions } from "../utils/generate";
2
-
3
- const Light = generateDeviceFunctions("lights");
4
-
5
- export default Light;
@@ -1,5 +0,0 @@
1
- import { generateDeviceFunctions } from "../utils/generate";
2
-
3
- const Lock = generateDeviceFunctions("security/locks");
4
-
5
- export default Lock;
@@ -1,3 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- export default generateFunctions("/managers");
@@ -1,11 +0,0 @@
1
- const base = "/manifest.json";
2
-
3
- const Manifest = {};
4
-
5
- function get() {
6
- return this.get(base);
7
- }
8
-
9
- Manifest.get = get;
10
-
11
- export default Manifest;
@@ -1,28 +0,0 @@
1
- const base = "/media/sources";
2
- const MediaSources = function generateFunctions() {
3
- return {
4
- getAll: function (room) {
5
- return this.get(`/rooms/${room}/media/sources`);
6
- },
7
- get: function (room,id) {
8
- return this.get(`/rooms/${room}/media/sources/${id}`);
9
- },
10
- add: function (room,body) {
11
- return this.post(`/rooms/${room}/media/sources`, body);
12
- },
13
- };
14
- };
15
-
16
- function getGenres(room, currentSource) {
17
- const url = `/rooms/${room}/media/sources/${currentSource}/browse/genres`;
18
- return this.http.get(url, {});
19
- }
20
-
21
- function getStations(room, currentSource) {
22
- const url = `/rooms/${room}/media/sources/${currentSource}/browse/stations`;
23
- return this.http.get(url, {});
24
- }
25
-
26
- MediaSources.getGenres = getGenres;
27
- MediaSources.getStations = getStations;
28
- export default MediaSources;
@@ -1,18 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- const base = "/notifications";
4
- const Notifications = generateFunctions(base);
5
-
6
- function getResponse(data) {
7
- const url = `${base}/response`;
8
- return this.http.post(url, { params: data });
9
- }
10
- function send(id,data) {
11
- const url = `${base}/${id}`;
12
- return this.http.post(url, { params: data });
13
- }
14
-
15
-
16
- Notifications.Response = getResponse;
17
- Notifications.Send = send;
18
- export default Notifications;
@@ -1,5 +0,0 @@
1
- import { generateDeviceFunctions } from "../utils/generate";
2
-
3
- const Privacy = generateDeviceFunctions("privacy");
4
-
5
- export default Privacy;
@@ -1,18 +0,0 @@
1
- import generateFunctions from "../utils/generate";
2
-
3
- const base = "/reports";
4
- const Reports = generateFunctions(base);
5
-
6
- function getEnergyStats(data) {
7
- const url = `${base}/room/stats`;
8
- return this.http.get(url, { params: data });
9
- }
10
-
11
- function getTicketStats(data) {
12
- const url = `${base}/ticket/stats`;
13
- return this.http.get(url, { params: data });
14
- }
15
-
16
- Reports.getEnergyStats = getEnergyStats;
17
- Reports.getTicketStats = getTicketStats;
18
- export default Reports;