mailtm-proxy
Version:
TypeScript library for interacting with temporary email services like mail.tm and mail.gw with proxy support
182 lines (178 loc) • 5.45 kB
TypeScript
declare const providers: readonly ["mail.tm", "mail.gw"];
type MailProvider = (typeof providers)[number];
type CreateInstanceOptions = {
proxy?: string;
provider?: MailProvider;
};
type EmailContact = {
address: string;
name: string;
};
type Attachment = {
id: string;
filename: string;
contentType: string;
disposition: string;
transferEncoding: string;
related: boolean;
size: number;
downloadUrl: string;
};
type CreateRandomEmailBody = {
emailLength?: number;
emailPrefix?: string;
passwordLength?: number;
};
type LoginBody = {
email: string;
password: string;
};
type MeResponse = {
id: string;
address: string;
quota: number;
used: number;
isDisabled: boolean;
isDeleted: boolean;
createdAt: string;
updatedAt: string;
};
type CreateRandomEmailResponse = {
email?: string;
password?: string;
id?: string;
};
type LoginResponse = {
token: string;
};
type GetMessagesResponse = {
'@id': string;
'@type': string;
id: string;
accountId: string;
msgId: string;
from: EmailContact;
to: EmailContact[];
subject: string;
intro: string;
seen: boolean;
isDeleted: boolean;
hasAttachments: boolean;
size: number;
downloadUrl: string;
createdAt: string;
updatedAt: string;
};
type GetMessageResponse = {
'@id': string;
'@type': string;
id: string;
from: EmailContact;
to: EmailContact[];
cc: Record<string, string>[] | string[];
bcc: Record<string, string>[] | string[];
subject: string;
seen: boolean;
flagged: boolean;
isDeleted: boolean;
verifications: Record<string, string>[];
retention: boolean;
retentionDate: string;
text: string;
html: string[];
hasAttachments: boolean;
attachments: Attachment[];
size: number;
downloadUrl: string;
createdAt: string;
updatedAt: string;
};
/**
* Create new instance of CustomMailjs
* @param {CreateInstanceOptions} options - Options to create the instance
* @param {string} [options.provider='mail.tm'] - Mail provider, default to 'mail.tm'
* @param {string} [options.proxy] - Proxy URL to use for requests
* @returns {CustomMailjs} Returns a new instance of CustomMailjs
*
* @example
* const mailjs = new CustomMailjs({
* provider: 'mail.tm',
* proxy: 'http://user:pass@ip:port'
* });
*/
declare class CustomMailjs {
private api;
/**
* Initialize a new CustomMailjs instance
*
* @param {CreateInstanceOptions} options - Options for creating the instance
*/
constructor({ provider, proxy }?: CreateInstanceOptions);
/**
* Get all available domains
*
* @returns {Promise<string[]>} Returns a list of domains from Mail.tm
* @example ['punkproof.com', 'oakon.com']
*/
getDomains(): Promise<string[]>;
/**
* Create a random email account
*
* @param {Object} [params] - Options to create the email
* @param {number} [params.emailLength=15] - Length of the email, default to 15
* @param {number} [params.passwordLength=7] - Length of the password, default to 7
* @param {string} [params.emailPrefix] - Prefix for the email address
* @returns {Promise<CreateRandomEmailResponse>} The created email and password. If creation is successful, all fields will be defined. If creation fails, all fields will be undefined.
*/
createRandomEmail({ emailLength, emailPrefix, passwordLength, }?: CreateRandomEmailBody): Promise<CreateRandomEmailResponse>;
/**
* Authenticate and get bearer token
*
* @param {Object} params - Parameters for login
* @param {string} params.email - Email address to login
* @param {string} params.password - Password to login
* @returns {Promise<LoginResponse>} Returns the token for authenticated requests or empty object if failed
*/
login({ email, password }: LoginBody): Promise<LoginResponse>;
/**
* Get all messages from the authenticated account
*
* @returns {Promise<GetMessagesResponse[]>} Returns a list of messages or empty array if failed
*/
getMessages(): Promise<GetMessagesResponse[]>;
/**
* Get a specific message by ID
*
* @param {string} id - ID of the message to retrieve
* @returns {Promise<GetMessageResponse | null>} Returns the message details or null if failed
*/
getMessage(id: string): Promise<GetMessageResponse | null>;
/**
* Delete a specific message by ID
*
* @param {string} id - ID of the message to delete
* @returns {Promise<boolean>} Returns true on success, false on failure
*/
deleteMessage(id: string): Promise<boolean>;
/**
* Delete the authenticated account by ID
*
* @param {string} id - ID of the account to delete
* @returns {Promise<boolean>} Returns true on success, false on failure
*/
deleteAccount(id: string): Promise<boolean>;
/**
* Get the authenticated user's account details
*
* @returns {Promise<MeResponse | null>} Returns the account details of the authenticated user or null if failed
*/
me(): Promise<MeResponse | null>;
/**
* Set the authentication token for API requests
*
* @param {string} token - The authentication token
* @private
*/
private setToken;
}
export { CustomMailjs, CustomMailjs as default };