universal-parcel-scraper 0.34.0-main.379 → 0.34.1-main.381

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/data/catalog.json CHANGED
@@ -354,8 +354,8 @@
354
354
  "adapter": "postlogistics",
355
355
  "recognitionRank": 26
356
356
  },
357
- "canaryUrl": "https://tracking.postlogistics.ch/public/trackandtrace",
358
- "trackingUrlTemplate": "https://tracking.postlogistics.ch/public/trackandtrace/{trackingNumber}",
357
+ "canaryUrl": "https://apv.swisspost-cargo.com/public/trackandtrace",
358
+ "trackingUrlTemplate": "https://apv.swisspost-cargo.com/public/trackandtrace/{trackingNumber}",
359
359
  "linkRules": [
360
360
  {
361
361
  "domains": [
@@ -390,8 +390,8 @@ var ce = {
390
390
  adapter: "postlogistics",
391
391
  recognitionRank: 26
392
392
  },
393
- canaryUrl: "https://tracking.postlogistics.ch/public/trackandtrace",
394
- trackingUrlTemplate: "https://tracking.postlogistics.ch/public/trackandtrace/{trackingNumber}",
393
+ canaryUrl: "https://apv.swisspost-cargo.com/public/trackandtrace",
394
+ trackingUrlTemplate: "https://apv.swisspost-cargo.com/public/trackandtrace/{trackingNumber}",
395
395
  linkRules: [{
396
396
  domains: ["tracking.postlogistics.ch"],
397
397
  path: "^/public/trackandtrace/([^/?#]+)/?$"
@@ -35,14 +35,17 @@ export interface DPDTrackerOptions {
35
35
  trawl?: TrawlClient | null;
36
36
  recorder?: StepRecorder;
37
37
  userAgent?: string;
38
- /** A further German tier, and the failures of the guest tier it may answer after. */
38
+ /** A further German tier, ahead of the guest tier when no postcode is given. */
39
39
  app?: DPDAppTier;
40
40
  }
41
41
  export interface DPDAppTier {
42
+ /** `leads` when the guest tier is still to come and needs time left. */
42
43
  run(number: string, context: {
43
44
  signal: AbortSignal;
44
45
  timeoutMs: number;
46
+ leads: boolean;
45
47
  }): Promise<CarrierResult>;
48
+ /** The failures of either tier the other may answer after. */
46
49
  recovers(error: unknown): boolean;
47
50
  }
48
51
  export declare class DPDTracker {
@@ -550,11 +550,23 @@ export class DPDTracker {
550
550
  const kind = carrierErrorKind(error);
551
551
  return !context.signal?.aborted && kind !== null && PAGE_RECOVERS.has(kind);
552
552
  };
553
+ const app = this.app;
554
+ const appRecovers = (error) => !context.signal?.aborted && app.recovers(error);
555
+ // Without a postcode the app's scans are the richer history; with one, the
556
+ // guest tier's verified reply comes first.
557
+ const appLeads = app !== undefined && !resolvedPostcode;
558
+ const appStep = (leads) => ({
559
+ id: 'app',
560
+ ...(leads ? {} : { recovers: appRecovers }),
561
+ run: ({ signal, remainingMs }) => app.run(trackingNumber, { signal, timeoutMs: remainingMs, leads }),
562
+ });
553
563
  const result = await runSteps({
554
564
  carrier, budgetMs: lookup.budgetMs, signal: lookup.signal, recorder: this.recorder,
555
565
  }, [
566
+ ...(appLeads ? [appStep(true)] : []),
556
567
  {
557
568
  id: 'direct',
569
+ ...(appLeads ? { recovers: appRecovers } : {}),
558
570
  run: () => this.apiFetch(trackingNumber, resolvedPostcode, lookup).catch((error) => {
559
571
  // The signal ends the guest tier a moment before the runner counts
560
572
  // the budget as spent: the tier reports the budget itself, so the
@@ -569,11 +581,7 @@ export class DPDTracker {
569
581
  id: 'page',
570
582
  recovers: pageRecovers,
571
583
  run: ({ previousError }) => this.pageFetch(trackingNumber, previousError !== undefined, lookup),
572
- }] : this.app ? [{
573
- id: 'app',
574
- recovers: (error) => !context.signal?.aborted && this.app.recovers(error),
575
- run: ({ signal, remainingMs }) => this.app.run(trackingNumber, { signal, timeoutMs: remainingMs }),
576
- }] : []),
584
+ }] : app && !appLeads ? [appStep(false)] : []),
577
585
  ]);
578
586
  result.tracking_url = this.country === 'DE'
579
587
  ? `https://tracking.dpd.de/status/en_US/parcel/${trackingNumber}`
@@ -1,3 +1,3 @@
1
1
  import type { AdapterFactory } from '../../core/adapter/index.js';
2
- /** Germany uses the same guest protocol, with its own business-unit selector, then the German app's service. */
2
+ /** Germany reads the German app's service, then the guest protocol with its own business-unit selector. */
3
3
  export declare const adapter: AdapterFactory;
@@ -1,8 +1,9 @@
1
1
  import { CarrierError, carrierErrorKind } from '../../core/errors/index.js';
2
- import { recoverableByDefault } from '../../core/runner/index.js';
3
2
  import { DPDTracker } from '../dpd/adapter.js';
4
3
  import { DPD_DE_OTHER_COUNTRY, DpdDeAppClient } from './app.js';
5
- /** Germany uses the same guest protocol, with its own business-unit selector, then the German app's service. */
4
+ /** Left to the guest API when the app's session is still opening ahead of it. */
5
+ const GUEST_RESERVE_MS = 20_000;
6
+ /** Germany reads the German app's service, then the guest protocol with its own business-unit selector. */
6
7
  export const adapter = (environment) => {
7
8
  const app = new DpdDeAppClient({ fetcher: environment.fetcher, userAgent: environment.userAgent });
8
9
  const tracker = new DPDTracker({
@@ -12,14 +13,18 @@ export const adapter = (environment) => {
12
13
  recorder: environment.recorder,
13
14
  userAgent: environment.userAgent,
14
15
  app: {
15
- run: (number, context) => app.track(number, context),
16
- // The app reads the same parcel, so it cannot place another country's delivery in Germany.
17
- recovers: error => (recoverableByDefault(error) || carrierErrorKind(error) === 'schema')
16
+ run: (number, { signal, timeoutMs, leads }) => app.track(number, {
17
+ signal, timeoutMs, sessionWaitMs: leads ? Math.max(0, timeoutMs - GUEST_RESERVE_MS) : timeoutMs,
18
+ }),
19
+ // Each service has its own host, limits and outages, so either answers when
20
+ // the other fails. Both read the same parcel: neither can place another
21
+ // country's delivery in Germany, nor find a parcel the guest API does not know.
22
+ recovers: error => carrierErrorKind(error) !== 'not_found'
18
23
  && !(error instanceof CarrierError && error.reason === DPD_DE_OTHER_COUNTRY),
19
24
  },
20
25
  });
21
26
  return {
22
- id: 'dpd-de', recordsSteps: true, steps: ['direct', 'app'],
27
+ id: 'dpd-de', recordsSteps: true, steps: ['app', 'direct'],
23
28
  track: (input, context) => tracker.fetch(input.number, input.postcode ?? '', context),
24
29
  };
25
30
  };
@@ -4,6 +4,8 @@ import { type XmlNode } from '../../core/transport/xml.js';
4
4
  export declare const DPD_DE_APP_API = "https://api.paketnavigator.de/services/v1/Navigator3Service.asmx";
5
5
  /** Activity the service places outside Germany; the app tier would read the same parcel. */
6
6
  export declare const DPD_DE_OTHER_COUNTRY = "other_country";
7
+ /** The lookup stopped waiting for the session, which keeps opening for the next one. */
8
+ export declare const DPD_DE_SESSION_OPENING = "session_opening";
7
9
  export interface DpdDePartner {
8
10
  name: string;
9
11
  token: string;
@@ -18,6 +20,7 @@ export declare function parseDpdDeApp(data: XmlNode, scans: XmlNode, number: str
18
20
  /**
19
21
  * The German app's SOAP service. Tracking needs an anonymous device session, which the
20
22
  * service takes tens of seconds to open and then accepts for hours: one is kept per client.
23
+ * The opening runs on its own clock, so a lookup that stops waiting leaves it to the next.
21
24
  */
22
25
  export declare class DpdDeAppClient {
23
26
  #private;
@@ -27,11 +30,16 @@ export declare class DpdDeAppClient {
27
30
  userAgent?: string;
28
31
  now?: () => number;
29
32
  });
33
+ /** `sessionWaitMs` bounds the wait for a session still opening; the whole `timeoutMs` by default. */
30
34
  track(number: string, options: {
31
35
  signal: AbortSignal;
32
36
  timeoutMs: number;
37
+ sessionWaitMs?: number;
33
38
  }): Promise<CarrierResult>;
34
- /** One session for every lookup; the lookup that opens it lends its signal, the others only wait. */
39
+ /**
40
+ * One session for every lookup. The opening runs while a lookup that asked for it is still
41
+ * running, even one that stopped waiting; each lookup waits until its signal or `waitMs` ends.
42
+ */
35
43
  private session;
36
44
  private call;
37
45
  }
@@ -6,9 +6,13 @@ import { xmlDocument } from '../../core/transport/xml.js';
6
6
  export const DPD_DE_APP_API = 'https://api.paketnavigator.de/services/v1/Navigator3Service.asmx';
7
7
  /** Activity the service places outside Germany; the app tier would read the same parcel. */
8
8
  export const DPD_DE_OTHER_COUNTRY = 'other_country';
9
+ /** The lookup stopped waiting for the session, which keeps opening for the next one. */
10
+ export const DPD_DE_SESSION_OPENING = 'session_opening';
9
11
  const SOAP = 'http://schemas.xmlsoap.org/soap/envelope/';
10
12
  const SERVICE = 'https://cloud.dpd.com/';
11
13
  const MAX_BYTES = 2_000_000;
14
+ /** Opening a session has taken up to 42 seconds. */
15
+ const SESSION_OPEN_MS = 75_000;
12
16
  // Shared partner credentials of the public app, distributed with the maintainer's approval.
13
17
  const PARTNER = { name: 'Android Paketnavigator3', token: 'A33363237662F5945576', password: '272 WetFd2mpXrgD' };
14
18
  /** The app's progress rail: one coarse state for the whole parcel. */
@@ -120,6 +124,7 @@ export function parseDpdDeApp(data, scans, number) {
120
124
  /**
121
125
  * The German app's SOAP service. Tracking needs an anonymous device session, which the
122
126
  * service takes tens of seconds to open and then accepts for hours: one is kept per client.
127
+ * The opening runs on its own clock, so a lookup that stops waiting leaves it to the next.
123
128
  */
124
129
  export class DpdDeAppClient {
125
130
  #partner;
@@ -135,6 +140,7 @@ export class DpdDeAppClient {
135
140
  this.#userAgent = userAgentOf(options.userAgent);
136
141
  this.#now = options.now ?? Date.now;
137
142
  }
143
+ /** `sessionWaitMs` bounds the wait for a session still opening; the whole `timeoutMs` by default. */
138
144
  async track(number, options) {
139
145
  if (!/^\d{14}$/.test(number))
140
146
  throw new TypeError('DPD Germany app tracking takes 14 digits');
@@ -142,7 +148,7 @@ export class DpdDeAppClient {
142
148
  const left = () => Math.max(1, Math.floor(deadline - performance.now()));
143
149
  try {
144
150
  for (let attempt = 0;; attempt += 1) {
145
- const session = await this.session(options.signal, left());
151
+ const session = await this.session(options.signal, Math.min(left(), options.sessionWaitMs ?? Infinity));
146
152
  try {
147
153
  const data = await this.call('getTrackingData', { SessionToken: session, ParcelNo: number, DeliveryZipCode: '',
148
154
  UpdateNewDeliveryData: 'false', addParcelIfNoTrackingdataAvailable: 'false', ParcelFlowTypeID: 'receiving' }, options.signal, left());
@@ -168,32 +174,60 @@ export class DpdDeAppClient {
168
174
  throw new TransportError('DPD Germany', 'DPD Germany app request failed');
169
175
  }
170
176
  }
171
- /** One session for every lookup; the lookup that opens it lends its signal, the others only wait. */
172
- async session(signal, timeoutMs) {
177
+ /**
178
+ * One session for every lookup. The opening runs while a lookup that asked for it is still
179
+ * running, even one that stopped waiting; each lookup waits until its signal or `waitMs` ends.
180
+ */
181
+ async session(signal, waitMs) {
173
182
  if (this.#session)
174
183
  return this.#session;
184
+ signal.throwIfAborted();
175
185
  if (!this.#opening) {
176
- const opening = this.call('getSessionFullState', { SessionToken: '', DeviceData: {
186
+ const controller = new AbortController();
187
+ const holders = new Set();
188
+ const token = this.call('getSessionFullState', { SessionToken: '', DeviceData: {
177
189
  HardwareID: this.#device, BootSystemID: 'Android_Phone', Version: '15', AppVersion: '4.2.0',
178
- } }, signal, timeoutMs).then(result => {
179
- const token = scalar(one(result, 'SessionFullState'), 'SessionToken', 600);
180
- if (!/^[A-Za-z0-9+/=]{16,512}$/.test(token))
190
+ } }, controller.signal, SESSION_OPEN_MS).then(result => {
191
+ const value = scalar(one(result, 'SessionFullState'), 'SessionToken', 600);
192
+ if (!/^[A-Za-z0-9+/=]{16,512}$/.test(value))
181
193
  invalid();
182
- return this.#session = token;
194
+ return this.#session = value;
183
195
  });
196
+ const release = () => {
197
+ for (const holder of holders)
198
+ if (holder.aborted)
199
+ holders.delete(holder);
200
+ if (!holders.size)
201
+ controller.abort(new Error('No lookup is waiting for the DPD Germany session'));
202
+ };
203
+ const opening = { token, holders, release };
184
204
  this.#opening = opening;
185
- void opening.catch(() => undefined).finally(() => { if (this.#opening === opening)
186
- this.#opening = null; });
205
+ void token.catch(() => undefined).finally(() => {
206
+ if (this.#opening === opening)
207
+ this.#opening = null;
208
+ for (const holder of holders)
209
+ holder.removeEventListener('abort', release);
210
+ });
211
+ }
212
+ const { token, holders, release } = this.#opening;
213
+ if (!holders.has(signal)) {
214
+ holders.add(signal);
215
+ signal.addEventListener('abort', release, { once: true });
187
216
  }
188
- const shared = this.#opening;
189
- signal.throwIfAborted();
190
217
  let leave;
191
- const left = new Promise((_resolve, reject) => { leave = () => reject(signal.reason); });
218
+ let timer;
219
+ const left = new Promise((_resolve, reject) => {
220
+ leave = () => reject(signal.reason);
221
+ timer = setTimeout(() => reject(new IndeterminateError('DPD Germany', 'DPD Germany app session is still opening', {
222
+ reason: DPD_DE_SESSION_OPENING,
223
+ })), Math.max(0, Math.min(waitMs, SESSION_OPEN_MS)));
224
+ });
192
225
  signal.addEventListener('abort', leave, { once: true });
193
226
  try {
194
- return await Promise.race([shared, left]);
227
+ return await Promise.race([token, left]);
195
228
  }
196
229
  finally {
230
+ clearTimeout(timer);
197
231
  signal.removeEventListener('abort', leave);
198
232
  }
199
233
  }
@@ -18,8 +18,8 @@
18
18
  "mode": "automatic",
19
19
  "adapter": "dpd-de",
20
20
  "steps": [
21
- "direct",
22
- "app"
21
+ "app",
22
+ "direct"
23
23
  ],
24
24
  "requirements": [
25
25
  {
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * PostLogistics tracking.
3
3
  *
4
- * The public tracker at `tracking.postlogistics.ch` posts the identifier to
5
- * `eosapi.postlogistics.ch/api/trackandtrace/public`. The response says what
6
- * the identifier was:
4
+ * PostLogistics now trades as Swiss Post Cargo, and its tracker moved to
5
+ * `apv.swisspost-cargo.com`, which posts the identifier to
6
+ * `eosapi.swisspost-cargo.com/api/trackandtrace/public`. The former
7
+ * `postlogistics.ch` hosts answer 404. The response says what the identifier
8
+ * was:
7
9
  *
8
10
  * - `Type` 1: a barcode. The answer may contain several shipments, so only the
9
11
  * one whose `Identifier` equals the requested barcode is read.
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * PostLogistics tracking.
3
3
  *
4
- * The public tracker at `tracking.postlogistics.ch` posts the identifier to
5
- * `eosapi.postlogistics.ch/api/trackandtrace/public`. The response says what
6
- * the identifier was:
4
+ * PostLogistics now trades as Swiss Post Cargo, and its tracker moved to
5
+ * `apv.swisspost-cargo.com`, which posts the identifier to
6
+ * `eosapi.swisspost-cargo.com/api/trackandtrace/public`. The former
7
+ * `postlogistics.ch` hosts answer 404. The response says what the identifier
8
+ * was:
7
9
  *
8
10
  * - `Type` 1: a barcode. The answer may contain several shipments, so only the
9
11
  * one whose `Identifier` equals the requested barcode is read.
@@ -28,7 +30,7 @@ import { postlogisticsIdentifier } from './number.js';
28
30
  import { POSTLOGISTICS_IMAGE_CODE, postlogisticsStage, postlogisticsStatus } from './status.js';
29
31
  const PROVIDER = 'PostLogistics';
30
32
  const UPSTREAM = 'PostLogistics tracking';
31
- const TRACK_URL = 'https://eosapi.postlogistics.ch/api/trackandtrace/public?culture=fr-FR';
33
+ const TRACK_URL = 'https://eosapi.swisspost-cargo.com/api/trackandtrace/public?culture=fr-FR';
32
34
  const DEFAULT_TIMEOUT_MS = 15_000;
33
35
  const BASE_HEADERS = {
34
36
  Accept: 'application/json, text/plain, */*',
@@ -146,8 +148,8 @@ export class PostlogisticsTracker {
146
148
  ...BASE_HEADERS,
147
149
  'User-Agent': this.userAgent,
148
150
  'Content-Type': 'application/json',
149
- Origin: 'https://tracking.postlogistics.ch',
150
- Referer: 'https://tracking.postlogistics.ch/',
151
+ Origin: 'https://apv.swisspost-cargo.com',
152
+ Referer: 'https://apv.swisspost-cargo.com/',
151
153
  },
152
154
  body: JSON.stringify({ Identifier: identifier }),
153
155
  signal: budget.signal,
@@ -28,8 +28,8 @@
28
28
  "eta"
29
29
  ],
30
30
  "portal": {
31
- "url": "https://tracking.postlogistics.ch/public/trackandtrace/{trackingNumber}",
32
- "canaryUrl": "https://tracking.postlogistics.ch/public/trackandtrace",
31
+ "url": "https://apv.swisspost-cargo.com/public/trackandtrace/{trackingNumber}",
32
+ "canaryUrl": "https://apv.swisspost-cargo.com/public/trackandtrace",
33
33
  "shows": [
34
34
  "status",
35
35
  "history",
@@ -354,8 +354,8 @@
354
354
  "adapter": "postlogistics",
355
355
  "recognitionRank": 26
356
356
  },
357
- "canaryUrl": "https://tracking.postlogistics.ch/public/trackandtrace",
358
- "trackingUrlTemplate": "https://tracking.postlogistics.ch/public/trackandtrace/{trackingNumber}",
357
+ "canaryUrl": "https://apv.swisspost-cargo.com/public/trackandtrace",
358
+ "trackingUrlTemplate": "https://apv.swisspost-cargo.com/public/trackandtrace/{trackingNumber}",
359
359
  "linkRules": [
360
360
  {
361
361
  "domains": [
@@ -236,8 +236,8 @@ export declare const CARRIER_CATALOG: {
236
236
  readonly adapter: "postlogistics";
237
237
  readonly recognitionRank: 26;
238
238
  };
239
- readonly canaryUrl: "https://tracking.postlogistics.ch/public/trackandtrace";
240
- readonly trackingUrlTemplate: "https://tracking.postlogistics.ch/public/trackandtrace/{trackingNumber}";
239
+ readonly canaryUrl: "https://apv.swisspost-cargo.com/public/trackandtrace";
240
+ readonly trackingUrlTemplate: "https://apv.swisspost-cargo.com/public/trackandtrace/{trackingNumber}";
241
241
  readonly linkRules: readonly [{
242
242
  readonly domains: readonly ["tracking.postlogistics.ch"];
243
243
  readonly path: "^/public/trackandtrace/([^/?#]+)/?$";
@@ -355,8 +355,8 @@ export const CARRIER_CATALOG = {
355
355
  "adapter": "postlogistics",
356
356
  "recognitionRank": 26
357
357
  },
358
- "canaryUrl": "https://tracking.postlogistics.ch/public/trackandtrace",
359
- "trackingUrlTemplate": "https://tracking.postlogistics.ch/public/trackandtrace/{trackingNumber}",
358
+ "canaryUrl": "https://apv.swisspost-cargo.com/public/trackandtrace",
359
+ "trackingUrlTemplate": "https://apv.swisspost-cargo.com/public/trackandtrace/{trackingNumber}",
360
360
  "linkRules": [
361
361
  {
362
362
  "domains": [
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "Universal Parcel Scraper",
5
- "version": "0.34.0"
5
+ "version": "0.34.1"
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.34.0-main.379",
3
+ "version": "0.34.1-main.381",
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",