universal-parcel-scraper 0.3.0 → 0.3.1-main.311

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  **Parcel tracking that asks the carrier directly, from your own machine.**
8
8
 
9
- The engine behind [Peek](https://github.com/plhery/delivery-tracker), the open-source parcel tracker for iPhone and the web.
9
+ The engine behind [Peek](https://peektracker.com) ([GitHub](https://github.com/plhery/peek-delivery-tracker)), the open-source parcel tracker for iPhone and the web.
10
10
 
11
11
  [![npm](https://img.shields.io/npm/v/universal-parcel-scraper)](https://www.npmjs.com/package/universal-parcel-scraper)
12
12
  [![CI](https://github.com/plhery/universal-parcel-scraper/actions/workflows/ci.yml/badge.svg)](https://github.com/plhery/universal-parcel-scraper/actions/workflows/ci.yml)
@@ -27,7 +27,7 @@ The engine behind [Peek](https://github.com/plhery/delivery-tracker), the open-s
27
27
  Give it a tracking number. It finds the carrier, fetches the history from the carrier's own
28
28
  site and returns the same JSON for every carrier. No account, no API key.
29
29
 
30
- It is the tracking engine of [Peek](https://github.com/plhery/delivery-tracker), usable on
30
+ It is the tracking engine of [Peek](https://github.com/plhery/peek-delivery-tracker), usable on
31
31
  its own as a command, a Node library or an HTTP server.
32
32
 
33
33
  ## Benchmark
@@ -120,7 +120,7 @@ settings, such as `SCRAPER_TOKEN` and `SCRAPER_TRUSTED_PROXIES`, in [.env.exampl
120
120
 
121
121
  ## What you can build with it
122
122
 
123
- - A parcel-tracking app, like [Peek](https://github.com/plhery/delivery-tracker).
123
+ - A parcel-tracking app, like [Peek](https://github.com/plhery/peek-delivery-tracker).
124
124
  - A [Home Assistant sensor](examples/home-assistant.yaml) for the parcel you are waiting on.
125
125
  - Order status inside a shop or help desk, from any backend that speaks HTTP.
126
126
  - Tracking numbers pulled out of shipping emails: `detect` reads pasted text and links.
package/dist/app.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  export * from './core/catalog/parcel.js';
9
9
  export * from './core/catalog/hints.js';
10
10
  export * from './core/time/result.js';
11
- export { sameInstantIdentityPolicy, type SameInstantIdentityPolicy } from './core/catalog/eventIdentity.js';
11
+ export { sameInstantIdentityPolicy, type SameInstantIdentityPolicy, type SameInstantScan } from './core/catalog/eventIdentity.js';
12
12
  export { universalCarrierHints } from './providers/shared/hints.js';
13
13
  export { recognitionAskedCarriers } from './core/catalog/recognition.js';
14
14
  export { countryFlag, countryName, trackingLocationCountry, trackingPlace, type TrackingPlace } from './places/trackingLocation.js';
@@ -0,0 +1,2 @@
1
+ import type { SameInstantIdentityPolicy } from '../../core/catalog/eventIdentity.js';
2
+ export declare const sameInstantIdentityPolicy: SameInstantIdentityPolicy;
@@ -0,0 +1,15 @@
1
+ function normalized(value) {
2
+ return value.replace(/\s+/g, ' ').trim().toLocaleLowerCase('en-US');
3
+ }
4
+ // UPS can add a location later. Its wording distinguishes scans sharing a clock.
5
+ export const sameInstantIdentityPolicy = {
6
+ sourceCarrierId: 'ups', storedSources: ['ups'], requireProviderCode: false,
7
+ matches(incoming, stored) {
8
+ const wording = normalized(incoming.description);
9
+ const location = normalized(incoming.location);
10
+ const savedLocation = normalized(stored.location);
11
+ return incoming.stage !== '' && incoming.stage !== 'unknown' && incoming.stage === stored.stage
12
+ && wording !== '' && wording === normalized(stored.description)
13
+ && (!location || !savedLocation || location === savedLocation);
14
+ },
15
+ };
@@ -1,8 +1,18 @@
1
+ /** Scan evidence available to the app before it reuses a stored identity. */
2
+ export interface SameInstantScan {
3
+ readonly stage: string;
4
+ readonly description: string;
5
+ readonly location: string;
6
+ readonly providerCode: string;
7
+ }
1
8
  /** Carrier evidence the parcel app uses when updating a stored scan in place. */
2
9
  export interface SameInstantIdentityPolicy {
3
10
  readonly sourceCarrierId: string;
4
11
  readonly storedSources: readonly string[];
5
12
  readonly requireProviderCode: boolean;
13
+ readonly matches?: (incoming: SameInstantScan, stored: SameInstantScan) => boolean;
6
14
  }
7
15
  /** Unlisted sources cannot identify a reworded scan by its instant alone. */
8
- export declare function sameInstantIdentityPolicy(sourceCarrierId: string): SameInstantIdentityPolicy | undefined;
16
+ export declare function sameInstantIdentityPolicy(sourceCarrierId: string, options?: {
17
+ supportsScanMatching?: boolean;
18
+ }): SameInstantIdentityPolicy | undefined;
@@ -1,7 +1,10 @@
1
1
  import { sameInstantIdentityPolicy as dpd } from '../../carriers/dpd/app.js';
2
2
  import { sameInstantIdentityPolicy as indiaPost } from '../../carriers/india-post/app.js';
3
- const policies = new Map([dpd, indiaPost].map((policy) => [policy.sourceCarrierId, policy]));
3
+ import { sameInstantIdentityPolicy as ups } from '../../carriers/ups/app.js';
4
+ const policies = new Map([dpd, indiaPost, ups].map((policy) => [policy.sourceCarrierId, policy]));
4
5
  /** Unlisted sources cannot identify a reworded scan by its instant alone. */
5
- export function sameInstantIdentityPolicy(sourceCarrierId) {
6
- return policies.get(sourceCarrierId);
6
+ export function sameInstantIdentityPolicy(sourceCarrierId, options = {}) {
7
+ const policy = policies.get(sourceCarrierId);
8
+ // Older app versions only check the clock and provider code.
9
+ return policy?.matches && !options.supportsScanMatching ? undefined : policy;
7
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universal-parcel-scraper",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-main.311",
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",