homey-api 3.0.25 → 3.0.27
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/assets/types/homey-api.private.d.ts +8 -0
- package/lib/AthomCloudAPI.js +34 -28
- package/lib/Util.js +19 -0
- package/package.json +1 -3
|
@@ -4465,6 +4465,8 @@ export class Util {
|
|
|
4465
4465
|
|
|
4466
4466
|
static serializeQueryObject(queryObject: object): string;
|
|
4467
4467
|
|
|
4468
|
+
static encodeUrlSearchParams(params: object): string;
|
|
4469
|
+
|
|
4468
4470
|
static fetch(args: any): Promise;
|
|
4469
4471
|
|
|
4470
4472
|
static wait(ms: number): Promise<void>;
|
|
@@ -4498,6 +4500,8 @@ export class Util {
|
|
|
4498
4500
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
4499
4501
|
|
|
4500
4502
|
static serializeQueryObject(queryObject: object): string;
|
|
4503
|
+
|
|
4504
|
+
static encodeUrlSearchParams(params: object): string;
|
|
4501
4505
|
}
|
|
4502
4506
|
|
|
4503
4507
|
export class APIDefinition {}
|
|
@@ -7425,6 +7429,8 @@ export class Util {
|
|
|
7425
7429
|
|
|
7426
7430
|
static serializeQueryObject(queryObject: object): string;
|
|
7427
7431
|
|
|
7432
|
+
static encodeUrlSearchParams(params: object): string;
|
|
7433
|
+
|
|
7428
7434
|
static fetch(args: any): Promise;
|
|
7429
7435
|
|
|
7430
7436
|
static wait(ms: number): Promise<void>;
|
|
@@ -7458,6 +7464,8 @@ export class Util {
|
|
|
7458
7464
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
7459
7465
|
|
|
7460
7466
|
static serializeQueryObject(queryObject: object): string;
|
|
7467
|
+
|
|
7468
|
+
static encodeUrlSearchParams(params: object): string;
|
|
7461
7469
|
}
|
|
7462
7470
|
|
|
7463
7471
|
export namespace HomeyAPIV3Cloud {
|
package/lib/AthomCloudAPI.js
CHANGED
|
@@ -214,20 +214,21 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
214
214
|
throw new Error('Missing Redirect URL');
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
const params = {
|
|
218
|
+
client_id: this.__clientId,
|
|
219
|
+
redirect_uri: this.__redirectUrl,
|
|
220
|
+
response_type: 'code',
|
|
221
|
+
}
|
|
221
222
|
|
|
222
223
|
if (typeof state === 'string') {
|
|
223
|
-
|
|
224
|
+
params.state = state;
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
if (Array.isArray(scopes)) {
|
|
227
|
-
|
|
228
|
+
params.scope = scopes.join(',');
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
return `${this.baseUrl}/oauth2/authorise?${
|
|
231
|
+
return `${this.baseUrl}/oauth2/authorise?${Util.encodeUrlSearchParams(params)}`;
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
async getDelegatedLoginUrl(args = {}) {
|
|
@@ -240,19 +241,20 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
240
241
|
meta: args.meta,
|
|
241
242
|
});
|
|
242
243
|
|
|
243
|
-
const
|
|
244
|
-
|
|
244
|
+
const params = {
|
|
245
|
+
user_token: token,
|
|
246
|
+
}
|
|
245
247
|
|
|
246
248
|
if (typeof args.state === 'string') {
|
|
247
|
-
|
|
249
|
+
params.state = args.state;
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
if (typeof args.resource === 'string') {
|
|
251
|
-
|
|
253
|
+
params.resource = args.resource;
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
const seperator = args.baseUrl.indexOf('?') >= 0 ? '&' : '?';
|
|
255
|
-
return args.baseUrl + seperator +
|
|
257
|
+
return args.baseUrl + seperator + Util.encodeUrlSearchParams(params);
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
/**
|
|
@@ -366,11 +368,12 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
366
368
|
throw new Error('Missing Client Secret');
|
|
367
369
|
}
|
|
368
370
|
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
+
const params = {
|
|
372
|
+
grant_type: 'client_credentials',
|
|
373
|
+
}
|
|
371
374
|
|
|
372
375
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
373
|
-
body:
|
|
376
|
+
body: Util.encodeUrlSearchParams(params),
|
|
374
377
|
method: 'post',
|
|
375
378
|
headers: {
|
|
376
379
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -427,12 +430,13 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
427
430
|
throw new Error('Missing Client Secret');
|
|
428
431
|
}
|
|
429
432
|
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
+
const params = {
|
|
434
|
+
grant_type: 'authorization_code',
|
|
435
|
+
code: code,
|
|
436
|
+
}
|
|
433
437
|
|
|
434
438
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
435
|
-
body:
|
|
439
|
+
body: Util.encodeUrlSearchParams(params),
|
|
436
440
|
method: 'post',
|
|
437
441
|
headers: {
|
|
438
442
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -487,13 +491,14 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
487
491
|
throw new Error('Missing Client Secret');
|
|
488
492
|
}
|
|
489
493
|
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
+
const params = {
|
|
495
|
+
grant_type: 'password',
|
|
496
|
+
username: username,
|
|
497
|
+
password: password,
|
|
498
|
+
}
|
|
494
499
|
|
|
495
500
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
496
|
-
body:
|
|
501
|
+
body: Util.encodeUrlSearchParams(params),
|
|
497
502
|
method: 'post',
|
|
498
503
|
headers: {
|
|
499
504
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -533,12 +538,13 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
533
538
|
throw new Error('Missing Refresh Token');
|
|
534
539
|
}
|
|
535
540
|
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
|
|
541
|
+
const params = {
|
|
542
|
+
grant_type: 'refresh_token',
|
|
543
|
+
refresh_token: this.__token.refresh_token,
|
|
544
|
+
}
|
|
539
545
|
|
|
540
546
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
541
|
-
body:
|
|
547
|
+
body: Util.encodeUrlSearchParams(params),
|
|
542
548
|
method: 'post',
|
|
543
549
|
headers: {
|
|
544
550
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
package/lib/Util.js
CHANGED
|
@@ -309,6 +309,25 @@ class Util {
|
|
|
309
309
|
return querystring.join('&');
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
/**
|
|
313
|
+
* We use this instead of URLSearchParams because in react-native URLSearchParams are not encoded
|
|
314
|
+
* for some reason.
|
|
315
|
+
*
|
|
316
|
+
* @param {object} params
|
|
317
|
+
* @returns {string} encoded params
|
|
318
|
+
*/
|
|
319
|
+
static encodeUrlSearchParams(params) {
|
|
320
|
+
const encodedPairs = [];
|
|
321
|
+
|
|
322
|
+
for (const [key, value] of Object.entries(params)) {
|
|
323
|
+
const encodedKey = encodeURIComponent(key);
|
|
324
|
+
const encodedValue = encodeURIComponent(value);
|
|
325
|
+
encodedPairs.push(encodedKey + "=" + encodedValue);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return encodedPairs.join("&");
|
|
329
|
+
}
|
|
330
|
+
|
|
312
331
|
}
|
|
313
332
|
|
|
314
333
|
module.exports = Util;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homey-api",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.27",
|
|
4
4
|
"description": "Homey API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -47,10 +47,8 @@
|
|
|
47
47
|
"node": ">=16"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"core-js": "^3.19.1",
|
|
51
50
|
"form-data": "^4.0.0",
|
|
52
51
|
"node-fetch": "^2.6.7",
|
|
53
|
-
"regenerator-runtime": "^0.13.9",
|
|
54
52
|
"socket.io-client": "^2.5.0"
|
|
55
53
|
},
|
|
56
54
|
"devDependencies": {
|