@serve.zone/interfaces 32.96.0 → 32.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/changelog.md +19 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/coremail.d.ts +106 -1
  4. package/dist_ts/data/coremail.js +14 -1
  5. package/dist_ts/data/coremail.runtime.d.ts +25 -1
  6. package/dist_ts/data/coremail.runtime.js +106 -2
  7. package/dist_ts/data/idempotencykey.d.ts +20 -0
  8. package/dist_ts/data/idempotencykey.js +47 -0
  9. package/dist_ts/data/index.d.ts +2 -0
  10. package/dist_ts/data/index.js +3 -1
  11. package/dist_ts/data/mail.d.ts +14 -0
  12. package/dist_ts/data/mail.js +1 -1
  13. package/dist_ts/data/outcomeunknown.d.ts +31 -0
  14. package/dist_ts/data/outcomeunknown.js +43 -0
  15. package/dist_ts/data/runtimesession.d.ts +19 -0
  16. package/dist_ts/data/runtimesession.js +12 -3
  17. package/dist_ts/data/witness.js +6 -4
  18. package/dist_ts/requests/backup.d.ts +9 -0
  19. package/dist_ts/requests/cluster.d.ts +9 -0
  20. package/dist_ts/requests/coremail.d.ts +31 -0
  21. package/dist_ts/requests/image.d.ts +9 -0
  22. package/dist_ts/requests/service.d.ts +9 -0
  23. package/package.json +1 -1
  24. package/readme.md +95 -4
  25. package/ts/00_commitinfo_data.ts +1 -1
  26. package/ts/data/coremail.runtime.ts +152 -2
  27. package/ts/data/coremail.ts +111 -1
  28. package/ts/data/idempotencykey.ts +51 -0
  29. package/ts/data/index.ts +2 -0
  30. package/ts/data/mail.ts +14 -0
  31. package/ts/data/outcomeunknown.ts +71 -0
  32. package/ts/data/runtimesession.ts +29 -2
  33. package/ts/data/witness.ts +5 -3
  34. package/ts/requests/backup.ts +9 -0
  35. package/ts/requests/cluster.ts +9 -0
  36. package/ts/requests/coremail.ts +31 -0
  37. package/ts/requests/image.ts +9 -0
  38. package/ts/requests/service.ts +9 -0
package/readme.md CHANGED
@@ -4146,6 +4146,45 @@ interface IExampleRequest {
4146
4146
 
4147
4147
  `requests.config.IRequest_Any_Cloudly_GetClusterConfig` accepts `data.IIdentityCredential`, which contains only the JWT needed for server-side identity resolution. Username/password login and machine-token exchange responses continue to return the full `data.IIdentity`.
4148
4148
 
4149
+ ### Unknown Write Outcomes
4150
+
4151
+ A write that was sent and never confirmed may have been stored or not (a deadline expired during its
4152
+ commit, the connection was lost after the commit was sent, the database closed while the commit ran).
4153
+ A controller answers that to an operator (admin API, dashboard, CLI) by one name,
4154
+ `data.outcomeUnknownCode` (`outcome-unknown`): never as `Internal server error`, as a refusal that
4155
+ says nothing was stored, or as done.
4156
+
4157
+ - Over TypedRequest the answer is a `TypedResponseError` whose `errorData` is
4158
+ `data.IOutcomeUnknownErrorData`, exactly `{ code: 'outcome-unknown', retryable: false }`
4159
+ (`data.createOutcomeUnknownErrorData`); `data.readOutcomeUnknownErrorData` reads anything else as no
4160
+ such answer. An operator surface with its own answer form (a CLI result line, an HTTP body) states the
4161
+ same `code`.
4162
+ - What the caller does is `data.outcomeUnknownInstruction`: read the current state again, then decide;
4163
+ never send the write again unread. Sending a request again unchanged is such a read only when its
4164
+ replay answers what it stored (a request that carries an `idempotencyKey`).
4165
+ - Node-facing answers keep their own names (`deadline`, `controller-deadline`). The witness's own
4166
+ `outcome-unknown` (`data.witnessRefusals`) is the same word for the same fact about its record, but
4167
+ its payload differs: it is one of `data.witnessMomentaryRefusals`, so its `errorData` carries
4168
+ `retryable: true` (the same request may be sent later, once the record has been read), where the
4169
+ general answer carries `retryable: false`.
4170
+
4171
+ ### Create Idempotency Keys
4172
+
4173
+ `createService`, `createCluster`, `createServiceBackup` (a manual backup) and `createImage` take an
4174
+ optional `idempotencyKey` naming the user action the create belongs to: a create sent again with the
4175
+ same key, after an answer that never arrived or one named `outcome-unknown`, is answered with the record
4176
+ the first one stored instead of creating a second. A first-party caller sends one key per user action,
4177
+ never one per attempt, and never a key derived from the request's content. The key is a bounded
4178
+ canonical identifier (`data.isIdempotencyKey`, at most `data.idempotencyKeyContract.maximumLength`
4179
+ (200) characters, the rule `data.validateDeploymentReservationInput`,
4180
+ `data.validateServiceReleaseDeploymentStartInput` and the deployment adoption validators apply; a
4181
+ CoreMail submission's `idempotencyKey` keeps its own rule, any non-empty string of at most 256 UTF-8
4182
+ bytes), and
4183
+ `data.validateCreateIdempotencyKey(request)` judges the member when the request states it. It is
4184
+ optional in this major so callers built before it keep working, and becomes required at the next major.
4185
+ A controller built before the member ignores it, so a caller that relies on it names the minimum
4186
+ controller that honours it.
4187
+
4149
4188
  ### Immutable Deployment Contracts
4150
4189
 
4151
4190
  Cloudly deployment authority is expressed as an exact `data.IServiceDeploymentGrant`. A `service` grant applies to one owned existing service. An `organization-service-slot` grant reserves authority for one exact future service ID in an organization; it is not an organization-wide wildcard. `configureServiceDeploymentMachineUser` accepts this discriminated `grant` object instead of separate service and capability fields.
@@ -4860,9 +4899,10 @@ const sealedVersions = data.listGatewayAreaSecrets('routes', routes).map((secret
4860
4899
  ### Controller Peer Set
4861
4900
 
4862
4901
  `data.IControllerPeerSet` (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) is where the
4863
- components that dial a controller reach it: a gateway, a relay and a Spark node. AGL-1192 adds the
4864
- ways the controller states it beyond the gateway's adoption and hello answers, and one rule for
4865
- admitting it.
4902
+ components that dial a controller reach it: a gateway, a relay, a Spark node and a Pallet node.
4903
+ CoreMail, which never dials a controller, receives the same set on its control session and stores
4904
+ it only to fence that session. AGL-1192 adds the ways the controller states it beyond the
4905
+ gateway's adoption and hello answers, and one rule for admitting it.
4866
4906
 
4867
4907
  - Judge: `data.judgeControllerPeerSet(stored, next)` answers, in this order, `controller-mismatch`
4868
4908
  for another `controllerId`, `controller-epoch-older` for an older `epoch`, `equal` when all four
@@ -4885,6 +4925,20 @@ admitting it.
4885
4925
  set, so `data.sparkSwarmNodeContracts.heartbeat.maxResponseBytes` is 40_960: the largest set
4886
4926
  `data.validateControllerPeerSet` admits (a 200-character id, a 16-digit epoch, 17 origins of
4887
4927
  2048 characters) on top of the 2048 bytes the rest of the answer takes.
4928
+ - Node registration answer: `data.IRegisterPalletRuntimeSessionResponse.controller` (32.98.0) is
4929
+ optional too, beside the session binding and never in it. That answer is read exactly
4930
+ (`data.snapshotRegisterPalletRuntimeSessionResponse`) by the relay that carries it and again by
4931
+ the node, so a reader built before the member refuses the whole answer and the node's session
4932
+ ends. From the Cloudly release that sends it, Cloudly's sender states it only when the
4933
+ `IProtocolOffer.interfacesVersion` of the node's registration and of the carrying relay's
4934
+ `registerClusterRelay` are both 32.98.0 or later; no other member states support. The relay
4935
+ registration answer needs no such gate, because its reader ignores the member.
4936
+ - CoreMail: `requests.coremail.IReq_CoreMailAuthenticateControl` carries an optional `controller`
4937
+ (32.98.0). From the CoreMail release with the check, CoreMail judges it with
4938
+ `data.judgeControllerPeerSet` only after the control credential verified, stores it and never
4939
+ dials an origin in it, and answers `controller-mismatch` or `controller-epoch-older` as a CoreMail
4940
+ error code before it closes the session; a credential failure still closes 4401 unanswered. See
4941
+ [CoreMail contracts](#coremail-contracts).
4888
4942
  - Adding a shadow: `requests.controller.IReq_Admin_Cloudly_AddControllerShadow`
4889
4943
  (`addControllerShadow`, `{ identity, origin, bearerSha256 }`) names the shadow's site origin and
4890
4944
  the SHA-256 of the witness bearer that site created for itself, never the bearer. The active
@@ -5247,6 +5301,25 @@ shape is removed in the next major. Apply
5247
5301
  `data.normalizeCoreMailReconciliationStatus` before using pending-inbound or
5248
5302
  composite active-session counts for drain and rotation decisions.
5249
5303
 
5304
+ The `coreMailAuthenticateControl` request carries an optional `controller`, the
5305
+ controller's `data.IControllerPeerSet` (32.98.0, see
5306
+ [Controller Peer Set](#controller-peer-set)). From the CoreMail release with the
5307
+ check, CoreMail judges it with `data.judgeControllerPeerSet` only after the
5308
+ credential verified, stores the first set it is stated, and never dials an
5309
+ origin in it. It answers the two controller refusals, `controller-mismatch` and
5310
+ `controller-epoch-older`, which are `data.TCoreMailErrorCode` values under their
5311
+ own names (`retryable: false`), and then closes the session; a credential
5312
+ failure still closes 4401 unanswered. Once a set is stored, a session without
5313
+ one is refused `controller-epoch-older`. CoreMail never writes either code into
5314
+ a reconciliation status, and `data.normalizeCoreMailReconciliationStatus`
5315
+ refuses a status `errorCode` that is one. The response answers an optional
5316
+ `appliedConfigEpoch`, the epoch of the desired state CoreMail has applied, `0`
5317
+ when it has applied none, read by
5318
+ `data.normalizeCoreMailControlAppliedConfigEpoch`. A CoreMail built before it
5319
+ omits the member: absent is "not stated", never `0`. Both members sit at the top
5320
+ level, where the readers built before them ignore them; neither enters the
5321
+ desired state, its digest or the reconciliation status.
5322
+
5250
5323
  #### CoreMail runtime environment (CoreMail 34 and later)
5251
5324
 
5252
5325
  CoreMail 34 reads:
@@ -5312,6 +5385,20 @@ part of settings: `data.cloudlySystemSecretKeys` publishes
5312
5385
  stable keys of the removed values. The submission listener's PEM material is
5313
5386
  operator-supplied in v1; automatic issuance is a later workstream.
5314
5387
 
5388
+ `data.ICoreMailInstance` (32.98.0) is one cluster's CoreMail, the per-cluster
5389
+ record that is to replace these settings, keyed by `clusterId`: the CoreMail
5390
+ service, an `enabled` switch, the control endpoint, the transfer origin, the
5391
+ control and gateway credential identities, the SMTP listener or `null`, the
5392
+ binding limits, and the controller's `reservedConfigEpoch`.
5393
+ `data.normalizeCoreMailInstance` reads it exactly. It names no secret or
5394
+ verifier: an instance's system secrets live under the owner and management scope
5395
+ `data.createCoreMailInstanceSecretOwnership(clusterId)` answers, keyed by
5396
+ `data.coreMailInstanceSecretKeys`, the same names as above, so the TLS key
5397
+ names a desired state carries stay byte-identical. It names no gateway endpoint
5398
+ (that stays `coreMailGatewayEndpointUrl`) and no applied epoch (CoreMail answers
5399
+ it at session open). Nothing reads the record yet, and the settings above stay
5400
+ the working path in this release.
5401
+
5315
5402
  Secrets that Cloudly manages for CoreMail use the `coremail` management source
5316
5403
  and a `coremail:<identifier>` management scope, validated by the existing
5317
5404
  `data.validateSecretManagementScope` and secret-metadata validators.
@@ -5323,7 +5410,11 @@ verification hash, the binding state, and any `retiring` predecessor with its
5323
5410
  `data.TServiceWritableData`, so only the control plane writes it while the rest
5324
5411
  of `mail` stays caller-writable. `IServiceMailConfig.allowedSenders` makes the
5325
5412
  outbound sender allowlist explicit instead of inferring it from per-address
5326
- `outbound.enabled`.
5413
+ `outbound.enabled`. `ICoreMailServiceBinding.coreMailServiceId` (32.98.0,
5414
+ optional, required at the next major) names the CoreMail the binding was minted
5415
+ on, which holds its state; it is never re-derived from the service's placement.
5416
+ From the Cloudly release that writes it, Cloudly derives it once at mint and
5417
+ reports a service whose cluster no longer matches instead of moving it.
5327
5418
 
5328
5419
  `requests.coremailAdmin` carries the identity-authenticated operator surface:
5329
5420
  `getCoreMailServiceMailStatistics` for per-service daily counters,
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.96.0',
6
+ version: '32.98.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
@@ -27,6 +27,10 @@ import {
27
27
  type ICoreMailInboundDelivery,
28
28
  type ICoreMailInboundDeliveryPage,
29
29
  type ICoreMailInboundMailCounters,
30
+ type ICoreMailInstance,
31
+ type ICoreMailInstanceCredential,
32
+ type ICoreMailInstanceSecretOwnership,
33
+ type ICoreMailInstanceSmtp,
30
34
  type ICoreMailMailbox,
31
35
  type ICoreMailOutboundMailCounters,
32
36
  type ICoreMailOutboundMessageDescriptor,
@@ -47,7 +51,9 @@ import {
47
51
  type TCoreMailSubmissionSource,
48
52
  type TCoreMailWorkloadOperation,
49
53
  } from './coremail.js';
50
- import type { IMailConnectionInfo } from './mail.js';
54
+ import { controllerPeerSetRefusals } from './controller.js';
55
+ import type { IMailConnectionInfo, TServiceMailSubmissionTlsMode } from './mail.js';
56
+ import { isClusterNodeId } from '../private/nodeidentifier.js';
51
57
  import {
52
58
  validateWorkloadReplicaIdentity,
53
59
  type IWorkloadReplicaIdentity,
@@ -1055,8 +1061,19 @@ const coreMailErrorCodes = new Set<TCoreMailErrorCode>([
1055
1061
  'DELIVERY_DEAD_LETTERED',
1056
1062
  'GATEWAY_UNAVAILABLE',
1057
1063
  'RECONCILIATION_FENCE_MISMATCH',
1064
+ ...controllerPeerSetRefusals,
1058
1065
  ]);
1059
1066
 
1067
+ /**
1068
+ * The codes a reconciliation status may carry as `errorCode`: every CoreMail error code but the
1069
+ * controller refusals (`controllerPeerSetRefusals`), which CoreMail answers only to the control
1070
+ * authentication and never writes into a status. Derived from the one code list, never a copy.
1071
+ */
1072
+ const coreMailReconciliationErrorCodes: ReadonlySet<TCoreMailErrorCode> = new Set(
1073
+ [...coreMailErrorCodes].filter((codeArg) =>
1074
+ !controllerPeerSetRefusals.some((refusalArg) => refusalArg === codeArg)),
1075
+ );
1076
+
1060
1077
  export const normalizeCoreMailErrorData = (
1061
1078
  valueArg: unknown,
1062
1079
  pathArg = 'error',
@@ -2055,7 +2072,7 @@ export const normalizeCoreMailReconciliationStatus = (
2055
2072
  if (hasErrorCode) {
2056
2073
  if (
2057
2074
  typeof record.errorCode !== 'string'
2058
- || !coreMailErrorCodes.has(record.errorCode as TCoreMailErrorCode)
2075
+ || !coreMailReconciliationErrorCodes.has(record.errorCode as TCoreMailErrorCode)
2059
2076
  ) {
2060
2077
  fail(`${pathArg}.errorCode is invalid`);
2061
2078
  }
@@ -2140,6 +2157,139 @@ export const normalizeCoreMailGatewayPeerDesiredState = (
2140
2157
  });
2141
2158
  };
2142
2159
 
2160
+ const coreMailInstanceSmtpTlsModes: readonly TServiceMailSubmissionTlsMode[] = Object.freeze([
2161
+ 'plain',
2162
+ 'starttls',
2163
+ 'implicitTls',
2164
+ ]);
2165
+
2166
+ const requireCoreMailClusterId = (valueArg: unknown, pathArg: string): string => {
2167
+ if (!isClusterNodeId(valueArg)) {
2168
+ return fail(`${pathArg} must be 1 to 128 characters of letters, digits, underscore or hyphen`);
2169
+ }
2170
+ return valueArg;
2171
+ };
2172
+
2173
+ const normalizeInstanceCredential = (
2174
+ valueArg: unknown,
2175
+ pathArg: string,
2176
+ ): ICoreMailInstanceCredential => {
2177
+ const record = readRecord(valueArg, pathArg);
2178
+ assertKeys(record, pathArg, ['credentialId', 'credentialVersion']);
2179
+ return {
2180
+ credentialId: requireIdentifier(record.credentialId, `${pathArg}.credentialId`),
2181
+ credentialVersion: requireSafeInteger(record.credentialVersion, `${pathArg}.credentialVersion`, 1),
2182
+ };
2183
+ };
2184
+
2185
+ const normalizeInstanceSmtp = (valueArg: unknown, pathArg: string): ICoreMailInstanceSmtp => {
2186
+ const record = readRecord(valueArg, pathArg);
2187
+ assertKeys(record, pathArg, ['host', 'port', 'tlsMode']);
2188
+ if (!coreMailInstanceSmtpTlsModes.some((modeArg) => modeArg === record.tlsMode)) {
2189
+ fail(`${pathArg}.tlsMode must be one of ${coreMailInstanceSmtpTlsModes.join(', ')}`);
2190
+ }
2191
+ return {
2192
+ // The listener's EHLO hostname in the desired state, so it is read by that member's rule.
2193
+ host: requireCanonicalHostname(record.host, `${pathArg}.host`),
2194
+ port: requireSafeInteger(record.port, `${pathArg}.port`, 1, 65_535),
2195
+ tlsMode: record.tlsMode as TServiceMailSubmissionTlsMode,
2196
+ };
2197
+ };
2198
+
2199
+ /**
2200
+ * One cluster's CoreMail record (`ICoreMailInstance`), read exactly: every member required, no
2201
+ * other member, `smtp` an object or `null`. The URLs, credential identities and limits are read by
2202
+ * the rules of the desired-state members they compose into (the transfer origin, the gateway
2203
+ * credential, the SMTP listener and the binding limits), so a record that passes composes a
2204
+ * desired state that passes. The control endpoint is the canonical `https://<host>/socket`.
2205
+ *
2206
+ * Shape only: whether the cluster exists, whether the service runs on it, and whether this record
2207
+ * is the only one naming either id are the controller's to judge against its own records.
2208
+ */
2209
+ export const normalizeCoreMailInstance = (
2210
+ valueArg: unknown,
2211
+ pathArg = 'coreMailInstance',
2212
+ ): ICoreMailInstance => {
2213
+ const record = readRecord(valueArg, pathArg);
2214
+ assertKeys(record, pathArg, [
2215
+ 'clusterId',
2216
+ 'coreMailServiceId',
2217
+ 'enabled',
2218
+ 'controlEndpointUrl',
2219
+ 'transferOrigin',
2220
+ 'controlCredential',
2221
+ 'gatewayCredential',
2222
+ 'smtp',
2223
+ 'bindingLimits',
2224
+ 'reservedConfigEpoch',
2225
+ ]);
2226
+ if (typeof record.enabled !== 'boolean') {
2227
+ fail(`${pathArg}.enabled must be boolean`);
2228
+ }
2229
+ const controlEndpointUrl = requireCanonicalUrl(
2230
+ record.controlEndpointUrl,
2231
+ `${pathArg}.controlEndpointUrl`,
2232
+ 'https:',
2233
+ false,
2234
+ );
2235
+ if (new URL(controlEndpointUrl).pathname !== '/socket') {
2236
+ fail(`${pathArg}.controlEndpointUrl must be the /socket path`);
2237
+ }
2238
+ return deepFreezeValue({
2239
+ clusterId: requireCoreMailClusterId(record.clusterId, `${pathArg}.clusterId`),
2240
+ coreMailServiceId: requireIdentifier(record.coreMailServiceId, `${pathArg}.coreMailServiceId`),
2241
+ enabled: record.enabled as boolean,
2242
+ controlEndpointUrl,
2243
+ transferOrigin: requireCanonicalUrl(
2244
+ record.transferOrigin,
2245
+ `${pathArg}.transferOrigin`,
2246
+ 'https:',
2247
+ true,
2248
+ ),
2249
+ controlCredential: normalizeInstanceCredential(
2250
+ record.controlCredential,
2251
+ `${pathArg}.controlCredential`,
2252
+ ),
2253
+ gatewayCredential: normalizeInstanceCredential(
2254
+ record.gatewayCredential,
2255
+ `${pathArg}.gatewayCredential`,
2256
+ ),
2257
+ smtp: record.smtp === null ? null : normalizeInstanceSmtp(record.smtp, `${pathArg}.smtp`),
2258
+ bindingLimits: normalizeLimits(record.bindingLimits, `${pathArg}.bindingLimits`),
2259
+ reservedConfigEpoch: requireSafeInteger(
2260
+ record.reservedConfigEpoch,
2261
+ `${pathArg}.reservedConfigEpoch`,
2262
+ 0,
2263
+ ),
2264
+ });
2265
+ };
2266
+
2267
+ /**
2268
+ * Where one cluster's CoreMail keeps its system secrets (`coreMailInstanceSecretKeys`): the system
2269
+ * owner `coremail-instance:<clusterId>` and its management scope `system:coremail-instance:<clusterId>`.
2270
+ * One owner per cluster, so two instances never share a secret and an instance's secrets are found
2271
+ * from its record's identity alone; the record itself names none.
2272
+ */
2273
+ export const createCoreMailInstanceSecretOwnership = (
2274
+ clusterIdArg: string,
2275
+ ): ICoreMailInstanceSecretOwnership => {
2276
+ const systemId = `coremail-instance:${requireCoreMailClusterId(clusterIdArg, 'clusterId')}`;
2277
+ return deepFreezeValue({
2278
+ owner: { kind: 'system', systemId },
2279
+ managementScope: `system:${systemId}`,
2280
+ });
2281
+ };
2282
+
2283
+ /**
2284
+ * The applied epoch a control authentication answers (`IReq_CoreMailAuthenticateControl`
2285
+ * `appliedConfigEpoch`): a non-negative safe integer, `0` when CoreMail has applied no desired
2286
+ * state yet, which is also the `expectedAppliedConfigEpoch` the next preparation states.
2287
+ */
2288
+ export const normalizeCoreMailControlAppliedConfigEpoch = (
2289
+ valueArg: unknown,
2290
+ pathArg = 'appliedConfigEpoch',
2291
+ ): number => requireSafeInteger(valueArg, pathArg, 0);
2292
+
2143
2293
  const requireUtcCalendarDay = (valueArg: unknown, pathArg: string): string => {
2144
2294
  const value = requireString(valueArg, pathArg, 10);
2145
2295
  if (!utcCalendarDayPattern.test(value)) {
@@ -7,6 +7,9 @@
7
7
  * binding authority.
8
8
  */
9
9
 
10
+ import type { TControllerPeerSetRefusal } from './controller.js';
11
+ import type { TServiceMailSubmissionTlsMode } from './mail.js';
12
+ import type { ISystemSecretOwner, TSecretManagementScope } from './secret.js';
10
13
  import type { IWorkloadReplicaIdentity } from './workloadreplicaidentity.js';
11
14
  import type { TCorestoreDatabaseCredentialKey, TCorestoreObjectStorageCredentialSecretKey } from '../runtime.corestore.js';
12
15
  import type { TObjectStorageEndpointEnvironmentKey } from '../platform/objectstorage.js';
@@ -76,7 +79,16 @@ export type TCoreMailErrorCode =
76
79
  | 'DELIVERY_FAILED'
77
80
  | 'DELIVERY_DEAD_LETTERED'
78
81
  | 'GATEWAY_UNAVAILABLE'
79
- | 'RECONCILIATION_FENCE_MISMATCH';
82
+ | 'RECONCILIATION_FENCE_MISMATCH'
83
+ /**
84
+ * The controller refusals of `judgeControllerPeerSet`, under their own names
85
+ * (`controllerPeerSetRefusals`): `controller-mismatch` for a control authentication whose peer
86
+ * set names another controller than the one CoreMail stored, `controller-epoch-older` for an
87
+ * older epoch, or for no peer set once CoreMail stored one. Answered only to
88
+ * `coreMailAuthenticateControl`, always `retryable: false`, and never written into a
89
+ * reconciliation status (`ICoreMailReconciliationStatus.errorCode`), whose reader refuses them.
90
+ */
91
+ | TControllerPeerSetRefusal;
80
92
 
81
93
  export interface ICoreMailErrorData {
82
94
  code: TCoreMailErrorCode;
@@ -254,6 +266,99 @@ export interface ICoreMailGatewayPeerDesiredState {
254
266
  credentials: ICoreMailBindingCredentialVerifier[];
255
267
  }
256
268
 
269
+ /**
270
+ * One credential a CoreMail instance record names, by identity only. Its plaintext is a system
271
+ * secret of the instance (`createCoreMailInstanceSecretOwnership`, `coreMailInstanceSecretKeys`)
272
+ * and its verifier is the controller's own stored record; neither is ever a member of this record.
273
+ */
274
+ export interface ICoreMailInstanceCredential {
275
+ credentialId: string;
276
+ /** A positive safe integer; a changed version rotates the credential. */
277
+ credentialVersion: number;
278
+ }
279
+
280
+ /** The SMTP submission listener of one CoreMail instance, as its workloads submit to it. */
281
+ export interface ICoreMailInstanceSmtp {
282
+ /** The listener's advertised EHLO hostname and the host workloads submit to (`SMTP_HOST`). */
283
+ host: string;
284
+ /** The listener port inside the CoreMail workload and the port workloads submit to (`SMTP_PORT`). */
285
+ port: number;
286
+ /** What workloads are told to speak to the listener (`SMTP_TLS_MODE`). */
287
+ tlsMode: TServiceMailSubmissionTlsMode;
288
+ }
289
+
290
+ /**
291
+ * One cluster's CoreMail as its controller records it (Linus rulings 249 and 250): the record that
292
+ * replaces the single set of `coreMail*` settings, one per cluster, read exactly by
293
+ * `normalizeCoreMailInstance`.
294
+ *
295
+ * - Identity: `clusterId`. A cluster has at most one record, and a CoreMail serves one cluster, so
296
+ * `coreMailServiceId` is unique across records too. A Service's binding names the instance it
297
+ * was minted on by that service id (`ICoreMailServiceBinding.coreMailServiceId`), which is also
298
+ * the gateway peer key, the control bootstrap's id and every inbound target's id.
299
+ * - Secrets: by reference only. No member carries a secret or a verifier. The four secrets of an
300
+ * instance live under the system owner `createCoreMailInstanceSecretOwnership(clusterId)`
301
+ * answers, keyed by `coreMailInstanceSecretKeys`.
302
+ * - Epochs: `reservedConfigEpoch` is the controller's own counter. The applied epoch is CoreMail's
303
+ * and is not a member: CoreMail answers it at session open (`IReq_CoreMailAuthenticateControl`
304
+ * `appliedConfigEpoch`), and the controller keeps no copy of it (ruling 250 W2).
305
+ * - Not a member: the gateway endpoint CoreMail dials. It is the gateway's, the same for every
306
+ * instance, and stays `ICloudlySettings.coreMailGatewayEndpointUrl` (ruling 250 part 1).
307
+ */
308
+ export interface ICoreMailInstance {
309
+ /** The cluster this CoreMail serves and the record's identity. */
310
+ clusterId: string;
311
+ /** The Service that runs this CoreMail, on a node of `clusterId`. */
312
+ coreMailServiceId: string;
313
+ /**
314
+ * Whether the controller reconciles this CoreMail and binds the cluster's mail-eligible Services
315
+ * to it. `false` keeps the record (credentials, epoch) and leaves the cluster's Services on the
316
+ * dcrouter-direct path, as `coreMailEnabled: false` does today.
317
+ */
318
+ enabled: boolean;
319
+ /** The canonical control socket URL, `https://<host>/socket`, and the workloads' `MAIL_COREMAIL_URL`. */
320
+ controlEndpointUrl: string;
321
+ /** The canonical HTTPS transfer origin, an origin without a path. */
322
+ transferOrigin: string;
323
+ /** The credential the controller authenticates its control session with. */
324
+ controlCredential: ICoreMailInstanceCredential;
325
+ /** The credential this CoreMail authenticates to the gateway with; its own, never shared. */
326
+ gatewayCredential: ICoreMailInstanceCredential;
327
+ /** The SMTP submission listener; `null` keeps the API-only surface. */
328
+ smtp: ICoreMailInstanceSmtp | null;
329
+ /** The limits every binding of this instance carries (`ICoreMailBindingDesiredState.limits`). */
330
+ bindingLimits: ICoreMailBindingDesiredState['limits'];
331
+ /**
332
+ * The last `configEpoch` the controller reserved for this CoreMail, `0` before the first: a
333
+ * non-negative safe integer that never falls. The controller's epoch reservation is its only
334
+ * writer; an administrator's write never states it, and a copied record keeps it, never reset.
335
+ */
336
+ reservedConfigEpoch: number;
337
+ }
338
+
339
+ /**
340
+ * The keys of one CoreMail instance's system secrets, under the owner
341
+ * `createCoreMailInstanceSecretOwnership` answers for its cluster. They are the names the single
342
+ * settings set used (`cloudlySystemSecretKeys.coreMail*`), so each value moves under its instance
343
+ * without a rename, and the SMTP TLS names a desired state carries
344
+ * (`ICoreMailSmtpTlsDesiredState`) stay byte-identical.
345
+ */
346
+ export const coreMailInstanceSecretKeys = Object.freeze({
347
+ controlCredentialSecret: 'COREMAIL_CONTROL_CREDENTIAL_SECRET',
348
+ gatewayCredentialSecret: 'COREMAIL_GATEWAY_CREDENTIAL_SECRET',
349
+ smtpTlsCertificatePem: 'COREMAIL_SMTP_TLS_CERTIFICATE_PEM',
350
+ smtpTlsPrivateKeyPem: 'COREMAIL_SMTP_TLS_PRIVATE_KEY_PEM',
351
+ } as const);
352
+
353
+ /**
354
+ * Where one CoreMail instance's system secrets are kept: the system owner of its cluster and the
355
+ * management scope its secrets carry (`createCoreMailInstanceSecretOwnership`).
356
+ */
357
+ export interface ICoreMailInstanceSecretOwnership {
358
+ owner: ISystemSecretOwner;
359
+ managementScope: TSecretManagementScope;
360
+ }
361
+
257
362
  export interface ICoreMailRuntimeKeyReference {
258
363
  keyId: string;
259
364
  version: number;
@@ -337,6 +442,11 @@ export interface ICoreMailReconciliationStatus {
337
442
  appliedDesiredStateDigest: TCoreMailSha256;
338
443
  bindings: ICoreMailBindingReconciliationStatus[];
339
444
  updatedAt: number;
445
+ /**
446
+ * Present exactly for a `failed` state. Never a controller refusal (`controller-mismatch`,
447
+ * `controller-epoch-older`): CoreMail never writes one into a status, and
448
+ * `normalizeCoreMailReconciliationStatus` refuses a status that carries one.
449
+ */
340
450
  errorCode?: TCoreMailErrorCode;
341
451
  }
342
452
 
@@ -0,0 +1,51 @@
1
+ import { readDataProperties } from '../private/dataproperties.js';
2
+
3
+ /*
4
+ * Create idempotency keys (AGL-2106, Linus ruling 247, "Creates, the design").
5
+ *
6
+ * A create request that may be sent again after an unknown outcome (`outcomeUnknownCode`) names
7
+ * the user action it belongs to with an `idempotencyKey`: the controller derives the created
8
+ * record's id from it and answers a create it already stored with that record, so a re-sent create
9
+ * never makes a second one. First-party callers send one key per user action, never one per
10
+ * attempt, and never a key derived from the request's content, which would merge two legitimate
11
+ * identical creates.
12
+ *
13
+ * The member is optional on `createService`, `createCluster`, `createServiceBackup` and
14
+ * `createImage` so callers built before it keep working, and becomes required at the next major of
15
+ * this package. A controller built before the member ignores it (those requests have no exact-key
16
+ * reader), so a caller that relies on it names the minimum controller that honours it.
17
+ */
18
+
19
+ /** Bounds of an idempotency key. */
20
+ export const idempotencyKeyContract = Object.freeze({
21
+ /** The longest key, in characters. */
22
+ maximumLength: 200,
23
+ });
24
+
25
+ const idempotencyKeyPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
26
+
27
+ /**
28
+ * True for a valid idempotency key: a bounded canonical identifier (an ASCII letter or digit, then
29
+ * up to `idempotencyKeyContract.maximumLength - 1` of letters, digits and `:._-`), the rule
30
+ * `validateDeploymentReservationInput`, `validateServiceReleaseDeploymentStartInput` and the
31
+ * adoption validators in `deploymentadoption.ts` apply. A CoreMail submission's `idempotencyKey`
32
+ * has its own rule (`coremail.runtime.ts`: any non-empty string of at most 256 UTF-8 bytes).
33
+ */
34
+ export const isIdempotencyKey = (valueArg: unknown): valueArg is string => (
35
+ typeof valueArg === 'string' && idempotencyKeyPattern.test(valueArg)
36
+ );
37
+
38
+ /**
39
+ * Every error of the optional `idempotencyKey` of a create request (`createService`,
40
+ * `createCluster`, `createServiceBackup`, `createImage`); empty when the request omits the member
41
+ * (absent or `undefined`, which the wire never carries) or states a valid key. It judges that
42
+ * member only, never the request's other members.
43
+ */
44
+ export const validateCreateIdempotencyKey = (requestArg: unknown): string[] => {
45
+ const request = readDataProperties(requestArg);
46
+ if (request === null) return ['create request must be a plain object'];
47
+ if (request.idempotencyKey === undefined) return [];
48
+ return isIdempotencyKey(request.idempotencyKey)
49
+ ? []
50
+ : ['idempotencyKey must be a bounded canonical identifier'];
51
+ };
package/ts/data/index.ts CHANGED
@@ -35,6 +35,7 @@ export * from './gatewayarearows.js';
35
35
  export * from './gatewayconnector.js';
36
36
  export * from './gatewayintent.js';
37
37
  export * from './hostedapp.js';
38
+ export * from './idempotencykey.js';
38
39
  export * from './image.js';
39
40
  export * from './immutableimage.js';
40
41
  export * from './isolatedrestore.js';
@@ -45,6 +46,7 @@ export * from './nodeenrollment.js';
45
46
  export * from './noderuntimebinding.js';
46
47
  export * from './noderetirement.js';
47
48
  export * from './networkaddressplan.js';
49
+ export * from './outcomeunknown.js';
48
50
  export * from './networkapplication.js';
49
51
  export * from './networkauthority.js';
50
52
  export * from './networkcredential.js';
package/ts/data/mail.ts CHANGED
@@ -310,6 +310,20 @@ export interface IServiceMailAddressConfig {
310
310
  */
311
311
  export interface ICoreMailServiceBinding {
312
312
  bindingId: string;
313
+ /**
314
+ * The CoreMail this binding was minted on (`ICoreMailInstance.coreMailServiceId`), and so the
315
+ * one that holds its state: its published verifier, pending inbound deliveries, submissions and
316
+ * quota counters. It is a fact about where the binding lives, never re-derived from the
317
+ * Service's placement (Linus ruling 253 point 4). From the controller release that writes it,
318
+ * the controller derives the CoreMail once, at mint, as the CoreMail of the Service's cluster,
319
+ * and then publishes, routes inbound mail to and points `MAIL_COREMAIL_URL` at this CoreMail
320
+ * alone; a Service whose cluster no longer matches is reported and stays served by this CoreMail.
321
+ *
322
+ * Absent on a binding minted before per-cluster CoreMail. The controller's per-cluster data step
323
+ * writes it on every stored binding, and from that step on the controller refuses a binding
324
+ * without it by name and never derives it. It becomes required in the next major.
325
+ */
326
+ coreMailServiceId?: string;
313
327
  credentialId: string;
314
328
  credentialVersion: number;
315
329
  verificationHash: string;
@@ -0,0 +1,71 @@
1
+ import { readExactDataRecord } from '../private/dataproperties.js';
2
+ import type { TCompleteKeyList } from '../private/keylist.js';
3
+
4
+ /*
5
+ * An unknown write outcome at the operator boundary (AGL-2106, Linus rulings 243 and 247).
6
+ *
7
+ * A write that was sent and never confirmed may have been stored or not: a deadline expired during
8
+ * its commit, the connection was lost after the commit was sent, or the database closed while the
9
+ * commit ran. A controller answers that to an operator (admin API, dashboard, CLI) by one name,
10
+ * `outcome-unknown`, and never as `Internal server error`, as a refusal that says nothing was
11
+ * stored, or as done. Node-facing answers keep their own names (`deadline`,
12
+ * `controller-deadline`); the witness answers its own `outcome-unknown` for its record
13
+ * (`witnessRefusals`), the same word for the same fact.
14
+ *
15
+ * What the caller does is `outcomeUnknownInstruction`: read the state again, then decide. It never
16
+ * sends the write again unread. Sending again unchanged is such a read only for a request whose
17
+ * replay answers what it stored (one that carries an `idempotencyKey`); every other write is sent
18
+ * again only once the read shows it is still wanted.
19
+ */
20
+
21
+ /** The one name of an operator-facing answer to a write whose outcome is unknown. */
22
+ export const outcomeUnknownCode = 'outcome-unknown';
23
+
24
+ /** The name `outcomeUnknownCode` states. */
25
+ export type TOutcomeUnknownCode = typeof outcomeUnknownCode;
26
+
27
+ /**
28
+ * What a caller answered `outcome-unknown` does, as one sentence a CLI prints and a dashboard
29
+ * shows beside the name.
30
+ */
31
+ export const outcomeUnknownInstruction =
32
+ 'The write was sent and its outcome is unknown: it may have been stored. Read the current state again, then decide; do not send the write again unread.';
33
+
34
+ /**
35
+ * The answer as `TypedResponseError.errorData`; the error text carries the detail. An operator
36
+ * surface that answers in its own form (a CLI's result line, an HTTP body) states the same `code`.
37
+ */
38
+ export interface IOutcomeUnknownErrorData {
39
+ code: TOutcomeUnknownCode;
40
+ /**
41
+ * Always false: the answer does not say the same request may be sent again. The caller reads
42
+ * first; whether sending the request again is that read is the request's own contract.
43
+ */
44
+ retryable: false;
45
+ }
46
+
47
+ /** True exactly for `outcomeUnknownCode`. */
48
+ export const isOutcomeUnknownCode = (valueArg: unknown): valueArg is TOutcomeUnknownCode => (
49
+ valueArg === outcomeUnknownCode
50
+ );
51
+
52
+ /** The `errorData` a controller answers an unknown write outcome with. */
53
+ export const createOutcomeUnknownErrorData = (): IOutcomeUnknownErrorData => (
54
+ Object.freeze({ code: outcomeUnknownCode, retryable: false })
55
+ );
56
+
57
+ const errorDataKeyList = ['code', 'retryable'] as const;
58
+ const errorDataKeys: TCompleteKeyList<IOutcomeUnknownErrorData, typeof errorDataKeyList> = errorDataKeyList;
59
+
60
+ /**
61
+ * The answer an error payload states, or `null` when it is not exactly `IOutcomeUnknownErrorData`:
62
+ * a payload with another member, another code or `retryable` other than `false` is no
63
+ * `outcome-unknown` answer.
64
+ */
65
+ export const readOutcomeUnknownErrorData = (valueArg: unknown): IOutcomeUnknownErrorData | null => {
66
+ const record = readExactDataRecord(valueArg, errorDataKeys);
67
+ if (record === null || !isOutcomeUnknownCode(record.code) || record.retryable !== false) {
68
+ return null;
69
+ }
70
+ return createOutcomeUnknownErrorData();
71
+ };