@mailiam/shared

v0.2.0

Published

Shared types and utilities for Mailiam SDK

Downloads

273

Readme

@mailiam/shared

Shared types, errors, constants, and utilities for Mailiam SDK packages.

This package is used internally by @mailiam/node and @mailiam/client. You typically don't need to install this directly unless you're building custom integrations.

Installation

npm install @mailiam/shared

Exports

Types

  • SendEmailRequest - Email send request structure
  • SendEmailResponse - Email send response structure
  • SendBatchRequest - Batch send request structure
  • SendBatchResponse - Batch send response structure
  • BatchEmailResult - Individual batch result
  • EmailAddress - Email address type
  • FormSubmission - Form submission data
  • FormSubmissionResponse - Form submission response
  • MailiamErrorResponse - API error response
  • ApiKeyType - API key types
  • RateLimitInfo - Rate limit information

Error Classes

  • MailiamError - Base error class
  • AuthenticationError - Authentication failure
  • RateLimitError - Rate limit exceeded
  • ValidationError - Request validation failure
  • NetworkError - Network request failure
  • ApiError - General API error

Constants

  • DEFAULT_API_BASE_URL - Default API URL
  • API_VERSION - Current API version
  • DEFAULT_TIMEOUT - Default request timeout
  • DEFAULT_RETRY_CONFIG - Default retry configuration
  • HTTP_STATUS - HTTP status code constants
  • ENDPOINTS - API endpoint paths
  • HEADERS - Header name constants
  • USER_AGENT - SDK user agent

Utilities

  • isValidEmail() - Validate email format
  • normalizeEmailAddress() - Normalize email to string
  • normalizeEmailAddresses() - Normalize array of emails
  • validateEmailContent() - Validate text/html content
  • sleep() - Promise-based sleep
  • calculateBackoff() - Calculate exponential backoff
  • isRetryableStatusCode() - Check if status is retryable
  • isNetworkError() - Check if error is network-related

Usage

import {
  type SendEmailRequest,
  AuthenticationError,
  DEFAULT_API_BASE_URL,
  isValidEmail
} from '@mailiam/shared';

// Use types
const request: SendEmailRequest = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Test',
  html: '<p>Test</p>'
};

// Use utilities
if (isValidEmail('[email protected]')) {
  console.log('Valid email');
}

// Use errors
throw new AuthenticationError('Invalid API key');

License

MIT