universal-parcel-scraper 0.1283.0-main.8564 → 0.1285.2-main.8580
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 +3 -3
- package/data/carrier.schema.json +4 -0
- package/data/catalog.json +169 -3
- package/data/coverage-summary.json +2 -2
- package/data/detection-golden.json +547 -0
- package/dist/browser/scraper.js +1599 -1438
- package/dist/carriers/benniao-express/adapter.d.ts +21 -0
- package/dist/carriers/benniao-express/adapter.js +52 -0
- package/dist/carriers/benniao-express/carrier.json +79 -0
- package/dist/carriers/benniao-express/numbers.json +119 -0
- package/dist/carriers/benniao-express/parser.d.ts +15 -0
- package/dist/carriers/benniao-express/parser.js +109 -0
- package/dist/carriers/benniao-express/status.d.ts +4 -0
- package/dist/carriers/benniao-express/status.js +9 -0
- package/dist/carriers/benniao-express/statuses.json +61 -0
- package/dist/carriers/correos-spain/status.js +4 -2
- package/dist/carriers/correos-spain/statuses.json +1 -0
- package/dist/carriers/disu-logistics/adapter.d.ts +14 -0
- package/dist/carriers/disu-logistics/adapter.js +43 -0
- package/dist/carriers/disu-logistics/carrier.json +76 -0
- package/dist/carriers/disu-logistics/numbers.json +208 -0
- package/dist/carriers/disu-logistics/parser.d.ts +14 -0
- package/dist/carriers/disu-logistics/parser.js +109 -0
- package/dist/carriers/disu-logistics/status.d.ts +4 -0
- package/dist/carriers/disu-logistics/status.js +9 -0
- package/dist/carriers/disu-logistics/statuses.json +77 -0
- package/dist/carriers/dpd-fr/status.js +2 -0
- package/dist/carriers/dpd-fr/statuses.json +8 -0
- package/dist/carriers/ecoscooting/carrier.json +2 -1
- package/dist/carriers/feibao-logistics/adapter.d.ts +14 -0
- package/dist/carriers/feibao-logistics/adapter.js +43 -0
- package/dist/carriers/feibao-logistics/carrier.json +74 -0
- package/dist/carriers/feibao-logistics/numbers.json +173 -0
- package/dist/carriers/feibao-logistics/parser.d.ts +15 -0
- package/dist/carriers/feibao-logistics/parser.js +118 -0
- package/dist/carriers/feibao-logistics/status.d.ts +4 -0
- package/dist/carriers/feibao-logistics/status.js +9 -0
- package/dist/carriers/feibao-logistics/statuses.json +45 -0
- package/dist/carriers/huaqi-express/adapter.d.ts +14 -0
- package/dist/carriers/huaqi-express/adapter.js +41 -0
- package/dist/carriers/huaqi-express/carrier.json +72 -0
- package/dist/carriers/huaqi-express/numbers.json +39 -0
- package/dist/carriers/huaqi-express/parser.d.ts +14 -0
- package/dist/carriers/huaqi-express/parser.js +106 -0
- package/dist/carriers/huaqi-express/status.d.ts +4 -0
- package/dist/carriers/huaqi-express/status.js +9 -0
- package/dist/carriers/huaqi-express/statuses.json +77 -0
- package/dist/carriers/lindao-express/adapter.d.ts +14 -0
- package/dist/carriers/lindao-express/adapter.js +42 -0
- package/dist/carriers/lindao-express/carrier.json +68 -0
- package/dist/carriers/lindao-express/numbers.json +120 -0
- package/dist/carriers/lindao-express/parser.d.ts +13 -0
- package/dist/carriers/lindao-express/parser.js +80 -0
- package/dist/carriers/lindao-express/status.d.ts +4 -0
- package/dist/carriers/lindao-express/status.js +9 -0
- package/dist/carriers/lindao-express/statuses.json +101 -0
- package/dist/carriers/ontrac/carrier.json +1 -1
- package/dist/carriers/ontrac/numbers.json +15 -0
- package/dist/carriers/paack/carrier.json +2 -1
- package/dist/carriers/riyu-logistics/adapter.d.ts +14 -0
- package/dist/carriers/riyu-logistics/adapter.js +42 -0
- package/dist/carriers/riyu-logistics/carrier.json +70 -0
- package/dist/carriers/riyu-logistics/numbers.json +71 -0
- package/dist/carriers/riyu-logistics/parser.d.ts +19 -0
- package/dist/carriers/riyu-logistics/parser.js +90 -0
- package/dist/carriers/riyu-logistics/status.d.ts +4 -0
- package/dist/carriers/riyu-logistics/status.js +9 -0
- package/dist/carriers/riyu-logistics/statuses.json +69 -0
- package/dist/carriers/wanjia-logistics/adapter.d.ts +14 -0
- package/dist/carriers/wanjia-logistics/adapter.js +41 -0
- package/dist/carriers/wanjia-logistics/carrier.json +77 -0
- package/dist/carriers/wanjia-logistics/numbers.json +114 -0
- package/dist/carriers/wanjia-logistics/parser.d.ts +15 -0
- package/dist/carriers/wanjia-logistics/parser.js +145 -0
- package/dist/carriers/wanjia-logistics/status.d.ts +4 -0
- package/dist/carriers/wanjia-logistics/status.js +9 -0
- package/dist/carriers/wanjia-logistics/statuses.json +77 -0
- package/dist/core/catalog/recognition.js +9 -0
- package/dist/core/catalog/statusMaps.js +14 -7
- package/dist/core/catalog/types.d.ts +5 -0
- package/dist/core/detection/index.d.ts +1 -0
- package/dist/core/detection/index.js +1 -0
- package/dist/data/catalog.json +169 -3
- package/dist/generated/catalog.d.ts +1 -1
- package/dist/generated/catalog.js +183 -3
- package/dist/generated/registry.js +21 -0
- package/dist/server/openapi.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
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 { parseBenniao } from './parser.js';
|
|
5
|
+
/**
|
|
6
|
+
* The page's signature, from https://www.benniaosuyun.com/static/js/api.js: the MD5 of the JSON
|
|
7
|
+
* body followed by `×tamp=` and the millisecond clock. The key the script passes to CryptoJS.MD5
|
|
8
|
+
* is taken as options, not mixed in.
|
|
9
|
+
*/
|
|
10
|
+
export declare function benniaoSignature(body: string, timestamp: number): string;
|
|
11
|
+
export declare class BenniaoTracker {
|
|
12
|
+
private readonly options;
|
|
13
|
+
constructor(options?: {
|
|
14
|
+
fetcher?: typeof fetch;
|
|
15
|
+
recorder?: StepRecorder;
|
|
16
|
+
userAgent?: string;
|
|
17
|
+
now?: () => number;
|
|
18
|
+
});
|
|
19
|
+
fetch(raw: string, context?: TrackingContext): Promise<CarrierResult>;
|
|
20
|
+
}
|
|
21
|
+
export declare const adapter: AdapterFactory;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ChallengeError, 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 { BENNIAO_ENDPOINT, BENNIAO_ORIGIN, BENNIAO_PAGE, benniaoJson, normalizeBenniaoNumber, parseBenniao, PROVIDER } from './parser.js';
|
|
8
|
+
export { parseBenniao } from './parser.js';
|
|
9
|
+
const REDIRECTS = [301, 302, 303, 307, 308];
|
|
10
|
+
/**
|
|
11
|
+
* The page's signature, from https://www.benniaosuyun.com/static/js/api.js: the MD5 of the JSON
|
|
12
|
+
* body followed by `×tamp=` and the millisecond clock. The key the script passes to CryptoJS.MD5
|
|
13
|
+
* is taken as options, not mixed in.
|
|
14
|
+
*/
|
|
15
|
+
export function benniaoSignature(body, timestamp) {
|
|
16
|
+
return createHash('md5').update(`${body}×tamp=${timestamp}`).digest('hex');
|
|
17
|
+
}
|
|
18
|
+
export class BenniaoTracker {
|
|
19
|
+
options;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
fetch(raw, context = {}) {
|
|
24
|
+
context.signal?.throwIfAborted();
|
|
25
|
+
const number = normalizeBenniaoNumber(raw);
|
|
26
|
+
const read = async (signal, timeoutMs) => {
|
|
27
|
+
// The search page's request: the waybill as JSON, signed as its script does, with no session, captcha or account.
|
|
28
|
+
const body = JSON.stringify({ nums: [number] }), timestamp = (this.options.now ?? Date.now)();
|
|
29
|
+
const { response, bytes } = await fetchBounded(BENNIAO_ENDPOINT, { method: 'POST', signal, body, headers: {
|
|
30
|
+
Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json', 'X-Signature': benniaoSignature(body, timestamp),
|
|
31
|
+
'X-Timestamp': String(timestamp), Origin: BENNIAO_ORIGIN, Referer: `${BENNIAO_PAGE}&keyword=${number}`, 'User-Agent': userAgentOf(this.options.userAgent),
|
|
32
|
+
} }, { provider: PROVIDER, fetcher: this.options.fetcher, maxBytes: 1_000_000, timeoutMs: Math.max(1, Math.floor(timeoutMs)),
|
|
33
|
+
redirect: 'manual', allowHttpStatuses: [...REDIRECTS, 401, 403, 404, 410] });
|
|
34
|
+
if ([401, 403].includes(response.status))
|
|
35
|
+
throw new ChallengeError(PROVIDER, 'Benniao refused its guest request');
|
|
36
|
+
// An unknown waybill is HTTP 200 too; anything else is a moved route.
|
|
37
|
+
if (response.status !== 200)
|
|
38
|
+
throw new TransportError(PROVIDER, 'Benniao tracking endpoint moved', { status: response.status });
|
|
39
|
+
return parseBenniao(benniaoJson(decodeText(bytes)), number);
|
|
40
|
+
};
|
|
41
|
+
// A request that fails to reach the server, or hangs, gets one more try in the rest of the budget.
|
|
42
|
+
return runSteps({ carrier: 'benniao-express', budgetMs: context.budgetMs ?? 15_000, signal: context.signal,
|
|
43
|
+
recorder: this.options.recorder ?? NOOP_RECORDER }, [
|
|
44
|
+
{ id: 'direct', run: ({ signal, remainingMs }) => read(signal, firstAttemptMs(remainingMs)) },
|
|
45
|
+
networkRetryStep(({ signal, remainingMs }) => read(signal, remainingMs)),
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const adapter = environment => {
|
|
50
|
+
const tracker = new BenniaoTracker({ fetcher: environment.fetcher, recorder: environment.recorder, userAgent: environment.userAgent });
|
|
51
|
+
return { id: 'benniao-express', recordsSteps: true, steps: ['direct', 'retry'], track: (input, context) => tracker.fetch(input.number, context) };
|
|
52
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "benniao-express",
|
|
3
|
+
"displayName": "Benniao Express",
|
|
4
|
+
"aliases": [
|
|
5
|
+
"笨鸟速运",
|
|
6
|
+
"笨鸟快递",
|
|
7
|
+
"Benniao Suyun"
|
|
8
|
+
],
|
|
9
|
+
"region": {
|
|
10
|
+
"countries": [
|
|
11
|
+
"CN"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"brand": {
|
|
15
|
+
"color": "#e00000"
|
|
16
|
+
},
|
|
17
|
+
"selectable": true,
|
|
18
|
+
"timezone": "Asia/Shanghai",
|
|
19
|
+
"tracking": {
|
|
20
|
+
"mode": "automatic",
|
|
21
|
+
"adapter": "benniao-express",
|
|
22
|
+
"steps": [
|
|
23
|
+
"direct",
|
|
24
|
+
"retry"
|
|
25
|
+
],
|
|
26
|
+
"localClocks": true
|
|
27
|
+
},
|
|
28
|
+
"capabilities": [
|
|
29
|
+
"history",
|
|
30
|
+
"location",
|
|
31
|
+
"provider_code"
|
|
32
|
+
],
|
|
33
|
+
"portal": {
|
|
34
|
+
"searchUrl": "https://www.benniaosuyun.com/",
|
|
35
|
+
"canaryUrl": "https://www.benniaosuyun.com/",
|
|
36
|
+
"shows": [
|
|
37
|
+
"status",
|
|
38
|
+
"history",
|
|
39
|
+
"location",
|
|
40
|
+
"office_contact_details",
|
|
41
|
+
"driver_name",
|
|
42
|
+
"driver_phone",
|
|
43
|
+
"signatory"
|
|
44
|
+
],
|
|
45
|
+
"scraped": [
|
|
46
|
+
"status",
|
|
47
|
+
"history",
|
|
48
|
+
"location",
|
|
49
|
+
"provider_code"
|
|
50
|
+
],
|
|
51
|
+
"discarded": [
|
|
52
|
+
"office_contact_details",
|
|
53
|
+
"driver_name",
|
|
54
|
+
"driver_phone",
|
|
55
|
+
"signatory"
|
|
56
|
+
],
|
|
57
|
+
"unavailable": [
|
|
58
|
+
"weight",
|
|
59
|
+
"service_name",
|
|
60
|
+
"eta",
|
|
61
|
+
"pieces",
|
|
62
|
+
"origin",
|
|
63
|
+
"destination",
|
|
64
|
+
"offset_timestamps",
|
|
65
|
+
"proof_of_delivery",
|
|
66
|
+
"sender_name",
|
|
67
|
+
"recipient_name",
|
|
68
|
+
"recipient_address"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"links": [],
|
|
72
|
+
"detection": [
|
|
73
|
+
{
|
|
74
|
+
"id": "benniao-express-1",
|
|
75
|
+
"pattern": "^BN\\d{14}$",
|
|
76
|
+
"confidence": "high"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"carrier": "benniao-express",
|
|
3
|
+
"records": [
|
|
4
|
+
{
|
|
5
|
+
"number": "BN55400024097008",
|
|
6
|
+
"role": "shipment",
|
|
7
|
+
"evidence": "public_shipment_report",
|
|
8
|
+
"source": {
|
|
9
|
+
"url": "https://www.kuaidi.com/all/benniaosuyun.html",
|
|
10
|
+
"date": "2026-11-22",
|
|
11
|
+
"dateKind": "capture",
|
|
12
|
+
"access": "full_page"
|
|
13
|
+
},
|
|
14
|
+
"context": {
|
|
15
|
+
"assessment": "confirmed"
|
|
16
|
+
},
|
|
17
|
+
"expect": {
|
|
18
|
+
"carrier": "benniao-express",
|
|
19
|
+
"confidence": "high"
|
|
20
|
+
},
|
|
21
|
+
"note": "A waybill kuaidi.com's Benniao page lists. Benniao's endpoint answers it with a parcel taken in at Yingshang, through the Fuyang and Zhengzhou hubs and signed for in Jia County."
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"number": "BN55400024239491",
|
|
25
|
+
"role": "shipment",
|
|
26
|
+
"evidence": "public_shipment_report",
|
|
27
|
+
"source": {
|
|
28
|
+
"url": "https://www.kuaidi.com/all/benniaosuyun.html",
|
|
29
|
+
"date": "2026-11-22",
|
|
30
|
+
"dateKind": "capture",
|
|
31
|
+
"access": "full_page"
|
|
32
|
+
},
|
|
33
|
+
"context": {
|
|
34
|
+
"assessment": "confirmed"
|
|
35
|
+
},
|
|
36
|
+
"expect": {
|
|
37
|
+
"carrier": "benniao-express",
|
|
38
|
+
"confidence": "high"
|
|
39
|
+
},
|
|
40
|
+
"note": "A waybill kuaidi.com's Benniao page lists. Benniao's endpoint answers it with a parcel taken in at Yingshang, stopped on the way and signed for in Hangzhou."
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"number": "BN55400024000525",
|
|
44
|
+
"role": "shipment",
|
|
45
|
+
"evidence": "public_shipment_report",
|
|
46
|
+
"source": {
|
|
47
|
+
"url": "https://www.kuaidi.com/all/benniaosuyun.html",
|
|
48
|
+
"date": "2026-11-22",
|
|
49
|
+
"dateKind": "capture",
|
|
50
|
+
"access": "full_page"
|
|
51
|
+
},
|
|
52
|
+
"context": {
|
|
53
|
+
"assessment": "confirmed"
|
|
54
|
+
},
|
|
55
|
+
"expect": {
|
|
56
|
+
"carrier": "benniao-express",
|
|
57
|
+
"confidence": "high"
|
|
58
|
+
},
|
|
59
|
+
"note": "A waybill kuaidi.com's Benniao page lists. Benniao's endpoint answers it with a parcel taken in at Ningjin, sent through Shijiazhuang and Zhengzhou to Chongqing, stopped and signed for in Hangzhou."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"number": "BN55400024405207",
|
|
63
|
+
"role": "shipment",
|
|
64
|
+
"evidence": "public_shipment_report",
|
|
65
|
+
"source": {
|
|
66
|
+
"url": "https://www.kuaidi.com/all/benniaosuyun.html",
|
|
67
|
+
"date": "2026-11-22",
|
|
68
|
+
"dateKind": "capture",
|
|
69
|
+
"access": "full_page"
|
|
70
|
+
},
|
|
71
|
+
"context": {
|
|
72
|
+
"assessment": "confirmed"
|
|
73
|
+
},
|
|
74
|
+
"expect": {
|
|
75
|
+
"carrier": "benniao-express",
|
|
76
|
+
"confidence": "high"
|
|
77
|
+
},
|
|
78
|
+
"note": "A waybill kuaidi.com's Benniao page lists. Benniao's endpoint answers it with a parcel taken in at Anxi, stopped at the Zhengzhou hub and brought back to Quanzhou."
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"number": "BN55100094737324",
|
|
82
|
+
"role": "shipment",
|
|
83
|
+
"evidence": "public_shipment_report",
|
|
84
|
+
"source": {
|
|
85
|
+
"url": "https://www.kuaidi.com/all/benniaosuyun.html",
|
|
86
|
+
"date": "2026-11-22",
|
|
87
|
+
"dateKind": "capture",
|
|
88
|
+
"access": "full_page"
|
|
89
|
+
},
|
|
90
|
+
"context": {
|
|
91
|
+
"assessment": "confirmed"
|
|
92
|
+
},
|
|
93
|
+
"expect": {
|
|
94
|
+
"carrier": "benniao-express",
|
|
95
|
+
"confidence": "high"
|
|
96
|
+
},
|
|
97
|
+
"note": "A waybill kuaidi.com's Benniao page lists. Benniao's endpoint answers it with a parcel taken in at Dongguan, out for delivery in Xi'an, stopped and brought back to Dongguan, where it was signed for."
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"number": "BN55400024779801",
|
|
101
|
+
"role": "shipment",
|
|
102
|
+
"evidence": "public_shipment_report",
|
|
103
|
+
"source": {
|
|
104
|
+
"url": "https://www.kuaidi.com/all/benniaosuyun.html",
|
|
105
|
+
"date": "2026-11-22",
|
|
106
|
+
"dateKind": "capture",
|
|
107
|
+
"access": "full_page"
|
|
108
|
+
},
|
|
109
|
+
"context": {
|
|
110
|
+
"assessment": "confirmed"
|
|
111
|
+
},
|
|
112
|
+
"expect": {
|
|
113
|
+
"carrier": "benniao-express",
|
|
114
|
+
"confidence": "high"
|
|
115
|
+
},
|
|
116
|
+
"note": "A waybill kuaidi.com's Benniao page lists. Benniao's endpoint answers it with a parcel taken in at Zhongshan, held at the Guangzhou hub for a late trunk truck and signed for in Shantou."
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CarrierResult } from '../../core/result/index.js';
|
|
2
|
+
export declare const PROVIDER = "Benniao Express";
|
|
3
|
+
export declare const BENNIAO_ORIGIN = "https://www.benniaosuyun.com";
|
|
4
|
+
/** The page the site's waybill search opens, whose script asks the endpoint below. */
|
|
5
|
+
export declare const BENNIAO_PAGE = "https://www.benniaosuyun.com/?search/";
|
|
6
|
+
export declare const BENNIAO_ENDPOINT = "https://bnsy.benniaosuyun.com/api/officialWebSitePortal/findWaybillTrack";
|
|
7
|
+
/** BN and fourteen digits, as Benniao's labels and the waybills kuaidi.com lists are; the endpoint answers without the BN. */
|
|
8
|
+
export declare function normalizeBenniaoNumber(raw: string): string;
|
|
9
|
+
/** The endpoint's JSON, or the failure a page in its place stands for. */
|
|
10
|
+
export declare function benniaoJson(text: string): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* The scans the endpoint gives for one waybill, oldest first, each with its China wall clock,
|
|
13
|
+
* its city and its wording. The reply must name the whole waybill asked, without its BN.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseBenniao(body: unknown, raw: string): CarrierResult;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { normalizeTrackingNumber } from '../../core/detection/index.js';
|
|
2
|
+
import { ChallengeError, IndeterminateError, InvalidInputError, NotFoundError, RateLimitedError, SchemaError } from '../../core/errors/index.js';
|
|
3
|
+
import { languageStageStatus } from '../../core/status/index.js';
|
|
4
|
+
import { calendarDay } from '../../core/time/index.js';
|
|
5
|
+
import { textFromHtml } from '../../core/transport/text.js';
|
|
6
|
+
import { benniaoStage } from './status.js';
|
|
7
|
+
export const PROVIDER = 'Benniao Express';
|
|
8
|
+
export const BENNIAO_ORIGIN = 'https://www.benniaosuyun.com';
|
|
9
|
+
/** The page the site's waybill search opens, whose script asks the endpoint below. */
|
|
10
|
+
export const BENNIAO_PAGE = `${BENNIAO_ORIGIN}/?search/`;
|
|
11
|
+
export const BENNIAO_ENDPOINT = 'https://bnsy.benniaosuyun.com/api/officialWebSitePortal/findWaybillTrack';
|
|
12
|
+
const CHALLENGE = /_cf_chl_opt|cf-turnstile|<title>\s*Just a moment|acw_sc__v2|aliyun_waf|_____tmd_____|waf\.tencent|<title>\s*(?:滑动验证|验证码|安全验证|访问受限|访问被拒绝)/i;
|
|
13
|
+
/** BN and fourteen digits, as Benniao's labels and the waybills kuaidi.com lists are; the endpoint answers without the BN. */
|
|
14
|
+
export function normalizeBenniaoNumber(raw) {
|
|
15
|
+
const number = typeof raw === 'string' && raw.length <= 64 ? normalizeTrackingNumber(raw) : '';
|
|
16
|
+
const digits = /^(?:BN)?(\d{14})$/.exec(number)?.[1];
|
|
17
|
+
if (!digits)
|
|
18
|
+
throw new InvalidInputError(PROVIDER, 'Benniao waybills are BN and fourteen digits');
|
|
19
|
+
return `BN${digits}`;
|
|
20
|
+
}
|
|
21
|
+
/** The endpoint's JSON, or the failure a page in its place stands for. */
|
|
22
|
+
export function benniaoJson(text) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(text.replace(/^\uFEFF/, ''));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
if (CHALLENGE.test(text.slice(0, 64_000)))
|
|
28
|
+
throw new ChallengeError(PROVIDER, 'Benniao answered with a browser check');
|
|
29
|
+
throw new SchemaError(PROVIDER, 'Benniao returned an invalid reply');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const text = (value, max = 200) => (typeof value === 'string' ? textFromHtml(value, max) : '');
|
|
33
|
+
/**
|
|
34
|
+
* A row's wording without the phone numbers its branches carry, the courier, the signatory or
|
|
35
|
+
* the customer service notice.
|
|
36
|
+
*/
|
|
37
|
+
function wording(message) {
|
|
38
|
+
return message
|
|
39
|
+
.replace(/[((]物流问题[^))]{0,80}[))]/g, '')
|
|
40
|
+
.replace(/\(\s*[\d\s-]{7,20}\)/g, '')
|
|
41
|
+
.replace(/[,,]\s*派件员是【[^】]{0,40}】/g, '')
|
|
42
|
+
.replace(/[,,]\s*签收人是【[^】]{0,40}】/g, '')
|
|
43
|
+
.replace(/[,,]\s*上一站是【\s*】/g, '')
|
|
44
|
+
.replace(/1[3-9]\d{9}|\d{3,4}-\d{7,8}|400\d{7}/g, '')
|
|
45
|
+
.replace(/[\s,,::]+$/, '')
|
|
46
|
+
.trim();
|
|
47
|
+
}
|
|
48
|
+
/** The scan a row stands for, as 已到达 or 已操作拦截扫描. */
|
|
49
|
+
function code(description) {
|
|
50
|
+
return /已(?:揽收|发件|到达|派件|签收|操作[一-鿿]{1,6}扫描)/.exec(description.replace(/【[^】]*】/g, ''))?.[0];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The scans the endpoint gives for one waybill, oldest first, each with its China wall clock,
|
|
54
|
+
* its city and its wording. The reply must name the whole waybill asked, without its BN.
|
|
55
|
+
*/
|
|
56
|
+
export function parseBenniao(body, raw) {
|
|
57
|
+
const number = normalizeBenniaoNumber(raw), digits = number.slice(2);
|
|
58
|
+
if (!body || typeof body !== 'object' || Array.isArray(body))
|
|
59
|
+
throw new SchemaError(PROVIDER, 'Benniao returned an invalid reply');
|
|
60
|
+
const { success, code: status, msg, result } = body;
|
|
61
|
+
if (success !== true || status !== 200) {
|
|
62
|
+
const reason = text(msg, 120);
|
|
63
|
+
// The page signs each request; a refused signature means its scheme changed.
|
|
64
|
+
if (/验签|签名/.test(reason))
|
|
65
|
+
throw new ChallengeError(PROVIDER, 'Benniao refused the search page\'s signature');
|
|
66
|
+
if (/频繁|太快|过多/.test(reason))
|
|
67
|
+
throw new RateLimitedError(PROVIDER);
|
|
68
|
+
throw new IndeterminateError(PROVIDER, 'Benniao did not complete the lookup');
|
|
69
|
+
}
|
|
70
|
+
if (!Array.isArray(result) || result.length !== 1 || !result[0] || typeof result[0] !== 'object') {
|
|
71
|
+
throw new SchemaError(PROVIDER, 'Benniao returned an invalid result');
|
|
72
|
+
}
|
|
73
|
+
const { waybillNum, waybillStateInfo } = result[0];
|
|
74
|
+
if (waybillNum !== digits)
|
|
75
|
+
throw new SchemaError(PROVIDER, 'Benniao returned another waybill');
|
|
76
|
+
if (waybillStateInfo === null || (Array.isArray(waybillStateInfo) && !waybillStateInfo.length))
|
|
77
|
+
throw new NotFoundError(PROVIDER);
|
|
78
|
+
if (!Array.isArray(waybillStateInfo) || waybillStateInfo.length > 500)
|
|
79
|
+
throw new SchemaError(PROVIDER, 'Benniao returned an invalid history');
|
|
80
|
+
const events = [], seen = new Set();
|
|
81
|
+
for (const row of waybillStateInfo) {
|
|
82
|
+
if (!row || typeof row !== 'object')
|
|
83
|
+
throw new SchemaError(PROVIDER, 'Benniao returned an invalid history row');
|
|
84
|
+
const { date: stamp, location: city, msg: message } = row;
|
|
85
|
+
const clock = typeof stamp === 'string' ? /^(\d{4})-(\d{2})-(\d{2}) ((?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d)$/.exec(stamp) : null;
|
|
86
|
+
const date = clock && calendarDay(+clock[1], +clock[2], +clock[3]);
|
|
87
|
+
if (!clock || !date)
|
|
88
|
+
throw new SchemaError(PROVIDER, 'Benniao returned an invalid scan time');
|
|
89
|
+
const description = wording(text(message, 400));
|
|
90
|
+
if (!description)
|
|
91
|
+
continue;
|
|
92
|
+
const type = code(description), stage = type ? benniaoStage(type) : undefined, location = text(city, 40);
|
|
93
|
+
const event = { local_time: `${date}T${clock[4]}`, description, ...(type ? { provider_code: type } : {}),
|
|
94
|
+
...(location ? { location } : {}), ...(stage ? { stage, stage_source: 'carrier_map' } : {}) };
|
|
95
|
+
const key = JSON.stringify(event);
|
|
96
|
+
if (!seen.has(key)) {
|
|
97
|
+
seen.add(key);
|
|
98
|
+
events.push(event);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!events.length)
|
|
102
|
+
throw new NotFoundError(PROVIDER);
|
|
103
|
+
// Newest first; rows on the same clock keep the endpoint's order reversed.
|
|
104
|
+
events.reverse().sort((a, b) => b.local_time.localeCompare(a.local_time));
|
|
105
|
+
const newest = events[0];
|
|
106
|
+
const stage = newest.stage;
|
|
107
|
+
return { status: stage ? languageStageStatus(stage) : 'unknown', ...(stage ? { current_stage: stage, current_stage_source: 'carrier_map' } : {}),
|
|
108
|
+
last_status_text: newest.description, last_update: null, last_update_local: newest.local_time, events: events.slice(0, 200) };
|
|
109
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import statuses from './statuses.json' with { type: 'json' };
|
|
2
|
+
const ENTRIES = statuses.entries;
|
|
3
|
+
/** The stages of the scans Benniao's rows are built around, as recorded in `statuses.json`. */
|
|
4
|
+
const CODES = new Map(ENTRIES.filter(entry => entry.code && entry.stage)
|
|
5
|
+
.map(entry => [entry.code, entry.stage]));
|
|
6
|
+
export function benniaoStage(code) {
|
|
7
|
+
return CODES.get(code);
|
|
8
|
+
}
|
|
9
|
+
export const statusMap = { stage: code => (code ? CODES.get(code) : undefined), gaps: [] };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"carrier": "benniao-express",
|
|
3
|
+
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"code": "已揽收",
|
|
6
|
+
"wording": "【…】已揽收",
|
|
7
|
+
"stage": "accepted",
|
|
8
|
+
"language": "zh",
|
|
9
|
+
"confirmedBy": "live",
|
|
10
|
+
"note": "The origin branch took the parcel in."
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"code": "已发件",
|
|
14
|
+
"wording": "【…】已发件,发往下一站【…】",
|
|
15
|
+
"stage": "in_transit",
|
|
16
|
+
"language": "zh",
|
|
17
|
+
"confirmedBy": "live",
|
|
18
|
+
"note": "Sent from a branch or hub to the next one."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"code": "已到达",
|
|
22
|
+
"wording": "已到达【…】,上一站是【…】",
|
|
23
|
+
"stage": "in_transit",
|
|
24
|
+
"language": "zh",
|
|
25
|
+
"confirmedBy": "live",
|
|
26
|
+
"note": "Arrived at a hub or the delivering branch."
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"code": "已派件",
|
|
30
|
+
"wording": "【…】已派件,派件员是【…】",
|
|
31
|
+
"stage": "out_for_delivery",
|
|
32
|
+
"language": "zh",
|
|
33
|
+
"confirmedBy": "live",
|
|
34
|
+
"note": "Out with a courier; the adapter leaves the courier's name and phone out."
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"code": "已签收",
|
|
38
|
+
"wording": "已签收,签收人是【…】",
|
|
39
|
+
"stage": "delivered",
|
|
40
|
+
"language": "zh",
|
|
41
|
+
"confirmedBy": "live",
|
|
42
|
+
"note": "Signed for; the adapter leaves the signatory out."
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"code": "已操作拦截扫描",
|
|
46
|
+
"wording": "【…】已操作拦截扫描,原因【拦截】",
|
|
47
|
+
"stage": "exception",
|
|
48
|
+
"language": "zh",
|
|
49
|
+
"confirmedBy": "live",
|
|
50
|
+
"note": "The parcel was stopped on the sender's request, usually to come back."
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"code": "已操作问题件扫描",
|
|
54
|
+
"wording": "【…】已操作问题件扫描,原因【…】",
|
|
55
|
+
"stage": "exception",
|
|
56
|
+
"language": "zh",
|
|
57
|
+
"confirmedBy": "live",
|
|
58
|
+
"note": "A hub recorded a problem with the parcel, such as a late trunk truck."
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
@@ -78,11 +78,13 @@ const EVENT_STATUS = {
|
|
|
78
78
|
'E040000V': { status: 'in_transit', stage: 'customs' },
|
|
79
79
|
'E050000V': { status: 'in_transit', stage: 'in_transit' },
|
|
80
80
|
'E020000V': { status: 'in_transit', stage: 'in_transit' },
|
|
81
|
-
// An import under customs transit: procedures started, transit authorised, transit cleared,
|
|
82
|
-
// in customs; then the procedures finished, which puts the
|
|
81
|
+
// An import under customs transit: procedures started, transit authorised, transit cleared, in
|
|
82
|
+
// processing at the same minute, all in customs; then the procedures finished, which puts the
|
|
83
|
+
// parcel back in transit.
|
|
83
84
|
'E819300V': { status: 'in_transit', stage: 'customs' },
|
|
84
85
|
'E508700V': { status: 'in_transit', stage: 'customs' },
|
|
85
86
|
'E134630V': { status: 'in_transit', stage: 'customs' },
|
|
87
|
+
'E314004V': { status: 'in_transit', stage: 'customs' },
|
|
86
88
|
'E190000V': { status: 'in_transit', stage: 'in_transit' },
|
|
87
89
|
// Handed back to the sender, or on the way back: never a delivery to the recipient.
|
|
88
90
|
'I020000V': { status: 'exception', stage: 'returned' },
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
{ "code": "E819300V", "wording": "Customs procedures starting", "language": "en", "stage": "customs", "confirmedBy": "live", "firstSeen": "2026-10-25", "note": "An import's customs procedures started." },
|
|
64
64
|
{ "code": "E508700V", "wording": "Transit authorised", "language": "en", "stage": "customs", "confirmedBy": "live", "firstSeen": "2026-10-25", "note": "Customs authorised the parcel's transit, between the start and the end of its customs procedures." },
|
|
65
65
|
{ "code": "E134630V", "wording": "Transit cleared", "language": "en", "stage": "customs", "confirmedBy": "live", "firstSeen": "2026-10-25", "note": "The customs transit ended, seconds before the procedures finished." },
|
|
66
|
+
{ "code": "E314004V", "wording": "En tramitación aduanera", "language": "es", "stage": "customs", "confirmedBy": "live", "firstSeen": "2026-11-22", "note": "An import under customs transit in processing, at the minute its transit cleared and minutes before the procedures finished." },
|
|
66
67
|
{ "code": "E190000V", "wording": "Customs procedures finished", "language": "en", "stage": "in_transit", "confirmedBy": "live", "firstSeen": "2026-10-25", "note": "Customs processing completed; the parcel goes on in transit." },
|
|
67
68
|
{ "code": "B170000V", "wording": "En aduana de origen", "language": "es", "stage": "customs", "confirmedBy": "live", "firstSeen": "2026-10-20", "note": "In the origin country's customs." },
|
|
68
69
|
{ "code": "B180000V", "wording": "Finalizada tramitación aduanera", "language": "es", "stage": "in_transit", "confirmedBy": "live", "firstSeen": "2026-11-18", "note": "The origin customs' processing completed, after B170000V; the parcel goes on in transit." },
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { parseDisu } from './parser.js';
|
|
5
|
+
export declare class DisuTracker {
|
|
6
|
+
private readonly options;
|
|
7
|
+
constructor(options?: {
|
|
8
|
+
fetcher?: typeof fetch;
|
|
9
|
+
recorder?: StepRecorder;
|
|
10
|
+
userAgent?: string;
|
|
11
|
+
});
|
|
12
|
+
fetch(raw: string, context?: TrackingContext): Promise<CarrierResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare const adapter: AdapterFactory;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ChallengeError, 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 { DISU_PAGE, disuLookupUrl, normalizeDisuNumber, parseDisu, PROVIDER } from './parser.js';
|
|
7
|
+
export { parseDisu } from './parser.js';
|
|
8
|
+
const REDIRECTS = [301, 302, 303, 307, 308];
|
|
9
|
+
export class DisuTracker {
|
|
10
|
+
options;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
fetch(raw, context = {}) {
|
|
15
|
+
context.signal?.throwIfAborted();
|
|
16
|
+
const number = normalizeDisuNumber(raw);
|
|
17
|
+
const read = async (signal, timeoutMs) => {
|
|
18
|
+
// The tracking box's request: a POST naming the waybill in its query, with an empty body (the
|
|
19
|
+
// IIS server wants a length), and no session, captcha or account.
|
|
20
|
+
const { response, bytes } = await fetchBounded(disuLookupUrl(number), { method: 'POST', signal, body: '', headers: {
|
|
21
|
+
Accept: 'text/plain, */*; q=0.01', 'Content-Type': 'text/plain', 'X-Requested-With': 'XMLHttpRequest',
|
|
22
|
+
Referer: DISU_PAGE, 'User-Agent': userAgentOf(this.options.userAgent),
|
|
23
|
+
} }, { provider: PROVIDER, fetcher: this.options.fetcher, maxBytes: 1_000_000, timeoutMs: Math.max(1, Math.floor(timeoutMs)),
|
|
24
|
+
redirect: 'manual', allowHttpStatuses: [...REDIRECTS, 401, 403, 404, 410] });
|
|
25
|
+
if ([401, 403].includes(response.status))
|
|
26
|
+
throw new ChallengeError(PROVIDER, 'Disu refused its guest request');
|
|
27
|
+
// An unknown waybill is HTTP 200 too; anything else is a moved route.
|
|
28
|
+
if (response.status !== 200)
|
|
29
|
+
throw new TransportError(PROVIDER, 'Disu tracking endpoint moved', { status: response.status });
|
|
30
|
+
return parseDisu(decodeText(bytes), number);
|
|
31
|
+
};
|
|
32
|
+
// A request that fails to reach the server, or hangs, gets one more try in the rest of the budget.
|
|
33
|
+
return runSteps({ carrier: 'disu-logistics', budgetMs: context.budgetMs ?? 15_000, signal: context.signal,
|
|
34
|
+
recorder: this.options.recorder ?? NOOP_RECORDER }, [
|
|
35
|
+
{ id: 'direct', run: ({ signal, remainingMs }) => read(signal, firstAttemptMs(remainingMs)) },
|
|
36
|
+
networkRetryStep(({ signal, remainingMs }) => read(signal, remainingMs)),
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const adapter = environment => {
|
|
41
|
+
const tracker = new DisuTracker({ fetcher: environment.fetcher, recorder: environment.recorder, userAgent: environment.userAgent });
|
|
42
|
+
return { id: 'disu-logistics', recordsSteps: true, steps: ['direct', 'retry'], track: (input, context) => tracker.fetch(input.number, context) };
|
|
43
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "disu-logistics",
|
|
3
|
+
"displayName": "Disu Logistics",
|
|
4
|
+
"aliases": [
|
|
5
|
+
"D速物流",
|
|
6
|
+
"D速快递",
|
|
7
|
+
"山东递速物流有限公司",
|
|
8
|
+
"D-exp"
|
|
9
|
+
],
|
|
10
|
+
"region": {
|
|
11
|
+
"countries": [
|
|
12
|
+
"CN"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"brand": {
|
|
16
|
+
"color": "#e4393c"
|
|
17
|
+
},
|
|
18
|
+
"selectable": true,
|
|
19
|
+
"timezone": "Asia/Shanghai",
|
|
20
|
+
"tracking": {
|
|
21
|
+
"mode": "automatic",
|
|
22
|
+
"adapter": "disu-logistics",
|
|
23
|
+
"steps": [
|
|
24
|
+
"direct",
|
|
25
|
+
"retry"
|
|
26
|
+
],
|
|
27
|
+
"localClocks": true
|
|
28
|
+
},
|
|
29
|
+
"capabilities": [
|
|
30
|
+
"history",
|
|
31
|
+
"location",
|
|
32
|
+
"provider_code",
|
|
33
|
+
"delivery_tracking_number"
|
|
34
|
+
],
|
|
35
|
+
"portal": {
|
|
36
|
+
"canaryUrl": "https://t.17track.net/",
|
|
37
|
+
"shows": [
|
|
38
|
+
"status",
|
|
39
|
+
"history",
|
|
40
|
+
"location",
|
|
41
|
+
"driver_name",
|
|
42
|
+
"driver_phone",
|
|
43
|
+
"signatory",
|
|
44
|
+
"pickup_point",
|
|
45
|
+
"delivery_tracking_number"
|
|
46
|
+
],
|
|
47
|
+
"scraped": [
|
|
48
|
+
"status",
|
|
49
|
+
"history",
|
|
50
|
+
"location",
|
|
51
|
+
"provider_code",
|
|
52
|
+
"pickup_point",
|
|
53
|
+
"delivery_tracking_number"
|
|
54
|
+
],
|
|
55
|
+
"discarded": [
|
|
56
|
+
"driver_name",
|
|
57
|
+
"driver_phone",
|
|
58
|
+
"signatory"
|
|
59
|
+
],
|
|
60
|
+
"unavailable": [
|
|
61
|
+
"weight",
|
|
62
|
+
"service_name",
|
|
63
|
+
"eta",
|
|
64
|
+
"pieces",
|
|
65
|
+
"origin",
|
|
66
|
+
"destination",
|
|
67
|
+
"offset_timestamps",
|
|
68
|
+
"proof_of_delivery",
|
|
69
|
+
"sender_name",
|
|
70
|
+
"recipient_name",
|
|
71
|
+
"recipient_address"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"links": [],
|
|
75
|
+
"detection": []
|
|
76
|
+
}
|