mailery 0.16.1 → 0.16.2
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/index.cjs +24 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +16 -5
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +16 -5
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -300,6 +300,7 @@ var init_webhook_tolerance = __esm({
|
|
|
300
300
|
var sendgrid_exports = {};
|
|
301
301
|
__export(sendgrid_exports, {
|
|
302
302
|
SendGridProvider: () => SendGridProvider,
|
|
303
|
+
normalizeSendGridMessageId: () => normalizeSendGridMessageId,
|
|
303
304
|
normalizeWebhookVerificationKey: () => normalizeWebhookVerificationKey
|
|
304
305
|
});
|
|
305
306
|
function normalizeWebhookVerificationKey(input) {
|
|
@@ -329,13 +330,18 @@ ${PEM_FOOTER}
|
|
|
329
330
|
}
|
|
330
331
|
return pem;
|
|
331
332
|
}
|
|
333
|
+
function normalizeSendGridMessageId(raw) {
|
|
334
|
+
const id = String(raw ?? "");
|
|
335
|
+
const marker = /\.(?:filter|recvd)\S*$/i.exec(id);
|
|
336
|
+
return marker ? id.slice(0, marker.index) : id;
|
|
337
|
+
}
|
|
332
338
|
function normalizeSendGridEvent(e) {
|
|
333
339
|
const type = mapEventType(e.event);
|
|
334
340
|
if (!type) return null;
|
|
335
341
|
return {
|
|
336
342
|
type,
|
|
337
343
|
providerEventId: String(e.sg_event_id ?? e["smtp-id"] ?? `${e.event}-${e.timestamp}-${e.email}`),
|
|
338
|
-
providerMessageId:
|
|
344
|
+
providerMessageId: e.sg_message_id != null ? normalizeSendGridMessageId(e.sg_message_id) : String(e["smtp-id"] ?? ""),
|
|
339
345
|
email: String(e.email ?? "").toLowerCase(),
|
|
340
346
|
occurredAt: new Date(Number(e.timestamp) * 1e3),
|
|
341
347
|
details: {
|
|
@@ -15462,11 +15468,16 @@ async function processWebhookBacklog(ctx, opts = {}) {
|
|
|
15462
15468
|
}
|
|
15463
15469
|
}
|
|
15464
15470
|
}
|
|
15471
|
+
async function findSendForEvent(event, ctx) {
|
|
15472
|
+
if (event.providerMessageId) {
|
|
15473
|
+
const byId = await ctx.collections.sends.findOne({ providerMessageId: event.providerMessageId });
|
|
15474
|
+
if (byId) return byId;
|
|
15475
|
+
}
|
|
15476
|
+
if (!event.email) return null;
|
|
15477
|
+
return ctx.collections.sends.findOne({ emailAtSend: event.email, sentAt: { $ne: null } }, { sort: { sentAt: -1 } });
|
|
15478
|
+
}
|
|
15465
15479
|
async function applyWebhookEvent(event, ctx) {
|
|
15466
|
-
const send = await ctx
|
|
15467
|
-
event.providerMessageId ? { $or: [{ providerMessageId: event.providerMessageId }, { emailAtSend: event.email }] } : { emailAtSend: event.email },
|
|
15468
|
-
{ sort: { queuedAt: -1 } }
|
|
15469
|
-
);
|
|
15480
|
+
const send = await findSendForEvent(event, ctx);
|
|
15470
15481
|
switch (event.type) {
|
|
15471
15482
|
case "delivered":
|
|
15472
15483
|
if (send) {
|