Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix the imports

Kiran Ka6cc52bc4d2b
diff --git a/apps/web/app/api/admin/ban/route.ts b/apps/web/app/api/admin/ban/route.ts
index c7c38dbbcb..05299d684a 100644
--- a/apps/web/app/api/admin/ban/route.ts
+++ b/apps/web/app/api/admin/ban/route.ts
@@ -1,7 +1,7 @@
import { deleteWorkspaceAdmin } from "@/lib/api/workspaces";
import { withAdmin } from "@/lib/auth";
import { updateConfig } from "@/lib/edge-config";
-import { unsubscribe } from "@/lib/resend";
+import { unsubscribe } from "@dub/email/resend/unsubscribe";
import { isStored, storage } from "@/lib/storage";
import { prisma } from "@dub/prisma";
import { R2_URL } from "@dub/utils";
diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.ts
index 8b201ee231..23449219d4 100644
--- a/apps/web/app/api/user/route.ts
+++ b/apps/web/app/api/user/route.ts
@@ -1,6 +1,6 @@
import { DubApiError } from "@/lib/api/errors";
import { withSession } from "@/lib/auth";
-import { unsubscribe } from "@/lib/resend";
+import { unsubscribe } from "@dub/email/resend/unsubscribe";
import { storage } from "@/lib/storage";
import { prisma } from "@dub/prisma";
import { R2_URL, nanoid, trim } from "@dub/utils";
diff --git a/apps/web/app/api/user/subscribe/route.ts b/apps/web/app/api/user/subscribe/route.ts
index ac6b4bdcd0..46910a35fa 100644
--- a/apps/web/app/api/user/subscribe/route.ts
+++ b/apps/web/app/api/user/subscribe/route.ts
@@ -1,5 +1,6 @@
import { withSession } from "@/lib/auth";
-import { subscribe, unsubscribe } from "@/lib/resend";
+import { unsubscribe } from "@dub/email/resend/unsubscribe";
+import { subscribe } from "@dub/email/resend/subscribe";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index c7c0a1117d..4fddce9984 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -1,9 +1,9 @@
import { isBlacklistedEmail } from "@/lib/edge-config";
import jackson from "@/lib/jackson";
-import { subscribe } from "@/lib/resend";
import { isStored, storage } from "@/lib/storage";
import { UserProps } from "@/lib/types";
import { ratelimit } from "@/lib/upstash";
+import { subscribe } from "@dub/email/resend/subscribe";
import { LoginLink } from "@dub/email/templates/login-link";
import { WelcomeEmail } from "@dub/email/templates/welcome-email";
import { prisma } from "@dub/prisma";
diff --git a/packages/email/package.json b/packages/email/package.json
index 9d75d569fb..04b9d7064c 100644
--- a/packages/email/package.json
+++ b/packages/email/package.json
@@ -31,6 +31,9 @@
},
"./templates/*": {
"import": "./src/templates/*.tsx"
+ },
+ "./resend/*": {
+ "import": "./src/resend/*.ts"
}
}
}
diff --git a/packages/email/src/resend.ts b/packages/email/src/resend.ts
index b465b4d44b..7ed3e93912 100644
--- a/packages/email/src/resend.ts
+++ b/packages/email/src/resend.ts
@@ -1,36 +1,5 @@
import { Resend } from "resend";
-const resendApiKey = process.env.RESEND_API_KEY;
-
-export const resend = resendApiKey ? new Resend(resendApiKey) : null;
-
-export async function subscribe({
- email,
- name,
-}: {
- email: string;
- name?: string | null;
-}) {
- const audienceId = process.env.RESEND_AUDIENCE_ID;
-
- if (!audienceId) {
- console.error("RESEND_AUDIENCE_ID is not set in the .env. Skipping.");
- return;
- }
-
- return await resend?.contacts.create({
- email,
- ...(name && {
- firstName: name.split(" ")[0],
- lastName: name.split(" ").slice(1).join(" "),
- }),
- audienceId: process.env.RESEND_AUDIENCE_ID as string,
- });
-}
-
-export async function unsubscribe({ email }: { email: string }) {
- return await resend?.contacts.remove({
- email,
- audienceId: process.env.RESEND_AUDIENCE_ID as string,
- });
-}
+export const resend = process.env.RESEND_API_KEY
+ ? new Resend(process.env.RESEND_API_KEY)
+ : null;
diff --git a/packages/email/src/resend/subscribe.ts b/packages/email/src/resend/subscribe.ts
new file mode 100644
index 0000000000..54a740f188
--- /dev/null
+++ b/packages/email/src/resend/subscribe.ts
@@ -0,0 +1,25 @@
+import { resend } from "../resend";
+
+export async function subscribe({
+ email,
+ name,
+}: {
+ email: string;
+ name?: string | null;
+}) {
+ const audienceId = process.env.RESEND_AUDIENCE_ID;
+
+ if (!audienceId) {
+ console.error("RESEND_AUDIENCE_ID is not set in the .env. Skipping.");
+ return;
+ }
+
+ return await resend?.contacts.create({
+ email,
+ ...(name && {
+ firstName: name.split(" ")[0],
+ lastName: name.split(" ").slice(1).join(" "),
+ }),
+ audienceId,
+ });
+}
diff --git a/packages/email/src/resend/unsubscribe.ts b/packages/email/src/resend/unsubscribe.ts
new file mode 100644
index 0000000000..017b97fc49
--- /dev/null
+++ b/packages/email/src/resend/unsubscribe.ts
@@ -0,0 +1,15 @@
+import { resend } from "../resend";
+
+export async function unsubscribe({ email }: { email: string }) {
+ const audienceId = process.env.RESEND_AUDIENCE_ID;
+
+ if (!audienceId) {
+ console.error("RESEND_AUDIENCE_ID is not set in the .env. Skipping.");
+ return;
+ }
+
+ return await resend?.contacts.remove({
+ email,
+ audienceId,
+ });
+}