The scwrap CLI is the usual way to deploy. It is a thin layer over createDeployer, which you can call yourself when a deploy is part of a larger program.
@scwrap/deploy has three entry points:
| Import | Contains |
|---|---|
@scwrap/deploy | Deployment.worker. Safe to import anywhere. |
@scwrap/deploy/client | createDeployer and the bundler. Node only. |
@scwrap/deploy/protocol | The schemas of the deployment API. Depends only on effect. |
createDeployer
import { createDeployer } from "@scwrap/deploy/client";
import { Redacted } from "effect";
const deployer = createDeployer({
instance: "https://scwrap.example.com",
token: Redacted.make(deployerToken),
});| Method | Does | Needs |
|---|---|---|
prepare(release) | Builds the artifact and returns { artifact, inputs, deprecated }, where deprecated lists the deprecated scwrap-sdk.mjs names it imports. Uploads nothing. | Nothing |
readDeployments() | Reads the instance's generation and installed Releases. | HttpClient |
submit(command) | Sends one removal or rollback command and returns its status. A deployment command with an artifact is deprecated. | HttpClient |
deploy(release, command) | Deprecated: prepare, then submit once with the artifact (Client-built artifacts). | HttpClient |
build(request) | Sends a BuildRequest to the instance's POST /builds and reads GET /builds/<buildId> every 2 seconds, for up to 10 minutes, until the build ended and any deployment is active; returns the last BuildStatus. What scwrap check and scwrap deploy use. | HttpClient |
collectSource(module), also from @scwrap/deploy/client, reads a Release module and the local .ts files it imports into { entry, files } for a BuildRequest (What the CLI sends).
bundleRelease(module), also exported from @scwrap/deploy/client, is the bundling step of prepare on its own: it bundles the module whose default export is a Release against scwrap-sdk.mjs and returns { code, inputs }. The instance's builds bundle with it.
Example (Building a Release without deploying it)
import { createDeployer } from "@scwrap/deploy/client";
import { Console, Effect, Redacted } from "effect";
import QuotesRelease from "./quotes.ts";
const deployer = createDeployer({
instance: "https://scwrap.example.com",
token: Redacted.make("unused"),
});
const program = Effect.gen(function* inspect() {
const { artifact, inputs } = yield* deployer.prepare(QuotesRelease);
yield* Console.log(artifact.id, artifact.digest, artifact.code.length);
yield* Console.log(inputs);
});inputs lists every file that went into the bundle. It is the quickest way to see why a Release grew, or which dependency pulled in something unexpected.
Client-built artifacts
deploy, and submit with an artifact, upload an artifact your machine built. Both are deprecated since 0.10.0 and marked @deprecated in their types, and 0.11.0 removes them: the instance then installs only what it built and typechecked itself. Until then the instance still installs such an artifact and answers it with a Deprecation header (Client-built artifacts).
Deploy the source with build instead. collectSource reads a Release module and the local files it imports:
const source = yield* collectSource("./quotes.ts");
const status = yield* deployer.build({ ...source, deploy: true });build fails only when the instance cannot be reached or refuses the request; check status.status, which is failed with the compiler's output in diagnostics when the source does not typecheck.
You own the command
A removal or rollback command has three parts, and an optional fourth.
| Field | Meaning |
|---|---|
remove, rollback or rollbackPlatform | What to remove or roll back. |
deploymentId | An ID you generate for this deployment. |
expectedGeneration | The generation the instance must be at, from readDeployments(). null for an instance with nothing installed. |
force | Optional, true only. Stop the instance's active Runs before activating instead of letting them finish (Forcing a deploy). |
The deployer invents neither the ID nor the generation, and it never retries. That is on purpose: only the caller knows whether a second attempt is the same deployment or a new one.
Two rules follow:
- Repeat the same command when the outcome is unknown. The instance recognises the ID and answers with the saved result. A new ID would be a second deployment.
pendingis notactive. Send the same command again until the status isactive.
The CLI's journal exists to keep these two promises across process restarts. If you deploy from code, persist each command before you send it.
The protocol
@scwrap/deploy/protocol exports the schemas both sides decode with.
| Schema | Describes |
|---|---|
Artifact | A built Release: id, revision, code, digest, the SDK and Effect versions. |
DeploymentCommand | artifact, deploymentId, expectedGeneration and an optional force. |
RemovalCommand | remove, the Scraper ID, plus deploymentId, expectedGeneration and an optional force. |
RollbackCommand | rollback, the Scraper ID, an optional revision, plus deploymentId, expectedGeneration and an optional force (scwrap rollback). |
PlatformRollbackCommand | rollbackPlatform, a platform digest or null for the previous platform, plus deploymentId, expectedGeneration and an optional force. Sent to /platform-deployments. |
Incompatibility | A Release a platform would break: id, revision, digest and the missing names. |
BuildRequest | What POST /builds takes: files, an optional entry, deploy and force. |
BuildStatus | What a build answers: buildId, status, diagnostics, and optional scraper and deployment. |
DeploymentStatus | deploymentId, status (pending or active), generation, optional versionId. |
DeploymentState | What GET /deployments?include=isolation,runs answers: activeRuns, one { scraper, count } per Scraper with running Runs, generation, releases with each one's isolation, platformDigest, pendingDeploymentId. |
ReleaseIdentity | id, revision, digest, and an optional isolation. |
DeploymentFailure | The error every deployer method fails with. |
It also exports digest, the SHA-256 function used for artifacts; sharedImportsOf, sharedExportsOf and missingSharedImports, which read the names a built module imports from and exports to scwrap-sdk.mjs; and the constants sdkVersion, effectVersion and sharedModule.
Decode uploads with { onExcessProperty: "error" }. Unknown fields are rejected, and so is a Node artifact with code but no digest.
A generation is an opaque 64-character hexadecimal value the instance computes. Clients compare it and never calculate it.
Safety
createDeployer refuses to send the token anywhere it should not go:
- The token is a
Redactedvalue, so it does not print in logs or errors. - The instance must be an HTTPS URL without credentials, query string or fragment.
- Redirects are errors, not followed.
- The token is sent only to
<instance>/deployments,<instance>/platform-deploymentsfor a platform rollback,<instance>/buildsand<instance>/secrets/<name>.
Source
- client.ts:
createDeployer - protocol.ts: the schemas
- Deployment service: the other side of this API