pushy-electron 1.0.14 → 1.0.16

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/Pushy.d.ts CHANGED
@@ -30,6 +30,8 @@ declare namespace Pushy {
30
30
 
31
31
  function setEnterpriseConfig(endpoint: string, mqttEndpoint: string): void
32
32
 
33
+ function mTLS(config: object): void
34
+
33
35
  function disconnect(): void
34
36
 
35
37
  function alert(win: BrowserWindow, msg: string): void
package/lib/Pushy.js CHANGED
@@ -88,7 +88,7 @@ module.exports = {
88
88
 
89
89
  try {
90
90
  // Register the device
91
- response = await api.post('/register', postData);
91
+ response = await api.post('/register', postData, this.mTLSConfig);
92
92
  }
93
93
  catch (e) {
94
94
  // Registration failed
@@ -147,7 +147,7 @@ module.exports = {
147
147
 
148
148
  try {
149
149
  // Subscribe to topic(s)
150
- response = await api.post('/devices/subscribe', postData);
150
+ response = await api.post('/devices/subscribe', postData, this.mTLSConfig);
151
151
  }
152
152
  catch (e) {
153
153
  // Request failed
@@ -183,7 +183,7 @@ module.exports = {
183
183
 
184
184
  try {
185
185
  // Unsubscribe from topic(s)
186
- response = await api.post('/devices/unsubscribe', postData);
186
+ response = await api.post('/devices/unsubscribe', postData, this.mTLSConfig);
187
187
  }
188
188
  catch (e) {
189
189
  // Request failed
@@ -214,7 +214,7 @@ module.exports = {
214
214
 
215
215
  try {
216
216
  // Authenticate the device
217
- response = await api.post('/devices/auth', postData);
217
+ response = await api.post('/devices/auth', postData, this.mTLSConfig);
218
218
  }
219
219
  catch (e) {
220
220
  // Request failed
@@ -242,6 +242,11 @@ module.exports = {
242
242
  localStorage.set(config.storageKeys.keepAliveInt, seconds);
243
243
  },
244
244
 
245
+ mTLS(config) {
246
+ // Store in Pushy object for later
247
+ this.mTLSConfig = config;
248
+ },
249
+
245
250
  setEnterpriseConfig(endpoint, mqttEndpoint) {
246
251
  // Clear requested?
247
252
  if (!endpoint || !mqttEndpoint) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushy-electron",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "main": "lib/Pushy.js",
7
7
  "typings": "lib/Pushy.d.ts",
8
8
  "//": "Also update version in config.js",
9
- "version": "1.0.14",
9
+ "version": "1.0.16",
10
10
  "scripts": {
11
11
  "dev": "electron electron.js"
12
12
  },
package/util/api.js CHANGED
@@ -1,16 +1,18 @@
1
+ const https = require('https');
1
2
  const config = require('../config');
2
3
  const localStorage = require('./storage');
3
4
  const fetch = require('node-fetch').default; // Workaround for #2: https://github.com/pushy/pushy-electron/issues/2
4
5
 
5
6
  module.exports = {
6
- async get(path, options) {
7
- // Nothing special to do here, simply send the request
8
- return await this.execute(path, options || {});
9
- },
10
-
11
- async post(path, json, options) {
7
+ async post(path, json, mTLS) {
12
8
  // Default request options
13
- options = options || {};
9
+ let options = {};
10
+
11
+ // mTLS configured?
12
+ if (mTLS) {
13
+ // Prepare HTTPS agent with config
14
+ options.agent = https.Agent(mTLS);
15
+ }
14
16
 
15
17
  // Set POST request options
16
18
  options.method = 'POST';
package/util/mqtt.js CHANGED
@@ -112,6 +112,19 @@ module.exports = {
112
112
  let keepAlive = localStorage.get(config.storageKeys.keepAliveInt) || config.mqtt.defaultKeepAlive;
113
113
 
114
114
  // MQTT connection options
115
- return { keepalive: keepAlive, username: token, password: tokenAuth, clientId: token };
115
+ let options = { keepalive: keepAlive, username: token, password: tokenAuth, clientId: token };
116
+
117
+ // mTLS support
118
+ let mTLS = this.Pushy.mTLSConfig;
119
+
120
+ // mTLS support
121
+ if (mTLS) {
122
+ options.ca = mTLS.ca;
123
+ options.key = mTLS.key;
124
+ options.cert = mTLS.cert;
125
+ }
126
+
127
+ // Return options
128
+ return options;
116
129
  }
117
130
  }
package/util/storage.js CHANGED
@@ -12,6 +12,9 @@ module.exports = {
12
12
  },
13
13
  set(key, value) {
14
14
  return getLocalStorage().set(key, value);
15
+ },
16
+ delete(key) {
17
+ return getLocalStorage().delete(key);
15
18
  }
16
19
  };
17
20
 
package/.DS_Store DELETED
Binary file