@softure-ai/mailing 0.1.6 → 0.1.7
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 +19 -0
- package/README.md +83 -18
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +46 -15
- package/dist/cli/run.js.map +1 -1
- package/dist/contract.d.ts +48 -8
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/messages/en.d.ts +2 -0
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +2 -0
- package/dist/messages/en.js.map +1 -1
- package/dist/messages/index.d.ts +4 -0
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/messages/pl.d.ts.map +1 -1
- package/dist/messages/pl.js +2 -0
- package/dist/messages/pl.js.map +1 -1
- package/dist/next/actions.d.ts.map +1 -1
- package/dist/next/actions.js +6 -6
- package/dist/next/actions.js.map +1 -1
- package/dist/next/pages.d.ts.map +1 -1
- package/dist/next/pages.js +8 -6
- package/dist/next/pages.js.map +1 -1
- package/dist/next/route.d.ts +2 -1
- package/dist/next/route.d.ts.map +1 -1
- package/dist/next/route.js +6 -4
- package/dist/next/route.js.map +1 -1
- package/dist/options.d.ts +15 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +32 -1
- package/dist/options.js.map +1 -1
- package/dist/providers/resend.d.ts.map +1 -1
- package/dist/providers/resend.js +12 -6
- package/dist/providers/resend.js.map +1 -1
- package/dist/schema.d.ts +17 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -1
- package/dist/server/campaigns.d.ts +30 -4
- package/dist/server/campaigns.d.ts.map +1 -1
- package/dist/server/campaigns.js +67 -12
- package/dist/server/campaigns.js.map +1 -1
- package/dist/server/deliveries.d.ts +30 -2
- package/dist/server/deliveries.d.ts.map +1 -1
- package/dist/server/deliveries.js +58 -23
- package/dist/server/deliveries.js.map +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/send-mail.d.ts +3 -1
- package/dist/server/send-mail.d.ts.map +1 -1
- package/dist/server/send-mail.js +18 -6
- package/dist/server/send-mail.js.map +1 -1
- package/dist/server/suppressions.d.ts +8 -6
- package/dist/server/suppressions.d.ts.map +1 -1
- package/dist/server/suppressions.js +23 -7
- package/dist/server/suppressions.js.map +1 -1
- package/dist/server/unsubscribe-link.d.ts +23 -0
- package/dist/server/unsubscribe-link.d.ts.map +1 -1
- package/dist/server/unsubscribe-link.js +30 -1
- package/dist/server/unsubscribe-link.js.map +1 -1
- package/migrations/0003_add_delivery_provider_status.sql +13 -0
- package/module.json +1 -1
- package/package.json +1 -1
- package/src/cli/run.ts +61 -18
- package/src/contract.ts +49 -6
- package/src/index.ts +8 -3
- package/src/messages/en.ts +2 -0
- package/src/messages/pl.ts +2 -0
- package/src/next/actions.ts +5 -6
- package/src/next/pages.tsx +10 -7
- package/src/next/route.ts +6 -4
- package/src/options.ts +36 -2
- package/src/providers/resend.ts +11 -7
- package/src/schema.ts +2 -0
- package/src/server/campaigns.ts +95 -17
- package/src/server/deliveries.ts +89 -29
- package/src/server/index.ts +8 -0
- package/src/server/send-mail.ts +30 -6
- package/src/server/suppressions.ts +23 -8
- package/src/server/unsubscribe-link.ts +41 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,mGAAmG;AACnG,mGAAmG;AACnG,mGAAmG;AACnG,gDAAgD;AAChD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAA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AS,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAuB,MAAM,aAAa,CAAC"}
|
package/dist/messages/en.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Bd,CAAC"}
|
package/dist/messages/en.js
CHANGED
|
@@ -5,6 +5,8 @@ export const en = {
|
|
|
5
5
|
rejected: "The mail service refused this message.",
|
|
6
6
|
unavailable: "The mail service is not answering. Try again in a moment.",
|
|
7
7
|
suppressed: "This address unsubscribed from these emails, so nothing was sent.",
|
|
8
|
+
provider_refused: "The mail service refused our account, so nothing was sent. We need to fix it on our side.",
|
|
9
|
+
quota_exceeded: "We reached our sending limit for now. Try again later.",
|
|
8
10
|
},
|
|
9
11
|
},
|
|
10
12
|
footer: {
|
package/dist/messages/en.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,MAAM,EAAE;QACN,OAAO,EAAE;YACP,aAAa,EAAE,+DAA+D;YAC9E,QAAQ,EAAE,wCAAwC;YAClD,WAAW,EAAE,2DAA2D;YACxE,UAAU,EAAE,mEAAmE;
|
|
1
|
+
{"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,MAAM,EAAE;QACN,OAAO,EAAE;YACP,aAAa,EAAE,+DAA+D;YAC9E,QAAQ,EAAE,wCAAwC;YAClD,WAAW,EAAE,2DAA2D;YACxE,UAAU,EAAE,mEAAmE;YAC/E,gBAAgB,EAAE,2FAA2F;YAC7G,cAAc,EAAE,wDAAwD;SACzE;KACF;IACD,MAAM,EAAE;QACN,IAAI,EAAE,4CAA4C;QAClD,QAAQ,EAAE,0BAA0B;QACpC,QAAQ,EAAE,aAAa;KACxB;IACD,WAAW,EAAE;QACX,KAAK,EAAE,aAAa;QACpB,IAAI,EAAE,8GAA8G;QACpH,MAAM,EAAE,gBAAgB;QACxB,SAAS,EAAE,sBAAsB;QACjC,QAAQ,EAAE,6CAA6C;QACvD,YAAY,EAAE,yBAAyB;QACvC,WAAW,EAAE,gHAAgH;QAC7H,MAAM,EAAE,gDAAgD;KACzD;CACF,CAAC"}
|
package/dist/messages/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare const mailingMessages: {
|
|
|
9
9
|
rejected: string;
|
|
10
10
|
unavailable: string;
|
|
11
11
|
suppressed: string;
|
|
12
|
+
provider_refused: string;
|
|
13
|
+
quota_exceeded: string;
|
|
12
14
|
};
|
|
13
15
|
};
|
|
14
16
|
footer: {
|
|
@@ -34,6 +36,8 @@ export declare const mailingMessages: {
|
|
|
34
36
|
rejected: string;
|
|
35
37
|
unavailable: string;
|
|
36
38
|
suppressed: string;
|
|
39
|
+
provider_refused: string;
|
|
40
|
+
quota_exceeded: string;
|
|
37
41
|
};
|
|
38
42
|
};
|
|
39
43
|
footer: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAG7B,6EAA6E;AAC7E,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAG7B,6EAA6E;AAC7E,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAa,CAAC;AAE1C,MAAM,MAAM,eAAe,GAAG,OAAO,EAAE,CAAC;AAExC,qGAAqG;AACrG,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAIhG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl.d.ts","sourceRoot":"","sources":["../../src/messages/pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAGlC,eAAO,MAAM,EAAE,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"pl.d.ts","sourceRoot":"","sources":["../../src/messages/pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAGlC,eAAO,MAAM,EAAE,EAAE,OAAO,EA0BvB,CAAC"}
|
package/dist/messages/pl.js
CHANGED
|
@@ -6,6 +6,8 @@ export const pl = {
|
|
|
6
6
|
rejected: "Usługa pocztowa odrzuciła tę wiadomość.",
|
|
7
7
|
unavailable: "Usługa pocztowa nie odpowiada. Spróbuj ponownie za chwilę.",
|
|
8
8
|
suppressed: "Ten adres wypisał się z takich wiadomości, więc nic nie wysłano.",
|
|
9
|
+
provider_refused: "Usługa pocztowa odrzuciła nasze konto, więc nic nie wysłano. Musimy to naprawić po naszej stronie.",
|
|
10
|
+
quota_exceeded: "Wyczerpaliśmy na razie limit wysyłki. Spróbuj ponownie później.",
|
|
9
11
|
},
|
|
10
12
|
},
|
|
11
13
|
footer: {
|
package/dist/messages/pl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pl.js","sourceRoot":"","sources":["../../src/messages/pl.ts"],"names":[],"mappings":"AAEA,iGAAiG;AACjG,MAAM,CAAC,MAAM,EAAE,GAAc;IAC3B,MAAM,EAAE;QACN,OAAO,EAAE;YACP,aAAa,EAAE,qEAAqE;YACpF,QAAQ,EAAE,yCAAyC;YACnD,WAAW,EAAE,4DAA4D;YACzE,UAAU,EAAE,kEAAkE;
|
|
1
|
+
{"version":3,"file":"pl.js","sourceRoot":"","sources":["../../src/messages/pl.ts"],"names":[],"mappings":"AAEA,iGAAiG;AACjG,MAAM,CAAC,MAAM,EAAE,GAAc;IAC3B,MAAM,EAAE;QACN,OAAO,EAAE;YACP,aAAa,EAAE,qEAAqE;YACpF,QAAQ,EAAE,yCAAyC;YACnD,WAAW,EAAE,4DAA4D;YACzE,UAAU,EAAE,kEAAkE;YAC9E,gBAAgB,EAAE,oGAAoG;YACtH,cAAc,EAAE,iEAAiE;SAClF;KACF;IACD,MAAM,EAAE;QACN,IAAI,EAAE,wDAAwD;QAC9D,QAAQ,EAAE,sCAAsC;QAChD,QAAQ,EAAE,YAAY;KACvB;IACD,WAAW,EAAE;QACX,KAAK,EAAE,WAAW;QAClB,IAAI,EAAE,0HAA0H;QAChI,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,uCAAuC;QACjD,YAAY,EAAE,yBAAyB;QACvC,WAAW,EAAE,wHAAwH;QACrI,MAAM,EAAE,yDAAyD;KAClE;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/next/actions.ts"],"names":[],"mappings":"AAeA,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/next/actions.ts"],"names":[],"mappings":"AAeA,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBzE"}
|
package/dist/next/actions.js
CHANGED
|
@@ -8,15 +8,15 @@ import { getSoftureConfig } from "@softure-ai/core/next";
|
|
|
8
8
|
import { redirect } from "next/navigation";
|
|
9
9
|
import { getMailingRoutes } from "../server/options.js";
|
|
10
10
|
import { unsubscribe } from "../server/suppressions.js";
|
|
11
|
-
import {
|
|
11
|
+
import { getUnsubscribeLinkParams, readUnsubscribeLink } from "../server/unsubscribe-link.js";
|
|
12
12
|
import { getMailingContext } from "./context.js";
|
|
13
13
|
import { UNSUBSCRIBE_STATUS_PARAM } from "./params.js";
|
|
14
14
|
export async function unsubscribeAction(formData) {
|
|
15
15
|
const config = getSoftureConfig();
|
|
16
|
-
const
|
|
16
|
+
const link = readUnsubscribeLink(formData, config);
|
|
17
17
|
let status;
|
|
18
18
|
try {
|
|
19
|
-
const result = await unsubscribe(await getMailingContext(config),
|
|
19
|
+
const result = await unsubscribe(await getMailingContext(config), link, "page");
|
|
20
20
|
status = result.ok ? "done" : "invalid";
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
@@ -25,10 +25,10 @@ export async function unsubscribeAction(formData) {
|
|
|
25
25
|
status = "failed";
|
|
26
26
|
}
|
|
27
27
|
const query = new URLSearchParams({ [UNSUBSCRIBE_STATUS_PARAM]: status });
|
|
28
|
-
if (status === "failed" &&
|
|
28
|
+
if (status === "failed" && link !== null) {
|
|
29
29
|
// The form comes back with the same link, so the person can try again.
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
for (const [name, value] of Object.entries(getUnsubscribeLinkParams(link)))
|
|
31
|
+
query.set(name, value);
|
|
32
32
|
}
|
|
33
33
|
redirect(`${getMailingRoutes(config).unsubscribe}?${query.toString()}`);
|
|
34
34
|
}
|
package/dist/next/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/next/actions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,gGAAgG;AAChG,mGAAmG;AAC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,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yFAAyF;QACzF,OAAO,CAAC,KAAK,CAAC,4CAA4C,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClF,MAAM,GAAG,QAAQ,CAAC;IACpB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,EAAE,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1E,IAAI,MAAM,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACzC,uEAAuE;QACvE,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;YAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrG,CAAC;IACD,QAAQ,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
package/dist/next/pages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":"AAeA,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;CACtC;AAyBD,wBAAsB,eAAe,CAAC,EAAE,YAAY,EAAE,EAAE,oBAAoB,wCA2B3E"}
|
package/dist/next/pages.js
CHANGED
|
@@ -3,10 +3,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
// `export { UnsubscribePage as default } from "@softure-ai/mailing/next"`.
|
|
4
4
|
// A server component without client JavaScript: the button is a plain form posting a server
|
|
5
5
|
// action, so it works in any browser a mail client opens. Opening the page changes nothing (mail
|
|
6
|
-
// scanners open links too) and does not check the signature: the submit does.
|
|
6
|
+
// scanners open links too) and does not check the signature: the submit does. It takes the
|
|
7
|
+
// module's signed links and, with `mailing({ legacyUnsubscribe })`, the app's older ones: mount it
|
|
8
|
+
// at the old links' path too.
|
|
7
9
|
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
8
10
|
import { Button, Card, FormError } from "@softure-ai/ui";
|
|
9
|
-
import {
|
|
11
|
+
import { getUnsubscribeLinkParams, readUnsubscribeLink } from "../server/unsubscribe-link.js";
|
|
10
12
|
import { unsubscribeAction } from "./actions.js";
|
|
11
13
|
import { getMailingMessages } from "./messages.js";
|
|
12
14
|
import { UNSUBSCRIBE_STATUS_PARAM } from "./params.js";
|
|
@@ -30,11 +32,11 @@ export async function UnsubscribePage({ searchParams }) {
|
|
|
30
32
|
const status = readParam(params, UNSUBSCRIBE_STATUS_PARAM);
|
|
31
33
|
if (status === "done")
|
|
32
34
|
return _jsx(UnsubscribeLayout, { title: messages.doneTitle, lead: messages.doneBody });
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
if (status === "invalid" ||
|
|
35
|
+
const link = readUnsubscribeLink({ get: (name) => readParam(params, name) ?? null }, config);
|
|
36
|
+
const linkParams = link === null ? {} : getUnsubscribeLinkParams(link);
|
|
37
|
+
if (status === "invalid" || link === null || Object.values(linkParams).some((value) => value === "")) {
|
|
36
38
|
return _jsx(UnsubscribeLayout, { title: messages.invalidTitle, lead: messages.invalidBody });
|
|
37
39
|
}
|
|
38
|
-
return (_jsx(UnsubscribeLayout, { title: messages.title, lead: messages.lead, children: _jsxs("form", { action: unsubscribeAction, className: FORM_CLASS, children: [
|
|
40
|
+
return (_jsx(UnsubscribeLayout, { title: messages.title, lead: messages.lead, children: _jsxs("form", { action: unsubscribeAction, className: FORM_CLASS, children: [Object.entries(linkParams).map(([name, value]) => (_jsx("input", { type: "hidden", name: name, value: value }, name))), _jsx(FormError, { message: status === "failed" ? messages.failed : undefined }), _jsx("div", { children: _jsx(Button, { type: "submit", variant: "primary", children: messages.submit }) })] }) }));
|
|
39
41
|
}
|
|
40
42
|
//# sourceMappingURL=pages.js.map
|
package/dist/next/pages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,2EAA2E;AAC3E,4FAA4F;AAC5F,iGAAiG;AACjG,
|
|
1
|
+
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,2EAA2E;AAC3E,4FAA4F;AAC5F,iGAAiG;AACjG,2FAA2F;AAC3F,mGAAmG;AACnG,8BAA8B;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAQvD,MAAM,YAAY,GAAG,yEAAyE,CAAC;AAC/F,MAAM,UAAU,GAAG,+CAA+C,CAAC;AAEnE,SAAS,SAAS,CAAC,MAAqD,EAAE,IAAY;IACpF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC,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AC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,EAAE,CAAC;QACrG,OAAO,KAAC,iBAAiB,IAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,EAAE,QAAQ,CAAC,WAAW,GAAI,CAAC;IACzF,CAAC;IACD,OAAO,CACL,KAAC,iBAAiB,IAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,YAC3D,gBAAM,MAAM,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,aACnD,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CACjD,gBAAkB,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IAA5C,IAAI,CAA4C,CAC7D,CAAC,EACF,KAAC,SAAS,IAAC,OAAO,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,GAAI,EACzE,wBACE,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAC,SAAS,YACpC,QAAQ,CAAC,MAAM,GACT,GACL,IACD,GACW,CACrB,CAAC;AACJ,CAAC"}
|
package/dist/next/route.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Records the opt-out of the link in the URL. The body (`List-Unsubscribe=One-Click`) is not read:
|
|
3
3
|
* anyone can send it, the signature is the proof. 200 once recorded (also again), 400 for a link
|
|
4
4
|
* that does not verify, 500 when the database fails: the client may retry, and 200 would claim an
|
|
5
|
-
* opt-out that did not happen.
|
|
5
|
+
* opt-out that did not happen. A legacy link (`mailing({ legacyUnsubscribe })`) is handled the same
|
|
6
|
+
* way; mount this route at the old link's path too.
|
|
6
7
|
*/
|
|
7
8
|
export declare function postUnsubscribeRoute(request: Request): Promise<Response>;
|
|
8
9
|
/**
|
package/dist/next/route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAmBA
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAmBA;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAU9E;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAG9D"}
|
package/dist/next/route.js
CHANGED
|
@@ -12,19 +12,21 @@ import { errorLogLabel } from "@softure-ai/core";
|
|
|
12
12
|
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
13
13
|
import { getMailingRoutes } from "../server/options.js";
|
|
14
14
|
import { unsubscribe } from "../server/suppressions.js";
|
|
15
|
-
import {
|
|
15
|
+
import { readUnsubscribeLink } from "../server/unsubscribe-link.js";
|
|
16
16
|
import { getMailingContext } from "./context.js";
|
|
17
17
|
const NO_STORE = { "cache-control": "no-store" };
|
|
18
18
|
/**
|
|
19
19
|
* Records the opt-out of the link in the URL. The body (`List-Unsubscribe=One-Click`) is not read:
|
|
20
20
|
* anyone can send it, the signature is the proof. 200 once recorded (also again), 400 for a link
|
|
21
21
|
* that does not verify, 500 when the database fails: the client may retry, and 200 would claim an
|
|
22
|
-
* opt-out that did not happen.
|
|
22
|
+
* opt-out that did not happen. A legacy link (`mailing({ legacyUnsubscribe })`) is handled the same
|
|
23
|
+
* way; mount this route at the old link's path too.
|
|
23
24
|
*/
|
|
24
25
|
export async function postUnsubscribeRoute(request) {
|
|
25
|
-
const token = readUnsubscribeToken(new URL(request.url).searchParams);
|
|
26
26
|
try {
|
|
27
|
-
const
|
|
27
|
+
const ctx = await getMailingContext();
|
|
28
|
+
const link = readUnsubscribeLink(new URL(request.url).searchParams, ctx.config);
|
|
29
|
+
const result = await unsubscribe(ctx, link, "one-click");
|
|
28
30
|
return new Response(null, { status: result.ok ? 200 : 400, headers: NO_STORE });
|
|
29
31
|
}
|
|
30
32
|
catch (error) {
|
package/dist/next/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,wCAAwC;AACxC,yGAAyG;AACzG,EAAE;AACF,6FAA6F;AAC7F,gGAAgG;AAChG,0FAA0F;AAC1F,8FAA8F;AAC9F,+FAA+F;AAC/F,0CAA0C;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,wCAAwC;AACxC,yGAAyG;AACzG,EAAE;AACF,6FAA6F;AAC7F,gGAAgG;AAChG,0FAA0F;AAC1F,8FAA8F;AAC9F,+FAA+F;AAC/F,0CAA0C;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,QAAQ,GAA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
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { MailProvider, OnUnsubscribedHook } from "./contract.js";
|
|
2
|
+
import type { CampaignRecipientFilter, MailProvider, OnUnsubscribedHook } from "./contract.js";
|
|
3
3
|
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
4
|
+
/** How long a delivery claim may stay open before another sender may take it over (and send again, same key). */
|
|
5
|
+
export declare const DEFAULT_STALE_CLAIM_MS: number;
|
|
6
|
+
/**
|
|
7
|
+
* How old a claim may get before it is "uncertain" and never taken over by itself: its send may have gone out, and
|
|
8
|
+
* the provider may have forgotten the idempotency key (Resend keeps one for 24 hours), so a retake could mail twice.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_UNCERTAIN_CLAIM_MS: number;
|
|
4
11
|
export declare const mailingOptionsSchema: z.ZodObject<{
|
|
5
12
|
from: z.ZodString;
|
|
6
13
|
replyTo: z.ZodOptional<z.ZodString>;
|
|
7
14
|
provider: z.ZodCustom<MailProvider, MailProvider>;
|
|
8
15
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
9
16
|
onUnsubscribed: z.ZodOptional<z.ZodCustom<OnUnsubscribedHook, OnUnsubscribedHook>>;
|
|
17
|
+
legacyUnsubscribe: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
params: z.ZodArray<z.ZodString>;
|
|
19
|
+
verify: z.ZodCustom<(values: Readonly<Record<string, string>>, ctx: import("@softure-ai/core").ModuleContext<import("@softure-ai/db").Queryable>) => Promise<string | null>, (values: Readonly<Record<string, string>>, ctx: import("@softure-ai/core").ModuleContext<import("@softure-ai/db").Queryable>) => Promise<string | null>>;
|
|
20
|
+
}, z.core.$strict>>;
|
|
21
|
+
filterCampaignRecipient: z.ZodOptional<z.ZodCustom<CampaignRecipientFilter, CampaignRecipientFilter>>;
|
|
22
|
+
staleClaimMs: z.ZodDefault<z.ZodNumber>;
|
|
23
|
+
uncertainClaimMs: z.ZodDefault<z.ZodNumber>;
|
|
10
24
|
}, z.core.$strict>;
|
|
11
25
|
export type MailingOptionsInput = z.input<typeof mailingOptionsSchema>;
|
|
12
26
|
export type MailingOptions = z.output<typeof mailingOptionsSchema>;
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,uBAAuB,EAAqB,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAElH,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,iHAAiH;AACjH,eAAO,MAAM,sBAAsB,QAAc,CAAC;AAClD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAmB,CAAC;AAwB3D,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;kBA4BiH,CAAC;AAEnJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/dist/options.js
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { isMailbox, isSingleAddress } from "./address.js";
|
|
4
4
|
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
5
|
+
/** How long a delivery claim may stay open before another sender may take it over (and send again, same key). */
|
|
6
|
+
export const DEFAULT_STALE_CLAIM_MS = 15 * 60_000;
|
|
7
|
+
/**
|
|
8
|
+
* How old a claim may get before it is "uncertain" and never taken over by itself: its send may have gone out, and
|
|
9
|
+
* the provider may have forgotten the idempotency key (Resend keeps one for 24 hours), so a retake could mail twice.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_UNCERTAIN_CLAIM_MS = 23 * 60 * 60_000;
|
|
12
|
+
/** Query names the signed link and the page use; a legacy link cannot claim them. */
|
|
13
|
+
const RESERVED_LINK_PARAMS = new Set(["r", "status"]);
|
|
14
|
+
const LINK_PARAM = /^[A-Za-z][A-Za-z0-9_-]{0,31}$/;
|
|
15
|
+
const legacyUnsubscribeSchema = z.strictObject({
|
|
16
|
+
params: z
|
|
17
|
+
.array(z.string().regex(LINK_PARAM, "must be a query name: a letter, then letters, digits, _ or -, at most 32 characters"))
|
|
18
|
+
.min(1)
|
|
19
|
+
.max(8)
|
|
20
|
+
.refine((params) => new Set(params).size === params.length, "must not repeat a name")
|
|
21
|
+
.refine((params) => params.every((param) => !RESERVED_LINK_PARAMS.has(param)), "must not use r or status: the signed link and the page own them"),
|
|
22
|
+
verify: z.custom((value) => typeof value === "function", "must be a function"),
|
|
23
|
+
});
|
|
24
|
+
const HOUR_MS = 60 * 60_000;
|
|
5
25
|
function isMailProvider(value) {
|
|
6
26
|
if (typeof value !== "object" || value === null)
|
|
7
27
|
return false;
|
|
@@ -25,5 +45,16 @@ export const mailingOptionsSchema = z.strictObject({
|
|
|
25
45
|
* `@softure-ai/waitlist/server`, which records the withdrawal in privacy's consent ledger.
|
|
26
46
|
*/
|
|
27
47
|
onUnsubscribed: z.custom((value) => typeof value === "function", "must be a function").optional(),
|
|
28
|
-
|
|
48
|
+
/** Verifies unsubscribe links the app sent before it adopted the module (see `LegacyUnsubscribe`). */
|
|
49
|
+
legacyUnsubscribe: legacyUnsubscribeSchema.optional(),
|
|
50
|
+
/** Decides per recipient whether a campaign goes to them, e.g. by consent scope (see `CampaignRecipientFilter`). */
|
|
51
|
+
filterCampaignRecipient: z.custom((value) => typeof value === "function", "must be a function").optional(),
|
|
52
|
+
/** How long a delivery claim may stay open before another sender takes it over. 1 minute to 23 hours. */
|
|
53
|
+
staleClaimMs: z.number().int().min(60_000).max(23 * HOUR_MS).default(DEFAULT_STALE_CLAIM_MS),
|
|
54
|
+
/**
|
|
55
|
+
* How old a claim may get before it is never taken over by itself (`uncertain`); keep it under the provider's
|
|
56
|
+
* idempotency window. More than `staleClaimMs`, at most 30 days.
|
|
57
|
+
*/
|
|
58
|
+
uncertainClaimMs: z.number().int().min(60_000).max(30 * 24 * HOUR_MS).default(DEFAULT_UNCERTAIN_CLAIM_MS),
|
|
59
|
+
}).refine((options) => options.uncertainClaimMs > options.staleClaimMs, { message: "must be more than staleClaimMs", path: ["uncertainClaimMs"] });
|
|
29
60
|
//# sourceMappingURL=options.js.map
|
package/dist/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,iHAAiH;AACjH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,MAAM,CAAC;AAClD;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;AAE3D,qFAAqF;AACrF,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,QAAQ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O,CAAC,gBAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,gCAAgC,EAAE,IAAI,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resend.d.ts","sourceRoot":"","sources":["../../src/providers/resend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,gBAAgB,CAAC;AAErF,eAAO,MAAM,eAAe,kCAAkC,CAAC;AAC/D,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B;
|
|
1
|
+
{"version":3,"file":"resend.d.ts","sourceRoot":"","sources":["../../src/providers/resend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,gBAAgB,CAAC;AAErF,eAAO,MAAM,eAAe,kCAAkC,CAAC;AAC/D,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B;AAWD,uCAAuC;AACvC,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,YAAY,CA0BhE"}
|
package/dist/providers/resend.js
CHANGED
|
@@ -2,8 +2,10 @@ export const RESEND_ENDPOINT = "https://api.resend.com/emails";
|
|
|
2
2
|
export const RESEND_API_KEY_ENV = "RESEND_API_KEY";
|
|
3
3
|
/** Resend's name for an idempotency key that another request is still using: retry later. */
|
|
4
4
|
const CONCURRENT_IDEMPOTENT_REQUESTS = "concurrent_idempotent_requests";
|
|
5
|
-
/**
|
|
6
|
-
const
|
|
5
|
+
/** Resend's name for a 429 that is a per-second rate limit; any other 429 is a spent daily or monthly quota. */
|
|
6
|
+
const RATE_LIMIT_EXCEEDED = "rate_limit_exceeded";
|
|
7
|
+
/** Statuses that refuse the sender (missing, invalid or restricted key, account not allowed to send). */
|
|
8
|
+
const REFUSED_STATUSES = new Set([401, 403]);
|
|
7
9
|
/** Sends through Resend's HTTP API. */
|
|
8
10
|
export function resend(options = {}) {
|
|
9
11
|
const endpoint = options.endpoint ?? RESEND_ENDPOINT;
|
|
@@ -50,10 +52,14 @@ async function readOutcome(response) {
|
|
|
50
52
|
return id === null ? { status: "unavailable", httpStatus: response.status } : { status: "sent", id };
|
|
51
53
|
}
|
|
52
54
|
// Only the error's `name` (an enum) is read: its `message` can echo the address back.
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const name = readString(payload, "name");
|
|
56
|
+
const httpStatus = response.status;
|
|
57
|
+
if (REFUSED_STATUSES.has(httpStatus))
|
|
58
|
+
return { status: "refused", httpStatus };
|
|
59
|
+
if (httpStatus === 429)
|
|
60
|
+
return { status: name === RATE_LIMIT_EXCEEDED ? "unavailable" : "quota_exceeded", httpStatus };
|
|
61
|
+
const isRetryable = httpStatus >= 500 || httpStatus === 408 || (httpStatus === 409 && name === CONCURRENT_IDEMPOTENT_REQUESTS);
|
|
62
|
+
return { status: isRetryable ? "unavailable" : "rejected", httpStatus };
|
|
57
63
|
}
|
|
58
64
|
function readString(payload, key) {
|
|
59
65
|
if (typeof payload !== "object" || payload === null || !Object.hasOwn(payload, key))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resend.js","sourceRoot":"","sources":["../../src/providers/resend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AAM,KAAK,GAAa,OAAmC,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -325,6 +325,23 @@ export declare const deliveries: import("drizzle-orm/pg-core").PgTableWithColumn
|
|
|
325
325
|
identity: undefined;
|
|
326
326
|
generated: undefined;
|
|
327
327
|
}, {}, {}>;
|
|
328
|
+
providerStatus: import("drizzle-orm/pg-core").PgColumn<{
|
|
329
|
+
name: "provider_status";
|
|
330
|
+
tableName: "deliveries";
|
|
331
|
+
dataType: "number";
|
|
332
|
+
columnType: "PgInteger";
|
|
333
|
+
data: number;
|
|
334
|
+
driverParam: string | number;
|
|
335
|
+
notNull: false;
|
|
336
|
+
hasDefault: false;
|
|
337
|
+
isPrimaryKey: false;
|
|
338
|
+
isAutoincrement: false;
|
|
339
|
+
hasRuntimeDefault: false;
|
|
340
|
+
enumValues: undefined;
|
|
341
|
+
baseColumn: never;
|
|
342
|
+
identity: undefined;
|
|
343
|
+
generated: undefined;
|
|
344
|
+
}, {}, {}>;
|
|
328
345
|
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
329
346
|
name: "created_at";
|
|
330
347
|
tableName: "deliveries";
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,mDAAsB,CAAC;AAEjD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIvB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMpB,CAAC;AAEH,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,mDAAsB,CAAC;AAEjD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIvB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMpB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBtB,CAAC;AAEF,yGAAyG;AACzG,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -25,6 +25,8 @@ export const deliveries = mailingSchema.table("deliveries", {
|
|
|
25
25
|
finishedAt: timestamp("finished_at", { withTimezone: true }),
|
|
26
26
|
providerMessageId: text("provider_message_id"),
|
|
27
27
|
reason: text("reason"),
|
|
28
|
+
/** The provider's HTTP status of the last answer that failed or was released; null when there was none. */
|
|
29
|
+
providerStatus: integer("provider_status"),
|
|
28
30
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
29
31
|
}, (table) => [primaryKey({ columns: [table.scope, table.recipientKey] })]);
|
|
30
32
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1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AQ,CAAC;IACtB,2GAA2G;IAC3G,cAAc,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAC1C,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;CACrE,EACD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CACxE,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type Result } from "@softure-ai/core";
|
|
2
2
|
import type { MailingErrorCode } from "../contract.js";
|
|
3
3
|
import { type CampaignContent } from "./campaign-file.js";
|
|
4
|
-
import { type DeliverOptions, type DeliveryContext, type DeliveryOutcome } from "./deliveries.js";
|
|
4
|
+
import { type DeliverOptions, type DeliveryContext, type DeliveryOutcome, type HaltingErrorCode } from "./deliveries.js";
|
|
5
|
+
/** Why a run stopped before the end of the list. */
|
|
6
|
+
export interface CampaignHalt {
|
|
7
|
+
readonly reason: HaltingErrorCode;
|
|
8
|
+
readonly httpStatus?: number;
|
|
9
|
+
}
|
|
5
10
|
/** The campaign id is taken by other content. Give the new content a new id. */
|
|
6
11
|
export type CampaignErrorCode = "mailing.campaign_changed";
|
|
7
12
|
export interface CampaignSummary {
|
|
@@ -16,6 +21,15 @@ export interface CampaignSummary {
|
|
|
16
21
|
readonly inFlight: number;
|
|
17
22
|
/** The provider was unavailable; the next run tries them again. */
|
|
18
23
|
readonly retryLater: number;
|
|
24
|
+
/** Skipped by `filterCampaignRecipient`; nothing stored, so a later run sends to them once they qualify. */
|
|
25
|
+
readonly filtered: number;
|
|
26
|
+
/** Claimed more than `uncertainClaimMs` ago and never closed: their mail may have gone out. */
|
|
27
|
+
readonly uncertain: number;
|
|
28
|
+
/**
|
|
29
|
+
* Set when the run stopped at a failure about the sending account. The recipient it happened to and every one
|
|
30
|
+
* after it were left as they were; run again once the account can send.
|
|
31
|
+
*/
|
|
32
|
+
readonly halted: CampaignHalt | null;
|
|
19
33
|
}
|
|
20
34
|
export interface SendCampaignOptions extends DeliverOptions {
|
|
21
35
|
/** Pause after every mail that reached the provider, for its rate limit. Default 0. */
|
|
@@ -33,7 +47,9 @@ export declare function getCampaignContentHash(content: CampaignContent): string
|
|
|
33
47
|
export declare function registerCampaign(ctx: DeliveryContext, content: CampaignContent): Promise<Result<undefined, CampaignErrorCode>>;
|
|
34
48
|
/**
|
|
35
49
|
* Sends `campaign` to every recipient that has no outcome yet, one at a time. Recipients who
|
|
36
|
-
* unsubscribed are rejected (`mailing.suppressed`) and never retried
|
|
50
|
+
* unsubscribed are rejected (`mailing.suppressed`) and never retried; recipients the module's
|
|
51
|
+
* `filterCampaignRecipient` refuses are skipped. Stops at the first `halted` delivery. Throws on a
|
|
52
|
+
* database failure and when the filter throws.
|
|
37
53
|
*/
|
|
38
54
|
export declare function sendCampaign(ctx: DeliveryContext, input: {
|
|
39
55
|
readonly campaign: CampaignContent;
|
|
@@ -45,14 +61,24 @@ export interface CampaignPlan {
|
|
|
45
61
|
readonly done: number;
|
|
46
62
|
/** Not closed yet, but unsubscribed: they will be rejected without a send. */
|
|
47
63
|
readonly suppressed: number;
|
|
64
|
+
/** Not closed yet, but `filterCampaignRecipient` refuses them: they will be skipped. */
|
|
65
|
+
readonly filtered: number;
|
|
66
|
+
/**
|
|
67
|
+
* Claimed more than `uncertainClaimMs` ago and never closed: skipped unless the run retakes uncertain claims
|
|
68
|
+
* (then they are sent again and counted in `toSend` too).
|
|
69
|
+
*/
|
|
70
|
+
readonly uncertain: number;
|
|
48
71
|
/** Would be sent now. */
|
|
49
72
|
readonly toSend: number;
|
|
50
73
|
/** The campaign id is stored with other content: a real run would be refused. */
|
|
51
74
|
readonly contentChanged: boolean;
|
|
52
75
|
}
|
|
53
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* What `sendCampaign` would do, without writing or sending anything (the filter runs, and must not write). Throws
|
|
78
|
+
* on a database failure. `toSend` counts uncertain recipients only with `retakeUncertain`.
|
|
79
|
+
*/
|
|
54
80
|
export declare function planCampaign(ctx: DeliveryContext, input: {
|
|
55
81
|
readonly campaign: CampaignContent;
|
|
56
82
|
readonly recipients: Iterable<string> | AsyncIterable<string>;
|
|
57
|
-
}): Promise<CampaignPlan>;
|
|
83
|
+
}, options?: Pick<DeliverOptions, "uncertainClaimMs" | "retakeUncertain">): Promise<CampaignPlan>;
|
|
58
84
|
//# sourceMappingURL=campaigns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaigns.d.ts","sourceRoot":"","sources":["../../src/server/campaigns.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"campaigns.d.ts","sourceRoot":"","sources":["../../src/server/campaigns.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,KAAK,EAAqB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE1E,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAe,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAQtI,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,gFAAgF;AAChF,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC9B,iGAAiG;IACjG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mGAAmG;IACnG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB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