@arkstack/notifications 0.16.8 → 0.16.10
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 +4 -2
- package/dist/index.js +8 -4
- package/package.json +10 -5
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Transporter } from "nodemailer";
|
|
|
3
3
|
import { Model } from "@arkstack/database";
|
|
4
4
|
import { User } from "@app/models/User";
|
|
5
5
|
import { User as User$1 } from "@arkstack/auth";
|
|
6
|
+
import { PhoneNumber } from "@kanun-hq/plugin-phone";
|
|
6
7
|
|
|
7
8
|
//#region src/Contracts/UserNotification.d.ts
|
|
8
9
|
declare abstract class UserNotification extends Model {
|
|
@@ -374,8 +375,9 @@ declare class SmsNotification extends NotificationContract {
|
|
|
374
375
|
constructor(options?: SmsDriverOptions);
|
|
375
376
|
from(from: string): this;
|
|
376
377
|
subject(_subject: string): this;
|
|
377
|
-
recipient(recipient: NotificationRecipient): this;
|
|
378
|
-
send(message: string, _subject?: string, recipient?: NotificationRecipient, data?: NotificationData): Promise<unknown>;
|
|
378
|
+
recipient(recipient: NotificationRecipient | PhoneNumber | PhoneNumber[]): this;
|
|
379
|
+
send(message: string, _subject?: string, recipient?: NotificationRecipient | PhoneNumber | PhoneNumber[], data?: NotificationData): Promise<unknown>;
|
|
380
|
+
private resolveRecipient;
|
|
379
381
|
}
|
|
380
382
|
//#endregion
|
|
381
383
|
//#region src/Contracts/Maps.d.ts
|
package/dist/index.js
CHANGED
|
@@ -447,7 +447,7 @@ var RealtimeNotification = class extends NotificationContract {
|
|
|
447
447
|
* @returns
|
|
448
448
|
*/
|
|
449
449
|
recipient(recipient) {
|
|
450
|
-
if (typeof recipient === "object" && !Array.isArray(recipient) &&
|
|
450
|
+
if (typeof recipient === "object" && !Array.isArray(recipient) && typeof recipient.id !== "undefined") {
|
|
451
451
|
this.user = recipient;
|
|
452
452
|
return this;
|
|
453
453
|
}
|
|
@@ -622,14 +622,18 @@ var SmsNotification = class extends NotificationContract {
|
|
|
622
622
|
return this;
|
|
623
623
|
}
|
|
624
624
|
async send(message, _subject, recipient, data) {
|
|
625
|
-
const resolvedRecipient = recipient ?? this.recipients;
|
|
626
|
-
if (!resolvedRecipient) throw new Error("No recipient provided for SMS notification");
|
|
625
|
+
const resolvedRecipient = this.resolveRecipient(recipient ?? this.recipients ?? []);
|
|
626
|
+
if (!resolvedRecipient || Array.isArray(resolvedRecipient) && resolvedRecipient.length === 0) throw new Error("No recipient provided for SMS notification");
|
|
627
627
|
return await this.driver.send(message, resolvedRecipient, {
|
|
628
628
|
app_name: env("APP_NAME", "Arkstack"),
|
|
629
629
|
from: this.fromValue,
|
|
630
630
|
...this.mergeData(data)
|
|
631
631
|
});
|
|
632
632
|
}
|
|
633
|
+
resolveRecipient(recipient) {
|
|
634
|
+
if (Array.isArray(recipient)) return recipient.map((r) => typeof r === "string" ? r : r.toString());
|
|
635
|
+
return typeof recipient === "string" ? recipient : recipient.toString();
|
|
636
|
+
}
|
|
633
637
|
};
|
|
634
638
|
//#endregion
|
|
635
639
|
//#region src/Notification.ts
|
|
@@ -658,7 +662,7 @@ var Notification = class Notification {
|
|
|
658
662
|
}
|
|
659
663
|
prepare(recipient, data = {}) {
|
|
660
664
|
this.driver.data(data);
|
|
661
|
-
if (recipient && typeof recipient === "object" && !Array.isArray(recipient) &&
|
|
665
|
+
if (recipient && typeof recipient === "object" && !Array.isArray(recipient) && typeof recipient.id !== "undefined") {
|
|
662
666
|
if (this.driver instanceof MailNotification) {
|
|
663
667
|
if (recipient.email) this.driver.recipient(recipient.email);
|
|
664
668
|
} else if (this.driver instanceof SmsNotification) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/notifications",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.10",
|
|
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,13 +34,14 @@
|
|
|
34
34
|
"africastalking": "^0.8.0",
|
|
35
35
|
"nodemailer": "^8.0.7",
|
|
36
36
|
"twilio": "^6.0.0",
|
|
37
|
-
"@arkstack/common": "^0.16.
|
|
37
|
+
"@arkstack/common": "^0.16.10"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"
|
|
40
|
+
"@kanun-hq/plugin-phone": "^0.1.8",
|
|
41
41
|
"firebase-admin": "^13.0.0",
|
|
42
|
-
"
|
|
43
|
-
"@arkstack/
|
|
42
|
+
"pusher": "^5.2.0",
|
|
43
|
+
"@arkstack/contract": "^0.16.10",
|
|
44
|
+
"@arkstack/database": "^0.16.10"
|
|
44
45
|
},
|
|
45
46
|
"peerDependenciesMeta": {
|
|
46
47
|
"pusher": {
|
|
@@ -48,9 +49,13 @@
|
|
|
48
49
|
},
|
|
49
50
|
"firebase-admin": {
|
|
50
51
|
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@kanun-hq/plugin-phone": {
|
|
54
|
+
"optional": true
|
|
51
55
|
}
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
58
|
+
"@types/africastalking": "^0.8.0",
|
|
54
59
|
"@types/nodemailer": "^7.0.11"
|
|
55
60
|
},
|
|
56
61
|
"scripts": {
|