@repose-sh/sdk
v0.1.1
Published
TypeScript client for the Repose REST API. Dependency-free.
Maintainers
Readme
@repose-sh/sdk
TypeScript client for the Repose REST API. One file, no dependencies, global fetch.
Install
npm install @repose-sh/sdkNode 20 or newer. ESM only. Published from packages/sdk in the Repose repo.
Getting a token
Settings → API tokens in the app. Tokens are workspace-scoped and look like rsk_….
A read token can list monitors and incidents. Creating, updating, deleting and
acknowledging need a read-write token.
Usage
import { Repose, ReposeError } from "@repose-sh/sdk";
const repose = new Repose({ token: process.env.REPOSE_TOKEN! });
// what are we watching
const monitors = await repose.listMonitors();
for (const m of monitors) {
console.log(`${m.name} — every ${m.intervalSeconds}s, ${m.consensusRequired} probes must agree`);
}
// add a check
const created = await repose.createMonitor({
name: "checkout",
kind: "http",
url: "https://checkout.acme.com/health",
intervalSeconds: 30,
consensusRequired: 3,
});
// slow it down
await repose.updateMonitor(created.id, { intervalSeconds: 60 });
// who is on fire right now
const open = await repose.listIncidents({ status: "open" });
if (open[0]) await repose.acknowledgeIncident(open[0].id);Errors that came from the API are ReposeError with the status and the API's own
message — no wrapping, no re-phrasing:
try {
await repose.deleteMonitor("mon_nope");
} catch (error) {
if (error instanceof ReposeError) {
console.error(error.status, error.message); // 404 monitor not found
}
}status is 0 when the request never reached the API at all (DNS, TLS, connection
refused, wrong baseUrl).
Methods
| method | endpoint | token |
| --- | --- | --- |
| listMonitors() | GET /api/v1/monitors | read |
| getMonitor(id) | — see below | read |
| createMonitor(input) | POST /api/v1/monitors | write |
| updateMonitor(id, patch) | PATCH /api/v1/monitors/:id | write |
| deleteMonitor(id) | DELETE /api/v1/monitors/:id | write |
| listIncidents(options?) | GET /api/v1/incidents | read |
| acknowledgeIncident(id) | POST /api/v1/incidents/:id/acknowledge | write |
Two things the API can't do yet, and what we do instead
- There is no
GET /api/v1/monitors/:id.getMonitor(id)lists the workspace and filters client-side. It returns the right answer; it just costs a full list. If you need several, calllistMonitors()once and index it yourself. - The incidents endpoint has no filters. It returns the 100 most recent incidents,
newest first.
listIncidents({ status: "open" })filters those 100 after they arrive, so a workspace with more than 100 recent incidents can have older open ones this doesn't return.
Also worth knowing before you write a sync loop:
- The monitor list doesn't return
timeoutMsorexpectedStatus, so you can't read back what you wrote for those two. updateMonitorcan't change a monitor'skind,url,hostorport. Delete and recreate to move a target.deleteMonitoris a soft delete. Checks stop; history stays.- Acknowledging an incident quiets the page. It does not resolve it — the probes decide when something is healthy again.
Options
new Repose({
token: "rsk_…",
baseUrl: "http://localhost:3000", // default https://repose.sh
fetch: myFetch, // default globalThis.fetch
});