|
| 1 | +[← Back to index](./index.md) |
| 2 | + |
| 3 | +# Getting Started |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### npm |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install @openstatus/sdk-node |
| 11 | +``` |
| 12 | + |
| 13 | +### JSR |
| 14 | + |
| 15 | +```bash |
| 16 | +npx jsr add @openstatus/sdk-node |
| 17 | +``` |
| 18 | + |
| 19 | +### Deno |
| 20 | + |
| 21 | +```typescript |
| 22 | +import { createOpenStatusClient } from "jsr:@openstatus/sdk-node"; |
| 23 | +``` |
| 24 | + |
| 25 | +### Bun |
| 26 | + |
| 27 | +```bash |
| 28 | +bun add @openstatus/sdk-node |
| 29 | +``` |
| 30 | + |
| 31 | +## Quick Start |
| 32 | + |
| 33 | +```typescript |
| 34 | +import { |
| 35 | + createOpenStatusClient, |
| 36 | + Periodicity, |
| 37 | + Region, |
| 38 | +} from "@openstatus/sdk-node"; |
| 39 | + |
| 40 | +const client = createOpenStatusClient({ |
| 41 | + apiKey: process.env.OPENSTATUS_API_KEY, |
| 42 | +}); |
| 43 | + |
| 44 | +// Create an HTTP monitor |
| 45 | +const { monitor } = await client.monitor.v1.MonitorService.createHTTPMonitor({ |
| 46 | + monitor: { |
| 47 | + name: "My API", |
| 48 | + url: "https://api.example.com/health", |
| 49 | + periodicity: Periodicity.PERIODICITY_1M, |
| 50 | + regions: [Region.FLY_AMS, Region.FLY_IAD, Region.FLY_SYD], |
| 51 | + active: true, |
| 52 | + }, |
| 53 | +}); |
| 54 | + |
| 55 | +console.log(`Monitor created: ${monitor?.id}`); |
| 56 | + |
| 57 | +// List all monitors |
| 58 | +const { httpMonitors, tcpMonitors, dnsMonitors, totalSize } = |
| 59 | + await client.monitor.v1.MonitorService.listMonitors({}); |
| 60 | + |
| 61 | +console.log(`Found ${totalSize} monitors`); |
| 62 | +``` |
| 63 | + |
| 64 | +## Runtime Support |
| 65 | + |
| 66 | +| Runtime | Version | Module Format | |
| 67 | +|---------|---------|---------------| |
| 68 | +| Node.js | >= 18 | ESM and CJS | |
| 69 | +| Deno | >= 2 | ESM (native) | |
| 70 | +| Bun | Latest | ESM | |
| 71 | + |
| 72 | +## Full Workflow Example |
| 73 | + |
| 74 | +A complete example: create a monitor, set up a status page, add the monitor as a component, configure a Slack notification, and check overall status. |
| 75 | + |
| 76 | +```typescript |
| 77 | +import { |
| 78 | + createOpenStatusClient, |
| 79 | + NotificationProvider, |
| 80 | + Periodicity, |
| 81 | + Region, |
| 82 | +} from "@openstatus/sdk-node"; |
| 83 | + |
| 84 | +const client = createOpenStatusClient({ |
| 85 | + apiKey: process.env.OPENSTATUS_API_KEY, |
| 86 | +}); |
| 87 | + |
| 88 | +// 1. Check API health |
| 89 | +const health = await client.health.v1.HealthService.check({}); |
| 90 | +console.log(`API status: ${health.status}`); |
| 91 | + |
| 92 | +// 2. Create an HTTP monitor |
| 93 | +const { monitor } = await client.monitor.v1.MonitorService.createHTTPMonitor({ |
| 94 | + monitor: { |
| 95 | + name: "Production API", |
| 96 | + url: "https://api.example.com/health", |
| 97 | + periodicity: Periodicity.PERIODICITY_1M, |
| 98 | + regions: [Region.FLY_AMS, Region.FLY_IAD, Region.FLY_SYD], |
| 99 | + active: true, |
| 100 | + }, |
| 101 | +}); |
| 102 | + |
| 103 | +// 3. Create a status page |
| 104 | +const { statusPage } = await client.statusPage.v1.StatusPageService |
| 105 | + .createStatusPage({ |
| 106 | + title: "Example Status", |
| 107 | + slug: "example-status", |
| 108 | + description: "Status page for Example services", |
| 109 | + }); |
| 110 | + |
| 111 | +// 4. Add the monitor as a component |
| 112 | +const { component } = await client.statusPage.v1.StatusPageService |
| 113 | + .addMonitorComponent({ |
| 114 | + pageId: statusPage!.id, |
| 115 | + monitorId: monitor!.id, |
| 116 | + name: "Production API", |
| 117 | + }); |
| 118 | + |
| 119 | +// 5. Set up Slack notifications |
| 120 | +const { notification } = await client.notification.v1.NotificationService |
| 121 | + .createNotification({ |
| 122 | + name: "Slack Alerts", |
| 123 | + provider: NotificationProvider.SLACK, |
| 124 | + data: { |
| 125 | + data: { |
| 126 | + case: "slack", |
| 127 | + value: { webhookUrl: "https://hooks.slack.com/services/..." }, |
| 128 | + }, |
| 129 | + }, |
| 130 | + monitorIds: [monitor!.id], |
| 131 | + }); |
| 132 | + |
| 133 | +// 6. Check overall status |
| 134 | +const { overallStatus } = await client.statusPage.v1.StatusPageService |
| 135 | + .getOverallStatus({ |
| 136 | + identifier: { case: "id", value: statusPage!.id }, |
| 137 | + }); |
| 138 | + |
| 139 | +console.log(`Overall status: ${overallStatus}`); |
| 140 | +``` |
0 commit comments