- Sendy
- MongoDB
- validateEmail
- validateEmailBulk
- tld
- atIndex
This class handles all the Sendy API requests including email validation with VeryMail
const sendy = new Sendy(process.env.SEND_URL, process.env.SEND_API_KEY)
This methods querys sendy for all subscribers from a particular list
-
list_id
{list_id: string} The list id to get subscribers from-
list_id.list_id
-
Returns Array<Object> returns an array of subscribers from a particular list
-
subscription
Object
try {
const { data } = await sendy.subscribe({
name: 'Alex',
email: 'user@example.com',
list_id: 'list_id',
})
} catch (error) {
throw error
}
Returns Promise<Boolean> returns true if the contact was successfully subscribed
-
emailList
Array<Object> list of emails to subscribe -
verify
boolean Whether to verify the email addresses or not, defaults to true (optional, defaulttrue
)
Returns Promise<Array<Object>> return all subscriptions successfully made
-
subscription
Object
Returns Promise<Boolean> returns true if the contact was successfully unsubscribed
-
subscription
Object
Returns Promise<Boolean> returns true if the contact was successfully deleted
-
subscription
Object
Returns Promise<any> returns the status of the contact
-
subscription
Object
Returns Promise<Number> returns the number of active subscribers
Returns Promise<any> returns the subscriber details
Returns Promise<any> returns the brands available on the platform
-
options
(CampaignOptions | any) -
campaign
Object-
campaign.from_name
String the 'From name' of your campaign -
campaign.from_email
String the 'From email' of your campaign -
campaign.reply_to
String the 'Reply to' of your campaign -
campaign.title
String the 'Title' of your campaign -
campaign.subject
String the 'Subject' of your campaign -
campaign.track_opens
String Set to 0 to disable, 1 to enable and 2 for anonymous opens tracking -
campaign.track_clicks
String Set to 0 to disable, 1 to enable and 2 for anonymous clicks tracking -
campaign.plain_text
String the 'Plain text version' of your campaign (optional) (optional, default''
) -
campaign.html_text
String the 'HTML version' of your campaign -
campaign.send_campaign
String Set to 1 if you want to send the campaign as well and not just create a draft. Default is 0 -
campaign.list_ids
String Required only if you set send_campaign to 1 and no segment_ids are passed in. List IDs should be single or comma-separated. The encrypted & hashed ids can be found under View all lists section named ID. -
campaign.brand_id
String Required only if you are creating a 'Draft' campaign (send_campaign set to 0 or left as default). Brand IDs can be found under 'Brands' page named ID -
campaign.schedule_date_time
String Campaign will be scheduled if a valid date/time is passed. Date/time format eg. June 15, 2021 6:05pm. The minutes part of the time has to be in increments of 5, eg. 6pm, 6:05pm, 6:10pm, 6:15pm. -
campaign.schedule_timezone
String Eg. 'America/New_York'.
-
Returns Promise<any> returns the campaign details
This is a class that handles all the mongo db methods and operations.
const mongo = new MongoDB(process.env.MONGO_URL, process.env.MONGO_DB)
This method returns the database client.
await db.collection(collection).findOne({ _id: id })
Returns Function database object
This method finds a record from a mongo collection by id.
const user = await mongo.findById('users', id);
Returns Array collection data by id.
This method finds all record from a mongo collection.
-
query
Object
const users = await mongo.searchBy({collection: 'users', searchColumn: 'name', searchValue: 'John', limit: 100});
Returns Array<Object> collection data.
This method finds all record from a mongo collection.
-
collection
String name of the collection -
limit
Number limit the number of records to return (optional, default1000
)
const users = await mongo.findAll('users', 100);
Returns Array<Object> collection data.
This method finds all record from a mongo collection.
-
collection
String name of the collection -
searchText
String the text to search for -
limit
Number limit the number of records to return (optional, default1000
)
const users = await mongo.search('users', 'John', 800);
Returns Array<Object> collection data.
This method saves a single record to a mongo collection.
await mongo.save('users', {
name: 'John Doe',
email: 'john.doe@example.com',
age: 30,
location: 'New York',
});
Returns Array<Object> database response.
This method saves all records to a mongo collection.
await mongo.save('users', [{
name: 'John Doe',
email: 'john.doe@example.com',
age: 30,
location: 'New York',
}, {...}, {...}]);
Returns Array<Object> array of records from collection.
This method saves all records to a mongo collection.
-
collection
String collection name -
body
String data to to be updated -
id
String id of the record to be updated
await mongo.update<User>('users', id, { name: 'John Doe' })
Returns Object object response from from collection.
This method saves all records to a mongo collection.
await mongo.updateMany('users', [
{ _id: '603ca52d89c8f102ab323684', status: 'active' },
{ _id: '603ca53389c8f102ab323685', status: 'inactive' },
])
Returns Object object response from from collection.
This method deletes a record from a mongo collection.
await mongo.delete('users', id)
Returns Object object response from deletion
This method deletes all duplicate records from a mongo collection. Ideally you would want create appropriate indexes on the collection.
await mongo.deleteDuplicateByColumn(
'users',
'email'
);
mongo sh command
db.contact.find().forEach(function(doc) {
var email = doc.email;
db.contact.deleteMany({ email: email, _id: { $ne: doc._id } });
});
Returns Object object response from deletion
This method deletes all duplicate records from a mongo collection using given filter parameters.
const deleted = await mongodb.deleteMany("users", ['603ca52d89c8f102ab323684', '603ca53389c8f102ab323685'])
Returns Object object response from deletion
This method validates email address
const isValid = await validateEmail({
email: 'user@example.com',
})
Returns boolean {Promise} a boolean value indicating if the email is valid or not
This method validates all supplied email addresses.
-
mailingList
Array array of email objects to be verified
const { data } = await validateEmailBulk(
{
email: 'user1@example.com',
},
{
email: 'user2@example.com',
},
])
Returns Array object consisting of valid and invalid email addresses { valid: [], invalid: [] }
Validate TLD
-
email
any
remove email modifier