@devhelm/sdk 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +182 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # DevHelm JavaScript / TypeScript SDK
2
+
3
+ Typed JavaScript / TypeScript client for the [DevHelm](https://devhelm.io) monitoring API — monitors, incidents, alerting, and more. Works in Node.js 18+ and modern bundlers; ships with full TypeScript types.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @devhelm/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import {Devhelm} from '@devhelm/sdk'
15
+
16
+ const client = new Devhelm({
17
+ token: 'your-api-token',
18
+ orgId: 'your-org-id',
19
+ workspaceId: 'your-workspace-id',
20
+ })
21
+
22
+ // List all monitors
23
+ const monitors = await client.monitors.list()
24
+ for (const m of monitors) {
25
+ console.log(`${m.name} — ${m.type}`)
26
+ }
27
+
28
+ // Create a monitor
29
+ const monitor = await client.monitors.create({
30
+ name: 'My API Health',
31
+ type: 'HTTP',
32
+ config: {url: 'https://api.example.com/health', method: 'GET'},
33
+ frequencySeconds: 60,
34
+ regions: ['us-east'],
35
+ // `managedBy` records who reconciles drift. `DASHBOARD` (default) means
36
+ // "no reconciliation" — the right answer for one-off scripts and most
37
+ // SDK use. Use `CLI` if this monitor lives in a `devhelm.yml` you
38
+ // re-deploy, or `TERRAFORM` if it lives in `.tf` you re-apply.
39
+ managedBy: 'DASHBOARD',
40
+ })
41
+
42
+ // Get a single monitor
43
+ const fetched = await client.monitors.get(monitor.id)
44
+
45
+ // Pause / resume
46
+ await client.monitors.pause(monitor.id)
47
+ await client.monitors.resume(monitor.id)
48
+
49
+ // Delete
50
+ await client.monitors.delete(monitor.id)
51
+ ```
52
+
53
+ ## Configuration
54
+
55
+ ```ts
56
+ import {Devhelm} from '@devhelm/sdk'
57
+
58
+ const client = new Devhelm({
59
+ token: 'your-api-token', // required (or DEVHELM_API_TOKEN env var)
60
+ orgId: '1', // optional (or DEVHELM_ORG_ID; defaults to '1')
61
+ workspaceId: '1', // optional (or DEVHELM_WORKSPACE_ID; defaults to '1')
62
+ baseUrl: 'https://api.devhelm.io', // optional, defaults to production
63
+ })
64
+ ```
65
+
66
+ Environment variables are used as fallbacks when constructor arguments are not provided:
67
+
68
+ | Parameter | Env Variable |
69
+ | ------------- | ---------------------- |
70
+ | `token` | `DEVHELM_API_TOKEN` |
71
+ | `orgId` | `DEVHELM_ORG_ID` |
72
+ | `workspaceId` | `DEVHELM_WORKSPACE_ID` |
73
+
74
+ ## Resources
75
+
76
+ The client exposes the following resource modules:
77
+
78
+ | Resource | Description |
79
+ | ------------------------------ | ---------------------------------------------------------- |
80
+ | `client.monitors` | HTTP, DNS, TCP, ICMP, MCP, and Heartbeat monitors |
81
+ | `client.incidents` | Manual and auto-detected incidents |
82
+ | `client.forensics` | Per-monitor rule evaluations, transitions, and policy snapshots |
83
+ | `client.alertChannels` | Slack, email, webhook, and other alert channels |
84
+ | `client.notificationPolicies` | Routing rules for alerts |
85
+ | `client.environments` | Environment grouping (prod, staging, etc.) |
86
+ | `client.secrets` | Encrypted secrets for monitor auth |
87
+ | `client.tags` | Organize monitors with tags |
88
+ | `client.resourceGroups` | Logical resource groups |
89
+ | `client.webhooks` | Outgoing webhook endpoints |
90
+ | `client.apiKeys` | API key management |
91
+ | `client.dependencies` | Service dependency tracking |
92
+ | `client.deployLock` | Deploy lock for safe deployments |
93
+ | `client.statusPages` | Public status page management |
94
+ | `client.status` | Dashboard overview |
95
+
96
+ ## Pagination
97
+
98
+ List methods auto-paginate by default. For manual page control:
99
+
100
+ ```ts
101
+ // Auto-paginate (fetches all pages)
102
+ const allMonitors = await client.monitors.list()
103
+
104
+ // Manual page control
105
+ const page = await client.monitors.listPage(0, 20)
106
+ console.log(page.data) // array of monitors
107
+ console.log(page.hasNext) // true if more pages
108
+ console.log(page.hasPrev) // true if previous page exists
109
+
110
+ // Cursor pagination (for check results)
111
+ const results = await client.monitors.results(monitorId, {limit: 50})
112
+ console.log(results.data)
113
+ console.log(results.nextCursor)
114
+ console.log(results.hasMore)
115
+ ```
116
+
117
+ ## Error Handling
118
+
119
+ The SDK raises three top-level error types:
120
+
121
+ - `DevhelmValidationError` — local request/response shape validation failed.
122
+ - `DevhelmApiError` — the API returned a non-2xx status. Subclassed by HTTP class for ergonomics:
123
+ - `DevhelmAuthError` (401/403)
124
+ - `DevhelmNotFoundError` (404)
125
+ - `DevhelmConflictError` (409)
126
+ - `DevhelmRateLimitError` (429)
127
+ - `DevhelmServerError` (5xx)
128
+ - `DevhelmTransportError` — the request never reached a server response (connection refused, timeout, TLS failure, etc.).
129
+
130
+ Every `DevhelmApiError` carries:
131
+
132
+ - `status` — the HTTP status code
133
+ - `code` — coarse machine-readable category (e.g. `NOT_FOUND`, `RATE_LIMITED`); switch on this, not the human-readable `message`
134
+ - `requestId` — the per-request id from the `X-Request-Id` response header; always include this in support tickets
135
+
136
+ ```ts
137
+ import {Devhelm, DevhelmAuthError, DevhelmError} from '@devhelm/sdk'
138
+
139
+ const client = new Devhelm({token: 'bad-token', orgId: '1', workspaceId: '1'})
140
+
141
+ try {
142
+ await client.monitors.list()
143
+ } catch (e) {
144
+ if (e instanceof DevhelmAuthError) {
145
+ console.log(`Auth failed: ${e.message} (HTTP ${e.status}, requestId=${e.requestId})`)
146
+ } else if (e instanceof DevhelmError) {
147
+ console.log(`API error [${e.code}]: ${e.message}`)
148
+ } else {
149
+ throw e
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## TypeScript
155
+
156
+ All resource methods return strongly-typed responses. DTOs are re-exported from the package root:
157
+
158
+ ```ts
159
+ import {
160
+ Devhelm,
161
+ type MonitorDto,
162
+ type IncidentDto,
163
+ type CreateMonitorRequest,
164
+ } from '@devhelm/sdk'
165
+
166
+ const client = new Devhelm({token: process.env.DEVHELM_API_TOKEN!})
167
+ const monitors: MonitorDto[] = await client.monitors.list()
168
+ ```
169
+
170
+ Strict-mode TypeScript and ESM are first-class — the package ships ESM-only with named `exports` map.
171
+
172
+ ## Compatibility
173
+
174
+ - Node.js ≥ 18 (uses native `fetch`)
175
+ - Browser bundlers (Vite, Webpack, esbuild, Rollup) — works with the same ESM build
176
+ - Cloudflare Workers — works (uses native `fetch`)
177
+
178
+ The client sends `X-DevHelm-Surface: sdk-js` and `X-DevHelm-Surface-Version: <package version>` on every request so the API can attribute traffic and warn you if your version is end-of-life. See [Surface Support Policy](https://devhelm.io/surfaces/support).
179
+
180
+ ## License
181
+
182
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devhelm/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "DevHelm SDK for TypeScript and JavaScript — typed client for monitors, incidents, alerting, and more",
5
5
  "author": "DevHelm <hello@devhelm.io>",
6
6
  "license": "MIT",