Skip to content

oack-io/oack-node

Repository files navigation

npm version CI TypeScript Node.js License: MPL-2.0

oack-node

Official Node.js client for the Oack monitoring API.

Installation

npm install oack-node

Quick Start

import { Oack } from "oack-node";

const client = new Oack({ apiKey: "sk-..." });

const teams = await client.teams.list();
for (const team of teams) {
  console.log(team.id, team.name);
}

Configuration

const client = new Oack({
  apiKey: "sk-...",
  baseUrl: "https://api.oack.io", // default
  timeout: 30_000,                 // ms, default
  maxRetries: 2,                   // default
});

// Dynamic token (e.g. refreshable JWT)
const client = new Oack({
  apiKey: () => getCurrentJwt(),
});

Browser Login (Device Flow)

Authenticate via browser instead of a static API key. The JWT lives only in memory and disappears when the program exits.

import { deviceFlowAuthenticate, Oack } from "oack-node";

// Opens your browser, waits for approval, returns JWT
const token = await deviceFlowAuthenticate();

const client = new Oack({ apiKey: token });
const teams = await client.teams.list();

Error Handling

import { Oack, NotFoundError, RateLimitError, APIError } from "oack-node";

try {
  const monitor = await client.monitors.get(teamId, monitorId);
} catch (err) {
  if (err instanceof NotFoundError) {
    console.log("Monitor not found");
  } else if (err instanceof RateLimitError) {
    console.log(`Retry after ${err.retryAfter}s`);
  } else if (err instanceof APIError) {
    console.log(`API error ${err.statusCode}: ${err.message}`);
  }
}

Resources

Resource Access Key Methods
Accounts client.accounts create, list, get, update, delete, restore, transfer
Teams client.teams create, list, get, update, delete, listMembers, addMember
Monitors client.monitors create, list, get, update, delete, pause, unpause, duplicate, move
Probes client.probes list, get, getDetails, downloadPcap, aggregate
Alert Channels client.alertChannels create, list, get, update, delete, test
Metrics client.metrics getMonitorMetrics, getExpiration, listTimeline, chart events
Geo client.geo listCheckers, listRegions

Types

All types are exported and provide full TypeScript inference:

import type { Monitor, Team, Probe, CreateMonitorParams } from "oack-node";