@render-lab/tasks-scrape 0.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.
Files changed (50) hide show
  1. package/README.md +60 -0
  2. package/dist/client.d.ts +31 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +20 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/crawl.d.ts +12 -0
  7. package/dist/crawl.d.ts.map +1 -0
  8. package/dist/crawl.js +48 -0
  9. package/dist/crawl.js.map +1 -0
  10. package/dist/extract.d.ts +6 -0
  11. package/dist/extract.d.ts.map +1 -0
  12. package/dist/extract.js +9 -0
  13. package/dist/extract.js.map +1 -0
  14. package/dist/fetch.d.ts +11 -0
  15. package/dist/fetch.d.ts.map +1 -0
  16. package/dist/fetch.js +19 -0
  17. package/dist/fetch.js.map +1 -0
  18. package/dist/html.d.ts +30 -0
  19. package/dist/html.d.ts.map +1 -0
  20. package/dist/html.js +197 -0
  21. package/dist/html.js.map +1 -0
  22. package/dist/index.d.ts +12 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +17 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/links.d.ts +10 -0
  27. package/dist/links.d.ts.map +1 -0
  28. package/dist/links.js +16 -0
  29. package/dist/links.js.map +1 -0
  30. package/dist/metadata.d.ts +10 -0
  31. package/dist/metadata.d.ts.map +1 -0
  32. package/dist/metadata.js +16 -0
  33. package/dist/metadata.js.map +1 -0
  34. package/dist/retry.d.ts +8 -0
  35. package/dist/retry.d.ts.map +1 -0
  36. package/dist/retry.js +11 -0
  37. package/dist/retry.js.map +1 -0
  38. package/dist/sitemap.d.ts +10 -0
  39. package/dist/sitemap.d.ts.map +1 -0
  40. package/dist/sitemap.js +16 -0
  41. package/dist/sitemap.js.map +1 -0
  42. package/dist/toMarkdown.d.ts +10 -0
  43. package/dist/toMarkdown.d.ts.map +1 -0
  44. package/dist/toMarkdown.js +20 -0
  45. package/dist/toMarkdown.js.map +1 -0
  46. package/dist/types.d.ts +85 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +3 -0
  49. package/dist/types.js.map +1 -0
  50. package/package.json +34 -0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @render-lab/tasks-scrape
2
+
3
+ Durable web-scrape tasks for [Render Workflows](https://render.com/docs/workflows).
4
+
5
+ ```ts
6
+ import { fetchUrl, extractContent, toMarkdown, crawl } from "@render-lab/tasks-scrape";
7
+ ```
8
+
9
+ | Task | Input | Output |
10
+ | ----------------------- | ---------------------------------------------- | -------------------------------------------------------- |
11
+ | `scrape.fetch` | `{ url, headers? }` | `{ url, status, ok, contentType, body }` |
12
+ | `scrape.extract` | `{ html, baseUrl? }` | `{ title, text, links }` |
13
+ | `scrape.toMarkdown` | `{ url, headers? }` | `{ url, title, markdown }` |
14
+ | `scrape.extractLinks` | `{ url, headers? }` | `{ url, links }` |
15
+ | `scrape.extractMetadata`| `{ url, headers? }` | `{ url, title, description, ogTitle?, ogImage?, canonical? }` |
16
+ | `scrape.sitemap` | `{ url, headers? }` | `{ url, urls }` |
17
+ | `scrape.crawl` | `{ startUrl, maxPages?, sameHost?, headers? }` | `{ pages: [{ url, title }] }` |
18
+
19
+ The two primitives compose: fetch a page, then extract readable text from it. Keeping them separate lets a workflow **fan out** — fetch many URLs as parallel durable runs — and pass each body to `extract` on its own instance, which is exactly the dashboard lineage a plain helper can't give you. The higher-level tasks bundle a fetch with a pure transform so common one-shot needs are a single call.
20
+
21
+ - **`scrape.fetch`** follows redirects and returns the raw body. It **throws on 429/5xx** so the durable retry policy re-runs it, and **returns 4xx** (e.g. 404) to the caller so a genuine client error doesn't burn retries.
22
+ - **`scrape.extract`** is pure CPU work (no retry): it strips `script`/`style`/tags, decodes entities, collapses whitespace, and pulls out the `<title>` and de-duplicated absolute links.
23
+ - **`scrape.toMarkdown`** fetches and converts the page's main content to clean markdown (headings, lists, emphasis, `[text](href)` links) — RAG/agent input, not a perfect converter.
24
+ - **`scrape.extractLinks`** fetches and returns the de-duplicated absolute links on the page.
25
+ - **`scrape.extractMetadata`** fetches and parses `<title>`, `<meta name="description">`, OpenGraph `og:title`/`og:image`, and `<link rel="canonical">`.
26
+ - **`scrape.sitemap`** fetches a `sitemap.xml` and returns the URLs from its `<loc>` entries (handles both `<urlset>` and `<sitemapindex>`).
27
+ - **`scrape.crawl`** does a bounded breadth-first walk from `startUrl`, following links (same host only when `sameHost`, default `true`) up to `maxPages` (default `10`), deduping visited URLs — all in one durable run.
28
+
29
+ Like `scrape.fetch`, the fetch-backed tasks throw on 429/5xx so the durable retry re-runs, and pass 4xx bodies through. All parsing is done by pure, exported helpers (`htmlToMarkdown`, `extractMetadata`, `parseSitemap`, `extractLinks`, `htmlToText`, `extractTitle`).
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pnpm add @render-lab/tasks-scrape @renderinc/sdk
35
+ ```
36
+
37
+ `@renderinc/sdk` is a peer dependency. There is no vendor dependency — the default port uses global `fetch` (Node 18+).
38
+
39
+ ## Environment contract
40
+
41
+ None. `scrape.fetch` takes everything it needs as input. Pass a `User-Agent` via `headers` if a site requires one.
42
+
43
+ ## A note on extraction quality
44
+
45
+ `scrape.extract` is a **minimal, dependency-free** extractor — regex tag-stripping, not a DOM parser — which is enough to hand readable text to an LLM. It does not run JavaScript. For JS-rendered pages or precise DOM queries, swap in a Firecrawl/Browserbase-backed `ScrapePort`; the port interface is the seam for exactly that, and it's why this is a **capability** package rather than `tasks-firecrawl`.
46
+
47
+ ## Extending & testing
48
+
49
+ Both operations export the wrapped task and its raw `*Impl`. `scrape.fetch` depends on a small `ScrapePort`, so it unit-tests without the network; the extraction transforms (`extract`, `htmlToText`, `extractLinks`, `extractTitle`) are pure and exported:
50
+
51
+ ```ts
52
+ import { fetchUrlImpl, type ScrapePort } from "@render-lab/tasks-scrape";
53
+
54
+ const scrape: ScrapePort = {
55
+ fetch: async () => ({ url, status: 200, ok: true, contentType: "text/html", body: "<p>hi</p>" }),
56
+ };
57
+ await fetchUrlImpl({ url: "https://example.com" }, { scrape });
58
+ ```
59
+
60
+ Run the tests with `pnpm -C packages/tasks-scrape test`.
@@ -0,0 +1,31 @@
1
+ import type { FetchResult } from "./types.js";
2
+ /**
3
+ * The slice of the network the tasks need. The default port uses global `fetch`;
4
+ * a Firecrawl/Browserbase-backed port (JS rendering) is a drop-in replacement.
5
+ */
6
+ export interface ScrapePort {
7
+ fetch(url: string, headers?: Record<string, string>): Promise<FetchResult>;
8
+ }
9
+ export interface ScrapeDeps {
10
+ scrape: ScrapePort;
11
+ }
12
+ /** Minimal fetch shape the default port uses (keeps it unit-testable). */
13
+ export type FetchLike = (url: string, init: {
14
+ headers?: Record<string, string>;
15
+ redirect: "follow";
16
+ }) => Promise<{
17
+ url: string;
18
+ status: number;
19
+ ok: boolean;
20
+ headers: {
21
+ get(name: string): string | null;
22
+ };
23
+ text(): Promise<string>;
24
+ }>;
25
+ /** Default scrape port backed by global `fetch`. */
26
+ export declare function fetchPort(opts?: {
27
+ fetchImpl?: FetchLike;
28
+ }): ScrapePort;
29
+ /** Default deps used by the wrapped tasks in production. */
30
+ export declare const defaultDeps: ScrapeDeps;
31
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,KAC3D,OAAO,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAC9C,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB,CAAC,CAAC;AAEH,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,SAAS,CAAA;CAAO,GAAG,UAAU,CAe1E;AAED,4DAA4D;AAC5D,eAAO,MAAM,WAAW,EAAE,UAAoC,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,20 @@
1
+ /** Default scrape port backed by global `fetch`. */
2
+ export function fetchPort(opts = {}) {
3
+ const doFetch = opts.fetchImpl ?? fetch;
4
+ return {
5
+ async fetch(url, headers) {
6
+ const res = await doFetch(url, { headers, redirect: "follow" });
7
+ const body = await res.text();
8
+ return {
9
+ url: res.url || url,
10
+ status: res.status,
11
+ ok: res.ok,
12
+ contentType: res.headers.get("content-type") ?? "",
13
+ body,
14
+ };
15
+ },
16
+ };
17
+ }
18
+ /** Default deps used by the wrapped tasks in production. */
19
+ export const defaultDeps = { scrape: fetchPort() };
20
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA0BA,oDAAoD;AACpD,MAAM,UAAU,SAAS,CAAC,OAAkC,EAAE;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,IAAK,KAA8B,CAAC;IAClE,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO;YACtB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAChE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAC9B,OAAO;gBACL,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG;gBACnB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE;gBAClD,IAAI;aACL,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,MAAM,WAAW,GAAe,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type ScrapeDeps } from "./client.js";
2
+ import type { CrawlInput, CrawlResult } from "./types.js";
3
+ /**
4
+ * Raw implementation of scrape.crawl. Bounded breadth-first walk from `startUrl`:
5
+ * fetch a page, record its title, enqueue its links (same-host only when `sameHost`),
6
+ * and stop at `maxPages`. Visited URLs are de-duplicated. Kept a single bounded loop
7
+ * so the whole crawl is one durable run.
8
+ */
9
+ export declare function crawlImpl(input: CrawlInput, deps?: ScrapeDeps): Promise<CrawlResult>;
10
+ /** Bounded BFS crawl following same-host links from a start URL. */
11
+ export declare const crawl: import("@renderinc/sdk/workflows").TaskFunction<[input: CrawlInput, deps?: ScrapeDeps | undefined], CrawlResult>;
12
+ //# sourceMappingURL=crawl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crawl.d.ts","sourceRoot":"","sources":["../src/crawl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU1D;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,UAAwB,GAC7B,OAAO,CAAC,WAAW,CAAC,CAyBtB;AAED,oEAAoE;AACpE,eAAO,MAAM,KAAK,kHAGjB,CAAC"}
package/dist/crawl.js ADDED
@@ -0,0 +1,48 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { fetchUrlImpl } from "./fetch.js";
3
+ import { extractLinks, extractTitle } from "./html.js";
4
+ import { defaultDeps } from "./client.js";
5
+ import { SCRAPE_RETRY } from "./retry.js";
6
+ function hostOf(url) {
7
+ try {
8
+ return new URL(url).host;
9
+ }
10
+ catch {
11
+ return undefined;
12
+ }
13
+ }
14
+ /**
15
+ * Raw implementation of scrape.crawl. Bounded breadth-first walk from `startUrl`:
16
+ * fetch a page, record its title, enqueue its links (same-host only when `sameHost`),
17
+ * and stop at `maxPages`. Visited URLs are de-duplicated. Kept a single bounded loop
18
+ * so the whole crawl is one durable run.
19
+ */
20
+ export async function crawlImpl(input, deps = defaultDeps) {
21
+ const maxPages = input.maxPages ?? 10;
22
+ const sameHost = input.sameHost ?? true;
23
+ const startHost = hostOf(input.startUrl);
24
+ const visited = new Set();
25
+ const queue = [input.startUrl];
26
+ const pages = [];
27
+ while (queue.length > 0 && pages.length < maxPages) {
28
+ const next = queue.shift();
29
+ if (visited.has(next))
30
+ continue;
31
+ visited.add(next);
32
+ const res = await fetchUrlImpl({ url: next, headers: input.headers }, deps);
33
+ if (!res.ok)
34
+ continue; // skip client errors; retryable statuses already threw
35
+ pages.push({ url: res.url, title: extractTitle(res.body) });
36
+ for (const link of extractLinks(res.body, res.url)) {
37
+ if (visited.has(link))
38
+ continue;
39
+ if (sameHost && hostOf(link) !== startHost)
40
+ continue;
41
+ queue.push(link);
42
+ }
43
+ }
44
+ return { pages };
45
+ }
46
+ /** Bounded BFS crawl following same-host links from a start URL. */
47
+ export const crawl = task({ name: "scrape.crawl", retry: SCRAPE_RETRY }, crawlImpl);
48
+ //# sourceMappingURL=crawl.js.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G,MAAM,YAAY,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;QAC5E,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,SAAS,CAAC,uDAAuD;QAC9E,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE5D,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,SAAS;YAChC,IAAI,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;gBAAE,SAAS;YACrD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CACvB,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,EAC7C,SAAS,CACV,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ExtractInput, ExtractResult } from "./types.js";
2
+ /** Raw implementation of scrape.extract. Pure CPU work, so no retry policy. */
3
+ export declare function extractImpl(input: ExtractInput): Promise<ExtractResult>;
4
+ /** Pull title, visible text, and links out of HTML. */
5
+ export declare const extractContent: import("@renderinc/sdk/workflows").TaskFunction<[input: ExtractInput], ExtractResult>;
6
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9D,+EAA+E;AAC/E,wBAAsB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAE7E;AAED,uDAAuD;AACvD,eAAO,MAAM,cAAc,uFAAgD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { extract } from "./html.js";
3
+ /** Raw implementation of scrape.extract. Pure CPU work, so no retry policy. */
4
+ export async function extractImpl(input) {
5
+ return extract(input.html, input.baseUrl);
6
+ }
7
+ /** Pull title, visible text, and links out of HTML. */
8
+ export const extractContent = task({ name: "scrape.extract" }, extractImpl);
9
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAmB;IACnD,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,WAAW,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type ScrapeDeps } from "./client.js";
2
+ import type { FetchInput, FetchResult } from "./types.js";
3
+ /**
4
+ * Raw implementation of scrape.fetch. Throws on 429/5xx so the durable retry
5
+ * policy re-runs the fetch; returns other non-2xx (e.g. 404) to the caller so a
6
+ * genuine client error doesn't burn retries or fail the whole workflow.
7
+ */
8
+ export declare function fetchUrlImpl(input: FetchInput, deps?: ScrapeDeps): Promise<FetchResult>;
9
+ /** Fetch a URL and return status + body. */
10
+ export declare const fetchUrl: import("@renderinc/sdk/workflows").TaskFunction<[input: FetchInput, deps?: ScrapeDeps | undefined], FetchResult>;
11
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,UAAwB,GAC7B,OAAO,CAAC,WAAW,CAAC,CAMtB;AAED,4CAA4C;AAC5C,eAAO,MAAM,QAAQ,kHAGpB,CAAC"}
package/dist/fetch.js ADDED
@@ -0,0 +1,19 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { isRetryable } from "@render-lab/tasks-core";
3
+ import { defaultDeps } from "./client.js";
4
+ import { SCRAPE_RETRY } from "./retry.js";
5
+ /**
6
+ * Raw implementation of scrape.fetch. Throws on 429/5xx so the durable retry
7
+ * policy re-runs the fetch; returns other non-2xx (e.g. 404) to the caller so a
8
+ * genuine client error doesn't burn retries or fail the whole workflow.
9
+ */
10
+ export async function fetchUrlImpl(input, deps = defaultDeps) {
11
+ const res = await deps.scrape.fetch(input.url, input.headers);
12
+ if (isRetryable(res.status)) {
13
+ throw new Error(`scrape.fetch ${input.url} failed: ${res.status}`);
14
+ }
15
+ return res;
16
+ }
17
+ /** Fetch a URL and return status + body. */
18
+ export const fetchUrl = task({ name: "scrape.fetch", retry: SCRAPE_RETRY }, fetchUrlImpl);
19
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAiB,EACjB,OAAmB,WAAW;IAE9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,CAAC,GAAG,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAC1B,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,EAC7C,YAAY,CACb,CAAC"}
package/dist/html.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { ExtractResult, PageMetadata } from "./types.js";
2
+ /** Contents of the first <title> tag, decoded and trimmed. */
3
+ export declare function extractTitle(html: string): string;
4
+ /**
5
+ * Absolute hrefs from <a> tags, de-duplicated. Skips in-page anchors and
6
+ * javascript:/mailto: links; resolves relative hrefs against `baseUrl`.
7
+ */
8
+ export declare function extractLinks(html: string, baseUrl?: string): string[];
9
+ /** Strip script/style/tags to visible text, decode entities, collapse whitespace. */
10
+ export declare function htmlToText(html: string): string;
11
+ /** Title + visible text + links from a page's HTML. */
12
+ export declare function extract(html: string, baseUrl?: string): ExtractResult;
13
+ /**
14
+ * Convert HTML to clean markdown. Deliberately minimal (regex, not a DOM parser):
15
+ * headings become `#`, list items `-`, `<strong>/<em>` map to markdown emphasis, and
16
+ * `<a>` links become `[text](href)`. Good enough as RAG/agent input, not a perfect
17
+ * converter. `baseUrl` resolves relative link hrefs to absolute ones.
18
+ */
19
+ export declare function htmlToMarkdown(html: string, baseUrl?: string): string;
20
+ /**
21
+ * Parse document metadata: <title>, <meta name="description">, OpenGraph og:title /
22
+ * og:image, and <link rel="canonical">. Optional fields are omitted when absent.
23
+ */
24
+ export declare function extractMetadata(html: string): PageMetadata;
25
+ /**
26
+ * Parse the `<loc>` entries out of a sitemap.xml (works for both `<urlset>` and
27
+ * `<sitemapindex>` documents). Entries are entity-decoded and trimmed.
28
+ */
29
+ export declare function parseSitemap(xml: string): string[];
30
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAqC9D,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrE;AAED,qFAAqF;AACrF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiB/C;AAED,uDAAuD;AACvD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,aAAa,CAMrE;AASD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAiDrE;AAuCD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAY1D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CASlD"}
package/dist/html.js ADDED
@@ -0,0 +1,197 @@
1
+ // Minimal, dependency-free HTML extraction. This is deliberately NOT a full DOM
2
+ // parser — it strips tags with regex and collapses whitespace, which is enough to
3
+ // hand readable text to an LLM. For JS-rendered pages or precise DOM queries, swap
4
+ // in a Firecrawl/Browserbase-backed ScrapePort. Kept pure so it unit-tests cleanly.
5
+ const ENTITIES = {
6
+ "&amp;": "&",
7
+ "&lt;": "<",
8
+ "&gt;": ">",
9
+ "&quot;": '"',
10
+ "&#39;": "'",
11
+ "&apos;": "'",
12
+ "&nbsp;": " ",
13
+ };
14
+ function decodeEntities(s) {
15
+ return s
16
+ .replace(/&amp;|&lt;|&gt;|&quot;|&#39;|&apos;|&nbsp;/g, (m) => ENTITIES[m] ?? m)
17
+ .replace(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d)))
18
+ .replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)));
19
+ }
20
+ function stripElement(html, tag) {
21
+ return html.replace(new RegExp(`<${tag}\\b[\\s\\S]*?</${tag}>`, "gi"), " ");
22
+ }
23
+ function resolveUrl(href, base) {
24
+ if (!base)
25
+ return href;
26
+ try {
27
+ return new URL(href, base).toString();
28
+ }
29
+ catch {
30
+ return href;
31
+ }
32
+ }
33
+ /** Contents of the first <title> tag, decoded and trimmed. */
34
+ export function extractTitle(html) {
35
+ const m = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
36
+ return m ? decodeEntities(m[1]).trim() : "";
37
+ }
38
+ /**
39
+ * Absolute hrefs from <a> tags, de-duplicated. Skips in-page anchors and
40
+ * javascript:/mailto: links; resolves relative hrefs against `baseUrl`.
41
+ */
42
+ export function extractLinks(html, baseUrl) {
43
+ const out = new Set();
44
+ const re = /<a\b[^>]*\bhref\s*=\s*["']([^"']+)["']/gi;
45
+ let m;
46
+ while ((m = re.exec(html))) {
47
+ const href = m[1].trim();
48
+ if (href === "" || /^(javascript:|mailto:|tel:|#)/i.test(href))
49
+ continue;
50
+ out.add(resolveUrl(href, baseUrl));
51
+ }
52
+ return [...out];
53
+ }
54
+ /** Strip script/style/tags to visible text, decode entities, collapse whitespace. */
55
+ export function htmlToText(html) {
56
+ let s = html;
57
+ s = stripElement(s, "script");
58
+ s = stripElement(s, "style");
59
+ s = stripElement(s, "noscript");
60
+ s = stripElement(s, "title"); // extracted separately; keep it out of body text
61
+ s = s.replace(/<br\s*\/?>/gi, "\n");
62
+ s = s.replace(/<\/(p|div|section|article|h[1-6]|li|tr|blockquote)>/gi, "\n");
63
+ s = s.replace(/<[^>]+>/g, " ");
64
+ s = decodeEntities(s);
65
+ s = s.replace(/[^\S\n]+/g, " "); // collapse runs of spaces/tabs, keep newlines
66
+ s = s.replace(/\n{3,}/g, "\n\n"); // cap consecutive blank lines
67
+ return s
68
+ .split("\n")
69
+ .map((line) => line.trim())
70
+ .join("\n")
71
+ .trim();
72
+ }
73
+ /** Title + visible text + links from a page's HTML. */
74
+ export function extract(html, baseUrl) {
75
+ return {
76
+ title: extractTitle(html),
77
+ text: htmlToText(html),
78
+ links: extractLinks(html, baseUrl),
79
+ };
80
+ }
81
+ /** Drop all tags from a fragment and decode entities — used for inline markdown text. */
82
+ function stripTags(html) {
83
+ return decodeEntities(html.replace(/<[^>]+>/g, " "))
84
+ .replace(/\s+/g, " ")
85
+ .trim();
86
+ }
87
+ /**
88
+ * Convert HTML to clean markdown. Deliberately minimal (regex, not a DOM parser):
89
+ * headings become `#`, list items `-`, `<strong>/<em>` map to markdown emphasis, and
90
+ * `<a>` links become `[text](href)`. Good enough as RAG/agent input, not a perfect
91
+ * converter. `baseUrl` resolves relative link hrefs to absolute ones.
92
+ */
93
+ export function htmlToMarkdown(html, baseUrl) {
94
+ let s = html;
95
+ s = stripElement(s, "script");
96
+ s = stripElement(s, "style");
97
+ s = stripElement(s, "noscript");
98
+ s = stripElement(s, "title"); // extracted separately
99
+ for (let level = 1; level <= 6; level++) {
100
+ const hashes = "#".repeat(level);
101
+ s = s.replace(new RegExp(`<h${level}\\b[^>]*>([\\s\\S]*?)</h${level}>`, "gi"), (_m, inner) => `\n\n${hashes} ${stripTags(inner)}\n\n`);
102
+ }
103
+ s = s.replace(/<li\b[^>]*>([\s\S]*?)<\/li>/gi, (_m, inner) => `\n- ${stripTags(inner)}`);
104
+ s = s.replace(/<(strong|b)\b[^>]*>([\s\S]*?)<\/\1>/gi, (_m, _tag, inner) => {
105
+ const text = stripTags(inner);
106
+ return text ? `**${text}**` : "";
107
+ });
108
+ s = s.replace(/<(em|i)\b[^>]*>([\s\S]*?)<\/\1>/gi, (_m, _tag, inner) => {
109
+ const text = stripTags(inner);
110
+ return text ? `*${text}*` : "";
111
+ });
112
+ s = s.replace(/<a\b[^>]*\bhref\s*=\s*["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi, (_m, href, inner) => {
113
+ const text = stripTags(inner);
114
+ return text ? `[${text}](${resolveUrl(href.trim(), baseUrl)})` : "";
115
+ });
116
+ s = s.replace(/<br\s*\/?>/gi, "\n");
117
+ s = s.replace(/<\/(p|div|section|article|blockquote|tr|ul|ol)>/gi, "\n\n");
118
+ s = s.replace(/<[^>]+>/g, " ");
119
+ s = decodeEntities(s);
120
+ s = s.replace(/[^\S\n]+/g, " "); // collapse spaces/tabs, keep newlines
121
+ return s
122
+ .split("\n")
123
+ .map((line) => line.trim())
124
+ .join("\n")
125
+ .replace(/\n{3,}/g, "\n\n") // cap consecutive blank lines
126
+ .trim();
127
+ }
128
+ /** Parse `key="value"`/`key='value'` attribute pairs from a single tag, keyed lowercase. */
129
+ function parseAttrs(tag) {
130
+ const attrs = {};
131
+ const re = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*("([^"]*)"|'([^']*)')/g;
132
+ let m;
133
+ while ((m = re.exec(tag))) {
134
+ attrs[m[1].toLowerCase()] = m[3] ?? m[4] ?? "";
135
+ }
136
+ return attrs;
137
+ }
138
+ /** content of the first <meta> whose `attr` (name|property) equals `value`. */
139
+ function metaContent(html, attr, value) {
140
+ const re = /<meta\b[^>]*>/gi;
141
+ let m;
142
+ while ((m = re.exec(html))) {
143
+ const attrs = parseAttrs(m[0]);
144
+ if ((attrs[attr] ?? "").toLowerCase() === value && attrs.content !== undefined) {
145
+ return decodeEntities(attrs.content).trim();
146
+ }
147
+ }
148
+ return undefined;
149
+ }
150
+ /** href of the first <link> whose rel equals `rel`. */
151
+ function linkHref(html, rel) {
152
+ const re = /<link\b[^>]*>/gi;
153
+ let m;
154
+ while ((m = re.exec(html))) {
155
+ const attrs = parseAttrs(m[0]);
156
+ if ((attrs.rel ?? "").toLowerCase() === rel && attrs.href) {
157
+ return decodeEntities(attrs.href).trim();
158
+ }
159
+ }
160
+ return undefined;
161
+ }
162
+ /**
163
+ * Parse document metadata: <title>, <meta name="description">, OpenGraph og:title /
164
+ * og:image, and <link rel="canonical">. Optional fields are omitted when absent.
165
+ */
166
+ export function extractMetadata(html) {
167
+ const meta = {
168
+ title: extractTitle(html),
169
+ description: metaContent(html, "name", "description") ?? "",
170
+ };
171
+ const ogTitle = metaContent(html, "property", "og:title");
172
+ const ogImage = metaContent(html, "property", "og:image");
173
+ const canonical = linkHref(html, "canonical");
174
+ if (ogTitle)
175
+ meta.ogTitle = ogTitle;
176
+ if (ogImage)
177
+ meta.ogImage = ogImage;
178
+ if (canonical)
179
+ meta.canonical = canonical;
180
+ return meta;
181
+ }
182
+ /**
183
+ * Parse the `<loc>` entries out of a sitemap.xml (works for both `<urlset>` and
184
+ * `<sitemapindex>` documents). Entries are entity-decoded and trimmed.
185
+ */
186
+ export function parseSitemap(xml) {
187
+ const out = [];
188
+ const re = /<loc>\s*([\s\S]*?)\s*<\/loc>/gi;
189
+ let m;
190
+ while ((m = re.exec(xml))) {
191
+ const url = decodeEntities(m[1].trim());
192
+ if (url)
193
+ out.push(url);
194
+ }
195
+ return out;
196
+ }
197
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,kFAAkF;AAClF,mFAAmF;AACnF,oFAAo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Aa,CAAC,IAAI,EAAE;KAC5D,CAAC;IACF,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAC1D,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC9C,IAAI,OAAO;QAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACpC,IAAI,OAAO;QAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACpC,IAAI,SAAS;QAAE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,EAAE,GAAG,gCAAgC,CAAC;IAC5C,IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACzC,IAAI,GAAG;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,12 @@
1
+ export * from "./types.js";
2
+ export { fetchPort, defaultDeps, type ScrapePort, type ScrapeDeps, type FetchLike, } from "./client.js";
3
+ export { extract, extractTitle, extractLinks, htmlToText, htmlToMarkdown, extractMetadata, parseSitemap, } from "./html.js";
4
+ export { SCRAPE_RETRY } from "./retry.js";
5
+ export { fetchUrl, fetchUrlImpl } from "./fetch.js";
6
+ export { extractContent, extractImpl } from "./extract.js";
7
+ export { toMarkdown, toMarkdownImpl } from "./toMarkdown.js";
8
+ export { extractPageLinks, extractPageLinksImpl } from "./links.js";
9
+ export { extractPageMetadata, extractPageMetadataImpl } from "./metadata.js";
10
+ export { sitemap, sitemapImpl } from "./sitemap.js";
11
+ export { crawl, crawlImpl } from "./crawl.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,SAAS,EACT,WAAW,EACX,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,eAAe,EACf,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ // @render-lab/tasks-scrape — durable web-scrape tasks.
2
+ //
3
+ // Importing this module registers scrape.fetch, scrape.extract, scrape.toMarkdown,
4
+ // scrape.extractLinks, scrape.extractMetadata, scrape.sitemap, and scrape.crawl with
5
+ // the Workflows TaskRegistry as a side effect.
6
+ export * from "./types.js";
7
+ export { fetchPort, defaultDeps, } from "./client.js";
8
+ export { extract, extractTitle, extractLinks, htmlToText, htmlToMarkdown, extractMetadata, parseSitemap, } from "./html.js";
9
+ export { SCRAPE_RETRY } from "./retry.js";
10
+ export { fetchUrl, fetchUrlImpl } from "./fetch.js";
11
+ export { extractContent, extractImpl } from "./extract.js";
12
+ export { toMarkdown, toMarkdownImpl } from "./toMarkdown.js";
13
+ export { extractPageLinks, extractPageLinksImpl } from "./links.js";
14
+ export { extractPageMetadata, extractPageMetadataImpl } from "./metadata.js";
15
+ export { sitemap, sitemapImpl } from "./sitemap.js";
16
+ export { crawl, crawlImpl } from "./crawl.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,mFAAmF;AACnF,qFAAqF;AACrF,+CAA+C;AAE/C,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,SAAS,EACT,WAAW,GAIZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,eAAe,EACf,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type ScrapeDeps } from "./client.js";
2
+ import type { FetchInput, LinksResult } from "./types.js";
3
+ /**
4
+ * Raw implementation of scrape.extractLinks. Fetches the page and returns its
5
+ * de-duplicated absolute links, resolved against the final URL.
6
+ */
7
+ export declare function extractPageLinksImpl(input: FetchInput, deps?: ScrapeDeps): Promise<LinksResult>;
8
+ /** Fetch a URL and return its absolute links. */
9
+ export declare const extractPageLinks: import("@renderinc/sdk/workflows").TaskFunction<[input: FetchInput, deps?: ScrapeDeps | undefined], LinksResult>;
10
+ //# sourceMappingURL=links.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE1D;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,UAAwB,GAC7B,OAAO,CAAC,WAAW,CAAC,CAGtB;AAED,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,kHAG5B,CAAC"}
package/dist/links.js ADDED
@@ -0,0 +1,16 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { fetchUrlImpl } from "./fetch.js";
3
+ import { extractLinks } from "./html.js";
4
+ import { defaultDeps } from "./client.js";
5
+ import { SCRAPE_RETRY } from "./retry.js";
6
+ /**
7
+ * Raw implementation of scrape.extractLinks. Fetches the page and returns its
8
+ * de-duplicated absolute links, resolved against the final URL.
9
+ */
10
+ export async function extractPageLinksImpl(input, deps = defaultDeps) {
11
+ const res = await fetchUrlImpl(input, deps);
12
+ return { url: res.url, links: extractLinks(res.body, res.url) };
13
+ }
14
+ /** Fetch a URL and return its absolute links. */
15
+ export const extractPageLinks = task({ name: "scrape.extractLinks", retry: SCRAPE_RETRY }, extractPageLinksImpl);
16
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAiB,EACjB,OAAmB,WAAW;IAE9B,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;AAClE,CAAC;AAED,iDAAiD;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAClC,EAAE,IAAI,EAAE,qBAAqB,EAAE,KAAK,EAAE,YAAY,EAAE,EACpD,oBAAoB,CACrB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type ScrapeDeps } from "./client.js";
2
+ import type { FetchInput, MetadataResult } from "./types.js";
3
+ /**
4
+ * Raw implementation of scrape.extractMetadata. Fetches the page and parses its
5
+ * <title>, description, OpenGraph og:* tags, and canonical link.
6
+ */
7
+ export declare function extractPageMetadataImpl(input: FetchInput, deps?: ScrapeDeps): Promise<MetadataResult>;
8
+ /** Fetch a URL and return its head metadata. */
9
+ export declare const extractPageMetadata: import("@renderinc/sdk/workflows").TaskFunction<[input: FetchInput, deps?: ScrapeDeps | undefined], MetadataResult>;
10
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7D;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,UAAwB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAGzB;AAED,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,qHAG/B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { fetchUrlImpl } from "./fetch.js";
3
+ import { extractMetadata } from "./html.js";
4
+ import { defaultDeps } from "./client.js";
5
+ import { SCRAPE_RETRY } from "./retry.js";
6
+ /**
7
+ * Raw implementation of scrape.extractMetadata. Fetches the page and parses its
8
+ * <title>, description, OpenGraph og:* tags, and canonical link.
9
+ */
10
+ export async function extractPageMetadataImpl(input, deps = defaultDeps) {
11
+ const res = await fetchUrlImpl(input, deps);
12
+ return { url: res.url, ...extractMetadata(res.body) };
13
+ }
14
+ /** Fetch a URL and return its head metadata. */
15
+ export const extractPageMetadata = task({ name: "scrape.extractMetadata", retry: SCRAPE_RETRY }, extractPageMetadataImpl);
16
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAiB,EACjB,OAAmB,WAAW;IAE9B,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;AACxD,CAAC;AAED,gDAAgD;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CACrC,EAAE,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,EACvD,uBAAuB,CACxB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Retry } from "@renderinc/sdk/workflows";
2
+ /**
3
+ * Retry policy for network fetches — covers transient DNS/connection failures,
4
+ * 429s, and 5xx. Backoff over ~1s, 2s, 4s. Client errors (4xx other than 429)
5
+ * are returned to the caller, not retried.
6
+ */
7
+ export declare const SCRAPE_RETRY: Retry;
8
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAI1B,CAAC"}
package/dist/retry.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Retry policy for network fetches — covers transient DNS/connection failures,
3
+ * 429s, and 5xx. Backoff over ~1s, 2s, 4s. Client errors (4xx other than 429)
4
+ * are returned to the caller, not retried.
5
+ */
6
+ export const SCRAPE_RETRY = {
7
+ maxRetries: 3,
8
+ waitDurationMs: 1_000,
9
+ backoffScaling: 2,
10
+ };
11
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAU;IACjC,UAAU,EAAE,CAAC;IACb,cAAc,EAAE,KAAK;IACrB,cAAc,EAAE,CAAC;CAClB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type ScrapeDeps } from "./client.js";
2
+ import type { FetchInput, SitemapResult } from "./types.js";
3
+ /**
4
+ * Raw implementation of scrape.sitemap. Fetches a sitemap.xml and returns the URLs
5
+ * from its <loc> entries (handles both <urlset> and <sitemapindex> documents).
6
+ */
7
+ export declare function sitemapImpl(input: FetchInput, deps?: ScrapeDeps): Promise<SitemapResult>;
8
+ /** Fetch a sitemap.xml and return its listed URLs. */
9
+ export declare const sitemap: import("@renderinc/sdk/workflows").TaskFunction<[input: FetchInput, deps?: ScrapeDeps | undefined], SitemapResult>;
10
+ //# sourceMappingURL=sitemap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../src/sitemap.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE5D;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,UAAwB,GAC7B,OAAO,CAAC,aAAa,CAAC,CAGxB;AAED,sDAAsD;AACtD,eAAO,MAAM,OAAO,oHAGnB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { fetchUrlImpl } from "./fetch.js";
3
+ import { parseSitemap } from "./html.js";
4
+ import { defaultDeps } from "./client.js";
5
+ import { SCRAPE_RETRY } from "./retry.js";
6
+ /**
7
+ * Raw implementation of scrape.sitemap. Fetches a sitemap.xml and returns the URLs
8
+ * from its <loc> entries (handles both <urlset> and <sitemapindex> documents).
9
+ */
10
+ export async function sitemapImpl(input, deps = defaultDeps) {
11
+ const res = await fetchUrlImpl(input, deps);
12
+ return { url: res.url, urls: parseSitemap(res.body) };
13
+ }
14
+ /** Fetch a sitemap.xml and return its listed URLs. */
15
+ export const sitemap = task({ name: "scrape.sitemap", retry: SCRAPE_RETRY }, sitemapImpl);
16
+ //# sourceMappingURL=sitemap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sitemap.js","sourceRoot":"","sources":["../src/sitemap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAiB,EACjB,OAAmB,WAAW;IAE9B,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;AACxD,CAAC;AAED,sDAAsD;AACtD,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CACzB,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAE,EAC/C,WAAW,CACZ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type ScrapeDeps } from "./client.js";
2
+ import type { FetchInput, ToMarkdownResult } from "./types.js";
3
+ /**
4
+ * Raw implementation of scrape.toMarkdown. Fetches the page (reusing scrape.fetch's
5
+ * retry-on-429/5xx semantics) and converts its main text to clean markdown.
6
+ */
7
+ export declare function toMarkdownImpl(input: FetchInput, deps?: ScrapeDeps): Promise<ToMarkdownResult>;
8
+ /** Fetch a URL and convert its content to markdown. */
9
+ export declare const toMarkdown: import("@renderinc/sdk/workflows").TaskFunction<[input: FetchInput, deps?: ScrapeDeps | undefined], ToMarkdownResult>;
10
+ //# sourceMappingURL=toMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toMarkdown.d.ts","sourceRoot":"","sources":["../src/toMarkdown.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D;;;GAGG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE,UAAwB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAO3B;AAED,uDAAuD;AACvD,eAAO,MAAM,UAAU,uHAGtB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { task } from "@renderinc/sdk/workflows";
2
+ import { fetchUrlImpl } from "./fetch.js";
3
+ import { extractTitle, htmlToMarkdown } from "./html.js";
4
+ import { defaultDeps } from "./client.js";
5
+ import { SCRAPE_RETRY } from "./retry.js";
6
+ /**
7
+ * Raw implementation of scrape.toMarkdown. Fetches the page (reusing scrape.fetch's
8
+ * retry-on-429/5xx semantics) and converts its main text to clean markdown.
9
+ */
10
+ export async function toMarkdownImpl(input, deps = defaultDeps) {
11
+ const res = await fetchUrlImpl(input, deps);
12
+ return {
13
+ url: res.url,
14
+ title: extractTitle(res.body),
15
+ markdown: htmlToMarkdown(res.body, res.url),
16
+ };
17
+ }
18
+ /** Fetch a URL and convert its content to markdown. */
19
+ export const toMarkdown = task({ name: "scrape.toMarkdown", retry: SCRAPE_RETRY }, toMarkdownImpl);
20
+ //# sourceMappingURL=toMarkdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toMarkdown.js","sourceRoot":"","sources":["../src/toMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,KAAiB,EACjB,OAAmB,WAAW;IAE9B,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;QAC7B,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAC5B,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,YAAY,EAAE,EAClD,cAAc,CACf,CAAC"}
@@ -0,0 +1,85 @@
1
+ export interface FetchInput {
2
+ url: string;
3
+ /** Optional request headers (e.g. a custom User-Agent). */
4
+ headers?: Record<string, string>;
5
+ }
6
+ export interface FetchResult {
7
+ /** Final URL after redirects. */
8
+ url: string;
9
+ status: number;
10
+ /** True for a 2xx status. */
11
+ ok: boolean;
12
+ /** Value of the response's content-type header, or "". */
13
+ contentType: string;
14
+ /** Raw response body as text. */
15
+ body: string;
16
+ }
17
+ export interface ExtractInput {
18
+ /** Raw HTML to extract from. */
19
+ html: string;
20
+ /** Base URL used to resolve relative links to absolute ones. */
21
+ baseUrl?: string;
22
+ }
23
+ export interface ExtractResult {
24
+ /** Contents of <title>, or "". */
25
+ title: string;
26
+ /** Visible text with tags/script/style stripped and whitespace collapsed. */
27
+ text: string;
28
+ /** Absolute hrefs found in <a> tags, de-duplicated. */
29
+ links: string[];
30
+ }
31
+ /** Page metadata parsed out of the document head. */
32
+ export interface PageMetadata {
33
+ /** Contents of <title>, or "". */
34
+ title: string;
35
+ /** Value of <meta name="description">, or "". */
36
+ description: string;
37
+ /** Value of <meta property="og:title">, if present. */
38
+ ogTitle?: string;
39
+ /** Value of <meta property="og:image">, if present. */
40
+ ogImage?: string;
41
+ /** href of <link rel="canonical">, if present. */
42
+ canonical?: string;
43
+ }
44
+ export interface ToMarkdownResult {
45
+ /** Final URL after redirects. */
46
+ url: string;
47
+ /** Contents of <title>, or "". */
48
+ title: string;
49
+ /** Main text converted to clean markdown (RAG/agent input, not a perfect converter). */
50
+ markdown: string;
51
+ }
52
+ export interface LinksResult {
53
+ /** Final URL after redirects. */
54
+ url: string;
55
+ /** Absolute hrefs found in <a> tags, de-duplicated. */
56
+ links: string[];
57
+ }
58
+ export interface MetadataResult extends PageMetadata {
59
+ /** Final URL after redirects. */
60
+ url: string;
61
+ }
62
+ export interface SitemapResult {
63
+ /** Final URL after redirects. */
64
+ url: string;
65
+ /** URLs parsed from the sitemap's <loc> entries. */
66
+ urls: string[];
67
+ }
68
+ export interface CrawlInput {
69
+ /** URL to start the crawl from. */
70
+ startUrl: string;
71
+ /** Maximum number of pages to fetch. Default 10. */
72
+ maxPages?: number;
73
+ /** Only follow links on the same host as `startUrl`. Default true. */
74
+ sameHost?: boolean;
75
+ /** Optional request headers applied to every fetch (e.g. a custom User-Agent). */
76
+ headers?: Record<string, string>;
77
+ }
78
+ export interface CrawlResult {
79
+ /** Pages that were successfully fetched, in crawl order. */
80
+ pages: {
81
+ url: string;
82
+ title: string;
83
+ }[];
84
+ }
85
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,OAAO,CAAC,EAAE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AC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,4DAA4D;IAC5D,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACzC"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ // JSON-serializable DTOs for the scrape.* tasks.
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,iDAAiD"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@render-lab/tasks-scrape",
3
+ "version": "0.1.0",
4
+ "description": "Durable web-scrape tasks for Render Workflows: scrape.fetch, scrape.extract.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "peerDependencies": {
18
+ "@renderinc/sdk": "0.6.0"
19
+ },
20
+ "devDependencies": {
21
+ "@renderinc/sdk": "0.6.0",
22
+ "@types/node": "^24.0.0",
23
+ "typescript": "^6.0.0",
24
+ "vitest": "^4.1.0"
25
+ },
26
+ "dependencies": {
27
+ "@render-lab/tasks-core": "0.1.0"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.json",
31
+ "typecheck": "tsc -p tsconfig.json --noEmit",
32
+ "test": "vitest run"
33
+ }
34
+ }