scrapebadger 0.81.0 → 0.82.1

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
@@ -24,7 +24,7 @@ The official Node.js/TypeScript client library for the [ScrapeBadger](https://sc
24
24
  - **Typed Exceptions** - Distinct error classes for every failure scenario
25
25
  - **Async requests and webhooks** - Run any call asynchronously, wait for it or get a signed webhook; idempotent resubmits
26
26
  - **37+ Twitter endpoints** - Tweets, users, lists, communities, trends, geo, real-time streams
27
- - **20 Google product APIs** - Search (with optional deferred AI Overview follow-up), Maps, News, Hotels, Trends (incl. topic autocomplete), Jobs, Shopping (+ merchant URL enrichment, barcode offers), Patents, Scholar (search + profiles + author + author citation + cite formats), Images, Videos, Finance, AI Mode, Lens, **Local Pack**, **Shorts**, **Flights**, Products, **Ads Transparency Center**
27
+ - **20 Google product APIs** - Search (with optional deferred AI Overview follow-up and result link resolving), Maps, News, Hotels, Trends (incl. topic autocomplete), Jobs, Shopping (+ merchant URL enrichment, barcode offers), Patents, Scholar (search + profiles + author + author citation + cite formats), Images, Videos, Finance, AI Mode, Lens, **Local Pack**, **Shorts**, **Flights**, Products, **Ads Transparency Center**
28
28
  - **Vinted scraping** - Search items, item details, user profiles, brands, colors, markets
29
29
  - **Web scraping** - Anti-bot bypass, JS rendering, screenshots, and selector/AI data extraction
30
30
 
package/dist/index.cjs CHANGED
@@ -9,7 +9,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
  var WebSocket__default = /*#__PURE__*/_interopDefault(WebSocket);
10
10
 
11
11
  // src/internal/version.ts
12
- var SDK_VERSION = "0.81.0";
12
+ var SDK_VERSION = "0.82.1";
13
13
 
14
14
  // src/internal/exceptions.ts
15
15
  var ScrapeBadgerError = class _ScrapeBadgerError extends Error {
@@ -3497,10 +3497,12 @@ var MapsClient = class {
3497
3497
  * Get full place detail by `place_id` or `data_id`.
3498
3498
  *
3499
3499
  * Returns title, address, phone, website, GPS, rating, reviews_count,
3500
- * rating_summary (per-star distribution), categories, extensions
3501
- * (service_options, accessibility, offerings, payments), weekly
3502
- * operating hours, popular_times graph, provider_id,
3503
- * permanently_closed, thumbnail, and photo list.
3500
+ * categories, extensions (amenity groups such as accessibility),
3501
+ * opening hours (`open_state`, today's `hours`, and `operating_hours`
3502
+ * for the coming seven days), `price_level` (Google's price per person,
3503
+ * e.g. "฿2,000+"), popular_times, provider_id, `thumbnail`/`image`, and
3504
+ * up to 20 photo URLs. `service_options` is null: Google no longer
3505
+ * exposes those flags to signed-out clients.
3504
3506
  */
3505
3507
  async place(params) {
3506
3508
  if (!params.place_id && !params.data_id) {
@@ -3523,12 +3525,13 @@ var MapsClient = class {
3523
3525
  });
3524
3526
  }
3525
3527
  /**
3526
- * Get photos for a place with place-specific categories.
3528
+ * Get photos for a place.
3527
3529
  *
3528
- * Returns place-specific categories (Menu, Vibe, Comfort food, dish
3529
- * names) and photo URLs from all CDN families. Use `category_id` to
3530
- * scope to a category, or `page_size: 200` to fetch all photos in
3531
- * one call (Google caps at ~120 photos per response).
3530
+ * Returns the photos Google exposes to signed-out clients (usually the
3531
+ * first 8 of the gallery) as `thumbnail` and `image` URLs.
3532
+ * `pagination.total_results` is the place's total photo count on Google;
3533
+ * there is one page (`next` is null). To get another size, replace a
3534
+ * URL's `=w..-h..-k-no` suffix and keep its path.
3532
3535
  */
3533
3536
  async photos(params) {
3534
3537
  return this.client.request("/v1/google/maps/photos", {
@@ -3666,6 +3669,9 @@ var ScholarClient = class {
3666
3669
 
3667
3670
  // src/google/search.ts
3668
3671
  var FULL_SEARCH_ONLY = ["mode", "ai_overview", "expand_related_questions"];
3672
+ var RESOLVE_MAX_RESULTS = 25;
3673
+ var DEFAULT_RESOLVE_MAX_WAIT_MS = 24e4;
3674
+ var MIN_RESOLVE_WAIT_MS = 1e3;
3669
3675
  var SearchClient2 = class {
3670
3676
  constructor(client) {
3671
3677
  this.client = client;
@@ -3682,7 +3688,128 @@ var SearchClient2 = class {
3682
3688
  params: light
3683
3689
  });
3684
3690
  }
3691
+ /**
3692
+ * Resolve Google redirect links to the results' own URLs. One
3693
+ * `POST /v1/google/resolve` call, 0 credits.
3694
+ *
3695
+ * Google can return a result's `link` as a redirect
3696
+ * (`https://www.google.com/goto?url=...`) and limits how fast the links of
3697
+ * one result page can be followed. Such a result has a `link_token`. Send
3698
+ * 1 to 25 results that have one; every other field of an item is returned
3699
+ * unchanged on its row, so `organic_results` items can be sent as they
3700
+ * are.
3701
+ *
3702
+ * `results` in the response has one row per item, in the order sent. Each
3703
+ * row is one of:
3704
+ * - resolved: `link` is the result's own URL. The row has no `link_token`,
3705
+ * `retry_after_seconds` or `error`.
3706
+ * - not ready: the row has `link_token` and `retry_after_seconds`. Wait
3707
+ * that many seconds, then send the row's `link_token` again. It can
3708
+ * differ from the one sent, so always keep the latest. `link` is as
3709
+ * sent.
3710
+ * - failed: the row has `link_token` as sent and `error`. Do not send it
3711
+ * again.
3712
+ *
3713
+ * The top-level `retry_after_seconds` is the smallest wait among the rows
3714
+ * that are not ready, or `null` when no row is waiting. A token sent
3715
+ * before its wait is over is not an error: its row comes back not ready
3716
+ * with the wait that is left.
3717
+ *
3718
+ * Polling as `retry_after_seconds` says, all ten links of a result page
3719
+ * are usually known 45 to 70 seconds after the search. Once the result
3720
+ * page is about 160 seconds old, every remaining link resolves in one
3721
+ * call. {@link resolveAll} runs this loop for you.
3722
+ *
3723
+ * @example
3724
+ * ```typescript
3725
+ * const serp = await client.google.search.search({ q: "python 3.13" });
3726
+ * const pending = (serp.organic_results as any[]).filter((r) => r.link_token);
3727
+ * const { results, retry_after_seconds } = await client.google.search.resolve({
3728
+ * results: pending,
3729
+ * });
3730
+ * ```
3731
+ *
3732
+ * @param params - `results`: 1 to 25 items, each with a `link_token`.
3733
+ * @returns The rows in the order sent, and the smallest wait.
3734
+ * @throws ValidationError - 422: no results, more than 25, or an item without a `link_token`.
3735
+ * @throws ServerError - 503 with `Retry-After`: links cannot be resolved right now; try again later.
3736
+ */
3737
+ async resolve(params) {
3738
+ return this.client.request("/v1/google/resolve", {
3739
+ method: "POST",
3740
+ body: { results: params.results }
3741
+ });
3742
+ }
3743
+ /**
3744
+ * Resolve every Google redirect link in a list of results, polling
3745
+ * {@link resolve} until all are known or `maxWaitMs` has passed. Free.
3746
+ *
3747
+ * Pass a search response's `organic_results`. Rows with a `link_token` are
3748
+ * sent, at most 25 per request. Between rounds it waits the
3749
+ * `retry_after_seconds` the API returned (at least one second, never past
3750
+ * the deadline). A row without a `link_token` is returned as it is and
3751
+ * never sent. A row that failed (`error`) is not sent again.
3752
+ *
3753
+ * It does not throw for rows that are still not ready at the deadline:
3754
+ * they are returned with their latest `link_token` and
3755
+ * `retry_after_seconds`, and can be passed to `resolveAll` or
3756
+ * {@link resolve} again. An API error (for example a 503) is thrown as
3757
+ * usual.
3758
+ *
3759
+ * The input array and its objects are not changed.
3760
+ *
3761
+ * @example
3762
+ * ```typescript
3763
+ * const serp = await client.google.search.search({ q: "python 3.13" });
3764
+ * const results = await client.google.search.resolveAll(
3765
+ * serp.organic_results as Record<string, unknown>[]
3766
+ * );
3767
+ * for (const r of results) {
3768
+ * if (r.error) console.log("failed:", r.title, r.error);
3769
+ * else if (r.link_token) console.log("not ready yet:", r.title);
3770
+ * else console.log(r.title, r.link);
3771
+ * }
3772
+ * ```
3773
+ *
3774
+ * @param results - Result objects, normally a search response's `organic_results`.
3775
+ * @param options - `maxWaitMs`: longest time to keep polling (default 240000, four minutes).
3776
+ * @returns A new array with one row per input row, in the same order.
3777
+ */
3778
+ async resolveAll(results, options = {}) {
3779
+ const deadline = Date.now() + (options.maxWaitMs ?? DEFAULT_RESOLVE_MAX_WAIT_MS);
3780
+ const rows = results.map((row) => ({ ...row }));
3781
+ for (; ; ) {
3782
+ const waiting = rows.flatMap((row, index) => isWaiting(row) ? [index] : []);
3783
+ if (waiting.length === 0) return rows;
3784
+ let waitSeconds = null;
3785
+ for (let start = 0; start < waiting.length; start += RESOLVE_MAX_RESULTS) {
3786
+ const chunk = waiting.slice(start, start + RESOLVE_MAX_RESULTS);
3787
+ const response = await this.resolve({
3788
+ results: chunk.map((index) => rows[index])
3789
+ });
3790
+ chunk.forEach((index, n) => {
3791
+ const row = response.results[n];
3792
+ if (row) rows[index] = row;
3793
+ });
3794
+ const retryAfter = response.retry_after_seconds;
3795
+ if (typeof retryAfter === "number" && (waitSeconds === null || retryAfter < waitSeconds)) {
3796
+ waitSeconds = retryAfter;
3797
+ }
3798
+ }
3799
+ if (!rows.some(isWaiting)) return rows;
3800
+ const remainingMs = deadline - Date.now();
3801
+ if (remainingMs <= 0) return rows;
3802
+ const waitMs = Math.max((waitSeconds ?? 0) * 1e3, MIN_RESOLVE_WAIT_MS);
3803
+ await sleep2(Math.min(waitMs, remainingMs));
3804
+ }
3805
+ }
3685
3806
  };
3807
+ function isWaiting(row) {
3808
+ return typeof row.link_token === "string" && row.link_token !== "" && (row.error === void 0 || row.error === null);
3809
+ }
3810
+ function sleep2(ms) {
3811
+ return new Promise((resolve) => setTimeout(resolve, ms));
3812
+ }
3686
3813
 
3687
3814
  // src/google/shopping.ts
3688
3815
  var ShoppingClient = class {
@@ -5337,7 +5464,7 @@ var RequestsClient = class {
5337
5464
  const remainingMs = deadline - Date.now();
5338
5465
  if (remainingMs <= 0) throw new WaitTimeoutError(requestId, timeoutMs);
5339
5466
  const suggestedMs = (state.retryAfterSeconds ?? DEFAULT_POLL_S) * 1e3;
5340
- await sleep2(Math.min(Math.max(suggestedMs, MIN_POLL_MS), remainingMs));
5467
+ await sleep3(Math.min(Math.max(suggestedMs, MIN_POLL_MS), remainingMs));
5341
5468
  }
5342
5469
  }
5343
5470
  /**
@@ -5424,7 +5551,7 @@ function retryAfterSeconds(headers, fromBody) {
5424
5551
  }
5425
5552
  return typeof fromBody === "number" && Number.isFinite(fromBody) && fromBody >= 0 ? fromBody : null;
5426
5553
  }
5427
- function sleep2(ms) {
5554
+ function sleep3(ms) {
5428
5555
  return new Promise((resolve) => setTimeout(resolve, ms));
5429
5556
  }
5430
5557