@growth-labs/mailer 0.1.3 → 0.2.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/README.md +2 -4
- package/dist/options.d.ts +1 -65
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +1 -9
- package/dist/options.js.map +1 -1
- package/dist/queue/consumer.d.ts.map +1 -1
- package/dist/queue/consumer.js +1 -15
- package/dist/queue/consumer.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/providers.d.ts +0 -10
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/providers.js +0 -56
- package/dist/utils/providers.js.map +1 -1
- package/package.json +80 -84
- package/src/options.ts +51 -60
- package/src/queue/consumer.ts +1 -18
- package/src/utils/index.ts +0 -2
- package/src/utils/providers.ts +0 -67
- package/src/virtual.d.ts +0 -2
package/README.md
CHANGED
|
@@ -29,8 +29,6 @@ mailer({
|
|
|
29
29
|
accentColor: '#e53e3e',
|
|
30
30
|
footerText: '© FEDweek. All rights reserved.',
|
|
31
31
|
},
|
|
32
|
-
fallbackProvider: 'resend', // 'resend' | 'none'
|
|
33
|
-
resendApiKey: '...', // Via Cloudflare Secrets
|
|
34
32
|
analyticsEnabled: true, // Emit email events to @growth-labs/analytics
|
|
35
33
|
})
|
|
36
34
|
```
|
|
@@ -74,7 +72,7 @@ max_batch_size = 10
|
|
|
74
72
|
## Email Sending Flow
|
|
75
73
|
|
|
76
74
|
1. Consumer calls `sendTransactional()`, `sendCampaign()`, or `sendDigest()` → message enqueued
|
|
77
|
-
2. Queue consumer dequeues → sends via Cloudflare Email
|
|
75
|
+
2. Queue consumer dequeues → sends via the Cloudflare Email Sending binding
|
|
78
76
|
3. Status updated in `gl_email_sends`: queued → sent → delivered/bounced
|
|
79
77
|
4. Open/click tracking updates status further
|
|
80
78
|
|
|
@@ -84,6 +82,6 @@ max_batch_size = 10
|
|
|
84
82
|
- Status never downgrades (sent → delivered → opened → clicked)
|
|
85
83
|
- List-Unsubscribe header on every email (RFC 8058)
|
|
86
84
|
- Turnstile on subscribe endpoint (+ IP rate limiting as backup)
|
|
87
|
-
-
|
|
85
|
+
- Cloudflare Email Sending is the only outbound provider
|
|
88
86
|
- WAE events via `@growth-labs/analytics` writeDataPoint() — fire-and-forget, non-blocking
|
|
89
87
|
- `.astro` component files ship as source, not compiled
|
package/dist/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const mailerOptionsSchema: z.
|
|
2
|
+
export declare const mailerOptionsSchema: z.ZodObject<{
|
|
3
3
|
senderName: z.ZodString;
|
|
4
4
|
fromAddress: z.ZodString;
|
|
5
5
|
replyTo: z.ZodOptional<z.ZodString>;
|
|
@@ -34,8 +34,6 @@ export declare const mailerOptionsSchema: z.ZodEffects<z.ZodObject<{
|
|
|
34
34
|
accentColor?: string | undefined;
|
|
35
35
|
footerText?: string | undefined;
|
|
36
36
|
}>>;
|
|
37
|
-
fallbackProvider: z.ZodDefault<z.ZodEnum<["resend", "none"]>>;
|
|
38
|
-
resendApiKey: z.ZodOptional<z.ZodString>;
|
|
39
37
|
batchSize: z.ZodDefault<z.ZodNumber>;
|
|
40
38
|
analyticsEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
41
39
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -61,12 +59,10 @@ export declare const mailerOptionsSchema: z.ZodEffects<z.ZodObject<{
|
|
|
61
59
|
logoUrl?: string | undefined;
|
|
62
60
|
footerText?: string | undefined;
|
|
63
61
|
};
|
|
64
|
-
fallbackProvider: "resend" | "none";
|
|
65
62
|
batchSize: number;
|
|
66
63
|
analyticsEnabled: boolean;
|
|
67
64
|
replyTo?: string | undefined;
|
|
68
65
|
topics?: string[] | undefined;
|
|
69
|
-
resendApiKey?: string | undefined;
|
|
70
66
|
}, {
|
|
71
67
|
senderName: string;
|
|
72
68
|
fromAddress: string;
|
|
@@ -92,66 +88,6 @@ export declare const mailerOptionsSchema: z.ZodEffects<z.ZodObject<{
|
|
|
92
88
|
accentColor?: string | undefined;
|
|
93
89
|
footerText?: string | undefined;
|
|
94
90
|
} | undefined;
|
|
95
|
-
fallbackProvider?: "resend" | "none" | undefined;
|
|
96
|
-
resendApiKey?: string | undefined;
|
|
97
|
-
batchSize?: number | undefined;
|
|
98
|
-
analyticsEnabled?: boolean | undefined;
|
|
99
|
-
}>, {
|
|
100
|
-
senderName: string;
|
|
101
|
-
fromAddress: string;
|
|
102
|
-
d1Binding: string;
|
|
103
|
-
queueBinding: string;
|
|
104
|
-
turnstileSiteKey: string;
|
|
105
|
-
turnstileSecretKey: string;
|
|
106
|
-
doubleOptIn: boolean;
|
|
107
|
-
signingSecret: string;
|
|
108
|
-
subscribePath: string;
|
|
109
|
-
confirmPath: string;
|
|
110
|
-
unsubscribePath: string;
|
|
111
|
-
preferencesPath: string;
|
|
112
|
-
webhookPath: string;
|
|
113
|
-
trackOpenPath: string;
|
|
114
|
-
trackClickPath: string;
|
|
115
|
-
siteUrl: string;
|
|
116
|
-
brand: {
|
|
117
|
-
primaryColor: string;
|
|
118
|
-
accentColor: string;
|
|
119
|
-
logoUrl?: string | undefined;
|
|
120
|
-
footerText?: string | undefined;
|
|
121
|
-
};
|
|
122
|
-
fallbackProvider: "resend" | "none";
|
|
123
|
-
batchSize: number;
|
|
124
|
-
analyticsEnabled: boolean;
|
|
125
|
-
replyTo?: string | undefined;
|
|
126
|
-
topics?: string[] | undefined;
|
|
127
|
-
resendApiKey?: string | undefined;
|
|
128
|
-
}, {
|
|
129
|
-
senderName: string;
|
|
130
|
-
fromAddress: string;
|
|
131
|
-
turnstileSiteKey: string;
|
|
132
|
-
turnstileSecretKey: string;
|
|
133
|
-
signingSecret: string;
|
|
134
|
-
siteUrl: string;
|
|
135
|
-
replyTo?: string | undefined;
|
|
136
|
-
d1Binding?: string | undefined;
|
|
137
|
-
queueBinding?: string | undefined;
|
|
138
|
-
doubleOptIn?: boolean | undefined;
|
|
139
|
-
topics?: string[] | undefined;
|
|
140
|
-
subscribePath?: string | undefined;
|
|
141
|
-
confirmPath?: string | undefined;
|
|
142
|
-
unsubscribePath?: string | undefined;
|
|
143
|
-
preferencesPath?: string | undefined;
|
|
144
|
-
webhookPath?: string | undefined;
|
|
145
|
-
trackOpenPath?: string | undefined;
|
|
146
|
-
trackClickPath?: string | undefined;
|
|
147
|
-
brand?: {
|
|
148
|
-
logoUrl?: string | undefined;
|
|
149
|
-
primaryColor?: string | undefined;
|
|
150
|
-
accentColor?: string | undefined;
|
|
151
|
-
footerText?: string | undefined;
|
|
152
|
-
} | undefined;
|
|
153
|
-
fallbackProvider?: "resend" | "none" | undefined;
|
|
154
|
-
resendApiKey?: string | undefined;
|
|
155
91
|
batchSize?: number | undefined;
|
|
156
92
|
analyticsEnabled?: boolean | undefined;
|
|
157
93
|
}>;
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkD9B,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAC/D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
package/dist/options.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const mailerOptionsSchema = z
|
|
3
|
-
.object({
|
|
2
|
+
export const mailerOptionsSchema = z.object({
|
|
4
3
|
// ─── Required ───
|
|
5
4
|
senderName: z.string(),
|
|
6
5
|
fromAddress: z.string().email(),
|
|
@@ -36,16 +35,9 @@ export const mailerOptionsSchema = z
|
|
|
36
35
|
footerText: z.string().optional(),
|
|
37
36
|
})
|
|
38
37
|
.default({}),
|
|
39
|
-
// ─── Fallback provider ───
|
|
40
|
-
fallbackProvider: z.enum(['resend', 'none']).default('none'),
|
|
41
|
-
resendApiKey: z.string().optional(),
|
|
42
38
|
// ─── Queue batching ───
|
|
43
39
|
batchSize: z.number().min(1).max(500).default(100),
|
|
44
40
|
// ─── Optional peer: analytics ───
|
|
45
41
|
analyticsEnabled: z.boolean().default(false),
|
|
46
|
-
})
|
|
47
|
-
.refine((data) => data.fallbackProvider !== 'resend' || data.resendApiKey, {
|
|
48
|
-
message: 'resendApiKey is required when fallbackProvider is "resend"',
|
|
49
|
-
path: ['resendApiKey'],
|
|
50
42
|
});
|
|
51
43
|
//# 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,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,mBAAmB;IACnB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,WAAW,EAAE,CA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AAE,CAAC,GAAG,EAAE;IAEzB,4CAA4C;IAC5C,KAAK,EAAE,CAAC;SACN,MAAM,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;QACpC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;QAC3C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;QAC1C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACjC,CAAC;SACD,OAAO,CAAC,EAAE,CAAC;IAEb,yBAAyB;IACzB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAElD,mCAAmC;IACnC,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAC5C,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumer.d.ts","sourceRoot":"","sources":["../../src/queue/consumer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EAAiB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAGlE,wBAAsB,gBAAgB,CACrC,KAAK,EAAE,YAAY,CAAC,iBAAiB,CAAC,EACtC,GAAG,EAAE;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,YAAY,CAAC,EAAE,qBAAqB,CAAA;CAAE,EAC7D,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"consumer.d.ts","sourceRoot":"","sources":["../../src/queue/consumer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EAAiB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAGlE,wBAAsB,gBAAgB,CACrC,KAAK,EAAE,YAAY,CAAC,iBAAiB,CAAC,EACtC,GAAG,EAAE;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,YAAY,CAAC,EAAE,qBAAqB,CAAA;CAAE,EAC7D,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAsEf"}
|
package/dist/queue/consumer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/d1';
|
|
2
2
|
import { updateSendStatus } from '../utils/bounce.js';
|
|
3
|
-
import { CloudflareEmailProvider,
|
|
3
|
+
import { CloudflareEmailProvider, sleep } from '../utils/providers.js';
|
|
4
4
|
export async function handleEmailQueue(batch, env, options) {
|
|
5
5
|
const db = drizzle(env.DB);
|
|
6
6
|
const provider = env.EMAIL_SENDER
|
|
@@ -8,7 +8,6 @@ export async function handleEmailQueue(batch, env, options) {
|
|
|
8
8
|
: new CloudflareEmailProvider({
|
|
9
9
|
send: () => Promise.reject(new Error('No email sender configured')),
|
|
10
10
|
});
|
|
11
|
-
const fallback = getFallbackProvider(options);
|
|
12
11
|
for (const message of batch.messages) {
|
|
13
12
|
const { recipients, htmlTemplate, subject, from, replyTo, headers, type } = message.body;
|
|
14
13
|
for (const recipient of recipients) {
|
|
@@ -51,19 +50,6 @@ export async function handleEmailQueue(batch, env, options) {
|
|
|
51
50
|
break;
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
if (!result.success && fallback) {
|
|
55
|
-
result = await fallback.send({
|
|
56
|
-
to: recipient.email,
|
|
57
|
-
from,
|
|
58
|
-
replyTo,
|
|
59
|
-
subject,
|
|
60
|
-
html,
|
|
61
|
-
headers: recipientHeaders,
|
|
62
|
-
});
|
|
63
|
-
if (result.success) {
|
|
64
|
-
console.warn(`[mailer] Fallback provider used for ${recipient.email}: ${provider.name} → ${fallback.name}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
53
|
if (result.success) {
|
|
68
54
|
await updateSendStatus(db, recipient.trackingId, 'sent', {
|
|
69
55
|
sentAt: new Date().toISOString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumer.js","sourceRoot":"","sources":["../../src/queue/consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAGxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"consumer.js","sourceRoot":"","sources":["../../src/queue/consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAGxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAEtE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,KAAsC,EACtC,GAA6D,EAC7D,OAA8B;IAE9B,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC1B,MAAM,QAAQ,GAAkB,GAAG,CAAC,YAAY;QAC/C,CAAC,CAAC,IAAI,uBAAuB,CAAC,GAAG,CAAC,YAAY,CAAC;QAC/C,CAAC,CAAC,IAAI,uBAAuB,CAAC;YAC5B,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SACnE,CAAC,CAAA;IAEJ,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;Q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,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;oBAC/C,MAAM,KAAK,CAAC,CAAC,IAAI,OAAO,GAAG,IAAI,CAAC,CAAA;oBAChC,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC;wBAC5B,EAAE,EAAE,SAAS,CAAC,KAAK;wBACnB,IAAI;wBACJ,OAAO;wBACP,OAAO;wBACP,IAAI;wBACJ,OAAO,EAAE,gBAAgB;qBACzB,CAAC,CAAA;oBACF,IAAI,MAAM,CAAC,OAAO;wBAAE,MAAK;gBAC1B,CAAC;YACF,CAAC;YAED,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,gBAAgB,CAAC,EAAE,EAAE,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE;oBACxD,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBAChC,CAAC,CAAA;YACH,CAAC;iBAAM,CAAC;gBACP,MAAM,gBAAgB,CAAC,EAAE,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE;oBAC3D,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACnC,UAAU,EAAE,MAAM;iBAClB,CAAC,CAAA;gBACF,OAAO,CAAC,KAAK,CAAC,4BAA4B,SAAS,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;YAC9E,CAAC;QACF,CAAC;QAED,OAAO,CAAC,GAAG,EAAE,CAAA;IACd,CAAC;AACF,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { handleBounce, handleComplaint, handleDelivery, updateSendStatus, } from './bounce.js';
|
|
2
2
|
export type { CloudflareEmailSender } from './providers.js';
|
|
3
|
-
export { CloudflareEmailProvider,
|
|
3
|
+
export { CloudflareEmailProvider, getProvider, sleep, } from './providers.js';
|
|
4
4
|
export type { CampaignSchedule, DigestSchedule } from './scheduling.js';
|
|
5
5
|
export { executeCampaignSchedule, executeDigestSchedule, prepareCampaign, prepareDigest, sendBatchCampaigns, } from './scheduling.js';
|
|
6
6
|
export type { MailerEnv } from './send.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,GAChB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EACN,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,GAChB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EACN,uBAAuB,EACvB,WAAW,EACX,KAAK,GACL,MAAM,gBAAgB,CAAA;AACvB,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EACN,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,kBAAkB,GAClB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACvE,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACN,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GACX,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EACN,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GACf,MAAM,eAAe,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { handleBounce, handleComplaint, handleDelivery, updateSendStatus, } from './bounce.js';
|
|
2
|
-
export { CloudflareEmailProvider,
|
|
2
|
+
export { CloudflareEmailProvider, getProvider, sleep, } from './providers.js';
|
|
3
3
|
export { executeCampaignSchedule, executeDigestSchedule, prepareCampaign, prepareDigest, sendBatchCampaigns, } from './scheduling.js';
|
|
4
4
|
export { sendCampaign, sendDigest, sendTransactional } from './send.js';
|
|
5
5
|
export { confirmSubscriber, countSubscribers, createSubscriber, getSubscriberBatch, getSubscriberByEmail, getSubscriberById, unsubscribeSubscriber, updatePreferences, } from './subscribers.js';
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,GAChB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACN,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,GAChB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACN,uBAAuB,EACvB,WAAW,EACX,KAAK,GACL,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACN,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,kBAAkB,GAClB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACvE,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACN,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GACX,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EACN,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GACf,MAAM,eAAe,CAAA"}
|
|
@@ -16,16 +16,6 @@ export declare class CloudflareEmailProvider implements EmailProvider {
|
|
|
16
16
|
constructor(emailSender: CloudflareEmailSender);
|
|
17
17
|
send(email: OutboundEmail): Promise<SendResult>;
|
|
18
18
|
}
|
|
19
|
-
export declare class ResendFallbackProvider implements EmailProvider {
|
|
20
|
-
readonly name = "resend";
|
|
21
|
-
private readonly apiKey;
|
|
22
|
-
constructor(apiKey: string);
|
|
23
|
-
send(email: OutboundEmail): Promise<SendResult>;
|
|
24
|
-
}
|
|
25
19
|
export declare function getProvider(emailSender: CloudflareEmailSender): EmailProvider;
|
|
26
|
-
export declare function getFallbackProvider(options: {
|
|
27
|
-
fallbackProvider: string;
|
|
28
|
-
resendApiKey?: string;
|
|
29
|
-
}): EmailProvider | null;
|
|
30
20
|
export declare function sleep(ms: number): Promise<void>;
|
|
31
21
|
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/utils/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI3E,MAAM,WAAW,qBAAqB;IACrC,IAAI,CAAC,OAAO,EAAE;QACb,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAC1C,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjB;AAID,qBAAa,uBAAwB,YAAW,aAAa;IAC5D,QAAQ,CAAC,IAAI,gBAAe;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAElC,WAAW,EAAE,qBAAqB;IAIxC,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;CAqBrD;AAID,
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/utils/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI3E,MAAM,WAAW,qBAAqB;IACrC,IAAI,CAAC,OAAO,EAAE;QACb,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAC1C,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjB;AAID,qBAAa,uBAAwB,YAAW,aAAa;IAC5D,QAAQ,CAAC,IAAI,gBAAe;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAElC,WAAW,EAAE,qBAAqB;IAIxC,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;CAqBrD;AAID,wBAAgB,WAAW,CAAC,WAAW,EAAE,qBAAqB,GAAG,aAAa,CAE7E;AAID,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
package/dist/utils/providers.js
CHANGED
|
@@ -26,66 +26,10 @@ export class CloudflareEmailProvider {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
// ─── ResendFallbackProvider ───
|
|
30
|
-
export class ResendFallbackProvider {
|
|
31
|
-
name = 'resend';
|
|
32
|
-
apiKey;
|
|
33
|
-
constructor(apiKey) {
|
|
34
|
-
this.apiKey = apiKey;
|
|
35
|
-
}
|
|
36
|
-
async send(email) {
|
|
37
|
-
try {
|
|
38
|
-
const response = await fetch('https://api.resend.com/emails', {
|
|
39
|
-
method: 'POST',
|
|
40
|
-
headers: {
|
|
41
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
42
|
-
'Content-Type': 'application/json',
|
|
43
|
-
},
|
|
44
|
-
body: JSON.stringify({
|
|
45
|
-
to: email.to,
|
|
46
|
-
from: email.from,
|
|
47
|
-
reply_to: email.replyTo,
|
|
48
|
-
subject: email.subject,
|
|
49
|
-
html: email.html,
|
|
50
|
-
headers: email.headers,
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
if (response.ok) {
|
|
54
|
-
const data = (await response.json());
|
|
55
|
-
return {
|
|
56
|
-
success: true,
|
|
57
|
-
messageId: data.id,
|
|
58
|
-
retryable: false,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const retryable = response.status === 429 || response.status >= 500;
|
|
62
|
-
const errorText = await response.text().catch(() => 'Unknown error');
|
|
63
|
-
return {
|
|
64
|
-
success: false,
|
|
65
|
-
error: `Resend API ${response.status}: ${errorText}`,
|
|
66
|
-
retryable,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
error: message,
|
|
74
|
-
retryable: true,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
29
|
// ─── Factory functions ───
|
|
80
30
|
export function getProvider(emailSender) {
|
|
81
31
|
return new CloudflareEmailProvider(emailSender);
|
|
82
32
|
}
|
|
83
|
-
export function getFallbackProvider(options) {
|
|
84
|
-
if (options.fallbackProvider === 'resend' && options.resendApiKey) {
|
|
85
|
-
return new ResendFallbackProvider(options.resendApiKey);
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
33
|
// ─── Helpers ───
|
|
90
34
|
export function sleep(ms) {
|
|
91
35
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/utils/providers.ts"],"names":[],"mappings":"AAaA,kCAAkC;AAElC,MAAM,OAAO,uBAAuB;IAC1B,IAAI,GAAG,YAAY,CAAA;IACX,MAAM,CAAuB;IAE9C,YAAY,WAAkC;QAC7C,IAAI,CAAC,MAAM,GAAG,WAAW,CAAA;IAC1B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAoB;QAC9B,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACtB,EAAE,EAAE,KAAK,CAAC,EAAE;gBACZ,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;aACnD,CAAC,CAAA;YAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAChE,MAAM,WAAW,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAEnD,OAAO;gBACN,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,OAAO;gBACd,S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|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"vite": "^7.0.0",
|
|
83
|
-
"vitest": "^3.0.0"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
2
|
+
"name": "@growth-labs/mailer",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./components": {
|
|
11
|
+
"types": "./src/components/index.ts",
|
|
12
|
+
"import": "./src/components/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"./utils": {
|
|
15
|
+
"types": "./dist/utils/index.d.ts",
|
|
16
|
+
"import": "./dist/utils/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./utils/*": {
|
|
19
|
+
"types": "./dist/utils/*.d.ts",
|
|
20
|
+
"import": "./dist/utils/*.js"
|
|
21
|
+
},
|
|
22
|
+
"./middleware/*": {
|
|
23
|
+
"types": "./dist/middleware/*.d.ts",
|
|
24
|
+
"import": "./dist/middleware/*.js",
|
|
25
|
+
"default": "./dist/middleware/*.js"
|
|
26
|
+
},
|
|
27
|
+
"./routes/preferences": {
|
|
28
|
+
"types": "./src/routes/preferences.astro",
|
|
29
|
+
"import": "./src/routes/preferences.astro",
|
|
30
|
+
"default": "./src/routes/preferences.astro"
|
|
31
|
+
},
|
|
32
|
+
"./routes/*": {
|
|
33
|
+
"types": "./dist/routes/*.d.ts",
|
|
34
|
+
"import": "./dist/routes/*.js",
|
|
35
|
+
"default": "./dist/routes/*.js"
|
|
36
|
+
},
|
|
37
|
+
"./queue": {
|
|
38
|
+
"types": "./dist/queue/consumer.d.ts",
|
|
39
|
+
"import": "./dist/queue/consumer.js"
|
|
40
|
+
},
|
|
41
|
+
"./components/*": {
|
|
42
|
+
"types": "./src/components/*.astro",
|
|
43
|
+
"import": "./src/components/*.astro"
|
|
44
|
+
},
|
|
45
|
+
"./schema": {
|
|
46
|
+
"types": "./dist/schema.d.ts",
|
|
47
|
+
"import": "./dist/schema.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"src",
|
|
53
|
+
"README.md"
|
|
54
|
+
],
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"astro": "^6.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@growth-labs/analytics": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"drizzle-orm": "^0.38.0",
|
|
65
|
+
"ulidx": "^2.4.0",
|
|
66
|
+
"zod": "^3.23.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@cloudflare/workers-types": "^4.20260402.1",
|
|
70
|
+
"astro": "^6.0.0",
|
|
71
|
+
"drizzle-kit": "^0.30.0",
|
|
72
|
+
"typescript": "^5.7.0",
|
|
73
|
+
"vite": "^7.0.0",
|
|
74
|
+
"vitest": "^3.0.0"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "tsc",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"test:watch": "vitest"
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/options.ts
CHANGED
|
@@ -1,65 +1,56 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
export const mailerOptionsSchema = z
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
batchSize: z.number().min(1).max(500).default(100),
|
|
55
|
-
|
|
56
|
-
// ─── Optional peer: analytics ───
|
|
57
|
-
analyticsEnabled: z.boolean().default(false),
|
|
58
|
-
})
|
|
59
|
-
.refine((data) => data.fallbackProvider !== 'resend' || data.resendApiKey, {
|
|
60
|
-
message: 'resendApiKey is required when fallbackProvider is "resend"',
|
|
61
|
-
path: ['resendApiKey'],
|
|
62
|
-
})
|
|
3
|
+
export const mailerOptionsSchema = z.object({
|
|
4
|
+
// ─── Required ───
|
|
5
|
+
senderName: z.string(),
|
|
6
|
+
fromAddress: z.string().email(),
|
|
7
|
+
|
|
8
|
+
// ─── Reply-to ───
|
|
9
|
+
replyTo: z.string().email().optional(),
|
|
10
|
+
|
|
11
|
+
// ─── Cloudflare bindings ───
|
|
12
|
+
d1Binding: z.string().default('SITE_DB'),
|
|
13
|
+
queueBinding: z.string().default('EMAIL_QUEUE'),
|
|
14
|
+
|
|
15
|
+
// ─── Turnstile (subscribe form) ───
|
|
16
|
+
turnstileSiteKey: z.string(),
|
|
17
|
+
turnstileSecretKey: z.string(),
|
|
18
|
+
|
|
19
|
+
// ─── Subscriber lifecycle ───
|
|
20
|
+
doubleOptIn: z.boolean().default(true),
|
|
21
|
+
topics: z.array(z.string()).optional(),
|
|
22
|
+
|
|
23
|
+
// ─── Token signing ───
|
|
24
|
+
signingSecret: z.string(),
|
|
25
|
+
|
|
26
|
+
// ─── Routes ───
|
|
27
|
+
subscribePath: z.string().default('/api/newsletter/subscribe'),
|
|
28
|
+
confirmPath: z.string().default('/api/newsletter/confirm'),
|
|
29
|
+
unsubscribePath: z.string().default('/api/newsletter/unsubscribe'),
|
|
30
|
+
preferencesPath: z.string().default('/email/preferences'),
|
|
31
|
+
webhookPath: z.string().default('/api/email/webhook'),
|
|
32
|
+
|
|
33
|
+
// ─── Tracking ───
|
|
34
|
+
trackOpenPath: z.string().default('/api/email/open'),
|
|
35
|
+
trackClickPath: z.string().default('/api/email/click'),
|
|
36
|
+
siteUrl: z.string().url(),
|
|
37
|
+
|
|
38
|
+
// ─── Branding (for built-in templates) ───
|
|
39
|
+
brand: z
|
|
40
|
+
.object({
|
|
41
|
+
logoUrl: z.string().url().optional(),
|
|
42
|
+
primaryColor: z.string().default('#1a365d'),
|
|
43
|
+
accentColor: z.string().default('#e53e3e'),
|
|
44
|
+
footerText: z.string().optional(),
|
|
45
|
+
})
|
|
46
|
+
.default({}),
|
|
47
|
+
|
|
48
|
+
// ─── Queue batching ───
|
|
49
|
+
batchSize: z.number().min(1).max(500).default(100),
|
|
50
|
+
|
|
51
|
+
// ─── Optional peer: analytics ───
|
|
52
|
+
analyticsEnabled: z.boolean().default(false),
|
|
53
|
+
})
|
|
63
54
|
|
|
64
55
|
export type MailerOptions = z.input<typeof mailerOptionsSchema>
|
|
65
56
|
export type ResolvedMailerOptions = z.output<typeof mailerOptionsSchema>
|
package/src/queue/consumer.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ResolvedMailerOptions } from '../options.js'
|
|
|
3
3
|
import type { EmailProvider, EmailQueueMessage } from '../types.js'
|
|
4
4
|
import { updateSendStatus } from '../utils/bounce.js'
|
|
5
5
|
import type { CloudflareEmailSender } from '../utils/providers.js'
|
|
6
|
-
import { CloudflareEmailProvider,
|
|
6
|
+
import { CloudflareEmailProvider, sleep } from '../utils/providers.js'
|
|
7
7
|
|
|
8
8
|
export async function handleEmailQueue(
|
|
9
9
|
batch: MessageBatch<EmailQueueMessage>,
|
|
@@ -16,7 +16,6 @@ export async function handleEmailQueue(
|
|
|
16
16
|
: new CloudflareEmailProvider({
|
|
17
17
|
send: () => Promise.reject(new Error('No email sender configured')),
|
|
18
18
|
})
|
|
19
|
-
const fallback = getFallbackProvider(options)
|
|
20
19
|
|
|
21
20
|
for (const message of batch.messages) {
|
|
22
21
|
const { recipients, htmlTemplate, subject, from, replyTo, headers, type } = message.body
|
|
@@ -65,22 +64,6 @@ export async function handleEmailQueue(
|
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
if (!result.success && fallback) {
|
|
69
|
-
result = await fallback.send({
|
|
70
|
-
to: recipient.email,
|
|
71
|
-
from,
|
|
72
|
-
replyTo,
|
|
73
|
-
subject,
|
|
74
|
-
html,
|
|
75
|
-
headers: recipientHeaders,
|
|
76
|
-
})
|
|
77
|
-
if (result.success) {
|
|
78
|
-
console.warn(
|
|
79
|
-
`[mailer] Fallback provider used for ${recipient.email}: ${provider.name} → ${fallback.name}`,
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
67
|
if (result.success) {
|
|
85
68
|
await updateSendStatus(db, recipient.trackingId, 'sent', {
|
|
86
69
|
sentAt: new Date().toISOString(),
|
package/src/utils/index.ts
CHANGED
|
@@ -7,9 +7,7 @@ export {
|
|
|
7
7
|
export type { CloudflareEmailSender } from './providers.js'
|
|
8
8
|
export {
|
|
9
9
|
CloudflareEmailProvider,
|
|
10
|
-
getFallbackProvider,
|
|
11
10
|
getProvider,
|
|
12
|
-
ResendFallbackProvider,
|
|
13
11
|
sleep,
|
|
14
12
|
} from './providers.js'
|
|
15
13
|
export type { CampaignSchedule, DigestSchedule } from './scheduling.js'
|
package/src/utils/providers.ts
CHANGED
|
@@ -44,79 +44,12 @@ export class CloudflareEmailProvider implements EmailProvider {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// ─── ResendFallbackProvider ───
|
|
48
|
-
|
|
49
|
-
export class ResendFallbackProvider implements EmailProvider {
|
|
50
|
-
readonly name = 'resend'
|
|
51
|
-
private readonly apiKey: string
|
|
52
|
-
|
|
53
|
-
constructor(apiKey: string) {
|
|
54
|
-
this.apiKey = apiKey
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async send(email: OutboundEmail): Promise<SendResult> {
|
|
58
|
-
try {
|
|
59
|
-
const response = await fetch('https://api.resend.com/emails', {
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: {
|
|
62
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
63
|
-
'Content-Type': 'application/json',
|
|
64
|
-
},
|
|
65
|
-
body: JSON.stringify({
|
|
66
|
-
to: email.to,
|
|
67
|
-
from: email.from,
|
|
68
|
-
reply_to: email.replyTo,
|
|
69
|
-
subject: email.subject,
|
|
70
|
-
html: email.html,
|
|
71
|
-
headers: email.headers,
|
|
72
|
-
}),
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
if (response.ok) {
|
|
76
|
-
const data = (await response.json()) as { id?: string }
|
|
77
|
-
return {
|
|
78
|
-
success: true,
|
|
79
|
-
messageId: data.id,
|
|
80
|
-
retryable: false,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const retryable = response.status === 429 || response.status >= 500
|
|
85
|
-
const errorText = await response.text().catch(() => 'Unknown error')
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
success: false,
|
|
89
|
-
error: `Resend API ${response.status}: ${errorText}`,
|
|
90
|
-
retryable,
|
|
91
|
-
}
|
|
92
|
-
} catch (err) {
|
|
93
|
-
const message = err instanceof Error ? err.message : String(err)
|
|
94
|
-
return {
|
|
95
|
-
success: false,
|
|
96
|
-
error: message,
|
|
97
|
-
retryable: true,
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
47
|
// ─── Factory functions ───
|
|
104
48
|
|
|
105
49
|
export function getProvider(emailSender: CloudflareEmailSender): EmailProvider {
|
|
106
50
|
return new CloudflareEmailProvider(emailSender)
|
|
107
51
|
}
|
|
108
52
|
|
|
109
|
-
export function getFallbackProvider(options: {
|
|
110
|
-
fallbackProvider: string
|
|
111
|
-
resendApiKey?: string
|
|
112
|
-
}): EmailProvider | null {
|
|
113
|
-
if (options.fallbackProvider === 'resend' && options.resendApiKey) {
|
|
114
|
-
return new ResendFallbackProvider(options.resendApiKey)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return null
|
|
118
|
-
}
|
|
119
|
-
|
|
120
53
|
// ─── Helpers ───
|
|
121
54
|
|
|
122
55
|
export function sleep(ms: number): Promise<void> {
|