@serve.zone/interfaces 32.124.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.
@@ -0,0 +1,273 @@
1
+ export const externalDnsProviderTypes = Object.freeze([
2
+ 'cloudflare',
3
+ ] as const);
4
+
5
+ export type TExternalDnsProviderType = typeof externalDnsProviderTypes[number];
6
+
7
+ export const externalDnsRecordTypes = Object.freeze([
8
+ 'A',
9
+ 'AAAA',
10
+ 'CNAME',
11
+ 'TXT',
12
+ 'MX',
13
+ 'SRV',
14
+ 'CAA',
15
+ 'NS',
16
+ ] as const);
17
+
18
+ export type TExternalDnsRecordType = typeof externalDnsRecordTypes[number];
19
+
20
+ export const externalDnsRefusalCodes = Object.freeze([
21
+ 'administrator-required',
22
+ 'fresh-sign-in-required',
23
+ 'invalid-request',
24
+ 'provider-not-found',
25
+ 'provider-name-conflict',
26
+ 'provider-in-use',
27
+ 'zone-not-found',
28
+ 'record-not-found',
29
+ 'record-conflict',
30
+ 'precondition-failed',
31
+ 'provider-unavailable',
32
+ 'protected-hostname',
33
+ 'invalid-record-value',
34
+ 'mutation-not-found',
35
+ ] as const);
36
+
37
+ export type TExternalDnsRefusalCode = typeof externalDnsRefusalCodes[number];
38
+
39
+ export const externalDnsMutationActions = Object.freeze([
40
+ 'create',
41
+ 'update',
42
+ 'delete',
43
+ 'takeover',
44
+ 'rollback',
45
+ ] as const);
46
+
47
+ export type TExternalDnsMutationAction = typeof externalDnsMutationActions[number];
48
+
49
+ export const externalDnsContract = Object.freeze({
50
+ managementMarkerPrefix: 'servezone:cloudly:',
51
+ defaultTtlSeconds: 60,
52
+ minimumTtlSeconds: 1,
53
+ maximumTtlSeconds: 86_400,
54
+ maximumProviderNameLength: 160,
55
+ maximumHostnameLength: 253,
56
+ maximumRecordValueLength: 4_096,
57
+ maximumBatchRecords: 200,
58
+ } as const);
59
+
60
+ export interface IExternalDnsProviderTokenMetadata {
61
+ configured: boolean;
62
+ updatedAt: number | null;
63
+ /** Short SHA-256 prefix fingerprint (never the token itself). */
64
+ fingerprint: string | null;
65
+ }
66
+
67
+ export interface IExternalDnsProvider {
68
+ id: string;
69
+ name: string;
70
+ type: TExternalDnsProviderType;
71
+ enabled: boolean;
72
+ token: IExternalDnsProviderTokenMetadata;
73
+ status: 'untested' | 'ok' | 'error';
74
+ lastTestedAt: number | null;
75
+ lastSyncedAt: number | null;
76
+ lastError: string | null;
77
+ zoneCount: number;
78
+ createdAt: number;
79
+ updatedAt: number;
80
+ }
81
+
82
+ export interface IExternalDnsZone {
83
+ id: string;
84
+ providerId: string;
85
+ name: string;
86
+ externalZoneId: string;
87
+ nameservers: string[];
88
+ recordCount: number;
89
+ lastSyncedAt: number;
90
+ createdAt: number;
91
+ updatedAt: number;
92
+ }
93
+
94
+ export interface IExternalDnsRecord {
95
+ id: string;
96
+ providerId: string;
97
+ zoneName: string;
98
+ providerRecordId: string;
99
+ name: string;
100
+ type: TExternalDnsRecordType;
101
+ value: string;
102
+ ttl: number;
103
+ proxied: boolean;
104
+ ownership: 'cloudly' | 'unmanaged';
105
+ managementMarker: string | null;
106
+ ownerKey: string | null;
107
+ updatedAt: number;
108
+ }
109
+
110
+ export interface IExternalDnsDesiredRecord {
111
+ name: string;
112
+ type: TExternalDnsRecordType;
113
+ value: string;
114
+ ttl?: number;
115
+ proxied?: boolean;
116
+ /** Stable Cloudly ownership key (e.g. `service:<id>` or `control-plane:cloudly`). */
117
+ ownerKey: string;
118
+ }
119
+
120
+ export interface IExternalDnsConflict {
121
+ fqdn: string;
122
+ zoneName: string;
123
+ providerId: string;
124
+ blockingRecords: IExternalDnsRecord[];
125
+ desiredRecords: IExternalDnsDesiredRecord[];
126
+ detectedAt: number;
127
+ message: string;
128
+ }
129
+
130
+ export interface IExternalDnsTakeoverPreview {
131
+ fqdn: string;
132
+ zoneName: string;
133
+ providerId: string;
134
+ blockingRecords: IExternalDnsRecord[];
135
+ desiredRecords: IExternalDnsDesiredRecord[];
136
+ willReplaceRecordIds: string[];
137
+ }
138
+
139
+ export interface IExternalDnsRecordSnapshot {
140
+ providerRecordId: string;
141
+ name: string;
142
+ type: TExternalDnsRecordType;
143
+ value: string;
144
+ ttl: number;
145
+ proxied: boolean;
146
+ managementMarker: string | null;
147
+ }
148
+
149
+ export interface IExternalDnsMutationJournalEntry {
150
+ id: string;
151
+ providerId: string;
152
+ zoneName: string;
153
+ fqdn: string;
154
+ action: TExternalDnsMutationAction;
155
+ actorId: string;
156
+ reason: string | null;
157
+ previousRecords: IExternalDnsRecordSnapshot[];
158
+ resultingRecords: IExternalDnsRecordSnapshot[];
159
+ rolledBackByMutationId: string | null;
160
+ createdAt: number;
161
+ }
162
+
163
+ export interface IExternalDnsReconcileSummary {
164
+ providerId: string;
165
+ zoneName: string;
166
+ applied: number;
167
+ unchanged: number;
168
+ deleted: number;
169
+ conflicts: IExternalDnsConflict[];
170
+ }
171
+
172
+ const hostnameLabelPattern = /^[a-z0-9_](?:[a-z0-9_-]{0,61}[a-z0-9])?$/;
173
+
174
+ export const isExternalDnsProviderType = (valueArg: unknown): valueArg is TExternalDnsProviderType =>
175
+ typeof valueArg === 'string' && (externalDnsProviderTypes as readonly string[]).includes(valueArg);
176
+
177
+ export const isExternalDnsRecordType = (valueArg: unknown): valueArg is TExternalDnsRecordType =>
178
+ typeof valueArg === 'string' && (externalDnsRecordTypes as readonly string[]).includes(valueArg);
179
+
180
+ export const normalizeExternalDnsName = (nameArg: unknown): string | null => {
181
+ if (typeof nameArg !== 'string') return null;
182
+ const trimmed = nameArg.trim().toLowerCase().replace(/\.+$/, '');
183
+ if (trimmed.length === 0 || trimmed.length > externalDnsContract.maximumHostnameLength) return null;
184
+ const labels = trimmed.split('.');
185
+ if (labels.length < 2) return null;
186
+ const [first, ...rest] = labels;
187
+ const firstValid = first === '*' ? rest.length > 0 : hostnameLabelPattern.test(first);
188
+ if (!firstValid || !rest.every((labelArg) => hostnameLabelPattern.test(labelArg))) return null;
189
+ return trimmed;
190
+ };
191
+
192
+ export const normalizeExternalDnsZone = (zoneArg: unknown): string | null => {
193
+ const normalized = normalizeExternalDnsName(zoneArg);
194
+ if (!normalized || normalized.startsWith('*.')) return null;
195
+ return normalized;
196
+ };
197
+
198
+ export const isHostnameInZone = (fqdnArg: string, zoneNameArg: string): boolean => {
199
+ const fqdn = normalizeExternalDnsName(fqdnArg);
200
+ const zone = normalizeExternalDnsZone(zoneNameArg);
201
+ if (!fqdn || !zone) return false;
202
+ return fqdn === zone || fqdn.endsWith(`.${zone}`);
203
+ };
204
+
205
+ export const createCloudlyManagementMarker = (ownerKeyArg: string): string => {
206
+ const sanitized = ownerKeyArg.trim().replace(/\s+/g, '');
207
+ if (!sanitized || sanitized.length > 160) {
208
+ throw new Error('ownerKey must be a non-empty string of at most 160 characters');
209
+ }
210
+ return `${externalDnsContract.managementMarkerPrefix}${sanitized}`;
211
+ };
212
+
213
+ export const parseCloudlyManagementMarker = (markerArg: unknown): string | null => {
214
+ if (typeof markerArg !== 'string') return null;
215
+ const trimmed = markerArg.trim();
216
+ if (!trimmed.startsWith(externalDnsContract.managementMarkerPrefix)) return null;
217
+ const ownerKey = trimmed.slice(externalDnsContract.managementMarkerPrefix.length).trim();
218
+ return ownerKey.length > 0 ? ownerKey : null;
219
+ };
220
+
221
+ export const isCloudlyManagedMarker = (markerArg: unknown): boolean =>
222
+ parseCloudlyManagementMarker(markerArg) !== null;
223
+
224
+ /**
225
+ * Returns true when an existing record at the same FQDN conflicts with writing a desired record.
226
+ * CNAME records conflict with any other record type at the same name (RFC 1034 §3.6.2);
227
+ * otherwise records of the same type conflict unless owned by Cloudly.
228
+ */
229
+ export const isConflictingDnsRecordType = (
230
+ existingTypeArg: TExternalDnsRecordType,
231
+ desiredTypeArg: TExternalDnsRecordType,
232
+ ): boolean => {
233
+ if (existingTypeArg === desiredTypeArg) return true;
234
+ return existingTypeArg === 'CNAME' || desiredTypeArg === 'CNAME';
235
+ };
236
+
237
+ export const validateExternalDnsDesiredRecord = (recordArg: unknown): string[] => {
238
+ const errors: string[] = [];
239
+ if (recordArg === null || typeof recordArg !== 'object' || Array.isArray(recordArg)) {
240
+ return ['desired record must be an object'];
241
+ }
242
+ const candidate = recordArg as Record<string, unknown>;
243
+ if (normalizeExternalDnsName(candidate.name) === null) {
244
+ errors.push('name must be a valid DNS hostname');
245
+ }
246
+ if (!isExternalDnsRecordType(candidate.type)) {
247
+ errors.push('type must be a supported DNS record type');
248
+ }
249
+ if (
250
+ typeof candidate.value !== 'string'
251
+ || candidate.value.trim().length === 0
252
+ || candidate.value.length > externalDnsContract.maximumRecordValueLength
253
+ ) {
254
+ errors.push('value must be a non-empty string within maximum length');
255
+ }
256
+ if (candidate.ttl !== undefined) {
257
+ if (
258
+ typeof candidate.ttl !== 'number'
259
+ || !Number.isInteger(candidate.ttl)
260
+ || candidate.ttl < externalDnsContract.minimumTtlSeconds
261
+ || candidate.ttl > externalDnsContract.maximumTtlSeconds
262
+ ) {
263
+ errors.push('ttl must be an integer between 1 and 86400');
264
+ }
265
+ }
266
+ if (candidate.proxied !== undefined && typeof candidate.proxied !== 'boolean') {
267
+ errors.push('proxied must be a boolean when provided');
268
+ }
269
+ if (typeof candidate.ownerKey !== 'string' || candidate.ownerKey.trim().length === 0 || candidate.ownerKey.trim().length > 160) {
270
+ errors.push('ownerKey must be a non-empty string of at most 160 characters');
271
+ }
272
+ return errors;
273
+ };
@@ -287,6 +287,12 @@ export interface IGatewayCapabilities {
287
287
  configEvents?: true;
288
288
  /** The adopted controller session serves `readGatewayServiceHealth`. */
289
289
  serviceHealth?: true;
290
+ /** Multi-gateway optimal path routing capabilities advertised by the gateway. */
291
+ routing?: {
292
+ pathTelemetry?: true;
293
+ pathProbing?: true;
294
+ loopGuard?: true;
295
+ };
290
296
  routes: {
291
297
  read: boolean;
292
298
  write: boolean;
@@ -323,6 +329,11 @@ export interface IGatewayCapabilities {
323
329
  storeManagement?: true;
324
330
  /** Related wildcard import against an observed legacy backing on the adopted session. */
325
331
  storeRelatedImport?: true;
332
+ /**
333
+ * When `true`, Cloudly owns ACME issuance and pushes leaf certificate bundles to the gateway
334
+ * via `pushGatewayCertificateBundle`; the gateway disables local ACME issuance.
335
+ */
336
+ controllerPushed?: true;
326
337
  };
327
338
  email: {
328
339
  domains: boolean;
@@ -358,6 +369,12 @@ export interface IGatewayCapabilities {
358
369
  providerManaged: boolean;
359
370
  /** The adopted connector serves redacted DNS diagnostics and stored-credential connection tests. */
360
371
  operations?: true;
372
+ /**
373
+ * When `true`, Cloudly owns external DNS providers (e.g. Cloudflare) directly: Cloudly strips
374
+ * external provider rows and API tokens from the gateway's pushed `dns` area, and the gateway
375
+ * skips external provider mirroring and external route DNS reconciliation.
376
+ */
377
+ externalProvidersDisabled?: true;
361
378
  /** The adopted connector pages records from its durable provider-zone mirror; no provider call is made. */
362
379
  providerRecords?: true;
363
380
  /**
package/ts/data/index.ts CHANGED
@@ -28,6 +28,7 @@ export * from './deploymentpreflight.js';
28
28
  export * from './deploymentreleaseredeploy.js';
29
29
  export * from './migration.js';
30
30
  export * from './dns.js';
31
+ export * from './externaldns.js';
31
32
  export * from './docker.js';
32
33
  export * from './domain.js';
33
34
  export * from './event.js';
@@ -94,6 +95,8 @@ export * from './baremetal.js';
94
95
  export * from './baseos.js';
95
96
  export * from './backup.js';
96
97
  export * from './backupmx.js';
98
+ export * from './certificateauthority.js';
99
+ export * from './pathrouting.js';
97
100
  export * from './backuprestorerefusal.js';
98
101
  export * from './hetzner.js';
99
102
  export * from './clusternode.js';