@decodo/sdk-ts 2.3.0 → 2.5.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/README.md CHANGED
@@ -68,7 +68,7 @@ node -e "let p=require('./package.json'); p.type='module'; require('fs').writeFi
68
68
 
69
69
  </details>
70
70
 
71
- Get a Web Scraping API basic authentication token from the [Decodo dashboard](https://dashboard.decodo.com/welcome) and use it in the following example:
71
+ Copy your Web Data API key from your Web Data API subscription on the [Decodo dashboard](https://dashboard.decodo.com/web-data/playground) and use it in the following example. Older plans only have a basic authentication token, which you can pass as `token` instead (see [Configuration](#configuration)).
72
72
 
73
73
  ```typescript
74
74
  // main.js
@@ -76,7 +76,7 @@ import { DecodoClient, Target } from '@decodo/sdk-ts';
76
76
 
77
77
  const client = new DecodoClient({
78
78
  webScrapingApi: {
79
- token: '<basic_auth_token>',
79
+ apiKey: '<api_key>',
80
80
  },
81
81
  });
82
82
 
@@ -358,16 +358,28 @@ node main.js
358
358
  ```typescript
359
359
  const client = new DecodoClient({
360
360
  webScrapingApi: {
361
- token: '<basic_auth_token>',
361
+ apiKey: '<api_key>',
362
362
  },
363
363
  timeoutMs: 120_000, // optional, request timeout in ms (default: 180s)
364
364
  });
365
365
  ```
366
366
 
367
- | Parameter | Description |
368
- | --- | --- |
369
- | `token` | Web Scraping API basic authentication token |
370
- | `timeoutMs` | Request timeout in milliseconds (default: 180000) |
367
+ Pass either `apiKey` or `token`, not both. The client throws if you set both.
368
+
369
+ ```typescript
370
+ // Basic authentication token (older plans)
371
+ const client = new DecodoClient({
372
+ webScrapingApi: {
373
+ token: '<basic_auth_token>',
374
+ },
375
+ });
376
+ ```
377
+
378
+ | Parameter | Description |
379
+ | ----------- | ---------------------------------------------------------------------------------------- |
380
+ | `apiKey` | Web Data API key. Recommended |
381
+ | `token` | Web Scraping API basic authentication token, for older plans. Use it instead of `apiKey` |
382
+ | `timeoutMs` | Request timeout in milliseconds (default: 180000) |
371
383
 
372
384
  ## Web Scraping API
373
385
 
@@ -430,52 +442,52 @@ Each target accepts one primary input parameter (`url`, `query`, `product_id`, o
430
442
 
431
443
  ### Search engines
432
444
 
433
- | Target | Description | Example |
434
- | --- | --- | --- |
435
- | `Target.GoogleSearch` | Google Search results for a query | `{ target: Target.GoogleSearch, query: "coffee shops" }` |
436
- | `Target.GoogleMaps` | Google Maps search results | `{ target: Target.GoogleMaps, query: "coffee shops brooklyn" }` |
437
- | `Target.GoogleShoppingSearch` | Google Shopping search results | `{ target: Target.GoogleShoppingSearch, query: "laptop" }` |
438
- | `Target.GoogleSuggest` | Google Autocomplete suggestions | `{ target: Target.GoogleSuggest, query: "coffee" }` |
439
- | `Target.GoogleLens` | Google Lens reverse image search | `{ target: Target.GoogleLens, query: "https://example.com/cat.jpg" }` |
440
- | `Target.BingSearch` | Bing Search results | `{ target: Target.BingSearch, query: "electric vehicles" }` |
445
+ | Target | Description | Example |
446
+ | ----------------------------- | --------------------------------- | --------------------------------------------------------------------- |
447
+ | `Target.GoogleSearch` | Google Search results for a query | `{ target: Target.GoogleSearch, query: "coffee shops" }` |
448
+ | `Target.GoogleMaps` | Google Maps search results | `{ target: Target.GoogleMaps, query: "coffee shops brooklyn" }` |
449
+ | `Target.GoogleShoppingSearch` | Google Shopping search results | `{ target: Target.GoogleShoppingSearch, query: "laptop" }` |
450
+ | `Target.GoogleSuggest` | Google Autocomplete suggestions | `{ target: Target.GoogleSuggest, query: "coffee" }` |
451
+ | `Target.GoogleLens` | Google Lens reverse image search | `{ target: Target.GoogleLens, query: "https://example.com/cat.jpg" }` |
452
+ | `Target.BingSearch` | Bing Search results | `{ target: Target.BingSearch, query: "electric vehicles" }` |
441
453
 
442
454
  ### eCommerce
443
455
 
444
- | Target | Description | Example |
445
- | --- | --- | --- |
446
- | `Target.AmazonProduct` | Amazon product detail page by ASIN | `{ target: Target.AmazonProduct, query: "B09H74FXNW" }` |
447
- | `Target.AmazonSearch` | Amazon search results | `{ target: Target.AmazonSearch, query: "laptop" }` |
448
- | `Target.AmazonPricing` | Amazon pricing and offers | `{ target: Target.AmazonPricing, query: "B09H74FXNW" }` |
449
- | `Target.WalmartProduct` | Walmart product page by product ID | `{ target: Target.WalmartProduct, product_id: "15296401808" }` |
450
- | `Target.TargetProduct` | Target.com product page by product ID | `{ target: Target.TargetProduct, product_id: "92186007" }` |
451
- | `Target.Ecommerce` | Generic eCommerce page with parser | `{ target: Target.Ecommerce, url: "https://example.com/product/123" }` |
456
+ | Target | Description | Example |
457
+ | ----------------------- | ------------------------------------- | ---------------------------------------------------------------------- |
458
+ | `Target.AmazonProduct` | Amazon product detail page by ASIN | `{ target: Target.AmazonProduct, query: "B09H74FXNW" }` |
459
+ | `Target.AmazonSearch` | Amazon search results | `{ target: Target.AmazonSearch, query: "laptop" }` |
460
+ | `Target.AmazonPricing` | Amazon pricing and offers | `{ target: Target.AmazonPricing, query: "B09H74FXNW" }` |
461
+ | `Target.WalmartProduct` | Walmart product page by product ID | `{ target: Target.WalmartProduct, product_id: "15296401808" }` |
462
+ | `Target.TargetProduct` | Target.com product page by product ID | `{ target: Target.TargetProduct, product_id: "92186007" }` |
463
+ | `Target.Ecommerce` | Generic eCommerce page with parser | `{ target: Target.Ecommerce, url: "https://example.com/product/123" }` |
452
464
 
453
465
  ### Social media
454
466
 
455
- | Target | Description | Example |
456
- | --- | --- | --- |
457
- | `Target.RedditPost` | Reddit post by URL | `{ target: Target.RedditPost, url: "https://reddit.com/r/nba/..." }` |
458
- | `Target.RedditSubreddit` | Reddit subreddit by URL | `{ target: Target.RedditSubreddit, url: "https://reddit.com/r/nba/" }` |
459
- | `Target.YoutubeVideo` | YouTube video by ID | `{ target: Target.YoutubeVideo, query: "dFu9aKJoqGg" }` |
460
- | `Target.YoutubeSearch` | YouTube search results | `{ target: Target.YoutubeSearch, query: "ambient music" }` |
461
- | `Target.TiktokPost` | TikTok post by URL | `{ target: Target.TiktokPost, url: "https://www.tiktok.com/@nba/video/..." }` |
467
+ | Target | Description | Example |
468
+ | ------------------------ | ----------------------- | ----------------------------------------------------------------------------- |
469
+ | `Target.RedditPost` | Reddit post by URL | `{ target: Target.RedditPost, url: "https://reddit.com/r/nba/..." }` |
470
+ | `Target.RedditSubreddit` | Reddit subreddit by URL | `{ target: Target.RedditSubreddit, url: "https://reddit.com/r/nba/" }` |
471
+ | `Target.YoutubeVideo` | YouTube video by ID | `{ target: Target.YoutubeVideo, query: "dFu9aKJoqGg" }` |
472
+ | `Target.YoutubeSearch` | YouTube search results | `{ target: Target.YoutubeSearch, query: "ambient music" }` |
473
+ | `Target.TiktokPost` | TikTok post by URL | `{ target: Target.TiktokPost, url: "https://www.tiktok.com/@nba/video/..." }` |
462
474
 
463
475
  ### AI tools
464
476
 
465
- | Target | Description | Example |
466
- | --- | --- | --- |
467
- | `Target.Chatgpt` | ChatGPT response for a prompt | `{ target: Target.Chatgpt, prompt: "What are the top three dog breeds?" }` |
468
- | `Target.Perplexity` | Perplexity response for a prompt | `{ target: Target.Perplexity, prompt: "What causes seasonal allergies?" }` |
469
- | `Target.Gemini` | Gemini response for a prompt | `{ target: Target.Gemini, prompt: "What are the top three dog breeds?" }` |
470
- | `Target.GoogleAiMode` | Google AI Mode response | `{ target: Target.GoogleAiMode, query: "What are the top three dog breeds?" }` |
477
+ | Target | Description | Example |
478
+ | --------------------- | -------------------------------- | ------------------------------------------------------------------------------ |
479
+ | `Target.Chatgpt` | ChatGPT response for a prompt | `{ target: Target.Chatgpt, prompt: "What are the top three dog breeds?" }` |
480
+ | `Target.Perplexity` | Perplexity response for a prompt | `{ target: Target.Perplexity, prompt: "What causes seasonal allergies?" }` |
481
+ | `Target.Gemini` | Gemini response for a prompt | `{ target: Target.Gemini, prompt: "What are the top three dog breeds?" }` |
482
+ | `Target.GoogleAiMode` | Google AI Mode response | `{ target: Target.GoogleAiMode, query: "What are the top three dog breeds?" }` |
471
483
 
472
484
  ### Universal scraping
473
485
 
474
- | Target | Description | Example |
475
- | --- | --- | --- |
476
- | `Target.Universal` | Any URL via the universal scraper | `{ target: Target.Universal, url: "https://example.com" }` |
477
- | `Target.Google` | Raw Google URL scraping | `{ target: Target.Google, url: "https://google.com/search?q=laptop" }` |
478
- | `Target.Amazon` | Raw Amazon URL scraping | `{ target: Target.Amazon, url: "https://amazon.com/dp/B09H74FXNW" }` |
486
+ | Target | Description | Example |
487
+ | ------------------ | --------------------------------- | ---------------------------------------------------------------------- |
488
+ | `Target.Universal` | Any URL via the universal scraper | `{ target: Target.Universal, url: "https://example.com" }` |
489
+ | `Target.Google` | Raw Google URL scraping | `{ target: Target.Google, url: "https://google.com/search?q=laptop" }` |
490
+ | `Target.Amazon` | Raw Amazon URL scraping | `{ target: Target.Amazon, url: "https://amazon.com/dp/B09H74FXNW" }` |
479
491
 
480
492
  > `Target.UniversalEcommerce` isn't listed above because it doesn't accept a primary input parameter like `url`, `query`, `product_id`, or `prompt`. It only accepts optional configuration fields such as `callback_url`.
481
493
 
@@ -2811,8 +2811,19 @@ var DEFAULT_TIMEOUT_MS = 18e4;
2811
2811
  var notConfigured = (namespace, hint) => {
2812
2812
  throw new Error(`${namespace} is not configured. ${hint}`);
2813
2813
  };
2814
+ var resolveBaseUrl = (baseUrl, fallback) => {
2815
+ if (baseUrl === void 0) {
2816
+ return fallback;
2817
+ }
2818
+ try {
2819
+ new URL(baseUrl);
2820
+ } catch {
2821
+ throw new Error("webScrapingApi baseUrl must be a valid URL.");
2822
+ }
2823
+ return baseUrl;
2824
+ };
2814
2825
  var resolveTransport = (config) => {
2815
- const { token, apiKey } = config;
2826
+ const { token, apiKey, baseUrl } = config;
2816
2827
  if (token !== void 0 && apiKey !== void 0) {
2817
2828
  throw new Error(
2818
2829
  "webScrapingApi accepts either token or apiKey, not both. Provide only one."
@@ -2823,7 +2834,7 @@ var resolveTransport = (config) => {
2823
2834
  throw new Error("webScrapingApi apiKey must be a non-empty string.");
2824
2835
  }
2825
2836
  return {
2826
- baseUrl: DATA_API_BASE_URL,
2837
+ baseUrl: resolveBaseUrl(baseUrl, DATA_API_BASE_URL),
2827
2838
  auth: { type: "apiKey", apiKey },
2828
2839
  routes: DATA_API_ROUTES
2829
2840
  };
@@ -2833,12 +2844,12 @@ var resolveTransport = (config) => {
2833
2844
  throw new Error("webScrapingApi token must be a non-empty string.");
2834
2845
  }
2835
2846
  return {
2836
- baseUrl: WEB_API_BASE_URL,
2847
+ baseUrl: resolveBaseUrl(baseUrl, WEB_API_BASE_URL),
2837
2848
  auth: { type: "basic", token },
2838
2849
  routes: SCRAPER_API_ROUTES
2839
2850
  };
2840
2851
  }
2841
- throw new Error("webScrapingApi requires token in DecodoConfig.");
2852
+ throw new Error("webScrapingApi requires apiKey or token in DecodoConfig.");
2842
2853
  };
2843
2854
  var DecodoClient = class {
2844
2855
  webScrapingApi;
@@ -2862,7 +2873,7 @@ var DecodoClient = class {
2862
2873
  get() {
2863
2874
  notConfigured(
2864
2875
  "webScrapingApi",
2865
- "Provide webScrapingApi.token in DecodoConfig."
2876
+ "Provide webScrapingApi.apiKey or webScrapingApi.token in DecodoConfig."
2866
2877
  );
2867
2878
  }
2868
2879
  });
@@ -859,6 +859,7 @@ export type WebScrapingApiCredentials = {
859
859
  };
860
860
  export type WebScrapingApiConfig = WebScrapingApiCredentials & {
861
861
  integrationHeader?: string;
862
+ baseUrl?: string;
862
863
  };
863
864
  export type DecodoConfig = {
864
865
  webScrapingApi?: WebScrapingApiConfig;
@@ -9,6 +9,7 @@ type WebScrapingApiCredentials = {
9
9
  };
10
10
  export type WebScrapingApiConfig = WebScrapingApiCredentials & {
11
11
  integrationHeader?: string;
12
+ baseUrl?: string;
12
13
  };
13
14
  export type DecodoConfig = {
14
15
  webScrapingApi?: WebScrapingApiConfig;
@@ -7,8 +7,20 @@ const DEFAULT_TIMEOUT_MS = 180_000;
7
7
  const notConfigured = (namespace, hint) => {
8
8
  throw new Error(`${namespace} is not configured. ${hint}`);
9
9
  };
10
+ const resolveBaseUrl = (baseUrl, fallback) => {
11
+ if (baseUrl === undefined) {
12
+ return fallback;
13
+ }
14
+ try {
15
+ new URL(baseUrl);
16
+ }
17
+ catch {
18
+ throw new Error('webScrapingApi baseUrl must be a valid URL.');
19
+ }
20
+ return baseUrl;
21
+ };
10
22
  const resolveTransport = (config) => {
11
- const { token, apiKey } = config;
23
+ const { token, apiKey, baseUrl } = config;
12
24
  if (token !== undefined && apiKey !== undefined) {
13
25
  throw new Error('webScrapingApi accepts either token or apiKey, not both. Provide only one.');
14
26
  }
@@ -17,7 +29,7 @@ const resolveTransport = (config) => {
17
29
  throw new Error('webScrapingApi apiKey must be a non-empty string.');
18
30
  }
19
31
  return {
20
- baseUrl: DATA_API_BASE_URL,
32
+ baseUrl: resolveBaseUrl(baseUrl, DATA_API_BASE_URL),
21
33
  auth: { type: 'apiKey', apiKey },
22
34
  routes: DATA_API_ROUTES,
23
35
  };
@@ -27,12 +39,12 @@ const resolveTransport = (config) => {
27
39
  throw new Error('webScrapingApi token must be a non-empty string.');
28
40
  }
29
41
  return {
30
- baseUrl: WEB_API_BASE_URL,
42
+ baseUrl: resolveBaseUrl(baseUrl, WEB_API_BASE_URL),
31
43
  auth: { type: 'basic', token },
32
44
  routes: SCRAPER_API_ROUTES,
33
45
  };
34
46
  }
35
- throw new Error('webScrapingApi requires token in DecodoConfig.');
47
+ throw new Error('webScrapingApi requires apiKey or token in DecodoConfig.');
36
48
  };
37
49
  export class DecodoClient {
38
50
  webScrapingApi;
@@ -51,7 +63,7 @@ export class DecodoClient {
51
63
  else {
52
64
  this.webScrapingApi = new Proxy({}, {
53
65
  get() {
54
- notConfigured('webScrapingApi', 'Provide webScrapingApi.token in DecodoConfig.');
66
+ notConfigured('webScrapingApi', 'Provide webScrapingApi.apiKey or webScrapingApi.token in DecodoConfig.');
55
67
  },
56
68
  });
57
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decodo/sdk-ts",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "Official TypeScript SDK for the Decodo APIs",
5
5
  "type": "module",
6
6
  "main": "./build/cjs/index.cjs",