@xyz17711/web-scraper 0.0.0-stage → 0.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.
package/README.md CHANGED
@@ -1,3 +1,90 @@
1
- # Temporary Holding Version
1
+ # @xyz17711/web-scraper
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![Publish](https://github.com/17711-services/clients/actions/workflows/publish-node.yml/badge.svg)](https://github.com/17711-services/clients/actions/workflows/publish-node.yml)
4
+ [![npm](https://img.shields.io/npm/v/@xyz17711/web-scraper)](https://www.npmjs.com/package/@xyz17711/web-scraper)
5
+ [![License](https://img.shields.io/npm/l/@xyz17711/web-scraper)](https://github.com/17711-services/clients/blob/main/LICENSE)
6
+
7
+ Typed TypeScript client for **web-scraper**, part of the
8
+ [17711.xyz](https://api.17711.xyz) microservice fleet -- pay-per-call APIs settled in USDC via
9
+ [x402](https://x402.org), listed on [x402scan](https://www.x402scan.com/server/f1c7b972-3405-4b75-8b4f-d1bfbd6305ff).
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @xyz17711/web-scraper
15
+ ```
16
+
17
+ ## Methods
18
+
19
+ | Method | Description |
20
+ | --- | --- |
21
+ | `extractMarkdown` | URL to Markdown: read any web page and get its main article content as clean Markdown for agents ($0.003, x402) |
22
+ | `getTaskStatus` | Polls for the result of a task enqueued by a *_async tool |
23
+ | `scrapeUrl` | Scrape URL: fetch any web page through a proxy and get its status, content type and raw HTML ($0.002, x402) |
24
+ | `scrapeUrlAsync` | [Deprecated - use web_scraper_scrape_url] Enqueues a web_scraper_scrape_url job and returns a task id immediately ($0.002, x402) |
25
+
26
+ ## Quickstart
27
+
28
+ ```typescript
29
+ import { Client } from "@xyz17711/web-scraper";
30
+
31
+ const client = new Client("https://api.17711.xyz/registry/web-scraper");
32
+ // see the Methods table above for every available call and its request/response type
33
+ ```
34
+
35
+ ## Paying past the free quota
36
+
37
+ Every gated tool allows a small number of free calls per day; beyond that it returns a 402
38
+ challenge. Without a wallet configured, this client throws `PaymentRequiredError` with the price,
39
+ network, and payee address attached:
40
+
41
+ ```typescript
42
+ import { Client, PaymentRequiredError } from "@xyz17711/web-scraper";
43
+
44
+ const client = new Client("https://api.17711.xyz/registry/web-scraper");
45
+ try {
46
+ await client.extractMarkdown(/* ... */);
47
+ } catch (e) {
48
+ if (e instanceof PaymentRequiredError) {
49
+ console.log(`needs ${e.priceUsdc} USDC on ${e.network}, payable to ${e.payTo}`);
50
+ }
51
+ }
52
+ ```
53
+
54
+ To pay automatically, configure a wallet on the client -- the private key should come from your
55
+ own environment/secrets manager, never a literal string in source code:
56
+
57
+ ```typescript
58
+ import { Client } from "@xyz17711/web-scraper";
59
+
60
+ const client = new Client("https://api.17711.xyz/registry/web-scraper", {
61
+ x402PrivateKey: process.env.X402_PRIVATE_KEY,
62
+ x402ExpectedNetwork: "eip155:8453", // Base mainnet; use eip155:84532 for Base Sepolia testnet
63
+ x402MaxPaymentUsdc: 0.01, // refuse any single call above this
64
+ x402MaxTotalSpendUsdc: 1.0, // refuse once this WALLET's lifetime spend would exceed it
65
+ });
66
+ ```
67
+
68
+ **Never commit a private key.** Both spend caps are required together with the key -- a wallet
69
+ with real funds and no explicit caps refuses to construct at all (`WalletConfigError`), on
70
+ purpose. The cumulative cap is tracked per wallet address, shared by every `Client` you construct
71
+ with that same key in this process.
72
+
73
+ ## LangChain.js
74
+
75
+ ```typescript
76
+ import { Client } from "@xyz17711/web-scraper";
77
+ import { WebScraperToolkit } from "@xyz17711/web-scraper/langchain";
78
+
79
+ const client = new Client("https://api.17711.xyz/registry/web-scraper", { /* ...wallet options... */ });
80
+ const tools = new WebScraperToolkit(client).getTools();
81
+ ```
82
+
83
+ Requires the optional `@langchain/core`+`zod` peer dependencies (`npm install @langchain/core
84
+ zod`) -- importing the base package above never requires them; only `@xyz17711/web-scraper/langchain`
85
+ does.
86
+
87
+ ## License
88
+
89
+ MIT -- see [`LICENSE`](../../LICENSE), shared by every language's client library in the
90
+ `clients` repo this package lives in.
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Typed HTTP client and request/response interfaces for web-scraper.
3
+ */
4
+ import { Client as BaseClient, type ClientOptions } from "@xyz17711/core";
5
+ export interface ExtractMarkdownResponse {
6
+ content_type?: string | null;
7
+ /** The URL actually reached, after any redirects the target sent. */
8
+ final_url: string;
9
+ /** Boilerplate-stripped main article content, as Markdown -- navigation, ads, and sidebars removed, not the raw page HTML. */
10
+ markdown: string;
11
+ /** The REAL HTTP status the underlying fetch received. */
12
+ status: number;
13
+ /** Article title, if Readability found one. */
14
+ title?: string | null;
15
+ /** `true` if the underlying fetch's HTML was truncated by web-scraper's own fixed byte ceiling (see `web_scraper_scrape_url`'s own `truncated` field) -- `markdown` may then also be incomplete. */
16
+ truncated: boolean;
17
+ /** The URL as requested, verbatim. */
18
+ url: string;
19
+ }
20
+ export interface ExtractMarkdownRequest {
21
+ /** The target URL to fetch, e.g. `"https://example.com/article"`. Must be `http://` or `https://` -- same validation as `web_scraper_scrape_url`, since this tool fetches through the exact same internal scraper. */
22
+ url: string;
23
+ }
24
+ /** `"pending"` (enqueued, no result yet), `"finished"` (a worker wrote a result -- see `ok`/ `result`), or `"unknown"` (this id was never valid, or both it and its result have expired -- see [`nimpoleon_tasks::TaskState`]'s own doc comment for why this is 3 states, not 2). */
25
+ export interface TaskStatusKind {
26
+ }
27
+ export interface GetTaskStatusResponse {
28
+ ok?: boolean | null;
29
+ result?: unknown;
30
+ status: TaskStatusKind;
31
+ }
32
+ export interface GetTaskStatusRequest {
33
+ /** The `task_id` a `*_async` tool returned. */
34
+ task_id: string;
35
+ }
36
+ export interface ScrapeUrlResponse {
37
+ content_type?: string | null;
38
+ /** The URL actually reached, after any redirects the target sent. */
39
+ final_url: string;
40
+ /** Raw response body, decoded as UTF-8 (lossy -- see this tool's own description for why), truncated to this service's own fixed byte ceiling if needed. */
41
+ html: string;
42
+ /** The REAL HTTP status the target returned -- never masked, never itself a reason to retry. */
43
+ status: number;
44
+ /** `true` if `html` was cut short by this service's own fixed byte ceiling. */
45
+ truncated: boolean;
46
+ /** The URL as requested, verbatim. */
47
+ url: string;
48
+ }
49
+ export interface ScrapeUrlRequest {
50
+ /** The target URL to fetch, e.g. `"https://example.com/page"`. Must be `http://` or `https://` -- any other scheme is rejected before any fetch is attempted. */
51
+ url: string;
52
+ }
53
+ /** The fixed response shape of every `*_async` tool -- deliberately NOT generic over the underlying sync tool's own response type, since no work has actually happened yet at this point. */
54
+ export interface AsyncTaskResponse {
55
+ task_id: string;
56
+ }
57
+ export interface ScrapeUrlAsyncRequest {
58
+ /** When set, the worker that processes this task POSTs the eventual result (a `TaskResult` JSON body) here, best-effort -- polling `web_scraper_get_task_status` always works too, regardless of whether this is set. */
59
+ callback_url?: string | null;
60
+ /** The target URL to fetch, e.g. `"https://example.com/page"`. Must be `http://` or `https://` -- any other scheme is rejected before any fetch is attempted. */
61
+ url: string;
62
+ }
63
+ /** Typed client for web-scraper, e.g. `client.extractMarkdown(...)`. */
64
+ export declare class Client extends BaseClient {
65
+ /** URL to Markdown: read any web page and get its main article content as clean Markdown for agents ($0.003, x402) */
66
+ extractMarkdown(request: ExtractMarkdownRequest): Promise<ExtractMarkdownResponse>;
67
+ /** Polls for the result of a task enqueued by a *_async tool */
68
+ getTaskStatus(request: GetTaskStatusRequest): Promise<GetTaskStatusResponse>;
69
+ /** Scrape URL: fetch any web page through a proxy and get its status, content type and raw HTML ($0.002, x402) */
70
+ scrapeUrl(request: ScrapeUrlRequest): Promise<ScrapeUrlResponse>;
71
+ /** [Deprecated - use web_scraper_scrape_url] Enqueues a web_scraper_scrape_url job and returns a task id immediately ($0.002, x402) */
72
+ scrapeUrlAsync(request: ScrapeUrlAsyncRequest): Promise<AsyncTaskResponse>;
73
+ }
74
+ export { ClientOptions };
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Typed HTTP client and request/response interfaces for web-scraper.
3
+ */
4
+ import { Client as BaseClient } from "@xyz17711/core";
5
+ /** Typed client for web-scraper, e.g. `client.extractMarkdown(...)`. */
6
+ export class Client extends BaseClient {
7
+ /** URL to Markdown: read any web page and get its main article content as clean Markdown for agents ($0.003, x402) */
8
+ async extractMarkdown(request) {
9
+ return this.post("/v1/web-scraper/extract_markdown", request);
10
+ }
11
+ /** Polls for the result of a task enqueued by a *_async tool */
12
+ async getTaskStatus(request) {
13
+ return this.post("/v1/web-scraper/get_task_status", request);
14
+ }
15
+ /** Scrape URL: fetch any web page through a proxy and get its status, content type and raw HTML ($0.002, x402) */
16
+ async scrapeUrl(request) {
17
+ return this.post("/v1/web-scraper/scrape_url", request);
18
+ }
19
+ /** [Deprecated - use web_scraper_scrape_url] Enqueues a web_scraper_scrape_url job and returns a task id immediately ($0.002, x402) */
20
+ async scrapeUrlAsync(request) {
21
+ return this.post("/v1/web-scraper/scrape_url_async", request);
22
+ }
23
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * LangChain.js tools for web-scraper, grouped in one Toolkit -- one tool per operation, each just an async function (JS has no separate sync form to generate). Requires the `@langchain/core`+`zod` peer dependencies declared in this package's own package.json -- imported from `web-scraper/langchain`, never from the package root, so importing the base client never requires them installed.
3
+ */
4
+ import { z } from "zod";
5
+ import { Client } from "./index.js";
6
+ export declare class WebScraperToolkit {
7
+ private client;
8
+ constructor(client: Client);
9
+ getTools(): (import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
10
+ url: z.ZodString;
11
+ }, z.core.$strip>, {
12
+ url: string;
13
+ }, {
14
+ url: string;
15
+ }, import("./index.js").ExtractMarkdownResponse, unknown, "extractMarkdown"> | import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
16
+ task_id: z.ZodString;
17
+ }, z.core.$strip>, {
18
+ task_id: string;
19
+ }, {
20
+ task_id: string;
21
+ }, import("./index.js").GetTaskStatusResponse, unknown, "getTaskStatus"> | import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
22
+ url: z.ZodString;
23
+ }, z.core.$strip>, {
24
+ url: string;
25
+ }, {
26
+ url: string;
27
+ }, import("./index.js").ScrapeUrlResponse, unknown, "scrapeUrl"> | import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
28
+ callback_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
+ url: z.ZodString;
30
+ }, z.core.$strip>, {
31
+ url: string;
32
+ callback_url?: string | null | undefined;
33
+ }, {
34
+ url: string;
35
+ callback_url?: string | null | undefined;
36
+ }, import("./index.js").AsyncTaskResponse, unknown, "scrapeUrlAsync">)[];
37
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * LangChain.js tools for web-scraper, grouped in one Toolkit -- one tool per operation, each just an async function (JS has no separate sync form to generate). Requires the `@langchain/core`+`zod` peer dependencies declared in this package's own package.json -- imported from `web-scraper/langchain`, never from the package root, so importing the base client never requires them installed.
3
+ */
4
+ import { tool } from "@langchain/core/tools";
5
+ import { z } from "zod";
6
+ export class WebScraperToolkit {
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ getTools() {
11
+ return [
12
+ tool(async (input) => this.client.extractMarkdown(input), {
13
+ name: "extractMarkdown",
14
+ description: "URL to Markdown: read any web page and get its main article content as clean Markdown for agents ($0.003, x402)",
15
+ schema: z.object({ url: z.string() }),
16
+ }),
17
+ tool(async (input) => this.client.getTaskStatus(input), {
18
+ name: "getTaskStatus",
19
+ description: "Polls for the result of a task enqueued by a *_async tool",
20
+ schema: z.object({ task_id: z.string() }),
21
+ }),
22
+ tool(async (input) => this.client.scrapeUrl(input), {
23
+ name: "scrapeUrl",
24
+ description: "Scrape URL: fetch any web page through a proxy and get its status, content type and raw HTML ($0.002, x402)",
25
+ schema: z.object({ url: z.string() }),
26
+ }),
27
+ tool(async (input) => this.client.scrapeUrlAsync(input), {
28
+ name: "scrapeUrlAsync",
29
+ description: "[Deprecated - use web_scraper_scrape_url] Enqueues a web_scraper_scrape_url job and returns a task id immediately ($0.002, x402)",
30
+ schema: z.object({ callback_url: z.string().nullable().optional(), url: z.string() }),
31
+ }),
32
+ ];
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@xyz17711/web-scraper",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Typed TypeScript client for the 17711.xyz Web Scraper API: pay-per-call, settled in USDC via x402.",
5
+ "license": "MIT",
6
+ "author": "17711 Services",
7
+ "homepage": "https://api.17711.xyz",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/17711-services/clients.git",
11
+ "directory": "node/packages/web-scraper"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/17711-services/clients/issues"
15
+ },
16
+ "keywords": [
17
+ "x402",
18
+ "usdc",
19
+ "api-client",
20
+ "pay-per-call",
21
+ "ai-agents",
22
+ "mcp",
23
+ "langchain",
24
+ "web-scraper"
25
+ ],
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "type": "module",
34
+ "main": "dist/index.js",
35
+ "types": "dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "default": "./dist/index.js"
40
+ },
41
+ "./langchain": {
42
+ "types": "./dist/langchain.d.ts",
43
+ "default": "./dist/langchain.js"
44
+ }
45
+ },
46
+ "scripts": {
47
+ "build": "tsc -p .",
48
+ "test": "npm run build && node --test test/*.test.mjs"
49
+ },
50
+ "dependencies": {
51
+ "@xyz17711/core": "^0.1.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@langchain/core": ">=0.3",
55
+ "zod": "^3 || ^4"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@langchain/core": {
59
+ "optional": true
60
+ },
61
+ "zod": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "devDependencies": {
66
+ "typescript": "^5",
67
+ "@langchain/core": "^1.2",
68
+ "zod": "^4"
69
+ }
70
+ }