universal-parcel-scraper 0.569.2-main.2644 → 0.569.3-main.2646
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isValidS10TrackingNumber, normalizeTrackingNumber } from '../../core/detection/index.js';
|
|
2
2
|
import { IndeterminateError, InvalidInputError, NotFoundError, SchemaError } from '../../core/errors/index.js';
|
|
3
3
|
import { languageStageStatus } from '../../core/status/index.js';
|
|
4
|
-
import { calendarDay } from '../../core/time/index.js';
|
|
4
|
+
import { calendarDay, isoTime } from '../../core/time/index.js';
|
|
5
5
|
import { clean } from '../../core/transport/index.js';
|
|
6
6
|
import { isRecord } from '../../core/types.js';
|
|
7
7
|
import { ATTEMPT_DELIVERED, ATTEMPT_MADE, anPostPostOffice, anPostScanStage, anPostSummaryStage } from './status.js';
|
|
@@ -9,6 +9,12 @@ export const AN_POST = 'An Post';
|
|
|
9
9
|
const MAX_ITEMS = 50;
|
|
10
10
|
const MAX_SCANS = 500;
|
|
11
11
|
const CLOCK = /^(\d{4})-(\d{2})-(\d{2})T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
|
|
12
|
+
const ZONE = 'Europe/Dublin';
|
|
13
|
+
/**
|
|
14
|
+
* An outbound item's codes as it leaves Ireland (5) and as the destination's
|
|
15
|
+
* delivery partner relays its scans (40, 49, 67, 68), in whole minutes.
|
|
16
|
+
*/
|
|
17
|
+
const ABROAD = new Set([5, 40, 49, 67, 68]);
|
|
12
18
|
/** An Post's own items: the catalog's S10 rule with an IE suffix and a valid check digit. */
|
|
13
19
|
export function normalizeAnPostNumber(raw) {
|
|
14
20
|
const number = normalizeTrackingNumber(raw);
|
|
@@ -27,6 +33,11 @@ function wallClock(value) {
|
|
|
27
33
|
invalid('An Post returned an invalid scan clock');
|
|
28
34
|
return match[0];
|
|
29
35
|
}
|
|
36
|
+
/** An Post's own wall clock on Irish time, unless the clocks skip it. */
|
|
37
|
+
function irishTime(local) {
|
|
38
|
+
const placed = isoTime(local, ZONE);
|
|
39
|
+
return placed?.iso.startsWith(local) ? placed.iso : undefined;
|
|
40
|
+
}
|
|
30
41
|
function text(value, max) {
|
|
31
42
|
if (value == null)
|
|
32
43
|
return '';
|
|
@@ -142,14 +153,27 @@ export function parseAnPostEvents(payload, summary) {
|
|
|
142
153
|
if (seen.has(key))
|
|
143
154
|
continue;
|
|
144
155
|
seen.add(key);
|
|
145
|
-
scans.push({ event, activity, stage, text: description, local, ...(office ? { office } : {}) });
|
|
156
|
+
scans.push({ event, code, activity, stage, text: description, local, ...(office ? { office } : {}) });
|
|
146
157
|
}
|
|
158
|
+
// The scans until an outbound item's dispatch abroad, or before the partner's
|
|
159
|
+
// first relayed scan, are An Post's own, on Irish time. Later ones may keep
|
|
160
|
+
// the destination's clock, so they keep their wall clocks.
|
|
161
|
+
let abroad = -1;
|
|
162
|
+
scans.forEach(({ code }, index) => { if (ABROAD.has(code))
|
|
163
|
+
abroad = index; });
|
|
164
|
+
scans.forEach((scan, index) => {
|
|
165
|
+
const time = abroad < 0 || index > abroad || (index === abroad && scan.code === 5) ? irishTime(scan.local) : undefined;
|
|
166
|
+
if (time)
|
|
167
|
+
scan.event = { time, ...scan.event };
|
|
168
|
+
});
|
|
147
169
|
// Provider order is kept: relayed partner scans may keep another country's
|
|
148
170
|
// clock, so the wall clocks do not reorder them.
|
|
149
171
|
const current = currentState(scans, summary);
|
|
150
172
|
const pickup = pickupPoint(scans, current);
|
|
173
|
+
// A summary ahead of the history is no listed scan, so it keeps its wall clock.
|
|
174
|
+
const time = scans.includes(current) ? current.event.time : undefined;
|
|
151
175
|
return { status: current.stage ? languageStageStatus(current.stage.stage) : 'unknown',
|
|
152
176
|
...(current.stage ? { current_stage: current.stage.stage, current_stage_source: current.stage.source } : {}),
|
|
153
|
-
last_status_text: current.text, last_update: null, last_update_local: current.local,
|
|
177
|
+
last_status_text: current.text, last_update: time ?? null, last_update_local: current.local,
|
|
154
178
|
...(pickup ? { pickup_point: pickup } : {}), expected_delivery: null, events: scans.slice(0, 100).map(({ event }) => event) };
|
|
155
179
|
}
|
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.569.
|
|
3
|
+
"version": "0.569.3-main.2646",
|
|
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",
|