Streaming
Stream a deployment's build answers with Server-Sent Events: the build's steps and log lines as they happen. It's what hiraiship deploy prints while you wait.
Events
Each event has a name and a JSON data line, and a log event an id too:
| Event | When | data |
|---|---|---|
status | While the deployment waits, and when it leaves the queue. | status, queuePosition (1 is next), startedAt, queueReason (plan_limit or capacity, see Build queue) |
step | A step starts or ends: preparing, installing, building, packaging. | step, status (running, success, failed), startedAt, finishedAt |
log | A line of the build's output. | id, step, stream (stdout or stderr), message, timestamp |
done | The deployment succeeded or failed. The stream closes after it. | status, dispatchStatus (live once it serves traffic), publishDurationMs |
A new connection replays everything recorded so far, then continues live: you never miss the start of a build by connecting late.
While nothing happens, for example during a long install, the stream sends a comment line every 15 seconds so that proxies keep the connection open. Comments start with : and carry no event; skip them.
Reconnecting
To pick up where a dropped connection left off, send the id of the last log line you received as Last-Event-ID. The stream sends the steps and the queue status again, then only the log lines after that id. The browser's EventSource does this on its own when it reconnects.
From Node.js
The browser's EventSource can't send an Authorization header, so read the stream with fetch:
Without a stream
If your client can't hold a connection open, poll Get a deployment until status is success or failed, and Get a deployment's build steps for the steps. A few seconds between calls is plenty.