universal-parcel-scraper 0.1343.0-main.9141 → 0.1346.0-main.9155
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 +7 -4
- package/data/coverage-summary.json +1 -1
- package/data/detection-golden.json +48 -10
- package/dist/browser/scraper.js +6 -4
- package/dist/carriers/bfe-express/carrier.json +2 -1
- package/dist/carriers/huaya-express/statuses.json +2 -1
- package/dist/carriers/instapack/adapter.d.ts +20 -0
- package/dist/carriers/instapack/adapter.js +73 -0
- package/dist/carriers/instapack/carrier.json +42 -7
- package/dist/carriers/instapack/numbers.json +46 -2
- package/dist/carriers/instapack/parser.d.ts +27 -0
- package/dist/carriers/instapack/parser.js +165 -0
- package/dist/carriers/instapack/status.d.ts +6 -0
- package/dist/carriers/instapack/status.js +23 -0
- package/dist/carriers/instapack/statuses.json +6 -1
- package/dist/carriers/jcw-express/numbers.json +21 -2
- package/dist/carriers/pasarex/carrier.json +1 -1
- package/dist/carriers/pasarex/numbers.json +10 -25
- package/dist/carriers/xingyunyi/adapter.d.ts +15 -0
- package/dist/carriers/xingyunyi/adapter.js +64 -0
- package/dist/carriers/xingyunyi/carrier.json +45 -7
- package/dist/carriers/xingyunyi/numbers.json +40 -2
- package/dist/carriers/xingyunyi/parser.d.ts +17 -0
- package/dist/carriers/xingyunyi/parser.js +194 -0
- package/dist/carriers/xingyunyi/status.d.ts +8 -0
- package/dist/carriers/xingyunyi/status.js +52 -0
- package/dist/carriers/xingyunyi/statuses.json +19 -1
- package/dist/carriers/yunexpress/adapter.js +43 -3
- package/dist/carriers/yunexpress/status.js +11 -5
- package/dist/carriers/yunexpress/statuses.json +4 -1
- package/dist/core/catalog/statusMaps.js +4 -2
- package/dist/data/catalog.json +7 -4
- package/dist/generated/catalog.js +7 -4
- package/dist/generated/registry.js +6 -2
- 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
|
-
**4,500+ carriers** through **
|
|
16
|
+
**4,500+ carriers** through **1142 dedicated adapters** and **5 universal fallbacks**
|
|
17
17
|
|
|
18
18
|
<sub>2057 catalog entries · 166 countries represented</sub>
|
|
19
19
|
<!-- /GENERATED:summary -->
|
|
@@ -164,7 +164,7 @@ the command line's `track --source ParcelsApp` does the same.
|
|
|
164
164
|
<!-- GENERATED:stages -->
|
|
165
165
|
<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">
|
|
166
166
|
|
|
167
|
-
The carrier folders record 25,
|
|
167
|
+
The carrier folders record 25,362 such statuses, each filed under one stage.
|
|
168
168
|
<!-- /GENERATED:stages -->
|
|
169
169
|
|
|
170
170
|
Wording nobody recorded yet goes through a classifier that reads seven European languages.
|
package/data/catalog.json
CHANGED
|
@@ -12172,7 +12172,8 @@
|
|
|
12172
12172
|
"displayName": "BFE Express",
|
|
12173
12173
|
"color": "#122a88",
|
|
12174
12174
|
"aliases": [
|
|
12175
|
-
"BFEexpress"
|
|
12175
|
+
"BFEexpress",
|
|
12176
|
+
"BFE"
|
|
12176
12177
|
],
|
|
12177
12178
|
"countries": [
|
|
12178
12179
|
"AR",
|
|
@@ -35033,7 +35034,8 @@
|
|
|
35033
35034
|
"timezone": "Europe/Madrid",
|
|
35034
35035
|
"tracking": {
|
|
35035
35036
|
"mode": "automatic",
|
|
35036
|
-
"adapter": "
|
|
35037
|
+
"adapter": "instapack",
|
|
35038
|
+
"localClocks": true
|
|
35037
35039
|
},
|
|
35038
35040
|
"canaryUrl": "https://www.instapack.es/",
|
|
35039
35041
|
"trackingSearchUrl": "https://back.instapack.es/client-dashboard/seguimiento-de-envios/",
|
|
@@ -49320,7 +49322,7 @@
|
|
|
49320
49322
|
"detectionRules": [
|
|
49321
49323
|
{
|
|
49322
49324
|
"pattern": "^AMZPSR\\d{9}$",
|
|
49323
|
-
"confidence": "
|
|
49325
|
+
"confidence": "high"
|
|
49324
49326
|
}
|
|
49325
49327
|
]
|
|
49326
49328
|
},
|
|
@@ -69917,7 +69919,8 @@
|
|
|
69917
69919
|
"timezone": "Asia/Shanghai",
|
|
69918
69920
|
"tracking": {
|
|
69919
69921
|
"mode": "automatic",
|
|
69920
|
-
"adapter": "
|
|
69922
|
+
"adapter": "xingyunyi",
|
|
69923
|
+
"localClocks": true
|
|
69921
69924
|
},
|
|
69922
69925
|
"canaryUrl": "https://www.xingyunyi.com/",
|
|
69923
69926
|
"trackingUrlTemplate": "https://www.xingyunyi.com/tracking?nums={trackingNumber}",
|
|
@@ -11944,6 +11944,20 @@
|
|
|
11944
11944
|
"postlogistics"
|
|
11945
11945
|
]
|
|
11946
11946
|
},
|
|
11947
|
+
{
|
|
11948
|
+
"input": "090420181030503",
|
|
11949
|
+
"carrier": "unknown",
|
|
11950
|
+
"confidence": "low",
|
|
11951
|
+
"candidates": [
|
|
11952
|
+
"dpd-fr",
|
|
11953
|
+
"brt",
|
|
11954
|
+
"yunda",
|
|
11955
|
+
"ozon-logistics"
|
|
11956
|
+
],
|
|
11957
|
+
"asked": [
|
|
11958
|
+
"brt"
|
|
11959
|
+
]
|
|
11960
|
+
},
|
|
11947
11961
|
{
|
|
11948
11962
|
"input": "09187717",
|
|
11949
11963
|
"carrier": "unknown",
|
|
@@ -84685,40 +84699,40 @@
|
|
|
84685
84699
|
},
|
|
84686
84700
|
{
|
|
84687
84701
|
"input": "AMZPSR020816106",
|
|
84688
|
-
"carrier": "
|
|
84689
|
-
"confidence": "
|
|
84702
|
+
"carrier": "pasarex",
|
|
84703
|
+
"confidence": "high",
|
|
84690
84704
|
"candidates": [
|
|
84691
84705
|
"pasarex"
|
|
84692
84706
|
]
|
|
84693
84707
|
},
|
|
84694
84708
|
{
|
|
84695
84709
|
"input": "AMZPSR020965874",
|
|
84696
|
-
"carrier": "
|
|
84697
|
-
"confidence": "
|
|
84710
|
+
"carrier": "pasarex",
|
|
84711
|
+
"confidence": "high",
|
|
84698
84712
|
"candidates": [
|
|
84699
84713
|
"pasarex"
|
|
84700
84714
|
]
|
|
84701
84715
|
},
|
|
84702
84716
|
{
|
|
84703
84717
|
"input": "AMZPSR023935072",
|
|
84704
|
-
"carrier": "
|
|
84705
|
-
"confidence": "
|
|
84718
|
+
"carrier": "pasarex",
|
|
84719
|
+
"confidence": "high",
|
|
84706
84720
|
"candidates": [
|
|
84707
84721
|
"pasarex"
|
|
84708
84722
|
]
|
|
84709
84723
|
},
|
|
84710
84724
|
{
|
|
84711
84725
|
"input": "AMZPSR024279529",
|
|
84712
|
-
"carrier": "
|
|
84713
|
-
"confidence": "
|
|
84726
|
+
"carrier": "pasarex",
|
|
84727
|
+
"confidence": "high",
|
|
84714
84728
|
"candidates": [
|
|
84715
84729
|
"pasarex"
|
|
84716
84730
|
]
|
|
84717
84731
|
},
|
|
84718
84732
|
{
|
|
84719
84733
|
"input": "AMZPSR025530371",
|
|
84720
|
-
"carrier": "
|
|
84721
|
-
"confidence": "
|
|
84734
|
+
"carrier": "pasarex",
|
|
84735
|
+
"confidence": "high",
|
|
84722
84736
|
"candidates": [
|
|
84723
84737
|
"pasarex"
|
|
84724
84738
|
]
|
|
@@ -89478,6 +89492,12 @@
|
|
|
89478
89492
|
"aliexpress"
|
|
89479
89493
|
]
|
|
89480
89494
|
},
|
|
89495
|
+
{
|
|
89496
|
+
"input": "CNES00102358787",
|
|
89497
|
+
"carrier": "unknown",
|
|
89498
|
+
"confidence": "none",
|
|
89499
|
+
"candidates": []
|
|
89500
|
+
},
|
|
89481
89501
|
{
|
|
89482
89502
|
"input": "CNES00602228835",
|
|
89483
89503
|
"carrier": "unknown",
|
|
@@ -99734,6 +99754,12 @@
|
|
|
99734
99754
|
"jch"
|
|
99735
99755
|
]
|
|
99736
99756
|
},
|
|
99757
|
+
{
|
|
99758
|
+
"input": "JCW00002276193",
|
|
99759
|
+
"carrier": "unknown",
|
|
99760
|
+
"confidence": "none",
|
|
99761
|
+
"candidates": []
|
|
99762
|
+
},
|
|
99737
99763
|
{
|
|
99738
99764
|
"input": "JCZ0318108989DH",
|
|
99739
99765
|
"carrier": "jcex",
|
|
@@ -120865,6 +120891,18 @@
|
|
|
120865
120891
|
"dhlink"
|
|
120866
120892
|
]
|
|
120867
120893
|
},
|
|
120894
|
+
{
|
|
120895
|
+
"input": "XYYEX0035607568YQ",
|
|
120896
|
+
"carrier": "unknown",
|
|
120897
|
+
"confidence": "none",
|
|
120898
|
+
"candidates": []
|
|
120899
|
+
},
|
|
120900
|
+
{
|
|
120901
|
+
"input": "XYYEX1036968315YQ",
|
|
120902
|
+
"carrier": "unknown",
|
|
120903
|
+
"confidence": "none",
|
|
120904
|
+
"candidates": []
|
|
120905
|
+
},
|
|
120868
120906
|
{
|
|
120869
120907
|
"input": "XYZ000000001",
|
|
120870
120908
|
"carrier": "unknown",
|
package/dist/browser/scraper.js
CHANGED
|
@@ -9522,7 +9522,7 @@ var r = {
|
|
|
9522
9522
|
"bfe-express": {
|
|
9523
9523
|
displayName: "BFE Express",
|
|
9524
9524
|
color: "#122a88",
|
|
9525
|
-
aliases: ["BFEexpress"],
|
|
9525
|
+
aliases: ["BFEexpress", "BFE"],
|
|
9526
9526
|
countries: [
|
|
9527
9527
|
"AR",
|
|
9528
9528
|
"PE",
|
|
@@ -26948,7 +26948,8 @@ var r = {
|
|
|
26948
26948
|
timezone: "Europe/Madrid",
|
|
26949
26949
|
tracking: {
|
|
26950
26950
|
mode: "automatic",
|
|
26951
|
-
adapter: "
|
|
26951
|
+
adapter: "instapack",
|
|
26952
|
+
localClocks: !0
|
|
26952
26953
|
},
|
|
26953
26954
|
canaryUrl: "https://www.instapack.es/",
|
|
26954
26955
|
trackingSearchUrl: "https://back.instapack.es/client-dashboard/seguimiento-de-envios/",
|
|
@@ -37947,7 +37948,7 @@ var r = {
|
|
|
37947
37948
|
}],
|
|
37948
37949
|
detectionRules: [{
|
|
37949
37950
|
pattern: "^AMZPSR\\d{9}$",
|
|
37950
|
-
confidence: "
|
|
37951
|
+
confidence: "high"
|
|
37951
37952
|
}]
|
|
37952
37953
|
},
|
|
37953
37954
|
"pasha-hawaii": {
|
|
@@ -53665,7 +53666,8 @@ var r = {
|
|
|
53665
53666
|
timezone: "Asia/Shanghai",
|
|
53666
53667
|
tracking: {
|
|
53667
53668
|
mode: "automatic",
|
|
53668
|
-
adapter: "
|
|
53669
|
+
adapter: "xingyunyi",
|
|
53670
|
+
localClocks: !0
|
|
53669
53671
|
},
|
|
53670
53672
|
canaryUrl: "https://www.xingyunyi.com/",
|
|
53671
53673
|
trackingUrlTemplate: "https://www.xingyunyi.com/tracking?nums={trackingNumber}",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
{"wording": "【…】【…】¡Recolección exitosa!. El mensajero de J&T asignado … recolectó tu envío.", "language": "es", "stage": "in_transit", "confirmedBy": "live", "firstSeen": "2026-11-21", "note": "Copied from J&T Express Mexico, which delivers the last leg on the line into Mexico: its courier collects the cleared parcel. It is not the first acceptance. The town, the site, the courier and what follows the sentence are read as ellipses."},
|
|
51
51
|
{"wording": "【…】Tu envío ha salido de【…】con destino a【…】", "language": "es", "stage": "in_transit", "confirmedBy": "live", "firstSeen": "2026-11-21", "note": "Copied from J&T Express Mexico: the parcel leaves one of its sites for the next. The towns and sites are read as ellipses."},
|
|
52
52
|
{"wording": "【…】Tu envío ha llegado a【…】", "language": "es", "stage": "in_transit", "confirmedBy": "live", "firstSeen": "2026-11-21", "note": "Copied from J&T Express Mexico: the parcel reaches one of its sites."},
|
|
53
|
-
{"wording": "【…】【…】El mensajero de J&T Express … está en camino a tu domicilio.", "language": "es", "stage": "out_for_delivery", "confirmedBy": "source", "note": "J&T Express Mexico's courier on the way to the recipient's home, as JRT's tracker copies it from the same feed on the same platform. The town, the site, the courier and what follows the sentence are read as ellipses."}
|
|
53
|
+
{"wording": "【…】【…】El mensajero de J&T Express … está en camino a tu domicilio.", "language": "es", "stage": "out_for_delivery", "confirmedBy": "source", "note": "J&T Express Mexico's courier on the way to the recipient's home, as JRT's tracker copies it from the same feed on the same platform. The town, the site, the courier and what follows the sentence are read as ellipses."},
|
|
54
|
+
{"wording": "la spedizione è in transito", "language": "it", "stage": "in_transit", "confirmedBy": "live", "firstSeen": "2026-11-24", "note": "The Italian last mile's sentence, as Poste Italiane opens its own: the parcel in transit, at a town and its province."}
|
|
54
55
|
]
|
|
55
56
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AdapterFactory, 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
|
+
export { INSTAPACK_TRACKING, normalizeInstapackNumber, parseInstapack } from './parser.js';
|
|
5
|
+
export declare class InstapackTracker {
|
|
6
|
+
private readonly options;
|
|
7
|
+
constructor(options?: {
|
|
8
|
+
fetcher?: typeof fetch;
|
|
9
|
+
recorder?: StepRecorder;
|
|
10
|
+
userAgent?: string;
|
|
11
|
+
});
|
|
12
|
+
private request;
|
|
13
|
+
/**
|
|
14
|
+
* The form posted with the code. A known code is redirected to the parcel's signed page, read
|
|
15
|
+
* next; an unknown one gets the form again with a message.
|
|
16
|
+
*/
|
|
17
|
+
private read;
|
|
18
|
+
fetch(raw: string, context?: TrackingContext): Promise<CarrierResult>;
|
|
19
|
+
}
|
|
20
|
+
export declare const adapter: AdapterFactory;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ChallengeError, MaintenanceError, RateLimitedError, SchemaError, TransportError } from '../../core/errors/index.js';
|
|
2
|
+
import { runSteps } from '../../core/runner/index.js';
|
|
3
|
+
import { firstAttemptMs, networkRetryStep } from '../../core/runner/networkRetry.js';
|
|
4
|
+
import { NOOP_RECORDER } from '../../core/telemetry/index.js';
|
|
5
|
+
import { decodeText, fetchBounded, userAgentOf } from '../../core/transport/index.js';
|
|
6
|
+
import { INSTAPACK_MAX_BYTES, INSTAPACK_TRACKING, instapackResultPath, isInstapackBlocked, normalizeInstapackNumber, parseInstapack, parseInstapackRefusal, PROVIDER, } from './parser.js';
|
|
7
|
+
export { INSTAPACK_TRACKING, normalizeInstapackNumber, parseInstapack } from './parser.js';
|
|
8
|
+
const ORIGIN = 'https://back.instapack.es';
|
|
9
|
+
const REDIRECTS = [301, 302, 303, 307, 308];
|
|
10
|
+
const GONE = [404, 405, 410];
|
|
11
|
+
const DEFAULT_BUDGET_MS = 20_000;
|
|
12
|
+
export class InstapackTracker {
|
|
13
|
+
options;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
async request(url, init, signal, timeoutMs) {
|
|
18
|
+
const { response, bytes } = await fetchBounded(url, { ...init, signal, headers: {
|
|
19
|
+
...init.headers, Accept: 'text/html', 'User-Agent': userAgentOf(this.options.userAgent),
|
|
20
|
+
} }, { provider: PROVIDER, timeoutMs: Math.max(1, Math.floor(timeoutMs)), maxBytes: INSTAPACK_MAX_BYTES, redirect: 'manual',
|
|
21
|
+
fetcher: this.options.fetcher, allowHttpStatuses: [...REDIRECTS, ...GONE, 403, 429, 503] });
|
|
22
|
+
const { status } = response;
|
|
23
|
+
const html = decodeText(bytes);
|
|
24
|
+
if (status === 429)
|
|
25
|
+
throw new RateLimitedError(PROVIDER);
|
|
26
|
+
if (status === 403 || (status === 503 && isInstapackBlocked(html)))
|
|
27
|
+
throw new ChallengeError(PROVIDER, 'Instapack refused the lookup', { status });
|
|
28
|
+
if (status === 503)
|
|
29
|
+
throw new MaintenanceError(PROVIDER, undefined, { status });
|
|
30
|
+
if (GONE.includes(status))
|
|
31
|
+
throw new TransportError(PROVIDER, 'Instapack tracking is unavailable', { status });
|
|
32
|
+
return { response, html };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The form posted with the code. A known code is redirected to the parcel's signed page, read
|
|
36
|
+
* next; an unknown one gets the form again with a message.
|
|
37
|
+
*/
|
|
38
|
+
async read(number, signal, timeoutMs) {
|
|
39
|
+
const deadline = performance.now() + timeoutMs;
|
|
40
|
+
const left = () => Math.max(1, deadline - performance.now());
|
|
41
|
+
const posted = await this.request(INSTAPACK_TRACKING, { method: 'POST', headers: {
|
|
42
|
+
'Content-Type': 'application/x-www-form-urlencoded', Origin: ORIGIN, Referer: INSTAPACK_TRACKING,
|
|
43
|
+
}, body: new URLSearchParams({ code: number }).toString() }, signal, left());
|
|
44
|
+
if (posted.response.status === 200)
|
|
45
|
+
parseInstapackRefusal(posted.html);
|
|
46
|
+
const path = REDIRECTS.includes(posted.response.status) ? instapackResultPath(posted.response.headers.get('location')) : undefined;
|
|
47
|
+
if (!path)
|
|
48
|
+
throw new SchemaError(PROVIDER, 'Instapack sent the lookup somewhere other than a parcel’s page', { status: posted.response.status });
|
|
49
|
+
const page = await this.request(`${ORIGIN}${path}`, { method: 'GET', headers: { Referer: INSTAPACK_TRACKING } }, signal, left());
|
|
50
|
+
if (page.response.status !== 200)
|
|
51
|
+
throw new SchemaError(PROVIDER, 'Instapack redirected the parcel’s page', { status: page.response.status });
|
|
52
|
+
return parseInstapack(page.html, number);
|
|
53
|
+
}
|
|
54
|
+
async fetch(raw, context = {}) {
|
|
55
|
+
const number = normalizeInstapackNumber(raw);
|
|
56
|
+
// A lookup that fails to reach Instapack, or hangs, starts again once: the first try gets
|
|
57
|
+
// half of the budget. An HTTP status or a page is never sent again.
|
|
58
|
+
return runSteps({ carrier: PROVIDER, budgetMs: context.budgetMs ?? DEFAULT_BUDGET_MS, signal: context.signal,
|
|
59
|
+
recorder: this.options.recorder ?? NOOP_RECORDER }, [
|
|
60
|
+
{ id: 'direct', run: ({ signal, remainingMs }) => this.read(number, signal, firstAttemptMs(remainingMs)) },
|
|
61
|
+
networkRetryStep(({ signal, remainingMs }) => this.read(number, signal, remainingMs)),
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// No recognition: Instapack tracks the codes its senders give, marketplace numbers among them, and
|
|
66
|
+
// no detection rule offers it, so preflight never asks it.
|
|
67
|
+
export const adapter = (environment) => {
|
|
68
|
+
const tracker = new InstapackTracker({ fetcher: environment.fetcher, recorder: environment.recorder, userAgent: environment.userAgent });
|
|
69
|
+
return {
|
|
70
|
+
id: PROVIDER, recordsSteps: true, steps: ['direct', 'retry'],
|
|
71
|
+
track: (input, context) => tracker.fetch(input.number, context),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -18,17 +18,52 @@
|
|
|
18
18
|
"timezone": "Europe/Madrid",
|
|
19
19
|
"tracking": {
|
|
20
20
|
"mode": "automatic",
|
|
21
|
-
"adapter": "
|
|
22
|
-
"steps": [
|
|
21
|
+
"adapter": "instapack",
|
|
22
|
+
"steps": [
|
|
23
|
+
"direct",
|
|
24
|
+
"retry"
|
|
25
|
+
],
|
|
26
|
+
"localClocks": true
|
|
23
27
|
},
|
|
24
|
-
"capabilities": [
|
|
28
|
+
"capabilities": [
|
|
29
|
+
"history"
|
|
30
|
+
],
|
|
25
31
|
"portal": {
|
|
26
32
|
"searchUrl": "https://back.instapack.es/client-dashboard/seguimiento-de-envios/",
|
|
27
33
|
"canaryUrl": "https://www.instapack.es/",
|
|
28
|
-
"shows": [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
"shows": [
|
|
35
|
+
"status",
|
|
36
|
+
"history",
|
|
37
|
+
"scan_times",
|
|
38
|
+
"recipient_address",
|
|
39
|
+
"driver_name",
|
|
40
|
+
"contact_details",
|
|
41
|
+
"parcel_count",
|
|
42
|
+
"customer_reference",
|
|
43
|
+
"coordinates"
|
|
44
|
+
],
|
|
45
|
+
"scraped": [
|
|
46
|
+
"status",
|
|
47
|
+
"history",
|
|
48
|
+
"scan_times"
|
|
49
|
+
],
|
|
50
|
+
"discarded": [
|
|
51
|
+
"recipient_address",
|
|
52
|
+
"driver_name",
|
|
53
|
+
"contact_details",
|
|
54
|
+
"parcel_count",
|
|
55
|
+
"customer_reference",
|
|
56
|
+
"coordinates"
|
|
57
|
+
],
|
|
58
|
+
"unavailable": [
|
|
59
|
+
"location",
|
|
60
|
+
"eta",
|
|
61
|
+
"offset_timestamps",
|
|
62
|
+
"sender_name",
|
|
63
|
+
"recipient_name",
|
|
64
|
+
"weight",
|
|
65
|
+
"service_name"
|
|
66
|
+
]
|
|
32
67
|
},
|
|
33
68
|
"links": [],
|
|
34
69
|
"detection": []
|
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"carrier": "instapack",
|
|
3
|
-
"
|
|
4
|
-
|
|
3
|
+
"records": [
|
|
4
|
+
{
|
|
5
|
+
"number": "CNES00102358787",
|
|
6
|
+
"role": "shipment",
|
|
7
|
+
"evidence": "public_shipment_report",
|
|
8
|
+
"source": {
|
|
9
|
+
"url": "https://es.trustpilot.com/reviews/62421cd6f144199fc9ccd94b",
|
|
10
|
+
"date": "2022-03-28",
|
|
11
|
+
"dateKind": "publication",
|
|
12
|
+
"access": "full_page"
|
|
13
|
+
},
|
|
14
|
+
"context": {
|
|
15
|
+
"assessment": "confirmed"
|
|
16
|
+
},
|
|
17
|
+
"expect": {
|
|
18
|
+
"carrier": "unknown",
|
|
19
|
+
"confidence": "none"
|
|
20
|
+
},
|
|
21
|
+
"note": "Review on Instapack's Trustpilot page denying the recipient was out, with this AliExpress economy number. Instapack's tracker answers it with a delivery round, two incidents for an absent recipient and the delivery."
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"number": "090420181030503",
|
|
25
|
+
"role": "shipment",
|
|
26
|
+
"evidence": "public_shipment_report",
|
|
27
|
+
"source": {
|
|
28
|
+
"url": "https://web.archive.org/web/20230316041846/http://instapack.es/check-order/090420181030503",
|
|
29
|
+
"date": "2023-03-16",
|
|
30
|
+
"dateKind": "capture",
|
|
31
|
+
"access": "full_page"
|
|
32
|
+
},
|
|
33
|
+
"context": {
|
|
34
|
+
"assessment": "confirmed"
|
|
35
|
+
},
|
|
36
|
+
"expect": {
|
|
37
|
+
"carrier": "unknown",
|
|
38
|
+
"confidence": "low",
|
|
39
|
+
"candidates": [
|
|
40
|
+
"dpd-fr",
|
|
41
|
+
"brt",
|
|
42
|
+
"yunda",
|
|
43
|
+
"ozon-logistics"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"note": "Archived link to Instapack's former order page with one of its own order ids, the order's day and a counter. Instapack's tracker answers it with a delivery in Madrid."
|
|
47
|
+
}
|
|
48
|
+
]
|
|
5
49
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CarrierResult } from '../../core/result/index.js';
|
|
2
|
+
export declare const PROVIDER = "instapack";
|
|
3
|
+
/** The tracking page instapack.es links to; its form posts `code` back to the same address. */
|
|
4
|
+
export declare const INSTAPACK_TRACKING = "https://back.instapack.es/client-dashboard/seguimiento-de-envios/";
|
|
5
|
+
export declare const INSTAPACK_MAX_BYTES: number;
|
|
6
|
+
/** A code for Instapack's tracker: letters and digits with at least one digit, in capitals. */
|
|
7
|
+
export declare function normalizeInstapackNumber(raw: string): string;
|
|
8
|
+
/** Whether a reply is a block page instead of the tracker's. */
|
|
9
|
+
export declare function isInstapackBlocked(html: string): boolean;
|
|
10
|
+
/** The path of the parcel's page the form's redirect names, or nothing when it names another. */
|
|
11
|
+
export declare function instapackResultPath(location: string | null): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The tracking form again, HTTP 200, for a code without a redirect: its message saying there is
|
|
14
|
+
* no such parcel is not found. Any other message, or none, is not.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseInstapackRefusal(html: string): never;
|
|
17
|
+
/**
|
|
18
|
+
* The parcel's page, which the form redirects to for a code the tracker knows. A heading panel
|
|
19
|
+
* names the code; then a panel lists the driver's steps, `dd/mm/yy HH:MM - <step>`, under a title
|
|
20
|
+
* naming the driver and their phone; a panel lists the delivery incidents, `dd/mm/yyyy HH:MM-
|
|
21
|
+
* <type> - <reason>`; and a delivered parcel's last panel is titled with the delivery's time and
|
|
22
|
+
* wording over the delivery address. Times are wall clocks without a zone.
|
|
23
|
+
*
|
|
24
|
+
* The delivery address, the driver's name and phone, the parcel count, the sender's references
|
|
25
|
+
* and the map's coordinates are never read.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseInstapack(html: string, raw: string): CarrierResult;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
|
+
import { isText } from 'domhandler';
|
|
3
|
+
import { normalizeTrackingNumber } from '../../core/detection/index.js';
|
|
4
|
+
import { ChallengeError, IndeterminateError, InvalidInputError, NoHistoryError, NotFoundError, SchemaError } from '../../core/errors/index.js';
|
|
5
|
+
import { leadingScan } from '../../core/result/unstaged.js';
|
|
6
|
+
import { languageStageStatus } from '../../core/status/index.js';
|
|
7
|
+
import { calendarDay } from '../../core/time/index.js';
|
|
8
|
+
import { clean } from '../../core/transport/index.js';
|
|
9
|
+
import { instapackStage, statusMap } from './status.js';
|
|
10
|
+
export const PROVIDER = 'instapack';
|
|
11
|
+
/** The tracking page instapack.es links to; its form posts `code` back to the same address. */
|
|
12
|
+
export const INSTAPACK_TRACKING = 'https://back.instapack.es/client-dashboard/seguimiento-de-envios/';
|
|
13
|
+
// A delivered parcel's page is about 20 kB, most of it the map's script.
|
|
14
|
+
export const INSTAPACK_MAX_BYTES = 512 * 1024;
|
|
15
|
+
// The tracker finds a parcel by the code the sender gave it, in any case: Instapack's own order
|
|
16
|
+
// ids and marketplace numbers. Every code seen has a digit.
|
|
17
|
+
const NUMBER = /^(?=[A-Z]*\d)[A-Z0-9]{6,40}$/;
|
|
18
|
+
// The parcel's page the form redirects to: a signed token naming the code, valid for a week.
|
|
19
|
+
const RESULT = /^(?:https:\/\/back\.instapack\.es)?(\/client-dashboard\/seguimiento-de-envios\/[\w-]{10,600}\.[\w-]{10,1200}\.[\w-]{10,200})$/;
|
|
20
|
+
// A firewall's, CDN's or bot check's page.
|
|
21
|
+
const BLOCKED = /<title>\s*(?:Just a moment|Attention Required|Access Denied|Request Rejected|403 Forbidden)|_cf_chl_opt|cf-turnstile|challenge-platform|g-recaptcha|h-captcha|captcha/i;
|
|
22
|
+
// The form's message for a code the tracker has no parcel under. It does not repeat the code.
|
|
23
|
+
const NOT_FOUND = /^No se localiza ningún paquete\.?$/i;
|
|
24
|
+
// The heading's label; the code follows it.
|
|
25
|
+
const LABEL = /^N[º°o]\.? de seguimiento:?$/i;
|
|
26
|
+
const CODE = /^[A-Za-z0-9-]{1,64}$/;
|
|
27
|
+
// "25/03/22 08:56 - Salida a reparto", a scan row, or "25/03/2022 10:58- Incidencias en entrega - Ausente", an incident's.
|
|
28
|
+
const ROW = /^(\d{2}\/\d{2}\/(?:\d{2}|\d{4}) \d{2}:\d{2})\s*-\s*(\S.{0,199})$/;
|
|
29
|
+
const STAMP = /^(\d{2})\/(\d{2})\/(\d{2}|\d{4}) ([01]\d|2[0-3]):([0-5]\d)$/;
|
|
30
|
+
// A phone number or an email address, which a row must not pass on.
|
|
31
|
+
const PERSONAL = /\+?\d[\d .-]{6,}\d|\S+@\S+\.\S+/g;
|
|
32
|
+
const MAX_SCANS = 200;
|
|
33
|
+
// Later steps first among scans of one minute: the driver is assigned, then leaves on the round.
|
|
34
|
+
const ORDER = { registered: 1, accepted: 2, in_transit: 3, out_for_delivery: 4, failed_attempt: 5, delivered: 6 };
|
|
35
|
+
/** A code for Instapack's tracker: letters and digits with at least one digit, in capitals. */
|
|
36
|
+
export function normalizeInstapackNumber(raw) {
|
|
37
|
+
const number = typeof raw === 'string' && raw.length <= 64 ? normalizeTrackingNumber(raw).toUpperCase() : '';
|
|
38
|
+
if (!NUMBER.test(number))
|
|
39
|
+
throw new InvalidInputError(PROVIDER, 'Instapack tracks codes of 6 to 40 letters and digits');
|
|
40
|
+
return number;
|
|
41
|
+
}
|
|
42
|
+
/** Whether a reply is a block page instead of the tracker's. */
|
|
43
|
+
export function isInstapackBlocked(html) {
|
|
44
|
+
return BLOCKED.test(html.slice(0, 64_000));
|
|
45
|
+
}
|
|
46
|
+
/** The path of the parcel's page the form's redirect names, or nothing when it names another. */
|
|
47
|
+
export function instapackResultPath(location) {
|
|
48
|
+
return location ? RESULT.exec(location.trim())?.[1] : undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The tracking form again, HTTP 200, for a code without a redirect: its message saying there is
|
|
52
|
+
* no such parcel is not found. Any other message, or none, is not.
|
|
53
|
+
*/
|
|
54
|
+
export function parseInstapackRefusal(html) {
|
|
55
|
+
const $ = load(html);
|
|
56
|
+
const message = clean($('#id_alert_body').first().text(), 200);
|
|
57
|
+
if (NOT_FOUND.test(message))
|
|
58
|
+
throw new NotFoundError(PROVIDER, 'Instapack has no parcel under this code');
|
|
59
|
+
if (isInstapackBlocked(html))
|
|
60
|
+
throw new ChallengeError(PROVIDER, 'Instapack answered with a browser check');
|
|
61
|
+
if (message)
|
|
62
|
+
throw new IndeterminateError(PROVIDER, 'Instapack refused the lookup');
|
|
63
|
+
if ($('form input[name="code"]').length)
|
|
64
|
+
throw new SchemaError(PROVIDER, 'Instapack returned its form without an answer');
|
|
65
|
+
throw new SchemaError(PROVIDER, 'Instapack returned an unexpected page');
|
|
66
|
+
}
|
|
67
|
+
/** A row's wall clock, calendar-checked; a two-digit year is this century's. */
|
|
68
|
+
function wallClock(stamp) {
|
|
69
|
+
const parts = STAMP.exec(stamp);
|
|
70
|
+
const year = parts ? Number(parts[3].length === 2 ? `20${parts[3]}` : parts[3]) : 0;
|
|
71
|
+
const day = parts && calendarDay(year, Number(parts[2]), Number(parts[1]));
|
|
72
|
+
if (!parts || !day)
|
|
73
|
+
throw new SchemaError(PROVIDER, 'Instapack returned an invalid scan time');
|
|
74
|
+
return `${day}T${parts[4]}:${parts[5]}:00`;
|
|
75
|
+
}
|
|
76
|
+
function event(stamp, wording) {
|
|
77
|
+
const description = clean(wording.replace(PERSONAL, ' '), 200).replace(/[\s-]+$/, '');
|
|
78
|
+
if (!description)
|
|
79
|
+
throw new SchemaError(PROVIDER, 'Instapack returned a scan without its wording');
|
|
80
|
+
const staged = instapackStage(description);
|
|
81
|
+
return { local_time: wallClock(stamp), description, ...(staged ? { stage: staged.stage, stage_source: staged.source } : {}) };
|
|
82
|
+
}
|
|
83
|
+
/** A panel body's lines, as the page breaks them, each with its spaces collapsed. */
|
|
84
|
+
function lines(body) {
|
|
85
|
+
return (body.html() ?? '').split(/<br\s*\/?>/i).map((part) => clean(load(part).text(), 400)).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
/** The code a panel's heading names after its label, or nothing when the panel is not the heading's. */
|
|
88
|
+
function headingCode($, panel) {
|
|
89
|
+
const label = panel.find('.panel-title strong').toArray().find((node) => LABEL.test(clean($(node).text(), 60)));
|
|
90
|
+
if (!label)
|
|
91
|
+
return undefined;
|
|
92
|
+
const next = label.nextSibling;
|
|
93
|
+
const code = next && isText(next) ? clean(next.data, 80) : '';
|
|
94
|
+
if (!CODE.test(code))
|
|
95
|
+
throw new SchemaError(PROVIDER, 'Instapack returned a parcel without its code');
|
|
96
|
+
return code;
|
|
97
|
+
}
|
|
98
|
+
/** Newest first; scans of one minute keep the later step first, else the page's order. */
|
|
99
|
+
function newestFirst(events) {
|
|
100
|
+
const rank = (scan) => ORDER[scan.stage] ?? 0;
|
|
101
|
+
return events.map((scan, index) => ({ scan, index }))
|
|
102
|
+
.sort((a, b) => b.scan.local_time.localeCompare(a.scan.local_time) || rank(b.scan) - rank(a.scan) || a.index - b.index)
|
|
103
|
+
.map(({ scan }) => scan);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The parcel's page, which the form redirects to for a code the tracker knows. A heading panel
|
|
107
|
+
* names the code; then a panel lists the driver's steps, `dd/mm/yy HH:MM - <step>`, under a title
|
|
108
|
+
* naming the driver and their phone; a panel lists the delivery incidents, `dd/mm/yyyy HH:MM-
|
|
109
|
+
* <type> - <reason>`; and a delivered parcel's last panel is titled with the delivery's time and
|
|
110
|
+
* wording over the delivery address. Times are wall clocks without a zone.
|
|
111
|
+
*
|
|
112
|
+
* The delivery address, the driver's name and phone, the parcel count, the sender's references
|
|
113
|
+
* and the map's coordinates are never read.
|
|
114
|
+
*/
|
|
115
|
+
export function parseInstapack(html, raw) {
|
|
116
|
+
const number = normalizeInstapackNumber(raw);
|
|
117
|
+
const $ = load(html);
|
|
118
|
+
const panels = $('article.panel').toArray().map((node) => $(node));
|
|
119
|
+
const headings = panels.map((panel) => headingCode($, panel));
|
|
120
|
+
const heading = headings.find(Boolean);
|
|
121
|
+
if (!heading) {
|
|
122
|
+
if (isInstapackBlocked(html))
|
|
123
|
+
throw new ChallengeError(PROVIDER, 'Instapack answered with a browser check');
|
|
124
|
+
throw new SchemaError(PROVIDER, 'Instapack returned an unexpected page');
|
|
125
|
+
}
|
|
126
|
+
// The page must name the code asked.
|
|
127
|
+
if (normalizeTrackingNumber(heading).toUpperCase() !== number)
|
|
128
|
+
throw new SchemaError(PROVIDER, 'Instapack answered for a different parcel');
|
|
129
|
+
const events = [];
|
|
130
|
+
for (const [index, panel] of panels.entries()) {
|
|
131
|
+
// The heading's body is the delivery address, the parcel count and the sender's references.
|
|
132
|
+
if (headings[index])
|
|
133
|
+
continue;
|
|
134
|
+
const title = panel.find('.panel-title').first();
|
|
135
|
+
const stamp = clean(title.find('span').first().text(), 40);
|
|
136
|
+
if (STAMP.test(stamp)) {
|
|
137
|
+
// A dated title, the delivery's: its body is the delivery address.
|
|
138
|
+
events.push(event(stamp, title.find('strong').first().text()));
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// The title names the driver or counts the incidents; only the body's dated rows are read.
|
|
142
|
+
for (const line of lines(panel.find('.panel-body').first())) {
|
|
143
|
+
const row = ROW.exec(line);
|
|
144
|
+
if (row)
|
|
145
|
+
events.push(event(row[1], row[2]));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (events.length > MAX_SCANS)
|
|
149
|
+
throw new SchemaError(PROVIDER, 'Instapack returned too many scans');
|
|
150
|
+
const ordered = newestFirst(events);
|
|
151
|
+
const newest = ordered[0];
|
|
152
|
+
if (!newest)
|
|
153
|
+
throw new NoHistoryError(PROVIDER, 'Instapack lists the parcel without scans', { reason: 'listed' });
|
|
154
|
+
const lead = leadingScan(ordered, statusMap);
|
|
155
|
+
const stage = lead?.stage;
|
|
156
|
+
return {
|
|
157
|
+
status: stage ? languageStageStatus(stage) : 'unknown',
|
|
158
|
+
...(stage ? { current_stage: stage, current_stage_source: lead?.stage_source ?? 'carrier_map' } : {}),
|
|
159
|
+
last_status_text: newest.description,
|
|
160
|
+
last_update: null,
|
|
161
|
+
last_update_local: newest.local_time,
|
|
162
|
+
expected_delivery: null,
|
|
163
|
+
events: ordered,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ClassifiedWording } from '../../core/status/index.js';
|
|
2
|
+
import { type CarrierStatusMap } from '../../core/status/statusMap.js';
|
|
3
|
+
/** A scan's stage by its whole wording, else the shared rules on it, else nothing, which keeps it visible for review. */
|
|
4
|
+
export declare function instapackStage(wording: string): ClassifiedWording | null;
|
|
5
|
+
/** Scans are staged by their whole Spanish wording. */
|
|
6
|
+
export declare const statusMap: CarrierStatusMap;
|