@stamhoofd/models 2.3.0 → 2.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/src/factories/GroupFactory.d.ts.map +1 -1
- package/dist/src/factories/GroupFactory.js +5 -5
- package/dist/src/factories/GroupFactory.js.map +1 -1
- package/dist/src/helpers/EmailBuilder.d.ts +3 -2
- package/dist/src/helpers/EmailBuilder.d.ts.map +1 -1
- package/dist/src/helpers/EmailBuilder.js +29 -16
- package/dist/src/helpers/EmailBuilder.js.map +1 -1
- package/dist/src/helpers/GroupBuilder.d.ts.map +1 -1
- package/dist/src/helpers/GroupBuilder.js +0 -23
- package/dist/src/helpers/GroupBuilder.js.map +1 -1
- package/dist/src/migrations/1721050380-email-table.sql +24 -0
- package/dist/src/migrations/1721050381-email-recipients-table.sql +18 -0
- package/dist/src/migrations/1721342679-responsibility-groupId.sql +2 -0
- package/dist/src/migrations/1721342680-responsibility-groupId-foreign-key.sql +1 -0
- package/dist/src/migrations/1721400546-users-memberId.sql +3 -0
- package/dist/src/migrations/1721639159-membership-deleted-at.sql +2 -0
- package/dist/src/migrations/1721639160-membership-generated.sql +2 -0
- package/dist/src/migrations/1721841819-group-type.sql +2 -0
- package/dist/src/migrations/1722090482-events.sql +18 -0
- package/dist/src/models/DocumentTemplate.js +14 -14
- package/dist/src/models/DocumentTemplate.js.map +1 -1
- package/dist/src/models/Email.d.ts +41 -0
- package/dist/src/models/Email.d.ts.map +1 -0
- package/dist/src/models/Email.js +490 -0
- package/dist/src/models/Email.js.map +1 -0
- package/dist/src/models/EmailRecipient.d.ts +20 -0
- package/dist/src/models/EmailRecipient.d.ts.map +1 -0
- package/dist/src/models/EmailRecipient.js +95 -0
- package/dist/src/models/EmailRecipient.js.map +1 -0
- package/dist/src/models/EmailTemplate.d.ts +2 -1
- package/dist/src/models/EmailTemplate.d.ts.map +1 -1
- package/dist/src/models/EmailTemplate.js +4 -0
- package/dist/src/models/EmailTemplate.js.map +1 -1
- package/dist/src/models/Event.d.ts +19 -0
- package/dist/src/models/Event.d.ts.map +1 -0
- package/dist/src/models/Event.js +78 -0
- package/dist/src/models/Event.js.map +1 -0
- package/dist/src/models/Group.d.ts +2 -1
- package/dist/src/models/Group.d.ts.map +1 -1
- package/dist/src/models/Group.js +9 -22
- package/dist/src/models/Group.js.map +1 -1
- package/dist/src/models/Member.d.ts +1 -0
- package/dist/src/models/Member.d.ts.map +1 -1
- package/dist/src/models/Member.js +42 -11
- package/dist/src/models/Member.js.map +1 -1
- package/dist/src/models/MemberPlatformMembership.d.ts +7 -0
- package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -1
- package/dist/src/models/MemberPlatformMembership.js +22 -0
- package/dist/src/models/MemberPlatformMembership.js.map +1 -1
- package/dist/src/models/MemberResponsibilityRecord.d.ts +3 -0
- package/dist/src/models/MemberResponsibilityRecord.d.ts.map +1 -1
- package/dist/src/models/MemberResponsibilityRecord.js +8 -0
- package/dist/src/models/MemberResponsibilityRecord.js.map +1 -1
- package/dist/src/models/Organization.d.ts +8 -1
- package/dist/src/models/Organization.d.ts.map +1 -1
- package/dist/src/models/Organization.js +37 -9
- package/dist/src/models/Organization.js.map +1 -1
- package/dist/src/models/OrganizationRegistrationPeriod.d.ts +1 -0
- package/dist/src/models/OrganizationRegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/OrganizationRegistrationPeriod.js +7 -0
- package/dist/src/models/OrganizationRegistrationPeriod.js.map +1 -1
- package/dist/src/models/RegistrationPeriod.d.ts +1 -0
- package/dist/src/models/RegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/RegistrationPeriod.js +12 -0
- package/dist/src/models/RegistrationPeriod.js.map +1 -1
- package/dist/src/models/User.d.ts +2 -1
- package/dist/src/models/User.d.ts.map +1 -1
- package/dist/src/models/User.js +13 -3
- package/dist/src/models/User.js.map +1 -1
- package/dist/src/models/index.d.ts +3 -0
- package/dist/src/models/index.d.ts.map +1 -1
- package/dist/src/models/index.js +3 -0
- package/dist/src/models/index.js.map +1 -1
- package/package.json +2 -2
- package/src/factories/GroupFactory.ts +6 -6
- package/src/helpers/EmailBuilder.ts +33 -18
- package/src/helpers/GroupBuilder.ts +0 -23
- package/src/migrations/1721050380-email-table.sql +24 -0
- package/src/migrations/1721050381-email-recipients-table.sql +18 -0
- package/src/migrations/1721342679-responsibility-groupId.sql +2 -0
- package/src/migrations/1721342680-responsibility-groupId-foreign-key.sql +1 -0
- package/src/migrations/1721400546-users-memberId.sql +3 -0
- package/src/migrations/1721639159-membership-deleted-at.sql +2 -0
- package/src/migrations/1721639160-membership-generated.sql +2 -0
- package/src/migrations/1721841819-group-type.sql +2 -0
- package/src/migrations/1722090482-events.sql +18 -0
- package/src/models/DocumentTemplate.ts +2 -2
- package/src/models/Email.ts +556 -0
- package/src/models/EmailRecipient.ts +81 -0
- package/src/models/EmailTemplate.ts +5 -1
- package/src/models/Event.ts +71 -0
- package/src/models/Group.ts +10 -37
- package/src/models/Member.ts +60 -12
- package/src/models/MemberPlatformMembership.ts +21 -0
- package/src/models/MemberResponsibilityRecord.ts +7 -0
- package/src/models/Organization.ts +42 -9
- package/src/models/OrganizationRegistrationPeriod.ts +8 -0
- package/src/models/RegistrationPeriod.ts +14 -0
- package/src/models/User.ts +13 -3
- package/src/models/index.ts +3 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Email = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const simple_database_1 = require("@simonbackx/simple-database");
|
|
6
|
+
const structures_1 = require("@stamhoofd/structures");
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const simple_encoding_1 = require("@simonbackx/simple-encoding");
|
|
9
|
+
const simple_errors_1 = require("@simonbackx/simple-errors");
|
|
10
|
+
const queues_1 = require("@stamhoofd/queues");
|
|
11
|
+
const sql_1 = require("@stamhoofd/sql");
|
|
12
|
+
const EmailRecipient_1 = require("./EmailRecipient");
|
|
13
|
+
const EmailBuilder_1 = require("../helpers/EmailBuilder");
|
|
14
|
+
const Organization_1 = require("./Organization");
|
|
15
|
+
const utility_1 = require("@stamhoofd/utility");
|
|
16
|
+
const email_1 = require("@stamhoofd/email");
|
|
17
|
+
class Email extends simple_database_1.Model {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.organizationId = null;
|
|
21
|
+
this.userId = null;
|
|
22
|
+
this.recipientFilter = structures_1.EmailRecipientFilter.create({});
|
|
23
|
+
/** Raw json structure to edit the template */
|
|
24
|
+
this.json = {};
|
|
25
|
+
this.html = null;
|
|
26
|
+
this.text = null;
|
|
27
|
+
this.fromAddress = null;
|
|
28
|
+
this.fromName = null;
|
|
29
|
+
this.recipientCount = null;
|
|
30
|
+
this.status = structures_1.EmailStatus.Draft;
|
|
31
|
+
this.recipientsStatus = structures_1.EmailRecipientsStatus.NotCreated;
|
|
32
|
+
/**
|
|
33
|
+
* todo: ignore automatically
|
|
34
|
+
*/
|
|
35
|
+
this.attachments = [];
|
|
36
|
+
this.sentAt = null;
|
|
37
|
+
}
|
|
38
|
+
throwIfNotReadyToSend() {
|
|
39
|
+
if (this.subject == null || this.subject.length == 0) {
|
|
40
|
+
throw new simple_errors_1.SimpleError({
|
|
41
|
+
code: 'invalid_field',
|
|
42
|
+
message: 'Missing subject',
|
|
43
|
+
human: 'Vul een onderwerp in voor je een e-mail verstuurt'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (this.text == null || this.text.length == 0) {
|
|
47
|
+
throw new simple_errors_1.SimpleError({
|
|
48
|
+
code: 'invalid_field',
|
|
49
|
+
message: 'Missing text',
|
|
50
|
+
human: 'Vul een tekst in voor je een e-mail verstuurt'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (this.html == null || this.html.length == 0) {
|
|
54
|
+
throw new simple_errors_1.SimpleError({
|
|
55
|
+
code: 'invalid_field',
|
|
56
|
+
message: 'Missing html',
|
|
57
|
+
human: 'Vul een tekst in voor je een e-mail verstuurt'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getFromAddress() {
|
|
62
|
+
if (!this.fromName) {
|
|
63
|
+
return this.fromAddress;
|
|
64
|
+
}
|
|
65
|
+
const cleanedName = utility_1.Formatter.emailSenderName(this.fromName);
|
|
66
|
+
if (cleanedName.length < 2) {
|
|
67
|
+
return this.fromAddress;
|
|
68
|
+
}
|
|
69
|
+
return '"' + cleanedName + '" <' + this.fromAddress + '>';
|
|
70
|
+
}
|
|
71
|
+
getDefaultFromAddress(organization) {
|
|
72
|
+
let address = "noreply@stamhoofd.email";
|
|
73
|
+
if (organization) {
|
|
74
|
+
address = organization.uri + "@stamhoofd.email";
|
|
75
|
+
}
|
|
76
|
+
if (!this.fromName) {
|
|
77
|
+
return address;
|
|
78
|
+
}
|
|
79
|
+
const cleanedName = utility_1.Formatter.emailSenderName(this.fromName);
|
|
80
|
+
if (cleanedName.length < 2) {
|
|
81
|
+
return address;
|
|
82
|
+
}
|
|
83
|
+
return '"' + cleanedName + '" <' + address + '>';
|
|
84
|
+
}
|
|
85
|
+
async send() {
|
|
86
|
+
this.throwIfNotReadyToSend();
|
|
87
|
+
await this.save();
|
|
88
|
+
const id = this.id;
|
|
89
|
+
return await queues_1.QueueHandler.schedule('send-email', async function () {
|
|
90
|
+
var _a;
|
|
91
|
+
let upToDate = await Email.getByID(id);
|
|
92
|
+
if (!upToDate) {
|
|
93
|
+
throw new simple_errors_1.SimpleError({
|
|
94
|
+
code: 'not_found',
|
|
95
|
+
message: 'Email not found',
|
|
96
|
+
human: 'De e-mail die je probeert te versturen bestaat niet meer'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (upToDate.status === structures_1.EmailStatus.Sent) {
|
|
100
|
+
// Already done
|
|
101
|
+
// In other cases -> queue has stopped and we can retry
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const organization = upToDate.organizationId ? await Organization_1.Organization.getByID(upToDate.organizationId) : null;
|
|
105
|
+
upToDate.throwIfNotReadyToSend();
|
|
106
|
+
let from = upToDate.getDefaultFromAddress(organization);
|
|
107
|
+
let replyTo = upToDate.getFromAddress();
|
|
108
|
+
if (!from) {
|
|
109
|
+
throw new simple_errors_1.SimpleError({
|
|
110
|
+
code: 'invalid_field',
|
|
111
|
+
message: 'Missing from',
|
|
112
|
+
human: 'Vul een afzender in voor je een e-mail verstuurt'
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// Can we send from this e-mail or reply-to?
|
|
116
|
+
if (organization) {
|
|
117
|
+
if (organization.privateMeta.mailDomain && organization.privateMeta.mailDomainActive && upToDate.fromAddress.endsWith("@" + organization.privateMeta.mailDomain)) {
|
|
118
|
+
from = upToDate.getFromAddress();
|
|
119
|
+
replyTo = null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Platform
|
|
124
|
+
const domains = Object.values(STAMHOOFD.domains.marketing);
|
|
125
|
+
for (const domain of domains) {
|
|
126
|
+
if (upToDate.fromAddress.endsWith("@" + domain)) {
|
|
127
|
+
from = upToDate.getFromAddress();
|
|
128
|
+
replyTo = null;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
upToDate.status = structures_1.EmailStatus.Sending;
|
|
134
|
+
upToDate.sentAt = (_a = upToDate.sentAt) !== null && _a !== void 0 ? _a : new Date();
|
|
135
|
+
await upToDate.save();
|
|
136
|
+
// Create recipients if not yet created
|
|
137
|
+
await upToDate.buildRecipients();
|
|
138
|
+
// Refresh model
|
|
139
|
+
upToDate = await Email.getByID(id);
|
|
140
|
+
if (!upToDate) {
|
|
141
|
+
throw new simple_errors_1.SimpleError({
|
|
142
|
+
code: 'not_found',
|
|
143
|
+
message: 'Email not found',
|
|
144
|
+
human: 'De e-mail die je probeert te versturen bestaat niet meer'
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (upToDate.recipientsStatus !== structures_1.EmailRecipientsStatus.Created) {
|
|
148
|
+
throw new simple_errors_1.SimpleError({
|
|
149
|
+
code: 'recipients_not_created',
|
|
150
|
+
message: 'Failed to create recipients',
|
|
151
|
+
human: 'Er ging iets mis bij het aanmaken van de afzenders.'
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// Start actually sending in batches of recipients that are not yet sent
|
|
155
|
+
let idPointer = '';
|
|
156
|
+
const batchSize = 100;
|
|
157
|
+
const recipientsSet = new Set();
|
|
158
|
+
// eslint-disable-next-line no-constant-condition
|
|
159
|
+
while (true) {
|
|
160
|
+
const q = sql_1.SQL.select()
|
|
161
|
+
.from(sql_1.SQL.table('email_recipients'))
|
|
162
|
+
.where(sql_1.SQL.column('emailId'), upToDate.id)
|
|
163
|
+
.where(sql_1.SQL.column('sentAt'), null)
|
|
164
|
+
.where(sql_1.SQL.column('id'), sql_1.SQLWhereSign.Greater, idPointer);
|
|
165
|
+
q.orderBy(sql_1.SQL.column('id'), 'ASC');
|
|
166
|
+
q.limit(batchSize);
|
|
167
|
+
const data = await q.fetch();
|
|
168
|
+
const recipients = EmailRecipient_1.EmailRecipient.fromRows(data, 'email_recipients');
|
|
169
|
+
if (recipients.length == 0) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
const sendingPromises = [];
|
|
173
|
+
for (const recipient of recipients) {
|
|
174
|
+
if (recipientsSet.has(recipient.id)) {
|
|
175
|
+
console.error('Found duplicate recipient while sending email', recipient.id);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
recipientsSet.add(recipient.email);
|
|
179
|
+
idPointer = recipient.id;
|
|
180
|
+
let promiseResolve;
|
|
181
|
+
const promise = new Promise((resolve) => {
|
|
182
|
+
promiseResolve = resolve;
|
|
183
|
+
});
|
|
184
|
+
sendingPromises.push(promise);
|
|
185
|
+
const callback = async (error) => {
|
|
186
|
+
var _a;
|
|
187
|
+
if (error === null) {
|
|
188
|
+
// Mark saved
|
|
189
|
+
recipient.sentAt = new Date();
|
|
190
|
+
await recipient.save();
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
recipient.failCount += 1;
|
|
194
|
+
recipient.failErrorMessage = error.message;
|
|
195
|
+
recipient.firstFailedAt = (_a = recipient.firstFailedAt) !== null && _a !== void 0 ? _a : new Date();
|
|
196
|
+
recipient.lastFailedAt = new Date();
|
|
197
|
+
await recipient.save();
|
|
198
|
+
}
|
|
199
|
+
promiseResolve();
|
|
200
|
+
};
|
|
201
|
+
// Do send the email
|
|
202
|
+
// Create e-mail builder
|
|
203
|
+
const builder = await (0, EmailBuilder_1.getEmailBuilder)(organization !== null && organization !== void 0 ? organization : null, {
|
|
204
|
+
recipients: [
|
|
205
|
+
structures_1.Recipient.create({
|
|
206
|
+
...recipient
|
|
207
|
+
})
|
|
208
|
+
],
|
|
209
|
+
from,
|
|
210
|
+
replyTo,
|
|
211
|
+
subject: upToDate.subject,
|
|
212
|
+
html: upToDate.html,
|
|
213
|
+
type: "broadcast",
|
|
214
|
+
callback(error) {
|
|
215
|
+
callback(error).catch(console.error);
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
email_1.Email.schedule(builder);
|
|
219
|
+
}
|
|
220
|
+
await Promise.all(sendingPromises);
|
|
221
|
+
}
|
|
222
|
+
console.log('Finished sending email', upToDate.id);
|
|
223
|
+
// Mark email as sent
|
|
224
|
+
upToDate.status = structures_1.EmailStatus.Sent;
|
|
225
|
+
await upToDate.save();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
updateCount() {
|
|
229
|
+
const id = this.id;
|
|
230
|
+
queues_1.QueueHandler.schedule('email-count-' + this.id, async function () {
|
|
231
|
+
let upToDate = await Email.getByID(id);
|
|
232
|
+
if (!upToDate || upToDate.sentAt || !upToDate.id || upToDate.status !== structures_1.EmailStatus.Draft) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (upToDate.recipientsStatus === structures_1.EmailRecipientsStatus.Created) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
let count = 0;
|
|
239
|
+
try {
|
|
240
|
+
for (const subfilter of upToDate.recipientFilter.filters) {
|
|
241
|
+
// Create recipients
|
|
242
|
+
const loader = Email.recipientLoaders.get(subfilter.type);
|
|
243
|
+
if (!loader) {
|
|
244
|
+
throw new Error('Loader for type ' + subfilter.type + ' has not been initialised on the Email model');
|
|
245
|
+
}
|
|
246
|
+
const request = new structures_1.LimitedFilteredRequest({
|
|
247
|
+
filter: subfilter.filter,
|
|
248
|
+
sort: [{ key: 'id', order: structures_1.SortItemDirection.ASC }],
|
|
249
|
+
limit: 1,
|
|
250
|
+
search: subfilter.search,
|
|
251
|
+
});
|
|
252
|
+
const c = await loader.count(request);
|
|
253
|
+
count += c;
|
|
254
|
+
}
|
|
255
|
+
// Check if we have a more reliable recipientCount in the meantime
|
|
256
|
+
upToDate = await Email.getByID(id);
|
|
257
|
+
if (!upToDate) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (upToDate.recipientsStatus === structures_1.EmailRecipientsStatus.Created) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
upToDate.recipientCount = count;
|
|
264
|
+
await upToDate.save();
|
|
265
|
+
}
|
|
266
|
+
catch (e) {
|
|
267
|
+
console.error("Failed to update count for email", id);
|
|
268
|
+
console.error(e);
|
|
269
|
+
}
|
|
270
|
+
}).catch(console.error);
|
|
271
|
+
}
|
|
272
|
+
async buildRecipients() {
|
|
273
|
+
const id = this.id;
|
|
274
|
+
await queues_1.QueueHandler.schedule('email-build-recipients-' + this.id, async function () {
|
|
275
|
+
var _a;
|
|
276
|
+
const upToDate = await Email.getByID(id);
|
|
277
|
+
if (!upToDate || !upToDate.id) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (upToDate.recipientsStatus === structures_1.EmailRecipientsStatus.Created) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (upToDate.status === structures_1.EmailStatus.Sent) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
// If it is already creating -> something went wrong (e.g. server restart) and we can safely try again
|
|
287
|
+
upToDate.recipientsStatus = structures_1.EmailRecipientsStatus.Creating;
|
|
288
|
+
await upToDate.save();
|
|
289
|
+
let count = 0;
|
|
290
|
+
try {
|
|
291
|
+
// Delete all recipients
|
|
292
|
+
await sql_1.SQL
|
|
293
|
+
.delete()
|
|
294
|
+
.from(sql_1.SQL.table('email_recipients'))
|
|
295
|
+
.where(sql_1.SQL.column('emailId'), upToDate.id);
|
|
296
|
+
for (const subfilter of upToDate.recipientFilter.filters) {
|
|
297
|
+
// Create recipients
|
|
298
|
+
const loader = Email.recipientLoaders.get(subfilter.type);
|
|
299
|
+
if (!loader) {
|
|
300
|
+
throw new Error('Loader for type ' + subfilter.type + ' has not been initialised on the Email model');
|
|
301
|
+
}
|
|
302
|
+
let request = new structures_1.LimitedFilteredRequest({
|
|
303
|
+
filter: subfilter.filter,
|
|
304
|
+
sort: [{ key: 'id', order: structures_1.SortItemDirection.ASC }],
|
|
305
|
+
limit: 1000,
|
|
306
|
+
search: subfilter.search,
|
|
307
|
+
});
|
|
308
|
+
while (request) {
|
|
309
|
+
console.log('Loading page', subfilter.type, request);
|
|
310
|
+
const response = await loader.fetch(request);
|
|
311
|
+
count += response.results.length;
|
|
312
|
+
for (const item of response.results) {
|
|
313
|
+
const recipient = new EmailRecipient_1.EmailRecipient();
|
|
314
|
+
recipient.emailId = upToDate.id;
|
|
315
|
+
recipient.email = item.email;
|
|
316
|
+
recipient.firstName = item.firstName;
|
|
317
|
+
recipient.lastName = item.lastName;
|
|
318
|
+
recipient.replacements = item.replacements;
|
|
319
|
+
await recipient.save();
|
|
320
|
+
}
|
|
321
|
+
request = (_a = response.next) !== null && _a !== void 0 ? _a : null;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// todo: loop all members that match the filter in batches of 1000
|
|
325
|
+
// create a new row for every member + calculate the replacement values
|
|
326
|
+
// todo: do intermediate checks on whether the email was deleted, and stop processing if needed
|
|
327
|
+
upToDate.recipientsStatus = structures_1.EmailRecipientsStatus.Created;
|
|
328
|
+
upToDate.recipientCount = count;
|
|
329
|
+
await upToDate.save();
|
|
330
|
+
}
|
|
331
|
+
catch (e) {
|
|
332
|
+
console.error("Failed to build recipients for email", id);
|
|
333
|
+
console.error(e);
|
|
334
|
+
upToDate.recipientsStatus = structures_1.EmailRecipientsStatus.NotCreated;
|
|
335
|
+
await upToDate.save();
|
|
336
|
+
}
|
|
337
|
+
}).catch(console.error);
|
|
338
|
+
}
|
|
339
|
+
async buildExampleRecipient() {
|
|
340
|
+
const id = this.id;
|
|
341
|
+
await queues_1.QueueHandler.schedule('email-build-recipients-' + this.id, async function () {
|
|
342
|
+
var _a;
|
|
343
|
+
const upToDate = await Email.getByID(id);
|
|
344
|
+
if (!upToDate || upToDate.sentAt || !upToDate.id) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (upToDate.recipientsStatus !== structures_1.EmailRecipientsStatus.NotCreated) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
// Delete all recipients
|
|
352
|
+
await sql_1.SQL
|
|
353
|
+
.delete()
|
|
354
|
+
.from(sql_1.SQL.table('email_recipients'))
|
|
355
|
+
.where(sql_1.SQL.column('emailId'), upToDate.id);
|
|
356
|
+
for (const subfilter of upToDate.recipientFilter.filters) {
|
|
357
|
+
// Create recipients
|
|
358
|
+
const loader = Email.recipientLoaders.get(subfilter.type);
|
|
359
|
+
if (!loader) {
|
|
360
|
+
throw new Error('Loader for type ' + subfilter.type + ' has not been initialised on the Email model');
|
|
361
|
+
}
|
|
362
|
+
let request = new structures_1.LimitedFilteredRequest({
|
|
363
|
+
filter: subfilter.filter,
|
|
364
|
+
sort: [{ key: 'id', order: structures_1.SortItemDirection.ASC }],
|
|
365
|
+
limit: 1,
|
|
366
|
+
search: subfilter.search,
|
|
367
|
+
});
|
|
368
|
+
while (request) {
|
|
369
|
+
console.log('Loading page', subfilter.type, request);
|
|
370
|
+
const response = await loader.fetch(request);
|
|
371
|
+
// Note: it is possible that a result in the database doesn't return a recipient (in memory filtering)
|
|
372
|
+
// so we do need pagination
|
|
373
|
+
for (const item of response.results) {
|
|
374
|
+
const recipient = new EmailRecipient_1.EmailRecipient();
|
|
375
|
+
recipient.emailId = upToDate.id;
|
|
376
|
+
recipient.email = item.email;
|
|
377
|
+
recipient.firstName = item.firstName;
|
|
378
|
+
recipient.lastName = item.lastName;
|
|
379
|
+
recipient.replacements = item.replacements;
|
|
380
|
+
await recipient.save();
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
request = (_a = response.next) !== null && _a !== void 0 ? _a : null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
console.warn('No example recipient found for email', id);
|
|
387
|
+
}
|
|
388
|
+
catch (e) {
|
|
389
|
+
console.error("Failed to build example recipient for email", id);
|
|
390
|
+
console.error(e);
|
|
391
|
+
}
|
|
392
|
+
}).catch(console.error);
|
|
393
|
+
}
|
|
394
|
+
getStructure() {
|
|
395
|
+
return structures_1.Email.create(this);
|
|
396
|
+
}
|
|
397
|
+
async getPreviewStructure() {
|
|
398
|
+
const recipient = await sql_1.SQL.select()
|
|
399
|
+
.from(sql_1.SQL.table(EmailRecipient_1.EmailRecipient.table))
|
|
400
|
+
.where(sql_1.SQL.column('emailId'), this.id)
|
|
401
|
+
.first(false);
|
|
402
|
+
const recipientRow = recipient ? EmailRecipient_1.EmailRecipient.fromRow(recipient[EmailRecipient_1.EmailRecipient.table]) : null;
|
|
403
|
+
const smartVariables = recipientRow ? structures_1.EditorSmartVariable.forRecipient(recipientRow) : [];
|
|
404
|
+
const smartButtons = recipientRow ? structures_1.EditorSmartButton.forRecipient(recipientRow) : [];
|
|
405
|
+
return structures_1.EmailPreview.create({
|
|
406
|
+
...this,
|
|
407
|
+
exampleRecipient: recipientRow ? (recipientRow.getStructure()) : null,
|
|
408
|
+
smartVariables,
|
|
409
|
+
smartButtons
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
exports.Email = Email;
|
|
414
|
+
Email.table = "emails";
|
|
415
|
+
Email.recipientLoaders = new Map();
|
|
416
|
+
tslib_1.__decorate([
|
|
417
|
+
(0, simple_database_1.column)({
|
|
418
|
+
primary: true, type: "string", beforeSave(value) {
|
|
419
|
+
return value !== null && value !== void 0 ? value : (0, uuid_1.v4)();
|
|
420
|
+
}
|
|
421
|
+
})
|
|
422
|
+
], Email.prototype, "id", void 0);
|
|
423
|
+
tslib_1.__decorate([
|
|
424
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
425
|
+
], Email.prototype, "organizationId", void 0);
|
|
426
|
+
tslib_1.__decorate([
|
|
427
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
428
|
+
], Email.prototype, "userId", void 0);
|
|
429
|
+
tslib_1.__decorate([
|
|
430
|
+
(0, simple_database_1.column)({ type: "json", decoder: structures_1.EmailRecipientFilter })
|
|
431
|
+
], Email.prototype, "recipientFilter", void 0);
|
|
432
|
+
tslib_1.__decorate([
|
|
433
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
434
|
+
], Email.prototype, "subject", void 0);
|
|
435
|
+
tslib_1.__decorate([
|
|
436
|
+
(0, simple_database_1.column)({ type: "json", decoder: simple_encoding_1.AnyDecoder })
|
|
437
|
+
], Email.prototype, "json", void 0);
|
|
438
|
+
tslib_1.__decorate([
|
|
439
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
440
|
+
], Email.prototype, "html", void 0);
|
|
441
|
+
tslib_1.__decorate([
|
|
442
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
443
|
+
], Email.prototype, "text", void 0);
|
|
444
|
+
tslib_1.__decorate([
|
|
445
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
446
|
+
], Email.prototype, "fromAddress", void 0);
|
|
447
|
+
tslib_1.__decorate([
|
|
448
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
449
|
+
], Email.prototype, "fromName", void 0);
|
|
450
|
+
tslib_1.__decorate([
|
|
451
|
+
(0, simple_database_1.column)({ type: "integer", nullable: true })
|
|
452
|
+
], Email.prototype, "recipientCount", void 0);
|
|
453
|
+
tslib_1.__decorate([
|
|
454
|
+
(0, simple_database_1.column)({ type: "string" })
|
|
455
|
+
], Email.prototype, "status", void 0);
|
|
456
|
+
tslib_1.__decorate([
|
|
457
|
+
(0, simple_database_1.column)({ type: "string" })
|
|
458
|
+
], Email.prototype, "recipientsStatus", void 0);
|
|
459
|
+
tslib_1.__decorate([
|
|
460
|
+
(0, simple_database_1.column)({ type: "json", decoder: new simple_encoding_1.ArrayDecoder(structures_1.EmailAttachment) })
|
|
461
|
+
], Email.prototype, "attachments", void 0);
|
|
462
|
+
tslib_1.__decorate([
|
|
463
|
+
(0, simple_database_1.column)({
|
|
464
|
+
type: "datetime",
|
|
465
|
+
nullable: true
|
|
466
|
+
})
|
|
467
|
+
], Email.prototype, "sentAt", void 0);
|
|
468
|
+
tslib_1.__decorate([
|
|
469
|
+
(0, simple_database_1.column)({
|
|
470
|
+
type: "datetime", beforeSave(old) {
|
|
471
|
+
if (old !== undefined) {
|
|
472
|
+
return old;
|
|
473
|
+
}
|
|
474
|
+
const date = new Date();
|
|
475
|
+
date.setMilliseconds(0);
|
|
476
|
+
return date;
|
|
477
|
+
}
|
|
478
|
+
})
|
|
479
|
+
], Email.prototype, "createdAt", void 0);
|
|
480
|
+
tslib_1.__decorate([
|
|
481
|
+
(0, simple_database_1.column)({
|
|
482
|
+
type: "datetime", beforeSave() {
|
|
483
|
+
const date = new Date();
|
|
484
|
+
date.setMilliseconds(0);
|
|
485
|
+
return date;
|
|
486
|
+
},
|
|
487
|
+
skipUpdate: true
|
|
488
|
+
})
|
|
489
|
+
], Email.prototype, "updat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C;6CACT;AAGlC;IADC,IAAA,wBAAM,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;qCACA;AAG3B;IADC,IAAA,wBAAM,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;+CACyB;AAMpD;IADC,IAAA,wBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,8BAAY,CAAC,4BAAe,CAAC,EAAE,CAAC;0CAClC;AAOnC;IAJC,IAAA,wBAAM,EAAC;QACJ,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;KACjB,CAAC;qCACsB;AAYxB;IAVC,IAAA,wBAAM,EAAC;QACJ,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,GAAS;YAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACpB,OAAO,GAAG,CAAC;YACf,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;YACvB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,IAAI,CAAA;QACf,CAAC;KACJ,CAAC;wCACa;AAUf;IARC,IAAA,wBAAM,EAAC;QACJ,IAAI,EAAE,UAAU,EAAE,UAAU;YACxB,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;YACvB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;YACvB,OAAO,IAAI,CAAA;QACf,CAAC;QACD,UAAU,EAAE,IAAI;KACnB,CAAC;wCACa"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { EmailRecipient as EmailRecipientStruct, Replacement } from '@stamhoofd/structures';
|
|
3
|
+
export declare class EmailRecipient extends Model {
|
|
4
|
+
static table: string;
|
|
5
|
+
id: string;
|
|
6
|
+
emailId: string;
|
|
7
|
+
firstName: string | null;
|
|
8
|
+
lastName: string | null;
|
|
9
|
+
email: string;
|
|
10
|
+
replacements: Replacement[];
|
|
11
|
+
failErrorMessage: string | null;
|
|
12
|
+
failCount: number;
|
|
13
|
+
firstFailedAt: Date | null;
|
|
14
|
+
lastFailedAt: Date | null;
|
|
15
|
+
sentAt: Date | null;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
getStructure(): EmailRecipientStruct;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=EmailRecipient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailRecipient.d.ts","sourceRoot":"","sources":["../../../src/models/EmailRecipient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,IAAI,oBAAoB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAK5F,qBAAa,cAAe,SAAQ,KAAK;IACrC,MAAM,CAAC,KAAK,SAAsB;IAOlC,EAAE,EAAG,MAAM,CAAC;IAGZ,OAAO,EAAE,MAAM,CAAA;IAGf,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGhC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAG/B,KAAK,EAAE,MAAM,CAAC;IAGd,YAAY,EAAE,WAAW,EAAE,CAAK;IAGhC,gBAAgB,EAAE,MAAM,GAAC,IAAI,CAAO;IAGpC,SAAS,SAAI;IAMb,aAAa,EAAE,IAAI,GAAC,IAAI,CAAO;IAM/B,YAAY,EAAE,IAAI,GAAC,IAAI,CAAO;IAM9B,MAAM,EAAE,IAAI,GAAC,IAAI,CAAO;IAYxB,SAAS,EAAE,IAAI,CAAA;IAUf,SAAS,EAAE,IAAI,CAAA;IAEf,YAAY;CAGf"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailRecipient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const simple_database_1 = require("@simonbackx/simple-database");
|
|
6
|
+
const structures_1 = require("@stamhoofd/structures");
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const simple_encoding_1 = require("@simonbackx/simple-encoding");
|
|
9
|
+
class EmailRecipient extends simple_database_1.Model {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.firstName = null;
|
|
13
|
+
this.lastName = null;
|
|
14
|
+
this.replacements = [];
|
|
15
|
+
this.failErrorMessage = null;
|
|
16
|
+
this.failCount = 0;
|
|
17
|
+
this.firstFailedAt = null;
|
|
18
|
+
this.lastFailedAt = null;
|
|
19
|
+
this.sentAt = null;
|
|
20
|
+
}
|
|
21
|
+
getStructure() {
|
|
22
|
+
return structures_1.EmailRecipient.create(this);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.EmailRecipient = EmailRecipient;
|
|
26
|
+
EmailRecipient.table = "email_recipients";
|
|
27
|
+
tslib_1.__decorate([
|
|
28
|
+
(0, simple_database_1.column)({
|
|
29
|
+
primary: true, type: "string", beforeSave(value) {
|
|
30
|
+
return value !== null && value !== void 0 ? value : (0, uuid_1.v4)();
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
], EmailRecipient.prototype, "id", void 0);
|
|
34
|
+
tslib_1.__decorate([
|
|
35
|
+
(0, simple_database_1.column)({ type: "string" })
|
|
36
|
+
], EmailRecipient.prototype, "emailId", void 0);
|
|
37
|
+
tslib_1.__decorate([
|
|
38
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
39
|
+
], EmailRecipient.prototype, "firstName", void 0);
|
|
40
|
+
tslib_1.__decorate([
|
|
41
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
42
|
+
], EmailRecipient.prototype, "lastName", void 0);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, simple_database_1.column)({ type: "string" })
|
|
45
|
+
], EmailRecipient.prototype, "email", void 0);
|
|
46
|
+
tslib_1.__decorate([
|
|
47
|
+
(0, simple_database_1.column)({ type: "json", decoder: new simple_encoding_1.ArrayDecoder(structures_1.Replacement) })
|
|
48
|
+
], EmailRecipient.prototype, "replacements", void 0);
|
|
49
|
+
tslib_1.__decorate([
|
|
50
|
+
(0, simple_database_1.column)({ type: "string", nullable: true })
|
|
51
|
+
], EmailRecipient.prototype, "failErrorMessage", void 0);
|
|
52
|
+
tslib_1.__decorate([
|
|
53
|
+
(0, simple_database_1.column)({ type: "integer" })
|
|
54
|
+
], EmailRecipient.prototype, "failCount", void 0);
|
|
55
|
+
tslib_1.__decorate([
|
|
56
|
+
(0, simple_database_1.column)({
|
|
57
|
+
type: "datetime",
|
|
58
|
+
nullable: true
|
|
59
|
+
})
|
|
60
|
+
], EmailRecipient.prototype, "firstFailedAt", void 0);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, simple_database_1.column)({
|
|
63
|
+
type: "datetime",
|
|
64
|
+
nullable: true
|
|
65
|
+
})
|
|
66
|
+
], EmailRecipient.prototype, "lastFailedAt", void 0);
|
|
67
|
+
tslib_1.__decorate([
|
|
68
|
+
(0, simple_database_1.column)({
|
|
69
|
+
type: "datetime",
|
|
70
|
+
nullable: true
|
|
71
|
+
})
|
|
72
|
+
], EmailRecipient.prototype, "sentAt", void 0);
|
|
73
|
+
tslib_1.__decorate([
|
|
74
|
+
(0, simple_database_1.column)({
|
|
75
|
+
type: "datetime", beforeSave(old) {
|
|
76
|
+
if (old !== undefined) {
|
|
77
|
+
return old;
|
|
78
|
+
}
|
|
79
|
+
const date = new Date();
|
|
80
|
+
date.setMilliseconds(0);
|
|
81
|
+
return date;
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
], EmailRecipient.prototype, "createdAt", void 0);
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, simple_database_1.column)({
|
|
87
|
+
type: "datetime", beforeSave() {
|
|
88
|
+
const date = new Date();
|
|
89
|
+
date.setMilliseconds(0);
|
|
90
|
+
return date;
|
|
91
|
+
},
|
|
92
|
+
skipUpdate: true
|
|
93
|
+
})
|
|
94
|
+
], EmailRecipient.prototype, "updatedAt", void 0);
|
|
95
|
+
//# sourceMappingURL=EmailRecipient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailRecipient.js","sourceRoot":"","sources":["../../../src/models/EmailRecipient.ts"],"names":[],"mappings":";;;;AAAA,iEAA4D;AAC5D,sDAA4F;AAC5F,+BAAoC;AAEpC,iEAA2D;AAE3D,MAAa,cAAe,SAAQ,uBAAK;IAAzC;;QAcI,cAAS,GAAkB,IAAI,CAAC;QAGhC,aAAQ,GAAkB,IAAI,CAAC;QAM/B,iBAAY,GAAkB,EAAE,CAAA;QAGhC,qBAAgB,GAAgB,IAAI,CAAA;QAGpC,cAAS,GAAG,CAAC,CAAA;QAMb,kBAAa,GAAc,IAAI,CAAA;QAM/B,iBAAY,GAAc,IAAI,CAAA;QAM9B,WAAM,GAAc,IAAI,CAAA;IA2B5B,CAAC;IAHG,YAAY;QACR,OAAO,2BAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;;AAzEL,wCA0EC;AAzEU,oBAAK,GAAG,kBAAkB,AAArB,CAAsB;AAOlC;IALC,IAAA,wBAAM,EAAC;QACJ,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK;YAC3C,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAA,SAAM,GAAE,CAAC;QAC7B,CAAC;KACJ,CAAC;0CACU;AAGZ;IADC,IAAA,wBAAM,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;+CACZ;AAGf;IADC,IAAA,wBAAM,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;iDACX;AAGhC;IADC,IAAA,wBAAM,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ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AI;KACnB,CAAC;iDACa"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Model } from "@simonbackx/simple-database";
|
|
2
|
-
import { EmailTemplateType } from "@stamhoofd/structures";
|
|
2
|
+
import { EmailTemplate as EmailTemplateStruct, EmailTemplateType } from "@stamhoofd/structures";
|
|
3
3
|
/**
|
|
4
4
|
* Holds the challenges for a given email. User should not exist, since that would allow user enumeration attacks
|
|
5
5
|
*/
|
|
@@ -18,5 +18,6 @@ export declare class EmailTemplate extends Model {
|
|
|
18
18
|
text: string;
|
|
19
19
|
createdAt: Date;
|
|
20
20
|
updatedAt: Date;
|
|
21
|
+
getStructure(): EmailTemplateStruct;
|
|
21
22
|
}
|
|
22
23
|
//# sourceMappingURL=EmailTemplate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailTemplate.d.ts","sourceRoot":"","sources":["../../../src/models/EmailTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"EmailTemplate.d.ts","sourceRoot":"","sources":["../../../src/models/EmailTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAA4B,aAAa,IAAI,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1H;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACpC,MAAM,CAAC,KAAK,SAAqB;IAOjC,EAAE,EAAG,MAAM,CAAC;IAGZ,OAAO,EAAE,MAAM,CAAC;IAGhB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAG9B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IAG9B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGhC,IAAI,EAAE,iBAAiB,CAAC;IAExB,8CAA8C;IAE9C,IAAI,EAAE,GAAG,CAAC;IAEV,uFAAuF;IAEvF,IAAI,EAAE,MAAM,CAAC;IAGb,IAAI,EAAE,MAAM,CAAC;IASb,SAAS,EAAE,IAAI,CAAA;IAUf,SAAS,EAAE,IAAI,CAAA;IAEf,YAAY;CAGf"}
|