node-radial
Advanced tools
Comparing version 0.2.4 to 0.3.0
/* LIB */ | ||
const radial = require('../../../radial'); | ||
const utils = require('../../utils'); | ||
const utils = radial.utils; | ||
@@ -6,0 +6,0 @@ /* MODULES */ |
@@ -5,3 +5,3 @@ /* LIB */ | ||
const params = radial.getParams(); | ||
const utils = require('../../utils'); | ||
const utils = radial.utils; | ||
const sendRequest = require('../../sendRequestXML'); | ||
@@ -8,0 +8,0 @@ |
@@ -5,3 +5,3 @@ /* LIB */ | ||
const params = radial.getParams(); | ||
const utils = require('../../utils'); | ||
const utils = radial.utils; | ||
const sendRequest = require('../../sendRequestXML'); | ||
@@ -8,0 +8,0 @@ |
@@ -5,3 +5,3 @@ /* LIB */ | ||
const params = radial.getParams(); | ||
const utils = require('../../utils'); | ||
const utils = radial.utils; | ||
const sendRequest = require('../../sendRequestXML'); | ||
@@ -8,0 +8,0 @@ |
@@ -5,3 +5,3 @@ /* LIB */ | ||
const params = radial.getParams(); | ||
const utils = require('../../utils'); | ||
const utils = radial.utils; | ||
const sendRequest = require('../../sendRequestXML'); | ||
@@ -8,0 +8,0 @@ |
@@ -5,3 +5,3 @@ /* LIB */ | ||
const params = radial.getParams(); | ||
const utils = require('../utils'); | ||
const utils = radial.utils; | ||
const sendRequest = require('../sendRequestXML'); | ||
@@ -90,3 +90,2 @@ | ||
requestOrder.LineItems = {}; | ||
requestOrder.ExternalRiskResults = {}; | ||
requestOrder.ShoppingSession = {}; | ||
@@ -402,2 +401,3 @@ requestOrder.TotalCost = {}; | ||
if (orderOptions.externalRiskResults) { | ||
requestOrder.ExternalRiskResults = {}; | ||
orderOptions.externalRiskResults.forEach(function (external) { | ||
@@ -404,0 +404,0 @@ var riskData = {}; |
@@ -8,2 +8,4 @@ /* LIB */ | ||
const xmlConvert = require('xml-js'); | ||
/* CONSTRUCTOR */ | ||
@@ -34,2 +36,57 @@ | ||
Utils.bodyParser = function () { | ||
return xmlBodyParser; | ||
function xmlBodyParser(req, res, next) { | ||
var data = ''; | ||
if (req._body) return next(); | ||
req.body = req.body || {}; | ||
if (!hasBody(req) || !module.exports.regexp.test(mime(req))) { | ||
return next(); | ||
} | ||
req._body = true; | ||
req.setEncoding('utf-8'); | ||
req.on('data', function (chunk) { | ||
data += chunk; | ||
}); | ||
req.on('end', function () { | ||
// invalid xml, length required | ||
if (data.trim().length === 0) { | ||
return next(error(411)); | ||
} | ||
var jsonBody = xmlConvert.xml2js(body, { | ||
compact: true | ||
}); | ||
req.body = jsonBody || req.body; | ||
req.rawBody = data; | ||
return next(); | ||
}); | ||
} | ||
}; | ||
/* HELPERS */ | ||
function hasBody(req) { | ||
var encoding = 'transfer-encoding' in req.headers; | ||
var length = 'content-length' in req.headers && req.headers['content-length'] !== '0'; | ||
return encoding || length; | ||
} | ||
function mime(req) { | ||
var str = req.headers['content-type'] || ''; | ||
return str.split(';')[0]; | ||
} | ||
function error(code, msg) { | ||
var err = new Error(msg || http.STATUS_CODES[code]); | ||
err.status = code; | ||
return err; | ||
} | ||
/* NPM EXPORT */ | ||
@@ -36,0 +93,0 @@ |
@@ -19,3 +19,3 @@ /* LIB */ | ||
Authenticate.execute = function (route, req, fn) { | ||
var webhookAuth = params.webhooks[route]; | ||
const webhookAuth = params.webhooks[route]; | ||
if (!webhookAuth || !webhookAuth.username || !webhookAuth.password) { | ||
@@ -26,2 +26,13 @@ return fn({ | ||
} | ||
var username = req.headers.username; | ||
var password = req.headers.password; | ||
if (username === webhookAuth.username && password === webhookAuth.password) { | ||
return fn(); | ||
} else { | ||
return fn({ | ||
message: 'Invalid username or password' | ||
}); | ||
} | ||
}; | ||
@@ -28,0 +39,0 @@ |
@@ -9,3 +9,3 @@ /* LIB */ | ||
var Webhook = {}; | ||
var Webhooks = {}; | ||
@@ -18,3 +18,3 @@ /* PRIVATE VARIABLES */ | ||
Webhook.riskOrderStatus = require('./riskOrderStatus'); | ||
Webhooks.riskOrderStatus = require('./riskOrderStatus'); | ||
@@ -24,3 +24,3 @@ /* NPM EXPORT */ | ||
if (typeof module === 'object' && module.exports) { | ||
module.exports = Webhook; | ||
module.exports = Webhooks; | ||
} else { | ||
@@ -27,0 +27,0 @@ throw new Error('This module only works with NPM in NodeJS environments.'); |
@@ -31,2 +31,3 @@ /* LIB */ | ||
} | ||
var jsonBody = xmlConvert.xml2js(req.body, { | ||
@@ -33,0 +34,0 @@ compact: true |
{ | ||
"name": "node-radial", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "NodeJS SDK for the Radial APIs", | ||
@@ -5,0 +5,0 @@ "main": "radial.js", |
@@ -54,2 +54,4 @@ /* LIB */ | ||
Radial.risk = require('./lib/risk/index'); | ||
Radial.webhooks = require('./lib/webhooks/index'); | ||
Radial.utils = require('./lib/utils'); | ||
@@ -56,0 +58,0 @@ return this; |
@@ -499,2 +499,3 @@ [![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url] | ||
- **0.3.0:** Adding webhook support. Not 100% integrated yet. | ||
- **0.2.4:** Logging cleanup. | ||
@@ -501,0 +502,0 @@ - **0.2.3:** `ItemListRPH` was missing from the fraud assessment request. The module now generates this string automatically from the item list. |
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
83761
1971
519