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/index.cjs
CHANGED
|
@@ -287,6 +287,7 @@ var init_webhook_tolerance = __esm({
|
|
|
287
287
|
var sendgrid_exports = {};
|
|
288
288
|
__export(sendgrid_exports, {
|
|
289
289
|
SendGridProvider: () => exports.SendGridProvider,
|
|
290
|
+
normalizeSendGridMessageId: () => normalizeSendGridMessageId,
|
|
290
291
|
normalizeWebhookVerificationKey: () => normalizeWebhookVerificationKey
|
|
291
292
|
});
|
|
292
293
|
function normalizeWebhookVerificationKey(input) {
|
|
@@ -316,13 +317,18 @@ ${PEM_FOOTER}
|
|
|
316
317
|
}
|
|
317
318
|
return pem;
|
|
318
319
|
}
|
|
320
|
+
function normalizeSendGridMessageId(raw) {
|
|
321
|
+
const id = String(raw ?? "");
|
|
322
|
+
const marker = /\.(?:filter|recvd)\S*$/i.exec(id);
|
|
323
|
+
return marker ? id.slice(0, marker.index) : id;
|
|
324
|
+
}
|
|
319
325
|
function normalizeSendGridEvent(e) {
|
|
320
326
|
const type = mapEventType(e.event);
|
|
321
327
|
if (!type) return null;
|
|
322
328
|
return {
|
|
323
329
|
type,
|
|
324
330
|
providerEventId: String(e.sg_event_id ?? e["smtp-id"] ?? `${e.event}-${e.timestamp}-${e.email}`),
|
|
325
|
-
providerMessageId:
|
|
331
|
+
providerMessageId: e.sg_message_id != null ? normalizeSendGridMessageId(e.sg_message_id) : String(e["smtp-id"] ?? ""),
|
|
326
332
|
email: String(e.email ?? "").toLowerCase(),
|
|
327
333
|
occurredAt: new Date(Number(e.timestamp) * 1e3),
|
|
328
334
|
details: {
|
|
@@ -1759,11 +1765,20 @@ async function processWebhookBacklog(ctx, opts = {}) {
|
|
|
1759
1765
|
}
|
|
1760
1766
|
}
|
|
1761
1767
|
}
|
|
1768
|
+
async function findSendForEvent(event, ctx) {
|
|
1769
|
+
if (event.providerMessageId) {
|
|
1770
|
+
const byId = await ctx.collections.sends.findOne({ providerMessageId: event.providerMessageId });
|
|
1771
|
+
if (byId) return byId;
|
|
1772
|
+
}
|
|
1773
|
+
if (!event.email) return null;
|
|
1774
|
+
return ctx.collections.sends.findOne({ emailAtSend: event.email, sentAt: { $ne: null } }, { sort: { sentAt: -1 } });
|
|
1775
|
+
}
|
|
1776
|
+
function webhookEventsForMessageId(providerMessageId) {
|
|
1777
|
+
const escaped = providerMessageId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1778
|
+
return { $or: [{ providerMessageId }, { providerMessageId: { $regex: `^${escaped}\\.` } }] };
|
|
1779
|
+
}
|
|
1762
1780
|
async function applyWebhookEvent(event, ctx) {
|
|
1763
|
-
const send = await ctx
|
|
1764
|
-
event.providerMessageId ? { $or: [{ providerMessageId: event.providerMessageId }, { emailAtSend: event.email }] } : { emailAtSend: event.email },
|
|
1765
|
-
{ sort: { queuedAt: -1 } }
|
|
1766
|
-
);
|
|
1781
|
+
const send = await findSendForEvent(event, ctx);
|
|
1767
1782
|
switch (event.type) {
|
|
1768
1783
|
case "delivered":
|
|
1769
1784
|
if (send) {
|
|
@@ -6517,7 +6532,7 @@ function createAdminApiRouter(mailer, opts = {}) {
|
|
|
6517
6532
|
if (!mongodb.ObjectId.isValid(id)) return res.status(400).json({ error: "bad_id" });
|
|
6518
6533
|
const send = await c.sends.findOne({ _id: new mongodb.ObjectId(id) });
|
|
6519
6534
|
if (!send) return res.status(404).json({ error: "not_found" });
|
|
6520
|
-
const events = send.providerMessageId ? await c.webhookEvents.find(
|
|
6535
|
+
const events = send.providerMessageId ? await c.webhookEvents.find(webhookEventsForMessageId(send.providerMessageId)).sort({ receivedAt: -1 }).limit(100).toArray() : [];
|
|
6521
6536
|
return res.json({ send, webhookEvents: events });
|
|
6522
6537
|
})
|
|
6523
6538
|
);
|
|
@@ -8256,7 +8271,7 @@ function unitToMs2(value, unit) {
|
|
|
8256
8271
|
}
|
|
8257
8272
|
|
|
8258
8273
|
// src/server/api/agent.ts
|
|
8259
|
-
var VERSION = "0.16.
|
|
8274
|
+
var VERSION = "0.16.2" ;
|
|
8260
8275
|
var MIN_AGENT_TOKEN_LENGTH = 24;
|
|
8261
8276
|
function createAgentRouter(mailer, opts) {
|
|
8262
8277
|
if (!opts || !Array.isArray(opts.tokens) || opts.tokens.length === 0) {
|
|
@@ -8459,7 +8474,7 @@ function createAgentRouter(mailer, opts) {
|
|
|
8459
8474
|
if (reached || Date.now() - started >= timeoutMs) break;
|
|
8460
8475
|
await sleep2(1e3);
|
|
8461
8476
|
}
|
|
8462
|
-
const webhookEvents = send.providerMessageId ? await c.webhookEvents.find(
|
|
8477
|
+
const webhookEvents = send.providerMessageId ? await c.webhookEvents.find(webhookEventsForMessageId(send.providerMessageId)).sort({ receivedAt: 1 }).limit(100).toArray() : [];
|
|
8463
8478
|
res.json({ reached, target, waitedMs: Date.now() - started, send: sendSummary(send), webhookEvents });
|
|
8464
8479
|
})
|
|
8465
8480
|
);
|
|
@@ -9956,7 +9971,7 @@ var DEDUPE_POLICIES = [
|
|
|
9956
9971
|
];
|
|
9957
9972
|
|
|
9958
9973
|
// src/server/index.ts
|
|
9959
|
-
var VERSION2 = "0.16.
|
|
9974
|
+
var VERSION2 = "0.16.2" ;
|
|
9960
9975
|
|
|
9961
9976
|
exports.DEDUPE_POLICIES = DEDUPE_POLICIES;
|
|
9962
9977
|
exports.DEFAULT_BOT_UA_RE = DEFAULT_BOT_UA_RE;
|