homey-api 1.6.0 → 1.6.1
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/lib/AthomCloudAPI.js +12 -8
- package/lib/Util.js +45 -7
- package/package.json +1 -1
package/lib/AthomCloudAPI.js
CHANGED
|
@@ -304,10 +304,11 @@ for(const device of Object.values(devices)) {
|
|
|
304
304
|
body.append('grant_type', 'client_credentials');
|
|
305
305
|
|
|
306
306
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
307
|
-
body,
|
|
307
|
+
body: body.toString(),
|
|
308
308
|
method: 'post',
|
|
309
309
|
headers: {
|
|
310
|
-
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
310
|
+
'Authorization': `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
311
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
311
312
|
},
|
|
312
313
|
});
|
|
313
314
|
|
|
@@ -358,10 +359,11 @@ for(const device of Object.values(devices)) {
|
|
|
358
359
|
body.append('code', code);
|
|
359
360
|
|
|
360
361
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
361
|
-
body,
|
|
362
|
+
body: body.toString(),
|
|
362
363
|
method: 'post',
|
|
363
364
|
headers: {
|
|
364
|
-
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
365
|
+
'Authorization': `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
366
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
365
367
|
},
|
|
366
368
|
});
|
|
367
369
|
|
|
@@ -418,10 +420,11 @@ for(const device of Object.values(devices)) {
|
|
|
418
420
|
body.append('password', password);
|
|
419
421
|
|
|
420
422
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
421
|
-
body,
|
|
423
|
+
body: body.toString(),
|
|
422
424
|
method: 'post',
|
|
423
425
|
headers: {
|
|
424
|
-
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
426
|
+
'Authorization': `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
427
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
425
428
|
},
|
|
426
429
|
});
|
|
427
430
|
|
|
@@ -462,10 +465,11 @@ for(const device of Object.values(devices)) {
|
|
|
462
465
|
body.append('refresh_token', this.__token.refresh_token);
|
|
463
466
|
|
|
464
467
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
465
|
-
body,
|
|
468
|
+
body: body.toString(),
|
|
466
469
|
method: 'post',
|
|
467
470
|
headers: {
|
|
468
|
-
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
471
|
+
'Authorization': `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
472
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
469
473
|
},
|
|
470
474
|
});
|
|
471
475
|
|
package/lib/Util.js
CHANGED
|
@@ -22,7 +22,6 @@ class Util {
|
|
|
22
22
|
return fetch(...args);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// If in a browser
|
|
26
25
|
if (this.isBrowser()) {
|
|
27
26
|
return window.fetch(...args);
|
|
28
27
|
}
|
|
@@ -138,19 +137,58 @@ class Util {
|
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
/**
|
|
140
|
+
* This method encodes a string into a base64 string.
|
|
141
|
+
* It's provided as Util because Node.js uses `Buffer`,
|
|
142
|
+
* browsers use `btoa` and React Native doesn't provide anything.
|
|
141
143
|
* @param {string} input - Input
|
|
142
144
|
* @returns {string} - Base64 encoded output
|
|
143
145
|
*/
|
|
144
|
-
static base64(
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
static base64(s) {
|
|
147
|
+
function btoaLookup(index) {
|
|
148
|
+
if (index >= 0 && index < 64) {
|
|
149
|
+
const keystr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
150
|
+
return keystr[index];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the tests.
|
|
154
|
+
return undefined;
|
|
147
155
|
}
|
|
148
156
|
|
|
149
|
-
if (typeof
|
|
150
|
-
|
|
157
|
+
if (typeof s !== 'string') {
|
|
158
|
+
throw new Error('Invalid Input');
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
|
|
161
|
+
let i;
|
|
162
|
+
|
|
163
|
+
// "The btoa() method must throw an "InvalidCharacterError" DOMException if
|
|
164
|
+
// data contains any character whose code point is greater than U+00FF."
|
|
165
|
+
for (i = 0; i < s.length; i++) {
|
|
166
|
+
if (s.charCodeAt(i) > 255) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let out = '';
|
|
171
|
+
for (i = 0; i < s.length; i += 3) {
|
|
172
|
+
const groupsOfSix = [undefined, undefined, undefined, undefined];
|
|
173
|
+
groupsOfSix[0] = s.charCodeAt(i) >> 2;
|
|
174
|
+
groupsOfSix[1] = (s.charCodeAt(i) & 0x03) << 4;
|
|
175
|
+
if (s.length > i + 1) {
|
|
176
|
+
groupsOfSix[1] |= s.charCodeAt(i + 1) >> 4;
|
|
177
|
+
groupsOfSix[2] = (s.charCodeAt(i + 1) & 0x0f) << 2;
|
|
178
|
+
}
|
|
179
|
+
if (s.length > i + 2) {
|
|
180
|
+
groupsOfSix[2] |= s.charCodeAt(i + 2) >> 6;
|
|
181
|
+
groupsOfSix[3] = s.charCodeAt(i + 2) & 0x3f;
|
|
182
|
+
}
|
|
183
|
+
for (let j = 0; j < groupsOfSix.length; j++) {
|
|
184
|
+
if (typeof groupsOfSix[j] === 'undefined') {
|
|
185
|
+
out += '=';
|
|
186
|
+
} else {
|
|
187
|
+
out += btoaLookup(groupsOfSix[j]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
154
192
|
}
|
|
155
193
|
|
|
156
194
|
/**
|