homey-api 1.5.28 → 1.6.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.
@@ -34,6 +34,10 @@
34
34
  "quantity": {
35
35
  "type": "number",
36
36
  "in": "body"
37
+ },
38
+ "options": {
39
+ "type": "object",
40
+ "in": "body"
37
41
  }
38
42
  }
39
43
  },
@@ -369,6 +373,93 @@
369
373
  "required": true
370
374
  }
371
375
  }
376
+ },
377
+ "getOffer": {
378
+ "path": "/offer/{offerId}",
379
+ "method": "get",
380
+ "parameters": {
381
+ "offerId": {
382
+ "in": "path",
383
+ "type": "string",
384
+ "required": true
385
+ }
386
+ }
387
+ },
388
+ "redeemOffer": {
389
+ "path": "/offer/{offerId}/redeem",
390
+ "method": "post",
391
+ "parameters": {
392
+ "offerId": {
393
+ "in": "path",
394
+ "type": "string",
395
+ "required": true
396
+ },
397
+ "paymentProvider": {
398
+ "type": "string",
399
+ "in": "body"
400
+ }
401
+ }
402
+ },
403
+ "createOfferCouponApple": {
404
+ "path": "/offer/coupon_apple",
405
+ "method": "post",
406
+ "parameters": {
407
+ "coupon": {
408
+ "type": "string",
409
+ "in": "body"
410
+ },
411
+ "expiresAt": {
412
+ "type": "string",
413
+ "in": "body"
414
+ },
415
+ "subscriptionType": {
416
+ "type": "string",
417
+ "in": "body"
418
+ },
419
+ "subscriptionQuantity": {
420
+ "type": "number",
421
+ "in": "body"
422
+ },
423
+ "subscriptionDuration": {
424
+ "type": "string",
425
+ "in": "body"
426
+ }
427
+ }
428
+ },
429
+ "getOffers": {
430
+ "path": "/offer",
431
+ "method": "get",
432
+ "parameters": {}
433
+ },
434
+ "createOffer": {
435
+ "path": "/offer",
436
+ "method": "post",
437
+ "parameters": {
438
+ "userId": {
439
+ "type": "string",
440
+ "in": "body"
441
+ },
442
+ "expiresAt": {
443
+ "type": "string",
444
+ "in": "body"
445
+ },
446
+ "campaignId": {
447
+ "type": "string",
448
+ "in": "body"
449
+ },
450
+ "subscriptionType": {
451
+ "type": "string",
452
+ "in": "body"
453
+ },
454
+ "subscriptionQuantity": {
455
+ "type": "number",
456
+ "in": "body"
457
+ },
458
+ "subscriptionDuration": {
459
+ "type": "string",
460
+ "in": "body"
461
+ }
462
+ }
372
463
  }
373
464
  }
374
465
  }
@@ -579,7 +579,7 @@
579
579
 
580
580
  }
581
581
 
582
- export class StorageAdapterNodeJS extends StorageAdapter {
582
+ export class StorageAdapterMemory extends StorageAdapter {
583
583
 
584
584
 
585
585
 
@@ -4232,6 +4232,10 @@
4232
4232
  quantity: number,
4233
4233
 
4234
4234
 
4235
+
4236
+ options: object,
4237
+
4238
+
4235
4239
  },
4236
4240
 
4237
4241
 
@@ -4700,6 +4704,127 @@
4700
4704
 
4701
4705
 
4702
4706
 
4707
+ ):
4708
+ Promise<any>;
4709
+
4710
+ getOffer(
4711
+
4712
+
4713
+
4714
+
4715
+ opts: {
4716
+
4717
+
4718
+ offerId: string,
4719
+
4720
+
4721
+ },
4722
+
4723
+
4724
+
4725
+
4726
+ ):
4727
+ Promise<any>;
4728
+
4729
+ redeemOffer(
4730
+
4731
+
4732
+
4733
+
4734
+ opts: {
4735
+
4736
+
4737
+ offerId: string,
4738
+
4739
+
4740
+
4741
+ paymentProvider: string,
4742
+
4743
+
4744
+ },
4745
+
4746
+
4747
+
4748
+
4749
+ ):
4750
+ Promise<any>;
4751
+
4752
+ createOfferCouponApple(
4753
+
4754
+
4755
+
4756
+
4757
+ opts: {
4758
+
4759
+
4760
+ coupon: string,
4761
+
4762
+
4763
+
4764
+ expiresAt: string,
4765
+
4766
+
4767
+
4768
+ subscriptionType: string,
4769
+
4770
+
4771
+
4772
+ subscriptionQuantity: number,
4773
+
4774
+
4775
+
4776
+ subscriptionDuration: string,
4777
+
4778
+
4779
+ },
4780
+
4781
+
4782
+
4783
+
4784
+ ):
4785
+ Promise<any>;
4786
+
4787
+ getOffers(
4788
+
4789
+ ):
4790
+ Promise<any>;
4791
+
4792
+ createOffer(
4793
+
4794
+
4795
+
4796
+
4797
+ opts: {
4798
+
4799
+
4800
+ userId: string,
4801
+
4802
+
4803
+
4804
+ expiresAt: string,
4805
+
4806
+
4807
+
4808
+ campaignId: string,
4809
+
4810
+
4811
+
4812
+ subscriptionType: string,
4813
+
4814
+
4815
+
4816
+ subscriptionQuantity: number,
4817
+
4818
+
4819
+
4820
+ subscriptionDuration: string,
4821
+
4822
+
4823
+ },
4824
+
4825
+
4826
+
4827
+
4703
4828
  ):
4704
4829
  Promise<any>;
4705
4830
 
@@ -5512,6 +5637,15 @@
5512
5637
 
5513
5638
 
5514
5639
 
5640
+ ):
5641
+ boolean;
5642
+
5643
+ isReactNative(
5644
+
5645
+
5646
+
5647
+
5648
+
5515
5649
  ):
5516
5650
  boolean;
5517
5651
 
@@ -5719,7 +5853,7 @@
5719
5853
 
5720
5854
  }
5721
5855
 
5722
- export class StorageAdapterNodeJS extends StorageAdapter {
5856
+ export class StorageAdapterMemory extends StorageAdapter {
5723
5857
 
5724
5858
 
5725
5859
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Abstract storage adapter. To be extended by your own, or {@link AthomCloudAPI.StorageAdapterBrowser} or {@link AthomCloudAPI.StorageAdapterNodeJS}.
4
+ * Abstract storage adapter. To be extended by your own, or {@link AthomCloudAPI.StorageAdapterBrowser} or {@link AthomCloudAPI.StorageAdapterMemory}.
5
5
  * @class
6
6
  * @memberof AthomCloudAPI
7
7
  */
@@ -3,12 +3,12 @@
3
3
  const StorageAdapter = require('./StorageAdapter');
4
4
 
5
5
  /**
6
- * In-memory storage adapter for Node.js.
6
+ * In-memory storage adapter for Node.js or React Native.
7
7
  * @class
8
8
  * @extends StorageAdapter
9
9
  * @memberof AthomCloudAPI
10
10
  */
11
- class StorageAdapterNodeJS extends StorageAdapter {
11
+ class StorageAdapterMemory extends StorageAdapter {
12
12
 
13
13
  constructor() {
14
14
  super();
@@ -34,4 +34,4 @@ class StorageAdapterNodeJS extends StorageAdapter {
34
34
 
35
35
  }
36
36
 
37
- module.exports = StorageAdapterNodeJS;
37
+ module.exports = StorageAdapterMemory;
@@ -9,7 +9,7 @@ const Homey = require('./AthomCloudAPI/Homey');
9
9
  const Token = require('./AthomCloudAPI/Token');
10
10
  const StorageAdapter = require('./AthomCloudAPI/StorageAdapter');
11
11
  const StorageAdapterBrowser = require('./AthomCloudAPI/StorageAdapterBrowser');
12
- const StorageAdapterNodeJS = require('./AthomCloudAPI/StorageAdapterNodeJS');
12
+ const StorageAdapterMemory = require('./AthomCloudAPI/StorageAdapterMemory');
13
13
 
14
14
  class AthomCloudAPI extends API {
15
15
 
@@ -18,7 +18,7 @@ class AthomCloudAPI extends API {
18
18
  static Token = Token;
19
19
  static StorageAdapter = StorageAdapter;
20
20
  static StorageAdapterBrowser = StorageAdapterBrowser;
21
- static StorageAdapterNodeJS = StorageAdapterNodeJS;
21
+ static StorageAdapterMemory = StorageAdapterMemory;
22
22
 
23
23
  static SPECIFICATION = require('../assets/specifications/AthomCloudAPI.json');
24
24
  static SPECIFICATION_URL = 'https://api.athom.com/specification.json';
@@ -75,7 +75,7 @@ for(const device of Object.values(devices)) {
75
75
  @param {string} opts.redirectUrl
76
76
  @param {boolean} [opts.autoRefreshTokens=true]
77
77
  @param {AthomCloudAPI.Token} [opts.token=null]
78
- @param {AthomCloudAPI.StorageAdapter} [opts.store={@link AthomCloudAPI.StorageAdapterBrowser} or {@link AthomCloudAPI.StorageAdapterNodeJS}]`;
78
+ @param {AthomCloudAPI.StorageAdapter} [opts.store={@link AthomCloudAPI.StorageAdapterBrowser} or {@link AthomCloudAPI.StorageAdapterMemory}]`;
79
79
 
80
80
  constructor({
81
81
  clientId,
@@ -85,7 +85,7 @@ for(const device of Object.values(devices)) {
85
85
  token = null,
86
86
  store = Util.isBrowser()
87
87
  ? new StorageAdapterBrowser()
88
- : new StorageAdapterNodeJS(),
88
+ : new StorageAdapterMemory(),
89
89
  ...args
90
90
  } = {}) {
91
91
  super({ ...args });
@@ -1,9 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const fetch = require('node-fetch');
4
-
5
3
  const API = require('./API');
6
4
  const APIError = require('./APIError');
5
+ const Util = require('./Util');
7
6
 
8
7
  class HomeyCloudAPI extends API {
9
8
 
@@ -26,7 +25,7 @@ class HomeyCloudAPI extends API {
26
25
  * @returns {string} result.region - e.g. `eu-central-1`
27
26
  */
28
27
  static async getClosestRegion() {
29
- const res = await fetch(`https://${HomeyCloudAPI.SPECIFICATION.host}`);
28
+ const res = await Util.fetch(`https://${HomeyCloudAPI.SPECIFICATION.host}`);
30
29
  if (!res.ok) {
31
30
  throw new Error(res.statusText || 'Unknown Error');
32
31
  }
@@ -56,7 +55,7 @@ class HomeyCloudAPI extends API {
56
55
  * @returns {Promise<object>} result
57
56
  */
58
57
  async getSystemStatus({ secret }) {
59
- const res = await fetch(`${this.baseUrl}/api/system/status`, {
58
+ const res = await Util.fetch(`${this.baseUrl}/api/system/status`, {
60
59
  headers: {
61
60
  'X-Homey-Secret': secret,
62
61
  },
package/lib/Util.js CHANGED
@@ -18,13 +18,23 @@ class Util {
18
18
  * @returns {Promise}
19
19
  */
20
20
  static async fetch(...args) {
21
+ if (this.isReactNative()) {
22
+ return fetch(...args);
23
+ }
24
+
21
25
  // If in a browser
22
26
  if (this.isBrowser()) {
23
27
  return window.fetch(...args);
24
28
  }
25
29
 
26
- const fetch = require('node-fetch');
27
- return fetch(...args);
30
+ if (this.isNodeJS()) {
31
+ const fetch = require('node-fetch');
32
+ return fetch(...args);
33
+ }
34
+
35
+ if (typeof fetch !== 'undefined') {
36
+ return fetch(...args);
37
+ }
28
38
  }
29
39
 
30
40
  /**
@@ -81,17 +91,26 @@ class Util {
81
91
  return window.location.protocol === 'http:';
82
92
  }
83
93
 
94
+ /**
95
+ * @returns {boolean}
96
+ */
97
+ static isReactNative() {
98
+ return (typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
99
+ }
100
+
84
101
  /**
85
102
  * @returns {boolean}
86
103
  */
87
104
  static isBrowser() {
88
- return (typeof window !== 'undefined');
105
+ if (this.isReactNative()) return false;
106
+ return (typeof document !== 'undefined' && typeof document.window !== 'undefined');
89
107
  }
90
108
 
91
109
  /**
92
110
  * @returns {boolean}
93
111
  */
94
112
  static isNodeJS() {
113
+ if (this.isReactNative()) return false;
95
114
  return (typeof process !== 'undefined');
96
115
  }
97
116
 
@@ -161,6 +180,10 @@ class Util {
161
180
  return process.env[key] || null;
162
181
  }
163
182
 
183
+ if (this.isReactNative()) {
184
+ return null;
185
+ }
186
+
164
187
  return null;
165
188
  }
166
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.5.28",
3
+ "version": "1.6.0",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "types": "assets/types/homey-api.d.ts",