@arkstack/notifications 0.16.12 → 0.17.0
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/dist/index.d.ts +26 -0
- package/dist/index.js +34 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -215,13 +215,29 @@ declare abstract class NotificationContract<TResult = DriverResult> {
|
|
|
215
215
|
declare class DbNotification extends NotificationContract<UserNotification> {
|
|
216
216
|
private user?;
|
|
217
217
|
private payload;
|
|
218
|
+
private realtime;
|
|
218
219
|
from(_from: string): this;
|
|
219
220
|
subject(subject: string): this;
|
|
220
221
|
recipient(recipient: NotificationRecipient | User): this;
|
|
221
222
|
type(type: DbNotificationPayload['type']): this;
|
|
222
223
|
action(text?: string | null, link?: string | null): this;
|
|
223
224
|
meta(meta?: NotificationData | null): this;
|
|
225
|
+
/**
|
|
226
|
+
* Broadcast the notification using the default realtime driver.
|
|
227
|
+
*
|
|
228
|
+
* @param realtime Set to false to disable realtime broadcast
|
|
229
|
+
*/
|
|
230
|
+
broadcast(realtime?: boolean): void;
|
|
224
231
|
create(user: User, payload: DbNotificationPayload): Promise<UserNotification>;
|
|
232
|
+
/**
|
|
233
|
+
* Send the database notification
|
|
234
|
+
*
|
|
235
|
+
* @param message
|
|
236
|
+
* @param subject
|
|
237
|
+
* @param _recipient
|
|
238
|
+
* @param data
|
|
239
|
+
* @returns
|
|
240
|
+
*/
|
|
225
241
|
send(message: string, subject?: string, _recipient?: NotificationRecipient, data?: NotificationData): Promise<UserNotification>;
|
|
226
242
|
}
|
|
227
243
|
//#endregion
|
|
@@ -362,6 +378,15 @@ declare class RealtimeNotification extends NotificationContract<RealtimeBroadcas
|
|
|
362
378
|
action(text?: string | null, link?: string | null): this;
|
|
363
379
|
meta(meta?: NotificationData | null): this;
|
|
364
380
|
private resolveChannel;
|
|
381
|
+
/**
|
|
382
|
+
* Send a realtime notification using the default realtime driver
|
|
383
|
+
*
|
|
384
|
+
* @param message
|
|
385
|
+
* @param subject
|
|
386
|
+
* @param _recipient
|
|
387
|
+
* @param data
|
|
388
|
+
* @returns
|
|
389
|
+
*/
|
|
365
390
|
send(message: string, subject?: string, _recipient?: NotificationRecipient, data?: NotificationData): Promise<RealtimeBroadcastResult>;
|
|
366
391
|
}
|
|
367
392
|
//#endregion
|
|
@@ -429,6 +454,7 @@ declare class UserNotificationCenter {
|
|
|
429
454
|
* @param payload
|
|
430
455
|
*/
|
|
431
456
|
static send(user: User, payload: DbNotificationPayload, channel?: string[]): Promise<RealtimeBroadcastResult>;
|
|
457
|
+
private static resolvePushTokens;
|
|
432
458
|
/**
|
|
433
459
|
* Create a database notification
|
|
434
460
|
*
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,12 @@ var UserNotificationCenter = class {
|
|
|
36
36
|
* @param payload
|
|
37
37
|
*/
|
|
38
38
|
static async send(user, payload, channel = []) {
|
|
39
|
-
return await Notification.realtime().store().channel(user.pushTokens ?? channel).meta(payload.meta).type(payload.type).subject(payload.title).action(payload.actionText, payload.actionLink).send(payload.description, payload.title, void 0, payload);
|
|
39
|
+
return await Notification.realtime().store().channel(this.resolvePushTokens(user.pushTokens ?? channel)).meta(payload.meta).type(payload.type).subject(payload.title).action(payload.actionText, payload.actionLink).send(payload.description, payload.title, void 0, payload);
|
|
40
|
+
}
|
|
41
|
+
static resolvePushTokens(pushTokens) {
|
|
42
|
+
if (!pushTokens) return [];
|
|
43
|
+
if (Array.isArray(pushTokens)) return pushTokens.map((e) => typeof e === "string" ? e : e.token);
|
|
44
|
+
return [typeof pushTokens === "string" ? pushTokens : pushTokens.token];
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
42
47
|
* Create a database notification
|
|
@@ -120,6 +125,7 @@ const interpolate = (value, data = {}) => {
|
|
|
120
125
|
var DbNotification = class extends NotificationContract {
|
|
121
126
|
user;
|
|
122
127
|
payload = {};
|
|
128
|
+
realtime = false;
|
|
123
129
|
from(_from) {
|
|
124
130
|
return this;
|
|
125
131
|
}
|
|
@@ -147,10 +153,28 @@ var DbNotification = class extends NotificationContract {
|
|
|
147
153
|
this.payload.meta = meta;
|
|
148
154
|
return this;
|
|
149
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Broadcast the notification using the default realtime driver.
|
|
158
|
+
*
|
|
159
|
+
* @param realtime Set to false to disable realtime broadcast
|
|
160
|
+
*/
|
|
161
|
+
broadcast(realtime = true) {
|
|
162
|
+
this.realtime = realtime;
|
|
163
|
+
}
|
|
150
164
|
async create(user, payload) {
|
|
151
165
|
await getModel("UserNotification");
|
|
166
|
+
if (this.realtime) return await UserNotificationCenter.send(user, payload);
|
|
152
167
|
return await UserNotificationCenter.create(user, payload);
|
|
153
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Send the database notification
|
|
171
|
+
*
|
|
172
|
+
* @param message
|
|
173
|
+
* @param subject
|
|
174
|
+
* @param _recipient
|
|
175
|
+
* @param data
|
|
176
|
+
* @returns
|
|
177
|
+
*/
|
|
154
178
|
async send(message, subject, _recipient, data) {
|
|
155
179
|
if (!this.user) throw new Error("No user recipient provided for database notification");
|
|
156
180
|
const mergedData = this.mergeData(data);
|
|
@@ -584,6 +608,15 @@ var RealtimeNotification = class extends NotificationContract {
|
|
|
584
608
|
if (this.user) return `${this.channelPrefix}${this.user.id}`;
|
|
585
609
|
throw new Error("No channel resolved for realtime notification (provide a user or channel)");
|
|
586
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* Send a realtime notification using the default realtime driver
|
|
613
|
+
*
|
|
614
|
+
* @param message
|
|
615
|
+
* @param subject
|
|
616
|
+
* @param _recipient
|
|
617
|
+
* @param data
|
|
618
|
+
* @returns
|
|
619
|
+
*/
|
|
587
620
|
async send(message, subject, _recipient, data) {
|
|
588
621
|
const channel = this.resolveChannel();
|
|
589
622
|
const mergedData = this.mergeData(data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/notifications",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Framework-agnostic notification module for Arkstack and Nodejs, providing support for multi-channel notification delivery.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net/guide/notifications",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"africastalking": "^0.8.0",
|
|
35
35
|
"nodemailer": "^8.0.7",
|
|
36
36
|
"twilio": "^6.0.0",
|
|
37
|
-
"@arkstack/common": "^0.
|
|
37
|
+
"@arkstack/common": "^0.17.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@kanun-hq/plugin-phone": "^0.1.8",
|
|
41
41
|
"firebase-admin": "^13.0.0",
|
|
42
42
|
"pusher": "^5.2.0",
|
|
43
|
-
"@arkstack/contract": "^0.
|
|
44
|
-
"@arkstack/database": "^0.
|
|
43
|
+
"@arkstack/contract": "^0.17.0",
|
|
44
|
+
"@arkstack/database": "^0.17.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependenciesMeta": {
|
|
47
47
|
"pusher": {
|