alepha
Version:
Easy-to-use modern TypeScript framework for building many kind of applications.
159 lines • 4.86 kB
TypeScript
import { AlephaError, InstantiableClass, KIND, Primitive, Static } from "alepha";
import { FileSystemProvider } from "alepha/system";
//#region ../../src/email/core/providers/EmailProvider.d.ts
/**
* Email provider interface.
*
* All methods are asynchronous and return promises.
*/
declare abstract class EmailProvider {
/**
* Send an email.
*
* @return Promise that resolves when the email is sent.
*/
abstract send(options: EmailSendOptions): Promise<void>;
}
type EmailSendOptions = {
to: string | string[];
subject: string;
body: string;
};
//#endregion
//#region ../../src/email/core/errors/EmailError.d.ts
declare class EmailError extends AlephaError {
constructor(message: string, cause?: Error);
}
//#endregion
//#region ../../src/email/core/primitives/$email.d.ts
declare const $email: {
(options?: EmailPrimitiveOptions): EmailPrimitive;
[KIND]: typeof EmailPrimitive;
};
interface EmailPrimitiveOptions {
name?: string;
provider?: InstantiableClass<EmailProvider> | "memory";
}
/**
* Email primitive for sending emails through various providers.
*
* The primitive's `name` identifies the channel in the `email:sending` /
* `email:sent` hooks; it does not select a template — `send()` expects an
* already-rendered `subject` and `body`.
*
* Usage:
* ```typescript
* class MyService {
* protected readonly welcomeEmail = $email({ name: "welcome" });
*
* async sendWelcome(userEmail: string, userName: string) {
* await this.welcomeEmail.send({
* to: userEmail,
* subject: "Welcome!",
* body: `<p>Hello ${userName}!</p>`
* });
* }
* }
* ```
*/
declare class EmailPrimitive extends Primitive<EmailPrimitiveOptions> {
protected readonly provider: EmailProvider;
get name(): string;
/**
* Send an email using the configured provider.
*/
send(options: EmailSendOptions): Promise<void>;
protected $provider(): EmailProvider;
}
//#endregion
//#region ../../src/email/core/providers/LocalEmailProvider.d.ts
/**
* Local email provider configuration atom
*/
declare const localEmailOptions: import("alepha").Atom<import("zod").ZodObject<{
directory: import("zod").ZodString;
}, import("zod/v4/core").$strip>, "alepha.email.local.options">;
type LocalEmailProviderOptions = Static<typeof localEmailOptions.schema>;
declare module "alepha" {
interface State {
[localEmailOptions.key]: LocalEmailProviderOptions;
}
}
declare class LocalEmailProvider implements EmailProvider {
protected readonly log: import("alepha/logger").Logger;
protected readonly fs: FileSystemProvider;
protected readonly options: Readonly<{
directory: string;
}>;
protected get directory(): string;
protected onStart: import("alepha").HookPrimitive<"start">;
send(options: EmailSendOptions): Promise<void>;
createEmailJson(options: {
to: string;
subject: string;
body: string;
}): {
to: string;
subject: string;
body: string;
sentAt: string;
};
}
//#endregion
//#region ../../src/email/core/providers/MemoryEmailProvider.d.ts
interface EmailRecord {
to: string;
subject: string;
body: string;
sentAt: Date;
}
declare class MemoryEmailProvider implements EmailProvider {
protected readonly log: import("alepha/logger").Logger;
records: EmailRecord[];
send(options: EmailSendOptions): Promise<void>;
/**
* Get the last email sent (for testing purposes).
*/
get last(): EmailRecord | undefined;
}
//#endregion
//#region ../../src/email/core/index.d.ts
declare module "alepha" {
interface Hooks {
"email:sending": {
to: string | string[];
template: string;
variables: Record<string, unknown>;
provider: EmailProvider;
abort(): void;
};
"email:sent": {
to: string | string[];
template: string;
provider: EmailProvider;
};
}
}
/**
* Email delivery over pluggable providers.
*
* **Features:**
* - `$email` declares a named send channel; the name is surfaced to the
* `email:sending` / `email:sent` hooks (as their `template` field) for
* auditing and interception
* - Multiple recipients
* - Local file provider for development
* - Memory provider for testing
*
* There is **no template rendering**: `send()` takes an already-rendered
* `subject` and `body` — bring your own templating if you need it.
*
* For SMTP support, use `AlephaEmailSmtp` from `alepha/email/smtp`.
* For Brevo support, use `AlephaEmailBrevo` from `alepha/email/brevo`.
*
* @module alepha.email
*/
declare const AlephaEmail: import("alepha").Service<import("alepha").Module>;
//#endregion
export { $email, AlephaEmail, EmailError, EmailPrimitive, EmailPrimitiveOptions, EmailProvider, EmailRecord, EmailSendOptions, LocalEmailProvider, LocalEmailProviderOptions, MemoryEmailProvider, localEmailOptions };
//# sourceMappingURL=index.d.ts.map