@arkstack/notifications 0.12.7 → 0.12.8
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 +20 -14
- package/dist/index.js +10 -10
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DotPath, DotPathValue, MergedConfig } from "@arkstack/common";
|
|
2
|
-
import { Model } from "@arkstack/database";
|
|
3
2
|
import { Transporter } from "nodemailer";
|
|
3
|
+
import { Model } from "@arkstack/database";
|
|
4
4
|
import * as _$arkormx from "arkormx";
|
|
5
5
|
import { User } from "@arkstack/auth";
|
|
6
6
|
import * as _$twilio_lib_rest_api_v2010_account_message0 from "twilio/lib/rest/api/v2010/account/message.js";
|
|
@@ -30,11 +30,6 @@ type MailRecipient = string | MailRecipientAddress | Array<string | MailRecipien
|
|
|
30
30
|
type NotificationData = Record<string, unknown>;
|
|
31
31
|
type SmsDriverName = 'africastalking' | 'twilio';
|
|
32
32
|
type NotificationChannel = 'mail' | 'sms' | 'db';
|
|
33
|
-
type NotificationUser = {
|
|
34
|
-
id: string | number;
|
|
35
|
-
email?: string | null;
|
|
36
|
-
phone?: string | null;
|
|
37
|
-
};
|
|
38
33
|
type MailDriverOptions = {
|
|
39
34
|
transport?: 'africastalking' | 'twilio' | 'file' | 'smtp';
|
|
40
35
|
host?: string;
|
|
@@ -147,17 +142,28 @@ declare abstract class NotificationContract<TResult = DriverResult> {
|
|
|
147
142
|
};
|
|
148
143
|
}
|
|
149
144
|
//#endregion
|
|
145
|
+
//#region src/Contracts/User.d.ts
|
|
146
|
+
declare abstract class User$1 extends Model {
|
|
147
|
+
[key: string]: any;
|
|
148
|
+
email: string;
|
|
149
|
+
name: string;
|
|
150
|
+
password: string;
|
|
151
|
+
createdAt: Date;
|
|
152
|
+
updatedAt: Date;
|
|
153
|
+
protected static table?: string | undefined;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
150
156
|
//#region src/drivers/DbNotification.d.ts
|
|
151
157
|
declare class DbNotification extends NotificationContract<UserNotification> {
|
|
152
158
|
private user?;
|
|
153
159
|
private payload;
|
|
154
160
|
from(_from: string): this;
|
|
155
161
|
subject(subject: string): this;
|
|
156
|
-
recipient(recipient: NotificationRecipient |
|
|
162
|
+
recipient(recipient: NotificationRecipient | User$1): this;
|
|
157
163
|
type(type: DbNotificationPayload['type']): this;
|
|
158
164
|
action(text?: string | null, link?: string | null): this;
|
|
159
165
|
meta(meta?: NotificationData | null): this;
|
|
160
|
-
create(user:
|
|
166
|
+
create(user: User$1, payload: DbNotificationPayload): Promise<UserNotification & _$arkormx.Model<any, any>>;
|
|
161
167
|
send(message: string, subject?: string, _recipient?: NotificationRecipient, data?: NotificationData): Promise<UserNotification & _$arkormx.Model<any, any>>;
|
|
162
168
|
}
|
|
163
169
|
//#endregion
|
|
@@ -275,18 +281,18 @@ declare class Notification<D extends keyof DriverMap = keyof DriverMap> {
|
|
|
275
281
|
static sms(options?: SmsDriverOptions): SmsNotification;
|
|
276
282
|
static db(): DbNotification;
|
|
277
283
|
static channel(channel?: NotificationChannel | 'email', options?: MailDriverOptions | SmsDriverOptions): MailNotification | SmsNotification | DbNotification;
|
|
278
|
-
prepare(recipient?: null | MailRecipient | NotificationRecipient |
|
|
284
|
+
prepare(recipient?: null | MailRecipient | NotificationRecipient | User$1, data?: NotificationData): DriverMap[D];
|
|
279
285
|
private static createDriver;
|
|
280
286
|
}
|
|
281
287
|
//#endregion
|
|
282
288
|
//#region src/UserNotificationCenter.d.ts
|
|
283
289
|
declare class UserNotificationCenter {
|
|
284
290
|
private static getModel;
|
|
285
|
-
static create(user:
|
|
286
|
-
static forUser(user:
|
|
287
|
-
static unreadForUser(user:
|
|
291
|
+
static create(user: User$1, payload: DbNotificationPayload): Promise<UserNotification & _$arkormx.Model<any, any>>;
|
|
292
|
+
static forUser(user: User$1): Promise<_$arkormx.ArkormCollection<UserNotification & _$arkormx.Model<any, any>, (UserNotification & _$arkormx.Model<any, any>)[]>>;
|
|
293
|
+
static unreadForUser(user: User$1): Promise<_$arkormx.ArkormCollection<UserNotification & _$arkormx.Model<any, any>, (UserNotification & _$arkormx.Model<any, any>)[]>>;
|
|
288
294
|
static markRead(notification: UserNotification | UserNotification['id']): Promise<void>;
|
|
289
|
-
static markAllRead(user:
|
|
295
|
+
static markAllRead(user: User$1): Promise<void>;
|
|
290
296
|
static delete(notification: UserNotification | UserNotification['id']): Promise<void>;
|
|
291
297
|
}
|
|
292
298
|
//#endregion
|
|
@@ -296,4 +302,4 @@ declare const configure: <T extends DotPath<NotificationConfig>>(key: T, default
|
|
|
296
302
|
//#region src/utils/template.d.ts
|
|
297
303
|
declare const interpolate: (value: string, data?: NotificationData) => string;
|
|
298
304
|
//#endregion
|
|
299
|
-
export { AfricasTalkingSmsDriver, DbNotification, DbNotificationPayload, DbNotificationType, DriverResult, MailDriverOptions, MailNotification, MailRecipient, MailRecipientAddress, MergedTransportConfig, Notification, NotificationChannel, NotificationConfig, NotificationContract, NotificationData, NotificationDriverMap, NotificationRecipient,
|
|
305
|
+
export { AfricasTalkingSmsDriver, DbNotification, DbNotificationPayload, DbNotificationType, DriverResult, MailDriverOptions, MailNotification, MailRecipient, MailRecipientAddress, MergedTransportConfig, Notification, NotificationChannel, NotificationConfig, NotificationContract, NotificationData, NotificationDriverMap, NotificationRecipient, SmsDriverName, SmsDriverOptions, SmsNotification, TwilioSmsDriver, UserNotification, UserNotificationCenter, configure, interpolate };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { config, env, getModel } from "@arkstack/common";
|
|
2
|
-
import { Model } from "@arkstack/database";
|
|
3
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import nodemailer from "nodemailer";
|
|
6
5
|
import { Arkstack } from "@arkstack/contract";
|
|
7
6
|
import africastalking from "africastalking";
|
|
8
7
|
import twilio from "twilio";
|
|
8
|
+
import { Model } from "@arkstack/database";
|
|
9
9
|
//#region src/Contracts/NotificationContract.ts
|
|
10
10
|
var NotificationContract = class {
|
|
11
11
|
contextData = {};
|
|
@@ -22,12 +22,6 @@ var NotificationContract = class {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
//#endregion
|
|
25
|
-
//#region src/Contracts/UserNotification.ts
|
|
26
|
-
var UserNotification = class extends Model {
|
|
27
|
-
static table = "user_notifications";
|
|
28
|
-
casts = { meta: "json" };
|
|
29
|
-
};
|
|
30
|
-
//#endregion
|
|
31
25
|
//#region src/UserNotificationCenter.ts
|
|
32
26
|
var UserNotificationCenter = class {
|
|
33
27
|
static async getModel() {
|
|
@@ -55,10 +49,10 @@ var UserNotificationCenter = class {
|
|
|
55
49
|
}
|
|
56
50
|
static async markRead(notification) {
|
|
57
51
|
const Model = await this.getModel();
|
|
58
|
-
const id = notification
|
|
52
|
+
const id = typeof notification === "object" ? notification.id : notification;
|
|
59
53
|
const readAt = /* @__PURE__ */ new Date();
|
|
60
54
|
await Model.query().where({ id }).update({ readAt });
|
|
61
|
-
if (notification
|
|
55
|
+
if (typeof notification === "object") notification.readAt = readAt;
|
|
62
56
|
}
|
|
63
57
|
static async markAllRead(user) {
|
|
64
58
|
await (await this.getModel()).query().where({
|
|
@@ -68,7 +62,7 @@ var UserNotificationCenter = class {
|
|
|
68
62
|
}
|
|
69
63
|
static async delete(notification) {
|
|
70
64
|
const Model = await this.getModel();
|
|
71
|
-
const id = notification
|
|
65
|
+
const id = typeof notification === "object" ? notification.id : notification;
|
|
72
66
|
await Model.query().where({ id }).delete();
|
|
73
67
|
}
|
|
74
68
|
};
|
|
@@ -469,4 +463,10 @@ var Notification = class Notification {
|
|
|
469
463
|
}
|
|
470
464
|
};
|
|
471
465
|
//#endregion
|
|
466
|
+
//#region src/Contracts/UserNotification.ts
|
|
467
|
+
var UserNotification = class extends Model {
|
|
468
|
+
static table = "user_notifications";
|
|
469
|
+
casts = { meta: "json" };
|
|
470
|
+
};
|
|
471
|
+
//#endregion
|
|
472
472
|
export { AfricasTalkingSmsDriver, DbNotification, MailNotification, Notification, NotificationContract, SmsNotification, TwilioSmsDriver, UserNotification, UserNotificationCenter, configure, interpolate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/notifications",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.8",
|
|
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,11 +34,11 @@
|
|
|
34
34
|
"africastalking": "^0.8.0",
|
|
35
35
|
"nodemailer": "^8.0.7",
|
|
36
36
|
"twilio": "^6.0.0",
|
|
37
|
-
"@arkstack/common": "^0.12.
|
|
37
|
+
"@arkstack/common": "^0.12.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@arkstack/
|
|
41
|
-
"@arkstack/
|
|
40
|
+
"@arkstack/database": "^0.12.8",
|
|
41
|
+
"@arkstack/contract": "^0.12.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/nodemailer": "^7.0.11"
|