universal-parcel-scraper 0.892.0-main.4787 → 0.894.0-main.4792

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.
Files changed (45) hide show
  1. package/README.md +3 -3
  2. package/data/catalog.json +196 -3
  3. package/data/coverage-summary.json +2 -2
  4. package/dist/browser/scraper.js +167 -4
  5. package/dist/carriers/ekart/adapter.d.ts +1 -1
  6. package/dist/carriers/ekart/adapter.js +6 -1
  7. package/dist/carriers/ekart/carrier.json +4 -1
  8. package/dist/carriers/far-international/carrier.json +1 -1
  9. package/dist/carriers/gofast/carrier.json +46 -0
  10. package/dist/carriers/gofast/numbers.json +5 -0
  11. package/dist/carriers/gofast/statuses.json +4 -0
  12. package/dist/carriers/hiyes/carrier.json +37 -0
  13. package/dist/carriers/hiyes/numbers.json +5 -0
  14. package/dist/carriers/hiyes/statuses.json +4 -0
  15. package/dist/carriers/htt-logistics/carrier.json +35 -0
  16. package/dist/carriers/htt-logistics/numbers.json +5 -0
  17. package/dist/carriers/htt-logistics/statuses.json +4 -0
  18. package/dist/carriers/nas-express/carrier.json +35 -0
  19. package/dist/carriers/nas-express/numbers.json +5 -0
  20. package/dist/carriers/nas-express/statuses.json +4 -0
  21. package/dist/carriers/odm-express/carrier.json +43 -0
  22. package/dist/carriers/odm-express/numbers.json +5 -0
  23. package/dist/carriers/odm-express/statuses.json +4 -0
  24. package/dist/carriers/online-worldwide-logistics/carrier.json +51 -0
  25. package/dist/carriers/online-worldwide-logistics/numbers.json +5 -0
  26. package/dist/carriers/online-worldwide-logistics/statuses.json +4 -0
  27. package/dist/carriers/ontask-express/carrier.json +36 -0
  28. package/dist/carriers/ontask-express/numbers.json +5 -0
  29. package/dist/carriers/ontask-express/statuses.json +4 -0
  30. package/dist/carriers/skybox/adapter.d.ts +18 -0
  31. package/dist/carriers/skybox/adapter.js +49 -0
  32. package/dist/carriers/skybox/carrier.json +45 -7
  33. package/dist/carriers/skybox/parser.d.ts +17 -0
  34. package/dist/carriers/skybox/parser.js +125 -0
  35. package/dist/carriers/skybox/status.d.ts +7 -0
  36. package/dist/carriers/skybox/status.js +22 -0
  37. package/dist/carriers/skybox/statuses.json +8 -1
  38. package/dist/core/catalog/statusMaps.js +2 -1
  39. package/dist/data/catalog.json +196 -3
  40. package/dist/generated/catalog.d.ts +131 -3
  41. package/dist/generated/catalog.js +210 -3
  42. package/dist/generated/recognition.js +1 -0
  43. package/dist/generated/registry.js +10 -1
  44. package/dist/server/openapi.json +1 -1
  45. package/package.json +1 -1
@@ -0,0 +1,46 @@
1
+ {
2
+ "id": "gofast",
3
+ "displayName": "GoFast",
4
+ "aliases": [
5
+ "够快供应链",
6
+ "够快"
7
+ ],
8
+ "region": {
9
+ "countries": [
10
+ "CN",
11
+ "US"
12
+ ]
13
+ },
14
+ "brand": {
15
+ "color": "#f46a0e"
16
+ },
17
+ "selectable": true,
18
+ "timezone": "Asia/Shanghai",
19
+ "tracking": {
20
+ "mode": "automatic",
21
+ "adapter": "universal",
22
+ "steps": []
23
+ },
24
+ "capabilities": [],
25
+ "portal": {
26
+ "url": "https://gzgk.hailei2018.com/trackIndex.htm?documentCode={trackingNumber}",
27
+ "searchUrl": "https://gzgk.hailei2018.com/trackIndex.htm",
28
+ "canaryUrl": "https://www.gofastcn.com/",
29
+ "shows": [],
30
+ "scraped": [],
31
+ "discarded": [],
32
+ "unavailable": []
33
+ },
34
+ "links": [
35
+ {
36
+ "domains": [
37
+ "gzgk.hailei2018.com"
38
+ ],
39
+ "pathPattern": "^/trackIndex\\.htm$",
40
+ "params": [
41
+ "documentCode"
42
+ ]
43
+ }
44
+ ],
45
+ "detection": []
46
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "gofast",
3
+ "gap": "No public page shows a GoFast tracking number.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "gofast",
3
+ "entries": []
4
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "id": "hiyes",
3
+ "displayName": "Hiyes",
4
+ "aliases": [
5
+ "新航通運",
6
+ "新航通運有限公司",
7
+ "新航通运",
8
+ "Hiyes Logistics",
9
+ "Hiyes Logistics Corporation"
10
+ ],
11
+ "region": {
12
+ "countries": [
13
+ "TW"
14
+ ]
15
+ },
16
+ "brand": {
17
+ "color": "#00af50"
18
+ },
19
+ "selectable": true,
20
+ "timezone": "Asia/Taipei",
21
+ "tracking": {
22
+ "mode": "automatic",
23
+ "adapter": "universal",
24
+ "steps": []
25
+ },
26
+ "capabilities": [],
27
+ "portal": {
28
+ "searchUrl": "https://www.hiyes.com.tw/CargoTracking",
29
+ "canaryUrl": "https://www.hiyes.com.tw/",
30
+ "shows": [],
31
+ "scraped": [],
32
+ "discarded": [],
33
+ "unavailable": []
34
+ },
35
+ "links": [],
36
+ "detection": []
37
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "hiyes",
3
+ "gap": "No public page shows a Hiyes consignment note number.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "hiyes",
3
+ "entries": []
4
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "id": "htt-logistics",
3
+ "displayName": "HTT Logistics",
4
+ "aliases": [
5
+ "昊通国际物流",
6
+ "深圳昊通国际物流有限公司",
7
+ "OOPSTON (昊通国际物流)"
8
+ ],
9
+ "region": {
10
+ "countries": [
11
+ "CN"
12
+ ]
13
+ },
14
+ "brand": {
15
+ "color": "#006dba"
16
+ },
17
+ "selectable": true,
18
+ "timezone": "Asia/Shanghai",
19
+ "tracking": {
20
+ "mode": "automatic",
21
+ "adapter": "universal",
22
+ "steps": []
23
+ },
24
+ "capabilities": [],
25
+ "portal": {
26
+ "searchUrl": "https://tracking.httlogistics.com/tracking.aspx",
27
+ "canaryUrl": "https://httlogistics.com/",
28
+ "shows": [],
29
+ "scraped": [],
30
+ "discarded": [],
31
+ "unavailable": []
32
+ },
33
+ "links": [],
34
+ "detection": []
35
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "htt-logistics",
3
+ "gap": "No public page shows a 昊通国际物流 tracking number.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "htt-logistics",
3
+ "entries": []
4
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "id": "nas-express",
3
+ "displayName": "NAS Express",
4
+ "aliases": [
5
+ "NAS Express Couriers",
6
+ "NAS Express Couriers LLC",
7
+ "NASEX"
8
+ ],
9
+ "region": {
10
+ "countries": [
11
+ "AE"
12
+ ]
13
+ },
14
+ "brand": {
15
+ "color": "#f92205"
16
+ },
17
+ "selectable": true,
18
+ "timezone": "Asia/Dubai",
19
+ "tracking": {
20
+ "mode": "automatic",
21
+ "adapter": "universal",
22
+ "steps": []
23
+ },
24
+ "capabilities": [],
25
+ "portal": {
26
+ "searchUrl": "https://online.nasxpress.com/track/",
27
+ "canaryUrl": "https://nasxpress.com/",
28
+ "shows": [],
29
+ "scraped": [],
30
+ "discarded": [],
31
+ "unavailable": []
32
+ },
33
+ "links": [],
34
+ "detection": []
35
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "nas-express",
3
+ "gap": "No public page shows a NAS Express air waybill number.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "nas-express",
3
+ "entries": []
4
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "id": "odm-express",
3
+ "displayName": "ODM Express",
4
+ "aliases": [],
5
+ "region": {
6
+ "countries": [
7
+ "MX"
8
+ ]
9
+ },
10
+ "brand": {
11
+ "color": "#272f6f"
12
+ },
13
+ "selectable": true,
14
+ "timezone": "America/Mexico_City",
15
+ "tracking": {
16
+ "mode": "automatic",
17
+ "adapter": "universal",
18
+ "steps": []
19
+ },
20
+ "capabilities": [],
21
+ "portal": {
22
+ "url": "https://odmexpress.com.mx/rastreo-2/?rastreo_fall={trackingNumber}",
23
+ "searchUrl": "https://odmexpress.com.mx/rastreo/",
24
+ "canaryUrl": "https://odmexpress.com.mx/",
25
+ "shows": [],
26
+ "scraped": [],
27
+ "discarded": [],
28
+ "unavailable": []
29
+ },
30
+ "links": [
31
+ {
32
+ "domains": [
33
+ "odmexpress.com.mx",
34
+ "www.odmexpress.com.mx"
35
+ ],
36
+ "pathPattern": "^/rastreo-2/?$",
37
+ "params": [
38
+ "rastreo_fall"
39
+ ]
40
+ }
41
+ ],
42
+ "detection": []
43
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "odm-express",
3
+ "gap": "No public page shows an ODM Express guide number.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "odm-express",
3
+ "entries": []
4
+ }
@@ -0,0 +1,51 @@
1
+ {
2
+ "id": "online-worldwide-logistics",
3
+ "displayName": "Online Worldwide",
4
+ "aliases": [
5
+ "Online Worldwide Logistics (欧莱物流)",
6
+ "Online Worldwide Logistics",
7
+ "Guangzhou Online Worldwide Logistics",
8
+ "Online Logistics",
9
+ "欧莱国际货运",
10
+ "欧莱物流供应链",
11
+ "广州市欧莱国际货运代理有限公司"
12
+ ],
13
+ "region": {
14
+ "countries": [
15
+ "CN"
16
+ ]
17
+ },
18
+ "brand": {
19
+ "color": "#8bc43f"
20
+ },
21
+ "selectable": true,
22
+ "timezone": "Asia/Shanghai",
23
+ "tracking": {
24
+ "mode": "automatic",
25
+ "adapter": "universal",
26
+ "steps": []
27
+ },
28
+ "capabilities": [],
29
+ "portal": {
30
+ "url": "https://www.online56.com.cn/cargo-tracking/?sn={trackingNumber}",
31
+ "searchUrl": "https://www.online56.com.cn/cargo-tracking/",
32
+ "canaryUrl": "https://www.online56.com.cn/",
33
+ "shows": [],
34
+ "scraped": [],
35
+ "discarded": [],
36
+ "unavailable": []
37
+ },
38
+ "links": [
39
+ {
40
+ "domains": [
41
+ "www.online56.com.cn",
42
+ "online56.com.cn"
43
+ ],
44
+ "pathPattern": "^/cargo-tracking/?$",
45
+ "params": [
46
+ "sn"
47
+ ]
48
+ }
49
+ ],
50
+ "detection": []
51
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "online-worldwide-logistics",
3
+ "gap": "No public page shows an Online Worldwide waybill number other than the tracker's placeholder example.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "online-worldwide-logistics",
3
+ "entries": []
4
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "id": "ontask-express",
3
+ "displayName": "Ontask Express",
4
+ "aliases": [
5
+ "Ontask Express (广州安时达)",
6
+ "安时达",
7
+ "广州安时达",
8
+ "广州安时达国际供应链有限公司"
9
+ ],
10
+ "region": {
11
+ "countries": [
12
+ "CN"
13
+ ]
14
+ },
15
+ "brand": {
16
+ "color": "#030097"
17
+ },
18
+ "selectable": true,
19
+ "timezone": "Asia/Shanghai",
20
+ "tracking": {
21
+ "mode": "automatic",
22
+ "adapter": "universal",
23
+ "steps": []
24
+ },
25
+ "capabilities": [],
26
+ "portal": {
27
+ "searchUrl": "https://logistics.ontaskksad2d.com/",
28
+ "canaryUrl": "https://www.ontaskd2d.com/",
29
+ "shows": [],
30
+ "scraped": [],
31
+ "discarded": [],
32
+ "unavailable": []
33
+ },
34
+ "links": [],
35
+ "detection": []
36
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "carrier": "ontask-express",
3
+ "gap": "No public page shows an Ontask Express tracking number.",
4
+ "records": []
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "carrier": "ontask-express",
3
+ "entries": []
4
+ }
@@ -0,0 +1,18 @@
1
+ import { type AdapterFactory, type TrackingContext } from '../../core/adapter/index.js';
2
+ import type { CarrierResult } from '../../core/result/index.js';
3
+ import { type StepRecorder } from '../../core/telemetry/index.js';
4
+ /** The fragment SkyBox's public tracking page loads for a number. */
5
+ export declare const SKYBOX_TRACKING = "https://www.skybox.net/TrackingInformation/GetContentPublic";
6
+ /** The fragment's address for one number. */
7
+ export declare function skyboxTrackingUrl(number: string): string;
8
+ export declare class SkyboxTracker {
9
+ private readonly options;
10
+ constructor(options?: {
11
+ fetcher?: typeof fetch;
12
+ recorder?: StepRecorder;
13
+ userAgent?: string;
14
+ });
15
+ private read;
16
+ fetch(raw: string, context?: TrackingContext): Promise<CarrierResult>;
17
+ }
18
+ export declare const adapter: AdapterFactory;
@@ -0,0 +1,49 @@
1
+ import { accepted, recognizeFromLookup } from '../../core/adapter/index.js';
2
+ import { TransportError } from '../../core/errors/index.js';
3
+ import { runSteps } from '../../core/runner/index.js';
4
+ import { firstAttemptMs, networkRetryStep } from '../../core/runner/networkRetry.js';
5
+ import { NOOP_RECORDER } from '../../core/telemetry/index.js';
6
+ import { decodeText, fetchBounded, userAgentOf } from '../../core/transport/index.js';
7
+ import { CARRIER, normalizeSkyboxNumber, parseSkybox, PROVIDER, SKYBOX_MAX_BYTES } from './parser.js';
8
+ /** The fragment SkyBox's public tracking page loads for a number. */
9
+ export const SKYBOX_TRACKING = 'https://www.skybox.net/TrackingInformation/GetContentPublic';
10
+ const REDIRECTS = [301, 302, 303, 307, 308];
11
+ const DEFAULT_BUDGET_MS = 20_000;
12
+ /** The fragment's address for one number. */
13
+ export function skyboxTrackingUrl(number) {
14
+ return `${SKYBOX_TRACKING}?${new URLSearchParams({ tracking: number })}`;
15
+ }
16
+ export class SkyboxTracker {
17
+ options;
18
+ constructor(options = {}) {
19
+ this.options = options;
20
+ }
21
+ async read(number, signal, timeoutMs) {
22
+ const { response, bytes } = await fetchBounded(skyboxTrackingUrl(number), { method: 'GET', signal, headers: {
23
+ Accept: 'text/html', 'Accept-Language': 'en', 'User-Agent': userAgentOf(this.options.userAgent),
24
+ } }, { provider: PROVIDER, timeoutMs: Math.max(1, Math.floor(timeoutMs)), maxBytes: SKYBOX_MAX_BYTES, redirect: 'manual',
25
+ fetcher: this.options.fetcher, allowHttpStatuses: [...REDIRECTS, 404, 410] });
26
+ // The fragment answers HTTP 200 for a number it does not know; a redirect, such as to the site's error page, or a 404 is a moved route.
27
+ if (response.status !== 200)
28
+ throw new TransportError(PROVIDER, 'SkyBox tracking fragment moved', { status: response.status });
29
+ return parseSkybox(decodeText(bytes), number);
30
+ }
31
+ async fetch(raw, context = {}) {
32
+ const number = normalizeSkyboxNumber(raw);
33
+ // A read that fails to reach the tracker, or hangs, is sent once more: the
34
+ // first try gets half of the budget.
35
+ return runSteps({ carrier: CARRIER, budgetMs: context.budgetMs ?? DEFAULT_BUDGET_MS, signal: context.signal,
36
+ recorder: this.options.recorder ?? NOOP_RECORDER }, [
37
+ { id: 'direct', run: ({ signal, remainingMs }) => this.read(number, signal, firstAttemptMs(remainingMs)) },
38
+ networkRetryStep(({ signal, remainingMs }) => this.read(number, signal, remainingMs)),
39
+ ]);
40
+ }
41
+ }
42
+ export const adapter = (environment) => {
43
+ const tracker = new SkyboxTracker({ fetcher: environment.fetcher, recorder: environment.recorder, userAgent: environment.userAgent });
44
+ return {
45
+ id: CARRIER, recordsSteps: true, steps: ['direct', 'retry'],
46
+ track: (input, context) => tracker.fetch(input.number, context),
47
+ recognize: (number, context) => recognizeFromLookup(() => tracker.fetch(number, context), () => accepted(() => normalizeSkyboxNumber(number))),
48
+ };
49
+ };
@@ -21,18 +21,56 @@
21
21
  "timezone": "America/New_York",
22
22
  "tracking": {
23
23
  "mode": "automatic",
24
- "adapter": "universal",
25
- "steps": []
24
+ "adapter": "skybox",
25
+ "steps": [
26
+ "direct",
27
+ "retry"
28
+ ],
29
+ "localClocks": true
26
30
  },
27
- "capabilities": [],
31
+ "capabilities": [
32
+ "history",
33
+ "location"
34
+ ],
28
35
  "portal": {
29
36
  "url": "https://www.skybox.net/TrackingInformation/IndexPublic?tracking={trackingNumber}",
30
37
  "searchUrl": "https://www.skybox.net/TrackingInformation/IndexPublic",
31
38
  "canaryUrl": "https://www.skybox.net/",
32
- "shows": [],
33
- "scraped": [],
34
- "discarded": [],
35
- "unavailable": []
39
+ "shows": [
40
+ "progress_rail",
41
+ "history",
42
+ "location",
43
+ "origin",
44
+ "destination",
45
+ "awb_date",
46
+ "recipient_id",
47
+ "recipient_name",
48
+ "weight",
49
+ "order_contents",
50
+ "tracking_alias"
51
+ ],
52
+ "scraped": [
53
+ "history",
54
+ "location"
55
+ ],
56
+ "discarded": [
57
+ "progress_rail",
58
+ "origin",
59
+ "destination",
60
+ "awb_date",
61
+ "recipient_id",
62
+ "recipient_name",
63
+ "weight",
64
+ "order_contents",
65
+ "tracking_alias"
66
+ ],
67
+ "unavailable": [
68
+ "provider_code",
69
+ "eta",
70
+ "offset_timestamps",
71
+ "service_name",
72
+ "proof_of_delivery"
73
+ ]
36
74
  },
37
75
  "links": [
38
76
  {
@@ -0,0 +1,17 @@
1
+ import type { CarrierResult } from '../../core/result/index.js';
2
+ export declare const PROVIDER = "SkyBox";
3
+ export declare const CARRIER = "skybox";
4
+ export declare const SKYBOX_MAX_BYTES: number;
5
+ /** A number for SkyBox's tracker: twelve digits, with or without the dash it prints after the fourth. */
6
+ export declare function normalizeSkyboxNumber(raw: string): string;
7
+ /**
8
+ * The fragment SkyBox's public tracking page loads for one number,
9
+ * `/TrackingInformation/GetContentPublic?tracking=`, which its server renders.
10
+ * Its search box carries the number asked. A known parcel has a skybill id,
11
+ * a card with SkyBox's number, the number it arrived under, the reception
12
+ * date, the suite, the origin, the destination, the consignee, the weight and
13
+ * the items, a status bar and the tracking table. SkyBox's number must be the
14
+ * one asked. An unknown number has the skybill id 0, one message and no card.
15
+ * Only the tracking table is kept.
16
+ */
17
+ export declare function parseSkybox(html: string, raw: string): CarrierResult;
@@ -0,0 +1,125 @@
1
+ import { load } from 'cheerio';
2
+ import { normalizeTrackingNumber } from '../../core/detection/index.js';
3
+ import { ChallengeError, IndeterminateError, InvalidInputError, NoHistoryError, NotFoundError, SchemaError } from '../../core/errors/index.js';
4
+ import { languageStageStatus } from '../../core/status/index.js';
5
+ import { calendarDay } from '../../core/time/index.js';
6
+ import { clean } from '../../core/transport/index.js';
7
+ import { skyboxStage } from './status.js';
8
+ export const PROVIDER = 'SkyBox';
9
+ export const CARRIER = 'skybox';
10
+ // A fragment is about 21 kB.
11
+ export const SKYBOX_MAX_BYTES = 512 * 1024;
12
+ // Twelve digits, which the tracker prints as four digits, a dash and eight digits.
13
+ const NUMBER = /^\d{12}$/;
14
+ const SHOWN_NUMBER = /^\d{4}-?\d{8}$/;
15
+ // "04/24/2025 18:00": month, day, year and a wall clock to the minute with no zone.
16
+ const CLOCK = /^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;
17
+ // Bot checks and firewall refusals that could stand in for the fragment.
18
+ const CHALLENGE = /_cf_chl_opt|cf-turnstile|<title>\s*(?:Just a moment|Attention Required!|Access Denied)|g-recaptcha|h-captcha|The requested URL was rejected|Request Rejected/i;
19
+ // The whole message the fragment shows for a number the tracker does not know.
20
+ const NOT_FOUND = 'The tracking number does not exists';
21
+ const MAX_EVENTS = 200;
22
+ /** A number for SkyBox's tracker: twelve digits, with or without the dash it prints after the fourth. */
23
+ export function normalizeSkyboxNumber(raw) {
24
+ const number = typeof raw === 'string' && raw.length <= 64 ? normalizeTrackingNumber(raw) : '';
25
+ if (!NUMBER.test(number))
26
+ throw new InvalidInputError(PROVIDER, 'SkyBox numbers are twelve digits');
27
+ return number;
28
+ }
29
+ /** A row's wall clock, to the minute. */
30
+ function wallClock(text) {
31
+ const parts = CLOCK.exec(text);
32
+ if (parts) {
33
+ const [month, day, year, hour, minute] = parts.slice(1).map(Number);
34
+ const date = calendarDay(year, month, day);
35
+ if (date && year >= 2000 && hour <= 23 && minute <= 59)
36
+ return `${date}T${parts[4]}:${parts[5]}:00`;
37
+ }
38
+ throw new SchemaError(PROVIDER, 'SkyBox returned an invalid scan time');
39
+ }
40
+ /** A hidden or disabled field's value, or null when the fragment has no such field. */
41
+ function field($, id) {
42
+ const input = $(`input#${id}`);
43
+ if (input.length > 1)
44
+ throw new SchemaError(PROVIDER, 'SkyBox returned several parcels');
45
+ return input.length ? clean(input.attr('value') ?? '', 80) : null;
46
+ }
47
+ /** The tracking table, newest first: each row gives a scan's wording, its place and its wall clock. */
48
+ function eventsOf($) {
49
+ const card = $('#collapse-tracking');
50
+ if (card.length > 1)
51
+ throw new SchemaError(PROVIDER, 'SkyBox returned several histories');
52
+ const rows = card.find('table tbody tr').toArray();
53
+ if (rows.length > MAX_EVENTS)
54
+ throw new SchemaError(PROVIDER, 'SkyBox returned an invalid history');
55
+ const events = rows.map((row) => {
56
+ const cells = $(row).children('td').toArray().map((cell) => clean($(cell).text(), 300));
57
+ const [description, location, clock] = cells;
58
+ if (cells.length !== 3 || !description || clock === undefined)
59
+ throw new SchemaError(PROVIDER, 'SkyBox returned an invalid scan');
60
+ const staged = skyboxStage(description);
61
+ return {
62
+ local_time: wallClock(clock),
63
+ ...(location ? { location } : {}),
64
+ description,
65
+ ...(staged ? { stage: staged.stage, stage_source: staged.source } : {}),
66
+ };
67
+ });
68
+ // Newest first; the table lists them so, and a stable sort keeps scans of one minute in its order.
69
+ return events.sort((left, right) => right.local_time.localeCompare(left.local_time));
70
+ }
71
+ /**
72
+ * The fragment SkyBox's public tracking page loads for one number,
73
+ * `/TrackingInformation/GetContentPublic?tracking=`, which its server renders.
74
+ * Its search box carries the number asked. A known parcel has a skybill id,
75
+ * a card with SkyBox's number, the number it arrived under, the reception
76
+ * date, the suite, the origin, the destination, the consignee, the weight and
77
+ * the items, a status bar and the tracking table. SkyBox's number must be the
78
+ * one asked. An unknown number has the skybill id 0, one message and no card.
79
+ * Only the tracking table is kept.
80
+ */
81
+ export function parseSkybox(html, raw) {
82
+ const number = normalizeSkyboxNumber(raw);
83
+ if (CHALLENGE.test(html.slice(0, 64_000)))
84
+ throw new ChallengeError(PROVIDER, 'SkyBox answered with a browser check');
85
+ const $ = load(html);
86
+ $('script, style, noscript').remove();
87
+ if ($('#trackinginfo-search-content').length !== 1)
88
+ throw new SchemaError(PROVIDER, 'SkyBox returned an unexpected page');
89
+ const asked = field($, 'trackinginfosearch-txtTracking');
90
+ if (!asked)
91
+ throw new SchemaError(PROVIDER, 'SkyBox returned a fragment without the number asked');
92
+ if (normalizeTrackingNumber(asked) !== number)
93
+ throw new IndeterminateError(PROVIDER, 'SkyBox answered for another number');
94
+ const skybill = field($, 'hdn_trackinginfosearch_skybillid');
95
+ if (skybill === null || !/^\d+$/.test(skybill))
96
+ throw new SchemaError(PROVIDER, 'SkyBox returned a fragment without its skybill');
97
+ const sections = $('.trackinginfosearch-section');
98
+ if (Number(skybill) === 0) {
99
+ const message = clean($('#search-msg').text(), 120);
100
+ if (sections.length || message !== NOT_FOUND)
101
+ throw new SchemaError(PROVIDER, 'SkyBox returned an unexpected fragment');
102
+ throw new NotFoundError(PROVIDER, 'SkyBox does not know this number');
103
+ }
104
+ const shown = field($, 'trackinginfosearch-lblTrackingNumber');
105
+ if (!sections.length || !shown || !SHOWN_NUMBER.test(shown))
106
+ throw new SchemaError(PROVIDER, 'SkyBox returned a parcel without its number');
107
+ // The tracker also finds a parcel by the number it arrived under; only SkyBox's own number is taken.
108
+ if (normalizeTrackingNumber(shown) !== number)
109
+ throw new IndeterminateError(PROVIDER, 'SkyBox answered for another parcel');
110
+ const events = eventsOf($);
111
+ const newest = events[0];
112
+ if (!newest)
113
+ throw new NoHistoryError(PROVIDER);
114
+ const current = events.find((event) => event.stage);
115
+ const stage = current?.stage;
116
+ return {
117
+ status: stage ? languageStageStatus(stage) : 'unknown',
118
+ ...(stage ? { current_stage: stage, current_stage_source: current.stage_source } : {}),
119
+ last_status_text: newest.description,
120
+ last_update: null,
121
+ last_update_local: newest.local_time,
122
+ expected_delivery: null,
123
+ events,
124
+ };
125
+ }
@@ -0,0 +1,7 @@
1
+ import { type ClassifiedWording, type Stage } from '../../core/status/index.js';
2
+ import { type CarrierStatusMap } from '../../core/status/statusMap.js';
3
+ /** The stage SkyBox's map gives a wording in `normalizeStatusWording` form; one it does not list has none. */
4
+ export declare function skyboxMappedStage(wording: string): Stage | undefined;
5
+ /** A scan's stage: the map, else the shared wording rules, else nothing. */
6
+ export declare function skyboxStage(wording: string): ClassifiedWording | null;
7
+ export declare const statusMap: CarrierStatusMap;