@serve.zone/interfaces 32.75.0 → 32.77.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 (50) hide show
  1. package/changelog.md +22 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/backup.d.ts +3 -1
  4. package/dist_ts/data/backup.js +1 -1
  5. package/dist_ts/data/controller.d.ts +92 -0
  6. package/dist_ts/data/controller.js +138 -0
  7. package/dist_ts/data/gatewayconnector.d.ts +347 -0
  8. package/dist_ts/data/gatewayconnector.js +594 -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/data/user.d.ts +8 -2
  14. package/dist_ts/private/controllercontract.d.ts +10 -0
  15. package/dist_ts/private/controllercontract.js +64 -0
  16. package/dist_ts/private/gatewayclientid.d.ts +6 -0
  17. package/dist_ts/private/gatewayclientid.js +11 -0
  18. package/dist_ts/requests/baremetal.d.ts +2 -1
  19. package/dist_ts/requests/cluster.d.ts +5 -3
  20. package/dist_ts/requests/gateway.d.ts +20 -3
  21. package/dist_ts/requests/gatewayconnector.d.ts +142 -0
  22. package/dist_ts/requests/gatewayconnector.js +2 -0
  23. package/dist_ts/requests/index.d.ts +2 -1
  24. package/dist_ts/requests/index.js +3 -2
  25. package/dist_ts/requests/node.d.ts +4 -1
  26. package/dist_ts/requests/settings.js +3 -5
  27. package/dist_ts/runtime.corestore.database.d.ts +23 -0
  28. package/dist_ts/runtime.corestore.database.js +41 -0
  29. package/dist_ts/runtime.d.ts +1 -0
  30. package/dist_ts/runtime.js +2 -1
  31. package/package.json +2 -2
  32. package/readme.md +146 -5
  33. package/ts/00_commitinfo_data.ts +1 -1
  34. package/ts/data/backup.ts +3 -1
  35. package/ts/data/controller.ts +218 -0
  36. package/ts/data/gatewayconnector.ts +955 -0
  37. package/ts/data/index.ts +2 -0
  38. package/ts/data/location.ts +6 -4
  39. package/ts/data/user.ts +8 -2
  40. package/ts/private/controllercontract.ts +74 -0
  41. package/ts/private/gatewayclientid.ts +13 -0
  42. package/ts/requests/baremetal.ts +2 -1
  43. package/ts/requests/cluster.ts +5 -3
  44. package/ts/requests/gateway.ts +20 -3
  45. package/ts/requests/gatewayconnector.ts +179 -0
  46. package/ts/requests/index.ts +2 -0
  47. package/ts/requests/node.ts +4 -1
  48. package/ts/requests/settings.ts +2 -4
  49. package/ts/runtime.corestore.database.ts +64 -0
  50. 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. */
package/ts/data/user.ts CHANGED
@@ -142,7 +142,12 @@ export interface IIdentity extends IIdentityCredential {
142
142
  name: string;
143
143
  userId: string;
144
144
  type: 'machine' | 'human';
145
- role: 'admin' | 'user' | 'api' | 'cluster';
145
+ /**
146
+ * `gateway` is a gateway's (dcrouter's) machine identity, minted by its adoption
147
+ * (`adoptGateway`). It is its own role so every guard that names roles excludes it by type;
148
+ * Cloudly admits it only on the gateway's own connector calls.
149
+ */
150
+ role: 'admin' | 'user' | 'api' | 'cluster' | 'gateway';
146
151
  expiresAt: number;
147
152
  }
148
153
 
@@ -150,7 +155,8 @@ export interface IUser {
150
155
  id: string;
151
156
  data: {
152
157
  type: 'machine' | 'human';
153
- role: 'admin' | 'user' | 'api' | 'cluster';
158
+ /** As `IIdentity.role`; a `gateway` user is a machine user. */
159
+ role: 'admin' | 'user' | 'api' | 'cluster' | 'gateway';
154
160
  username?: string;
155
161
  password?: string;
156
162
  tokens?: IToken[];
@@ -0,0 +1,74 @@
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 { canonicalizeStrictJson } from './canonicaljson.js';
6
+ import { networkId } from './networkcontract.js';
7
+
8
+ /** The generic canonical identifier: the rule `networkId` reads, never a second spelling of it. */
9
+ export const validateControllerIdentifier = (valueArg: unknown, pathArg: string): string[] => {
10
+ try {
11
+ networkId(valueArg);
12
+ return [];
13
+ } catch {
14
+ return [`${pathArg} must be 1 to 200 characters of letters, digits, colon, dot, underscore or `
15
+ + 'hyphen, starting with a letter or digit'];
16
+ }
17
+ };
18
+
19
+ /** A positive safe integer: an epoch, a revision or a generation. */
20
+ export const validateControllerCounter = (valueArg: unknown, pathArg: string): string[] => (
21
+ typeof valueArg === 'number' && Number.isSafeInteger(valueArg) && valueArg > 0
22
+ ? []
23
+ : [`${pathArg} must be a positive safe integer`]
24
+ );
25
+
26
+ /** A non-negative safe integer: a sequence that restarts at 0, a count or a time. */
27
+ export const validateControllerNonNegativeInteger = (valueArg: unknown, pathArg: string): string[] => (
28
+ typeof valueArg === 'number' && Number.isSafeInteger(valueArg) && valueArg >= 0
29
+ ? []
30
+ : [`${pathArg} must be a non-negative safe integer`]
31
+ );
32
+
33
+ const failStrictJson = (reasonArg: string): never => {
34
+ throw new Error(`Controller contract value rejected: ${reasonArg}.`);
35
+ };
36
+
37
+ /** A value that is strict canonical JSON: safe integers only, no `undefined`, cycle or accessor. */
38
+ export const validateControllerStrictJson = (valueArg: unknown, pathArg: string): string[] => {
39
+ try {
40
+ canonicalizeStrictJson(valueArg, failStrictJson, pathArg);
41
+ return [];
42
+ } catch {
43
+ return [`${pathArg} must be strict canonical JSON: safe integers only, no undefined, cycle or accessor`];
44
+ }
45
+ };
46
+
47
+ /** A canonical `https` origin: no userinfo, path, query, fragment, trailing slash or default port. */
48
+ export const validateControllerOrigin = (
49
+ valueArg: unknown,
50
+ pathArg: string,
51
+ maximumLengthArg: number,
52
+ ): string[] => {
53
+ if (typeof valueArg !== 'string' || valueArg.length === 0 || valueArg.length > maximumLengthArg) {
54
+ return [`${pathArg} must be a string of 1 to ${maximumLengthArg} characters`];
55
+ }
56
+ let parsedOrigin: URL;
57
+ try {
58
+ parsedOrigin = new URL(valueArg);
59
+ } catch {
60
+ return [`${pathArg} must be a parsable URL`];
61
+ }
62
+ const errors: string[] = [];
63
+ if (parsedOrigin.protocol !== 'https:') {
64
+ errors.push(`${pathArg} must use the https scheme`);
65
+ }
66
+ if (parsedOrigin.username || parsedOrigin.password) {
67
+ errors.push(`${pathArg} must not carry userinfo`);
68
+ }
69
+ if (parsedOrigin.origin !== valueArg) {
70
+ errors.push(`${pathArg} must be the canonical origin ${parsedOrigin.origin}, `
71
+ + 'without a path, query, fragment, trailing slash or default port');
72
+ }
73
+ return errors;
74
+ };
@@ -0,0 +1,13 @@
1
+ import { externalGatewayBootstrapContract } from '../data/settings.js';
2
+
3
+ /**
4
+ * The one rule a gateway client id is stated in: 1 to
5
+ * `externalGatewayBootstrapContract.maximumGatewayClientIdLength` visible ASCII characters, no
6
+ * whitespace. The id is dcrouter's; this only refuses what could never be one.
7
+ */
8
+ export const isGatewayClientIdText = (valueArg: unknown): valueArg is string => (
9
+ typeof valueArg === 'string'
10
+ && valueArg.length > 0
11
+ && valueArg.length <= externalGatewayBootstrapContract.maximumGatewayClientIdLength
12
+ && /^[\x21-\x7e]+$/.test(valueArg)
13
+ );
@@ -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.
@@ -31,6 +31,11 @@ import type { IMailOverviewDomain, IMailOverviewEmail } from './mail.js';
31
31
  * envelope used by the newer mail contracts. The method strings
32
32
  * 'exportCertificate' and 'importCertificate' likewise keep their deployed
33
33
  * names and deliberately lack a gateway prefix.
34
+ *
35
+ * Over the gateway connector socket an adopted gateway (`data.IGateway`) serves its controller's
36
+ * gateway-client calls without a credential: the socket is authenticated as the gateway and the
37
+ * calls are bound to its `controllerGatewayClientId`. The credential handover
38
+ * (`provisionGatewayClientCredential`, `finalizeGatewayClientCredential`) stays on HTTP.
34
39
  */
35
40
 
36
41
  export interface IReq_GetGatewayCapabilities extends plugins.typedrequestInterfaces.implementsTR<
@@ -257,7 +262,11 @@ export interface IReq_SyncGatewayClientDnsRecord extends plugins.typedrequestInt
257
262
  > {
258
263
  method: 'syncGatewayClientDnsRecord';
259
264
  request: {
260
- apiToken: string;
265
+ /**
266
+ * The gateway client's credential. Required over HTTP, omitted over the connector socket, where
267
+ * the gateway client is the controller-bound one (`data.IGateway` `controllerGatewayClientId`).
268
+ */
269
+ apiToken?: string;
261
270
  identity?: never;
262
271
  ownership: IGatewayClientHostnameOwnership;
263
272
  } & (
@@ -282,7 +291,11 @@ export interface IReq_GetGatewayClientCertificate extends plugins.typedrequestIn
282
291
  > {
283
292
  method: 'getGatewayClientCertificate';
284
293
  request: {
285
- apiToken: string;
294
+ /**
295
+ * The gateway client's credential. Required over HTTP, omitted over the connector socket, where
296
+ * the gateway client is the controller-bound one (`data.IGateway` `controllerGatewayClientId`).
297
+ */
298
+ apiToken?: string;
286
299
  identity?: never;
287
300
  ownership: IGatewayClientHostnameOwnership;
288
301
  };
@@ -301,7 +314,11 @@ export interface IReq_ReleaseGatewayClientCertificate extends plugins.typedreque
301
314
  > {
302
315
  method: 'releaseGatewayClientCertificate';
303
316
  request: {
304
- apiToken: string;
317
+ /**
318
+ * The gateway client's credential. Required over HTTP, omitted over the connector socket, where
319
+ * the gateway client is the controller-bound one (`data.IGateway` `controllerGatewayClientId`).
320
+ */
321
+ apiToken?: string;
305
322
  identity?: never;
306
323
  ownership: IGatewayClientHostnameOwnership;
307
324
  };
@@ -0,0 +1,179 @@
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. Either side
21
+ * refuses a request by one of `data.gatewayConnectorRefusals`, as a `TypedResponseError` whose
22
+ * `errorData` is `data.IGatewayConnectorRefusalErrorData`.
23
+ */
24
+
25
+ /**
26
+ * A gateway redeems an adoption code (`createGatewayAdoptionCode`) with the facts it states about
27
+ * itself. The controller consumes the code and writes the adoption revision in one transaction and
28
+ * answers the gateway's credential once; adopting again with a new code raises the credential
29
+ * generation and the previous generation stops authenticating. Exclude bodies from logs: the
30
+ * request carries the code and the answer the bearer.
31
+ */
32
+ export interface IReq_Gateway_Cloudly_AdoptGateway extends plugins.typedrequestInterfaces.implementsTR<
33
+ plugins.typedrequestInterfaces.ITypedRequest,
34
+ IReq_Gateway_Cloudly_AdoptGateway
35
+ > {
36
+ method: 'adoptGateway';
37
+ request: {
38
+ code: string;
39
+ /** `data.validateGatewayAdoptionFacts`. */
40
+ facts: IGatewayAdoptionFacts;
41
+ };
42
+ response: {
43
+ gatewayId: string;
44
+ /** The gateway stores it and refuses any other controller and any older epoch from then on. */
45
+ controller: IControllerPeerSet;
46
+ /** Answered once; the gateway authenticates its socket as `userId` with `bearer`. */
47
+ credential: { userId: string; generation: number; bearer: string };
48
+ /**
49
+ * The gateway client the controller's existing `requests.gateway`, `requests.mail` and
50
+ * `requests.webpush` calls are bound to once they run over the connector socket; `null` when
51
+ * the controller binds none (`data.IGateway` `controllerGatewayClientId`).
52
+ */
53
+ controllerGatewayClientId: string | null;
54
+ };
55
+ }
56
+
57
+ /**
58
+ * The hello a gateway sends after `registerCloudlyClientSession` on its socket: the gateway is the
59
+ * one the verified machine identity names. The controller answers its current peer set.
60
+ */
61
+ export interface IReq_Gateway_Cloudly_RegisterGatewaySession extends plugins.typedrequestInterfaces.implementsTR<
62
+ plugins.typedrequestInterfaces.ITypedRequest,
63
+ IReq_Gateway_Cloudly_RegisterGatewaySession
64
+ > {
65
+ method: 'registerGatewaySession';
66
+ /** `data.validateRegisterGatewaySessionRequest`. */
67
+ request: IRegisterGatewaySessionRequest;
68
+ response: {
69
+ controller: IControllerPeerSet;
70
+ };
71
+ }
72
+
73
+ /**
74
+ * A gateway pushes its status document after its hello, after every apply and whenever it
75
+ * changes, at most once per `data.gatewayConnectorContract.minimumStatusPushIntervalMs`.
76
+ */
77
+ export interface IReq_Gateway_Cloudly_PushGatewayStatus extends plugins.typedrequestInterfaces.implementsTR<
78
+ plugins.typedrequestInterfaces.ITypedRequest,
79
+ IReq_Gateway_Cloudly_PushGatewayStatus
80
+ > {
81
+ method: 'pushGatewayStatus';
82
+ request: {
83
+ /** `data.validateGatewayStatusDocument`. */
84
+ status: IGatewayStatusDocument;
85
+ };
86
+ response: {};
87
+ }
88
+
89
+ /**
90
+ * The controller pushes a gateway's whole desired state; the gateway answers what it applied.
91
+ *
92
+ * A document equal by `(epoch, revision)` to the one applied is answered with the stored report.
93
+ * The gateway refuses a whole document on the request and never stores the refusal in its report:
94
+ * `request-invalid` when `data.validateGatewayDesiredState` fails, `controller-mismatch` for another
95
+ * controller's document, `gateway-mismatch` for another gateway's and `desired-state-stale` for an
96
+ * older one, whose text names the applied epoch and revision. An area of an accepted document is
97
+ * refused per area in the report (`data.gatewayApplyRefusals`).
98
+ */
99
+ export interface IReq_Cloudly_Gateway_ApplyDesiredState extends plugins.typedrequestInterfaces.implementsTR<
100
+ plugins.typedrequestInterfaces.ITypedRequest,
101
+ IReq_Cloudly_Gateway_ApplyDesiredState
102
+ > {
103
+ method: 'applyDesiredState';
104
+ request: {
105
+ /** `data.validateGatewayDesiredState`. */
106
+ desired: IGatewayDesiredState;
107
+ };
108
+ response: {
109
+ report: IGatewayApplyReport;
110
+ };
111
+ }
112
+
113
+ /**
114
+ * The controller reads one gateway-owned area table, the first step of taking the area over: it
115
+ * writes an import revision of it and pushes it back with `takeover.localDigest` set to `digest`.
116
+ * An area the gateway does not take from a controller (`controllerAreas`) is refused
117
+ * `unsupported-area` (`data.gatewayConnectorRefusals`).
118
+ */
119
+ export interface IReq_Cloudly_Gateway_ExportGatewayArea extends plugins.typedrequestInterfaces.implementsTR<
120
+ plugins.typedrequestInterfaces.ITypedRequest,
121
+ IReq_Cloudly_Gateway_ExportGatewayArea
122
+ > {
123
+ method: 'exportGatewayArea';
124
+ request: {
125
+ area: TGatewayConfigArea;
126
+ };
127
+ /** `data.validateGatewayAreaExport`. */
128
+ response: IGatewayAreaExport;
129
+ }
130
+
131
+ /**
132
+ * An administrator makes a one-time adoption code, either for a new gateway in an existing
133
+ * location or for an existing gateway record (re-adoption). Adoption never creates a location.
134
+ * `command` is the command to run on the gateway's host.
135
+ */
136
+ export interface IReq_Admin_Cloudly_CreateGatewayAdoptionCode extends plugins.typedrequestInterfaces.implementsTR<
137
+ plugins.typedrequestInterfaces.ITypedRequest,
138
+ IReq_Admin_Cloudly_CreateGatewayAdoptionCode
139
+ > {
140
+ method: 'createGatewayAdoptionCode';
141
+ request: {
142
+ identity: IIdentityCredential;
143
+ target:
144
+ | { kind: 'new'; locationId: string; name: string }
145
+ | { kind: 'existing'; gatewayId: string };
146
+ };
147
+ response: {
148
+ code: string;
149
+ /** Unix milliseconds on the controller's clock. */
150
+ expiresAt: number;
151
+ command: string;
152
+ };
153
+ }
154
+
155
+ /**
156
+ * Every gateway the controller records, with whether a socket carries it now and the status
157
+ * document it pushed last. `locationScope` narrows the answer to one location's gateways; a
158
+ * Cloudly that applied it echoes it as `appliedLocationScope`.
159
+ */
160
+ export interface IReq_Admin_Cloudly_GetGateways extends plugins.typedrequestInterfaces.implementsTR<
161
+ plugins.typedrequestInterfaces.ITypedRequest,
162
+ IReq_Admin_Cloudly_GetGateways
163
+ > {
164
+ method: 'getGateways';
165
+ request: {
166
+ identity: IIdentityCredential;
167
+ locationScope?: ILocationScope;
168
+ };
169
+ response: {
170
+ gateways: {
171
+ gateway: IGateway;
172
+ connected: boolean;
173
+ status: IGatewayStatusDocument | null;
174
+ /** Unix milliseconds on the controller's clock when `status` arrived; `null` with it. */
175
+ statusAt: number | null;
176
+ }[];
177
+ appliedLocationScope?: ILocationScope;
178
+ };
179
+ }
@@ -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: {
@@ -5,6 +5,7 @@ import type { IActiveSecretRecipientMetadata } from '../data/secret.js';
5
5
  import type { ICloudlySettings, IExternalGatewayEnrollmentState } from '../data/settings.js';
6
6
  import type { IIdentity, IIdentityCredential } from '../data/user.js';
7
7
  import { readDataProperties, hasExactKeys } from '../private/dataproperties.js';
8
+ import { isGatewayClientIdText } from '../private/gatewayclientid.js';
8
9
 
9
10
  // Get Settings
10
11
  export interface IRequest_GetSettings extends plugins.typedrequestInterfaces.ITypedRequest {
@@ -151,10 +152,7 @@ const validateExpectedGatewayTarget = (urlArg: unknown, clientIdArg: unknown): s
151
152
  || url.hash !== '') {
152
153
  errors.push('bootstrap expectedGatewayUrl must be an HTTPS URL without credentials, query or fragment');
153
154
  }
154
- if (typeof clientIdArg !== 'string'
155
- || clientIdArg.length === 0
156
- || clientIdArg.length > settingsData.externalGatewayBootstrapContract.maximumGatewayClientIdLength
157
- || !/^[\x21-\x7e]+$/.test(clientIdArg)) {
155
+ if (!isGatewayClientIdText(clientIdArg)) {
158
156
  errors.push('bootstrap expectedGatewayClientId must be a bounded identifier without whitespace');
159
157
  }
160
158
  return errors;
@@ -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';