pushy 2.0.13 → 3.0.1
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/README.md +6 -6
- package/api/device/info.js +15 -11
- package/api/device/presence.js +16 -12
- package/api/pubsub/subscribe.js +16 -12
- package/api/pubsub/subscribers.js +15 -11
- package/api/pubsub/topics.js +15 -11
- package/api/pubsub/unsubscribe.js +16 -12
- package/api/push/delete.js +15 -11
- package/api/push/send.js +20 -19
- package/api/push/status.js +15 -11
- package/examples/push.js +2 -2
- package/index.d.ts +361 -0
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -42,14 +42,14 @@ var options = {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
// Send push notification using the Send Notifications API
|
|
45
|
-
pushy.sendPushNotification(data, to, options, function (err,
|
|
45
|
+
pushy.sendPushNotification(data, to, options, function (err, result) {
|
|
46
46
|
// Log errors to console
|
|
47
47
|
if (err) {
|
|
48
48
|
return console.error(err);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// Log success
|
|
52
|
-
console.log('Push sent successfully! (ID: ' + id + ')');
|
|
52
|
+
console.log('Push sent successfully! (ID: ' + result.id + ')');
|
|
53
53
|
});
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -61,9 +61,9 @@ The library also supports using promise syntax instead of callbacks for all API
|
|
|
61
61
|
|
|
62
62
|
```js
|
|
63
63
|
pushy.sendPushNotification(data, tokens, options)
|
|
64
|
-
.then(function (
|
|
64
|
+
.then(function (result) {
|
|
65
65
|
// Log success
|
|
66
|
-
console.log('Push sent successfully! (ID: ' + id + ')');
|
|
66
|
+
console.log('Push sent successfully! (ID: ' + result.id + ')');
|
|
67
67
|
}).catch(function (err) {
|
|
68
68
|
// Log errors to console
|
|
69
69
|
return console.error(err);
|
|
@@ -79,14 +79,14 @@ pushy.sendPushNotification(data, tokens, options)
|
|
|
79
79
|
Instantly send push notifications to your users using the [Send Notifications API](https://pushy.me/docs/api/send-notifications) (see example above):
|
|
80
80
|
|
|
81
81
|
```js
|
|
82
|
-
pushy.sendPushNotification(data, to, options, function (err,
|
|
82
|
+
pushy.sendPushNotification(data, to, options, function (err, result) {
|
|
83
83
|
// Log errors to console
|
|
84
84
|
if (err) {
|
|
85
85
|
return console.error(err);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// Log success
|
|
89
|
-
console.log('Push sent successfully! (ID: ' + id + ')');
|
|
89
|
+
console.log('Push sent successfully! (ID: ' + result.id + ')');
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
92
|
|
package/api/device/info.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Device Info API
|
|
5
4
|
module.exports = function (deviceToken, callback) {
|
|
@@ -20,17 +19,14 @@ module.exports = function (deviceToken, callback) {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
// Make a request to the Device Info API
|
|
23
|
-
|
|
22
|
+
axios(
|
|
24
23
|
Object.assign({
|
|
25
|
-
|
|
24
|
+
url: that.getApiEndpoint() + '/devices/' + deviceToken + '?api_key=' + that.apiKey,
|
|
26
25
|
method: 'GET',
|
|
27
26
|
json: true
|
|
28
|
-
}, that.extraRequestOptions || {})
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
// Send to callback
|
|
32
|
-
return reject(err);
|
|
33
|
-
}
|
|
27
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
28
|
+
// API response
|
|
29
|
+
var body = res.data;
|
|
34
30
|
|
|
35
31
|
// Missing body?
|
|
36
32
|
if (!body) {
|
|
@@ -43,7 +39,7 @@ module.exports = function (deviceToken, callback) {
|
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
// Check for 200 OK
|
|
46
|
-
if (res.
|
|
42
|
+
if (res.status != 200) {
|
|
47
43
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
48
44
|
}
|
|
49
45
|
|
|
@@ -59,6 +55,14 @@ module.exports = function (deviceToken, callback) {
|
|
|
59
55
|
// Resolve the promise
|
|
60
56
|
resolve(deviceInfo);
|
|
61
57
|
}
|
|
58
|
+
}).catch(function (err) {
|
|
59
|
+
// Invoke callback/reject promise with Pushy error
|
|
60
|
+
if (err.response && err.response.data) {
|
|
61
|
+
reject(err.response.data);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
reject(err);
|
|
65
|
+
}
|
|
62
66
|
});
|
|
63
67
|
});
|
|
64
68
|
}
|
package/api/device/presence.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Device Presence API
|
|
5
4
|
module.exports = function (deviceTokens, callback) {
|
|
@@ -40,17 +39,14 @@ module.exports = function (deviceTokens, callback) {
|
|
|
40
39
|
postData.tokens = deviceTokens;
|
|
41
40
|
|
|
42
41
|
// Make a request to the Device Presence API
|
|
43
|
-
|
|
42
|
+
axios(
|
|
44
43
|
Object.assign({
|
|
45
|
-
|
|
44
|
+
url: that.getApiEndpoint() + '/devices/presence' + '?api_key=' + that.apiKey,
|
|
46
45
|
method: 'POST',
|
|
47
|
-
|
|
48
|
-
}, that.extraRequestOptions || {})
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
// Send to callback
|
|
52
|
-
return reject(err);
|
|
53
|
-
}
|
|
46
|
+
data: postData
|
|
47
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
48
|
+
// API response
|
|
49
|
+
var body = res.data;
|
|
54
50
|
|
|
55
51
|
// Missing body?
|
|
56
52
|
if (!body) {
|
|
@@ -63,7 +59,7 @@ module.exports = function (deviceTokens, callback) {
|
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
// Check for 200 OK
|
|
66
|
-
if (res.
|
|
62
|
+
if (res.status != 200) {
|
|
67
63
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
68
64
|
}
|
|
69
65
|
|
|
@@ -79,6 +75,14 @@ module.exports = function (deviceTokens, callback) {
|
|
|
79
75
|
// Resolve the promise
|
|
80
76
|
resolve(devicePresence);
|
|
81
77
|
}
|
|
78
|
+
}).catch(function (err) {
|
|
79
|
+
// Invoke callback/reject promise with Pushy error
|
|
80
|
+
if (err.response && err.response.data) {
|
|
81
|
+
reject(err.response.data);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
reject(err);
|
|
85
|
+
}
|
|
82
86
|
});
|
|
83
87
|
});
|
|
84
88
|
}
|
package/api/pubsub/subscribe.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Pub/Sub Subscribe API
|
|
5
4
|
module.exports = function (topics, deviceToken, callback) {
|
|
@@ -34,17 +33,14 @@ module.exports = function (topics, deviceToken, callback) {
|
|
|
34
33
|
postData.topics = Array.isArray(topics) ? topics : [topics];
|
|
35
34
|
|
|
36
35
|
// Make a request to the Pub/Sub Subscribe API
|
|
37
|
-
|
|
36
|
+
axios(
|
|
38
37
|
Object.assign({
|
|
39
|
-
|
|
38
|
+
url: that.getApiEndpoint() + '/topics/subscribe/' + '?api_key=' + that.apiKey,
|
|
40
39
|
method: 'POST',
|
|
41
|
-
|
|
42
|
-
}, that.extraRequestOptions || {})
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
// Send to callback
|
|
46
|
-
return reject(err);
|
|
47
|
-
}
|
|
40
|
+
data: postData
|
|
41
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
42
|
+
// API response
|
|
43
|
+
var body = res.data;
|
|
48
44
|
|
|
49
45
|
// Missing body?
|
|
50
46
|
if (!body) {
|
|
@@ -57,7 +53,7 @@ module.exports = function (topics, deviceToken, callback) {
|
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
// Check for 200 OK
|
|
60
|
-
if (res.
|
|
56
|
+
if (res.status != 200) {
|
|
61
57
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
62
58
|
}
|
|
63
59
|
|
|
@@ -70,6 +66,14 @@ module.exports = function (topics, deviceToken, callback) {
|
|
|
70
66
|
// Resolve the promise successfully
|
|
71
67
|
resolve();
|
|
72
68
|
}
|
|
69
|
+
}).catch(function (err) {
|
|
70
|
+
// Invoke callback/reject promise with Pushy error
|
|
71
|
+
if (err.response && err.response.data) {
|
|
72
|
+
reject(err.response.data);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
reject(err);
|
|
76
|
+
}
|
|
73
77
|
});
|
|
74
78
|
});
|
|
75
79
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Pub/Sub Subscribers API
|
|
5
4
|
module.exports = function (topic, callback) {
|
|
@@ -20,17 +19,14 @@ module.exports = function (topic, callback) {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
// Make a request to the Pub/Sub Subscribers API
|
|
23
|
-
|
|
22
|
+
axios(
|
|
24
23
|
Object.assign({
|
|
25
|
-
|
|
24
|
+
url: that.getApiEndpoint() + '/topics/' + topic + '?api_key=' + that.apiKey,
|
|
26
25
|
method: 'GET',
|
|
27
26
|
json: true
|
|
28
|
-
}, that.extraRequestOptions || {})
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
// Send to callback
|
|
32
|
-
return reject(err);
|
|
33
|
-
}
|
|
27
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
28
|
+
// API response
|
|
29
|
+
var body = res.data;
|
|
34
30
|
|
|
35
31
|
// Missing body?
|
|
36
32
|
if (!body) {
|
|
@@ -43,7 +39,7 @@ module.exports = function (topic, callback) {
|
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
// Check for 200 OK
|
|
46
|
-
if (res.
|
|
42
|
+
if (res.status != 200) {
|
|
47
43
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
48
44
|
}
|
|
49
45
|
|
|
@@ -59,6 +55,14 @@ module.exports = function (topic, callback) {
|
|
|
59
55
|
// Resolve the promise
|
|
60
56
|
resolve(body);
|
|
61
57
|
}
|
|
58
|
+
}).catch(function (err) {
|
|
59
|
+
// Invoke callback/reject promise with Pushy error
|
|
60
|
+
if (err.response && err.response.data) {
|
|
61
|
+
reject(err.response.data);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
reject(err);
|
|
65
|
+
}
|
|
62
66
|
});
|
|
63
67
|
});
|
|
64
68
|
}
|
package/api/pubsub/topics.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Pub/Sub Topics API
|
|
5
4
|
module.exports = function (callback) {
|
|
@@ -15,17 +14,14 @@ module.exports = function (callback) {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
// Make a request to the Pub/Sub Topics API
|
|
18
|
-
|
|
17
|
+
axios(
|
|
19
18
|
Object.assign({
|
|
20
|
-
|
|
19
|
+
url: that.getApiEndpoint() + '/topics/' + '?api_key=' + that.apiKey,
|
|
21
20
|
method: 'GET',
|
|
22
21
|
json: true
|
|
23
|
-
}, that.extraRequestOptions || {})
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
// Send to callback
|
|
27
|
-
return reject(err);
|
|
28
|
-
}
|
|
22
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
23
|
+
// API response
|
|
24
|
+
var body = res.data;
|
|
29
25
|
|
|
30
26
|
// Missing body?
|
|
31
27
|
if (!body) {
|
|
@@ -38,7 +34,7 @@ module.exports = function (callback) {
|
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
// Check for 200 OK
|
|
41
|
-
if (res.
|
|
37
|
+
if (res.status != 200) {
|
|
42
38
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
43
39
|
}
|
|
44
40
|
|
|
@@ -54,6 +50,14 @@ module.exports = function (callback) {
|
|
|
54
50
|
// Resolve the promise
|
|
55
51
|
resolve(body);
|
|
56
52
|
}
|
|
53
|
+
}).catch(function (err) {
|
|
54
|
+
// Invoke callback/reject promise with Pushy error
|
|
55
|
+
if (err.response && err.response.data) {
|
|
56
|
+
reject(err.response.data);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
reject(err);
|
|
60
|
+
}
|
|
57
61
|
});
|
|
58
62
|
});
|
|
59
63
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Pub/Sub Unsubscribe API
|
|
5
4
|
module.exports = function (topics, deviceToken, callback) {
|
|
@@ -34,17 +33,14 @@ module.exports = function (topics, deviceToken, callback) {
|
|
|
34
33
|
postData.topics = Array.isArray(topics) ? topics : [topics];
|
|
35
34
|
|
|
36
35
|
// Make a request to the Pub/Sub Unsubscribe API
|
|
37
|
-
|
|
36
|
+
axios(
|
|
38
37
|
Object.assign({
|
|
39
|
-
|
|
38
|
+
url: that.getApiEndpoint() + '/topics/unsubscribe/' + '?api_key=' + that.apiKey,
|
|
40
39
|
method: 'POST',
|
|
41
|
-
|
|
42
|
-
}, that.extraRequestOptions || {})
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
// Send to callback
|
|
46
|
-
return reject(err);
|
|
47
|
-
}
|
|
40
|
+
data: postData
|
|
41
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
42
|
+
// API response
|
|
43
|
+
var body = res.data;
|
|
48
44
|
|
|
49
45
|
// Missing body?
|
|
50
46
|
if (!body) {
|
|
@@ -57,7 +53,7 @@ module.exports = function (topics, deviceToken, callback) {
|
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
// Check for 200 OK
|
|
60
|
-
if (res.
|
|
56
|
+
if (res.status != 200) {
|
|
61
57
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
62
58
|
}
|
|
63
59
|
|
|
@@ -70,6 +66,14 @@ module.exports = function (topics, deviceToken, callback) {
|
|
|
70
66
|
// Resolve the promise successfully
|
|
71
67
|
resolve();
|
|
72
68
|
}
|
|
69
|
+
}).catch(function (err) {
|
|
70
|
+
// Invoke callback/reject promise with Pushy error
|
|
71
|
+
if (err.response && err.response.data) {
|
|
72
|
+
reject(err.response.data);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
reject(err);
|
|
76
|
+
}
|
|
73
77
|
});
|
|
74
78
|
});
|
|
75
79
|
}
|
package/api/push/delete.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird')
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Notification Deletion API
|
|
5
4
|
module.exports = function (pushId, callback) {
|
|
@@ -30,17 +29,14 @@ module.exports = function (pushId, callback) {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
// Make a request to the Notification Deletion API
|
|
33
|
-
|
|
32
|
+
axios(
|
|
34
33
|
Object.assign({
|
|
35
|
-
|
|
34
|
+
url: that.getApiEndpoint() + '/pushes/' + pushId + '?api_key=' + that.apiKey,
|
|
36
35
|
method: 'DELETE',
|
|
37
36
|
json: true
|
|
38
|
-
}, that.extraRequestOptions || {})
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
// Send to callback
|
|
42
|
-
return reject(err);
|
|
43
|
-
}
|
|
37
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
38
|
+
// API response
|
|
39
|
+
var body = res.data;
|
|
44
40
|
|
|
45
41
|
// Missing body?
|
|
46
42
|
if (!body) {
|
|
@@ -53,7 +49,7 @@ module.exports = function (pushId, callback) {
|
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
// Check for 200 OK
|
|
56
|
-
if (res.
|
|
52
|
+
if (res.status != 200) {
|
|
57
53
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
58
54
|
}
|
|
59
55
|
|
|
@@ -66,6 +62,14 @@ module.exports = function (pushId, callback) {
|
|
|
66
62
|
// Resolve the promise
|
|
67
63
|
resolve();
|
|
68
64
|
}
|
|
65
|
+
}).catch(function (err) {
|
|
66
|
+
// Invoke callback/reject promise with Pushy error
|
|
67
|
+
if (err.response && err.response.data) {
|
|
68
|
+
reject(err.response.data);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
reject(err);
|
|
72
|
+
}
|
|
69
73
|
});
|
|
70
74
|
});
|
|
71
75
|
};
|
package/api/push/send.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Send Notifications API
|
|
5
4
|
module.exports = function (data, recipient, options, callback) {
|
|
@@ -59,17 +58,14 @@ module.exports = function (data, recipient, options, callback) {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
// Make a request to the Send Notifications API
|
|
62
|
-
|
|
61
|
+
axios(
|
|
63
62
|
Object.assign({
|
|
64
|
-
|
|
63
|
+
url: that.getApiEndpoint() + '/push?api_key=' + that.apiKey,
|
|
65
64
|
method: 'POST',
|
|
66
|
-
|
|
67
|
-
}, that.extraRequestOptions || {})
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
// Send to callback
|
|
71
|
-
return reject(err);
|
|
72
|
-
}
|
|
65
|
+
data: postData
|
|
66
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
67
|
+
// API response
|
|
68
|
+
var body = res.data;
|
|
73
69
|
|
|
74
70
|
// Missing body?
|
|
75
71
|
if (!body) {
|
|
@@ -82,21 +78,26 @@ module.exports = function (data, recipient, options, callback) {
|
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
// Check for 200 OK
|
|
85
|
-
if (res.
|
|
81
|
+
if (res.status != 200) {
|
|
86
82
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
87
83
|
}
|
|
88
84
|
|
|
89
|
-
// Fetch push notification ID
|
|
90
|
-
var pushId = body.id;
|
|
91
|
-
|
|
92
85
|
// Callback?
|
|
93
86
|
if (callback) {
|
|
94
|
-
// Pass
|
|
95
|
-
callback(null,
|
|
87
|
+
// Pass response body to callback with a null error
|
|
88
|
+
callback(null, body);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Resolve the promise with response body
|
|
92
|
+
resolve(body);
|
|
93
|
+
}
|
|
94
|
+
}).catch(function (err) {
|
|
95
|
+
// Invoke callback/reject promise with Pushy error
|
|
96
|
+
if (err.response && err.response.data) {
|
|
97
|
+
reject(err.response.data);
|
|
96
98
|
}
|
|
97
99
|
else {
|
|
98
|
-
|
|
99
|
-
resolve(pushId);
|
|
100
|
+
reject(err);
|
|
100
101
|
}
|
|
101
102
|
});
|
|
102
103
|
});
|
package/api/push/status.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Promise = require('bluebird');
|
|
1
|
+
var axios = require('axios');
|
|
3
2
|
|
|
4
3
|
// Notification Status API
|
|
5
4
|
module.exports = function (pushId, callback) {
|
|
@@ -20,17 +19,14 @@ module.exports = function (pushId, callback) {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
// Make a request to the Notification Status API
|
|
23
|
-
|
|
22
|
+
axios(
|
|
24
23
|
Object.assign({
|
|
25
|
-
|
|
24
|
+
url: that.getApiEndpoint() + '/pushes/' + pushId + '?api_key=' + that.apiKey,
|
|
26
25
|
method: 'GET',
|
|
27
26
|
json: true
|
|
28
|
-
}, that.extraRequestOptions || {})
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
// Send to callback
|
|
32
|
-
return reject(err);
|
|
33
|
-
}
|
|
27
|
+
}, that.extraRequestOptions || {})).then(function (res) {
|
|
28
|
+
// API response
|
|
29
|
+
var body = res.data;
|
|
34
30
|
|
|
35
31
|
// Missing body?
|
|
36
32
|
if (!body) {
|
|
@@ -43,7 +39,7 @@ module.exports = function (pushId, callback) {
|
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
// Check for 200 OK
|
|
46
|
-
if (res.
|
|
42
|
+
if (res.status != 200) {
|
|
47
43
|
return reject(new Error('An invalid response code was received from the Pushy API.'));
|
|
48
44
|
}
|
|
49
45
|
|
|
@@ -59,6 +55,14 @@ module.exports = function (pushId, callback) {
|
|
|
59
55
|
// Resolve the promise
|
|
60
56
|
resolve(status);
|
|
61
57
|
}
|
|
58
|
+
}).catch(function (err) {
|
|
59
|
+
// Invoke callback/reject promise with Pushy error
|
|
60
|
+
if (err.response && err.response.data) {
|
|
61
|
+
reject(err.response.data);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
reject(err);
|
|
65
|
+
}
|
|
62
66
|
});
|
|
63
67
|
});
|
|
64
68
|
}
|
package/examples/push.js
CHANGED
|
@@ -23,14 +23,14 @@ var options = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
// Send push notification using the Send Notifications API
|
|
26
|
-
pushy.sendPushNotification(data, to, options, function (err,
|
|
26
|
+
pushy.sendPushNotification(data, to, options, function (err, result) {
|
|
27
27
|
// Log errors to console
|
|
28
28
|
if (err) {
|
|
29
29
|
return console.error(err);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Log success
|
|
33
|
-
console.log('Push sent successfully! (ID: ' + id + ')');
|
|
33
|
+
console.log('Push sent successfully! (ID: ' + result.id + ')');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
// Check the delivery status of your push notifications using the Notification Status API
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
declare module 'pushy' {
|
|
2
|
+
interface SendPushNotificationOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Specifies how long (in seconds) the push notification should be kept if the device is offline.
|
|
5
|
+
*
|
|
6
|
+
* The default value is 1 month. The maximum value is 1 year.
|
|
7
|
+
*/
|
|
8
|
+
time_to_live: number;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Schedule the notification for later by specifying a futuristic Unix timestamp (in seconds).
|
|
12
|
+
*
|
|
13
|
+
* Your scheduled time cannot exceed 1 year.
|
|
14
|
+
*/
|
|
15
|
+
schedule: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Group notifications by specifying a collapse key. When specified, any undelivered notifications
|
|
19
|
+
* pending for device(s) with the same collapse_key are discarded. Only the last message gets delivered
|
|
20
|
+
* when connectivity can be re-established with the device.
|
|
21
|
+
*
|
|
22
|
+
* Collapse keys should not exceed 32 characters.
|
|
23
|
+
*/
|
|
24
|
+
collapse_key: string;
|
|
25
|
+
|
|
26
|
+
/** When set to true, your app's notification handler will be invoked even if the app is running
|
|
27
|
+
* in the background, making it possible to fetch updated content from the server or execute other
|
|
28
|
+
* custom logic without necessarily alerting the user.
|
|
29
|
+
*
|
|
30
|
+
* Requires the Background Modes -> Remote Notifications' capability to be enabled.
|
|
31
|
+
*/
|
|
32
|
+
content_available: boolean;
|
|
33
|
+
|
|
34
|
+
/** When set to true, your app's Notification Service Extension will be invoked even if the app is
|
|
35
|
+
* running in the background, making it possible to download and display rich media attachments
|
|
36
|
+
* within your notification.
|
|
37
|
+
*
|
|
38
|
+
* Requires the Background Modes -> Remote Notifications' capability to be enabled.
|
|
39
|
+
*/
|
|
40
|
+
mutable_content: boolean;
|
|
41
|
+
|
|
42
|
+
/** iOS's notification options, such as the alert message, sound, or badge number. */
|
|
43
|
+
notification: {
|
|
44
|
+
/**
|
|
45
|
+
* The main alert message, visible on the lock screen and in other areas on iOS.
|
|
46
|
+
* Supports Apple Emojis via their unicode representation.
|
|
47
|
+
*/
|
|
48
|
+
body: string;
|
|
49
|
+
|
|
50
|
+
/** The number to display as the badge of the app icon. */
|
|
51
|
+
badge: number;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The filename of a sound in the app bundle or in the Library/Sounds folder of your app's data
|
|
55
|
+
* container, or a sound dictionary object for critical alerts (iOS 12, more info) .
|
|
56
|
+
*/
|
|
57
|
+
sound: unknown;
|
|
58
|
+
|
|
59
|
+
/** A short string describing the purpose of the notification, visible on Apple Watch and iOS 8.2+. */
|
|
60
|
+
title: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Your app's Notification Content Extension with the matching category will be invoked in order to
|
|
64
|
+
* display custom notification UI.
|
|
65
|
+
*/
|
|
66
|
+
category: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The localization key of a string present in your app's Localizable.strings file.
|
|
70
|
+
*
|
|
71
|
+
* Use this parameter to localize the notification body. Refer to the APNs documentation for more
|
|
72
|
+
* information.
|
|
73
|
+
*/
|
|
74
|
+
loc_key: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The replacement strings to substitute in place of the %@ placeholders of the localization string
|
|
78
|
+
* matching the specified loc_key.
|
|
79
|
+
*
|
|
80
|
+
* Use this parameter to localize the notification body. Refer to the APNs documentation for more
|
|
81
|
+
* information.
|
|
82
|
+
*/
|
|
83
|
+
loc_args: Array<string>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The localization key of a string present in your app's Localizable.strings file.
|
|
87
|
+
*
|
|
88
|
+
* Use this parameter to localize the notification title. Refer to the APNs documentation for more
|
|
89
|
+
* information.
|
|
90
|
+
*/
|
|
91
|
+
title_loc_key: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The replacement strings to substitute in place of the %@ placeholders of the localization string
|
|
95
|
+
* matching the specified title_loc_key.
|
|
96
|
+
*
|
|
97
|
+
* Use this parameter to localize the notification title. Refer to the APNs documentation for more
|
|
98
|
+
* information.
|
|
99
|
+
*/
|
|
100
|
+
title_loc_args: Array<string>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Indicate the importance and delivery timing of a notification on iOS 15+, with possible values
|
|
104
|
+
* of passive, active, time-sensitive, or critical.
|
|
105
|
+
*
|
|
106
|
+
* Defaults to active. Anything above active requires capabilities to be enabled in your Xcode
|
|
107
|
+
* project. Refer to the APNs documentation for more information.
|
|
108
|
+
*/
|
|
109
|
+
interruption_level: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface SendPushNotificationResult {
|
|
114
|
+
/** Returned if the API request was successful. */
|
|
115
|
+
success: boolean;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The push notification unique ID.
|
|
119
|
+
*
|
|
120
|
+
* Use it to check delivery status using the Notification Status API.
|
|
121
|
+
*/
|
|
122
|
+
id: string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Contains additional information about the notification, for debugging purposes.
|
|
126
|
+
*/
|
|
127
|
+
info: {
|
|
128
|
+
/**
|
|
129
|
+
* The number of devices that will potentially receive the notification.
|
|
130
|
+
*/
|
|
131
|
+
devices: number;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* An array of invalid device tokens passed in which could not be found in our
|
|
135
|
+
* database registered under the app with the Secret API Key used to authenticate this request.
|
|
136
|
+
*/
|
|
137
|
+
failed: Array<string>;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
interface NotificationStatus {
|
|
141
|
+
/** The creation date of the push notification (unix timestamp). */
|
|
142
|
+
date: number;
|
|
143
|
+
|
|
144
|
+
/** The push notification payload data. */
|
|
145
|
+
payload: unknown;
|
|
146
|
+
|
|
147
|
+
/** The push notification expiration date (unix timestamp). */
|
|
148
|
+
expiration: number;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* An array of device tokens that have not received the push notification yet.
|
|
152
|
+
* Limited to a maximum of 1,000 tokens.
|
|
153
|
+
*/
|
|
154
|
+
pending_devices: Array<string>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface DeviceInfo {
|
|
158
|
+
/** Metadata object for the device. */
|
|
159
|
+
device: {
|
|
160
|
+
/** The device's registration date (unix timestamp). */
|
|
161
|
+
date: number;
|
|
162
|
+
|
|
163
|
+
/** The device platform string identifier. */
|
|
164
|
+
platform: 'android' | 'ios' | 'web' | 'electron' | 'python';
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** Information about the device's presence and last communication. */
|
|
168
|
+
presence: {
|
|
169
|
+
/** The device's current connectivity status. */
|
|
170
|
+
online: boolean;
|
|
171
|
+
|
|
172
|
+
/** The device's last communication info. */
|
|
173
|
+
last_active: {
|
|
174
|
+
/** The device's last communication date (unix timestamp). */
|
|
175
|
+
date: number;
|
|
176
|
+
|
|
177
|
+
/** The device's last communication, in seconds ago. */
|
|
178
|
+
seconds_ago: number;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/** When returned, the iOS user has uninstalled your app
|
|
182
|
+
* (detected only after sending a failed notification to the device).
|
|
183
|
+
*/
|
|
184
|
+
uninstalled?: boolean;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* When returned, the Web Push user has unsubscribed from notifications from your website
|
|
188
|
+
* (detected only after sending a failed notification to the device).
|
|
189
|
+
*/
|
|
190
|
+
unsubscribed?: boolean;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Pending notifications that have not yet been delivered to the device.
|
|
195
|
+
*
|
|
196
|
+
* Only supported for Android & Electron devices.
|
|
197
|
+
* iOS & Web Push make it impossible to track notification delivery and will always return an empty array.
|
|
198
|
+
* */
|
|
199
|
+
pending_notifications: Array<{
|
|
200
|
+
/** The push notification's unique ID. */
|
|
201
|
+
id: string;
|
|
202
|
+
|
|
203
|
+
/** The creation date of the push notification (unix timestamp). */
|
|
204
|
+
date: number;
|
|
205
|
+
|
|
206
|
+
/** The push notification payload data. */
|
|
207
|
+
payload: unknown;
|
|
208
|
+
|
|
209
|
+
/** The push notification expiration date (unix timestamp). */
|
|
210
|
+
expiration: number;
|
|
211
|
+
}>;
|
|
212
|
+
|
|
213
|
+
/** An array of topics the device is subscribed to. */
|
|
214
|
+
subscriptions: Array<string>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface DevicePresenceInfo {
|
|
218
|
+
/** The device token linked to this presence object. */
|
|
219
|
+
id: string;
|
|
220
|
+
|
|
221
|
+
/** The device's current connectivity status. */
|
|
222
|
+
online: boolean;
|
|
223
|
+
|
|
224
|
+
/** The device's last connection date (unix timestamp). */
|
|
225
|
+
last_active: number;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* When returned, the iOS user has uninstalled your app
|
|
229
|
+
* (detected only after sending a failed notification to the device).
|
|
230
|
+
*/
|
|
231
|
+
uninstalled?: boolean;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* When returned, the Web Push user has unsubscribed from notifications from your website
|
|
235
|
+
* (detected only after sending a failed notification to the device).
|
|
236
|
+
*/
|
|
237
|
+
unsubscribed?: boolean;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
interface TopicStatus {
|
|
241
|
+
/** The Pub/Sub topic name. */
|
|
242
|
+
name: string;
|
|
243
|
+
|
|
244
|
+
/** The Pub/Sub topic subscriber count. */
|
|
245
|
+
subscribers: number;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
interface TopicSuscribers {
|
|
249
|
+
/** Array of device tokens currently subscribed to the provided Pub/Sub topic, limited to 1,000 per page. */
|
|
250
|
+
subscribers: Array<string>;
|
|
251
|
+
|
|
252
|
+
/** A link to fetch the next page of results, in case there are more than 1,000 subscribers for this topic. */
|
|
253
|
+
pagination: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default class Pushy {
|
|
257
|
+
constructor(apiKey: string);
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Send push notification
|
|
261
|
+
* @see {@link https://pushy.me/docs/api/send-notifications}
|
|
262
|
+
*
|
|
263
|
+
* @param data JSON notification data object
|
|
264
|
+
* @param recipient one or array of device token OR one or array of topics
|
|
265
|
+
* @param options Extra options for the notification
|
|
266
|
+
*
|
|
267
|
+
* @returns pushId
|
|
268
|
+
*/
|
|
269
|
+
sendPushNotification(
|
|
270
|
+
data: unknown,
|
|
271
|
+
recipient: string | Array<string>,
|
|
272
|
+
options?: SendPushNotificationOptions,
|
|
273
|
+
callback?: (error: Error | null, result: SendPushNotificationResult) => void
|
|
274
|
+
): Promise<SendPushNotificationResult>;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Check the delivery status of your push notifications to Android / Electron recipients.
|
|
278
|
+
* @see {@link https://pushy.me/docs/api/notification-status}
|
|
279
|
+
*
|
|
280
|
+
* @param pushId
|
|
281
|
+
*/
|
|
282
|
+
getNotificationStatus(
|
|
283
|
+
pushId: string,
|
|
284
|
+
callback?: (error: Error | null, status: NotificationStatus) => void
|
|
285
|
+
): Promise<NotificationStatus>;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Permanently delete a pending notification.
|
|
289
|
+
* @see {@link https://pushy.me/docs/api/notification-deletion}
|
|
290
|
+
*
|
|
291
|
+
* @param pushId
|
|
292
|
+
*/
|
|
293
|
+
deletePushNotification(pushId: string, callback?: (error: Error | null) => void): Promise<void>;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Check the presence and connectivity status of multiple devices.
|
|
297
|
+
* @see {@link https://pushy.me/docs/api/device-presence}
|
|
298
|
+
*
|
|
299
|
+
* @param deviceTokens
|
|
300
|
+
*/
|
|
301
|
+
getDevicePresence(
|
|
302
|
+
deviceTokens: string | Array<string>,
|
|
303
|
+
callback?: (error: Error | null, presence: Array<DevicePresenceInfo>) => void
|
|
304
|
+
): Promise<Array<DevicePresenceInfo>>;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Fetch device info, presence, undelivered notifications, and more by device token.
|
|
308
|
+
*
|
|
309
|
+
* @see {@link https://pushy.me/docs/api/device}
|
|
310
|
+
*
|
|
311
|
+
* @param deviceToken
|
|
312
|
+
*/
|
|
313
|
+
getDeviceInfo(
|
|
314
|
+
deviceToken: string,
|
|
315
|
+
callback?: (error: Error | null, device: DeviceInfo) => void
|
|
316
|
+
): Promise<DeviceInfo>;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Subscribe a device to one or more topics.
|
|
320
|
+
* @see {@link https://pushy.me/docs/api/pubsub-subscribe}
|
|
321
|
+
*
|
|
322
|
+
* @param topics
|
|
323
|
+
* @param deviceToken
|
|
324
|
+
*/
|
|
325
|
+
subscribe(
|
|
326
|
+
topics: string | Array<string>,
|
|
327
|
+
deviceToken: string,
|
|
328
|
+
callback?: (error: Error | null) => void
|
|
329
|
+
): Promise<void>;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Unsubscribe a device from one or more topics.
|
|
333
|
+
* @see {@link https://pushy.me/docs/api/pubsub-unsubscribe}
|
|
334
|
+
*
|
|
335
|
+
* @param topics
|
|
336
|
+
* @param deviceToken
|
|
337
|
+
*/
|
|
338
|
+
unsubscribe(
|
|
339
|
+
topics: string | Array<string>,
|
|
340
|
+
deviceToken: string,
|
|
341
|
+
callback?: (error: Error | null) => void
|
|
342
|
+
): Promise<void>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Retrieve a list of your app's topics and subscribers count.
|
|
346
|
+
* @see {@link https://pushy.me/docs/api/pubsub-topics}
|
|
347
|
+
*/
|
|
348
|
+
getTopics(): Promise<Array<TopicStatus>>;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Retrieve a list of devices subscribed to a certain topic.
|
|
352
|
+
* @see {@link https://pushy.me/docs/api/pubsub-subscribers}
|
|
353
|
+
*
|
|
354
|
+
* @param topic The Pub/Sub topic to retrieve subscribers for. Topics are case-sensitive and must match the following regular expression: [a-zA-Z0-9-_.]+.
|
|
355
|
+
*/
|
|
356
|
+
getSubscribers(
|
|
357
|
+
topic: string,
|
|
358
|
+
callback?: (error: Error | null, subscribers: TopicSuscribers) => void
|
|
359
|
+
): Promise<TopicSuscribers>;
|
|
360
|
+
}
|
|
361
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pushy",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "The official Node.js package for sending push notifications with Pushy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/pushy/pushy-node#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"
|
|
21
|
-
"request": "^2.72.0"
|
|
20
|
+
"axios": "^0.27.2"
|
|
22
21
|
}
|
|
23
22
|
}
|