Files
dcrouter/ts_apiclient/readme.md
T

162 lines
6.2 KiB
Markdown
Raw Normal View History

# @serve.zone/dcrouter-apiclient
2026-05-07 20:22:12 +00:00
`@serve.zone/dcrouter-apiclient` is the object-oriented TypeScript client for the dcrouter OpsServer API. It wraps `/typedrequest` calls in managers, builders, and resource classes for routes, certificates, API tokens, remote ingress, email, stats, config, logs, RADIUS, and WorkHoster integrations.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://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/](https://code.foss.global/) account to submit Pull Requests directly.
2026-05-07 20:22:12 +00:00
## Install
```bash
pnpm add @serve.zone/dcrouter-apiclient
```
2026-05-07 20:22:12 +00:00
The same client is also exposed as a subpath of the main package:
```typescript
import { DcRouterApiClient } from '@serve.zone/dcrouter/apiclient';
```
## Quick Start
```typescript
import { DcRouterApiClient } from '@serve.zone/dcrouter-apiclient';
const client = new DcRouterApiClient({
baseUrl: 'https://dcrouter.example.com',
});
await client.login('admin', 'admin');
const { routes, warnings } = await client.routes.list();
2026-05-07 20:22:12 +00:00
console.log(routes.length, warnings.length);
const route = 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();
2026-05-07 20:22:12 +00:00
await route.toggle(true);
```
2026-05-07 20:22:12 +00:00
## Authentication
2026-05-07 20:22:12 +00:00
The client supports session login and API-token authentication.
```typescript
2026-05-07 20:22:12 +00:00
const sessionClient = new DcRouterApiClient({
baseUrl: 'https://dcrouter.example.com',
2026-05-07 20:22:12 +00:00
});
await sessionClient.login('admin', 'admin');
const tokenClient = new DcRouterApiClient({
baseUrl: 'https://dcrouter.example.com',
apiToken: 'dcr_token_value',
});
```
2026-05-07 20:22:12 +00:00
`baseUrl` is normalized by removing trailing slashes. Requests are sent to `${baseUrl}/typedrequest`. `buildRequestPayload()` injects the current identity and optional API token for manager methods.
2026-05-07 20:22:12 +00:00
## Manager Map
2026-05-07 20:22:12 +00:00
| Manager | Purpose |
| --- | --- |
| `client.routes` | List merged routes, build API routes, update/delete API routes, and toggle routes. |
| `client.certificates` | Inspect certificate summaries and trigger certificate operations. |
| `client.apiTokens` | Create, list, toggle, roll, and revoke API tokens. |
| `client.remoteIngress` | Manage edge registrations, statuses, ports, tags, and connection tokens. |
| `client.emails` | Inspect received/cached email items and trigger resend flows. |
| `client.workHosters` | Manage WorkHoster-facing route/application integration calls. |
| `client.stats` | Read health, counters, summaries, and runtime status. |
| `client.config` | Read the current configuration view. |
| `client.logs` | Read recent log information. |
| `client.radius` | Manage RADIUS clients, VLAN mappings, and accounting sessions. |
## Route Builder
```typescript
2026-05-07 20:22:12 +00:00
const route = await client.routes.build()
.setName('internal-app')
.setMatch({
ports: 443,
domains: ['internal.example.com'],
})
.setAction({
type: 'forward',
targets: [{ host: '127.0.0.1', port: 3000 }],
})
.setEnabled(true)
.save();
2026-05-07 20:22:12 +00:00
await route.update({
action: {
type: 'forward',
targets: [{ host: '127.0.0.1', port: 3001 }],
},
});
```
2026-05-07 20:22:12 +00:00
System routes from `config`, `email`, and `dns` origins are designed to be toggled, not edited. Full create/update/delete behavior is for routes with origin `api`.
## API Tokens and Remote Ingress
```typescript
const token = await client.apiTokens.build()
2026-05-07 20:22:12 +00:00
.setName('automation')
.setScopes(['routes:read', 'routes:write'])
.setExpiresInDays(30)
.save();
const edge = await client.remoteIngress.build()
.setName('edge-eu-1')
.setListenPorts([80, 443])
.setAutoDerivePorts(true)
.setTags(['production', 'eu'])
.save();
const connectionToken = await edge.getConnectionToken();
2026-05-07 20:22:12 +00:00
console.log(token.tokenValue, connectionToken);
```
2026-05-07 20:22:12 +00:00
## What This Package Is Not
- It does not start dcrouter.
2026-05-07 20:22:12 +00:00
- It does not serve or bundle the Ops dashboard.
- It does not replace `@serve.zone/dcrouter-interfaces` when you want raw TypedRequest contracts.
Use `@serve.zone/dcrouter` for the server runtime and `@serve.zone/dcrouter-interfaces` for shared request/data types.
## Development
This folder is published from the dcrouter monorepo via `tspublish.json` with order `5`.
Useful source entry points:
2026-05-07 20:22:12 +00:00
- `index.ts` exports the public client surface.
- `classes.dcrouterapiclient.ts` owns authentication and request dispatch.
- `classes.route.ts` owns route resources and builders.
- `classes.remoteingress.ts`, `classes.apitoken.ts`, `classes.radius.ts`, and the other manager files wrap focused API domains.
## License and Legal Information
2026-05-07 20:22:12 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../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
2026-05-07 20:22:12 +00:00
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.