universal-parcel-scraper 0.960.5-main.5218 → 0.960.6-main.5220
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.
|
@@ -5,7 +5,6 @@ import { type TrawlClient, type TrawlScrapeResponse } from '../../core/transport
|
|
|
5
5
|
export declare function normalizeYunExpressNumber(raw: string): string;
|
|
6
6
|
export declare function yunExpressTrackingUrl(raw: string): string;
|
|
7
7
|
export declare function parse(payload: unknown, trackingNumber: string): CarrierResult;
|
|
8
|
-
/** A later captured reply is final; never silently reuse an earlier success. */
|
|
9
8
|
export declare function parseCaptured(page: TrawlScrapeResponse, number: string): CarrierResult;
|
|
10
9
|
export declare class YunExpressTracker {
|
|
11
10
|
private readonly options;
|
|
@@ -325,6 +325,8 @@ export function parse(payload, trackingNumber) {
|
|
|
325
325
|
...(/^[A-Z]{2}$/.test(country) ? { destination_country: country } : {}), events: dated.slice(0, 100) };
|
|
326
326
|
}
|
|
327
327
|
/** A later captured reply is final; never silently reuse an earlier success. */
|
|
328
|
+
/** Time a retry needs for tier 2 to replay the session a refused tier 3 page saved. */
|
|
329
|
+
const TRAWL_RETRY_MS = 8_000;
|
|
328
330
|
export function parseCaptured(page, number) {
|
|
329
331
|
const capture = page.capturedResponses.filter((entry) => entry.url === API).at(-1);
|
|
330
332
|
if (!capture)
|
|
@@ -414,14 +416,31 @@ export class YunExpressTracker {
|
|
|
414
416
|
// The shared launcher serves a lookup for at most 60 s; a longer budget gives the browser that much.
|
|
415
417
|
{ id: 'browser', enabled: Boolean(this.options.executablePath), run: ({ signal, remainingMs }) => localBrowser(number, this.options.executablePath, signal, Math.min(60_000, Math.max(1, Math.floor(remainingMs)))) },
|
|
416
418
|
// Keep the local runtime primary. Service capture needs the matching
|
|
417
|
-
// decoded-response hook and is used only without local Chromium.
|
|
419
|
+
// decoded-response hook and is used only without local Chromium. The
|
|
420
|
+
// service skips tier 2 until it holds a session for the site, which only
|
|
421
|
+
// a tier 3 page saves, so tier 3 is allowed.
|
|
418
422
|
{ id: 'trawl', enabled: !this.options.executablePath && Boolean(this.options.trawl), run: async ({ signal, remainingMs }) => {
|
|
419
|
-
const
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
423
|
+
const started = Date.now();
|
|
424
|
+
const read = (budgetMs) => {
|
|
425
|
+
const timeoutMs = Math.max(1, Math.min(25_000, Math.floor(budgetMs)));
|
|
426
|
+
return this.options.trawl.scrape({ url: yunExpressTrackingUrl(number), skipHttp: true, maxTier: 3,
|
|
427
|
+
maxTimeout: timeoutMs, captureResponses: [API], settleTimeout: 5_000 }, {
|
|
428
|
+
provider: 'TRAWL while fetching YunExpress', timeoutMs, maxBytes: 2_000_000, fetcher: this.options.fetcher, signal
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
const page = await read(remainingMs);
|
|
432
|
+
try {
|
|
433
|
+
return parseCaptured(page, number);
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
// YunExpress's firewall often refuses the API call of a fresh tier 3 page. The page
|
|
437
|
+
// still leaves the service the site's session, and tier 2 replays it with that call.
|
|
438
|
+
const left = remainingMs - (Date.now() - started);
|
|
439
|
+
if (!(error instanceof ChallengeError) || page.tier !== 3 || left < TRAWL_RETRY_MS)
|
|
440
|
+
throw error;
|
|
441
|
+
signal.throwIfAborted();
|
|
442
|
+
return parseCaptured(await read(left), number);
|
|
443
|
+
}
|
|
425
444
|
} },
|
|
426
445
|
]);
|
|
427
446
|
}
|
|
@@ -14,7 +14,7 @@ export interface TrawlScrapeRequest extends JsonObject {
|
|
|
14
14
|
url: string;
|
|
15
15
|
/** Skip the plain HTTP tier and go straight to a browser. */
|
|
16
16
|
skipHttp?: boolean;
|
|
17
|
-
/** 1 = HTTP client, 2 =
|
|
17
|
+
/** 1 = HTTP client, 2 = browser replaying a session an earlier tier 3 page saved for the site (skipped without one), 3 = full browser with challenge solving. */
|
|
18
18
|
maxTier?: 1 | 2 | 3;
|
|
19
19
|
/** Milliseconds the service may spend before answering. */
|
|
20
20
|
maxTimeout?: number;
|
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.960.
|
|
3
|
+
"version": "0.960.6-main.5220",
|
|
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",
|