1.1.5 • Published 1 year ago

every-utils v1.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Table of Contents

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 from

    • list_id.list_id

Returns Array<Object> returns an array of subscribers from a particular list

subscribe

Parameters

  • subscription Object

    • subscription.name String? The contact name
    • subscription.email string he contact email address
    • subscription.list_id string The list id the contact should be subscribed to
    • subscription.verify boolean Whether to verify the email address or not, defaults to true (optional, default true)

Examples

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

subscribeMany

Parameters

  • emailList Array<Object> list of emails to subscribe
  • verify boolean Whether to verify the email addresses or not, defaults to true (optional, default true)

Returns Promise<Array<Object>> return all subscriptions successfully made

unsubscribe

Parameters

  • subscription Object

    • subscription.email String The contact email
    • subscription.list_id String The list id the contact should be unsubscribed from

Returns Promise<Boolean> returns true if the contact was successfully unsubscribed

deleteSubscriber

Parameters

  • subscription Object

    • subscription.email String The contact email
    • subscription.list_id String The list id the contact should be deleted from

Returns Promise<Boolean> returns true if the contact was successfully deleted

getSubscriberStatus

Parameters

  • subscription Object

    • subscription.email String The contact email
    • subscription.list_id String The list id the contact should be deleted from

Returns Promise\ returns the status of the contact

getSubscriberCount

Parameters

  • subscription Object

    • subscription.email String The contact email
    • subscription.list_id String The list id the contact belongs

Returns Promise<Number> returns the number of active subscribers

getMailingLists

Parameters

Returns Promise\ returns the subscriber details

getBrands

Returns Promise\ returns the brands available on the platform

createCampaign

Parameters

  • 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\ 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

    • query.collection String name of the collection
    • query.searchColumn String the text to search for
    • query.searchValue String the text to search for
    • query.limit String the text to search for (optional, default 800)

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 collection
  • limit Number limit the number of records to return (optional, default 1000)

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 collection
  • searchText String the text to search for
  • limit Number limit the number of records to return (optional, default 1000)

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

  • collection String name of the collection
  • body String data to save

Examples

await mongo.save('users', {
	name: 'John Doe',
email: 'john.doe@example.com',
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: 'john.doe@example.com',
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 name
  • body String data to to be updated
  • id 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

  • collection String collection name
  • filter String data to to be updated

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

  • collection String collection name
  • id String id of the record to be updated

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

  • collection String collection name
  • column String id of the record to be updated

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

  • collection String collection name
  • filter String id of the record to be updated

Examples

const deleted = await mongodb.deleteMany("users", ['603ca52d89c8f102ab323684', '603ca53389c8f102ab323685'])

Returns Object object response from deletion

validateEmail

This method validates email address

Parameters

  • contact Object

    • contact.email String the email to be validated

Examples

const isValid = await validateEmail({
     email: 'user@example.com',
 })

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: 'user1@example.com',
  },
  {
      email: 'user2@example.com',
  },
])

Returns Array object consisting of valid and invalid email addresses { valid: [], invalid: [] }

tld

Validate TLD

Parameters

  • email any

atIndex

remove email modifier

1.1.1

1 year ago

1.1.0

1 year ago

1.1.5

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.45

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago