|
1 | 1 | const EventEmitter = require('events'); |
| 2 | +const VError = require('verror'); |
2 | 3 |
|
3 | 4 | module.exports = function (dependencies) { |
4 | 5 | const Client = dependencies.Client; |
@@ -42,6 +43,51 @@ module.exports = function (dependencies) { |
42 | 43 | }); |
43 | 44 | }; |
44 | 45 |
|
| 46 | + Provider.prototype.manageChannels = function manageChannels(notification, bundleId, action) { |
| 47 | + let type = 'channels'; |
| 48 | + let method = 'post'; |
| 49 | + |
| 50 | + switch (action) { |
| 51 | + case 'create': |
| 52 | + if (notification['push-type'] == null) { |
| 53 | + // Add live activity push type if it's not already provided. |
| 54 | + // Live activity is the only current type supported. |
| 55 | + // Note, this seems like it should be lower cased, but the |
| 56 | + // docs shows it in the current format. |
| 57 | + notification['push-type'] = 'LiveActivity'; |
| 58 | + } |
| 59 | + type = 'channels'; |
| 60 | + method = 'post'; |
| 61 | + break; |
| 62 | + case 'read': |
| 63 | + type = 'channels'; |
| 64 | + method = 'get'; |
| 65 | + break; |
| 66 | + case 'readAll': |
| 67 | + type = 'allChannels'; |
| 68 | + method = 'get'; |
| 69 | + break; |
| 70 | + case 'delete': |
| 71 | + type = 'channels'; |
| 72 | + method = 'delete'; |
| 73 | + break; |
| 74 | + default: { |
| 75 | + const error = { |
| 76 | + bundleId, |
| 77 | + error: new VError(`the action "${action}" is not supported`), |
| 78 | + }; |
| 79 | + return Promise.resolve(error); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + const builtNotification = { |
| 84 | + headers: notification.headers(), |
| 85 | + body: notification.compile(), |
| 86 | + }; |
| 87 | + |
| 88 | + return this.client.write(builtNotification, bundleId, type, method); |
| 89 | + }; |
| 90 | + |
45 | 91 | Provider.prototype.broadcast = function broadcast(notification, bundleId) { |
46 | 92 | const builtNotification = { |
47 | 93 | headers: notification.headers(), |
|
0 commit comments