vintasend 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/README.md +227 -12
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/next.config.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/next.config.js +9 -4
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/forgot-password/forgot-password-notification-context.d.ts +6 -6
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/forgot-password/forgot-password-notification-context.js +16 -17
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/forgot-password/route.d.ts +7 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/forgot-password/route.js +105 -79
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/login/route.d.ts +4 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/login/route.js +96 -66
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/reset-password/route.d.ts +7 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/reset-password/route.js +95 -71
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/signup/email-verification-notification-context.d.ts +6 -6
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/signup/email-verification-notification-context.js +18 -18
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/signup/route.d.ts +4 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/signup/route.js +124 -96
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/verify-email/route.d.ts +7 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/api/auth/verify-email/route.js +94 -70
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/login/page.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/login/page.js +67 -55
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/reset-password/[token]/page.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/reset-password/[token]/page.js +76 -63
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/signup/page.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/signup/page.js +87 -63
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/verify-email/[token]/page.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/verify-email/[token]/page.js +50 -35
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/verify-email-sent/page.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/auth/verify-email-sent/page.js +12 -12
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/layout.d.ts +7 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/layout.js +15 -16
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/page.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/app/page.js +65 -21
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/AuthLayout.d.ts +7 -4
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/AuthLayout.js +7 -8
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/accordion.d.ts +18 -6
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/accordion.js +86 -48
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/alert-dialog.d.ts +58 -14
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/alert-dialog.js +135 -53
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/alert.d.ts +21 -7
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/alert.js +85 -49
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/avatar.d.ts +14 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/avatar.js +77 -40
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/button.d.ts +25 -9
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/button.js +80 -58
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/card.d.ts +19 -7
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/card.js +98 -48
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/checkbox.d.ts +6 -3
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/checkbox.js +66 -42
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/collapsible.d.ts +10 -4
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/collapsible.js +48 -35
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/dialog.d.ts +40 -13
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/dialog.js +116 -50
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/dropdown-menu.d.ts +83 -19
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/dropdown-menu.js +170 -68
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/form.d.ts +53 -21
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/form.js +137 -83
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/input.d.ts +8 -2
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/input.js +60 -37
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/label.d.ts +10 -4
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/label.js +61 -40
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/menubar.d.ts +77 -23
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/menubar.js +188 -64
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/select.d.ts +48 -12
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/select.js +148 -66
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/textarea.d.ts +8 -2
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/components/ui/textarea.js +59 -37
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/api-clients/auth.d.ts +10 -10
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/api-clients/auth.js +54 -55
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/api-clients/core.d.ts +14 -11
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/api-clients/core.js +1 -2
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/email.js +0 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/logger.d.ts +3 -3
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/logger.js +9 -10
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/schemas/auth.d.ts +66 -32
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/schemas/auth.js +74 -54
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/auth.js +7 -8
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/notifications-with-queue.d.ts +14 -4
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/notifications-with-queue.js +14 -10
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/notifications.d.ts +11 -7
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/notifications.js +39 -26
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/temporal-queue-service.d.ts +11 -8
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/services/temporal-queue-service.js +14 -15
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/temporal.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/temporal.js +9 -10
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/utils.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/lib/utils.js +4 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/activities.d.ts +6 -5
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/activities.js +14 -14
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/config.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/config.js +2 -3
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/constants.d.ts +1 -1
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/constants.js +1 -2
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/worker.js +20 -22
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/workflows.d.ts +3 -2
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/src/workers/notifications/workflows.js +10 -9
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/tailwind.config.d.ts +74 -74
- package/dist/examples/nextjs-prisma-nodemailer-pug-temporal/tailwind.config.js +80 -81
- package/dist/implementations/vintasend-nodemailer/src/index.js +6 -4
- package/dist/implementations/vintasend-nodemailer/src/nodemailer-notification-adapter.d.ts +36 -14
- package/dist/implementations/vintasend-nodemailer/src/nodemailer-notification-adapter.js +26 -28
- package/dist/implementations/vintasend-prisma/src/index.js +6 -4
- package/dist/implementations/vintasend-prisma/src/prisma-notification-backend.d.ts +232 -138
- package/dist/implementations/vintasend-prisma/src/prisma-notification-backend.js +275 -262
- package/dist/implementations/vintasend-pug/src/index.js +6 -4
- package/dist/implementations/vintasend-pug/src/pug-email-template-renderer.d.ts +18 -7
- package/dist/implementations/vintasend-pug/src/pug-email-template-renderer.js +19 -21
- package/dist/implementations/vintasend-winston/src/index.js +6 -4
- package/dist/implementations/vintasend-winston/src/winston-logger.d.ts +6 -6
- package/dist/implementations/vintasend-winston/src/winston-logger.js +65 -50
- package/dist/index.d.ts +13 -5
- package/dist/index.js +13 -1
- package/dist/services/attachment-manager/base-attachment-manager.d.ts +42 -0
- package/dist/services/attachment-manager/base-attachment-manager.js +115 -0
- package/dist/services/attachment-manager/local-file-attachment-manager.d.ts +58 -0
- package/dist/services/attachment-manager/local-file-attachment-manager.js +192 -0
- package/dist/services/notification-adapters/base-notification-adapter.d.ts +36 -4
- package/dist/services/notification-adapters/base-notification-adapter.js +73 -4
- package/dist/services/notification-backends/base-notification-backend.d.ts +54 -11
- package/dist/services/notification-backends/base-notification-backend.js +12 -0
- package/dist/services/notification-context-generators-map.d.ts +1 -1
- package/dist/services/notification-context-registry.d.ts +14 -9
- package/dist/services/notification-context-registry.js +30 -31
- package/dist/services/notification-queue-service/base-notification-queue-service.d.ts +1 -1
- package/dist/services/notification-service.d.ts +73 -13
- package/dist/services/notification-service.js +125 -8
- package/dist/services/notification-template-renderers/base-email-template-renderer.d.ts +3 -3
- package/dist/services/notification-template-renderers/base-notification-template-renderer.d.ts +2 -2
- package/dist/types/attachment.d.ts +42 -0
- package/dist/types/attachment.js +7 -0
- package/dist/types/notification-type-config.d.ts +2 -2
- package/dist/types/notification.d.ts +21 -0
- package/dist/types/one-off-notification.d.ts +72 -0
- package/dist/types/one-off-notification.js +2 -0
- package/package.json +13 -11
|
@@ -1,272 +1,285 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
exports.PrismaNotificationBackend =
|
|
3
|
+
exports.NotificationTypeEnum =
|
|
4
|
+
exports.NotificationStatusEnum =
|
|
5
|
+
void 0;
|
|
4
6
|
exports.NotificationStatusEnum = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
PENDING_SEND: 'PENDING_SEND',
|
|
8
|
+
SENT: 'SENT',
|
|
9
|
+
FAILED: 'FAILED',
|
|
10
|
+
READ: 'READ',
|
|
11
|
+
CANCELLED: 'CANCELLED',
|
|
10
12
|
};
|
|
11
13
|
exports.NotificationTypeEnum = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
EMAIL: 'EMAIL',
|
|
15
|
+
PUSH: 'PUSH',
|
|
16
|
+
SMS: 'SMS',
|
|
17
|
+
IN_APP: 'IN_APP',
|
|
16
18
|
};
|
|
17
19
|
function convertJsonValueToRecord(jsonValue) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (typeof jsonValue === 'object' && !Array.isArray(jsonValue) && jsonValue !== null) {
|
|
21
|
+
return jsonValue;
|
|
22
|
+
}
|
|
23
|
+
throw new Error('Invalid JSON value. It should be an object.');
|
|
22
24
|
}
|
|
23
25
|
class PrismaNotificationBackend {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
readAt: null,
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
return notifications.map(this.serializeNotification);
|
|
236
|
-
}
|
|
237
|
-
async filterInAppUnreadNotifications(userId, page, pageSize) {
|
|
238
|
-
const notifications = await this.prismaClient.notification.findMany({
|
|
239
|
-
where: {
|
|
240
|
-
userId,
|
|
241
|
-
status: 'SENT',
|
|
242
|
-
readAt: null,
|
|
243
|
-
},
|
|
244
|
-
skip: page * pageSize,
|
|
245
|
-
take: pageSize,
|
|
246
|
-
});
|
|
247
|
-
return notifications.map(this.serializeNotification);
|
|
248
|
-
}
|
|
249
|
-
async getUserEmailFromNotification(notificationId) {
|
|
250
|
-
var _a;
|
|
251
|
-
const notification = await this.prismaClient.notification.findUnique({
|
|
252
|
-
where: {
|
|
253
|
-
id: notificationId,
|
|
254
|
-
},
|
|
255
|
-
include: {
|
|
256
|
-
user: true,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
return (_a = notification === null || notification === void 0 ? void 0 : notification.user) === null || _a === void 0 ? void 0 : _a.email;
|
|
260
|
-
}
|
|
261
|
-
async storeContextUsed(notificationId, context) {
|
|
262
|
-
await this.prismaClient.notification.update({
|
|
263
|
-
where: {
|
|
264
|
-
id: notificationId,
|
|
265
|
-
},
|
|
266
|
-
data: {
|
|
267
|
-
contextUsed: context,
|
|
268
|
-
},
|
|
269
|
-
});
|
|
26
|
+
constructor(prismaClient) {
|
|
27
|
+
this.prismaClient = prismaClient;
|
|
28
|
+
}
|
|
29
|
+
serializeNotification(notification) {
|
|
30
|
+
return {
|
|
31
|
+
id: notification.id,
|
|
32
|
+
userId: notification.userId,
|
|
33
|
+
notificationType: notification.notificationType,
|
|
34
|
+
title: notification.title,
|
|
35
|
+
bodyTemplate: notification.bodyTemplate,
|
|
36
|
+
contextName: notification.contextName,
|
|
37
|
+
contextParameters: notification.contextParameters ? notification.contextParameters : {},
|
|
38
|
+
sendAfter: notification.sendAfter,
|
|
39
|
+
subjectTemplate: notification.subjectTemplate,
|
|
40
|
+
status: notification.status,
|
|
41
|
+
contextUsed: notification.contextUsed,
|
|
42
|
+
extraParams: notification.extraParams
|
|
43
|
+
? convertJsonValueToRecord(notification.extraParams)
|
|
44
|
+
: null,
|
|
45
|
+
adapterUsed: notification.adapterUsed,
|
|
46
|
+
sentAt: notification.sentAt,
|
|
47
|
+
readAt: notification.readAt,
|
|
48
|
+
createdAt: notification.createdAt,
|
|
49
|
+
updatedAt: notification.updatedAt,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
deserializeNotification(notification) {
|
|
53
|
+
return {
|
|
54
|
+
user: {
|
|
55
|
+
connect: {
|
|
56
|
+
id: notification.userId,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
notificationType: notification.notificationType,
|
|
60
|
+
title: notification.title,
|
|
61
|
+
bodyTemplate: notification.bodyTemplate,
|
|
62
|
+
contextName: notification.contextName,
|
|
63
|
+
contextParameters: notification.contextParameters,
|
|
64
|
+
sendAfter: notification.sendAfter,
|
|
65
|
+
subjectTemplate: notification.subjectTemplate,
|
|
66
|
+
extraParams: notification.extraParams,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
deserializeNotificationForUpdate(notification) {
|
|
70
|
+
return {
|
|
71
|
+
...(notification.userId ? { user: { connect: { id: notification.userId } } } : {}),
|
|
72
|
+
...(notification.notificationType
|
|
73
|
+
? {
|
|
74
|
+
notificationType: exports.NotificationTypeEnum[notification.notificationType],
|
|
75
|
+
}
|
|
76
|
+
: {}),
|
|
77
|
+
...(notification.title ? { title: notification.title } : {}),
|
|
78
|
+
...(notification.bodyTemplate ? { bodyTemplate: notification.bodyTemplate } : {}),
|
|
79
|
+
...(notification.contextName ? { contextName: notification.contextName } : {}),
|
|
80
|
+
...(notification.contextParameters
|
|
81
|
+
? {
|
|
82
|
+
contextParameters: notification.contextParameters ? notification.contextParameters : {},
|
|
83
|
+
}
|
|
84
|
+
: {}),
|
|
85
|
+
...(notification.sendAfter ? { sendAfter: notification.sendAfter } : {}),
|
|
86
|
+
...(notification.subjectTemplate ? { subjectTemplate: notification.subjectTemplate } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async getAllPendingNotifications() {
|
|
90
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
91
|
+
where: {
|
|
92
|
+
status: exports.NotificationStatusEnum.PENDING_SEND,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
return notifications.map(this.serializeNotification);
|
|
96
|
+
}
|
|
97
|
+
async getPendingNotifications() {
|
|
98
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
99
|
+
where: {
|
|
100
|
+
status: exports.NotificationStatusEnum.PENDING_SEND,
|
|
101
|
+
sendAfter: null,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
return notifications.map(this.serializeNotification);
|
|
105
|
+
}
|
|
106
|
+
async getAllFutureNotifications() {
|
|
107
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
108
|
+
where: {
|
|
109
|
+
status: {
|
|
110
|
+
not: exports.NotificationStatusEnum.PENDING_SEND,
|
|
111
|
+
},
|
|
112
|
+
sendAfter: {
|
|
113
|
+
lte: new Date(),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
return notifications.map(this.serializeNotification);
|
|
118
|
+
}
|
|
119
|
+
async getFutureNotifications() {
|
|
120
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
121
|
+
where: {
|
|
122
|
+
status: {
|
|
123
|
+
not: exports.NotificationStatusEnum.PENDING_SEND,
|
|
124
|
+
},
|
|
125
|
+
sendAfter: {
|
|
126
|
+
lte: new Date(),
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
return notifications.map(this.serializeNotification);
|
|
131
|
+
}
|
|
132
|
+
async getAllFutureNotificationsFromUser(userId) {
|
|
133
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
134
|
+
where: {
|
|
135
|
+
userId,
|
|
136
|
+
status: {
|
|
137
|
+
not: exports.NotificationStatusEnum.PENDING_SEND,
|
|
138
|
+
},
|
|
139
|
+
sendAfter: {
|
|
140
|
+
lte: new Date(),
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return notifications.map(this.serializeNotification);
|
|
145
|
+
}
|
|
146
|
+
async getFutureNotificationsFromUser(userId) {
|
|
147
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
148
|
+
where: {
|
|
149
|
+
userId,
|
|
150
|
+
status: {
|
|
151
|
+
not: exports.NotificationStatusEnum.PENDING_SEND,
|
|
152
|
+
},
|
|
153
|
+
sendAfter: {
|
|
154
|
+
lte: new Date(),
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
return notifications.map(this.serializeNotification);
|
|
159
|
+
}
|
|
160
|
+
async persistNotification(notification) {
|
|
161
|
+
return this.serializeNotification(
|
|
162
|
+
await this.prismaClient.notification.create({
|
|
163
|
+
data: this.deserializeNotification(notification),
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
async persistNotificationUpdate(notificationId, notification) {
|
|
168
|
+
return this.serializeNotification(
|
|
169
|
+
await this.prismaClient.notification.update({
|
|
170
|
+
where: {
|
|
171
|
+
id: notificationId,
|
|
172
|
+
},
|
|
173
|
+
data: this.deserializeNotificationForUpdate(notification),
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
async markPendingAsSent(notificationId) {
|
|
178
|
+
return this.serializeNotification(
|
|
179
|
+
await this.prismaClient.notification.update({
|
|
180
|
+
where: {
|
|
181
|
+
id: notificationId,
|
|
182
|
+
},
|
|
183
|
+
data: {
|
|
184
|
+
status: exports.NotificationStatusEnum.SENT,
|
|
185
|
+
sentAt: new Date(),
|
|
186
|
+
},
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
async markPendingAsFailed(notificationId) {
|
|
191
|
+
return this.serializeNotification(
|
|
192
|
+
await this.prismaClient.notification.update({
|
|
193
|
+
where: {
|
|
194
|
+
id: notificationId,
|
|
195
|
+
},
|
|
196
|
+
data: {
|
|
197
|
+
status: exports.NotificationStatusEnum.FAILED,
|
|
198
|
+
sentAt: new Date(),
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
async markSentAsRead(notificationId) {
|
|
204
|
+
return this.serializeNotification(
|
|
205
|
+
await this.prismaClient.notification.update({
|
|
206
|
+
where: {
|
|
207
|
+
id: notificationId,
|
|
208
|
+
},
|
|
209
|
+
data: {
|
|
210
|
+
status: 'READ',
|
|
211
|
+
readAt: new Date(),
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
async cancelNotification(notificationId) {
|
|
217
|
+
await this.prismaClient.notification.update({
|
|
218
|
+
where: {
|
|
219
|
+
id: notificationId,
|
|
220
|
+
},
|
|
221
|
+
data: {
|
|
222
|
+
status: exports.NotificationStatusEnum.CANCELLED,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async getNotification(notificationId, _forUpdate) {
|
|
227
|
+
const notification = await this.prismaClient.notification.findUnique({
|
|
228
|
+
where: {
|
|
229
|
+
id: notificationId,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
if (!notification) {
|
|
233
|
+
return null;
|
|
270
234
|
}
|
|
235
|
+
return this.serializeNotification(notification);
|
|
236
|
+
}
|
|
237
|
+
async filterAllInAppUnreadNotifications(userId) {
|
|
238
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
239
|
+
where: {
|
|
240
|
+
userId,
|
|
241
|
+
status: 'SENT',
|
|
242
|
+
readAt: null,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
return notifications.map(this.serializeNotification);
|
|
246
|
+
}
|
|
247
|
+
async filterInAppUnreadNotifications(userId, page, pageSize) {
|
|
248
|
+
const notifications = await this.prismaClient.notification.findMany({
|
|
249
|
+
where: {
|
|
250
|
+
userId,
|
|
251
|
+
status: 'SENT',
|
|
252
|
+
readAt: null,
|
|
253
|
+
},
|
|
254
|
+
skip: page * pageSize,
|
|
255
|
+
take: pageSize,
|
|
256
|
+
});
|
|
257
|
+
return notifications.map(this.serializeNotification);
|
|
258
|
+
}
|
|
259
|
+
async getUserEmailFromNotification(notificationId) {
|
|
260
|
+
var _a;
|
|
261
|
+
const notification = await this.prismaClient.notification.findUnique({
|
|
262
|
+
where: {
|
|
263
|
+
id: notificationId,
|
|
264
|
+
},
|
|
265
|
+
include: {
|
|
266
|
+
user: true,
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
return (_a = notification === null || notification === void 0 ? void 0 : notification.user) ===
|
|
270
|
+
null || _a === void 0
|
|
271
|
+
? void 0
|
|
272
|
+
: _a.email;
|
|
273
|
+
}
|
|
274
|
+
async storeContextUsed(notificationId, context) {
|
|
275
|
+
await this.prismaClient.notification.update({
|
|
276
|
+
where: {
|
|
277
|
+
id: notificationId,
|
|
278
|
+
},
|
|
279
|
+
data: {
|
|
280
|
+
contextUsed: context,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
}
|
|
271
284
|
}
|
|
272
285
|
exports.PrismaNotificationBackend = PrismaNotificationBackend;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
2
|
exports.PugEmailTemplateRenderer = void 0;
|
|
4
|
-
var pug_email_template_renderer_1 = require(
|
|
5
|
-
Object.defineProperty(exports,
|
|
3
|
+
var pug_email_template_renderer_1 = require('./pug-email-template-renderer');
|
|
4
|
+
Object.defineProperty(exports, 'PugEmailTemplateRenderer', {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: () => pug_email_template_renderer_1.PugEmailTemplateRenderer,
|
|
7
|
+
});
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
import type pug from 'pug';
|
|
1
2
|
import type { ContextGenerator } from 'vintasend/src/services/notification-context-registry';
|
|
2
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
BaseEmailTemplateRenderer,
|
|
5
|
+
EmailTemplate,
|
|
6
|
+
} from 'vintasend/src/services/notification-template-renderers/base-email-template-renderer';
|
|
7
|
+
import type { Identifier } from 'vintasend/src/types/identifier';
|
|
3
8
|
import type { JsonObject } from 'vintasend/src/types/json-values';
|
|
4
9
|
import type { Notification } from 'vintasend/src/types/notification';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export declare class PugEmailTemplateRenderer<
|
|
11
|
+
AvailableContexts extends Record<string, ContextGenerator>,
|
|
12
|
+
NotificationIdType extends Identifier = Identifier,
|
|
13
|
+
UserIdType extends Identifier = Identifier,
|
|
14
|
+
> implements BaseEmailTemplateRenderer<AvailableContexts, NotificationIdType, UserIdType>
|
|
15
|
+
{
|
|
16
|
+
private options;
|
|
17
|
+
constructor(options?: pug.Options);
|
|
18
|
+
render(
|
|
19
|
+
notification: Notification<AvailableContexts, NotificationIdType, UserIdType>,
|
|
20
|
+
context: JsonObject,
|
|
21
|
+
): Promise<EmailTemplate>;
|
|
11
22
|
}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
var __importDefault =
|
|
2
|
+
(this && this.__importDefault) || ((mod) => (mod && mod.__esModule ? mod : { default: mod }));
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
4
|
exports.PugEmailTemplateRenderer = void 0;
|
|
7
|
-
const pug_1 = __importDefault(require(
|
|
5
|
+
const pug_1 = __importDefault(require('pug'));
|
|
8
6
|
class PugEmailTemplateRenderer {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const subjectTemplate = pug_1.default.compileFile(notification.subjectTemplate, this.options);
|
|
18
|
-
return new Promise((resolve) => {
|
|
19
|
-
resolve({
|
|
20
|
-
subject: subjectTemplate(context || {}),
|
|
21
|
-
body: bodyTemplate(context || {}),
|
|
22
|
-
});
|
|
23
|
-
});
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
render(notification, context) {
|
|
11
|
+
const bodyTemplate = pug_1.default.compileFile(notification.bodyTemplate, this.options);
|
|
12
|
+
if (!notification.subjectTemplate) {
|
|
13
|
+
throw new Error('Subject template is required');
|
|
24
14
|
}
|
|
15
|
+
const subjectTemplate = pug_1.default.compileFile(notification.subjectTemplate, this.options);
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
resolve({
|
|
18
|
+
subject: subjectTemplate(context || {}),
|
|
19
|
+
body: bodyTemplate(context || {}),
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
25
23
|
}
|
|
26
24
|
exports.PugEmailTemplateRenderer = PugEmailTemplateRenderer;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
2
|
exports.WinstonLogger = void 0;
|
|
4
|
-
var winston_logger_1 = require(
|
|
5
|
-
Object.defineProperty(exports,
|
|
3
|
+
var winston_logger_1 = require('./winston-logger');
|
|
4
|
+
Object.defineProperty(exports, 'WinstonLogger', {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: () => winston_logger_1.WinstonLogger,
|
|
7
|
+
});
|