@arkstack/notifications 0.17.21 → 0.17.23
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 +25 -3
- package/dist/index.js +49 -9
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -237,6 +237,10 @@ interface NotificationConfig<T = any> {
|
|
|
237
237
|
admin_sdk_path: string;
|
|
238
238
|
};
|
|
239
239
|
};
|
|
240
|
+
queue?: {
|
|
241
|
+
name?: string;
|
|
242
|
+
connection?: string;
|
|
243
|
+
};
|
|
240
244
|
}
|
|
241
245
|
type MergedTransportConfig = MergedConfig<Required<NotificationConfig['transports']>[NonNullable<MailDriverOptions['transport']>]>;
|
|
242
246
|
type MailNotificationOptions = MailDriverOptions & {
|
|
@@ -246,11 +250,29 @@ type MailNotificationOptions = MailDriverOptions & {
|
|
|
246
250
|
//#region src/Contracts/NotificationContract.d.ts
|
|
247
251
|
declare abstract class NotificationContract<TResult = DriverResult> {
|
|
248
252
|
protected contextData: NotificationData;
|
|
253
|
+
/**
|
|
254
|
+
* Send your notification
|
|
255
|
+
*
|
|
256
|
+
* @param message
|
|
257
|
+
* @param subject
|
|
258
|
+
* @param recipient
|
|
259
|
+
* @param data
|
|
260
|
+
*/
|
|
249
261
|
abstract send(message: string, subject?: string, recipient?: NotificationRecipient, data?: NotificationData): Promise<TResult>;
|
|
250
262
|
abstract from(from: string): this;
|
|
251
263
|
abstract subject(subject: string): this;
|
|
252
264
|
abstract recipient(recipient: NotificationRecipient): this;
|
|
253
265
|
data(data: NotificationData): this;
|
|
266
|
+
/**
|
|
267
|
+
* Send the notification to our configured queue
|
|
268
|
+
*
|
|
269
|
+
* @param message
|
|
270
|
+
* @param subject
|
|
271
|
+
* @param recipient
|
|
272
|
+
* @param data
|
|
273
|
+
* @returns
|
|
274
|
+
*/
|
|
275
|
+
queue(message: string, subject?: string, recipient?: NotificationRecipient, data?: NotificationData): Promise<string>;
|
|
254
276
|
protected mergeData(data?: NotificationData): {
|
|
255
277
|
year: number;
|
|
256
278
|
};
|
|
@@ -319,13 +341,13 @@ declare class MailNotification extends NotificationContract {
|
|
|
319
341
|
*
|
|
320
342
|
* @param attachments
|
|
321
343
|
*/
|
|
322
|
-
attachments(attachments: Attachment[]):
|
|
344
|
+
attachments(attachments: Attachment[]): this;
|
|
323
345
|
/**
|
|
324
346
|
* A single attachemnt to send with the mail
|
|
325
347
|
*
|
|
326
348
|
* @param attachment
|
|
327
349
|
*/
|
|
328
|
-
attachment(attachment: Attachment):
|
|
350
|
+
attachment(attachment: Attachment): this;
|
|
329
351
|
/**
|
|
330
352
|
* Set email the notification recipeint
|
|
331
353
|
*
|
|
@@ -712,7 +734,7 @@ declare class UserNotificationCenter {
|
|
|
712
734
|
}
|
|
713
735
|
//#endregion
|
|
714
736
|
//#region src/config.d.ts
|
|
715
|
-
declare const configure: <T extends DotPath<NotificationConfig>>(key: T, defaultValue
|
|
737
|
+
declare const configure: <T extends DotPath<NotificationConfig>>(key: T, defaultValue?: unknown) => DotPathValue<NotificationConfig, T>;
|
|
716
738
|
//#endregion
|
|
717
739
|
//#region src/utils/template.d.ts
|
|
718
740
|
declare const interpolate: (value: string, data?: NotificationData) => string;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Job } from "@arkstack/jobs";
|
|
1
2
|
import { RequestException, config as config$1, env, getModel } from "@arkstack/common";
|
|
2
3
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
4
|
import path, { join } from "node:path";
|
|
@@ -8,6 +9,37 @@ import { randomUUID } from "node:crypto";
|
|
|
8
9
|
import africastalking from "africastalking";
|
|
9
10
|
import twilio from "twilio";
|
|
10
11
|
import { Model } from "@arkstack/database";
|
|
12
|
+
//#region src/jobs/SendNotification.ts
|
|
13
|
+
var SendNotification = class extends Job {
|
|
14
|
+
notification;
|
|
15
|
+
message;
|
|
16
|
+
subject;
|
|
17
|
+
recipient;
|
|
18
|
+
data;
|
|
19
|
+
tries = 3;
|
|
20
|
+
backoff = 30;
|
|
21
|
+
constructor(notification, message, subject, recipient, data) {
|
|
22
|
+
super();
|
|
23
|
+
this.notification = notification;
|
|
24
|
+
this.message = message;
|
|
25
|
+
this.subject = subject;
|
|
26
|
+
this.recipient = recipient;
|
|
27
|
+
this.data = data;
|
|
28
|
+
}
|
|
29
|
+
async handle() {
|
|
30
|
+
await this.notification.send(this.message, this.subject, this.recipient, this.data);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/config.ts
|
|
35
|
+
const configure = (key, defaultValue) => {
|
|
36
|
+
try {
|
|
37
|
+
return config$1(`notifications.${key}`, defaultValue);
|
|
38
|
+
} catch {
|
|
39
|
+
return defaultValue;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
11
43
|
//#region src/Contracts/NotificationContract.ts
|
|
12
44
|
var NotificationContract = class {
|
|
13
45
|
contextData = {};
|
|
@@ -15,6 +47,21 @@ var NotificationContract = class {
|
|
|
15
47
|
this.contextData = data;
|
|
16
48
|
return this;
|
|
17
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Send the notification to our configured queue
|
|
52
|
+
*
|
|
53
|
+
* @param message
|
|
54
|
+
* @param subject
|
|
55
|
+
* @param recipient
|
|
56
|
+
* @param data
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
async queue(message, subject, recipient, data) {
|
|
60
|
+
const job = SendNotification.dispatch(this, message, subject, recipient, data);
|
|
61
|
+
if (configure("queue.name")) job.onQueue(configure("queue.name"));
|
|
62
|
+
if (configure("queue.connection")) job.onConnection(configure("queue.connection"));
|
|
63
|
+
return job;
|
|
64
|
+
}
|
|
18
65
|
mergeData(data) {
|
|
19
66
|
return {
|
|
20
67
|
...this.contextData,
|
|
@@ -189,15 +236,6 @@ var DbNotification = class extends NotificationContract {
|
|
|
189
236
|
}
|
|
190
237
|
};
|
|
191
238
|
//#endregion
|
|
192
|
-
//#region src/config.ts
|
|
193
|
-
const configure = (key, defaultValue) => {
|
|
194
|
-
try {
|
|
195
|
-
return config$1(`notifications.${key}`, defaultValue);
|
|
196
|
-
} catch {
|
|
197
|
-
return defaultValue;
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
//#endregion
|
|
201
239
|
//#region src/drivers/MailNotification.ts
|
|
202
240
|
var MailNotification = class extends NotificationContract {
|
|
203
241
|
driver;
|
|
@@ -312,6 +350,7 @@ var MailNotification = class extends NotificationContract {
|
|
|
312
350
|
*/
|
|
313
351
|
attachments(attachments) {
|
|
314
352
|
this.attachmentList = attachments;
|
|
353
|
+
return this;
|
|
315
354
|
}
|
|
316
355
|
/**
|
|
317
356
|
* A single attachemnt to send with the mail
|
|
@@ -320,6 +359,7 @@ var MailNotification = class extends NotificationContract {
|
|
|
320
359
|
*/
|
|
321
360
|
attachment(attachment) {
|
|
322
361
|
this.attachmentList = [...this.attachmentList ?? [], attachment];
|
|
362
|
+
return this;
|
|
323
363
|
}
|
|
324
364
|
/**
|
|
325
365
|
* Set email the notification recipeint
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/notifications",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.23",
|
|
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,16 +34,17 @@
|
|
|
34
34
|
"africastalking": "^0.8.0",
|
|
35
35
|
"nodemailer": "^9.0.3",
|
|
36
36
|
"twilio": "^6.0.2",
|
|
37
|
-
"@arkstack/common": "^0.17.
|
|
37
|
+
"@arkstack/common": "^0.17.23"
|
|
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.17.
|
|
44
|
-
"@arkstack/database": "^0.17.
|
|
45
|
-
"@arkstack/driver-
|
|
46
|
-
"@arkstack/
|
|
43
|
+
"@arkstack/contract": "^0.17.22",
|
|
44
|
+
"@arkstack/database": "^0.17.22",
|
|
45
|
+
"@arkstack/driver-express": "^0.17.23",
|
|
46
|
+
"@arkstack/jobs": "^0.17.23",
|
|
47
|
+
"@arkstack/driver-h3": "^0.17.23"
|
|
47
48
|
},
|
|
48
49
|
"peerDependenciesMeta": {
|
|
49
50
|
"@arkstack/driver-express": {
|