Socket
Socket
Sign inDemoInstall

clang

Package Overview
Dependencies
63
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.3 to 0.2.4

78

lib/clang.js

@@ -126,2 +126,14 @@ var _ = require('lodash');

if (arguments.length !== 3) {
callback = customer;
return setImmediate(function() {
callback(new Error('send takes 3 arguments: customer, options and callback function'));
});
}
if (!customer || typeof customer !== 'object' || !Object.keys(customer).length) {
return setImmediate(function() {
callback(new Error('The customer argument must be an non-empty object'));
});
}
options.lookup = options.lookup || 'externalId';

@@ -132,25 +144,44 @@

customerGetMethodName = 'customer_getByExternalId';
customerArgs.externalId = customer.externalId;
customerArgs.externalId = customer.externalId;
if (!customerArgs.externalId) {
return setImmediate(function() {
callback(new Error('customer.externalId is required with lookup method `' + options.lookup + '`'));
});
}
}
else if (options.lookup === 'customerId') {
customerGetMethodName = 'customer_getById';
customerArgs.customerId = customer.id || customer.customerId;
customerArgs.customerId = customer.id || customer.customerId;
if (!customerArgs.customerId) {
return setImmediate(function() {
callback(new Error('customer.id/customerId is required with lookup method `' + options.lookup + '`'));
});
}
}
else if (options.lookup === 'id') {
else if (options.lookup === 'email') {
customerGetMethodName = 'customer_getByEmailAddress';
customerArgs.emailAddress = customer.email || customer.emailAddress;
customerArgs.emailAddress = customer.email || customer.emailAddress;
if (!customerArgs.emailAddress) {
return setImmediate(function() {
callback(new Error('customer.email/emailAddress is required with lookup method `' + options.lookup + '`'));
});
}
}
else {
return callback(new Error('lookup method `' + options.lookup + '` is not supported'));
return setImmediate(function() {
callback(new Error('lookup method `' + options.lookup + '` is not supported'));
});
}
options.context = options.context || 'group';
if (!options.contextId) {
return callback(new Error('Unknown lookup method used'));
if (options.context && !options.contextId) {
return setImmediate(function() {
callback(new Error('When a send context is used, a contextId is mandatory'));
});
}
// only support send to group for now. Needs a backing Clang campaign listening to the group
if (['group'].indexOf(options.context) === -1 ) {
return callback(new Error('send to context `' + options.context + '` is not supported'));
if (options.context && ['group'].indexOf(options.context) === -1 ) {
return setImmediate(function() {
callback(new Error('send to context `' + options.context + '` is not supported'));
});
}

@@ -180,6 +211,18 @@

},
function asyncWtfCreate(record, callback) {
function asyncWtfMerge(record, callback) {
if (record) {
setImmediate(function() {
callback(null, record);
// The found record should be included in the supplied data
// to make sure that record is updated.
customer.id = record.id;
me.request('customer_update', {customer: customer}, function(err, result) {
if (err) {
return callback(err);
}
if (!result || !result.length) {
return callback(new Error('No customer returned after update'));
}
if (result.length > 1) {
return callback(new Error('Multiple customers returned after update'));
}
callback(null, result[0]);
});

@@ -190,7 +233,10 @@ return;

me.request('customer_insert', {customer: customer}, function(err, result) {
if (err) {
return callback(err);
}
if (!result || !result.length) {
return callback(new Error('No customer returned after creation'));
return callback(new Error('No customer returned after create'));
}
if (result.length > 1) {
return callback(new Error('Multiple customers returned after creation'));
return callback(new Error('Multiple customers returned after create'));
}

@@ -197,0 +243,0 @@ callback(null, result[0]);

{
"name": "clang",
"version": "0.2.3",
"version": "0.2.4",
"description": "Node.js api wrapper for Clang's SOAP api",

@@ -5,0 +5,0 @@ "author": "Christiaan Westerbeek <chris@devotis.nl>",

@@ -34,1 +34,60 @@ var should = require('should');

});
describe('Send signature', function() {
it('Send requires 3 arguments or else should callback with an error', function(done) {
clang.send(function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Empty customer object should callback with an error', function(done) {
clang.send({}, {}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Send with unsupport lookup key should callback with an error', function(done) {
clang.send({externalId: 1}, {lookup: 'some-unsupported-key'}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Send with context without contextId should callback with an error', function(done) {
clang.send({externalId: 1}, {context: 'group'}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Send with unsupported context should callback with an error', function(done) {
clang.send({externalId: 1}, {context: 'some-unsupported-context'}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Send with lookup=externalId without an externalId should callback with an error', function(done) {
clang.send({x: 1}, {lookup: 'externalId', context: 'group'}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Send with lookup=customerId without an id/customerId should callback with an error', function(done) {
clang.send({x: 1}, {lookup: 'customerId', context: 'group'}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
it('Send with lookup=email without an email/emailAddress should callback with an error', function(done) {
clang.send({x: 1}, {lookup: 'email', context: 'group'}, function(err, result) {
(!!err).should.be.equal(true);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc