node-mailjet
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ var express = require('express'); |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ var mailjetController = require('../mailjetController'); |
@@ -0,0 +0,0 @@ var express = require('express'); |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
var mailjet = require('./mailjet-client') | ||
module.exports = mailjet |
@@ -31,4 +31,2 @@ /* | ||
const STRICT = false | ||
/* | ||
@@ -51,3 +49,3 @@ * Imports. | ||
/* Extend superagent request with proxy method */ | ||
require('superagent-proxy')(request); | ||
require('superagent-proxy')(request) | ||
@@ -65,3 +63,3 @@ /* | ||
function MailjetClient (api_key, api_secret, options, perform_api_call) { | ||
this.config = this.setConfig(options); | ||
this.config = this.setConfig(options) | ||
this.perform_api_call = perform_api_call || false | ||
@@ -113,3 +111,3 @@ // To be updated according to the npm repo version | ||
if (options) { | ||
this.config = this.setConfig(options); | ||
this.config = this.setConfig(options) | ||
} | ||
@@ -120,3 +118,3 @@ return this | ||
MailjetClient.prototype.setConfig = function (options) { | ||
config = require('./config') | ||
const config = require('./config') | ||
if (typeof options === 'object' && options != null && options.length != 0) { | ||
@@ -127,8 +125,8 @@ if (options.url) config.url = options.url | ||
if (options.perform_api_call) config.perform_api_call = options.perform_api_call | ||
} else if (options != undefined) { | ||
throw "warning, your options variable is not a valid object." | ||
} else if (options != null) { | ||
throw new Error('warning, your options variable is not a valid object.') | ||
} | ||
return config | ||
}; | ||
} | ||
@@ -153,4 +151,4 @@ /* | ||
url = (options && 'url' in options ? options.url : this.config.url) | ||
api_version = (options && 'version' in options ? options.version : this.config.version) | ||
const url = (options && 'url' in options ? options.url : this.config.url) | ||
const api_version = (options && 'version' in options ? options.version : this.config.version) | ||
@@ -232,3 +230,3 @@ var base = _path.join(api_version, sub) | ||
error.statusCode = err.status || null | ||
error.response = result || null | ||
error.response = result || null | ||
return ret(error) | ||
@@ -305,13 +303,14 @@ } | ||
})(), that.options) | ||
var secured = null | ||
if (that.options && 'secured' in that.options) { | ||
secured = that.options.secured; | ||
secured = that.options.secured | ||
} else { | ||
secured = self.config.secured; | ||
secured = self.config.secured | ||
} | ||
var perform_api_call = null | ||
if (that.options && 'perform_api_call' in that.options) { | ||
perform_api_call = that.options.perform_api_call; | ||
perform_api_call = that.options.perform_api_call | ||
} else { | ||
perform_api_call = self.config.perform_api_call; | ||
perform_api_call = self.config.perform_api_call | ||
} | ||
@@ -318,0 +317,0 @@ |
{ | ||
"name": "node-mailjet", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Mailjet NodeJS API client", | ||
@@ -20,3 +20,4 @@ "main": "index.js", | ||
"nock": "^8.1.0", | ||
"to-iso-string": "0.0.2" | ||
"to-iso-string": "0.0.2", | ||
"eslint": "^3.19.0" | ||
}, | ||
@@ -38,3 +39,3 @@ "scripts": { | ||
"contributors": [ | ||
"Arnaud Breton <iam@arnaud.ninja> (https://github.com/arnaudbreton)", | ||
"Arnaud Breton <arnaud@mailjet.com> (https://github.com/arnaudbreton)", | ||
"Nicholas Smith <nicksmith.biz@gmail.com> (https://github.com/safani)", | ||
@@ -41,0 +42,0 @@ "Jérémie Parker <jeremie@vizeat.com> (https://github.com/p-j)" |
116
README.md
@@ -12,3 +12,4 @@ | ||
[![Build Status](https://travis-ci.org/mailjet/mailjet-apiv3-nodejs.svg?branch=master)](https://travis-ci.org/mailjet/mailjet-apiv3-nodejs) | ||
![Current Version](https://img.shields.io/badge/version-3.0.6-green.svg) | ||
![Current Version](https://img.shields.io/badge/version-3.2-green.svg) | ||
# Mailjet NodeJs Wrapper | ||
@@ -37,4 +38,2 @@ | ||
### Show me the code | ||
@@ -51,16 +50,37 @@ | ||
Additional connection options may be passed as the third argument. These values are supported: | ||
Additional connection options may be passed as the third argument. The supported values are: | ||
- `proxyUrl`: HTTP proxy URL to send the email requests through | ||
- `proxyUrl`: HTTP proxy URL to send the API requests through | ||
- `timeout`: API request timeout in milliseconds | ||
- `url` (default: `api.mailjet.com`): Base Mailjet API URL | ||
- `version` (default: v3): API version to use in the URL | ||
- `perform_api_call` (default: true): controls if the must call must be performed to Mailjet API or not (dry run) | ||
Example: | ||
``` javascript | ||
``` javascript | ||
var Mailjet = require('node-mailjet').connect('api key', 'api secret', { | ||
proxyUrl: process.env.https_proxy, | ||
timeout: 60000 // 1 minute | ||
}); | ||
// The third argument (the object) is not mandatory. Each configuration key is also optional | ||
const mailjet = require ('apiv3') | ||
.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE, { | ||
url: 'api.mailjet.com', // default is the API url | ||
version: 'v3.1', // default is '/v3' | ||
perform_api_call: true // used for tests. default is true | ||
}) | ||
``` | ||
On top of that, you can also pass those options locally to a request: | ||
```javascript | ||
// the second argument (the object) is not mandatory. Each configuration key is also optional | ||
const request = mailjet | ||
.post("send", { | ||
url: 'api.mailjet.com', version: 'v3', perform_api_call: false | ||
}) | ||
.request({ | ||
FromEmail: 'pilot@mailjet.com', | ||
FromName: 'Mailjet Pilot', | ||
Subject: 'Hello world Mailjet!', | ||
'Text-part': 'Hello World', | ||
Recipients: [{'Email': 'passenger@mailjet.com'}] | ||
}) | ||
``` | ||
The proxy URL is passed directly to [superagent-proxy](https://github.com/TooTallNate/superagent-proxy). | ||
@@ -70,3 +90,2 @@ | ||
#### Save your `API_KEY` and `API_SECRET`: | ||
@@ -185,7 +204,7 @@ | ||
'Recipients': [{'Email': 'roger@smith.com'}], | ||
'Attachments': [{ | ||
"Content-Type": "text-plain", | ||
"Filename": "test.txt", | ||
"Content": "VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK", | ||
}], | ||
'Attachments': [{ | ||
"Content-Type": "text-plain", | ||
"Filename": "test.txt", | ||
"Content": "VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK", // Base64 for "This is your attached file!!!" | ||
}] | ||
} | ||
@@ -206,5 +225,5 @@ | ||
'FromEmail': 'pilot@mailjet.com', | ||
'FromName': 'Pilot', | ||
'Subject': 'Coucou Mailjet2', | ||
'Text-part': 'Hello World2', | ||
'FromName': 'Mailjet Pilot', | ||
'Subject': 'Hello world Mailjet!', | ||
'Text-part': 'Hello world!', | ||
'Recipients': [{'Email': 'passenger@mailjet.com'}], | ||
@@ -215,4 +234,4 @@ }; | ||
'FromEmail': 'pilot@mailjet.com', | ||
'FromName': 'Pilot', | ||
'Subject': 'Coucou Mailjet2', | ||
'FromName': 'Mailjet Pilot', | ||
'Subject': 'Hello world Mailjet!', | ||
'Text-part': 'This is another Email', | ||
@@ -250,6 +269,6 @@ 'Recipients': [{'Email': 'passenger@mailjet.com'}], | ||
email = {}; | ||
email['FromName'] = 'Your Name'; | ||
email['FromEmail'] = 'Your Sender Address'; | ||
email['Subject'] = 'Test Email'; | ||
email['Recipients'] = [{Email: 'Your email'}]; | ||
email.FromName = 'Your Name'; | ||
email.FromEmail = 'Your Sender Address'; | ||
email.Subject = 'Test Email'; | ||
email.Recipients = [{Email: 'Your email'}]; | ||
email['Text-Part'] = text; | ||
@@ -271,41 +290,10 @@ | ||
``` | ||
## Node.js compatibility | ||
Officially supported Node.js versions: | ||
- ~~v0.12.0~~ (deprecated) | ||
- v4.1 | ||
- v4.0 | ||
- v5.0.0 | ||
- v6.11.1 | ||
## New !! Version 3.1.0 of the Nodejs wrapper ! | ||
This version modifies the way to construct the Client or the calls. We add the possibility to add an array with parameters on both Client creation and API call (please, note that each of these parameters are preset and are not mandatory in the creation or the call) : | ||
Properties of the $settings (Client constructor) and $options (API call function) | ||
url (Default: api.mailjet.com) : domain name of the API | ||
version (Default: v3) : API version (only working for Mailjet API V3 +) | ||
perform_api_call (Default: true) : turns on(true) / off the call to the API | ||
secured (Default: true) : turns on(true) / off the use of 'https' | ||
``` javascript | ||
// The third argument (the object) is not mandatory, as each of its 4 keys. | ||
const mailjet = require ('apiv3') | ||
.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE, { | ||
'url': 'api.mailjet.com', // default is the API url | ||
'version': 'v3', // default is '/v3' | ||
'secured': true, // default is a boolean true | ||
'perform_api_call': true // used for tests. default is true | ||
}) | ||
// the second argument (the object) is not mandatory, as each of its 4 keys | ||
const request = mailjet | ||
.post("send", { | ||
'url': 'api.mailjet.com', 'version': 'v3', 'secured': 'https', 'perform_api_call': false | ||
}) | ||
.request({ | ||
'FromEmail': 'pilot@mailjet.com', | ||
'FromName': 'Pilot', | ||
'Subject': 'Coucou Mailjet2', | ||
'Text-part': 'Hello World2', | ||
'Recipients': [{'Email': 'passenger@mailjet.com'}]}) | ||
``` | ||
## Contribute | ||
@@ -312,0 +300,0 @@ |
@@ -0,0 +0,0 @@ const Mailjet = require('./mailjet-client') |
@@ -0,1 +1,2 @@ | ||
/* global describe, it */ | ||
const FILE = 'FILE' | ||
@@ -104,4 +105,6 @@ const EMAIL = 'test@mailjet.com' | ||
var sender = client.post('sender') | ||
// eslint-disable-next-line no-unused-vars | ||
var deletedErrorMessage = 'There is an already existing deleted sender with the same email. ' + | ||
'You can use "validate" action in order to activate it.' | ||
// eslint-disable-next-line no-unused-vars | ||
var inactiveErrorMessage = 'There is an already existing inactive sender with the same email. ' + | ||
@@ -235,3 +238,3 @@ 'You can use "validate" action in order to activate it.' | ||
.catch(function (reason) { | ||
expect(reason.ErrorMessage).to.equal('timeout of 10ms exceeded') | ||
expect(reason.ErrorMessage).to.equal('Timeout of 10ms exceeded') | ||
expect(reason.statusCode).to.equal(null) | ||
@@ -238,0 +241,0 @@ expect(reason.response).to.equal(null) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309567
8854
5
307