Skip to content

Domain overview

@scwrap/domain is what a Scraper is written with: the Definition, schema-checked execution, Shared errors, HTTP helpers and the Capability ports.

@scwrap/domain is the SDK a Scraper package imports. It owns the contract and stays out of everything else: it knows nothing about Cloudflare, deployment or storage, and depends only on effect.

Because of that, a Scraper runs the same in a test, in a script and on an instance.

What it exports ​

ExportJobPage
ScraperScraper.make declares a Definition, Scraper.layer implements one, Scraper.run runs one with its input and output checked, Scraper.rpc reads its schemas.Scraper
Blocked, RateLimited, UpstreamDown, QuotaExhausted, SchemaDrift, InvalidInputThe Shared errors.Errors
Download, retryHttpClient, httpFailure, httpStatusFailure, isTransientHttpFailure, decodeScrapedRecord, cleanText, clockTime, numericDate, localTimeToUtcHelpers for HTTP sources and for decoding scraped data, text and dates.HTTP helpers
ProxiedHttpClient, ProxyRoute, CountryCodeThe Capability for proxy routes.Proxied HTTP client
Browser, Page, BrowserOptions, NavigationOptions, BrowserError, navigate, clickUntilChangedThe Capability for a real browser, and the page helpers.The Browser Capability
TextCaptchaSolver, TextCaptcha, TextCaptchaReading, CaptchaUnreadable, firstConfidentThe Capability for text captchas.Captcha solving
FakeSite, ScraperTest, from @scwrap/domain/testingThe test kit: a fake site and a typed Run.Test kit

Ports, not providers ​

Three of these exports are ports: ProxiedHttpClient, Browser and TextCaptchaSolver. A port is the interface of a Capability. It says what a Scraper can ask for and nothing about who answers.

Providers live in other packages:

PortProviders
ProxiedHttpClientapifyProxy in @scwrap/platform-apify, for Workers and for Node
BrowserbrowserRun, browserUse, nodeBrowser and playwrightBrowser in @scwrap/browser
TextCaptchaSolverThe template engine in @scwrap/captcha-templates; any DecisionModel through TextCaptchaSolver.fromDecisionModel

One Capability is not in this package at all: HttpClient is Effect's own, from effect/http. The Browser port names no Playwright type, so a Scraper that opens a browser still depends only on @scwrap/domain; Playwright stays in its providers.

Boundaries ​

Lint enforces what this package may import:

  • packages/domain imports only effect. Its ports may name effect/http types such as HttpClient, but never effect/http-api, a vendor SDK or Alchemy.
  • A Scraper package imports @scwrap/domain, browser Scrapers included; its tests may use a provider such as nodeBrowser. It never imports @scwrap/deploy or an app.

The rule is scwrap-boundaries/no-core-adapters in boundaries.ts.

Source ​

packages/domain/src has one file per export. Its tests in packages/domain/test are properties over generated Definitions, inputs and failures.