@mediocre/bloodhound
Advanced tools
Comparing version 1.10.0 to 1.11.0
@@ -42,56 +42,63 @@ const async = require('async'); | ||
// This is the API being used from: https://developer.dhl.com/api-reference/shipment-tracking | ||
const req = { | ||
forever: true, | ||
gzip: true, | ||
headers: { | ||
'DHL-API-Key': options.apiKey | ||
}, | ||
json: true, | ||
method: 'GET', | ||
timeout: 5000, | ||
url: `https://api-eu.dhl.com/track/shipments?trackingNumber=${trackingNumber}` | ||
}; | ||
async.retry(function(callback) { | ||
request(req, function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
if (options.dhlEcommerceSolutions && dhlEcommerceSolutions.isTrackingNumberValid(trackingNumber)) { | ||
async.retry(function(callback) { | ||
dhlEcommerceSolutions.track(trackingNumber, callback); | ||
}, function(err, results) { | ||
// If DHL eCommerce Solutions fails, try UTAPI | ||
if (err || !results.raw?.packages?.length) { | ||
return trackWithUTAPI(); | ||
} | ||
if (res.statusCode !== 200) { | ||
return callback(new Error(`${res.statusCode} ${res.request.method} ${res.request.href} ${body || ''}`.trim())); | ||
} | ||
callback(null, body); | ||
return callback(err, results); | ||
}); | ||
}, function(err, body) { | ||
} else { | ||
return trackWithUTAPI(); | ||
} | ||
const results = { | ||
carrier: 'DHL', | ||
events: [], | ||
raw: body | ||
function trackWithUTAPI() { | ||
// This is the API being used from: https://developer.dhl.com/api-reference/shipment-tracking | ||
const req = { | ||
forever: true, | ||
gzip: true, | ||
headers: { | ||
'DHL-API-Key': options.apiKey | ||
}, | ||
json: true, | ||
method: 'GET', | ||
timeout: 5000, | ||
url: `https://api-eu.dhl.com/track/shipments?trackingNumber=${trackingNumber}` | ||
}; | ||
if (err || !body?.shipments?.length) { | ||
// If DHL fails, try DHL eCommerce Solutions | ||
if (options.dhlEcommerceSolutions && dhlEcommerceSolutions.isTrackingNumberValid(trackingNumber)) { | ||
async.retry(function(callback) { | ||
dhlEcommerceSolutions.track(trackingNumber, callback); | ||
}, function(err, results) { | ||
// If DHL eCommerce Solutions fails, try USPS | ||
if (err || !results.raw?.packages?.length) { | ||
if (options.usps && usps.isTrackingNumberValid(trackingNumber)) { | ||
return usps.track(trackingNumber, callback); | ||
} | ||
} | ||
async.retry(function(callback) { | ||
request(req, function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return callback(err, results); | ||
}); | ||
} else if (options.usps && usps.isTrackingNumberValid(trackingNumber)) { | ||
return usps.track(trackingNumber, callback); | ||
} else { | ||
return callback(err, results); | ||
if (res.statusCode !== 200) { | ||
return callback(new Error(`${res.statusCode} ${res.request.method} ${res.request.href} ${body || ''}`.trim())); | ||
} | ||
callback(null, body); | ||
}); | ||
}, function(err, body) { | ||
if (err) { | ||
// If UTAPI fails, try USPS | ||
if (options.usps && usps.isTrackingNumberValid(trackingNumber)) { | ||
return usps.track(trackingNumber, callback); | ||
} | ||
return callback(err); | ||
} | ||
} else { | ||
const results = { | ||
carrier: 'DHL', | ||
events: [], | ||
raw: body | ||
}; | ||
if (!body || !body.shipments || !body.shipments.length) { | ||
return callback(null, results); | ||
} | ||
// We only support the first shipment | ||
@@ -186,5 +193,4 @@ const shipment = body.shipments[0]; | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -191,0 +197,0 @@ } |
@@ -9,2 +9,6 @@ # Changelog | ||
## [1.11.0] - 2021-06-13 | ||
### Changed | ||
- Updated DHL to use DHL eCommerce Solutions first if configured. | ||
## [1.10.0] - 2021-06-13 | ||
@@ -11,0 +15,0 @@ ### Changed |
@@ -43,3 +43,3 @@ { | ||
}, | ||
"version": "1.10.0" | ||
"version": "1.11.0" | ||
} |
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
76917
1178