@arkstack/notifications 0.12.6 → 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 +64 -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
|
|
@@ -173,12 +179,56 @@ declare class MailNotification extends NotificationContract {
|
|
|
173
179
|
private fileDirectory?;
|
|
174
180
|
constructor(options?: MailDriverOptions);
|
|
175
181
|
from(from: string): this;
|
|
182
|
+
/**
|
|
183
|
+
* The email subject
|
|
184
|
+
*
|
|
185
|
+
* @param subject
|
|
186
|
+
* @returns
|
|
187
|
+
*/
|
|
176
188
|
subject(subject: string): this;
|
|
189
|
+
/**
|
|
190
|
+
* Set email the notification recipeint
|
|
191
|
+
*
|
|
192
|
+
* @param recipient string or array of email addresses
|
|
193
|
+
* @returns
|
|
194
|
+
*/
|
|
177
195
|
recipient(recipient: MailRecipient): this;
|
|
196
|
+
/**
|
|
197
|
+
* Set email the notification view name
|
|
198
|
+
*
|
|
199
|
+
* @param view view name
|
|
200
|
+
* @returns
|
|
201
|
+
*/
|
|
178
202
|
view(view: string): this;
|
|
203
|
+
/**
|
|
204
|
+
* Set email the notification html template
|
|
205
|
+
*
|
|
206
|
+
* @param content view name
|
|
207
|
+
* @returns
|
|
208
|
+
*/
|
|
179
209
|
html(content: string): this;
|
|
210
|
+
/**
|
|
211
|
+
* Set email the notification text template
|
|
212
|
+
*
|
|
213
|
+
* @param content view name
|
|
214
|
+
* @returns
|
|
215
|
+
*/
|
|
180
216
|
text(content: string): this;
|
|
217
|
+
/**
|
|
218
|
+
* Prepare a notification to be sent.
|
|
219
|
+
*
|
|
220
|
+
* @param user The recipient user(s) for the notification.
|
|
221
|
+
*/
|
|
181
222
|
prepare(user?: null | string | string[] | User, data?: Record<string, any>): this;
|
|
223
|
+
/**
|
|
224
|
+
* Send a notification to the specified recipient(s) with the given message.
|
|
225
|
+
*
|
|
226
|
+
* @param message The message content to be sent to the recipient(s).
|
|
227
|
+
* @param subject The message subject to be sent to the recipient(s).
|
|
228
|
+
* @param recipient An array of recipient identifiers
|
|
229
|
+
* @param data Additioal context data
|
|
230
|
+
* @returns
|
|
231
|
+
*/
|
|
182
232
|
send(message: string, subject?: string, recipient?: MailRecipient, data?: NotificationData): Promise<any>;
|
|
183
233
|
private storeFileMail;
|
|
184
234
|
private resolveRecipients;
|
|
@@ -231,18 +281,18 @@ declare class Notification<D extends keyof DriverMap = keyof DriverMap> {
|
|
|
231
281
|
static sms(options?: SmsDriverOptions): SmsNotification;
|
|
232
282
|
static db(): DbNotification;
|
|
233
283
|
static channel(channel?: NotificationChannel | 'email', options?: MailDriverOptions | SmsDriverOptions): MailNotification | SmsNotification | DbNotification;
|
|
234
|
-
prepare(recipient?: null | MailRecipient | NotificationRecipient |
|
|
284
|
+
prepare(recipient?: null | MailRecipient | NotificationRecipient | User$1, data?: NotificationData): DriverMap[D];
|
|
235
285
|
private static createDriver;
|
|
236
286
|
}
|
|
237
287
|
//#endregion
|
|
238
288
|
//#region src/UserNotificationCenter.d.ts
|
|
239
289
|
declare class UserNotificationCenter {
|
|
240
290
|
private static getModel;
|
|
241
|
-
static create(user:
|
|
242
|
-
static forUser(user:
|
|
243
|
-
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>)[]>>;
|
|
244
294
|
static markRead(notification: UserNotification | UserNotification['id']): Promise<void>;
|
|
245
|
-
static markAllRead(user:
|
|
295
|
+
static markAllRead(user: User$1): Promise<void>;
|
|
246
296
|
static delete(notification: UserNotification | UserNotification['id']): Promise<void>;
|
|
247
297
|
}
|
|
248
298
|
//#endregion
|
|
@@ -252,4 +302,4 @@ declare const configure: <T extends DotPath<NotificationConfig>>(key: T, default
|
|
|
252
302
|
//#region src/utils/template.d.ts
|
|
253
303
|
declare const interpolate: (value: string, data?: NotificationData) => string;
|
|
254
304
|
//#endregion
|
|
255
|
-
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/database": "^0.12.
|
|
41
|
-
"@arkstack/contract": "^0.12.
|
|
40
|
+
"@arkstack/database": "^0.12.8",
|
|
41
|
+
"@arkstack/contract": "^0.12.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/nodemailer": "^7.0.11"
|