Email SDK
PluginsBuilt-in plugins

Capture plugin

Record lifecycle events in memory and expose the store through a typed client extension.

capturePlugin is useful in application tests and local debugging. It stores full normalized messages, so do not use it as an unbounded production log.

src/email.test.ts
import { expect, test } from "bun:test";
import { createEmailClient } from "@opencoredev/email-sdk";
import { capturePlugin } from "@opencoredev/email-sdk/plugins/capture";
import { memoryAdapter } from "@opencoredev/email-sdk/testing";

const email = createEmailClient({
  adapters: [memoryAdapter()],
  plugins: [capturePlugin()],
});

await email.send(message);
expect(email.capture.events.map((event) => event.type)).toEqual([
  "beforeSend",
  "afterSend",
]);

Captured events

The store records beforeSend, afterSend, retry, and error. Success, retry, and error records include the adapter and attempt. The store keeps the complete message and send metadata.

Supply a store

Use createEmailCaptureStore when multiple clients or tests should share an explicitly managed store.

src/email.test.ts
import {
  capturePlugin,
  createEmailCaptureStore,
} from "@opencoredev/email-sdk/plugins/capture";

const store = createEmailCaptureStore();
const plugin = capturePlugin(store);

store.clear();

Rename the client property

src/email.ts
const email = createEmailClient({
  adapters: [adapter],
  plugins: [capturePlugin({ clientKey: "emailEvents" })],
});

email.emailEvents.clear();

The plugin rejects a client key that collides with a built-in client property or another extension.

Test email behavior

Assert messages, retries, fallback, and failures without network calls.

Plugin API

See captured event and extension types.

On this page