thordata-js-sdk 1.1.0 → 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.
- package/README.md +78 -101
- package/dist/examples/basic_scraper_task.d.ts +1 -0
- package/dist/examples/basic_scraper_task.d.ts.map +1 -0
- package/dist/examples/internal/example.d.ts +1 -0
- package/dist/examples/internal/example.d.ts.map +1 -0
- package/dist/examples/location_api.d.ts +1 -0
- package/dist/examples/location_api.d.ts.map +1 -0
- package/dist/examples/locations_basic.d.ts +1 -0
- package/dist/examples/locations_basic.d.ts.map +1 -0
- package/dist/examples/proxy_datacenter.d.ts +1 -0
- package/dist/examples/proxy_datacenter.d.ts.map +1 -0
- package/dist/examples/proxy_isp.d.ts +1 -0
- package/dist/examples/proxy_isp.d.ts.map +1 -0
- package/dist/examples/proxy_mobile.d.ts +1 -0
- package/dist/examples/proxy_mobile.d.ts.map +1 -0
- package/dist/examples/proxy_residential.d.ts +1 -0
- package/dist/examples/proxy_residential.d.ts.map +1 -0
- package/dist/examples/serp_basic.d.ts +1 -0
- package/dist/examples/serp_basic.d.ts.map +1 -0
- package/dist/examples/serp_google_news.d.ts +1 -0
- package/dist/examples/serp_google_news.d.ts.map +1 -0
- package/dist/examples/smoke_proxy_protocols.d.ts +2 -0
- package/dist/examples/smoke_proxy_protocols.d.ts.map +1 -0
- package/dist/examples/smoke_proxy_protocols.js +29 -0
- package/dist/examples/smoke_proxy_protocols.js.map +1 -0
- package/dist/examples/universal_basic.d.ts +1 -0
- package/dist/examples/universal_basic.d.ts.map +1 -0
- package/dist/examples/verify_new_features.d.ts +1 -0
- package/dist/examples/verify_new_features.d.ts.map +1 -0
- package/dist/examples/verify_structured_serp.d.ts +2 -0
- package/dist/examples/verify_structured_serp.d.ts.map +1 -0
- package/dist/examples/verify_structured_serp.js +38 -0
- package/dist/examples/verify_structured_serp.js.map +1 -0
- package/dist/src/auth.d.ts +1 -0
- package/dist/src/auth.d.ts.map +1 -0
- package/dist/src/client.d.ts +14 -77
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +130 -93
- package/dist/src/client.js.map +1 -1
- package/dist/src/endpoints.d.ts +1 -0
- package/dist/src/endpoints.d.ts.map +1 -0
- package/dist/src/enums.d.ts +1 -0
- package/dist/src/enums.d.ts.map +1 -0
- package/dist/src/errors.d.ts +1 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/models.d.ts +1 -0
- package/dist/src/models.d.ts.map +1 -0
- package/dist/src/proxy.d.ts +1 -0
- package/dist/src/proxy.d.ts.map +1 -0
- package/dist/src/proxy.js +12 -3
- package/dist/src/proxy.js.map +1 -1
- package/dist/src/retry.d.ts +1 -0
- package/dist/src/retry.d.ts.map +1 -0
- package/dist/src/serp_engines.d.ts +54 -0
- package/dist/src/serp_engines.d.ts.map +1 -0
- package/dist/src/serp_engines.js +81 -0
- package/dist/src/serp_engines.js.map +1 -0
- package/dist/src/thordata.d.ts +1 -0
- package/dist/src/thordata.d.ts.map +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -2,163 +2,140 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<img src="https://img.shields.io/badge/Thordata-AI%20Infrastructure-blue?style=for-the-badge" alt="Thordata Logo">
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**The Official Node.js/TypeScript Client for Thordata APIs**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
*Proxy Network • SERP API • Web Unlocker • Web Scraper API*
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/thordata-js-sdk)
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
[](https://github.com/Thordata/thordata-js-sdk/actions)
|
|
11
14
|
|
|
12
15
|
</div>
|
|
13
16
|
|
|
14
17
|
---
|
|
15
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.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
16
31
|
## 📦 Installation
|
|
17
32
|
|
|
18
33
|
```bash
|
|
19
34
|
npm install thordata-js-sdk
|
|
35
|
+
# or
|
|
36
|
+
yarn add thordata-js-sdk
|
|
20
37
|
```
|
|
21
38
|
|
|
39
|
+
---
|
|
40
|
+
|
|
22
41
|
## 🔐 Configuration
|
|
23
42
|
|
|
24
|
-
|
|
43
|
+
We recommend using `dotenv` to manage credentials.
|
|
25
44
|
|
|
26
45
|
```bash
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
30
51
|
```
|
|
31
52
|
|
|
53
|
+
---
|
|
54
|
+
|
|
32
55
|
## 🚀 Quick Start
|
|
33
56
|
|
|
57
|
+
### 1. SERP Search
|
|
58
|
+
|
|
34
59
|
```typescript
|
|
35
|
-
import {
|
|
60
|
+
import { ThordataClient, Engine } from "thordata-js-sdk";
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
const client = new Thordata();
|
|
62
|
+
const client = new ThordataClient({}); // Auto-loads from env
|
|
39
63
|
|
|
40
|
-
async function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
engine: "google",
|
|
64
|
+
async function search() {
|
|
65
|
+
const result = await client.serpSearch({
|
|
66
|
+
query: "SpaceX launch",
|
|
67
|
+
engine: Engine.GOOGLE_NEWS,
|
|
45
68
|
country: "us",
|
|
69
|
+
num: 5
|
|
46
70
|
});
|
|
47
|
-
|
|
71
|
+
|
|
72
|
+
console.log(result.news_results);
|
|
48
73
|
}
|
|
49
74
|
|
|
50
|
-
|
|
75
|
+
search();
|
|
51
76
|
```
|
|
52
77
|
|
|
53
|
-
|
|
78
|
+
### 2. Universal Scrape (Web Unlocker)
|
|
54
79
|
|
|
55
|
-
|
|
80
|
+
```typescript
|
|
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
|
+
}
|
|
91
|
+
```
|
|
56
92
|
|
|
57
|
-
|
|
93
|
+
### 3. Using the Proxy Network
|
|
58
94
|
|
|
59
95
|
```typescript
|
|
60
96
|
import { Thordata } from "thordata-js-sdk";
|
|
61
97
|
|
|
62
|
-
// Create proxy config
|
|
63
|
-
const proxy = Thordata.Proxy.residentialFromEnv()
|
|
98
|
+
// Create a targeted proxy config
|
|
99
|
+
const proxy = Thordata.Proxy.residentialFromEnv()
|
|
100
|
+
.country("gb")
|
|
101
|
+
.city("london")
|
|
102
|
+
.sticky(10); // 10 minutes session
|
|
64
103
|
|
|
65
|
-
|
|
66
|
-
console.log(proxy.toProxyUrl());
|
|
104
|
+
const client = new Thordata();
|
|
67
105
|
|
|
68
|
-
//
|
|
69
|
-
const response = await client.request("https://
|
|
106
|
+
// Request uses the proxy automatically
|
|
107
|
+
const response = await client.request("https://ipinfo.io/json", { proxy });
|
|
70
108
|
console.log(response);
|
|
71
109
|
```
|
|
72
110
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
import { Engine } from "thordata-js-sdk";
|
|
77
|
-
|
|
78
|
-
const news = await client.serpSearch({
|
|
79
|
-
query: "SpaceX",
|
|
80
|
-
engine: Engine.GOOGLE_NEWS,
|
|
81
|
-
num: 20,
|
|
82
|
-
country: "us",
|
|
83
|
-
language: "en",
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 🔓 Universal Scraping API (Web Unlocker)
|
|
111
|
+
---
|
|
88
112
|
|
|
89
|
-
|
|
90
|
-
const html = await client.universalScrape({
|
|
91
|
-
url: "https://example.com/spa",
|
|
92
|
-
jsRender: true,
|
|
93
|
-
waitFor: ".loaded-content",
|
|
94
|
-
blockResources: "image,media",
|
|
95
|
-
});
|
|
96
|
-
```
|
|
113
|
+
## ⚙️ Advanced Usage
|
|
97
114
|
|
|
98
|
-
###
|
|
115
|
+
### Task Management (Async)
|
|
99
116
|
|
|
100
117
|
```typescript
|
|
101
|
-
//
|
|
118
|
+
// Create a scraping task
|
|
102
119
|
const taskId = await client.createScraperTask({
|
|
103
|
-
fileName: "
|
|
120
|
+
fileName: "task_001",
|
|
104
121
|
spiderId: "universal",
|
|
105
122
|
spiderName: "universal",
|
|
106
|
-
parameters: { url: "https://example.com" }
|
|
123
|
+
parameters: { url: "https://example.com" }
|
|
107
124
|
});
|
|
108
125
|
|
|
109
|
-
|
|
126
|
+
console.log(`Task ${taskId} created. Waiting...`);
|
|
127
|
+
|
|
128
|
+
// Poll for completion
|
|
110
129
|
const status = await client.waitForTask(taskId);
|
|
111
130
|
|
|
112
|
-
// 3. Download
|
|
113
131
|
if (status === "ready") {
|
|
114
|
-
const
|
|
115
|
-
console.log(
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### 📊 Account Management
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
// Usage Stats
|
|
123
|
-
const stats = await client.getUsageStatistics("2024-01-01", "2024-01-31");
|
|
124
|
-
|
|
125
|
-
// Manage Whitelist
|
|
126
|
-
await client.addWhitelistIp("1.2.3.4");
|
|
127
|
-
|
|
128
|
-
// Check ISP Proxies
|
|
129
|
-
const servers = await client.listProxyServers(1); // 1=ISP
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## ⚙️ Advanced Usage
|
|
133
|
-
|
|
134
|
-
### Error Handling
|
|
135
|
-
|
|
136
|
-
The SDK throws typed errors for better control.
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
import { ThordataRateLimitError, ThordataAuthError } from "thordata-js-sdk";
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
await client.serpSearch({ ... });
|
|
143
|
-
} catch (e) {
|
|
144
|
-
if (e instanceof ThordataRateLimitError) {
|
|
145
|
-
console.log(`Rate limited! Retry after ${e.retryAfter}s`);
|
|
146
|
-
} else if (e instanceof ThordataAuthError) {
|
|
147
|
-
console.log("Check your tokens!");
|
|
148
|
-
}
|
|
132
|
+
const downloadUrl = await client.getTaskResult(taskId);
|
|
133
|
+
console.log("Result:", downloadUrl);
|
|
149
134
|
}
|
|
150
135
|
```
|
|
151
136
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
const client = new ThordataClient({
|
|
156
|
-
scraperToken: "...",
|
|
157
|
-
timeoutMs: 60000,
|
|
158
|
-
maxRetries: 3, // Auto-retry on 429/5xx
|
|
159
|
-
});
|
|
160
|
-
```
|
|
137
|
+
---
|
|
161
138
|
|
|
162
139
|
## 📄 License
|
|
163
140
|
|
|
164
|
-
MIT License
|
|
141
|
+
MIT License.
|
|
@@ -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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location_api.d.ts","sourceRoot":"","sources":["../../examples/location_api.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locations_basic.d.ts","sourceRoot":"","sources":["../../examples/locations_basic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy_datacenter.d.ts","sourceRoot":"","sources":["../../examples/proxy_datacenter.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy_isp.d.ts","sourceRoot":"","sources":["../../examples/proxy_isp.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy_mobile.d.ts","sourceRoot":"","sources":["../../examples/proxy_mobile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy_residential.d.ts","sourceRoot":"","sources":["../../examples/proxy_residential.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serp_basic.d.ts","sourceRoot":"","sources":["../../examples/serp_basic.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal_basic.d.ts","sourceRoot":"","sources":["../../examples/universal_basic.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"verify_structured_serp.js","sourceRoot":"","sources":["../../examples/verify_structured_serp.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,KAAK,UAAU,IAAI;IACjB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;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+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"}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -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
|
|
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;
|
|
@@ -143,24 +94,10 @@ export declare class ThordataClient {
|
|
|
143
94
|
addWhitelistIp(ip: string, status?: boolean, proxyType?: ProxyTypeParam): Promise<any>;
|
|
144
95
|
listProxyServers(proxyType: 1 | 2): Promise<ProxyServer[]>;
|
|
145
96
|
getProxyExpiration(ips: string | string[], proxyType: 1 | 2): Promise<Record<string, unknown>>;
|
|
146
|
-
/**
|
|
147
|
-
* Internal method to call locations API.
|
|
148
|
-
*/
|
|
149
97
|
private getLocations;
|
|
150
|
-
/**
|
|
151
|
-
* List all supported countries for a proxy type.
|
|
152
|
-
*/
|
|
153
98
|
listCountries(proxyType?: ProxyTypeParam): Promise<CountryInfo[]>;
|
|
154
|
-
/**
|
|
155
|
-
* List states/regions for a country.
|
|
156
|
-
*/
|
|
157
99
|
listStates(countryCode: string, proxyType?: ProxyTypeParam): Promise<StateInfo[]>;
|
|
158
|
-
/**
|
|
159
|
-
* List cities for a country (and optionally state).
|
|
160
|
-
*/
|
|
161
100
|
listCities(countryCode: string, stateCode?: string, proxyType?: ProxyTypeParam): Promise<CityInfo[]>;
|
|
162
|
-
/**
|
|
163
|
-
* List ASNs for a country.
|
|
164
|
-
*/
|
|
165
101
|
listAsns(countryCode: string, proxyType?: ProxyTypeParam): Promise<AsnInfo[]>;
|
|
166
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,MAA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