geartrack
Advanced tools
Comparing version
{ | ||
"name": "geartrack", | ||
"version": "2.7.23", | ||
"version": "2.8.0", | ||
"description": "Tracking providers for Gearbest and AliExpress Orders.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,3 +36,3 @@ 'use strict'; | ||
const maxTries = 3 | ||
const maxTries = 10 | ||
let tries = maxTries // sometimes the website returns an error (seems random :/) | ||
@@ -46,6 +46,10 @@ while (tries > 0) { | ||
} catch (e) { | ||
await utils.sleep(2000) | ||
continue | ||
} | ||
if (info.msg != "Ok") continue | ||
if (info.msg != "Ok" || info.dat[0].delay == -1) { | ||
await utils.sleep(2000) | ||
continue | ||
} | ||
@@ -110,5 +114,9 @@ if (info.dat[0].yt != null) { | ||
this.trackerWebsite = URL + id | ||
this.trackerWebsite = tracker.getLink(id) | ||
} | ||
tracker.getLink = function (id) { | ||
return URL + id | ||
} | ||
module.exports = tracker |
@@ -70,5 +70,9 @@ 'use strict'; | ||
this.notes = obj.Notes | ||
this.trackerWebsite = "http://www.adicional.pt" | ||
this.trackerWebsite = adicional.getLink(null) | ||
} | ||
adicional.getLink = function (id) { | ||
return "http://www.adicional.pt" | ||
} | ||
module.exports = adicional |
@@ -92,5 +92,9 @@ 'use strict'; | ||
this.destinyId = destinyId | ||
this.trackerWebsite = URL + id | ||
this.trackerWebsite = cainiao.getLink(id) | ||
} | ||
cainiao.getLink = function (id) { | ||
return URL + id | ||
} | ||
/* | ||
@@ -97,0 +101,0 @@ |-------------------------------------------------------------------------- |
@@ -86,5 +86,9 @@ 'use strict'; | ||
this.states = obj.states | ||
this.trackerWebsite = URL.replace('{{id}}', obj.id) | ||
this.trackerWebsite = cjah.getLink(obj.id) | ||
} | ||
cjah.getLink = function (id) { | ||
return URL.replace('{{id}}', id) | ||
} | ||
module.exports = cjah |
@@ -114,5 +114,9 @@ 'use strict'; | ||
this.states = obj.states | ||
this.trackerWebsite = URL.replace('{{id}}', obj.id) | ||
this.trackerWebsite = correos.getLink(obj.id) | ||
} | ||
correos.getLink = function (id) { | ||
return URL.replace('{{id}}', id) | ||
} | ||
module.exports = correos |
@@ -131,5 +131,9 @@ 'use strict'; | ||
this.trackerWebsite = sprintf(URL, utils.getPostalCode(obj.id), obj.id) | ||
this.trackerWebsite = correos.getLink(obj.id) | ||
} | ||
correos.getLink = function (id) { | ||
return sprintf(URL, utils.getPostalCode(id), id) | ||
} | ||
module.exports = correos |
@@ -138,5 +138,9 @@ 'use strict'; | ||
this.destiny = obj.destiny | ||
this.trackerWebsite = "https://s.correosexpress.com" | ||
this.trackerWebsite = correos.getLink(null) | ||
} | ||
correos.getLink = function (id) { | ||
return "https://s.correosexpress.com" | ||
} | ||
module.exports = correos |
@@ -151,5 +151,9 @@ 'use strict'; | ||
this.messages = messages | ||
this.trackerWebsite = URL + id | ||
this.trackerWebsite = ctt.getLink(id) | ||
} | ||
ctt.getLink = function (id) { | ||
return URL + id | ||
} | ||
/* | ||
@@ -156,0 +160,0 @@ |-------------------------------------------------------------------------- |
@@ -96,5 +96,9 @@ 'use strict'; | ||
this.destiny = obj.destiny | ||
this.trackerWebsite = "http://www.dhl.com/en/express/tracking.html?AWB=" + this.id | ||
this.trackerWebsite = exportModule.getLink(this.id) | ||
} | ||
exportModule.getLink = function (id) { | ||
return "http://www.dhl.com/en/express/tracking.html?AWB=" + id | ||
} | ||
module.exports = exportModule |
@@ -156,5 +156,9 @@ 'use strict'; | ||
this.states = obj.states.reverse() | ||
this.trackerWebsite = directURL + obj.tracking_no | ||
this.trackerWebsite = directLink.getLink(obj.tracking_no) | ||
} | ||
directLink.getLink = function (id) { | ||
return directURL + id | ||
} | ||
module.exports = directLink |
@@ -98,5 +98,10 @@ 'use strict'; | ||
this.ref = obj.ref | ||
this.trackerWebsite = URL | ||
this.trackerWebsite = expresso.getLink(null) | ||
} | ||
expresso.getLink = function (id) { | ||
return URL | ||
} | ||
/* | ||
@@ -103,0 +108,0 @@ |-------------------------------------------------------------------------- |
@@ -95,5 +95,9 @@ 'use strict'; | ||
this.trackerWebsite = URL + id | ||
this.trackerWebsite = tracker.getLink(id) | ||
} | ||
tracker.getLink = function (id) { | ||
return URL + id | ||
} | ||
module.exports = tracker |
@@ -119,5 +119,9 @@ 'use strict'; | ||
this.states = obj.states | ||
this.trackerWebsite = URL | ||
this.trackerWebsite = malaysiaPos.getLink(null) | ||
} | ||
malaysiaPos.getLink = function (id) { | ||
return URL | ||
} | ||
module.exports = malaysiaPos |
@@ -95,5 +95,9 @@ 'use strict'; | ||
this.trackerWebsite = URL + id | ||
this.trackerWebsite = tracker.getLink(id) | ||
} | ||
tracker.getLink = function (id) { | ||
return URL + id | ||
} | ||
module.exports = tracker |
@@ -114,4 +114,9 @@ 'use strict'; | ||
this.country = obj.country | ||
this.trackerWebsite = URL.replace('{{id}}', obj.id) | ||
this.trackerWebsite = panasia.getLink(obj.id) | ||
} | ||
panasia.getLink = function (id) { | ||
return URL.replace('{{id}}', id) | ||
} | ||
module.exports = panasia |
@@ -110,5 +110,9 @@ 'use strict'; | ||
this.destiny = obj.destiny | ||
this.trackerWebsite = "https://parceltracking.pb.com/app/#/dashboard/" + this.id | ||
this.trackerWebsite = pitney.getLink(this.id) | ||
} | ||
pitney.getLink = function (id) { | ||
return "https://parceltracking.pb.com/app/#/dashboard/" + id | ||
} | ||
module.exports = pitney |
@@ -92,5 +92,9 @@ 'use strict'; | ||
this.states = obj.states | ||
this.trackerWebsite = "http://www.postnl.post/tracktrace" | ||
this.trackerWebsite = postNL.getLink(null) | ||
} | ||
postNL.getLink = function (id) { | ||
return "http://www.postnl.post/tracktrace" | ||
} | ||
module.exports = postNL |
@@ -98,5 +98,9 @@ 'use strict'; | ||
this.states = messages | ||
this.trackerWebsite = URL | ||
this.trackerWebsite = singpost.getLink(null) | ||
} | ||
singpost.getLink = function (id) { | ||
return URL | ||
} | ||
/* | ||
@@ -103,0 +107,0 @@ |-------------------------------------------------------------------------- |
@@ -109,3 +109,3 @@ 'use strict'; | ||
this.status = obj.status | ||
this.trackerWebsite = "http://www.sky56.cn/english/track/index" | ||
this.trackerWebsite = sky.getLink(this.id) | ||
@@ -117,2 +117,6 @@ this.isNL = () => { | ||
sky.getLink = function (id) { | ||
return "http://www.sky56.cn/english/track/index" | ||
} | ||
/* | ||
@@ -119,0 +123,0 @@ |-------------------------------------------------------------------------- |
@@ -131,5 +131,9 @@ 'use strict'; | ||
this.destiny = obj.destiny | ||
this.trackerWebsite = "https://track24.net/?code=" + this.id | ||
this.trackerWebsite = exportModule.getLink(this.id) | ||
} | ||
exportModule.getLink = function (id) { | ||
return "https://track24.net/?code=" + id | ||
} | ||
module.exports = exportModule |
@@ -11,13 +11,13 @@ 'use strict'; | ||
const directLink = {} | ||
const trackchinapost = {} | ||
/** | ||
* Get DirectLink info | ||
* Get China Post info | ||
* Async | ||
* | ||
* @param id | ||
* @param callback(Error, DirectLinkInfo) | ||
* @param callback(Error, ChinaPostInfo) | ||
* @param _try | ||
*/ | ||
directLink.getInfo = function (id, callback, _try = 0) { | ||
trackchinapost.getInfo = function (id, callback, _try = 0) { | ||
if (_try >= 4) { | ||
@@ -42,3 +42,3 @@ return callback(utils.errorBusy()) | ||
if (body.indexOf('server is busy') != -1) { | ||
return setTimeout(directLink.getInfo, 2000, id, callback, ++_try) | ||
return setTimeout(trackchinapost.getInfo, 2000, id, callback, ++_try) | ||
} | ||
@@ -101,5 +101,9 @@ | ||
this.trackerWebsite = "http://track-chinapost.com/startairmail.php" | ||
this.trackerWebsite = trackchinapost.getLink(null) | ||
} | ||
module.exports = directLink | ||
trackchinapost.getLink = function (id) { | ||
return "http://track-chinapost.com/startairmail.php" | ||
} | ||
module.exports = trackchinapost |
@@ -10,3 +10,3 @@ "use strict"; | ||
*/ | ||
const getErrorMessage = function(type, error = null, id = null) { | ||
const getErrorMessage = function (type, error = null, id = null) { | ||
type = type.toUpperCase() | ||
@@ -30,27 +30,27 @@ let errors = { | ||
module.exports.errorParser = function(id = null, error = null) { | ||
module.exports.errorParser = function (id = null, error = null) { | ||
return getErrorMessage('PARSER', error, id) | ||
} | ||
module.exports.errorEmpty = function(id = null, error = null) { | ||
module.exports.errorEmpty = function (id = null, error = null) { | ||
return getErrorMessage('EMPTY', error, id) | ||
} | ||
module.exports.errorNoData = function(id = null, error = null) { | ||
module.exports.errorNoData = function (id = null, error = null) { | ||
return getErrorMessage('NO_DATA', error, id) | ||
} | ||
module.exports.errorBusy = function(id = null, error = null) { | ||
module.exports.errorBusy = function (id = null, error = null) { | ||
return getErrorMessage('BUSY', error, id) | ||
} | ||
module.exports.errorUnavailable = function(id = null, error = null) { | ||
module.exports.errorUnavailable = function (id = null, error = null) { | ||
return getErrorMessage('UNAVAILABLE', error, id) | ||
} | ||
module.exports.errorDown = function(id = null, error = null) { | ||
module.exports.errorDown = function (id = null, error = null) { | ||
return getErrorMessage('DOWN', error, id) | ||
} | ||
module.exports.errorActionRequired = function(id = null, error = null) { | ||
module.exports.errorActionRequired = function (id = null, error = null) { | ||
return getErrorMessage('ACTION_REQUIRED', error, id) | ||
@@ -125,3 +125,3 @@ } | ||
} else { | ||
if(line[key] = elem.children[fields[key].idx].children.length > 0){ | ||
if (line[key] = elem.children[fields[key].idx].children.length > 0) { | ||
line[key] = elem.children[fields[key].idx].children[0].data.trim() | ||
@@ -145,4 +145,13 @@ } else { | ||
return str | ||
.replace(/\p{Han}+/, '') | ||
.replace(/[\u3400-\u9FBF]/g, '') | ||
.replace(/\p{Han}+/, '') | ||
.replace(/[\u3400-\u9FBF]/g, '') | ||
} | ||
/** | ||
* Useful to create some delays between requests | ||
* @param ms | ||
* @returns {Promise} | ||
*/ | ||
module.exports.sleep = function (ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} |
@@ -129,5 +129,9 @@ 'use strict'; | ||
this.states = obj.states | ||
this.trackerWebsite = URL | ||
this.trackerWebsite = winit.getLink(null) | ||
} | ||
winit.getLink = function (id) { | ||
return URL | ||
} | ||
module.exports = winit |
@@ -112,5 +112,9 @@ 'use strict'; | ||
this.state = this.states[0].state | ||
this.trackerWebsite = URL | ||
this.trackerWebsite = yanwen.getLink(null) | ||
} | ||
yanwen.getLink = function (id) { | ||
return URL | ||
} | ||
/* | ||
@@ -117,0 +121,0 @@ |-------------------------------------------------------------------------- |
@@ -8,5 +8,7 @@ const Promise = require("bluebird") | ||
if(!process.env.CI) { // this test fails in Travis CI | ||
test('extract info with success', () => { | ||
test('extract info with success', async () => { | ||
const id = 'BZ012761245CN' | ||
return getInfo(id).then(info => { | ||
try { | ||
const info = await getInfo(id) | ||
expect(info.id).toBe(id) | ||
@@ -17,3 +19,5 @@ expect(info.destiny).toBe('Portugal') | ||
expect(info.states.length).toBeGreaterThanOrEqual(2) | ||
}) | ||
} catch (e) { | ||
expect(e.message).toContain('DOWN') // only allow down exceptions | ||
} | ||
}) | ||
@@ -20,0 +24,0 @@ } |
124779
1.77%3301
2.61%