homey-api 3.0.13 → 3.0.15
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.
|
@@ -4451,8 +4451,6 @@ export class Util {
|
|
|
4451
4451
|
|
|
4452
4452
|
static getSearchParameter(name: string): string | null;
|
|
4453
4453
|
|
|
4454
|
-
static stringifyQuery(object: object): string;
|
|
4455
|
-
|
|
4456
4454
|
static base64(input: string): string;
|
|
4457
4455
|
|
|
4458
4456
|
static uuid(): string;
|
|
@@ -4461,6 +4459,8 @@ export class Util {
|
|
|
4461
4459
|
|
|
4462
4460
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
4463
4461
|
|
|
4462
|
+
static serializeQueryObject(queryObject: object): string;
|
|
4463
|
+
|
|
4464
4464
|
static fetch(args: any): Promise;
|
|
4465
4465
|
|
|
4466
4466
|
static wait(ms: number): Promise<void>;
|
|
@@ -4485,8 +4485,6 @@ export class Util {
|
|
|
4485
4485
|
|
|
4486
4486
|
static getSearchParameter(name: string): string | null;
|
|
4487
4487
|
|
|
4488
|
-
static stringifyQuery(object: object): string;
|
|
4489
|
-
|
|
4490
4488
|
static base64(input: string): string;
|
|
4491
4489
|
|
|
4492
4490
|
static uuid(): string;
|
|
@@ -4494,6 +4492,8 @@ export class Util {
|
|
|
4494
4492
|
static env(): string;
|
|
4495
4493
|
|
|
4496
4494
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
4495
|
+
|
|
4496
|
+
static serializeQueryObject(queryObject: object): string;
|
|
4497
4497
|
}
|
|
4498
4498
|
|
|
4499
4499
|
export class APIDefinition {}
|
|
@@ -7407,8 +7407,6 @@ export class Util {
|
|
|
7407
7407
|
|
|
7408
7408
|
static getSearchParameter(name: string): string | null;
|
|
7409
7409
|
|
|
7410
|
-
static stringifyQuery(object: object): string;
|
|
7411
|
-
|
|
7412
7410
|
static base64(input: string): string;
|
|
7413
7411
|
|
|
7414
7412
|
static uuid(): string;
|
|
@@ -7417,6 +7415,8 @@ export class Util {
|
|
|
7417
7415
|
|
|
7418
7416
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
7419
7417
|
|
|
7418
|
+
static serializeQueryObject(queryObject: object): string;
|
|
7419
|
+
|
|
7420
7420
|
static fetch(args: any): Promise;
|
|
7421
7421
|
|
|
7422
7422
|
static wait(ms: number): Promise<void>;
|
|
@@ -7441,8 +7441,6 @@ export class Util {
|
|
|
7441
7441
|
|
|
7442
7442
|
static getSearchParameter(name: string): string | null;
|
|
7443
7443
|
|
|
7444
|
-
static stringifyQuery(object: object): string;
|
|
7445
|
-
|
|
7446
7444
|
static base64(input: string): string;
|
|
7447
7445
|
|
|
7448
7446
|
static uuid(): string;
|
|
@@ -7450,6 +7448,8 @@ export class Util {
|
|
|
7450
7448
|
static env(): string;
|
|
7451
7449
|
|
|
7452
7450
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
7451
|
+
|
|
7452
|
+
static serializeQueryObject(queryObject: object): string;
|
|
7453
7453
|
}
|
|
7454
7454
|
|
|
7455
7455
|
export namespace HomeyAPIV3Cloud {
|
package/lib/API.js
CHANGED
|
@@ -97,7 +97,7 @@ class API {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
if (typeof value !== 'undefined') {
|
|
100
|
-
if (parameter.type === 'string' && typeof value !== 'string') {
|
|
100
|
+
if (parameter.in !== 'query' && parameter.type === 'string' && typeof value !== 'string') {
|
|
101
101
|
throw new Error(`Invalid Parameter Type: ${parameterId}. Got: ${typeof value}. Expected: string`);
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -201,7 +201,7 @@ class API {
|
|
|
201
201
|
|
|
202
202
|
if (request.query) {
|
|
203
203
|
if (Object.keys(request.query).length) {
|
|
204
|
-
request.url += `?${Util.
|
|
204
|
+
request.url += `?${Util.serializeQueryObject(request.query)}`;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -280,7 +280,8 @@ class API {
|
|
|
280
280
|
|
|
281
281
|
if (responseContentType && responseContentType.toLowerCase().includes('application/json')) {
|
|
282
282
|
try {
|
|
283
|
-
|
|
283
|
+
const parsed = JSON.parse(responseText);
|
|
284
|
+
return parsed;
|
|
284
285
|
} catch (err) {
|
|
285
286
|
throw new Error(`Failed to parse response body as JSON: ${err.message}`);
|
|
286
287
|
}
|
|
@@ -298,6 +299,21 @@ class API {
|
|
|
298
299
|
// eslint-disable-next-line no-unused-vars
|
|
299
300
|
statusText,
|
|
300
301
|
}) {
|
|
302
|
+
if (typeof body !== 'object' || body === null) {
|
|
303
|
+
return body;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// For ?
|
|
307
|
+
if (body.status != null && body.result != null) {
|
|
308
|
+
return body.result;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// For setup API. https://github.com/athombv/athom-cloud-setup/blob/e7764021d33415f21a1e27ce6a874aa41dc7cfdc/lib/Server/index.js#L30
|
|
312
|
+
if (body.success != null && body.message != null) {
|
|
313
|
+
return body.message;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
|
|
301
317
|
return body;
|
|
302
318
|
}
|
|
303
319
|
|
|
@@ -319,7 +335,10 @@ class API {
|
|
|
319
335
|
} else if (typeof body.error === 'string') {
|
|
320
336
|
message = body.error;
|
|
321
337
|
} else if (typeof body.message === 'string') {
|
|
338
|
+
// Setup API returns message.
|
|
322
339
|
message = body.message;
|
|
340
|
+
} else if (typeof body.result === 'string') {
|
|
341
|
+
message = body.result;
|
|
323
342
|
}
|
|
324
343
|
|
|
325
344
|
throw new APIError(message, statusCode);
|
|
@@ -189,19 +189,22 @@ class Manager extends EventEmitter {
|
|
|
189
189
|
path = `${path}?${queryString}`;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
const pendingCallId = `${operationId}::${path}`
|
|
193
|
+
|
|
192
194
|
if (
|
|
193
195
|
operation.method.toLowerCase() === 'get' &&
|
|
194
196
|
$cache === true &&
|
|
195
|
-
this.__pendingCalls[
|
|
197
|
+
this.__pendingCalls[pendingCallId] != null &&
|
|
196
198
|
Object.keys(body).length === 0
|
|
197
199
|
) {
|
|
198
|
-
this.__debug(`Reusing pending call ${
|
|
199
|
-
|
|
200
|
+
this.__debug(`Reusing pending call ${pendingCallId}`);
|
|
201
|
+
|
|
202
|
+
const result = await this.__pendingCalls[pendingCallId];
|
|
200
203
|
|
|
201
204
|
return result;
|
|
202
205
|
}
|
|
203
206
|
|
|
204
|
-
|
|
207
|
+
const pendingCall = (async () => {
|
|
205
208
|
const result = await this.__request({
|
|
206
209
|
$validate,
|
|
207
210
|
$cache,
|
|
@@ -217,11 +220,21 @@ class Manager extends EventEmitter {
|
|
|
217
220
|
});
|
|
218
221
|
|
|
219
222
|
return result;
|
|
220
|
-
})()
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
})();
|
|
224
|
+
|
|
225
|
+
if (
|
|
226
|
+
operation.method.toLowerCase() === 'get' &&
|
|
227
|
+
$cache === true &&
|
|
228
|
+
this.__pendingCalls[pendingCallId] == null &&
|
|
229
|
+
Object.keys(body).length === 0
|
|
230
|
+
) {
|
|
231
|
+
this.__pendingCalls[pendingCallId] = pendingCall;
|
|
232
|
+
this.__pendingCalls[pendingCallId].finally(() => {
|
|
233
|
+
delete this.__pendingCalls[pendingCallId];
|
|
234
|
+
});
|
|
235
|
+
}
|
|
223
236
|
|
|
224
|
-
const result = await
|
|
237
|
+
const result = await pendingCall;
|
|
225
238
|
|
|
226
239
|
return result;
|
|
227
240
|
},
|
|
@@ -25,11 +25,6 @@ class FlowToken extends Item {
|
|
|
25
25
|
return item;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
get uri() {
|
|
29
|
-
console.warn('FlowToken.uri is deprecated. Use FlowToken.ownerUri instead.');
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
28
|
get uriObj() {
|
|
34
29
|
console.warn('FlowToken.uriObj is deprecated.');
|
|
35
30
|
return undefined;
|
package/lib/Util.js
CHANGED
|
@@ -123,19 +123,6 @@ class Util {
|
|
|
123
123
|
return searchParams.get(name) || null;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
/**
|
|
127
|
-
* Converts an object to a query string
|
|
128
|
-
* @param {object} object - Query parameter object
|
|
129
|
-
* @returns {string}
|
|
130
|
-
*/
|
|
131
|
-
static stringifyQuery(obj) {
|
|
132
|
-
const searchParams = new URLSearchParams();
|
|
133
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
134
|
-
searchParams.append(key, value);
|
|
135
|
-
}
|
|
136
|
-
return searchParams.toString();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
126
|
/**
|
|
140
127
|
* This method encodes a string into a base64 string.
|
|
141
128
|
* It's provided as Util because Node.js uses `Buffer`,
|
|
@@ -256,6 +243,11 @@ class Util {
|
|
|
256
243
|
});
|
|
257
244
|
}
|
|
258
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Converts an object to a query string
|
|
248
|
+
* @param {object} queryObject - Query parameter object
|
|
249
|
+
* @returns {string}
|
|
250
|
+
*/
|
|
259
251
|
static serializeQueryObject(queryObject) {
|
|
260
252
|
let prefix;
|
|
261
253
|
let querystring = [];
|