From 5374b3e4447a82d420d31cd771227cedd516c063 Mon Sep 17 00:00:00 2001 From: Hussein Ait Lahcen Date: Thu, 21 Nov 2024 14:39:11 +0100 Subject: [PATCH] feat(mpc): add ping edge function --- mpc/edge/supabase/.gitignore | 4 ++ mpc/edge/supabase/functions/ping/index.ts | 49 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 mpc/edge/supabase/.gitignore create mode 100644 mpc/edge/supabase/functions/ping/index.ts diff --git a/mpc/edge/supabase/.gitignore b/mpc/edge/supabase/.gitignore new file mode 100644 index 0000000000..a3ad88055b --- /dev/null +++ b/mpc/edge/supabase/.gitignore @@ -0,0 +1,4 @@ +# Supabase +.branches +.temp +.env diff --git a/mpc/edge/supabase/functions/ping/index.ts b/mpc/edge/supabase/functions/ping/index.ts new file mode 100644 index 0000000000..3f077e7ac4 --- /dev/null +++ b/mpc/edge/supabase/functions/ping/index.ts @@ -0,0 +1,49 @@ +const resendSecret = Deno.env.get("RESEND_SECRET") +const resendApiKey = Deno.env.get("RESEND_API_KEY") + +const handler = async (request: Request): Promise => { + const { secret, email } = await request.json() + if (secret !== resendSecret) { + return new Response(JSON.stringify("too bad"), { + status: 403, + headers: { + "Content-Type": "application/json" + } + }) + } + const res = await fetch("https://api.resend.com/emails", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${resendApiKey}` + }, + body: JSON.stringify({ + from: "Union Ceremony ", + to: [email], + reply_to: "ceremony@union.build", + subject: "Your Turn Is Almost Here - Log Into Union Ceremony", + html: ` +

+ Your contribution slot for the Union Trusted Setup Ceremony is almost here. +

+

+ Your place in queue: 5
+ Estimated time until your slot: between 1 hour and 5 hours +

+

+ Please go to ceremony.union.build, log in, and follow all steps on the page.
+ If you do not follow all steps by the time your contribution slot arrives, you will lose your slot. +

+ ` + }) + }) + const data = await res.json() + return new Response(JSON.stringify(data), { + status: 200, + headers: { + "Content-Type": "application/json" + } + }) +} + +Deno.serve(handler)