universal-parcel-scraper 0.426.1-main.2173 → 0.428.0-main.2178
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/data/catalog.json +5 -3
- package/data/coverage-summary.json +1 -1
- package/data/detection-golden.json +72 -0
- package/dist/browser/scraper.js +7 -3
- package/dist/carriers/tracx-logis/action.d.ts +25 -0
- package/dist/carriers/tracx-logis/action.js +61 -0
- package/dist/carriers/tracx-logis/adapter.d.ts +28 -0
- package/dist/carriers/tracx-logis/adapter.js +127 -0
- package/dist/carriers/tracx-logis/carrier.json +61 -7
- package/dist/carriers/tracx-logis/numbers.json +171 -0
- package/dist/carriers/tracx-logis/parser.d.ts +38 -0
- package/dist/carriers/tracx-logis/parser.js +285 -0
- package/dist/carriers/tracx-logis/partners.d.ts +6 -0
- package/dist/carriers/tracx-logis/partners.js +36 -0
- package/dist/carriers/tracx-logis/status.d.ts +7 -0
- package/dist/carriers/tracx-logis/status.js +61 -0
- package/dist/carriers/tracx-logis/statuses.json +32 -1
- package/dist/carriers/via-cargo/adapter.d.ts +17 -0
- package/dist/carriers/via-cargo/adapter.js +69 -0
- package/dist/carriers/via-cargo/carrier.json +52 -7
- package/dist/carriers/via-cargo/numbers.json +8 -8
- package/dist/carriers/via-cargo/parser.d.ts +15 -0
- package/dist/carriers/via-cargo/parser.js +159 -0
- package/dist/carriers/via-cargo/status.d.ts +7 -0
- package/dist/carriers/via-cargo/status.js +32 -0
- package/dist/carriers/via-cargo/statuses.json +6 -3
- package/dist/carriers/xde-logistics/adapter.d.ts +16 -0
- package/dist/carriers/xde-logistics/adapter.js +73 -0
- package/dist/carriers/xde-logistics/carrier.json +41 -7
- package/dist/carriers/xde-logistics/parser.d.ts +15 -0
- package/dist/carriers/xde-logistics/parser.js +151 -0
- package/dist/carriers/xde-logistics/status.d.ts +7 -0
- package/dist/carriers/xde-logistics/status.js +28 -0
- package/dist/carriers/xde-logistics/statuses.json +8 -4
- package/dist/core/catalog/statusMaps.js +6 -2
- package/dist/data/catalog.json +5 -3
- package/dist/generated/catalog.d.ts +5 -3
- package/dist/generated/catalog.js +5 -3
- package/dist/generated/recognition.js +2 -0
- package/dist/generated/registry.js +9 -3
- package/dist/server/openapi.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ The engine behind [Peek](https://peektracker.com) ([GitHub](https://github.com/p
|
|
|
13
13
|
[](LICENSE)
|
|
14
14
|
|
|
15
15
|
<!-- GENERATED:summary -->
|
|
16
|
-
**3,500+ carriers** through **
|
|
16
|
+
**3,500+ carriers** through **463 dedicated adapters** and **5 universal fallbacks**
|
|
17
17
|
|
|
18
18
|
<sub>767 catalog entries · 134 countries represented</sub>
|
|
19
19
|
<!-- /GENERATED:summary -->
|
|
@@ -155,7 +155,7 @@ createTracker({ providers: ['ParcelsApp', 'Ship24', '17TRACK', 'Postal Ninja', '
|
|
|
155
155
|
<!-- GENERATED:stages -->
|
|
156
156
|
<img src="docs/assets/stages.svg" alt="DHL: Die Sendung wurde in das Zustellfahrzeug geladen.; Mondial Relay: En cours de livraison; Correios Brazil: Objeto saiu para entrega ao destinatário; Correos Express: EN REPARTO; Yamato Transport: 配達中; La Poste / Colissimo: DISTOU. All are filed under out_for_delivery." width="760">
|
|
157
157
|
|
|
158
|
-
The carrier folders record 14,
|
|
158
|
+
The carrier folders record 14,524 such statuses, each filed under one stage.
|
|
159
159
|
<!-- /GENERATED:stages -->
|
|
160
160
|
|
|
161
161
|
Wording nobody recorded yet goes through a classifier that reads seven European languages.
|
package/data/catalog.json
CHANGED
|
@@ -28429,7 +28429,8 @@
|
|
|
28429
28429
|
"timezone": "Asia/Singapore",
|
|
28430
28430
|
"tracking": {
|
|
28431
28431
|
"mode": "automatic",
|
|
28432
|
-
"adapter": "
|
|
28432
|
+
"adapter": "tracx-logis",
|
|
28433
|
+
"recognitionRank": 777
|
|
28433
28434
|
},
|
|
28434
28435
|
"canaryUrl": "https://www.tracxlogis.com/tracking",
|
|
28435
28436
|
"trackingUrlTemplate": "https://www.tracxlogis.com/tracking?trackingNo={trackingNumber}",
|
|
@@ -29386,7 +29387,8 @@
|
|
|
29386
29387
|
"timezone": "America/Argentina/Buenos_Aires",
|
|
29387
29388
|
"tracking": {
|
|
29388
29389
|
"mode": "automatic",
|
|
29389
|
-
"adapter": "
|
|
29390
|
+
"adapter": "via-cargo",
|
|
29391
|
+
"recognitionRank": 936
|
|
29390
29392
|
},
|
|
29391
29393
|
"canaryUrl": "https://formularios.viacargo.com.ar/seguimiento-envio",
|
|
29392
29394
|
"trackingUrlTemplate": "https://formularios.viacargo.com.ar/seguimiento-envio/{trackingNumber}",
|
|
@@ -29979,7 +29981,7 @@
|
|
|
29979
29981
|
"timezone": "Asia/Manila",
|
|
29980
29982
|
"tracking": {
|
|
29981
29983
|
"mode": "automatic",
|
|
29982
|
-
"adapter": "
|
|
29984
|
+
"adapter": "xde-logistics"
|
|
29983
29985
|
},
|
|
29984
29986
|
"canaryUrl": "https://www.xde.com.ph/",
|
|
29985
29987
|
"trackingUrlTemplate": "https://www.xde.com.ph/?tn={trackingNumber}",
|
|
@@ -82237,6 +82237,78 @@
|
|
|
82237
82237
|
"tracx-logis"
|
|
82238
82238
|
]
|
|
82239
82239
|
},
|
|
82240
|
+
{
|
|
82241
|
+
"input": "QSP184265966",
|
|
82242
|
+
"carrier": "tracx-logis",
|
|
82243
|
+
"confidence": "high",
|
|
82244
|
+
"candidates": [
|
|
82245
|
+
"tracx-logis"
|
|
82246
|
+
]
|
|
82247
|
+
},
|
|
82248
|
+
{
|
|
82249
|
+
"input": "QSP198482732",
|
|
82250
|
+
"carrier": "tracx-logis",
|
|
82251
|
+
"confidence": "high",
|
|
82252
|
+
"candidates": [
|
|
82253
|
+
"tracx-logis"
|
|
82254
|
+
]
|
|
82255
|
+
},
|
|
82256
|
+
{
|
|
82257
|
+
"input": "QSP202668109",
|
|
82258
|
+
"carrier": "tracx-logis",
|
|
82259
|
+
"confidence": "high",
|
|
82260
|
+
"candidates": [
|
|
82261
|
+
"tracx-logis"
|
|
82262
|
+
]
|
|
82263
|
+
},
|
|
82264
|
+
{
|
|
82265
|
+
"input": "QSP205361135",
|
|
82266
|
+
"carrier": "tracx-logis",
|
|
82267
|
+
"confidence": "high",
|
|
82268
|
+
"candidates": [
|
|
82269
|
+
"tracx-logis"
|
|
82270
|
+
]
|
|
82271
|
+
},
|
|
82272
|
+
{
|
|
82273
|
+
"input": "QSP210201535",
|
|
82274
|
+
"carrier": "tracx-logis",
|
|
82275
|
+
"confidence": "high",
|
|
82276
|
+
"candidates": [
|
|
82277
|
+
"tracx-logis"
|
|
82278
|
+
]
|
|
82279
|
+
},
|
|
82280
|
+
{
|
|
82281
|
+
"input": "QSP212901660",
|
|
82282
|
+
"carrier": "tracx-logis",
|
|
82283
|
+
"confidence": "high",
|
|
82284
|
+
"candidates": [
|
|
82285
|
+
"tracx-logis"
|
|
82286
|
+
]
|
|
82287
|
+
},
|
|
82288
|
+
{
|
|
82289
|
+
"input": "QSP216440445",
|
|
82290
|
+
"carrier": "tracx-logis",
|
|
82291
|
+
"confidence": "high",
|
|
82292
|
+
"candidates": [
|
|
82293
|
+
"tracx-logis"
|
|
82294
|
+
]
|
|
82295
|
+
},
|
|
82296
|
+
{
|
|
82297
|
+
"input": "QSP220318030",
|
|
82298
|
+
"carrier": "tracx-logis",
|
|
82299
|
+
"confidence": "high",
|
|
82300
|
+
"candidates": [
|
|
82301
|
+
"tracx-logis"
|
|
82302
|
+
]
|
|
82303
|
+
},
|
|
82304
|
+
{
|
|
82305
|
+
"input": "QSP222954533",
|
|
82306
|
+
"carrier": "tracx-logis",
|
|
82307
|
+
"confidence": "high",
|
|
82308
|
+
"candidates": [
|
|
82309
|
+
"tracx-logis"
|
|
82310
|
+
]
|
|
82311
|
+
},
|
|
82240
82312
|
{
|
|
82241
82313
|
"input": "QUL-DL-9194640",
|
|
82242
82314
|
"carrier": "unknown",
|
package/dist/browser/scraper.js
CHANGED
|
@@ -21388,7 +21388,8 @@ var Re = {
|
|
|
21388
21388
|
timezone: "Asia/Singapore",
|
|
21389
21389
|
tracking: {
|
|
21390
21390
|
mode: "automatic",
|
|
21391
|
-
adapter: "
|
|
21391
|
+
adapter: "tracx-logis",
|
|
21392
|
+
recognitionRank: 777
|
|
21392
21393
|
},
|
|
21393
21394
|
canaryUrl: "https://www.tracxlogis.com/tracking",
|
|
21394
21395
|
trackingUrlTemplate: "https://www.tracxlogis.com/tracking?trackingNo={trackingNumber}",
|
|
@@ -22078,7 +22079,8 @@ var Re = {
|
|
|
22078
22079
|
timezone: "America/Argentina/Buenos_Aires",
|
|
22079
22080
|
tracking: {
|
|
22080
22081
|
mode: "automatic",
|
|
22081
|
-
adapter: "
|
|
22082
|
+
adapter: "via-cargo",
|
|
22083
|
+
recognitionRank: 936
|
|
22082
22084
|
},
|
|
22083
22085
|
canaryUrl: "https://formularios.viacargo.com.ar/seguimiento-envio",
|
|
22084
22086
|
trackingUrlTemplate: "https://formularios.viacargo.com.ar/seguimiento-envio/{trackingNumber}",
|
|
@@ -22530,7 +22532,7 @@ var Re = {
|
|
|
22530
22532
|
timezone: "Asia/Manila",
|
|
22531
22533
|
tracking: {
|
|
22532
22534
|
mode: "automatic",
|
|
22533
|
-
adapter: "
|
|
22535
|
+
adapter: "xde-logistics"
|
|
22534
22536
|
},
|
|
22535
22537
|
canaryUrl: "https://www.xde.com.ph/",
|
|
22536
22538
|
trackingUrlTemplate: "https://www.xde.com.ph/?tn={trackingNumber}",
|
|
@@ -29477,6 +29479,7 @@ var _l = {
|
|
|
29477
29479
|
torrestir: 866,
|
|
29478
29480
|
"total-express": 975,
|
|
29479
29481
|
trackon: 821,
|
|
29482
|
+
"tracx-logis": 777,
|
|
29480
29483
|
transaher: 852,
|
|
29481
29484
|
transcorp: 787,
|
|
29482
29485
|
tsjy: 992,
|
|
@@ -29489,6 +29492,7 @@ var _l = {
|
|
|
29489
29492
|
"uzbekistan-post": 906,
|
|
29490
29493
|
"vasp-expresso": 885,
|
|
29491
29494
|
venipak: 240,
|
|
29495
|
+
"via-cargo": 936,
|
|
29492
29496
|
"vinted-go": 410,
|
|
29493
29497
|
wanbexpress: 33,
|
|
29494
29498
|
whistl: 320,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id of the server action TracX Logis's tracking page calls for a parcel's
|
|
3
|
+
* history, read from the page's client chunks. Next builds the page's
|
|
4
|
+
* reference with `createServerReference("<id>", …, "getTrackingHistory")`:
|
|
5
|
+
* only an id bound to that name counts, since the same module registers the
|
|
6
|
+
* page's other actions next to it.
|
|
7
|
+
*/
|
|
8
|
+
/** Chunks read per discovery, the last ones the tracking view loads first. */
|
|
9
|
+
export declare const MAX_CHUNKS = 8;
|
|
10
|
+
/** Fetches a chunk's text within the bytes it may have. */
|
|
11
|
+
export type ChunkReader = (url: string) => Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* The chunks the tracking view loads, in the page's order; when the page no
|
|
14
|
+
* longer names the view, every chunk its scripts load, except the
|
|
15
|
+
* polyfills older browsers take instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare function viewChunks(html: string, page: string): string[];
|
|
18
|
+
/** The id a chunk binds to the history lookup, if it builds that reference. */
|
|
19
|
+
export declare function lookupActionId(source: string): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The action id the page's chunks bind to the history lookup. The view's own
|
|
22
|
+
* code comes after the shared chunks it loads, so the chunks are read from the
|
|
23
|
+
* last one back, one at a time, and never more than `MAX_CHUNKS`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function discoverActionId(html: string, page: string, read: ChunkReader): Promise<string | undefined>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id of the server action TracX Logis's tracking page calls for a parcel's
|
|
3
|
+
* history, read from the page's client chunks. Next builds the page's
|
|
4
|
+
* reference with `createServerReference("<id>", …, "getTrackingHistory")`:
|
|
5
|
+
* only an id bound to that name counts, since the same module registers the
|
|
6
|
+
* page's other actions next to it.
|
|
7
|
+
*/
|
|
8
|
+
/** Chunks read per discovery, the last ones the tracking view loads first. */
|
|
9
|
+
export const MAX_CHUNKS = 8;
|
|
10
|
+
const SCRIPT = /<script\b([^>]*)>/gi;
|
|
11
|
+
const SOURCE = /\bsrc\s*=\s*["']([^"'<>]+)["']/i;
|
|
12
|
+
const CHUNK_PATH = /\/_next\/static\/chunks\/[\w.-]+\.js/g;
|
|
13
|
+
// The tracking view's client module, with the chunks it loads, in the page's own server components.
|
|
14
|
+
const VIEW = /I\[\d+,\[([^\]]{0,8000})\],\\*"TrackingContent\\*"\]/;
|
|
15
|
+
// The page streams its server components in pieces, which can split a row.
|
|
16
|
+
const PIECE_BREAK = /"\]\)<\/script><script\b[^>]*>self\.__next_f\.push\(\[1,"/g;
|
|
17
|
+
const LOOKUP = /createServerReference\)\(\s*"([0-9a-f]{40,42})"\s*,[\w$.\s,]{0,200}?,\s*"getTrackingHistory"\s*\)/;
|
|
18
|
+
/**
|
|
19
|
+
* The chunks the tracking view loads, in the page's order; when the page no
|
|
20
|
+
* longer names the view, every chunk its scripts load, except the
|
|
21
|
+
* polyfills older browsers take instead.
|
|
22
|
+
*/
|
|
23
|
+
export function viewChunks(html, page) {
|
|
24
|
+
const origin = new URL(page).origin;
|
|
25
|
+
const listed = VIEW.exec(html.replace(PIECE_BREAK, ''))?.[1];
|
|
26
|
+
const paths = listed !== undefined ? [...listed.matchAll(CHUNK_PATH)].map(([path]) => path)
|
|
27
|
+
: [...html.matchAll(SCRIPT)].map(([, attributes = '']) => attributes).filter(attributes => !/\bnomodule\b/i.test(attributes))
|
|
28
|
+
.flatMap(attributes => SOURCE.exec(attributes)?.[1] ?? []);
|
|
29
|
+
const chunks = [];
|
|
30
|
+
for (const path of paths) {
|
|
31
|
+
let url;
|
|
32
|
+
try {
|
|
33
|
+
url = new URL(path.replace(/&/g, '&'), page);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (url.origin !== origin || !/^\/_next\/static\/chunks\/[\w.-]+\.js$/.test(url.pathname))
|
|
39
|
+
continue;
|
|
40
|
+
if (!chunks.includes(url.href))
|
|
41
|
+
chunks.push(url.href);
|
|
42
|
+
}
|
|
43
|
+
return chunks;
|
|
44
|
+
}
|
|
45
|
+
/** The id a chunk binds to the history lookup, if it builds that reference. */
|
|
46
|
+
export function lookupActionId(source) {
|
|
47
|
+
return LOOKUP.exec(source)?.[1];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The action id the page's chunks bind to the history lookup. The view's own
|
|
51
|
+
* code comes after the shared chunks it loads, so the chunks are read from the
|
|
52
|
+
* last one back, one at a time, and never more than `MAX_CHUNKS`.
|
|
53
|
+
*/
|
|
54
|
+
export async function discoverActionId(html, page, read) {
|
|
55
|
+
for (const chunk of viewChunks(html, page).reverse().slice(0, MAX_CHUNKS)) {
|
|
56
|
+
const found = lookupActionId(await read(chunk));
|
|
57
|
+
if (found !== undefined)
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AdapterFactory, type TrackingContext } from '../../core/adapter/index.js';
|
|
2
|
+
import type { CarrierResult } from '../../core/result/index.js';
|
|
3
|
+
import { type StepRecorder } from '../../core/telemetry/index.js';
|
|
4
|
+
/** The tracking page, whose server actions look a parcel up. */
|
|
5
|
+
export declare const TRACX_PAGE = "https://www.tracxlogis.com/tracking";
|
|
6
|
+
/**
|
|
7
|
+
* The id of the page's `getTrackingHistory` action, tried first. Every
|
|
8
|
+
* visitor's page carries the same one until the site is built again; when the
|
|
9
|
+
* tracker no longer knows it, the lookup reads the current one from the page.
|
|
10
|
+
*/
|
|
11
|
+
export declare const TRACX_ACTION = "406dae20d6d6ebbae5417f417519605f84915781b6";
|
|
12
|
+
export declare class TracxTracker {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private discovered;
|
|
15
|
+
constructor(options?: {
|
|
16
|
+
fetcher?: typeof fetch;
|
|
17
|
+
recorder?: StepRecorder;
|
|
18
|
+
userAgent?: string;
|
|
19
|
+
/** The id tried first when none read from the page is current; the built-in one by default. */
|
|
20
|
+
action?: string;
|
|
21
|
+
});
|
|
22
|
+
fetch(raw: string, context?: TrackingContext): Promise<CarrierResult>;
|
|
23
|
+
private remember;
|
|
24
|
+
private post;
|
|
25
|
+
/** The page or one of its chunks, as text. */
|
|
26
|
+
private get;
|
|
27
|
+
}
|
|
28
|
+
export declare const adapter: AdapterFactory;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { accepted, recognizeFromLookup } from '../../core/adapter/index.js';
|
|
2
|
+
import { ChallengeError, NotFoundError, SchemaError, TransportError } from '../../core/errors/index.js';
|
|
3
|
+
import { runSteps } from '../../core/runner/index.js';
|
|
4
|
+
import { firstAttemptMs, networkRetryStep } from '../../core/runner/networkRetry.js';
|
|
5
|
+
import { NOOP_RECORDER } from '../../core/telemetry/index.js';
|
|
6
|
+
import { decodeText, fetchBounded, userAgentOf } from '../../core/transport/index.js';
|
|
7
|
+
import { discoverActionId } from './action.js';
|
|
8
|
+
import { isChallengePage, normalizeTracxNumber, parseTracx, PROVIDER, readActionReply, TRACX_MAX_BYTES, UnknownActionError } from './parser.js';
|
|
9
|
+
/** The tracking page, whose server actions look a parcel up. */
|
|
10
|
+
export const TRACX_PAGE = 'https://www.tracxlogis.com/tracking';
|
|
11
|
+
/**
|
|
12
|
+
* The id of the page's `getTrackingHistory` action, tried first. Every
|
|
13
|
+
* visitor's page carries the same one until the site is built again; when the
|
|
14
|
+
* tracker no longer knows it, the lookup reads the current one from the page.
|
|
15
|
+
*/
|
|
16
|
+
export const TRACX_ACTION = '406dae20d6d6ebbae5417f417519605f84915781b6';
|
|
17
|
+
// The page is about a hundred kilobytes, and each of its chunks under a hundred.
|
|
18
|
+
const PAGE_MAX_BYTES = 600_000;
|
|
19
|
+
const CHUNK_MAX_BYTES = 600_000;
|
|
20
|
+
/** How long an id read from the page stays the first try after it last answered. */
|
|
21
|
+
const ACTION_TTL_MS = 6 * 3_600_000;
|
|
22
|
+
const REDIRECTS = [301, 302, 303, 307, 308];
|
|
23
|
+
const UNAVAILABLE = [405, 410];
|
|
24
|
+
const NOT_FOUND = 404;
|
|
25
|
+
export class TracxTracker {
|
|
26
|
+
options;
|
|
27
|
+
// An id the page named and the tracker then answered, for the lookups after it.
|
|
28
|
+
discovered;
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
async fetch(raw, context = {}) {
|
|
33
|
+
const number = normalizeTracxNumber(raw);
|
|
34
|
+
const cached = this.discovered && this.discovered.until > Date.now() ? this.discovered.id : undefined;
|
|
35
|
+
let action = cached ?? this.options.action ?? TRACX_ACTION;
|
|
36
|
+
let stale = false;
|
|
37
|
+
const refresh = async (signal, deadline) => {
|
|
38
|
+
const html = await this.get(TRACX_PAGE, signal, deadline, PAGE_MAX_BYTES);
|
|
39
|
+
const found = await discoverActionId(html, TRACX_PAGE, url => this.get(url, signal, deadline, CHUNK_MAX_BYTES));
|
|
40
|
+
if (found === undefined)
|
|
41
|
+
throw new SchemaError(PROVIDER, 'TracX Logis tracking page no longer names its lookup: the tracking lookup changed');
|
|
42
|
+
// The page naming the id that just failed means the id is not what changed.
|
|
43
|
+
if (found === action)
|
|
44
|
+
throw new SchemaError(PROVIDER, 'TracX Logis did not answer its own lookup: the tracking lookup changed');
|
|
45
|
+
action = found;
|
|
46
|
+
stale = false;
|
|
47
|
+
};
|
|
48
|
+
const attempt = async (signal, timeoutMs) => {
|
|
49
|
+
const deadline = performance.now() + timeoutMs;
|
|
50
|
+
if (stale)
|
|
51
|
+
await refresh(signal, deadline);
|
|
52
|
+
const id = action;
|
|
53
|
+
try {
|
|
54
|
+
const result = await this.post(number, id, signal, deadline);
|
|
55
|
+
this.remember(id);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof NotFoundError)
|
|
60
|
+
this.remember(id);
|
|
61
|
+
if (error instanceof UnknownActionError) {
|
|
62
|
+
stale = true;
|
|
63
|
+
if (id === cached)
|
|
64
|
+
this.discovered = undefined;
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
// The first try gets half of the budget, so a retry fits in the rest. An
|
|
70
|
+
// action the tracker no longer has is read again from the page and tried
|
|
71
|
+
// once more; a lookup that fails to reach TracX Logis, or hangs, gets one retry.
|
|
72
|
+
return runSteps({ carrier: 'tracx-logis', budgetMs: context.budgetMs ?? 15_000, signal: context.signal,
|
|
73
|
+
recorder: this.options.recorder ?? NOOP_RECORDER }, [
|
|
74
|
+
{ id: 'direct', run: ({ signal, remainingMs }) => attempt(signal, firstAttemptMs(remainingMs)) },
|
|
75
|
+
{ id: 'action', recovers: error => error instanceof UnknownActionError,
|
|
76
|
+
run: ({ signal, remainingMs }) => attempt(signal, firstAttemptMs(remainingMs)) },
|
|
77
|
+
networkRetryStep(({ signal, remainingMs }) => attempt(signal, remainingMs)),
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
remember(id) {
|
|
81
|
+
if (id !== TRACX_ACTION)
|
|
82
|
+
this.discovered = { id, until: Date.now() + ACTION_TTL_MS };
|
|
83
|
+
}
|
|
84
|
+
async post(number, action, signal, deadline) {
|
|
85
|
+
// The page calls its action with the number typed in, as a one-item argument list.
|
|
86
|
+
const { response, bytes } = await fetchBounded(TRACX_PAGE, { method: 'POST', signal, headers: {
|
|
87
|
+
Accept: 'text/x-component', 'Content-Type': 'text/plain;charset=UTF-8', 'Next-Action': action,
|
|
88
|
+
'User-Agent': userAgentOf(this.options.userAgent),
|
|
89
|
+
}, body: JSON.stringify([number]) }, { provider: PROVIDER, timeoutMs: timeLeft(deadline), maxBytes: TRACX_MAX_BYTES,
|
|
90
|
+
redirect: 'manual', fetcher: this.options.fetcher, allowHttpStatuses: [...REDIRECTS, 403, NOT_FOUND, ...UNAVAILABLE] });
|
|
91
|
+
// Next answers an action it does not have with 404 and this header.
|
|
92
|
+
if (response.headers.has('x-nextjs-action-not-found'))
|
|
93
|
+
throw new UnknownActionError();
|
|
94
|
+
if (response.status === 403) {
|
|
95
|
+
if (isChallengePage(decodeText(bytes)))
|
|
96
|
+
throw new ChallengeError(PROVIDER, 'TracX Logis answered with a browser check');
|
|
97
|
+
throw new ChallengeError(PROVIDER, 'TracX Logis refused the lookup', { status: 403 });
|
|
98
|
+
}
|
|
99
|
+
if (REDIRECTS.includes(response.status) || response.status === NOT_FOUND || UNAVAILABLE.includes(response.status)) {
|
|
100
|
+
throw new TransportError(PROVIDER, 'TracX Logis tracking lookup is unavailable', { status: response.status });
|
|
101
|
+
}
|
|
102
|
+
return parseTracx(readActionReply(bytes, response.headers.get('content-type')), number);
|
|
103
|
+
}
|
|
104
|
+
/** The page or one of its chunks, as text. */
|
|
105
|
+
async get(url, signal, deadline, maxBytes) {
|
|
106
|
+
const { response, bytes } = await fetchBounded(url, { method: 'GET', signal, headers: {
|
|
107
|
+
Accept: url.endsWith('.js') ? '*/*' : 'text/html', 'User-Agent': userAgentOf(this.options.userAgent),
|
|
108
|
+
} }, { provider: PROVIDER, timeoutMs: timeLeft(deadline), maxBytes, redirect: 'manual', fetcher: this.options.fetcher,
|
|
109
|
+
allowHttpStatuses: [...REDIRECTS, 403, NOT_FOUND, ...UNAVAILABLE] });
|
|
110
|
+
const text = decodeText(bytes);
|
|
111
|
+
if (response.status === 403 || (/^\s*</.test(text) && isChallengePage(text))) {
|
|
112
|
+
throw new ChallengeError(PROVIDER, 'TracX Logis answered its tracking page with a browser check');
|
|
113
|
+
}
|
|
114
|
+
if (response.status !== 200)
|
|
115
|
+
throw new TransportError(PROVIDER, 'TracX Logis tracking page is unavailable', { status: response.status });
|
|
116
|
+
return text;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const timeLeft = (deadline) => Math.max(1, Math.floor(deadline - performance.now()));
|
|
120
|
+
export const adapter = (environment) => {
|
|
121
|
+
const tracker = new TracxTracker({ fetcher: environment.fetcher, recorder: environment.recorder, userAgent: environment.userAgent });
|
|
122
|
+
return {
|
|
123
|
+
id: 'tracx-logis', recordsSteps: true, steps: ['direct', 'action', 'retry'],
|
|
124
|
+
track: (input, context) => tracker.fetch(input.number, context),
|
|
125
|
+
recognize: (number, context) => recognizeFromLookup(() => tracker.fetch(number, context), () => accepted(() => normalizeTracxNumber(number))),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
@@ -23,18 +23,72 @@
|
|
|
23
23
|
"timezone": "Asia/Singapore",
|
|
24
24
|
"tracking": {
|
|
25
25
|
"mode": "automatic",
|
|
26
|
-
"adapter": "
|
|
27
|
-
"steps": [
|
|
26
|
+
"adapter": "tracx-logis",
|
|
27
|
+
"steps": [
|
|
28
|
+
"direct",
|
|
29
|
+
"action",
|
|
30
|
+
"retry"
|
|
31
|
+
],
|
|
32
|
+
"recognition": {
|
|
33
|
+
"rank": 777
|
|
34
|
+
}
|
|
28
35
|
},
|
|
29
|
-
"capabilities": [
|
|
36
|
+
"capabilities": [
|
|
37
|
+
"history",
|
|
38
|
+
"location",
|
|
39
|
+
"provider_code",
|
|
40
|
+
"offset_timestamps",
|
|
41
|
+
"delivered_at",
|
|
42
|
+
"destination_country",
|
|
43
|
+
"delivery_partner",
|
|
44
|
+
"delivery_tracking_number"
|
|
45
|
+
],
|
|
30
46
|
"portal": {
|
|
31
47
|
"url": "https://www.tracxlogis.com/tracking?trackingNo={trackingNumber}",
|
|
32
48
|
"searchUrl": "https://www.tracxlogis.com/tracking",
|
|
33
49
|
"canaryUrl": "https://www.tracxlogis.com/tracking",
|
|
34
|
-
"shows": [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
"shows": [
|
|
51
|
+
"status",
|
|
52
|
+
"history",
|
|
53
|
+
"location",
|
|
54
|
+
"provider_code",
|
|
55
|
+
"offset_timestamps",
|
|
56
|
+
"delivered_at",
|
|
57
|
+
"progress_rail",
|
|
58
|
+
"origin_country",
|
|
59
|
+
"destination_country",
|
|
60
|
+
"delivery_partner",
|
|
61
|
+
"delivery_tracking_number",
|
|
62
|
+
"customer_reference",
|
|
63
|
+
"recipient_name",
|
|
64
|
+
"remarks"
|
|
65
|
+
],
|
|
66
|
+
"scraped": [
|
|
67
|
+
"status",
|
|
68
|
+
"history",
|
|
69
|
+
"location",
|
|
70
|
+
"provider_code",
|
|
71
|
+
"offset_timestamps",
|
|
72
|
+
"delivered_at",
|
|
73
|
+
"destination_country",
|
|
74
|
+
"delivery_partner",
|
|
75
|
+
"delivery_tracking_number"
|
|
76
|
+
],
|
|
77
|
+
"discarded": [
|
|
78
|
+
"progress_rail",
|
|
79
|
+
"origin_country",
|
|
80
|
+
"customer_reference",
|
|
81
|
+
"recipient_name",
|
|
82
|
+
"remarks"
|
|
83
|
+
],
|
|
84
|
+
"unavailable": [
|
|
85
|
+
"eta",
|
|
86
|
+
"weight",
|
|
87
|
+
"service_name",
|
|
88
|
+
"sender_name",
|
|
89
|
+
"recipient_address",
|
|
90
|
+
"proof_of_delivery"
|
|
91
|
+
]
|
|
38
92
|
},
|
|
39
93
|
"links": [
|
|
40
94
|
{
|