@decodo/sdk-ts 2.1.0 → 2.1.2

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 (57) hide show
  1. package/build/cjs/index.cjs +3107 -0
  2. package/build/cjs/index.d.cts +903 -0
  3. package/build/esm/client.d.ts +1 -0
  4. package/build/esm/client.js +1 -0
  5. package/build/esm/http.d.ts +2 -0
  6. package/build/esm/http.js +3 -1
  7. package/package.json +9 -5
  8. package/build/cjs/api/web-scraping-api.d.ts +0 -15
  9. package/build/cjs/api/web-scraping-api.js +0 -43
  10. package/build/cjs/client.d.ts +0 -13
  11. package/build/cjs/client.js +0 -36
  12. package/build/cjs/errors.d.ts +0 -18
  13. package/build/cjs/errors.js +0 -44
  14. package/build/cjs/generated/parameters.d.ts +0 -11
  15. package/build/cjs/generated/parameters.js +0 -82
  16. package/build/cjs/generated/request-schemas.d.ts +0 -1951
  17. package/build/cjs/generated/request-schemas.js +0 -2241
  18. package/build/cjs/generated/targets.d.ts +0 -675
  19. package/build/cjs/generated/targets.js +0 -319
  20. package/build/cjs/http.d.ts +0 -22
  21. package/build/cjs/http.js +0 -95
  22. package/build/cjs/index.d.ts +0 -12
  23. package/build/cjs/index.js +0 -23
  24. package/build/cjs/schema/build-request-schemas.d.ts +0 -4
  25. package/build/cjs/schema/build-request-schemas.js +0 -56
  26. package/build/cjs/schema/build-target-meta.d.ts +0 -3
  27. package/build/cjs/schema/build-target-meta.js +0 -19
  28. package/build/cjs/schema/bundled-provider.d.ts +0 -2
  29. package/build/cjs/schema/bundled-provider.js +0 -9
  30. package/build/cjs/schema/bundled-schema.d.ts +0 -10
  31. package/build/cjs/schema/bundled-schema.js +0 -24
  32. package/build/cjs/schema/constants.d.ts +0 -5
  33. package/build/cjs/schema/constants.js +0 -8
  34. package/build/cjs/schema/expand-path.d.ts +0 -1
  35. package/build/cjs/schema/expand-path.js +0 -15
  36. package/build/cjs/schema/remote-provider.d.ts +0 -8
  37. package/build/cjs/schema/remote-provider.js +0 -120
  38. package/build/cjs/schema/remote-schema.d.ts +0 -19
  39. package/build/cjs/schema/remote-schema.js +0 -149
  40. package/build/cjs/schema/resolve-latest-ir.d.ts +0 -2
  41. package/build/cjs/schema/resolve-latest-ir.js +0 -55
  42. package/build/cjs/schema/resolve-provider.d.ts +0 -3
  43. package/build/cjs/schema/resolve-provider.js +0 -27
  44. package/build/cjs/schema/types.d.ts +0 -44
  45. package/build/cjs/schema/types.js +0 -2
  46. package/build/cjs/types/requests.d.ts +0 -1
  47. package/build/cjs/types/requests.js +0 -2
  48. package/build/cjs/types/responses.d.ts +0 -62
  49. package/build/cjs/types/responses.js +0 -2
  50. package/build/esm/schema/build-request-schemas.d.ts +0 -4
  51. package/build/esm/schema/build-request-schemas.js +0 -18
  52. package/build/esm/schema/bundled-provider.d.ts +0 -2
  53. package/build/esm/schema/bundled-provider.js +0 -6
  54. package/build/esm/schema/remote-provider.d.ts +0 -8
  55. package/build/esm/schema/remote-provider.js +0 -83
  56. package/build/esm/schema/resolve-provider.d.ts +0 -3
  57. package/build/esm/schema/resolve-provider.js +0 -22
@@ -3,6 +3,7 @@ import type { DecodoSchema } from './schema/types.js';
3
3
  export type DecodoConfig = {
4
4
  webScrapingApi?: {
5
5
  token: string;
6
+ integrationHeader?: string;
6
7
  };
7
8
  timeoutMs?: number;
8
9
  schema?: DecodoSchema;
@@ -19,6 +19,7 @@ export class DecodoClient {
19
19
  token: config.webScrapingApi.token,
20
20
  },
21
21
  timeoutMs,
22
+ integrationHeader: config.webScrapingApi.integrationHeader,
22
23
  }), schema);
23
24
  }
24
25
  else {
@@ -10,11 +10,13 @@ export type HttpClientConfig = {
10
10
  baseUrl: string;
11
11
  auth: BasicAuth | ApiKeyAuth;
12
12
  timeoutMs: number;
13
+ integrationHeader?: string;
13
14
  };
14
15
  export declare class HttpClient {
15
16
  private readonly baseUrl;
16
17
  private readonly authHeader;
17
18
  private readonly timeoutMs;
19
+ private readonly integrationHeader;
18
20
  constructor(config: HttpClientConfig);
19
21
  request<T>(method: string, path: string, body?: unknown): Promise<T>;
20
22
  post<T>(path: string, body: unknown): Promise<T>;
package/build/esm/http.js CHANGED
@@ -3,9 +3,11 @@ export class HttpClient {
3
3
  baseUrl;
4
4
  authHeader;
5
5
  timeoutMs;
6
+ integrationHeader;
6
7
  constructor(config) {
7
8
  this.baseUrl = config.baseUrl.replace(/\/+$/, '');
8
9
  this.timeoutMs = config.timeoutMs;
10
+ this.integrationHeader = config.integrationHeader ?? 'sdk-ts';
9
11
  if (config.auth.type === 'basic') {
10
12
  this.authHeader = `Basic ${config.auth.token}`;
11
13
  }
@@ -24,7 +26,7 @@ export class HttpClient {
24
26
  Authorization: this.authHeader,
25
27
  'Content-Type': 'application/json',
26
28
  Accept: 'application/json',
27
- 'x-integration': 'sdk-ts',
29
+ 'x-integration': this.integrationHeader,
28
30
  },
29
31
  signal: controller.signal,
30
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decodo/sdk-ts",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Official TypeScript SDK for the Decodo APIs",
5
5
  "type": "module",
6
6
  "main": "./build/cjs/index.cjs",
@@ -25,12 +25,13 @@
25
25
  "codegen": "tsx src/codegen/codegen.ts",
26
26
  "build": "pnpm run codegen && pnpm run build:esm && pnpm run build:cjs",
27
27
  "build:esm": "tsc -p tsconfig.build.json",
28
- "build:cjs": "tsc -p tsconfig.build.cjs.json",
28
+ "build:cjs": "rm -rf build/cjs && mkdir -p build/cjs && esbuild src/index.ts --bundle --platform=node --format=cjs --external:zod --outfile=build/cjs/index.cjs && dts-bundle-generator -o build/cjs/index.d.cts --project tsconfig.build.json build/esm/index.d.ts",
29
29
  "typecheck": "tsc --noEmit",
30
30
  "lint": "eslint .",
31
31
  "lint:fix": "eslint . --fix",
32
32
  "test": "vitest run",
33
- "test:watch": "vitest"
33
+ "test:watch": "vitest",
34
+ "prepack": "pnpm run build:esm && pnpm run build:cjs"
34
35
  },
35
36
  "engines": {
36
37
  "node": ">=18.0.0"
@@ -39,14 +40,17 @@
39
40
  "@eslint/js": "^9.39.1",
40
41
  "@types/json-schema": "^7.0.15",
41
42
  "@types/node": "^25.7.0",
43
+ "dts-bundle-generator": "^9.5.1",
44
+ "esbuild": "^0.28.0",
42
45
  "eslint": "^9.39.1",
46
+ "json-schema-to-typescript": "^15.0.4",
43
47
  "tsx": "^4.19.0",
44
48
  "typescript": "^5.3.3",
45
49
  "typescript-eslint": "^8.40.0",
46
50
  "vitest": "^4.1.7"
47
51
  },
48
52
  "dependencies": {
49
- "json-schema-to-typescript": "^15.0.4",
50
53
  "zod": "^4"
51
- }
54
+ },
55
+ "license": "MIT"
52
56
  }
@@ -1,15 +0,0 @@
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
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebScrapingApi = void 0;
4
- const zod_1 = require("zod");
5
- const errors_js_1 = require("../errors.js");
6
- const bundled_schema_js_1 = require("../schema/bundled-schema.js");
7
- class WebScrapingApi {
8
- http;
9
- schemas;
10
- constructor(http, schemas = bundled_schema_js_1.BundledSchema.shared) {
11
- this.http = http;
12
- this.schemas = schemas;
13
- }
14
- validate(params) {
15
- const schema = this.schemas.getRequestSchema(params.target);
16
- if (!schema) {
17
- return;
18
- }
19
- const parsed = schema.safeParse(params);
20
- if (!parsed.success) {
21
- throw new errors_js_1.ValidationError((0, zod_1.prettifyError)(parsed.error));
22
- }
23
- }
24
- async scrape(params) {
25
- this.validate(params);
26
- return this.http.post('/v2/scrape', params);
27
- }
28
- async scrapeAsync(params) {
29
- this.validate(params);
30
- return this.http.post('/v3/task', params);
31
- }
32
- async scrapeBatch(params) {
33
- return this.http.post('/v3/task/batch', params);
34
- }
35
- async getStatus(taskId) {
36
- return this.http.get(`/v3/task/${taskId}`);
37
- }
38
- async getResults(taskId) {
39
- const res = await this.http.get(`/v3/task/${taskId}/results`);
40
- return res ?? null;
41
- }
42
- }
43
- exports.WebScrapingApi = WebScrapingApi;
@@ -1,13 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DecodoClient = void 0;
4
- const http_js_1 = require("./http.js");
5
- const web_scraping_api_js_1 = require("./api/web-scraping-api.js");
6
- const bundled_schema_js_1 = require("./schema/bundled-schema.js");
7
- const WEB_API_BASE_URL = 'https://scraper-api.decodo.com';
8
- const DEFAULT_TIMEOUT_MS = 180_000;
9
- const notConfigured = (namespace, hint) => {
10
- throw new Error(`${namespace} is not configured. ${hint}`);
11
- };
12
- class DecodoClient {
13
- webScrapingApi;
14
- constructor(config) {
15
- const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
16
- const schema = config.schema ?? bundled_schema_js_1.BundledSchema.shared;
17
- if (config.webScrapingApi) {
18
- this.webScrapingApi = new web_scraping_api_js_1.WebScrapingApi(new http_js_1.HttpClient({
19
- baseUrl: WEB_API_BASE_URL,
20
- auth: {
21
- type: 'basic',
22
- token: config.webScrapingApi.token,
23
- },
24
- timeoutMs,
25
- }), schema);
26
- }
27
- else {
28
- this.webScrapingApi = new Proxy({}, {
29
- get() {
30
- notConfigured('webScrapingApi', 'Provide webScrapingApi.token in DecodoConfig.');
31
- },
32
- });
33
- }
34
- }
35
- }
36
- exports.DecodoClient = DecodoClient;
@@ -1,18 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeoutError = exports.ValidationError = exports.RateLimitError = exports.AuthenticationError = exports.DecodoError = void 0;
4
- class DecodoError extends Error {
5
- statusCode;
6
- apiStatus;
7
- constructor(message, statusCode, apiStatus) {
8
- super(message);
9
- this.name = 'DecodoError';
10
- this.statusCode = statusCode;
11
- this.apiStatus = apiStatus;
12
- }
13
- }
14
- exports.DecodoError = DecodoError;
15
- class AuthenticationError extends DecodoError {
16
- constructor(message = 'Authentication failed. Check your credentials.') {
17
- super(message, 401, 'failed');
18
- this.name = 'AuthenticationError';
19
- }
20
- }
21
- exports.AuthenticationError = AuthenticationError;
22
- class RateLimitError extends DecodoError {
23
- constructor(message = 'Rate limit exceeded. Slow down your request rate.') {
24
- super(message, 429, 'failed');
25
- this.name = 'RateLimitError';
26
- }
27
- }
28
- exports.RateLimitError = RateLimitError;
29
- class ValidationError extends DecodoError {
30
- errors;
31
- constructor(message, errors) {
32
- super(message, 422, 'failed');
33
- this.name = 'ValidationError';
34
- this.errors = errors;
35
- }
36
- }
37
- exports.ValidationError = ValidationError;
38
- class TimeoutError extends Error {
39
- constructor(message = 'The request timed out.') {
40
- super(message);
41
- this.name = 'TimeoutError';
42
- }
43
- }
44
- exports.TimeoutError = TimeoutError;
@@ -1,11 +0,0 @@
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>;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- // Auto-generated by src/codegen/web-scraping-api/generate-parameters.ts — do not edit
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parameterMeta = void 0;
5
- exports.parameterMeta = {
6
- "360": { type: "boolean" },
7
- callback_url: { type: "string" },
8
- query: { type: "string", maxLength: 2048 },
9
- headless: { type: "string", enum: ["html", "png"] },
10
- locale: { type: "string" },
11
- geo: { type: "string" },
12
- device_type: { type: "string" },
13
- page_from: { type: "number", minimum: 0, maximum: 100 },
14
- google_results_language: { type: "string" },
15
- google_tbm: { type: "string" },
16
- google_tbs: { type: "string" },
17
- parse: { type: "boolean" },
18
- google_nfpr: { type: "boolean" },
19
- google_safe_search: { type: "boolean" },
20
- session_id: { type: "string" },
21
- xhr: { type: "boolean" },
22
- markdown: { type: "boolean" },
23
- page_count: { type: "number", minimum: 1, maximum: 10 },
24
- date_range: { type: "string" },
25
- stars: { type: "number" },
26
- adults: { type: "number", minimum: 1, maximum: 3 },
27
- children: { type: "number", minimum: 1, maximum: 3 },
28
- search_type: { type: "string" },
29
- date_start: { type: "string" },
30
- date_end: { type: "string" },
31
- url: { type: "string", maxLength: 2056 },
32
- hotel_occupancy: { type: "string" },
33
- domain: { type: "string" },
34
- language_code: { type: "string" },
35
- transcript_origin: { type: "string" },
36
- autoselect_variant: { type: "boolean" },
37
- currency: { type: "string" },
38
- category: { type: "string" },
39
- merchant: { type: "string" },
40
- sort_by: { type: "string" },
41
- parser_type: { type: "string" },
42
- product_id: { type: "string" },
43
- fulfillment_type: { type: "string" },
44
- walmart_store_id: { type: "string" },
45
- delivery_zip: { type: "string" },
46
- store_id: { type: "string" },
47
- delivery_type: { type: "string" },
48
- target_store_id: { type: "string" },
49
- lowes_store_id: { type: "string" },
50
- user_agent_type: { type: "string" },
51
- free_delivery: { type: "boolean" },
52
- pickup_today: { type: "boolean" },
53
- delivery_today_tomorrow: { type: "boolean" },
54
- payload: { type: "string" },
55
- proxy_pool: { type: "string", enum: ["standard", "premium"] },
56
- http_method: { type: "string" },
57
- successful_status_codes: { type: "array", items: { type: "number" } },
58
- headers: { type: "object" },
59
- cookies: { type: "object" },
60
- force_headers: { type: "boolean" },
61
- force_cookies: { type: "boolean" },
62
- prompt: { type: "string", maxLength: 8192 },
63
- search: { type: "boolean" },
64
- country: { type: "string" },
65
- sort: { type: "string" },
66
- upload_date: { type: "string" },
67
- type: { type: "string" },
68
- duration: { type: "string" },
69
- video_sort_by: { type: "string" },
70
- "3d": { type: "boolean" },
71
- "4k": { type: "boolean" },
72
- creative_commons: { type: "boolean" },
73
- hd: { type: "boolean" },
74
- hdr: { type: "boolean" },
75
- vr180: { type: "boolean" },
76
- live: { type: "boolean" },
77
- location: { type: "boolean" },
78
- purchased: { type: "boolean" },
79
- subtitles: { type: "boolean" },
80
- subtitle_origin: { type: "string" },
81
- limit: { type: "number", minimum: 0, maximum: 100 },
82
- };