@mediocre/bloodhound
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -19,3 +19,13 @@ const async = require('async'); | ||
this.track = function(trackingNumber, callback) { | ||
this.track = function(trackingNumber, options, callback) { | ||
// Options are optional | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (!options.minDate) { | ||
options.minDate = new Date(0); | ||
} | ||
// Pitney Bowes Marketing Mail Flats (length 31): 0004290252994200071698133931119 | ||
@@ -105,2 +115,7 @@ const isImb = trackingNumber.length === 31; | ||
// Ensure event is after minDate (used to prevent data from reused tracking numbers) | ||
if (event.date < options.minDate) { | ||
return; | ||
} | ||
if (DELIVERED_TRACKING_STATUS_CODES.includes(scanDetail.scanType.toString())) { | ||
@@ -107,0 +122,0 @@ results.deliveredAt = new Date(event.date); |
43
index.js
@@ -59,3 +59,3 @@ const NodeGeocoder = require('node-geocoder'); | ||
this.track = function(trackingNumber, carrier, callback) { | ||
this.track = function(trackingNumber, options, callback) { | ||
if (!trackingNumber) { | ||
@@ -65,14 +65,21 @@ return callback(new Error('Tracking number is not specified.')); | ||
// Carrier is optional | ||
if (typeof carrier === 'function') { | ||
callback = carrier; | ||
carrier = undefined; | ||
// Options are optional | ||
if (typeof options === 'function') { | ||
options = {}; | ||
callback = options; | ||
} | ||
// Backwards compatibility | ||
if (typeof options === 'string') { | ||
options = { | ||
carrier: options | ||
}; | ||
} | ||
// Try to guess the carrier | ||
if (!carrier) { | ||
carrier = this.guessCarrier(trackingNumber); | ||
if (!options.carrier) { | ||
options.carrier = this.guessCarrier(trackingNumber); | ||
// If we still don't know the carrier return an error | ||
if (!carrier) { | ||
if (!options.carrier) { | ||
return callback(new Error('Unknown carrier.')); | ||
@@ -82,20 +89,20 @@ } | ||
carrier = carrier.toLowerCase(); | ||
options.carrier = options.carrier.toLowerCase(); | ||
trackingNumber = trackingNumber.replace(/\s/g, ''); | ||
trackingNumber = trackingNumber.toUpperCase(); | ||
if (carrier === 'dhl') { | ||
if (options.carrier === 'dhl') { | ||
dhl.track(trackingNumber, callback); | ||
} else if (carrier === 'fedex') { | ||
} else if (options.carrier === 'fedex') { | ||
fedEx.track(trackingNumber, callback); | ||
} else if (carrier === 'newgistics') { | ||
pitneyBowes.track(trackingNumber, callback); | ||
} else if (carrier === 'pitney bowes') { | ||
pitneyBowes.track(trackingNumber, callback); | ||
} else if (carrier === 'ups'){ | ||
} else if (options.carrier === 'newgistics') { | ||
pitneyBowes.track(trackingNumber, options, callback); | ||
} else if (options.carrier === 'pitney bowes') { | ||
pitneyBowes.track(trackingNumber, options, callback); | ||
} else if (options.carrier === 'ups'){ | ||
ups.track(trackingNumber, callback); | ||
} else if (carrier === 'usps') { | ||
} else if (options.carrier === 'usps') { | ||
usps.track(trackingNumber, callback); | ||
} else { | ||
return callback(new Error(`Carrier ${carrier} is not supported.`)); | ||
return callback(new Error(`Carrier ${options.carrier} is not supported.`)); | ||
} | ||
@@ -102,0 +109,0 @@ }; |
@@ -7,4 +7,4 @@ { | ||
"node-geocoder": "~3.27.0", | ||
"petty-cache": "~2.6.1", | ||
"pitney-bowes": "~0.1.2", | ||
"petty-cache": "~3.0.1", | ||
"pitney-bowes": "~0.2.0", | ||
"shipping-fedex": "0.2.0", | ||
@@ -42,3 +42,3 @@ "tz-lookup": "~6.1.25", | ||
}, | ||
"version": "1.3.3" | ||
"version": "1.4.0" | ||
} |
# Bloodhound | ||
[![Build Status](https://github.com/mediocre/bloodhound/workflows/build/badge.svg](https://github.com/mediocre/bloodhound/actions?query=workflow%3Abuild) | ||
[![Build Status](https://github.com/mediocre/bloodhound/workflows/build/badge.svg)](https://github.com/mediocre/bloodhound/actions?query=workflow%3Abuild) | ||
[![Coverage Status](https://coveralls.io/repos/github/mediocre/bloodhound/badge.svg)](https://coveralls.io/github/mediocre/bloodhound) | ||
@@ -14,3 +14,3 @@ | ||
**Common format** | ||
**Common format** | ||
@@ -53,3 +53,3 @@ Bloodhound interfaces with several carrier APIs and returns results in a single, unified format. | ||
bloodhound.track('tracking number', 'USPS', function(err, data) { | ||
bloodhound.track('tracking number', { carrier: 'USPS' }, function(err, data) { | ||
console.log(data); | ||
@@ -136,3 +136,3 @@ }); | ||
### bloodhound.track(trackingNumber, [carrier,] callback) | ||
### bloodhound.track(trackingNumber, [options,] callback) | ||
@@ -142,3 +142,3 @@ Retrieves tracking data for the specified tracking number. | ||
```javascript | ||
bloodhound.track('tracking number', 'USPS', function(err, data) { | ||
bloodhound.track('tracking number', { carrier: 'USPS' }, function(err, data) { | ||
console.log(data); | ||
@@ -154,4 +154,4 @@ }); | ||
"address": { | ||
"city": "CARROLLTON", | ||
"state": "TX", | ||
"city": "CARROLLTON", | ||
"state": "TX", | ||
"zip": "75010" | ||
@@ -164,4 +164,4 @@ }, | ||
"address": { | ||
"city": "CARROLLTON", | ||
"state": "TX", | ||
"city": "CARROLLTON", | ||
"state": "TX", | ||
"zip": "75010" | ||
@@ -176,2 +176,2 @@ }, | ||
} | ||
``` | ||
``` |
@@ -128,2 +128,2 @@ const async = require('async'); | ||
exports.geocoder = NodeGeocoder({ provider: 'openstreetmap' }); | ||
exports.geocoder = NodeGeocoder({ apiKey: process.env.GOOGLE_API_KEY, language: 'en', provider: 'google', region: '.us' }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65299
891
170
1
+ Addeddenque@1.5.1(transitive)
+ Addedpetty-cache@3.0.1(transitive)
+ Addedpitney-bowes@0.2.0(transitive)
+ Addedredis@3.0.2(transitive)
+ Addedredis-errors@1.2.0(transitive)
+ Addedredis-parser@3.0.0(transitive)
- Removeddouble-ended-queue@2.1.0-0(transitive)
- Removedpetty-cache@2.6.1(transitive)
- Removedpitney-bowes@0.1.2(transitive)
- Removedredis@2.8.0(transitive)
- Removedredis-parser@2.6.0(transitive)
Updatedpetty-cache@~3.0.1
Updatedpitney-bowes@~0.2.0