UNPKG

fastmail-masked-email

Version:

A library for creating, deleting, and updating Fastmail masked emails

119 lines (118 loc) 4.73 kB
import { MaskedEmail, MaskedEmailState } from './types/maskedEmail'; import { CreateOptions, Options } from './types/options'; /** * MaskedEmailService - A comprehensive service for managing Fastmail masked emails * Provides methods for creating, retrieving, updating, and deleting masked email addresses */ export declare class MaskedEmailService { private token?; private hostname?; private session; private debugLogger; private errorLogger; /** * Creates a new MaskedEmailService instance * @param token - Optional Fastmail API token for authentication * @param hostname - Optional Fastmail API hostname; defaults to api.fastmail.com */ constructor(token?: string | undefined, hostname?: string | undefined); /** * Initialize the service by getting a session from the JMAP server * @returns Promise that resolves when the session is established * @throws Error if no auth token is provided */ initialize(): Promise<void>; getSession(): Promise<any>; /** * Creates a new masked email address * @param options - The {@link CreateOptions|options} for creating the masked email * @throws {@link InvalidArgumentError} if no session is provided */ createEmail(options?: CreateOptions): Promise<MaskedEmail>; /** * Retrieves all masked emails * @throws {@link InvalidArgumentError} if no session is provided * @returns A list of all {@link MaskedEmail} objects */ getAllEmails(): Promise<MaskedEmail[]>; /** * Get a masked email by id * @param id - The id of the masked email address. * @returns A {@link MaskedEmail} object * @throws {@link InvalidArgumentError} if no session is provided or no id is provided */ getEmailById(id: string | undefined): Promise<MaskedEmail>; /** * Get a masked email by address * @param address - The address to retrieve * @returns A {@link MaskedEmail} object */ getEmailByAddress(address: string): Promise<MaskedEmail[] | []>; /** * Updates a masked email * @param id - The id of the masked email to update * @param options - The {@link Options} containing the fields to update * @throws {@link InvalidArgumentError} if no id is provided, no session is provided, or the {@link Options} are empty */ updateEmail(id: string | undefined, options: Options): Promise<{ [key: string]: null; }>; /** * Deletes a masked email by setting the state to deleted * @param id - The id of the masked email to deleteEmail */ deleteEmail(id: string): Promise<{ [key: string]: null; }>; /** * Disables a masked email by setting the state to disabled * @param id - The id of the masked email to disableEmail */ disableEmail(id: string): Promise<{ [key: string]: null; }>; /** * Enables a masked email by setting the state to enabled * @param id - The id of the masked email to enableEmail */ enableEmail(id: string): Promise<{ [key: string]: null; }>; /** * Permanently deletes a masked email * @param id - The id of the masked email to permanently deleteEmail * @throws {@link InvalidArgumentError} if no id is provided or no session is provided */ permanentlyDeleteEmail(id: string | undefined): Promise<{ [key: string]: null; }>; /** * Filter masked emails by state * @param state - The state to filter by * @param list - The list of masked emails (optional, will fetch all if not provided) * @returns Promise that resolves to a filtered {@link MaskedEmail} array */ filterByState(state: MaskedEmailState, list?: MaskedEmail[]): Promise<MaskedEmail[]>; /** * Filter masked emails by domain * @param domain - The domain to filter by * @param list - The list of masked emails (optional, will fetch all if not provided) * @returns Promise that resolves to a filtered {@link MaskedEmail} array */ filterByForDomain(domain: string, list?: MaskedEmail[]): Promise<MaskedEmail[]>; private ensureInitialized; private parseSession; /** * Builds headers for requests using the JMAP token * @param authToken - The JMAP authentication token */ private buildHeaders; private maskedEmailNotFound; private filterByAddress; /** * Handles an axios error and returns a rejected promise with a formatted error message based on the type of error and action attempted. * @param error - The axios error * @param action - The action that was being performed when the error occurred */ private handleAxiosError; }