@decodo/sdk-ts 2.1.2 → 2.3.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 +1 -0
- package/build/cjs/index.cjs +88 -14
- package/build/cjs/index.d.cts +27 -5
- package/build/esm/api/web-scraping-api.d.ts +8 -1
- package/build/esm/api/web-scraping-api.js +16 -6
- package/build/esm/client.d.ts +12 -4
- package/build/esm/client.js +33 -7
- package/build/esm/generated/request-schemas.d.ts +26 -0
- package/build/esm/generated/request-schemas.js +29 -0
- package/build/esm/generated/targets.d.ts +10 -1
- package/build/esm/generated/targets.js +7 -1
- package/build/esm/http.js +1 -1
- package/build/esm/index.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -466,6 +466,7 @@ Each target accepts one primary input parameter (`url`, `query`, `product_id`, o
|
|
|
466
466
|
| --- | --- | --- |
|
|
467
467
|
| `Target.Chatgpt` | ChatGPT response for a prompt | `{ target: Target.Chatgpt, prompt: "What are the top three dog breeds?" }` |
|
|
468
468
|
| `Target.Perplexity` | Perplexity response for a prompt | `{ target: Target.Perplexity, prompt: "What causes seasonal allergies?" }` |
|
|
469
|
+
| `Target.Gemini` | Gemini response for a prompt | `{ target: Target.Gemini, prompt: "What are the top three dog breeds?" }` |
|
|
469
470
|
| `Target.GoogleAiMode` | Google AI Mode response | `{ target: Target.GoogleAiMode, query: "What are the top three dog breeds?" }` |
|
|
470
471
|
|
|
471
472
|
### Universal scraping
|
package/build/cjs/index.cjs
CHANGED
|
@@ -97,7 +97,7 @@ var HttpClient = class {
|
|
|
97
97
|
if (config.auth.type === "basic") {
|
|
98
98
|
this.authHeader = `Basic ${config.auth.token}`;
|
|
99
99
|
} else {
|
|
100
|
-
this.authHeader = config.auth.apiKey
|
|
100
|
+
this.authHeader = `Bearer ${config.auth.apiKey}`;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
async request(method, path, body) {
|
|
@@ -215,6 +215,7 @@ var Target = /* @__PURE__ */ ((_Target) => {
|
|
|
215
215
|
_Target["Universal"] = "universal";
|
|
216
216
|
_Target["Chatgpt"] = "chatgpt";
|
|
217
217
|
_Target["Perplexity"] = "perplexity";
|
|
218
|
+
_Target["Gemini"] = "gemini";
|
|
218
219
|
_Target["Bbb"] = "bbb";
|
|
219
220
|
_Target["Autotrader"] = "autotrader";
|
|
220
221
|
_Target["Mobile"] = "mobile";
|
|
@@ -236,7 +237,7 @@ var Target = /* @__PURE__ */ ((_Target) => {
|
|
|
236
237
|
_Target["YoutubeChannel"] = "youtube_channel";
|
|
237
238
|
return _Target;
|
|
238
239
|
})(Target || {});
|
|
239
|
-
var targets = ["universal_ecommerce" /* UniversalEcommerce */, "google_search" /* GoogleSearch */, "google_travel_hotels" /* GoogleTravelHotels */, "google_trends_explore" /* GoogleTrendsExplore */, "google_shopping_search" /* GoogleShoppingSearch */, "google_shopping_product" /* GoogleShoppingProduct */, "google" /* Google */, "google_suggest" /* GoogleSuggest */, "google_maps" /* GoogleMaps */, "google_ai_mode" /* GoogleAiMode */, "google_ads" /* GoogleAds */, "google_lens" /* GoogleLens */, "bing_search" /* BingSearch */, "bing" /* Bing */, "youtube_transcript" /* YoutubeTranscript */, "amazon_product" /* AmazonProduct */, "amazon_pricing" /* AmazonPricing */, "amazon_search" /* AmazonSearch */, "amazon_sellers" /* AmazonSellers */, "amazon_bestsellers" /* AmazonBestsellers */, "amazon" /* Amazon */, "ecommerce" /* Ecommerce */, "walmart_product" /* WalmartProduct */, "walmart_search" /* WalmartSearch */, "walmart" /* Walmart */, "target_product" /* TargetProduct */, "target_search" /* TargetSearch */, "target" /* Target */, "lowes_search" /* LowesSearch */, "universal" /* Universal */, "chatgpt" /* Chatgpt */, "perplexity" /* Perplexity */, "bbb" /* Bbb */, "autotrader" /* Autotrader */, "mobile" /* Mobile */, "airbnb" /* Airbnb */, "apple_app_store" /* AppleAppStore */, "instagram_graphql_profile" /* InstagramGraphqlProfile */, "tiktok_post" /* TiktokPost */, "tiktok_shop_search" /* TiktokShopSearch */, "tiktok_shop_product" /* TiktokShopProduct */, "tiktok" /* Tiktok */, "reddit_post" /* RedditPost */, "reddit_subreddit" /* RedditSubreddit */, "reddit_user" /* RedditUser */, "youtube_video" /* YoutubeVideo */, "youtube_metadata" /* YoutubeMetadata */, "youtube_search" /* YoutubeSearch */, "youtube_search_max" /* YoutubeSearchMax */, "youtube_subtitles" /* YoutubeSubtitles */, "youtube_channel" /* YoutubeChannel */];
|
|
240
|
+
var targets = ["universal_ecommerce" /* UniversalEcommerce */, "google_search" /* GoogleSearch */, "google_travel_hotels" /* GoogleTravelHotels */, "google_trends_explore" /* GoogleTrendsExplore */, "google_shopping_search" /* GoogleShoppingSearch */, "google_shopping_product" /* GoogleShoppingProduct */, "google" /* Google */, "google_suggest" /* GoogleSuggest */, "google_maps" /* GoogleMaps */, "google_ai_mode" /* GoogleAiMode */, "google_ads" /* GoogleAds */, "google_lens" /* GoogleLens */, "bing_search" /* BingSearch */, "bing" /* Bing */, "youtube_transcript" /* YoutubeTranscript */, "amazon_product" /* AmazonProduct */, "amazon_pricing" /* AmazonPricing */, "amazon_search" /* AmazonSearch */, "amazon_sellers" /* AmazonSellers */, "amazon_bestsellers" /* AmazonBestsellers */, "amazon" /* Amazon */, "ecommerce" /* Ecommerce */, "walmart_product" /* WalmartProduct */, "walmart_search" /* WalmartSearch */, "walmart" /* Walmart */, "target_product" /* TargetProduct */, "target_search" /* TargetSearch */, "target" /* Target */, "lowes_search" /* LowesSearch */, "universal" /* Universal */, "chatgpt" /* Chatgpt */, "perplexity" /* Perplexity */, "gemini" /* Gemini */, "bbb" /* Bbb */, "autotrader" /* Autotrader */, "mobile" /* Mobile */, "airbnb" /* Airbnb */, "apple_app_store" /* AppleAppStore */, "instagram_graphql_profile" /* InstagramGraphqlProfile */, "tiktok_post" /* TiktokPost */, "tiktok_shop_search" /* TiktokShopSearch */, "tiktok_shop_product" /* TiktokShopProduct */, "tiktok" /* Tiktok */, "reddit_post" /* RedditPost */, "reddit_subreddit" /* RedditSubreddit */, "reddit_user" /* RedditUser */, "youtube_video" /* YoutubeVideo */, "youtube_metadata" /* YoutubeMetadata */, "youtube_search" /* YoutubeSearch */, "youtube_search_max" /* YoutubeSearchMax */, "youtube_subtitles" /* YoutubeSubtitles */, "youtube_channel" /* YoutubeChannel */];
|
|
240
241
|
var targetMeta = {
|
|
241
242
|
["universal_ecommerce" /* UniversalEcommerce */]: {
|
|
242
243
|
group: "None",
|
|
@@ -398,6 +399,11 @@ var targetMeta = {
|
|
|
398
399
|
response_format: "json",
|
|
399
400
|
parameters: ["prompt", "parse", "geo", "device_type", "markdown", "xhr", "callback_url"]
|
|
400
401
|
},
|
|
402
|
+
["gemini" /* Gemini */]: {
|
|
403
|
+
group: "AI Tools",
|
|
404
|
+
response_format: "json",
|
|
405
|
+
parameters: ["prompt", "parse", "geo", "xhr", "callback_url"]
|
|
406
|
+
},
|
|
401
407
|
["bbb" /* Bbb */]: {
|
|
402
408
|
group: "Business Reviews",
|
|
403
409
|
response_format: "html",
|
|
@@ -2007,6 +2013,34 @@ var requestJsonSchemas = {
|
|
|
2007
2013
|
],
|
|
2008
2014
|
"additionalProperties": false
|
|
2009
2015
|
},
|
|
2016
|
+
["gemini" /* Gemini */]: {
|
|
2017
|
+
"type": "object",
|
|
2018
|
+
"properties": {
|
|
2019
|
+
"target": {
|
|
2020
|
+
"const": "gemini"
|
|
2021
|
+
},
|
|
2022
|
+
"prompt": {
|
|
2023
|
+
"type": "string",
|
|
2024
|
+
"maxLength": 8192
|
|
2025
|
+
},
|
|
2026
|
+
"parse": {
|
|
2027
|
+
"type": "boolean"
|
|
2028
|
+
},
|
|
2029
|
+
"geo": {
|
|
2030
|
+
"type": "string"
|
|
2031
|
+
},
|
|
2032
|
+
"xhr": {
|
|
2033
|
+
"type": "boolean"
|
|
2034
|
+
},
|
|
2035
|
+
"callback_url": {
|
|
2036
|
+
"type": "string"
|
|
2037
|
+
}
|
|
2038
|
+
},
|
|
2039
|
+
"required": [
|
|
2040
|
+
"target"
|
|
2041
|
+
],
|
|
2042
|
+
"additionalProperties": false
|
|
2043
|
+
},
|
|
2010
2044
|
["bbb" /* Bbb */]: {
|
|
2011
2045
|
"type": "object",
|
|
2012
2046
|
"properties": {
|
|
@@ -2678,6 +2712,7 @@ var requestSchemas = {
|
|
|
2678
2712
|
["universal" /* Universal */]: z.fromJSONSchema(requestJsonSchemas["universal" /* Universal */]),
|
|
2679
2713
|
["chatgpt" /* Chatgpt */]: z.fromJSONSchema(requestJsonSchemas["chatgpt" /* Chatgpt */]),
|
|
2680
2714
|
["perplexity" /* Perplexity */]: z.fromJSONSchema(requestJsonSchemas["perplexity" /* Perplexity */]),
|
|
2715
|
+
["gemini" /* Gemini */]: z.fromJSONSchema(requestJsonSchemas["gemini" /* Gemini */]),
|
|
2681
2716
|
["bbb" /* Bbb */]: z.fromJSONSchema(requestJsonSchemas["bbb" /* Bbb */]),
|
|
2682
2717
|
["autotrader" /* Autotrader */]: z.fromJSONSchema(requestJsonSchemas["autotrader" /* Autotrader */]),
|
|
2683
2718
|
["mobile" /* Mobile */]: z.fromJSONSchema(requestJsonSchemas["mobile" /* Mobile */]),
|
|
@@ -2720,12 +2755,22 @@ var BundledSchema = class _BundledSchema {
|
|
|
2720
2755
|
};
|
|
2721
2756
|
|
|
2722
2757
|
// src/api/web-scraping-api.ts
|
|
2758
|
+
var SCRAPER_API_ROUTES = {
|
|
2759
|
+
scrape: "/v2/scrape",
|
|
2760
|
+
task: "/v3/task"
|
|
2761
|
+
};
|
|
2762
|
+
var DATA_API_ROUTES = {
|
|
2763
|
+
scrape: "/v1/scrape",
|
|
2764
|
+
task: "/v1/task"
|
|
2765
|
+
};
|
|
2723
2766
|
var WebScrapingApi = class {
|
|
2724
2767
|
http;
|
|
2725
2768
|
schemas;
|
|
2726
|
-
|
|
2769
|
+
routes;
|
|
2770
|
+
constructor(http, schemas = BundledSchema.shared, routes = SCRAPER_API_ROUTES) {
|
|
2727
2771
|
this.http = http;
|
|
2728
2772
|
this.schemas = schemas;
|
|
2773
|
+
this.routes = routes;
|
|
2729
2774
|
}
|
|
2730
2775
|
validate(params) {
|
|
2731
2776
|
const schema = this.schemas.getRequestSchema(params.target);
|
|
@@ -2739,21 +2784,21 @@ var WebScrapingApi = class {
|
|
|
2739
2784
|
}
|
|
2740
2785
|
async scrape(params) {
|
|
2741
2786
|
this.validate(params);
|
|
2742
|
-
return this.http.post(
|
|
2787
|
+
return this.http.post(this.routes.scrape, params);
|
|
2743
2788
|
}
|
|
2744
2789
|
async scrapeAsync(params) {
|
|
2745
2790
|
this.validate(params);
|
|
2746
|
-
return this.http.post(
|
|
2791
|
+
return this.http.post(this.routes.task, params);
|
|
2747
2792
|
}
|
|
2748
2793
|
async scrapeBatch(params) {
|
|
2749
|
-
return this.http.post(
|
|
2794
|
+
return this.http.post(`${this.routes.task}/batch`, params);
|
|
2750
2795
|
}
|
|
2751
2796
|
async getStatus(taskId) {
|
|
2752
|
-
return this.http.get(
|
|
2797
|
+
return this.http.get(`${this.routes.task}/${taskId}`);
|
|
2753
2798
|
}
|
|
2754
2799
|
async getResults(taskId) {
|
|
2755
2800
|
const res = await this.http.get(
|
|
2756
|
-
|
|
2801
|
+
`${this.routes.task}/${taskId}/results`
|
|
2757
2802
|
);
|
|
2758
2803
|
return res ?? null;
|
|
2759
2804
|
}
|
|
@@ -2761,27 +2806,56 @@ var WebScrapingApi = class {
|
|
|
2761
2806
|
|
|
2762
2807
|
// src/client.ts
|
|
2763
2808
|
var WEB_API_BASE_URL = "https://scraper-api.decodo.com";
|
|
2809
|
+
var DATA_API_BASE_URL = "https://data.decodo.com";
|
|
2764
2810
|
var DEFAULT_TIMEOUT_MS = 18e4;
|
|
2765
2811
|
var notConfigured = (namespace, hint) => {
|
|
2766
2812
|
throw new Error(`${namespace} is not configured. ${hint}`);
|
|
2767
2813
|
};
|
|
2814
|
+
var resolveTransport = (config) => {
|
|
2815
|
+
const { token, apiKey } = config;
|
|
2816
|
+
if (token !== void 0 && apiKey !== void 0) {
|
|
2817
|
+
throw new Error(
|
|
2818
|
+
"webScrapingApi accepts either token or apiKey, not both. Provide only one."
|
|
2819
|
+
);
|
|
2820
|
+
}
|
|
2821
|
+
if (apiKey !== void 0) {
|
|
2822
|
+
if (!apiKey.trim()) {
|
|
2823
|
+
throw new Error("webScrapingApi apiKey must be a non-empty string.");
|
|
2824
|
+
}
|
|
2825
|
+
return {
|
|
2826
|
+
baseUrl: DATA_API_BASE_URL,
|
|
2827
|
+
auth: { type: "apiKey", apiKey },
|
|
2828
|
+
routes: DATA_API_ROUTES
|
|
2829
|
+
};
|
|
2830
|
+
}
|
|
2831
|
+
if (token !== void 0) {
|
|
2832
|
+
if (!token.trim()) {
|
|
2833
|
+
throw new Error("webScrapingApi token must be a non-empty string.");
|
|
2834
|
+
}
|
|
2835
|
+
return {
|
|
2836
|
+
baseUrl: WEB_API_BASE_URL,
|
|
2837
|
+
auth: { type: "basic", token },
|
|
2838
|
+
routes: SCRAPER_API_ROUTES
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
throw new Error("webScrapingApi requires token in DecodoConfig.");
|
|
2842
|
+
};
|
|
2768
2843
|
var DecodoClient = class {
|
|
2769
2844
|
webScrapingApi;
|
|
2770
2845
|
constructor(config) {
|
|
2771
2846
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
2772
2847
|
const schema = config.schema ?? BundledSchema.shared;
|
|
2773
2848
|
if (config.webScrapingApi) {
|
|
2849
|
+
const { baseUrl, auth, routes } = resolveTransport(config.webScrapingApi);
|
|
2774
2850
|
this.webScrapingApi = new WebScrapingApi(
|
|
2775
2851
|
new HttpClient({
|
|
2776
|
-
baseUrl
|
|
2777
|
-
auth
|
|
2778
|
-
type: "basic",
|
|
2779
|
-
token: config.webScrapingApi.token
|
|
2780
|
-
},
|
|
2852
|
+
baseUrl,
|
|
2853
|
+
auth,
|
|
2781
2854
|
timeoutMs,
|
|
2782
2855
|
integrationHeader: config.webScrapingApi.integrationHeader
|
|
2783
2856
|
}),
|
|
2784
|
-
schema
|
|
2857
|
+
schema,
|
|
2858
|
+
routes
|
|
2785
2859
|
);
|
|
2786
2860
|
} else {
|
|
2787
2861
|
this.webScrapingApi = new Proxy({}, {
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -63,6 +63,7 @@ export declare enum Target {
|
|
|
63
63
|
Universal = "universal",
|
|
64
64
|
Chatgpt = "chatgpt",
|
|
65
65
|
Perplexity = "perplexity",
|
|
66
|
+
Gemini = "gemini",
|
|
66
67
|
Bbb = "bbb",
|
|
67
68
|
Autotrader = "autotrader",
|
|
68
69
|
Mobile = "mobile",
|
|
@@ -118,6 +119,7 @@ export declare const targets: readonly [
|
|
|
118
119
|
Target.Universal,
|
|
119
120
|
Target.Chatgpt,
|
|
120
121
|
Target.Perplexity,
|
|
122
|
+
Target.Gemini,
|
|
121
123
|
Target.Bbb,
|
|
122
124
|
Target.Autotrader,
|
|
123
125
|
Target.Mobile,
|
|
@@ -526,6 +528,13 @@ export interface PerplexityParams {
|
|
|
526
528
|
xhr?: boolean;
|
|
527
529
|
callback_url?: string;
|
|
528
530
|
}
|
|
531
|
+
export interface GeminiParams {
|
|
532
|
+
prompt?: string;
|
|
533
|
+
parse?: boolean;
|
|
534
|
+
geo?: string;
|
|
535
|
+
xhr?: boolean;
|
|
536
|
+
callback_url?: string;
|
|
537
|
+
}
|
|
529
538
|
export interface BbbParams {
|
|
530
539
|
url?: string;
|
|
531
540
|
headless?: "html" | "png";
|
|
@@ -716,6 +725,7 @@ export type TargetParamsMap = {
|
|
|
716
725
|
[Target.Universal]: UniversalParams;
|
|
717
726
|
[Target.Chatgpt]: ChatgptParams;
|
|
718
727
|
[Target.Perplexity]: PerplexityParams;
|
|
728
|
+
[Target.Gemini]: GeminiParams;
|
|
719
729
|
[Target.Bbb]: BbbParams;
|
|
720
730
|
[Target.Autotrader]: AutotraderParams;
|
|
721
731
|
[Target.Mobile]: MobileParams;
|
|
@@ -824,10 +834,15 @@ export type TaskMetadata = {
|
|
|
824
834
|
export type TaskResultsResponse = {
|
|
825
835
|
results: ResultEntry[];
|
|
826
836
|
};
|
|
837
|
+
export type WebScrapingApiRoutes = {
|
|
838
|
+
scrape: string;
|
|
839
|
+
task: string;
|
|
840
|
+
};
|
|
827
841
|
export declare class WebScrapingApi {
|
|
828
842
|
private readonly http;
|
|
829
843
|
private readonly schemas;
|
|
830
|
-
|
|
844
|
+
private readonly routes;
|
|
845
|
+
constructor(http: HttpClient, schemas?: DecodoSchema, routes?: WebScrapingApiRoutes);
|
|
831
846
|
private validate;
|
|
832
847
|
scrape(params: ScrapeRequest): Promise<SyncResponse>;
|
|
833
848
|
scrapeAsync(params: ScrapeRequest): Promise<AsyncTaskResponse>;
|
|
@@ -835,11 +850,18 @@ export declare class WebScrapingApi {
|
|
|
835
850
|
getStatus(taskId: string): Promise<TaskMetadata>;
|
|
836
851
|
getResults(taskId: string): Promise<TaskResultsResponse | null>;
|
|
837
852
|
}
|
|
853
|
+
export type WebScrapingApiCredentials = {
|
|
854
|
+
token: string;
|
|
855
|
+
apiKey?: never;
|
|
856
|
+
} | {
|
|
857
|
+
apiKey: string;
|
|
858
|
+
token?: never;
|
|
859
|
+
};
|
|
860
|
+
export type WebScrapingApiConfig = WebScrapingApiCredentials & {
|
|
861
|
+
integrationHeader?: string;
|
|
862
|
+
};
|
|
838
863
|
export type DecodoConfig = {
|
|
839
|
-
webScrapingApi?:
|
|
840
|
-
token: string;
|
|
841
|
-
integrationHeader?: string;
|
|
842
|
-
};
|
|
864
|
+
webScrapingApi?: WebScrapingApiConfig;
|
|
843
865
|
timeoutMs?: number;
|
|
844
866
|
schema?: DecodoSchema;
|
|
845
867
|
};
|
|
@@ -2,10 +2,17 @@ import { HttpClient } from '../http.js';
|
|
|
2
2
|
import type { DecodoSchema } from '../schema/types.js';
|
|
3
3
|
import type { ScrapeRequest, BatchRequest } from '../generated/targets.js';
|
|
4
4
|
import type { SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse } from '../types/responses.js';
|
|
5
|
+
export type WebScrapingApiRoutes = {
|
|
6
|
+
scrape: string;
|
|
7
|
+
task: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const SCRAPER_API_ROUTES: WebScrapingApiRoutes;
|
|
10
|
+
export declare const DATA_API_ROUTES: WebScrapingApiRoutes;
|
|
5
11
|
export declare class WebScrapingApi {
|
|
6
12
|
private readonly http;
|
|
7
13
|
private readonly schemas;
|
|
8
|
-
|
|
14
|
+
private readonly routes;
|
|
15
|
+
constructor(http: HttpClient, schemas?: DecodoSchema, routes?: WebScrapingApiRoutes);
|
|
9
16
|
private validate;
|
|
10
17
|
scrape(params: ScrapeRequest): Promise<SyncResponse>;
|
|
11
18
|
scrapeAsync(params: ScrapeRequest): Promise<AsyncTaskResponse>;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { prettifyError } from 'zod';
|
|
2
2
|
import { ValidationError } from '../errors.js';
|
|
3
3
|
import { BundledSchema } from '../schema/bundled-schema.js';
|
|
4
|
+
export const SCRAPER_API_ROUTES = {
|
|
5
|
+
scrape: '/v2/scrape',
|
|
6
|
+
task: '/v3/task',
|
|
7
|
+
};
|
|
8
|
+
export const DATA_API_ROUTES = {
|
|
9
|
+
scrape: '/v1/scrape',
|
|
10
|
+
task: '/v1/task',
|
|
11
|
+
};
|
|
4
12
|
export class WebScrapingApi {
|
|
5
13
|
http;
|
|
6
14
|
schemas;
|
|
7
|
-
|
|
15
|
+
routes;
|
|
16
|
+
constructor(http, schemas = BundledSchema.shared, routes = SCRAPER_API_ROUTES) {
|
|
8
17
|
this.http = http;
|
|
9
18
|
this.schemas = schemas;
|
|
19
|
+
this.routes = routes;
|
|
10
20
|
}
|
|
11
21
|
validate(params) {
|
|
12
22
|
const schema = this.schemas.getRequestSchema(params.target);
|
|
@@ -20,20 +30,20 @@ export class WebScrapingApi {
|
|
|
20
30
|
}
|
|
21
31
|
async scrape(params) {
|
|
22
32
|
this.validate(params);
|
|
23
|
-
return this.http.post(
|
|
33
|
+
return this.http.post(this.routes.scrape, params);
|
|
24
34
|
}
|
|
25
35
|
async scrapeAsync(params) {
|
|
26
36
|
this.validate(params);
|
|
27
|
-
return this.http.post(
|
|
37
|
+
return this.http.post(this.routes.task, params);
|
|
28
38
|
}
|
|
29
39
|
async scrapeBatch(params) {
|
|
30
|
-
return this.http.post(
|
|
40
|
+
return this.http.post(`${this.routes.task}/batch`, params);
|
|
31
41
|
}
|
|
32
42
|
async getStatus(taskId) {
|
|
33
|
-
return this.http.get(
|
|
43
|
+
return this.http.get(`${this.routes.task}/${taskId}`);
|
|
34
44
|
}
|
|
35
45
|
async getResults(taskId) {
|
|
36
|
-
const res = await this.http.get(
|
|
46
|
+
const res = await this.http.get(`${this.routes.task}/${taskId}/results`);
|
|
37
47
|
return res ?? null;
|
|
38
48
|
}
|
|
39
49
|
}
|
package/build/esm/client.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { WebScrapingApi } from './api/web-scraping-api.js';
|
|
2
2
|
import type { DecodoSchema } from './schema/types.js';
|
|
3
|
+
type WebScrapingApiCredentials = {
|
|
4
|
+
token: string;
|
|
5
|
+
apiKey?: never;
|
|
6
|
+
} | {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
token?: never;
|
|
9
|
+
};
|
|
10
|
+
export type WebScrapingApiConfig = WebScrapingApiCredentials & {
|
|
11
|
+
integrationHeader?: string;
|
|
12
|
+
};
|
|
3
13
|
export type DecodoConfig = {
|
|
4
|
-
webScrapingApi?:
|
|
5
|
-
token: string;
|
|
6
|
-
integrationHeader?: string;
|
|
7
|
-
};
|
|
14
|
+
webScrapingApi?: WebScrapingApiConfig;
|
|
8
15
|
timeoutMs?: number;
|
|
9
16
|
schema?: DecodoSchema;
|
|
10
17
|
};
|
|
@@ -12,3 +19,4 @@ export declare class DecodoClient {
|
|
|
12
19
|
readonly webScrapingApi: WebScrapingApi;
|
|
13
20
|
constructor(config: DecodoConfig);
|
|
14
21
|
}
|
|
22
|
+
export {};
|
package/build/esm/client.js
CHANGED
|
@@ -1,26 +1,52 @@
|
|
|
1
1
|
import { HttpClient } from './http.js';
|
|
2
|
-
import { WebScrapingApi } from './api/web-scraping-api.js';
|
|
2
|
+
import { WebScrapingApi, SCRAPER_API_ROUTES, DATA_API_ROUTES, } from './api/web-scraping-api.js';
|
|
3
3
|
import { BundledSchema } from './schema/bundled-schema.js';
|
|
4
4
|
const WEB_API_BASE_URL = 'https://scraper-api.decodo.com';
|
|
5
|
+
const DATA_API_BASE_URL = 'https://data.decodo.com';
|
|
5
6
|
const DEFAULT_TIMEOUT_MS = 180_000;
|
|
6
7
|
const notConfigured = (namespace, hint) => {
|
|
7
8
|
throw new Error(`${namespace} is not configured. ${hint}`);
|
|
8
9
|
};
|
|
10
|
+
const resolveTransport = (config) => {
|
|
11
|
+
const { token, apiKey } = config;
|
|
12
|
+
if (token !== undefined && apiKey !== undefined) {
|
|
13
|
+
throw new Error('webScrapingApi accepts either token or apiKey, not both. Provide only one.');
|
|
14
|
+
}
|
|
15
|
+
if (apiKey !== undefined) {
|
|
16
|
+
if (!apiKey.trim()) {
|
|
17
|
+
throw new Error('webScrapingApi apiKey must be a non-empty string.');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
baseUrl: DATA_API_BASE_URL,
|
|
21
|
+
auth: { type: 'apiKey', apiKey },
|
|
22
|
+
routes: DATA_API_ROUTES,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (token !== undefined) {
|
|
26
|
+
if (!token.trim()) {
|
|
27
|
+
throw new Error('webScrapingApi token must be a non-empty string.');
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
baseUrl: WEB_API_BASE_URL,
|
|
31
|
+
auth: { type: 'basic', token },
|
|
32
|
+
routes: SCRAPER_API_ROUTES,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
throw new Error('webScrapingApi requires token in DecodoConfig.');
|
|
36
|
+
};
|
|
9
37
|
export class DecodoClient {
|
|
10
38
|
webScrapingApi;
|
|
11
39
|
constructor(config) {
|
|
12
40
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
13
41
|
const schema = config.schema ?? BundledSchema.shared;
|
|
14
42
|
if (config.webScrapingApi) {
|
|
43
|
+
const { baseUrl, auth, routes } = resolveTransport(config.webScrapingApi);
|
|
15
44
|
this.webScrapingApi = new WebScrapingApi(new HttpClient({
|
|
16
|
-
baseUrl
|
|
17
|
-
auth
|
|
18
|
-
type: 'basic',
|
|
19
|
-
token: config.webScrapingApi.token,
|
|
20
|
-
},
|
|
45
|
+
baseUrl,
|
|
46
|
+
auth,
|
|
21
47
|
timeoutMs,
|
|
22
48
|
integrationHeader: config.webScrapingApi.integrationHeader,
|
|
23
|
-
}), schema);
|
|
49
|
+
}), schema, routes);
|
|
24
50
|
}
|
|
25
51
|
else {
|
|
26
52
|
this.webScrapingApi = new Proxy({}, {
|
|
@@ -1372,6 +1372,32 @@ export declare const requestJsonSchemas: {
|
|
|
1372
1372
|
readonly required: readonly ["target"];
|
|
1373
1373
|
readonly additionalProperties: false;
|
|
1374
1374
|
};
|
|
1375
|
+
readonly gemini: {
|
|
1376
|
+
readonly type: "object";
|
|
1377
|
+
readonly properties: {
|
|
1378
|
+
readonly target: {
|
|
1379
|
+
readonly const: "gemini";
|
|
1380
|
+
};
|
|
1381
|
+
readonly prompt: {
|
|
1382
|
+
readonly type: "string";
|
|
1383
|
+
readonly maxLength: 8192;
|
|
1384
|
+
};
|
|
1385
|
+
readonly parse: {
|
|
1386
|
+
readonly type: "boolean";
|
|
1387
|
+
};
|
|
1388
|
+
readonly geo: {
|
|
1389
|
+
readonly type: "string";
|
|
1390
|
+
};
|
|
1391
|
+
readonly xhr: {
|
|
1392
|
+
readonly type: "boolean";
|
|
1393
|
+
};
|
|
1394
|
+
readonly callback_url: {
|
|
1395
|
+
readonly type: "string";
|
|
1396
|
+
};
|
|
1397
|
+
};
|
|
1398
|
+
readonly required: readonly ["target"];
|
|
1399
|
+
readonly additionalProperties: false;
|
|
1400
|
+
};
|
|
1375
1401
|
readonly bbb: {
|
|
1376
1402
|
readonly type: "object";
|
|
1377
1403
|
readonly properties: {
|
|
@@ -1512,6 +1512,34 @@ export const requestJsonSchemas = {
|
|
|
1512
1512
|
],
|
|
1513
1513
|
"additionalProperties": false
|
|
1514
1514
|
},
|
|
1515
|
+
[Target.Gemini]: {
|
|
1516
|
+
"type": "object",
|
|
1517
|
+
"properties": {
|
|
1518
|
+
"target": {
|
|
1519
|
+
"const": "gemini"
|
|
1520
|
+
},
|
|
1521
|
+
"prompt": {
|
|
1522
|
+
"type": "string",
|
|
1523
|
+
"maxLength": 8192
|
|
1524
|
+
},
|
|
1525
|
+
"parse": {
|
|
1526
|
+
"type": "boolean"
|
|
1527
|
+
},
|
|
1528
|
+
"geo": {
|
|
1529
|
+
"type": "string"
|
|
1530
|
+
},
|
|
1531
|
+
"xhr": {
|
|
1532
|
+
"type": "boolean"
|
|
1533
|
+
},
|
|
1534
|
+
"callback_url": {
|
|
1535
|
+
"type": "string"
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
"required": [
|
|
1539
|
+
"target"
|
|
1540
|
+
],
|
|
1541
|
+
"additionalProperties": false
|
|
1542
|
+
},
|
|
1515
1543
|
[Target.Bbb]: {
|
|
1516
1544
|
"type": "object",
|
|
1517
1545
|
"properties": {
|
|
@@ -2183,6 +2211,7 @@ export const requestSchemas = {
|
|
|
2183
2211
|
[Target.Universal]: z.fromJSONSchema(requestJsonSchemas[Target.Universal]),
|
|
2184
2212
|
[Target.Chatgpt]: z.fromJSONSchema(requestJsonSchemas[Target.Chatgpt]),
|
|
2185
2213
|
[Target.Perplexity]: z.fromJSONSchema(requestJsonSchemas[Target.Perplexity]),
|
|
2214
|
+
[Target.Gemini]: z.fromJSONSchema(requestJsonSchemas[Target.Gemini]),
|
|
2186
2215
|
[Target.Bbb]: z.fromJSONSchema(requestJsonSchemas[Target.Bbb]),
|
|
2187
2216
|
[Target.Autotrader]: z.fromJSONSchema(requestJsonSchemas[Target.Autotrader]),
|
|
2188
2217
|
[Target.Mobile]: z.fromJSONSchema(requestJsonSchemas[Target.Mobile]),
|
|
@@ -34,6 +34,7 @@ export declare enum Target {
|
|
|
34
34
|
Universal = "universal",
|
|
35
35
|
Chatgpt = "chatgpt",
|
|
36
36
|
Perplexity = "perplexity",
|
|
37
|
+
Gemini = "gemini",
|
|
37
38
|
Bbb = "bbb",
|
|
38
39
|
Autotrader = "autotrader",
|
|
39
40
|
Mobile = "mobile",
|
|
@@ -56,7 +57,7 @@ export declare enum Target {
|
|
|
56
57
|
}
|
|
57
58
|
/** API discriminator string literals (same values as {@link Target}). */
|
|
58
59
|
export type TargetString = (typeof Target)[keyof typeof Target];
|
|
59
|
-
export declare const targets: readonly [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.WalmartProduct, Target.WalmartSearch, Target.Walmart, Target.TargetProduct, Target.TargetSearch, Target.Target, Target.LowesSearch, Target.Universal, 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];
|
|
60
|
+
export declare const targets: readonly [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.WalmartProduct, Target.WalmartSearch, Target.Walmart, Target.TargetProduct, Target.TargetSearch, Target.Target, Target.LowesSearch, Target.Universal, Target.Chatgpt, Target.Perplexity, Target.Gemini, 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];
|
|
60
61
|
export interface UniversalEcommerceParams {
|
|
61
62
|
callback_url?: string;
|
|
62
63
|
}
|
|
@@ -445,6 +446,13 @@ export interface PerplexityParams {
|
|
|
445
446
|
xhr?: boolean;
|
|
446
447
|
callback_url?: string;
|
|
447
448
|
}
|
|
449
|
+
export interface GeminiParams {
|
|
450
|
+
prompt?: string;
|
|
451
|
+
parse?: boolean;
|
|
452
|
+
geo?: string;
|
|
453
|
+
xhr?: boolean;
|
|
454
|
+
callback_url?: string;
|
|
455
|
+
}
|
|
448
456
|
export interface BbbParams {
|
|
449
457
|
url?: string;
|
|
450
458
|
headless?: 'html' | 'png';
|
|
@@ -635,6 +643,7 @@ export type TargetParamsMap = {
|
|
|
635
643
|
[Target.Universal]: UniversalParams;
|
|
636
644
|
[Target.Chatgpt]: ChatgptParams;
|
|
637
645
|
[Target.Perplexity]: PerplexityParams;
|
|
646
|
+
[Target.Gemini]: GeminiParams;
|
|
638
647
|
[Target.Bbb]: BbbParams;
|
|
639
648
|
[Target.Autotrader]: AutotraderParams;
|
|
640
649
|
[Target.Mobile]: MobileParams;
|
|
@@ -36,6 +36,7 @@ export var Target;
|
|
|
36
36
|
Target["Universal"] = "universal";
|
|
37
37
|
Target["Chatgpt"] = "chatgpt";
|
|
38
38
|
Target["Perplexity"] = "perplexity";
|
|
39
|
+
Target["Gemini"] = "gemini";
|
|
39
40
|
Target["Bbb"] = "bbb";
|
|
40
41
|
Target["Autotrader"] = "autotrader";
|
|
41
42
|
Target["Mobile"] = "mobile";
|
|
@@ -56,7 +57,7 @@ export var Target;
|
|
|
56
57
|
Target["YoutubeSubtitles"] = "youtube_subtitles";
|
|
57
58
|
Target["YoutubeChannel"] = "youtube_channel";
|
|
58
59
|
})(Target || (Target = {}));
|
|
59
|
-
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.WalmartProduct, Target.WalmartSearch, Target.Walmart, Target.TargetProduct, Target.TargetSearch, Target.Target, Target.LowesSearch, Target.Universal, 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];
|
|
60
|
+
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.WalmartProduct, Target.WalmartSearch, Target.Walmart, Target.TargetProduct, Target.TargetSearch, Target.Target, Target.LowesSearch, Target.Universal, Target.Chatgpt, Target.Perplexity, Target.Gemini, 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];
|
|
60
61
|
export const targetMeta = {
|
|
61
62
|
[Target.UniversalEcommerce]: {
|
|
62
63
|
group: "None",
|
|
@@ -218,6 +219,11 @@ export const targetMeta = {
|
|
|
218
219
|
response_format: "json",
|
|
219
220
|
parameters: ["prompt", "parse", "geo", "device_type", "markdown", "xhr", "callback_url"],
|
|
220
221
|
},
|
|
222
|
+
[Target.Gemini]: {
|
|
223
|
+
group: "AI Tools",
|
|
224
|
+
response_format: "json",
|
|
225
|
+
parameters: ["prompt", "parse", "geo", "xhr", "callback_url"],
|
|
226
|
+
},
|
|
221
227
|
[Target.Bbb]: {
|
|
222
228
|
group: "Business Reviews",
|
|
223
229
|
response_format: "html",
|
package/build/esm/http.js
CHANGED
package/build/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DecodoClient } from './client.js';
|
|
2
|
-
export type { DecodoConfig } from './client.js';
|
|
2
|
+
export type { DecodoConfig, WebScrapingApiConfig } from './client.js';
|
|
3
3
|
export { WebScrapingApi } from './api/web-scraping-api.js';
|
|
4
|
+
export type { WebScrapingApiRoutes } from './api/web-scraping-api.js';
|
|
4
5
|
export { BundledSchema } from './schema/bundled-schema.js';
|
|
5
6
|
export { RemoteSchema } from './schema/remote-schema.js';
|
|
6
7
|
export type { DecodoSchema, RemoteSchemaLoadOptions } from './schema/types.js';
|