@arkstack/notifications 0.17.10 → 0.17.12

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 CHANGED
@@ -1,7 +1,8 @@
1
1
  import { DotPath, DotPathValue, MergedConfig } from "@arkstack/common";
2
- import { Transport, Transporter } from "nodemailer";
2
+ import { TransportOptions, Transporter } from "nodemailer";
3
3
  import { Model } from "@arkstack/database";
4
4
  import { Logger } from "nodemailer/lib/shared/index.js";
5
+ import MailMessage from "nodemailer/lib/mailer/mail-message.js";
5
6
  import { User } from "@app/models/User";
6
7
  import { User as User$1 } from "@arkstack/auth";
7
8
  import { PhoneNumber } from "@kanun-hq/plugin-phone";
@@ -33,6 +34,15 @@ type NotificationData = Record<string, unknown>;
33
34
  type SmsDriverName = 'africastalking' | 'twilio';
34
35
  type RealtimeDriverName = 'pusher' | 'firebase';
35
36
  type NotificationChannel = 'mail' | 'sms' | 'db' | 'realtime';
37
+ interface Transport<T = any, D extends TransportOptions = TransportOptions> {
38
+ mailer?: Transporter<T, D> | undefined;
39
+ name: string;
40
+ version: string;
41
+ send(mail: MailMessage<T>, callback: (err: Error | null, info: T) => void): void;
42
+ verify?(callback: (err: Error | null, success: true) => void): void;
43
+ verify?(): Promise<true>;
44
+ close?(): void;
45
+ }
36
46
  type MailDriverOptions = {
37
47
  transport?: 'file' | 'smtp' | 'sendmail' | 'ses';
38
48
  url?: string;
@@ -648,4 +658,4 @@ declare const configure: <T extends DotPath<NotificationConfig>>(key: T, default
648
658
  //#region src/utils/template.d.ts
649
659
  declare const interpolate: (value: string, data?: NotificationData) => string;
650
660
  //#endregion
651
- export { AfricasTalkingSmsDriver, DbNotification, DbNotificationPayload, DbNotificationType, DriverResult, FirebaseMulticastResult, FirebaseRealtimeDriver, FirebaseTransportConfig, MailDriverOptions, MailNotification, MailNotificationOptions, MailRecipient, MailRecipientAddress, MergedTransportConfig, Notification, NotificationChannel, NotificationConfig, NotificationContract, NotificationData, NotificationDriverMap, NotificationRecipient, PusherRealtimeDriver, PusherTransportConfig, RealtimeBroadcastResult, RealtimeDriver, RealtimeDriverName, RealtimeDriverOptions, RealtimeNotification, RealtimeNotificationDriver, RealtimeNotificationPayload, SmsDriverName, SmsDriverOptions, SmsNotification, TwilioSmsDriver, UserNotification, UserNotificationCenter, configure, interpolate };
661
+ export { AfricasTalkingSmsDriver, DbNotification, DbNotificationPayload, DbNotificationType, DriverResult, FirebaseMulticastResult, FirebaseRealtimeDriver, FirebaseTransportConfig, MailDriverOptions, MailNotification, MailNotificationOptions, MailRecipient, MailRecipientAddress, MergedTransportConfig, Notification, NotificationChannel, NotificationConfig, NotificationContract, NotificationData, NotificationDriverMap, NotificationRecipient, PusherRealtimeDriver, PusherTransportConfig, RealtimeBroadcastResult, RealtimeDriver, RealtimeDriverName, RealtimeDriverOptions, RealtimeNotification, RealtimeNotificationDriver, RealtimeNotificationPayload, SmsDriverName, SmsDriverOptions, SmsNotification, Transport, TwilioSmsDriver, UserNotification, UserNotificationCenter, configure, interpolate };
package/dist/index.js CHANGED
@@ -222,18 +222,19 @@ var MailNotification = class extends NotificationContract {
222
222
  * Prepare the mail driver so we can use it to relay the message
223
223
  */
224
224
  async prepareDriver() {
225
+ const options = this.options;
226
+ this.fromAddress = options.from ?? this.driverConfig.from ?? env("MAIL_FROM_ADDRESS", "no-reply@example.com");
225
227
  if (typeof this.transport !== "string") {
226
228
  this.driver = nodemailer.createTransport(this.transport);
227
229
  return;
228
230
  }
229
- const options = this.options;
230
231
  const transport = configure(`transports.${this.transport}`, {});
232
+ this.fromAddress = transport.from || this.fromAddress;
231
233
  /**
232
234
  * Setup nodemailer to stream messages so we can store the mail to file
233
235
  */
234
236
  if (this.transport === "file") {
235
237
  this.fileDirectory = options.directory ?? transport.directory ?? env("MAIL_FILE_PATH", join(Arkstack.rootDir(), "./storage/framework/mails"));
236
- this.fromAddress = options.from ?? this.driverConfig.from ?? transport.from ?? env("MAIL_FROM_ADDRESS", "no-reply@example.com");
237
238
  this.driver = nodemailer.createTransport({
238
239
  streamTransport: true,
239
240
  buffer: true
@@ -272,7 +273,6 @@ var MailNotification = class extends NotificationContract {
272
273
  }
273
274
  const user = options.user ?? transport.auth?.user ?? transport.user ?? env("MAIL_USERNAME", "");
274
275
  const pass = options.pass ?? transport.auth?.pass ?? transport.pass ?? env("MAIL_PASSWORD", "");
275
- this.fromAddress = options.from ?? this.driverConfig.from ?? transport.from ?? env("MAIL_FROM_ADDRESS", "no-reply@example.com");
276
276
  this.driver = nodemailer.createTransport({
277
277
  url: transport.url ?? options.url ?? env("MAIL_URL"),
278
278
  host: options.host ?? transport.host ?? env("MAIL_HOST", "localhost"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/notifications",
3
- "version": "0.17.10",
3
+ "version": "0.17.12",
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,14 +34,14 @@
34
34
  "africastalking": "^0.8.0",
35
35
  "nodemailer": "^9.0.3",
36
36
  "twilio": "^6.0.2",
37
- "@arkstack/common": "^0.17.10"
37
+ "@arkstack/common": "^0.17.12"
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.10",
44
- "@arkstack/database": "^0.17.10"
43
+ "@arkstack/database": "^0.17.12",
44
+ "@arkstack/contract": "^0.17.12"
45
45
  },
46
46
  "peerDependenciesMeta": {
47
47
  "pusher": {