@decodo/sdk-ts 4.0.0 → 4.1.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 +56 -4
- package/build/cjs/index.cjs +5557 -191
- package/build/cjs/index.d.cts +174 -2
- package/build/esm/api/flows.d.ts +52 -0
- package/build/esm/api/flows.js +301 -0
- package/build/esm/api/limits.d.ts +6 -0
- package/build/esm/api/limits.js +36 -0
- package/build/esm/api/results.d.ts +2 -0
- package/build/esm/api/results.js +87 -0
- package/build/esm/api/tools.d.ts +6 -0
- package/build/esm/api/tools.js +185 -0
- package/build/esm/api/web-scraping-api.d.ts +2 -0
- package/build/esm/api/web-scraping-api.js +3 -0
- package/build/esm/errors.d.ts +10 -0
- package/build/esm/errors.js +20 -0
- package/build/esm/generated/flows.d.ts +3 -0
- package/build/esm/generated/flows.js +4633 -0
- package/build/esm/index.d.ts +8 -2
- package/build/esm/index.js +5 -1
- package/build/esm/schema/bundled-schema.d.ts +7 -2
- package/build/esm/schema/bundled-schema.js +14 -0
- package/build/esm/schema/remote-schema.d.ts +7 -2
- package/build/esm/schema/remote-schema.js +75 -14
- package/build/esm/schema/types.d.ts +95 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<a href="https://dashboard.decodo.com/integrations?utm_source=github&utm_medium=social&utm_campaign=mcp_server"> <img src="https://github.com/user-attachments/assets/a1e52a9e-3da1-4081-b3c6-053aafb8f196"/></a>
|
|
10
10
|
|
|
11
|
-
The official TypeScript SDK for the Decodo Web
|
|
11
|
+
The official TypeScript SDK for the Decodo Web Data API.
|
|
12
12
|
|
|
13
|
-
Build strongly typed scraping workflows for search engines, eCommerce platforms, social media, AI tools, and more using the Decodo Web
|
|
13
|
+
Build strongly typed scraping workflows for search engines, eCommerce platforms, social media, AI tools, and more using the Decodo Web Data API.
|
|
14
14
|
|
|
15
15
|
- Fully typed targets and parameters with IDE autocomplete
|
|
16
16
|
- Sync, async, and batch scraping methods
|
|
@@ -20,7 +20,7 @@ Build strongly typed scraping workflows for search engines, eCommerce platforms,
|
|
|
20
20
|
|
|
21
21
|
# What is Decodo TypeScript SDK?
|
|
22
22
|
|
|
23
|
-
Decodo TypeScript SDK is the official TypeScript SDK for the Decodo Web
|
|
23
|
+
Decodo TypeScript SDK is the official TypeScript SDK for the Decodo Web Data API. It provides a typed interface for interacting with Decodo targets like Google, Amazon, TikTok, YouTube, ChatGPT, Perplexity, and more.
|
|
24
24
|
|
|
25
25
|
Instead of manually constructing HTTP requests and validating payloads, you can work with fully typed methods and target-specific parameters directly in your editor.
|
|
26
26
|
|
|
@@ -381,7 +381,7 @@ const client = new DecodoClient({
|
|
|
381
381
|
| `token` | Web Scraping API basic authentication token, for older plans. Use it instead of `apiKey` |
|
|
382
382
|
| `timeoutMs` | Request timeout in milliseconds (default: 180000) |
|
|
383
383
|
|
|
384
|
-
## Web
|
|
384
|
+
## Web Data API
|
|
385
385
|
|
|
386
386
|
Access the API via `client.webScrapingApi`.
|
|
387
387
|
|
|
@@ -496,6 +496,58 @@ if (firstPage.next) {
|
|
|
496
496
|
await client.webScrapingApi.cancelCrawl(job.crawl_id);
|
|
497
497
|
```
|
|
498
498
|
|
|
499
|
+
### Flows
|
|
500
|
+
|
|
501
|
+
`client.webScrapingApi.flows` runs any product by the pattern the Decodo IR gives it, so an endpoint added to the IR works without a new SDK method. There are three patterns: `call` (one request), `job` (start, wait, read, cancel) and `batch` (one request that starts many jobs). Flows need `apiKey` and IR 2.6.0 or newer; load the latest IR with `RemoteSchema` and pass it to the client:
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
import { DecodoClient, RemoteSchema } from '@decodo/sdk-ts';
|
|
505
|
+
|
|
506
|
+
const schema = await RemoteSchema.load({ ttlMs: 3_600_000 });
|
|
507
|
+
const client = new DecodoClient({ webScrapingApi: { apiKey: '<api_key>' }, schema });
|
|
508
|
+
const { flows } = client.webScrapingApi;
|
|
509
|
+
|
|
510
|
+
const links = await flows.call('map', { url: 'https://example.com' });
|
|
511
|
+
|
|
512
|
+
const job = await flows.start('crawl', { url: 'https://example.com', limit: 10 });
|
|
513
|
+
const crawlId = job[flows.describe('crawl', 'job').idField] as string;
|
|
514
|
+
const status = await flows.wait('crawl', crawlId, { timeout: 120_000 });
|
|
515
|
+
if (!flows.hasFailed('crawl', status)) {
|
|
516
|
+
const pages = await flows.results('crawl', crawlId);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
await flows.checkKey(); // rejects with AuthenticationError when the key is refused
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
`wait` throws a `JobTimeoutError` when the job is still running after `timeout`.
|
|
523
|
+
|
|
524
|
+
`results` reads every page of a job. To read a few at a time, use `resultsPage`, which returns up to `maxItems` results (one API page when left out) and a `nextCursor` to pass back for the rest:
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
const { items, nextCursor } = await flows.resultsPage('crawl', crawlId, { maxItems: 10 });
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Surfaces
|
|
531
|
+
|
|
532
|
+
The IR also describes each integration's tools as a surface, keyed by the integration's `x-integration` value: tool names, descriptions, which API fields each tool shows, fixed values, defaults, caps and how to read the result. Build tools from it instead of hard-coding them:
|
|
533
|
+
|
|
534
|
+
```typescript
|
|
535
|
+
import { buildToolInputSchema, runTool } from '@decodo/sdk-ts';
|
|
536
|
+
|
|
537
|
+
for (const tool of schema.getSurface('mcp')?.tools ?? []) {
|
|
538
|
+
const inputSchema = buildToolInputSchema(schema, tool); // JSON schema of the tool's input
|
|
539
|
+
register(tool.name, tool.description, inputSchema, (args) => runTool(client.webScrapingApi.flows, tool, args));
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
`runTool` sends the tool's request (shown fields, defaults, then fixed values), applies the tool's result rule and throws a `ResultError` (with `code` and `retryable`) for a failure the rule declares. `readResult` and `buildToolRequest` are exported for clients that send requests themselves.
|
|
544
|
+
|
|
545
|
+
A `results` tool of a paged job takes an optional `cursor` and returns `{ items, nextCursor?, status? }`: `nextCursor` reads on, and `status` appears when the job was cancelled or faulted but kept the pages it finished. A failed job with no pages throws a `ResultError`.
|
|
546
|
+
|
|
547
|
+
`runTool` returns the result in full. To cap what a model sees by the tool's `limits` (`maxTextChars` per string, `maxListValues` per list, `maxItems` for the result's items and `maxResultChars` for the whole text), pass the result, or your own transformation of it, through `limitResult(tool.limits, value)`, which returns `{ text, truncated }`.
|
|
548
|
+
|
|
549
|
+
`RemoteSchema.load({ url })` also takes a `file:` URL, read from disk on every load, for testing an IR that isn't published yet.
|
|
550
|
+
|
|
499
551
|
## Supported targets
|
|
500
552
|
|
|
501
553
|
Each target accepts one primary input parameter (`url`, `query`, `product_id`, or `prompt`) together with optional configuration. The examples below show the minimum payload to call `client.webScrapingApi.scrape(...)`.
|