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