@arkstack/notifications 0.17.22 → 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 +23 -1
- package/dist/index.js +47 -9
- package/package.json +5 -4
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
|
};
|
|
@@ -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;
|
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,7 +34,7 @@
|
|
|
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",
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
"pusher": "^5.2.0",
|
|
43
43
|
"@arkstack/contract": "^0.17.22",
|
|
44
44
|
"@arkstack/database": "^0.17.22",
|
|
45
|
-
"@arkstack/driver-express": "^0.17.
|
|
46
|
-
"@arkstack/
|
|
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": {
|