@serve.zone/interfaces 32.76.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.
- package/changelog.md +7 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/backup.d.ts +3 -1
- package/dist_ts/data/backup.js +1 -1
- package/dist_ts/data/controller.d.ts +24 -2
- package/dist_ts/data/controller.js +97 -3
- package/dist_ts/data/gatewayconnector.d.ts +76 -7
- package/dist_ts/data/gatewayconnector.js +200 -24
- package/dist_ts/data/user.d.ts +8 -2
- package/dist_ts/private/controllercontract.d.ts +2 -0
- package/dist_ts/private/controllercontract.js +15 -1
- package/dist_ts/private/gatewayclientid.d.ts +6 -0
- package/dist_ts/private/gatewayclientid.js +11 -0
- package/dist_ts/requests/gateway.d.ts +20 -3
- package/dist_ts/requests/gatewayconnector.d.ts +11 -2
- package/dist_ts/requests/settings.js +3 -5
- package/package.json +1 -1
- package/readme.md +54 -6
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/backup.ts +3 -1
- package/ts/data/controller.ts +115 -3
- package/ts/data/gatewayconnector.ts +269 -28
- package/ts/data/user.ts +8 -2
- package/ts/private/controllercontract.ts +15 -0
- package/ts/private/gatewayclientid.ts +13 -0
- package/ts/requests/gateway.ts +20 -3
- package/ts/requests/gatewayconnector.ts +14 -3
- package/ts/requests/settings.ts +2 -4
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
|
-
|
|
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
|
|
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[];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The value rules the controller contracts (`data/controller.ts`, `data/gatewayconnector.ts`) share,
|
|
3
3
|
* stated as refusals a validator can collect so it names every reason a body is refused.
|
|
4
4
|
*/
|
|
5
|
+
import { canonicalizeStrictJson } from './canonicaljson.js';
|
|
5
6
|
import { networkId } from './networkcontract.js';
|
|
6
7
|
|
|
7
8
|
/** The generic canonical identifier: the rule `networkId` reads, never a second spelling of it. */
|
|
@@ -29,6 +30,20 @@ export const validateControllerNonNegativeInteger = (valueArg: unknown, pathArg:
|
|
|
29
30
|
: [`${pathArg} must be a non-negative safe integer`]
|
|
30
31
|
);
|
|
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
|
+
|
|
32
47
|
/** A canonical `https` origin: no userinfo, path, query, fragment, trailing slash or default port. */
|
|
33
48
|
export const validateControllerOrigin = (
|
|
34
49
|
valueArg: unknown,
|
|
@@ -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
|
+
);
|
package/ts/requests/gateway.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
};
|
|
@@ -17,7 +17,9 @@ import type { IIdentityCredential } from '../data/user.js';
|
|
|
17
17
|
* The gateway connector (AGL-1182). A gateway dials its controller on the controller's typedsocket
|
|
18
18
|
* server; the controller never dials an adopted gateway. `Gateway_Cloudly` requests travel from the
|
|
19
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.
|
|
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`.
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -44,8 +46,9 @@ export interface IReq_Gateway_Cloudly_AdoptGateway extends plugins.typedrequestI
|
|
|
44
46
|
/** Answered once; the gateway authenticates its socket as `userId` with `bearer`. */
|
|
45
47
|
credential: { userId: string; generation: number; bearer: string };
|
|
46
48
|
/**
|
|
47
|
-
* The gateway client the controller's existing `requests.gateway
|
|
48
|
-
* bound to once they run over the connector socket; `null` when
|
|
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`).
|
|
49
52
|
*/
|
|
50
53
|
controllerGatewayClientId: string | null;
|
|
51
54
|
};
|
|
@@ -85,7 +88,13 @@ export interface IReq_Gateway_Cloudly_PushGatewayStatus extends plugins.typedreq
|
|
|
85
88
|
|
|
86
89
|
/**
|
|
87
90
|
* The controller pushes a gateway's whole desired state; the gateway answers what it applied.
|
|
91
|
+
*
|
|
88
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`).
|
|
89
98
|
*/
|
|
90
99
|
export interface IReq_Cloudly_Gateway_ApplyDesiredState extends plugins.typedrequestInterfaces.implementsTR<
|
|
91
100
|
plugins.typedrequestInterfaces.ITypedRequest,
|
|
@@ -104,6 +113,8 @@ export interface IReq_Cloudly_Gateway_ApplyDesiredState extends plugins.typedreq
|
|
|
104
113
|
/**
|
|
105
114
|
* The controller reads one gateway-owned area table, the first step of taking the area over: it
|
|
106
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`).
|
|
107
118
|
*/
|
|
108
119
|
export interface IReq_Cloudly_Gateway_ExportGatewayArea extends plugins.typedrequestInterfaces.implementsTR<
|
|
109
120
|
plugins.typedrequestInterfaces.ITypedRequest,
|
package/ts/requests/settings.ts
CHANGED
|
@@ -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 (
|
|
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;
|