1- # Thordata JS SDK ( Node.js / TypeScript)
1+ # Thordata Node.js SDK
22
3- Official JavaScript/TypeScript SDK for Thordata APIs.
3+ <div align =" center " >
4+
5+ ** Official Node.js/TypeScript Client for Thordata APIs**
6+
7+ * Proxy Network • SERP API • Web Unlocker • Web Scraper API*
48
59[ ![ npm version] ( https://img.shields.io/npm/v/thordata-js-sdk.svg )] ( https://www.npmjs.com/package/thordata-js-sdk )
610[ ![ License] ( https://img.shields.io/badge/license-MIT-green )] ( LICENSE )
711
8- Supports:
9-
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)
12+ </div >
1513
1614---
1715
@@ -21,110 +19,149 @@ Supports:
2119npm install thordata-js-sdk
2220```
2321
24- ---
25-
2622## 🔐 Configuration
2723
24+ Set environment variables:
25+
2826``` bash
29- export THORDATA_SCRAPER_TOKEN=your_token
30- export THORDATA_PUBLIC_TOKEN=your_public_token
31- export THORDATA_PUBLIC_KEY=your_public_key
27+ export THORDATA_SCRAPER_TOKEN=" your_token"
28+ export THORDATA_PUBLIC_TOKEN=" your_public_token"
29+ export THORDATA_PUBLIC_KEY=" your_public_key"
3230```
3331
34- ---
35-
3632## 🚀 Quick Start
3733
3834``` typescript
3935import { Thordata } from " thordata-js-sdk" ;
4036
41- const client = new Thordata (); // Reads from env vars
37+ // Initialize (reads from env vars)
38+ const client = new Thordata ();
39+
40+ async function main() {
41+ // SERP Search
42+ const results = await client .serpSearch ({
43+ query: " nodejs" ,
44+ engine: " google" ,
45+ country: " us"
46+ });
47+ console .log (results .organic ?.[0 ]?.title );
48+ }
4249
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 );
50+ main ();
5051```
5152
52- ---
53+ ## 📚 Core Features
5354
54- ## 📖 Features
55+ ### 🌐 Proxy Network
5556
56- ### SERP API
57+ Build proxy URLs for ` axios ` , ` fetch ` , ` puppeteer ` , etc.
5758
5859``` typescript
60+ import { Thordata } from " thordata-js-sdk" ;
61+
62+ // Create proxy config
63+ const proxy = Thordata .Proxy .residentialFromEnv ()
64+ .country (" jp" )
65+ .city (" tokyo" )
66+ .sticky (30 ); // 30 min session
67+
68+ // Get URL string
69+ console .log (proxy .toProxyUrl ());
70+
71+ // Use with internal client
72+ const response = await client .request (" https://httpbin.org/ip" , { proxy });
73+ console .log (response );
74+ ```
75+
76+ ### 🔍 SERP API
77+
78+ ``` typescript
79+ import { Engine } from " thordata-js-sdk" ;
80+
5981const news = await client .serpSearch ({
60- query: " AI News" ,
61- engine: " google_news" ,
62- num: 10 ,
82+ query: " SpaceX" ,
83+ engine: Engine .GOOGLE_NEWS ,
84+ num: 20 ,
85+ country: " us" ,
86+ language: " en"
6387});
6488```
6589
66- ### Web Unlocker (Universal )
90+ ### 🔓 Universal Scraping API (Web Unlocker )
6791
6892``` typescript
6993const html = await client .universalScrape ({
70- url: " https://example.com" ,
94+ url: " https://example.com/spa " ,
7195 jsRender: true ,
72- waitFor: " .content" ,
96+ waitFor: " .loaded-content" ,
97+ blockResources: " image,media"
7398});
7499```
75100
76- ### Web Scraper API (Async )
101+ ### 🕷️ Web Scraper API (Tasks )
77102
78103``` typescript
79- // Create Task
104+ // 1. Create Task
80105const taskId = await client .createScraperTask ({
81- fileName: " task1 " ,
106+ fileName: " task_1 " ,
82107 spiderId: " universal" ,
83108 spiderName: " universal" ,
84- parameters: { url: " https://example.com" },
109+ parameters: { url: " https://example.com" }
85110});
86111
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- });
95-
96- // Wait & Result
112+ // 2. Wait
97113const status = await client .waitForTask (taskId );
114+
115+ // 3. Download
98116if (status === " ready" ) {
99117 const url = await client .getTaskResult (taskId );
100118 console .log (url );
101119}
102120```
103121
104- ### Account Management
122+ ### 📊 Account Management
105123
106124``` typescript
107125// Usage Stats
108126const stats = await client .getUsageStatistics (" 2024-01-01" , " 2024-01-31" );
109- console .log (" Balance:" , stats .traffic_balance );
110127
111- // Proxy Users
112- const users = await client .listProxyUsers (" residential" );
113-
114- // Whitelist
128+ // Manage Whitelist
115129await client .addWhitelistIp (" 1.2.3.4" );
130+
131+ // Check ISP Proxies
132+ const servers = await client .listProxyServers (1 ); // 1=ISP
116133```
117134
118- ### Proxy Configuration
135+ ## ⚙️ Advanced Usage
136+
137+ ### Error Handling
138+
139+ The SDK throws typed errors for better control.
119140
120141``` typescript
121- // Residential Proxy
122- const proxy = Thordata .Proxy .residentialFromEnv ().country (" us" );
123- await client .request (" https://httpbin.org/ip" , { proxy });
142+ import { ThordataRateLimitError , ThordataAuthError } from " thordata-js-sdk" ;
143+
144+ try {
145+ await client .serpSearch ({ ... });
146+ } catch (e ) {
147+ if (e instanceof ThordataRateLimitError ) {
148+ console .log (` Rate limited! Retry after ${e .retryAfter }s ` );
149+ } else if (e instanceof ThordataAuthError ) {
150+ console .log (" Check your tokens!" );
151+ }
152+ }
124153```
125154
126- ---
155+ ### Configuration Options
156+
157+ ``` typescript
158+ const client = new ThordataClient ({
159+ scraperToken: " ..." ,
160+ timeoutMs: 60000 ,
161+ maxRetries: 3 , // Auto-retry on 429/5xx
162+ });
163+ ```
127164
128165## 📄 License
129166
130- MIT License
167+ MIT License
0 commit comments