every-utils
v1.1.5
Published
* [Sendy][1] * [Examples][2] * [subscribers][3] * [Parameters][4] * [subscribe][5] * [Parameters][6] * [Examples][7] * [subscribeMany][8] * [Parameters][9] * [unsubscribe][10] * [Parameters][11] * [deleteSubscriber][12] * [Parame
Downloads
54
Readme
Table of Contents
- Sendy
- MongoDB
- validateEmail
- validateEmailBulk
- tld
- atIndex
Sendy
This class handles all the Sendy API requests including email validation with VeryMail
Examples
const sendy = new Sendy(process.env.SEND_URL, process.env.SEND_API_KEY)
subscribers
This methods querys sendy for all subscribers from a particular list
Parameters
list_id
{list_id: string} The list id to get subscribers fromlist_id.list_id
Returns Array<Object> returns an array of subscribers from a particular list
subscribe
Parameters
subscription
Object
Examples
try {
const { data } = await sendy.subscribe({
name: 'Alex',
email: '[email protected]',
list_id: 'list_id',
})
} catch (error) {
throw error
}
Returns Promise<Boolean> returns true if the contact was successfully subscribed
subscribeMany
Parameters
emailList
Array<Object> list of emails to subscribeverify
boolean Whether to verify the email addresses or not, defaults to true (optional, defaulttrue
)
Returns Promise<Array<Object>> return all subscriptions successfully made
unsubscribe
Parameters
subscription
Object
Returns Promise<Boolean> returns true if the contact was successfully unsubscribed
deleteSubscriber
Parameters
subscription
Object
Returns Promise<Boolean> returns true if the contact was successfully deleted
getSubscriberStatus
Parameters
subscription
Object
Returns Promise<any> returns the status of the contact
getSubscriberCount
Parameters
subscription
Object
Returns Promise<Number> returns the number of active subscribers
getMailingLists
Parameters
Returns Promise<any> returns the subscriber details
getBrands
Returns Promise<any> returns the brands available on the platform
createCampaign
Parameters
options
(CampaignOptions | any)campaign
Objectcampaign.from_name
String the 'From name' of your campaigncampaign.from_email
String the 'From email' of your campaigncampaign.reply_to
String the 'Reply to' of your campaigncampaign.title
String the 'Title' of your campaigncampaign.subject
String the 'Subject' of your campaigncampaign.track_opens
String Set to 0 to disable, 1 to enable and 2 for anonymous opens trackingcampaign.track_clicks
String Set to 0 to disable, 1 to enable and 2 for anonymous clicks trackingcampaign.plain_text
String the 'Plain text version' of your campaign (optional) (optional, default''
)campaign.html_text
String the 'HTML version' of your campaigncampaign.send_campaign
String Set to 1 if you want to send the campaign as well and not just create a draft. Default is 0campaign.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 IDcampaign.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
MongoDB
This is a class that handles all the mongo db methods and operations.
Examples
const mongo = new MongoDB(process.env.MONGO_URL, process.env.MONGO_DB)
db
This method returns the database client.
Examples
await db.collection(collection).findOne({ _id: id })
Returns Function database object
findById
This method finds a record from a mongo collection by id.
Parameters
Examples
const user = await mongo.findById('users', id);
Returns Array collection data by id.
findById
This method finds all record from a mongo collection.
Parameters
query
Object
Examples
const users = await mongo.searchBy({collection: 'users', searchColumn: 'name', searchValue: 'John', limit: 100});
Returns Array<Object> collection data.
findAll
This method finds all record from a mongo collection.
Parameters
collection
String name of the collectionlimit
Number limit the number of records to return (optional, default1000
)
Examples
const users = await mongo.findAll('users', 100);
Returns Array<Object> collection data.
search
This method finds all record from a mongo collection.
Parameters
collection
String name of the collectionsearchText
String the text to search forlimit
Number limit the number of records to return (optional, default1000
)
Examples
const users = await mongo.search('users', 'John', 800);
Returns Array<Object> collection data.
save
This method saves a single record to a mongo collection.
Parameters
Examples
await mongo.save('users', {
name: 'John Doe',
email: '[email protected]',
age: 30,
location: 'New York',
});
Returns Array<Object> database response.
saveMany
This method saves all records to a mongo collection.
Parameters
Examples
await mongo.save('users', [{
name: 'John Doe',
email: '[email protected]',
age: 30,
location: 'New York',
}, {...}, {...}]);
Returns Array<Object> array of records from collection.
update
This method saves all records to a mongo collection.
Parameters
collection
String collection namebody
String data to to be updatedid
String id of the record to be updated
Examples
await mongo.update<User>('users', id, { name: 'John Doe' })
Returns Object object response from from collection.
updateMany
This method saves all records to a mongo collection.
Parameters
Examples
await mongo.updateMany('users', [
{ _id: '603ca52d89c8f102ab323684', status: 'active' },
{ _id: '603ca53389c8f102ab323685', status: 'inactive' },
])
Returns Object object response from from collection.
delete
This method deletes a record from a mongo collection.
Parameters
Examples
await mongo.delete('users', id)
Returns Object object response from deletion
deleteDuplicateByColumn
This method deletes all duplicate records from a mongo collection. Ideally you would want create appropriate indexes on the collection.
Parameters
Examples
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
deleteDuplicateByFilter
This method deletes all duplicate records from a mongo collection using given filter parameters.
Parameters
Examples
const deleted = await mongodb.deleteMany("users", ['603ca52d89c8f102ab323684', '603ca53389c8f102ab323685'])
Returns Object object response from deletion
validateEmail
This method validates email address
Parameters
Examples
const isValid = await validateEmail({
email: '[email protected]',
})
Returns boolean {Promise} a boolean value indicating if the email is valid or not
validateEmailBulk
This method validates all supplied email addresses.
Parameters
mailingList
Array array of email objects to be verified
Examples
const { data } = await validateEmailBulk(
{
email: '[email protected]',
},
{
email: '[email protected]',
},
])
Returns Array object consisting of valid and invalid email addresses { valid: [], invalid: [] }
tld
Validate TLD
Parameters
email
any
atIndex
remove email modifier