Update & format
This commit is contained in:
@@ -4,52 +4,57 @@ import { UseSend } from 'usesend-js';
|
||||
/** @todo Document this */
|
||||
export const Usesend = (config: EmailUserConfig): EmailConfig => {
|
||||
return {
|
||||
id: "usesend",
|
||||
type: "email",
|
||||
name: "Usesend",
|
||||
from: "TechTracker Admin <admin@mail.techtracker.gbrown.org>",
|
||||
id: 'usesend',
|
||||
type: 'email',
|
||||
name: 'Usesend',
|
||||
from: 'TechTracker Admin <admin@mail.techtracker.gbrown.org>',
|
||||
maxAge: 24 * 60 * 60,
|
||||
async sendVerificationRequest(params) {
|
||||
const { identifier: to, provider, url, theme } = params
|
||||
const { host } = new URL(url)
|
||||
const useSend = new UseSend(provider.apiKey, 'https://usesend.gbrown.org')
|
||||
const { identifier: to, provider, url, theme } = params;
|
||||
const { host } = new URL(url);
|
||||
const useSend = new UseSend(
|
||||
provider.apiKey,
|
||||
'https://usesend.gbrown.org',
|
||||
);
|
||||
const { error } = await useSend.emails.send({
|
||||
to,
|
||||
from: provider.from ?? 'TechTracker Admin <admin@mail.techtracker.gbrown.org>',
|
||||
from:
|
||||
provider.from ??
|
||||
'TechTracker Admin <admin@mail.techtracker.gbrown.org>',
|
||||
subject: `Sign in to ${host}`,
|
||||
html: html({ url, host, theme }),
|
||||
text: text({ url, host })
|
||||
text: text({ url, host }),
|
||||
});
|
||||
if (error) throw new Error("Usesend error: " + error.message)
|
||||
if (error) throw new Error('Usesend error: ' + error.message);
|
||||
},
|
||||
options: config,
|
||||
};
|
||||
};
|
||||
|
||||
type Theme = {
|
||||
colorScheme?: "auto" | "dark" | "light"
|
||||
logo?: string
|
||||
brandColor?: string
|
||||
buttonText?: string
|
||||
type Theme = {
|
||||
colorScheme?: 'auto' | 'dark' | 'light';
|
||||
logo?: string;
|
||||
brandColor?: string;
|
||||
buttonText?: string;
|
||||
};
|
||||
|
||||
const text = ({ url, host }: { url: string; host: string }) => {
|
||||
return `Sign in to ${host}\n${url}\n\n`
|
||||
return `Sign in to ${host}\n${url}\n\n`;
|
||||
};
|
||||
|
||||
const html = (params: { url: string; host: string; theme: Theme }) => {
|
||||
const { url, host, theme } = params;
|
||||
|
||||
const escapedHost = host.replace(/\./g, "​.");
|
||||
const escapedHost = host.replace(/\./g, '​.');
|
||||
|
||||
const brandColor = theme.brandColor || "#346df1";
|
||||
const brandColor = theme.brandColor || '#346df1';
|
||||
|
||||
const buttonText = theme.buttonText || "#fff";
|
||||
const buttonText = theme.buttonText || '#fff';
|
||||
|
||||
const color = {
|
||||
background: "#f9f9f9",
|
||||
text: "#444",
|
||||
mainBackground: "#fff",
|
||||
background: '#f9f9f9',
|
||||
text: '#444',
|
||||
mainBackground: '#fff',
|
||||
buttonBackground: brandColor,
|
||||
buttonBorder: brandColor,
|
||||
buttonText,
|
||||
@@ -85,5 +90,5 @@ const html = (params: { url: string; host: string; theme: Theme }) => {
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
`
|
||||
`;
|
||||
};
|
||||
|
Reference in New Issue
Block a user