universal-parcel-scraper 0.807.2-main.4341 → 0.807.4-main.4345
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.
|
@@ -250,12 +250,13 @@ export function parseDhlink(payload, raw, readAt = Date.now()) {
|
|
|
250
250
|
const dated = [...scans.values()].sort((left, right) => (left.stamp < right.stamp ? 1 : left.stamp > right.stamp ? -1 : 0))
|
|
251
251
|
.map((scan) => {
|
|
252
252
|
const zone = scanZone(scan, destination, last?.leg.beijingClock === true && !(scan.hub && last.leg.hubClockPickup));
|
|
253
|
-
return { scan, time: zone ? isoTime(scan.stamp, zone) : null };
|
|
253
|
+
return { scan, zone, time: zone ? isoTime(scan.stamp, zone) : null };
|
|
254
254
|
});
|
|
255
255
|
// Beside DHLink's own record of a partner's scan on Beijing time, the partner's copy can come
|
|
256
256
|
// on its US wall clock: the same wording, at the instant of DHLink's row on a US reading.
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
// Without a partner known to be relayed on Beijing time, DHLink's row must be read on it.
|
|
258
|
+
const copies = destination === 'US' ? dated.filter(({ scan }) => dated.some((other) => other.scan !== scan && other.time && (last?.leg.beijingClock || other.zone === RECORD_ZONE)
|
|
259
|
+
&& other.scan.event.description === scan.event.description && usClockCopy(scan.stamp, other.time.timestamp))) : [];
|
|
259
260
|
const events = dated.filter((entry) => !copies.includes(entry))
|
|
260
261
|
.map(({ scan, time }) => ({ ...(time ? { time: time.iso } : { local_time: scan.stamp }), ...scan.event }));
|
|
261
262
|
if (!events.length)
|
|
@@ -4,8 +4,8 @@ import type { StepRecorder } from '../../core/telemetry/index.js';
|
|
|
4
4
|
import type { TrawlClient } from '../../core/transport/index.js';
|
|
5
5
|
import { ParcelsAppHttpClient } from './http.js';
|
|
6
6
|
export declare const PARCELSAPP_BUDGET_MS = 45000;
|
|
7
|
-
export declare function parseParcelsAppResponse(payload: unknown, trackingNumber: string, html: string, timezone?: string | null): CarrierResult;
|
|
8
|
-
export declare function parseParcelsAppHtml(html: string, trackingNumber: string, timezone?: string | null): CarrierResult;
|
|
7
|
+
export declare function parseParcelsAppResponse(payload: unknown, trackingNumber: string, html: string, timezone?: string | null, readAt?: number): CarrierResult;
|
|
8
|
+
export declare function parseParcelsAppHtml(html: string, trackingNumber: string, timezone?: string | null, readAt?: number): CarrierResult;
|
|
9
9
|
export interface ParcelsAppOptions {
|
|
10
10
|
trawl?: TrawlClient | null;
|
|
11
11
|
fetcher?: typeof fetch;
|
|
@@ -54,10 +54,10 @@ function emptyView(html) {
|
|
|
54
54
|
const $ = load(html);
|
|
55
55
|
return $('.tracking-info.empty').length === 1 && !$('.tracking-info .parcel .parcel-attributes tr').length;
|
|
56
56
|
}
|
|
57
|
-
export function parseParcelsAppResponse(payload, trackingNumber, html, timezone = null) {
|
|
57
|
+
export function parseParcelsAppResponse(payload, trackingNumber, html, timezone = null, readAt = Date.now()) {
|
|
58
58
|
if (!parcelsIdentity(html, numberOf(trackingNumber)))
|
|
59
59
|
throw new SchemaError(SOURCE, 'ParcelsApp shipment identity missing');
|
|
60
|
-
return parseHistory(payload, trackingNumber, timezone);
|
|
60
|
+
return parseHistory(payload, trackingNumber, timezone, readAt);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* ParcelsApp's `date` is the scan's local clock, labeled as UTC or shifted
|
|
@@ -1419,6 +1419,19 @@ function replyOrigin(payload, number) {
|
|
|
1419
1419
|
* destination's post names: no scan, and dated ahead of the read.
|
|
1420
1420
|
*/
|
|
1421
1421
|
const FORECAST = /^estimated delivery$/i;
|
|
1422
|
+
// How far after the read a scan that only a guess dates may come out.
|
|
1423
|
+
const GUESS_LEAD_MS = 60 * 60 * 1_000;
|
|
1424
|
+
/**
|
|
1425
|
+
* Whether a scan with no place that only routing's zone or ParcelsApp's label
|
|
1426
|
+
* dates comes out more than an hour after the read. Its clock is another: a
|
|
1427
|
+
* Cainiao step on China's wall clock, read on the UTC of EcoScooting's catalog,
|
|
1428
|
+
* came out 7.6 hours ahead. It is held back until a read catches up with it.
|
|
1429
|
+
* A scan its carrier's clock or its place dates keeps its time, so that the
|
|
1430
|
+
* alert on scans dated ahead still shows a wrong clock there.
|
|
1431
|
+
*/
|
|
1432
|
+
function guessedAhead(event, location, zone, routing, readAt) {
|
|
1433
|
+
return !location && (!zone || zone === routing) && typeof event.time === 'string' && Date.parse(event.time) > readAt + GUESS_LEAD_MS;
|
|
1434
|
+
}
|
|
1422
1435
|
/**
|
|
1423
1436
|
* GEODIS Poland's summary status before its first scan, which ParcelsApp
|
|
1424
1437
|
* relays under "Pekaes" dated ten minutes after its own read on Warsaw's
|
|
@@ -1490,7 +1503,7 @@ function dropDhlinkCopies(entries) {
|
|
|
1490
1503
|
if (copies.size)
|
|
1491
1504
|
entries.splice(0, entries.length, ...entries.filter((entry) => !copies.has(entry)));
|
|
1492
1505
|
}
|
|
1493
|
-
function parseHistory(payload, trackingNumber, timezone = null) {
|
|
1506
|
+
function parseHistory(payload, trackingNumber, timezone = null, readAt = Date.now()) {
|
|
1494
1507
|
if (isRecord(payload) && payload.error === 'RELOAD')
|
|
1495
1508
|
throw new ChallengeError(SOURCE);
|
|
1496
1509
|
if (isRecord(payload) && (payload.error === 'NO_DATA' || payload.error === 'NO_TRACKER')) {
|
|
@@ -1610,6 +1623,8 @@ function parseHistory(payload, trackingNumber, timezone = null) {
|
|
|
1610
1623
|
undated++;
|
|
1611
1624
|
continue;
|
|
1612
1625
|
}
|
|
1626
|
+
if (parsed && guessedAhead(parsed, entry.location, zone, timezone, readAt))
|
|
1627
|
+
continue;
|
|
1613
1628
|
if (parsed) {
|
|
1614
1629
|
// Some Chronopost rows put the service label in the location field.
|
|
1615
1630
|
const location = reportedPlace(raw.location);
|
|
@@ -1690,7 +1705,7 @@ function browserCanRecover(error) {
|
|
|
1690
1705
|
const kind = carrierErrorKind(error);
|
|
1691
1706
|
return kind === null || kind === 'challenge' || kind === 'transport' || kind === 'schema';
|
|
1692
1707
|
}
|
|
1693
|
-
export function parseParcelsAppHtml(html, trackingNumber, timezone = null) {
|
|
1708
|
+
export function parseParcelsAppHtml(html, trackingNumber, timezone = null, readAt = Date.now()) {
|
|
1694
1709
|
if (!parcelsIdentity(html, numberOf(trackingNumber)))
|
|
1695
1710
|
throw new SchemaError(SOURCE, 'ParcelsApp shipment identity missing');
|
|
1696
1711
|
const $ = load(html);
|
|
@@ -1774,6 +1789,8 @@ export function parseParcelsAppHtml(html, trackingNumber, timezone = null) {
|
|
|
1774
1789
|
const parsed = day ? dayEvent(day, scan?.wording ?? description)
|
|
1775
1790
|
: wall ? localEvent(wall, scan?.wording ?? description)
|
|
1776
1791
|
: event((zone ? mislabeledLocalTime(state.date, zone)?.iso : undefined) ?? state.date, scan?.wording ?? description);
|
|
1792
|
+
if (parsed && guessedAhead(parsed, '', zone, timezone, readAt))
|
|
1793
|
+
continue;
|
|
1777
1794
|
if (parsed)
|
|
1778
1795
|
events.push(parsed);
|
|
1779
1796
|
if (parsed)
|
package/dist/server/openapi.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universal-parcel-scraper",
|
|
3
|
-
"version": "0.807.
|
|
3
|
+
"version": "0.807.4-main.4345",
|
|
4
4
|
"description": "Self-hosted parcel tracking: carrier detection, dedicated scrapers and optional universal providers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|