From c7dcfa09cc7a6d435d1221c454bc909f035f0b81 Mon Sep 17 00:00:00 2001 From: hellovikram Date: Tue, 4 Sep 2018 14:50:46 +0530 Subject: [PATCH] initial commit --- LICENSE | 53 ++--- README.md | 236 +++++++++++++++----- example.js | 68 +++--- lib/APIHelper.js | 343 +++++++++++++++++------------ lib/Controllers/BaseController.js | 46 ++++ lib/Controllers/EmailController.js | 188 +++++----------- lib/Exceptions/APIException.js | 30 +++ lib/Http/Client/HttpContext.js | 19 +- lib/Http/Client/RequestClient.js | 90 ++++---- lib/Http/Request/HttpRequest.js | 32 ++- lib/Http/Response/HttpResponse.js | 23 +- lib/ModelFactory.js | 45 ++++ lib/Models/Attachments.js | 49 +++++ lib/Models/Attribute.js | 49 +++++ lib/Models/BaseModel.js | 137 ++++++++++-- lib/Models/EmailBody.js | 73 ++++++ lib/Models/EmailBodyAttachments.js | 49 +++++ lib/Models/From.js | 49 +++++ lib/Models/Personalizations.js | 57 +++++ lib/Models/SendEmailError.js | 49 +++++ lib/Models/SendEmailResponse.js | 51 +++++ lib/Models/Settings.js | 196 ++++------------- lib/ObjectMapper.js | 178 +++++++++++++++ lib/configuration.js | 16 +- lib/index.js | 58 +++-- package.json | 56 ++++- 26 files changed, 1574 insertions(+), 666 deletions(-) create mode 100644 lib/Controllers/BaseController.js create mode 100644 lib/Exceptions/APIException.js create mode 100644 lib/ModelFactory.js create mode 100644 lib/Models/Attachments.js create mode 100644 lib/Models/Attribute.js create mode 100644 lib/Models/EmailBody.js create mode 100644 lib/Models/EmailBodyAttachments.js create mode 100644 lib/Models/From.js create mode 100644 lib/Models/Personalizations.js create mode 100644 lib/Models/SendEmailError.js create mode 100644 lib/Models/SendEmailResponse.js create mode 100644 lib/ObjectMapper.js diff --git a/LICENSE b/LICENSE index 3b3f1e7..252a1c6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,25 +1,28 @@ -License: -======== -The MIT License (MIT) -http://opensource.org/licenses/MIT - -Copyright (c) 2014 - 2016 Pepipost - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - +License: +======== +The MIT License (MIT) +http://opensource.org/licenses/MIT + +Copyright (c) 2014 - 2016 APIMATIC Limited + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +Trade Mark: +========== +APIMATIC is a trade mark for APIMATIC Limited \ No newline at end of file diff --git a/README.md b/README.md index d6126b5..fe5832e 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,183 @@ -Pepipost SDK for NodeJS -================= -This SDK was semi-automatically generated by APIMATIC v2.0. Thanks to [APIMATIC](http://apimatic.io/) - -Installation -================= -``` -npm install pepipost-sdk-nodejs -``` - -Usage -================= -create a file example.js and put the below code - -***example.js*** -```js -var PepipostSDK = require('pepipost-sdk-nodejs'); - -var Email = PepipostSDK.EmailController; - -var data = { - "api_key": "yoursecretapikey", - "email_details": { - "fromname": "yourfromname", - "subject": "this is test email subject", - "from": "from@example.com", - "content": "

hi, this is a test email sent via Pepipost JSON API.

" - }, - "recipients": [ - "recipient@example.com" - ] -}; - -Email.send(data,callback_mail_sent); - -function callback_mail_sent(err_msg,parsed,context){ - if(parsed.errorcode==0){ - console.log("mail sent successfully.\n"); - } - else{ - console.log("Email sent Failed.\n"); - console.log("errormessage("+parsed.errormessage+")\n"); - console.log("errorcode("+parsed.errorcode+")\n"); - } -} -``` - -Change the "yoursecretkey" with your API key and example.com with your approved domain name. To get your api key you need to signup/register on [Pepipost](http://pepipost.com/) - - -``` -nodejs example.js -``` +![pepipostlogo](https://pepipost.com/assets/img/pepipost-footLogo.png) + +[![npm](https://img.shields.io/npm/v/pepipost.svg)](https://www.npmjs.com/package/pepipost) +[![NpmLicense](https://img.shields.io/npm/l/pepipost.svg)](https://www.npmjs.com/package/pepipost) +[![Twitter Follow](https://img.shields.io/twitter/follow/pepi_post.svg?style=social&label=Follow)](https://twitter.com/pepi_post) + + + +# Official nodejs library of Pepipost + +This library allows you to quickly integrate Pepipost Web API v2 for sending emails. + +We are trying to make our libraries Community Driven- which means we need your help in building the right things in proper order we would request you to help us by sharing comments, creating new issues or pull requests. + +We welcome any sort of contribution to this library. + +The latest 2.5.0 version of this library provides is fully compatible with the latest Pepipost v2.0 API. + +# Table of Content + + * [Installation](#installation) + * [Quick Start](#quick-start) + * [Usage](#usage) + * [Announcements](#announcements) + * [Roadmap](#roadmap) + * [About](#about) + * [License](#license) + + +# Installation + + This library relies on [Node Package Manager](https://www.npmjs.com/)(NPM) which will help in resolving dependencies. Hope you have latest NPM installed, if not please go ahead and follow the instruction to update NPM from [here](https://docs.npmjs.com/cli/update) + +## Prerequisites + + * npm (by default installed when node is installed). + * node + * [Pepipost library](https://www.npmjs.com/package/pepipost) + * A free account on [Pepipost](https://app.pepipost.com/index.php/signup/registeruser). If you don't have a one, click here to sign-up and get 30,000 emails free every month. + + +# Quick Start + +1. To check if node and npm have been successfully installed, write the following commands in command prompt: + + * `node --version` + * `npm -version` + + ![Version Check](https://apidocs.io/illustration/nodejs?step=versionCheck&workspaceFolder=Pepipost%20API-Node) + +2. Since npm is install you can directly install pepipost packages using below command + + ``` mkdir TestConsole && cd TestConsole``` + + ![img1](http://app1.falconide.com/integration_imgs/node/2.png) + + + ```npm i pepipost ``` + + ![img2](http://app1.falconide.com/integration_imgs/node/3.png) + + + once you package is install see `node_modules` folder. + +3. The following section explains how to use the library in a new project. + + 1. Open Project Folder + + Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE. + + Click on `File` and select `Open Folder`. + + ![Open Folder](https://apidocs.io/illustration/nodejs?step=openFolder) + + Select the folder of your SDK and click on `Select Folder` to open it up in Sublime Text. The folder will become visible in the bar on the left. + + ![Open Project](http://app1.falconide.com/integration_imgs/node/6.png) + + 2. Creating a Test File + + Now right click on the folder name. + + select the `New File` option to create a new test file. + + ![img](http://app1.falconide.com/integration_imgs/node/8.png) + + Save it as `example.js` Now import the generated NodeJS library using the following lines of code: + +```js + var lib = require('pepipost'); +``` + Save changes. + + ![Create new file](http://app1.falconide.com/integration_imgs/node/9.png) + +) + + 3. copy and paste from [SampleUsage](#Usage) in example.js file + + * apikey will be available under Login to Pepipost -> Settings -> Integration + * Sending Domain will be available under Login to Pepiost -> Settings -> Sending Domains + + 4. Running The Test File + + To run the `example.js` file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file: + +``` + node example.js +``` + ![Run file](http://app1.falconide.com/integration_imgs/node/10.png) + + +# Usage + +```javascript +//if you are using SDK require will be changed to require('./lib'). +const lib = require('pepipost'); +const configuration = lib.Configuration; +const controller = lib.EmailController; +let apiKey = 'api key to be passed here'; +let body = new lib.EmailBody(); + +body.personalizations = []; +body.personalizations[0] = new lib.Personalizations(); +body.personalizations[0].recipient = 'email To be sent to'; +body.personalizations[0].xApiheaderCc = '123'; +body.personalizations[0].xApiheader = '12'; +body.personalizations[0].attributes = JSON.parse('{"name":"pepi"}'); +body.personalizations[0].attachments = []; + +body.personalizations[0].attachments[0] = new lib.Attachments(); +body.personalizations[0].attachments[0].fileContent = 'SGVsbG8gRm9sa3MsIFRoaXMgaXMgUGVwaXBvc3QncyBub2RlSlMgU0RL'; //base64encoded value to be passed here +body.personalizations[0].attachments[0].fileName = 'filename.txt'; +body.personalizations[0].recipientCc = ['CC emailid to be sent']; + + +body.tags = 'tagsTransnodejs'; +body.from = new lib.From(); +body.from.fromEmail = 'your from domain'; +body.from.fromName = 'Nodejs Pepi'; +body.subject = 'Pepipost SDK For Node JS'; +body.content = 'Hello Folks, This is Pepipost\'s nodeJS SDK. Regards [% name %]'; +body.settings = new lib.Settings(); + +body.settings.footer = 1; +body.settings.clicktrack = 1; +body.settings.opentrack = 1; +body.settings.unsubscribe = 1; +body.settings.bcc = 'bcc email id to be passed'; +body.replyToId = 'replyto id to be passed here'; + + +const promise = controller.createSendEmail(apiKey, body); + +promise.then((response) => { + console.log(response); +}, (err) => { + console.log(response); +}); +``` + + +# Announcements + +v2.5.0 has been released! Please see the [release notes](https://github.com/pepipost/pepipost-sdk-nodejs/releases/tag/v2.5.0) for details. + +All updates to this library are documented in our [releases](https://github.com/pepipost/pepipost-sdk-nodejs/releases). For any queries, feel free to reach out us at dx@pepipost.com + + +## Roadmap + +If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/pepipost/pepipost-sdk-nodejs/issues) and [pull requests](https://github.com/pepipost/pepipost-sdk-nodejs/pulls). We would love to hear your feedback. + + +## About +pepipost-nodejs-sdk library is guided and supported by the Pepipost Developer Experience Team. +This pepipost-nodejs-sdk library is maintained and funded by Pepipost Ltd. The names and logos for pepipost-nodejs-sdk are trademarks of Pepipost Ltd. + + +## License +This code library was semi-automatically generated by APIMATIC v2.0 and licensed under The MIT License (MIT). + + diff --git a/example.js b/example.js index de0f5f6..adcda4a 100644 --- a/example.js +++ b/example.js @@ -1,31 +1,41 @@ -var PepipostSDK = require('pepipost-sdk-nodejs'); - -var Email = PepipostSDK.EmailController; - -var data = { - "api_key": "yoursecretapikey", - "email_details": { - "fromname": "yourfromname", - "subject": "this is test email subject", - "from": "from@example.com", - "content": "

hi, this is a test email sent via Pepipost JSON API.

" - }, - "recipients": [ - "recipient@example.com" - ] -}; - -Email.send(data,callback_mail_sent); - -function callback_mail_sent(err_msg,parsed,context){ - if(parsed.errorcode==0){ - console.log("mail sent successfully.\n"); - } - else{ - console.log("Email sent Failed.\n"); - console.log("errormessage("+parsed.errormessage+")\n"); - console.log("errorcode("+parsed.errorcode+")\n"); - } -} +const lib = require('./lib'); +const configuration = lib.Configuration; +const controller = lib.EmailController; +let apiKey = '304b54cbda55828c0a34070ed7b626d5'; +let body = new lib.EmailBody(); +body.personalizations = []; +body.personalizations[0] = new lib.Personalizations(); +body.personalizations[0].recipient = 'vikramsahu36@gmail.com'; +body.personalizations[0].recipientCc = []; + + +body.from = new lib.From(); +body.from.fromEmail = 'pepi_nodesdk@pepipost.com'; +body.from.fromName = 'Nodejs SDK'; +body.subject = 'Pepi- Nodejs'; +body.content = 'this is pepipost email'; + +body.settings = new lib.Settings(); +body.settings.footer = 0; +body.settings.clicktrack = 1; +body.settings.opentrack = 1; +body.settings.unsubscribe = 1; + +const promise = controller.createSendEmail(apiKey, body); + +promise.then((response) => { + + // this block will be executed on successful endpoint call + console.log(response); + + // `response` will be of type 'SendEmailResponse' + +}, (err) => { + + // this block will be executed on endpoint call failure + console.log(response); + // `err` is an 'object' containing more information about the error + +}); diff --git a/lib/APIHelper.js b/lib/APIHelper.js index 3d888a4..8470318 100644 --- a/lib/APIHelper.js +++ b/lib/APIHelper.js @@ -1,219 +1,288 @@ /** - * PepipostAPIV10Lib + * PepipostLib * - * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) on 08/20/2016 + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ - -var stream = require('stream'); +'use strict'; -var APIHelper = { +const stream = require('stream'); + +class APIHelper { /** * Replaces template parameters in the given url - * @param {String} queryBuilder The query string builder to replace the template parameters - * @param {Array} parameters The parameters to replace in the queryBuilder + * @param {String} queryBuilder The query string builder to replace the template parameters + * @param {Array} parameters The parameters to replace in the queryBuilder + * @returns {String} The query string with replaced template parameters */ - appendUrlWithTemplateParameters:function(queryBuilder, parameters) { - //perform parameter validation - if(queryBuilder == null) { - console.log('queryBuilder is null'); - return; + static appendUrlWithTemplateParameters(queryBuilder, parameters) { + // perform parameter validation + if (queryBuilder === null) { + return null; } - if(parameters ==null) { + if (parameters === null) { return queryBuilder; - } - //iterate and replace parameters - for(var key in parameters) { - var replaceValue = ""; - //load parameter value - var element = parameters[key]; - if(element == null) { - replaceValue = ""; + } + + let queryString = queryBuilder; + // iterate and replace parameters + const keys = Object.keys(parameters); + for (let iter = 0; iter < keys.length; iter += 1) { + let replaceValue = ''; + + // load parameter value + const element = parameters[keys[iter]]; + if (element === null) { + replaceValue = ''; } else if (element instanceof Array) { - replaceValue = element.map(function(element){ - return encodeURIComponent(element); - }) - replaceValue = replaceValue.join("/"); + replaceValue = element.map(el => encodeURIComponent(el)); + replaceValue = replaceValue.join('/'); } else { replaceValue = encodeURIComponent(element.toString()); } - queryBuilder = queryBuilder.replace('{'+(key)+'}', replaceValue) + queryString = queryString.replace(`{${keys[iter]}}`, replaceValue); } - return queryBuilder; - }, + return queryString; + } /** * Appends the given set of parameters to the given query string - * @param {String} queryBuilder The query url string to append the parameters - * @param {Array} parameters The parameters to append + * @param {String} queryBuilder The query url string to append the parameters + * @param {Array} parameters The parameters to append + * @returns {String} The query string appended with query parameters */ - appendUrlWithQueryParameters:function(queryBuilder, parameters) { - //perform parameter validation - if(queryBuilder == null) { - console.log('queryBuilder is null'); - return; + static appendUrlWithQueryParameters(queryBuilder, parameters) { + // perform parameter validation + if (queryBuilder === null) { + return null; } - if(parameters == queryBuilder) { + if (parameters === queryBuilder) { return queryBuilder; } - var hasParams = queryBuilder.indexOf('?') >-1; - //iterate and replace parameters - var encoded = this.urlEncodeObject(parameters); - var separator = (hasParams)?'&':'?' - queryBuilder = queryBuilder + separator + encoded; - return queryBuilder; - }, + const hasParams = queryBuilder.indexOf('?') > -1; + + // iterate and replace parameters + const encoded = this.urlEncodeObject(parameters); + const separator = (hasParams) ? '&' : '?'; + const queryString = queryBuilder + separator + encoded; + return queryString; + } /** * Validates and processes the given Url - * @param {String} url The Url to process - * @return {String} Pocessed url + * @param {String} url The Url to process + * @return {String} Processed url */ - cleanUrl:function(url) { - //ensure that the urls are absolute - var re = /^https?:\/\/[^\/]+/; - var str = url; - var match = url.match(re); - if(match==null) { - console.log('Invalid Url format'); - return; - } - //remove redundant forward slashes - var protocol = match[0]; - var queryUrl = url.substring(protocol.length); - queryUrl = queryUrl.replace(/\/\/+/,"/"); - var result = protocol+queryUrl; + static cleanUrl(url) { + // ensure that the urls are absolute + const re = /^https?:\/\/[^/]+/; + const match = url.match(re); + if (match === null) { + return null; + } + + // remove redundant forward slashes + const protocol = match[0]; + let queryUrl = url.substring(protocol.length); + queryUrl = queryUrl.replace(/\/\/+/, '/'); + const result = protocol + queryUrl; return result; - }, - + } + /** * JSON Serialization of a given object. - * @param {Object} data The object to serialize into JSON - * @return The serialized Json string representation of the given object + * @param {Object} data The object to serialize into JSON + * @return {Object} The serialized Json string representation of the given object */ - jsonSerialize: function(data) { + static jsonSerialize(data) { return JSON.stringify(data); - }, - + } + /** * Formats the template parameters in the string - * @param str The string containing the template - * @return The string with template parameters filled in. + * @param {string} str The string containing the template + * @return {string} The string with template parameters filled in. */ - formatString: function(str){ - if (!str || arguments.length <=1 ) return str; - var args = arguments; - for (var i = 1; i < arguments.length; i++) { - var reg = new RegExp("\\{" + (i - 1) + "\\}", "gm"); - str = str.replace(reg, arguments[i]); + static formatString(str) { + let formattedStr = str; + if (!formattedStr || arguments.length <= 1) return formattedStr; + for (let iter = 1; iter < arguments.length; iter += 1) { + const reg = new RegExp(`\\{${(iter - 1)}\\}`, 'gm'); + formattedStr = formattedStr.replace(reg, arguments[iter]); } - return str; - }, + return formattedStr; + } /** * Cleans the object by removing null properties. - * @param {object} input Object or dictionary. - * @return {object} Returns the cleaned version of the object. + * @param {object} input Object or dictionary. + * @return {object} Returns the cleaned version of the object. */ - cleanObject: function(input){ - if(input instanceof stream.Stream){ + static cleanObject(input) { + if (!input) { return input; } - for(var key in input) { - var value = input[key]; - if (value == null || value == undefined){ - if (input.constructor === Array){input.splice(key, 1)} - else delete input[key]; + const cleanedObj = input; + if (cleanedObj instanceof stream.Stream) { + return cleanedObj; + } + const keys = Object.keys(cleanedObj); + for (let iter = 0; iter < keys.length; iter += 1) { + const value = cleanedObj[keys[iter]]; + if (value === null || value === undefined) { + if (cleanedObj.constructor === Array) { + cleanedObj.splice(keys[iter], 1); + } else delete cleanedObj[keys[iter]]; } else if (Object.prototype.toString.call(value) === '[object Object]') { this.cleanObject(value); } else if (value.constructor === Array) { this.cleanObject(value); } } - return input; - }, + return cleanedObj; + } /** * Shallow merges the properties of two objects - * @param {object} first The object to merge in to - * @param {object} second The object to be added to first + * @param {object} first The object to merge in to + * @param {object} second The object to be added to first * - * @return the merged (modified) first object + * @return {object} The merged (modified) first object */ - merge:function(first,second){ - for (var attrname in second) { first[attrname] = second[attrname]; } - return first; - }, + static merge(first, second) { + if (!first) { + return first; + } + const merged = first; + if (second !== undefined && second !== null) { + const attrNamesSecond = Object.keys(second); + for (let iter = 0; iter < attrNamesSecond.length; iter += 1) { + merged[attrNamesSecond[iter]] = second[attrNamesSecond[iter]]; + } + } + return merged; + } /** * Checks if the elements of the given array are all primitives + * @param {array} value The array to be checked + * + * @return {bool} The result of primitive checking */ - isPrimitiveArray: function(value){ - if(value.constructor && value.constructor !== Array){ + static isPrimitiveArray(value) { + if (value.constructor && value.constructor !== Array) { return false; } - if(value.length == 0) return true; - return value.every(function (obj) { - return obj == null || obj == undefined || obj.constructor && [String, Number, Boolean].indexOf(obj.constructor) >=0 - }); - }, + if (value.length === 0) return true; + return value.every(obj => + (obj === null + || obj === undefined) + || (obj.constructor + && [String, Number, Boolean].indexOf(obj.constructor) >= 0)); + } + /** * Converts an object to formdata serialization. - * @param {Object} obj - * @return {array} + * @param {Object} obj The object to serialize + * @param {array} keys The keys of the object + * @return {array} Result of serialization */ - formDataEncodeObject : function (obj,keys) { - var query = '', key, value, fullSubName, subName, subValue, innerObj, i; - if(!keys){ - keys=[]; - } - for (key in obj) { - value = obj[key]; - if(value instanceof stream.Stream){ - keys.push({key:key,value:value}); + static formDataEncodeObject(obj, keys) { + let value; + let fullSubName; + let subValue; + let innerObj; + let returnKeys = keys; + if (!keys) { + returnKeys = []; + } + if (!obj) { + return null; + } + const keysOfObj = Object.keys(obj); + for (let outerIter = 0; outerIter < keysOfObj.length; outerIter += 1) { + value = obj[keysOfObj[outerIter]]; + if (value instanceof stream.Stream) { + returnKeys.push({ + key: keysOfObj[outerIter], + value, + }); } else if (value instanceof Array) { - var arrayFormat = "{0}[{1}]"; - for (i = 0; i < value.length; ++i) { - subValue = value[i]; - fullSubName = this.formatString(arrayFormat,key,i); + const arrayFormat = '{0}[{1}]'; + for (let iter = 0; iter < value.length; iter += 1) { + subValue = value[iter]; + fullSubName = this.formatString(arrayFormat, keysOfObj[outerIter], iter); innerObj = {}; innerObj[fullSubName] = subValue; - this.formDataEncodeObject(innerObj,keys); + this.formDataEncodeObject(innerObj, returnKeys); } } else if (value instanceof Object) { - for (subName in value) { - subValue = value[subName]; - fullSubName = key + '[' + subName + ']'; + const subNameKeys = Object.keys(value); + for (let iter = 0; iter < subNameKeys.length; iter += 1) { + subValue = value[subNameKeys[iter]]; + fullSubName = `${keysOfObj[outerIter]}[${subNameKeys[iter]}]`; innerObj = {}; innerObj[fullSubName] = subValue; - this.formDataEncodeObject(innerObj,keys); + this.formDataEncodeObject(innerObj, returnKeys); } - } else if (value !== undefined && value !== null){ - if(!(value instanceof Object)) { - keys.push({key:key,value:value}); + } else if (value !== undefined && value !== null) { + if (!(value instanceof Object)) { + returnKeys.push({ + key: keysOfObj[outerIter], + value, + }); } } } - return keys; - }, + return returnKeys; + } /** * Converts an object to x-www-form-urlencoded serialization. - * @param {Object} obj - * @return {String} + * @param {Object} obj The object to be serialized + * @return {String} The result of serialization */ - urlEncodeObject : function (obj) { - var params = this.formDataEncodeObject(obj); - var query=""; - for(var index in params){ - var pair = params[index]; - var key = pair.key - var value = pair.value; - query= query += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&' + static urlEncodeObject(obj) { + if (!obj) { + return null; + } + const params = this.formDataEncodeObject(obj); + let query = ''; + const index = Object.keys(params); + for (let iter = 0; iter < index.length; iter += 1) { + const pair = params[index[iter]]; + const key = pair.key; + const value = pair.value; + query += `${encodeURIComponent(key)}=${encodeURIComponent(value)}&`; } return query.length ? query.substr(0, query.length - 1) : query; } + + /** + * Returns Datetime string value for field + * @param value {object} Datetime object + * @param type {string} The Datetime format of the date object (value) passed in + * @returns {string} Stringified Datetime object + */ + static stringifyDateTime(value, type) { + if (value === null || value === undefined) { + return null; + } + switch (type) { + case 'unixtimestamp': + return value.getTime(); + case 'rfc1123': + return value.toUTCString(); + case 'rfc3339': + return value.format(); + case 'date': + return value.format('YYYY-MM-DD'); + default: + return value.format('YYYY-MM-DD'); + } + } } -module.exports = APIHelper; \ No newline at end of file + +module.exports = APIHelper; diff --git a/lib/Controllers/BaseController.js b/lib/Controllers/BaseController.js new file mode 100644 index 0000000..396b141 --- /dev/null +++ b/lib/Controllers/BaseController.js @@ -0,0 +1,46 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const _objectMapper = require('../ObjectMapper'); + +const _objectMapperInstance = new _objectMapper(); + +class BaseController { + /** + * Get ObjectMapper instance + * @return {ObjectMapper} Shared instance + */ + static getObjectMapper() { + return _objectMapperInstance; + } + + /** + * Global error handling + * @param {HttpContext} _context HttpContext containing request and response objects + * @callback Callback function which returns error, response, context + */ + static validateResponse(_context) { + const errorObj = { + errorMessage: '', + errorCode: '', + errorResponse: _context.response.body, + }; + const returnObj = { + error: errorObj, + response: null, + context: _context, + }; + + returnObj.error.errorMessage = 'HTTP Response Not OK'; + returnObj.error.errorCode = _context.response.statusCode; + + return returnObj; + } +} + +module.exports = BaseController; diff --git a/lib/Controllers/EmailController.js b/lib/Controllers/EmailController.js index 0fc30b0..920a80a 100644 --- a/lib/Controllers/EmailController.js +++ b/lib/Controllers/EmailController.js @@ -1,146 +1,80 @@ -/** - * PepipostAPIV10Lib +/** + * PepipostLib * - * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) on 08/20/2016 + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ -var _request = require('../Http/Client/RequestClient'), - _configuration = require('../configuration'), - _APIHelper = require('../APIHelper'); +'use strict'; -var EmailController = { +const _request = require('../Http/Client/RequestClient'); +const _configuration = require('../configuration'); +const _apiHelper = require('../APIHelper'); +const _baseController = require('./BaseController'); +class EmailController { /** - * `Sending Mails` – This API is used for sending emails. Pepipost supports REST as well JSON formats for the input - * @param {string} apiKey Required parameter: Your API Key - * @param {string} content Required parameter: Email body in html (to use attributes to display dynamic values such as name, account number, etc. for ex. [% NAME %] for ATT_NAME , [% AGE %] for ATT_AGE etc.) - * @param {string} from Required parameter: From email address - * @param {string} recipients Required parameter: Email addresses for recipients (multiple values allowed) - * @param {string} subject Required parameter: Subject of the Email - * @param {string|null} aTTNAME Optional parameter: Specify attributes followed by ATT_ for recipient to personalized email for ex. ATT_NAME for name, ATT_AGE for age etc. (Multiple attributes are allowed) - * @param {string|null} attachmentid Optional parameter: specify uploaded attachments id (Multiple attachments are allowed) - * @param {string|null} bcc Optional parameter: Email address for bcc - * @param {bool|null} clicktrack Optional parameter: set ‘0’ or ‘1’ in-order to disable or enable the click-track - * @param {bool|null} footer Optional parameter: Set '0' or '1' in order to include footer or not - * @param {string|null} fromname Optional parameter: Email Sender name - * @param {bool|null} opentrack Optional parameter: set open-track value to ‘0’ or ‘1’ in-order to disable or enable - * @param {string|null} replytoid Optional parameter: Reply to email address - * @param {string|null} tags Optional parameter: To relate each message. Useful for reports. - * @param {int|null} template Optional parameter: Email template ID - * @param {string|null} xAPIHEADER Optional parameter: Your defined unique identifier - * @param {function} callback Required parameter: Callback function in the form of function(error, response) + * This Endpoint sends emails with the credentials passed. * - * @return {mixed} + * @param {string} apiKey (optional) Generated header parameter. Example value + * ='5ce7096ed4bf2b39dfa932ff5fa84ed9ed8' + * @param {EmailBody} body (optional) The body passed will be json format. + * + * @callback The callback function that returns response from the API call + * + * @returns {Promise} */ - getApiWebSendRest : function(apiKey, content, from, recipients, subject, aTTNAME, attachmentid, bcc, clicktrack, footer, fromname, opentrack, replytoid, tags, template, xAPIHEADER, callback){ - //Assign default values - clicktrack = clicktrack || true; - footer = footer || true; - opentrack = opentrack || true; - - //prepare query string for API call; - var _baseUri = _configuration.BASEURI; - - var _queryBuilder = _baseUri + "/api/web.send.rest"; - - //Process query parameters - _queryBuilder = _APIHelper.appendUrlWithQueryParameters(_queryBuilder, { - "api_key" : apiKey, - "content" : content, - "from" : from, - "recipients" : recipients, - "subject" : subject, - "ATT_NAME" : aTTNAME, - "attachmentid" : attachmentid, - "bcc" : bcc, - "clicktrack" : (null != clicktrack)? clicktrack: true, - "footer" : (null != footer)? footer: true, - "fromname" : fromname, - "opentrack" : (null != opentrack)? opentrack: true, - "replytoid" : replytoid, - "tags" : tags, - "template" : template, - "X-APIHEADER" : xAPIHEADER - }); + static createSendEmail(apiKey, body, callback) { + // create empty callback if absent + const _callback = typeof callback === 'function' ? callback : () => undefined; - //validate and preprocess url - var _queryUrl = _APIHelper.cleanUrl(_queryBuilder); - - //prepare headers - var _headers = { - "accept" : "application/json" - }; + // prepare query string for API call + const _baseUri = _configuration.BASEURI; - //Construct the request - var _options = { - queryUrl: _queryUrl, - method: "GET", - headers: _headers, - }; - - //Build the response processing. - function cb(_error, _response, _context) { - if(_error) { - callback({errorMessage: _error.message, errorCode: _error.code},null,_context); - } else if (_response.statusCode >= 200 && _response.statusCode <= 206) { - var parsed = JSON.parse(_response.body); - callback(null,parsed,_context); - } else { - callback({errorMessage: "HTTP Response Not OK", errorCode: _response.statusCode, errorResponse:_response.body},null,_context); - } - } - _request(_options, cb); - }, + const _queryBuilder = `${_baseUri}${'/v2/sendEmail'}`; + // validate and preprocess url + const _queryUrl = _apiHelper.cleanUrl(_queryBuilder); - /** - * `Sending Mails` – This API is used for sending emails. Pepipost supports REST as well JSON formats for the input. This is JSON API. - * @param {Emailv1} data Required parameter: Data in JSON format - * @param {function} callback Required parameter: Callback function in the form of function(error, response) - * - * @return {mixed} - */ - //createApiWebSendJson : function(data, callback){ - send : function(data, callback){ - //prepare query string for API call; - var _baseUri = _configuration.BASEURI; - - var _queryBuilder = _baseUri + "/api/web.send.json"; - - //validate and preprocess url - var _queryUrl = _APIHelper.cleanUrl(_queryBuilder); - - //prepare headers - var _headers = { - "accept" : "application/json", - "content-type" : "application/json; charset=utf-8" + // prepare headers + const _headers = { + accept: 'application/json', + 'content-type': 'application/json; charset=utf-8', + api_key: apiKey, }; - //Remove null values - _APIHelper.cleanObject(data); + // remove null values + _apiHelper.cleanObject(body); - //Construct the request - var _options = { + // construct the request + const _options = { queryUrl: _queryUrl, - method: "POST", + method: 'POST', headers: _headers, - body : _APIHelper.jsonSerialize(data), + body: _apiHelper.jsonSerialize(body), }; - - //Build the response processing. - function cb(_error, _response, _context) { - if(_error) { - callback({errorMessage: _error.message, errorCode: _error.code},null,_context); - } else if (_response.statusCode >= 200 && _response.statusCode <= 206) { - var parsed = JSON.parse(_response.body); - callback(null,parsed,_context); - } else { - callback({errorMessage: "HTTP Response Not OK", errorCode: _response.statusCode, errorResponse:_response.body},null,_context); - } - } - _request(_options, cb); - } -}; - -module.exports = EmailController; \ No newline at end of file + // build the response processing. + return new Promise((_fulfill, _reject) => { + _request(_options, (_error, _response, _context) => { + let errorResponse; + if (_error) { + _fulfill(_response.body); + } else if (_response.statusCode >= 200 && _response.statusCode <= 206) { + let parsed = JSON.parse(_response.body); + _callback(null, parsed, _context); + _fulfill(parsed); + } else if (_response.statusCode === 405) { + const _err = { errorMessage: 'Method not allowed', + errorCode: 405, + errorResponse: _response.body, + }; + _callback(_err, null, _context); + _reject(_err); + } else { + _fulfill(_response.body); + } + }); + }); + } +} +module.exports = EmailController; diff --git a/lib/Exceptions/APIException.js b/lib/Exceptions/APIException.js new file mode 100644 index 0000000..c985708 --- /dev/null +++ b/lib/Exceptions/APIException.js @@ -0,0 +1,30 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + + /** + * Creates an instance of APIException + */ +class APIException { + /** + * @constructor + */ + constructor() { + this.reason = ''; + this.context = ''; + } + + /** + * Function containing information about the fields of this model + * @return {array} Empty array + */ + static mappingInfo() { + return []; + } +} + +module.exports = APIException; diff --git a/lib/Http/Client/HttpContext.js b/lib/Http/Client/HttpContext.js index 48382ac..01751c9 100644 --- a/lib/Http/Client/HttpContext.js +++ b/lib/Http/Client/HttpContext.js @@ -1,18 +1,17 @@ /** - * Created by Kartik Andalam on 9/8/15. - * Copyright (c) 2015 APIMatic. All rights reserved. - * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ +'use strict'; /** - * Creates a instance of HttpContext. - * - * @constructor + * Creates an instance of HttpContext. */ -function HttpContext() { - this.request = null; - this.response = null; +class HttpContext { + constructor() { + this.request = null; + this.response = null; + } } -module.exports = HttpContext; \ No newline at end of file +module.exports = HttpContext; diff --git a/lib/Http/Client/RequestClient.js b/lib/Http/Client/RequestClient.js index 61285d5..cbbf813 100644 --- a/lib/Http/Client/RequestClient.js +++ b/lib/Http/Client/RequestClient.js @@ -1,85 +1,87 @@ /** - * Created by Kartik Andalam on 9/8/15. - * Copyright (c) 2015 APIMatic. All rights reserved. - * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ -var HttpContext = require("./HttpContext"); -var HttpResponse = require("../Response/HttpResponse"); -var request = require("request"); -var APIHelper = require('../../APIHelper'); -var convertHttpRequest = function (req) { - //Convert to request's version of http request +'use strict'; - var options = { +const HttpContext = require('./HttpContext'); +const HttpResponse = require('../Response/HttpResponse'); +const request = require('request'); +const APIHelper = require('../../APIHelper'); + +// convert to request's version of http request +const convertHttpRequest = function convertHttpRequest(req) { + const options = { url: req.queryUrl, method: req.method, - headers: req.headers + headers: req.headers, }; if (req.username) { - options.auth = {user:req.username, pass:req.password}; + options.auth = { user: req.username, pass: req.password }; } if (req.body) { options.body = req.body; } if (req.formData) { - //Need to add to request's formdata object directly - //options.formData = APIHelper.formDataEncodeObject(req.formData); + // need to add to request's formdata object directly + // options.formData = APIHelper.formDataEncodeObject(req.formData); } if (req.form) { options.form = APIHelper.urlEncodeObject(req.form); - options.headers["content-type"] = 'application/x-www-form-urlencoded'; + options.headers['content-type'] = 'application/x-www-form-urlencoded'; } return options; -} +}; -var appendFormdata = function (form, data) { - var dataArray = APIHelper.formDataEncodeObject(data); - for (var index in dataArray) { - var key = dataArray[index].key - var value = dataArray[index].value; - form.append(key, value); +const appendFormdata = function appendFormdata(form, data) { + const dataArray = APIHelper.formDataEncodeObject(data); + for (let index = 0; index < dataArray.length; index += 1) { + if (Object.prototype.hasOwnProperty.call(dataArray, index)) { + const key = dataArray[index].key; + const value = dataArray[index].value; + form.append(key, value); + } } -} +}; -var convertHttpResponse = function (resp) { - var response = new HttpResponse(); - if(resp) { +const convertHttpResponse = function convertHttpResponse(resp) { + const response = new HttpResponse(); + if (resp) { response.body = resp.body; response.headers = resp.headers; response.statusCode = resp.statusCode; } return response; -} +}; /** * Execute a given HttpRequest to get string response back - * @param {HttpRequest | HttpBodyRequest} request The query string builder to replace the template parameters - * @param {Array} parameters The parameters to replace in the queryBuilder + * @param {HttpRequest | HttpBodyRequest} req The query string builder to replace the + * template parameters + * @param {function} callback Callback function to execute when request completes or fails + * @param {Array} parameters The parameters to replace in the queryBuilder + * @returns {void} Does not return anything */ -function executeRequest(req, callback) { - - //Convert abstracted request to request's http request - var convertedRequest = convertHttpRequest(req); - var context = new HttpContext(); +const executeRequest = function executeRequest(req, callback) { + // convert abstracted request to request's http request + const convertedRequest = convertHttpRequest(req); + const context = new HttpContext(); context.request = req; - //Make a temp callback - var internalCallback = function cb(error, res, body) { - var response = convertHttpResponse(res); + // make a temp callback + const internalCallback = function cb(error, res) { + const response = convertHttpResponse(res); context.response = response; callback(error, response, context); }; - //Make the request; - var r = request(convertedRequest, internalCallback); - - //Add formdata directly. + // make the request + const rq = request(convertedRequest, internalCallback); + // add formdata directly. if (req.formData) { - var form = r.form(); + const form = rq.form(); appendFormdata(form, req.formData); } - -} +}; module.exports = executeRequest; diff --git a/lib/Http/Request/HttpRequest.js b/lib/Http/Request/HttpRequest.js index fa74bdb..4699b27 100644 --- a/lib/Http/Request/HttpRequest.js +++ b/lib/Http/Request/HttpRequest.js @@ -1,25 +1,23 @@ /** - * Created by Kartik Andalam on 9/8/15. - * Copyright (c) 2015 APIMatic. All rights reserved. - * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ +'use strict'; /** - * Creates a instance of HttpRequest - * - * @constructor + * Creates an instance of HttpRequest */ -function HttpRequest() { - - this.method = null; - this.headers = {}; - this.queryUrl = null; - this.formData = null; - this.form = null; - this.username = null; - this.password = null; - this.body = null; +class HttpRequest { + constructor() { + this.method = null; + this.headers = {}; + this.queryUrl = null; + this.formData = null; + this.form = null; + this.username = null; + this.password = null; + this.body = null; + } } -module.exports = HttpRequest; \ No newline at end of file +module.exports = HttpRequest; diff --git a/lib/Http/Response/HttpResponse.js b/lib/Http/Response/HttpResponse.js index aa14c0b..0dbbd7a 100644 --- a/lib/Http/Response/HttpResponse.js +++ b/lib/Http/Response/HttpResponse.js @@ -1,21 +1,18 @@ /** - * Created by Kartik Andalam on 9/8/15. - * Copyright (c) 2015 APIMatic. All rights reserved. - * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ +'use strict'; /** - * Creates a instance of HttpResponse - * - * @constructor + * Creates an instance of HttpResponse */ -function HttpResponse() { - - this.statusCode = null; - this.body = null; - this.headers = null; - +class HttpResponse { + constructor() { + this.statusCode = null; + this.body = null; + this.headers = null; + } } -module.exports = HttpResponse; \ No newline at end of file +module.exports = HttpResponse; diff --git a/lib/ModelFactory.js b/lib/ModelFactory.js new file mode 100644 index 0000000..0bf43f9 --- /dev/null +++ b/lib/ModelFactory.js @@ -0,0 +1,45 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const Attribute = require('../lib/Models/Attribute'); +const From = require('../lib/Models/From'); +const EmailBodyAttachments = require('../lib/Models/EmailBodyAttachments'); +const Attachments = require('../lib/Models/Attachments'); +const Personalizations = require('../lib/Models/Personalizations'); +const EmailBody = require('../lib/Models/EmailBody'); +const Settings = require('../lib/Models/Settings'); +const SendEmailError = require('../lib/Models/SendEmailError'); +const SendEmailResponse = require('../lib/Models/SendEmailResponse'); + +const classMap = { + Attribute, + From, + EmailBodyAttachments, + Attachments, + Personalizations, + EmailBody, + Settings, + SendEmailError, + SendEmailResponse, +}; + +/** + * Factory class to create instances of models and exception classes + */ +class ModelFactory { + /** + * Creates instance of a model class + * @param modelName {string} Name of class to instantiate + * @returns {object} Instance of the model class + */ + static getInstance(modelName) { + return new classMap[modelName](); + } +} + +module.exports = ModelFactory; diff --git a/lib/Models/Attachments.js b/lib/Models/Attachments.js new file mode 100644 index 0000000..27e15d5 --- /dev/null +++ b/lib/Models/Attachments.js @@ -0,0 +1,49 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of Attachments + */ +class Attachments extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.fileContent = this.constructor.getValue(obj.fileContent); + this.fileName = this.constructor.getValue(obj.fileName); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'fileContent', realName: 'fileContent' }, + { name: 'fileName', realName: 'fileName' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = Attachments; diff --git a/lib/Models/Attribute.js b/lib/Models/Attribute.js new file mode 100644 index 0000000..0c81f1e --- /dev/null +++ b/lib/Models/Attribute.js @@ -0,0 +1,49 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of Attribute + */ +class Attribute extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.myname = this.constructor.getValue(obj.myname); + this.age = this.constructor.getValue(obj.age); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'myname', realName: 'myname' }, + { name: 'age', realName: 'age' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = Attribute; diff --git a/lib/Models/BaseModel.js b/lib/Models/BaseModel.js index ea86069..44a5e7f 100644 --- a/lib/Models/BaseModel.js +++ b/lib/Models/BaseModel.js @@ -1,30 +1,129 @@ /** - * PepipostAPIV10Lib + * PepipostLib * - * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) on 08/20/2016 + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ +'use strict'; + +const _apiHelper = require('../APIHelper'); +const moment = require('moment'); + /** - * Creates a instance of BaseModel - * - * @constructor + * Creates an instance of BaseModel */ -function BaseModel() { - //Maintain a name mapping dictionary - this._variableDict= []; - this.toJSON = function(){ - var newDict = {}; - for(var prop in this){ - if(typeof this[prop]!=="function" && prop !== "_variableDict"){ - if(prop in this._variableDict){ - var value = this._variableDict[prop]; - newDict[value] = this[prop]; - }else{ - newDict[prop] = this[prop]; +class BaseModel { + /** + * Returns value for the object called + * @param obj {string} The value to be assigned + * @param defaultValue {string} The default value for the field + * @returns The correct value for the field + */ + static getValue(obj, defaultValue) { + if (obj === undefined || obj === null) { + return null; + } + let returnValue; + if (obj !== undefined) { + returnValue = obj; + } else { + returnValue = (defaultValue !== null || defaultValue !== undefined) ? + defaultValue : null; + } + return returnValue; + } + + /** + * Helper function to check if value exists in the array of objects + * @param val {string} The value to be checked in array + * @returns If value doesn't exist in the array, returns null. Otherwise, returns the value + */ + mappingInfoContains(val) { + const mapInfo = this.constructor.mappingInfo(); + const keys = Object.keys(mapInfo); + let returnValue = null; + for (let iter = 0; iter < keys.length; iter += 1) { + if (val === mapInfo[iter].name) { + returnValue = mapInfo[iter].realName; + break; + } + } + return returnValue; + } + + /** + * Helper function to get the value (type) of datetime fields + * @param name {string} The (actual) name of the field + * @returns If field is not a date/datetime field, returns undefined. + * Otherwise, returns the value (type) + */ + getDateTimeValueForField(name) { + if (name === undefined || name === null) { + return null; + } + let value; + const fieldsInfo = this.constructor.mappingInfo(); + fieldsInfo.forEach((field) => { + if (field.realName === name && field.isDateTime && value === undefined) { + value = (field.dateTimeValue !== undefined) ? field.dateTimeValue : 'date'; + } + }); + return value; + } + + /** + * Helper Function to get Serialized Model + * @returns {object} Dictionary of all model properties alongwith + * additional properties (if any) + */ + toJSON() { + const newDict = {}; + const props = Object.keys(this); + for (let iter = 0; iter < props.length; iter += 1) { + if (typeof this[props[iter]] !== 'function') { + // the properties that already exist in the models + const propsThatExist = this.mappingInfoContains(props[iter]); + const value = propsThatExist !== null ? propsThatExist : props[iter]; + if (this[props[iter]] instanceof Object && + this[props[iter]].constructor !== Array && + !(this[props[iter]] instanceof moment) && + !(this[props[iter]] instanceof Date)) { + if (typeof this[props[iter]].toJSON === 'function') { + this[props[iter]] = this[props[iter]].toJSON(); + newDict[value] = this[props[iter]]; + } + } else if (this[props[iter]] !== undefined && + this[props[iter]] !== null && + this[props[iter]].constructor === Array) { + this[props[iter]].forEach((item, index) => { + if (item !== undefined && typeof item.toJSON === 'function') { + const serializedItem = item.toJSON(); + this[props[iter]][index] = serializedItem; + } + }); + newDict[value] = this[props[iter]]; + } else { + const dateTimeType = this.getDateTimeValueForField(value); + if (dateTimeType !== null && dateTimeType !== undefined) { + // this means it's date/datetime field + newDict[value] = + _apiHelper.stringifyDateTime(this[props[iter]], dateTimeType); + } else { + newDict[value] = this[props[iter]]; } } - } + } + } return (newDict); } + + /** + * Function containing information about the fields of this model + * @returns {array} Empty array + */ + static mappingInfo() { + return []; + } } -module.exports = BaseModel; \ No newline at end of file + +module.exports = BaseModel; diff --git a/lib/Models/EmailBody.js b/lib/Models/EmailBody.js new file mode 100644 index 0000000..2dfa4dd --- /dev/null +++ b/lib/Models/EmailBody.js @@ -0,0 +1,73 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of EmailBody + */ +class EmailBody extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.personalizations = this.constructor.getValue(obj.personalizations); + this.tags = this.constructor.getValue(obj.tags); + this.from = this.constructor.getValue(obj.from); + this.subject = this.constructor.getValue(obj.subject); + this.content = this.constructor.getValue(obj.content); + this.attachments = this.constructor.getValue(obj.attachments); + this.settings = this.constructor.getValue(obj.settings); + this.replyToId = this.constructor.getValue(obj.replyToId); + this.templateId = this.constructor.getValue(obj.templateId); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { + name: 'personalizations', + realName: 'personalizations', + array: true, + type: 'Personalizations', + }, + { name: 'tags', realName: 'tags' }, + { name: 'from', realName: 'from', type: 'From' }, + { name: 'subject', realName: 'subject' }, + { name: 'content', realName: 'content' }, + { + name: 'attachments', + realName: 'attachments', + array: true, + type: 'EmailBodyAttachments', + }, + { name: 'settings', realName: 'settings', type: 'Settings' }, + { name: 'replyToId', realName: 'replyToId' }, + { name: 'templateId', realName: 'templateId' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = EmailBody; diff --git a/lib/Models/EmailBodyAttachments.js b/lib/Models/EmailBodyAttachments.js new file mode 100644 index 0000000..143cbbf --- /dev/null +++ b/lib/Models/EmailBodyAttachments.js @@ -0,0 +1,49 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of EmailBodyAttachments + */ +class EmailBodyAttachments extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.fileContent = this.constructor.getValue(obj.fileContent); + this.fileName = this.constructor.getValue(obj.fileName); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'fileContent', realName: 'fileContent' }, + { name: 'fileName', realName: 'fileName' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = EmailBodyAttachments; diff --git a/lib/Models/From.js b/lib/Models/From.js new file mode 100644 index 0000000..b144199 --- /dev/null +++ b/lib/Models/From.js @@ -0,0 +1,49 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of From + */ +class From extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.fromEmail = this.constructor.getValue(obj.fromEmail); + this.fromName = this.constructor.getValue(obj.fromName); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'fromEmail', realName: 'fromEmail' }, + { name: 'fromName', realName: 'fromName' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = From; diff --git a/lib/Models/Personalizations.js b/lib/Models/Personalizations.js new file mode 100644 index 0000000..19c5aac --- /dev/null +++ b/lib/Models/Personalizations.js @@ -0,0 +1,57 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of Personalizations + */ +class Personalizations extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.recipient = this.constructor.getValue(obj.recipient); + this.xApiheaderCc = this.constructor.getValue(obj.xApiheaderCc || obj['x-apiheader_cc']); + this.xApiheader = this.constructor.getValue(obj.xApiheader || obj['x-apiheader']); + this.attributes = this.constructor.getValue(obj.attributes); + this.attachments = this.constructor.getValue(obj.attachments); + this.recipientCc = this.constructor.getValue(obj.recipientCc || obj.recipient_cc); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'recipient', realName: 'recipient' }, + { name: 'xApiheaderCc', realName: 'x-apiheader_cc' }, + { name: 'xApiheader', realName: 'x-apiheader' }, + { name: 'attributes', realName: 'attributes' }, + { name: 'attachments', realName: 'attachments', array: true, type: 'Attachments' }, + { name: 'recipientCc', realName: 'recipient_cc', array: true }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = Personalizations; diff --git a/lib/Models/SendEmailError.js b/lib/Models/SendEmailError.js new file mode 100644 index 0000000..6daa5d0 --- /dev/null +++ b/lib/Models/SendEmailError.js @@ -0,0 +1,49 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of SendEmailError + */ +class SendEmailError extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.errorMessage = this.constructor.getValue(obj.errorMessage || obj.error_message); + this.errorCode = this.constructor.getValue(obj.errorCode || obj.error_code); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'errorMessage', realName: 'error_message' }, + { name: 'errorCode', realName: 'error_code' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = SendEmailError; diff --git a/lib/Models/SendEmailResponse.js b/lib/Models/SendEmailResponse.js new file mode 100644 index 0000000..92e044f --- /dev/null +++ b/lib/Models/SendEmailResponse.js @@ -0,0 +1,51 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const BaseModel = require('./BaseModel'); + +/** + * Creates an instance of SendEmailResponse + */ +class SendEmailResponse extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.data = this.constructor.getValue(obj.data); + this.message = this.constructor.getValue(obj.message); + this.errorInfo = this.constructor.getValue(obj.errorInfo || obj.error_info); + } + + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'data', realName: 'data' }, + { name: 'message', realName: 'message' }, + { name: 'errorInfo', realName: 'error_info', type: 'SendEmailError' }, + ]); + } + + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} + +module.exports = SendEmailResponse; diff --git a/lib/Models/Settings.js b/lib/Models/Settings.js index 118eaa9..f4afb9e 100644 --- a/lib/Models/Settings.js +++ b/lib/Models/Settings.js @@ -1,163 +1,55 @@ - -/** - * PepipostAPIV10Lib - * - * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) on 08/20/2016 - */ -var BaseModel = require("./BaseModel"); -/** - * Creates a instance of Settings - * - * @constructor - */ -Settings = function (obj) { - if(!obj) { - this.attachmentid = null; - this.bcc = null; - this.clicktrack = true; - this.footer = true; - this.opentrack = true; - this.template = null; - this.unsubscribe = true; - } else { - this.attachmentid = obj.attachmentid; - this.bcc = obj.bcc; - this.clicktrack = obj.clicktrack; - this.footer = obj.footer; - this.opentrack = obj.opentrack; - this.template = obj.template; - this.unsubscribe = obj.unsubscribe; - } -}; - -Settings.prototype = new BaseModel(); -Settings.prototype.constructor = Settings; - -/** - * TODO: Write general description for this method - * - * @return {string|null} - */ -Settings.prototype.getAttachmentid = function() { - return this.attachmentid; -}; - -/** - * Setter for Attachmentid - * - * @param {string|null} value - */ -Settings.prototype.setAttachmentid = function(value) { - this.attachmentid = value; -}; - -/** - * TODO: Write general description for this method - * - * @return {string|null} - */ -Settings.prototype.getBcc = function() { - return this.bcc; -}; - -/** - * Setter for Bcc - * - * @param {string|null} value - */ -Settings.prototype.setBcc = function(value) { - this.bcc = value; -}; - -/** - * TODO: Write general description for this method - * - * @return {bool|null} - */ -Settings.prototype.getClicktrack = function() { - return this.clicktrack; -}; - /** - * Setter for Clicktrack - * - * @param {bool|null} value - */ -Settings.prototype.setClicktrack = function(value) { - this.clicktrack = value; -}; - -/** - * TODO: Write general description for this method + * PepipostLib * - * @return {bool|null} - */ -Settings.prototype.getFooter = function() { - return this.footer; -}; - -/** - * Setter for Footer - * - * @param {bool|null} value - */ -Settings.prototype.setFooter = function(value) { - this.footer = value; -}; - -/** - * TODO: Write general description for this method - * - * @return {bool|null} - */ -Settings.prototype.getOpentrack = function() { - return this.opentrack; -}; - -/** - * Setter for Opentrack - * - * @param {bool|null} value + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ -Settings.prototype.setOpentrack = function(value) { - this.opentrack = value; -}; -/** - * TODO: Write general description for this method - * - * @return {int|null} - */ -Settings.prototype.getTemplate = function() { - return this.template; -}; +'use strict'; -/** - * Setter for Template - * - * @param {int|null} value - */ -Settings.prototype.setTemplate = function(value) { - this.template = value; -}; +const BaseModel = require('./BaseModel'); /** - * TODO: Write general description for this method - * - * @return {bool|null} + * Creates an instance of Settings */ -Settings.prototype.getUnsubscribe = function() { - return this.unsubscribe; -}; +class Settings extends BaseModel { + /** + * @constructor + * @param {Object} obj The object passed to constructor + */ + constructor(obj) { + super(obj); + if (obj === undefined || obj === null) return; + this.footer = this.constructor.getValue(obj.footer); + this.clicktrack = this.constructor.getValue(obj.clicktrack); + this.opentrack = this.constructor.getValue(obj.opentrack); + this.unsubscribe = this.constructor.getValue(obj.unsubscribe); + this.bcc = this.constructor.getValue(obj.bcc); + } -/** - * Setter for Unsubscribe - * - * @param {bool|null} value - */ -Settings.prototype.setUnsubscribe = function(value) { - this.unsubscribe = value; -}; + /** + * Function containing information about the fields of this model + * @return {array} Array of objects containing information about the fields + */ + static mappingInfo() { + return super.mappingInfo().concat([ + { name: 'footer', realName: 'footer' }, + { name: 'clicktrack', realName: 'clicktrack' }, + { name: 'opentrack', realName: 'opentrack' }, + { name: 'unsubscribe', realName: 'unsubscribe' }, + { name: 'bcc', realName: 'bcc' }, + ]); + } + /** + * Function containing information about discriminator values + * mapped with their corresponding model class names + * + * @return {object} Object containing Key-Value pairs mapping discriminator + * values with their corresponding model classes + */ + static discriminatorMap() { + return {}; + } +} -module.exports = Settings; \ No newline at end of file +module.exports = Settings; diff --git a/lib/ObjectMapper.js b/lib/ObjectMapper.js new file mode 100644 index 0000000..90875a7 --- /dev/null +++ b/lib/ObjectMapper.js @@ -0,0 +1,178 @@ +/** + * PepipostLib + * + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) + */ + +'use strict'; + +const moment = require('moment'); +const modelFactory = require('./ModelFactory'); + +/** + * ObjectMapper is utility class that helps maps a POJO to a model or exception object. + * Embedded models and dates are also instantiated to their correct types. + */ +class ObjectMapper { + /** + * Returns Datetime parsed value for field + * @param value {string} The value to be parsed + * @param type {string} The Datetime format to be parsed into + * @returns {object} Parsed Datetime object + */ + static parseDateTime(value, type) { + if (value === null || value === undefined) { + return null; + } + switch (type) { + case 'unixtimestamp': + return new Date(value); + case 'rfc1123': + return new Date(value); + case 'rfc3339': + return moment(value).parseZone(value); + case 'date': + return moment(value, 'YYYY-MM-DD'); + default: + return moment(value, 'YYYY-MM-DD'); + } + } + + /** + * Helper function to get the name of discriminator field + * + * @param fieldMap {array} The mapping information of the model's fields + * + * @returns {string} The name of the discriminator field. + * Returns null if discriminator field is not present + */ + static getDiscriminatorFieldName(fieldMap) { + if (fieldMap === null || fieldMap === undefined) { + return null; + } + let name = null; + fieldMap.forEach((field) => { + if (field.isDiscrim) { + name = field.realName; + } + }); + return name; + } + + /** + * Helper function to get the value of discriminator + * This helper function checks values inside nested objects and arrays of objects as well. + * + * @param json {object} Input object (API response) + * @param discrimName {string} The name of the discriminator field + * + * @returns {string} The value of the discriminator field present in the input object + * Returns null if no value is present in the input + */ + static getDiscriminatorFieldValue(json, discrimName) { + if (json === null || + json === undefined || + discrimName === null || + discrimName === undefined) { + return null; + } + let value = null; + if (json instanceof Object && json.constructor !== Array) { + if (Object.prototype.hasOwnProperty.call(json, discrimName)) { + value = json[discrimName]; + } + } + return value; + } + + /** + * Helper function to get the model name corresponding to the discriminator value + * + * @param fieldMap {object} The discriminator map stored in the model class + * @param discrimValue {string} The value of the discriminator which maps + * to a model class + * + * @returns {string} The name of the model class corresponding to the discriminator + * value passed in. + */ + static getDiscriminatorClass(fieldMap, discrimValue) { + if (discrimValue === undefined || + discrimValue === null || + fieldMap === null || + fieldMap === undefined) { + return null; + } + let className = null; + if (Object.prototype.hasOwnProperty.call(fieldMap, discrimValue)) { + className = fieldMap[discrimValue]; + } + return className; + } + + /** + * Helper function to map input object with model fields + * @param json {object} Input object to be mapped onto model fields + * @param modelName {string} The name of model to instantiate + * @returns {object} Object containing mapped fields of model + */ + mapObject(json, modelName) { + if (json === null || json === undefined) { + return null; + } + let instance = modelName; + const modelInstance = modelFactory.getInstance(modelName); + const discrimName = + ObjectMapper.getDiscriminatorFieldName(modelInstance.constructor.mappingInfo()); + const discrimValue = + ObjectMapper.getDiscriminatorFieldValue(json, discrimName); + if (discrimName !== null && + discrimName !== undefined && + discrimValue !== null && + discrimValue !== undefined) { + instance = + ObjectMapper.getDiscriminatorClass(modelInstance.constructor.discriminatorMap(), + discrimValue); + } + return this.mapFields(json, modelFactory.getInstance(instance)); + } + + /** + * Maps the instance's fields with the values in input object + * The function helps in deserializing a model instance + * @param json {object} Input object to be mapped onto model fields + * @param instance {object} The instance of the model class + * @returns {object} Mapped instance of model class + */ + mapFields(json, instance) { + const returnInstance = instance; + const fieldsInfo = instance.constructor.mappingInfo(); + fieldsInfo.forEach((fieldInfo) => { + if (fieldInfo.type) { + if (fieldInfo.array) { + if (json[fieldInfo.realName] !== null && + json[fieldInfo.realName] !== undefined) { + returnInstance[fieldInfo.name] = json[fieldInfo.realName].map(obj => + this.mapObject(obj, fieldInfo.type)); + } + } else { + returnInstance[fieldInfo.name] = + this.mapObject(json[fieldInfo.realName], fieldInfo.type); + } + } else if (fieldInfo.isDateTime) { + returnInstance[fieldInfo.name] = + json[fieldInfo.realName] === null || json[fieldInfo.realName] === undefined ? + json[fieldInfo.realName] : + ObjectMapper.parseDateTime(json[fieldInfo.realName], + fieldInfo.dateTimeValue); + } else { + returnInstance[fieldInfo.name] = + json[fieldInfo.realName] === null || json[fieldInfo.realName] === undefined ? + instance[fieldInfo.name] : + json[fieldInfo.realName]; + } + }); + return returnInstance; + } +} + +module.exports = ObjectMapper; diff --git a/lib/configuration.js b/lib/configuration.js index 31c8a94..10b803f 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -1,14 +1,16 @@ /** - * PepipostAPIV10Lib + * PepipostLib * - * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) on 08/20/2016 + * This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) */ -var configuration = { - //The base Uri for API calls - BASEURI : "https://api.pepipost.com" +'use strict'; -}; -module.exports = configuration; +const Configuration = { + // The base Uri for API calls + BASEURI: 'http://api.pepipost.com', + +}; +module.exports = Configuration; diff --git a/lib/index.js b/lib/index.js index 65e1c85..04b3b4a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,29 +1,43 @@ /** - * @module PepipostAPIV10Lib - * - * Pepipost API documentation + * @module PepipostLib + * + * Pepipost is a cloud-based SMTP relay service that delivers highly personalised transactional + * emails to the inbox within seconds of your customer’s transaction */ -var configuration = require('./configuration'), - EmailController = require('./Controllers/EmailController'), - Attributes = require('./Models/Attributes'), - Files = require('./Models/Files'), - Emailv1 = require('./Models/Emailv1'), - EmailDetails = require('./Models/EmailDetails'), - Settings = require('./Models/Settings'); +'use strict'; +const Configuration = require('./configuration'); +const EmailController = require('./Controllers/EmailController'); +const Attribute = require('./Models/Attribute'); +const From = require('./Models/From'); +const EmailBodyAttachments = require('./Models/EmailBodyAttachments'); +const Attachments = require('./Models/Attachments'); +const Personalizations = require('./Models/Personalizations'); +const EmailBody = require('./Models/EmailBody'); +const Settings = require('./Models/Settings'); +const SendEmailError = require('./Models/SendEmailError'); +const SendEmailResponse = require('./Models/SendEmailResponse'); +const APIException = require('./Exceptions/APIException'); -function initializer(){} -//Main functional components of PepipostAPIV10Lib -initializer.configuration = configuration; -initializer.EmailController = EmailController; +const initializer = { + // functional components of PepipostLib + Configuration, + // controllers of PepipostLib + EmailController, + // models of PepipostLib + Attribute, + From, + EmailBodyAttachments, + Attachments, + Personalizations, + EmailBody, + Settings, + SendEmailError, + SendEmailResponse, + // exceptions of PepipostLib + APIException, +}; -//Main Models of PepipostAPIV10Lib -initializer.Attributes = Attributes; -initializer.Files = Files; -initializer.Emailv1 = Emailv1; -initializer.EmailDetails = EmailDetails; -initializer.Settings = Settings; - -module.exports = initializer; \ No newline at end of file +module.exports = initializer; diff --git a/package.json b/package.json index a00d9b9..015689b 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,47 @@ { - "name": "pepipost-sdk-nodejs", - "version": "0.2.0", - "description": "Pepipost SDK for NodeJS", - "main": "./lib/index.js", - "scripts": {}, - "keywords": [], - "author": "Tabrez Shaikh", - "dependencies": { - "request": "^2.55.0", - "string": "^3.1.1" - } + "name": "pepipost", + "version": "2.5.2", + "description": "Official nodejs library for sending email using web API v2", + "main": "./lib/index.js", + "scripts": { + "lint": "eslint lib" + }, + "keywords": [], + "author": "Vikram Sahu - DX team, Pepipost", + "bugs": { + "email": "dx@pepipost.com" + }, + "license": "(MIT)", + "repository": { + "type": "git", + "url": "https://github.com/pepipost/pepipost-sdk-nodejs.git" + }, + "devDependencies": { + "eslint": "^3.18.0", + "eslint-config-airbnb": "^14.1.0", + "eslint-plugin-import": "^2.2.0", + "eslint-plugin-jsx-a11y": "^4.0.0", + "eslint-plugin-react": "^6.10.3" + }, + "dependencies": { + "request": "^2.55.0", + "moment": "^2.17.1" + }, + "eslintConfig": { + "extends": "airbnb", + "env": { + "commonjs": true, + "node": true, + "mocha": true + }, + "rules": { + "indent": [ + "error", + 4 + ], + "no-underscore-dangle": 0, + "strict": 0, + "prefer-rest-params": 0 + } + } }