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.
Files changed (88) hide show
  1. package/README.md +3 -3
  2. package/data/carrier.schema.json +4 -0
  3. package/data/catalog.json +169 -3
  4. package/data/coverage-summary.json +2 -2
  5. package/data/detection-golden.json +547 -0
  6. package/dist/browser/scraper.js +1599 -1438
  7. package/dist/carriers/benniao-express/adapter.d.ts +21 -0
  8. package/dist/carriers/benniao-express/adapter.js +52 -0
  9. package/dist/carriers/benniao-express/carrier.json +79 -0
  10. package/dist/carriers/benniao-express/numbers.json +119 -0
  11. package/dist/carriers/benniao-express/parser.d.ts +15 -0
  12. package/dist/carriers/benniao-express/parser.js +109 -0
  13. package/dist/carriers/benniao-express/status.d.ts +4 -0
  14. package/dist/carriers/benniao-express/status.js +9 -0
  15. package/dist/carriers/benniao-express/statuses.json +61 -0
  16. package/dist/carriers/correos-spain/status.js +4 -2
  17. package/dist/carriers/correos-spain/statuses.json +1 -0
  18. package/dist/carriers/disu-logistics/adapter.d.ts +14 -0
  19. package/dist/carriers/disu-logistics/adapter.js +43 -0
  20. package/dist/carriers/disu-logistics/carrier.json +76 -0
  21. package/dist/carriers/disu-logistics/numbers.json +208 -0
  22. package/dist/carriers/disu-logistics/parser.d.ts +14 -0
  23. package/dist/carriers/disu-logistics/parser.js +109 -0
  24. package/dist/carriers/disu-logistics/status.d.ts +4 -0
  25. package/dist/carriers/disu-logistics/status.js +9 -0
  26. package/dist/carriers/disu-logistics/statuses.json +77 -0
  27. package/dist/carriers/dpd-fr/status.js +2 -0
  28. package/dist/carriers/dpd-fr/statuses.json +8 -0
  29. package/dist/carriers/ecoscooting/carrier.json +2 -1
  30. package/dist/carriers/feibao-logistics/adapter.d.ts +14 -0
  31. package/dist/carriers/feibao-logistics/adapter.js +43 -0
  32. package/dist/carriers/feibao-logistics/carrier.json +74 -0
  33. package/dist/carriers/feibao-logistics/numbers.json +173 -0
  34. package/dist/carriers/feibao-logistics/parser.d.ts +15 -0
  35. package/dist/carriers/feibao-logistics/parser.js +118 -0
  36. package/dist/carriers/feibao-logistics/status.d.ts +4 -0
  37. package/dist/carriers/feibao-logistics/status.js +9 -0
  38. package/dist/carriers/feibao-logistics/statuses.json +45 -0
  39. package/dist/carriers/huaqi-express/adapter.d.ts +14 -0
  40. package/dist/carriers/huaqi-express/adapter.js +41 -0
  41. package/dist/carriers/huaqi-express/carrier.json +72 -0
  42. package/dist/carriers/huaqi-express/numbers.json +39 -0
  43. package/dist/carriers/huaqi-express/parser.d.ts +14 -0
  44. package/dist/carriers/huaqi-express/parser.js +106 -0
  45. package/dist/carriers/huaqi-express/status.d.ts +4 -0
  46. package/dist/carriers/huaqi-express/status.js +9 -0
  47. package/dist/carriers/huaqi-express/statuses.json +77 -0
  48. package/dist/carriers/lindao-express/adapter.d.ts +14 -0
  49. package/dist/carriers/lindao-express/adapter.js +42 -0
  50. package/dist/carriers/lindao-express/carrier.json +68 -0
  51. package/dist/carriers/lindao-express/numbers.json +120 -0
  52. package/dist/carriers/lindao-express/parser.d.ts +13 -0
  53. package/dist/carriers/lindao-express/parser.js +80 -0
  54. package/dist/carriers/lindao-express/status.d.ts +4 -0
  55. package/dist/carriers/lindao-express/status.js +9 -0
  56. package/dist/carriers/lindao-express/statuses.json +101 -0
  57. package/dist/carriers/ontrac/carrier.json +1 -1
  58. package/dist/carriers/ontrac/numbers.json +15 -0
  59. package/dist/carriers/paack/carrier.json +2 -1
  60. package/dist/carriers/riyu-logistics/adapter.d.ts +14 -0
  61. package/dist/carriers/riyu-logistics/adapter.js +42 -0
  62. package/dist/carriers/riyu-logistics/carrier.json +70 -0
  63. package/dist/carriers/riyu-logistics/numbers.json +71 -0
  64. package/dist/carriers/riyu-logistics/parser.d.ts +19 -0
  65. package/dist/carriers/riyu-logistics/parser.js +90 -0
  66. package/dist/carriers/riyu-logistics/status.d.ts +4 -0
  67. package/dist/carriers/riyu-logistics/status.js +9 -0
  68. package/dist/carriers/riyu-logistics/statuses.json +69 -0
  69. package/dist/carriers/wanjia-logistics/adapter.d.ts +14 -0
  70. package/dist/carriers/wanjia-logistics/adapter.js +41 -0
  71. package/dist/carriers/wanjia-logistics/carrier.json +77 -0
  72. package/dist/carriers/wanjia-logistics/numbers.json +114 -0
  73. package/dist/carriers/wanjia-logistics/parser.d.ts +15 -0
  74. package/dist/carriers/wanjia-logistics/parser.js +145 -0
  75. package/dist/carriers/wanjia-logistics/status.d.ts +4 -0
  76. package/dist/carriers/wanjia-logistics/status.js +9 -0
  77. package/dist/carriers/wanjia-logistics/statuses.json +77 -0
  78. package/dist/core/catalog/recognition.js +9 -0
  79. package/dist/core/catalog/statusMaps.js +14 -7
  80. package/dist/core/catalog/types.d.ts +5 -0
  81. package/dist/core/detection/index.d.ts +1 -0
  82. package/dist/core/detection/index.js +1 -0
  83. package/dist/data/catalog.json +169 -3
  84. package/dist/generated/catalog.d.ts +1 -1
  85. package/dist/generated/catalog.js +183 -3
  86. package/dist/generated/registry.js +21 -0
  87. package/dist/server/openapi.json +1 -1
  88. package/package.json +1 -1
@@ -0,0 +1,173 @@
1
+ {
2
+ "carrier": "feibao-logistics",
3
+ "records": [
4
+ {
5
+ "number": "F00002866447",
6
+ "role": "shipment",
7
+ "evidence": "public_shipment_report",
8
+ "source": {
9
+ "url": "https://www.kuaidi.com/all/ztky.html",
10
+ "date": "2026-11-22",
11
+ "dateKind": "capture",
12
+ "access": "full_page"
13
+ },
14
+ "context": {
15
+ "assessment": "confirmed"
16
+ },
17
+ "expect": {
18
+ "carrier": "unknown",
19
+ "confidence": "low",
20
+ "candidates": [
21
+ "colis-prive"
22
+ ]
23
+ },
24
+ "note": "A waybill kuaidi.com's Feibao page lists. Feibao's endpoint answers it with freight from Shenzhen through the Dongguan and Haikou hubs, out for delivery at Baisha."
25
+ },
26
+ {
27
+ "number": "119033244150",
28
+ "role": "shipment",
29
+ "evidence": "public_shipment_report",
30
+ "source": {
31
+ "url": "https://www.kuaidi.com/all/ztky.html",
32
+ "date": "2026-11-22",
33
+ "dateKind": "capture",
34
+ "access": "full_page"
35
+ },
36
+ "context": {
37
+ "assessment": "confirmed"
38
+ },
39
+ "expect": {
40
+ "carrier": "unknown",
41
+ "confidence": "low",
42
+ "candidates": [
43
+ "dpd-fr",
44
+ "mondial-relay",
45
+ "colis-prive",
46
+ "mrw",
47
+ "brt",
48
+ "sf-express",
49
+ "sto",
50
+ "zto",
51
+ "j-and-t",
52
+ "lbc-express",
53
+ "metropolitan-warehouse",
54
+ "paquetexpress",
55
+ "sending"
56
+ ]
57
+ },
58
+ "note": "A waybill kuaidi.com's Feibao page lists. Feibao's endpoint answers it with freight from a Beijing branch through the Beijing hub to Xinyi, signed for."
59
+ },
60
+ {
61
+ "number": "119033303959",
62
+ "role": "shipment",
63
+ "evidence": "public_shipment_report",
64
+ "source": {
65
+ "url": "https://www.kuaidi.com/all/ztky.html",
66
+ "date": "2026-11-22",
67
+ "dateKind": "capture",
68
+ "access": "full_page"
69
+ },
70
+ "context": {
71
+ "assessment": "confirmed"
72
+ },
73
+ "expect": {
74
+ "carrier": "unknown",
75
+ "confidence": "low",
76
+ "candidates": [
77
+ "dpd-fr",
78
+ "mondial-relay",
79
+ "colis-prive",
80
+ "mrw",
81
+ "brt",
82
+ "sf-express",
83
+ "sto",
84
+ "zto",
85
+ "j-and-t",
86
+ "lbc-express",
87
+ "metropolitan-warehouse",
88
+ "paquetexpress",
89
+ "sending"
90
+ ]
91
+ },
92
+ "note": "A waybill kuaidi.com's Feibao page lists. Feibao's endpoint answers it with freight from Tongzhou through the Beijing hub to Chengdu, signed for."
93
+ },
94
+ {
95
+ "number": "F00002864814",
96
+ "role": "shipment",
97
+ "evidence": "public_shipment_report",
98
+ "source": {
99
+ "url": "https://www.kuaidi.com/all/ztky.html",
100
+ "date": "2026-11-22",
101
+ "dateKind": "capture",
102
+ "access": "full_page"
103
+ },
104
+ "context": {
105
+ "assessment": "confirmed"
106
+ },
107
+ "expect": {
108
+ "carrier": "unknown",
109
+ "confidence": "low",
110
+ "candidates": [
111
+ "colis-prive"
112
+ ]
113
+ },
114
+ "note": "A waybill kuaidi.com's Feibao page lists. Feibao's endpoint answers it with freight from Guangzhou to Chongqing, signed for."
115
+ },
116
+ {
117
+ "number": "119033213799",
118
+ "role": "shipment",
119
+ "evidence": "public_shipment_report",
120
+ "source": {
121
+ "url": "https://www.kuaidi.com/all/ztky.html",
122
+ "date": "2026-11-22",
123
+ "dateKind": "capture",
124
+ "access": "full_page"
125
+ },
126
+ "context": {
127
+ "assessment": "confirmed"
128
+ },
129
+ "expect": {
130
+ "carrier": "unknown",
131
+ "confidence": "low",
132
+ "candidates": [
133
+ "dpd-fr",
134
+ "mondial-relay",
135
+ "colis-prive",
136
+ "mrw",
137
+ "brt",
138
+ "sf-express",
139
+ "sto",
140
+ "zto",
141
+ "j-and-t",
142
+ "lbc-express",
143
+ "metropolitan-warehouse",
144
+ "paquetexpress",
145
+ "sending"
146
+ ]
147
+ },
148
+ "note": "A waybill kuaidi.com's Feibao page lists. Feibao's endpoint answers it with freight from Harbin through the Guangzhou hub to Nanhai, signed for."
149
+ },
150
+ {
151
+ "number": "F00002866297",
152
+ "role": "shipment",
153
+ "evidence": "public_shipment_report",
154
+ "source": {
155
+ "url": "https://www.kuaidi.com/all/ztky.html",
156
+ "date": "2026-11-22",
157
+ "dateKind": "capture",
158
+ "access": "full_page"
159
+ },
160
+ "context": {
161
+ "assessment": "confirmed"
162
+ },
163
+ "expect": {
164
+ "carrier": "unknown",
165
+ "confidence": "low",
166
+ "candidates": [
167
+ "colis-prive"
168
+ ]
169
+ },
170
+ "note": "A waybill kuaidi.com's Feibao page lists. Feibao's endpoint answers it with freight from Dachang through the Beijing and Harbin hubs to Hailar, signed for."
171
+ }
172
+ ]
173
+ }
@@ -0,0 +1,15 @@
1
+ import type { CarrierResult } from '../../core/result/index.js';
2
+ export declare const PROVIDER = "Feibao Logistics";
3
+ /** The site's goods tracking page, whose script posts to the endpoint below; the site answers over HTTP only. */
4
+ export declare const FEIBAO_PAGE = "http://www.fb56.com/GoodsTrace/indexNew";
5
+ export declare const FEIBAO_ENDPOINT = "http://www.fb56.com/GoodsTrace/GetOrderAjax2";
6
+ /** F and eleven digits, or twelve digits, as the waybills kuaidi.com lists for Feibao are. */
7
+ export declare function normalizeFeibaoNumber(raw: string): string;
8
+ /** The endpoint's JSON, or the failure a page or code in its place stands for. */
9
+ export declare function feibaoJson(text: string): unknown;
10
+ /**
11
+ * The tracks the endpoint gives for one waybill: its scans with their status, station, next station
12
+ * and instant. The reply must hold one track, for the whole waybill asked, and every row must name it.
13
+ * The recipient, sender and goods fields beside the track are not read.
14
+ */
15
+ export declare function parseFeibao(body: unknown, raw: string): CarrierResult;
@@ -0,0 +1,118 @@
1
+ import { DateTime } from 'luxon';
2
+ import { normalizeTrackingNumber } from '../../core/detection/index.js';
3
+ import { ChallengeError, InvalidInputError, NotFoundError, SchemaError } from '../../core/errors/index.js';
4
+ import { languageStageStatus } from '../../core/status/index.js';
5
+ import { textFromHtml } from '../../core/transport/text.js';
6
+ import { feibaoStage } from './status.js';
7
+ export const PROVIDER = 'Feibao Logistics';
8
+ /** The site's goods tracking page, whose script posts to the endpoint below; the site answers over HTTP only. */
9
+ export const FEIBAO_PAGE = 'http://www.fb56.com/GoodsTrace/indexNew';
10
+ export const FEIBAO_ENDPOINT = 'http://www.fb56.com/GoodsTrace/GetOrderAjax2';
11
+ const ZONE = 'Asia/Shanghai';
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
+ // Scans after 2015 and before 2100: anything else is a changed reply.
14
+ const EARLIEST = Date.UTC(2015, 0, 1), LATEST = Date.UTC(2100, 0, 1);
15
+ /** F and eleven digits, or twelve digits, as the waybills kuaidi.com lists for Feibao are. */
16
+ export function normalizeFeibaoNumber(raw) {
17
+ const number = typeof raw === 'string' && raw.length <= 64 ? normalizeTrackingNumber(raw) : '';
18
+ if (!/^(?:F\d{11}|\d{12})$/.test(number))
19
+ throw new InvalidInputError(PROVIDER, 'Feibao waybills are F and eleven digits, or twelve digits');
20
+ return number;
21
+ }
22
+ /** The endpoint's JSON, or the failure a page or code in its place stands for. */
23
+ export function feibaoJson(text) {
24
+ // The page's script reads a bare 1 as a wrong captcha code.
25
+ if (text.trim() === '1' || text.trim() === '"1"')
26
+ throw new ChallengeError(PROVIDER, 'Feibao asked for the search page\'s captcha');
27
+ try {
28
+ return JSON.parse(text.replace(/^\uFEFF/, ''));
29
+ }
30
+ catch {
31
+ if (CHALLENGE.test(text.slice(0, 64_000)))
32
+ throw new ChallengeError(PROVIDER, 'Feibao answered with a browser check');
33
+ throw new SchemaError(PROVIDER, 'Feibao returned an invalid reply');
34
+ }
35
+ }
36
+ const text = (value, max = 200) => (typeof value === 'string' ? textFromHtml(value, max) : '');
37
+ /** An `/Date(ms)/` stamp as epoch milliseconds, or undefined when it is anything else. */
38
+ function millis(value) {
39
+ const match = typeof value === 'string' ? /^\/Date\((\d{12,14})(?:[+-]\d{4})?\)\/$/.exec(value) : null;
40
+ const ms = match ? Number(match[1]) : NaN;
41
+ return Number.isSafeInteger(ms) && ms >= EARLIEST && ms < LATEST ? ms : undefined;
42
+ }
43
+ /**
44
+ * A row's wording, as the search page's script builds it from the status and the stations, without
45
+ * the driver, the driver's phone or the masked signatory. The row's station is its location, except
46
+ * on a signature row, where that column holds the signatory.
47
+ */
48
+ function row(status, station, next, remark) {
49
+ if (!station)
50
+ return remark ? { description: remark } : undefined;
51
+ switch (status) {
52
+ case 1: return { description: `快件已到达【${station}】`, location: station };
53
+ case 2: return { description: `由【${station}】发往【${next}】`, location: station };
54
+ case 3: return { description: '正在送货', location: station };
55
+ case 4: return { description: '已签收' };
56
+ case 5: return { description: '已拒签', location: station };
57
+ case 99: return { description: remark || station, location: station };
58
+ case 70: return { description: station, location: station };
59
+ default: return undefined;
60
+ }
61
+ }
62
+ /**
63
+ * The tracks the endpoint gives for one waybill: its scans with their status, station, next station
64
+ * and instant. The reply must hold one track, for the whole waybill asked, and every row must name it.
65
+ * The recipient, sender and goods fields beside the track are not read.
66
+ */
67
+ export function parseFeibao(body, raw) {
68
+ const number = normalizeFeibaoNumber(raw);
69
+ if (!body || typeof body !== 'object' || Array.isArray(body))
70
+ throw new SchemaError(PROVIDER, 'Feibao returned an invalid reply');
71
+ const { track } = body;
72
+ if (!Array.isArray(track))
73
+ throw new SchemaError(PROVIDER, 'Feibao returned an invalid reply');
74
+ if (!track.length)
75
+ throw new NotFoundError(PROVIDER);
76
+ if (track.length !== 1 || !track[0] || typeof track[0] !== 'object')
77
+ throw new SchemaError(PROVIDER, 'Feibao returned another waybill');
78
+ const { ConsignID, GoodsTrackObject } = track[0];
79
+ if (typeof ConsignID !== 'string' || ConsignID.toUpperCase() !== number)
80
+ throw new SchemaError(PROVIDER, 'Feibao returned another waybill');
81
+ if (!Array.isArray(GoodsTrackObject) || GoodsTrackObject.length > 500)
82
+ throw new SchemaError(PROVIDER, 'Feibao returned an invalid history');
83
+ const events = [], seen = new Set();
84
+ for (const scan of GoodsTrackObject) {
85
+ if (!scan || typeof scan !== 'object')
86
+ throw new SchemaError(PROVIDER, 'Feibao returned an invalid history row');
87
+ const { ConsignID: waybill, BillType, Status, StationName, NextStationName, Remark, operTime } = scan;
88
+ if (typeof waybill !== 'string' || waybill.toUpperCase() !== number)
89
+ throw new SchemaError(PROVIDER, 'Feibao returned a scan of another waybill');
90
+ // The page shows only waybill rows (bill type 0).
91
+ if (BillType !== 0)
92
+ continue;
93
+ const ms = millis(operTime);
94
+ if (ms === undefined || typeof Status !== 'number' || !Number.isSafeInteger(Status))
95
+ throw new SchemaError(PROVIDER, 'Feibao returned an invalid scan');
96
+ const built = row(Status, text(StationName, 80), text(NextStationName, 80), text(Remark, 300));
97
+ if (!built)
98
+ continue;
99
+ const code = String(Status), stage = feibaoStage(code);
100
+ const event = { time: DateTime.fromMillis(Math.floor(ms / 1000) * 1000, { zone: ZONE }).toISO({ suppressMilliseconds: true }),
101
+ description: built.description, provider_code: code, ...(built.location ? { location: built.location } : {}),
102
+ ...(stage ? { stage, stage_source: 'carrier_map' } : {}) };
103
+ const key = JSON.stringify(event);
104
+ if (!seen.has(key)) {
105
+ seen.add(key);
106
+ events.push({ millis: ms, event });
107
+ }
108
+ }
109
+ if (!events.length)
110
+ throw new NotFoundError(PROVIDER);
111
+ // Newest first; rows at the same instant keep the endpoint's order reversed.
112
+ const sorted = events.reverse().sort((a, b) => b.millis - a.millis).map(({ event }) => event);
113
+ const newest = sorted[0];
114
+ const stage = newest.stage;
115
+ return { status: stage ? languageStageStatus(stage) : 'unknown', ...(stage ? { current_stage: stage, current_stage_source: 'carrier_map' } : {}),
116
+ last_status_text: newest.location ? `${newest.description} · ${newest.location}` : newest.description,
117
+ last_update: newest.time, events: sorted.slice(0, 200) };
118
+ }
@@ -0,0 +1,4 @@
1
+ import type { Stage } from '../../core/status/index.js';
2
+ import type { CarrierStatusMap } from '../../core/status/statusMap.js';
3
+ export declare function feibaoStage(code: string): Stage | undefined;
4
+ export declare const statusMap: CarrierStatusMap;
@@ -0,0 +1,9 @@
1
+ import statuses from './statuses.json' with { type: 'json' };
2
+ const ENTRIES = statuses.entries;
3
+ /** The stages of the scans Feibao'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 feibaoStage(code) {
7
+ return CODES.get(code);
8
+ }
9
+ export const statusMap = { stage: code => (code ? CODES.get(code) : undefined), gaps: [] };
@@ -0,0 +1,45 @@
1
+ {
2
+ "carrier": "feibao-logistics",
3
+ "entries": [
4
+ {
5
+ "code": "1",
6
+ "wording": "快件已到达【…】",
7
+ "stage": "in_transit",
8
+ "language": "zh",
9
+ "confirmedBy": "live",
10
+ "note": "Status 1: arrived at a branch or hub, the origin branch's first scan included."
11
+ },
12
+ {
13
+ "code": "2",
14
+ "wording": "由【…】发往【…】",
15
+ "stage": "in_transit",
16
+ "language": "zh",
17
+ "confirmedBy": "live",
18
+ "note": "Status 2: sent from a branch or hub to the next one."
19
+ },
20
+ {
21
+ "code": "3",
22
+ "wording": "正在送货",
23
+ "stage": "out_for_delivery",
24
+ "language": "zh",
25
+ "confirmedBy": "live",
26
+ "note": "Status 3: out for delivery; the adapter leaves the driver and the driver's phone out."
27
+ },
28
+ {
29
+ "code": "4",
30
+ "wording": "签收人:…",
31
+ "stage": "delivered",
32
+ "language": "zh",
33
+ "confirmedBy": "live",
34
+ "note": "Status 4: signed for; the row's station column holds the masked signatory, which the adapter leaves out."
35
+ },
36
+ {
37
+ "code": "5",
38
+ "wording": "已拒签",
39
+ "stage": "exception",
40
+ "language": "zh",
41
+ "confirmedBy": "bundle",
42
+ "note": "Status 5: the recipient refused the delivery, as the search page's script words it."
43
+ }
44
+ ]
45
+ }
@@ -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 { parseHuaqi } from './parser.js';
5
+ export declare class HuaqiTracker {
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,41 @@
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 { HUAQI_PAGE, huaqiLookupUrl, normalizeHuaqiNumber, parseHuaqi, PROVIDER } from './parser.js';
7
+ export { parseHuaqi } from './parser.js';
8
+ const REDIRECTS = [301, 302, 303, 307, 308];
9
+ export class HuaqiTracker {
10
+ options;
11
+ constructor(options = {}) {
12
+ this.options = options;
13
+ }
14
+ fetch(raw, context = {}) {
15
+ context.signal?.throwIfAborted();
16
+ const number = normalizeHuaqiNumber(raw);
17
+ const read = async (signal, timeoutMs) => {
18
+ // The waybill alone, as the page's search box sends it, with no session, captcha or account.
19
+ const { response, bytes } = await fetchBounded(huaqiLookupUrl(number), { method: 'GET', signal, headers: {
20
+ Accept: 'text/html,application/xhtml+xml', Referer: HUAQI_PAGE, 'User-Agent': userAgentOf(this.options.userAgent),
21
+ } }, { provider: PROVIDER, fetcher: this.options.fetcher, maxBytes: 1_000_000, timeoutMs: Math.max(1, Math.floor(timeoutMs)),
22
+ redirect: 'manual', allowHttpStatuses: [...REDIRECTS, 401, 403, 404, 410] });
23
+ if ([401, 403].includes(response.status))
24
+ throw new ChallengeError(PROVIDER, 'Huaqi refused its guest request');
25
+ // An unknown waybill is HTTP 200 too; anything else is a moved route.
26
+ if (response.status !== 200)
27
+ throw new TransportError(PROVIDER, 'Huaqi tracking page moved', { status: response.status });
28
+ return parseHuaqi(decodeText(bytes), number);
29
+ };
30
+ // A request that fails to reach the server, or hangs, gets one more try in the rest of the budget.
31
+ return runSteps({ carrier: 'huaqi-express', budgetMs: context.budgetMs ?? 15_000, signal: context.signal,
32
+ recorder: this.options.recorder ?? NOOP_RECORDER }, [
33
+ { id: 'direct', run: ({ signal, remainingMs }) => read(signal, firstAttemptMs(remainingMs)) },
34
+ networkRetryStep(({ signal, remainingMs }) => read(signal, remainingMs)),
35
+ ]);
36
+ }
37
+ }
38
+ export const adapter = environment => {
39
+ const tracker = new HuaqiTracker({ fetcher: environment.fetcher, recorder: environment.recorder, userAgent: environment.userAgent });
40
+ return { id: 'huaqi-express', recordsSteps: true, steps: ['direct', 'retry'], track: (input, context) => tracker.fetch(input.number, context) };
41
+ };
@@ -0,0 +1,72 @@
1
+ {
2
+ "id": "huaqi-express",
3
+ "displayName": "Huaqi Express",
4
+ "aliases": [
5
+ "华企快运",
6
+ "华企物流",
7
+ "上海华企物流有限公司"
8
+ ],
9
+ "region": {
10
+ "countries": [
11
+ "CN"
12
+ ]
13
+ },
14
+ "brand": {
15
+ "color": "#e7851a"
16
+ },
17
+ "selectable": true,
18
+ "timezone": "Asia/Shanghai",
19
+ "tracking": {
20
+ "mode": "automatic",
21
+ "adapter": "huaqi-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.huaqiex.com/tracking",
35
+ "canaryUrl": "https://www.huaqiex.com/",
36
+ "shows": [
37
+ "status",
38
+ "history",
39
+ "location",
40
+ "driver_name",
41
+ "driver_phone",
42
+ "scanner_name"
43
+ ],
44
+ "scraped": [
45
+ "status",
46
+ "history",
47
+ "location",
48
+ "provider_code"
49
+ ],
50
+ "discarded": [
51
+ "driver_name",
52
+ "driver_phone",
53
+ "scanner_name"
54
+ ],
55
+ "unavailable": [
56
+ "weight",
57
+ "service_name",
58
+ "eta",
59
+ "pieces",
60
+ "origin",
61
+ "destination",
62
+ "offset_timestamps",
63
+ "proof_of_delivery",
64
+ "signatory",
65
+ "sender_name",
66
+ "recipient_name",
67
+ "recipient_address"
68
+ ]
69
+ },
70
+ "links": [],
71
+ "detection": []
72
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "carrier": "huaqi-express",
3
+ "records": [
4
+ {
5
+ "number": "400800901904",
6
+ "role": "shipment",
7
+ "evidence": "public_shipment_report",
8
+ "source": {
9
+ "url": "https://www.kuaidi.com/all/huaqikuaiyun.html",
10
+ "date": "2026-11-22",
11
+ "dateKind": "capture",
12
+ "access": "full_page"
13
+ },
14
+ "context": {
15
+ "assessment": "confirmed"
16
+ },
17
+ "expect": {
18
+ "carrier": "unknown",
19
+ "confidence": "low",
20
+ "candidates": [
21
+ "mondial-relay",
22
+ "colis-prive",
23
+ "mrw",
24
+ "brt",
25
+ "purolator",
26
+ "sf-express",
27
+ "sto",
28
+ "zto",
29
+ "j-and-t",
30
+ "lbc-express",
31
+ "metropolitan-warehouse",
32
+ "paquetexpress",
33
+ "sending"
34
+ ]
35
+ },
36
+ "note": "A waybill kuaidi.com's Huaqi page lists. Huaqi's tracker answers it with freight taken in at its Shanghai branch, carried through partner hubs in Shanghai and Guangzhou and signed for in Guangzhou."
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,14 @@
1
+ import type { CarrierResult } from '../../core/result/index.js';
2
+ export declare const PROVIDER = "Huaqi Express";
3
+ /** The site's waybill tracking page, which renders the history for the numbers in its query. */
4
+ export declare const HUAQI_PAGE = "https://www.huaqiex.com/tracking";
5
+ /** The waybill on kuaidi.com's Huaqi page is twelve digits. */
6
+ export declare function normalizeHuaqiNumber(raw: string): string;
7
+ export declare function huaqiLookupUrl(number: string): string;
8
+ /**
9
+ * The tracking page for one waybill: a panel titled with the waybill, holding its scans newest
10
+ * first on China wall clocks. The panel must be the whole waybill asked; an empty panel is a
11
+ * waybill the site does not know. Huaqi hands long-distance legs to a partner network, whose
12
+ * hub scans appear in the same list.
13
+ */
14
+ export declare function parseHuaqi(html: string, raw: string): CarrierResult;
@@ -0,0 +1,106 @@
1
+ import { ChallengeError, InvalidInputError, NotFoundError, SchemaError } from '../../core/errors/index.js';
2
+ import { languageStageStatus } from '../../core/status/index.js';
3
+ import { calendarDay } from '../../core/time/index.js';
4
+ import { textFromHtml } from '../../core/transport/text.js';
5
+ import { huaqiStage } from './status.js';
6
+ export const PROVIDER = 'Huaqi Express';
7
+ /** The site's waybill tracking page, which renders the history for the numbers in its query. */
8
+ export const HUAQI_PAGE = 'https://www.huaqiex.com/tracking';
9
+ const CHALLENGE = /_cf_chl_opt|cf-turnstile|<title>\s*Just a moment|acw_sc__v2|aliyun_waf|_____tmd_____|waf\.tencent|<title>\s*(?:滑动验证|验证码|安全验证|访问受限|访问被拒绝)/i;
10
+ const ROW = /<li class="timline-item">\s*<div class="timeline\s*(?:active)?\s*"\s*><\/div>\s*<div class="order-content">\s*<span class="arrow"><\/span>\s*<span class="time">(\d{4})-(\d{2})-(\d{2}) ((?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d)<\/span>\s*<span class="desc">([^<]{0,600})<\/span>\s*<\/div>\s*<\/li>/g;
11
+ /** The waybill on kuaidi.com's Huaqi page is twelve digits. */
12
+ export function normalizeHuaqiNumber(raw) {
13
+ const number = typeof raw === 'string' && raw.length <= 64 ? raw.replace(/\s+/g, '') : '';
14
+ if (!/^\d{12}$/.test(number))
15
+ throw new InvalidInputError(PROVIDER, 'Huaqi waybills are twelve digits');
16
+ return number;
17
+ }
18
+ export function huaqiLookupUrl(number) {
19
+ return `${HUAQI_PAGE}?${new URLSearchParams({ orderNumbers: number })}`;
20
+ }
21
+ /** A row's wording without couriers, scanners, phone numbers or the closing courtesy lines. */
22
+ function wording(desc) {
23
+ return desc
24
+ .replace(/\s+(?=【)/g, '').replace(/(?<=】)\s+/g, '')
25
+ .replace(/[,,]?\s*如有疑问[^【]{0,20}【[^】]{0,60}】[\s\S]*$/, '')
26
+ .replace(/交给【[^】]{0,60}】[,,]?/, '')
27
+ .replace(/([^)]{0,120})/g, '')
28
+ .replace(/[,,]?\s*扫描员是【[^】]{0,30}】/g, '')
29
+ .replace(/[,,]该场地[^。!]{0,80}[。!]?$/, '')
30
+ .replace(/1[3-9]\d{9}|\d{3,4}-\d{7,8}/g, '')
31
+ .replace(/[\s,,。::]+$/, '')
32
+ .trim();
33
+ }
34
+ /** The scan a row's fixed phrase names, as 已收件 or 快件到达. */
35
+ function code(description) {
36
+ if (/^已收件/.test(description))
37
+ return '已收件';
38
+ if (/^已入库/.test(description))
39
+ return '已入库';
40
+ if (/^(?:快件)?离开【/.test(description))
41
+ return '离开';
42
+ if (/^快件在【[^】]+】完成分拣/.test(description))
43
+ return '完成分拣';
44
+ if (/^快件到达【/.test(description))
45
+ return '快件到达';
46
+ if (/^(?:快件开始|车辆正在)长途运输/.test(description))
47
+ return '长途运输';
48
+ if (/正在派送途中$/.test(description))
49
+ return '派送途中';
50
+ if (/^您的快件已派送至本人/.test(description))
51
+ return '已派送';
52
+ if (/^快件已签收$/.test(description))
53
+ return '已签收';
54
+ return undefined;
55
+ }
56
+ const PLACED = new Set(['已收件', '已入库', '离开', '完成分拣', '快件到达']);
57
+ /**
58
+ * The tracking page for one waybill: a panel titled with the waybill, holding its scans newest
59
+ * first on China wall clocks. The panel must be the whole waybill asked; an empty panel is a
60
+ * waybill the site does not know. Huaqi hands long-distance legs to a partner network, whose
61
+ * hub scans appear in the same list.
62
+ */
63
+ export function parseHuaqi(html, raw) {
64
+ const number = normalizeHuaqiNumber(raw);
65
+ if (typeof html !== 'string' || !html)
66
+ throw new SchemaError(PROVIDER, 'Huaqi returned an empty page');
67
+ if (CHALLENGE.test(html.slice(0, 64_000)))
68
+ throw new ChallengeError(PROVIDER, 'Huaqi answered with a browser check');
69
+ const titles = [...html.matchAll(/<h2 class="layui-colla-title">运单号:([^<]{1,40})<i/g)].map(match => match[1].trim());
70
+ if (titles.length !== 1 || titles[0] !== number)
71
+ throw new SchemaError(PROVIDER, 'Huaqi returned another waybill');
72
+ const list = /<ul class="timeline-list">([\s\S]*?)<\/ul>/.exec(html)?.[1];
73
+ if (list === undefined)
74
+ throw new SchemaError(PROVIDER, 'Huaqi returned a waybill without its scan list');
75
+ const rows = [...list.matchAll(ROW)];
76
+ if (rows.length > 500 || rows.length !== (list.match(/<li\b/g)?.length ?? 0))
77
+ throw new SchemaError(PROVIDER, 'Huaqi returned an invalid scan row');
78
+ if (!rows.length)
79
+ throw new NotFoundError(PROVIDER);
80
+ const events = [], seen = new Set();
81
+ for (const [, year, month, day, clock, desc] of rows) {
82
+ const date = calendarDay(+year, +month, +day);
83
+ if (!date)
84
+ throw new SchemaError(PROVIDER, 'Huaqi returned an invalid scan time');
85
+ const description = wording(textFromHtml(desc, 600));
86
+ if (!description)
87
+ continue;
88
+ const type = code(description), stage = type ? huaqiStage(type) : undefined;
89
+ const place = type && PLACED.has(type) ? /【([^】]{1,40})】/.exec(description)?.[1] : undefined;
90
+ const event = { local_time: `${date}T${clock}`, description, ...(type ? { provider_code: type } : {}),
91
+ ...(place ? { location: place } : {}), ...(stage ? { stage, stage_source: 'carrier_map' } : {}) };
92
+ const key = JSON.stringify(event);
93
+ if (!seen.has(key)) {
94
+ seen.add(key);
95
+ events.push(event);
96
+ }
97
+ }
98
+ if (!events.length)
99
+ throw new NotFoundError(PROVIDER);
100
+ // The page lists scans newest first; rows on the same clock keep its order.
101
+ events.sort((a, b) => b.local_time.localeCompare(a.local_time));
102
+ const newest = events.find(event => event.stage === 'delivered') ?? events[0];
103
+ const stage = newest.stage;
104
+ return { status: stage ? languageStageStatus(stage) : 'unknown', ...(stage ? { current_stage: stage, current_stage_source: 'carrier_map' } : {}),
105
+ last_status_text: newest.description, last_update: null, last_update_local: newest.local_time, events: events.slice(0, 300) };
106
+ }