Files
dcrouter/ts_apiclient/readme.md

5.5 KiB

@serve.zone/dcrouter-apiclient

Typed, object-oriented API client for operating a running dcrouter instance. 🔧

Use this package when you want a clean TypeScript client instead of manually firing TypedRequest calls. It wraps the OpsServer API in resource managers and resource classes such as routes, certificates, tokens, edges, emails, stats, logs, config, and RADIUS.

Issue Reporting and Security

For reporting bugs, issues, or security vulnerabilities, please visit community.foss.global/. This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a code.foss.global/ account to submit Pull Requests directly.

Installation

pnpm add @serve.zone/dcrouter-apiclient

Or import through the main package:

import { DcRouterApiClient } from '@serve.zone/dcrouter/apiclient';

Quick Start

import { DcRouterApiClient } from '@serve.zone/dcrouter-apiclient';

const client = new DcRouterApiClient({
  baseUrl: 'https://dcrouter.example.com',
});

await client.login('admin', 'password');

const { routes } = await client.routes.list();
console.log(routes.map((route) => `${route.origin}:${route.name}`));

await client.routes.build()
  .setName('api-gateway')
  .setMatch({ ports: 443, domains: ['api.example.com'] })
  .setAction({ type: 'forward', targets: [{ host: '127.0.0.1', port: 8080 }] })
  .save();

Authentication Modes

Mode How it works
Admin login Call login(username, password) and the client stores the returned identity for later requests
API token Pass apiToken into the constructor for token-based automation
const client = new DcRouterApiClient({
  baseUrl: 'https://dcrouter.example.com',
  apiToken: 'dcr_your_token_here',
});

Main Managers

Manager Purpose
client.routes List routes and create API-managed routes
client.certificates Inspect and operate on certificate records
client.apiTokens Create, list, toggle, roll, revoke API tokens
client.remoteIngress Manage registered remote ingress edges
client.stats Read operational metrics and health data
client.config Read current configuration view
client.logs Read recent logs or stream them
client.emails List emails and trigger resend flows
client.radius Operate on RADIUS clients, VLANs, sessions, and accounting

Route Behavior

Routes are returned as Route instances with:

  • id
  • name
  • enabled
  • origin

Important behavior:

  • API routes can be created, updated, deleted, and toggled.
  • System routes can be listed and toggled, but not edited or deleted.
  • A system route is any route whose origin !== 'api'.
const { routes } = await client.routes.list();

for (const route of routes) {
  if (route.origin !== 'api') {
    await route.toggle(false);
  }
}

Builder Example

const route = await client.routes.build()
  .setName('internal-app')
  .setMatch({
    ports: 80,
    domains: ['internal.example.com'],
  })
  .setAction({
    type: 'forward',
    targets: [{ host: '127.0.0.1', port: 3000 }],
  })
  .setEnabled(true)
  .save();

await route.toggle(false);

Example: Certificates and Stats

const { certificates, summary } = await client.certificates.list();
console.log(summary.valid, summary.failed);

const health = await client.stats.getHealth();
const recentLogs = await client.logs.getRecent({ level: 'error', limit: 20 });

What This Package Does Not Do

  • It does not start dcrouter.
  • It does not embed the dashboard.
  • It does not replace the request interfaces package if you only need raw types.

Use @serve.zone/dcrouter to run the server, @serve.zone/dcrouter-web for the dashboard bundle/components, and @serve.zone/dcrouter-interfaces for raw API contracts.

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the license file.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

Company Information

Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.