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.
- package/dist/implementations/vintasend-prisma/src/index.d.ts +2 -0
- package/dist/implementations/vintasend-prisma/src/index.js +7 -0
- package/dist/implementations/vintasend-prisma/src/prisma-notification-backend.d.ts +318 -0
- package/dist/implementations/vintasend-prisma/src/prisma-notification-backend.js +406 -0
- package/dist/prisma-notification-backend.d.ts +276 -30
- package/dist/prisma-notification-backend.js +573 -76
- package/dist/services/notification-backends/base-notification-backend.d.ts +89 -0
- package/dist/services/notification-backends/base-notification-backend.js +1 -0
- package/dist/types/identifier.d.ts +2 -0
- package/dist/types/identifier.js +1 -0
- package/dist/types/json-values.d.ts +19 -0
- package/dist/types/json-values.js +1 -0
- package/dist/types/notification-context-generators.d.ts +6 -0
- package/dist/types/notification-context-generators.js +1 -0
- package/dist/types/notification-status.d.ts +1 -0
- package/dist/types/notification-status.js +1 -0
- package/dist/types/notification-type-config.d.ts +7 -0
- package/dist/types/notification-type-config.js +1 -0
- package/dist/types/notification-type.d.ts +1 -0
- package/dist/types/notification-type.js +1 -0
- package/dist/types/notification.d.ts +97 -0
- package/dist/types/notification.js +1 -0
- package/dist/types/one-off-notification.d.ts +91 -0
- package/dist/types/one-off-notification.js +1 -0
- package/dist/types/uuid.d.ts +1 -0
- package/dist/types/uuid.js +1 -0
- package/package.json +27 -29
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
exports.PrismaNotificationBackendFactory = void 0;
|
|
3
|
+
var prisma_notification_backend_1 = require('./prisma-notification-backend');
|
|
4
|
+
Object.defineProperty(exports, 'PrismaNotificationBackendFactory', {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: () => prisma_notification_backend_1.PrismaNotificationBackendFactory,
|
|
7
|
+
});
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { InputJsonValue, JsonValue } from 'vintasend/dist/types/json-values';
|
|
2
|
+
import type {
|
|
3
|
+
DatabaseNotification,
|
|
4
|
+
Notification,
|
|
5
|
+
NotificationInput,
|
|
6
|
+
} from 'vintasend/dist/types/notification';
|
|
7
|
+
import type { NotificationStatus } from 'vintasend/dist/types/notification-status';
|
|
8
|
+
import type { NotificationType } from 'vintasend/dist/types/notification-type';
|
|
9
|
+
import type { BaseNotificationTypeConfig } from 'vintasend/dist/types/notification-type-config';
|
|
10
|
+
import type { BaseNotificationBackend } from '../../../services/notification-backends/base-notification-backend';
|
|
11
|
+
import type {
|
|
12
|
+
AnyDatabaseNotification,
|
|
13
|
+
DatabaseOneOffNotification,
|
|
14
|
+
OneOffNotificationInput,
|
|
15
|
+
} from '../../../types/notification';
|
|
16
|
+
export declare const NotificationStatusEnum: {
|
|
17
|
+
readonly PENDING_SEND: 'PENDING_SEND';
|
|
18
|
+
readonly SENT: 'SENT';
|
|
19
|
+
readonly FAILED: 'FAILED';
|
|
20
|
+
readonly READ: 'READ';
|
|
21
|
+
readonly CANCELLED: 'CANCELLED';
|
|
22
|
+
};
|
|
23
|
+
export declare const NotificationTypeEnum: {
|
|
24
|
+
readonly EMAIL: 'EMAIL';
|
|
25
|
+
readonly PUSH: 'PUSH';
|
|
26
|
+
readonly SMS: 'SMS';
|
|
27
|
+
readonly IN_APP: 'IN_APP';
|
|
28
|
+
};
|
|
29
|
+
export interface PrismaNotificationModel<IdType, UserId> {
|
|
30
|
+
id: IdType;
|
|
31
|
+
userId: UserId | null;
|
|
32
|
+
emailOrPhone: string | null;
|
|
33
|
+
firstName: string | null;
|
|
34
|
+
lastName: string | null;
|
|
35
|
+
notificationType: NotificationType;
|
|
36
|
+
title: string | null;
|
|
37
|
+
bodyTemplate: string;
|
|
38
|
+
contextName: string;
|
|
39
|
+
contextParameters: JsonValue;
|
|
40
|
+
sendAfter: Date | null;
|
|
41
|
+
subjectTemplate: string | null;
|
|
42
|
+
status: NotificationStatus;
|
|
43
|
+
contextUsed: JsonValue | null;
|
|
44
|
+
extraParams: JsonValue | null;
|
|
45
|
+
adapterUsed: string | null;
|
|
46
|
+
sentAt: Date | null;
|
|
47
|
+
readAt: Date | null;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
updatedAt: Date;
|
|
50
|
+
user?: {
|
|
51
|
+
email: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface NotificationPrismaClientInterface<NotificationIdType, UserIdType> {
|
|
55
|
+
notification: {
|
|
56
|
+
findMany(args: {
|
|
57
|
+
where?: {
|
|
58
|
+
status?:
|
|
59
|
+
| NotificationStatus
|
|
60
|
+
| {
|
|
61
|
+
not: NotificationStatus;
|
|
62
|
+
};
|
|
63
|
+
sendAfter?: {
|
|
64
|
+
lte: Date;
|
|
65
|
+
} | null;
|
|
66
|
+
userId?: UserIdType | null;
|
|
67
|
+
readAt?: null;
|
|
68
|
+
emailOrPhone?:
|
|
69
|
+
| string
|
|
70
|
+
| {
|
|
71
|
+
not: null;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
skip?: number;
|
|
75
|
+
take?: number;
|
|
76
|
+
include?: {
|
|
77
|
+
user?: boolean;
|
|
78
|
+
};
|
|
79
|
+
}): Promise<PrismaNotificationModel<NotificationIdType, UserIdType>[]>;
|
|
80
|
+
create(args: {
|
|
81
|
+
data: BaseNotificationCreateInput<UserIdType>;
|
|
82
|
+
include?: {
|
|
83
|
+
user?: boolean;
|
|
84
|
+
};
|
|
85
|
+
}): Promise<PrismaNotificationModel<NotificationIdType, UserIdType>>;
|
|
86
|
+
createMany(args: {
|
|
87
|
+
data: BaseNotificationCreateInput<UserIdType>[];
|
|
88
|
+
}): Promise<NotificationIdType[]>;
|
|
89
|
+
update(args: {
|
|
90
|
+
where: {
|
|
91
|
+
id: NotificationIdType;
|
|
92
|
+
};
|
|
93
|
+
data: Partial<BaseNotificationUpdateInput<UserIdType>>;
|
|
94
|
+
include?: {
|
|
95
|
+
user?: boolean;
|
|
96
|
+
};
|
|
97
|
+
}): Promise<PrismaNotificationModel<NotificationIdType, UserIdType>>;
|
|
98
|
+
findUnique(args: {
|
|
99
|
+
where: {
|
|
100
|
+
id: NotificationIdType;
|
|
101
|
+
};
|
|
102
|
+
include?: {
|
|
103
|
+
user?: boolean;
|
|
104
|
+
};
|
|
105
|
+
}): Promise<PrismaNotificationModel<NotificationIdType, UserIdType> | null>;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
type NoExpand<T> = T extends unknown ? T : never;
|
|
109
|
+
type AtLeast<O extends object, K extends string> = NoExpand<
|
|
110
|
+
O extends unknown
|
|
111
|
+
?
|
|
112
|
+
| (K extends keyof O
|
|
113
|
+
? {
|
|
114
|
+
[P in K]: O[P];
|
|
115
|
+
} & O
|
|
116
|
+
: O)
|
|
117
|
+
| ({
|
|
118
|
+
[P in keyof O as P extends K ? K : never]-?: O[P];
|
|
119
|
+
} & O)
|
|
120
|
+
: never
|
|
121
|
+
>;
|
|
122
|
+
export interface BaseNotificationCreateInput<UserIdType> {
|
|
123
|
+
user?: {
|
|
124
|
+
connect?: AtLeast<
|
|
125
|
+
{
|
|
126
|
+
id?: UserIdType;
|
|
127
|
+
email?: string;
|
|
128
|
+
},
|
|
129
|
+
'id' | 'email'
|
|
130
|
+
>;
|
|
131
|
+
};
|
|
132
|
+
userId?: UserIdType | null;
|
|
133
|
+
emailOrPhone?: string | null;
|
|
134
|
+
firstName?: string | null;
|
|
135
|
+
lastName?: string | null;
|
|
136
|
+
notificationType: NotificationType;
|
|
137
|
+
title?: string | null;
|
|
138
|
+
bodyTemplate: string;
|
|
139
|
+
contextName: string;
|
|
140
|
+
contextParameters: InputJsonValue;
|
|
141
|
+
sendAfter?: Date | null;
|
|
142
|
+
subjectTemplate?: string | null;
|
|
143
|
+
status?: NotificationStatus;
|
|
144
|
+
contextUsed?: InputJsonValue;
|
|
145
|
+
extraParams?: InputJsonValue;
|
|
146
|
+
adapterUsed?: string | null;
|
|
147
|
+
sentAt?: Date | null;
|
|
148
|
+
readAt?: Date | null;
|
|
149
|
+
}
|
|
150
|
+
export interface BaseNotificationUpdateInput<UserIdType> {
|
|
151
|
+
user?: {
|
|
152
|
+
connect?: AtLeast<
|
|
153
|
+
{
|
|
154
|
+
id?: UserIdType;
|
|
155
|
+
email?: string;
|
|
156
|
+
},
|
|
157
|
+
'id' | 'email'
|
|
158
|
+
>;
|
|
159
|
+
};
|
|
160
|
+
emailOrPhone?: string | null;
|
|
161
|
+
firstName?: string | null;
|
|
162
|
+
lastName?: string | null;
|
|
163
|
+
notificationType?: NotificationType;
|
|
164
|
+
title?: string | null;
|
|
165
|
+
bodyTemplate?: string;
|
|
166
|
+
contextName?: string;
|
|
167
|
+
contextParameters?: InputJsonValue;
|
|
168
|
+
sendAfter?: Date | null;
|
|
169
|
+
subjectTemplate?: string | null;
|
|
170
|
+
status?: NotificationStatus;
|
|
171
|
+
contextUsed?: InputJsonValue;
|
|
172
|
+
extraParams?: InputJsonValue;
|
|
173
|
+
adapterUsed?: string | null;
|
|
174
|
+
sentAt?: Date | null;
|
|
175
|
+
readAt?: Date | null;
|
|
176
|
+
}
|
|
177
|
+
export declare class PrismaNotificationBackend<
|
|
178
|
+
Client extends NotificationPrismaClientInterface<
|
|
179
|
+
Config['NotificationIdType'],
|
|
180
|
+
Config['UserIdType']
|
|
181
|
+
>,
|
|
182
|
+
Config extends BaseNotificationTypeConfig,
|
|
183
|
+
> implements BaseNotificationBackend<Config>
|
|
184
|
+
{
|
|
185
|
+
private prismaClient;
|
|
186
|
+
constructor(prismaClient: Client);
|
|
187
|
+
/**
|
|
188
|
+
* Serialize a Prisma notification model to either DatabaseNotification or DatabaseOneOffNotification
|
|
189
|
+
* based on whether it has a userId or not
|
|
190
|
+
*/
|
|
191
|
+
serializeNotification(
|
|
192
|
+
notification: NonNullable<
|
|
193
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
194
|
+
>,
|
|
195
|
+
): AnyDatabaseNotification<Config>;
|
|
196
|
+
deserializeNotification(
|
|
197
|
+
notification: NotificationInput<Config>,
|
|
198
|
+
): BaseNotificationCreateInput<Config['UserIdType']>;
|
|
199
|
+
deserializeNotificationForUpdate(
|
|
200
|
+
notification: Partial<Notification<Config>>,
|
|
201
|
+
): Partial<Parameters<typeof this.prismaClient.notification.update>[0]['data']>;
|
|
202
|
+
getAllPendingNotifications(): Promise<AnyDatabaseNotification<Config>[]>;
|
|
203
|
+
getPendingNotifications(
|
|
204
|
+
page?: number,
|
|
205
|
+
pageSize?: number,
|
|
206
|
+
): Promise<AnyDatabaseNotification<Config>[]>;
|
|
207
|
+
getAllFutureNotifications(): Promise<AnyDatabaseNotification<Config>[]>;
|
|
208
|
+
getFutureNotifications(
|
|
209
|
+
page?: number,
|
|
210
|
+
pageSize?: number,
|
|
211
|
+
): Promise<AnyDatabaseNotification<Config>[]>;
|
|
212
|
+
getAllFutureNotificationsFromUser(
|
|
213
|
+
userId: NonNullable<
|
|
214
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
215
|
+
>['userId'],
|
|
216
|
+
): Promise<DatabaseNotification<Config>[]>;
|
|
217
|
+
getFutureNotificationsFromUser(
|
|
218
|
+
userId: NonNullable<
|
|
219
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
220
|
+
>['userId'],
|
|
221
|
+
page: number,
|
|
222
|
+
pageSize: number,
|
|
223
|
+
): Promise<DatabaseNotification<Config>[]>;
|
|
224
|
+
getAllNotifications(): Promise<AnyDatabaseNotification<Config>[]>;
|
|
225
|
+
getNotifications(page: number, pageSize: number): Promise<AnyDatabaseNotification<Config>[]>;
|
|
226
|
+
persistNotification(
|
|
227
|
+
notification: NotificationInput<Config>,
|
|
228
|
+
): Promise<DatabaseNotification<Config>>;
|
|
229
|
+
persistNotificationUpdate(
|
|
230
|
+
notificationId: NonNullable<
|
|
231
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
232
|
+
>['id'],
|
|
233
|
+
notification: Partial<Omit<DatabaseNotification<Config>, 'id'>>,
|
|
234
|
+
): Promise<DatabaseNotification<Config>>;
|
|
235
|
+
persistOneOffNotification(
|
|
236
|
+
notification: OneOffNotificationInput<Config>,
|
|
237
|
+
): Promise<DatabaseOneOffNotification<Config>>;
|
|
238
|
+
persistOneOffNotificationUpdate(
|
|
239
|
+
notificationId: NonNullable<
|
|
240
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
241
|
+
>['id'],
|
|
242
|
+
notification: Partial<Omit<DatabaseOneOffNotification<Config>, 'id'>>,
|
|
243
|
+
): Promise<DatabaseOneOffNotification<Config>>;
|
|
244
|
+
getOneOffNotification(
|
|
245
|
+
notificationId: NonNullable<
|
|
246
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
247
|
+
>['id'],
|
|
248
|
+
_forUpdate: boolean,
|
|
249
|
+
): Promise<DatabaseOneOffNotification<Config> | null>;
|
|
250
|
+
getAllOneOffNotifications(): Promise<DatabaseOneOffNotification<Config>[]>;
|
|
251
|
+
getOneOffNotifications(
|
|
252
|
+
page: number,
|
|
253
|
+
pageSize: number,
|
|
254
|
+
): Promise<DatabaseOneOffNotification<Config>[]>;
|
|
255
|
+
markAsSent(
|
|
256
|
+
notificationId: NonNullable<
|
|
257
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
258
|
+
>['id'],
|
|
259
|
+
checkIsPending?: boolean,
|
|
260
|
+
): Promise<AnyDatabaseNotification<Config>>;
|
|
261
|
+
markAsFailed(
|
|
262
|
+
notificationId: NonNullable<
|
|
263
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
264
|
+
>['id'],
|
|
265
|
+
checkIsPending?: boolean,
|
|
266
|
+
): Promise<AnyDatabaseNotification<Config>>;
|
|
267
|
+
markAsRead(
|
|
268
|
+
notificationId: NonNullable<
|
|
269
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
270
|
+
>['id'],
|
|
271
|
+
checkIsSent?: boolean,
|
|
272
|
+
): Promise<DatabaseNotification<Config>>;
|
|
273
|
+
cancelNotification(
|
|
274
|
+
notificationId: NonNullable<
|
|
275
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
276
|
+
>['id'],
|
|
277
|
+
): Promise<void>;
|
|
278
|
+
getNotification(
|
|
279
|
+
notificationId: NonNullable<
|
|
280
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
281
|
+
>['id'],
|
|
282
|
+
_forUpdate: boolean,
|
|
283
|
+
): Promise<AnyDatabaseNotification<Config> | null>;
|
|
284
|
+
filterAllInAppUnreadNotifications(
|
|
285
|
+
userId: NonNullable<
|
|
286
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
287
|
+
>['userId'],
|
|
288
|
+
): Promise<DatabaseNotification<Config>[]>;
|
|
289
|
+
filterInAppUnreadNotifications(
|
|
290
|
+
userId: NonNullable<
|
|
291
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
292
|
+
>['userId'],
|
|
293
|
+
page: number,
|
|
294
|
+
pageSize: number,
|
|
295
|
+
): Promise<DatabaseNotification<Config>[]>;
|
|
296
|
+
getUserEmailFromNotification(
|
|
297
|
+
notificationId: NonNullable<
|
|
298
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
299
|
+
>['id'],
|
|
300
|
+
): Promise<string | undefined>;
|
|
301
|
+
storeContextUsed(
|
|
302
|
+
notificationId: NonNullable<
|
|
303
|
+
Awaited<ReturnType<typeof this.prismaClient.notification.findUnique>>
|
|
304
|
+
>['id'],
|
|
305
|
+
context: InputJsonValue,
|
|
306
|
+
): Promise<void>;
|
|
307
|
+
bulkPersistNotifications(
|
|
308
|
+
notifications: Omit<Notification<Config>, 'id'>[],
|
|
309
|
+
): Promise<Config['NotificationIdType'][]>;
|
|
310
|
+
}
|
|
311
|
+
export declare class PrismaNotificationBackendFactory<Config extends BaseNotificationTypeConfig> {
|
|
312
|
+
create<
|
|
313
|
+
Client extends NotificationPrismaClientInterface<
|
|
314
|
+
Config['NotificationIdType'],
|
|
315
|
+
Config['UserIdType']
|
|
316
|
+
>,
|
|
317
|
+
>(prismaClient: Client): PrismaNotificationBackend<Client, Config>;
|
|
318
|
+
}
|