Skip to content

Commit

Permalink
Updated FedEx to return the most recent tracking number data when Fed…
Browse files Browse the repository at this point in the history
…Ex creates a duplicate tracking number.
  • Loading branch information
freshlogic committed May 8, 2024
1 parent 3498cd1 commit 4a10ca1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.12.0] - 2024-05-08
### Changed
- Updated FedEx to return the most recent tracking number data when FedEx creates a duplicate tracking number.

## [1.11.0] - 2021-06-13
### Changed
- Updated DHL to use DHL eCommerce Solutions first if configured.
Expand Down
44 changes: 43 additions & 1 deletion carriers/fedEx.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,49 @@ function FedEx(options) {
return callback(new Error(trackReply.Notifications[0].Message));
}

callback(null, trackReply);
// Return if only one track detail is returned
if (trackReply?.CompletedTrackDetails?.[0]?.TrackDetails.length === 1) {
return callback(null, trackReply);
}

async.mapLimit(trackReply.CompletedTrackDetails[0].TrackDetails, 10, function(trackDetail, callback) {
const trackRequest = {
SelectionDetails: {
PackageIdentifier: {
Type: 'TRACKING_NUMBER_OR_DOORTAG',
Value: trackingNumber
},
TrackingNumberUniqueIdentifier: trackDetail.TrackingNumberUniqueIdentifier
},
ProcessingOptions: 'INCLUDE_DETAILED_SCANS'
};

async.retry(function(callback) {
async.timeout(fedExClient.track, 5000)(trackRequest, function(err, trackReply) {
if (err) {
return callback(err);
}

if (trackReply.HighestSeverity === 'ERROR') {
return callback(new Error(trackReply.Notifications[0].Message));
}

callback(null, trackReply);
});
}, callback);
}, function(err, trackReplies) {
if (err) {
return callback(err);
}

// Sort track replies by timestamp
trackReplies.sort((a, b) => b.CompletedTrackDetails[0].TrackDetails[0].StatusDetail.CreationTime - a.CompletedTrackDetails[0].TrackDetails[0].StatusDetail.CreationTime);

// Get the most recent track reply
trackReply = trackReplies[0];

callback(null, trackReply);
});
});
}, function(err, trackReply) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
"type": "git",
"url": "https://github.com/mediocre/bloodhound.git"
},
"version": "1.11.9"
"version": "1.12.0"
}

0 comments on commit 4a10ca1

Please sign in to comment.