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.cjs
CHANGED
|
@@ -315,6 +315,7 @@ var init_webhook_tolerance = __esm({
|
|
|
315
315
|
var sendgrid_exports = {};
|
|
316
316
|
__export(sendgrid_exports, {
|
|
317
317
|
SendGridProvider: () => SendGridProvider,
|
|
318
|
+
normalizeSendGridMessageId: () => normalizeSendGridMessageId,
|
|
318
319
|
normalizeWebhookVerificationKey: () => normalizeWebhookVerificationKey
|
|
319
320
|
});
|
|
320
321
|
function normalizeWebhookVerificationKey(input) {
|
|
@@ -344,13 +345,18 @@ ${PEM_FOOTER}
|
|
|
344
345
|
}
|
|
345
346
|
return pem;
|
|
346
347
|
}
|
|
348
|
+
function normalizeSendGridMessageId(raw) {
|
|
349
|
+
const id = String(raw ?? "");
|
|
350
|
+
const marker = /\.(?:filter|recvd)\S*$/i.exec(id);
|
|
351
|
+
return marker ? id.slice(0, marker.index) : id;
|
|
352
|
+
}
|
|
347
353
|
function normalizeSendGridEvent(e) {
|
|
348
354
|
const type = mapEventType(e.event);
|
|
349
355
|
if (!type) return null;
|
|
350
356
|
return {
|
|
351
357
|
type,
|
|
352
358
|
providerEventId: String(e.sg_event_id ?? e["smtp-id"] ?? `${e.event}-${e.timestamp}-${e.email}`),
|
|
353
|
-
providerMessageId:
|
|
359
|
+
providerMessageId: e.sg_message_id != null ? normalizeSendGridMessageId(e.sg_message_id) : String(e["smtp-id"] ?? ""),
|
|
354
360
|
email: String(e.email ?? "").toLowerCase(),
|
|
355
361
|
occurredAt: new Date(Number(e.timestamp) * 1e3),
|
|
356
362
|
details: {
|
|
@@ -15477,11 +15483,16 @@ async function processWebhookBacklog(ctx, opts = {}) {
|
|
|
15477
15483
|
}
|
|
15478
15484
|
}
|
|
15479
15485
|
}
|
|
15486
|
+
async function findSendForEvent(event, ctx) {
|
|
15487
|
+
if (event.providerMessageId) {
|
|
15488
|
+
const byId = await ctx.collections.sends.findOne({ providerMessageId: event.providerMessageId });
|
|
15489
|
+
if (byId) return byId;
|
|
15490
|
+
}
|
|
15491
|
+
if (!event.email) return null;
|
|
15492
|
+
return ctx.collections.sends.findOne({ emailAtSend: event.email, sentAt: { $ne: null } }, { sort: { sentAt: -1 } });
|
|
15493
|
+
}
|
|
15480
15494
|
async function applyWebhookEvent(event, ctx) {
|
|
15481
|
-
const send = await ctx
|
|
15482
|
-
event.providerMessageId ? { $or: [{ providerMessageId: event.providerMessageId }, { emailAtSend: event.email }] } : { emailAtSend: event.email },
|
|
15483
|
-
{ sort: { queuedAt: -1 } }
|
|
15484
|
-
);
|
|
15495
|
+
const send = await findSendForEvent(event, ctx);
|
|
15485
15496
|
switch (event.type) {
|
|
15486
15497
|
case "delivered":
|
|
15487
15498
|
if (send) {
|