vintasend-prisma 0.2.3 → 0.4.0

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.
@@ -0,0 +1,89 @@
1
+ import type { InputJsonValue } from '../../types/json-values';
2
+ import type {
3
+ AnyDatabaseNotification,
4
+ DatabaseNotification,
5
+ DatabaseOneOffNotification,
6
+ Notification,
7
+ OneOffNotificationInput,
8
+ } from '../../types/notification';
9
+ import type { BaseNotificationTypeConfig } from '../../types/notification-type-config';
10
+ export interface BaseNotificationBackend<Config extends BaseNotificationTypeConfig> {
11
+ getAllPendingNotifications(): Promise<AnyDatabaseNotification<Config>[]>;
12
+ getPendingNotifications(
13
+ page: number,
14
+ pageSize: number,
15
+ ): Promise<AnyDatabaseNotification<Config>[]>;
16
+ getAllFutureNotifications(): Promise<AnyDatabaseNotification<Config>[]>;
17
+ getFutureNotifications(
18
+ page: number,
19
+ pageSize: number,
20
+ ): Promise<AnyDatabaseNotification<Config>[]>;
21
+ getAllFutureNotificationsFromUser(
22
+ userId: Config['UserIdType'],
23
+ ): Promise<DatabaseNotification<Config>[]>;
24
+ getFutureNotificationsFromUser(
25
+ userId: Config['UserIdType'],
26
+ page: number,
27
+ pageSize: number,
28
+ ): Promise<DatabaseNotification<Config>[]>;
29
+ persistNotification(
30
+ notification: Omit<Notification<Config>, 'id'>,
31
+ ): Promise<DatabaseNotification<Config>>;
32
+ getAllNotifications(): Promise<AnyDatabaseNotification<Config>[]>;
33
+ getNotifications(page: number, pageSize: number): Promise<AnyDatabaseNotification<Config>[]>;
34
+ bulkPersistNotifications(
35
+ notifications: Omit<Notification<Config>, 'id'>[],
36
+ ): Promise<Config['NotificationIdType'][]>;
37
+ persistNotificationUpdate(
38
+ notificationId: Config['NotificationIdType'],
39
+ notification: Partial<Omit<Notification<Config>, 'id'>>,
40
+ ): Promise<DatabaseNotification<Config>>;
41
+ markAsSent(
42
+ notificationId: Config['NotificationIdType'],
43
+ checkIsPending: boolean,
44
+ ): Promise<AnyDatabaseNotification<Config>>;
45
+ markAsFailed(
46
+ notificationId: Config['NotificationIdType'],
47
+ checkIsPending: boolean,
48
+ ): Promise<AnyDatabaseNotification<Config>>;
49
+ markAsRead(
50
+ notificationId: Config['NotificationIdType'],
51
+ checkIsSent: boolean,
52
+ ): Promise<DatabaseNotification<Config>>;
53
+ cancelNotification(notificationId: Config['NotificationIdType']): Promise<void>;
54
+ getNotification(
55
+ notificationId: Config['NotificationIdType'],
56
+ forUpdate: boolean,
57
+ ): Promise<AnyDatabaseNotification<Config> | null>;
58
+ filterAllInAppUnreadNotifications(
59
+ userId: Config['UserIdType'],
60
+ ): Promise<DatabaseNotification<Config>[]>;
61
+ filterInAppUnreadNotifications(
62
+ userId: Config['UserIdType'],
63
+ page: number,
64
+ pageSize: number,
65
+ ): Promise<DatabaseNotification<Config>[]>;
66
+ getUserEmailFromNotification(
67
+ notificationId: Config['NotificationIdType'],
68
+ ): Promise<string | undefined>;
69
+ storeContextUsed(
70
+ notificationId: Config['NotificationIdType'],
71
+ context: InputJsonValue,
72
+ ): Promise<void>;
73
+ persistOneOffNotification(
74
+ notification: Omit<OneOffNotificationInput<Config>, 'id'>,
75
+ ): Promise<DatabaseOneOffNotification<Config>>;
76
+ persistOneOffNotificationUpdate(
77
+ notificationId: Config['NotificationIdType'],
78
+ notification: Partial<Omit<OneOffNotificationInput<Config>, 'id'>>,
79
+ ): Promise<DatabaseOneOffNotification<Config>>;
80
+ getOneOffNotification(
81
+ notificationId: Config['NotificationIdType'],
82
+ forUpdate: boolean,
83
+ ): Promise<DatabaseOneOffNotification<Config> | null>;
84
+ getAllOneOffNotifications(): Promise<DatabaseOneOffNotification<Config>[]>;
85
+ getOneOffNotifications(
86
+ page: number,
87
+ pageSize: number,
88
+ ): Promise<DatabaseOneOffNotification<Config>[]>;
89
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,2 @@
1
+ import type { UUID } from './uuid';
2
+ export type Identifier = string | number | UUID;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,19 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export interface JsonArray extends Array<JsonValue> {}
3
+ export type JsonObject = {
4
+ [Key in string]?: JsonValue;
5
+ };
6
+ export type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
7
+ export type InputJsonObject = {
8
+ readonly [Key in string]?: InputJsonValue | null;
9
+ };
10
+ export interface InputJsonArray extends ReadonlyArray<InputJsonValue | null> {}
11
+ export type InputJsonValue =
12
+ | string
13
+ | number
14
+ | boolean
15
+ | InputJsonObject
16
+ | InputJsonArray
17
+ | {
18
+ toJSON(): unknown;
19
+ };
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,6 @@
1
+ import type { JsonObject, JsonPrimitive } from './json-values';
2
+ export interface ContextGenerator<
3
+ Params extends Record<string, JsonPrimitive> = Record<string, JsonPrimitive>,
4
+ > {
5
+ generate(params: Params): JsonObject | Promise<JsonObject>;
6
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1 @@
1
+ export type NotificationStatus = 'PENDING_SEND' | 'SENT' | 'FAILED' | 'READ' | 'CANCELLED';
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,7 @@
1
+ import type { Identifier } from './identifier';
2
+ import type { ContextGenerator } from './notification-context-generators';
3
+ export type BaseNotificationTypeConfig = {
4
+ ContextMap: Record<string, ContextGenerator>;
5
+ NotificationIdType: Identifier;
6
+ UserIdType: Identifier;
7
+ };
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1 @@
1
+ export type NotificationType = 'PUSH' | 'EMAIL' | 'SMS' | 'IN_APP';
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,97 @@
1
+ import type { InputJsonValue, JsonValue } from './json-values';
2
+ import type { NotificationStatus } from './notification-status';
3
+ import type { NotificationType } from './notification-type';
4
+ import type { BaseNotificationTypeConfig } from './notification-type-config';
5
+ export type {
6
+ OneOffNotificationInput,
7
+ OneOffNotificationResendWithContextInput,
8
+ DatabaseOneOffNotification,
9
+ OneOffNotification,
10
+ } from './one-off-notification';
11
+ export type NotificationInput<Config extends BaseNotificationTypeConfig> = {
12
+ userId: Config['UserIdType'];
13
+ notificationType: NotificationType;
14
+ title: string | null;
15
+ bodyTemplate: string;
16
+ contextName: string & keyof Config['ContextMap'];
17
+ contextParameters: Parameters<
18
+ Config['ContextMap'][NotificationInput<Config>['contextName']]['generate']
19
+ >[0];
20
+ sendAfter: Date | null;
21
+ subjectTemplate: string | null;
22
+ extraParams: InputJsonValue | null;
23
+ };
24
+ export type NotificationResendWithContextInput<Config extends BaseNotificationTypeConfig> = {
25
+ userId: Config['UserIdType'];
26
+ notificationType: NotificationType;
27
+ title: string | null;
28
+ bodyTemplate: string;
29
+ contextName: string & keyof Config['ContextMap'];
30
+ contextParameters: Parameters<
31
+ Config['ContextMap'][NotificationResendWithContextInput<Config>['contextName']]['generate']
32
+ >[0];
33
+ contextUsed: ReturnType<
34
+ Config['ContextMap'][NotificationResendWithContextInput<Config>['contextName']]['generate']
35
+ > extends Promise<infer T>
36
+ ? T
37
+ : ReturnType<
38
+ Config['ContextMap'][NotificationResendWithContextInput<Config>['contextName']]['generate']
39
+ >;
40
+ sendAfter: Date | null;
41
+ subjectTemplate: string | null;
42
+ extraParams: InputJsonValue | null;
43
+ };
44
+ export type DatabaseNotification<Config extends BaseNotificationTypeConfig> = {
45
+ id: Config['NotificationIdType'];
46
+ userId: Config['UserIdType'];
47
+ notificationType: NotificationType;
48
+ title: string | null;
49
+ bodyTemplate: string;
50
+ contextName: string & keyof Config['ContextMap'];
51
+ contextParameters: Parameters<
52
+ Config['ContextMap'][DatabaseNotification<Config>['contextName']]['generate']
53
+ >[0];
54
+ sendAfter: Date | null;
55
+ subjectTemplate: string | null;
56
+ status: NotificationStatus;
57
+ contextUsed:
58
+ | null
59
+ | (ReturnType<
60
+ Config['ContextMap'][DatabaseNotification<Config>['contextName']]['generate']
61
+ > extends Promise<infer T>
62
+ ? T
63
+ : ReturnType<
64
+ Config['ContextMap'][DatabaseNotification<Config>['contextName']]['generate']
65
+ >);
66
+ extraParams: JsonValue;
67
+ adapterUsed: string | null;
68
+ sentAt: Date | null;
69
+ readAt: Date | null;
70
+ createdAt?: Date;
71
+ updatedAt?: Date;
72
+ };
73
+ export type Notification<Config extends BaseNotificationTypeConfig> =
74
+ | NotificationInput<Config>
75
+ | NotificationResendWithContextInput<Config>
76
+ | DatabaseNotification<Config>;
77
+ /**
78
+ * Union type representing any notification type (regular or one-off).
79
+ * This is useful for methods that handle both notification types.
80
+ */
81
+ export type AnyNotification<Config extends BaseNotificationTypeConfig> =
82
+ | Notification<Config>
83
+ | import('./one-off-notification').OneOffNotification<Config>;
84
+ /**
85
+ * Union type for database notifications only (regular or one-off).
86
+ * Useful for send methods and database queries.
87
+ */
88
+ export type AnyDatabaseNotification<Config extends BaseNotificationTypeConfig> =
89
+ | DatabaseNotification<Config>
90
+ | import('./one-off-notification').DatabaseOneOffNotification<Config>;
91
+ /**
92
+ * Union type for notification inputs only (regular or one-off).
93
+ * Useful for creation methods.
94
+ */
95
+ export type AnyNotificationInput<Config extends BaseNotificationTypeConfig> =
96
+ | NotificationInput<Config>
97
+ | import('./one-off-notification').OneOffNotificationInput<Config>;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,91 @@
1
+ import type { InputJsonValue, JsonValue } from './json-values';
2
+ import type { NotificationStatus } from './notification-status';
3
+ import type { NotificationType } from './notification-type';
4
+ import type { BaseNotificationTypeConfig } from './notification-type-config';
5
+ /**
6
+ * Input type for creating a one-off notification.
7
+ * One-off notifications are sent directly to an email/phone without requiring a user account.
8
+ */
9
+ export type OneOffNotificationInput<Config extends BaseNotificationTypeConfig> = {
10
+ emailOrPhone: string;
11
+ firstName: string;
12
+ lastName: string;
13
+ notificationType: NotificationType;
14
+ title: string | null;
15
+ bodyTemplate: string;
16
+ contextName: string & keyof Config['ContextMap'];
17
+ contextParameters: Parameters<
18
+ Config['ContextMap'][OneOffNotificationInput<Config>['contextName']]['generate']
19
+ >[0];
20
+ sendAfter: Date | null;
21
+ subjectTemplate: string | null;
22
+ extraParams: InputJsonValue | null;
23
+ };
24
+ /**
25
+ * Input type for resending a one-off notification with stored context.
26
+ * Similar to OneOffNotificationInput but includes the contextUsed field.
27
+ */
28
+ export type OneOffNotificationResendWithContextInput<Config extends BaseNotificationTypeConfig> = {
29
+ emailOrPhone: string;
30
+ firstName: string;
31
+ lastName: string;
32
+ notificationType: NotificationType;
33
+ title: string | null;
34
+ bodyTemplate: string;
35
+ contextName: string & keyof Config['ContextMap'];
36
+ contextParameters: Parameters<
37
+ Config['ContextMap'][OneOffNotificationResendWithContextInput<Config>['contextName']]['generate']
38
+ >[0];
39
+ contextUsed: ReturnType<
40
+ Config['ContextMap'][OneOffNotificationResendWithContextInput<Config>['contextName']]['generate']
41
+ > extends Promise<infer T>
42
+ ? T
43
+ : ReturnType<
44
+ Config['ContextMap'][OneOffNotificationResendWithContextInput<Config>['contextName']]['generate']
45
+ >;
46
+ sendAfter: Date | null;
47
+ subjectTemplate: string | null;
48
+ extraParams: InputJsonValue | null;
49
+ };
50
+ /**
51
+ * Database representation of a one-off notification.
52
+ * Includes all fields from input plus database-managed fields (id, status, timestamps, etc.)
53
+ */
54
+ export type DatabaseOneOffNotification<Config extends BaseNotificationTypeConfig> = {
55
+ id: Config['NotificationIdType'];
56
+ emailOrPhone: string;
57
+ firstName: string;
58
+ lastName: string;
59
+ notificationType: NotificationType;
60
+ title: string | null;
61
+ bodyTemplate: string;
62
+ contextName: string & keyof Config['ContextMap'];
63
+ contextParameters: Parameters<
64
+ Config['ContextMap'][DatabaseOneOffNotification<Config>['contextName']]['generate']
65
+ >[0];
66
+ sendAfter: Date | null;
67
+ subjectTemplate: string | null;
68
+ status: NotificationStatus;
69
+ contextUsed:
70
+ | null
71
+ | (ReturnType<
72
+ Config['ContextMap'][DatabaseOneOffNotification<Config>['contextName']]['generate']
73
+ > extends Promise<infer T>
74
+ ? T
75
+ : ReturnType<
76
+ Config['ContextMap'][DatabaseOneOffNotification<Config>['contextName']]['generate']
77
+ >);
78
+ extraParams: JsonValue;
79
+ adapterUsed: string | null;
80
+ sentAt: Date | null;
81
+ readAt: Date | null;
82
+ createdAt?: Date;
83
+ updatedAt?: Date;
84
+ };
85
+ /**
86
+ * Union type representing any one-off notification (input, resend, or database).
87
+ */
88
+ export type OneOffNotification<Config extends BaseNotificationTypeConfig> =
89
+ | OneOffNotificationInput<Config>
90
+ | OneOffNotificationResendWithContextInput<Config>
91
+ | DatabaseOneOffNotification<Config>;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1 @@
1
+ export type UUID = `${string}-${string}-${string}-${string}-${string}`;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
package/package.json CHANGED
@@ -1,29 +1,27 @@
1
- {
2
- "name": "vintasend-prisma",
3
- "version": "0.2.3",
4
- "description": "VintaSend Backend implementation for Prisma",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "build": "tsc",
8
- "prepublishOnly": "npm run build",
9
- "test": "jest",
10
- "test:watch": "jest --watch",
11
- "test:coverage": "jest --coverage"
12
- },
13
- "files": [
14
- "dist"
15
- ],
16
- "author": "Hugo Bessa",
17
- "license": "MIT",
18
- "dependencies": {
19
- "@prisma/client": "^6.3.1",
20
- "prisma": "^6.3.1",
21
- "vintasend": "^0.2.3"
22
- },
23
- "devDependencies": {
24
- "@types/jest": "^29.5.14",
25
- "jest": "^29.7.0",
26
- "ts-jest": "^29.2.6",
27
- "typescript": "^5.8.2"
28
- }
29
- }
1
+ {
2
+ "name": "vintasend-prisma",
3
+ "version": "0.4.0",
4
+ "description": "VintaSend Backend implementation for Prisma",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "prepublishOnly": "npm run build",
9
+ "test": "jest",
10
+ "test:watch": "jest --watch",
11
+ "test:coverage": "jest --coverage"
12
+ },
13
+ "files": ["dist"],
14
+ "author": "Hugo Bessa",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@prisma/client": "^6.3.1",
18
+ "prisma": "^6.3.1",
19
+ "vintasend": "^0.4.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/jest": "^29.5.14",
23
+ "jest": "^29.7.0",
24
+ "ts-jest": "^29.2.6",
25
+ "typescript": "^5.8.2"
26
+ }
27
+ }