@serve.zone/interfaces 32.123.0 → 32.125.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 (51) hide show
  1. package/changelog.md +17 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/backupmx.d.ts +135 -0
  4. package/dist_ts/data/backupmx.js +128 -0
  5. package/dist_ts/data/certificateauthority.d.ts +57 -0
  6. package/dist_ts/data/certificateauthority.js +69 -0
  7. package/dist_ts/data/externaldns.d.ts +135 -0
  8. package/dist_ts/data/externaldns.js +138 -0
  9. package/dist_ts/data/gateway.d.ts +22 -0
  10. package/dist_ts/data/gateway.js +1 -1
  11. package/dist_ts/data/gatewayarearows.d.ts +2 -1
  12. package/dist_ts/data/gatewayarearows.js +1 -1
  13. package/dist_ts/data/gatewayareas.d.ts +19 -0
  14. package/dist_ts/data/gatewayareas.js +1 -1
  15. package/dist_ts/data/gatewayareas.validation.js +37 -5
  16. package/dist_ts/data/hetzner.d.ts +177 -0
  17. package/dist_ts/data/hetzner.js +253 -0
  18. package/dist_ts/data/index.d.ts +5 -0
  19. package/dist_ts/data/index.js +6 -1
  20. package/dist_ts/data/pathrouting.d.ts +170 -0
  21. package/dist_ts/data/pathrouting.js +227 -0
  22. package/dist_ts/requests/backupmx.d.ts +209 -0
  23. package/dist_ts/requests/backupmx.js +2 -0
  24. package/dist_ts/requests/certificateauthority.d.ts +118 -0
  25. package/dist_ts/requests/certificateauthority.js +2 -0
  26. package/dist_ts/requests/externaldns.d.ts +213 -0
  27. package/dist_ts/requests/externaldns.js +2 -0
  28. package/dist_ts/requests/hetzner.d.ts +216 -0
  29. package/dist_ts/requests/hetzner.js +2 -0
  30. package/dist_ts/requests/index.d.ts +6 -1
  31. package/dist_ts/requests/index.js +7 -2
  32. package/dist_ts/requests/pathrouting.d.ts +107 -0
  33. package/dist_ts/requests/pathrouting.js +2 -0
  34. package/package.json +47 -8
  35. package/ts/00_commitinfo_data.ts +1 -1
  36. package/ts/data/backupmx.ts +252 -0
  37. package/ts/data/certificateauthority.ts +115 -0
  38. package/ts/data/externaldns.ts +273 -0
  39. package/ts/data/gateway.ts +22 -0
  40. package/ts/data/gatewayarearows.ts +2 -0
  41. package/ts/data/gatewayareas.ts +20 -0
  42. package/ts/data/gatewayareas.validation.ts +40 -4
  43. package/ts/data/hetzner.ts +419 -0
  44. package/ts/data/index.ts +5 -0
  45. package/ts/data/pathrouting.ts +410 -0
  46. package/ts/requests/backupmx.ts +275 -0
  47. package/ts/requests/certificateauthority.ts +139 -0
  48. package/ts/requests/externaldns.ts +263 -0
  49. package/ts/requests/hetzner.ts +276 -0
  50. package/ts/requests/index.ts +10 -0
  51. package/ts/requests/pathrouting.ts +134 -0
@@ -0,0 +1,410 @@
1
+ export const serviceRoutingProfiles = Object.freeze([
2
+ 'latency',
3
+ 'balanced',
4
+ 'throughput',
5
+ ] as const);
6
+
7
+ export type TServiceRoutingProfile = typeof serviceRoutingProfiles[number];
8
+
9
+ export const pathRoutingRefusalCodes = Object.freeze([
10
+ 'administrator-required',
11
+ 'fresh-sign-in-required',
12
+ 'invalid-request',
13
+ 'policy-not-found',
14
+ 'gateway-not-found',
15
+ 'gateway-disconnected',
16
+ 'gateway-unsupported',
17
+ 'no-healthy-path',
18
+ 'probe-unavailable',
19
+ ] as const);
20
+
21
+ export type TPathRoutingRefusalCode = typeof pathRoutingRefusalCodes[number];
22
+
23
+ export const pathSwitchReasons = Object.freeze([
24
+ 'initial',
25
+ 'failover',
26
+ 'degradation',
27
+ 'optimization',
28
+ 'pinned',
29
+ 'retained-hysteresis',
30
+ 'retained-dwell',
31
+ 'no-healthy-path',
32
+ ] as const);
33
+
34
+ export type TPathSwitchReason = typeof pathSwitchReasons[number];
35
+
36
+ export const pathRoutingContract = Object.freeze({
37
+ defaultHysteresisMargin: 0.2,
38
+ defaultMinDwellMs: 5 * 60_000,
39
+ defaultSampleStaleMs: 120_000,
40
+ defaultProbeIntervalMs: 30_000,
41
+ defaultProbeJitterRatio: 0.2,
42
+ defaultThroughputProbeMaxBytes: 512 * 1024,
43
+ defaultThroughputProbeTimeoutMs: 2_500,
44
+ defaultThroughputProbeCooldownMs: 60_000,
45
+ defaultDnsTtlSeconds: 60,
46
+ gatewayHopHeader: 'x-servezone-gateway-hop',
47
+ diagnosticProbeTtlHeader: 'x-servezone-probe-ttl',
48
+ } as const);
49
+
50
+ /**
51
+ * Hop 1 telemetry: RemoteIngress edge (e) <-> dcrouter hub (d).
52
+ * Combines passive RemoteIngressHub flow-control/QUIC signals with active tunnel probes.
53
+ */
54
+ export interface IRemoteIngressEdgePathSample {
55
+ edgeId: string;
56
+ edgeName: string;
57
+ publicIpv4: string | null;
58
+ publicIpv6: string | null;
59
+ connected: boolean;
60
+ rttMs: number | null;
61
+ throughputMbps: number | null;
62
+ stalledStreams: number;
63
+ rejectedStreams: number;
64
+ dataQueueDepth: number;
65
+ blackHolesDetected: number;
66
+ fallbackUsed: boolean;
67
+ observedAt: number;
68
+ }
69
+
70
+ /**
71
+ * Hop 2 telemetry: dcrouter (d) <-> backend CoreTraffic / service target (s).
72
+ * Deduplicated per unique cluster/node backend targetKey so co-located services share network probes.
73
+ */
74
+ export interface IGatewayBackendPathSample {
75
+ targetKey: string;
76
+ clusterId: string | null;
77
+ targetHost: string;
78
+ targetPort: number;
79
+ reachable: boolean;
80
+ rttMs: number | null;
81
+ p95TtfbMs: number | null;
82
+ throughputMbps: number | null;
83
+ /** Fraction of recent requests failing with 5xx or TCP resets, in [0, 1]. */
84
+ errorRate: number;
85
+ consecutiveFailures: number;
86
+ observedAt: number;
87
+ }
88
+
89
+ export interface IGatewayPathTelemetryReport {
90
+ gatewayId: string;
91
+ reportedAt: number;
92
+ edgeSamples: IRemoteIngressEdgePathSample[];
93
+ backendSamples: IGatewayBackendPathSample[];
94
+ }
95
+
96
+ export interface IGatewayPathProbeRequest {
97
+ probeId: string;
98
+ kind: 'rtt' | 'throughput';
99
+ targetHost: string;
100
+ targetPort: number;
101
+ /** Optional HTTP probe path (e.g. '/_servezone/probe'). */
102
+ path?: string;
103
+ /** Upper bound on bytes transferred for throughput micro-probes. */
104
+ maxBytes?: number;
105
+ timeoutMs?: number;
106
+ /**
107
+ * Explicitly permits a bounded single-pass diagnostic loopback measurement
108
+ * (tagged with `x-servezone-probe-ttl: 1`) without relaxing production loop guards.
109
+ */
110
+ allowDiagnosticLoopback?: boolean;
111
+ }
112
+
113
+ export interface IGatewayPathProbeResult {
114
+ probeId: string;
115
+ ok: boolean;
116
+ kind: 'rtt' | 'throughput';
117
+ rttMs: number | null;
118
+ throughputMbps: number | null;
119
+ bytesTransferred: number;
120
+ statusCode: number | null;
121
+ error: string | null;
122
+ measuredAt: number;
123
+ }
124
+
125
+ export interface IServicePathPolicy {
126
+ serviceId: string;
127
+ hostname: string;
128
+ /** Backend target key matched against `IGatewayBackendPathSample.targetKey`. */
129
+ targetKey: string;
130
+ clusterId: string | null;
131
+ enabled: boolean;
132
+ profile: TServiceRoutingProfile;
133
+ pinnedGatewayId: string | null;
134
+ pinnedEdgeId: string | null;
135
+ /** Minimum relative score improvement (0..1) required to move a healthy service. */
136
+ hysteresisMargin: number;
137
+ /** Minimum dwell time (ms) between optimization switches while healthy. */
138
+ minDwellMs: number;
139
+ ttlSeconds: number;
140
+ proxied: boolean;
141
+ updatedAt: number;
142
+ }
143
+
144
+ export interface IServicePathCandidateScore {
145
+ gatewayId: string;
146
+ edgeId: string;
147
+ edgePublicIpv4: string | null;
148
+ edgePublicIpv6: string | null;
149
+ healthy: boolean;
150
+ degraded: boolean;
151
+ effectiveRttMs: number | null;
152
+ effectiveThroughputMbps: number | null;
153
+ /** Higher is better; 0 indicates a disqualified/unhealthy candidate. */
154
+ score: number;
155
+ disqualifyReason: string | null;
156
+ }
157
+
158
+ export interface IServicePathDecision {
159
+ serviceId: string;
160
+ hostname: string;
161
+ targetKey: string;
162
+ selectedGatewayId: string | null;
163
+ selectedEdgeId: string | null;
164
+ selectedPublicIpv4: string | null;
165
+ selectedPublicIpv6: string | null;
166
+ selectedScore: number | null;
167
+ effectiveRttMs: number | null;
168
+ effectiveThroughputMbps: number | null;
169
+ switchReason: TPathSwitchReason;
170
+ decidedAt: number;
171
+ lastSwitchedAt: number | null;
172
+ candidates: IServicePathCandidateScore[];
173
+ }
174
+
175
+ export const isServiceRoutingProfile = (valueArg: unknown): valueArg is TServiceRoutingProfile =>
176
+ typeof valueArg === 'string' && (serviceRoutingProfiles as readonly string[]).includes(valueArg);
177
+
178
+ const normalizeIpToken = (valueArg: string): string => valueArg.trim().toLowerCase().replace(/^\[|\]$/g, '');
179
+
180
+ /**
181
+ * Enforces the strict loop-free production DAG `RemoteIngress -> dcrouter -> Service`.
182
+ * Production routes MUST NOT target a known RemoteIngress edge public IP or peer dcrouter ingress IP.
183
+ */
184
+ export const isProductionRoutingLoopTarget = (
185
+ targetHostArg: string,
186
+ knownEdgePublicIpsArg: readonly string[],
187
+ peerGatewayIngressIpsArg: readonly string[],
188
+ ): boolean => {
189
+ const normalizedTarget = normalizeIpToken(targetHostArg);
190
+ if (!normalizedTarget) return false;
191
+ for (const ip of knownEdgePublicIpsArg) {
192
+ if (normalizeIpToken(ip) === normalizedTarget) return true;
193
+ }
194
+ for (const ip of peerGatewayIngressIpsArg) {
195
+ if (normalizeIpToken(ip) === normalizedTarget) return true;
196
+ }
197
+ return false;
198
+ };
199
+
200
+ /**
201
+ * Computes a deterministic phase-staggered + jittered probe delay so checks across many services
202
+ * spread smoothly across `intervalMs` instead of firing in synchronized bursts.
203
+ */
204
+ export const computeStaggeredProbeDelayMs = (
205
+ targetKeyArg: string,
206
+ intervalMsArg: number,
207
+ jitterRatioArg: number = pathRoutingContract.defaultProbeJitterRatio,
208
+ randomUnitArg: number = Math.random(),
209
+ ): number => {
210
+ const interval = Math.max(1_000, Math.floor(intervalMsArg));
211
+ // 32-bit FNV-1a hash for stable phase distribution across targets
212
+ let hash = 0x811c9dc5;
213
+ for (let i = 0; i < targetKeyArg.length; i += 1) {
214
+ hash ^= targetKeyArg.charCodeAt(i);
215
+ hash = Math.imul(hash, 0x01000193) >>> 0;
216
+ }
217
+ const baseOffset = hash % interval;
218
+ const clampedJitter = Math.max(0, Math.min(0.5, jitterRatioArg));
219
+ const clampedUnit = Math.max(0, Math.min(1, randomUnitArg));
220
+ const jitterSpan = Math.floor(interval * clampedJitter);
221
+ const jitterDelta = Math.floor((clampedUnit * 2 - 1) * jitterSpan);
222
+ return Math.max(0, (baseOffset + jitterDelta + interval) % interval);
223
+ };
224
+
225
+ /**
226
+ * Scores one candidate path `RemoteIngress edge (e) -> dcrouter (d) -> backend (s)`.
227
+ * Higher score is better; unhealthy/stale/disconnected paths receive score 0.
228
+ */
229
+ export const scoreServicePathCandidate = (paramsArg: {
230
+ gatewayId: string;
231
+ edge: IRemoteIngressEdgePathSample;
232
+ backend: IGatewayBackendPathSample;
233
+ profile: TServiceRoutingProfile;
234
+ nowMs: number;
235
+ maxStaleMs?: number;
236
+ }): IServicePathCandidateScore => {
237
+ const { gatewayId, edge, backend, profile, nowMs } = paramsArg;
238
+ const maxStaleMs = paramsArg.maxStaleMs ?? pathRoutingContract.defaultSampleStaleMs;
239
+
240
+ const baseResult: Omit<IServicePathCandidateScore, 'healthy' | 'degraded' | 'effectiveRttMs' | 'effectiveThroughputMbps' | 'score' | 'disqualifyReason'> = {
241
+ gatewayId,
242
+ edgeId: edge.edgeId,
243
+ edgePublicIpv4: edge.publicIpv4,
244
+ edgePublicIpv6: edge.publicIpv6,
245
+ };
246
+
247
+ if (!edge.connected) {
248
+ return { ...baseResult, healthy: false, degraded: true, effectiveRttMs: null, effectiveThroughputMbps: null, score: 0, disqualifyReason: 'edge-disconnected' };
249
+ }
250
+ if (!edge.publicIpv4 && !edge.publicIpv6) {
251
+ return { ...baseResult, healthy: false, degraded: true, effectiveRttMs: null, effectiveThroughputMbps: null, score: 0, disqualifyReason: 'edge-no-public-ip' };
252
+ }
253
+ if (!backend.reachable || backend.consecutiveFailures >= 3) {
254
+ return { ...baseResult, healthy: false, degraded: true, effectiveRttMs: null, effectiveThroughputMbps: null, score: 0, disqualifyReason: 'backend-unreachable' };
255
+ }
256
+ if (nowMs - edge.observedAt > maxStaleMs || nowMs - backend.observedAt > maxStaleMs) {
257
+ return { ...baseResult, healthy: false, degraded: true, effectiveRttMs: null, effectiveThroughputMbps: null, score: 0, disqualifyReason: 'telemetry-stale' };
258
+ }
259
+
260
+ const edgeRtt = edge.rttMs !== null && edge.rttMs >= 0 ? edge.rttMs : 25;
261
+ const backendRtt = backend.rttMs !== null && backend.rttMs >= 0
262
+ ? backend.rttMs
263
+ : (backend.p95TtfbMs !== null && backend.p95TtfbMs >= 0 ? backend.p95TtfbMs : 25);
264
+ const effectiveRttMs = Math.round((edgeRtt + backendRtt) * 100) / 100;
265
+
266
+ // Bottleneck throughput of the two-hop path = min(hop1, hop2)
267
+ let effectiveThroughputMbps: number | null = null;
268
+ if (edge.throughputMbps !== null && backend.throughputMbps !== null) {
269
+ effectiveThroughputMbps = Math.min(edge.throughputMbps, backend.throughputMbps);
270
+ } else if (edge.throughputMbps !== null) {
271
+ effectiveThroughputMbps = edge.throughputMbps;
272
+ } else if (backend.throughputMbps !== null) {
273
+ effectiveThroughputMbps = backend.throughputMbps;
274
+ }
275
+ const throughputForScore = effectiveThroughputMbps !== null && effectiveThroughputMbps > 0 ? effectiveThroughputMbps : 100;
276
+
277
+ // Normalized components in (0, 1]
278
+ const latencyComponent = 1 / (1 + effectiveRttMs / 50);
279
+ const throughputComponent = Math.min(1, Math.log10(1 + throughputForScore) / 3); // ~1.0 at 1000 Mbps
280
+
281
+ const weights = profile === 'latency'
282
+ ? { latency: 0.78, throughput: 0.22 }
283
+ : profile === 'throughput'
284
+ ? { latency: 0.25, throughput: 0.75 }
285
+ : { latency: 0.55, throughput: 0.45 };
286
+
287
+ let rawScore = (weights.latency * latencyComponent + weights.throughput * throughputComponent) * 100;
288
+
289
+ // Apply degradation penalties
290
+ const degraded =
291
+ backend.errorRate >= 0.05
292
+ || backend.consecutiveFailures > 0
293
+ || edge.stalledStreams > 0
294
+ || edge.blackHolesDetected > 0
295
+ || edge.fallbackUsed
296
+ || edge.dataQueueDepth > 256;
297
+
298
+ if (backend.errorRate > 0) {
299
+ rawScore *= Math.max(0.1, 1 - Math.min(0.9, backend.errorRate * 4));
300
+ }
301
+ if (edge.stalledStreams > 0) rawScore *= 0.75;
302
+ if (edge.blackHolesDetected > 0) rawScore *= 0.7;
303
+ if (edge.fallbackUsed) rawScore *= 0.85;
304
+ if (backend.consecutiveFailures > 0) rawScore *= 0.6;
305
+
306
+ const score = Math.max(0.01, Math.round(rawScore * 100) / 100);
307
+ return {
308
+ ...baseResult,
309
+ healthy: true,
310
+ degraded,
311
+ effectiveRttMs,
312
+ effectiveThroughputMbps,
313
+ score,
314
+ disqualifyReason: null,
315
+ };
316
+ };
317
+
318
+ /**
319
+ * Selects the optimal healthy `(edge, dcrouter)` path for one service, enforcing:
320
+ * - Immediate failover on hard failure or severe degradation (zero dwell wait).
321
+ * - Hysteresis margin + minimum dwell time when moving a healthy service to a faster healthy path.
322
+ */
323
+ export const selectOptimalServicePath = (paramsArg: {
324
+ policy: IServicePathPolicy;
325
+ candidates: IServicePathCandidateScore[];
326
+ previous: IServicePathDecision | null;
327
+ nowMs: number;
328
+ }): IServicePathDecision => {
329
+ const { policy, candidates, previous, nowMs } = paramsArg;
330
+ const sorted = [...candidates].sort((a, b) => (
331
+ b.score - a.score
332
+ || a.gatewayId.localeCompare(b.gatewayId)
333
+ || a.edgeId.localeCompare(b.edgeId)
334
+ ));
335
+ const healthy = sorted.filter((c) => c.healthy);
336
+
337
+ const makeDecision = (
338
+ chosen: IServicePathCandidateScore | null,
339
+ switchReason: TPathSwitchReason,
340
+ switched: boolean,
341
+ ): IServicePathDecision => ({
342
+ serviceId: policy.serviceId,
343
+ hostname: policy.hostname,
344
+ targetKey: policy.targetKey,
345
+ selectedGatewayId: chosen?.gatewayId ?? null,
346
+ selectedEdgeId: chosen?.edgeId ?? null,
347
+ selectedPublicIpv4: chosen?.edgePublicIpv4 ?? null,
348
+ selectedPublicIpv6: chosen?.edgePublicIpv6 ?? null,
349
+ selectedScore: chosen?.score ?? null,
350
+ effectiveRttMs: chosen?.effectiveRttMs ?? null,
351
+ effectiveThroughputMbps: chosen?.effectiveThroughputMbps ?? null,
352
+ switchReason,
353
+ decidedAt: nowMs,
354
+ lastSwitchedAt: switched ? nowMs : (previous?.lastSwitchedAt ?? null),
355
+ candidates: sorted,
356
+ });
357
+
358
+ if (healthy.length === 0) {
359
+ return makeDecision(null, 'no-healthy-path', previous?.selectedEdgeId !== null);
360
+ }
361
+
362
+ // Respect explicit operator pin when healthy
363
+ if (policy.pinnedGatewayId || policy.pinnedEdgeId) {
364
+ const pinned = healthy.find((c) => (
365
+ (!policy.pinnedGatewayId || c.gatewayId === policy.pinnedGatewayId)
366
+ && (!policy.pinnedEdgeId || c.edgeId === policy.pinnedEdgeId)
367
+ ));
368
+ if (pinned) {
369
+ const changed = previous?.selectedGatewayId !== pinned.gatewayId || previous?.selectedEdgeId !== pinned.edgeId;
370
+ return makeDecision(pinned, 'pinned', changed);
371
+ }
372
+ }
373
+
374
+ const best = healthy[0];
375
+ if (!previous || !previous.selectedGatewayId || !previous.selectedEdgeId) {
376
+ return makeDecision(best, 'initial', true);
377
+ }
378
+
379
+ const current = sorted.find(
380
+ (c) => c.gatewayId === previous.selectedGatewayId && c.edgeId === previous.selectedEdgeId,
381
+ );
382
+
383
+ // Instant failover if current path disappeared or became unhealthy
384
+ if (!current || !current.healthy) {
385
+ return makeDecision(best, 'failover', true);
386
+ }
387
+
388
+ // If current path is already the top candidate, retain cleanly
389
+ if (current.gatewayId === best.gatewayId && current.edgeId === best.edgeId) {
390
+ return makeDecision(current, previous.switchReason === 'no-healthy-path' ? 'initial' : previous.switchReason, false);
391
+ }
392
+
393
+ // Immediate switch if current path is degraded and best is clean (non-degraded)
394
+ if (current.degraded && !best.degraded) {
395
+ return makeDecision(best, 'degradation', true);
396
+ }
397
+
398
+ // Healthy -> faster healthy path requires hysteresis margin + minimum dwell time
399
+ const margin = Math.max(0, policy.hysteresisMargin);
400
+ const improvement = current.score > 0 ? (best.score - current.score) / current.score : 1;
401
+ if (improvement < margin) {
402
+ return makeDecision(current, 'retained-hysteresis', false);
403
+ }
404
+ const lastSwitch = previous.lastSwitchedAt ?? 0;
405
+ if (nowMs - lastSwitch < Math.max(0, policy.minDwellMs)) {
406
+ return makeDecision(current, 'retained-dwell', false);
407
+ }
408
+
409
+ return makeDecision(best, 'optimization', true);
410
+ };
@@ -0,0 +1,275 @@
1
+ import type { ITypedRequest, implementsTR } from '@api.global/typedrequest-interfaces';
2
+ import type {
3
+ IBackupMxDesiredState,
4
+ IBackupMxInstance,
5
+ IBackupMxQueueItemSummary,
6
+ IBackupMxStatus,
7
+ TBackupMxRefusalCode,
8
+ } from '../data/backupmx.js';
9
+ import type { IControllerPeerSet } from '../data/controller.js';
10
+ import type { IIdentityCredential } from '../data/user.js';
11
+
12
+ // ---------------------------------------------------------------------------------------------
13
+ // TypedSocket session protocol (Backup MX daemon <-> Cloudly)
14
+ // ---------------------------------------------------------------------------------------------
15
+
16
+ /** Sent by `@serve.zone/backupmx` immediately after opening its outbound TypedSocket to Cloudly. */
17
+ export interface IReq_BackupMx_Cloudly_Authenticate extends implementsTR<
18
+ ITypedRequest,
19
+ IReq_BackupMx_Cloudly_Authenticate
20
+ > {
21
+ method: 'backupMxAuthenticate';
22
+ request: {
23
+ instanceId: string;
24
+ credentialSecret: string;
25
+ version: string;
26
+ appliedConfigEpoch: number;
27
+ };
28
+ response: {
29
+ ok: true;
30
+ controllerPeerSet: IControllerPeerSet;
31
+ desiredConfigEpoch: number;
32
+ } | {
33
+ ok: false;
34
+ code: TBackupMxRefusalCode;
35
+ message: string;
36
+ };
37
+ }
38
+
39
+ /** Periodic or event-driven status & queue counter report from Backup MX daemon to Cloudly. */
40
+ export interface IReq_BackupMx_Cloudly_ReportStatus extends implementsTR<
41
+ ITypedRequest,
42
+ IReq_BackupMx_Cloudly_ReportStatus
43
+ > {
44
+ method: 'backupMxReportStatus';
45
+ request: {
46
+ status: IBackupMxStatus;
47
+ };
48
+ response: {
49
+ acknowledged: true;
50
+ };
51
+ }
52
+
53
+ /** Pushed by Cloudly to a connected Backup MX daemon over the live TypedSocket session. */
54
+ export interface IReq_Cloudly_BackupMx_ApplyDesiredState extends implementsTR<
55
+ ITypedRequest,
56
+ IReq_Cloudly_BackupMx_ApplyDesiredState
57
+ > {
58
+ method: 'applyBackupMxDesiredState';
59
+ request: {
60
+ controllerPeerSet: IControllerPeerSet;
61
+ desiredState: IBackupMxDesiredState;
62
+ };
63
+ response: {
64
+ ok: true;
65
+ appliedConfigEpoch: number;
66
+ status: IBackupMxStatus;
67
+ } | {
68
+ ok: false;
69
+ code: TBackupMxRefusalCode;
70
+ message: string;
71
+ };
72
+ }
73
+
74
+ /** Called by Cloudly over the live TypedSocket session to inspect pending or dead queue metadata. */
75
+ export interface IReq_Cloudly_BackupMx_ListQueueItems extends implementsTR<
76
+ ITypedRequest,
77
+ IReq_Cloudly_BackupMx_ListQueueItems
78
+ > {
79
+ method: 'listBackupMxQueueItems';
80
+ request: {
81
+ queue: 'pending' | 'dead';
82
+ domain?: string;
83
+ limit?: number;
84
+ };
85
+ response: {
86
+ items: IBackupMxQueueItemSummary[];
87
+ total: number;
88
+ };
89
+ }
90
+
91
+ /** Re-queues one dead-letter message back into `pending` for immediate retry. */
92
+ export interface IReq_Cloudly_BackupMx_RetryDeadItem extends implementsTR<
93
+ ITypedRequest,
94
+ IReq_Cloudly_BackupMx_RetryDeadItem
95
+ > {
96
+ method: 'retryBackupMxDeadItem';
97
+ request: {
98
+ queueId: string;
99
+ };
100
+ response: {
101
+ ok: true;
102
+ } | {
103
+ ok: false;
104
+ code: TBackupMxRefusalCode;
105
+ message: string;
106
+ };
107
+ }
108
+
109
+ /** Permanently deletes one dead-letter message from disk. */
110
+ export interface IReq_Cloudly_BackupMx_PurgeDeadItem extends implementsTR<
111
+ ITypedRequest,
112
+ IReq_Cloudly_BackupMx_PurgeDeadItem
113
+ > {
114
+ method: 'purgeBackupMxDeadItem';
115
+ request: {
116
+ queueId: string;
117
+ };
118
+ response: {
119
+ ok: true;
120
+ } | {
121
+ ok: false;
122
+ code: TBackupMxRefusalCode;
123
+ message: string;
124
+ };
125
+ }
126
+
127
+ // ---------------------------------------------------------------------------------------------
128
+ // Cloudly Administrator API
129
+ // ---------------------------------------------------------------------------------------------
130
+
131
+ export interface IReq_Admin_Cloudly_CreateBackupMxInstance extends implementsTR<
132
+ ITypedRequest,
133
+ IReq_Admin_Cloudly_CreateBackupMxInstance
134
+ > {
135
+ method: 'createBackupMxInstance';
136
+ request: {
137
+ identity: IIdentityCredential;
138
+ name: string;
139
+ hostname: string;
140
+ mxPriority?: number;
141
+ ipv4?: string | null;
142
+ ipv6?: string | null;
143
+ hetznerHostId?: string | null;
144
+ enabled?: boolean;
145
+ };
146
+ response: {
147
+ ok: true;
148
+ instance: IBackupMxInstance;
149
+ /** Returned once on creation for manual hosts; Hetzner hosts receive it via claimManagedHostEnrollment. */
150
+ enrollmentSecret?: string;
151
+ } | {
152
+ ok: false;
153
+ code: TBackupMxRefusalCode;
154
+ message: string;
155
+ };
156
+ }
157
+
158
+ export interface IReq_Admin_Cloudly_UpdateBackupMxInstance extends implementsTR<
159
+ ITypedRequest,
160
+ IReq_Admin_Cloudly_UpdateBackupMxInstance
161
+ > {
162
+ method: 'updateBackupMxInstance';
163
+ request: {
164
+ identity: IIdentityCredential;
165
+ instanceId: string;
166
+ name?: string;
167
+ hostname?: string;
168
+ mxPriority?: number;
169
+ ipv4?: string | null;
170
+ ipv6?: string | null;
171
+ enabled?: boolean;
172
+ };
173
+ response: {
174
+ ok: true;
175
+ instance: IBackupMxInstance;
176
+ } | {
177
+ ok: false;
178
+ code: TBackupMxRefusalCode;
179
+ message: string;
180
+ };
181
+ }
182
+
183
+ export interface IReq_Admin_Cloudly_DeleteBackupMxInstance extends implementsTR<
184
+ ITypedRequest,
185
+ IReq_Admin_Cloudly_DeleteBackupMxInstance
186
+ > {
187
+ method: 'deleteBackupMxInstance';
188
+ request: {
189
+ identity: IIdentityCredential;
190
+ instanceId: string;
191
+ forceNonEmptyQueue?: boolean;
192
+ };
193
+ response: {
194
+ ok: true;
195
+ deleted: true;
196
+ } | {
197
+ ok: false;
198
+ code: TBackupMxRefusalCode;
199
+ message: string;
200
+ };
201
+ }
202
+
203
+ export interface IReq_Admin_Cloudly_ListBackupMxInstances extends implementsTR<
204
+ ITypedRequest,
205
+ IReq_Admin_Cloudly_ListBackupMxInstances
206
+ > {
207
+ method: 'listBackupMxInstances';
208
+ request: {
209
+ identity: IIdentityCredential;
210
+ };
211
+ response: {
212
+ instances: IBackupMxInstance[];
213
+ };
214
+ }
215
+
216
+ export interface IReq_Admin_Cloudly_ListBackupMxInstanceQueue extends implementsTR<
217
+ ITypedRequest,
218
+ IReq_Admin_Cloudly_ListBackupMxInstanceQueue
219
+ > {
220
+ method: 'listBackupMxInstanceQueue';
221
+ request: {
222
+ identity: IIdentityCredential;
223
+ instanceId: string;
224
+ queue: 'pending' | 'dead';
225
+ domain?: string;
226
+ limit?: number;
227
+ };
228
+ response: {
229
+ ok: true;
230
+ items: IBackupMxQueueItemSummary[];
231
+ total: number;
232
+ } | {
233
+ ok: false;
234
+ code: TBackupMxRefusalCode;
235
+ message: string;
236
+ };
237
+ }
238
+
239
+ export interface IReq_Admin_Cloudly_RetryBackupMxInstanceDeadItem extends implementsTR<
240
+ ITypedRequest,
241
+ IReq_Admin_Cloudly_RetryBackupMxInstanceDeadItem
242
+ > {
243
+ method: 'retryBackupMxInstanceDeadItem';
244
+ request: {
245
+ identity: IIdentityCredential;
246
+ instanceId: string;
247
+ queueId: string;
248
+ };
249
+ response: {
250
+ ok: true;
251
+ } | {
252
+ ok: false;
253
+ code: TBackupMxRefusalCode;
254
+ message: string;
255
+ };
256
+ }
257
+
258
+ export interface IReq_Admin_Cloudly_PurgeBackupMxInstanceDeadItem extends implementsTR<
259
+ ITypedRequest,
260
+ IReq_Admin_Cloudly_PurgeBackupMxInstanceDeadItem
261
+ > {
262
+ method: 'purgeBackupMxInstanceDeadItem';
263
+ request: {
264
+ identity: IIdentityCredential;
265
+ instanceId: string;
266
+ queueId: string;
267
+ };
268
+ response: {
269
+ ok: true;
270
+ } | {
271
+ ok: false;
272
+ code: TBackupMxRefusalCode;
273
+ message: string;
274
+ };
275
+ }