UNPKG

@drptbl/mailsac

Version:
290 lines (289 loc) 13.2 kB
import { IAddress, IForwardOptions, IOwned } from "./models/Address"; import { IAttachment } from "./models/Attachment"; import { FolderTypes, IFolderResponse, IHeadersResponse, IInboxOptions, IInboxResponse, ILabelsResponse, IMessage, IReadResponse, ISearchResponse, ISendMessageOptions } from "./models/Message"; import { ISignOutResult, IUser, IUserStats } from "./models/User"; export interface ICountResponse { _id: string; n: number; } /** * Querystring Param Format Description * startDate date (UTC) Required - Limit results to inboxes that received messages after this date. * endDate date (UTC) Required - Limit results to inboxes that received messages before this date. * limit integer Optional - Limit results to this many, default 20, max 1000. * skip integer Optional - Skip this many, default 0. */ export interface IQueryOptions { startDate: Date; endDate: Date; limit?: number; skip?: number; } export declare class Client { apiKey?: string; private axios; constructor(apiKey?: string); /** * Get an array of private inbox address objects for the account. * @return {Promise<IAddress[]>} address list */ getPrivateAddresses(): Promise<IAddress[]>; /** * Get a single address object. * Returns an object if owned by the user or not owned. * Returns 401 if owned by other user. * @param {string} email email * @return {Promise<IAddress>} Address */ getAddress(email: string): Promise<IAddress>; /** * Check if an address is private (AKA owned). * @param {string} email email * @return {Promise<IOwned>} owned */ checkAddressOwnership(email: string): Promise<IOwned>; /** * Reserve ownership of a private email address. * No POST body is required. * Returns 200 if successfully reserves the address. * Returns 401 if owned by other user. * Returns 400 if it is already owned by the user. * @param {string} email email * @return {Promise<IAddress>} address */ reserveAddress(email: string): Promise<IAddress>; /** * Release ownership of a private address. * Returns 200 if successfully releases the address. * Returns 401 if owned by other user. * Returns 400 if it is not owned. * @param {string} email email * @return {Promise<void>} void */ releaseAddress(email: string): Promise<void>; /** * For a privately owned address email, set it to forward to another email. * @param {string} email email * @return {Promise<void>} void */ forwardAddress(email: string, options: IForwardOptions): Promise<void>; /** * This is how to check the mail. Get a list of messages for the :email address. * The objects are abbreviated to provide basic metadata. * @param {string} email email * @return {Promise<IMessage[]>} message list */ getMessages(email: string): Promise<IMessage[]>; /** * Get a list of messages that have been saved and made private for the user. * @return {Promise<IMessage[]>} message list */ getSavedMessages(): Promise<IMessage[]>; /** * Get an individual message. * @param {string} email email address * @param {string} messageId the Mailsac Message._id * @return {Promise<IMessage>} message */ getMessage(email: string, messageId: string): Promise<IMessage>; /** * This is how to check the mail across all of an account's private email addresses. * @param {IInboxOptions} options IInboxOptions * @return {Promise<IInboxResponse>} response */ getPrivateMessages(options?: IInboxOptions): Promise<IInboxResponse>; /** * Search for messages in private address. query matches the to, from, and subject. * @param {string} query query * @return {Promise<ISearchResponse>} response */ searchPrivateMessages(query: string): Promise<ISearchResponse>; /** * Toggle starred status so it will not be automatically removed. * There is no PUT body. * It returns only the message metadata. * @param {string} email email * @param {string} messageId messageId * @return {Promise<IMessage>} message */ saveMessage(email: string, messageId: string): Promise<IMessage>; /** * Set labels on a message. * Any existing labels will be replaced with the new array of string labels. * Maximum 3 labels per message. * @param {string} email email * @param {string} messageId messageId * @param {string[]} labels labels list * @return {Promise<ILabelsResponse>} response */ setMessageLabels(email: string, messageId: string, labels: string[]): Promise<ILabelsResponse>; /** * Move the message to a different mail folder. * No PUT body is needed. * No other folders can be added. To organize mail, use labels. * @param {string} email email * @param {string} messageId messageId * @param {FolderTypes} folder folder * @return {Promise<IFolderResponse>} response */ changeMessageFolder(email: string, messageId: string, folder: FolderTypes): Promise<IFolderResponse>; /** * Change the read state of a message. No PUT body is needed. * Pass read as true to mark the message as read, and false to mark it as unread. The default is false - unread. * @param {string} email email * @param {string} messageId messageId * @param {boolean} read read * @return {Promise<IReadResponse>} response */ setMessageRead(email: string, messageId: string, read?: boolean): Promise<IReadResponse>; /** * Permanently removes a message. There is no history or trash bin. * @param {string} email email * @param {string} messageId messageId * @return {Promise<void>} void */ deleteMessage(email: string, messageId: string): Promise<void>; /** * Get the SMTP headers from an email message. * Use the querystring param ?download=1 to trigger file download in browser. * @param {string} email email * @param {string} messageId messageId * @param {[type]} download=false download * @return {Promise<IHeadersResponse>} void */ getMessageHeaders(email: string, messageId: string, download?: boolean): Promise<IHeadersResponse>; /** * Get safe HTML from an email message. Scripts, images and links are stripped out. * Use the querystring param ?download=1 to trigger file download in browser. * @param {string} email email * @param {string} messageId messageId * @param {[type]} download=false download * @return {Promise<string>} response */ getSanitizedMessage(email: string, messageId: string, download?: boolean): Promise<string>; /** * Get a message's HTML content. * Attached images are inlined and nothing has been stripped. * Use the querystring param ?download=1 to trigger file download in browser. * @param {string} email email * @param {string} messageId messageId * @param {[type]} download=false download * @return {Promise<string>} response */ getHTMLMessage(email: string, messageId: string, download?: boolean): Promise<string>; /** * Get a message's text content. * Use the querystring param ?download=1 to trigger file download in browser. * @param {string} email email * @param {string} messageId messageId * @param {[type]} download=false download * @return {Promise<string>} response */ getMessageText(email: string, messageId: string, download?: boolean): Promise<string>; /** * The entire original SMTP message transport message. * Use the querystring param ?download=1 to trigger file download in browser. * @param {string} email email * @param {string} messageId messageId * @param {[type]} download=false download * @return {Promise<string>} response */ getRawMessage(email: string, messageId: string, download?: boolean): Promise<string>; /** * Send transactional text-only email messages. * Outgoing message credits must be purchased first. * One credit will be used per recipient (as opposed to per email). * Either text or html is required to send a message. * When passing a raw SMTP package it should be a full SMTP message. * All required fields below must be included in the raw package * @param {ISendMessageOptions} options options * @return {Promise<ISendMessageOptions>} response */ sendMessage(options: ISendMessageOptions): Promise<ISendMessageOptions>; /** * Get Current User * @return {Promise<IUser>} user */ getCurrentUser(): Promise<IUser>; /** * Get information about non-owned addresses with starred * messages and total starred messages, and list of owned addresses. * @return {Promise<IUserStats>} stats */ getCurrentUserStats(): Promise<IUserStats>; /** * Destroy the logged in user's session. * No POST body. * For cookie auth which works on the website only. * @return {Promise<ISignOutResult>} result */ signOut(): Promise<ISignOutResult>; /** * List the metadata for all attachments on a message. * @param {string} email email * @param {string} messageId messageId * @return {Promise<IAttachment[]>} attachments list */ getAttachments(email: string, messageId: string): Promise<IAttachment[]>; /** * Download an attachment on a message. * The Content-Type will be set to the contentType field from the attachment metadata. * @param {string} email email * @param {string} messageId messageId * @param {string} attachmentId attachmentId * @return {Promise<void>} void */ downloadAttachment(email: string, messageId: string, attachmentId: string): Promise<void>; /** * Search for attachments that were received during the requested time period. * Limited to non-private inboxes. * @param {IQueryOptions} options options * Field Description * id MD5 hash of the attachment file * n count of messages with this attachment * @return {Promise<ICountResponse[]>} common attachments list */ getCommonAttachments(options: IQueryOptions): Promise<ICountResponse[]>; /** * Count the number of email messages that have attachments with this MD5 sum. * Limited to non-private inboxes. * @param {string} md5 md5 * @return {Promise<number>} number */ countMD5Attachments(md5: string): Promise<number>; /** * List the email messages that have attachments with the requested MD5 sum. * Limited to non-private inboxes. * @param {string} md5 MD5 * @return {Promise<IMessage[]>} messages */ getMessagesWitchAttachment(md5: string): Promise<IMessage[]>; /** * Download an attachment with the MD5 sum requested. * Warning: attachments may contain viruses! * @param {string} md5 MD5 * @return {Promise<void>} void */ downloadCommonAttachment(md5: string): Promise<void>; /** * Search for the top non-private addresses that have been receiving mail. * @param {IQueryOptions} options options * @return {Promise<ICountResponse>} response */ getTopAddresses(options: IQueryOptions): Promise<ICountResponse>; /** * Get an array of domains and IP addresses that have been * blacklisted for violating the terms of service and/or degrading the service experience for other customers. * @return {Promise<string[]>} blacklisted */ getBlacklistedDomainsAndIps(): Promise<string[]>; /** * Check if a domain or IP is on the blacklist. * Returns 404 if not blacklisted. * Returns 200 if blacklisted. * @param {string} domainOrIP domainOrIP * @return {Promise<boolean>} blacklisted */ checkBlacklist(domainOrIP: string): Promise<boolean>; private request; }