universal-parcel-scraper 0.855.0-main.4565 → 0.855.1-main.4568

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.
@@ -155,6 +155,15 @@ function summaryOnly(summary) {
155
155
  events: [],
156
156
  };
157
157
  }
158
+ /** What a reply other than rows holds, without its values: `false`, a string, or an object and its first keys. */
159
+ function jsonKind(value) {
160
+ if (typeof value === 'boolean')
161
+ return String(value);
162
+ if (!isRecord(value))
163
+ return `a ${typeof value}`;
164
+ const keys = Object.keys(value);
165
+ return `an object${keys.length ? ` keyed ${keys.slice(0, 4).map((key) => key.slice(0, 20)).join(', ')}${keys.length > 4 ? ', …' : ''}` : ''}`;
166
+ }
158
167
  /**
159
168
  * The shipment's history (`GET /en/?ltlHistory=`): JSON rows oldest first, or
160
169
  * `null` when it holds none. It does not echo the number; the search page,
@@ -166,7 +175,7 @@ export function parseGeodisPlHistory(payload, summary, readAt = Date.now()) {
166
175
  if (payload === null)
167
176
  return summaryOnly(summary);
168
177
  if (!Array.isArray(payload))
169
- throw new SchemaError(PROVIDER, 'GEODIS Poland returned an invalid history');
178
+ throw new SchemaError(PROVIDER, `GEODIS Poland returned an invalid history (${jsonKind(payload)})`);
170
179
  if (payload.length > MAX_ROWS)
171
180
  throw new SchemaError(PROVIDER, 'GEODIS Poland returned an oversized history');
172
181
  const seen = new Set();
@@ -106,11 +106,14 @@ export function parse(html, trackingNumber) {
106
106
  const own = pages.length === 1 ? pages.attr('value') ?? '' : '';
107
107
  const parcel = own !== number && /^[A-Z0-9]{8,40}$/.test(own) && $('.ny_cxjg > input').filter((_, element) => $(element).attr('name') === `wcdhB${own}` && $(element).attr('value') === number).length === 1 ? own : number;
108
108
  const identities = pages.filter((_, element) => $(element).attr('value') === parcel);
109
- if (identities.length !== 1)
110
- throw new SchemaError('Yanwen', 'Yanwen returned a different or ambiguous shipment');
109
+ // Which check failed tells a page without any shipment from one naming another.
110
+ if (identities.length !== 1) {
111
+ throw new SchemaError('Yanwen', `Yanwen returned a different or ambiguous shipment (${pages.length} listed, ${identities.length} matching)`);
112
+ }
111
113
  const resultBlocks = $('.cx_lb').filter((_, element) => clean($(element).find('.cx_bt_xx > h5').text()) === parcel);
112
- if (resultBlocks.length < 1 || resultBlocks.length > 2)
113
- throw new SchemaError('Yanwen', 'Yanwen returned a different or ambiguous shipment');
114
+ if (resultBlocks.length < 1 || resultBlocks.length > 2) {
115
+ throw new SchemaError('Yanwen', `Yanwen returned a different or ambiguous shipment (${resultBlocks.length} result blocks for it)`);
116
+ }
114
117
  const results = [];
115
118
  for (const element of resultBlocks.toArray()) {
116
119
  const block = $(element);
@@ -165,7 +168,7 @@ export function parse(html, trackingNumber) {
165
168
  const delivery = status === 'delivered' ? events.find((event) => event.stage === 'delivered') : undefined;
166
169
  const deliveryNumber = clean(columns.eq(1).text(), 64).toUpperCase();
167
170
  if (parcel !== number && deliveryNumber !== number)
168
- throw new SchemaError('Yanwen', 'Yanwen returned a different or ambiguous shipment');
171
+ throw new SchemaError('Yanwen', 'Yanwen returned a different or ambiguous shipment (another last-mile number)');
169
172
  const handoff = deliveryNumber !== number && /^[A-Z0-9]{4,40}$/.test(deliveryNumber) ? deliveryNumber : '';
170
173
  const notes = block.find('.addNotes p').toArray().map((line) => clean($(line).text(), 300));
171
174
  const partner = handoff ? distributor(notes, handoff) : undefined;
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "Universal Parcel Scraper",
5
- "version": "0.855.0-main.4565"
5
+ "version": "0.855.1-main.4568"
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.855.0-main.4565",
3
+ "version": "0.855.1-main.4568",
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",