Package Exports
- yield-siftscience
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (yield-siftscience) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Yield Sift Science - NodeJS
A promise-wrapped helper lib for yielding Sift Science API calls in nodejs.
Also supports regular callbacks.
Installation
Using npm:
$ npm install yield-siftscienceUsage
Require with API key:
// Default version
var siftscience = require('yield-siftscience')('YOUR_SIFT_SCIENCE_REST_API_KEY');
// For a specific siftscience API version
var siftscience = require('yield-siftscience')('YOUR_SIFT_SCIENCE_REST_API_KEY', 'v203');Send Event:
var create_account = yield siftscience.event.create_account({
'$session_id': 'abcdefghijklmnopqrstuvwxyz',
'$user_id': '12345',
'$user_email': 'example@email.com'
});
console.log(create_account);
var login = yield siftscience.event.login({
'$session_id': 'abcdefghijklmnopqrstuvwxyz',
'$user_id': '12345',
'$login_status': '$success'
});
console.log(login);Send Generic Custom Event:
var submit_comment = yield siftscience.event.custom_event('submit_comment', {
'$session_id': 'abcdefghijklmnopqrstuvwxyz',
'$user_id': '12345',
'$user_email': 'example@email.com',
'content': 'blah blah blah comment'
});
console.log(submit_comment);
var delete_account = yield siftscience.event.custom_event('delete_account', {
'$session_id': 'abcdefghijklmnopqrstuvwxyz',
'$user_id': '12345'
});
console.log(delete_account);Inject Custom Events:
Optionally, you can pass in an array of custom event names to add to the lib
var custom_events = ['submit_comment', 'delete_account', ...];
var siftscience = require('yield-siftscience')('YOUR_SIFT_SCIENCE_REST_API_KEY', null, custom_events);Then you could use
var submit_comment = yield siftscience.event.submit_comment({
'$session_id': 'abcdefghijklmnopqrstuvwxyz',
'$user_id': '12345',
'$user_email': 'example@email.com',
'content': 'blah blah blah comment'
});
console.log(submit_comment);
var delete_account = yield siftscience.event.delete_account({
'$session_id': 'abcdefghijklmnopqrstuvwxyz',
'$user_id': '12345',
});
console.log(delete_account);Send Label:
var result = yield siftscience.label('user_id', {
'$is_bad': true,
'$reasons': [ '$spam', '$chargeback' ],
'$description': 'Because they are spamming and abusing our system'
});
console.log(result);Remove Label:
var result = yield siftscience.unlabel('user_id');
console.log(result);Get Score:
var score = yield siftscience.score('user_id');
console.log(score);Callbacks
Don't know what yielding or promising is? Do it with a regular callback:
var callback = function(_err, _response) {
if (_err) {
console.log(_err);
}
else {
var score = _response.body;
console.log(score);
}
};
siftscience.score('user_id', callback);You can also inject a global callback for all requests:
var global_callback = function(_err, _response) {
if (_err) {
console.log(_err);
}
else {
var result = _response.body;
console.log(result);
}
};
var siftscience = require('yield-siftscience')('YOUR_SIFT_SCIENCE_REST_API_KEY', null, null, global_callback);