universal-parcel-scraper 0.733.9-main.3752 → 0.734.2-main.3759
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/dist/carriers/nacex/identity.d.ts +8 -0
- package/dist/carriers/nacex/identity.js +15 -0
- package/dist/carriers/nacex/parser.js +2 -1
- package/dist/carriers/zto/adapter.js +20 -4
- package/dist/core/catalog/eventIdentity.js +2 -1
- package/dist/places/hubs.json +6 -0
- package/dist/places/index.js +3 -2
- package/dist/places/places.tsv.br +0 -0
- package/dist/server/openapi.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SameInstantIdentityPolicy } from '../../core/catalog/eventIdentity.js';
|
|
2
|
+
/**
|
|
3
|
+
* A depot's locality without the "PLAT" NACEX writes before a platform's town, cut to twelve
|
|
4
|
+
* letters: "PLATMADRID" is its Madrid platform, "PLATJAEN" Jaén's. A beach town ("PLATJA D ARO")
|
|
5
|
+
* keeps its name.
|
|
6
|
+
*/
|
|
7
|
+
export declare function nacexPlace(locality: string): string;
|
|
8
|
+
export declare const sameInstantIdentityPolicy: SameInstantIdentityPolicy;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { matchesRereadLocation } from '../../core/catalog/locationIdentity.js';
|
|
2
|
+
/**
|
|
3
|
+
* A depot's locality without the "PLAT" NACEX writes before a platform's town, cut to twelve
|
|
4
|
+
* letters: "PLATMADRID" is its Madrid platform, "PLATJAEN" Jaén's. A beach town ("PLATJA D ARO")
|
|
5
|
+
* keeps its name.
|
|
6
|
+
*/
|
|
7
|
+
export function nacexPlace(locality) {
|
|
8
|
+
return locality.replace(/^PLAT ?(?!JA\b)(?=\p{Lu}{3})/u, '');
|
|
9
|
+
}
|
|
10
|
+
// A platform's scan stored under the name with "PLAT" keeps its row.
|
|
11
|
+
export const sameInstantIdentityPolicy = {
|
|
12
|
+
sourceCarrierId: 'nacex', storedSources: ['nacex'], requireProviderCode: false,
|
|
13
|
+
matchEachScan: true,
|
|
14
|
+
matches: (incoming, stored) => matchesRereadLocation(incoming, stored, nacexPlace),
|
|
15
|
+
};
|
|
@@ -2,6 +2,7 @@ import { load } from 'cheerio';
|
|
|
2
2
|
import { IndeterminateError, InvalidInputError, NotFoundError, SchemaError } from '../../core/errors/index.js';
|
|
3
3
|
import { calendarDay } from '../../core/time/index.js';
|
|
4
4
|
import { clean } from '../../core/transport/index.js';
|
|
5
|
+
import { nacexPlace } from './identity.js';
|
|
5
6
|
import { classifyNacexStatus, isNacexMovement, isNacexNotice } from './status.js';
|
|
6
7
|
// Headings name the month in the request's language: English without one, Spanish with `es`.
|
|
7
8
|
const MONTHS = new Map([['january', 'enero'], ['february', 'febrero'], ['march', 'marzo'], ['april', 'abril'],
|
|
@@ -125,7 +126,7 @@ export function parseNacex(html, raw) {
|
|
|
125
126
|
const locality = !booked && isNacexMovement(label) && /^\d{4}(?:-\d{1,3})?\s*-\s*([\p{L}][\p{L}\s.()-]{1,99})$/u.exec(trailing)?.[1];
|
|
126
127
|
scans.push({ mapped, notice: isNacexNotice(label), event: { description: mapped?.status === 'delivered' ? 'Delivered' : label,
|
|
127
128
|
provider_status: label, ...(day ? { local_time: day } : dayText ? { provider_time_text: dayText } : {}),
|
|
128
|
-
...(locality ? { location: locality } : {}) } });
|
|
129
|
+
...(locality ? { location: nacexPlace(locality) } : {}) } });
|
|
129
130
|
}
|
|
130
131
|
// Rows run newest first. A notice keeps the stage of the scan before it.
|
|
131
132
|
let previous;
|
|
@@ -2,7 +2,16 @@ import { accepted, recognizeFromBrowserLookup, recognizeFromLookup } from '../..
|
|
|
2
2
|
import { BudgetExceededError, ChallengeError, RateLimitedError, SchemaError, TransportError, UpstreamHttpError } from '../../core/errors/index.js';
|
|
3
3
|
import { runSteps } from '../../core/runner/index.js';
|
|
4
4
|
import { decodeText, fetchBounded, userAgentOf } from '../../core/transport/index.js';
|
|
5
|
+
import { isRecord } from '../../core/types.js';
|
|
5
6
|
import { API, MAX_BYTES, normalizeZtoNumber, PAGE, parseZto, PROVIDER } from './parser.js';
|
|
7
|
+
/** The challenge reason for each way the service's ZTO helper says the page stayed unverified. */
|
|
8
|
+
const VERIFICATION_REASONS = new Map([['unsolved', 'puzzle_unsolved'], ['solver_unavailable', 'solver_unavailable'],
|
|
9
|
+
['refused', 'verification_refused'], ['deadline', 'verification_unfinished'], ['no_puzzle', 'puzzle_missing']]);
|
|
10
|
+
function verificationReason(page) {
|
|
11
|
+
const last = Array.isArray(page.raw.timings) ? page.raw.timings.at(-1) : undefined;
|
|
12
|
+
const outcome = isRecord(last) && typeof last.reason === 'string' ? /^zto-([a-z_]{1,40})$/.exec(last.reason)?.[1] : undefined;
|
|
13
|
+
return outcome ? VERIFICATION_REASONS.get(outcome) : undefined;
|
|
14
|
+
}
|
|
6
15
|
export class ZtoTracker {
|
|
7
16
|
environment;
|
|
8
17
|
constructor(environment) {
|
|
@@ -46,20 +55,27 @@ export class ZtoTracker {
|
|
|
46
55
|
return false;
|
|
47
56
|
}
|
|
48
57
|
});
|
|
49
|
-
const response = matching.at(-1);
|
|
58
|
+
const response = matching.at(-1), reason = verificationReason(page);
|
|
50
59
|
if (!response || matching.length > 10)
|
|
51
|
-
throw new ChallengeError(PROVIDER, 'ZTO returned no matching tracking response');
|
|
60
|
+
throw new ChallengeError(PROVIDER, 'ZTO returned no matching tracking response', { reason });
|
|
52
61
|
if (response.status === 429)
|
|
53
62
|
throw new RateLimitedError(PROVIDER);
|
|
54
63
|
if ([401, 403, 428].includes(response.status))
|
|
55
|
-
throw new ChallengeError(PROVIDER);
|
|
64
|
+
throw new ChallengeError(PROVIDER, 'ZTO refused the browser tracking request', { status: response.status, reason: 'api_denied' });
|
|
56
65
|
if (response.status >= 400)
|
|
57
66
|
throw new UpstreamHttpError(PROVIDER, response.status);
|
|
58
67
|
if (response.error || response.truncated || response.base64Encoded || response.body === null)
|
|
59
68
|
throw new TransportError(PROVIDER, 'ZTO returned an incomplete browser response');
|
|
60
69
|
if (response.status !== 200 || Buffer.byteLength(response.body) > MAX_BYTES)
|
|
61
70
|
throw new SchemaError(PROVIDER, 'ZTO returned invalid browser data');
|
|
62
|
-
|
|
71
|
+
try {
|
|
72
|
+
return this.parse(response.body, number);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (!(error instanceof ChallengeError) || !reason)
|
|
76
|
+
throw error;
|
|
77
|
+
throw new ChallengeError(PROVIDER, 'ZTO verification did not complete', { reason, cause: error });
|
|
78
|
+
}
|
|
63
79
|
}
|
|
64
80
|
fetch(raw, context = {}) {
|
|
65
81
|
const number = normalizeZtoNumber(raw);
|
|
@@ -30,6 +30,7 @@ import { sameInstantIdentityPolicy as lbcExpress } from '../../carriers/lbc-expr
|
|
|
30
30
|
import { sameInstantIdentityPolicy as linhan } from '../../carriers/linhan/identity.js';
|
|
31
31
|
import { sameInstantIdentityPolicy as mondialRelay } from '../../carriers/mondial-relay/identity.js';
|
|
32
32
|
import { sameInstantIdentityPolicy as mrw } from '../../carriers/mrw/identity.js';
|
|
33
|
+
import { sameInstantIdentityPolicy as nacex } from '../../carriers/nacex/identity.js';
|
|
33
34
|
import { sameInstantIdentityPolicy as nzPost } from '../../carriers/nz-post/identity.js';
|
|
34
35
|
import { sameInstantIdentityPolicy as packeta } from '../../carriers/packeta/identity.js';
|
|
35
36
|
import { sameInstantIdentityPolicy as pitneyBowes } from '../../carriers/pitney-bowes/identity.js';
|
|
@@ -57,7 +58,7 @@ import { sameInstantIdentityPolicy as yunExpress } from '../../carriers/yunexpre
|
|
|
57
58
|
import { sameInstantIdentityPolicy as ztoInternational } from '../../carriers/zto-international/identity.js';
|
|
58
59
|
import { sameInstantIdentityPolicy as universal } from '../../providers/shared/app.js';
|
|
59
60
|
import { CARRIER_DEFINITIONS } from './definitions.js';
|
|
60
|
-
const policies = new Map([aliexpress, amazonShipping, australiaPost, austrianPost, canadaPost, chinaPost, chronopost, ciblex, correosExpress, correosSpain, ctt, cttyex, dhl, dhlEcommerce, dhlExpress, dhlink, dpd, dpdGermany, dpdFrance, fedex, hermesGermany, imile, indiaPost, inpost, jAndTAu, jdLogistics, jrt, laPoste, lbcExpress, linhan, mondialRelay, mrw, nzPost, packeta, parcelforce, pitneyBowes, pocztaPolska, posMalaysia, postlogistics, postnord, postaSlovenije, posteItaliane, posti, royalMail, sfExpress, shouwu, speedpak, spxBr, sunYou, thhy, ups, usps, swissPost, vintedGo, yanwen, yto, yunExpress, ztoInternational, universal].map((policy) => [policy.sourceCarrierId, policy]));
|
|
61
|
+
const policies = new Map([aliexpress, amazonShipping, australiaPost, austrianPost, canadaPost, chinaPost, chronopost, ciblex, correosExpress, correosSpain, ctt, cttyex, dhl, dhlEcommerce, dhlExpress, dhlink, dpd, dpdGermany, dpdFrance, fedex, hermesGermany, imile, indiaPost, inpost, jAndTAu, jdLogistics, jrt, laPoste, lbcExpress, linhan, mondialRelay, mrw, nacex, nzPost, packeta, parcelforce, pitneyBowes, pocztaPolska, posMalaysia, postlogistics, postnord, postaSlovenije, posteItaliane, posti, royalMail, sfExpress, shouwu, speedpak, spxBr, sunYou, thhy, ups, usps, swissPost, vintedGo, yanwen, yto, yunExpress, ztoInternational, universal].map((policy) => [policy.sourceCarrierId, policy]));
|
|
61
62
|
const wording = (scan) => scan.description.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
62
63
|
/** One scan read twice: the same wording and place, and codes that agree when both carry one. */
|
|
63
64
|
function sameScan(incoming, stored) {
|
package/dist/places/hubs.json
CHANGED
|
@@ -8,14 +8,20 @@
|
|
|
8
8
|
{ "country": "GB", "names": ["North West Super"], "town": "Warrington", "site": "North West Super Hub", "latitude": 53.409, "longitude": -2.666, "source": "https://www.openstreetmap.org/way/691307577" },
|
|
9
9
|
{ "country": "GB", "names": ["Midlands Super"], "town": "Daventry", "site": "Midlands Super Hub", "latitude": 52.371, "longitude": -1.172, "source": "https://www.openstreetmap.org/way/992030779" },
|
|
10
10
|
{ "country": "PL", "names": ["Sękocin Stary"], "town": "Sękocin Stary", "latitude": 52.108, "longitude": 20.88, "source": "https://download.geonames.org/export/zip/PL.zip" },
|
|
11
|
+
{ "country": "PL", "carriers": ["inpost"], "names": ["Mokronos Dolny"], "town": "Mokronos Dolny", "latitude": 51.071, "longitude": 16.935, "source": "https://en.wikipedia.org/wiki/Mokronos_Dolny" },
|
|
12
|
+
{ "country": "PL", "carriers": ["inpost"], "names": ["Szymanów"], "town": "Szymanów", "latitude": 50.999, "longitude": 16.72, "source": "https://en.wikipedia.org/wiki/Szyman%C3%B3w,_Wroc%C5%82aw_County" },
|
|
13
|
+
{ "country": "PL", "carriers": ["inpost"], "names": ["Robakowo"], "town": "Robakowo", "latitude": 52.31, "longitude": 17.075, "source": "https://www.geonames.org/3087163" },
|
|
14
|
+
{ "country": "PL", "carriers": ["inpost"], "names": ["Ujrzanów"], "town": "Ujrzanów", "latitude": 52.127, "longitude": 22.333, "source": "https://www.geonames.org/756385" },
|
|
11
15
|
{ "country": "CN", "names": ["Fenggang Town"], "town": "Fenggang", "latitude": 22.757, "longitude": 114.149, "source": "https://www.geonames.org/1916217" },
|
|
12
16
|
{ "country": "CN", "carriers": ["spx-br"], "names": ["ShiYan"], "town": "Shiyan", "latitude": 22.686, "longitude": 113.932, "source": "https://www.openstreetmap.org/relation/6661698" },
|
|
13
17
|
{ "country": "CN", "names": ["Shatian Town"], "town": "Shatian", "latitude": 22.923, "longitude": 113.613, "source": "https://www.openstreetmap.org/relation/5664242" },
|
|
18
|
+
{ "country": "CN", "names": ["Mayong Town"], "town": "Mayong", "latitude": 23.057, "longitude": 113.568, "source": "https://www.geonames.org/1800928" },
|
|
14
19
|
{ "country": "FR", "names": ["Terrasson"], "town": "Terrasson-Lavilledieu", "latitude": 45.129, "longitude": 1.32, "source": "https://www.openstreetmap.org/relation/19894168" },
|
|
15
20
|
{ "country": "US", "admin1": "MO", "names": ["Earth City"], "town": "Earth City", "latitude": 38.769, "longitude": -90.468, "source": "https://www.openstreetmap.org/node/151874554" },
|
|
16
21
|
{ "country": "DE", "carriers": ["dhl", "dhl-ecommerce", "dhl-express"], "names": ["Staufenberg"], "town": "Staufenberg", "latitude": 51.372, "longitude": 9.634, "source": "https://www.openstreetmap.org/way/35537407" },
|
|
17
22
|
{ "country": "CH", "admin1": "ZH", "carriers": ["dpd"], "names": ["Buchs"], "town": "Buchs", "latitude": 47.452, "longitude": 8.43, "source": "https://www.openstreetmap.org/way/193889834" },
|
|
18
23
|
{ "country": "ES", "carriers": ["mrw"], "names": ["Meres"], "town": "Meres", "latitude": 43.376, "longitude": -5.749, "source": "https://www.geonames.org/3116856" },
|
|
24
|
+
{ "country": "ES", "carriers": ["amazon-shipping", "amazon-logistics"], "names": ["Bobes"], "town": "Bobes", "latitude": 43.396, "longitude": -5.772, "source": "https://www.geonames.org/3127943" },
|
|
19
25
|
{ "country": "GB", "carriers": ["royal-mail", "parcelforce"], "names": ["Home Counties North"], "town": "Hemel Hempstead", "site": "Home Counties North Mail Centre", "latitude": 51.764, "longitude": -0.439, "source": "https://www.openstreetmap.org/way/61995366" },
|
|
20
26
|
{ "country": "GB", "carriers": ["royal-mail", "parcelforce"], "names": ["Mount Pleasant", "London Central"], "town": "London", "site": "London Central Mail Centre", "latitude": 51.525, "longitude": -0.112, "source": "https://www.openstreetmap.org/way/1368149790" },
|
|
21
27
|
{ "country": "GB", "carriers": ["royal-mail", "parcelforce"], "names": ["Jubilee"], "town": "Hounslow", "site": "Jubilee Mail Centre", "latitude": 51.451, "longitude": -0.387, "source": "https://www.openstreetmap.org/way/14464218" },
|
package/dist/places/index.js
CHANGED
|
@@ -355,7 +355,8 @@ function tokens(text) {
|
|
|
355
355
|
}
|
|
356
356
|
/**
|
|
357
357
|
* The field's words as printed, then with each abbreviated linking word written out: "Weil a. Rhein"
|
|
358
|
-
* is also "Weil am Rhein" and "Weil an Rhein".
|
|
358
|
+
* is also "Weil am Rhein" and "Weil an Rhein". A letter after another is an initialism's: CTT's
|
|
359
|
+
* "C.O. RIO DE MOURO" is its operations centre in Rio de Mouro.
|
|
359
360
|
*/
|
|
360
361
|
function spelledOut(field, list) {
|
|
361
362
|
const dotted = (token) => token?.key.length === 1 && field[token.end] === '.';
|
|
@@ -366,7 +367,7 @@ function spelledOut(field, list) {
|
|
|
366
367
|
const next = list[index + 1];
|
|
367
368
|
const paired = index > 0 && dotted(token) && dotted(next) && !field.slice(token.end + 1, next.start).trim()
|
|
368
369
|
? ABBREVIATED_LINKS[`${token.key} ${next.key}`] : undefined;
|
|
369
|
-
const words = paired ?? (index > 0 && dotted(token) ? ABBREVIATED_LINKS[token.key] : undefined);
|
|
370
|
+
const words = paired ?? (index > 0 && dotted(token) && !dotted(list[index - 1]) ? ABBREVIATED_LINKS[token.key] : undefined);
|
|
370
371
|
if (!words) {
|
|
371
372
|
printed.push(token);
|
|
372
373
|
variants = variants.map((variant) => [...variant, token]);
|
|
Binary file
|
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.
|
|
3
|
+
"version": "0.734.2-main.3759",
|
|
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",
|