@serve.zone/dcrouter-apiclient 32.3.0
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.
- package/dist_ts_apiclient/classes.apitoken.d.ts +41 -0
- package/dist_ts_apiclient/classes.apitoken.js +115 -0
- package/dist_ts_apiclient/classes.certificate.d.ts +57 -0
- package/dist_ts_apiclient/classes.certificate.js +69 -0
- package/dist_ts_apiclient/classes.config.d.ts +7 -0
- package/dist_ts_apiclient/classes.config.js +11 -0
- package/dist_ts_apiclient/classes.dcrouterapiclient.d.ts +54 -0
- package/dist_ts_apiclient/classes.dcrouterapiclient.js +97 -0
- package/dist_ts_apiclient/classes.email.d.ts +30 -0
- package/dist_ts_apiclient/classes.email.js +52 -0
- package/dist_ts_apiclient/classes.gatewayclient.d.ts +28 -0
- package/dist_ts_apiclient/classes.gatewayclient.js +52 -0
- package/dist_ts_apiclient/classes.logs.d.ts +28 -0
- package/dist_ts_apiclient/classes.logs.js +69 -0
- package/dist_ts_apiclient/classes.radius.d.ts +59 -0
- package/dist_ts_apiclient/classes.radius.js +95 -0
- package/dist_ts_apiclient/classes.remoteingress.d.ts +66 -0
- package/dist_ts_apiclient/classes.remoteingress.js +164 -0
- package/dist_ts_apiclient/classes.route.d.ts +39 -0
- package/dist_ts_apiclient/classes.route.js +125 -0
- package/dist_ts_apiclient/classes.stats.d.ts +47 -0
- package/dist_ts_apiclient/classes.stats.js +38 -0
- package/dist_ts_apiclient/classes.testing.d.ts +65 -0
- package/dist_ts_apiclient/classes.testing.js +120 -0
- package/dist_ts_apiclient/index.d.ts +12 -0
- package/dist_ts_apiclient/index.js +16 -0
- package/dist_ts_apiclient/plugins.d.ts +4 -0
- package/dist_ts_apiclient/plugins.js +6 -0
- package/dist_ts_interfaces/data/acme-config.d.ts +23 -0
- package/dist_ts_interfaces/data/acme-config.js +2 -0
- package/dist_ts_interfaces/data/auth.d.ts +8 -0
- package/dist_ts_interfaces/data/auth.js +2 -0
- package/dist_ts_interfaces/data/config-events.d.ts +34 -0
- package/dist_ts_interfaces/data/config-events.js +8 -0
- package/dist_ts_interfaces/data/dns-authority.d.ts +98 -0
- package/dist_ts_interfaces/data/dns-authority.js +26 -0
- package/dist_ts_interfaces/data/dns-provider.d.ts +136 -0
- package/dist_ts_interfaces/data/dns-provider.js +41 -0
- package/dist_ts_interfaces/data/dns-record.d.ts +48 -0
- package/dist_ts_interfaces/data/dns-record.js +2 -0
- package/dist_ts_interfaces/data/domain.d.ts +35 -0
- package/dist_ts_interfaces/data/domain.js +2 -0
- package/dist_ts_interfaces/data/email-domain.d.ts +177 -0
- package/dist_ts_interfaces/data/email-domain.js +2 -0
- package/dist_ts_interfaces/data/email-settings.d.ts +68 -0
- package/dist_ts_interfaces/data/email-settings.js +2 -0
- package/dist_ts_interfaces/data/index.d.ts +18 -0
- package/dist_ts_interfaces/data/index.js +19 -0
- package/dist_ts_interfaces/data/remoteingress.d.ts +181 -0
- package/dist_ts_interfaces/data/remoteingress.js +15 -0
- package/dist_ts_interfaces/data/route-management.d.ts +270 -0
- package/dist_ts_interfaces/data/route-management.js +130 -0
- package/dist_ts_interfaces/data/security-policy.d.ts +32 -0
- package/dist_ts_interfaces/data/security-policy.js +2 -0
- package/dist_ts_interfaces/data/smtp-account.d.ts +50 -0
- package/dist_ts_interfaces/data/smtp-account.js +9 -0
- package/dist_ts_interfaces/data/stats.d.ts +283 -0
- package/dist_ts_interfaces/data/stats.js +2 -0
- package/dist_ts_interfaces/data/target-profile.d.ts +30 -0
- package/dist_ts_interfaces/data/target-profile.js +2 -0
- package/dist_ts_interfaces/data/testing.d.ts +191 -0
- package/dist_ts_interfaces/data/testing.js +20 -0
- package/dist_ts_interfaces/data/vpn.d.ts +65 -0
- package/dist_ts_interfaces/data/vpn.js +2 -0
- package/dist_ts_interfaces/data/workhoster.d.ts +63 -0
- package/dist_ts_interfaces/data/workhoster.js +2 -0
- package/dist_ts_interfaces/index.d.ts +5 -0
- package/dist_ts_interfaces/index.js +8 -0
- package/dist_ts_interfaces/plugins.d.ts +2 -0
- package/dist_ts_interfaces/plugins.js +4 -0
- package/dist_ts_interfaces/requests/acme-config.d.ts +42 -0
- package/dist_ts_interfaces/requests/acme-config.js +2 -0
- package/dist_ts_interfaces/requests/admin.d.ts +69 -0
- package/dist_ts_interfaces/requests/admin.js +3 -0
- package/dist_ts_interfaces/requests/api-tokens.d.ts +85 -0
- package/dist_ts_interfaces/requests/api-tokens.js +2 -0
- package/dist_ts_interfaces/requests/certificate.d.ts +87 -0
- package/dist_ts_interfaces/requests/certificate.js +5 -0
- package/dist_ts_interfaces/requests/combined.stats.d.ts +29 -0
- package/dist_ts_interfaces/requests/combined.stats.js +2 -0
- package/dist_ts_interfaces/requests/config-events.d.ts +35 -0
- package/dist_ts_interfaces/requests/config-events.js +4 -0
- package/dist_ts_interfaces/requests/config.d.ts +93 -0
- package/dist_ts_interfaces/requests/config.js +3 -0
- package/dist_ts_interfaces/requests/dns-authority.d.ts +80 -0
- package/dist_ts_interfaces/requests/dns-authority.js +3 -0
- package/dist_ts_interfaces/requests/dns-providers.d.ts +117 -0
- package/dist_ts_interfaces/requests/dns-providers.js +2 -0
- package/dist_ts_interfaces/requests/dns-records.d.ts +89 -0
- package/dist_ts_interfaces/requests/dns-records.js +2 -0
- package/dist_ts_interfaces/requests/domains.d.ts +142 -0
- package/dist_ts_interfaces/requests/domains.js +2 -0
- package/dist_ts_interfaces/requests/email-domains.d.ts +154 -0
- package/dist_ts_interfaces/requests/email-domains.js +2 -0
- package/dist_ts_interfaces/requests/email-ops.d.ts +211 -0
- package/dist_ts_interfaces/requests/email-ops.js +3 -0
- package/dist_ts_interfaces/requests/email-settings.d.ts +26 -0
- package/dist_ts_interfaces/requests/email-settings.js +2 -0
- package/dist_ts_interfaces/requests/index.d.ts +29 -0
- package/dist_ts_interfaces/requests/index.js +30 -0
- package/dist_ts_interfaces/requests/logs.d.ts +43 -0
- package/dist_ts_interfaces/requests/logs.js +4 -0
- package/dist_ts_interfaces/requests/network-targets.d.ts +102 -0
- package/dist_ts_interfaces/requests/network-targets.js +2 -0
- package/dist_ts_interfaces/requests/radius.d.ts +280 -0
- package/dist_ts_interfaces/requests/radius.js +3 -0
- package/dist_ts_interfaces/requests/realtime.d.ts +38 -0
- package/dist_ts_interfaces/requests/realtime.js +12 -0
- package/dist_ts_interfaces/requests/remoteingress.d.ts +162 -0
- package/dist_ts_interfaces/requests/remoteingress.js +3 -0
- package/dist_ts_interfaces/requests/route-management.d.ts +147 -0
- package/dist_ts_interfaces/requests/route-management.js +2 -0
- package/dist_ts_interfaces/requests/security-policy.d.ts +105 -0
- package/dist_ts_interfaces/requests/security-policy.js +2 -0
- package/dist_ts_interfaces/requests/smtp-accounts.d.ts +125 -0
- package/dist_ts_interfaces/requests/smtp-accounts.js +2 -0
- package/dist_ts_interfaces/requests/source-profiles.d.ts +102 -0
- package/dist_ts_interfaces/requests/source-profiles.js +2 -0
- package/dist_ts_interfaces/requests/stats.d.ts +196 -0
- package/dist_ts_interfaces/requests/stats.js +4 -0
- package/dist_ts_interfaces/requests/target-profiles.d.ts +105 -0
- package/dist_ts_interfaces/requests/target-profiles.js +2 -0
- package/dist_ts_interfaces/requests/testing.d.ts +169 -0
- package/dist_ts_interfaces/requests/testing.js +2 -0
- package/dist_ts_interfaces/requests/users.d.ts +53 -0
- package/dist_ts_interfaces/requests/users.js +3 -0
- package/dist_ts_interfaces/requests/vpn.d.ts +188 -0
- package/dist_ts_interfaces/requests/vpn.js +3 -0
- package/dist_ts_interfaces/requests/workhoster.d.ts +79 -0
- package/dist_ts_interfaces/requests/workhoster.js +2 -0
- package/license +21 -0
- package/package.json +67 -0
- package/readme.md +218 -0
- package/ts_apiclient/classes.apitoken.ts +157 -0
- package/ts_apiclient/classes.certificate.ts +124 -0
- package/ts_apiclient/classes.config.ts +17 -0
- package/ts_apiclient/classes.dcrouterapiclient.ts +138 -0
- package/ts_apiclient/classes.email.ts +77 -0
- package/ts_apiclient/classes.gatewayclient.ts +110 -0
- package/ts_apiclient/classes.logs.ts +91 -0
- package/ts_apiclient/classes.radius.ts +180 -0
- package/ts_apiclient/classes.remoteingress.ts +217 -0
- package/ts_apiclient/classes.route.ts +166 -0
- package/ts_apiclient/classes.stats.ts +111 -0
- package/ts_apiclient/classes.testing.ts +152 -0
- package/ts_apiclient/index.ts +17 -0
- package/ts_apiclient/plugins.ts +10 -0
- package/ts_apiclient/readme.md +218 -0
- package/ts_interfaces/data/acme-config.ts +23 -0
- package/ts_interfaces/data/auth.ts +8 -0
- package/ts_interfaces/data/config-events.ts +38 -0
- package/ts_interfaces/data/dns-authority.ts +106 -0
- package/ts_interfaces/data/dns-provider.ts +174 -0
- package/ts_interfaces/data/dns-record.ts +50 -0
- package/ts_interfaces/data/domain.ts +36 -0
- package/ts_interfaces/data/email-domain.ts +206 -0
- package/ts_interfaces/data/email-settings.ts +75 -0
- package/ts_interfaces/data/index.ts +18 -0
- package/ts_interfaces/data/remoteingress.ts +204 -0
- package/ts_interfaces/data/route-management.ts +436 -0
- package/ts_interfaces/data/security-policy.ts +37 -0
- package/ts_interfaces/data/smtp-account.ts +63 -0
- package/ts_interfaces/data/stats.ts +305 -0
- package/ts_interfaces/data/target-profile.ts +31 -0
- package/ts_interfaces/data/testing.ts +184 -0
- package/ts_interfaces/data/vpn.ts +68 -0
- package/ts_interfaces/data/workhoster.ts +72 -0
- package/ts_interfaces/index.ts +9 -0
- package/ts_interfaces/plugins.ts +6 -0
- package/ts_interfaces/readme.md +194 -0
- package/ts_interfaces/requests/acme-config.ts +54 -0
- package/ts_interfaces/requests/admin.ts +96 -0
- package/ts_interfaces/requests/api-tokens.ts +109 -0
- package/ts_interfaces/requests/certificate.ts +106 -0
- package/ts_interfaces/requests/combined.stats.ts +30 -0
- package/ts_interfaces/requests/config-events.ts +45 -0
- package/ts_interfaces/requests/config.ts +94 -0
- package/ts_interfaces/requests/dns-authority.ts +104 -0
- package/ts_interfaces/requests/dns-providers.ts +154 -0
- package/ts_interfaces/requests/dns-records.ts +113 -0
- package/ts_interfaces/requests/domains.ts +178 -0
- package/ts_interfaces/requests/email-domains.ts +193 -0
- package/ts_interfaces/requests/email-ops.ts +266 -0
- package/ts_interfaces/requests/email-settings.ts +34 -0
- package/ts_interfaces/requests/index.ts +29 -0
- package/ts_interfaces/requests/logs.ts +58 -0
- package/ts_interfaces/requests/network-targets.ts +127 -0
- package/ts_interfaces/requests/radius.ts +341 -0
- package/ts_interfaces/requests/realtime.ts +59 -0
- package/ts_interfaces/requests/remoteingress.ts +202 -0
- package/ts_interfaces/requests/route-management.ts +194 -0
- package/ts_interfaces/requests/security-policy.ts +144 -0
- package/ts_interfaces/requests/smtp-accounts.ts +163 -0
- package/ts_interfaces/requests/source-profiles.ts +127 -0
- package/ts_interfaces/requests/stats.ts +207 -0
- package/ts_interfaces/requests/target-profiles.ts +130 -0
- package/ts_interfaces/requests/testing.ts +186 -0
- package/ts_interfaces/requests/users.ts +66 -0
- package/ts_interfaces/requests/vpn.ts +238 -0
- package/ts_interfaces/requests/workhoster.ts +100 -0
package/readme.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# @serve.zone/dcrouter-apiclient
|
|
2
|
+
|
|
3
|
+
`@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 gateway-client integrations.
|
|
4
|
+
|
|
5
|
+
It is the client half of dcrouter without the server: installing it does not pull the runtime, the dashboard, the database client or a native password hasher. It ships the shared contracts alongside the client under the `./interfaces` subpath, so a consumer that only reads request and data types never needs `@serve.zone/dcrouter` either.
|
|
6
|
+
|
|
7
|
+
## Issue Reporting and Security
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @serve.zone/dcrouter-apiclient
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Two entry points:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { DcRouterApiClient } from '@serve.zone/dcrouter-apiclient';
|
|
21
|
+
import { data, requests } from '@serve.zone/dcrouter-apiclient/interfaces';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The same client and contracts remain available as subpaths of the server package for consumers that already depend on it:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { DcRouterApiClient } from '@serve.zone/dcrouter/apiclient';
|
|
28
|
+
import { data, requests } from '@serve.zone/dcrouter/interfaces';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Platform support
|
|
32
|
+
|
|
33
|
+
**This package installs on Linux x64 and arm64 only.** Several contract members are typed against `@push.rocks/smartmta`, `@push.rocks/smartproxy` and `@push.rocks/smartnetwork`, so those packages are dependencies even though the imports are type-only, and `@push.rocks/smartmta` declares `os: ["linux"]` with `cpu: ["x64", "arm64"]`. Installing anywhere else fails with `ERR_PNPM_UNSUPPORTED_PLATFORM`. `@serve.zone/dcrouter` carries the same constraint today, so this is not a new restriction — but it does mean the client cannot yet be installed on a macOS or Windows developer machine.
|
|
34
|
+
|
|
35
|
+
The restriction is upstream and no change here lifts it. It goes away once `@push.rocks/smartproxy`, `@push.rocks/smartmta` and `@push.rocks/smartnetwork` move their Rust payloads into per-platform optional packages; today each of the three ships both the amd64 and the arm64 binary in one tarball and declares no macOS or Windows build.
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { DcRouterApiClient } from '@serve.zone/dcrouter-apiclient';
|
|
41
|
+
|
|
42
|
+
const client = new DcRouterApiClient({
|
|
43
|
+
baseUrl: 'https://dcrouter.example.com',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await client.login('admin@example.com', 'strong-password');
|
|
47
|
+
|
|
48
|
+
const { routes, warnings } = await client.routes.list();
|
|
49
|
+
console.log(routes.length, warnings.length);
|
|
50
|
+
|
|
51
|
+
const route = await client.routes.build()
|
|
52
|
+
.setName('api-gateway')
|
|
53
|
+
.setMatch({ ports: 443, domains: ['api.example.com'] })
|
|
54
|
+
.setAction({ type: 'forward', targets: [{ host: '127.0.0.1', port: 8080 }] })
|
|
55
|
+
.save();
|
|
56
|
+
|
|
57
|
+
await route.toggle(true);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Authentication
|
|
61
|
+
|
|
62
|
+
The client supports persisted-admin session login and API-token authentication. Initial admin creation is a bootstrap flow exposed by the Ops dashboard and raw TypedRequest contracts; after a persisted admin exists, use that account with `login()`.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const sessionClient = new DcRouterApiClient({
|
|
66
|
+
baseUrl: 'https://dcrouter.example.com',
|
|
67
|
+
});
|
|
68
|
+
await sessionClient.login('admin@example.com', 'strong-password');
|
|
69
|
+
|
|
70
|
+
const tokenClient = new DcRouterApiClient({
|
|
71
|
+
baseUrl: 'https://dcrouter.example.com',
|
|
72
|
+
apiToken: 'dcr_token_value',
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`baseUrl` is normalized by removing trailing slashes. Ordinary requests are sent to `${baseUrl}/typedrequest`; log streams use a dedicated TypedSocket connection. `buildRequestPayload()` injects the current identity and optional API token for manager methods.
|
|
77
|
+
|
|
78
|
+
## Manager Map
|
|
79
|
+
|
|
80
|
+
| Manager | Purpose |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `client.routes` | List merged routes, build/update/delete ordinary operator routes, and toggle routes. |
|
|
83
|
+
| `client.certificates` | Inspect certificate summaries and trigger certificate operations. |
|
|
84
|
+
| `client.apiTokens` | Create, list, toggle, roll, and revoke API tokens. |
|
|
85
|
+
| `client.remoteIngress` | Manage edge registrations, statuses, ports, tags, and connection tokens. |
|
|
86
|
+
| `client.emails` | Inspect received/cached email items and trigger resend flows. |
|
|
87
|
+
| `client.gatewayClients` | Manage gateway-client route, DNS, and domain integration calls. |
|
|
88
|
+
| `client.stats` | Read health, counters, summaries, and runtime status. |
|
|
89
|
+
| `client.config` | Read the current configuration view. |
|
|
90
|
+
| `client.logs` | Read recent logs or receive a live log stream. |
|
|
91
|
+
| `client.radius` | Manage RADIUS clients, VLAN mappings, and accounting sessions. |
|
|
92
|
+
|
|
93
|
+
## Log Streams
|
|
94
|
+
|
|
95
|
+
Log streaming requires a dcrouter server using TypedSocket 8. Each stream owns
|
|
96
|
+
one connection, which is released when the stream closes or aborts. Access needs
|
|
97
|
+
`logs:read` and is revalidated on the same physical peer during streaming.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
try {
|
|
101
|
+
const { logStream } = await client.logs.getStream({ follow: false });
|
|
102
|
+
try {
|
|
103
|
+
await logStream.opened;
|
|
104
|
+
const decoder = new TextDecoder();
|
|
105
|
+
for (;;) {
|
|
106
|
+
const chunk = await logStream.receive();
|
|
107
|
+
if (chunk === undefined) break;
|
|
108
|
+
console.log(JSON.parse(decoder.decode(chunk)));
|
|
109
|
+
}
|
|
110
|
+
await logStream.accept();
|
|
111
|
+
} catch (error) {
|
|
112
|
+
await logStream.abort(error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
} finally {
|
|
116
|
+
await client.stop();
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Use `follow: true` for ongoing logs and call `logStream.abort()` when finished,
|
|
121
|
+
including when no entries are arriving. Await each receive to apply backpressure.
|
|
122
|
+
`client.logs.close()` closes current streams while allowing a later session;
|
|
123
|
+
`client.stop()` permanently closes log streaming on that client instance.
|
|
124
|
+
Logout closes current streams and permits a later login.
|
|
125
|
+
|
|
126
|
+
## Route Builder
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const route = await client.routes.build()
|
|
130
|
+
.setName('internal-app')
|
|
131
|
+
.setMatch({
|
|
132
|
+
ports: 443,
|
|
133
|
+
domains: ['internal.example.com'],
|
|
134
|
+
})
|
|
135
|
+
.setAction({
|
|
136
|
+
type: 'forward',
|
|
137
|
+
targets: [{ host: '127.0.0.1', port: 3000 }],
|
|
138
|
+
})
|
|
139
|
+
.setEnabled(true)
|
|
140
|
+
.save();
|
|
141
|
+
|
|
142
|
+
await route.update({
|
|
143
|
+
action: {
|
|
144
|
+
type: 'forward',
|
|
145
|
+
targets: [{ host: '127.0.0.1', port: 3001 }],
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
System routes from `config`, `email`, and `dns` origins are designed to be toggled, not edited. Generic create/update/delete behavior is for ordinary operator-owned routes with origin `api`. API-origin routes carrying managed ownership metadata, including gateway-client routes and HTTP-01 Special Forwards, must be changed through their owning specialized TypedRequest workflow; `client.routes` does not bypass that protection.
|
|
151
|
+
|
|
152
|
+
## API Tokens and Remote Ingress
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const token = await client.apiTokens.build()
|
|
156
|
+
.setName('automation')
|
|
157
|
+
.setScopes(['routes:read', 'routes:write'])
|
|
158
|
+
.setExpiresInDays(30)
|
|
159
|
+
.save();
|
|
160
|
+
|
|
161
|
+
const edge = await client.remoteIngress.build()
|
|
162
|
+
.setName('edge-eu-1')
|
|
163
|
+
.setListenPorts([80, 443])
|
|
164
|
+
.setAutoDerivePorts(true)
|
|
165
|
+
.setEgress({
|
|
166
|
+
enabled: true,
|
|
167
|
+
allowedPorts: [25],
|
|
168
|
+
allowedHostPatterns: ['*.example.com'],
|
|
169
|
+
maxConcurrentStreams: 100,
|
|
170
|
+
})
|
|
171
|
+
.setTags(['production', 'eu'])
|
|
172
|
+
.save();
|
|
173
|
+
|
|
174
|
+
const connectionToken = await edge.getConnectionToken();
|
|
175
|
+
console.log(token.tokenValue, connectionToken);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
RemoteIngress resources expose `performance` and `egress` fields. `create()` and `update()` accept the same fields as the builder. Egress is default-disabled; dcrouter currently accepts outbound SMTP egress on port `25` only.
|
|
179
|
+
|
|
180
|
+
## What This Package Is Not
|
|
181
|
+
|
|
182
|
+
- It does not start dcrouter.
|
|
183
|
+
- It does not serve or bundle the Ops dashboard.
|
|
184
|
+
- It does not replace the raw dcrouter-local TypedRequest contracts under `@serve.zone/dcrouter-apiclient/interfaces` when you want to talk to `/typedrequest` yourself.
|
|
185
|
+
|
|
186
|
+
Use `@serve.zone/dcrouter` for the server runtime. The canonical machine-facing gateway client route, DNS, and domain contracts used by `client.gatewayClients` come from `@serve.zone/interfaces`.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
This folder is published from the dcrouter monorepo through its `tspublish.json`, which also owns `ts_interfaces` and exposes it as the `./interfaces` subpath. Both folders keep the build order they always had (`ts_interfaces` first, then `ts_apiclient`). See `../ts_interfaces/readme.md` for the contract surface. `gitzone release` publishes this package in the same release as `@serve.zone/dcrouter` and the Docker images, at the same version and before the runtime package.
|
|
191
|
+
|
|
192
|
+
Useful source entry points:
|
|
193
|
+
|
|
194
|
+
- `index.ts` exports the public client surface.
|
|
195
|
+
- `classes.dcrouterapiclient.ts` owns authentication and request dispatch.
|
|
196
|
+
- `classes.route.ts` owns route resources and builders.
|
|
197
|
+
- `classes.remoteingress.ts`, `classes.apitoken.ts`, `classes.radius.ts`, and the other manager files wrap focused API domains.
|
|
198
|
+
|
|
199
|
+
## License and Legal Information
|
|
200
|
+
|
|
201
|
+
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](../license) file.
|
|
202
|
+
|
|
203
|
+
**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.
|
|
204
|
+
|
|
205
|
+
### Trademarks
|
|
206
|
+
|
|
207
|
+
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.
|
|
208
|
+
|
|
209
|
+
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.
|
|
210
|
+
|
|
211
|
+
### Company Information
|
|
212
|
+
|
|
213
|
+
Task Venture Capital GmbH
|
|
214
|
+
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
215
|
+
|
|
216
|
+
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
|
217
|
+
|
|
218
|
+
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.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import * as interfaces from '../ts_interfaces/index.js';
|
|
2
|
+
import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
|
|
3
|
+
|
|
4
|
+
export class ApiToken {
|
|
5
|
+
private clientRef: DcRouterApiClient;
|
|
6
|
+
|
|
7
|
+
// Data from IApiTokenInfo
|
|
8
|
+
public id: string;
|
|
9
|
+
public name: string;
|
|
10
|
+
public scopes: interfaces.data.TApiTokenScope[];
|
|
11
|
+
public createdAt: number;
|
|
12
|
+
public expiresAt: number | null;
|
|
13
|
+
public lastUsedAt: number | null;
|
|
14
|
+
public enabled: boolean;
|
|
15
|
+
|
|
16
|
+
/** Only set on creation or roll. Not persisted on server side. */
|
|
17
|
+
public tokenValue?: string;
|
|
18
|
+
|
|
19
|
+
constructor(clientRef: DcRouterApiClient, data: interfaces.data.IApiTokenInfo, tokenValue?: string) {
|
|
20
|
+
this.clientRef = clientRef;
|
|
21
|
+
this.id = data.id;
|
|
22
|
+
this.name = data.name;
|
|
23
|
+
this.scopes = data.scopes;
|
|
24
|
+
this.createdAt = data.createdAt;
|
|
25
|
+
this.expiresAt = data.expiresAt;
|
|
26
|
+
this.lastUsedAt = data.lastUsedAt;
|
|
27
|
+
this.enabled = data.enabled;
|
|
28
|
+
this.tokenValue = tokenValue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async revoke(): Promise<void> {
|
|
32
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_RevokeApiToken>(
|
|
33
|
+
'revokeApiToken',
|
|
34
|
+
this.clientRef.buildRequestPayload({ id: this.id }) as any,
|
|
35
|
+
);
|
|
36
|
+
if (!response.success) {
|
|
37
|
+
throw new Error(response.message || 'Failed to revoke token');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public async roll(): Promise<string> {
|
|
42
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_RollApiToken>(
|
|
43
|
+
'rollApiToken',
|
|
44
|
+
this.clientRef.buildRequestPayload({ id: this.id }) as any,
|
|
45
|
+
);
|
|
46
|
+
if (!response.success) {
|
|
47
|
+
throw new Error(response.message || 'Failed to roll token');
|
|
48
|
+
}
|
|
49
|
+
this.tokenValue = response.tokenValue;
|
|
50
|
+
return response.tokenValue!;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public async toggle(enabled: boolean): Promise<void> {
|
|
54
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_ToggleApiToken>(
|
|
55
|
+
'toggleApiToken',
|
|
56
|
+
this.clientRef.buildRequestPayload({ id: this.id, enabled }) as any,
|
|
57
|
+
);
|
|
58
|
+
if (!response.success) {
|
|
59
|
+
throw new Error(response.message || 'Failed to toggle token');
|
|
60
|
+
}
|
|
61
|
+
this.enabled = enabled;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class ApiTokenBuilder {
|
|
66
|
+
private clientRef: DcRouterApiClient;
|
|
67
|
+
private tokenName: string = '';
|
|
68
|
+
private tokenScopes: interfaces.data.TApiTokenScope[] = [];
|
|
69
|
+
private tokenExpiresInDays?: number | null;
|
|
70
|
+
|
|
71
|
+
constructor(clientRef: DcRouterApiClient) {
|
|
72
|
+
this.clientRef = clientRef;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public setName(name: string): this {
|
|
76
|
+
this.tokenName = name;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public setScopes(scopes: interfaces.data.TApiTokenScope[]): this {
|
|
81
|
+
this.tokenScopes = scopes;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public addScope(scope: interfaces.data.TApiTokenScope): this {
|
|
86
|
+
if (!this.tokenScopes.includes(scope)) {
|
|
87
|
+
this.tokenScopes.push(scope);
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public setExpiresInDays(days: number | null): this {
|
|
93
|
+
this.tokenExpiresInDays = days;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public async save(): Promise<ApiToken> {
|
|
98
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_CreateApiToken>(
|
|
99
|
+
'createApiToken',
|
|
100
|
+
this.clientRef.buildRequestPayload({
|
|
101
|
+
name: this.tokenName,
|
|
102
|
+
scopes: this.tokenScopes,
|
|
103
|
+
expiresInDays: this.tokenExpiresInDays,
|
|
104
|
+
}) as any,
|
|
105
|
+
);
|
|
106
|
+
if (!response.success) {
|
|
107
|
+
throw new Error(response.message || 'Failed to create API token');
|
|
108
|
+
}
|
|
109
|
+
return new ApiToken(
|
|
110
|
+
this.clientRef,
|
|
111
|
+
{
|
|
112
|
+
id: response.tokenId!,
|
|
113
|
+
name: this.tokenName,
|
|
114
|
+
scopes: this.tokenScopes,
|
|
115
|
+
createdAt: Date.now(),
|
|
116
|
+
expiresAt: this.tokenExpiresInDays
|
|
117
|
+
? Date.now() + this.tokenExpiresInDays * 24 * 60 * 60 * 1000
|
|
118
|
+
: null,
|
|
119
|
+
lastUsedAt: null,
|
|
120
|
+
enabled: true,
|
|
121
|
+
},
|
|
122
|
+
response.tokenValue,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class ApiTokenManager {
|
|
128
|
+
private clientRef: DcRouterApiClient;
|
|
129
|
+
|
|
130
|
+
constructor(clientRef: DcRouterApiClient) {
|
|
131
|
+
this.clientRef = clientRef;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public async list(): Promise<ApiToken[]> {
|
|
135
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_ListApiTokens>(
|
|
136
|
+
'listApiTokens',
|
|
137
|
+
this.clientRef.buildRequestPayload() as any,
|
|
138
|
+
);
|
|
139
|
+
return response.tokens.map((t) => new ApiToken(this.clientRef, t));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public async create(options: {
|
|
143
|
+
name: string;
|
|
144
|
+
scopes: interfaces.data.TApiTokenScope[];
|
|
145
|
+
expiresInDays?: number | null;
|
|
146
|
+
}): Promise<ApiToken> {
|
|
147
|
+
return this.build()
|
|
148
|
+
.setName(options.name)
|
|
149
|
+
.setScopes(options.scopes)
|
|
150
|
+
.setExpiresInDays(options.expiresInDays ?? null)
|
|
151
|
+
.save();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public build(): ApiTokenBuilder {
|
|
155
|
+
return new ApiTokenBuilder(this.clientRef);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type * as servezoneInterfaces from '@serve.zone/interfaces';
|
|
2
|
+
import * as interfaces from '../ts_interfaces/index.js';
|
|
3
|
+
import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
|
|
4
|
+
|
|
5
|
+
export class Certificate {
|
|
6
|
+
private clientRef: DcRouterApiClient;
|
|
7
|
+
|
|
8
|
+
// Data from ICertificateInfo
|
|
9
|
+
public domain: string;
|
|
10
|
+
public routeNames: string[];
|
|
11
|
+
public status: interfaces.requests.TCertificateStatus;
|
|
12
|
+
public source: interfaces.requests.TCertificateSource;
|
|
13
|
+
public tlsMode: 'terminate' | 'terminate-and-reencrypt' | 'passthrough';
|
|
14
|
+
public expiryDate?: string;
|
|
15
|
+
public issuer?: string;
|
|
16
|
+
public issuedAt?: string;
|
|
17
|
+
public error?: string;
|
|
18
|
+
public canReprovision: boolean;
|
|
19
|
+
public backoffInfo?: {
|
|
20
|
+
failures: number;
|
|
21
|
+
retryAfter?: string;
|
|
22
|
+
lastError?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
constructor(clientRef: DcRouterApiClient, data: interfaces.requests.ICertificateInfo) {
|
|
26
|
+
this.clientRef = clientRef;
|
|
27
|
+
this.domain = data.domain;
|
|
28
|
+
this.routeNames = data.routeNames;
|
|
29
|
+
this.status = data.status;
|
|
30
|
+
this.source = data.source;
|
|
31
|
+
this.tlsMode = data.tlsMode;
|
|
32
|
+
this.expiryDate = data.expiryDate;
|
|
33
|
+
this.issuer = data.issuer;
|
|
34
|
+
this.issuedAt = data.issuedAt;
|
|
35
|
+
this.error = data.error;
|
|
36
|
+
this.canReprovision = data.canReprovision;
|
|
37
|
+
this.backoffInfo = data.backoffInfo;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async reprovision(): Promise<void> {
|
|
41
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_ReprovisionCertificateDomain>(
|
|
42
|
+
'reprovisionCertificateDomain',
|
|
43
|
+
this.clientRef.buildRequestPayload({ domain: this.domain }) as any,
|
|
44
|
+
);
|
|
45
|
+
if (!response.success) {
|
|
46
|
+
throw new Error(response.message || 'Failed to reprovision certificate');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async delete(): Promise<void> {
|
|
51
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_DeleteCertificate>(
|
|
52
|
+
'deleteCertificate',
|
|
53
|
+
this.clientRef.buildRequestPayload({ domain: this.domain }) as any,
|
|
54
|
+
);
|
|
55
|
+
if (!response.success) {
|
|
56
|
+
throw new Error(response.message || 'Failed to delete certificate');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async export(): Promise<{
|
|
61
|
+
id: string;
|
|
62
|
+
domainName: string;
|
|
63
|
+
created: number;
|
|
64
|
+
validUntil: number;
|
|
65
|
+
privateKey: string;
|
|
66
|
+
publicKey: string;
|
|
67
|
+
csr: string;
|
|
68
|
+
} | undefined> {
|
|
69
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_ExportCertificate>(
|
|
70
|
+
'exportCertificate',
|
|
71
|
+
this.clientRef.buildRequestPayload({ domain: this.domain }) as any,
|
|
72
|
+
);
|
|
73
|
+
if (!response.success) {
|
|
74
|
+
throw new Error(response.message || 'Failed to export certificate');
|
|
75
|
+
}
|
|
76
|
+
return response.cert;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ICertificateSummary {
|
|
81
|
+
total: number;
|
|
82
|
+
valid: number;
|
|
83
|
+
expiring: number;
|
|
84
|
+
expired: number;
|
|
85
|
+
failed: number;
|
|
86
|
+
unknown: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class CertificateManager {
|
|
90
|
+
private clientRef: DcRouterApiClient;
|
|
91
|
+
|
|
92
|
+
constructor(clientRef: DcRouterApiClient) {
|
|
93
|
+
this.clientRef = clientRef;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public async list(): Promise<{ certificates: Certificate[]; summary: ICertificateSummary }> {
|
|
97
|
+
const response = await this.clientRef.request<interfaces.requests.IReq_GetCertificateOverview>(
|
|
98
|
+
'getCertificateOverview',
|
|
99
|
+
this.clientRef.buildRequestPayload() as any,
|
|
100
|
+
);
|
|
101
|
+
return {
|
|
102
|
+
certificates: response.certificates.map((c) => new Certificate(this.clientRef, c)),
|
|
103
|
+
summary: response.summary,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public async import(cert: {
|
|
108
|
+
id: string;
|
|
109
|
+
domainName: string;
|
|
110
|
+
created: number;
|
|
111
|
+
validUntil: number;
|
|
112
|
+
privateKey: string;
|
|
113
|
+
publicKey: string;
|
|
114
|
+
csr: string;
|
|
115
|
+
}): Promise<void> {
|
|
116
|
+
const response = await this.clientRef.request<servezoneInterfaces.requests.gateway.IReq_ImportCertificate>(
|
|
117
|
+
'importCertificate',
|
|
118
|
+
this.clientRef.buildRequestPayload({ cert }) as any,
|
|
119
|
+
);
|
|
120
|
+
if (!response.success) {
|
|
121
|
+
throw new Error(response.message || 'Failed to import certificate');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as interfaces from '../ts_interfaces/index.js';
|
|
2
|
+
import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
|
|
3
|
+
|
|
4
|
+
export class ConfigManager {
|
|
5
|
+
private clientRef: DcRouterApiClient;
|
|
6
|
+
|
|
7
|
+
constructor(clientRef: DcRouterApiClient) {
|
|
8
|
+
this.clientRef = clientRef;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public async get(section?: string): Promise<interfaces.requests.IReq_GetConfiguration['response']> {
|
|
12
|
+
return this.clientRef.request<interfaces.requests.IReq_GetConfiguration>(
|
|
13
|
+
'getConfiguration',
|
|
14
|
+
this.clientRef.buildRequestPayload({ section }) as any,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import * as interfaces from '../ts_interfaces/index.js';
|
|
3
|
+
|
|
4
|
+
import { RouteManager } from './classes.route.js';
|
|
5
|
+
import { CertificateManager } from './classes.certificate.js';
|
|
6
|
+
import { ApiTokenManager } from './classes.apitoken.js';
|
|
7
|
+
import { RemoteIngressManager } from './classes.remoteingress.js';
|
|
8
|
+
import { StatsManager } from './classes.stats.js';
|
|
9
|
+
import { ConfigManager } from './classes.config.js';
|
|
10
|
+
import { LogManager } from './classes.logs.js';
|
|
11
|
+
import { EmailManager } from './classes.email.js';
|
|
12
|
+
import { RadiusManager } from './classes.radius.js';
|
|
13
|
+
import { GatewayClientApi } from './classes.gatewayclient.js';
|
|
14
|
+
import { TestingApi } from './classes.testing.js';
|
|
15
|
+
|
|
16
|
+
export interface IDcRouterApiClientOptions {
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
apiToken?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IDcRouterRequestOptions {
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
abortSignal?: AbortSignal;
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
/** Suppress traffic hooks for credentials and downloaded secret material. */
|
|
26
|
+
sensitive?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class DcRouterApiClient {
|
|
30
|
+
public baseUrl: string;
|
|
31
|
+
public apiToken?: string;
|
|
32
|
+
public identity?: interfaces.data.IIdentity;
|
|
33
|
+
|
|
34
|
+
// Resource managers
|
|
35
|
+
public routes: RouteManager;
|
|
36
|
+
public certificates: CertificateManager;
|
|
37
|
+
public apiTokens: ApiTokenManager;
|
|
38
|
+
public remoteIngress: RemoteIngressManager;
|
|
39
|
+
public stats: StatsManager;
|
|
40
|
+
public config: ConfigManager;
|
|
41
|
+
public logs: LogManager;
|
|
42
|
+
public emails: EmailManager;
|
|
43
|
+
public radius: RadiusManager;
|
|
44
|
+
public gatewayClients: GatewayClientApi;
|
|
45
|
+
public testing: TestingApi;
|
|
46
|
+
|
|
47
|
+
constructor(options: IDcRouterApiClientOptions) {
|
|
48
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
49
|
+
this.apiToken = options.apiToken;
|
|
50
|
+
|
|
51
|
+
this.routes = new RouteManager(this);
|
|
52
|
+
this.certificates = new CertificateManager(this);
|
|
53
|
+
this.apiTokens = new ApiTokenManager(this);
|
|
54
|
+
this.remoteIngress = new RemoteIngressManager(this);
|
|
55
|
+
this.stats = new StatsManager(this);
|
|
56
|
+
this.config = new ConfigManager(this);
|
|
57
|
+
this.logs = new LogManager(this);
|
|
58
|
+
this.emails = new EmailManager(this);
|
|
59
|
+
this.radius = new RadiusManager(this);
|
|
60
|
+
this.gatewayClients = new GatewayClientApi(this);
|
|
61
|
+
this.testing = new TestingApi(this);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// =====================
|
|
65
|
+
// Auth
|
|
66
|
+
// =====================
|
|
67
|
+
|
|
68
|
+
public async login(username: string, password: string): Promise<interfaces.data.IIdentity> {
|
|
69
|
+
const response = await this.request<interfaces.requests.IReq_AdminLoginWithUsernameAndPassword>(
|
|
70
|
+
'adminLoginWithUsernameAndPassword',
|
|
71
|
+
{ username, password },
|
|
72
|
+
);
|
|
73
|
+
if (response.identity) {
|
|
74
|
+
this.identity = response.identity;
|
|
75
|
+
}
|
|
76
|
+
return response.identity!;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public async logout(): Promise<void> {
|
|
80
|
+
await this.request<interfaces.requests.IReq_AdminLogout>(
|
|
81
|
+
'adminLogout',
|
|
82
|
+
{ identity: this.identity! },
|
|
83
|
+
);
|
|
84
|
+
this.identity = undefined;
|
|
85
|
+
await this.logs.close();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Release connections and active log streams owned by this client. */
|
|
89
|
+
public async stop(): Promise<void> {
|
|
90
|
+
this.testing.stop();
|
|
91
|
+
await this.logs.stop();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public async verifyIdentity(): Promise<{ valid: boolean; identity?: interfaces.data.IIdentity }> {
|
|
95
|
+
const response = await this.request<interfaces.requests.IReq_VerifyIdentity>(
|
|
96
|
+
'verifyIdentity',
|
|
97
|
+
{ identity: this.identity! },
|
|
98
|
+
);
|
|
99
|
+
if (response.identity) {
|
|
100
|
+
this.identity = response.identity;
|
|
101
|
+
}
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// =====================
|
|
106
|
+
// Internal request helper
|
|
107
|
+
// =====================
|
|
108
|
+
|
|
109
|
+
public async request<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
|
110
|
+
method: string,
|
|
111
|
+
requestData: T['request'],
|
|
112
|
+
options: IDcRouterRequestOptions = {},
|
|
113
|
+
): Promise<T['response']> {
|
|
114
|
+
const typedRequest = new plugins.typedrequest.TypedRequest<T>(
|
|
115
|
+
`${this.baseUrl}/typedrequest`,
|
|
116
|
+
method,
|
|
117
|
+
);
|
|
118
|
+
typedRequest.skipHooks = options.sensitive ?? false;
|
|
119
|
+
return typedRequest.fire(requestData, {
|
|
120
|
+
timeoutMs: options.timeoutMs, abortSignal: options.abortSignal,
|
|
121
|
+
maxRetries: options.maxRetries, useCache: false,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Build a request payload with identity and optional API token auto-injected.
|
|
127
|
+
*/
|
|
128
|
+
public buildRequestPayload(extra: Record<string, any> = {}): Record<string, any> {
|
|
129
|
+
const payload: Record<string, any> = { ...extra };
|
|
130
|
+
if (this.identity) {
|
|
131
|
+
payload.identity = this.identity;
|
|
132
|
+
}
|
|
133
|
+
if (this.apiToken) {
|
|
134
|
+
payload.apiToken = this.apiToken;
|
|
135
|
+
}
|
|
136
|
+
return payload;
|
|
137
|
+
}
|
|
138
|
+
}
|