vintasend 0.1.8 → 0.1.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/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # VintaSend TypeScript
2
+
3
+ A TypeScript library for sending emails using multiple email service providers with failover support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install vintasend
9
+ # or
10
+ yarn add vintasend
11
+ ```
12
+
13
+ ## Features
14
+ * **Storing notifications in a Database**: This package relies on a data store to record all the notifications that will be sent. It also keeps it's state column up to date.
15
+ * **Scheduling notifications**: Storing notifications to be send in the future. The notification's context for rendering the template is only evaluated at the moment the notification is sent due to the lib's context generation registry.
16
+ * **Notification context fetched at send time**: On scheduled notifications, we only get the notification context at the send time, so we always get the most up-to-date information.
17
+ * **Flexible backend**: Your projects database is getting slow after you created the first milion notifications? You can migrate to a faster no-sql database with a blink of an eye without affecting how you send the notifications.
18
+ * **Flexible adapters**: Your project probably will need to change how it sends notifications overtime. This package allows to change the adapter without having to change how notifications templates are rendered or how the notification themselves are stored.
19
+ * **Flexible template renderers**: Wanna start managing your templates with a third party tool (so non-technical people can help maintaining them)? Or even choose a more powerful rendering engine? You can do it independetly of how you send the notifications or store them in the database.
20
+
21
+ ## Development
22
+
23
+ 1. Clone the repository
24
+ 2. Install dependencies:
25
+ ```bash
26
+ npm install
27
+ # or
28
+ yarn
29
+ ```
30
+ 3. Run tests:
31
+ ```bash
32
+ npm test
33
+ # or
34
+ yarn test
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Feel free to open issues and submit pull requests.
40
+
41
+ ## License
42
+
43
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
44
+
45
+ ## Credits
46
+
47
+ Created by [Vinta Software](https://www.vinta.com.br/)
@@ -5,11 +5,13 @@ import type { BaseNotificationTemplateRenderer } from '../notification-template-
5
5
  import type { ContextGenerator } from '../notification-context-registry';
6
6
  import type { JsonValue } from '../../types/json-values';
7
7
  import type { Identifier } from '../../types/identifier';
8
- export interface BaseNotificationAdapter<TemplateRenderer extends BaseNotificationTemplateRenderer<AvailableContexts>, Backend extends BaseNotificationBackend<AvailableContexts>, AvailableContexts extends Record<string, ContextGenerator>, NotificationIdType extends Identifier = Identifier, UserIdType extends Identifier = Identifier> {
9
- notificationType: NotificationType;
10
- key: string;
11
- templateRenderer: TemplateRenderer;
12
- backend: Backend;
13
- enqueueNotifications: boolean;
8
+ export declare abstract class BaseNotificationAdapter<TemplateRenderer extends BaseNotificationTemplateRenderer<AvailableContexts>, AvailableContexts extends Record<string, ContextGenerator>, NotificationIdType extends Identifier = Identifier, UserIdType extends Identifier = Identifier> {
9
+ protected templateRenderer: TemplateRenderer;
10
+ readonly notificationType: NotificationType;
11
+ readonly enqueueNotifications: boolean;
12
+ key: string | null;
13
+ backend: BaseNotificationBackend<AvailableContexts, NotificationIdType, UserIdType> | null;
14
+ constructor(templateRenderer: TemplateRenderer, notificationType: NotificationType, enqueueNotifications: boolean);
14
15
  send(notification: Notification<AvailableContexts, NotificationIdType, UserIdType>, context: JsonValue): Promise<void>;
16
+ injectBackend(backend: BaseNotificationBackend<AvailableContexts, NotificationIdType, UserIdType>): void;
15
17
  }
@@ -1,2 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseNotificationAdapter = void 0;
4
+ class BaseNotificationAdapter {
5
+ constructor(templateRenderer, notificationType, enqueueNotifications) {
6
+ this.templateRenderer = templateRenderer;
7
+ this.notificationType = notificationType;
8
+ this.enqueueNotifications = enqueueNotifications;
9
+ this.key = null;
10
+ this.backend = null;
11
+ }
12
+ ;
13
+ send(notification, context) {
14
+ if (this.backend === null) {
15
+ throw new Error('Backend not injected');
16
+ }
17
+ return Promise.resolve();
18
+ }
19
+ ;
20
+ injectBackend(backend) {
21
+ this.backend = backend;
22
+ }
23
+ ;
24
+ }
25
+ exports.BaseNotificationAdapter = BaseNotificationAdapter;
@@ -16,7 +16,7 @@ export declare class NotificationService<AvailableContexts extends Record<string
16
16
  private logger;
17
17
  private queueService?;
18
18
  private options;
19
- constructor(adapters: BaseNotificationAdapter<BaseNotificationTemplateRenderer<AvailableContexts, NotificationIdType, UserIdType>, BaseNotificationBackend<AvailableContexts, NotificationIdType, UserIdType>, AvailableContexts, NotificationIdType, UserIdType>[], backend: BaseNotificationBackend<AvailableContexts, NotificationIdType, UserIdType>, logger: BaseLogger, queueService?: BaseNotificationQueueService<NotificationIdType> | undefined, options?: NotificationServiceOptions);
19
+ constructor(adapters: BaseNotificationAdapter<BaseNotificationTemplateRenderer<AvailableContexts, NotificationIdType, UserIdType>, AvailableContexts, NotificationIdType, UserIdType>[], backend: BaseNotificationBackend<AvailableContexts, NotificationIdType, UserIdType>, logger: BaseLogger, queueService?: BaseNotificationQueueService<NotificationIdType> | undefined, options?: NotificationServiceOptions);
20
20
  registerQueueService(queueService: BaseNotificationQueueService<NotificationIdType>): void;
21
21
  send(notification: Notification<AvailableContexts, NotificationIdType, UserIdType>): Promise<void>;
22
22
  createNotification(notification: Omit<Notification<AvailableContexts, NotificationIdType, UserIdType>, 'id'>): Promise<Notification<AvailableContexts, NotificationIdType, UserIdType>>;
@@ -11,6 +11,9 @@ class NotificationService {
11
11
  this.logger = logger;
12
12
  this.queueService = queueService;
13
13
  this.options = options;
14
+ for (const adapter of adapters) {
15
+ adapter.injectBackend(backend);
16
+ }
14
17
  }
15
18
  registerQueueService(queueService) {
16
19
  this.queueService = queueService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vintasend",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"