Skip to content

Commit fe0b31f

Browse files
committed
feat: last optimizations & renaming
1 parent 8f8182b commit fe0b31f

File tree

4 files changed

+157
-15
lines changed

4 files changed

+157
-15
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@scrape-do/do",
2+
"name": "@scrape-do/client",
33
"version": "1.0.0",
44
"main": "dist/lib.js",
55
"types": "src/lib.d.ts",
@@ -19,7 +19,7 @@
1919
],
2020
"repository": {
2121
"type": "git",
22-
"url": "git+ssh://git@github.com/scrape-do/node-do.git"
22+
"url": "git+ssh://git@github.com/scrape-do/node-client.git"
2323
},
2424
"scripts": {
2525
"dev": "npx ts-node src/lib.ts",

src/geocode.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
export type GeoCode =
2+
| "af" // Afghanistan
3+
| "al" // Albania
4+
| "ad" // Andorra
5+
| "ao" // Angola
6+
| "ar" // Argentina
7+
| "am" // Armenia
8+
| "aw" // Aruba
9+
| "au" // Australia
10+
| "at" // Austria
11+
| "az" // Azerbaijan
12+
| "bs" // Bahamas
13+
| "bd" // Bangladesh
14+
| "by" // Belarus
15+
| "be" // Belgium
16+
| "bz" // Belize
17+
| "bj" // Benin
18+
| "bt" // Bhutan
19+
| "bo" // Bolivia
20+
| "ba" // Bosnia Herzegovina
21+
| "br" // Brazil
22+
| "vg" // British Virgin Islands
23+
| "bg" // Bulgaria
24+
| "kh" // Cambodia
25+
| "cm" // Cameroon
26+
| "ca" // Canada
27+
| "cf" // Central African Republic
28+
| "td" // Chad
29+
| "cl" // Chile
30+
| "cn" // China
31+
| "co" // Colombia
32+
| "cr" // Costa Rica
33+
| "ci" // Cote D'Ivoire
34+
| "hr" // Croatia
35+
| "cu" // Cuba
36+
| "cy" // Cyprus
37+
| "cz" // Czech Republic
38+
| "dk" // Denmark
39+
| "dj" // Djibouti
40+
| "dm" // Dominica
41+
| "ec" // Ecuador
42+
| "eg" // Egypt
43+
| "ee" // Estonia
44+
| "et" // Ethiopia
45+
| "fj" // Fiji
46+
| "fi" // Finland
47+
| "fr" // France
48+
| "gm" // Gambia
49+
| "gb" // Great Britain
50+
| "ge" // Georgia
51+
| "de" // Germany
52+
| "gh" // Ghana
53+
| "gr" // Greece
54+
| "ht" // Haiti
55+
| "hn" // Honduras
56+
| "hk" // Hong Kong
57+
| "hu" // Hungary
58+
| "is" // Iceland
59+
| "il" // Israel
60+
| "in" // India
61+
| "id" // Indonesia
62+
| "ir" // Iran
63+
| "iq" // Iraq
64+
| "ie" // Ireland
65+
| "it" // Italy
66+
| "jm" // Jamaica
67+
| "jp" // Japan
68+
| "jo" // Jordan
69+
| "kz" // Kazakhstan
70+
| "ke" // Kenya
71+
| "lb" // Lebanon
72+
| "lr" // Liberia
73+
| "li" // Liechtenstein
74+
| "lt" // Lithuania
75+
| "lv" // Latvia
76+
| "lu" // Luxembourg
77+
| "mk" // Macedonia
78+
| "mg" // Madagascar
79+
| "my" // Malaysia
80+
| "mv" // Maldives
81+
| "ml" // Mali
82+
| "mt" // Malta
83+
| "mr" // Mauritania
84+
| "mu" // Mauritius
85+
| "mx" // Mexico
86+
| "md" // Moldova
87+
| "mc" // Monaco
88+
| "mn" // Mongolia
89+
| "me" // Montenegro
90+
| "ma" // Morocco
91+
| "mz" // Mozambique
92+
| "mm" // Myanmar
93+
| "nl" // Netherlands
94+
| "nz" // New Zealand
95+
| "ng" // Nigeria
96+
| "no" // Norway
97+
| "om" // Oman
98+
| "pk" // Pakistan
99+
| "pa" // Panama
100+
| "py" // Paraguay
101+
| "pe" // Peru
102+
| "ph" // Philippines
103+
| "pt" // Portugal
104+
| "pl" // Poland
105+
| "pr" // Puerto Rico
106+
| "qa" // Qatar
107+
| "ro" // Romania
108+
| "sa" // Saudi Arabia
109+
| "sn" // Senegal
110+
| "rs" // Serbia
111+
| "sc" // Seychelles
112+
| "sg" // Singapore
113+
| "sk" // Slovakia
114+
| "si" // Slovenia
115+
| "za" // South Africa
116+
| "kr" // South Korea
117+
| "ss" // South Sudan
118+
| "es" // Spain
119+
| "sd" // Sudan
120+
| "se" // Sweden
121+
| "ch" // Switzerland
122+
| "tw" // Taiwan
123+
| "th" // Thailand
124+
| "tn" // Tunisia
125+
| "tg" // Togo
126+
| "tr" // Turkey
127+
| "tm" // Turkmenistan
128+
| "ae" // United Arab Emirates
129+
| "ug" // Uganda
130+
| "ua" // Ukraine
131+
| "uy" // Uruguay
132+
| "us" // United States
133+
| "uz" // Uzbekistan
134+
| "ve" // Venezuela
135+
| "vn" // Vietnam
136+
| "ye" // Yemen
137+
| "zm" // Zambia
138+
| "zw"; // Zimbabwe

src/lib.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import axios, { AxiosInstance, AxiosResponse } from "axios";
22
import { PlayWithBrowser } from "./playwithbrowser";
3+
import { GeoCode } from "./geocode";
34

45
export const API_URL = "https://api.scrape.do";
56

67
/**
78
* Proxy options for the request
89
* @property {boolean} [super] - Use super proxy
9-
* @property {string} [geoCode] - Geographical code
10-
* @property {string} [regionalGeoCode] - Regional geographical code
10+
* @property {GeoCode} [geoCode] - Geographical code
11+
* @property {"europe" | "asia" | "africa" | "oceania" | "northamerica" | "southamerica"} [regionalGeoCode] - Regional geographical code
1112
* @property {string} [sessionId] - Session ID for the proxy
1213
*
1314
* @see https://scrape.do/documentation/
1415
*/
1516
type ProxyOptions = {
1617
super?: boolean;
17-
geoCode?: string;
18-
regionalGeoCode?: string;
18+
geoCode?: GeoCode;
19+
regionalGeoCode?: "europe" | "asia" | "africa" | "oceania" | "northamerica" | "southamerica";
1920
sessionId?: string;
2021
};
2122

@@ -63,8 +64,8 @@ type RenderOptions = {
6364
* @property {number} [timeout] - Timeout for the request
6465
* @property {number} [retryTimeout] - Retry timeout for the request
6566
* @property {boolean} [disableRetry] - Disable retry
66-
* @property {string} [device] - Device for the request
67-
* @property {string} [output] - Output format
67+
* @property {"Desktop" | "Mobile"} [device] - Device for the request
68+
* @property {"raw" | "markdown"} [output] - Output format
6869
* @property {boolean} [transparentResponse] - Get transparent response
6970
* @property {ProxyOptions} [super] - Proxy options
7071
* @property {RenderOptions} [render] - Render options
@@ -82,8 +83,8 @@ export type DoRequest = {
8283
timeout?: number;
8384
retryTimeout?: number;
8485
disableRetry?: boolean;
85-
device?: string;
86-
output?: string;
86+
device?: "Desktop" | "Mobile";
87+
output?: "raw" | "markdown";
8788
transparentResponse?: boolean;
8889
} & ProxyOptions &
8990
RenderOptions;
@@ -205,10 +206,13 @@ export class ScrapeDo {
205206
}
206207

207208
if (options.extraHeaders) {
208-
headers = {
209-
...headers,
210-
...options.extraHeaders,
211-
};
209+
for (let key in options.extraHeaders) {
210+
if (key.startsWith("sd-")) {
211+
headers[key] = options.extraHeaders[key];
212+
} else {
213+
headers[`sd-${key}`] = options.extraHeaders[key];
214+
}
215+
}
212216
}
213217

214218
if (options.forwardHeaders) {

tests/lib.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("Usability tests", () => {
99
const response = await client.doRequest("GET", {
1010
url: "https://httpbin.co/anything",
1111
extraHeaders: {
12-
"sd-A123": "Extra Header",
12+
A123: "Extra Header",
1313
},
1414
});
1515

0 commit comments

Comments
 (0)