@decodo/sdk-ts 1.1.2 → 2.0.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 (48) hide show
  1. package/README.md +136 -1
  2. package/build/cjs/api/web-scraping-api.d.ts +13 -0
  3. package/build/cjs/api/web-scraping-api.js +41 -0
  4. package/build/cjs/client.d.ts +11 -0
  5. package/build/cjs/client.js +34 -0
  6. package/build/cjs/errors.d.ts +18 -0
  7. package/build/cjs/errors.js +44 -0
  8. package/build/cjs/generated/parameters.d.ts +11 -0
  9. package/build/cjs/generated/parameters.js +85 -0
  10. package/build/cjs/generated/request-schemas.d.ts +2123 -0
  11. package/build/cjs/generated/request-schemas.js +2431 -0
  12. package/build/cjs/generated/targets.d.ts +735 -0
  13. package/build/cjs/generated/targets.js +343 -0
  14. package/build/cjs/http.d.ts +22 -0
  15. package/build/cjs/http.js +94 -0
  16. package/build/cjs/index.d.ts +9 -0
  17. package/build/cjs/index.js +19 -0
  18. package/build/cjs/types/requests.d.ts +1 -0
  19. package/build/cjs/types/requests.js +2 -0
  20. package/build/cjs/types/responses.d.ts +62 -0
  21. package/build/cjs/types/responses.js +2 -0
  22. package/build/esm/api/web-scraping-api.d.ts +13 -0
  23. package/build/esm/api/web-scraping-api.js +37 -0
  24. package/build/esm/client.d.ts +11 -0
  25. package/build/esm/client.js +30 -0
  26. package/build/esm/errors.d.ts +18 -0
  27. package/build/esm/errors.js +36 -0
  28. package/build/esm/generated/parameters.d.ts +11 -0
  29. package/build/esm/generated/parameters.js +82 -0
  30. package/build/esm/generated/request-schemas.d.ts +2123 -0
  31. package/build/esm/generated/request-schemas.js +2395 -0
  32. package/build/esm/generated/targets.d.ts +735 -0
  33. package/build/esm/generated/targets.js +340 -0
  34. package/build/esm/http.d.ts +22 -0
  35. package/build/esm/http.js +90 -0
  36. package/build/esm/index.d.ts +9 -0
  37. package/build/esm/index.js +5 -0
  38. package/build/esm/types/requests.d.ts +1 -0
  39. package/build/esm/types/requests.js +1 -0
  40. package/build/esm/types/responses.d.ts +62 -0
  41. package/build/esm/types/responses.js +1 -0
  42. package/package.json +37 -46
  43. package/CHANGELOG.md +0 -53
  44. package/lib/cjs/index.js +0 -1240
  45. package/lib/cjs/index.js.map +0 -1
  46. package/lib/esm/index.js +0 -1235
  47. package/lib/esm/index.js.map +0 -1
  48. package/lib/types/index.d.ts +0 -465
@@ -0,0 +1,340 @@
1
+ // Auto-generated by src/codegen/web-scraping-api/generate-targets.ts — do not edit
2
+ /**
3
+ * Scrape target discriminator (wire string values).
4
+ */
5
+ export var Target;
6
+ (function (Target) {
7
+ Target["UniversalEcommerce"] = "universal_ecommerce";
8
+ Target["GoogleSearch"] = "google_search";
9
+ Target["GoogleTravelHotels"] = "google_travel_hotels";
10
+ Target["GoogleTrendsExplore"] = "google_trends_explore";
11
+ Target["GoogleShoppingSearch"] = "google_shopping_search";
12
+ Target["GoogleShoppingProduct"] = "google_shopping_product";
13
+ Target["Google"] = "google";
14
+ Target["GoogleSuggest"] = "google_suggest";
15
+ Target["GoogleMaps"] = "google_maps";
16
+ Target["GoogleAiMode"] = "google_ai_mode";
17
+ Target["GoogleAds"] = "google_ads";
18
+ Target["GoogleLens"] = "google_lens";
19
+ Target["BingSearch"] = "bing_search";
20
+ Target["Bing"] = "bing";
21
+ Target["YoutubeTranscript"] = "youtube_transcript";
22
+ Target["AmazonProduct"] = "amazon_product";
23
+ Target["AmazonPricing"] = "amazon_pricing";
24
+ Target["AmazonSearch"] = "amazon_search";
25
+ Target["AmazonSellers"] = "amazon_sellers";
26
+ Target["AmazonBestsellers"] = "amazon_bestsellers";
27
+ Target["Amazon"] = "amazon";
28
+ Target["Ecommerce"] = "ecommerce";
29
+ Target["EcommerceCore"] = "ecommerce_core";
30
+ Target["WalmartProduct"] = "walmart_product";
31
+ Target["WalmartSearch"] = "walmart_search";
32
+ Target["Walmart"] = "walmart";
33
+ Target["TargetProduct"] = "target_product";
34
+ Target["TargetSearch"] = "target_search";
35
+ Target["Target"] = "target";
36
+ Target["LowesSearch"] = "lowes_search";
37
+ Target["Universal"] = "universal";
38
+ Target["UniversalCore"] = "universal_core";
39
+ Target["Chatgpt"] = "chatgpt";
40
+ Target["Perplexity"] = "perplexity";
41
+ Target["Bbb"] = "bbb";
42
+ Target["Autotrader"] = "autotrader";
43
+ Target["Mobile"] = "mobile";
44
+ Target["Airbnb"] = "airbnb";
45
+ Target["AppleAppStore"] = "apple_app_store";
46
+ Target["InstagramGraphqlProfile"] = "instagram_graphql_profile";
47
+ Target["TiktokPost"] = "tiktok_post";
48
+ Target["TiktokShopSearch"] = "tiktok_shop_search";
49
+ Target["TiktokShopProduct"] = "tiktok_shop_product";
50
+ Target["Tiktok"] = "tiktok";
51
+ Target["RedditPost"] = "reddit_post";
52
+ Target["RedditSubreddit"] = "reddit_subreddit";
53
+ Target["RedditUser"] = "reddit_user";
54
+ Target["YoutubeVideo"] = "youtube_video";
55
+ Target["YoutubeMetadata"] = "youtube_metadata";
56
+ Target["YoutubeSearch"] = "youtube_search";
57
+ Target["YoutubeSearchMax"] = "youtube_search_max";
58
+ Target["YoutubeSubtitles"] = "youtube_subtitles";
59
+ Target["YoutubeChannel"] = "youtube_channel";
60
+ Target["SiteUnblocker"] = "site_unblocker";
61
+ Target["SiteUnblockerReq"] = "site_unblocker_req";
62
+ })(Target || (Target = {}));
63
+ export const targets = [Target.UniversalEcommerce, Target.GoogleSearch, Target.GoogleTravelHotels, Target.GoogleTrendsExplore, Target.GoogleShoppingSearch, Target.GoogleShoppingProduct, Target.Google, Target.GoogleSuggest, Target.GoogleMaps, Target.GoogleAiMode, Target.GoogleAds, Target.GoogleLens, Target.BingSearch, Target.Bing, Target.YoutubeTranscript, Target.AmazonProduct, Target.AmazonPricing, Target.AmazonSearch, Target.AmazonSellers, Target.AmazonBestsellers, Target.Amazon, Target.Ecommerce, Target.EcommerceCore, Target.WalmartProduct, Target.WalmartSearch, Target.Walmart, Target.TargetProduct, Target.TargetSearch, Target.Target, Target.LowesSearch, Target.Universal, Target.UniversalCore, Target.Chatgpt, Target.Perplexity, Target.Bbb, Target.Autotrader, Target.Mobile, Target.Airbnb, Target.AppleAppStore, Target.InstagramGraphqlProfile, Target.TiktokPost, Target.TiktokShopSearch, Target.TiktokShopProduct, Target.Tiktok, Target.RedditPost, Target.RedditSubreddit, Target.RedditUser, Target.YoutubeVideo, Target.YoutubeMetadata, Target.YoutubeSearch, Target.YoutubeSearchMax, Target.YoutubeSubtitles, Target.YoutubeChannel, Target.SiteUnblocker, Target.SiteUnblockerReq];
64
+ export const targetMeta = {
65
+ [Target.UniversalEcommerce]: {
66
+ group: "None",
67
+ response_format: "html",
68
+ parameters: ["callback_url"],
69
+ },
70
+ [Target.GoogleSearch]: {
71
+ group: "Google",
72
+ response_format: "json",
73
+ parameters: ["query", "headless", "locale", "geo", "device_type", "page_from", "google_results_language", "google_tbm", "google_tbs", "parse", "google_nfpr", "google_safe_search", "session_id", "xhr", "markdown", "page_count", "callback_url"],
74
+ },
75
+ [Target.GoogleTravelHotels]: {
76
+ group: "Google",
77
+ response_format: "html",
78
+ parameters: ["query", "headless", "locale", "device_type", "page_from", "date_range", "stars", "adults", "children", "session_id", "markdown", "callback_url"],
79
+ },
80
+ [Target.GoogleTrendsExplore]: {
81
+ group: "Google",
82
+ response_format: "json",
83
+ parameters: ["query", "geo", "device_type", "search_type", "date_start", "date_end", "callback_url"],
84
+ },
85
+ [Target.GoogleShoppingSearch]: {
86
+ group: "Google",
87
+ response_format: "json",
88
+ parameters: ["query", "headless", "locale", "geo", "device_type", "page_from", "google_tbs", "parse", "session_id", "google_results_language", "markdown", "callback_url"],
89
+ },
90
+ [Target.GoogleShoppingProduct]: {
91
+ group: "Google",
92
+ response_format: "json",
93
+ parameters: ["query", "headless", "locale", "geo", "device_type", "page_from", "parse", "session_id", "google_results_language", "markdown", "xhr", "callback_url"],
94
+ },
95
+ [Target.Google]: {
96
+ group: "Google",
97
+ response_format: "json",
98
+ parameters: ["url", "headless", "locale", "device_type", "parse", "session_id", "markdown", "xhr", "page_count", "callback_url"],
99
+ },
100
+ [Target.GoogleSuggest]: {
101
+ group: "Google",
102
+ response_format: "json",
103
+ parameters: ["query", "device_type", "geo", "locale", "session_id", "callback_url"],
104
+ },
105
+ [Target.GoogleMaps]: {
106
+ group: "Google",
107
+ response_format: "html",
108
+ parameters: ["query", "headless", "geo", "locale", "page_from", "device_type", "session_id", "google_results_language", "google_nfpr", "hotel_occupancy", "date_range", "markdown", "callback_url"],
109
+ },
110
+ [Target.GoogleAiMode]: {
111
+ group: "AI Tools",
112
+ response_format: "json",
113
+ parameters: ["query", "geo", "parse", "device_type", "session_id", "markdown", "xhr", "callback_url"],
114
+ },
115
+ [Target.GoogleAds]: {
116
+ group: "Google",
117
+ response_format: "json",
118
+ parameters: ["query", "headless", "locale", "geo", "device_type", "page_from", "google_results_language", "google_tbm", "google_tbs", "parse", "google_nfpr", "session_id", "markdown", "xhr", "page_count", "callback_url"],
119
+ },
120
+ [Target.GoogleLens]: {
121
+ group: "Google",
122
+ response_format: "json",
123
+ parameters: ["query", "headless", "parse", "device_type", "markdown", "callback_url"],
124
+ },
125
+ [Target.BingSearch]: {
126
+ group: "Bing",
127
+ response_format: "json",
128
+ parameters: ["query", "headless", "locale", "geo", "domain", "device_type", "page_from", "parse", "page_count", "session_id", "markdown", "xhr", "callback_url"],
129
+ },
130
+ [Target.Bing]: {
131
+ group: "Bing",
132
+ response_format: "json",
133
+ parameters: ["url", "headless", "locale", "geo", "device_type", "page_from", "parse", "session_id", "markdown", "xhr", "callback_url"],
134
+ },
135
+ [Target.YoutubeTranscript]: {
136
+ group: "YouTube",
137
+ response_format: "json",
138
+ parameters: ["query", "language_code", "transcript_origin", "callback_url"],
139
+ },
140
+ [Target.AmazonProduct]: {
141
+ group: "Amazon",
142
+ response_format: "json",
143
+ parameters: ["query", "headless", "domain", "device_type", "parse", "autoselect_variant", "geo", "session_id", "currency", "markdown", "xhr", "callback_url"],
144
+ },
145
+ [Target.AmazonPricing]: {
146
+ group: "Amazon",
147
+ response_format: "json",
148
+ parameters: ["query", "headless", "domain", "device_type", "page_from", "parse", "geo", "session_id", "currency", "markdown", "xhr", "callback_url"],
149
+ },
150
+ [Target.AmazonSearch]: {
151
+ group: "Amazon",
152
+ response_format: "json",
153
+ parameters: ["query", "headless", "domain", "device_type", "page_from", "category", "merchant", "parse", "geo", "session_id", "sort_by", "currency", "markdown", "xhr", "callback_url"],
154
+ },
155
+ [Target.AmazonSellers]: {
156
+ group: "Amazon",
157
+ response_format: "json",
158
+ parameters: ["query", "headless", "locale", "domain", "device_type", "geo", "parse", "markdown", "xhr", "callback_url"],
159
+ },
160
+ [Target.AmazonBestsellers]: {
161
+ group: "Amazon",
162
+ response_format: "json",
163
+ parameters: ["query", "domain", "device_type", "geo", "page_from", "category", "parse", "session_id", "currency", "markdown", "xhr", "callback_url"],
164
+ },
165
+ [Target.Amazon]: {
166
+ group: "Amazon",
167
+ response_format: "json",
168
+ parameters: ["url", "headless", "device_type", "parse", "geo", "session_id", "markdown", "xhr", "callback_url"],
169
+ },
170
+ [Target.Ecommerce]: {
171
+ group: "Other eCommerce",
172
+ response_format: "json",
173
+ parameters: ["url", "headless", "locale", "geo", "device_type", "parse", "parser_type", "callback_url"],
174
+ },
175
+ [Target.EcommerceCore]: {
176
+ group: "None",
177
+ response_format: "html",
178
+ parameters: ["url", "payload", "geo", "http_method", "successful_status_codes", "callback_url"],
179
+ },
180
+ [Target.WalmartProduct]: {
181
+ group: "Walmart",
182
+ response_format: "html",
183
+ parameters: ["product_id", "headless", "parse", "xhr", "markdown", "fulfillment_type", "walmart_store_id", "delivery_zip", "callback_url"],
184
+ },
185
+ [Target.WalmartSearch]: {
186
+ group: "Walmart",
187
+ response_format: "json",
188
+ parameters: ["query", "headless", "parse", "markdown", "fulfillment_type", "walmart_store_id", "delivery_zip", "callback_url"],
189
+ },
190
+ [Target.Walmart]: {
191
+ group: "Walmart",
192
+ response_format: "html",
193
+ parameters: ["url", "headless", "locale", "geo", "device_type", "store_id", "markdown", "xhr", "callback_url"],
194
+ },
195
+ [Target.TargetProduct]: {
196
+ group: "Target",
197
+ response_format: "json",
198
+ parameters: ["product_id", "headless", "parse", "device_type", "markdown", "xhr", "delivery_type", "target_store_id", "delivery_zip", "callback_url"],
199
+ },
200
+ [Target.TargetSearch]: {
201
+ group: "Target",
202
+ response_format: "json",
203
+ parameters: ["query", "headless", "parse", "device_type", "delivery_type", "target_store_id", "delivery_zip", "xhr", "markdown", "callback_url"],
204
+ },
205
+ [Target.Target]: {
206
+ group: "Target",
207
+ response_format: "html",
208
+ parameters: ["url", "headless", "device_type", "xhr", "delivery_zip", "target_store_id", "callback_url"],
209
+ },
210
+ [Target.LowesSearch]: {
211
+ group: "Lowe's",
212
+ response_format: "json",
213
+ parameters: ["query", "lowes_store_id", "headless", "delivery_zip", "user_agent_type", "free_delivery", "pickup_today", "delivery_today_tomorrow", "callback_url"],
214
+ },
215
+ [Target.Universal]: {
216
+ group: "Universal",
217
+ response_format: "html",
218
+ parameters: ["url", "payload", "proxy_pool", "http_method", "headless", "geo", "locale", "device_type", "session_id", "successful_status_codes", "headers", "cookies", "force_headers", "force_cookies", "xhr", "markdown", "callback_url"],
219
+ },
220
+ [Target.UniversalCore]: {
221
+ group: "None",
222
+ response_format: "html",
223
+ parameters: ["url", "payload", "geo", "http_method", "successful_status_codes", "callback_url"],
224
+ },
225
+ [Target.Chatgpt]: {
226
+ group: "AI Tools",
227
+ response_format: "json",
228
+ parameters: ["prompt", "search", "parse", "geo", "device_type", "markdown", "xhr", "callback_url"],
229
+ },
230
+ [Target.Perplexity]: {
231
+ group: "AI Tools",
232
+ response_format: "json",
233
+ parameters: ["prompt", "parse", "geo", "device_type", "markdown", "xhr", "callback_url"],
234
+ },
235
+ [Target.Bbb]: {
236
+ group: "Business Reviews",
237
+ response_format: "html",
238
+ parameters: ["url", "headless", "geo", "device_type", "markdown", "xhr", "callback_url"],
239
+ },
240
+ [Target.Autotrader]: {
241
+ group: "Marketplace",
242
+ response_format: "html",
243
+ parameters: ["url", "headless", "geo", "device_type", "markdown", "xhr", "callback_url"],
244
+ },
245
+ [Target.Mobile]: {
246
+ group: "Marketplace",
247
+ response_format: "html",
248
+ parameters: ["url", "headless", "geo", "device_type", "markdown", "xhr", "callback_url"],
249
+ },
250
+ [Target.Airbnb]: {
251
+ group: "Travel",
252
+ response_format: "html",
253
+ parameters: ["url", "headless", "geo", "device_type", "markdown", "xhr", "callback_url"],
254
+ },
255
+ [Target.AppleAppStore]: {
256
+ group: "Marketplace",
257
+ response_format: "html",
258
+ parameters: ["url", "headless", "geo", "device_type", "markdown", "xhr", "callback_url"],
259
+ },
260
+ [Target.InstagramGraphqlProfile]: {
261
+ group: "Instagram",
262
+ response_format: "json",
263
+ parameters: ["query", "callback_url"],
264
+ },
265
+ [Target.TiktokPost]: {
266
+ group: "TikTok",
267
+ response_format: "html",
268
+ parameters: ["url", "xhr", "callback_url"],
269
+ },
270
+ [Target.TiktokShopSearch]: {
271
+ group: "TikTok",
272
+ response_format: "html",
273
+ parameters: ["query", "headless", "device_type", "markdown", "country", "callback_url"],
274
+ },
275
+ [Target.TiktokShopProduct]: {
276
+ group: "TikTok",
277
+ response_format: "html",
278
+ parameters: ["product_id", "headless", "device_type", "xhr", "markdown", "country", "callback_url"],
279
+ },
280
+ [Target.Tiktok]: {
281
+ group: "TikTok",
282
+ response_format: "html",
283
+ parameters: ["url", "headless", "user_agent_type", "callback_url"],
284
+ },
285
+ [Target.RedditPost]: {
286
+ group: "Reddit",
287
+ response_format: "json",
288
+ parameters: ["url", "locale", "geo", "callback_url"],
289
+ },
290
+ [Target.RedditSubreddit]: {
291
+ group: "Reddit",
292
+ response_format: "json",
293
+ parameters: ["url", "locale", "geo", "callback_url"],
294
+ },
295
+ [Target.RedditUser]: {
296
+ group: "Reddit",
297
+ response_format: "json",
298
+ parameters: ["url", "locale", "geo", "sort", "callback_url"],
299
+ },
300
+ [Target.YoutubeVideo]: {
301
+ group: "None",
302
+ response_format: "json",
303
+ parameters: ["query", "geo", "callback_url"],
304
+ },
305
+ [Target.YoutubeMetadata]: {
306
+ group: "YouTube",
307
+ response_format: "json",
308
+ parameters: ["query", "callback_url"],
309
+ },
310
+ [Target.YoutubeSearch]: {
311
+ group: "YouTube",
312
+ response_format: "json",
313
+ parameters: ["360", "query", "upload_date", "type", "duration", "video_sort_by", "3d", "4k", "creative_commons", "hd", "hdr", "vr180", "live", "location", "purchased", "subtitles", "callback_url"],
314
+ },
315
+ [Target.YoutubeSearchMax]: {
316
+ group: "YouTube",
317
+ response_format: "json",
318
+ parameters: ["360", "query", "upload_date", "type", "duration", "video_sort_by", "3d", "4k", "creative_commons", "hd", "hdr", "vr180", "live", "location", "purchased", "subtitles", "markdown", "callback_url"],
319
+ },
320
+ [Target.YoutubeSubtitles]: {
321
+ group: "YouTube",
322
+ response_format: "json",
323
+ parameters: ["query", "language_code", "subtitle_origin", "callback_url"],
324
+ },
325
+ [Target.YoutubeChannel]: {
326
+ group: "YouTube",
327
+ response_format: "json",
328
+ parameters: ["query", "parse", "limit", "markdown", "callback_url"],
329
+ },
330
+ [Target.SiteUnblocker]: {
331
+ group: "None",
332
+ response_format: "html",
333
+ parameters: ["url", "geo", "locale", "session_id", "http_method", "customStatusCode", "requestBody", "headless", "headers", "force_headers", "force_cookies", "customCookies", "markdown", "callback_url"],
334
+ },
335
+ [Target.SiteUnblockerReq]: {
336
+ group: "None",
337
+ response_format: "html",
338
+ parameters: ["url", "geo", "locale", "session_id", "http_method", "customStatusCode", "requestBody", "headless", "headers", "force_headers", "force_cookies", "customCookies", "markdown", "callback_url"],
339
+ },
340
+ };
@@ -0,0 +1,22 @@
1
+ export type BasicAuth = {
2
+ type: 'basic';
3
+ token: string;
4
+ };
5
+ export type ApiKeyAuth = {
6
+ type: 'apiKey';
7
+ apiKey: string;
8
+ };
9
+ export type HttpClientConfig = {
10
+ baseUrl: string;
11
+ auth: BasicAuth | ApiKeyAuth;
12
+ timeoutMs: number;
13
+ };
14
+ export declare class HttpClient {
15
+ private readonly baseUrl;
16
+ private readonly authHeader;
17
+ private readonly timeoutMs;
18
+ constructor(config: HttpClientConfig);
19
+ request<T>(method: string, path: string, body?: unknown): Promise<T>;
20
+ post<T>(path: string, body: unknown): Promise<T>;
21
+ get<T>(path: string, query?: Record<string, string>): Promise<T>;
22
+ }
@@ -0,0 +1,90 @@
1
+ import { DecodoError, AuthenticationError, RateLimitError, ValidationError, TimeoutError, } from './errors.js';
2
+ export class HttpClient {
3
+ baseUrl;
4
+ authHeader;
5
+ timeoutMs;
6
+ constructor(config) {
7
+ this.baseUrl = config.baseUrl.replace(/\/+$/, '');
8
+ this.timeoutMs = config.timeoutMs;
9
+ if (config.auth.type === 'basic') {
10
+ this.authHeader = `Basic ${config.auth.token}`;
11
+ }
12
+ else {
13
+ this.authHeader = config.auth.apiKey;
14
+ }
15
+ }
16
+ async request(method, path, body) {
17
+ const url = `${this.baseUrl}${path}`;
18
+ const controller = new AbortController();
19
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
20
+ try {
21
+ const init = {
22
+ method,
23
+ headers: {
24
+ Authorization: this.authHeader,
25
+ 'Content-Type': 'application/json',
26
+ Accept: 'application/json',
27
+ },
28
+ signal: controller.signal,
29
+ };
30
+ if (body !== undefined) {
31
+ init.body = JSON.stringify(body);
32
+ }
33
+ const res = await fetch(url, init);
34
+ if (res.ok) {
35
+ if (res.status === 204) {
36
+ return undefined;
37
+ }
38
+ return (await res.json());
39
+ }
40
+ let errorBody;
41
+ try {
42
+ errorBody = (await res.json());
43
+ }
44
+ catch {
45
+ // response body wasn't JSON
46
+ }
47
+ const message = errorBody?.message ?? `HTTP ${res.status}`;
48
+ if (res.status === 401 || res.status === 403) {
49
+ throw new AuthenticationError(message);
50
+ }
51
+ if (res.status === 429) {
52
+ throw new RateLimitError(message);
53
+ }
54
+ if (res.status === 422 || (res.status === 400 && errorBody?.errors)) {
55
+ throw new ValidationError(message, errorBody?.errors);
56
+ }
57
+ throw new DecodoError(message, res.status, errorBody?.status);
58
+ }
59
+ catch (err) {
60
+ if (err instanceof DecodoError) {
61
+ throw err;
62
+ }
63
+ if (err instanceof TypeError &&
64
+ err.cause?.code ===
65
+ 'ABORT_ERR') {
66
+ throw new TimeoutError(`Request to ${path} timed out after ${this.timeoutMs}ms`);
67
+ }
68
+ if (err instanceof DOMException && err.name === 'AbortError') {
69
+ throw new TimeoutError(`Request to ${path} timed out after ${this.timeoutMs}ms`);
70
+ }
71
+ throw err;
72
+ }
73
+ finally {
74
+ clearTimeout(timer);
75
+ }
76
+ }
77
+ post(path, body) {
78
+ return this.request('POST', path, body);
79
+ }
80
+ get(path, query) {
81
+ if (query) {
82
+ const params = new URLSearchParams(query);
83
+ const qs = params.toString();
84
+ if (qs) {
85
+ return this.request('GET', `${path}?${qs}`);
86
+ }
87
+ }
88
+ return this.request('GET', path);
89
+ }
90
+ }
@@ -0,0 +1,9 @@
1
+ export { DecodoClient } from './client.js';
2
+ export type { DecodoConfig } from './client.js';
3
+ export { WebScrapingApi } from './api/web-scraping-api.js';
4
+ export type { TargetString, TargetParamsMap, TargetMeta, ScrapeRequest, BatchRequest, } from './generated/targets.js';
5
+ export { targets, targetMeta, Target, } from './generated/targets.js';
6
+ export { parameterMeta } from './generated/parameters.js';
7
+ export type { ParameterMeta } from './generated/parameters.js';
8
+ export type { SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse, TaskStatus, ResultEntry, } from './types/responses.js';
9
+ export { DecodoError, AuthenticationError, RateLimitError, ValidationError, TimeoutError, } from './errors.js';
@@ -0,0 +1,5 @@
1
+ export { DecodoClient } from './client.js';
2
+ export { WebScrapingApi } from './api/web-scraping-api.js';
3
+ export { targets, targetMeta, Target, } from './generated/targets.js';
4
+ export { parameterMeta } from './generated/parameters.js';
5
+ export { DecodoError, AuthenticationError, RateLimitError, ValidationError, TimeoutError, } from './errors.js';
@@ -0,0 +1 @@
1
+ export type { ScrapeRequest, BatchRequest } from '../generated/targets.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ export type ResultEntry = {
2
+ content: unknown;
3
+ status_code: number;
4
+ url?: string;
5
+ task_id: string;
6
+ headers?: Record<string, string>;
7
+ cookies?: Record<string, string>[];
8
+ created_at: string;
9
+ updated_at: string;
10
+ help?: string;
11
+ browser_actions_warnings?: Record<string, string>[];
12
+ browser_actions_error?: Record<string, string>[];
13
+ delivery_zip?: string;
14
+ };
15
+ export type SyncResponse = {
16
+ results: ResultEntry[];
17
+ };
18
+ export type AsyncTaskResponse = {
19
+ id: string;
20
+ target?: string;
21
+ url?: string;
22
+ query?: string;
23
+ status: string;
24
+ created_at?: string;
25
+ updated_at?: string;
26
+ page_from?: number;
27
+ limit?: number;
28
+ geo?: string | null;
29
+ device_type?: string;
30
+ headless?: string | null;
31
+ parse?: boolean;
32
+ locale?: string | null;
33
+ domain?: string;
34
+ output_schema?: string | null;
35
+ content_encoding?: string;
36
+ page_count?: number;
37
+ adults?: number;
38
+ children?: number;
39
+ callback_url?: string;
40
+ browser_actions_error?: Record<string, string>[];
41
+ browser_actions_warnings?: Record<string, string>[];
42
+ };
43
+ export type BatchResponse = {
44
+ id?: string;
45
+ queries?: AsyncTaskResponse[];
46
+ errors?: Array<{
47
+ message: string;
48
+ }>;
49
+ };
50
+ export type TaskStatus = 'pending' | 'faulted' | 'done';
51
+ export type TaskMetadata = {
52
+ status: TaskStatus;
53
+ [key: string]: unknown;
54
+ };
55
+ export type TaskResultsResponse = {
56
+ results: ResultEntry[];
57
+ };
58
+ export type ErrorResponse = {
59
+ status: string;
60
+ message: string;
61
+ errors?: unknown[];
62
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,58 +1,49 @@
1
1
  {
2
2
  "name": "@decodo/sdk-ts",
3
- "version": "1.1.2",
4
- "description": "",
3
+ "version": "2.0.0",
4
+ "description": "Official TypeScript SDK for the Decodo APIs",
5
5
  "type": "module",
6
- "main": "lib/cjs/index.js",
7
- "module": "lib/esm/index.js",
8
- "types": "lib/types/index.d.ts",
6
+ "main": "./build/cjs/index.cjs",
7
+ "module": "./build/esm/index.js",
8
+ "types": "./build/esm/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./build/esm/index.d.ts",
13
+ "default": "./build/esm/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./build/cjs/index.d.cts",
17
+ "default": "./build/cjs/index.cjs"
18
+ }
19
+ }
20
+ },
9
21
  "files": [
10
- "lib/*",
11
- "CHANGELOG.md",
12
- "README.md"
22
+ "build"
13
23
  ],
14
24
  "scripts": {
15
- "build": "npm run lint && rm -rf lib && rollup -c",
16
- "lint": "npm run lint:es && npm run lint:ts",
17
- "lint:es": "eslint .",
18
- "lint:ts": "tsc --noEmit",
19
- "test": "echo \"No tests specified\" && exit 0"
20
- },
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/Decodo/sdk-ts.git"
25
+ "codegen": "tsx src/codegen/codegen.ts",
26
+ "build": "pnpm run codegen && pnpm run build:esm && pnpm run build:cjs",
27
+ "build:esm": "tsc -p tsconfig.build.json",
28
+ "build:cjs": "tsc -p tsconfig.build.cjs.json",
29
+ "typecheck": "tsc --noEmit",
30
+ "lint": "eslint .",
31
+ "lint:fix": "eslint . --fix"
24
32
  },
25
- "keywords": [],
26
- "author": "",
27
- "license": "ISC",
28
- "bugs": {
29
- "url": "https://github.com/Decodo/sdk/issues"
30
- },
31
- "homepage": "https://github.com/Decodo/sdk#readme",
32
- "dependencies": {
33
- "rollup": "^4.45.1",
34
- "typescript": "^5.8.3"
33
+ "engines": {
34
+ "node": ">=18.0.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@babel/preset-typescript": "^7.27.1",
38
- "@rollup/plugin-babel": "^6.0.4",
39
- "@rollup/plugin-json": "^6.1.0",
40
- "@rollup/plugin-node-resolve": "^16.0.1",
41
- "@rollup/plugin-typescript": "^12.1.4",
42
- "@semantic-release/changelog": "^6.0.3",
43
- "@semantic-release/git": "^10.0.1",
44
- "@semantic-release/github": "^11.0.0",
45
- "@semantic-release/npm": "^12.0.1",
46
- "@typescript-eslint/eslint-plugin": "^8.38.0",
47
- "eslint": "^8.0.0",
48
- "rollup-plugin-dts": "^6.2.1",
49
- "semantic-release": "^24.0.0",
50
- "tslib": "^2.8.1"
51
- },
52
- "publishConfig": {
53
- "access": "public"
37
+ "@eslint/js": "^9.39.1",
38
+ "@types/json-schema": "^7.0.15",
39
+ "@types/node": "^25.7.0",
40
+ "eslint": "^9.39.1",
41
+ "tsx": "^4.19.0",
42
+ "typescript": "^5.3.3",
43
+ "typescript-eslint": "^8.40.0"
54
44
  },
55
- "engines": {
56
- "node": ">=22"
45
+ "dependencies": {
46
+ "json-schema-to-typescript": "^15.0.4",
47
+ "zod": "^4"
57
48
  }
58
49
  }