Skip to content

Commit 5c9577b

Browse files
committed
refactor: nix unused low-level resend func
The comment indicates this isn't used anywhere else. There are no uses of it in our codebase.
1 parent 25ce6ec commit 5c9577b

1 file changed

Lines changed: 0 additions & 41 deletions

File tree

apps/backend/src/lib/emails-low-level.tsx

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { runAsynchronously, wait } from '@stackframe/stack-shared/dist/utils/pro
1010
import { Result } from '@stackframe/stack-shared/dist/utils/results';
1111
import { traceSpan } from '@stackframe/stack-shared/dist/utils/telemetry';
1212
import nodemailer from 'nodemailer';
13-
import { Resend } from 'resend';
14-
import { getTenancy } from './tenancies';
1513

1614
export function isSecureEmailPort(port: number | string) {
1715
let parsedPort = parseInt(port.toString());
@@ -221,42 +219,3 @@ export async function lowLevelSendEmailDirectWithoutRetries(options: LowLevelSen
221219

222220
return result;
223221
}
224-
225-
// currently unused, although in the future we may want to use this to minimize the number of requests to Resend
226-
export async function lowLevelSendEmailResendBatchedDirect(resendApiKey: string, emailOptions: LowLevelSendEmailOptions[]) {
227-
if (emailOptions.length === 0) {
228-
return Result.ok([]);
229-
}
230-
if (emailOptions.length > 100) {
231-
throw new StackAssertionError("sendEmailResendBatchedDirect expects at most 100 emails to be sent at once", { emailOptions });
232-
}
233-
if (emailOptions.some(option => option.tenancyId !== emailOptions[0].tenancyId)) {
234-
throw new StackAssertionError("sendEmailResendBatchedDirect expects all emails to be sent from the same tenancy", { emailOptions });
235-
}
236-
const tenancy = await getTenancy(emailOptions[0].tenancyId);
237-
if (!tenancy) {
238-
throw new StackAssertionError("Tenancy not found");
239-
}
240-
const resend = new Resend(resendApiKey);
241-
const result = await Result.retry(async (_) => {
242-
const { data, error } = await resend.batch.send(emailOptions.map((option) => ({
243-
from: option.emailConfig.senderEmail,
244-
to: option.to,
245-
subject: option.subject,
246-
html: option.html ?? "",
247-
text: option.text,
248-
})));
249-
250-
if (data) {
251-
return Result.ok(data.data);
252-
}
253-
if (error.name === "rate_limit_exceeded" || error.name === "internal_server_error") {
254-
// these are the errors we want to retry
255-
return Result.error(error);
256-
}
257-
throw new StackAssertionError("Failed to send email with Resend", { error });
258-
}, 3, { exponentialDelayBase: 2000 });
259-
260-
return result;
261-
}
262-

0 commit comments

Comments
 (0)