@decodo/sdk-ts 2.2.0 → 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/build/cjs/index.cjs +52 -13
- package/build/cjs/index.d.cts +17 -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/http.js +1 -1
- package/build/esm/index.d.ts +2 -1
- package/package.json +1 -1
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) {
|
|
@@ -2755,12 +2755,22 @@ var BundledSchema = class _BundledSchema {
|
|
|
2755
2755
|
};
|
|
2756
2756
|
|
|
2757
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
|
+
};
|
|
2758
2766
|
var WebScrapingApi = class {
|
|
2759
2767
|
http;
|
|
2760
2768
|
schemas;
|
|
2761
|
-
|
|
2769
|
+
routes;
|
|
2770
|
+
constructor(http, schemas = BundledSchema.shared, routes = SCRAPER_API_ROUTES) {
|
|
2762
2771
|
this.http = http;
|
|
2763
2772
|
this.schemas = schemas;
|
|
2773
|
+
this.routes = routes;
|
|
2764
2774
|
}
|
|
2765
2775
|
validate(params) {
|
|
2766
2776
|
const schema = this.schemas.getRequestSchema(params.target);
|
|
@@ -2774,21 +2784,21 @@ var WebScrapingApi = class {
|
|
|
2774
2784
|
}
|
|
2775
2785
|
async scrape(params) {
|
|
2776
2786
|
this.validate(params);
|
|
2777
|
-
return this.http.post(
|
|
2787
|
+
return this.http.post(this.routes.scrape, params);
|
|
2778
2788
|
}
|
|
2779
2789
|
async scrapeAsync(params) {
|
|
2780
2790
|
this.validate(params);
|
|
2781
|
-
return this.http.post(
|
|
2791
|
+
return this.http.post(this.routes.task, params);
|
|
2782
2792
|
}
|
|
2783
2793
|
async scrapeBatch(params) {
|
|
2784
|
-
return this.http.post(
|
|
2794
|
+
return this.http.post(`${this.routes.task}/batch`, params);
|
|
2785
2795
|
}
|
|
2786
2796
|
async getStatus(taskId) {
|
|
2787
|
-
return this.http.get(
|
|
2797
|
+
return this.http.get(`${this.routes.task}/${taskId}`);
|
|
2788
2798
|
}
|
|
2789
2799
|
async getResults(taskId) {
|
|
2790
2800
|
const res = await this.http.get(
|
|
2791
|
-
|
|
2801
|
+
`${this.routes.task}/${taskId}/results`
|
|
2792
2802
|
);
|
|
2793
2803
|
return res ?? null;
|
|
2794
2804
|
}
|
|
@@ -2796,27 +2806,56 @@ var WebScrapingApi = class {
|
|
|
2796
2806
|
|
|
2797
2807
|
// src/client.ts
|
|
2798
2808
|
var WEB_API_BASE_URL = "https://scraper-api.decodo.com";
|
|
2809
|
+
var DATA_API_BASE_URL = "https://data.decodo.com";
|
|
2799
2810
|
var DEFAULT_TIMEOUT_MS = 18e4;
|
|
2800
2811
|
var notConfigured = (namespace, hint) => {
|
|
2801
2812
|
throw new Error(`${namespace} is not configured. ${hint}`);
|
|
2802
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
|
+
};
|
|
2803
2843
|
var DecodoClient = class {
|
|
2804
2844
|
webScrapingApi;
|
|
2805
2845
|
constructor(config) {
|
|
2806
2846
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
2807
2847
|
const schema = config.schema ?? BundledSchema.shared;
|
|
2808
2848
|
if (config.webScrapingApi) {
|
|
2849
|
+
const { baseUrl, auth, routes } = resolveTransport(config.webScrapingApi);
|
|
2809
2850
|
this.webScrapingApi = new WebScrapingApi(
|
|
2810
2851
|
new HttpClient({
|
|
2811
|
-
baseUrl
|
|
2812
|
-
auth
|
|
2813
|
-
type: "basic",
|
|
2814
|
-
token: config.webScrapingApi.token
|
|
2815
|
-
},
|
|
2852
|
+
baseUrl,
|
|
2853
|
+
auth,
|
|
2816
2854
|
timeoutMs,
|
|
2817
2855
|
integrationHeader: config.webScrapingApi.integrationHeader
|
|
2818
2856
|
}),
|
|
2819
|
-
schema
|
|
2857
|
+
schema,
|
|
2858
|
+
routes
|
|
2820
2859
|
);
|
|
2821
2860
|
} else {
|
|
2822
2861
|
this.webScrapingApi = new Proxy({}, {
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -834,10 +834,15 @@ export type TaskMetadata = {
|
|
|
834
834
|
export type TaskResultsResponse = {
|
|
835
835
|
results: ResultEntry[];
|
|
836
836
|
};
|
|
837
|
+
export type WebScrapingApiRoutes = {
|
|
838
|
+
scrape: string;
|
|
839
|
+
task: string;
|
|
840
|
+
};
|
|
837
841
|
export declare class WebScrapingApi {
|
|
838
842
|
private readonly http;
|
|
839
843
|
private readonly schemas;
|
|
840
|
-
|
|
844
|
+
private readonly routes;
|
|
845
|
+
constructor(http: HttpClient, schemas?: DecodoSchema, routes?: WebScrapingApiRoutes);
|
|
841
846
|
private validate;
|
|
842
847
|
scrape(params: ScrapeRequest): Promise<SyncResponse>;
|
|
843
848
|
scrapeAsync(params: ScrapeRequest): Promise<AsyncTaskResponse>;
|
|
@@ -845,11 +850,18 @@ export declare class WebScrapingApi {
|
|
|
845
850
|
getStatus(taskId: string): Promise<TaskMetadata>;
|
|
846
851
|
getResults(taskId: string): Promise<TaskResultsResponse | null>;
|
|
847
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
|
+
};
|
|
848
863
|
export type DecodoConfig = {
|
|
849
|
-
webScrapingApi?:
|
|
850
|
-
token: string;
|
|
851
|
-
integrationHeader?: string;
|
|
852
|
-
};
|
|
864
|
+
webScrapingApi?: WebScrapingApiConfig;
|
|
853
865
|
timeoutMs?: number;
|
|
854
866
|
schema?: DecodoSchema;
|
|
855
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({}, {
|
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';
|