0.0.1 • Published 9 months ago
@mailavocado/client v0.0.1
MailAvocado
A simple client for managing email lists and sending emails through your email service.
Installation
npm install mailavocadoUsage
import { MailAvocado } from "mailavocado";
const mailAvocado = new MailAvocado({
endpoint: "https://your-api-endpoint.com",
apiKey: "your-api-key",
});
// Send email using userId
await mailAvocado.sendEmail({
templateId: "welcome-template",
userId: "user-123",
});
// Or send email using email and name
await mailAvocado.sendEmail({
templateId: "newsletter-template",
email: "user@example.com",
name: "John Doe",
});
// Add existing user to a list
await mailAvocado.addToList({
listId: "list-123",
userId: "user-456",
addIfNotExist: false,
});
// Add new or existing user to a list by email
await mailAvocado.addToList({
listId: "list-123",
email: "user@example.com",
name: "John Doe",
addIfNotExist: true,
});API
MailAvocado(config)
Creates a new MailAvocado instance.
config.endpoint: Your API endpoint URLconfig.apiKey: Your API key
sendEmail(options)
Sends an email using the specified options.
options.templateId: The ID of the email template to useoptions.userId: (Optional) The ID of the user to send the email tooptions.email: (Optional) The recipient's email addressoptions.name: (Optional) The recipient's name
Either userId or both email and name must be provided.
addToList(options)
Adds a user to a specified list.
options.listId: The ID of the list to add the user tooptions.userId: (Optional) The ID of the existing useroptions.email: (Optional) The user's email addressoptions.name: (Optional) The user's nameoptions.addIfNotExist: Whether to create a new user if they don't exist
Either userId or both email and name must be provided.
Error Handling
The package throws these types of errors:
ValidationError: When required fields are missing or invalidApiError: When the API returns an error responseNetworkError: When there are network connectivity issues
License
MIT
0.0.1
9 months ago