pushy 2.0.13 → 2.0.14

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.
Files changed (2) hide show
  1. package/index.d.ts +314 -0
  2. package/package.json +1 -1
package/index.d.ts ADDED
@@ -0,0 +1,314 @@
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 NotificationStatus {
114
+ /** The creation date of the push notification (unix timestamp). */
115
+ date: number;
116
+
117
+ /** The push notification payload data. */
118
+ payload: unknown;
119
+
120
+ /** The push notification expiration date (unix timestamp). */
121
+ expiration: number;
122
+
123
+ /**
124
+ * An array of device tokens that have not received the push notification yet.
125
+ * Limited to a maximum of 1,000 tokens.
126
+ */
127
+ pending_devices: Array<string>;
128
+ }
129
+
130
+ interface DeviceInfo {
131
+ /** Metadata object for the device. */
132
+ device: {
133
+ /** The device's registration date (unix timestamp). */
134
+ date: number;
135
+
136
+ /** The device platform string identifier. */
137
+ platform: 'android' | 'ios' | 'web' | 'electron' | 'python';
138
+ };
139
+
140
+ /** Information about the device's presence and last communication. */
141
+ presence: {
142
+ /** The device's current connectivity status. */
143
+ online: boolean;
144
+
145
+ /** The device's last communication info. */
146
+ last_active: {
147
+ /** The device's last communication date (unix timestamp). */
148
+ date: number;
149
+
150
+ /** The device's last communication, in seconds ago. */
151
+ seconds_ago: number;
152
+ };
153
+
154
+ /** When returned, the iOS user has uninstalled your app
155
+ * (detected only after sending a failed notification to the device).
156
+ */
157
+ uninstalled?: boolean;
158
+
159
+ /**
160
+ * When returned, the Web Push user has unsubscribed from notifications from your website
161
+ * (detected only after sending a failed notification to the device).
162
+ */
163
+ unsubscribed?: boolean;
164
+ };
165
+
166
+ /**
167
+ * Pending notifications that have not yet been delivered to the device.
168
+ *
169
+ * Only supported for Android & Electron devices.
170
+ * iOS & Web Push make it impossible to track notification delivery and will always return an empty array.
171
+ * */
172
+ pending_notifications: Array<{
173
+ /** The push notification's unique ID. */
174
+ id: string;
175
+
176
+ /** The creation date of the push notification (unix timestamp). */
177
+ date: number;
178
+
179
+ /** The push notification payload data. */
180
+ payload: unknown;
181
+
182
+ /** The push notification expiration date (unix timestamp). */
183
+ expiration: number;
184
+ }>;
185
+
186
+ /** An array of topics the device is subscribed to. */
187
+ subscriptions: Array<string>;
188
+ }
189
+
190
+ interface DevicePresenceInfo {
191
+ /** The device token linked to this presence object. */
192
+ id: string;
193
+
194
+ /** The device's current connectivity status. */
195
+ online: boolean;
196
+
197
+ /** The device's last connection date (unix timestamp). */
198
+ last_active: number;
199
+
200
+ /**
201
+ * When returned, the iOS user has uninstalled your app
202
+ * (detected only after sending a failed notification to the device).
203
+ */
204
+ uninstalled?: boolean;
205
+
206
+ /**
207
+ * When returned, the Web Push user has unsubscribed from notifications from your website
208
+ * (detected only after sending a failed notification to the device).
209
+ */
210
+ unsubscribed?: boolean;
211
+ }
212
+
213
+ interface TopicStatus {
214
+ /** The Pub/Sub topic name. */
215
+ name: string;
216
+
217
+ /** The Pub/Sub topic subscriber count. */
218
+ subscribers: number;
219
+ }
220
+
221
+ interface TopicSuscribers {
222
+ /** Array of device tokens currently subscribed to the provided Pub/Sub topic, limited to 1,000 per page. */
223
+ subscribers: Array<string>;
224
+
225
+ /** A link to fetch the next page of results, in case there are more than 1,000 subscribers for this topic. */
226
+ pagination: string;
227
+ }
228
+
229
+ export default class Pushy {
230
+ constructor(apiKey: string);
231
+
232
+ /**
233
+ * Send push notification
234
+ * @see {@link https://pushy.me/docs/api/send-notifications}
235
+ *
236
+ * @param data JSON notification data object
237
+ * @param recipient one or array of device token OR one or array of topics
238
+ * @param options Extra options for the notification
239
+ *
240
+ * @returns pushId
241
+ */
242
+ sendPushNotification(
243
+ data: unknown,
244
+ recipient: string | Array<string>,
245
+ options?: SendPushNotificationOptions,
246
+ callback?: (error: Error | null, pushId: string) => void
247
+ ): Promise<string>;
248
+
249
+ /**
250
+ * Check the delivery status of your push notifications to Android / Electron recipients.
251
+ * @see {@link https://pushy.me/docs/api/notification-status}
252
+ *
253
+ * @param pushId
254
+ */
255
+ getNotificationStatus(pushId: string): Promise<NotificationStatus>;
256
+
257
+ /**
258
+ * Permanently delete a pending notification.
259
+ * @see {@link https://pushy.me/docs/api/notification-deletion}
260
+ *
261
+ * @param pushId
262
+ */
263
+ deletePushNotification(pushId: string): Promise<void>;
264
+
265
+ /**
266
+ * Check the presence and connectivity status of multiple devices.
267
+ * @see {@link https://pushy.me/docs/api/device-presence}
268
+ *
269
+ * @param deviceTokens
270
+ */
271
+ getDevicePresence(deviceTokens: string | Array<string>): Promise<Array<DevicePresenceInfo>>;
272
+
273
+ /**
274
+ * Fetch device info, presence, undelivered notifications, and more by device token.
275
+ *
276
+ * @see {@link https://pushy.me/docs/api/device}
277
+ *
278
+ * @param deviceToken
279
+ */
280
+ getDeviceInfo(deviceToken: string): Promise<DeviceInfo>;
281
+
282
+ /**
283
+ * Subscribe a device to one or more topics.
284
+ * @see {@link https://pushy.me/docs/api/pubsub-subscribe}
285
+ *
286
+ * @param topics
287
+ * @param deviceToken
288
+ */
289
+ subscribe(topics: string | Array<string>, deviceToken: string): Promise<void>;
290
+
291
+ /**
292
+ * Unsubscribe a device from one or more topics.
293
+ * @see {@link https://pushy.me/docs/api/pubsub-unsubscribe}
294
+ *
295
+ * @param topics
296
+ * @param deviceToken
297
+ */
298
+ unsubscribe(topics: string | Array<string>, deviceToken: string): Promise<void>;
299
+
300
+ /**
301
+ * Retrieve a list of your app's topics and subscribers count.
302
+ * @see {@link https://pushy.me/docs/api/pubsub-topics}
303
+ */
304
+ getTopics(): Promise<Array<TopicStatus>>;
305
+
306
+ /**
307
+ * Retrieve a list of devices subscribed to a certain topic.
308
+ * @see {@link https://pushy.me/docs/api/pubsub-subscribers}
309
+ *
310
+ * @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-_.]+.
311
+ */
312
+ getSubscribers(topic: string): Promise<TopicSuscribers>;
313
+ }
314
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushy",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "description": "The official Node.js package for sending push notifications with Pushy.",
5
5
  "main": "index.js",
6
6
  "scripts": {