@serve.zone/interfaces 32.86.0 → 32.87.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/readme.md CHANGED
@@ -4391,6 +4391,19 @@ guard that names roles excludes it by type.
4391
4391
  stored one) and `forward-sources-exceed-allowlist` (a `new` adoption whose forward sources would
4392
4392
  make the union of every gateway's forward source prefixes exceed one cluster ingress allowlist; the
4393
4393
  code stays unconsumed). An unknown location stays `location-not-found` (`data.locationRefusals`).
4394
+ `local-changing-during-export` is the one momentary refusal (`data.gatewayConnectorMomentaryRefusals`),
4395
+ and `exportGatewayArea` its only request: local writes of the area kept overtaking the read, so the
4396
+ gateway answers no table and the controller asks again later. It travels as
4397
+ `data.IGatewayConnectorMomentaryRefusalErrorData` (`{ code, retryable: true }`);
4398
+ `data.createGatewayConnectorRefusalErrorData` writes either payload, and
4399
+ `data.readGatewayConnectorRefusalErrorData` reads a payload whose `retryable` disagrees with its code,
4400
+ an unknown code or an extra member as no answer. `data.IGatewayConnectorRefusalErrorData` keeps its
4401
+ shape. A reader built on an earlier release does not know the code and reads the answer as a failure
4402
+ that names no refusal, never as an export. A consumer that moves to this release writes every
4403
+ connector refusal with `data.createGatewayConnectorRefusalErrorData` and reads every one with
4404
+ `data.readGatewayConnectorRefusalErrorData`, both in the same commit: a writer that keeps a
4405
+ hard-coded `retryable: false` would send the momentary code as a verdict, and a reader that keeps
4406
+ its own check would read it as one.
4394
4407
  - Revisions: `data.IControllerRevision` is one record of the controller-wide sequence, validated
4395
4408
  exactly by `data.validateControllerRevision`: the actor's `sub` is `null` exactly for `system`,
4396
4409
  the bounds of `data.controllerRevisionContract` only ever rise,
@@ -4435,6 +4448,10 @@ guard that names roles excludes it by type.
4435
4448
  first failure; `data.IGatewayApplyReport.appliedRevision` advances only when the whole document
4436
4449
  applied. Per-area refusals are `data.gatewayApplyRefusals` (`invalid-table`, `unsupported-area`,
4437
4450
  `area-owner-mismatch`, `local-changed-since-export`, `apply-failed`).
4451
+ The controller waits `data.gatewayConnectorContract.applyDesiredStateTimeoutMs` (10 s) for an
4452
+ answer, the one number both sides read: it is Cloudly's push timeout, and a gateway's takeover wait
4453
+ ends at half of it, so the controller still receives the gateway's refusal. No deadline travels in
4454
+ the request.
4438
4455
  - Owners: every area the controller owns on a gateway must be carried in each document.
4439
4456
  `area-owner-mismatch` is the per-area refusal of a document that disagrees with an area's owner on
4440
4457
  the gateway; the entry's `owner` says which side owns it, and nothing of the document applies. A
@@ -4444,8 +4461,8 @@ guard that names roles excludes it by type.
4444
4461
  `not-attempted`, and `appliedRevision` and `epoch` stay. `data.validateGatewayDesiredState` checks
4445
4462
  the envelope only and never this. A gateway-owned area no document carried reports `applied` with
4446
4463
  `revision: null`.
4447
- - Area content is untyped here (`content: unknown`); each area's content type and validator ship in
4448
- the release that moves that area. Its digest is `data.computeGatewayAreaTableDigest(area, content)`,
4464
+ - Area content is `unknown` in the envelope; its typed form is `data.TGatewayAreaContent<area>` and
4465
+ `data.validateGatewayAreaTables` judges it (see Gateway Area Contents). Its digest is `data.computeGatewayAreaTableDigest(area, content)`,
4449
4466
  `sha256:<hex>` of the strict canonical JSON of the domain `serve.zone/gateway-area-table`, the area
4450
4467
  and the content, which both sides compute.
4451
4468
  - Takeover: an area has one owner per gateway, `gateway` or `controller`, and moves to the controller
@@ -4454,6 +4471,23 @@ guard that names roles excludes it by type.
4454
4471
  `local-changed-since-export`. A takeover of a table the gateway already serves is a pure owner
4455
4472
  change, whatever `localDigest` says, and `takeover` is ignored for an area the controller already
4456
4473
  owns.
4474
+ - Route DNS results: the controller reads what the gateway's route DNS reconciler last observed
4475
+ with `getGatewayRouteDnsResults` (`requests.gatewayconnector.IReq_Cloudly_Gateway_GetGatewayRouteDnsResults`):
4476
+ 1 to `data.gatewayConnectorContract.maximumRouteDnsHostnames` (256) lowercase hostnames, strictly
4477
+ ascending (`data.validateGatewayRouteDnsResultsRequest`, else `request-invalid`), answered with one
4478
+ `{ hostname, result: data.IGatewayRouteDnsResult }` per hostname in request order (`not-applicable`
4479
+ for a hostname no enabled route serves) and `routesRevision`, the `{ epoch, revision }` of the routes
4480
+ table the reconciler pass ran against (`data.compareControllerRevisionOrder`), `null` for a table no
4481
+ controller pushed and whenever no pass has observed one of the requested hostnames yet (that
4482
+ hostname answers the retryable `zone-unavailable`). It is observed state: never an area table
4483
+ member, and not in the status document. The controller judges every answer with
4484
+ `data.validateGatewayRouteDnsResultsResponse(answer, request)` (exact keys, one entry per requested
4485
+ hostname in request order, each result by `data.validateGatewayRouteDnsResult` within
4486
+ `data.gatewayRouteDnsResultContract`). One text over its bound refuses the whole answer, so the
4487
+ gateway shortens every text (a provider's error in `message`, for example) to the bound before it
4488
+ answers. Peer gate: it calls the request only on a gateway whose hello
4489
+ states an `interfacesVersion` of the release that declares it or later; a gateway moves to that
4490
+ release only together with serving it.
4457
4491
  - Status: a gateway pushes its `data.IGatewayStatusDocument` (`pushGatewayStatus`) after its hello,
4458
4492
  after every apply and on change, at most once per
4459
4493
  `data.gatewayConnectorContract.minimumStatusPushIntervalMs` (5 s). `getGateways` lists the gateways
@@ -4470,7 +4504,8 @@ guard that names roles excludes it by type.
4470
4504
  `data.validateControllerRevision`, `data.validateGateway`, `data.validateGatewayAdoptionFacts`,
4471
4505
  `data.validateAdoptGatewayResponse`, `data.validateRegisterGatewaySessionRequest`,
4472
4506
  `data.validateGatewayDesiredState` (envelope only), `data.validateGatewayApplyReport`,
4473
- `data.validateGatewayStatusDocument` and `data.validateGatewayAreaExport`.
4507
+ `data.validateGatewayStatusDocument`, `data.validateGatewayAreaExport`,
4508
+ `data.validateGatewayRouteDnsResultsRequest` and `data.validateGatewayRouteDnsResultsResponse`.
4474
4509
 
4475
4510
  ```typescript
4476
4511
  import { data, requests } from '@serve.zone/interfaces';
@@ -4488,6 +4523,119 @@ const desired: requests.gatewayconnector.IReq_Cloudly_Gateway_ApplyDesiredState[
4488
4523
  data.validateGatewayDesiredState(desired.desired); // []
4489
4524
  ```
4490
4525
 
4526
+ ### Gateway Area Contents
4527
+
4528
+ The typed content of the five areas (Linus rulings 117 §2 and 121), one content type per shipped
4529
+ area name: `data.IGatewayAreaContents[area]`, also `data.TGatewayAreaContent<area>`. The envelope
4530
+ (`IGatewayAreaTable.content`, `IGatewayAreaExport.content`) is unchanged and stays `unknown`.
4531
+
4532
+ | Area | Row lists (keyed by `id`) | Singletons (object or `null`) |
4533
+ | --- | --- | --- |
4534
+ | `security` | `blockRules`, `apiTokens` | `proxyPolicy` |
4535
+ | `dns` | `nameservers`, `providers`, `domains`, `records`, `staticRecords`, `protectedHostnames`, `authorityZones`, `clientHostnames` | `server`, `acme` |
4536
+ | `routes` | `routes`, `sourceProfiles`, `networkTargets`, `targetProfiles`, `disabledSystemRoutes` | `http3` |
4537
+ | `mail` | `domains`, `smtpAccounts`, `identities`, `coreMailPeers` | `server` (always an object, never `null`: mail a gateway never configured is `enabled: false`, `outboundMode: 'remoteIngress'`, `emailConfig` and `tlsKey` `null`, no port configuration, `tlsSource: 'managedCertificate'`) |
4538
+ | `edges` | `edges` | `hub` (always an object, never `null`: a hub that is off is `enabled: false`) |
4539
+
4540
+ - Intent only: what an operator, a gateway client or the controller authored. Derived state
4541
+ (`managedBy` records, ACME challenges, DKIM public records and active selectors, redirects,
4542
+ HTTP-01 answers, reactive blocks, `email`/`dns` system routes), observed state (provider zones and
4543
+ their mirrored records, delegation evidence) and local state (VPN, DKIM private keys, the ACME
4544
+ account and certificate store, testing, gateway clients, host facts) are never in a table. DNS
4545
+ `records` hold records of `dcrouter`-source zones only.
4546
+ - Canonical form: exact keys, an absent value is `null`, and where the gateway reads an absent list
4547
+ as empty the canonical spelling is `[]`. Row lists are strictly ascending by
4548
+ `data.compareWireTokens` on `id`, rows hold no nested row lists. A set inside a typed member is
4549
+ strictly ascending; a list whose order carries meaning (`sourceBindings`, `extendsProfiles`, a
4550
+ network target's hosts) and every array inside engine configuration keep their stated order.
4551
+ Two honest sides therefore compute the same `computeGatewayAreaTableDigest`.
4552
+ - Engine configuration (`data.TGatewayEngineConfig`: SmartProxy routes, route security, rate limits,
4553
+ challenges and the proxy policy; SmartMTA's `emailConfig`) is a strict JSON object the gateway
4554
+ judges itself. Every type dcrouter declares is typed exactly here, not only those in its
4555
+ `ts_interfaces` (route `ingress`, `remoteIngress`, `vpnOnly`, source bindings, token policies, edge
4556
+ performance and egress, mail rate limits, the email port configuration, HTTP/3:
4557
+ `data.IGatewayHttp3Settings` is the stored and the wire shape, which dcrouter's stored home imports).
4558
+ - What is enforced where: this package refuses the closed key vocabulary
4559
+ `data.gatewayAreaRefusedEngineKeys` (secrets such as `key`, `password`, `jwtSecret`, `auth.accounts`
4560
+ and `forward.auth`; host-path names such as `keyFile`, `root`, `receivedEmailsPath`; the
4561
+ header-injection members `headers.request`, `advanced.headers` and `customHeaders`) at any depth of
4562
+ every engine configuration, policy override values and record keys included, as
4563
+ `secret-in-engine-config` or `host-path-in-engine-config`. An entry is a key name, refused under any
4564
+ parent, or `parent.name`, refused only directly inside `parent`; any other entry (`a.b.c`) fails the
4565
+ module's import rather than never matching. Completeness against the engine
4566
+ types is the gateway's: dcrouter classifies every member of its pinned SmartProxy and SmartMTA
4567
+ types, refuses an unclassified stored engine path by name at export and as `invalid-table` at apply.
4568
+ Version skew: Cloudly writes no engine configuration for a gateway stating a newer
4569
+ `interfacesVersion` than its own.
4570
+ - Mail `auth` (Linus ruling 126): `auth.users` and `auth.accounts` are out; the rest of `auth`
4571
+ (`required`, `methods`) travels inside `emailConfig`. SMTP accounts are `smtpAccounts` rows, and a
4572
+ gateway that holds a plaintext `auth.users` login refuses to export by name. A route action's
4573
+ `forward.auth` is refused whole, whatever its members are called.
4574
+ - Canonical spelling is the author's (the gateway's exporter, the controller's compile); the
4575
+ validators judge and never rewrite a value. Where both authors write a member it has one spelling
4576
+ each: a route's `match.ports` is the list `data.canonicalizeGatewayRoutePorts(ports)` answers from
4577
+ any spelling SmartProxy takes (the maximal port runs, ascending: a port alone is a number, two or
4578
+ more consecutive ports are `{ from, to }` with `from < to`, no entries overlap or touch; a bare
4579
+ `443` is `[443]`, `[80, 443, 444, 445]` is `[80, { from: 443, to: 445 }]`; it throws
4580
+ `data.GatewayRoutePortsError` for a port outside 1 to 65535), and a route target's `port` is an
4581
+ integer 1 to 65535 or `'preserve'`, never a digit string. An edge setting that states nothing is
4582
+ `null`, never an object of `null` members or an empty list. Where `null` and an object would mean
4583
+ the same, the object is canonical and the member is never `null` (Linus ruling 128, B2): an edge's
4584
+ `egress` is always a policy (an enabled one states its ports, `[25]` written out; egress off is
4585
+ `{ enabled: false }` with every other member `null`), and the mail server's `emailPortConfig` is
4586
+ always the object (no port configuration is `{ portMapping: null, portSettings: {} }`; `null` is
4587
+ the gateway's default mapping and an empty `portMapping` is refused, because the gateway maps an
4588
+ unnamed port to port + 10000 either way).
4589
+ - DNS records lie inside their zone (the zone's name or a name below it, as written), and an `A` or
4590
+ `AAAA` value (operator and static records) is one address in the form the gateway's DNS encoder
4591
+ takes, with nothing around it: four decimal octets of one to three digits up to 255, or hex groups
4592
+ with at most one `::`, no IPv4 tail and no zone id.
4593
+ - Secret classes: `sealed` (`data.IGatewaySealedValue`, `{ version, value }`, `version` 22 base64url
4594
+ characters minted by whoever sets the value) for DNS provider tokens, route and mail TLS keys,
4595
+ basic-auth user lists, JWT secrets, route request headers and edge secrets; `verifier` for API
4596
+ token hashes, SMTP and WorkApp SCRAM verifiers (WorkApp: `data.gatewayMailIdentityScramIterations`,
4597
+ 4,096) and CoreMail argon2id verifiers. The secrets the gateway needs travel in `secrets`/`tlsKey`;
4598
+ `security.basicAuth` and `security.jwtAuth` are objects exactly when their secret is set (no empty
4599
+ user list, no secret-less JWT object; a gateway refuses to export one, by name). A basic-auth list
4600
+ and a request-header record are sealed whole in the one spelling of
4601
+ `data.encodeGatewayBasicAuthUsers` and `data.encodeGatewayRequestHeaders`.
4602
+ - Hard references (validated): `metadata.networkTargetRef`, `sourceBindings[].sourceProfileRef`,
4603
+ `extendsProfiles`, `records[].domainId` (a `dcrouter`-source zone), `domains[].providerId`,
4604
+ `dns.server.primaryNameserver`, and the cross-area `mail.domains[].linkedDomainId`. Every other
4605
+ reference is soft and resolves to nothing. An `extendsProfiles` cycle through two or more profiles
4606
+ is refused `reference-cycle` on every profile on it (a profile naming itself is `invalid-value`),
4607
+ and two static records with the same `(name, type, value)` are `duplicate-key`.
4608
+ - Bounds: `data.gatewayAreaContentContract` (row id length 256, rows per member, sealed value
4609
+ 16,384 characters, engine configuration 65,536 canonical characters, inner lists 1,024 entries).
4610
+ - `data.validateGatewayAreaTables(tables)` judges one whole document in
4611
+ `gatewayConfigAreaApplyOrder` and returns `data.IGatewayAreaContentRefusal[]`
4612
+ (`{ area, member, rowId, path, code }`, codes `data.gatewayAreaContentRefusalCodes`), never a value;
4613
+ `data.formatGatewayAreaContentRefusal` is its one-line form for an `invalid-table` detail. A table
4614
+ whose area is outside `gatewayConfigAreaApplyOrder` is refused `invalid-value` with `area: null` and
4615
+ its position as the path (`[n]`), never skipped.
4616
+ `data.validateGatewayAreaContent(area, content)` judges one area without its cross-area reference.
4617
+ `data.validateGatewayAreaContentChange(area, previous, next)` refuses a domain whose `source` or
4618
+ `providerId` changed under one id. A sealed version naming another value than the gateway stored is
4619
+ the gateway's own `invalid-table`; no validator over one document can see it.
4620
+ - Readers: `data.listGatewayAreaSecrets(area, content)` names every secret-class value by member, row
4621
+ id, path and sealed version (what a controller seals and what its diffs show).
4622
+ `data.createGatewayDnsStaticRecordId(record)` derives a static record's id;
4623
+ `data.canonicalizeGatewayRoutePorts(ports)` writes a route's `match.ports`; the scope vocabulary
4624
+ is `data.gatewayApiTokenScopes`, and a table's scopes are judged by syntax only
4625
+ (`data.isGatewayApiTokenScope`).
4626
+
4627
+ ```typescript
4628
+ import { data } from '@serve.zone/interfaces';
4629
+
4630
+ declare const document: data.IGatewayDesiredState;
4631
+ const refusals = data.validateGatewayAreaTables(document.areas);
4632
+ if (refusals.length > 0) {
4633
+ console.log(refusals.map(data.formatGatewayAreaContentRefusal).join('\n')); // ids and paths, never values
4634
+ }
4635
+ const routes = document.areas.find((tableArg) => tableArg.area === 'routes')!.content as data.IGatewayRoutesArea;
4636
+ const sealedVersions = data.listGatewayAreaSecrets('routes', routes).map((secretArg) => secretArg.version);
4637
+ ```
4638
+
4491
4639
  ### Controller Peer Set
4492
4640
 
4493
4641
  `data.IControllerPeerSet` (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) is where the
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.86.0',
6
+ version: '32.87.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
@@ -1,6 +1,7 @@
1
1
  import type { TDnsRecordType } from './dns.js';
2
2
  import { hasExactKeys, isPlainRecord, readDataElements, readDataProperties } from '../private/dataproperties.js';
3
3
  import { isPlausibleUnicastIpv4 } from '../private/ipv4.js';
4
+ import type { TCompleteKeyList } from '../private/keylist.js';
4
5
  import {
5
6
  ipPrefixContains,
6
7
  parseCanonicalIpAddress,
@@ -109,6 +110,154 @@ export interface IGatewayRouteDnsResult {
109
110
  message?: string;
110
111
  }
111
112
 
113
+ /**
114
+ * The bounds `validateGatewayRouteDnsResult` holds a route DNS result to. One text over its bound
115
+ * refuses the whole `getGatewayRouteDnsResults` answer, so the gateway shortens every text (a
116
+ * provider's error in `message`, for example) to the bound before it answers; a controller never
117
+ * shortens what it received.
118
+ */
119
+ export const gatewayRouteDnsResultContract = Object.freeze({
120
+ /** Each text member (hostname, address, zone, record fields, message), in UTF-16 code units. */
121
+ maximumTextLength: 4096,
122
+ /** Entries of `nameservers`, `records` and `overwrittenRecords`, each. */
123
+ maximumListEntries: 256,
124
+ } as const);
125
+
126
+ const gatewayRouteDnsModes = {
127
+ reconcile: true, observe: true, skip: true,
128
+ } as const satisfies Record<TGatewayRouteDnsMode, true>;
129
+ const gatewayRouteDnsStatuses = {
130
+ 'not-applicable': true,
131
+ skipped: true,
132
+ 'managed-created': true,
133
+ 'managed-updated': true,
134
+ 'managed-overwrote-manual': true,
135
+ 'managed-unchanged': true,
136
+ 'manual-satisfied': true,
137
+ 'observed-satisfied': true,
138
+ 'managed-deleted': true,
139
+ 'managed-released': true,
140
+ 'managed-orphan-deleted': true,
141
+ 'record-missing': true,
142
+ 'target-invalid': true,
143
+ 'zone-unmanaged': true,
144
+ 'zone-unavailable': true,
145
+ 'record-conflict': true,
146
+ 'mutation-failed': true,
147
+ 'compensation-failed': true,
148
+ } as const satisfies Record<TGatewayRouteDnsStatus, true>;
149
+
150
+ const routeDnsRecordRequiredKeys = ['type', 'name', 'value', 'ttl', 'managed'] as const;
151
+ const routeDnsRecordKeyList = [...routeDnsRecordRequiredKeys, 'id', 'proxied'] as const;
152
+ const routeDnsRecordKeys: TCompleteKeyList<IGatewayRouteDnsRecord, typeof routeDnsRecordKeyList> =
153
+ routeDnsRecordKeyList;
154
+ const routeDnsResultRequiredKeys = ['success', 'retryable', 'mode', 'status', 'checkedAt'] as const;
155
+ const routeDnsResultKeyList = [
156
+ ...routeDnsResultRequiredKeys, 'hostname', 'targetIp', 'recordType', 'zoneId', 'zoneName', 'nameservers', 'records',
157
+ 'overwrittenRecords', 'authoritativeVerifiedAt', 'message',
158
+ ] as const;
159
+ const routeDnsResultKeys: TCompleteKeyList<IGatewayRouteDnsResult, typeof routeDnsResultKeyList> =
160
+ routeDnsResultKeyList;
161
+
162
+ const validateRouteDnsText = (valueArg: unknown, pathArg: string): string[] => (
163
+ typeof valueArg === 'string' && valueArg.length <= gatewayRouteDnsResultContract.maximumTextLength
164
+ ? []
165
+ : [`${pathArg} must be a string of at most ${gatewayRouteDnsResultContract.maximumTextLength} characters`]
166
+ );
167
+
168
+ const validateRouteDnsTime = (valueArg: unknown, pathArg: string): string[] => (
169
+ typeof valueArg === 'number' && Number.isSafeInteger(valueArg) && valueArg >= 0
170
+ ? []
171
+ : [`${pathArg} must be a non-negative safe integer`]
172
+ );
173
+
174
+ const validateRouteDnsBoolean = (valueArg: unknown, pathArg: string): string[] => (
175
+ typeof valueArg === 'boolean' ? [] : [`${pathArg} must be a boolean`]
176
+ );
177
+
178
+ /** A bounded list whose every entry is judged by `validateEntryArg`. */
179
+ const validateRouteDnsList = (
180
+ valueArg: unknown,
181
+ pathArg: string,
182
+ validateEntryArg: (entryArg: unknown, entryPathArg: string) => string[],
183
+ ): string[] => {
184
+ const entries = readDataElements(valueArg, gatewayRouteDnsResultContract.maximumListEntries);
185
+ return entries === null
186
+ ? [`${pathArg} must be a dense list of at most ${gatewayRouteDnsResultContract.maximumListEntries} entries`]
187
+ : entries.flatMap((entryArg, indexArg) => validateEntryArg(entryArg, `${pathArg}[${indexArg}]`));
188
+ };
189
+
190
+ const validateRouteDnsRecord = (valueArg: unknown, pathArg: string): string[] => {
191
+ const record = readDataProperties(valueArg);
192
+ if (record === null || !hasExactKeys(record, routeDnsRecordRequiredKeys, routeDnsRecordKeys)) {
193
+ return [`${pathArg} must use its exact schema`];
194
+ }
195
+ const errors = [
196
+ ...(record.type === 'A' || record.type === 'AAAA' || record.type === 'CNAME'
197
+ ? []
198
+ : [`${pathArg} type must be A, AAAA or CNAME`]),
199
+ ...validateRouteDnsText(record.name, `${pathArg} name`),
200
+ ...validateRouteDnsText(record.value, `${pathArg} value`),
201
+ ...validateRouteDnsTime(record.ttl, `${pathArg} ttl`),
202
+ ...validateRouteDnsBoolean(record.managed, `${pathArg} managed`),
203
+ ];
204
+ if (Object.hasOwn(record, 'id')) {
205
+ errors.push(...validateRouteDnsText(record.id, `${pathArg} id`));
206
+ }
207
+ if (Object.hasOwn(record, 'proxied')) {
208
+ errors.push(...validateRouteDnsBoolean(record.proxied, `${pathArg} proxied`));
209
+ }
210
+ return errors;
211
+ };
212
+
213
+ /**
214
+ * Validates one `IGatewayRouteDnsResult` and names every reason it is refused: the keys of the type
215
+ * and no other (the required ones present, an optional one only with a value of its type), `mode`
216
+ * and `status` from their vocabularies, times as non-negative safe integers, texts and lists within
217
+ * `gatewayRouteDnsResultContract`, and each record evidence by the same rule. It judges the shape
218
+ * only: whether `success`, `retryable`, `status` and the evidence agree is the gateway's statement.
219
+ */
220
+ export const validateGatewayRouteDnsResult = (
221
+ valueArg: unknown,
222
+ pathArg = 'gateway route DNS result',
223
+ ): string[] => {
224
+ const result = readDataProperties(valueArg);
225
+ if (result === null || !hasExactKeys(result, routeDnsResultRequiredKeys, routeDnsResultKeys)) {
226
+ return [`${pathArg} must use its exact schema`];
227
+ }
228
+ const errors = [
229
+ ...validateRouteDnsBoolean(result.success, `${pathArg} success`),
230
+ ...validateRouteDnsBoolean(result.retryable, `${pathArg} retryable`),
231
+ ...(typeof result.mode === 'string' && Object.hasOwn(gatewayRouteDnsModes, result.mode)
232
+ ? []
233
+ : [`${pathArg} mode must be one of ${Object.keys(gatewayRouteDnsModes).join(', ')}`]),
234
+ ...(typeof result.status === 'string' && Object.hasOwn(gatewayRouteDnsStatuses, result.status)
235
+ ? []
236
+ : [`${pathArg} status must be a gateway route DNS status`]),
237
+ ...validateRouteDnsTime(result.checkedAt, `${pathArg} checkedAt`),
238
+ ];
239
+ for (const key of ['hostname', 'targetIp', 'zoneId', 'zoneName', 'message'] as const) {
240
+ if (Object.hasOwn(result, key)) {
241
+ errors.push(...validateRouteDnsText(result[key], `${pathArg} ${key}`));
242
+ }
243
+ }
244
+ if (Object.hasOwn(result, 'recordType') && result.recordType !== 'A' && result.recordType !== 'AAAA') {
245
+ errors.push(`${pathArg} recordType must be A or AAAA`);
246
+ }
247
+ if (Object.hasOwn(result, 'nameservers')) {
248
+ errors.push(...validateRouteDnsList(result.nameservers, `${pathArg} nameservers`, validateRouteDnsText));
249
+ }
250
+ for (const key of ['records', 'overwrittenRecords'] as const) {
251
+ if (Object.hasOwn(result, key)) {
252
+ errors.push(...validateRouteDnsList(result[key], `${pathArg} ${key}`, validateRouteDnsRecord));
253
+ }
254
+ }
255
+ if (Object.hasOwn(result, 'authoritativeVerifiedAt')) {
256
+ errors.push(...validateRouteDnsTime(result.authoritativeVerifiedAt, `${pathArg} authoritativeVerifiedAt`));
257
+ }
258
+ return errors;
259
+ };
260
+
112
261
  /**
113
262
  * Identity attached to gateway requests. Gateways run their own user/auth
114
263
  * domain (e.g. dcrouter operator accounts), so role/type stay open strings;