dread-steed
Module that helps handle a salesforce connection and all the fun mess that comes with salesforce.
Installation
npm install dread-steed --save
Configuration
pass this config object into dread steed
var config = {
maxConnDuration:10.000,
maxRetries:2,
silent:true,
errorTypes:['INVALID_SESSION_ID','INVALID_LOGIN','DUPLICATE_VALUE','SERVER_UNAVAILABLE','REQUEST_LIMIT_EXCEEDED'],
maxEventListeners:100,
salesforce: {
Username: 'salesforceapi@salesforce.com',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',
SecurityToken: 'thisisasecuritytoken',
}
};
For handling of multiple saleforce connections.
NOTE: Api user will switch if it hits an api limit and throws REQUEST_LIMIT_EXCEEDED or SERVER_UNAVAILABLE
otherwise it will just use the 1 api user
var config = {
maxConnDuration:10.000,
maxRetries:2,
silent:true,
errorTypes:['INVALID_SESSION_ID','INVALID_LOGIN','DUPLICATE_VALUE','SERVER_UNAVAILABLE','REQUEST_LIMIT_EXCEEDED'],
maxEventListeners:100,
salesforce: [
{
Username: 'salesforceapi@salesforce.com',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',
SecurityToken: 'thisisasecuritytoken',
},
{
Username: 'salesforceapi2@salesforce.com',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',
SecurityToken: 'thisisasecuritytoken',
},
{
Username: 'salesforceapi3@salesforce.com',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',
SecurityToken: 'thisisasecuritytoken',
},
{
Username: 'salesforceapi4@salesforce.com',
Password: 'salesforcepassword',
Endpoint: 'https://test.salesforce.com',
SecurityToken: 'thisisasecuritytoken',
}
]
};
Error Handling
Optional if you want to handle errors and or log then in your own way
var errorCallback = function(err){
};
Optional callbacks
If you want to use callbacks for more than just error handling, you can optionally pass in an object with a callback for error handling and a callback for when the salesforce connection is established or re-established.
var errorCallback = function(err){
};
var connectionCallback = function(conn){
}
var callbacks = {
onError: errorCallback,
onConnection: connectionCallback
};
Usage
var DreadSteed = require('dread-steed');
var dreadSteed = new DreadSteed(config, errorCallback);
var yourSalesForceQueryHere = "SELECT id, Name FROM Things WHERE id = '1' ";
Public functions
queryAsync
getAllTheThings = function(id){
return dreadSteed.getConnection().then(function(conn){
return conn.queryAsync(yourSalesForceQueryHere);
}).catch(function(err){
log.error(err);
throw err;
});
}
updateAsync
updateAllTheThings = function( updateObj, name ) {
return dreadSteed.getConnection().then(function(conn){
return conn.updateAsync( name, updateObj ).then(function( res ){
return res;
}).catch(function( err ){
log.error(err);
throw err;
});
}).catch(function(err){
log.error(err);
throw err;
});
}
createAsync
createAllTheThings = function( newObj, name ) {
return dreadSteed.getConnection().then(function(conn){
return conn.createAsync(name, newObj).then(function(res) {
return res;
}).catch(function(err) {
log.error(err);
throw err;
});
}).catch(function(err) {
log.error(err);
throw err;
});
}
deleteAsync
deleteTheThing = function ( Id ) {
return dreadSteed.getConnection()
.then(function ( conn ) {
return conn.deleteAsync( 'Things', Id );
}).catch(function(err) {
log.error(err);
throw err;
});
};
Tests
Release History
- 0.0.1 Initial release
- 0.0.2
- 0.0.3
- 0.0.4 Config changes
- 0.0.5 copyright added updated readme
- 0.0.6 error handle callback
- 0.0.7 removed unused salesforce config from README.md
- 0.0.8 allow optional callback for successful salesforce connections/re-connections
- 0.0.9 allow multiple api users to switch to when api limits are hit or server unavailable happens
- 0.0.10 Code cleanup and package json updates
- 0.0.11 changed to MIT license added LICENSE file
- 0.1.0 added a silent option to ignore console logs
- 0.1.1 Removed MomentJS dependency, Removed Lodash library. Moved to individual needed functions. Add Row lock error to retry logic on queries.