universal-parcel-scraper 0.49.2-main.563 → 0.49.2-main.565

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.
@@ -45,6 +45,24 @@ function abroadZone(location, abroad) {
45
45
  return canadaProvinceTimeZone(region);
46
46
  return countryTimeZone(abroad);
47
47
  }
48
+ /** Scans that leave the parcel at an Australian post office or parcel locker for collection. */
49
+ const COLLECTION_SCANS = new Set(['DD-ER4', 'NT-ER4']);
50
+ /** Deliveries left in a safe place, at the door. */
51
+ const SAFE_PLACE = new Set(['DD-ER15', 'DD-ER38']);
52
+ /**
53
+ * The post office or locker its awaiting-collection scan names: the newest scan while the
54
+ * parcel waits there, or the scan just before its delivery once it is collected there. A
55
+ * delivery left in a safe place was not collected.
56
+ */
57
+ function collectionPoint(stage, events) {
58
+ const index = events.findIndex((event) => event.stage !== 'delivered');
59
+ const placed = stage === 'ready_for_pickup' ? index === 0
60
+ : stage === 'delivered' && index > 0 && !events.slice(0, index).some((event) => SAFE_PLACE.has(String(event.provider_code)));
61
+ const scan = placed ? events[index] : undefined;
62
+ if (!scan || !COLLECTION_SCANS.has(String(scan.provider_code)))
63
+ return undefined;
64
+ return /^Awaiting collection at (.+)$/i.exec(scan.description ?? '')?.[1]?.trim() || undefined;
65
+ }
48
66
  /** The one lookup entry and article must independently match the submitted reference. */
49
67
  export function parse(payload, trackingNumber) {
50
68
  const number = normalizeAustraliaPostNumber(trackingNumber);
@@ -153,9 +171,8 @@ export function parse(payload, trackingNumber) {
153
171
  const latest = events[0];
154
172
  const status = australiaPostStatus(summary) ?? latest.classified;
155
173
  const deliveredAt = status?.status === 'delivered' ? events.find(({ event }) => event.stage === 'delivered')?.event.time : null;
156
- // The post office or locker holding the parcel, as its newest scan names it.
157
- const pickup = status?.stage === 'ready_for_pickup' && ['DD-ER4', 'NT-ER4'].includes(String(latest.event.provider_code))
158
- ? /^Awaiting collection at (.+)$/i.exec(latest.event.description ?? '')?.[1]?.trim() : undefined;
174
+ // The reply names the point but gives no address for it.
175
+ const pickup = collectionPoint(status?.stage, events.map(({ event }) => event));
159
176
  // Summary modification/milestone timestamps are not scan times. In the
160
177
  // observed reply they differed from the delivery event by about ten hours.
161
178
  return {
@@ -38,6 +38,19 @@ function scanClock(date, time) {
38
38
  const iso = day && calendarDay(Number(day[3]), Number(day[2]), Number(day[1]));
39
39
  return iso && clock && Number(clock[1]) < 24 && Number(clock[2]) < 60 ? { local_time: `${iso}T${clock[1]}:${clock[2]}:00` } : {};
40
40
  }
41
+ /**
42
+ * The ServicePoint's name, then its street and "postcode town", as the page's
43
+ * ServicePoint card shows them. The name alone when the street or town is missing.
44
+ */
45
+ function servicePoint(raw) {
46
+ const point = isRecord(raw) ? raw : {};
47
+ const name = clean(point.Name, 120);
48
+ const street = clean(point.Address, 120);
49
+ const town = clean(point.Location, 80);
50
+ if (!name || !street || !town)
51
+ return name;
52
+ return [name, street, [clean(point.ZipCode, 16), town].filter(Boolean).join(' ')].join('\n');
53
+ }
41
54
  function code(value) {
42
55
  if (value === undefined || value === null || value === '')
43
56
  return undefined;
@@ -80,8 +93,10 @@ export function parseDhlEcommerceEs(payload, rawNumber) {
80
93
  const current = final >= 0 && !reopened ? events[final] : latest;
81
94
  const stage = current.stage ?? dhlEcommerceEsSummaryStage(payload.Status);
82
95
  const weight = weightKg(payload.Weight);
83
- // The ServicePoint is where the parcel waits only while it is ready there.
84
- const point = stage === 'ready_for_pickup' && isRecord(payload.ServicePoint) ? clean(payload.ServicePoint.Name, 120) : '';
96
+ // The ServicePoint is where the parcel waits while it is ready there, and where it was
97
+ // collected when the shipment says it was delivered there and the recipient picked it up.
98
+ const collected = stage === 'delivered' && current.provider_code === 'RS' && payload.DeliveredInServicePoint === true;
99
+ const point = stage === 'ready_for_pickup' || collected ? servicePoint(payload.ServicePoint) : '';
85
100
  // CTT Express delivers DHL's consumer parcels in Spain under its own label code.
86
101
  const partner = typeof payload.ShippingCode === 'string' ? payload.ShippingCode.trim() : '';
87
102
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universal-parcel-scraper",
3
- "version": "0.49.2-main.563",
3
+ "version": "0.49.2-main.565",
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",