vintasend 0.1.11 → 0.1.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.
@@ -1,15 +1,16 @@
1
1
  import type { NotificationType } from '../../types/notification-type';
2
- import type { Notification } from '../../types/notification';
2
+ import type { DatabaseNotification } from '../../types/notification';
3
3
  import type { BaseNotificationTemplateRenderer } from '../notification-template-renderers/base-notification-template-renderer';
4
4
  import type { JsonValue } from '../../types/json-values';
5
5
  import type { BaseNotificationTypeConfig } from '../../types/notification-type-config';
6
+ import type { BaseNotificationBackend } from '../notification-backends/base-notification-backend';
6
7
  export declare abstract class BaseNotificationAdapter<TemplateRenderer extends BaseNotificationTemplateRenderer<Config>, Config extends BaseNotificationTypeConfig> {
7
8
  protected templateRenderer: TemplateRenderer;
8
9
  readonly notificationType: NotificationType;
9
10
  readonly enqueueNotifications: boolean;
10
11
  key: string | null;
11
- backend: Config['Backend'] | null;
12
+ backend: BaseNotificationBackend<Config> | null;
12
13
  constructor(templateRenderer: TemplateRenderer, notificationType: NotificationType, enqueueNotifications: boolean);
13
- send(notification: Notification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>, context: JsonValue): Promise<void>;
14
- injectBackend(backend: Config["Backend"]): void;
14
+ send(notification: DatabaseNotification<Config>, context: JsonValue): Promise<void>;
15
+ injectBackend(backend: BaseNotificationBackend<Config>): void;
15
16
  }
@@ -2,21 +2,21 @@ import type { InputJsonValue } from '../../types/json-values';
2
2
  import type { DatabaseNotification, Notification } from '../../types/notification';
3
3
  import type { BaseNotificationTypeConfig } from '../../types/notification-type-config';
4
4
  export interface BaseNotificationBackend<Config extends BaseNotificationTypeConfig> {
5
- getAllPendingNotifications(): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
6
- getPendingNotifications(): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
7
- getAllFutureNotifications(): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
8
- getFutureNotifications(): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
9
- getAllFutureNotificationsFromUser(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
10
- getFutureNotificationsFromUser(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
11
- persistNotification(notification: Omit<Notification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>, 'id'>): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>>;
12
- persistNotificationUpdate(notificationId: Config["NotificationIdType"], notification: Partial<Omit<Notification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>, 'id'>>): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>>;
13
- markPendingAsSent(notificationId: Config["NotificationIdType"]): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>>;
14
- markPendingAsFailed(notificationId: Config["NotificationIdType"]): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>>;
15
- markSentAsRead(notificationId: Config["NotificationIdType"]): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>>;
5
+ getAllPendingNotifications(): Promise<DatabaseNotification<Config>[]>;
6
+ getPendingNotifications(): Promise<DatabaseNotification<Config>[]>;
7
+ getAllFutureNotifications(): Promise<DatabaseNotification<Config>[]>;
8
+ getFutureNotifications(): Promise<DatabaseNotification<Config>[]>;
9
+ getAllFutureNotificationsFromUser(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config>[]>;
10
+ getFutureNotificationsFromUser(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config>[]>;
11
+ persistNotification(notification: Omit<Notification<Config>, 'id'>): Promise<DatabaseNotification<Config>>;
12
+ persistNotificationUpdate(notificationId: Config["NotificationIdType"], notification: Partial<Omit<Notification<Config>, 'id'>>): Promise<DatabaseNotification<Config>>;
13
+ markPendingAsSent(notificationId: Config["NotificationIdType"]): Promise<DatabaseNotification<Config>>;
14
+ markPendingAsFailed(notificationId: Config["NotificationIdType"]): Promise<DatabaseNotification<Config>>;
15
+ markSentAsRead(notificationId: Config["NotificationIdType"]): Promise<DatabaseNotification<Config>>;
16
16
  cancelNotification(notificationId: Config["NotificationIdType"]): Promise<void>;
17
- getNotification(notificationId: Config["NotificationIdType"], forUpdate: boolean): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]> | null>;
18
- filterAllInAppUnreadNotifications(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
19
- filterInAppUnreadNotifications(userId: Config["UserIdType"], page: number, pageSize: number): Promise<DatabaseNotification<Config["ContextMap"], Config["NotificationIdType"], Config["UserIdType"]>[]>;
17
+ getNotification(notificationId: Config["NotificationIdType"], forUpdate: boolean): Promise<DatabaseNotification<Config> | null>;
18
+ filterAllInAppUnreadNotifications(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config>[]>;
19
+ filterInAppUnreadNotifications(userId: Config["UserIdType"], page: number, pageSize: number): Promise<DatabaseNotification<Config>[]>;
20
20
  getUserEmailFromNotification(notificationId: Config["NotificationIdType"]): Promise<string | undefined>;
21
21
  storeContextUsed(notificationId: Config["NotificationIdType"], context: InputJsonValue): Promise<void>;
22
22
  }
@@ -1,8 +1,11 @@
1
- import type { Identifier } from '../types/identifier';
2
- import type { Notification } from '../types/notification';
3
- import type { BaseLogger } from './loggers/base-logger';
1
+ import type { DatabaseNotification, Notification } from '../types/notification';
4
2
  import type { JsonObject } from '../types/json-values';
5
3
  import type { BaseNotificationTypeConfig } from '../types/notification-type-config';
4
+ import type { BaseNotificationAdapter } from './notification-adapters/base-notification-adapter';
5
+ import type { BaseNotificationTemplateRenderer } from './notification-template-renderers/base-notification-template-renderer';
6
+ import type { BaseNotificationBackend } from './notification-backends/base-notification-backend';
7
+ import type { BaseLogger } from './loggers/base-logger';
8
+ import type { BaseNotificationQueueService } from './notification-queue-service/base-notification-queue-service';
6
9
  type NotificationServiceOptions = {
7
10
  raiseErrorOnFailedSend: boolean;
8
11
  };
@@ -12,21 +15,21 @@ export declare class NotificationService<Config extends BaseNotificationTypeConf
12
15
  private logger;
13
16
  private queueService?;
14
17
  private options;
15
- constructor(adapters: Config['AdaptersList'], backend: Config['Backend'], logger: BaseLogger, queueService?: Config["QueueService"] | undefined, options?: NotificationServiceOptions);
16
- registerQueueService(queueService: Config['QueueService']): void;
17
- send(notification: Notification<Config['ContextMap'], Config['NotificationIdType'], Config['UserIdType']>): Promise<void>;
18
- createNotification(notification: Omit<Notification<Config['ContextMap'], Config['NotificationIdType'], Config['UserIdType']>, 'id'>): Promise<Notification<Config['ContextMap'], Config['NotificationIdType'], Config['UserIdType']>>;
19
- updateNotification(notificationId: Identifier, notification: Partial<Omit<Notification<Config['ContextMap'], Config['NotificationIdType'], Config['UserIdType']>, 'id'>>): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>>;
20
- getAllFutureNotifications(): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>[]>;
21
- getAllFutureNotificationsFromUser(userId: Config['NotificationIdType']): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>[]>;
22
- getFutureNotificationsFromUser(userId: Config['NotificationIdType']): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>[]>;
23
- getFutureNotifications(): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>[]>;
18
+ constructor(adapters: BaseNotificationAdapter<BaseNotificationTemplateRenderer<Config>, Config>[], backend: BaseNotificationBackend<Config>, logger: BaseLogger, queueService?: BaseNotificationQueueService<Config> | undefined, options?: NotificationServiceOptions);
19
+ registerQueueService(queueService: BaseNotificationQueueService<Config>): void;
20
+ send(notification: DatabaseNotification<Config>): Promise<void>;
21
+ createNotification(notification: Omit<Notification<Config>, 'id'>): Promise<Notification<Config>>;
22
+ updateNotification(notificationId: Config['NotificationIdType'], notification: Partial<Omit<Notification<Config>, 'id'>>): Promise<DatabaseNotification<Config>>;
23
+ getAllFutureNotifications(): Promise<DatabaseNotification<Config>[]>;
24
+ getAllFutureNotificationsFromUser(userId: Config['NotificationIdType']): Promise<DatabaseNotification<Config>[]>;
25
+ getFutureNotificationsFromUser(userId: Config['NotificationIdType']): Promise<DatabaseNotification<Config>[]>;
26
+ getFutureNotifications(): Promise<DatabaseNotification<Config>[]>;
24
27
  getNotificationContext(contextName: keyof Config['ContextMap'], parameters: Parameters<Config['ContextMap'][keyof Config['ContextMap']]['generate']>[0]): Promise<JsonObject>;
25
28
  sendPendingNotifications(): Promise<void>;
26
- getPendingNotifications(): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>[]>;
27
- getNotification(notificationId: Config['NotificationIdType'], forUpdate?: boolean): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier> | null>;
28
- markRead(notificationId: Config['NotificationIdType']): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>>;
29
- getInAppUnread(userId: Config['NotificationIdType']): Promise<import("../types/notification").DatabaseNotification<Record<string, import("./notification-context-registry").ContextGenerator>, Identifier, Identifier>[]>;
29
+ getPendingNotifications(): Promise<DatabaseNotification<Config>[]>;
30
+ getNotification(notificationId: Config['NotificationIdType'], forUpdate?: boolean): Promise<DatabaseNotification<Config> | null>;
31
+ markRead(notificationId: Config['NotificationIdType']): Promise<DatabaseNotification<Config>>;
32
+ getInAppUnread(userId: Config['NotificationIdType']): Promise<DatabaseNotification<Config>[]>;
30
33
  cancelNotification(notificationId: Config['NotificationIdType']): Promise<void>;
31
34
  delayedSend(notificationId: Config['NotificationIdType']): Promise<void>;
32
35
  }
@@ -28,7 +28,7 @@ class NotificationService {
28
28
  return;
29
29
  }
30
30
  if (!notification.id) {
31
- throw new Error("Notification wan't created in the database. Please create it first");
31
+ throw new Error("Notification wasn't created in the database. Please create it first");
32
32
  }
33
33
  for (const adapter of adaptersOfType) {
34
34
  if (adapter.enqueueNotifications) {
@@ -9,5 +9,5 @@ export type EmailTemplate = {
9
9
  body: string;
10
10
  };
11
11
  export interface BaseEmailTemplateRenderer<Config extends BaseNotificationTypeConfig> extends BaseNotificationTemplateRenderer<Config, EmailTemplate> {
12
- render(notification: Notification<Config['ContextMap'], Config['NotificationIdType'], Config['UserIdType']>, context: JsonObject): Promise<EmailTemplate>;
12
+ render(notification: Notification<Config>, context: JsonObject): Promise<EmailTemplate>;
13
13
  }
@@ -2,5 +2,5 @@ import type { JsonObject } from '../../types/json-values';
2
2
  import type { Notification } from '../../types/notification';
3
3
  import type { BaseNotificationTypeConfig } from '../../types/notification-type-config';
4
4
  export interface BaseNotificationTemplateRenderer<Config extends BaseNotificationTypeConfig, T = unknown> {
5
- render(notification: Notification<Config['ContextMap'], Config['NotificationIdType'], Config['UserIdType']>, context: JsonObject): Promise<T>;
5
+ render(notification: Notification<Config>, context: JsonObject): Promise<T>;
6
6
  }
@@ -1,16 +1,7 @@
1
- import type { BaseLogger } from "../services/loggers/base-logger";
2
- import type { BaseNotificationAdapter } from "../services/notification-adapters/base-notification-adapter";
3
- import type { BaseNotificationBackend } from "../services/notification-backends/base-notification-backend";
4
1
  import type { ContextGenerator } from "../services/notification-context-registry";
5
- import type { BaseNotificationQueueService } from "../services/notification-queue-service/base-notification-queue-service";
6
- import type { BaseNotificationTemplateRenderer } from "../services/notification-template-renderers/base-notification-template-renderer";
7
2
  import type { Identifier } from "./identifier";
8
3
  export type BaseNotificationTypeConfig = {
9
4
  ContextMap: Record<string, ContextGenerator>;
10
5
  NotificationIdType: Identifier;
11
6
  UserIdType: Identifier;
12
- AdaptersList: BaseNotificationAdapter<BaseNotificationTemplateRenderer<BaseNotificationTypeConfig>, BaseNotificationTypeConfig>[];
13
- Backend: BaseNotificationBackend<BaseNotificationTypeConfig>;
14
- Logger: BaseLogger;
15
- QueueService: BaseNotificationQueueService<BaseNotificationTypeConfig>;
16
7
  };
@@ -1,32 +1,31 @@
1
- import type { ContextGenerator } from '../services/notification-context-registry';
2
- import type { Identifier } from './identifier';
3
1
  import type { InputJsonValue, JsonValue } from './json-values';
4
2
  import type { NotificationStatus } from './notification-status';
5
3
  import type { NotificationType } from './notification-type';
6
- export type NotificationInput<AvailableContexts extends Record<string, ContextGenerator>, UserIdType extends Identifier = Identifier> = {
4
+ import type { BaseNotificationTypeConfig } from './notification-type-config';
5
+ export type NotificationInput<Config extends BaseNotificationTypeConfig> = {
7
6
  id: undefined;
8
- userId: UserIdType;
7
+ userId: Config['UserIdType'];
9
8
  notificationType: NotificationType;
10
9
  title: string | null;
11
10
  bodyTemplate: string;
12
- contextName: keyof AvailableContexts;
13
- contextParameters: Parameters<AvailableContexts[NotificationInput<AvailableContexts>['contextName']]['generate']>[0];
11
+ contextName: keyof Config['ContextMap'];
12
+ contextParameters: Parameters<Config['ContextMap'][NotificationInput<Config>['contextName']]['generate']>[0];
14
13
  sendAfter: Date | null;
15
14
  subjectTemplate: string | null;
16
15
  extraParams: InputJsonValue | null;
17
16
  };
18
- export type DatabaseNotification<AvailableContexts extends Record<string, ContextGenerator>, NotificatioIdType extends Identifier = Identifier, UserIdType extends Identifier = Identifier> = {
19
- id: NotificatioIdType;
20
- userId: UserIdType;
17
+ export type DatabaseNotification<Config extends BaseNotificationTypeConfig> = {
18
+ id: Config['NotificationIdType'];
19
+ userId: Config['UserIdType'];
21
20
  notificationType: NotificationType;
22
21
  title: string | null;
23
22
  bodyTemplate: string;
24
- contextName: keyof AvailableContexts;
25
- contextParameters: Parameters<AvailableContexts[NotificationInput<AvailableContexts>['contextName']]['generate']>[0];
23
+ contextName: keyof Config['ContextMap'];
24
+ contextParameters: Parameters<Config['ContextMap'][NotificationInput<Config>['contextName']]['generate']>[0];
26
25
  sendAfter: Date | null;
27
26
  subjectTemplate: string | null;
28
27
  status: NotificationStatus;
29
- contextUsed: ReturnType<AvailableContexts[NotificationInput<AvailableContexts>['contextName']]['generate']> | null;
28
+ contextUsed: ReturnType<Config['ContextMap'][NotificationInput<Config>['contextName']]['generate']> | null;
30
29
  extraParams: JsonValue;
31
30
  adapterUsed: string | null;
32
31
  sentAt: Date | null;
@@ -34,4 +33,4 @@ export type DatabaseNotification<AvailableContexts extends Record<string, Contex
34
33
  createdAt?: Date;
35
34
  updatedAt?: Date;
36
35
  };
37
- export type Notification<AvailableContexts extends Record<string, ContextGenerator>, NotificatioIdType extends Identifier = Identifier, UserIdType extends Identifier = Identifier> = NotificationInput<AvailableContexts, UserIdType> | DatabaseNotification<AvailableContexts, NotificatioIdType, UserIdType>;
36
+ export type Notification<Config extends BaseNotificationTypeConfig> = NotificationInput<Config> | DatabaseNotification<Config>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vintasend",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"