mailchimp-api-v3
Advanced tools
Comparing version 1.14.0 to 1.15.0
10
index.js
@@ -17,6 +17,6 @@ "use strict"; | ||
function Mailchimp (api_key) { | ||
function Mailchimp (api_key, dc = null) { | ||
var api_key_regex = /.+\-.+/ | ||
if (!api_key_regex.test(api_key)) { | ||
if (!api_key_regex.test(api_key) && dc === null) { | ||
throw new Error('missing or invalid api key: ' + api_key) | ||
@@ -27,3 +27,7 @@ } | ||
this.__api_key = api_key; | ||
this.__base_url = "https://"+ this.__api_key.split('-')[1] + ".api.mailchimp.com/3.0" | ||
if(dc !== null){ | ||
this.__base_url = "https://"+ dc + ".api.mailchimp.com/3.0" | ||
}else{ | ||
this.__base_url = "https://"+ this.__api_key.split('-')[1] + ".api.mailchimp.com/3.0" | ||
} | ||
} | ||
@@ -30,0 +34,0 @@ |
{ | ||
"name": "mailchimp-api-v3", | ||
"version": "1.14.0", | ||
"version": "1.15.0", | ||
"description": "Mailchimp wrapper for v3 of the mailchimp api, with transparant handling of batch operations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var api_key = process.env.MAILCHIMP_TEST_API_KEY | ||
var oauth_token = process.env.MAILCHIMP_TEST_OAUTH_TOKEN | ||
var assert = require('assert') | ||
var dc = process.env.DC | ||
@@ -28,2 +30,6 @@ var Mailchimp = require('../index'); | ||
}) | ||
it('should work for correctly formated oauth token with a DC', function () { | ||
var mailchimp = new Mailchimp('token', 'us19') | ||
}) | ||
}) | ||
@@ -125,2 +131,96 @@ | ||
describe('basic mailchimp api methods with oauth token and dc', function () { | ||
var mailchimp = new Mailchimp(oauth_token, dc); | ||
it('should handle simple get', function (done) { | ||
mailchimp.get({ | ||
path : '/lists', | ||
}, function (err, result) { | ||
assert.equal(err, null); | ||
assert.ok(result) | ||
assert.ok(result.lists) | ||
done() | ||
}) | ||
}) | ||
it('should handle simple get with promise', function (done) { | ||
mailchimp.get({ | ||
path : '/lists', | ||
}).then(function (result) { | ||
assert.ok(result) | ||
assert.ok(result.lists) | ||
done() | ||
}).catch(function (err) { | ||
done(new Error(err)); | ||
}) | ||
}) | ||
it('should handle wrong path', function (done) { | ||
mailchimp.get({ | ||
path : '/wrong', | ||
}, function (err, result) { | ||
assert.equal(err.status, 404); | ||
done() | ||
}) | ||
}) | ||
it('should handle wrong path with promise', function (done) { | ||
mailchimp.get({ | ||
path : '/wrong', | ||
}).then(function (result) { | ||
//Error | ||
done(result) | ||
}).catch(function (err) { | ||
assert.equal(err.status, 404); | ||
done() | ||
}) | ||
}) | ||
it('should handle get with just a path', function (done) { | ||
mailchimp.get('/lists', function (err, result) { | ||
assert.equal(err, null); | ||
assert.ok(result) | ||
assert.ok(result.lists) | ||
done() | ||
}) | ||
}) | ||
it('should handle get with just a path with promise', function (done) { | ||
mailchimp.get('/lists') | ||
.then(function (result) { | ||
assert.ok(result); | ||
assert.ok(result.lists); | ||
done(); | ||
}) | ||
.catch(function (err) { | ||
done(new Error(err)) | ||
}) | ||
}) | ||
it('should handle get with a path and query', function (done) { | ||
mailchimp.get('/lists', {offset : 1}, function (err, result) { | ||
assert.equal(err, null); | ||
assert.ok(result) | ||
assert.ok(result.lists) | ||
done() | ||
}) | ||
}) | ||
it('should handle get with a path and query with promise', function (done) { | ||
mailchimp.get('/lists', {offset : 1}) | ||
.then(function (result) { | ||
assert.ok(result) | ||
assert.ok(result.lists) | ||
done() | ||
}) | ||
.catch(function (err) { | ||
done(new Error(err)) | ||
}) | ||
}) | ||
}) | ||
describe('batch mailchimp api methods', function () { | ||
@@ -127,0 +227,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
33392
1023
3