@serve.zone/interfaces 32.74.0 → 32.76.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 (43) hide show
  1. package/changelog.md +26 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/controller.d.ts +70 -0
  4. package/dist_ts/data/controller.js +44 -0
  5. package/dist_ts/data/gateway.d.ts +64 -1
  6. package/dist_ts/data/gateway.js +87 -2
  7. package/dist_ts/data/gatewayconnector.d.ts +278 -0
  8. package/dist_ts/data/gatewayconnector.js +418 -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/location.d.ts +3 -1
  12. package/dist_ts/data/location.js +7 -5
  13. package/dist_ts/private/controllercontract.d.ts +8 -0
  14. package/dist_ts/private/controllercontract.js +50 -0
  15. package/dist_ts/requests/baremetal.d.ts +2 -1
  16. package/dist_ts/requests/cluster.d.ts +5 -3
  17. package/dist_ts/requests/gateway.d.ts +9 -5
  18. package/dist_ts/requests/gatewayconnector.d.ts +133 -0
  19. package/dist_ts/requests/gatewayconnector.js +2 -0
  20. package/dist_ts/requests/index.d.ts +2 -1
  21. package/dist_ts/requests/index.js +3 -2
  22. package/dist_ts/requests/node.d.ts +4 -1
  23. package/dist_ts/runtime.corestore.database.d.ts +23 -0
  24. package/dist_ts/runtime.corestore.database.js +41 -0
  25. package/dist_ts/runtime.d.ts +1 -0
  26. package/dist_ts/runtime.js +2 -1
  27. package/package.json +2 -2
  28. package/readme.md +129 -6
  29. package/ts/00_commitinfo_data.ts +1 -1
  30. package/ts/data/controller.ts +106 -0
  31. package/ts/data/gateway.ts +137 -2
  32. package/ts/data/gatewayconnector.ts +714 -0
  33. package/ts/data/index.ts +2 -0
  34. package/ts/data/location.ts +6 -4
  35. package/ts/private/controllercontract.ts +59 -0
  36. package/ts/requests/baremetal.ts +2 -1
  37. package/ts/requests/cluster.ts +5 -3
  38. package/ts/requests/gateway.ts +9 -5
  39. package/ts/requests/gatewayconnector.ts +168 -0
  40. package/ts/requests/index.ts +2 -0
  41. package/ts/requests/node.ts +4 -1
  42. package/ts/runtime.corestore.database.ts +64 -0
  43. package/ts/runtime.ts +1 -0
package/ts/data/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './clusteringress.js';
6
6
  export * from './clusteringressdesignation.js';
7
7
  export * from './clusterrelaycredential.js';
8
8
  export * from './config.js';
9
+ export * from './controller.js';
9
10
  export * from './corestore.js';
10
11
  export * from './corestorecontroltoken.js';
11
12
  export * from './corestorelegacyadoption.js';
@@ -27,6 +28,7 @@ export * from './event.js';
27
28
  export * from './externalregistry.js';
28
29
  export * from './fleetcutover.js';
29
30
  export * from './gateway.js';
31
+ export * from './gatewayconnector.js';
30
32
  export * from './hostedapp.js';
31
33
  export * from './image.js';
32
34
  export * from './immutableimage.js';
@@ -122,13 +122,15 @@ export interface ILocationScope {
122
122
 
123
123
  /**
124
124
  * Every reason Cloudly answers instead of a location request or a create that names a location.
125
- * Each travels by name as a `TypedResponseError`, and a refused request changes nothing.
125
+ * Each travels by name as a `TypedResponseError`, except at a jump-code claim or node enrollment:
126
+ * there Cloudly logs the refusal by name and the claimant receives that path's single refusal
127
+ * sentence. A refused request changes nothing.
126
128
  */
127
129
  export const locationRefusals = Object.freeze([
128
130
  /**
129
- * A create named a location but creates no node to stand in it (`createCluster` with `setupMode`
130
- * `manual` or absent); name the location on `createNodeJumpCommand` instead. Checked before
131
- * `location-not-found`.
131
+ * A create named a location but creates no node to stand in it (`createCluster` with a setup
132
+ * mode that provisions no node: today every mode but `hetzner`); name the location on
133
+ * `createNodeJumpCommand` instead. Checked before `location-not-found`.
132
134
  */
133
135
  'location-needs-node',
134
136
  /** No location of that id exists. */
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The value rules the controller contracts (`data/controller.ts`, `data/gatewayconnector.ts`) share,
3
+ * stated as refusals a validator can collect so it names every reason a body is refused.
4
+ */
5
+ import { networkId } from './networkcontract.js';
6
+
7
+ /** The generic canonical identifier: the rule `networkId` reads, never a second spelling of it. */
8
+ export const validateControllerIdentifier = (valueArg: unknown, pathArg: string): string[] => {
9
+ try {
10
+ networkId(valueArg);
11
+ return [];
12
+ } catch {
13
+ return [`${pathArg} must be 1 to 200 characters of letters, digits, colon, dot, underscore or `
14
+ + 'hyphen, starting with a letter or digit'];
15
+ }
16
+ };
17
+
18
+ /** A positive safe integer: an epoch, a revision or a generation. */
19
+ export const validateControllerCounter = (valueArg: unknown, pathArg: string): string[] => (
20
+ typeof valueArg === 'number' && Number.isSafeInteger(valueArg) && valueArg > 0
21
+ ? []
22
+ : [`${pathArg} must be a positive safe integer`]
23
+ );
24
+
25
+ /** A non-negative safe integer: a sequence that restarts at 0, a count or a time. */
26
+ export const validateControllerNonNegativeInteger = (valueArg: unknown, pathArg: string): string[] => (
27
+ typeof valueArg === 'number' && Number.isSafeInteger(valueArg) && valueArg >= 0
28
+ ? []
29
+ : [`${pathArg} must be a non-negative safe integer`]
30
+ );
31
+
32
+ /** A canonical `https` origin: no userinfo, path, query, fragment, trailing slash or default port. */
33
+ export const validateControllerOrigin = (
34
+ valueArg: unknown,
35
+ pathArg: string,
36
+ maximumLengthArg: number,
37
+ ): string[] => {
38
+ if (typeof valueArg !== 'string' || valueArg.length === 0 || valueArg.length > maximumLengthArg) {
39
+ return [`${pathArg} must be a string of 1 to ${maximumLengthArg} characters`];
40
+ }
41
+ let parsedOrigin: URL;
42
+ try {
43
+ parsedOrigin = new URL(valueArg);
44
+ } catch {
45
+ return [`${pathArg} must be a parsable URL`];
46
+ }
47
+ const errors: string[] = [];
48
+ if (parsedOrigin.protocol !== 'https:') {
49
+ errors.push(`${pathArg} must use the https scheme`);
50
+ }
51
+ if (parsedOrigin.username || parsedOrigin.password) {
52
+ errors.push(`${pathArg} must not carry userinfo`);
53
+ }
54
+ if (parsedOrigin.origin !== valueArg) {
55
+ errors.push(`${pathArg} must be the canonical origin ${parsedOrigin.origin}, `
56
+ + 'without a path, query, fragment, trailing slash or default port');
57
+ }
58
+ return errors;
59
+ };
@@ -14,7 +14,8 @@ extends plugins.typedrequestInterfaces.implementsTR<
14
14
  /**
15
15
  * Only the servers standing in this location: those a node of the location names in its
16
16
  * `data.baremetalId`. A server no node names stands nowhere and is never in a scoped answer;
17
- * `IBareMetal.data.location` (the provider's datacenter) plays no part.
17
+ * `IBareMetal.data.location` (the provider's datacenter) plays no part. Refused
18
+ * `location-not-found` when no location has that id.
18
19
  */
19
20
  locationScope?: ILocationScope;
20
21
  };
@@ -20,7 +20,8 @@ export interface IReq_Any_Cloudly_GetClusters extends plugins.typedrequestInterf
20
20
  identity: userInterfaces.IIdentity;
21
21
  /**
22
22
  * Only the clusters standing in this location (`data.getClusterLocationId`); a cluster without
23
- * nodes stands nowhere and is never in a scoped answer.
23
+ * nodes stands nowhere and is never in a scoped answer, and neither is a cluster whose nodes
24
+ * span locations. Refused `location-not-found` when no location has that id.
24
25
  */
25
26
  locationScope?: locationInterfaces.ILocationScope;
26
27
  };
@@ -60,8 +61,9 @@ export interface IRequest_CreateCluster extends plugins.typedrequestInterfaces.i
60
61
  setupMode?: 'manual' | 'hetzner' | 'aws' | 'digitalocean';
61
62
  /**
62
63
  * The location the node a provisioning setup mode creates stands in. Refused
63
- * `location-needs-node` when the create makes no node to stand in it (`setupMode` `manual` or
64
- * absent; name the location on `createNodeJumpCommand` instead), checked before
64
+ * `location-needs-node` when the create makes no node to stand in it (a setup mode that
65
+ * provisions no node: today every mode but `hetzner`; name the location on
66
+ * `createNodeJumpCommand` instead), checked before
65
67
  * `location-not-found`, which answers a location that does not exist. Absent, the created node
66
68
  * stands in the location that receives unnamed creates (the initial location); a create that
67
69
  * makes no node leaves the cluster empty, standing nowhere.
@@ -219,9 +219,9 @@ export interface IReq_SyncGatewayClientRoute extends plugins.typedrequestInterfa
219
219
  enabled?: boolean;
220
220
  delete?: boolean;
221
221
  /**
222
- * Omission means 'skip' for backward wire compatibility. Reconciliation
223
- * claims or replaces exact-host manual A, AAAA, and CNAME records even
224
- * when their current value already satisfies the desired address.
222
+ * Omission keeps the route's stored mode, and is 'skip' for a new route.
223
+ * Reconciliation never adopts, replaces or deletes a record the route's
224
+ * gateway DNS ownership does not hold; see `TGatewayRouteDnsMode`.
225
225
  */
226
226
  dnsMode?: TGatewayRouteDnsMode;
227
227
  /**
@@ -230,8 +230,12 @@ export interface IReq_SyncGatewayClientRoute extends plugins.typedrequestInterfa
230
230
  */
231
231
  dnsProxied?: boolean;
232
232
  /**
233
- * Gateway source profile to bind the route to (by ref or name).
234
- * Defaults to the gateway's public profile when omitted.
233
+ * Gateway source profile to bind the route to, by id or name (an id
234
+ * first, then a name, case-insensitive). A profile the gateway cannot
235
+ * resolve fails the sync. Omission binds the route to the gateway's
236
+ * `STANDARD` profile on every sync, an update included, never to the
237
+ * profile stored before: send it explicitly, for example
238
+ * `'LOCAL NETWORK'` for a route only private networks may reach.
235
239
  */
236
240
  sourceProfileRef?: string;
237
241
  };
@@ -0,0 +1,168 @@
1
+ import * as plugins from '../plugins.js';
2
+ import type { IControllerPeerSet } from '../data/controller.js';
3
+ import type {
4
+ IGateway,
5
+ IGatewayAdoptionFacts,
6
+ IGatewayAreaExport,
7
+ IGatewayApplyReport,
8
+ IGatewayDesiredState,
9
+ IGatewayStatusDocument,
10
+ IRegisterGatewaySessionRequest,
11
+ TGatewayConfigArea,
12
+ } from '../data/gatewayconnector.js';
13
+ import type { ILocationScope } from '../data/location.js';
14
+ import type { IIdentityCredential } from '../data/user.js';
15
+
16
+ /*
17
+ * The gateway connector (AGL-1182). A gateway dials its controller on the controller's typedsocket
18
+ * server; the controller never dials an adopted gateway. `Gateway_Cloudly` requests travel from the
19
+ * gateway to the controller, `Cloudly_Gateway` requests from the controller to the gateway over
20
+ * the socket the gateway opened, and `Admin_Cloudly` requests are an administrator's.
21
+ */
22
+
23
+ /**
24
+ * A gateway redeems an adoption code (`createGatewayAdoptionCode`) with the facts it states about
25
+ * itself. The controller consumes the code and writes the adoption revision in one transaction and
26
+ * answers the gateway's credential once; adopting again with a new code raises the credential
27
+ * generation and the previous generation stops authenticating. Exclude bodies from logs: the
28
+ * request carries the code and the answer the bearer.
29
+ */
30
+ export interface IReq_Gateway_Cloudly_AdoptGateway extends plugins.typedrequestInterfaces.implementsTR<
31
+ plugins.typedrequestInterfaces.ITypedRequest,
32
+ IReq_Gateway_Cloudly_AdoptGateway
33
+ > {
34
+ method: 'adoptGateway';
35
+ request: {
36
+ code: string;
37
+ /** `data.validateGatewayAdoptionFacts`. */
38
+ facts: IGatewayAdoptionFacts;
39
+ };
40
+ response: {
41
+ gatewayId: string;
42
+ /** The gateway stores it and refuses any other controller and any older epoch from then on. */
43
+ controller: IControllerPeerSet;
44
+ /** Answered once; the gateway authenticates its socket as `userId` with `bearer`. */
45
+ credential: { userId: string; generation: number; bearer: string };
46
+ /**
47
+ * The gateway client the controller's existing `requests.gateway` and `requests.mail` calls are
48
+ * bound to once they run over the connector socket; `null` when the controller binds none.
49
+ */
50
+ controllerGatewayClientId: string | null;
51
+ };
52
+ }
53
+
54
+ /**
55
+ * The hello a gateway sends after `registerCloudlyClientSession` on its socket: the gateway is the
56
+ * one the verified machine identity names. The controller answers its current peer set.
57
+ */
58
+ export interface IReq_Gateway_Cloudly_RegisterGatewaySession extends plugins.typedrequestInterfaces.implementsTR<
59
+ plugins.typedrequestInterfaces.ITypedRequest,
60
+ IReq_Gateway_Cloudly_RegisterGatewaySession
61
+ > {
62
+ method: 'registerGatewaySession';
63
+ /** `data.validateRegisterGatewaySessionRequest`. */
64
+ request: IRegisterGatewaySessionRequest;
65
+ response: {
66
+ controller: IControllerPeerSet;
67
+ };
68
+ }
69
+
70
+ /**
71
+ * A gateway pushes its status document after its hello, after every apply and whenever it
72
+ * changes, at most once per `data.gatewayConnectorContract.minimumStatusPushIntervalMs`.
73
+ */
74
+ export interface IReq_Gateway_Cloudly_PushGatewayStatus extends plugins.typedrequestInterfaces.implementsTR<
75
+ plugins.typedrequestInterfaces.ITypedRequest,
76
+ IReq_Gateway_Cloudly_PushGatewayStatus
77
+ > {
78
+ method: 'pushGatewayStatus';
79
+ request: {
80
+ /** `data.validateGatewayStatusDocument`. */
81
+ status: IGatewayStatusDocument;
82
+ };
83
+ response: {};
84
+ }
85
+
86
+ /**
87
+ * The controller pushes a gateway's whole desired state; the gateway answers what it applied.
88
+ * A document equal by `(epoch, revision)` to the one applied is answered with the stored report.
89
+ */
90
+ export interface IReq_Cloudly_Gateway_ApplyDesiredState extends plugins.typedrequestInterfaces.implementsTR<
91
+ plugins.typedrequestInterfaces.ITypedRequest,
92
+ IReq_Cloudly_Gateway_ApplyDesiredState
93
+ > {
94
+ method: 'applyDesiredState';
95
+ request: {
96
+ /** `data.validateGatewayDesiredState`. */
97
+ desired: IGatewayDesiredState;
98
+ };
99
+ response: {
100
+ report: IGatewayApplyReport;
101
+ };
102
+ }
103
+
104
+ /**
105
+ * The controller reads one gateway-owned area table, the first step of taking the area over: it
106
+ * writes an import revision of it and pushes it back with `takeover.localDigest` set to `digest`.
107
+ */
108
+ export interface IReq_Cloudly_Gateway_ExportGatewayArea extends plugins.typedrequestInterfaces.implementsTR<
109
+ plugins.typedrequestInterfaces.ITypedRequest,
110
+ IReq_Cloudly_Gateway_ExportGatewayArea
111
+ > {
112
+ method: 'exportGatewayArea';
113
+ request: {
114
+ area: TGatewayConfigArea;
115
+ };
116
+ /** `data.validateGatewayAreaExport`. */
117
+ response: IGatewayAreaExport;
118
+ }
119
+
120
+ /**
121
+ * An administrator makes a one-time adoption code, either for a new gateway in an existing
122
+ * location or for an existing gateway record (re-adoption). Adoption never creates a location.
123
+ * `command` is the command to run on the gateway's host.
124
+ */
125
+ export interface IReq_Admin_Cloudly_CreateGatewayAdoptionCode extends plugins.typedrequestInterfaces.implementsTR<
126
+ plugins.typedrequestInterfaces.ITypedRequest,
127
+ IReq_Admin_Cloudly_CreateGatewayAdoptionCode
128
+ > {
129
+ method: 'createGatewayAdoptionCode';
130
+ request: {
131
+ identity: IIdentityCredential;
132
+ target:
133
+ | { kind: 'new'; locationId: string; name: string }
134
+ | { kind: 'existing'; gatewayId: string };
135
+ };
136
+ response: {
137
+ code: string;
138
+ /** Unix milliseconds on the controller's clock. */
139
+ expiresAt: number;
140
+ command: string;
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Every gateway the controller records, with whether a socket carries it now and the status
146
+ * document it pushed last. `locationScope` narrows the answer to one location's gateways; a
147
+ * Cloudly that applied it echoes it as `appliedLocationScope`.
148
+ */
149
+ export interface IReq_Admin_Cloudly_GetGateways extends plugins.typedrequestInterfaces.implementsTR<
150
+ plugins.typedrequestInterfaces.ITypedRequest,
151
+ IReq_Admin_Cloudly_GetGateways
152
+ > {
153
+ method: 'getGateways';
154
+ request: {
155
+ identity: IIdentityCredential;
156
+ locationScope?: ILocationScope;
157
+ };
158
+ response: {
159
+ gateways: {
160
+ gateway: IGateway;
161
+ connected: boolean;
162
+ status: IGatewayStatusDocument | null;
163
+ /** Unix milliseconds on the controller's clock when `status` arrived; `null` with it. */
164
+ statusAt: number | null;
165
+ }[];
166
+ appliedLocationScope?: ILocationScope;
167
+ };
168
+ }
@@ -19,6 +19,7 @@ import * as domainRequests from './domain.js';
19
19
  import * as externalRegistryRequests from './externalregistry.js';
20
20
  import * as fleetCutoverRequests from './fleetcutover.js';
21
21
  import * as gatewayRequests from './gateway.js';
22
+ import * as gatewayConnectorRequests from './gatewayconnector.js';
22
23
  import * as hostedAppRequests from './hostedapp.js';
23
24
  import * as identityRequests from './identity.js';
24
25
  import * as imageRequests from './image.js';
@@ -61,6 +62,7 @@ export {
61
62
  externalRegistryRequests as externalRegistry,
62
63
  fleetCutoverRequests as fleetcutover,
63
64
  gatewayRequests as gateway,
65
+ gatewayConnectorRequests as gatewayconnector,
64
66
  hostedAppRequests as hostedapp,
65
67
  identityRequests as identity,
66
68
  imageRequests as image,
@@ -186,7 +186,10 @@ export interface IReq_Any_Cloudly_GetNodes extends plugins.typedrequestInterface
186
186
  request: {
187
187
  identity: IIdentity;
188
188
  clusterId?: string;
189
- /** Only the nodes whose `data.locationId` is this location. */
189
+ /**
190
+ * Only the nodes whose `data.locationId` is this location. Refused `location-not-found` when no
191
+ * location has that id.
192
+ */
190
193
  locationScope?: ILocationScope;
191
194
  };
192
195
  response: {
@@ -0,0 +1,64 @@
1
+ import * as plugins from './plugins.runtime.js';
2
+
3
+ import type { ICorestoreDatabaseAllocationReference } from './runtime.corestore.js';
4
+
5
+ /*
6
+ * Corestore's database helpers that its readers share (Onebox, Corestore itself), moved here from
7
+ * `@serve.zone/corestore` so a reader needs no Corestore dependency. The allocation reference
8
+ * itself is `ICorestoreDatabaseAllocationReference`, read with
9
+ * `normalizeCorestoreDatabaseAllocationReference` (`runtime.corestore.ts`).
10
+ */
11
+
12
+ /** A service database's name and user, without the password or an address. */
13
+ export interface ICorestoreDatabaseIdentity {
14
+ databaseName: string;
15
+ username: string;
16
+ }
17
+
18
+ /**
19
+ * True when two allocation references name the same allocation: every member equal. Both are
20
+ * read with `normalizeCorestoreDatabaseAllocationReference` first; this compares, it does not
21
+ * validate.
22
+ */
23
+ export const corestoreDatabaseAllocationReferencesEqual = (
24
+ leftArg: Readonly<ICorestoreDatabaseAllocationReference>,
25
+ rightArg: Readonly<ICorestoreDatabaseAllocationReference>,
26
+ ): boolean => leftArg.purpose === rightArg.purpose
27
+ && leftArg.rehearsalId === rightArg.rehearsalId
28
+ && leftArg.allocationId === rightArg.allocationId
29
+ && leftArg.generation === rightArg.generation
30
+ && leftArg.bindingSha256 === rightArg.bindingSha256
31
+ && leftArg.receiptSha256 === rightArg.receiptSha256;
32
+
33
+ const sanitizeIdentifierPart = (valueArg: string): string => valueArg
34
+ .toLowerCase()
35
+ .replace(/[^a-z0-9_]+/g, '_')
36
+ .replace(/^_+|_+$/g, '')
37
+ .replace(/_+/g, '_');
38
+
39
+ /**
40
+ * The database name and user Corestore derives for a service: `sz_<base>_<hash>` and
41
+ * `u_<base>_<hash>`, where `<hash>` is the first 12 hex digits of the SHA-1 of the service id and
42
+ * `<base>` is the service name (the id when the name is absent or empty), lowercased, every run of
43
+ * characters outside `[a-z0-9_]` replaced by one `_`, leading and trailing `_` removed, every run of
44
+ * `_` collapsed to one, cut to 36 characters, and `service` when nothing remains.
45
+ *
46
+ * Every Corestore database already created carries these names, so the derivation never changes;
47
+ * `test.corestoredatabase` pins it to Corestore's own answers.
48
+ */
49
+ export const getCorestoreDatabaseIdentity = (
50
+ serviceIdArg: string,
51
+ serviceNameArg?: string,
52
+ ): ICorestoreDatabaseIdentity => {
53
+ const hash = plugins.crypto
54
+ .createHash('sha1')
55
+ .update(serviceIdArg)
56
+ .digest('hex')
57
+ .slice(0, 12);
58
+ const databaseBase = sanitizeIdentifierPart(serviceNameArg || serviceIdArg)
59
+ .slice(0, 36) || 'service';
60
+ return {
61
+ databaseName: `sz_${databaseBase}_${hash}`,
62
+ username: `u_${databaseBase}_${hash}`,
63
+ };
64
+ };
package/ts/runtime.ts CHANGED
@@ -43,6 +43,7 @@ import {
43
43
  export * from './runtime.workloadinit.js';
44
44
  export * from './runtime.networkprojection.js';
45
45
  export * from './runtime.corestore.js';
46
+ export * from './runtime.corestore.database.js';
46
47
  export * from './runtime.corestore.databaseexportpackage.js';
47
48
  export * from './runtime.corestore.relay.js';
48
49
  export * from './runtime.assignmentsecret.js';