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.
- package/dist/services/notification-adapters/base-notification-adapter.d.ts +5 -4
- package/dist/services/notification-backends/base-notification-backend.d.ts +14 -14
- package/dist/services/notification-service.d.ts +19 -16
- package/dist/services/notification-service.js +1 -1
- package/dist/services/notification-template-renderers/base-email-template-renderer.d.ts +1 -1
- package/dist/services/notification-template-renderers/base-notification-template-renderer.d.ts +1 -1
- package/dist/types/notification-type-config.d.ts +0 -9
- package/dist/types/notification.d.ts +12 -13
- package/package.json +1 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { NotificationType } from '../../types/notification-type';
|
|
2
|
-
import type {
|
|
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
|
|
12
|
+
backend: BaseNotificationBackend<Config> | null;
|
|
12
13
|
constructor(templateRenderer: TemplateRenderer, notificationType: NotificationType, enqueueNotifications: boolean);
|
|
13
|
-
send(notification:
|
|
14
|
-
injectBackend(backend: Config
|
|
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
|
|
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
|
|
12
|
-
persistNotificationUpdate(notificationId: Config["NotificationIdType"], notification: Partial<Omit<Notification<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
|
|
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
|
|
18
|
-
filterAllInAppUnreadNotifications(userId: Config["UserIdType"]): Promise<DatabaseNotification<Config
|
|
19
|
-
filterInAppUnreadNotifications(userId: Config["UserIdType"], page: number, pageSize: number): Promise<DatabaseNotification<Config
|
|
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 {
|
|
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[
|
|
16
|
-
registerQueueService(queueService: Config
|
|
17
|
-
send(notification:
|
|
18
|
-
createNotification(notification: Omit<Notification<Config
|
|
19
|
-
updateNotification(notificationId:
|
|
20
|
-
getAllFutureNotifications(): Promise<
|
|
21
|
-
getAllFutureNotificationsFromUser(userId: Config['NotificationIdType']): Promise<
|
|
22
|
-
getFutureNotificationsFromUser(userId: Config['NotificationIdType']): Promise<
|
|
23
|
-
getFutureNotifications(): Promise<
|
|
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<
|
|
27
|
-
getNotification(notificationId: Config['NotificationIdType'], forUpdate?: boolean): Promise<
|
|
28
|
-
markRead(notificationId: Config['NotificationIdType']): Promise<
|
|
29
|
-
getInAppUnread(userId: Config['NotificationIdType']): Promise<
|
|
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
|
|
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
|
|
12
|
+
render(notification: Notification<Config>, context: JsonObject): Promise<EmailTemplate>;
|
|
13
13
|
}
|
package/dist/services/notification-template-renderers/base-notification-template-renderer.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
13
|
-
contextParameters: Parameters<
|
|
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<
|
|
19
|
-
id:
|
|
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
|
|
25
|
-
contextParameters: Parameters<
|
|
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<
|
|
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<
|
|
36
|
+
export type Notification<Config extends BaseNotificationTypeConfig> = NotificationInput<Config> | DatabaseNotification<Config>;
|