homey-api 3.0.12 → 3.0.13

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.
@@ -22,7 +22,7 @@ class ManagerFlow extends ManagerFlowV3 {
22
22
  flow,
23
23
  ...props
24
24
  }) {
25
- return this.__super__.createFlow({
25
+ return this.__super__createFlow({
26
26
  flow: Flow.transformSet(flow),
27
27
  ...props,
28
28
  });
@@ -32,7 +32,7 @@ class ManagerFlow extends ManagerFlowV3 {
32
32
  flow,
33
33
  ...props
34
34
  }) {
35
- return this.__super__.updateFlow({
35
+ return this.__super__updateFlow({
36
36
  flow: Flow.transformSet(flow),
37
37
  ...props,
38
38
  });
@@ -42,7 +42,7 @@ class ManagerFlow extends ManagerFlowV3 {
42
42
  advancedflow,
43
43
  ...props
44
44
  }) {
45
- return this.__super__.createAdvancedFlow({
45
+ return this.__super__createAdvancedFlow({
46
46
  advancedflow: AdvancedFlow.transformSet(advancedflow),
47
47
  ...props,
48
48
  });
@@ -52,7 +52,7 @@ class ManagerFlow extends ManagerFlowV3 {
52
52
  advancedflow,
53
53
  ...props
54
54
  }) {
55
- return this.__super__.updateAdvancedFlow({
55
+ return this.__super__updateAdvancedFlow({
56
56
  advancedflow: AdvancedFlow.transformSet(advancedflow),
57
57
  ...props,
58
58
  });
@@ -122,6 +122,17 @@ class ManagerFlow extends ManagerFlowV3 {
122
122
  });
123
123
  }
124
124
 
125
+ async getFlowCardAutocomplete({
126
+ id,
127
+ ...props
128
+ }) {
129
+ return this.__super__getFlowCardAutocomplete({
130
+ id: id.split(':').reverse()[0],
131
+ uri: id.split(':', 3).join(':'),
132
+ ...props,
133
+ });
134
+ }
135
+
125
136
  }
126
137
 
127
138
  module.exports = ManagerFlow;
@@ -130,7 +130,7 @@ class Manager extends EventEmitter {
130
130
  }
131
131
 
132
132
  if (typeof value !== 'undefined') {
133
- if (parameter.type === 'string' && typeof value !== 'string') {
133
+ if (parameter.in !== 'query' && parameter.type === 'string' && typeof value !== 'string') {
134
134
  throw new Error(`Invalid Parameter Type: ${parameterId}. Got: ${typeof value}. Expected: string`);
135
135
  }
136
136
 
@@ -160,10 +160,6 @@ class Manager extends EventEmitter {
160
160
  if (typeof value !== 'undefined') {
161
161
  switch (parameter.in) {
162
162
  case 'path': {
163
- if (typeof value !== 'string') {
164
- throw new Error(`Invalid Parameter Type: ${parameterId}. Got: ${typeof value}. Expected: string`);
165
- }
166
-
167
163
  path = path.replace(`:${parameterId}`, value);
168
164
  break;
169
165
  }
@@ -176,10 +172,6 @@ class Manager extends EventEmitter {
176
172
  break;
177
173
  }
178
174
  case 'query': {
179
- if (typeof value !== 'string') {
180
- throw new Error(`Invalid Parameter Type: ${parameterId}. Got: ${typeof value}. Expected: string`);
181
- }
182
-
183
175
  query[parameterId] = value;
184
176
  break;
185
177
  }
@@ -193,9 +185,7 @@ class Manager extends EventEmitter {
193
185
 
194
186
  // Append query to path
195
187
  if (Object.keys(query).length > 0) {
196
- const queryString = Object.entries(query).map(([key, value]) => {
197
- return `${key}=${encodeURIComponent(value)}`;
198
- }).join('&');
188
+ const queryString = Util.serializeQueryObject(query);
199
189
  path = `${path}?${queryString}`;
200
190
  }
201
191
 
package/lib/Util.js CHANGED
@@ -256,6 +256,59 @@ class Util {
256
256
  });
257
257
  }
258
258
 
259
+ static serializeQueryObject(queryObject) {
260
+ let prefix;
261
+ let querystring = [];
262
+ let rbracket = /\[\]$/;
263
+
264
+ function add(key, value) {
265
+ // If value is a function, invoke it and return its value.
266
+ value = (typeof value === 'function') ?
267
+ value() :
268
+ value === null ?
269
+ '' :
270
+ value;
271
+ querystring[querystring.length] = encodeURIComponent(key) +
272
+ '=' + encodeURIComponent(value);
273
+ }
274
+
275
+ function buildParams(prefix, obj, add) {
276
+ let name;
277
+ if (Array.isArray(obj)) {
278
+ // Serialize array item.
279
+ for (let index = 0; index < obj.length; index++) {
280
+ if (rbracket.test(prefix)) {
281
+ // Treat each array item as a scalar.
282
+ add(prefix, obj[index]);
283
+ } else {
284
+ // Item is non-scalar (array or object), encode its numeric index.
285
+ buildParams(prefix + '[' + (typeof (obj[index]) === 'object' ?
286
+ index :
287
+ ''
288
+ ) + ']', obj[index], add);
289
+ }
290
+ }
291
+ } else if (typeof obj === 'object') {
292
+ // Serialize object item.
293
+ for (name in obj) {
294
+ buildParams(prefix + '[' + name + ']', obj[name], add);
295
+ }
296
+ } else {
297
+ // Serialize scalar item.
298
+ add(prefix, obj);
299
+ }
300
+ }
301
+
302
+ // Encode params recursively.
303
+ for (prefix in queryObject) {
304
+ if (typeof queryObject[prefix] === 'undefined') continue;
305
+ buildParams(prefix, queryObject[prefix], add);
306
+ }
307
+
308
+ // Return the resulting serialization.
309
+ return querystring.join('&');
310
+ }
311
+
259
312
  }
260
313
 
261
314
  module.exports = Util;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [