Skip to main content

Overview

This page documents all TypeScript types and interfaces provided by the Nuxt Lettermint module. These types are automatically available when using the module in your Nuxt application.

Module Configuration

ModuleOptions

Configuration options for the Lettermint module in nuxt.config.ts.
export interface ModuleOptions {
  /**
   * Lettermint API key
   * Can also be set via NUXT_LETTERMINT_API_KEY environment variable
   */
  apiKey?: string
  
  /**
   * Whether to automatically register the /api/lettermint/send endpoint
   * @default true
   */
  autoEndpoint?: boolean
}

Usage

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-lettermint'],
  lettermint: {
    apiKey: 'your-api-key',
    autoEndpoint: true
  }
})

Client-Side Types

LettermintEmailOptions

Options for sending an email using the client-side useLettermint composable.
export interface LettermintEmailOptions {
  /** Sender email address */
  from: string
  
  /** Recipient email address(es) */
  to: string | string[]
  
  /** Email subject line */
  subject: string
  
  /** Plain text content */
  text?: string
  
  /** HTML content */
  html?: string
  
  /** Carbon copy recipient(s) */
  cc?: string | string[]
  
  /** Blind carbon copy recipient(s) */
  bcc?: string | string[]
  
  /** Reply-to address(es) */
  replyTo?: string | string[]
  
  /** Custom email headers */
  headers?: Record<string, string>
  
  /** Custom metadata for tracking */
  metadata?: Record<string, unknown>
  
  /** Tags for categorization */
  tags?: string[]
  
  /** File attachments */
  attachments?: Array<{
    filename: string
    content: string | Buffer
    contentType?: string
  }>
}

LettermintResponse

Response object returned when sending an email from the client.
export interface LettermintResponse {
  /** Whether the email was sent successfully */
  success: boolean
  
  /** Unique message identifier (present on success) */
  messageId?: string
  
  /** Status of the email */
  status?: string
  
  /** Error message (present on failure) */
  error?: string
}

UseLettermintReturn

Return type of the client-side useLettermint() composable.
export interface UseLettermintReturn {
  /** Send an email */
  send: (options: LettermintEmailOptions) => Promise<LettermintResponse>
  
  /** Reactive state: whether an email is currently being sent */
  sending: Ref<boolean>
  
  /** Reactive state: last error message */
  error: Ref<string | null>
  
  /** Reactive state: last message ID */
  lastMessageId: Ref<string | null>
}

Server-Side Types

SendEmailOptions

Options for the server-side sendEmail() utility function.
export interface SendEmailOptions {
  /** Sender email address */
  from: string
  
  /** Recipient email address(es) */
  to: string | string[]
  
  /** Email subject line */
  subject: string
  
  /** Plain text content */
  text?: string
  
  /** HTML content */
  html?: string
  
  /** Carbon copy recipient(s) */
  cc?: string | string[]
  
  /** Blind carbon copy recipient(s) */
  bcc?: string | string[]
  
  /** Reply-to address(es) */
  replyTo?: string | string[]
  
  /** Custom email headers */
  headers?: Record<string, string>
  
  /** Custom metadata for tracking */
  metadata?: Record<string, unknown>
  
  /** Tags for categorization */
  tags?: string[]
  
  /** File attachments */
  attachments?: Array<{
    filename: string
    content: string | Buffer
    contentType?: string
  }>
}
SendEmailOptions has the same structure as LettermintEmailOptions. They are defined separately because they are used in different contexts (server vs. client).

Extended Types (from types/index.ts)

The following types are defined in src/runtime/types/index.ts for internal use and compatibility with the Lettermint SDK. They are not directly used for module configuration.

LettermintEmailAddress

Structured email address with optional display name.
export interface LettermintEmailAddress {
  /** Email address */
  email: string
  
  /** Display name */
  name?: string
}
This type is defined for compatibility with the Lettermint SDK but is not currently supported by the useLettermint() composable or sendEmail() utility. Use plain string email addresses instead.

LettermintAttachment

File attachment structure.
export interface LettermintAttachment {
  /** File name as it will appear to recipients */
  filename: string
  
  /** File content (base64 string or Buffer) */
  content: string | Buffer
  
  /** MIME type of the file */
  contentType?: string
}

LettermintSendResponse

Raw response from the Lettermint API.
export interface LettermintSendResponse {
  /** Unique message identifier */
  message_id: string
  
  /** Status of the email */
  status: 'pending' | 'sent' | 'failed'
}

LettermintApiResponse

Normalized API response used internally.
export interface LettermintApiResponse {
  /** Whether the request was successful */
  success: boolean
  
  /** Unique message identifier */
  messageId?: string
  
  /** Status of the email */
  status?: string
  
  /** Error message if failed */
  error?: string
}

LettermintError

Error object structure.
export interface LettermintError {
  /** HTTP status code */
  statusCode: number
  
  /** Error message */
  statusMessage: string
  
  /** Additional error data */
  data?: unknown
}

Runtime Config Types

Module Augmentation

The module extends Nuxt’s runtime config types:
declare module '@nuxt/schema' {
  interface RuntimeConfig {
    lettermint: {
      apiKey: string
    }
  }
  
  interface PublicRuntimeConfig {
    lettermint?: Record<string, never>
  }
}
This allows TypeScript to recognize the lettermint configuration:
// In server context
const config = useRuntimeConfig()
const apiKey = config.lettermint.apiKey // ✅ Type-safe

Type Usage Examples

<script setup lang="ts">
// useLettermint is auto-imported by Nuxt
const { send } = useLettermint()

// Types are inferred automatically
const emailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello',
  html: '<p>Hello World</p>'
}

const response = await send(emailOptions)
</script>

Type Imports

Most types are available automatically through Nuxt’s auto-import system. Explicit imports are only needed in specific cases.

Module Configuration Types

// In nuxt.config.ts
import type { ModuleOptions } from 'nuxt-lettermint'

Explicit Type Imports (Optional)

If you need to explicitly import types for type annotations, you can use:
// The composable and utilities are auto-imported
// But you can import their types for explicit annotations
const { send } = useLettermint()
const result = await sendEmail({ /* ... */ })

// Types are inferred automatically from the functions
// No explicit imports needed in most cases

Build docs developers (and LLMs) love