@voltro/plugin-mail 0.85.0 → 0.86.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/CHANGELOG.md +666 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- package/dist/egress.js +34 -0
- package/dist/events.js +46 -0
- package/dist/idempotency.js +62 -0
- package/dist/index.js +97 -1026
- package/dist/outbox.js +15 -0
- package/dist/providers.js +377 -0
- package/dist/registry.js +13 -0
- package/dist/render.js +44 -0
- package/dist/scheduler.js +36 -0
- package/dist/service.js +279 -0
- package/dist/skeleton.js +24 -0
- package/dist/storeTables.js +28 -0
- package/dist/suppression.js +46 -0
- package/dist/types.js +20 -0
- package/package.json +5 -5
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/plugin-mail
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/plugin-mail itself, which is proprietary (see LICENSE).
|
|
7
7
|
|
|
8
|
-
Generated from the resolved runtime dependency closure (
|
|
8
|
+
Generated from the resolved runtime dependency closure (42 packages).
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -3636,34 +3636,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
3636
3636
|
SOFTWARE.
|
|
3637
3637
|
```
|
|
3638
3638
|
|
|
3639
|
-
## layerr@3.0.0
|
|
3640
|
-
|
|
3641
|
-
License: MIT
|
|
3642
|
-
|
|
3643
|
-
```
|
|
3644
|
-
MIT License
|
|
3645
|
-
|
|
3646
|
-
Copyright (c) 2020 Perry Mitchell
|
|
3647
|
-
|
|
3648
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
3649
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
3650
|
-
in the Software without restriction, including without limitation the rights
|
|
3651
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
3652
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
3653
|
-
furnished to do so, subject to the following conditions:
|
|
3654
|
-
|
|
3655
|
-
The above copyright notice and this permission notice shall be included in all
|
|
3656
|
-
copies or substantial portions of the Software.
|
|
3657
|
-
|
|
3658
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
3659
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
3660
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
3661
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
3662
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
3663
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
3664
|
-
SOFTWARE.
|
|
3665
|
-
```
|
|
3666
|
-
|
|
3667
3639
|
## lib0@0.2.117
|
|
3668
3640
|
|
|
3669
3641
|
License: MIT
|
|
@@ -4036,14 +4008,14 @@ Apache License
|
|
|
4036
4008
|
limitations under the License.
|
|
4037
4009
|
```
|
|
4038
4010
|
|
|
4039
|
-
##
|
|
4011
|
+
## ulid@3.0.2
|
|
4040
4012
|
|
|
4041
4013
|
License: MIT
|
|
4042
4014
|
|
|
4043
4015
|
```
|
|
4044
|
-
MIT License
|
|
4016
|
+
The MIT License (MIT)
|
|
4045
4017
|
|
|
4046
|
-
Copyright (c)
|
|
4018
|
+
Copyright (c) 2017 Alizain Feerasta
|
|
4047
4019
|
|
|
4048
4020
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4049
4021
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/egress.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/egress.ts
|
|
2
|
+
var e = {
|
|
3
|
+
lettermint: "api.lettermint.co",
|
|
4
|
+
resend: "api.resend.com",
|
|
5
|
+
postmark: "api.postmarkapp.com",
|
|
6
|
+
sendgrid: "api.sendgrid.com"
|
|
7
|
+
}, t = (e) => {
|
|
8
|
+
try {
|
|
9
|
+
return new URL(e).host || void 0;
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}, n = (n) => {
|
|
14
|
+
let r = n.env ?? {}, i = (e) => [{
|
|
15
|
+
destination: e,
|
|
16
|
+
purpose: "outgoing email: recipients, subject and body",
|
|
17
|
+
data: ["personal", "content"],
|
|
18
|
+
disable: "MAIL_PROVIDER=console (or memory) logs mail instead of sending it — none leaves"
|
|
19
|
+
}];
|
|
20
|
+
if (n.provider !== void 0 && typeof n.provider != "string") {
|
|
21
|
+
let e = n.provider.name;
|
|
22
|
+
return e === "console" || e === "memory" ? [] : i(`runtime:the '${e}' mail provider`);
|
|
23
|
+
}
|
|
24
|
+
let a = n.provider ?? r.MAIL_PROVIDER ?? "console", o = e[a];
|
|
25
|
+
if (o !== void 0) return i(o);
|
|
26
|
+
switch (a) {
|
|
27
|
+
case "ses": return i(r.AWS_REGION ? `email.${r.AWS_REGION}.amazonaws.com` : "runtime:email.<AWS_REGION>.amazonaws.com");
|
|
28
|
+
case "mailgun": return i((r.MAILGUN_BASE_URL ? t(r.MAILGUN_BASE_URL) : void 0) ?? "api.mailgun.net");
|
|
29
|
+
case "smtp": return i((r.SMTP_URL ? t(r.SMTP_URL) : void 0) ?? (r.SMTP_HOST ? `${r.SMTP_HOST}${r.SMTP_PORT ? `:${r.SMTP_PORT}` : ""}` : void 0) ?? "runtime:SMTP_URL or SMTP_HOST");
|
|
30
|
+
default: return [];
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { n as mailEgressOf };
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Effect as e } from "effect";
|
|
2
|
+
//#region src/events.ts
|
|
3
|
+
var t = (e, t, n, r, i, a = {}) => {
|
|
4
|
+
if (!t) return null;
|
|
5
|
+
let o = a.metadata !== null && typeof a.metadata == "object" ? Object.fromEntries(Object.entries(a.metadata).filter(([, e]) => typeof e == "string")) : void 0;
|
|
6
|
+
return {
|
|
7
|
+
type: e,
|
|
8
|
+
email: t,
|
|
9
|
+
provider: n,
|
|
10
|
+
raw: i,
|
|
11
|
+
...r === void 0 ? {} : { messageId: r },
|
|
12
|
+
...a.eventId === void 0 ? {} : { eventId: a.eventId },
|
|
13
|
+
...o === void 0 ? {} : { metadata: o }
|
|
14
|
+
};
|
|
15
|
+
}, n = (e) => e === "message.hard_bounced" ? "bounced" : e === "message.spam_complaint" ? "complained" : e === "message.unsubscribed" ? "unsubscribed" : e === "message.delivered" ? "delivered" : e === "message.opened" ? "opened" : e === "message.clicked" ? "clicked" : "unknown", r = (e) => e === "hard_bounce" ? "bounced" : e === "spam_complaint" ? "complained" : e === "unsubscribe" ? "unsubscribed" : "unknown", i = (e) => e === "email.bounced" ? "bounced" : e === "email.complained" ? "complained" : e === "email.delivered" ? "delivered" : e === "email.opened" ? "opened" : e === "email.clicked" ? "clicked" : "unknown", a = (e) => e === "Bounce" ? "bounced" : e === "SpamComplaint" ? "complained" : e === "Delivery" ? "delivered" : e === "Open" ? "opened" : e === "Click" ? "clicked" : "unknown", o = (e) => e === "bounce" || e === "dropped" ? "bounced" : e === "spamreport" ? "complained" : e === "delivered" ? "delivered" : e === "open" ? "opened" : e === "click" ? "clicked" : "unknown", s = (e, s) => {
|
|
16
|
+
let c = [], l = (e) => {
|
|
17
|
+
e && c.push(e);
|
|
18
|
+
};
|
|
19
|
+
if (e === "sendgrid" && Array.isArray(s)) {
|
|
20
|
+
for (let e of s) l(t(o(String(e.event)), e.email, "sendgrid", e.sg_message_id, e));
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
let u = s ?? {};
|
|
24
|
+
if (e === "lettermint") {
|
|
25
|
+
let e = String(u.event), i = u.data ?? {}, a = typeof u.id == "string" ? u.id : void 0;
|
|
26
|
+
return e === "suppression.added" ? (i.type === "email" && l(t(r(String(i.reason)), i.value, "lettermint", void 0, s, { eventId: a })), c) : e === "suppression.removed" ? (i.type === "email" && l(t("unsuppressed", i.value, "lettermint", void 0, s, { eventId: a })), c) : (e.startsWith("message.") && l(t(n(e), i.recipient, "lettermint", i.message_id, s, {
|
|
27
|
+
eventId: a,
|
|
28
|
+
metadata: i.metadata
|
|
29
|
+
})), c);
|
|
30
|
+
}
|
|
31
|
+
if (e === "resend") {
|
|
32
|
+
let e = u.data ?? {}, n = Array.isArray(e.to) ? e.to[0] : e.to ?? e.email;
|
|
33
|
+
return l(t(i(String(u.type)), n, "resend", e.email_id, s)), c;
|
|
34
|
+
}
|
|
35
|
+
if (e === "postmark") {
|
|
36
|
+
let e = u.Email ?? u.Recipient;
|
|
37
|
+
return l(t(a(String(u.RecordType)), e, "postmark", u.MessageID, s, { metadata: u.Metadata })), c;
|
|
38
|
+
}
|
|
39
|
+
return c;
|
|
40
|
+
}, c = (t, n, r, i = null) => e.gen(function* () {
|
|
41
|
+
let e = s(t, n);
|
|
42
|
+
for (let t of e) t.type === "bounced" || t.type === "complained" ? yield* r.suppress(i, t.email, t.type) : t.type === "unsuppressed" && (yield* r.unsuppress(i, t.email));
|
|
43
|
+
return e;
|
|
44
|
+
});
|
|
45
|
+
//#endregion
|
|
46
|
+
export { c as handleMailEvents, s as parseMailEvent };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { MAIL_IDEMPOTENCY_TABLE as e, attempt as t, describeError as n } from "./storeTables.js";
|
|
2
|
+
import { Effect as r } from "effect";
|
|
3
|
+
import { createLogger as i } from "@voltro/logger";
|
|
4
|
+
import { and as a, eq as o } from "@voltro/database";
|
|
5
|
+
//#region src/idempotency.ts
|
|
6
|
+
var s = i({ scope: "@voltro/plugin-mail" }), c = (e) => e ?? "*", l = () => {
|
|
7
|
+
let e = /* @__PURE__ */ new Map(), t = (e, t) => `${c(e)} ${t}`;
|
|
8
|
+
return {
|
|
9
|
+
reserve: (n, i) => r.sync(() => {
|
|
10
|
+
let r = t(n, i);
|
|
11
|
+
if (e.has(r)) {
|
|
12
|
+
let t = e.get(r);
|
|
13
|
+
return t ? {
|
|
14
|
+
won: !1,
|
|
15
|
+
prior: t
|
|
16
|
+
} : { won: !1 };
|
|
17
|
+
}
|
|
18
|
+
return e.set(r, null), { won: !0 };
|
|
19
|
+
}),
|
|
20
|
+
record: (n, i, a) => r.sync(() => void e.set(t(n, i), a))
|
|
21
|
+
};
|
|
22
|
+
}, u = () => {
|
|
23
|
+
let i = null;
|
|
24
|
+
return {
|
|
25
|
+
reserve: (a, o) => {
|
|
26
|
+
let l = i;
|
|
27
|
+
return l ? t(() => l.insertIgnoreWithOutcome(e, {
|
|
28
|
+
tenant: c(a),
|
|
29
|
+
key: o,
|
|
30
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
31
|
+
}, { conflictColumns: ["tenant", "key"] })).pipe(r.map(({ row: e, outcome: t }) => {
|
|
32
|
+
if (t === "inserted") return { won: !0 };
|
|
33
|
+
let n = e.resultId, r = e.resultProvider;
|
|
34
|
+
return typeof n == "string" && typeof r == "string" ? {
|
|
35
|
+
won: !1,
|
|
36
|
+
prior: {
|
|
37
|
+
id: n,
|
|
38
|
+
provider: r
|
|
39
|
+
}
|
|
40
|
+
} : { won: !1 };
|
|
41
|
+
}), r.catch((e) => r.sync(() => (s.warn("idempotency reserve failed — skipping send to avoid a double", {
|
|
42
|
+
key: o,
|
|
43
|
+
message: n(e)
|
|
44
|
+
}), { won: !1 })))) : r.succeed({ won: !0 });
|
|
45
|
+
},
|
|
46
|
+
record: (l, u, d) => {
|
|
47
|
+
let f = i;
|
|
48
|
+
return f ? t(() => f.updateMany(e, {
|
|
49
|
+
resultId: d.id,
|
|
50
|
+
resultProvider: d.provider
|
|
51
|
+
}, { where: a(o("tenant", c(l)), o("key", u)) })).pipe(r.asVoid, r.catch((e) => r.sync(() => s.warn("idempotency record failed", {
|
|
52
|
+
key: u,
|
|
53
|
+
message: n(e)
|
|
54
|
+
})))) : r.void;
|
|
55
|
+
},
|
|
56
|
+
bind: async (e) => {
|
|
57
|
+
i = e;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { l as memoryIdempotencyStore, u as postgresIdempotencyStore };
|