better-svelte-email
Version:
Svelte email renderer with Tailwind support
104 lines (103 loc) • 2.81 kB
TypeScript
import type { RequestEvent } from '@sveltejs/kit';
/**
* Import all Svelte email components file paths.
* Create a list containing all Svelte email component file names.
* Return this list to the client.
*/
export type PreviewData = {
files: string[] | null;
path: string | null;
};
type EmailListProps = {
path?: string;
root?: string;
};
/**
* Get a list of all email component files in the specified directory.
*
* @param options.path - Relative path from root to emails folder (default: '/src/lib/emails')
* @param options.root - Absolute path to project root (auto-detected if not provided)
* @returns PreviewData object with list of email files and the path
*
* @example
* ```ts
* // In a +page.server.ts file
* import { emailList } from 'better-svelte-email/preview';
*
* export function load() {
* const emails = emailList({
* root: process.cwd(),
* path: '/src/lib/emails'
* });
* return { emails };
* }
* ```
*/
export declare const emailList: ({ path: emailPath, root }?: EmailListProps) => PreviewData;
/**
* SvelteKit form action to render an email component.
* Use this with the Preview component to render email templates on demand.
*
* @example
* ```ts
* // +page.server.ts
* import { createEmail } from 'better-svelte-email/preview';
*
* export const actions = createEmail;
* ```
*/
export declare const createEmail: {
'create-email': (event: RequestEvent) => Promise<{
status: number;
body: {
error: string;
};
error?: undefined;
} | {
body: string;
status?: undefined;
error?: undefined;
} | {
status: number;
error: {
message: string;
};
body?: undefined;
}>;
};
export declare const SendEmailFunction: ({ from, to, subject, html }: {
from: string;
to: string;
subject: string;
html: string;
}, resendApiKey?: string) => Promise<{
success: boolean;
error?: any;
}>;
/**
* Sends the email using the submitted form data.
*
* @param options.resendApiKey - Your Resend API key (keep this server-side only)
* @param options.customSendEmailFunction - Optional custom function to send emails
*
* @example
* ```ts
* // In +page.server.ts
* import { PRIVATE_RESEND_API_KEY } from '$env/static/private';
*
* export const actions = {
* ...createEmail,
* ...sendEmail({ resendApiKey: PRIVATE_RESEND_API_KEY })
* };
* ```
*/
export declare const sendEmail: ({ customSendEmailFunction, resendApiKey }?: {
customSendEmailFunction?: typeof SendEmailFunction;
resendApiKey?: string;
}) => {
'send-email': (event: RequestEvent) => Promise<{
success: boolean;
error: any;
}>;
};
export { default as EmailPreview } from './EmailPreview.svelte';