thordata-js-sdk 1.0.1 → 1.2.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.
Files changed (66) hide show
  1. package/README.md +88 -77
  2. package/dist/examples/basic_scraper_task.d.ts +1 -0
  3. package/dist/examples/basic_scraper_task.d.ts.map +1 -0
  4. package/dist/examples/internal/example.d.ts +1 -0
  5. package/dist/examples/internal/example.d.ts.map +1 -0
  6. package/dist/examples/location_api.d.ts +1 -0
  7. package/dist/examples/location_api.d.ts.map +1 -0
  8. package/dist/examples/locations_basic.d.ts +1 -0
  9. package/dist/examples/locations_basic.d.ts.map +1 -0
  10. package/dist/examples/proxy_datacenter.d.ts +1 -0
  11. package/dist/examples/proxy_datacenter.d.ts.map +1 -0
  12. package/dist/examples/proxy_isp.d.ts +1 -0
  13. package/dist/examples/proxy_isp.d.ts.map +1 -0
  14. package/dist/examples/proxy_mobile.d.ts +1 -0
  15. package/dist/examples/proxy_mobile.d.ts.map +1 -0
  16. package/dist/examples/proxy_residential.d.ts +1 -0
  17. package/dist/examples/proxy_residential.d.ts.map +1 -0
  18. package/dist/examples/serp_basic.d.ts +1 -0
  19. package/dist/examples/serp_basic.d.ts.map +1 -0
  20. package/dist/examples/serp_google_news.d.ts +1 -0
  21. package/dist/examples/serp_google_news.d.ts.map +1 -0
  22. package/dist/examples/smoke_proxy_protocols.d.ts +2 -0
  23. package/dist/examples/smoke_proxy_protocols.d.ts.map +1 -0
  24. package/dist/examples/smoke_proxy_protocols.js +29 -0
  25. package/dist/examples/smoke_proxy_protocols.js.map +1 -0
  26. package/dist/examples/universal_basic.d.ts +1 -0
  27. package/dist/examples/universal_basic.d.ts.map +1 -0
  28. package/dist/examples/verify_new_features.d.ts +1 -0
  29. package/dist/examples/verify_new_features.d.ts.map +1 -0
  30. package/dist/examples/verify_structured_serp.d.ts +2 -0
  31. package/dist/examples/verify_structured_serp.d.ts.map +1 -0
  32. package/dist/examples/verify_structured_serp.js +38 -0
  33. package/dist/examples/verify_structured_serp.js.map +1 -0
  34. package/dist/src/auth.d.ts +1 -0
  35. package/dist/src/auth.d.ts.map +1 -0
  36. package/dist/src/client.d.ts +15 -77
  37. package/dist/src/client.d.ts.map +1 -0
  38. package/dist/src/client.js +147 -93
  39. package/dist/src/client.js.map +1 -1
  40. package/dist/src/endpoints.d.ts +1 -0
  41. package/dist/src/endpoints.d.ts.map +1 -0
  42. package/dist/src/enums.d.ts +1 -0
  43. package/dist/src/enums.d.ts.map +1 -0
  44. package/dist/src/errors.d.ts +1 -0
  45. package/dist/src/errors.d.ts.map +1 -0
  46. package/dist/src/index.d.ts +1 -0
  47. package/dist/src/index.d.ts.map +1 -0
  48. package/dist/src/models.d.ts +1 -0
  49. package/dist/src/models.d.ts.map +1 -0
  50. package/dist/src/proxy.d.ts +1 -0
  51. package/dist/src/proxy.d.ts.map +1 -0
  52. package/dist/src/proxy.js +12 -3
  53. package/dist/src/proxy.js.map +1 -1
  54. package/dist/src/retry.d.ts +1 -0
  55. package/dist/src/retry.d.ts.map +1 -0
  56. package/dist/src/serp_engines.d.ts +54 -0
  57. package/dist/src/serp_engines.d.ts.map +1 -0
  58. package/dist/src/serp_engines.js +81 -0
  59. package/dist/src/serp_engines.js.map +1 -0
  60. package/dist/src/thordata.d.ts +1 -0
  61. package/dist/src/thordata.d.ts.map +1 -0
  62. package/dist/src/utils.d.ts +1 -0
  63. package/dist/src/utils.d.ts.map +1 -0
  64. package/dist/src/utils.js +16 -14
  65. package/dist/src/utils.js.map +1 -1
  66. package/package.json +9 -5
package/README.md CHANGED
@@ -1,17 +1,30 @@
1
- # Thordata JS SDK (Node.js / TypeScript)
1
+ # Thordata Node.js SDK
2
2
 
3
- Official JavaScript/TypeScript SDK for Thordata APIs.
3
+ <div align="center">
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/thordata-js-sdk.svg)](https://www.npmjs.com/package/thordata-js-sdk)
6
- [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
5
+ <img src="https://img.shields.io/badge/Thordata-AI%20Infrastructure-blue?style=for-the-badge" alt="Thordata Logo">
7
6
 
8
- Supports:
7
+ **The Official Node.js/TypeScript Client for Thordata APIs**
9
8
 
10
- - **SERP API** (Google / Bing / Yandex)
11
- - **Web Unlocker** (Universal API)
12
- - **Web Scraper API** (Text & Video Tasks)
13
- - **Proxy Network** (Residential / Datacenter / Mobile / ISP)
14
- - **Account Management** (Usage, Users, Whitelist)
9
+ *Proxy Network • SERP API Web Unlocker Web Scraper API*
10
+
11
+ [![npm version](https://img.shields.io/npm/v/thordata-js-sdk.svg?style=flat-square)](https://www.npmjs.com/package/thordata-js-sdk)
12
+ [![License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](LICENSE)
13
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/Thordata/thordata-js-sdk/ci.yml?branch=main&style=flat-square)](https://github.com/Thordata/thordata-js-sdk/actions)
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ ## 📖 Introduction
20
+
21
+ A fully typed TypeScript SDK for Thordata, optimized for Node.js environments. It provides seamless integration with Thordata's proxy network and scraping APIs.
22
+
23
+ **Key Features:**
24
+ * **🔒 Type-Safe:** Written in TypeScript with complete definitions.
25
+ * **🌐 Modern:** Uses `axios` and standard `https-proxy-agent` for reliable connectivity.
26
+ * **⚡ Lazy Validation:** Zero-config initialization; only provide credentials for the features you use.
27
+ * **🛡️ Proxy Support:** Full support for HTTPS and SOCKS5h protocols with authentication.
15
28
 
16
29
  ---
17
30
 
@@ -19,112 +32,110 @@ Supports:
19
32
 
20
33
  ```bash
21
34
  npm install thordata-js-sdk
35
+ # or
36
+ yarn add thordata-js-sdk
22
37
  ```
23
38
 
24
39
  ---
25
40
 
26
41
  ## 🔐 Configuration
27
42
 
43
+ We recommend using `dotenv` to manage credentials.
44
+
28
45
  ```bash
29
- export THORDATA_SCRAPER_TOKEN=your_token
30
- export THORDATA_PUBLIC_TOKEN=your_public_token
31
- export THORDATA_PUBLIC_KEY=your_public_key
46
+ # .env file
47
+ THORDATA_SCRAPER_TOKEN=your_token
48
+ THORDATA_RESIDENTIAL_USERNAME=your_username
49
+ THORDATA_RESIDENTIAL_PASSWORD=your_password
50
+ THORDATA_PROXY_HOST=vpnXXXX.pr.thordata.net
32
51
  ```
33
52
 
34
53
  ---
35
54
 
36
55
  ## 🚀 Quick Start
37
56
 
38
- ```typescript
39
- import { Thordata } from "thordata-js-sdk";
57
+ ### 1. SERP Search
40
58
 
41
- const client = new Thordata(); // Reads from env vars
59
+ ```typescript
60
+ import { ThordataClient, Engine } from "thordata-js-sdk";
61
+
62
+ const client = new ThordataClient({}); // Auto-loads from env
63
+
64
+ async function search() {
65
+ const result = await client.serpSearch({
66
+ query: "SpaceX launch",
67
+ engine: Engine.GOOGLE_NEWS,
68
+ country: "us",
69
+ num: 5
70
+ });
71
+
72
+ console.log(result.news_results);
73
+ }
42
74
 
43
- // SERP Search
44
- const results = await client.serpSearch({
45
- query: "Thordata SDK",
46
- engine: "google",
47
- country: "us",
48
- });
49
- console.log(results.organic?.[0]?.link);
75
+ search();
50
76
  ```
51
77
 
52
- ---
53
-
54
- ## 📖 Features
55
-
56
- ### SERP API
78
+ ### 2. Universal Scrape (Web Unlocker)
57
79
 
58
80
  ```typescript
59
- const news = await client.serpSearch({
60
- query: "AI News",
61
- engine: "google_news",
62
- num: 10,
63
- });
81
+ async function scrape() {
82
+ const html = await client.universalScrape({
83
+ url: "https://www.g2.com/products/thordata",
84
+ jsRender: true,
85
+ waitFor: ".reviews-list",
86
+ country: "us"
87
+ });
88
+
89
+ console.log("Page HTML length:", html.length);
90
+ }
64
91
  ```
65
92
 
66
- ### Web Unlocker (Universal)
93
+ ### 3. Using the Proxy Network
67
94
 
68
95
  ```typescript
69
- const html = await client.universalScrape({
70
- url: "https://example.com",
71
- jsRender: true,
72
- waitFor: ".content",
73
- });
96
+ import { Thordata } from "thordata-js-sdk";
97
+
98
+ // Create a targeted proxy config
99
+ const proxy = Thordata.Proxy.residentialFromEnv()
100
+ .country("gb")
101
+ .city("london")
102
+ .sticky(10); // 10 minutes session
103
+
104
+ const client = new Thordata();
105
+
106
+ // Request uses the proxy automatically
107
+ const response = await client.request("https://ipinfo.io/json", { proxy });
108
+ console.log(response);
74
109
  ```
75
110
 
76
- ### Web Scraper API (Async)
111
+ ---
112
+
113
+ ## ⚙️ Advanced Usage
114
+
115
+ ### Task Management (Async)
77
116
 
78
117
  ```typescript
79
- // Create Task
118
+ // Create a scraping task
80
119
  const taskId = await client.createScraperTask({
81
- fileName: "task1",
120
+ fileName: "task_001",
82
121
  spiderId: "universal",
83
122
  spiderName: "universal",
84
- parameters: { url: "https://example.com" },
123
+ parameters: { url: "https://example.com" }
85
124
  });
86
125
 
87
- // Video Task (New)
88
- const vidId = await client.createVideoTask({
89
- fileName: "video1",
90
- spiderId: "youtube_video_by-url",
91
- spiderName: "youtube.com",
92
- parameters: { url: "..." },
93
- commonSettings: { resolution: "1080p" },
94
- });
126
+ console.log(`Task ${taskId} created. Waiting...`);
95
127
 
96
- // Wait & Result
128
+ // Poll for completion
97
129
  const status = await client.waitForTask(taskId);
130
+
98
131
  if (status === "ready") {
99
- const url = await client.getTaskResult(taskId);
100
- console.log(url);
132
+ const downloadUrl = await client.getTaskResult(taskId);
133
+ console.log("Result:", downloadUrl);
101
134
  }
102
135
  ```
103
136
 
104
- ### Account Management
105
-
106
- ```typescript
107
- // Usage Stats
108
- const stats = await client.getUsageStatistics("2024-01-01", "2024-01-31");
109
- console.log("Balance:", stats.traffic_balance);
110
-
111
- // Proxy Users
112
- const users = await client.listProxyUsers("residential");
113
-
114
- // Whitelist
115
- await client.addWhitelistIp("1.2.3.4");
116
- ```
117
-
118
- ### Proxy Configuration
119
-
120
- ```typescript
121
- // Residential Proxy
122
- const proxy = Thordata.Proxy.residentialFromEnv().country("us");
123
- await client.request("https://httpbin.org/ip", { proxy });
124
- ```
125
-
126
137
  ---
127
138
 
128
139
  ## 📄 License
129
140
 
130
- MIT License
141
+ MIT License.
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=basic_scraper_task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic_scraper_task.d.ts","sourceRoot":"","sources":["../../examples/basic_scraper_task.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -3,3 +3,4 @@ export declare function env(name: string): string;
3
3
  export declare function skipIfMissing(...required: string[]): boolean;
4
4
  export declare function printJSON(v: unknown): void;
5
5
  export declare function truncate(s: string, n: number): string;
6
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../../examples/internal/example.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,SAEtB;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAO5D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,QAEnC;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAG5C"}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=location_api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location_api.d.ts","sourceRoot":"","sources":["../../examples/location_api.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=locations_basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locations_basic.d.ts","sourceRoot":"","sources":["../../examples/locations_basic.ts"],"names":[],"mappings":""}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=proxy_datacenter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy_datacenter.d.ts","sourceRoot":"","sources":["../../examples/proxy_datacenter.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=proxy_isp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy_isp.d.ts","sourceRoot":"","sources":["../../examples/proxy_isp.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=proxy_mobile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy_mobile.d.ts","sourceRoot":"","sources":["../../examples/proxy_mobile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=proxy_residential.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy_residential.d.ts","sourceRoot":"","sources":["../../examples/proxy_residential.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=serp_basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serp_basic.d.ts","sourceRoot":"","sources":["../../examples/serp_basic.ts"],"names":[],"mappings":""}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=serp_google_news.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serp_google_news.d.ts","sourceRoot":"","sources":["../../examples/serp_google_news.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ import "dotenv/config";
2
+ //# sourceMappingURL=smoke_proxy_protocols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoke_proxy_protocols.d.ts","sourceRoot":"","sources":["../../examples/smoke_proxy_protocols.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC"}
@@ -0,0 +1,29 @@
1
+ import "dotenv/config";
2
+ import { Thordata } from "../src/thordata.js";
3
+ function printProxyEndpoint(proxyUrl) {
4
+ const u = new URL(proxyUrl);
5
+ console.log("proxy_endpoint:", `${u.protocol}//${u.hostname}:${u.port}`);
6
+ console.log("proxy_user_prefix:", decodeURIComponent(u.username).slice(0, 50));
7
+ }
8
+ async function runOne(protocol) {
9
+ // IMPORTANT: set BOTH global and product-specific protocol to avoid .env overriding
10
+ process.env.THORDATA_PROXY_PROTOCOL = protocol;
11
+ process.env.THORDATA_RESIDENTIAL_PROXY_PROTOCOL = protocol;
12
+ const client = new Thordata();
13
+ const proxy = Thordata.Proxy.residentialFromEnv().country("us");
14
+ const proxyUrl = proxy.toProxyUrl();
15
+ console.log("====", protocol, "====");
16
+ printProxyEndpoint(proxyUrl);
17
+ const out = await client.request("https://ipinfo.thordata.com", { proxy });
18
+ console.log(out);
19
+ }
20
+ async function main() {
21
+ for (const p of ["https", "socks5h"]) {
22
+ await runOne(p);
23
+ }
24
+ }
25
+ main().catch((e) => {
26
+ console.error(e);
27
+ process.exit(1);
28
+ });
29
+ //# sourceMappingURL=smoke_proxy_protocols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoke_proxy_protocols.js","sourceRoot":"","sources":["../../examples/smoke_proxy_protocols.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACzE,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,KAAK,UAAU,MAAM,CAAC,QAAgB;IACpC,oFAAoF;IACpF,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,QAAQ,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,mCAAmC,GAAG,QAAQ,CAAC;IAE3D,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAE7B,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3E,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,KAAK,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;QACrC,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=universal_basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"universal_basic.d.ts","sourceRoot":"","sources":["../../examples/universal_basic.ts"],"names":[],"mappings":""}
@@ -1 +1,2 @@
1
1
  import "dotenv/config";
2
+ //# sourceMappingURL=verify_new_features.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify_new_features.d.ts","sourceRoot":"","sources":["../../examples/verify_new_features.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ import "dotenv/config";
2
+ //# sourceMappingURL=verify_structured_serp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify_structured_serp.d.ts","sourceRoot":"","sources":["../../examples/verify_structured_serp.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC"}
@@ -0,0 +1,38 @@
1
+ // examples/verify_structured_serp.ts
2
+ import "dotenv/config";
3
+ import { ThordataClient } from "../src/index.js";
4
+ async function main() {
5
+ const token = process.env.THORDATA_SCRAPER_TOKEN;
6
+ if (!token) {
7
+ console.error("❌ THORDATA_SCRAPER_TOKEN required");
8
+ process.exit(1);
9
+ }
10
+ // Init client
11
+ const client = new ThordataClient({ scraperToken: token });
12
+ console.log("--- 1. Testing Structured Google Maps (JS) ---");
13
+ try {
14
+ // New Syntax: client.serp.google.maps(...)
15
+ const res = await client.serp.google.maps("coffee", "@40.745,-74.008,14z");
16
+ // We expect an error if account is expired, but the structure is valid if we get here (or get a specific API error)
17
+ console.log("✅ Maps request structure valid. API Response:", JSON.stringify(res).slice(0, 100) + "...");
18
+ }
19
+ catch (e) {
20
+ // Catching the API error proves the SDK built the request correctly
21
+ console.log(`✅ SDK Structure Works! (API returned: ${e.message})`);
22
+ }
23
+ console.log("\n--- 2. Testing Structured Google Flights (JS) ---");
24
+ try {
25
+ // New Syntax: client.serp.google.flights(...)
26
+ await client.serp.google.flights({
27
+ departureId: "JFK",
28
+ arrivalId: "LHR",
29
+ outboundDate: "2025-12-25",
30
+ });
31
+ console.log("✅ Flights request structure valid.");
32
+ }
33
+ catch (e) {
34
+ console.log(`✅ SDK Structure Works! (API returned: ${e.message})`);
35
+ }
36
+ }
37
+ main();
38
+ //# sourceMappingURL=verify_structured_serp.js.map
@@ -0,0 +1 @@
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AC;QACH,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -20,3 +20,4 @@ export declare function buildPublicHeaders(creds: Credentials): Headers;
20
20
  * Interface docs require `token` + `key` (My Account) AND `Authorization: Bearer ...` (scraper token).
21
21
  */
22
22
  export declare function buildBuilderHeaders(creds: Credentials): Headers;
23
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7C,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAS/D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAS9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAK/D"}
@@ -1,3 +1,4 @@
1
+ import { SerpNamespace } from "./serp_engines.js";
1
2
  import { SerpOptions, UniversalOptions, ScraperTaskOptions, WaitForTaskOptions, ProxyTypeParam, CountryInfo, StateInfo, CityInfo, AsnInfo, VideoTaskOptions, UsageStatistics, ProxyUserList, ProxyServer } from "./models.js";
2
3
  import { type ThordataBaseUrls } from "./endpoints.js";
3
4
  import { Proxy } from "./proxy.js";
@@ -5,8 +6,8 @@ import { Proxy } from "./proxy.js";
5
6
  * Configuration options for ThordataClient.
6
7
  */
7
8
  export interface ThordataClientConfig {
8
- /** API token for SERP and Universal APIs */
9
- scraperToken: string;
9
+ /** API token for SERP and Universal APIs (Optional) */
10
+ scraperToken?: string;
10
11
  /** Public token for Web Scraper API and Location API */
11
12
  publicToken?: string;
12
13
  /** Public key for Web Scraper API and Location API */
@@ -46,6 +47,7 @@ export declare class ThordataClient {
46
47
  private proxyListUrl;
47
48
  private proxyExpirationUrl;
48
49
  private taskListUrl;
50
+ serp: SerpNamespace;
49
51
  constructor(config: ThordataClientConfig);
50
52
  /**
51
53
  * Execute request with retry logic.
@@ -53,80 +55,29 @@ export declare class ThordataClient {
53
55
  private execute;
54
56
  /**
55
57
  * Perform a search using the SERP API.
56
- *
57
- * Supported engines: google, bing, yandex, duckduckgo
58
- * Plus Google specialized engines: google_news, google_shopping, etc.
59
- *
60
- * @example
61
- * ```typescript
62
- * // Basic Google search
63
- * const results = await client.serpSearch({
64
- * query: "pizza",
65
- * engine: Engine.GOOGLE,
66
- * country: "us",
67
- * });
68
- *
69
- * // Google News (recommended: use dedicated engine)
70
- * const news = await client.serpSearch({
71
- * query: "AI regulation",
72
- * engine: Engine.GOOGLE_NEWS,
73
- * });
74
- * ```
75
58
  */
76
59
  serpSearch(options: SerpOptions): Promise<Record<string, unknown>>;
77
60
  /**
78
61
  * Scrape a URL using the Universal/Web Unlocker API.
79
- *
80
- * @example
81
- * ```typescript
82
- * // Basic HTML scraping
83
- * const html = await client.universalScrape({
84
- * url: "https://example.com",
85
- * jsRender: false,
86
- * });
87
- *
88
- * // With JS rendering and wait for element
89
- * const html = await client.universalScrape({
90
- * url: "https://example.com/spa",
91
- * jsRender: true,
92
- * waitFor: ".main-content",
93
- * });
94
- *
95
- * // Screenshot
96
- * const png = await client.universalScrape({
97
- * url: "https://example.com",
98
- * jsRender: true,
99
- * outputFormat: "png",
100
- * });
101
- * ```
102
62
  */
103
63
  universalScrape(options: UniversalOptions): Promise<string | Buffer | Record<string, unknown>>;
104
- /**
105
- * Create a new Web Scraper task.
106
- */
107
64
  createScraperTask(options: ScraperTaskOptions): Promise<string>;
108
- /**
109
- * Verify that public credentials are available.
110
- */
111
65
  private requirePublicCreds;
112
- /**
113
- * Get the status of a Web Scraper task.
114
- */
115
66
  getTaskStatus(taskId: string): Promise<string>;
116
- /**
117
- * Get the download URL for a completed task's results.
118
- */
119
67
  getTaskResult(taskId: string, fileType?: "json" | "csv" | "xlsx"): Promise<string>;
120
- /**
121
- * Create a YouTube video/audio download task.
122
- */
123
68
  createVideoTask(options: VideoTaskOptions): Promise<string>;
124
- /**
125
- * Wait for a task to complete.
126
- */
127
69
  waitForTask(taskId: string, options?: WaitForTaskOptions): Promise<string>;
128
70
  /**
129
71
  * Make an HTTP request through a proxy.
72
+ *
73
+ * Supported proxy protocols:
74
+ * - https:// (recommended, required by most accounts)
75
+ * - socks5:// or socks5h:// (SOCKS5 with remote DNS)
76
+ * - http:// (legacy, not supported by most Thordata accounts)
77
+ *
78
+ * For users in mainland China or behind corporate firewalls:
79
+ * Set THORDATA_UPSTREAM_PROXY environment variable to route through local proxy.
80
+ * Example: THORDATA_UPSTREAM_PROXY=socks5://127.0.0.1:7897
130
81
  */
131
82
  request(url: string, config?: {
132
83
  proxy?: Proxy;
@@ -142,24 +93,11 @@ export declare class ThordataClient {
142
93
  createProxyUser(username: string, pass: string, trafficLimit?: number, status?: boolean, proxyType?: ProxyTypeParam): Promise<any>;
143
94
  addWhitelistIp(ip: string, status?: boolean, proxyType?: ProxyTypeParam): Promise<any>;
144
95
  listProxyServers(proxyType: 1 | 2): Promise<ProxyServer[]>;
145
- /**
146
- * Internal method to call locations API.
147
- */
96
+ getProxyExpiration(ips: string | string[], proxyType: 1 | 2): Promise<Record<string, unknown>>;
148
97
  private getLocations;
149
- /**
150
- * List all supported countries for a proxy type.
151
- */
152
98
  listCountries(proxyType?: ProxyTypeParam): Promise<CountryInfo[]>;
153
- /**
154
- * List states/regions for a country.
155
- */
156
99
  listStates(countryCode: string, proxyType?: ProxyTypeParam): Promise<StateInfo[]>;
157
- /**
158
- * List cities for a country (and optionally state).
159
- */
160
100
  listCities(countryCode: string, stateCode?: string, proxyType?: ProxyTypeParam): Promise<CityInfo[]>;
161
- /**
162
- * List ASNs for a country.
163
- */
164
101
  listAsns(countryCode: string, proxyType?: ProxyTypeParam): Promise<AsnInfo[]>;
165
102
  }
103
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAOlD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,SAAS,EACT,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,WAAW,EACZ,MAAM,aAAa,CAAC;AAarB,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAErC,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAiDD;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CA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