npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@troyaaronjones/bloodhound

v1.14.0

Published

Bloodhound is a Node.js package that allows you to retrieve tracking data from shipping carriers (DHL, FedEx, UPS, USPS) in a common format.

Downloads

46

Readme

Bloodhound

Build Status Coverage Status

Elvis Presley & Bloodhound - Photo - 1964

Bloodhound is a Node.js package that allows you to retrieve tracking data from shipping carriers (DHL, FedEx, UPS, USPS) in a common format.

This module was inspired by the excellent shipit module. @mediocre built Bloodhound to provide better support for parsing of timestamps (read more below).

Features

Common format

Bloodhound interfaces with several carrier APIs and returns results in a single, unified format. Each carrier activity/movement/scan is represented as an event with a description, geographic location (city/state), and timestamp.

Timestamps

When it comes to timestamps there are two types of carrier APIs: those that include a UTC offset which can be easily parsed as proper dates, and those that provide timestamp strings that need to be interepreted based on the local timezone of the geographic location for the event.

When Bloodhound encounters a timestamp without a UTC offset it looks up the timezone by geocoding the event's geographic location. The returned results contain proper dates in the correct timezone.

Geocode results are cached in-memory locally. Geocode results can optionally be cached remotely in Redis.

Carrier Guessing

Bloodhound can guess the carrier given a tracking number explicity through the bloodhound.guessCarrier(trackingNumber) method. Bloodhound will also try to guess the carrier when tracking a package without specifying a carrier when using the bloodhound.track(trackingNumber) method.

Shipped/Delivered Dates

Bloodhound also examines each of the activity/movement/scan events for "shipped" and "delievered" event types (beyond simple electronic events like "shipping label created" or "manifest file sent"). When a matching event type is encountered Bloodhound returns a shippedAt and deliveredAt date.

Supported Carriers

  • DHL
  • FedEx
  • UPS
  • USPS

Getting Started

const Bloodhound = require('@troyaaronjones/bloodhound');

const bloodhound = new Bloodhound({
    usps: {
        userId: 'USPS_USER_ID'
    }
});

bloodhound.track('tracking number', { carrier: 'USPS' }, function(err, data) {
    console.log(data);
});

API

new Bloodhound(options)

Creates a new Bloodhound client. Each carrier requires a different combination of credentials (account numbers, meter numbers, passwords, user IDs, etc).

By default, when Bloodhound encounters a timestamp without a UTC offset it will geocode using OpenStreetMap (which does not require an API key). You can optionally use a different geocoder. You can also optionally cache geocode results in Redis.

const Bloodhound = require('@troyaaronjones/bloodhound');

const bloodhound = new Bloodhound({
    dhl: {
        apiKey: 'DHL API key from https://developer.dhl.com'
    },
    fedEx: {
        token: 'TOKEN_RETRIEVED_FROM_FEDEX'
    },
    geocoder: {
        apiKey: 'GOOGLE_API_KEY',
        language: 'en',
        provider: 'google',
        region: '.us'
    },
    pettyCache: {
        host: '127.0.0.1',
        options: {
            auth_pass: 'secret'
        },
        port: 6379
    },
    ups: {
        applicationName: 'test-tracking',
        token: 'TOKEN_RETRIEVED_FROM_UPS'
    },
    usps: {
        userId: 'USPS_USER_ID'
    }
});

bloodhound.track('tracking number', 'FedEx', function(err, data) {
    console.log(data);
});

dhl The DHL API requires an API key: https://developer.dhl.com.

fedEx

FedEx options are passed to the shipping-fedex module.

geocoder

By default Bloodhound uses the OpenStreetMap geocode provider. You can optionally specify geocoder options which are passed to the node-geocode module.

pettyCache

By default Bloodhound caches geocode results in-memory locally. You can optionally enable caching of geocoder results to a remote Redis server. These options are passed to the petty-cache module.

ups

The UPS API requires a username, password, and an access key.

usps

The USPS API simply requires a user ID: https://www.usps.com/business/web-tools-apis/track-and-confirm-api.htm

bloodhound.guessCarrier(trackingNumber)

Guesses the carrier of the specified tracking number.

const carrier = bloodhound.guessCarrier('tracking number');
console.log(carrier);

bloodhound.track(trackingNumber, [options,] callback)

Retrieves tracking data for the specified tracking number.

bloodhound.track('tracking number', { carrier: 'USPS' }, function(err, data) {
    console.log(data);
});

Data

{
    "events": [
        {
            "address": {
                "city": "CARROLLTON",
                "state": "TX",
                "zip": "75010"
            },
            "date": "2019-06-30T18:03:00.000Z",
            "description": "Delivered, Front Door/Porch"
        },
        {
            "address": {
                "city": "CARROLLTON",
                "state": "TX",
                "zip": "75010"
            },
            "date": "2019-05-13T17:32:00.000Z",
            "description": "Sorting Complete"
        }
    ],
    "shippedAt": "2019-05-13T17:32:00.000Z",
    "deliveredAt": "2019-06-30T18:03:00.000Z"
}