Email notifications: settings UI + mail adapter #4

Open
hudson wants to merge 162 commits from email-notifications into dev
Showing only changes of commit 3981ed9608 - Show all commits

View file

@ -99,9 +99,18 @@ export class MailNotifications {
throw new Error("Email notification server not configured") throw new Error("Email notification server not configured")
} }
const body = {email, frequency}
const bodyJson = JSON.stringify(body)
let authEvent let authEvent
try { try {
authEvent = await $signer.sign(await makeHttpAuth(EMAIL_NOTIFICATION_SERVER, "PUT")) authEvent = await $signer.sign(
await makeHttpAuth(
buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email"),
"PUT",
bodyJson,
),
)
} catch (e) { } catch (e) {
emailNotificationState.set({ emailNotificationState.set({
error: "Failed to create authentication. Check your signer.", error: "Failed to create authentication. Check your signer.",
@ -115,7 +124,7 @@ export class MailNotifications {
try { try {
res = await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email"), { res = await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", "email"), {
method: "PUT", method: "PUT",
body: JSON.stringify({email, frequency, pubkey: $user.pubkey}), body: bodyJson,
headers: {Authorization: authHeader, "Content-Type": "application/json"}, headers: {Authorization: authHeader, "Content-Type": "application/json"},
}) })
} catch (e) { } catch (e) {
@ -149,7 +158,9 @@ export class MailNotifications {
if (!$signer) return if (!$signer) return
try { try {
const authEvent = await $signer.sign(await makeHttpAuth(EMAIL_NOTIFICATION_SERVER, "DELETE")) const authEvent = await $signer.sign(
await makeHttpAuth(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", key), "DELETE"),
)
const authHeader = makeHttpAuthHeader(authEvent) const authHeader = makeHttpAuthHeader(authEvent)
await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", key), { await fetch(buildUrl(EMAIL_NOTIFICATION_SERVER, "subscription", key), {