universal-parcel-scraper 0.1102.1-main.6237 → 0.1102.2-main.6239

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.
@@ -10,6 +10,7 @@ import { canadaProvinceTimeZone, countryCode, countryTimeZone, explicitOffsetTim
10
10
  import { clean, fetchBounded, TRAWL_TRANSPORT_ALLOWANCE_MS } from '../../core/transport/index.js';
11
11
  import { isRecord } from '../../core/types.js';
12
12
  import { browserContextProxy } from '../../core/transport/browserRouteTrial.js';
13
+ import { trawlOutOfTime } from '../../core/transport/trawl.js';
13
14
  import { australiaPostCode, australiaPostCodeParts, australiaPostStatus } from './status.js';
14
15
  const PROVIDER = 'Australia Post';
15
16
  const DETAIL = 'https://auspost.com.au/mypost/track/details/';
@@ -335,7 +336,9 @@ export class AustraliaPostTracker {
335
336
  const apiUrl = australiaPostApiUrl(number);
336
337
  const page = await trawl.scrape({ url: australiaPostTrackingUrl(number), skipHttp: true, maxTier: 3,
337
338
  maxTimeout: timeoutMs, captureResponses: [apiUrl], ...(proxy ? { proxy } : {}), settleTimeout: Math.min(timeoutMs, 10_000),
338
- }, { provider: 'TRAWL while fetching Australia Post', timeoutMs, signal, maxBytes: 6_000_000, requireSolved: false });
339
+ }, { provider: 'TRAWL while fetching Australia Post', timeoutMs, signal, maxBytes: 6_000_000, requireSolved: false })
340
+ // A read that ran out of time says nothing about the page.
341
+ .catch((error) => { throw trawlOutOfTime(error) ? new BudgetExceededError(PROVIDER, budgetMs, { cause: error }) : error; });
339
342
  signal.throwIfAborted();
340
343
  if (![2, 3].includes(page.tier) || ![200, 304].includes(page.statusCode)) {
341
344
  throw new TransportError(PROVIDER, 'The browser service did not load Australia Post tracking');
@@ -74,6 +74,11 @@ export declare class TrawlError extends CarrierError {
74
74
  * its default leaves this much room after the service's time.
75
75
  */
76
76
  export declare const TRAWL_TRANSPORT_ALLOWANCE_MS = 15000;
77
+ /**
78
+ * Whether TRAWL gave a read up for lack of time. Its HTTP 500 reply then says the scrape's deadline
79
+ * passed, or that the page step ran out of its budget or was aborted at that deadline.
80
+ */
81
+ export declare function trawlOutOfTime(error: unknown): boolean;
77
82
  export declare function trawlEndpoint(configured: string): URL;
78
83
  /**
79
84
  * Decode the several shapes TRAWL releases use for a captured body: a string,
@@ -33,6 +33,18 @@ function pageHttpError(provider, status, headers) {
33
33
  ? Number(retryHeader) * 1_000 : Date.parse(retryHeader) - Date.now();
34
34
  return new UpstreamHttpError(provider, status, Number.isFinite(retryAfterMs) ? Math.max(0, retryAfterMs) : undefined);
35
35
  }
36
+ /**
37
+ * Whether TRAWL gave a read up for lack of time. Its HTTP 500 reply then says the scrape's deadline
38
+ * passed, or that the page step ran out of its budget or was aborted at that deadline.
39
+ */
40
+ export function trawlOutOfTime(error) {
41
+ if (!(error instanceof UpstreamHttpError) || error.status !== 500)
42
+ return false;
43
+ const reply = error.diagnostics?.body_excerpt ?? '';
44
+ return /"error"\s*:\s*"Scrape deadline exceeded"/.test(reply)
45
+ || (/"error"\s*:\s*"Max tier reached without success"/.test(reply)
46
+ && /"reason"\s*:\s*"[^"]*(?:budget exhausted|operation was aborted)/.test(reply));
47
+ }
36
48
  /**
37
49
  * End the call when its signal has aborted. A cancellation is rethrown as the
38
50
  * caller gave it. A deadline is a browser service that did not answer in
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "Universal Parcel Scraper",
5
- "version": "0.1102.1-main.6237"
5
+ "version": "0.1102.2-main.6239"
6
6
  },
7
7
  "paths": {
8
8
  "/health": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universal-parcel-scraper",
3
- "version": "0.1102.1-main.6237",
3
+ "version": "0.1102.2-main.6239",
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",