scrapebadger 0.47.0 → 0.48.0

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/dist/index.d.cts CHANGED
@@ -853,8 +853,9 @@ declare class ReferenceClient$f {
853
853
  /**
854
854
  * Search for brands by keyword.
855
855
  *
856
- * @param options - Optional parameters.
857
- * @param options.keyword - Brand name to search for.
856
+ * @param options - Search parameters.
857
+ * @param options.keyword - Brand name to search for. Required — the API
858
+ * answers 422 without it, so this was never optional.
858
859
  * @param options.market - Market code (default: "fr").
859
860
  * @param options.per_page - Number of results per page.
860
861
  * @returns Brands matching the keyword.
@@ -871,8 +872,8 @@ declare class ReferenceClient$f {
871
872
  * }
872
873
  * ```
873
874
  */
874
- brands(options?: {
875
- keyword?: string;
875
+ brands(options: {
876
+ keyword: string;
876
877
  market?: string;
877
878
  per_page?: number;
878
879
  }): Promise<BrandsResponse>;
package/dist/index.d.ts CHANGED
@@ -853,8 +853,9 @@ declare class ReferenceClient$f {
853
853
  /**
854
854
  * Search for brands by keyword.
855
855
  *
856
- * @param options - Optional parameters.
857
- * @param options.keyword - Brand name to search for.
856
+ * @param options - Search parameters.
857
+ * @param options.keyword - Brand name to search for. Required — the API
858
+ * answers 422 without it, so this was never optional.
858
859
  * @param options.market - Market code (default: "fr").
859
860
  * @param options.per_page - Number of results per page.
860
861
  * @returns Brands matching the keyword.
@@ -871,8 +872,8 @@ declare class ReferenceClient$f {
871
872
  * }
872
873
  * ```
873
874
  */
874
- brands(options?: {
875
- keyword?: string;
875
+ brands(options: {
876
+ keyword: string;
876
877
  market?: string;
877
878
  per_page?: number;
878
879
  }): Promise<BrandsResponse>;
package/dist/index.js 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.47.0";
12
+ var SDK_VERSION = "0.47.1";
13
13
 
14
14
  // src/internal/exceptions.ts
15
15
  var ScrapeBadgerError = class _ScrapeBadgerError extends Error {
@@ -211,8 +211,27 @@ var BaseClient = class _BaseClient {
211
211
  async executeWithRetry(url, options) {
212
212
  let lastError;
213
213
  for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
214
+ let retryAfterMs = 0;
214
215
  try {
215
216
  const httpResponse = await this.fetchWithTimeout(url, options);
217
+ const retryAfter = httpResponse.headers.get("Retry-After")?.trim();
218
+ if (retryAfter) {
219
+ let requestedDelay = 0;
220
+ if (/^\d+$/.test(retryAfter)) {
221
+ requestedDelay = Number(retryAfter) * 1e3;
222
+ } else if (/^(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} [A-Z][a-z]{2} \d{4}|(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), \d{2}-[A-Z][a-z]{2}-\d{2}) \d{2}:\d{2}:\d{2} GMT$/.test(
223
+ retryAfter
224
+ )) {
225
+ requestedDelay = Date.parse(retryAfter) - Date.now();
226
+ } else if (/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) [A-Z][a-z]{2} [ \d]\d \d{2}:\d{2}:\d{2} \d{4}$/.test(
227
+ retryAfter
228
+ )) {
229
+ requestedDelay = Date.parse(`${retryAfter} GMT`) - Date.now();
230
+ }
231
+ if (requestedDelay > 0 && requestedDelay <= 2147483647) {
232
+ retryAfterMs = requestedDelay;
233
+ }
234
+ }
216
235
  const data = await this.handleResponse(httpResponse);
217
236
  const rateLimit = this.parseRateLimitHeaders(httpResponse.headers);
218
237
  return { data, rateLimit };
@@ -224,7 +243,7 @@ var BaseClient = class _BaseClient {
224
243
  if (attempt === this.config.maxRetries) {
225
244
  break;
226
245
  }
227
- const delay = this.config.retryDelay * Math.pow(2, attempt);
246
+ const delay = Math.max(this.config.retryDelay * Math.pow(2, attempt), retryAfterMs);
228
247
  const delaySec = Math.round(delay / 1e3);
229
248
  const attemptNum = attempt + 1;
230
249
  const maxRetries = this.config.maxRetries;
@@ -235,7 +254,7 @@ var BaseClient = class _BaseClient {
235
254
  if (error.retryAfter) {
236
255
  const retryDelay = (error.retryAfter - Date.now() / 1e3) * 1e3;
237
256
  if (retryDelay > 0 && retryDelay < 6e4) {
238
- await this.sleep(retryDelay);
257
+ await this.sleep(Math.max(retryDelay, retryAfterMs));
239
258
  continue;
240
259
  }
241
260
  }
@@ -2857,8 +2876,9 @@ var ReferenceClient = class {
2857
2876
  /**
2858
2877
  * Search for brands by keyword.
2859
2878
  *
2860
- * @param options - Optional parameters.
2861
- * @param options.keyword - Brand name to search for.
2879
+ * @param options - Search parameters.
2880
+ * @param options.keyword - Brand name to search for. Required — the API
2881
+ * answers 422 without it, so this was never optional.
2862
2882
  * @param options.market - Market code (default: "fr").
2863
2883
  * @param options.per_page - Number of results per page.
2864
2884
  * @returns Brands matching the keyword.
@@ -2875,7 +2895,7 @@ var ReferenceClient = class {
2875
2895
  * }
2876
2896
  * ```
2877
2897
  */
2878
- async brands(options = {}) {
2898
+ async brands(options) {
2879
2899
  return this.client.request("/v1/vinted/brands", {
2880
2900
  params: {
2881
2901
  keyword: options.keyword,