Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mediocre/bloodhound

Package Overview
Dependencies
Maintainers
2
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mediocre/bloodhound - npm Package Compare versions

Comparing version 1.10.0 to 1.11.0

104

carriers/dhl.js

@@ -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"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc