forked from dubinc/dub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef75df9
commit b1689a0
Showing
9 changed files
with
2,272 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import "dotenv-flow/config"; | ||
import prisma from "@/lib/prisma"; | ||
|
||
async function main() { | ||
const users = await prisma.user.findMany({ | ||
where: { | ||
projects: { | ||
some: { | ||
project: { | ||
slug: "steven", | ||
}, | ||
}, | ||
}, | ||
}, | ||
select: { | ||
name: true, | ||
email: true, | ||
}, | ||
}); | ||
|
||
const response = await fetch("https://api.resend.com/emails/batch", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${process.env.RESEND_API_KEY}`, | ||
}, | ||
body: JSON.stringify( | ||
users.map(({ name, email }) => { | ||
return { | ||
from: "Steven from Dub <[email protected]>", | ||
to: email, | ||
subject: "Hello from Dub", | ||
text: `Hi ${name},\n\nThis is a test email from Dub.\n\nBest,\nSteven`, | ||
}; | ||
}), | ||
), | ||
}).then((res) => res.json()); | ||
|
||
console.log(response); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Redis } from "@upstash/redis"; | ||
import { Resend } from "resend"; | ||
|
||
// Initiate Redis instance by connecting to REST URL | ||
export const redis = new Redis({ | ||
url: process.env.UPSTASH_REDIS_REST_URL || "", | ||
token: process.env.UPSTASH_REDIS_REST_TOKEN || "", | ||
}); | ||
|
||
export const resend = new Resend(process.env.RESEND_API_KEY); | ||
|
||
export function linkConstructor({ | ||
key, | ||
domain = "dub.sh", | ||
localhost, | ||
pretty, | ||
noDomain, | ||
}: { | ||
key: string; | ||
domain?: string; | ||
localhost?: boolean; | ||
pretty?: boolean; | ||
noDomain?: boolean; | ||
}) { | ||
const link = `${ | ||
localhost ? "http://home.localhost:8888" : `https://${domain}` | ||
}${key !== "_root" ? `/${key}` : ""}`; | ||
|
||
if (noDomain) return `/${key}`; | ||
return pretty ? link.replace(/^https?:\/\//, "") : link; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
"use server"; | ||
|
||
import { nanoid } from "@dub/utils"; | ||
import { resend } from "emails"; | ||
import FeedbackEmail from "emails/feedback-email"; | ||
|
||
export async function submitFeedback(data: FormData) { | ||
const email = data.get("email") as string; | ||
const feedback = data.get("feedback") as string; | ||
|
||
return await fetch("https://api.resend.com/emails", { | ||
method: "POST", | ||
return await resend?.emails.send({ | ||
from: "[email protected]", | ||
to: ["[email protected]"], | ||
...(email && { reply_to: email }), | ||
subject: "🎉 New Feedback Received!", | ||
react: FeedbackEmail({ | ||
email, | ||
feedback, | ||
}), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer " + process.env.RESEND_API_KEY, | ||
"X-Entity-Ref-ID": nanoid(), | ||
}, | ||
body: JSON.stringify({ | ||
from: "[email protected]", | ||
to: "[email protected]", | ||
reply_to: email, | ||
...(email && { reply_to: email }), | ||
subject: "🎉 New Feedback Received!", | ||
text: feedback, | ||
}), | ||
}); | ||
} |
Oops, something went wrong.