Skip to content

Commit

Permalink
fixed an issue in USPS is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
egg- committed Nov 4, 2022
1 parent 9a0431f commit ca79817
Show file tree
Hide file tree
Showing 6 changed files with 2,726 additions and 2,585 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [10.x, 12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.7.3
* fixed an issue in USPS is not working

# 2.7.2
* fixed an issue in JNT is not working

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install delivery-tracker
var tracker = require('delivery-tracker')
var courier = tracker.courier(tracker.COURIER.KOREAPOST.CODE)

courier.trace({trace_number}, function (err, result) {
courier.trace('TRACE_NUMBER', function (err, result) {
console.log(result)
})
```
Expand Down
25 changes: 16 additions & 9 deletions lib/courier/usps.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,34 @@ var parser = {
}
var result = {
courier: courier,
number: $('input[name=label]').val(),
number: $('input[name=label]').val().trim(),
status: tracker.STATUS.PENDING
}

var checkpoints = []
var $history = $('.tracking-progress-bar-status-container').find('.tb-step')

$history.each((index, element) => {
if (element.attribs?.class.indexOf('toggle-history-container') !== -1)
if (element.attribs?.class.indexOf('toggle-history-container') !== -1) {
return
}

var checkpoint = {
courier: courier,
location: $(element).find('.tb-location').text().trim(),
message: $(element).find('.tb-status-detail').text(),
status: tracker.STATUS.IN_TRANSIT,
// November 17, 2017, 3:08 pm
time: moment($(element).find('.tb-date').text().trim(), 'MMMM DD, YYYY, hh:mm a').format('YYYY-MM-DDTHH:mm')
time: moment(
$(element).find('.tb-date').text().trim(),
'MMMM DD, YYYY, hh:mm a'
).format('YYYY-MM-DDTHH:mm')
}

checkpoint.message.indexOf('Shipping Label Created') !== -1 && (checkpoint.status = tracker.STATUS.INFO_RECEIVED)
checkpoint.message.indexOf('Delivered') !== -1 && (checkpoint.status = tracker.STATUS.DELIVERED)
checkpoint.message.indexOf('Shipping Label Created') !== -1 &&
(checkpoint.status = tracker.STATUS.INFO_RECEIVED)
checkpoint.message.indexOf('Delivered') !== -1 &&
(checkpoint.status = tracker.STATUS.DELIVERED)

checkpoints.push(checkpoint)
})
Expand All @@ -60,16 +66,17 @@ module.exports = function (opts) {
trackingInfo: trackingInfo,
trace: function (number, cb) {
var tracking = trackingInfo(number)
request.get({
url: tracking.url
}, function (err, res, body) {
request.get({ url: tracking.url }, function (err, res, body) {
if (err) {
return cb(err)
}

try {
var result = parser.trace(body)
cb(result ? null : tracker.error(tracker.ERROR.INVALID_NUMBER), result)
cb(
result ? null : tracker.error(tracker.ERROR.INVALID_NUMBER),
result
)
} catch (e) {
cb(tracker.error(e.message))
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delivery-tracker",
"version": "2.7.2",
"version": "2.7.3",
"author": {
"name": "egg",
"email": "[email protected]"
Expand Down
5,277 changes: 2,704 additions & 2,573 deletions test/fixtures/usps-DELIVEREDNM

Large diffs are not rendered by default.

0 comments on commit ca79817

Please sign in to comment.