@z_06/relay-temp-mail 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/cf-api.ts","../src/http.ts","../src/parser.ts","../src/relay-api.ts","../src/client.ts"],"sourcesContent":["/**\n * relay-temp-mail\n * \n * A JavaScript/TypeScript package for managing Firefox Relay email aliases\n * and retrieving temporary emails via the CloudFlare temp email API.\n */\n\n// Re-export types from types.ts\nexport type {\n RelayConfig,\n RelayAlias,\n Email,\n ParsedEmail,\n ListAliasesOptions,\n GetEmailsOptions,\n CFMailsResponse,\n RelayAddressesResponse,\n CreateAliasResponse,\n} from './types.js';\n\n// Re-export error classes from errors.ts\nexport {\n RelayTempMailError,\n NetworkError,\n AuthError,\n NotFoundError,\n ParseError,\n RateLimitError,\n} from './errors.js';\n\n// Re-export main class from client.ts\nexport { RelayClient } from './client.js';\n","/**\n * Custom error classes for the relay-temp-mail package.\n *\n * These errors provide structured error information including error codes,\n * HTTP status codes, and response data for better error handling.\n */\n\n/**\n * Base error class for all relay-temp-mail errors.\n *\n * Extends the built-in Error class with additional context about the error,\n * including an error code for programmatic error handling and optional\n * response data from the API.\n */\nexport class RelayTempMailError extends Error {\n /**\n * Machine-readable error code for programmatic error handling.\n * Examples: 'NETWORK_ERROR', 'AUTH_ERROR', 'NOT_FOUND'\n */\n code: string;\n\n /**\n * HTTP status code associated with this error, if applicable.\n */\n statusCode?: number;\n\n /**\n * Raw response data from the API, if available.\n */\n response?: any;\n\n /**\n * Creates a new RelayTempMailError instance.\n *\n * @param message - Human-readable error message describing the error.\n * @param code - Machine-readable error code (e.g., 'UNKNOWN_ERROR').\n * @param statusCode - Optional HTTP status code associated with the error.\n * @param response - Optional raw response data from the API.\n */\n constructor(\n message: string,\n code: string,\n statusCode?: number,\n response?: any\n ) {\n super(message);\n this.name = this.constructor.name;\n this.code = code;\n this.statusCode = statusCode;\n this.response = response;\n\n // Maintains proper stack trace in V8 environments\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Error for network-related failures.\n *\n * Thrown when there is a problem establishing or maintaining a network\n * connection, such as DNS resolution failures, connection timeouts,\n * or network unreachability.\n */\nexport class NetworkError extends RelayTempMailError {\n code = 'NETWORK_ERROR' as const;\n\n constructor(message: string, response?: any) {\n super(message, 'NETWORK_ERROR', undefined, response);\n }\n}\n\n/**\n * Error for authentication and authorization failures.\n *\n * Thrown when API requests fail due to invalid or missing credentials\n * (401) or when the authenticated user lacks permission for the\n * requested operation (403).\n */\nexport class AuthError extends RelayTempMailError {\n code = 'AUTH_ERROR' as const;\n\n constructor(message: string, statusCode?: number, response?: any) {\n super(message, 'AUTH_ERROR', statusCode, response);\n }\n}\n\n/**\n * Error for resource not found errors.\n *\n * Thrown when the requested resource does not exist (404 response),\n * such as when trying to access a non-existent alias or email.\n */\nexport class NotFoundError extends RelayTempMailError {\n code = 'NOT_FOUND' as const;\n\n constructor(message: string, response?: any) {\n super(message, 'NOT_FOUND', 404, response);\n }\n}\n\n/**\n * Error for MIME message parsing failures.\n *\n * Thrown when there is an error parsing email MIME content,\n * such as malformed headers or invalid message structure.\n */\nexport class ParseError extends RelayTempMailError {\n code = 'PARSE_ERROR' as const;\n\n constructor(message: string, response?: any) {\n super(message, 'PARSE_ERROR', undefined, response);\n }\n}\n\n/**\n * Error for rate limiting responses.\n *\n * Thrown when the API rate limit has been exceeded (429 response).\n * The client should wait and retry the request after the indicated\n * cooldown period.\n */\nexport class RateLimitError extends RelayTempMailError {\n code = 'RATE_LIMIT_ERROR' as const;\n\n constructor(message: string, response?: any) {\n super(message, 'RATE_LIMIT_ERROR', 429, response);\n }\n}\n","/**\n * CloudFlare temp email API client.\n *\n * This module provides the CFEmailClient class for interacting with the\n * CloudFlare temp email API to retrieve emails.\n */\n\nimport { Email, CFMailsResponse } from './types.js';\nimport { AuthError, NetworkError, NotFoundError, RateLimitError, RelayTempMailError } from './errors.js';\n\n/**\n * HTTP client interface for making requests.\n *\n * This interface allows for dependency injection, making testing easier\n * by allowing mock implementations.\n */\nexport interface HttpClient {\n /**\n * Makes an HTTP GET request.\n *\n * @param url - The URL to request\n * @param options - Request options including headers\n * @returns The response body as unknown\n */\n get(url: string, options?: { headers?: Record<string, string> }): Promise<unknown>;\n}\n\n/**\n * Default HTTP client implementation using fetch.\n */\nclass DefaultHttpClient implements HttpClient {\n async get(url: string, options?: { headers?: Record<string, string> }): Promise<unknown> {\n const response = await fetch(url, {\n method: 'GET',\n headers: options?.headers,\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n throw new RelayTempMailError(\n `HTTP ${response.status}: ${errorBody}`,\n 'HTTP_ERROR',\n response.status,\n errorBody\n );\n }\n\n return response.json();\n }\n}\n\n/**\n * Raw email response from CF API (snake_case properties).\n */\ninterface CFRawEmail {\n id: number;\n message_id: string;\n source: string;\n address: string;\n raw: string;\n metadata: any | null;\n created_at: string;\n}\n\n/**\n * Raw API response structure.\n */\ninterface CFRawResponse {\n results: CFRawEmail[];\n count: number;\n}\n\n/**\n * Client for interacting with the CloudFlare temp email API.\n *\n * This client handles authentication, request formatting, and response\n * mapping from the CF API's snake_case to camelCase.\n */\nexport class CFEmailClient {\n private readonly apiUrl: string;\n private readonly token: string;\n private readonly httpClient: HttpClient;\n\n /**\n * Creates a new CFEmailClient instance.\n *\n * @param apiUrl - Base URL for the CF temp email API\n * @param token - Bearer token for authentication\n * @param httpClient - Optional HTTP client (defaults to fetch-based implementation)\n */\n constructor(apiUrl: string, token: string, httpClient?: HttpClient) {\n this.apiUrl = apiUrl;\n this.token = token;\n this.httpClient = httpClient ?? new DefaultHttpClient();\n }\n\n /**\n * Retrieves emails from the CF temp email API.\n *\n * @param limit - Maximum number of emails to return (default: 20)\n * @param offset - Pagination offset (default: 0)\n * @returns Promise resolving to an array of Email objects\n * @throws AuthError if authentication fails\n * @throws NetworkError if there's a network problem\n * @throws NotFoundError if the endpoint doesn't exist\n * @throws RateLimitError if rate limited\n */\n async getMails(limit: number = 20, offset: number = 0): Promise<Email[]> {\n const url = new URL(`${this.apiUrl}/api/mails`);\n url.searchParams.set('limit', String(limit));\n url.searchParams.set('offset', String(offset));\n\n const headers: Record<string, string> = {\n 'Authorization': `Bearer ${this.token}`,\n };\n\n try {\n const response = await this.httpClient.get(url.toString(), { headers });\n return this.mapCFResponse(response as CFRawResponse);\n } catch (error) {\n throw this.handleError(error);\n }\n }\n\n /**\n * Maps the raw CF API response to the Email interface.\n *\n * Converts snake_case property names to camelCase.\n *\n * @param response - Raw response from CF API\n * @returns Array of Email objects\n */\n private mapCFResponse(response: CFRawResponse): Email[] {\n return response.results.map((item): Email => ({\n id: item.id,\n messageId: item.message_id,\n source: item.source,\n address: item.address,\n raw: item.raw,\n metadata: item.metadata,\n createdAt: item.created_at,\n }));\n }\n\n /**\n * Handles errors from HTTP requests.\n *\n * Maps HTTP errors to appropriate error classes.\n *\n * @param error - The caught error\n * @returns Appropriate RelayTempMailError subclass\n */\n private handleError(error: unknown): RelayTempMailError {\n if (error instanceof RelayTempMailError) {\n const statusCode = error.statusCode;\n\n if (statusCode === 401 || statusCode === 403) {\n return new AuthError(error.message, statusCode, error.response);\n }\n if (statusCode === 404) {\n return new NotFoundError(error.message, error.response);\n }\n if (statusCode === 429) {\n return new RateLimitError(error.message, error.response);\n }\n\n return error;\n }\n\n if (error instanceof TypeError && error.message.includes('fetch')) {\n return new NetworkError(error.message);\n }\n\n if (error instanceof Error) {\n return new NetworkError(error.message);\n }\n\n return new RelayTempMailError(\n 'Unknown error occurred',\n 'UNKNOWN_ERROR',\n undefined,\n error\n );\n }\n}\n","/**\n * HTTP client utilities for the relay-temp-mail package.\n *\n * This module provides a configurable HTTP client with timeout support,\n * automatic retry logic, and proper error classification for API responses.\n */\n\nimport {\n RelayTempMailError,\n NetworkError,\n AuthError,\n NotFoundError,\n RateLimitError,\n} from './errors';\n\n/**\n * Options for individual HTTP requests.\n */\nexport interface RequestOptions {\n /** Custom headers to include in the request */\n headers?: Record<string, string>;\n\n /** Request body (will be JSON serialized) */\n body?: unknown;\n\n /** Request timeout in milliseconds (overrides client default) */\n timeout?: number;\n\n /** Number of retries on failure (overrides client default) */\n retries?: number;\n}\n\n/**\n * HTTP client for making requests to the relay-temp-mail API.\n *\n * Provides a configurable base URL with timeout, retry, and automatic\n * JSON parsing capabilities.\n */\nexport class HttpClient {\n private baseUrl: string;\n private defaultTimeout: number;\n private defaultRetries: number;\n\n /**\n * Creates a new HttpClient instance.\n *\n * @param baseUrl - Base URL for all requests (e.g., 'https://api.example.com')\n * @param defaultTimeout - Default timeout in milliseconds (default: 30000)\n * @param defaultRetries - Default number of retries on failure (default: 0)\n */\n constructor(\n baseUrl: string,\n defaultTimeout: number = 30000,\n defaultRetries: number = 0\n ) {\n this.baseUrl = baseUrl.replace(/\\/$/, ''); // Remove trailing slash\n this.defaultTimeout = defaultTimeout;\n this.defaultRetries = defaultRetries;\n }\n\n /**\n * Makes an HTTP request to the specified path.\n *\n * @param method - HTTP method (GET, POST, PUT, DELETE, etc.)\n * @param path - API path (will be appended to baseUrl)\n * @param options - Optional request configuration\n * @returns Promise resolving to the parsed JSON response\n */\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const timeout = options.timeout ?? this.defaultTimeout;\n const retries = options.retries ?? this.defaultRetries;\n\n let lastError: RelayTempMailError | Error | undefined;\n\n for (let attempt = 0; attempt <= retries; attempt++) {\n try {\n const response = await this.executeRequest(method, path, options, timeout);\n return await this.handleResponse<T>(response);\n } catch (error) {\n lastError = error as Error;\n\n // Check if we should retry\n if (attempt < retries && this.shouldRetry(error)) {\n const delay = 1000 * Math.pow(2, attempt);\n await this.sleep(delay);\n continue;\n }\n\n // Don't retry, throw the classified error\n if (error instanceof RelayTempMailError) {\n throw error;\n }\n\n // Classify the error if not already classified\n throw this.classifyError(error);\n }\n }\n\n // This should never be reached, but just in case\n throw lastError || new NetworkError('Request failed');\n }\n\n /**\n * Executes the actual HTTP request with timeout support.\n */\n private async executeRequest(\n method: string,\n path: string,\n options: RequestOptions,\n timeout: number\n ): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const fetchOptions: RequestInit = {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n signal: controller.signal,\n };\n\n if (options.body !== undefined) {\n fetchOptions.body = JSON.stringify(options.body);\n }\n\n const response = await fetch(url, fetchOptions);\n return response;\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n /**\n * Handles the HTTP response, parsing JSON and checking for errors.\n */\n private async handleResponse<T>(response: Response): Promise<T> {\n if (!response.ok) {\n throw this.classifyError(new Error(`HTTP ${response.status}`), response);\n }\n\n const text = await response.text();\n\n // Handle empty responses\n if (!text) {\n return {} as T;\n }\n\n return JSON.parse(text) as T;\n }\n\n /**\n * Classifies an error based on the error type and HTTP response.\n */\n private classifyError(error: unknown, response?: Response): RelayTempMailError {\n // Network errors (fetch failed)\n if (error instanceof Error && error.name === 'AbortError') {\n return new NetworkError('Request timed out');\n }\n\n if (error instanceof TypeError && error.message.includes('fetch')) {\n return new NetworkError('Network request failed');\n }\n\n if (error instanceof Error && error.message.includes('Failed to fetch')) {\n return new NetworkError('Network request failed');\n }\n\n // HTTP status-based classification\n if (response) {\n const status = response.status;\n\n if (status === 401 || status === 403) {\n return new AuthError(\n `Authentication failed: ${response.statusText}`,\n status\n );\n }\n\n if (status === 404) {\n return new NotFoundError(`Resource not found: ${response.statusText}`);\n }\n\n if (status === 429) {\n return new RateLimitError(\n `Rate limit exceeded: ${response.statusText}`\n );\n }\n\n if (status >= 500) {\n return new NetworkError(\n `Server error: ${response.statusText}`,\n status\n );\n }\n }\n\n // Default error\n if (error instanceof Error) {\n return new RelayTempMailError(\n error.message,\n 'REQUEST_ERROR',\n response?.status\n );\n }\n\n return new RelayTempMailError('Unknown error occurred', 'UNKNOWN_ERROR');\n }\n\n /**\n * Determines if a request should be retried based on the error.\n */\n private shouldRetry(error: unknown): boolean {\n if (error instanceof NetworkError) {\n return true;\n }\n\n if (error instanceof RelayTempMailError && error.statusCode) {\n return error.statusCode >= 500;\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n return true;\n }\n if (error instanceof TypeError && error.message.includes('fetch')) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Sleep for a specified duration.\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","/**\n * MIME email parser for extracting Firefox Relay alias information.\n */\nimport type { ParsedEmail } from './types.js';\n\nconst MOZMAIL_PATTERN = /[a-zA-Z0-9]+@mozmail\\.com/g;\nconst ENCODED_WORD_PATTERN = /=\\?([^?]+)\\?([BbQq])\\?([^?]*)\\?=/g;\n\n/**\n * EmailParser class for parsing MIME email content.\n */\nexport class EmailParser {\n parseEmail(raw: string): ParsedEmail {\n const headers = this.parseHeaders(raw);\n const toHeader = headers.get('to') || '';\n const fromHeader = headers.get('from') || '';\n const messageIdHeader = headers.get('message-id') || '';\n const relayAlias = this.extractRelayAlias(raw);\n \n return {\n id: 0,\n messageId: this.extractMessageId(messageIdHeader),\n source: this.extractEmailAddress(fromHeader),\n address: this.extractEmailAddress(toHeader),\n raw,\n metadata: null,\n createdAt: new Date().toISOString(),\n relayAlias: relayAlias || undefined,\n };\n }\n\n extractRelayAlias(raw: string): string | null {\n try {\n const headers = this.parseHeaders(raw);\n const toHeader = headers.get('to');\n if (!toHeader) return null;\n \n const decodedTo = this.decodeHeader(toHeader);\n const matches = decodedTo.match(MOZMAIL_PATTERN);\n return matches && matches.length > 0 ? matches[0].toLowerCase() : null;\n } catch {\n return null;\n }\n }\n\n private parseHeaders(raw: string): Map<string, string> {\n const headers = new Map<string, string>();\n const headerEnd = raw.indexOf('\\r\\n\\r\\n');\n const headerSection = headerEnd === -1 ? raw : raw.substring(0, headerEnd);\n const lines = headerSection.split(/\\r?\\n/);\n let currentHeader: string | null = null;\n let currentValue = '';\n \n for (const line of lines) {\n if (/^\\s/.test(line)) {\n if (currentHeader) currentValue += ' ' + line.trim();\n } else {\n if (currentHeader) headers.set(currentHeader, currentValue);\n const colonIndex = line.indexOf(':');\n if (colonIndex > 0) {\n currentHeader = line.substring(0, colonIndex).toLowerCase().trim();\n currentValue = line.substring(colonIndex + 1).trim();\n } else {\n currentHeader = null;\n currentValue = '';\n }\n }\n }\n if (currentHeader) headers.set(currentHeader, currentValue);\n return headers;\n }\n\n private decodeHeader(value: string): string {\n return value.replace(ENCODED_WORD_PATTERN, (_, charset, encoding, encoded) => {\n try {\n if (encoding.toUpperCase() === 'Q') {\n return this.decodeQuotedPrintable(encoded);\n } else if (encoding.toUpperCase() === 'B') {\n return this.decodeBase64(encoded);\n }\n return encoded;\n } catch {\n return encoded;\n }\n });\n }\n\n private decodeQuotedPrintable(encoded: string): string {\n // RFC 2047: underscores represent spaces in encoded-word\n let decoded = encoded.replace(/_/g, ' ');\n decoded = decoded.replace(/=([0-9A-Fa-f]{2})/g, (_, hex) => \n String.fromCharCode(parseInt(hex, 16))\n );\n return decoded;\n }\n\n private decodeBase64(encoded: string): string {\n return Buffer.from(encoded, 'base64').toString('utf-8');\n }\n\n private extractEmailAddress(headerValue: string): string {\n if (!headerValue) return '';\n const decoded = this.decodeHeader(headerValue);\n const bracketMatch = decoded.match(/<([^>]+)>/);\n if (bracketMatch) return bracketMatch[1].trim().toLowerCase();\n const emailMatch = decoded.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/);\n return emailMatch ? emailMatch[0].toLowerCase() : decoded.trim().toLowerCase();\n }\n\n private extractMessageId(headerValue: string): string {\n if (!headerValue) return `<generated-${Date.now()}@relay-temp-mail>`;\n const cleaned = headerValue.replace(/[<>]/g, '').trim();\n return `<${cleaned}>`;\n }\n}\n","import { HttpClient } from './http';\nimport { RelayAlias } from './types';\n\ninterface RawAliasResponse {\n id: number;\n address: string;\n full_address: string;\n enabled: boolean;\n created_at: string;\n domain: number;\n mask_type: string;\n description?: string;\n num_forwarded?: number;\n num_blocked?: number;\n last_modified_at?: string;\n last_used_at?: string | null;\n num_level_one_trackers_blocked?: number;\n num_replied?: number;\n num_spam?: number;\n block_list_emails?: boolean;\n generated_for?: string;\n used_on?: string | null;\n}\n\nexport class RelayAPIClient {\n private csrfToken: string;\n private sessionId: string;\n private httpClient: HttpClient;\n\n constructor(\n csrfToken: string,\n sessionId: string,\n httpClient?: HttpClient\n ) {\n this.csrfToken = csrfToken;\n this.sessionId = sessionId;\n this.httpClient = httpClient ?? new HttpClient('https://relay.firefox.com');\n }\n\n private getAuthHeaders(): Record<string, string> {\n return {\n 'Origin': 'https://relay.firefox.com',\n 'Referer': 'https://relay.firefox.com/accounts/profile/?',\n 'Accept': 'application/json',\n 'X-CSRFToken': this.csrfToken,\n 'Cookie': `sessionid=${this.sessionId}; csrftoken=${this.csrfToken}`,\n };\n }\n\n async getAliases(): Promise<RelayAlias[]> {\n const response = await this.httpClient.request<RawAliasResponse[]>(\n 'GET',\n '/api/v1/relayaddresses/',\n { headers: this.getAuthHeaders() }\n );\n\n return response.map((item) => this.mapAliasResponse(item));\n }\n\n async createAlias(): Promise<RelayAlias> {\n const response = await this.httpClient.request<RawAliasResponse>(\n 'POST',\n '/api/v1/relayaddresses/',\n {\n headers: this.getAuthHeaders(),\n body: { enabled: true },\n }\n );\n\n return this.mapAliasResponse(response);\n }\n\n async deleteAlias(id: number): Promise<void> {\n await this.httpClient.request<void>(\n 'DELETE',\n `/api/v1/relayaddresses/${id}/`,\n { headers: this.getAuthHeaders() }\n );\n }\n\n private mapAliasResponse(data: RawAliasResponse): RelayAlias {\n return {\n id: data.id,\n address: data.address,\n fullAddress: data.full_address,\n enabled: data.enabled,\n createdAt: data.created_at,\n domain: data.domain,\n maskType: data.mask_type,\n description: data.description,\n numForwarded: data.num_forwarded,\n numBlocked: data.num_blocked,\n lastModifiedAt: data.last_modified_at,\n lastUsedAt: data.last_used_at,\n numLevelOneTrackersBlocked: data.num_level_one_trackers_blocked,\n numReplied: data.num_replied,\n numSpam: data.num_spam,\n blockListEmails: data.block_list_emails,\n generatedFor: data.generated_for,\n usedOn: data.used_on,\n };\n }\n}\n","/**\n * Main client for the relay-temp-mail package.\n *\n * This module provides the RelayClient class which integrates all components\n * (CF API, Relay API, Parser) into a unified interface.\n */\n\nimport { CFEmailClient } from './cf-api.js';\nimport { HttpClient } from './http.js';\nimport { EmailParser } from './parser.js';\nimport { RelayAPIClient } from './relay-api.js';\nimport type {\n RelayConfig,\n RelayAlias,\n ParsedEmail,\n GetEmailsOptions,\n} from './types.js';\n\n/**\n * Main client for interacting with Firefox Relay and CloudFlare temp email services.\n *\n * RelayClient integrates all components to provide a unified interface for:\n * - Managing Firefox Relay email aliases\n * - Retrieving and parsing emails from CloudFlare temp email API\n *\n * @example\n * ```typescript\n * const client = new RelayClient({\n * csrfToken: '...',\n * sessionId: '...',\n * cfApiUrl: 'https://...',\n * cfToken: '...',\n * timeout: 30000\n * });\n *\n * const aliases = await client.listAliases();\n * const emails = await client.getEmails('alias@mozmail.com', { limit: 10 });\n * ```\n */\nexport class RelayClient {\n private readonly relayApi: RelayAPIClient;\n private readonly cfApi: CFEmailClient;\n private readonly parser: EmailParser;\n\n /**\n * Creates a new RelayClient instance.\n *\n * @param config - Configuration object containing authentication tokens and API URLs\n */\n constructor(config: RelayConfig) {\n const timeout = config.timeout ?? 30000;\n\n const relayHttpClient = new HttpClient('https://relay.firefox.com', timeout);\n this.relayApi = new RelayAPIClient(\n config.csrfToken,\n config.sessionId,\n relayHttpClient\n );\n\n this.cfApi = new CFEmailClient(config.cfApiUrl, config.cfToken);\n this.parser = new EmailParser();\n }\n\n /**\n * Lists all Firefox Relay email aliases.\n *\n * @returns Promise resolving to an array of RelayAlias objects\n * @throws AuthError if authentication fails\n * @throws NetworkError if there's a network problem\n */\n async listAliases(): Promise<RelayAlias[]> {\n return this.relayApi.getAliases();\n }\n\n /**\n * Creates a new Firefox Relay email alias.\n *\n * @returns Promise resolving to the newly created RelayAlias\n * @throws AuthError if authentication fails\n * @throws NetworkError if there's a network problem\n */\n async createAlias(): Promise<RelayAlias> {\n return this.relayApi.createAlias();\n }\n\n /**\n * Deletes a Firefox Relay email alias.\n *\n * @param id - The ID of the alias to delete\n * @throws AuthError if authentication fails\n * @throws NotFoundError if the alias doesn't exist\n * @throws NetworkError if there's a network problem\n */\n async deleteAlias(id: number): Promise<void> {\n return this.relayApi.deleteAlias(id);\n }\n\n /**\n * Retrieves and parses emails from the CloudFlare temp email API.\n *\n * If aliasAddress is provided, only emails sent to that address are returned.\n *\n * @param aliasAddress - Optional email address to filter by\n * @param options - Query options for pagination\n * @returns Promise resolving to an array of ParsedEmail objects\n * @throws AuthError if authentication fails\n * @throws NetworkError if there's a network problem\n */\n async getEmails(\n aliasAddress?: string,\n options?: GetEmailsOptions\n ): Promise<ParsedEmail[]> {\n const limit = options?.limit ?? 20;\n const offset = options?.offset ?? 0;\n\n const emails = await this.cfApi.getMails(limit, offset);\n\n const parsedEmails: ParsedEmail[] = emails.map((email) => {\n const parsed = this.parser.parseEmail(email.raw);\n return {\n ...parsed,\n id: email.id,\n messageId: email.messageId,\n source: email.source,\n address: email.address,\n createdAt: email.createdAt,\n metadata: email.metadata,\n };\n });\n\n if (aliasAddress) {\n const normalizedAlias = aliasAddress.toLowerCase();\n return parsedEmails.filter(\n (email) => email.relayAlias?.toLowerCase() === normalizedAlias\n );\n }\n\n return parsedEmails;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcO,IAAM,qBAAN,cAAiC,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyB5C,YACE,SACA,MACA,YACA,UACA;AACA,UAAM,OAAO;AACb,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B;AAC3C,WAAO,KAAK,SAAS,YAAY,EAAE;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,UACJ,cACA,SACwB;AACxB,UAAM,QAAQ,SAAS,SAAS;AAChC,UAAM,SAAS,SAAS,UAAU;AAElC,UAAM,SAAS,MAAM,KAAK,MAAM,SAAS,OAAO,MAAM;AAEtD,UAAM,eAA8B,OAAO,IAAI,CAAC,UAAU;AACxD,YAAM,SAAS,KAAK,OAAO,WAAW,MAAM,GAAG;AAC/C,aAAO;AAAA,QACL,GAAG;AAAA,QACH,IAAI,MAAM;AAAA,QACV,WAAW,MAAM;AAAA,QACjB,QAAQ,MAAM;AAAA,QACd,SAAS,MAAM;AAAA,QACf,WAAW,MAAM;AAAA,QACjB,UAAU,MAAM;AAAA,MAClB;AAAA,IACF,CAAC;AAED,QAAI,cAAc;AAChB,YAAM,kBAAkB,aAAa,YAAY;AACjD,aAAO,aAAa;AAAA,QAClB,CAAC,UAAU,MAAM,YAAY,YAAY,MAAM;AAAA,MACjD;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,317 @@
1
+ /**
2
+ * TypeScript type definitions for the relay-temp-mail package.
3
+ *
4
+ * These interfaces define the core data structures used throughout the package,
5
+ * ensuring type safety when interacting with the Firefox Relay and CF temp email APIs.
6
+ */
7
+ /**
8
+ * Configuration interface for initializing the RelayClient.
9
+ *
10
+ * This interface contains all required authentication tokens and API URLs
11
+ * needed to communicate with both Firefox Relay and CloudFlare temp email services.
12
+ */
13
+ interface RelayConfig {
14
+ /** CSRF token for Firefox Relay API authentication */
15
+ csrfToken: string;
16
+ /** Session ID for Firefox Relay API authentication */
17
+ sessionId: string;
18
+ /** Base URL for the CloudFlare temp email API */
19
+ cfApiUrl: string;
20
+ /** Bearer token for CloudFlare temp email API authentication */
21
+ cfToken: string;
22
+ /** Optional timeout for HTTP requests in milliseconds */
23
+ timeout?: number;
24
+ }
25
+ /**
26
+ * Represents a Firefox Relay email alias.
27
+ *
28
+ * This interface maps to the JSON structure returned by the Firefox Relay API
29
+ * when listing or creating email aliases.
30
+ *
31
+ * Note: Property names use camelCase even though the API returns snake_case.
32
+ * The package will handle the conversion internally.
33
+ */
34
+ interface RelayAlias {
35
+ /** Unique identifier for the alias */
36
+ id: number;
37
+ /** The alias username (part before @) */
38
+ address: string;
39
+ /** Complete email address including domain */
40
+ fullAddress: string;
41
+ /** Whether the alias is currently enabled for receiving emails */
42
+ enabled: boolean;
43
+ /** ISO timestamp when the alias was created */
44
+ createdAt: string;
45
+ /** Domain identifier (2 for mozmail.com) */
46
+ domain: number;
47
+ /** Type of alias generation (e.g., "random") */
48
+ maskType: string;
49
+ /** Optional description for the alias */
50
+ description?: string;
51
+ /** Number of emails forwarded through this alias */
52
+ numForwarded?: number;
53
+ /** Number of emails blocked by this alias */
54
+ numBlocked?: number;
55
+ /** Optional timestamp when alias was last modified */
56
+ lastModifiedAt?: string;
57
+ /** Optional timestamp when alias was last used */
58
+ lastUsedAt?: string | null;
59
+ /** Number of level one trackers blocked */
60
+ numLevelOneTrackersBlocked?: number;
61
+ /** Number of replies sent from this alias */
62
+ numReplied?: number;
63
+ /** Number of spam emails marked */
64
+ numSpam?: number;
65
+ /** Whether the alias blocks list emails */
66
+ blockListEmails?: boolean;
67
+ /** Service the alias was generated for (optional) */
68
+ generatedFor?: string;
69
+ /** Where the alias is used (optional) */
70
+ usedOn?: string | null;
71
+ }
72
+ /**
73
+ * Email object returned by the CloudFlare temp email API.
74
+ *
75
+ * This interface represents the raw email data as returned from the CF API,
76
+ * including the complete MIME message in the `raw` field.
77
+ */
78
+ interface Email {
79
+ /** Unique identifier for the email */
80
+ id: number;
81
+ /** Original message ID from the email headers */
82
+ messageId: string;
83
+ /** Source email address that sent this email */
84
+ source: string;
85
+ /** Destination email address that received this email */
86
+ address: string;
87
+ /** Raw MIME content of the email */
88
+ raw: string;
89
+ /** Metadata associated with the email (can be any type) */
90
+ metadata: any | null;
91
+ /** ISO timestamp when the email was created/received */
92
+ createdAt: string;
93
+ }
94
+ /**
95
+ * Email object with parsed alias information.
96
+ *
97
+ * This interface extends the base Email interface and adds the parsed
98
+ * Firefox Relay alias information extracted from the MIME content.
99
+ */
100
+ interface ParsedEmail extends Email {
101
+ /**
102
+ * The Firefox Relay alias that this email was sent to.
103
+ * This is extracted from the `raw` MIME content by parsing the `To:` header.
104
+ */
105
+ relayAlias?: string;
106
+ }
107
+ /**
108
+ * Query options for listing Firefox Relay aliases.
109
+ */
110
+ interface ListAliasesOptions {
111
+ /** Maximum number of aliases to return */
112
+ limit?: number;
113
+ /** Offset for pagination (0-indexed) */
114
+ offset?: number;
115
+ }
116
+ /**
117
+ * Query options for retrieving emails from the CF temp email API.
118
+ */
119
+ interface GetEmailsOptions {
120
+ /** Maximum number of emails to return */
121
+ limit?: number;
122
+ /** Offset for pagination (0-indexed) */
123
+ offset?: number;
124
+ }
125
+ /**
126
+ * Response structure from the CloudFlare temp email API for listing emails.
127
+ *
128
+ * This matches the JSON structure returned by the `/api/mails` endpoint.
129
+ */
130
+ interface CFMailsResponse {
131
+ /** Array of email objects */
132
+ results: Email[];
133
+ /** Total number of emails available (for pagination) */
134
+ count: number;
135
+ }
136
+ /**
137
+ * Response type for listing Firefox Relay aliases.
138
+ *
139
+ * The Firefox Relay API returns an array of alias objects directly.
140
+ */
141
+ type RelayAddressesResponse = RelayAlias[];
142
+ /**
143
+ * Response type for creating a new Firefox Relay alias.
144
+ *
145
+ * The Firefox Relay API returns a single alias object when creating a new alias.
146
+ */
147
+ type CreateAliasResponse = RelayAlias;
148
+
149
+ /**
150
+ * Custom error classes for the relay-temp-mail package.
151
+ *
152
+ * These errors provide structured error information including error codes,
153
+ * HTTP status codes, and response data for better error handling.
154
+ */
155
+ /**
156
+ * Base error class for all relay-temp-mail errors.
157
+ *
158
+ * Extends the built-in Error class with additional context about the error,
159
+ * including an error code for programmatic error handling and optional
160
+ * response data from the API.
161
+ */
162
+ declare class RelayTempMailError extends Error {
163
+ /**
164
+ * Machine-readable error code for programmatic error handling.
165
+ * Examples: 'NETWORK_ERROR', 'AUTH_ERROR', 'NOT_FOUND'
166
+ */
167
+ code: string;
168
+ /**
169
+ * HTTP status code associated with this error, if applicable.
170
+ */
171
+ statusCode?: number;
172
+ /**
173
+ * Raw response data from the API, if available.
174
+ */
175
+ response?: any;
176
+ /**
177
+ * Creates a new RelayTempMailError instance.
178
+ *
179
+ * @param message - Human-readable error message describing the error.
180
+ * @param code - Machine-readable error code (e.g., 'UNKNOWN_ERROR').
181
+ * @param statusCode - Optional HTTP status code associated with the error.
182
+ * @param response - Optional raw response data from the API.
183
+ */
184
+ constructor(message: string, code: string, statusCode?: number, response?: any);
185
+ }
186
+ /**
187
+ * Error for network-related failures.
188
+ *
189
+ * Thrown when there is a problem establishing or maintaining a network
190
+ * connection, such as DNS resolution failures, connection timeouts,
191
+ * or network unreachability.
192
+ */
193
+ declare class NetworkError extends RelayTempMailError {
194
+ code: "NETWORK_ERROR";
195
+ constructor(message: string, response?: any);
196
+ }
197
+ /**
198
+ * Error for authentication and authorization failures.
199
+ *
200
+ * Thrown when API requests fail due to invalid or missing credentials
201
+ * (401) or when the authenticated user lacks permission for the
202
+ * requested operation (403).
203
+ */
204
+ declare class AuthError extends RelayTempMailError {
205
+ code: "AUTH_ERROR";
206
+ constructor(message: string, statusCode?: number, response?: any);
207
+ }
208
+ /**
209
+ * Error for resource not found errors.
210
+ *
211
+ * Thrown when the requested resource does not exist (404 response),
212
+ * such as when trying to access a non-existent alias or email.
213
+ */
214
+ declare class NotFoundError extends RelayTempMailError {
215
+ code: "NOT_FOUND";
216
+ constructor(message: string, response?: any);
217
+ }
218
+ /**
219
+ * Error for MIME message parsing failures.
220
+ *
221
+ * Thrown when there is an error parsing email MIME content,
222
+ * such as malformed headers or invalid message structure.
223
+ */
224
+ declare class ParseError extends RelayTempMailError {
225
+ code: "PARSE_ERROR";
226
+ constructor(message: string, response?: any);
227
+ }
228
+ /**
229
+ * Error for rate limiting responses.
230
+ *
231
+ * Thrown when the API rate limit has been exceeded (429 response).
232
+ * The client should wait and retry the request after the indicated
233
+ * cooldown period.
234
+ */
235
+ declare class RateLimitError extends RelayTempMailError {
236
+ code: "RATE_LIMIT_ERROR";
237
+ constructor(message: string, response?: any);
238
+ }
239
+
240
+ /**
241
+ * Main client for the relay-temp-mail package.
242
+ *
243
+ * This module provides the RelayClient class which integrates all components
244
+ * (CF API, Relay API, Parser) into a unified interface.
245
+ */
246
+
247
+ /**
248
+ * Main client for interacting with Firefox Relay and CloudFlare temp email services.
249
+ *
250
+ * RelayClient integrates all components to provide a unified interface for:
251
+ * - Managing Firefox Relay email aliases
252
+ * - Retrieving and parsing emails from CloudFlare temp email API
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const client = new RelayClient({
257
+ * csrfToken: '...',
258
+ * sessionId: '...',
259
+ * cfApiUrl: 'https://...',
260
+ * cfToken: '...',
261
+ * timeout: 30000
262
+ * });
263
+ *
264
+ * const aliases = await client.listAliases();
265
+ * const emails = await client.getEmails('alias@mozmail.com', { limit: 10 });
266
+ * ```
267
+ */
268
+ declare class RelayClient {
269
+ private readonly relayApi;
270
+ private readonly cfApi;
271
+ private readonly parser;
272
+ /**
273
+ * Creates a new RelayClient instance.
274
+ *
275
+ * @param config - Configuration object containing authentication tokens and API URLs
276
+ */
277
+ constructor(config: RelayConfig);
278
+ /**
279
+ * Lists all Firefox Relay email aliases.
280
+ *
281
+ * @returns Promise resolving to an array of RelayAlias objects
282
+ * @throws AuthError if authentication fails
283
+ * @throws NetworkError if there's a network problem
284
+ */
285
+ listAliases(): Promise<RelayAlias[]>;
286
+ /**
287
+ * Creates a new Firefox Relay email alias.
288
+ *
289
+ * @returns Promise resolving to the newly created RelayAlias
290
+ * @throws AuthError if authentication fails
291
+ * @throws NetworkError if there's a network problem
292
+ */
293
+ createAlias(): Promise<RelayAlias>;
294
+ /**
295
+ * Deletes a Firefox Relay email alias.
296
+ *
297
+ * @param id - The ID of the alias to delete
298
+ * @throws AuthError if authentication fails
299
+ * @throws NotFoundError if the alias doesn't exist
300
+ * @throws NetworkError if there's a network problem
301
+ */
302
+ deleteAlias(id: number): Promise<void>;
303
+ /**
304
+ * Retrieves and parses emails from the CloudFlare temp email API.
305
+ *
306
+ * If aliasAddress is provided, only emails sent to that address are returned.
307
+ *
308
+ * @param aliasAddress - Optional email address to filter by
309
+ * @param options - Query options for pagination
310
+ * @returns Promise resolving to an array of ParsedEmail objects
311
+ * @throws AuthError if authentication fails
312
+ * @throws NetworkError if there's a network problem
313
+ */
314
+ getEmails(aliasAddress?: string, options?: GetEmailsOptions): Promise<ParsedEmail[]>;
315
+ }
316
+
317
+ export { AuthError, type CFMailsResponse, type CreateAliasResponse, type Email, type GetEmailsOptions, type ListAliasesOptions, NetworkError, NotFoundError, ParseError, type ParsedEmail, RateLimitError, type RelayAddressesResponse, type RelayAlias, RelayClient, type RelayConfig, RelayTempMailError };