pushy-electron 1.0.15 → 1.0.17
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 +4 -0
- package/lib/Pushy.js +15 -4
- package/npm-shrinkwrap.json +1 -1
- package/package.json +1 -1
- package/util/api.js +9 -7
- package/util/mqtt.js +14 -1
- package/.DS_Store +0 -0
package/lib/Pushy.d.ts
CHANGED
|
@@ -28,8 +28,12 @@ declare namespace Pushy {
|
|
|
28
28
|
|
|
29
29
|
function isEnterpriseConfigured(): boolean
|
|
30
30
|
|
|
31
|
+
function setDeviceCredentials(token: string, auth: string): void
|
|
32
|
+
|
|
31
33
|
function setEnterpriseConfig(endpoint: string, mqttEndpoint: string): void
|
|
32
34
|
|
|
35
|
+
function mTLS(config: object): void
|
|
36
|
+
|
|
33
37
|
function disconnect(): void
|
|
34
38
|
|
|
35
39
|
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) {
|
|
@@ -283,6 +288,12 @@ module.exports = {
|
|
|
283
288
|
}
|
|
284
289
|
},
|
|
285
290
|
|
|
291
|
+
setDeviceCredentials(token, auth) {
|
|
292
|
+
// Manually set token & auth key
|
|
293
|
+
localStorage.set(config.storageKeys.token, token);
|
|
294
|
+
localStorage.set(config.storageKeys.tokenAuth, auth);
|
|
295
|
+
},
|
|
296
|
+
|
|
286
297
|
disconnect() {
|
|
287
298
|
// Attempt to disconnect from Pushy
|
|
288
299
|
mqtt.disconnect(this);
|
package/npm-shrinkwrap.json
CHANGED
package/package.json
CHANGED
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
|
|
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 =
|
|
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
|
-
|
|
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/.DS_Store
DELETED
|
Binary file
|