@scwrap/deploy is the deployment SDK. It turns a Scraper into something an instance can install: a Release.
A Release is immutable. It is identified by its Scraper ID, a revision label and the SHA-256 digest of its built code. Deploying a Release with an ID that is already installed replaces the installed one.
| Function | Declares |
|---|---|
Deployment.worker | A Release that runs on the instance, in its own Dynamic Worker sandbox. |
A Scraper package never imports this SDK. Releases are declared by the repository that deploys them: in a Scraper repository in its releases package (Installation), in the Scwrap repository under apps/infra/src/.
Deployment.worker
Use a Worker release for every new Release. Its Capabilities come from Layers that run in a Cloudflare Worker: FetchHttpClient.layer for fetch, apifyProxy for a proxy route, and browserRun or browserUse for a browser.
Example (apps/infra/src/instance-earthquakes.ts)
import { Deployment } from "@scwrap/deploy";
import { Earthquakes, UsgsFeedLive } from "@scwrap/earthquakes";
import { FetchHttpClient } from "effect/http";
export default Deployment.worker({
implementation: UsgsFeedLive,
module: import.meta.url,
scraper: Earthquakes,
services: FetchHttpClient.layer,
});A Release is its module's default export. The bundler imports it from there.
| Option | Meaning |
|---|---|
scraper | The Definition. Its ID is the Release's ID. |
implementation | The Implementation Layer to run. |
services | A Layer that provides every Capability the Implementation requires, plus any services its schemas need. |
module | Always import.meta.url. The bundler starts from this module. |
revision | Optional. A label you choose. Defaults to v1. The digest of the built code, not the label, tells two builds apart. |
maxRunDuration | Optional. A Duration.Input, such as "3 minutes": how long one Run may last before the instance ends it failed with RunTimeout. Defaults to 10 minutes; at most 14 minutes, and a build refuses a Release outside that range (Run duration). |
The Release wraps Scraper.run around the Implementation and its services. On the instance, that Stream is what a Run executes.
A Release's callers rely on two contracts: its Definition's input, output and errors, which change only when you change the Definition, and the instance's HTTP API and result record, which change only by the rules in Compatibility.
The instance supplies nothing
services must satisfy the Implementation completely. Its type is a Layer that provides the Implementation's requirements and itself requires nothing, so a missing Capability is a compile error on the Release:
Type 'HttpClient' is not assignable to type 'never'.
Missing 'HttpClient' in the expected Layer context. effect(missingLayerContext)To provide more than one Capability, merge Layers with Layer.mergeAll and pass the result.
Example (A browser Scraper on Cloudflare Browser Run, from Adding a browser)
import { browserRun } from "@scwrap/browser/browser-run";
import { Deployment } from "@scwrap/deploy";
import { Quotes, QuotesBrowserLive } from "@scwrap/quotes";
export default Deployment.worker({
implementation: QuotesBrowserLive,
module: import.meta.url,
scraper: Quotes,
services: browserRun,
});A provider that does not cover a country the Implementation opens its page in, or routes to, fails the same check at the implementation: line (The location is part of the type).
The catalog
A repository deploys the Releases listed in one array, the default export of its catalog module. A one-file Scraper needs no catalog: scwrap deploy <file.ts> deploys the one Release the file exports.
Example (apps/infra/src/instance-scrapers.ts, the Scwrap repository's catalog)
import EarthquakesRelease from "./instance-earthquakes.ts";
const instanceScrapers = [EarthquakesRelease];
export default instanceScrapers;A Scraper repository's catalog, releases/src/catalog.ts, has the same shape with its own Releases.
The array is the module's default export, which is what the scwrap CLI reads from a catalog module.
Rules for the array:
- One Release per Scraper ID. The CLI refuses a catalog with duplicate IDs.
- One module per Release. Each Release is the default export of its own file, so one Release's bundle never pulls in another's code.
- No credentials. The catalog is code. Secrets reach a Release through the instance, never through the catalog.
- One catalog per repository, several per instance. Several repositories can deploy their catalogs to one instance. A deploy replaces only the Releases it names, so Releases from other catalogs stay installed. Scraper IDs must not collide across them: a Release with an installed ID replaces the installed one.
Choosing a revision
revision is a label for people. It does not have to change when the code changes, because the digest already identifies the bytes. Change it when you want callers to see that a Release is a new edition, for example after changing the output schema.
Every result record names the Release that produced it by scraper, revision and digest.
Source
- index.ts:
Deployment.worker - instance-scrapers.ts: the Scwrap repository's catalog