universal-parcel-scraper 0.26.0-main.368 → 0.26.1-main.369
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,16 +10,18 @@ export const UKRPOSHTA_API = 'https://track.ukrposhta.ua/php/track_new.php';
|
|
|
10
10
|
export const UKRPOSHTA_STATUS_API = 'https://www.ukrposhta.ua/status-tracking/0.0.1/statuses';
|
|
11
11
|
const MAX_BYTES = 1_000_000;
|
|
12
12
|
const DIRECT_TIMEOUT_MS = 10_000;
|
|
13
|
+
// The Android app's shared application bearer is deliberately distributed with this adapter.
|
|
14
|
+
const APPLICATION_BEARER = 'c3e02b53-3b1d-386e-b676-141ffa054c57';
|
|
13
15
|
/** The API's bearer, or null when none is configured or the value could not be a header. */
|
|
14
16
|
function bearer(value) {
|
|
15
17
|
const token = value?.trim().replace(/^Bearer\s+/i, '') ?? '';
|
|
16
18
|
return /^[\w.~+/=-]{8,512}$/.test(token) ? token : null;
|
|
17
19
|
}
|
|
18
|
-
async function readStatuses(number, token, signal, timeoutMs, fetcher) {
|
|
20
|
+
async function readStatuses(number, token, signal, timeoutMs, userAgent = 'Mozilla/5.0', fetcher) {
|
|
19
21
|
const url = new URL(UKRPOSHTA_STATUS_API);
|
|
20
22
|
url.searchParams.set('barcode', number);
|
|
21
23
|
url.searchParams.set('lang', 'en');
|
|
22
|
-
const { response, bytes } = await fetchBounded(url, { signal, headers: { Accept: 'application/json', Authorization: `Bearer ${token}
|
|
24
|
+
const { response, bytes } = await fetchBounded(url, { signal, headers: { Accept: 'application/json', Authorization: `Bearer ${token}`, 'User-Agent': userAgent } }, {
|
|
23
25
|
provider: 'ukrposhta', timeoutMs, maxBytes: MAX_BYTES, allowHttpStatuses: [401, 403, 404, 429], fetcher,
|
|
24
26
|
});
|
|
25
27
|
// The refusal of a credential is an HTML page; it says nothing about the parcel.
|
|
@@ -141,7 +143,7 @@ export class UkrposhtaTracker {
|
|
|
141
143
|
throw new ChallengeError('ukrposhta', 'Ukrposhta requires a tracking API token or a configured tracking browser');
|
|
142
144
|
return runSteps({ carrier: 'ukrposhta', budgetMs, signal: context.signal, recorder: this.options.recorder ?? NOOP_RECORDER }, [
|
|
143
145
|
{ id: 'direct', enabled: token !== null,
|
|
144
|
-
run: ({ signal, remainingMs }) => readStatuses(number, token, signal, Math.max(1, Math.min(DIRECT_TIMEOUT_MS, Math.floor(remainingMs))), this.options.fetcher) },
|
|
146
|
+
run: ({ signal, remainingMs }) => readStatuses(number, token, signal, Math.max(1, Math.min(DIRECT_TIMEOUT_MS, Math.floor(remainingMs))), this.options.userAgent, this.options.fetcher) },
|
|
145
147
|
// The portal reads the same domestic records, so it cannot improve on an unknown
|
|
146
148
|
// domestic barcode. An international reference still gets its second source.
|
|
147
149
|
{ id: 'browser', enabled: Boolean(executablePath),
|
|
@@ -151,7 +153,7 @@ export class UkrposhtaTracker {
|
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
export const adapter = environment => {
|
|
154
|
-
const tracker = new UkrposhtaTracker({ executablePath: environment.browserExecutablePath, token: environment.env.UKRPOSHTA_TRACKING_TOKEN,
|
|
155
|
-
fetcher: environment.fetcher, recorder: environment.recorder });
|
|
156
|
+
const tracker = new UkrposhtaTracker({ executablePath: environment.browserExecutablePath, token: environment.env.UKRPOSHTA_TRACKING_TOKEN?.trim() || APPLICATION_BEARER,
|
|
157
|
+
userAgent: environment.userAgent, fetcher: environment.fetcher, recorder: environment.recorder });
|
|
156
158
|
return { id: 'ukrposhta', recordsSteps: true, steps: ['direct', 'browser'], track: (input, context) => tracker.fetch(input.number, context) };
|
|
157
159
|
};
|
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.26.
|
|
3
|
+
"version": "0.26.1-main.369",
|
|
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",
|