@decodo/sdk-ts 2.0.1 → 2.1.1

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 (37) hide show
  1. package/build/cjs/index.cjs +3104 -0
  2. package/build/cjs/index.d.cts +900 -0
  3. package/build/esm/api/web-scraping-api.d.ts +15 -0
  4. package/build/esm/api/web-scraping-api.js +39 -0
  5. package/build/esm/client.d.ts +13 -0
  6. package/build/esm/client.js +32 -0
  7. package/build/esm/errors.d.ts +18 -0
  8. package/build/esm/errors.js +36 -0
  9. package/build/esm/generated/parameters.d.ts +11 -0
  10. package/build/esm/generated/parameters.js +79 -0
  11. package/build/esm/generated/request-schemas.d.ts +1951 -0
  12. package/build/esm/generated/request-schemas.js +2205 -0
  13. package/build/esm/generated/targets.d.ts +675 -0
  14. package/build/esm/generated/targets.js +316 -0
  15. package/build/esm/http.d.ts +22 -0
  16. package/build/esm/http.js +91 -0
  17. package/build/esm/index.d.ts +12 -0
  18. package/build/esm/index.js +7 -0
  19. package/build/esm/schema/build-target-meta.d.ts +3 -0
  20. package/build/esm/schema/build-target-meta.js +15 -0
  21. package/build/esm/schema/bundled-schema.d.ts +10 -0
  22. package/build/esm/schema/bundled-schema.js +20 -0
  23. package/build/esm/schema/constants.d.ts +5 -0
  24. package/build/esm/schema/constants.js +5 -0
  25. package/build/esm/schema/expand-path.d.ts +1 -0
  26. package/build/esm/schema/expand-path.js +11 -0
  27. package/build/esm/schema/remote-schema.d.ts +19 -0
  28. package/build/esm/schema/remote-schema.js +112 -0
  29. package/build/esm/schema/resolve-latest-ir.d.ts +2 -0
  30. package/build/esm/schema/resolve-latest-ir.js +51 -0
  31. package/build/esm/schema/types.d.ts +44 -0
  32. package/build/esm/schema/types.js +1 -0
  33. package/build/esm/types/requests.d.ts +1 -0
  34. package/build/esm/types/requests.js +1 -0
  35. package/build/esm/types/responses.d.ts +62 -0
  36. package/build/esm/types/responses.js +1 -0
  37. package/package.json +13 -6
@@ -0,0 +1,15 @@
1
+ import { HttpClient } from '../http.js';
2
+ import type { DecodoSchema } from '../schema/types.js';
3
+ import type { ScrapeRequest, BatchRequest } from '../generated/targets.js';
4
+ import type { SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse } from '../types/responses.js';
5
+ export declare class WebScrapingApi {
6
+ private readonly http;
7
+ private readonly schemas;
8
+ constructor(http: HttpClient, schemas?: DecodoSchema);
9
+ private validate;
10
+ scrape(params: ScrapeRequest): Promise<SyncResponse>;
11
+ scrapeAsync(params: ScrapeRequest): Promise<AsyncTaskResponse>;
12
+ scrapeBatch(params: BatchRequest): Promise<BatchResponse>;
13
+ getStatus(taskId: string): Promise<TaskMetadata>;
14
+ getResults(taskId: string): Promise<TaskResultsResponse | null>;
15
+ }
@@ -0,0 +1,39 @@
1
+ import { prettifyError } from 'zod';
2
+ import { ValidationError } from '../errors.js';
3
+ import { BundledSchema } from '../schema/bundled-schema.js';
4
+ export class WebScrapingApi {
5
+ http;
6
+ schemas;
7
+ constructor(http, schemas = BundledSchema.shared) {
8
+ this.http = http;
9
+ this.schemas = schemas;
10
+ }
11
+ validate(params) {
12
+ const schema = this.schemas.getRequestSchema(params.target);
13
+ if (!schema) {
14
+ return;
15
+ }
16
+ const parsed = schema.safeParse(params);
17
+ if (!parsed.success) {
18
+ throw new ValidationError(prettifyError(parsed.error));
19
+ }
20
+ }
21
+ async scrape(params) {
22
+ this.validate(params);
23
+ return this.http.post('/v2/scrape', params);
24
+ }
25
+ async scrapeAsync(params) {
26
+ this.validate(params);
27
+ return this.http.post('/v3/task', params);
28
+ }
29
+ async scrapeBatch(params) {
30
+ return this.http.post('/v3/task/batch', params);
31
+ }
32
+ async getStatus(taskId) {
33
+ return this.http.get(`/v3/task/${taskId}`);
34
+ }
35
+ async getResults(taskId) {
36
+ const res = await this.http.get(`/v3/task/${taskId}/results`);
37
+ return res ?? null;
38
+ }
39
+ }
@@ -0,0 +1,13 @@
1
+ import { WebScrapingApi } from './api/web-scraping-api.js';
2
+ import type { DecodoSchema } from './schema/types.js';
3
+ export type DecodoConfig = {
4
+ webScrapingApi?: {
5
+ token: string;
6
+ };
7
+ timeoutMs?: number;
8
+ schema?: DecodoSchema;
9
+ };
10
+ export declare class DecodoClient {
11
+ readonly webScrapingApi: WebScrapingApi;
12
+ constructor(config: DecodoConfig);
13
+ }
@@ -0,0 +1,32 @@
1
+ import { HttpClient } from './http.js';
2
+ import { WebScrapingApi } from './api/web-scraping-api.js';
3
+ import { BundledSchema } from './schema/bundled-schema.js';
4
+ const WEB_API_BASE_URL = 'https://scraper-api.decodo.com';
5
+ const DEFAULT_TIMEOUT_MS = 180_000;
6
+ const notConfigured = (namespace, hint) => {
7
+ throw new Error(`${namespace} is not configured. ${hint}`);
8
+ };
9
+ export class DecodoClient {
10
+ webScrapingApi;
11
+ constructor(config) {
12
+ const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
13
+ const schema = config.schema ?? BundledSchema.shared;
14
+ if (config.webScrapingApi) {
15
+ this.webScrapingApi = new WebScrapingApi(new HttpClient({
16
+ baseUrl: WEB_API_BASE_URL,
17
+ auth: {
18
+ type: 'basic',
19
+ token: config.webScrapingApi.token,
20
+ },
21
+ timeoutMs,
22
+ }), schema);
23
+ }
24
+ else {
25
+ this.webScrapingApi = new Proxy({}, {
26
+ get() {
27
+ notConfigured('webScrapingApi', 'Provide webScrapingApi.token in DecodoConfig.');
28
+ },
29
+ });
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,18 @@
1
+ export declare class DecodoError extends Error {
2
+ readonly statusCode: number;
3
+ readonly apiStatus: string | undefined;
4
+ constructor(message: string, statusCode: number, apiStatus?: string);
5
+ }
6
+ export declare class AuthenticationError extends DecodoError {
7
+ constructor(message?: string);
8
+ }
9
+ export declare class RateLimitError extends DecodoError {
10
+ constructor(message?: string);
11
+ }
12
+ export declare class ValidationError extends DecodoError {
13
+ readonly errors: unknown[] | undefined;
14
+ constructor(message: string, errors?: unknown[]);
15
+ }
16
+ export declare class TimeoutError extends Error {
17
+ constructor(message?: string);
18
+ }
@@ -0,0 +1,36 @@
1
+ export class DecodoError extends Error {
2
+ statusCode;
3
+ apiStatus;
4
+ constructor(message, statusCode, apiStatus) {
5
+ super(message);
6
+ this.name = 'DecodoError';
7
+ this.statusCode = statusCode;
8
+ this.apiStatus = apiStatus;
9
+ }
10
+ }
11
+ export class AuthenticationError extends DecodoError {
12
+ constructor(message = 'Authentication failed. Check your credentials.') {
13
+ super(message, 401, 'failed');
14
+ this.name = 'AuthenticationError';
15
+ }
16
+ }
17
+ export class RateLimitError extends DecodoError {
18
+ constructor(message = 'Rate limit exceeded. Slow down your request rate.') {
19
+ super(message, 429, 'failed');
20
+ this.name = 'RateLimitError';
21
+ }
22
+ }
23
+ export class ValidationError extends DecodoError {
24
+ errors;
25
+ constructor(message, errors) {
26
+ super(message, 422, 'failed');
27
+ this.name = 'ValidationError';
28
+ this.errors = errors;
29
+ }
30
+ }
31
+ export class TimeoutError extends Error {
32
+ constructor(message = 'The request timed out.') {
33
+ super(message);
34
+ this.name = 'TimeoutError';
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ export type ParameterMeta = {
2
+ type: string;
3
+ maxLength?: number;
4
+ minimum?: number;
5
+ maximum?: number;
6
+ enum?: (string | number)[];
7
+ items?: {
8
+ type: string;
9
+ };
10
+ };
11
+ export declare const parameterMeta: Record<string, ParameterMeta>;
@@ -0,0 +1,79 @@
1
+ // Auto-generated by src/codegen/web-scraping-api/generate-parameters.ts — do not edit
2
+ export const parameterMeta = {
3
+ "360": { type: "boolean" },
4
+ callback_url: { type: "string" },
5
+ query: { type: "string", maxLength: 2048 },
6
+ headless: { type: "string", enum: ["html", "png"] },
7
+ locale: { type: "string" },
8
+ geo: { type: "string" },
9
+ device_type: { type: "string" },
10
+ page_from: { type: "number", minimum: 0, maximum: 100 },
11
+ google_results_language: { type: "string" },
12
+ google_tbm: { type: "string" },
13
+ google_tbs: { type: "string" },
14
+ parse: { type: "boolean" },
15
+ google_nfpr: { type: "boolean" },
16
+ google_safe_search: { type: "boolean" },
17
+ session_id: { type: "string" },
18
+ xhr: { type: "boolean" },
19
+ markdown: { type: "boolean" },
20
+ page_count: { type: "number", minimum: 1, maximum: 10 },
21
+ date_range: { type: "string" },
22
+ stars: { type: "number" },
23
+ adults: { type: "number", minimum: 1, maximum: 3 },
24
+ children: { type: "number", minimum: 1, maximum: 3 },
25
+ search_type: { type: "string" },
26
+ date_start: { type: "string" },
27
+ date_end: { type: "string" },
28
+ url: { type: "string", maxLength: 2056 },
29
+ hotel_occupancy: { type: "string" },
30
+ domain: { type: "string" },
31
+ language_code: { type: "string" },
32
+ transcript_origin: { type: "string" },
33
+ autoselect_variant: { type: "boolean" },
34
+ currency: { type: "string" },
35
+ category: { type: "string" },
36
+ merchant: { type: "string" },
37
+ sort_by: { type: "string" },
38
+ parser_type: { type: "string" },
39
+ product_id: { type: "string" },
40
+ fulfillment_type: { type: "string" },
41
+ walmart_store_id: { type: "string" },
42
+ delivery_zip: { type: "string" },
43
+ store_id: { type: "string" },
44
+ delivery_type: { type: "string" },
45
+ target_store_id: { type: "string" },
46
+ lowes_store_id: { type: "string" },
47
+ user_agent_type: { type: "string" },
48
+ free_delivery: { type: "boolean" },
49
+ pickup_today: { type: "boolean" },
50
+ delivery_today_tomorrow: { type: "boolean" },
51
+ payload: { type: "string" },
52
+ proxy_pool: { type: "string", enum: ["standard", "premium"] },
53
+ http_method: { type: "string" },
54
+ successful_status_codes: { type: "array", items: { type: "number" } },
55
+ headers: { type: "object" },
56
+ cookies: { type: "object" },
57
+ force_headers: { type: "boolean" },
58
+ force_cookies: { type: "boolean" },
59
+ prompt: { type: "string", maxLength: 8192 },
60
+ search: { type: "boolean" },
61
+ country: { type: "string" },
62
+ sort: { type: "string" },
63
+ upload_date: { type: "string" },
64
+ type: { type: "string" },
65
+ duration: { type: "string" },
66
+ video_sort_by: { type: "string" },
67
+ "3d": { type: "boolean" },
68
+ "4k": { type: "boolean" },
69
+ creative_commons: { type: "boolean" },
70
+ hd: { type: "boolean" },
71
+ hdr: { type: "boolean" },
72
+ vr180: { type: "boolean" },
73
+ live: { type: "boolean" },
74
+ location: { type: "boolean" },
75
+ purchased: { type: "boolean" },
76
+ subtitles: { type: "boolean" },
77
+ subtitle_origin: { type: "string" },
78
+ limit: { type: "number", minimum: 0, maximum: 100 },
79
+ };