@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.
Files changed (200) hide show
  1. package/dist_ts_apiclient/classes.apitoken.d.ts +41 -0
  2. package/dist_ts_apiclient/classes.apitoken.js +115 -0
  3. package/dist_ts_apiclient/classes.certificate.d.ts +57 -0
  4. package/dist_ts_apiclient/classes.certificate.js +69 -0
  5. package/dist_ts_apiclient/classes.config.d.ts +7 -0
  6. package/dist_ts_apiclient/classes.config.js +11 -0
  7. package/dist_ts_apiclient/classes.dcrouterapiclient.d.ts +54 -0
  8. package/dist_ts_apiclient/classes.dcrouterapiclient.js +97 -0
  9. package/dist_ts_apiclient/classes.email.d.ts +30 -0
  10. package/dist_ts_apiclient/classes.email.js +52 -0
  11. package/dist_ts_apiclient/classes.gatewayclient.d.ts +28 -0
  12. package/dist_ts_apiclient/classes.gatewayclient.js +52 -0
  13. package/dist_ts_apiclient/classes.logs.d.ts +28 -0
  14. package/dist_ts_apiclient/classes.logs.js +69 -0
  15. package/dist_ts_apiclient/classes.radius.d.ts +59 -0
  16. package/dist_ts_apiclient/classes.radius.js +95 -0
  17. package/dist_ts_apiclient/classes.remoteingress.d.ts +66 -0
  18. package/dist_ts_apiclient/classes.remoteingress.js +164 -0
  19. package/dist_ts_apiclient/classes.route.d.ts +39 -0
  20. package/dist_ts_apiclient/classes.route.js +125 -0
  21. package/dist_ts_apiclient/classes.stats.d.ts +47 -0
  22. package/dist_ts_apiclient/classes.stats.js +38 -0
  23. package/dist_ts_apiclient/classes.testing.d.ts +65 -0
  24. package/dist_ts_apiclient/classes.testing.js +120 -0
  25. package/dist_ts_apiclient/index.d.ts +12 -0
  26. package/dist_ts_apiclient/index.js +16 -0
  27. package/dist_ts_apiclient/plugins.d.ts +4 -0
  28. package/dist_ts_apiclient/plugins.js +6 -0
  29. package/dist_ts_interfaces/data/acme-config.d.ts +23 -0
  30. package/dist_ts_interfaces/data/acme-config.js +2 -0
  31. package/dist_ts_interfaces/data/auth.d.ts +8 -0
  32. package/dist_ts_interfaces/data/auth.js +2 -0
  33. package/dist_ts_interfaces/data/config-events.d.ts +34 -0
  34. package/dist_ts_interfaces/data/config-events.js +8 -0
  35. package/dist_ts_interfaces/data/dns-authority.d.ts +98 -0
  36. package/dist_ts_interfaces/data/dns-authority.js +26 -0
  37. package/dist_ts_interfaces/data/dns-provider.d.ts +136 -0
  38. package/dist_ts_interfaces/data/dns-provider.js +41 -0
  39. package/dist_ts_interfaces/data/dns-record.d.ts +48 -0
  40. package/dist_ts_interfaces/data/dns-record.js +2 -0
  41. package/dist_ts_interfaces/data/domain.d.ts +35 -0
  42. package/dist_ts_interfaces/data/domain.js +2 -0
  43. package/dist_ts_interfaces/data/email-domain.d.ts +177 -0
  44. package/dist_ts_interfaces/data/email-domain.js +2 -0
  45. package/dist_ts_interfaces/data/email-settings.d.ts +68 -0
  46. package/dist_ts_interfaces/data/email-settings.js +2 -0
  47. package/dist_ts_interfaces/data/index.d.ts +18 -0
  48. package/dist_ts_interfaces/data/index.js +19 -0
  49. package/dist_ts_interfaces/data/remoteingress.d.ts +181 -0
  50. package/dist_ts_interfaces/data/remoteingress.js +15 -0
  51. package/dist_ts_interfaces/data/route-management.d.ts +270 -0
  52. package/dist_ts_interfaces/data/route-management.js +130 -0
  53. package/dist_ts_interfaces/data/security-policy.d.ts +32 -0
  54. package/dist_ts_interfaces/data/security-policy.js +2 -0
  55. package/dist_ts_interfaces/data/smtp-account.d.ts +50 -0
  56. package/dist_ts_interfaces/data/smtp-account.js +9 -0
  57. package/dist_ts_interfaces/data/stats.d.ts +283 -0
  58. package/dist_ts_interfaces/data/stats.js +2 -0
  59. package/dist_ts_interfaces/data/target-profile.d.ts +30 -0
  60. package/dist_ts_interfaces/data/target-profile.js +2 -0
  61. package/dist_ts_interfaces/data/testing.d.ts +191 -0
  62. package/dist_ts_interfaces/data/testing.js +20 -0
  63. package/dist_ts_interfaces/data/vpn.d.ts +65 -0
  64. package/dist_ts_interfaces/data/vpn.js +2 -0
  65. package/dist_ts_interfaces/data/workhoster.d.ts +63 -0
  66. package/dist_ts_interfaces/data/workhoster.js +2 -0
  67. package/dist_ts_interfaces/index.d.ts +5 -0
  68. package/dist_ts_interfaces/index.js +8 -0
  69. package/dist_ts_interfaces/plugins.d.ts +2 -0
  70. package/dist_ts_interfaces/plugins.js +4 -0
  71. package/dist_ts_interfaces/requests/acme-config.d.ts +42 -0
  72. package/dist_ts_interfaces/requests/acme-config.js +2 -0
  73. package/dist_ts_interfaces/requests/admin.d.ts +69 -0
  74. package/dist_ts_interfaces/requests/admin.js +3 -0
  75. package/dist_ts_interfaces/requests/api-tokens.d.ts +85 -0
  76. package/dist_ts_interfaces/requests/api-tokens.js +2 -0
  77. package/dist_ts_interfaces/requests/certificate.d.ts +87 -0
  78. package/dist_ts_interfaces/requests/certificate.js +5 -0
  79. package/dist_ts_interfaces/requests/combined.stats.d.ts +29 -0
  80. package/dist_ts_interfaces/requests/combined.stats.js +2 -0
  81. package/dist_ts_interfaces/requests/config-events.d.ts +35 -0
  82. package/dist_ts_interfaces/requests/config-events.js +4 -0
  83. package/dist_ts_interfaces/requests/config.d.ts +93 -0
  84. package/dist_ts_interfaces/requests/config.js +3 -0
  85. package/dist_ts_interfaces/requests/dns-authority.d.ts +80 -0
  86. package/dist_ts_interfaces/requests/dns-authority.js +3 -0
  87. package/dist_ts_interfaces/requests/dns-providers.d.ts +117 -0
  88. package/dist_ts_interfaces/requests/dns-providers.js +2 -0
  89. package/dist_ts_interfaces/requests/dns-records.d.ts +89 -0
  90. package/dist_ts_interfaces/requests/dns-records.js +2 -0
  91. package/dist_ts_interfaces/requests/domains.d.ts +142 -0
  92. package/dist_ts_interfaces/requests/domains.js +2 -0
  93. package/dist_ts_interfaces/requests/email-domains.d.ts +154 -0
  94. package/dist_ts_interfaces/requests/email-domains.js +2 -0
  95. package/dist_ts_interfaces/requests/email-ops.d.ts +211 -0
  96. package/dist_ts_interfaces/requests/email-ops.js +3 -0
  97. package/dist_ts_interfaces/requests/email-settings.d.ts +26 -0
  98. package/dist_ts_interfaces/requests/email-settings.js +2 -0
  99. package/dist_ts_interfaces/requests/index.d.ts +29 -0
  100. package/dist_ts_interfaces/requests/index.js +30 -0
  101. package/dist_ts_interfaces/requests/logs.d.ts +43 -0
  102. package/dist_ts_interfaces/requests/logs.js +4 -0
  103. package/dist_ts_interfaces/requests/network-targets.d.ts +102 -0
  104. package/dist_ts_interfaces/requests/network-targets.js +2 -0
  105. package/dist_ts_interfaces/requests/radius.d.ts +280 -0
  106. package/dist_ts_interfaces/requests/radius.js +3 -0
  107. package/dist_ts_interfaces/requests/realtime.d.ts +38 -0
  108. package/dist_ts_interfaces/requests/realtime.js +12 -0
  109. package/dist_ts_interfaces/requests/remoteingress.d.ts +162 -0
  110. package/dist_ts_interfaces/requests/remoteingress.js +3 -0
  111. package/dist_ts_interfaces/requests/route-management.d.ts +147 -0
  112. package/dist_ts_interfaces/requests/route-management.js +2 -0
  113. package/dist_ts_interfaces/requests/security-policy.d.ts +105 -0
  114. package/dist_ts_interfaces/requests/security-policy.js +2 -0
  115. package/dist_ts_interfaces/requests/smtp-accounts.d.ts +125 -0
  116. package/dist_ts_interfaces/requests/smtp-accounts.js +2 -0
  117. package/dist_ts_interfaces/requests/source-profiles.d.ts +102 -0
  118. package/dist_ts_interfaces/requests/source-profiles.js +2 -0
  119. package/dist_ts_interfaces/requests/stats.d.ts +196 -0
  120. package/dist_ts_interfaces/requests/stats.js +4 -0
  121. package/dist_ts_interfaces/requests/target-profiles.d.ts +105 -0
  122. package/dist_ts_interfaces/requests/target-profiles.js +2 -0
  123. package/dist_ts_interfaces/requests/testing.d.ts +169 -0
  124. package/dist_ts_interfaces/requests/testing.js +2 -0
  125. package/dist_ts_interfaces/requests/users.d.ts +53 -0
  126. package/dist_ts_interfaces/requests/users.js +3 -0
  127. package/dist_ts_interfaces/requests/vpn.d.ts +188 -0
  128. package/dist_ts_interfaces/requests/vpn.js +3 -0
  129. package/dist_ts_interfaces/requests/workhoster.d.ts +79 -0
  130. package/dist_ts_interfaces/requests/workhoster.js +2 -0
  131. package/license +21 -0
  132. package/package.json +67 -0
  133. package/readme.md +218 -0
  134. package/ts_apiclient/classes.apitoken.ts +157 -0
  135. package/ts_apiclient/classes.certificate.ts +124 -0
  136. package/ts_apiclient/classes.config.ts +17 -0
  137. package/ts_apiclient/classes.dcrouterapiclient.ts +138 -0
  138. package/ts_apiclient/classes.email.ts +77 -0
  139. package/ts_apiclient/classes.gatewayclient.ts +110 -0
  140. package/ts_apiclient/classes.logs.ts +91 -0
  141. package/ts_apiclient/classes.radius.ts +180 -0
  142. package/ts_apiclient/classes.remoteingress.ts +217 -0
  143. package/ts_apiclient/classes.route.ts +166 -0
  144. package/ts_apiclient/classes.stats.ts +111 -0
  145. package/ts_apiclient/classes.testing.ts +152 -0
  146. package/ts_apiclient/index.ts +17 -0
  147. package/ts_apiclient/plugins.ts +10 -0
  148. package/ts_apiclient/readme.md +218 -0
  149. package/ts_interfaces/data/acme-config.ts +23 -0
  150. package/ts_interfaces/data/auth.ts +8 -0
  151. package/ts_interfaces/data/config-events.ts +38 -0
  152. package/ts_interfaces/data/dns-authority.ts +106 -0
  153. package/ts_interfaces/data/dns-provider.ts +174 -0
  154. package/ts_interfaces/data/dns-record.ts +50 -0
  155. package/ts_interfaces/data/domain.ts +36 -0
  156. package/ts_interfaces/data/email-domain.ts +206 -0
  157. package/ts_interfaces/data/email-settings.ts +75 -0
  158. package/ts_interfaces/data/index.ts +18 -0
  159. package/ts_interfaces/data/remoteingress.ts +204 -0
  160. package/ts_interfaces/data/route-management.ts +436 -0
  161. package/ts_interfaces/data/security-policy.ts +37 -0
  162. package/ts_interfaces/data/smtp-account.ts +63 -0
  163. package/ts_interfaces/data/stats.ts +305 -0
  164. package/ts_interfaces/data/target-profile.ts +31 -0
  165. package/ts_interfaces/data/testing.ts +184 -0
  166. package/ts_interfaces/data/vpn.ts +68 -0
  167. package/ts_interfaces/data/workhoster.ts +72 -0
  168. package/ts_interfaces/index.ts +9 -0
  169. package/ts_interfaces/plugins.ts +6 -0
  170. package/ts_interfaces/readme.md +194 -0
  171. package/ts_interfaces/requests/acme-config.ts +54 -0
  172. package/ts_interfaces/requests/admin.ts +96 -0
  173. package/ts_interfaces/requests/api-tokens.ts +109 -0
  174. package/ts_interfaces/requests/certificate.ts +106 -0
  175. package/ts_interfaces/requests/combined.stats.ts +30 -0
  176. package/ts_interfaces/requests/config-events.ts +45 -0
  177. package/ts_interfaces/requests/config.ts +94 -0
  178. package/ts_interfaces/requests/dns-authority.ts +104 -0
  179. package/ts_interfaces/requests/dns-providers.ts +154 -0
  180. package/ts_interfaces/requests/dns-records.ts +113 -0
  181. package/ts_interfaces/requests/domains.ts +178 -0
  182. package/ts_interfaces/requests/email-domains.ts +193 -0
  183. package/ts_interfaces/requests/email-ops.ts +266 -0
  184. package/ts_interfaces/requests/email-settings.ts +34 -0
  185. package/ts_interfaces/requests/index.ts +29 -0
  186. package/ts_interfaces/requests/logs.ts +58 -0
  187. package/ts_interfaces/requests/network-targets.ts +127 -0
  188. package/ts_interfaces/requests/radius.ts +341 -0
  189. package/ts_interfaces/requests/realtime.ts +59 -0
  190. package/ts_interfaces/requests/remoteingress.ts +202 -0
  191. package/ts_interfaces/requests/route-management.ts +194 -0
  192. package/ts_interfaces/requests/security-policy.ts +144 -0
  193. package/ts_interfaces/requests/smtp-accounts.ts +163 -0
  194. package/ts_interfaces/requests/source-profiles.ts +127 -0
  195. package/ts_interfaces/requests/stats.ts +207 -0
  196. package/ts_interfaces/requests/target-profiles.ts +130 -0
  197. package/ts_interfaces/requests/testing.ts +186 -0
  198. package/ts_interfaces/requests/users.ts +66 -0
  199. package/ts_interfaces/requests/vpn.ts +238 -0
  200. package/ts_interfaces/requests/workhoster.ts +100 -0
@@ -0,0 +1,166 @@
1
+ import * as interfaces from '../ts_interfaces/index.js';
2
+ import type { IRouteConfig } from '@push.rocks/smartproxy';
3
+ import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
4
+
5
+ export class Route {
6
+ private clientRef: DcRouterApiClient;
7
+
8
+ // Data from IMergedRoute
9
+ public routeConfig: IRouteConfig;
10
+ public id: string;
11
+ public enabled: boolean;
12
+ public origin: 'config' | 'email' | 'dns' | 'api';
13
+ public createdAt?: number;
14
+ public updatedAt?: number;
15
+
16
+ // Convenience accessors
17
+ public get name(): string {
18
+ return this.routeConfig.name || '';
19
+ }
20
+
21
+ constructor(clientRef: DcRouterApiClient, data: interfaces.data.IMergedRoute) {
22
+ this.clientRef = clientRef;
23
+ this.routeConfig = data.route;
24
+ this.id = data.id;
25
+ this.enabled = data.enabled;
26
+ this.origin = data.origin;
27
+ this.createdAt = data.createdAt;
28
+ this.updatedAt = data.updatedAt;
29
+ }
30
+
31
+ public async update(changes: Partial<IRouteConfig>): Promise<void> {
32
+ const response = await this.clientRef.request<interfaces.requests.IReq_UpdateRoute>(
33
+ 'updateRoute',
34
+ this.clientRef.buildRequestPayload({ id: this.id, route: changes }) as any,
35
+ );
36
+ if (!response.success) {
37
+ throw new Error(response.message || 'Failed to update route');
38
+ }
39
+ }
40
+
41
+ public async delete(): Promise<void> {
42
+ const response = await this.clientRef.request<interfaces.requests.IReq_DeleteRoute>(
43
+ 'deleteRoute',
44
+ this.clientRef.buildRequestPayload({ id: this.id }) as any,
45
+ );
46
+ if (!response.success) {
47
+ throw new Error(response.message || 'Failed to delete route');
48
+ }
49
+ }
50
+
51
+ public async toggle(enabled: boolean): Promise<void> {
52
+ const response = await this.clientRef.request<interfaces.requests.IReq_ToggleRoute>(
53
+ 'toggleRoute',
54
+ this.clientRef.buildRequestPayload({ id: this.id, enabled }) as any,
55
+ );
56
+ if (!response.success) {
57
+ throw new Error(response.message || 'Failed to toggle route');
58
+ }
59
+ this.enabled = enabled;
60
+ }
61
+ }
62
+
63
+ export class RouteBuilder {
64
+ private clientRef: DcRouterApiClient;
65
+ private routeConfig: Partial<IRouteConfig> = {};
66
+ private isEnabled: boolean = true;
67
+
68
+ constructor(clientRef: DcRouterApiClient) {
69
+ this.clientRef = clientRef;
70
+ }
71
+
72
+ public setName(name: string): this {
73
+ this.routeConfig.name = name;
74
+ return this;
75
+ }
76
+
77
+ public setMatch(match: IRouteConfig['match']): this {
78
+ this.routeConfig.match = match;
79
+ return this;
80
+ }
81
+
82
+ public setAction(action: IRouteConfig['action']): this {
83
+ this.routeConfig.action = action;
84
+ return this;
85
+ }
86
+
87
+ public setTls(tls: IRouteConfig['action']['tls']): this {
88
+ if (!this.routeConfig.action) {
89
+ this.routeConfig.action = { type: 'forward' } as IRouteConfig['action'];
90
+ }
91
+ this.routeConfig.action!.tls = tls;
92
+ return this;
93
+ }
94
+
95
+ public setEnabled(enabled: boolean): this {
96
+ this.isEnabled = enabled;
97
+ return this;
98
+ }
99
+
100
+ public async save(): Promise<Route> {
101
+ const response = await this.clientRef.request<interfaces.requests.IReq_CreateRoute>(
102
+ 'createRoute',
103
+ this.clientRef.buildRequestPayload({
104
+ route: this.routeConfig as IRouteConfig,
105
+ enabled: this.isEnabled,
106
+ }) as any,
107
+ );
108
+ if (!response.success) {
109
+ throw new Error(response.message || 'Failed to create route');
110
+ }
111
+
112
+ // Return a Route instance by re-fetching the list
113
+ const { routes } = await new RouteManager(this.clientRef).list();
114
+ const created = routes.find((r) => r.id === response.routeId);
115
+ if (created) {
116
+ return created;
117
+ }
118
+
119
+ // Fallback: construct from known data
120
+ return new Route(this.clientRef, {
121
+ route: this.routeConfig as IRouteConfig,
122
+ id: response.routeId || '',
123
+ enabled: this.isEnabled,
124
+ origin: 'api',
125
+ });
126
+ }
127
+ }
128
+
129
+ export class RouteManager {
130
+ private clientRef: DcRouterApiClient;
131
+
132
+ constructor(clientRef: DcRouterApiClient) {
133
+ this.clientRef = clientRef;
134
+ }
135
+
136
+ public async list(): Promise<{ routes: Route[]; warnings: interfaces.data.IRouteWarning[] }> {
137
+ const response = await this.clientRef.request<interfaces.requests.IReq_GetMergedRoutes>(
138
+ 'getMergedRoutes',
139
+ this.clientRef.buildRequestPayload() as any,
140
+ );
141
+ return {
142
+ routes: response.routes.map((r) => new Route(this.clientRef, r)),
143
+ warnings: response.warnings,
144
+ };
145
+ }
146
+
147
+ public async create(routeConfig: IRouteConfig, enabled?: boolean): Promise<Route> {
148
+ const response = await this.clientRef.request<interfaces.requests.IReq_CreateRoute>(
149
+ 'createRoute',
150
+ this.clientRef.buildRequestPayload({ route: routeConfig, enabled: enabled ?? true }) as any,
151
+ );
152
+ if (!response.success) {
153
+ throw new Error(response.message || 'Failed to create route');
154
+ }
155
+ return new Route(this.clientRef, {
156
+ route: routeConfig,
157
+ id: response.routeId || '',
158
+ enabled: enabled ?? true,
159
+ origin: 'api',
160
+ });
161
+ }
162
+
163
+ public build(): RouteBuilder {
164
+ return new RouteBuilder(this.clientRef);
165
+ }
166
+ }
@@ -0,0 +1,111 @@
1
+ import * as interfaces from '../ts_interfaces/index.js';
2
+ import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
3
+
4
+ type TTimeRange = '1h' | '6h' | '24h' | '7d' | '30d';
5
+
6
+ export class StatsManager {
7
+ private clientRef: DcRouterApiClient;
8
+
9
+ constructor(clientRef: DcRouterApiClient) {
10
+ this.clientRef = clientRef;
11
+ }
12
+
13
+ public async getServer(options?: {
14
+ timeRange?: TTimeRange;
15
+ includeHistory?: boolean;
16
+ }): Promise<interfaces.requests.IReq_GetServerStatistics['response']> {
17
+ return this.clientRef.request<interfaces.requests.IReq_GetServerStatistics>(
18
+ 'getServerStatistics',
19
+ this.clientRef.buildRequestPayload(options || {}) as any,
20
+ );
21
+ }
22
+
23
+ public async getEmail(options?: {
24
+ timeRange?: TTimeRange;
25
+ domain?: string;
26
+ includeDetails?: boolean;
27
+ }): Promise<interfaces.requests.IReq_GetEmailStatistics['response']> {
28
+ return this.clientRef.request<interfaces.requests.IReq_GetEmailStatistics>(
29
+ 'getEmailStatistics',
30
+ this.clientRef.buildRequestPayload(options || {}) as any,
31
+ );
32
+ }
33
+
34
+ public async getDns(options?: {
35
+ timeRange?: TTimeRange;
36
+ domain?: string;
37
+ includeQueryTypes?: boolean;
38
+ }): Promise<interfaces.requests.IReq_GetDnsStatistics['response']> {
39
+ return this.clientRef.request<interfaces.requests.IReq_GetDnsStatistics>(
40
+ 'getDnsStatistics',
41
+ this.clientRef.buildRequestPayload(options || {}) as any,
42
+ );
43
+ }
44
+
45
+ public async getRateLimits(options?: {
46
+ domain?: string;
47
+ ip?: string;
48
+ includeBlocked?: boolean;
49
+ }): Promise<interfaces.requests.IReq_GetRateLimitStatus['response']> {
50
+ return this.clientRef.request<interfaces.requests.IReq_GetRateLimitStatus>(
51
+ 'getRateLimitStatus',
52
+ this.clientRef.buildRequestPayload(options || {}) as any,
53
+ );
54
+ }
55
+
56
+ public async getSecurity(options?: {
57
+ timeRange?: TTimeRange;
58
+ includeDetails?: boolean;
59
+ }): Promise<interfaces.requests.IReq_GetSecurityMetrics['response']> {
60
+ return this.clientRef.request<interfaces.requests.IReq_GetSecurityMetrics>(
61
+ 'getSecurityMetrics',
62
+ this.clientRef.buildRequestPayload(options || {}) as any,
63
+ );
64
+ }
65
+
66
+ public async getConnections(options?: {
67
+ protocol?: 'smtp' | 'smtps' | 'http' | 'https';
68
+ state?: string;
69
+ }): Promise<interfaces.requests.IReq_GetActiveConnections['response']> {
70
+ return this.clientRef.request<interfaces.requests.IReq_GetActiveConnections>(
71
+ 'getActiveConnections',
72
+ this.clientRef.buildRequestPayload(options || {}) as any,
73
+ );
74
+ }
75
+
76
+ public async getQueues(options?: {
77
+ queueName?: string;
78
+ }): Promise<interfaces.requests.IReq_GetQueueStatus['response']> {
79
+ return this.clientRef.request<interfaces.requests.IReq_GetQueueStatus>(
80
+ 'getQueueStatus',
81
+ this.clientRef.buildRequestPayload(options || {}) as any,
82
+ );
83
+ }
84
+
85
+ public async getHealth(detailed?: boolean): Promise<interfaces.requests.IReq_GetHealthStatus['response']> {
86
+ return this.clientRef.request<interfaces.requests.IReq_GetHealthStatus>(
87
+ 'getHealthStatus',
88
+ this.clientRef.buildRequestPayload({ detailed }) as any,
89
+ );
90
+ }
91
+
92
+ public async getNetwork(): Promise<interfaces.requests.IReq_GetNetworkStats['response']> {
93
+ return this.clientRef.request<interfaces.requests.IReq_GetNetworkStats>(
94
+ 'getNetworkStats',
95
+ this.clientRef.buildRequestPayload() as any,
96
+ );
97
+ }
98
+
99
+ public async getCombined(sections?: {
100
+ server?: boolean;
101
+ email?: boolean;
102
+ dns?: boolean;
103
+ security?: boolean;
104
+ network?: boolean;
105
+ }): Promise<interfaces.requests.IReq_GetCombinedMetrics['response']> {
106
+ return this.clientRef.request<interfaces.requests.IReq_GetCombinedMetrics>(
107
+ 'getCombinedMetrics',
108
+ this.clientRef.buildRequestPayload({ sections }) as any,
109
+ );
110
+ }
111
+ }
@@ -0,0 +1,152 @@
1
+ import type { DcRouterApiClient } from './classes.dcrouterapiclient.js';
2
+ import type * as requests from '../ts_interfaces/requests/testing.js';
3
+
4
+ export interface ITestingRequestOptions {
5
+ timeoutMs?: number;
6
+ abortSignal?: AbortSignal;
7
+ }
8
+
9
+ export interface ITestingRequestMap {
10
+ createTestingRegistration: requests.IReq_CreateTestingRegistration;
11
+ getTestingRegistration: requests.IReq_GetTestingRegistration;
12
+ listTestingRegistrations: requests.IReq_ListTestingRegistrations;
13
+ rotateTestingRegistrationCredential: requests.IReq_RotateTestingRegistrationCredential;
14
+ revokeTestingRegistration: requests.IReq_RevokeTestingRegistration;
15
+ putTestingZone: requests.IReq_PutTestingZone;
16
+ listTestingZones: requests.IReq_ListTestingZones;
17
+ requestTestingDomainGrant: requests.IReq_RequestTestingDomainGrant;
18
+ listTestingDomainGrants: requests.IReq_ListTestingDomainGrants;
19
+ getTestingDomainGrant: requests.IReq_GetTestingDomainGrant;
20
+ reviewTestingDomainGrant: requests.IReq_ReviewTestingDomainGrant;
21
+ requestTestingCertificate: requests.IReq_RequestTestingCertificate;
22
+ getTestingCertificateJob: requests.IReq_GetTestingCertificateJob;
23
+ downloadTestingCertificate: requests.IReq_DownloadTestingCertificate;
24
+ listTestingDnsRecords: requests.IReq_ListTestingDnsRecords;
25
+ upsertTestingDnsRecord: requests.IReq_UpsertTestingDnsRecord;
26
+ deleteTestingDnsRecord: requests.IReq_DeleteTestingDnsRecord;
27
+ getTestingDnsMutation: requests.IReq_GetTestingDnsMutation;
28
+ listTestingOperationRecoveries: requests.IReq_ListTestingOperationRecoveries;
29
+ getTestingOperationRecovery: requests.IReq_GetTestingOperationRecovery;
30
+ recoverTestingOperation: requests.IReq_RecoverTestingOperation;
31
+ }
32
+
33
+ type TInput<K extends keyof ITestingRequestMap> = Omit<ITestingRequestMap[K]['request'], 'identity' | 'apiToken'>;
34
+
35
+ /** Transport errors intentionally exclude raw response bodies and nested causes. */
36
+ export class TestingTransportError extends Error {
37
+ constructor(public readonly code: 'cancelled' | 'timeout' | 'transport_unavailable') {
38
+ super(`Testing request ${code}`);
39
+ this.name = 'TestingTransportError';
40
+ }
41
+ }
42
+
43
+ /** No result cache, background polling, socket, or local credential persistence. */
44
+ export class TestingApi {
45
+ private lifecycle = new AbortController();
46
+ constructor(private clientRef: DcRouterApiClient) {}
47
+
48
+ public stop(): void { this.lifecycle.abort(); }
49
+
50
+ private async call<K extends keyof ITestingRequestMap>(
51
+ method: K, input: TInput<K>, options: ITestingRequestOptions = {},
52
+ ): Promise<ITestingRequestMap[K]['response']> {
53
+ const url = new URL(this.clientRef.baseUrl);
54
+ if (url.username || url.password || url.search || url.hash || url.pathname !== '/'
55
+ || (url.protocol !== 'https:' && !(url.protocol === 'http:'
56
+ && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)))) {
57
+ throw new Error('Testing requests require an HTTPS dcrouter origin or loopback test origin');
58
+ }
59
+ const timeoutMs = options.timeoutMs ?? 15000;
60
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120000) {
61
+ throw new Error('Testing request timeout must be between 1 and 120000 milliseconds');
62
+ }
63
+ const apiToken = this.clientRef.apiToken;
64
+ const identity = this.clientRef.identity;
65
+ if (Boolean(apiToken) === Boolean(identity)) {
66
+ throw new Error('Exactly one testing or admin credential is required');
67
+ }
68
+ const signal = AbortSignal.any([
69
+ this.lifecycle.signal, ...(options.abortSignal ? [options.abortSignal] : []),
70
+ ]);
71
+ // Snapshot input and authority before crossing the asynchronous transport boundary.
72
+ const payload = {
73
+ ...structuredClone(input),
74
+ ...(apiToken ? { apiToken } : { identity: structuredClone(identity) }),
75
+ } as ITestingRequestMap[K]['request'];
76
+ try {
77
+ return await this.clientRef.request<ITestingRequestMap[K]>(method, payload, {
78
+ sensitive: true, timeoutMs, abortSignal: signal, maxRetries: 0,
79
+ });
80
+ } catch (error) {
81
+ if (signal.aborted) throw new TestingTransportError('cancelled');
82
+ if (error instanceof Error && error.name === 'TypedRequestTimeoutError') {
83
+ throw new TestingTransportError('timeout');
84
+ }
85
+ throw new TestingTransportError('transport_unavailable');
86
+ }
87
+ }
88
+
89
+ public createRegistration(input: TInput<'createTestingRegistration'>, options?: ITestingRequestOptions) {
90
+ return this.call('createTestingRegistration', input, options);
91
+ }
92
+ public getRegistration(options?: ITestingRequestOptions) {
93
+ return this.call('getTestingRegistration', {}, options);
94
+ }
95
+ public listRegistrations(input: TInput<'listTestingRegistrations'> = {}, options?: ITestingRequestOptions) {
96
+ return this.call('listTestingRegistrations', input, options);
97
+ }
98
+ public rotateCredential(input: TInput<'rotateTestingRegistrationCredential'>, options?: ITestingRequestOptions) {
99
+ return this.call('rotateTestingRegistrationCredential', input, options);
100
+ }
101
+ public revokeRegistration(input: TInput<'revokeTestingRegistration'>, options?: ITestingRequestOptions) {
102
+ return this.call('revokeTestingRegistration', input, options);
103
+ }
104
+ public putZone(input: TInput<'putTestingZone'>, options?: ITestingRequestOptions) {
105
+ return this.call('putTestingZone', input, options);
106
+ }
107
+ public listZones(input: TInput<'listTestingZones'> = {}, options?: ITestingRequestOptions) {
108
+ return this.call('listTestingZones', input, options);
109
+ }
110
+ public requestGrant(input: TInput<'requestTestingDomainGrant'>, options?: ITestingRequestOptions) {
111
+ return this.call('requestTestingDomainGrant', input, options);
112
+ }
113
+ public listGrants(input: TInput<'listTestingDomainGrants'> = {}, options?: ITestingRequestOptions) {
114
+ return this.call('listTestingDomainGrants', input, options);
115
+ }
116
+ public getGrant(input: TInput<'getTestingDomainGrant'>, options?: ITestingRequestOptions) {
117
+ return this.call('getTestingDomainGrant', input, options);
118
+ }
119
+ public reviewGrant(input: TInput<'reviewTestingDomainGrant'>, options?: ITestingRequestOptions) {
120
+ return this.call('reviewTestingDomainGrant', input, options);
121
+ }
122
+ public requestCertificate(input: TInput<'requestTestingCertificate'>, options?: ITestingRequestOptions) {
123
+ return this.call('requestTestingCertificate', input, options);
124
+ }
125
+ public getCertificateJob(input: TInput<'getTestingCertificateJob'>, options?: ITestingRequestOptions) {
126
+ return this.call('getTestingCertificateJob', input, options);
127
+ }
128
+ public downloadCertificate(input: TInput<'downloadTestingCertificate'>, options?: ITestingRequestOptions) {
129
+ return this.call('downloadTestingCertificate', input, options);
130
+ }
131
+ public listDnsRecords(input: TInput<'listTestingDnsRecords'>, options?: ITestingRequestOptions) {
132
+ return this.call('listTestingDnsRecords', input, options);
133
+ }
134
+ public upsertDnsRecord(input: TInput<'upsertTestingDnsRecord'>, options?: ITestingRequestOptions) {
135
+ return this.call('upsertTestingDnsRecord', input, options);
136
+ }
137
+ public deleteDnsRecord(input: TInput<'deleteTestingDnsRecord'>, options?: ITestingRequestOptions) {
138
+ return this.call('deleteTestingDnsRecord', input, options);
139
+ }
140
+ public getDnsMutation(input: TInput<'getTestingDnsMutation'>, options?: ITestingRequestOptions) {
141
+ return this.call('getTestingDnsMutation', input, options);
142
+ }
143
+ public listRecoveries(input: TInput<'listTestingOperationRecoveries'>, options?: ITestingRequestOptions) {
144
+ return this.call('listTestingOperationRecoveries', input, options);
145
+ }
146
+ public getRecovery(input: TInput<'getTestingOperationRecovery'>, options?: ITestingRequestOptions) {
147
+ return this.call('getTestingOperationRecovery', input, options);
148
+ }
149
+ public recover(input: TInput<'recoverTestingOperation'>, options?: ITestingRequestOptions) {
150
+ return this.call('recoverTestingOperation', input, options);
151
+ }
152
+ }
@@ -0,0 +1,17 @@
1
+ // Main client
2
+ export { DcRouterApiClient, type IDcRouterApiClientOptions, type IDcRouterRequestOptions } from './classes.dcrouterapiclient.js';
3
+ export { TestingApi, TestingTransportError, type ITestingRequestOptions, type ITestingRequestMap } from './classes.testing.js';
4
+
5
+ // Resource classes
6
+ export { Route, RouteBuilder, RouteManager } from './classes.route.js';
7
+ export { Certificate, CertificateManager, type ICertificateSummary } from './classes.certificate.js';
8
+ export { ApiToken, ApiTokenBuilder, ApiTokenManager } from './classes.apitoken.js';
9
+ export { RemoteIngress, RemoteIngressBuilder, RemoteIngressManager } from './classes.remoteingress.js';
10
+ export { Email, EmailManager } from './classes.email.js';
11
+ export { GatewayClientApi } from './classes.gatewayclient.js';
12
+
13
+ // Read-only managers
14
+ export { StatsManager } from './classes.stats.js';
15
+ export { ConfigManager } from './classes.config.js';
16
+ export { LogManager } from './classes.logs.js';
17
+ export { RadiusManager, RadiusClientManager, RadiusVlanManager, RadiusSessionManager } from './classes.radius.js';
@@ -0,0 +1,10 @@
1
+ // @api.global scope
2
+ import * as typedrequest from '@api.global/typedrequest';
3
+ import * as typedrequestInterfaces from '@api.global/typedrequest-interfaces';
4
+ import * as typedsocket from '@api.global/typedsocket';
5
+
6
+ export {
7
+ typedrequest,
8
+ typedrequestInterfaces,
9
+ typedsocket,
10
+ };
@@ -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.