universal-parcel-scraper 0.49.0-main.541 → 0.49.0-main.547
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/NOTICE +6 -0
- package/README.md +1 -1
- package/dist/carriers/aliexpress/adapter.js +2 -0
- package/dist/carriers/aliexpress/status.d.ts +7 -0
- package/dist/carriers/aliexpress/status.js +33 -0
- package/dist/carriers/aliexpress/statuses.json +36 -0
- package/dist/carriers/chronopost/status.js +6 -0
- package/dist/carriers/chronopost/statuses.json +19 -1
- package/dist/carriers/correos-spain/adapter.js +2 -0
- package/dist/carriers/correos-spain/status.d.ts +3 -0
- package/dist/carriers/correos-spain/status.js +16 -0
- package/dist/carriers/dhl-express/adapter.d.ts +1 -1
- package/dist/carriers/dhl-express/adapter.js +4 -4
- package/dist/carriers/dhl-express/mobile.d.ts +23 -2
- package/dist/carriers/dhl-express/mobile.js +58 -18
- package/dist/carriers/dpd/status.js +1 -0
- package/dist/carriers/dpd/statuses.json +8 -0
- package/dist/carriers/dpd-de/app.d.ts +1 -6
- package/dist/carriers/dpd-de/app.js +2 -28
- package/dist/carriers/dpd-de/status.d.ts +15 -0
- package/dist/carriers/dpd-de/status.js +42 -0
- package/dist/carriers/dpd-de/statuses.json +8 -0
- package/dist/carriers/dpd-fr/status.d.ts +7 -0
- package/dist/carriers/dpd-fr/status.js +13 -1
- package/dist/carriers/swiss-post/status.js +8 -1
- package/dist/carriers/swiss-post/statuses.json +34 -0
- package/dist/carriers/ups/adapter.js +3 -2
- package/dist/carriers/ups/status.d.ts +4 -2
- package/dist/carriers/ups/status.js +18 -2
- package/dist/carriers/ups/statuses.json +4 -4
- package/dist/core/catalog/statusMaps.js +6 -1
- package/dist/places/hubs.json +2 -1
- package/dist/places/index.js +58 -8
- package/dist/places/pincodes.json +6554 -0
- package/dist/places/places.tsv.br +0 -0
- package/package.json +1 -1
package/NOTICE
CHANGED
|
@@ -14,3 +14,9 @@ Facility coordinates include OpenStreetMap data (https://www.openstreetmap.org/c
|
|
|
14
14
|
licensed under the Open Database License. Natural Earth country label points
|
|
15
15
|
(https://www.naturalearthdata.com) and OurAirports airports
|
|
16
16
|
(https://ourairports.com/data/) are public domain.
|
|
17
|
+
|
|
18
|
+
Indian PIN code towns (places/pincodes.json) are derived from: Department of
|
|
19
|
+
Posts, Ministry of Communications, 2025, All India Pincode Directory till last
|
|
20
|
+
month, Open Government Data Platform India, 26/06,
|
|
21
|
+
https://www.data.gov.in/resource/all-india-pincode-directory-till-last-month.
|
|
22
|
+
Published under Government Open Data License - India: https://www.data.gov.in/Godl.
|
package/README.md
CHANGED
|
@@ -149,7 +149,7 @@ createTracker({ providers: ['ParcelsApp', 'Ship24', '17TRACK', 'Postal Ninja', '
|
|
|
149
149
|
<!-- GENERATED:stages -->
|
|
150
150
|
<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">
|
|
151
151
|
|
|
152
|
-
The carrier folders record 2,
|
|
152
|
+
The carrier folders record 2,756 such statuses, each filed under one stage.
|
|
153
153
|
<!-- /GENERATED:stages -->
|
|
154
154
|
|
|
155
155
|
Wording nobody recorded yet goes through a classifier that reads seven European languages.
|
|
@@ -170,6 +170,8 @@ export function parseCainiaoTrackingResponse(value, trackingNumber) {
|
|
|
170
170
|
time: scanTime(event),
|
|
171
171
|
location,
|
|
172
172
|
description,
|
|
173
|
+
// The code keys the app's review of a scan the map does not stage.
|
|
174
|
+
...(/^[A-Z0-9_]{1,64}$/.test(code) ? { provider_code: code } : {}),
|
|
173
175
|
...(mapped ? { stage: actionStage[mapped] ?? 'in_transit' } : {}),
|
|
174
176
|
};
|
|
175
177
|
});
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { CarrierStatus } from '../../core/result/index.js';
|
|
18
18
|
import type { Stage } from '../../core/status/index.js';
|
|
19
|
+
import type { CarrierStatusMap } from '../../core/status/statusMap.js';
|
|
19
20
|
/** Parcel-level order tokens, used only when the newest trace has no action code. */
|
|
20
21
|
export declare const CAINIAO_STATUS: Map<string, CarrierStatus>;
|
|
21
22
|
export declare const CAINIAO_ACTION_STATUS: Map<string, CarrierStatus>;
|
|
@@ -29,3 +30,9 @@ export declare function cainiaoActionCode(value: unknown): string;
|
|
|
29
30
|
* the shipment and to every historical event, exactly as before the move.
|
|
30
31
|
*/
|
|
31
32
|
export declare function cainiaoStageByStatus(latestActionCode: string): Partial<Record<CarrierStatus, Stage>>;
|
|
33
|
+
/**
|
|
34
|
+
* What the map says about one scan, by its action code. An out-for-delivery
|
|
35
|
+
* code reads as the van or a pickup point by the newest code of the whole
|
|
36
|
+
* reply, so the code alone does not answer it.
|
|
37
|
+
*/
|
|
38
|
+
export declare const statusMap: CarrierStatusMap;
|
|
@@ -12,6 +12,9 @@ export const CAINIAO_STATUS = new Map([
|
|
|
12
12
|
// leg). The parcel-level `status` token vocabulary is unestablished (real
|
|
13
13
|
// parcels carry DELIVERED/CLEAR_CUSTOMS/transport/pickup/delivered), so the
|
|
14
14
|
// newest latestTrace.actionCode wins and the token is only a fallback.
|
|
15
|
+
// LH_HO_OUT_SUCCESS, TD_TRANSWH_OUTBOUND, TD_TRANS_ARRIVE_DCP and
|
|
16
|
+
// GTMS_SC_DEPART were seen live on 2026-10-08, between the linehaul's arrival
|
|
17
|
+
// and the local partner's round, each worded as one more leg of the journey.
|
|
15
18
|
export const CAINIAO_ACTION_STATUS = new Map([
|
|
16
19
|
['GWMS_ACCEPT', 'pending'],
|
|
17
20
|
['GWMS_PACKAGE', 'pending'],
|
|
@@ -32,12 +35,15 @@ export const CAINIAO_ACTION_STATUS = new Map([
|
|
|
32
35
|
['LH_HO_AIRLINE', 'in_transit'],
|
|
33
36
|
['LH_DEPART', 'in_transit'],
|
|
34
37
|
['LH_ARRIVE', 'in_transit'],
|
|
38
|
+
['LH_HO_OUT_SUCCESS', 'in_transit'],
|
|
35
39
|
['LH_POST_COLLECTION', 'in_transit'],
|
|
36
40
|
['COMMON_INTRANSIT', 'in_transit'],
|
|
37
41
|
['TD_TRANS_DEPART', 'in_transit'],
|
|
38
42
|
['TD_TRANS_ARRIVE', 'in_transit'],
|
|
39
43
|
['TD_TRANS_DEPART_C', 'in_transit'],
|
|
40
44
|
['TD_TRANS_ARRIVE_C', 'in_transit'],
|
|
45
|
+
['TD_TRANSWH_OUTBOUND', 'in_transit'],
|
|
46
|
+
['TD_TRANS_ARRIVE_DCP', 'in_transit'],
|
|
41
47
|
['CC_HO_IN_SUCCESS', 'in_transit'],
|
|
42
48
|
['CC_IM_START', 'in_transit'],
|
|
43
49
|
['CC_IM_SUCCESS', 'in_transit'],
|
|
@@ -45,6 +51,7 @@ export const CAINIAO_ACTION_STATUS = new Map([
|
|
|
45
51
|
['CC_IM_FAILURE', 'exception'],
|
|
46
52
|
['CC_IM_EXCEPTION', 'exception'],
|
|
47
53
|
['GTMS_ACCEPT', 'in_transit'],
|
|
54
|
+
['GTMS_SC_DEPART', 'in_transit'],
|
|
48
55
|
['SC_ARRIVE', 'in_transit'],
|
|
49
56
|
['SC_DEPART', 'in_transit'],
|
|
50
57
|
['OE_DEPART', 'in_transit'],
|
|
@@ -77,3 +84,29 @@ export function cainiaoStageByStatus(latestActionCode) {
|
|
|
77
84
|
exception: 'exception',
|
|
78
85
|
};
|
|
79
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* The scans the review queue holds without their action code, from before
|
|
89
|
+
* events kept it, by `normalizeStatusWording` wording without the town
|
|
90
|
+
* bracket. Each is the standard wording Cainiao gives that code.
|
|
91
|
+
*/
|
|
92
|
+
const UNCODED_SCANS = new Map([
|
|
93
|
+
['handed over from linehaul office', 'LH_HO_OUT_SUCCESS'],
|
|
94
|
+
['leaving transit country/region', 'TD_TRANSWH_OUTBOUND'],
|
|
95
|
+
['awaiting for transit to final delivery office', 'TD_TRANS_ARRIVE_DCP'],
|
|
96
|
+
['departed from destination country/region sorting center', 'GTMS_SC_DEPART'],
|
|
97
|
+
]);
|
|
98
|
+
/**
|
|
99
|
+
* What the map says about one scan, by its action code. An out-for-delivery
|
|
100
|
+
* code reads as the van or a pickup point by the newest code of the whole
|
|
101
|
+
* reply, so the code alone does not answer it.
|
|
102
|
+
*/
|
|
103
|
+
export const statusMap = {
|
|
104
|
+
stage: (code, wording) => {
|
|
105
|
+
const action = code ? cainiaoActionCode(code) : UNCODED_SCANS.get(wording.replace(/^\[[^\]]*\]\s*/, ''));
|
|
106
|
+
const status = action ? CAINIAO_ACTION_STATUS.get(action) : undefined;
|
|
107
|
+
if (!status || status === 'out_for_delivery')
|
|
108
|
+
return undefined;
|
|
109
|
+
return cainiaoStageByStatus('')[status] ?? 'in_transit';
|
|
110
|
+
},
|
|
111
|
+
gaps: [],
|
|
112
|
+
};
|
|
@@ -183,6 +183,15 @@
|
|
|
183
183
|
"firstSeen": "2026-09-12",
|
|
184
184
|
"note": ""
|
|
185
185
|
},
|
|
186
|
+
{
|
|
187
|
+
"code": "LH_HO_OUT_SUCCESS",
|
|
188
|
+
"wording": "Handed over from linehaul office",
|
|
189
|
+
"language": "en",
|
|
190
|
+
"stage": "in_transit",
|
|
191
|
+
"confirmedBy": "live",
|
|
192
|
+
"firstSeen": "2026-10-08",
|
|
193
|
+
"note": "Seen live after the linehaul office arrival, before the transit country scans."
|
|
194
|
+
},
|
|
186
195
|
{
|
|
187
196
|
"code": "LH_POST_COLLECTION",
|
|
188
197
|
"stage": "in_transit",
|
|
@@ -225,6 +234,24 @@
|
|
|
225
234
|
"firstSeen": "2026-09-12",
|
|
226
235
|
"note": ""
|
|
227
236
|
},
|
|
237
|
+
{
|
|
238
|
+
"code": "TD_TRANSWH_OUTBOUND",
|
|
239
|
+
"wording": "Leaving transit country/region",
|
|
240
|
+
"language": "en",
|
|
241
|
+
"stage": "in_transit",
|
|
242
|
+
"confirmedBy": "live",
|
|
243
|
+
"firstSeen": "2026-10-08",
|
|
244
|
+
"note": "Seen live between the arrival in and the departure from the transit country."
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"code": "TD_TRANS_ARRIVE_DCP",
|
|
248
|
+
"wording": "Awaiting for transit to final delivery office",
|
|
249
|
+
"language": "en",
|
|
250
|
+
"stage": "in_transit",
|
|
251
|
+
"confirmedBy": "live",
|
|
252
|
+
"firstSeen": "2026-10-08",
|
|
253
|
+
"note": "Seen live after customs or the transit country, before the local partner received the parcel."
|
|
254
|
+
},
|
|
228
255
|
{
|
|
229
256
|
"code": "CC_HO_IN_SUCCESS",
|
|
230
257
|
"stage": "in_transit",
|
|
@@ -274,6 +301,15 @@
|
|
|
274
301
|
"firstSeen": "2026-09-12",
|
|
275
302
|
"note": ""
|
|
276
303
|
},
|
|
304
|
+
{
|
|
305
|
+
"code": "GTMS_SC_DEPART",
|
|
306
|
+
"wording": "Departed from destination country/region sorting center",
|
|
307
|
+
"language": "en",
|
|
308
|
+
"stage": "in_transit",
|
|
309
|
+
"confirmedBy": "live",
|
|
310
|
+
"firstSeen": "2026-10-08",
|
|
311
|
+
"note": "Seen live between the local partner receiving the parcel and its round."
|
|
312
|
+
},
|
|
277
313
|
{
|
|
278
314
|
"code": "SC_ARRIVE",
|
|
279
315
|
"stage": "in_transit",
|
|
@@ -12,6 +12,12 @@ const observed = new Map([
|
|
|
12
12
|
['EI', { label: 'Colis entré dans le pays de destination', stage: 'in_transit' }],
|
|
13
13
|
['A2', { label: "Colis retardé à l'agence de distribution", stage: 'in_transit' }],
|
|
14
14
|
['IS', { label: 'Livraison prévue lundi prochain', stage: 'in_transit' }],
|
|
15
|
+
// The round, the courier on the way to a pickup point and its arrival there. They come
|
|
16
|
+
// within two minutes of the delivering partner's own scans, and La Poste's feed stages the
|
|
17
|
+
// same scans alike as MD1, ET1 and AG1.
|
|
18
|
+
['TA', { label: 'Colis en cours de livraison', stage: 'out_for_delivery' }],
|
|
19
|
+
['RB', { label: 'Colis en cours de livraison au point de retrait', stage: 'in_transit' }],
|
|
20
|
+
['AB', { label: 'Colis mis à disposition au point de retrait', stage: 'ready_for_pickup' }],
|
|
15
21
|
['P', { label: "Echec de livraison suite à l'absence du destinataire.", stage: 'failed_attempt' }],
|
|
16
22
|
['SK', { label: "Colis en attente d'informations complémentaires de votre part", stage: 'exception' }],
|
|
17
23
|
]);
|
|
@@ -139,6 +139,15 @@
|
|
|
139
139
|
"wording": "Livraison prévue lundi prochain",
|
|
140
140
|
"language": "fr"
|
|
141
141
|
},
|
|
142
|
+
{
|
|
143
|
+
"code": "TA",
|
|
144
|
+
"stage": "out_for_delivery",
|
|
145
|
+
"confirmedBy": "live",
|
|
146
|
+
"firstSeen": "2026-10-08",
|
|
147
|
+
"note": "Chronopost trackSkybillV2; code mapping requires matching wording. Seen with the delivering partner's own out-for-delivery scan, and staged like La Poste's MD1.",
|
|
148
|
+
"wording": "Colis en cours de livraison",
|
|
149
|
+
"language": "fr"
|
|
150
|
+
},
|
|
142
151
|
{
|
|
143
152
|
"code": "P",
|
|
144
153
|
"stage": "failed_attempt",
|
|
@@ -159,9 +168,18 @@
|
|
|
159
168
|
"code": "RB",
|
|
160
169
|
"stage": "in_transit",
|
|
161
170
|
"confirmedBy": "live",
|
|
162
|
-
"note": "
|
|
171
|
+
"note": "Chronopost trackSkybillV2; code mapping requires matching wording. The courier on the way to the pickup point, ahead of its arrival scan (AB); when it follows that scan, it keeps ready_for_pickup.",
|
|
163
172
|
"wording": "Colis en cours de livraison au point de retrait",
|
|
164
173
|
"language": "fr"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"code": "AB",
|
|
177
|
+
"stage": "ready_for_pickup",
|
|
178
|
+
"confirmedBy": "live",
|
|
179
|
+
"firstSeen": "2026-10-08",
|
|
180
|
+
"note": "Chronopost trackSkybillV2; code mapping requires matching wording. Seen with the delivering partner's own pickup-point arrival scan, and staged like La Poste's AG1.",
|
|
181
|
+
"wording": "Colis mis à disposition au point de retrait",
|
|
182
|
+
"language": "fr"
|
|
165
183
|
}
|
|
166
184
|
]
|
|
167
185
|
}
|
|
@@ -122,6 +122,8 @@ export function parseCorreosSpainTrackingResponse(payload, trackingNumber, exped
|
|
|
122
122
|
time: time.iso,
|
|
123
123
|
location: '',
|
|
124
124
|
description,
|
|
125
|
+
// The code keys the app's review of a scan the map does not stage.
|
|
126
|
+
...(/^[A-Z0-9.]{1,32}$/.test(code) ? { provider_code: code } : {}),
|
|
125
127
|
...(classified ? { stage: classified.stage } : {}),
|
|
126
128
|
},
|
|
127
129
|
classified,
|
|
@@ -13,5 +13,8 @@
|
|
|
13
13
|
* out for delivery → failed attempt → office hold → collected).
|
|
14
14
|
*/
|
|
15
15
|
import type { ClassifiedStatus } from '../../core/status/index.js';
|
|
16
|
+
import type { CarrierStatusMap } from '../../core/status/statusMap.js';
|
|
16
17
|
/** The stage and status for a Correos `codEvento`, or undefined when unmapped. */
|
|
17
18
|
export declare function classifyCorreosSpainStatus(code: string): ClassifiedStatus | undefined;
|
|
19
|
+
/** What the map says about one scan, by its `codEvento`. */
|
|
20
|
+
export declare const statusMap: CarrierStatusMap;
|
|
@@ -63,3 +63,19 @@ const EVENT_STATUS = {
|
|
|
63
63
|
export function classifyCorreosSpainStatus(code) {
|
|
64
64
|
return EVENT_STATUS[code];
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The scans the review queue holds without their code, from before events
|
|
68
|
+
* kept it, by `normalizeStatusWording` wording. Each is the summary Correos
|
|
69
|
+
* gives that code.
|
|
70
|
+
*/
|
|
71
|
+
const UNCODED_SCANS = new Map([
|
|
72
|
+
['a disposición del destinatario', 'G01L020V'],
|
|
73
|
+
]);
|
|
74
|
+
/** What the map says about one scan, by its `codEvento`. */
|
|
75
|
+
export const statusMap = {
|
|
76
|
+
stage: (code, wording) => {
|
|
77
|
+
const key = code ? code.toLocaleUpperCase('en-US') : UNCODED_SCANS.get(wording);
|
|
78
|
+
return key ? classifyCorreosSpainStatus(key)?.stage : undefined;
|
|
79
|
+
},
|
|
80
|
+
gaps: [],
|
|
81
|
+
};
|
|
@@ -10,7 +10,7 @@ export declare function parse(payload: unknown, raw: string): CarrierResult;
|
|
|
10
10
|
export declare function parseMobile(payload: unknown, raw: string): CarrierResult;
|
|
11
11
|
export declare class DhlExpressTracker {
|
|
12
12
|
private readonly environment;
|
|
13
|
-
private readonly
|
|
13
|
+
private readonly mobile;
|
|
14
14
|
constructor(environment: AdapterEnvironment);
|
|
15
15
|
direct(number: string, context?: TrackingContext): Promise<CarrierResult>;
|
|
16
16
|
browser(number: string, context?: TrackingContext): Promise<CarrierResult>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
2
|
import { accepted, lookupBudget, recognizeFromBrowserLookup, recognizeFromLookup } from '../../core/adapter/index.js';
|
|
4
3
|
import { isValidDhlExpressWaybill } from '../../core/detection/numericChecksums.js';
|
|
5
4
|
import { BudgetExceededError, ChallengeError, IndeterminateError, InvalidInputError, NotFoundError, RateLimitedError, SchemaError, TransportError, UpstreamHttpError } from '../../core/errors/index.js';
|
|
@@ -8,7 +7,7 @@ import { explicitOffsetTime, zonedTime } from '../../core/time/index.js';
|
|
|
8
7
|
import { clean, parseJsonBytes } from '../../core/transport/index.js';
|
|
9
8
|
import { isRecord } from '../../core/types.js';
|
|
10
9
|
import { facilityZone } from './clock.js';
|
|
11
|
-
import {
|
|
10
|
+
import { DhlMobileApi } from './mobile.js';
|
|
12
11
|
import { dhlExpressStage } from './status.js';
|
|
13
12
|
const PROVIDER = 'DHL Express';
|
|
14
13
|
const BROWSER_API = 'https://www.dhl.com/utapi';
|
|
@@ -146,14 +145,15 @@ export function parseMobile(payload, raw) {
|
|
|
146
145
|
}
|
|
147
146
|
export class DhlExpressTracker {
|
|
148
147
|
environment;
|
|
149
|
-
|
|
148
|
+
mobile;
|
|
150
149
|
constructor(environment) {
|
|
151
150
|
this.environment = environment;
|
|
151
|
+
this.mobile = new DhlMobileApi(environment);
|
|
152
152
|
}
|
|
153
153
|
async direct(number, context) {
|
|
154
154
|
const normalized = normalizeNumber(number);
|
|
155
155
|
const budget = lookupBudget(context, 10_000, PROVIDER);
|
|
156
|
-
return parseMobile(await
|
|
156
|
+
return parseMobile(await this.mobile.tracking(normalized, budget), normalized);
|
|
157
157
|
}
|
|
158
158
|
async browser(number, context) {
|
|
159
159
|
const budget = lookupBudget(context, 45_000, PROVIDER);
|
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
import type { AdapterEnvironment, LookupBudget } from '../../core/adapter/index.js';
|
|
2
|
-
/**
|
|
3
|
-
export declare
|
|
2
|
+
/** How long a confirmed plaintext-waybill setting is reused before it is read again. */
|
|
3
|
+
export declare const SETTINGS_TTL_MS: number;
|
|
4
|
+
/**
|
|
5
|
+
* The guest mobile API for one adapter instance: its device identity and the
|
|
6
|
+
* last time the application configuration allowed a plaintext waybill.
|
|
7
|
+
*/
|
|
8
|
+
export declare class DhlMobileApi {
|
|
9
|
+
private readonly environment;
|
|
10
|
+
private readonly device;
|
|
11
|
+
/** When `api_awb_encryption` last read N; null until it is read again. */
|
|
12
|
+
private settingsCheckedAt;
|
|
13
|
+
constructor(environment: AdapterEnvironment);
|
|
14
|
+
/**
|
|
15
|
+
* One waybill's shipments. The encryption setting is read first unless it was
|
|
16
|
+
* confirmed within the TTL, so an empty list counts as missing only under a
|
|
17
|
+
* recently verified configuration. Any reply other than a shipment list
|
|
18
|
+
* discards the setting. A request that got no reply, including one its own
|
|
19
|
+
* lookup cancelled or ran out of time for, says nothing about it.
|
|
20
|
+
*/
|
|
21
|
+
tracking(number: string, budget: LookupBudget): Promise<unknown>;
|
|
22
|
+
private checkSettings;
|
|
23
|
+
private request;
|
|
24
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
-
import { ChallengeError, RateLimitedError, SchemaError, TransportError, UpstreamHttpError } from '../../core/errors/index.js';
|
|
2
|
+
import { ChallengeError, RateLimitedError, SchemaError, TransportError, UpstreamHttpError, UpstreamNetworkError } from '../../core/errors/index.js';
|
|
3
3
|
import { decodeText, fetchBounded, parseJsonBytes } from '../../core/transport/index.js';
|
|
4
4
|
import { isRecord } from '../../core/types.js';
|
|
5
5
|
const PROVIDER = 'DHL Express';
|
|
@@ -8,6 +8,8 @@ const VERSION = '6.1.0';
|
|
|
8
8
|
const API = `https://dhle.dhl.com/access/access/${APP}`;
|
|
9
9
|
// The shared guest application bearer is deliberately distributed with this adapter.
|
|
10
10
|
const APPLICATION_BEARER = "Bearer MtX6uKNcGM295BXaJGa83GFhTHCL9a";
|
|
11
|
+
/** How long a confirmed plaintext-waybill setting is reused before it is read again. */
|
|
12
|
+
export const SETTINGS_TTL_MS = 15 * 60_000;
|
|
11
13
|
/** Mobile errors can arrive as JSON strings or envelopes with HTTP 200. */
|
|
12
14
|
function checkReply(payload, httpStatus) {
|
|
13
15
|
const root = isRecord(payload) ? payload : {};
|
|
@@ -24,19 +26,67 @@ function checkReply(payload, httpStatus) {
|
|
|
24
26
|
if (serverError)
|
|
25
27
|
throw new UpstreamHttpError(PROVIDER, Number(serverError));
|
|
26
28
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The guest mobile API for one adapter instance: its device identity and the
|
|
31
|
+
* last time the application configuration allowed a plaintext waybill.
|
|
32
|
+
*/
|
|
33
|
+
export class DhlMobileApi {
|
|
34
|
+
environment;
|
|
35
|
+
device = randomUUID();
|
|
36
|
+
/** When `api_awb_encryption` last read N; null until it is read again. */
|
|
37
|
+
settingsCheckedAt = null;
|
|
38
|
+
constructor(environment) {
|
|
39
|
+
this.environment = environment;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One waybill's shipments. The encryption setting is read first unless it was
|
|
43
|
+
* confirmed within the TTL, so an empty list counts as missing only under a
|
|
44
|
+
* recently verified configuration. Any reply other than a shipment list
|
|
45
|
+
* discards the setting. A request that got no reply, including one its own
|
|
46
|
+
* lookup cancelled or ran out of time for, says nothing about it.
|
|
47
|
+
*/
|
|
48
|
+
async tracking(number, budget) {
|
|
49
|
+
const checkedAt = this.settingsCheckedAt;
|
|
50
|
+
if (checkedAt === null || Date.now() - checkedAt >= SETTINGS_TTL_MS)
|
|
51
|
+
await this.checkSettings(budget);
|
|
52
|
+
let payload;
|
|
53
|
+
try {
|
|
54
|
+
payload = await this.request(budget, 'tracking', 'shipments', { airWayBill: number, countryCode: 'GB', languageCd: 'en',
|
|
55
|
+
addShipmentToODD: 'N', moreDetails: 'Y', iv: Buffer.from(randomBytes(8).toString('hex')).toString('base64'), captchaVerificationData: {} });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (!(error instanceof UpstreamNetworkError) && !budget.signal.aborted)
|
|
59
|
+
this.settingsCheckedAt = null;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
if (!Array.isArray(payload))
|
|
63
|
+
this.settingsCheckedAt = null;
|
|
64
|
+
return payload;
|
|
65
|
+
}
|
|
66
|
+
async checkSettings(budget) {
|
|
67
|
+
this.settingsCheckedAt = null;
|
|
68
|
+
const checkedAt = Date.now();
|
|
69
|
+
const settings = await this.request(budget, 'countrySettingsBySettingName', 'common', { countryCode: 'GB', settingNames: ['api_awb_encryption'] });
|
|
70
|
+
if (!Array.isArray(settings) || settings.length > 20 || settings.some((setting) => !isRecord(setting)))
|
|
71
|
+
throw new SchemaError(PROVIDER, 'DHL mobile tracking returned invalid settings');
|
|
72
|
+
const encryption = settings.filter(isRecord).filter((setting) => setting.name === 'api_awb_encryption');
|
|
73
|
+
if (encryption.length !== 1 || (encryption[0].value !== 'N' && encryption[0].value !== 'Y'))
|
|
74
|
+
throw new SchemaError(PROVIDER, 'DHL mobile tracking returned invalid encryption settings');
|
|
75
|
+
if (encryption[0].value === 'Y')
|
|
76
|
+
throw new ChallengeError(PROVIDER, 'DHL mobile tracking requires waybill encryption');
|
|
77
|
+
this.settingsCheckedAt = checkedAt;
|
|
78
|
+
}
|
|
79
|
+
async request(budget, method, service, extra) {
|
|
30
80
|
budget.signal.throwIfAborted();
|
|
31
81
|
const { response, bytes } = await fetchBounded(`${API}?${new URLSearchParams({ appVersion: VERSION, service: `${service}-${method}` })}`, {
|
|
32
82
|
method: 'POST', signal: budget.signal,
|
|
33
83
|
headers: { accept: 'application/json', 'content-type': 'application/json', authorization: APPLICATION_BEARER,
|
|
34
|
-
'cache-control': 'no-cache', transactionId: randomUUID(), 'user-agent': environment.userAgent ?? 'Mozilla/5.0' },
|
|
84
|
+
'cache-control': 'no-cache', transactionId: randomUUID(), 'user-agent': this.environment.userAgent ?? 'Mozilla/5.0' },
|
|
35
85
|
body: JSON.stringify({ method, service, authentication: { provider: 'DEMP.RS1', token: '', login: '' },
|
|
36
86
|
data: { parameters: {}, timezoneOffset: '+00:00', appVersion: VERSION, UIClient: 'Android',
|
|
37
|
-
device_info: { device_unique_id: device, deviceId: device, device_language: 'en', app_id: APP,
|
|
87
|
+
device_info: { device_unique_id: this.device, deviceId: this.device, device_language: 'en', app_id: APP,
|
|
38
88
|
platform: 'Android', appStore: 'PlayStore', gpsLoc: '', pushToken: '' }, ...extra } }),
|
|
39
|
-
}, { provider: PROVIDER, timeoutMs: budget.remainingMs(), maxBytes: 1_000_000, fetcher: environment.fetcher,
|
|
89
|
+
}, { provider: PROVIDER, timeoutMs: budget.remainingMs(), maxBytes: 1_000_000, fetcher: this.environment.fetcher,
|
|
40
90
|
allowHttpStatuses: [400, 404, 410, 503] });
|
|
41
91
|
budget.signal.throwIfAborted();
|
|
42
92
|
if (response.status === 404 || response.status === 410)
|
|
@@ -59,15 +109,5 @@ export async function mobileTracking(number, budget, environment, device) {
|
|
|
59
109
|
if (response.status !== 200)
|
|
60
110
|
throw new UpstreamHttpError(PROVIDER, response.status);
|
|
61
111
|
return payload;
|
|
62
|
-
}
|
|
63
|
-
const settings = await request('countrySettingsBySettingName', 'common', { countryCode: 'GB', settingNames: ['api_awb_encryption'] });
|
|
64
|
-
if (!Array.isArray(settings) || settings.length > 20 || settings.some((setting) => !isRecord(setting)))
|
|
65
|
-
throw new SchemaError(PROVIDER, 'DHL mobile tracking returned invalid settings');
|
|
66
|
-
const encryption = settings.filter(isRecord).filter((setting) => setting.name === 'api_awb_encryption');
|
|
67
|
-
if (encryption.length !== 1 || (encryption[0].value !== 'N' && encryption[0].value !== 'Y'))
|
|
68
|
-
throw new SchemaError(PROVIDER, 'DHL mobile tracking returned invalid encryption settings');
|
|
69
|
-
if (encryption[0].value === 'Y')
|
|
70
|
-
throw new ChallengeError(PROVIDER, 'DHL mobile tracking requires waybill encryption');
|
|
71
|
-
return request('tracking', 'shipments', { airWayBill: number, countryCode: 'GB', languageCd: 'en', addShipmentToODD: 'N',
|
|
72
|
-
moreDetails: 'Y', iv: Buffer.from(randomBytes(8).toString('hex')).toString('base64'), captchaVerificationData: {} });
|
|
112
|
+
}
|
|
73
113
|
}
|
|
@@ -121,5 +121,6 @@ export const statusMap = {
|
|
|
121
121
|
{ code: 'SPE', note: 'A delivery estimate or a changed delivery day, not a scan.' },
|
|
122
122
|
{ code: 'MSDLO', note: 'The notice DPD emailed for the delivery round, not a scan.' },
|
|
123
123
|
{ code: 'MIDLI', note: "The recipient's delivery instruction, not a scan." },
|
|
124
|
+
{ code: 'ENA', note: "A data exchange inside DPD's systems, not a scan: it comes before the parcel reaches the origin depot." },
|
|
124
125
|
],
|
|
125
126
|
};
|
|
@@ -207,6 +207,14 @@
|
|
|
207
207
|
"confirmedBy": "live",
|
|
208
208
|
"firstSeen": "2026-10-05",
|
|
209
209
|
"note": "The recipient's delivery instruction, not a scan."
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"code": "ENA",
|
|
213
|
+
"wording": "We are exchanging data internally",
|
|
214
|
+
"language": "en",
|
|
215
|
+
"confirmedBy": "live",
|
|
216
|
+
"firstSeen": "2026-10-02",
|
|
217
|
+
"note": "A data exchange inside DPD's systems, not a scan; seen twice before the parcel reached the origin depot."
|
|
210
218
|
}
|
|
211
219
|
]
|
|
212
220
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CarrierResult } from '../../core/result/index.js';
|
|
2
|
-
import type { ClassifiedStatus
|
|
2
|
+
import type { ClassifiedStatus } from '../../core/status/index.js';
|
|
3
3
|
import { type XmlNode } from '../../core/transport/xml.js';
|
|
4
4
|
export declare const DPD_DE_APP_API = "https://api.paketnavigator.de/services/v1/Navigator3Service.asmx";
|
|
5
5
|
/** Activity the service places outside Germany; the app tier would read the same parcel. */
|
|
@@ -13,11 +13,6 @@ export interface DpdDePartner {
|
|
|
13
13
|
}
|
|
14
14
|
/** The app's progress rail: one coarse state for the whole parcel. */
|
|
15
15
|
export declare const DPD_DE_APP_RAIL: Readonly<Record<string, ClassifiedStatus>>;
|
|
16
|
-
/**
|
|
17
|
-
* Scans carry wording only. The shared classifier misreads several of these, so each is mapped
|
|
18
|
-
* whole; a variable date is recorded as an ellipsis.
|
|
19
|
-
*/
|
|
20
|
-
export declare const DPD_DE_APP_SCANS: Readonly<Record<string, Stage>>;
|
|
21
16
|
/**
|
|
22
17
|
* Scans arrive oldest first, with a facility's wall clock and no offset. `shop` is the PUDO id of
|
|
23
18
|
* the shop the result names as its pickup point, else empty.
|
|
@@ -4,6 +4,7 @@ import { CarrierError, ChallengeError, IndeterminateError, SchemaError, Transpor
|
|
|
4
4
|
import { calendarDay, isoTime, zonedTime } from '../../core/time/index.js';
|
|
5
5
|
import { clean, decodeText, fetchBounded, userAgentOf } from '../../core/transport/index.js';
|
|
6
6
|
import { xmlDocument } from '../../core/transport/xml.js';
|
|
7
|
+
import { DPD_DE_APP_SCANS, dpdDeScanKey } from './status.js';
|
|
7
8
|
export const DPD_DE_APP_API = 'https://api.paketnavigator.de/services/v1/Navigator3Service.asmx';
|
|
8
9
|
/** Activity the service places outside Germany; the app tier would read the same parcel. */
|
|
9
10
|
export const DPD_DE_OTHER_COUNTRY = 'other_country';
|
|
@@ -26,33 +27,6 @@ export const DPD_DE_APP_RAIL = {
|
|
|
26
27
|
// Set while the return travels and after it reaches the sender: its own scans tell them apart.
|
|
27
28
|
RETURN_TO_SENDER: { status: 'exception', stage: 'exception' },
|
|
28
29
|
};
|
|
29
|
-
/**
|
|
30
|
-
* Scans carry wording only. The shared classifier misreads several of these, so each is mapped
|
|
31
|
-
* whole; a variable date is recorded as an ellipsis.
|
|
32
|
-
*/
|
|
33
|
-
export const DPD_DE_APP_SCANS = {
|
|
34
|
-
'Order information has been transmitted to DPD.': 'registered',
|
|
35
|
-
// The sender booked a collection, which has not happened yet.
|
|
36
|
-
'Pickup ordered for: …': 'registered',
|
|
37
|
-
'Pickup not possible No goods acceptance / goods pickup.': 'registered',
|
|
38
|
-
'Parcel handed to DPD': 'accepted',
|
|
39
|
-
'Parcel handed to Pickup parcelshop by consignor.': 'accepted',
|
|
40
|
-
'In transit.': 'in_transit',
|
|
41
|
-
'At parcel delivery centre.': 'in_transit',
|
|
42
|
-
'Transfer to DPD Pickup station by DPD driver.': 'in_transit',
|
|
43
|
-
'Out for delivery.': 'out_for_delivery',
|
|
44
|
-
'Unfortunately we have not been able to deliver your parcel.': 'failed_attempt',
|
|
45
|
-
'Back at parcel delivery centre after an unsuccessful delivery attempt.': 'failed_attempt',
|
|
46
|
-
"We're sorry but your parcel couldn't be delivered as arranged.": 'exception',
|
|
47
|
-
'Delivered by driver to DPD Pickup parcelshop/ station.': 'ready_for_pickup',
|
|
48
|
-
'Picked up from DPD Pickup station by consignee.': 'delivered',
|
|
49
|
-
'Parcel has been left in: mail box': 'delivered',
|
|
50
|
-
'Delivered.': 'delivered',
|
|
51
|
-
// The return's own scans: under way it stays nonterminal, then it reaches the sender.
|
|
52
|
-
'At parcel delivery centre. (Return to sender)': 'exception',
|
|
53
|
-
'Delivered. (Return to sender)': 'returned',
|
|
54
|
-
};
|
|
55
|
-
const scanKey = (wording) => wording.replace(/^(Pickup ordered for:) \d{2}\.\d{2}\.\d{4}$/, '$1 …');
|
|
56
30
|
function invalid() { throw new SchemaError('DPD Germany', 'DPD Germany returned invalid tracking XML'); }
|
|
57
31
|
function children(node, name, uri = SERVICE) {
|
|
58
32
|
return node.children.filter(child => child.name === name && child.uri === uri);
|
|
@@ -212,7 +186,7 @@ export function parseDpdDeApp(data, scans, number) {
|
|
|
212
186
|
const clock = zonedTime(`${day} ${time}`, 'dd.MM.yyyy HH:mm', place?.[2] === 'DE' ? 'Europe/Berlin' : 'UTC');
|
|
213
187
|
if (!clock)
|
|
214
188
|
invalid();
|
|
215
|
-
const key =
|
|
189
|
+
const key = dpdDeScanKey(wording);
|
|
216
190
|
const stage = Object.hasOwn(DPD_DE_APP_SCANS, key) ? DPD_DE_APP_SCANS[key] : undefined;
|
|
217
191
|
if (stage === 'ready_for_pickup')
|
|
218
192
|
shop = shopOf(row);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Stage } from '../../core/status/index.js';
|
|
2
|
+
import { type CarrierStatusMap } from '../../core/status/statusMap.js';
|
|
3
|
+
/**
|
|
4
|
+
* The German app's scans carry wording only. The shared classifier misreads several of these,
|
|
5
|
+
* so each is mapped whole; a variable date is recorded as an ellipsis.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DPD_DE_APP_SCANS: Readonly<Record<string, Stage>>;
|
|
8
|
+
/** The key a scan's wording is mapped under: a booked collection's date becomes an ellipsis. */
|
|
9
|
+
export declare const dpdDeScanKey: (wording: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* What the map says about one scan: the app's scans by their wording, the guest API's by DPD's
|
|
12
|
+
* codes. The guest API's codes left unmapped on purpose stay so; the Swiss page's labels do not
|
|
13
|
+
* apply, since German lookups never read that page.
|
|
14
|
+
*/
|
|
15
|
+
export declare const statusMap: CarrierStatusMap;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { normalizeStatusWording } from '../../core/status/statusMap.js';
|
|
2
|
+
import { statusMap as dpd } from '../dpd/status.js';
|
|
3
|
+
/**
|
|
4
|
+
* The German app's scans carry wording only. The shared classifier misreads several of these,
|
|
5
|
+
* so each is mapped whole; a variable date is recorded as an ellipsis.
|
|
6
|
+
*/
|
|
7
|
+
export const DPD_DE_APP_SCANS = {
|
|
8
|
+
'Order information has been transmitted to DPD.': 'registered',
|
|
9
|
+
// The sender booked a collection, which has not happened yet.
|
|
10
|
+
'Pickup ordered for: …': 'registered',
|
|
11
|
+
'Pickup not possible No goods acceptance / goods pickup.': 'registered',
|
|
12
|
+
'Parcel handed to DPD': 'accepted',
|
|
13
|
+
'Parcel handed to Pickup parcelshop by consignor.': 'accepted',
|
|
14
|
+
'In transit.': 'in_transit',
|
|
15
|
+
'At parcel delivery centre.': 'in_transit',
|
|
16
|
+
'Transfer to DPD Pickup station by DPD driver.': 'in_transit',
|
|
17
|
+
'Out for delivery.': 'out_for_delivery',
|
|
18
|
+
'Unfortunately we have not been able to deliver your parcel.': 'failed_attempt',
|
|
19
|
+
'Back at parcel delivery centre after an unsuccessful delivery attempt.': 'failed_attempt',
|
|
20
|
+
"We're sorry but your parcel couldn't be delivered as arranged.": 'exception',
|
|
21
|
+
'Delivered by driver to DPD Pickup parcelshop/ station.': 'ready_for_pickup',
|
|
22
|
+
// The recipient collected the parcel from a locker or a shop: delivered, as for UPS.
|
|
23
|
+
'Picked up from DPD Pickup station by consignee.': 'delivered',
|
|
24
|
+
'Picked up from Pickup parcelshop by consignee.': 'delivered',
|
|
25
|
+
'Parcel has been left in: mail box': 'delivered',
|
|
26
|
+
'Delivered.': 'delivered',
|
|
27
|
+
// The return's own scans: under way it stays nonterminal, then it reaches the sender.
|
|
28
|
+
'At parcel delivery centre. (Return to sender)': 'exception',
|
|
29
|
+
'Delivered. (Return to sender)': 'returned',
|
|
30
|
+
};
|
|
31
|
+
/** The key a scan's wording is mapped under: a booked collection's date becomes an ellipsis. */
|
|
32
|
+
export const dpdDeScanKey = (wording) => wording.replace(/^(Pickup ordered for:) \d{2}\.\d{2}\.\d{4}$/i, '$1 …');
|
|
33
|
+
const NORMALIZED_SCANS = new Map(Object.entries(DPD_DE_APP_SCANS).map(([wording, stage]) => [normalizeStatusWording(wording), stage]));
|
|
34
|
+
/**
|
|
35
|
+
* What the map says about one scan: the app's scans by their wording, the guest API's by DPD's
|
|
36
|
+
* codes. The guest API's codes left unmapped on purpose stay so; the Swiss page's labels do not
|
|
37
|
+
* apply, since German lookups never read that page.
|
|
38
|
+
*/
|
|
39
|
+
export const statusMap = {
|
|
40
|
+
stage: (code, wording) => code ? dpd.stage(code, wording) : NORMALIZED_SCANS.get(dpdDeScanKey(wording)),
|
|
41
|
+
gaps: dpd.gaps.filter(gap => gap.code !== undefined),
|
|
42
|
+
};
|
|
@@ -114,6 +114,14 @@
|
|
|
114
114
|
"firstSeen": "2026-10-07",
|
|
115
115
|
"note": "Seen in the German app's scan list, which carries wording only. Mapped whole because the shared classifier reads it as an acceptance."
|
|
116
116
|
},
|
|
117
|
+
{
|
|
118
|
+
"wording": "Picked up from Pickup parcelshop by consignee.",
|
|
119
|
+
"language": "en",
|
|
120
|
+
"stage": "delivered",
|
|
121
|
+
"confirmedBy": "live",
|
|
122
|
+
"firstSeen": "2026-10-08",
|
|
123
|
+
"note": "Seen in the German app's scan list, which carries wording only. The collection from a shop, after the driver's drop-off there; delivered, like the collection from a Pickup station. Mapped whole because the shared classifier reads it as an acceptance."
|
|
124
|
+
},
|
|
117
125
|
{
|
|
118
126
|
"wording": "Delivered.",
|
|
119
127
|
"language": "en",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* pages kept by the Internet Archive.
|
|
17
17
|
*/
|
|
18
18
|
import type { ClassifiedStatus } from '../../core/status/index.js';
|
|
19
|
+
import type { CarrierStatusMap } from '../../core/status/statusMap.js';
|
|
19
20
|
/**
|
|
20
21
|
* Lowercase, accent-free, punctuation-free form used for every wording
|
|
21
22
|
* comparison. A spacing accent typed for an apostrophe ("l´expéditeur")
|
|
@@ -24,3 +25,9 @@ import type { ClassifiedStatus } from '../../core/status/index.js';
|
|
|
24
25
|
export declare function comparableText(value: string): string;
|
|
25
26
|
export declare function includesAny(value: string, phrases: string[]): boolean;
|
|
26
27
|
export declare function classifyStatus(description: string): ClassifiedStatus;
|
|
28
|
+
/**
|
|
29
|
+
* What the map says about one scan. The trace page has no codes, so the
|
|
30
|
+
* wording is the whole key, and wording the map does not recognize gets no
|
|
31
|
+
* stage, as in the adapter.
|
|
32
|
+
*/
|
|
33
|
+
export declare const statusMap: CarrierStatusMap;
|