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

ts-shipment-tracking

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-shipment-tracking

Unified shipment tracking data from FedEx, UPS, and USPS APIs.

  • 1.1.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

ts-shipment-tracking

Unified shipment tracking data from FedEx, UPS, and USPS APIs.

Table of Contents
  1. About
  2. Installation
  3. Usage
  4. Built With
  5. 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

Keywords

FAQs

Package last updated on 23 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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