@serve.zone/interfaces 32.85.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/changelog.md +15 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/appstore/catalog.d.ts +26 -7
- package/dist_ts/appstore/catalog.js +31 -7
- package/dist_ts/appstore/types.d.ts +29 -1
- package/dist_ts/appstore/types.js +19 -1
- package/dist_ts/appstore/versionconfig.d.ts +4 -2
- package/dist_ts/appstore/versionconfig.js +36 -5
- package/dist_ts/data/gateway.d.ts +20 -0
- package/dist_ts/data/gateway.js +125 -1
- package/dist_ts/data/gatewayareas.d.ts +891 -0
- package/dist_ts/data/gatewayareas.js +298 -0
- package/dist_ts/data/gatewayareas.validation.d.ts +104 -0
- package/dist_ts/data/gatewayareas.validation.js +1770 -0
- package/dist_ts/data/gatewayconnector.d.ts +73 -1
- package/dist_ts/data/gatewayconnector.js +145 -2
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/private/enginekeyentries.d.ts +17 -0
- package/dist_ts/private/enginekeyentries.js +34 -0
- package/dist_ts/requests/gatewayconnector.d.ts +44 -0
- package/package.json +2 -2
- package/readme.md +154 -4
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/appstore/catalog.ts +42 -6
- package/ts/appstore/types.ts +33 -1
- package/ts/appstore/versionconfig.ts +38 -1
- package/ts/data/gateway.ts +149 -0
- package/ts/data/gatewayareas.ts +1135 -0
- package/ts/data/gatewayareas.validation.ts +2026 -0
- package/ts/data/gatewayconnector.ts +186 -0
- package/ts/data/index.ts +2 -0
- package/ts/private/enginekeyentries.ts +38 -0
- package/ts/requests/gatewayconnector.ts +45 -0
package/readme.md
CHANGED
|
@@ -3975,6 +3975,7 @@ Compatibility rules:
|
|
|
3975
3975
|
- `requiresFeatures` gates one version: a consumer passes the feature ids it fulfils (`supportedFeatureIds`, e.g. `appStoreStorageFeatureIds` values). A version naming any other id stays listed, is refused for install and upgrade there, and its config is not interpreted, so a new config capability ships under a feature id without refusing the rest of the catalog (`appstore.getAppStoreCatalogMissingFeatureIds`).
|
|
3976
3976
|
- A published `app@version` stays in every later catalog and never changes (`appstore.judgeAppStoreCatalogSuccession`): a later catalog that no longer lists it is `publishedVersionRemoved`, one that lists it with another `configDigest` is `publishedVersionMutated`, and a revision that does not increase is `revisionRegressed`.
|
|
3977
3977
|
- A version names the oldest host releases that run it (`minOneboxVersion`, `minCloudlyVersion`). A host passes itself to `appstore.judgeAppStoreCatalogInstallTarget` as `{ kind: 'onebox' | 'cloudly', version }` (`IAppStoreCatalogConsumer`), which refuses a version needing a newer release of it as `consumerVersionTooOld`; the version stays listed and installs once the host is upgraded.
|
|
3978
|
+
- A version names the host roles it installs as (`hostRoles`: `controllerHost`, the host that runs the controller itself, and `cluster`, a workload a controller places on its cluster; `appStoreHostRoles`). A version without it is a `cluster` version (`appStoreDefaultHostRoles`). A version declaring `hostRoles` names `appStoreHostRolesFeatureId` (`host.roles`) in `requiresFeatures`, so a reader built before the member skips that version. A host that advertises `host.roles` has its role judged: the role follows from its kind (`appStoreCatalogConsumerHostRoles`: `onebox` is `controllerHost`, `cloudly` is `cluster`), and `appstore.judgeAppStoreCatalogInstallTarget` refuses a version not naming it as `hostRoleUnsupported`, after withdrawal and features and before the minimum release. A host that does not advertise it is judged as before the member existed.
|
|
3978
3979
|
- A publisher retires a version by withdrawing it, never by removing it. A withdrawn version keeps its entry, config and digest, so services installed from it keep reading it, and is refused as an install or upgrade target, like a version gated on a feature the consumer lacks (`appstore.judgeAppStoreCatalogInstallTarget`). A withdrawal is final: a later catalog that revokes or rewrites it is `publishedWithdrawalChanged`; a version withdrawn by mistake is republished under a new version.
|
|
3979
3980
|
|
|
3980
3981
|
Digests are SHA-256 over strict canonical JSON (keys in UTF-16 code-unit order, safe integers only) of a domain-separated value: `computeAppStoreCatalogConfigDigest`, `computeAppStoreCatalogDigest` and `computeAppStoreCatalogSigningKeyId`. A signature covers `createAppStoreCatalogSignaturePayload(catalogDigest)`. These helpers use Web Crypto and are safe in the browser entry.
|
|
@@ -4013,8 +4014,9 @@ The catalog validator judges every supported version config in full; no consumer
|
|
|
4013
4014
|
|
|
4014
4015
|
- `image`, then the port model (`appstore.validateAppStoreVersionPortModel`): `port` or `targetPorts` is required, and `targetPorts`, `domains` and `publicPortMappings` are read as exactly their types and resolved through `data.normalizeServicePortConfig`.
|
|
4015
4016
|
- `containerArgs` and the environment declarations.
|
|
4016
|
-
- Storage (`appstore.validateAppStoreVersionStorage`): the exact config member set (`appstore.appStoreVersionConfigKeys`), `platformRequirements`, `storageClasses` and `storageRequests` (declared together, every class used), `backupExclusions`, `databaseBackupExclusions`, the
|
|
4017
|
+
- Storage (`appstore.validateAppStoreVersionStorage`): the exact config member set (`appstore.appStoreVersionConfigKeys`), `platformRequirements`, `storageClasses` and `storageRequests` (declared together, every class used), `backupExclusions`, `databaseBackupExclusions`, the feature ids `requiresFeatures` must name (the storage feature ids, and `host.roles` exactly when the config states `hostRoles`; any other `host.` id is refused), portable legacy `volumes`, and every environment, secret-file and mount destination used once.
|
|
4017
4018
|
- Platform OIDC, then Docker `publishedPorts` (`appstore.validateAppStorePublishedPorts`).
|
|
4019
|
+
- Host roles (`appstore.validateAppStoreVersionHostRoles`): `hostRoles` is absent, or a non-empty, strictly increasing list of `appstore.appStoreHostRoles` values.
|
|
4018
4020
|
|
|
4019
4021
|
A version declares data it keeps only for observability, such as workload logs, as `backupExclusions` (`IAppStoreBackupExclusion[]`): a backup leaves those object keys out, and a restore neither brings them back nor removes them. Each entry names one objectStorage request of the version (`storageRequest`: an explicit request id, or `legacy-s3` when the version declares `platformRequirements.s3`; a filesystem request is refused), 1 to 16 `keyPrefixes` and a one-line `reason` an operator reads:
|
|
4020
4022
|
|
|
@@ -4389,6 +4391,19 @@ guard that names roles excludes it by type.
|
|
|
4389
4391
|
stored one) and `forward-sources-exceed-allowlist` (a `new` adoption whose forward sources would
|
|
4390
4392
|
make the union of every gateway's forward source prefixes exceed one cluster ingress allowlist; the
|
|
4391
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.
|
|
4392
4407
|
- Revisions: `data.IControllerRevision` is one record of the controller-wide sequence, validated
|
|
4393
4408
|
exactly by `data.validateControllerRevision`: the actor's `sub` is `null` exactly for `system`,
|
|
4394
4409
|
the bounds of `data.controllerRevisionContract` only ever rise,
|
|
@@ -4433,6 +4448,10 @@ guard that names roles excludes it by type.
|
|
|
4433
4448
|
first failure; `data.IGatewayApplyReport.appliedRevision` advances only when the whole document
|
|
4434
4449
|
applied. Per-area refusals are `data.gatewayApplyRefusals` (`invalid-table`, `unsupported-area`,
|
|
4435
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.
|
|
4436
4455
|
- Owners: every area the controller owns on a gateway must be carried in each document.
|
|
4437
4456
|
`area-owner-mismatch` is the per-area refusal of a document that disagrees with an area's owner on
|
|
4438
4457
|
the gateway; the entry's `owner` says which side owns it, and nothing of the document applies. A
|
|
@@ -4442,8 +4461,8 @@ guard that names roles excludes it by type.
|
|
|
4442
4461
|
`not-attempted`, and `appliedRevision` and `epoch` stay. `data.validateGatewayDesiredState` checks
|
|
4443
4462
|
the envelope only and never this. A gateway-owned area no document carried reports `applied` with
|
|
4444
4463
|
`revision: null`.
|
|
4445
|
-
- Area content is
|
|
4446
|
-
|
|
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)`,
|
|
4447
4466
|
`sha256:<hex>` of the strict canonical JSON of the domain `serve.zone/gateway-area-table`, the area
|
|
4448
4467
|
and the content, which both sides compute.
|
|
4449
4468
|
- Takeover: an area has one owner per gateway, `gateway` or `controller`, and moves to the controller
|
|
@@ -4452,6 +4471,23 @@ guard that names roles excludes it by type.
|
|
|
4452
4471
|
`local-changed-since-export`. A takeover of a table the gateway already serves is a pure owner
|
|
4453
4472
|
change, whatever `localDigest` says, and `takeover` is ignored for an area the controller already
|
|
4454
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.
|
|
4455
4491
|
- Status: a gateway pushes its `data.IGatewayStatusDocument` (`pushGatewayStatus`) after its hello,
|
|
4456
4492
|
after every apply and on change, at most once per
|
|
4457
4493
|
`data.gatewayConnectorContract.minimumStatusPushIntervalMs` (5 s). `getGateways` lists the gateways
|
|
@@ -4468,7 +4504,8 @@ guard that names roles excludes it by type.
|
|
|
4468
4504
|
`data.validateControllerRevision`, `data.validateGateway`, `data.validateGatewayAdoptionFacts`,
|
|
4469
4505
|
`data.validateAdoptGatewayResponse`, `data.validateRegisterGatewaySessionRequest`,
|
|
4470
4506
|
`data.validateGatewayDesiredState` (envelope only), `data.validateGatewayApplyReport`,
|
|
4471
|
-
`data.validateGatewayStatusDocument
|
|
4507
|
+
`data.validateGatewayStatusDocument`, `data.validateGatewayAreaExport`,
|
|
4508
|
+
`data.validateGatewayRouteDnsResultsRequest` and `data.validateGatewayRouteDnsResultsResponse`.
|
|
4472
4509
|
|
|
4473
4510
|
```typescript
|
|
4474
4511
|
import { data, requests } from '@serve.zone/interfaces';
|
|
@@ -4486,6 +4523,119 @@ const desired: requests.gatewayconnector.IReq_Cloudly_Gateway_ApplyDesiredState[
|
|
|
4486
4523
|
data.validateGatewayDesiredState(desired.desired); // []
|
|
4487
4524
|
```
|
|
4488
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
|
+
|
|
4489
4639
|
### Controller Peer Set
|
|
4490
4640
|
|
|
4491
4641
|
`data.IControllerPeerSet` (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) is where the
|
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/appstore/catalog.ts
CHANGED
|
@@ -20,10 +20,12 @@ import {
|
|
|
20
20
|
} from '../private/canonicaljson.js';
|
|
21
21
|
import { hasExactKeys, readDataElements, readDataProperties } from '../private/dataproperties.js';
|
|
22
22
|
import type { TCompleteKeyList } from '../private/keylist.js';
|
|
23
|
+
import { appStoreDefaultHostRoles, appStoreHostRolesFeatureId } from './types.js';
|
|
23
24
|
import { validateAppStoreVersionConfig } from './versionconfig.js';
|
|
24
25
|
import type {
|
|
25
26
|
IAppStoreVersionConfig,
|
|
26
27
|
IServezoneAppStoreAppInfo,
|
|
28
|
+
TAppStoreHostRole,
|
|
27
29
|
TAppStoreUpgradeStrategy,
|
|
28
30
|
} from './types.js';
|
|
29
31
|
|
|
@@ -91,6 +93,7 @@ const versionConfigKeyList = [
|
|
|
91
93
|
'publishedPorts',
|
|
92
94
|
'platformRequirements',
|
|
93
95
|
'platformOidc',
|
|
96
|
+
'hostRoles',
|
|
94
97
|
'minOneboxVersion',
|
|
95
98
|
'minCloudlyVersion',
|
|
96
99
|
'changelog',
|
|
@@ -911,10 +914,31 @@ const consumerMinimumVersionKeys = Object.freeze({
|
|
|
911
914
|
cloudly: 'minCloudlyVersion',
|
|
912
915
|
} as const);
|
|
913
916
|
|
|
917
|
+
/**
|
|
918
|
+
* The host role each consumer installs as (`IAppStoreVersionConfig.hostRoles`): Onebox is the
|
|
919
|
+
* controller host, Cloudly installs workloads on its cluster.
|
|
920
|
+
*/
|
|
921
|
+
export const appStoreCatalogConsumerHostRoles: Readonly<Record<TAppStoreCatalogConsumerKind, TAppStoreHostRole>> =
|
|
922
|
+
Object.freeze({
|
|
923
|
+
onebox: 'controllerHost',
|
|
924
|
+
cloudly: 'cluster',
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
/** The host roles a version is installed as: its `hostRoles`, or `appStoreDefaultHostRoles` when absent. */
|
|
928
|
+
export const getAppStoreCatalogVersionHostRoles = (
|
|
929
|
+
configArg: TAppStoreCatalogVersionConfig,
|
|
930
|
+
): readonly TAppStoreHostRole[] => configArg.hostRoles ?? appStoreDefaultHostRoles;
|
|
931
|
+
|
|
914
932
|
/** Why a listed version is not an install or upgrade target for this consumer. */
|
|
915
933
|
export type TAppStoreCatalogInstallTargetRefusal =
|
|
916
934
|
| { reason: 'versionWithdrawn'; withdrawal: IAppStoreCatalogWithdrawal }
|
|
917
935
|
| { reason: 'featuresUnsupported'; missingFeatureIds: string[] }
|
|
936
|
+
/** The version's host roles (`getAppStoreCatalogVersionHostRoles`) do not include this host's role. */
|
|
937
|
+
| {
|
|
938
|
+
reason: 'hostRoleUnsupported';
|
|
939
|
+
consumerKind: TAppStoreCatalogConsumerKind;
|
|
940
|
+
hostRole: TAppStoreHostRole;
|
|
941
|
+
}
|
|
918
942
|
/** The version names a minimum release of this host (`minOneboxVersion`, `minCloudlyVersion`) newer than it runs. */
|
|
919
943
|
| {
|
|
920
944
|
reason: 'consumerVersionTooOld';
|
|
@@ -925,12 +949,18 @@ export type TAppStoreCatalogInstallTargetRefusal =
|
|
|
925
949
|
|
|
926
950
|
/**
|
|
927
951
|
* Whether a consumer may install a listed version, or upgrade a service to it; `null` when it may.
|
|
928
|
-
* A withdrawn version, a version requiring a feature the consumer does not fulfil
|
|
929
|
-
* requiring a newer release of the consumer stay
|
|
930
|
-
* nowhere else is a second answer needed.
|
|
952
|
+
* A withdrawn version, a version requiring a feature the consumer does not fulfil, a version not
|
|
953
|
+
* naming the consumer's host role and a version requiring a newer release of the consumer stay
|
|
954
|
+
* listed and are refused here, in that order, and nowhere else is a second answer needed.
|
|
931
955
|
*
|
|
932
|
-
*
|
|
933
|
-
* consumer
|
|
956
|
+
* The host role is judged for a consumer that fulfils `appStoreHostRolesFeatureId`: its role is
|
|
957
|
+
* `appStoreCatalogConsumerHostRoles[consumer.kind]`, and a version without `hostRoles` is a
|
|
958
|
+
* `cluster` version (`getAppStoreCatalogVersionHostRoles`). A consumer that does not advertise the
|
|
959
|
+
* feature is judged as before the member existed, and never installs a version declaring it.
|
|
960
|
+
*
|
|
961
|
+
* A host passes `consumerArg` on every call; without it neither the host role nor the minimum
|
|
962
|
+
* release is judged. A consumer version that is not `MAJOR.MINOR.PATCH` throws: it is the host's
|
|
963
|
+
* own constant.
|
|
934
964
|
*/
|
|
935
965
|
export const judgeAppStoreCatalogInstallTarget = (
|
|
936
966
|
versionArg: IAppStoreCatalogVersion,
|
|
@@ -942,9 +972,15 @@ export const judgeAppStoreCatalogInstallTarget = (
|
|
|
942
972
|
throw new Error('App Store catalog consumer version must be MAJOR.MINOR.PATCH');
|
|
943
973
|
}
|
|
944
974
|
if (versionArg.withdrawn !== undefined) return { reason: 'versionWithdrawn', withdrawal: versionArg.withdrawn };
|
|
945
|
-
const
|
|
975
|
+
const supportedFeatureIds = new Set(supportedFeatureIdsArg);
|
|
976
|
+
const missingFeatureIds = getAppStoreCatalogMissingFeatureIds(versionArg.config, supportedFeatureIds);
|
|
946
977
|
if (missingFeatureIds.length > 0) return { reason: 'featuresUnsupported', missingFeatureIds };
|
|
947
978
|
if (consumerArg === undefined || consumerVersion === null) return null;
|
|
979
|
+
const hostRole = appStoreCatalogConsumerHostRoles[consumerArg.kind];
|
|
980
|
+
if (supportedFeatureIds.has(appStoreHostRolesFeatureId)
|
|
981
|
+
&& !getAppStoreCatalogVersionHostRoles(versionArg.config).includes(hostRole)) {
|
|
982
|
+
return { reason: 'hostRoleUnsupported', consumerKind: consumerArg.kind, hostRole };
|
|
983
|
+
}
|
|
948
984
|
const minimumVersion = versionArg.config[consumerMinimumVersionKeys[consumerArg.kind]];
|
|
949
985
|
if (minimumVersion === undefined) return null;
|
|
950
986
|
const minimum = parseReleaseVersion(minimumVersion);
|
package/ts/appstore/types.ts
CHANGED
|
@@ -74,6 +74,29 @@ export const appStoreStorageFeatureIds = {
|
|
|
74
74
|
export type TAppStoreStorageFeatureId =
|
|
75
75
|
typeof appStoreStorageFeatureIds[keyof typeof appStoreStorageFeatureIds];
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The host roles a version can be installed as (`IAppStoreVersionConfig.hostRoles`):
|
|
79
|
+
* `controllerHost` is the host that runs the controller itself (Onebox, the base host of Cloudly);
|
|
80
|
+
* `cluster` is a workload a controller places on its cluster (Cloudly's App Store).
|
|
81
|
+
*/
|
|
82
|
+
export const appStoreHostRoles = ['cluster', 'controllerHost'] as const;
|
|
83
|
+
|
|
84
|
+
export type TAppStoreHostRole = typeof appStoreHostRoles[number];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The roles of a version that states no `hostRoles`: every version published before the member
|
|
88
|
+
* existed is a cluster workload template, never a controller-host one.
|
|
89
|
+
*/
|
|
90
|
+
export const appStoreDefaultHostRoles: readonly TAppStoreHostRole[] = Object.freeze(['cluster']);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The feature id a version declaring `hostRoles` names in `requiresFeatures`. A consumer that
|
|
94
|
+
* advertises it has its host role judged on every version (`judgeAppStoreCatalogInstallTarget`); a
|
|
95
|
+
* consumer that does not, including every one built before the member, skips the config of a
|
|
96
|
+
* version declaring it and never installs that version.
|
|
97
|
+
*/
|
|
98
|
+
export const appStoreHostRolesFeatureId = 'host.roles' as const;
|
|
99
|
+
|
|
77
100
|
export type TAppStoreStoragePurpose =
|
|
78
101
|
| 'runtime'
|
|
79
102
|
| 'database'
|
|
@@ -391,7 +414,8 @@ export interface IAppStoreAppVersionState {
|
|
|
391
414
|
/**
|
|
392
415
|
* `null` when the host may install the version or upgrade a service to it; otherwise
|
|
393
416
|
* `versionWithdrawn` with the withdrawal, `featuresUnsupported` with the feature ids the host
|
|
394
|
-
* does not fulfil
|
|
417
|
+
* does not fulfil, `hostRoleUnsupported` with the host role the version does not name or
|
|
418
|
+
* `consumerVersionTooOld` with the host release the version requires, as
|
|
395
419
|
* `judgeAppStoreCatalogInstallTarget` answers it.
|
|
396
420
|
*/
|
|
397
421
|
installRefusal: TAppStoreCatalogInstallTargetRefusal | null;
|
|
@@ -494,6 +518,14 @@ export interface IAppStoreVersionConfig {
|
|
|
494
518
|
* creates a client, injects credentials, or emits app-scoped role claims.
|
|
495
519
|
*/
|
|
496
520
|
platformOidc?: IAppStorePlatformOidcCapability;
|
|
521
|
+
/**
|
|
522
|
+
* The host roles this version is installed as, as a non-empty strictly increasing list of
|
|
523
|
+
* `appStoreHostRoles` values; absent means `appStoreDefaultHostRoles`. A host that advertises
|
|
524
|
+
* `appStoreHostRolesFeatureId` and whose role (`appStoreCatalogConsumerHostRoles`) is not listed
|
|
525
|
+
* refuses the version as an install or upgrade target (`hostRoleUnsupported`). A version
|
|
526
|
+
* declaring it names `appStoreHostRolesFeatureId` in `requiresFeatures`.
|
|
527
|
+
*/
|
|
528
|
+
hostRoles?: TAppStoreHostRole[];
|
|
497
529
|
minOneboxVersion?: string;
|
|
498
530
|
minCloudlyVersion?: string;
|
|
499
531
|
appStoreVersion?: string;
|
|
@@ -35,6 +35,8 @@ import type { TObjectStorageDelivery } from '../platform/storage.js';
|
|
|
35
35
|
import {
|
|
36
36
|
appStoreBackupExclusionLimits,
|
|
37
37
|
appStoreDatabaseBackupExclusionLimits,
|
|
38
|
+
appStoreHostRoles,
|
|
39
|
+
appStoreHostRolesFeatureId,
|
|
38
40
|
appStoreStorageFeatureIds,
|
|
39
41
|
validateAppStoreEnvironmentDeclarations,
|
|
40
42
|
validateAppStoreVersionPlatformOidc,
|
|
@@ -63,6 +65,7 @@ const versionConfigMemberList = [
|
|
|
63
65
|
'publishedPorts',
|
|
64
66
|
'platformRequirements',
|
|
65
67
|
'platformOidc',
|
|
68
|
+
'hostRoles',
|
|
66
69
|
'minOneboxVersion',
|
|
67
70
|
'minCloudlyVersion',
|
|
68
71
|
'appStoreVersion',
|
|
@@ -103,6 +106,7 @@ const legacyFilesystemClassKey = 'legacyFilesystem';
|
|
|
103
106
|
const legacyObjectStorageClassKey = 'legacyObjectStorage';
|
|
104
107
|
const legacyObjectStorageRequestId = 'legacy-s3';
|
|
105
108
|
const knownStorageFeatureIds: readonly string[] = Object.values(appStoreStorageFeatureIds);
|
|
109
|
+
const knownHostFeatureIds: readonly string[] = [appStoreHostRolesFeatureId];
|
|
106
110
|
const platformRequirementKeys = ['mongodb', 's3', 'clickhouse', 'valkey', 'mariadb', 'mail'] as const;
|
|
107
111
|
const controlCharacterPattern = /[\u0000-\u001f\u007f]/;
|
|
108
112
|
/** The C0 and C1 controls and DEL: what the database engine refuses in a namespace component. */
|
|
@@ -623,6 +627,7 @@ function checkFeatureDeclaration(
|
|
|
623
627
|
explicitRequestsArg: readonly TAppStoreStorageRequest[],
|
|
624
628
|
backupExclusionsArg: readonly IAppStoreBackupExclusion[],
|
|
625
629
|
databaseBackupExclusionsArg: readonly IAppStoreDatabaseBackupExclusion[],
|
|
630
|
+
hostRolesDeclaredArg: boolean,
|
|
626
631
|
labelArg: string,
|
|
627
632
|
): void {
|
|
628
633
|
const derivedFeatures = new Set<string>();
|
|
@@ -642,6 +647,7 @@ function checkFeatureDeclaration(
|
|
|
642
647
|
if (databaseBackupExclusionsArg.length > 0) {
|
|
643
648
|
derivedFeatures.add(appStoreStorageFeatureIds.databaseBackupExclusions);
|
|
644
649
|
}
|
|
650
|
+
if (hostRolesDeclaredArg) derivedFeatures.add(appStoreHostRolesFeatureId);
|
|
645
651
|
|
|
646
652
|
const declaredEntries = requiresFeaturesArg === undefined
|
|
647
653
|
? []
|
|
@@ -666,6 +672,12 @@ function checkFeatureDeclaration(
|
|
|
666
672
|
if (knownStorageFeatureIds.includes(declaredFeature) && !derivedFeatures.has(declaredFeature)) {
|
|
667
673
|
reject(`Invalid ${labelArg}: storage feature '${declaredFeature}' is not used`);
|
|
668
674
|
}
|
|
675
|
+
if (declaredFeature.startsWith('host.') && !knownHostFeatureIds.includes(declaredFeature)) {
|
|
676
|
+
reject(`Invalid ${labelArg}: unknown host feature '${declaredFeature}'`);
|
|
677
|
+
}
|
|
678
|
+
if (knownHostFeatureIds.includes(declaredFeature) && !derivedFeatures.has(declaredFeature)) {
|
|
679
|
+
reject(`Invalid ${labelArg}: host feature '${declaredFeature}' is not used`);
|
|
680
|
+
}
|
|
669
681
|
}
|
|
670
682
|
}
|
|
671
683
|
|
|
@@ -958,6 +970,7 @@ function checkStorage(configArg: Record<string, unknown>, labelArg: string): voi
|
|
|
958
970
|
explicitRequests,
|
|
959
971
|
backupExclusions,
|
|
960
972
|
databaseBackupExclusions,
|
|
973
|
+
configArg.hostRoles !== undefined,
|
|
961
974
|
labelArg,
|
|
962
975
|
);
|
|
963
976
|
checkDatabaseBackupExclusionTargets(databaseBackupExclusions, platformRequirements, labelArg);
|
|
@@ -1024,6 +1037,25 @@ function checkStorage(configArg: Record<string, unknown>, labelArg: string): voi
|
|
|
1024
1037
|
}
|
|
1025
1038
|
}
|
|
1026
1039
|
|
|
1040
|
+
// ---------------------------------------------------------------------------------------------
|
|
1041
|
+
// Host roles
|
|
1042
|
+
|
|
1043
|
+
function checkHostRoles(hostRolesArg: unknown, labelArg: string): void {
|
|
1044
|
+
if (hostRolesArg === undefined) return;
|
|
1045
|
+
const entries = readDataElements(hostRolesArg, appStoreHostRoles.length);
|
|
1046
|
+
if (entries === null || entries.length === 0) {
|
|
1047
|
+
reject(`Invalid ${labelArg}: hostRoles must list between 1 and ${appStoreHostRoles.length} host roles`);
|
|
1048
|
+
}
|
|
1049
|
+
let previous: string | null = null;
|
|
1050
|
+
entries.forEach((entryArg, indexArg) => {
|
|
1051
|
+
assertMember(entryArg, appStoreHostRoles, `${labelArg} hostRoles[${indexArg}]`);
|
|
1052
|
+
if (previous !== null && compareWireTokens(previous, entryArg) >= 0) {
|
|
1053
|
+
reject(`Invalid ${labelArg}: hostRoles must be in strictly increasing order`);
|
|
1054
|
+
}
|
|
1055
|
+
previous = entryArg;
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1027
1059
|
// ---------------------------------------------------------------------------------------------
|
|
1028
1060
|
// Exported validators
|
|
1029
1061
|
|
|
@@ -1072,9 +1104,13 @@ export const validateAppStoreDatabaseBackupExclusionCollections = (
|
|
|
1072
1104
|
labelArg = 'collections',
|
|
1073
1105
|
): string[] => firstRejection(() => checkDatabaseBackupExclusionCollections(valueArg, labelArg));
|
|
1074
1106
|
|
|
1107
|
+
/** `hostRoles`: absent, or a non-empty strictly increasing list of `appStoreHostRoles` values. */
|
|
1108
|
+
export const validateAppStoreVersionHostRoles = (hostRolesArg: unknown, labelArg = defaultLabel): string[] =>
|
|
1109
|
+
firstRejection(() => checkHostRoles(hostRolesArg, labelArg));
|
|
1110
|
+
|
|
1075
1111
|
/**
|
|
1076
1112
|
* Every member rule of a version config, in the order a host applies them: image, port model,
|
|
1077
|
-
* container arguments, environment declarations, storage, platform OIDC, published ports.
|
|
1113
|
+
* container arguments, environment declarations, storage, platform OIDC, published ports, host roles.
|
|
1078
1114
|
*/
|
|
1079
1115
|
export const validateAppStoreVersionConfig = (configArg: unknown, labelArg = defaultLabel): string[] =>
|
|
1080
1116
|
firstRejection(() => {
|
|
@@ -1089,4 +1125,5 @@ export const validateAppStoreVersionConfig = (configArg: unknown, labelArg = def
|
|
|
1089
1125
|
const platformOidcErrors = validateAppStoreVersionPlatformOidc(config);
|
|
1090
1126
|
if (platformOidcErrors.length > 0) reject(`Invalid ${labelArg}: ${platformOidcErrors.join('; ')}`);
|
|
1091
1127
|
checkPublishedPorts(config.publishedPorts, labelArg);
|
|
1128
|
+
checkHostRoles(config.hostRoles, labelArg);
|
|
1092
1129
|
});
|
package/ts/data/gateway.ts
CHANGED
|
@@ -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;
|