ts-shipment-tracking
Unified shipment tracking data from FedEx, UPS, and USPS APIs.
Table of Contents
- About
- Installation
- Usage
- Built With
- Acknowledgements
About
Returns a unified response from FedEx, UPS, and USPS tracking APIs.
Installation
$ npm install ts-shipment-tracking
Usage
Create a credentials.json
file with the following structure:
{
"fedex": {
"key": "",
"password": "",
"accountNumber": "",
"meterNumber": ""
},
"ups": {
"accessLicenseNumber": ""
},
"usps": {
"userId": ""
}
}
Input:
import * as credentials from './credentials.json';
import { TrackingInfo, trackFedex, trackUps, trackUsps } from 'ts-shipment-tracking';
import { fedex, getTracking, s10, ups, usps } from 'ts-tracking-number';
const trackByCourier = (
courierCode: string,
trackingNumber: string
): Promise<TrackingInfo | Error> =>
courierCode === 'fedex'
? trackFedex(trackingNumber, credentials.fedex)
: courierCode === 'ups'
? trackUps(trackingNumber, credentials.ups)
: trackUsps(trackingNumber, credentials.usps);
const track = (trackingNumber: string): Promise<TrackingInfo | Error> =>
trackByCourier(
getTracking(trackingNumber, [fedex, ups, usps, s10])?.courier.code ?? '',
trackingNumber
);
(async () => {
try {
const trackInfo = await track('<any_tracking_number_here>');
console.log('trackInfo:', trackInfo);
} catch (error) {
console.log(error);
}
})();
Output:
{
events: [
{
status: 'IN_TRANSIT',
label: 'Arrived at FedEx location',
location: 'LEBANON TN US 37090',
date: 1616823540000
},
...
],
estimatedDelivery: 1616996340000
}
Statuses:
'UNAVAILABLE'
'LABEL_CREATED'
'IN_TRANSIT'
'OUT_FOR_DELIVERY'
'DELIVERY_ATTEMPTED'
'RETURNED_TO_SENDER'
'EXCEPTION'
'DELIVERED'
Built With
Acknowledgements