@serve.zone/interfaces 32.99.1 → 32.101.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
@@ -3891,9 +3891,22 @@ a named location must be the cluster's (`location-mismatch`). A `createCluster`
3891
3891
  location but creates no node (a setup mode that provisions no node: today every mode but
3892
3892
  `hetzner`) is refused `location-needs-node`,
3893
3893
  checked before `location-not-found`: name the location on `createNodeJumpCommand` instead.
3894
- `getClusters`, `getNodes` and `getBaremetalServers` take an optional `locationScope` and echo it as `appliedLocationScope`: a
3894
+ `getClusters`, `getNodes`, `getBaremetalServers`, `getServices`, `getServiceBackups` and
3895
+ `getCorestoreInventory` take an optional `locationScope` and echo it as `appliedLocationScope`: a
3895
3896
  response without the echo comes from a Cloudly that ignored the scope and is not scoped. Each is
3896
- refused `location-not-found` when no location has that id.
3897
+ refused `location-not-found` when no location has that id. Where a row stands:
3898
+
3899
+ - A service stands in every location one of its placed clusters stands in. Its placed clusters are
3900
+ the union of its runtime specs' `clusterId`s, its current plan's
3901
+ `data.imageDeployment.targetScope.targetClusterIds` and, for a Swarm-era service, the cluster of
3902
+ the node `data.placement.nodeName` pins it to; a shadow counts through the record that places it
3903
+ on its cluster. A service with no placed cluster is in no scoped answer.
3904
+ - A backup stands where the cluster of its recorded `clusterId` stands. A backup without `clusterId`
3905
+ is in no scoped answer; its service's current placement plays no part.
3906
+ - A corestore inventory row (`inventories` and `probes`) stands where its node's own
3907
+ `data.locationId` says, the rule `getNodes` applies. The echo is a member of the answer only, not
3908
+ of `ICorestoreInventoryReport`.
3909
+ - A cluster without nodes or whose nodes span locations places nothing.
3897
3910
 
3898
3911
  Cloudly's `initial-location` data step writes one transaction per cluster (the cluster document and
3899
3912
  all its node documents, setting `locationId` only where it is missing, so a rerun is safe) and one
@@ -4615,6 +4628,35 @@ guard that names roles excludes it by type.
4615
4628
  answers. Peer gate: it calls the request only on a gateway whose hello
4616
4629
  states an `interfacesVersion` of the release that declares it or later; a gateway moves to that
4617
4630
  release only together with serving it.
4631
+ - Mail observations: the controller reads what a gateway observes about mail with
4632
+ `getGatewayMailObservations` (`requests.gatewayconnector.IReq_Cloudly_Gateway_GetGatewayMailObservations`,
4633
+ Linus ruling 376 item 2), read-only, after the session's registration. The request names the
4634
+ domains (`{ domains }`, 1 to `data.gatewayMailObservationsContract.maximumDomains` (256) lowercase
4635
+ domains, strictly ascending; `data.validateGatewayMailObservationsRequest`, else `request-invalid`),
4636
+ which the controller derives from its own records. The answer holds one
4637
+ `data.IGatewayMailDomainObservation` per domain in request order: `emailDomain`
4638
+ (`{ lifecycleStatus }`, the gateway's mail DNS lifecycle status as an open word of at most
4639
+ `maximumLifecycleStatusLength` (32) characters that a reader shows as text, so a new gateway state
4640
+ needs no release here (Linus ruling 378 item 2), or `null` before the first reconciliation; `null`
4641
+ for no email domain of that name) and `nameservers` (the zone of exactly that name, 1 to 16
4642
+ distinct lowercase hostnames in the gateway's order; `null` for no such zone or none listed, and a
4643
+ reader keeps what it knew). It also holds at most `maximumRecentEmails` (100) recent cached emails
4644
+ whose sender or a recipient is in those domains, newest first, as `data.IGatewayObservedEmail` (the
4645
+ entry shape of the 34.x `requests.mail.IMailOverviewEmail`), each text bounded and free of control
4646
+ characters and unpaired surrogates. An address is in a domain when the part after its last `@`,
4647
+ lowercased, equals that requested domain; there is no suffix or subdomain matching. On a gateway
4648
+ with the flag the view therefore shows the cached mail of the controller's whole domains, not only
4649
+ the bound addresses the 34.x gateway-client overview filtered to. The controller judges every
4650
+ answer with `data.validateGatewayMailObservationsResponse(answer, request)`; at every bound the
4651
+ answer stays below the 2 MiB socket message cap (1,779,407 bytes). "Cannot read" and "holds
4652
+ nothing" are different answers: a gateway with mail not configured answers the truth
4653
+ (`emailDomain: null`, `emails: []`), while a gateway whose email domain store, zone store or
4654
+ email cache exists but is not ready or fails answers an error, never a silent empty or partial
4655
+ answer. Capability gate: the controller calls it only on a
4656
+ gateway whose `getGatewayCapabilities` answers `email.observations: true`
4657
+ (`data.IGatewayCapabilities`, absent on dcrouter 34.x) and reads every other gateway through the
4658
+ gateway-client reads (`getGatewayClientMailOverview`, `getGatewayClientDomains`); it never chooses
4659
+ by catching an unknown method.
4618
4660
  - Status: a gateway pushes its `data.IGatewayStatusDocument` (`pushGatewayStatus`) after its hello,
4619
4661
  after every apply and on change, at most once per
4620
4662
  `data.gatewayConnectorContract.minimumStatusPushIntervalMs` (5 s). `getGateways` lists the gateways
@@ -4692,7 +4734,8 @@ guard that names roles excludes it by type.
4692
4734
  `data.validateAdoptGatewayResponse`, `data.validateRegisterGatewaySessionRequest`,
4693
4735
  `data.validateGatewayDesiredState` (envelope only), `data.validateGatewayApplyReport`,
4694
4736
  `data.validateGatewayStatusDocument`, `data.validateGatewayAreaExport`,
4695
- `data.validateGatewayRouteDnsResultsRequest`, `data.validateGatewayRouteDnsResultsResponse` and
4737
+ `data.validateGatewayRouteDnsResultsRequest`, `data.validateGatewayRouteDnsResultsResponse`,
4738
+ `data.validateGatewayMailObservationsRequest`, `data.validateGatewayMailObservationsResponse` and
4696
4739
  `data.validateGatewayAreaRowWrite`.
4697
4740
  - Operator rows (`ts/data/gatewayarearows.ts`, `requests.gatewayconnector`; Linus rulings 117 §4
4698
4741
  criterion 4, 121 §6 item 7, 166 points 2 and 4, 171): once a gateway is taken over, an
@@ -4729,7 +4772,10 @@ guard that names roles excludes it by type.
4729
4772
  compares it for equality only.
4730
4773
  - One check, one list: `data.validateGatewayAreaRowWrite` judges a write's envelope and secret
4731
4774
  forms (the controller before it reads, a client before it signs in; the controller answers a
4732
- problem as the connector refusal `request-invalid`), and `data.gatewayAreaSecretPaths` is the one
4775
+ problem as the connector refusal `request-invalid`; a put of a `security` `apiTokens` row
4776
+ whose policy binds a gateway client, by role `gatewayClient` or a `gatewayClient` member, is
4777
+ refused naming the row, while `data.validateGatewayAreaContent` keeps accepting such tokens in
4778
+ a 34.x gateway's export), and `data.gatewayAreaSecretPaths` is the one
4733
4779
  list of where a table holds a secret, from which `data.listGatewayAreaSecrets` is computed and
4734
4780
  which `data.projectGatewayAreaRow` and `data.resolveGatewayAreaRowWrite` walk. The controller
4735
4781
  mints versions with `data.createGatewaySealedVersion`.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.99.1',
6
+ version: '32.101.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
@@ -309,6 +309,13 @@ export interface IGatewayCapabilities {
309
309
  domains: boolean;
310
310
  inbound: boolean;
311
311
  outbound: boolean;
312
+ /**
313
+ * `getGatewayMailObservations` is served on the controller session
314
+ * (`requests.gatewayconnector.IReq_Cloudly_Gateway_GetGatewayMailObservations`): a controller
315
+ * reads mail observations through it, and through the gateway-client reads otherwise. Absent
316
+ * means unsupported.
317
+ */
318
+ observations?: boolean;
312
319
  };
313
320
  remoteIngress: {
314
321
  enabled: boolean;
@@ -507,9 +507,15 @@ const rowWriteKeys = Object.freeze({
507
507
  * deleted) and a row id (`isGatewayAreaRowId`) for a list member, a `sha256:` `expectedDigest`
508
508
  * (`null` only for a put), and for a put a strict JSON row whose `id` is the address's (a list
509
509
  * member) and whose every secret member (`gatewayAreaSecretPaths`) is `null` or one of its
510
- * keep-or-set forms. The controller answers any problem as the thrown connector refusal
511
- * `request-invalid`. The row's other members are the area validator's, judged with its table once
512
- * the write is resolved. Problems name keys and paths, never a value.
510
+ * keep-or-set forms. A put of a `security` `apiTokens` row whose policy binds a gateway client
511
+ * (role `gatewayClient`, or a non-null `gatewayClient`) is refused naming the row (Linus ruling 376
512
+ * item 6): the controller is the one author of the tables and compiles no gateway-client token, so
513
+ * such a write would vanish at the next compile and a gateway from dcrouter 35 refuses it. The
514
+ * content validator (`validateGatewayAreaContent`) keeps accepting the role, because it also judges
515
+ * exports of gateways before dcrouter 35, which legitimately hold such tokens. The controller answers
516
+ * any problem as the thrown connector refusal `request-invalid`. The row's other members are the
517
+ * area validator's, judged with its table once the write is resolved. Problems name keys, paths and
518
+ * the row id, never a value.
513
519
  */
514
520
  export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'): string[] => {
515
521
  const operation = readDataProperty(valueArg, 'operation')?.value;
@@ -538,6 +544,11 @@ export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'
538
544
  if (copied === null) return [...problems, `${pathArg} row must be strict JSON`];
539
545
  const row = copied.value;
540
546
  if (!singleton && !(isPlainRecord(row) && row.id === record.id)) problems.push(`${pathArg} row must be a row whose id is ${pathArg} id`);
547
+ if (area === 'security' && member === 'apiTokens' && isPlainRecord(row) && isPlainRecord(row.policy)
548
+ && (row.policy.role === 'gatewayClient' || (Object.hasOwn(row.policy, 'gatewayClient') && row.policy.gatewayClient !== null))) {
549
+ problems.push(`${pathArg} row ${isGatewayAreaRowId(record.id) ? record.id : '(invalid id)'} `
550
+ + 'binds a gateway client (policy role gatewayClient or a policy gatewayClient); a controller writes no gateway-client token');
551
+ }
541
552
  for (const secret of secretPathsOf(area, member)) {
542
553
  const place = parentOf(row, splitPath(secret.path));
543
554
  if (place === null || readSecretWriteForm(place.parent[place.key], secret.secretClass) === null) {
@@ -1312,6 +1312,265 @@ export const validateGatewayRouteDnsResultsResponse = (
1312
1312
  return errors;
1313
1313
  };
1314
1314
 
1315
+ // ---------------------------------------------------------------------------------------------
1316
+ // Mail observations (`getGatewayMailObservations`, Linus ruling 376 item 2)
1317
+ // ---------------------------------------------------------------------------------------------
1318
+
1319
+ /**
1320
+ * What a gateway observes about one domain its controller asked for: observed state, never a
1321
+ * member of an area table.
1322
+ */
1323
+ export interface IGatewayMailDomainObservation {
1324
+ /** The requested domain. */
1325
+ domain: string;
1326
+ /**
1327
+ * The gateway's email domain of exactly this name: `lifecycleStatus` is its mail DNS lifecycle
1328
+ * status (dcrouter's `TEmailDomainLifecycleStatus`, which its 34.x gateway-client mail overview
1329
+ * answered as `status`), `null` while the gateway has not reconciled it yet. An open word a reader
1330
+ * shows as text (Linus ruling 378 item 2), bounded by
1331
+ * `gatewayMailObservationsContract.maximumLifecycleStatusLength` like an email's `status`, so a new
1332
+ * gateway state needs no release here. `null` when the gateway configures no email domain of this
1333
+ * name.
1334
+ */
1335
+ emailDomain: { lifecycleStatus: string | null } | null;
1336
+ /**
1337
+ * The nameservers the gateway lists for its DNS zone of exactly this name, 1 to
1338
+ * `gatewayMailObservationsContract.maximumNameservers` distinct lowercase hostnames without a
1339
+ * trailing dot, in the gateway's order. `null` when the gateway holds no zone of this name or
1340
+ * lists no nameservers for it; a reader keeps what it knew before.
1341
+ */
1342
+ nameservers: string[] | null;
1343
+ }
1344
+
1345
+ /**
1346
+ * One recently cached email (dcrouter's `CachedEmail`): the entry shape of the 34.x gateway-client
1347
+ * mail overview (`requests.mail.IMailOverviewEmail`). `to` is the first recipient, `timestamp` the
1348
+ * Unix milliseconds the gateway accepted the email at; `direction` and `status` are the gateway's
1349
+ * open words, shown as text.
1350
+ */
1351
+ export interface IGatewayObservedEmail {
1352
+ id: string;
1353
+ direction?: string;
1354
+ from?: string;
1355
+ to?: string;
1356
+ subject?: string;
1357
+ status?: string;
1358
+ timestamp?: number;
1359
+ }
1360
+
1361
+ /**
1362
+ * The bounds of `getGatewayMailObservations`. Every text is judged in UTF-16 code units and holds no
1363
+ * control character (U+0000 to U+001F, U+007F) and no unpaired surrogate, so each unit costs at most
1364
+ * three bytes of JSON: at every bound the answer, with the request it answers, stays below the
1365
+ * 2 MiB message cap of the controller's socket server (Cloudly) at 1,779,407 bytes
1366
+ * (`test.gatewaymailobservations`). The gateway removes such characters from an email's texts and
1367
+ * shortens each text to its bound, on a code point boundary, before it answers; one text over its
1368
+ * bound refuses the whole answer.
1369
+ */
1370
+ export const gatewayMailObservationsContract = Object.freeze({
1371
+ /** Domains per request, and so domain entries per answer. */
1372
+ maximumDomains: 256,
1373
+ /** Nameservers per domain entry. */
1374
+ maximumNameservers: 16,
1375
+ /** Recent emails per answer: the 34.x overview's default limit. */
1376
+ maximumRecentEmails: 100,
1377
+ /** Characters of an email's `id`. */
1378
+ maximumEmailIdLength: 128,
1379
+ /** Characters of an email's `direction` and `status`, each. */
1380
+ maximumEmailWordLength: 32,
1381
+ /** Characters of an email domain's `lifecycleStatus`. */
1382
+ maximumLifecycleStatusLength: 32,
1383
+ /** Characters of an email's `from` and `to`, each. */
1384
+ maximumEmailAddressLength: 320,
1385
+ /** Characters of an email's `subject`: the RFC 5322 line limit. */
1386
+ maximumEmailSubjectLength: 998,
1387
+ } as const);
1388
+
1389
+ const observationControlCharacter = /[\u0000-\u001f\u007f]/;
1390
+ const unpairedSurrogate = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
1391
+
1392
+ /** A lowercase hostname without a trailing dot and without a wildcard label. */
1393
+ const isObservationHostname = (valueArg: unknown): valueArg is string => (
1394
+ typeof valueArg === 'string' && valueArg.length <= gatewayConnectorContract.maximumHostnameLength
1395
+ && valueArg.split('.').length >= 2
1396
+ && valueArg.split('.').every((labelArg) => dnsZoneLabel.test(labelArg))
1397
+ );
1398
+
1399
+ const validateObservationText = (valueArg: unknown, pathArg: string, maximumArg: number): string[] => (
1400
+ typeof valueArg === 'string' && valueArg.length > 0 && valueArg.length <= maximumArg
1401
+ && !observationControlCharacter.test(valueArg) && !unpairedSurrogate.test(valueArg)
1402
+ ? []
1403
+ : [`${pathArg} must be a text of 1 to ${maximumArg} characters without a control character or an unpaired `
1404
+ + 'UTF-16 surrogate']
1405
+ );
1406
+
1407
+ const observedEmailRequiredKeys = ['id'] as const;
1408
+ const observedEmailKeyList = ['id', 'direction', 'from', 'to', 'subject', 'status', 'timestamp'] as const;
1409
+ const observedEmailKeys: TCompleteKeyList<IGatewayObservedEmail, typeof observedEmailKeyList> = observedEmailKeyList;
1410
+ const mailDomainObservationKeyList = ['domain', 'emailDomain', 'nameservers'] as const;
1411
+ const mailDomainObservationKeys: TCompleteKeyList<IGatewayMailDomainObservation, typeof mailDomainObservationKeyList> =
1412
+ mailDomainObservationKeyList;
1413
+
1414
+ const validateObservedEmail = (valueArg: unknown, pathArg: string): string[] => {
1415
+ const email = readDataProperties(valueArg);
1416
+ if (email === null || !hasExactKeys(email, observedEmailRequiredKeys, observedEmailKeys)) {
1417
+ return [`${pathArg} must use its exact schema`];
1418
+ }
1419
+ const contract = gatewayMailObservationsContract;
1420
+ const errors = validateObservationText(email.id, `${pathArg} id`, contract.maximumEmailIdLength);
1421
+ const optionalTexts = [
1422
+ ['direction', contract.maximumEmailWordLength],
1423
+ ['from', contract.maximumEmailAddressLength],
1424
+ ['to', contract.maximumEmailAddressLength],
1425
+ ['subject', contract.maximumEmailSubjectLength],
1426
+ ['status', contract.maximumEmailWordLength],
1427
+ ] as const;
1428
+ for (const [key, maximum] of optionalTexts) {
1429
+ if (Object.hasOwn(email, key)) {
1430
+ errors.push(...validateObservationText(email[key], `${pathArg} ${key}`, maximum));
1431
+ }
1432
+ }
1433
+ if (Object.hasOwn(email, 'timestamp')
1434
+ && !(typeof email.timestamp === 'number' && Number.isSafeInteger(email.timestamp) && email.timestamp >= 0)) {
1435
+ errors.push(`${pathArg} timestamp must be a non-negative safe integer`);
1436
+ }
1437
+ return errors;
1438
+ };
1439
+
1440
+ const validateMailDomainObservation = (
1441
+ valueArg: unknown,
1442
+ requestedArg: readonly string[],
1443
+ indexArg: number,
1444
+ pathArg: string,
1445
+ ): string[] => {
1446
+ const entry = readExactDataRecord(valueArg, mailDomainObservationKeys);
1447
+ if (entry === null) {
1448
+ return [`${pathArg} must use its exact schema`];
1449
+ }
1450
+ const errors: string[] = [];
1451
+ if (indexArg >= requestedArg.length || entry.domain !== requestedArg[indexArg]) {
1452
+ errors.push(`${pathArg} domain must be requested domain ${indexArg + 1}, in request order`);
1453
+ }
1454
+ if (entry.emailDomain !== null) {
1455
+ const emailDomain = readExactDataRecord(entry.emailDomain, ['lifecycleStatus']);
1456
+ if (emailDomain === null) {
1457
+ errors.push(`${pathArg} emailDomain must be null or exactly { lifecycleStatus }`);
1458
+ } else if (emailDomain.lifecycleStatus !== null) {
1459
+ errors.push(...validateObservationText(emailDomain.lifecycleStatus, `${pathArg} emailDomain lifecycleStatus`,
1460
+ gatewayMailObservationsContract.maximumLifecycleStatusLength));
1461
+ }
1462
+ }
1463
+ if (entry.nameservers !== null) {
1464
+ const maximum = gatewayMailObservationsContract.maximumNameservers;
1465
+ const nameservers = readDataElements(entry.nameservers, maximum);
1466
+ if (nameservers === null || nameservers.length === 0) {
1467
+ errors.push(`${pathArg} nameservers must be null or a dense list of 1 to ${maximum} hostnames`);
1468
+ } else {
1469
+ nameservers.forEach((nameserverArg, indexArg) => {
1470
+ if (!isObservationHostname(nameserverArg)) {
1471
+ errors.push(`${pathArg} nameservers[${indexArg}] must be a lowercase hostname without a trailing dot`);
1472
+ } else if (nameservers.indexOf(nameserverArg) !== indexArg) {
1473
+ errors.push(`${pathArg} nameservers[${indexArg}] repeats an earlier nameserver`);
1474
+ }
1475
+ });
1476
+ }
1477
+ }
1478
+ return errors;
1479
+ };
1480
+
1481
+ /**
1482
+ * Validates a `getGatewayMailObservations` request and names every reason it is refused: exactly
1483
+ * `{ domains }`, 1 to `gatewayMailObservationsContract.maximumDomains` lowercase hostnames without a
1484
+ * trailing dot or a wildcard label, strictly ascending by `compareWireTokens`.
1485
+ */
1486
+ export const validateGatewayMailObservationsRequest = (
1487
+ valueArg: unknown,
1488
+ pathArg = 'gateway mail observations request',
1489
+ ): string[] => {
1490
+ const record = readExactDataRecord(valueArg, ['domains']);
1491
+ if (record === null) {
1492
+ return [`${pathArg} must use its exact schema`];
1493
+ }
1494
+ const maximum = gatewayMailObservationsContract.maximumDomains;
1495
+ const domains = readDataElements(record.domains, maximum);
1496
+ if (domains === null || domains.length === 0) {
1497
+ return [`${pathArg} domains must be a dense list of 1 to ${maximum} domains`];
1498
+ }
1499
+ const errors: string[] = [];
1500
+ domains.forEach((domainArg, indexArg) => {
1501
+ if (!isObservationHostname(domainArg)) {
1502
+ errors.push(`${pathArg} domains[${indexArg}] must be a lowercase domain without a trailing dot or a wildcard`);
1503
+ } else if (indexArg > 0 && typeof domains[indexArg - 1] === 'string'
1504
+ && compareWireTokens(domains[indexArg - 1] as string, domainArg) >= 0) {
1505
+ errors.push(`${pathArg} domains must be strictly ascending`);
1506
+ }
1507
+ });
1508
+ return errors;
1509
+ };
1510
+
1511
+ /**
1512
+ * Validates a `getGatewayMailObservations` answer against the request it answers and names every
1513
+ * reason it is refused: exactly `{ domains, emails }`; `domains` one `IGatewayMailDomainObservation`
1514
+ * per requested domain, each once and in the request's order, exact keys, a lifecycle status that
1515
+ * is `null` or a clean text of at most `gatewayMailObservationsContract.maximumLifecycleStatusLength`
1516
+ * characters, nameservers `null` or 1 to
1517
+ * `gatewayMailObservationsContract.maximumNameservers` distinct lowercase hostnames; `emails` at most
1518
+ * `gatewayMailObservationsContract.maximumRecentEmails` `IGatewayObservedEmail` entries with distinct
1519
+ * ids, the keys of the type and no other, each text within its bound. Which emails the gateway
1520
+ * chose (a sender or a recipient in a requested domain, newest first) is the gateway's statement,
1521
+ * which no shape can show. A request that fails `validateGatewayMailObservationsRequest` is refused
1522
+ * first, since no answer can match it. The controller judges every answer with this before it uses
1523
+ * one, never with a copy.
1524
+ */
1525
+ export const validateGatewayMailObservationsResponse = (
1526
+ valueArg: unknown,
1527
+ requestArg: Readonly<{ domains: readonly string[] }>,
1528
+ pathArg = 'gateway mail observations response',
1529
+ ): string[] => {
1530
+ const requestErrors = validateGatewayMailObservationsRequest(requestArg, `${pathArg} request`);
1531
+ if (requestErrors.length > 0) {
1532
+ return requestErrors;
1533
+ }
1534
+ const record = readExactDataRecord(valueArg, ['domains', 'emails']);
1535
+ if (record === null) {
1536
+ return [`${pathArg} must use its exact schema`];
1537
+ }
1538
+ const errors: string[] = [];
1539
+ const requested = requestArg.domains;
1540
+ const domains = readDataElements(record.domains, gatewayMailObservationsContract.maximumDomains);
1541
+ if (domains === null) {
1542
+ errors.push(`${pathArg} domains must be a dense list of at most ${gatewayMailObservationsContract.maximumDomains} `
1543
+ + 'entries');
1544
+ } else {
1545
+ if (domains.length !== requested.length) {
1546
+ errors.push(`${pathArg} domains must answer each of the ${requested.length} requested domains once`);
1547
+ }
1548
+ domains.forEach((entryArg, indexArg) => {
1549
+ errors.push(...validateMailDomainObservation(entryArg, requested, indexArg, `${pathArg} domains[${indexArg}]`));
1550
+ });
1551
+ }
1552
+ const maximumEmails = gatewayMailObservationsContract.maximumRecentEmails;
1553
+ const emails = readDataElements(record.emails, maximumEmails);
1554
+ if (emails === null) {
1555
+ errors.push(`${pathArg} emails must be a dense list of at most ${maximumEmails} entries`);
1556
+ return errors;
1557
+ }
1558
+ const seenIds = new Set<string>();
1559
+ emails.forEach((emailArg, indexArg) => {
1560
+ const emailPath = `${pathArg} emails[${indexArg}]`;
1561
+ const emailErrors = validateObservedEmail(emailArg, emailPath);
1562
+ errors.push(...emailErrors);
1563
+ const id = emailErrors.length === 0 ? readDataProperties(emailArg)?.id : undefined;
1564
+ if (typeof id === 'string') {
1565
+ if (seenIds.has(id)) {
1566
+ errors.push(`${emailPath} id repeats an earlier email`);
1567
+ }
1568
+ seenIds.add(id);
1569
+ }
1570
+ });
1571
+ return errors;
1572
+ };
1573
+
1315
1574
  const validateGatewayClientId = (valueArg: unknown, pathArg: string): string[] => (
1316
1575
  isGatewayClientIdText(valueArg)
1317
1576
  ? []
@@ -17,6 +17,7 @@ import type {
17
17
  IIsolatedRestoreControlWriteRequest,
18
18
  IIsolatedRestoreProgress,
19
19
  } from '../data/isolatedrestore.js';
20
+ import type { ILocationScope } from '../data/location.js';
20
21
  import type { IService } from '../data/service.js';
21
22
  import type { IIdentity, IIdentityCredential } from '../data/user.js';
22
23
  import type { ICorestoreDatabaseClosureDescriptor } from '../runtime.corestore.relay.js';
@@ -58,9 +59,22 @@ extends plugins.typedrequestInterfaces.implementsTR<
58
59
  identity: IIdentity;
59
60
  serviceId?: string;
60
61
  status?: IBackupRecord['status'];
62
+ /**
63
+ * Only the backups taken in this location: those whose recorded `clusterId` names a cluster
64
+ * standing in it (`data.getClusterLocationId`). A backup without `clusterId` is in no scoped
65
+ * answer; its service's current placement plays no part. A cluster without nodes or whose nodes
66
+ * span locations places nothing. Applies together with `serviceId` and `status`. Refused
67
+ * `location-not-found` when no location has that id.
68
+ */
69
+ locationScope?: ILocationScope;
61
70
  };
62
71
  response: {
63
72
  backups: IBackupRecord[];
73
+ /**
74
+ * The scope Cloudly applied, echoing `locationScope`. Absent from a Cloudly that ignored the
75
+ * scope (one built before it): its list is unscoped and must not be shown as scoped.
76
+ */
77
+ appliedLocationScope?: ILocationScope;
64
78
  };
65
79
  }
66
80
 
@@ -1,4 +1,5 @@
1
1
  import * as plugins from '../plugins.js';
2
+ import type { ILocationScope } from '../data/location.js';
2
3
  import type { IIdentity } from '../data/user.js';
3
4
  import type {
4
5
  ICorestoreLegacyResourceAdoptionPlanEntry,
@@ -239,8 +240,21 @@ extends plugins.typedrequestInterfaces.implementsTR<
239
240
  method: 'getCorestoreInventory';
240
241
  request: {
241
242
  identity: IIdentity;
243
+ /**
244
+ * Only the rows of the nodes standing in this location: `inventories` and `probes` hold only
245
+ * nodes whose own `data.locationId` is this location, the rule `getNodes` applies (not the
246
+ * node's cluster). Refused `location-not-found` when no location has that id.
247
+ */
248
+ locationScope?: ILocationScope;
249
+ };
250
+ /** The report itself carries no scope; the echo belongs to this answer only. */
251
+ response: ICorestoreInventoryReport & {
252
+ /**
253
+ * The scope Cloudly applied, echoing `locationScope`. Absent from a Cloudly that ignored the
254
+ * scope (one built before it): its report is unscoped and must not be shown as scoped.
255
+ */
256
+ appliedLocationScope?: ILocationScope;
242
257
  };
243
- response: ICorestoreInventoryReport;
244
258
  }
245
259
 
246
260
  /**
@@ -7,6 +7,8 @@ import type {
7
7
  IGatewayAreaExport,
8
8
  IGatewayApplyReport,
9
9
  IGatewayDesiredState,
10
+ IGatewayMailDomainObservation,
11
+ IGatewayObservedEmail,
10
12
  IGatewayStatusDocument,
11
13
  IRegisterGatewaySessionRequest,
12
14
  TGatewayConfigArea,
@@ -160,10 +162,11 @@ export interface IReq_Cloudly_Gateway_ExportGatewayArea extends plugins.typedreq
160
162
  *
161
163
  * Peer gate: a gateway built before this request answers no handler for it. The controller calls it
162
164
  * only on a gateway whose hello (`data.IRegisterGatewaySessionRequest.interfacesVersion`) states the
163
- * release of this package that declares it or a later one, the rule this package's validators set
164
- * for every new member and method (a controller sends one only to a gateway whose stated
165
- * `interfacesVersion` knows it); a gateway therefore moves to that release only together with
166
- * serving the call.
165
+ * release of this package that declares it or a later one (a controller sends a new member only to
166
+ * a gateway whose stated `interfacesVersion` knows it); a gateway therefore moves to that release
167
+ * only together with serving the call. A later controller-session read may instead be gated by an
168
+ * `IGatewayCapabilities` flag, as `getGatewayMailObservations` is (`email.observations`), because a
169
+ * gateway can move to the release that declares a read before it serves it.
167
170
  */
168
171
  export interface IReq_Cloudly_Gateway_GetGatewayRouteDnsResults extends plugins.typedrequestInterfaces.implementsTR<
169
172
  plugins.typedrequestInterfaces.ITypedRequest,
@@ -181,6 +184,54 @@ export interface IReq_Cloudly_Gateway_GetGatewayRouteDnsResults extends plugins.
181
184
  };
182
185
  }
183
186
 
187
+ /**
188
+ * The controller reads what the gateway observes about mail for some domains (Linus ruling 376
189
+ * item 2): per domain the mail DNS lifecycle status of the gateway's email domain of that name and
190
+ * the nameservers of its DNS zone of that name, and the gateway's recent cached emails whose sender
191
+ * or a recipient is in one of the domains, newest first, at most
192
+ * `data.gatewayMailObservationsContract.maximumRecentEmails`. An address is in a domain when the part
193
+ * after its last `@`, lowercased, equals that requested domain; there is no suffix or subdomain
194
+ * matching (Linus ruling 378 item 4). It is observed state, never a member of an area table, and
195
+ * nothing is written. It replaces, for a gateway that serves it, what the gateway-client reads
196
+ * `getGatewayClientMailOverview` and `getGatewayClientDomains` answered about these observations;
197
+ * the controller names the domains (from its own records), because a gateway that serves this read
198
+ * has no gateway-client scope to derive them from. The scope is the whole domain: on a gateway with
199
+ * the flag the view shows the cached mail of the controller's whole domains, not only the bound
200
+ * addresses the 34.x gateway-client overview filtered to.
201
+ *
202
+ * The gateway answers only after the session's registration, with one domain entry per requested
203
+ * domain, in request order (`data.IGatewayMailDomainObservation`; `emailDomain` and `nameservers`
204
+ * `null` for what it does not hold). A request that fails `data.validateGatewayMailObservationsRequest`
205
+ * is refused `request-invalid`. "Cannot read" and "holds nothing" are different answers (Linus
206
+ * ruling 378 item 1): a gateway with mail not configured answers the truth (`emailDomain: null`,
207
+ * `emails: []`), while a gateway whose email domain store, zone store or email cache exists but is
208
+ * not ready or fails answers an error without a named refusal, never a silent empty or partial
209
+ * answer. The
210
+ * controller judges every answer with `data.validateGatewayMailObservationsResponse` before it uses
211
+ * it; one text over its bound refuses the whole answer, so the gateway cleans and shortens every
212
+ * email text first (`data.gatewayMailObservationsContract`).
213
+ *
214
+ * Capability gate: the controller calls it only on a gateway whose `getGatewayCapabilities` answers
215
+ * `email.observations: true` (`data.IGatewayCapabilities`), and reads a gateway without the flag
216
+ * through the gateway-client reads as before. It never chooses by calling and catching an unknown
217
+ * method.
218
+ */
219
+ export interface IReq_Cloudly_Gateway_GetGatewayMailObservations extends plugins.typedrequestInterfaces.implementsTR<
220
+ plugins.typedrequestInterfaces.ITypedRequest,
221
+ IReq_Cloudly_Gateway_GetGatewayMailObservations
222
+ > {
223
+ method: 'getGatewayMailObservations';
224
+ /** `data.validateGatewayMailObservationsRequest`. */
225
+ request: {
226
+ domains: string[];
227
+ };
228
+ /** `data.validateGatewayMailObservationsResponse`. */
229
+ response: {
230
+ domains: IGatewayMailDomainObservation[];
231
+ emails: IGatewayObservedEmail[];
232
+ };
233
+ }
234
+
184
235
  /**
185
236
  * An administrator makes a one-time adoption code, either for a new gateway in an existing
186
237
  * location or for an existing gateway record (re-adoption). Adoption never creates a location.
@@ -4,6 +4,7 @@ import type { TServiceUpdateWritableData, TServiceWritableData } from '../data/s
4
4
  import type { IServicePlacement } from '../data/service.js';
5
5
  import type { TServiceVolumeInitialization } from '../data/servicevolumeinitialization.js';
6
6
  import type { IRegistryTarget } from '../data/registry.js';
7
+ import type { ILocationScope } from '../data/location.js';
7
8
  import type { IIdentity, IIdentityCredential } from '../data/user.js';
8
9
  import type { IServiceRessources } from '../data/docker.js';
9
10
  import type { IImageRelease } from '../data/immutableimage.js';
@@ -153,9 +154,26 @@ extends plugins.typedrequestInterfaces.implementsTR<
153
154
  method: 'getServices';
154
155
  request: {
155
156
  identity: IIdentity;
157
+ /**
158
+ * Only the services placed in this location. A service's placed clusters are the union of the
159
+ * clusters of its runtime specs (`IServiceRuntimeSpec.clusterId`, one per target), its current
160
+ * plan's `data.imageDeployment.targetScope.targetClusterIds` and, for a Swarm-era service, the
161
+ * cluster of the node `data.placement.nodeName` pins it to; a shadow counts through the record
162
+ * that places it on its cluster. The service is in the answer when any placed cluster stands in
163
+ * this location (`data.getClusterLocationId`), so a service placed in several locations is in
164
+ * each of their answers. A service with no placed cluster is in no scoped answer, and a cluster
165
+ * without nodes or whose nodes span locations places nothing. Refused `location-not-found` when
166
+ * no location has that id.
167
+ */
168
+ locationScope?: ILocationScope;
156
169
  };
157
170
  response: {
158
171
  services: IService[];
172
+ /**
173
+ * The scope Cloudly applied, echoing `locationScope`. Absent from a Cloudly that ignored the
174
+ * scope (one built before it): its list is unscoped and must not be shown as scoped.
175
+ */
176
+ appliedLocationScope?: ILocationScope;
159
177
  };
160
178
  }
161
179