@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
@@ -0,0 +1,347 @@
1
+ import { type IControllerPeerSet } from './controller.js';
2
+ import type { TSha256Digest } from './immutableimage.js';
3
+ /**
4
+ * Every configuration area of a gateway, in the one order a gateway applies a desired state's
5
+ * areas in. Each area is one whole table with exactly one owner per gateway: the gateway itself or
6
+ * its controller.
7
+ */
8
+ export declare const gatewayConfigAreaApplyOrder: readonly ["security", "dns", "routes", "mail", "edges"];
9
+ /** One configuration area of a gateway. */
10
+ export type TGatewayConfigArea = typeof gatewayConfigAreaApplyOrder[number];
11
+ /** True for one of `gatewayConfigAreaApplyOrder`. */
12
+ export declare const isGatewayConfigArea: (valueArg: unknown) => valueArg is TGatewayConfigArea;
13
+ export declare const gatewayConnectorContract: Readonly<{
14
+ /** The digest domain of `computeGatewayAreaTableDigest`. */
15
+ readonly areaTableDigestDomain: 'serve.zone/gateway-area-table';
16
+ /** A gateway pushes its status document at most once in this many milliseconds. */
17
+ readonly minimumStatusPushIntervalMs: 5000;
18
+ /** Each of `publicIps`, `proxyIps` and `forwardSourceAddresses`. */
19
+ readonly maximumAddresses: 64;
20
+ /** Ranges per transport in `IGatewayStatusDocument.listeningPorts`; a range of any width counts once. */
21
+ readonly maximumListeningPortRanges: 1024;
22
+ readonly maximumDnsZones: 1024;
23
+ readonly maximumHostnameLength: 253;
24
+ readonly maximumRefusalDetailLength: 1024;
25
+ readonly maximumStorageBackendLength: 64;
26
+ readonly maximumStoragePathLength: 4096;
27
+ }>;
28
+ /**
29
+ * True for a gateway name: the location name rule (`isLocationName`), one lowercase RFC 1123 label
30
+ * of 1 to 63 characters. A controller keeps each name on one of its gateways.
31
+ */
32
+ export declare const isGatewayName: (valueArg: unknown) => valueArg is string;
33
+ /**
34
+ * One gateway as its controller records it (`validateGateway`).
35
+ *
36
+ * `connection` says how the two reach each other. A `legacy` gateway is the dcrouter the
37
+ * controller still dials at its URL as the named gateway client. An `adopted` gateway dials the
38
+ * controller and is never dialled, so it carries no URL.
39
+ *
40
+ * The controller gateway is the one gateway whose gateway client the controller's own
41
+ * gateway-client calls (`requests.gateway`, `requests.mail` and `requests.webpush` under control
42
+ * auth) are bound to: a `legacy` gateway by its `gatewayClientId`, an `adopted` one by a non-null
43
+ * `controllerGatewayClientId`. A controller holds at most one.
44
+ */
45
+ export interface IGateway {
46
+ id: string;
47
+ /** Unique among the controller's gateways; `isGatewayName`. */
48
+ name: string;
49
+ /** The location the gateway stands in (`data.ILocation`); every gateway stands in one. */
50
+ locationId: string;
51
+ /**
52
+ * The sources the gateway's forwarded connections arrive from at a node, as canonical address
53
+ * prefixes (`192.0.2.10/32`) under the rules of `validateClusterRouteSourceAllowList`; empty when
54
+ * none is known. A cluster ingress admits a non-public hostname only from the union of every
55
+ * gateway's prefixes. The plain addresses a gateway states (`IGatewayAdoptionFacts`,
56
+ * `IGatewayStatusDocument` `forwardSourceAddresses`) become host prefixes here: `/32` for IPv4,
57
+ * `/128` for IPv6.
58
+ */
59
+ forwardSourcePrefixes: string[];
60
+ connection: {
61
+ kind: 'legacy';
62
+ /**
63
+ * The dcrouter URL the controller dials: an absolute `http` or `https` URL in its canonical
64
+ * spelling, without userinfo, query, fragment or trailing slash.
65
+ */
66
+ url: string;
67
+ /** The gateway client the controller's calls run as. */
68
+ gatewayClientId: string;
69
+ } | {
70
+ kind: 'adopted';
71
+ /** Unix milliseconds on the controller's clock. */
72
+ adoptedAt: number;
73
+ /** The machine identity the gateway authenticates as. */
74
+ machineUserId: string;
75
+ /** Raised by every re-adoption; the previous generation is dead from then on. */
76
+ credentialGeneration: number;
77
+ /**
78
+ * The one gateway client the controller's gateway-client calls are bound to over the
79
+ * connector socket.
80
+ *
81
+ * - A `new` adoption binds `null`; the gateway then refuses those calls
82
+ * `gateway-client-unbound`.
83
+ * - An `existing` re-adoption of a legacy gateway moves its `gatewayClientId` into this field.
84
+ * - A re-adoption of an already adopted gateway keeps this field unchanged, `null` included.
85
+ * - No operation changes a non-null binding to another value.
86
+ */
87
+ controllerGatewayClientId: string | null;
88
+ };
89
+ }
90
+ /** What a gateway states about itself when it is adopted (`adoptGateway`). */
91
+ export interface IGatewayAdoptionFacts {
92
+ /** The dcrouter release the gateway runs (`data.isReleaseVersion`). */
93
+ dcrouterVersion: string;
94
+ /** The release of this package the gateway speaks (`data.isReleaseVersion`). */
95
+ interfacesVersion: string;
96
+ /** The host name of the gateway's machine: dot-separated RFC 1123 labels. */
97
+ hostname: string;
98
+ /** Canonical IPv4 or IPv6 addresses, each at most once. */
99
+ publicIps: string[];
100
+ /** Canonical IPv4 or IPv6 addresses, each at most once. */
101
+ proxyIps: string[];
102
+ /** Canonical IPv4 or IPv6 addresses, each at most once. */
103
+ forwardSourceAddresses: string[];
104
+ /**
105
+ * The areas this gateway can take from a controller, as a canonical token list (sorted by
106
+ * `compareWireTokens`, each once). A controller never pushes an area the gateway does not name.
107
+ */
108
+ controllerAreas: TGatewayConfigArea[];
109
+ }
110
+ /** One whole area table of a desired state. */
111
+ export interface IGatewayAreaTable {
112
+ area: TGatewayConfigArea;
113
+ /** `computeGatewayAreaTableDigest(area, content)`. */
114
+ digest: TSha256Digest;
115
+ /**
116
+ * The whole table, strict canonical JSON. Untyped in this contract: each area's content type and
117
+ * validator ship with the release that moves that area to the controller.
118
+ */
119
+ content: unknown;
120
+ /**
121
+ * Set on the push that moves the area from the gateway to the controller: the digest
122
+ * `exportGatewayArea` answered. The gateway applies it only while its local table still has that
123
+ * digest and refuses `local-changed-since-export` otherwise. `null` on every other push.
124
+ */
125
+ takeover: {
126
+ localDigest: TSha256Digest;
127
+ } | null;
128
+ }
129
+ /**
130
+ * The whole desired state a controller pushes to one gateway (`applyDesiredState`).
131
+ *
132
+ * Documents are ordered by `(epoch, revision)` (`data.compareControllerRevisionOrder`): a newer one
133
+ * is applied, an equal one is an idempotent replay answered with the stored report, and an older
134
+ * one is refused `desired-state-stale` (`gatewayConnectorRefusals`).
135
+ */
136
+ export interface IGatewayDesiredState {
137
+ gatewayId: string;
138
+ controllerId: string;
139
+ epoch: number;
140
+ revision: number;
141
+ /** One table per controller-owned area, each area at most once. */
142
+ areas: IGatewayAreaTable[];
143
+ }
144
+ /**
145
+ * Every reason one side of the gateway connector answers instead of a request. The controller
146
+ * answers them instead of `adoptGateway`, `registerGatewaySession`, `pushGatewayStatus` and
147
+ * `createGatewayAdoptionCode`, and instead of a legacy gateway setting it no longer owns. The
148
+ * gateway answers them instead of a whole `applyDesiredState` document, an `exportGatewayArea`, a
149
+ * gateway-client call on the connector socket, or an HTTP call authenticated with a token of its
150
+ * controller-bound gateway client.
151
+ *
152
+ * Each is answered as a `TypedResponseError` whose `errorData` is
153
+ * `IGatewayConnectorRefusalErrorData` and whose text carries the detail, so a peer acts on the code
154
+ * without reading prose. A refusal of one area inside an applied document is none of these: the
155
+ * gateway reports it per area (`gatewayApplyRefusals`). An adoption code that names no location is
156
+ * refused `location-not-found` from `locationRefusals`.
157
+ */
158
+ export declare const gatewayConnectorRefusals: readonly ["adoption-code-unknown", "adoption-code-expired", "adoption-code-used", "gateway-name-taken", "gateway-not-found", "controller-origin-invalid", "credential-generation-stale", "registration-sequence-not-advancing", "controller-mismatch", "controller-epoch-ahead", "gateway-session-required", "status-too-frequent", "controller-gateway-adopted", "request-invalid", "desired-state-stale", "gateway-mismatch", "unsupported-area", "gateway-client-unbound"];
159
+ /** One of the reasons one side of the gateway connector answers instead of a request. */
160
+ export type TGatewayConnectorRefusal = typeof gatewayConnectorRefusals[number];
161
+ /** A connector refusal as `TypedResponseError.errorData`; the error text carries its detail. */
162
+ export interface IGatewayConnectorRefusalErrorData {
163
+ code: TGatewayConnectorRefusal;
164
+ /** Never: the same request is refused again until the state the code names has changed. */
165
+ retryable: false;
166
+ }
167
+ /** True for one of `gatewayConnectorRefusals`. */
168
+ export declare const isGatewayConnectorRefusal: (valueArg: unknown) => valueArg is TGatewayConnectorRefusal;
169
+ /**
170
+ * Every reason a gateway refuses an area of a desired state it accepted as a whole. Each is
171
+ * reported per area in `IGatewayAreaApplyState.refusal`. A refusal of the whole document (stale,
172
+ * from another controller, for another gateway, invalid) is answered on the request instead
173
+ * (`gatewayConnectorRefusals`) and never stored in a report.
174
+ */
175
+ export declare const gatewayApplyRefusals: readonly ["invalid-table", "unsupported-area", "local-changed-since-export", "apply-failed"];
176
+ /** One of the reasons a gateway refuses an area of a desired state. */
177
+ export type TGatewayApplyRefusal = typeof gatewayApplyRefusals[number];
178
+ /** True for one of `gatewayApplyRefusals`. */
179
+ export declare const isGatewayApplyRefusal: (valueArg: unknown) => valueArg is TGatewayApplyRefusal;
180
+ /** Where one area of one gateway stands after the last desired state it received. */
181
+ export interface IGatewayAreaApplyState {
182
+ area: TGatewayConfigArea;
183
+ /** Who writes the area on this gateway. It moves to `controller` once and never back. */
184
+ owner: 'gateway' | 'controller';
185
+ /** The digest of the table the gateway serves for the area; `null` while it serves none. */
186
+ digest: TSha256Digest | null;
187
+ /** The controller revision of that table; `null` for a table no controller pushed. */
188
+ revision: number | null;
189
+ /**
190
+ * `applied` with no refusal; `rejected` with the refusal; `not-attempted` for an area a gateway
191
+ * did not reach because an earlier area of the same document was refused.
192
+ */
193
+ state: 'applied' | 'rejected' | 'not-attempted';
194
+ refusal: {
195
+ reason: TGatewayApplyRefusal;
196
+ detail: string;
197
+ } | null;
198
+ }
199
+ /** What a gateway applied, as `applyDesiredState` answers and the status document carries it. */
200
+ export interface IGatewayApplyReport {
201
+ /** The epoch of the last document applied whole; `null` before the first. */
202
+ epoch: number | null;
203
+ /**
204
+ * The revision of the last document applied whole; `null` before the first. It advances only
205
+ * when every area of a document is applied, so a gateway applied revision N exactly when this is
206
+ * at least N.
207
+ */
208
+ appliedRevision: number | null;
209
+ /** Each area at most once. */
210
+ areas: IGatewayAreaApplyState[];
211
+ }
212
+ /**
213
+ * An inclusive range of ports a gateway listens on, as a route's `match.ports` states it
214
+ * (SmartProxy's `{ from, to }`); one port is `{ from: port, to: port }`.
215
+ */
216
+ export interface IGatewayPortRange {
217
+ /** 1 to 65535. */
218
+ from: number;
219
+ /** `from` to 65535. */
220
+ to: number;
221
+ }
222
+ /**
223
+ * Every port a gateway listens on, per socket transport; each list in the canonical range form:
224
+ * sorted by `from`, and each range starts at least two ports after the previous one ends, so ranges
225
+ * neither overlap nor touch (a gateway merges `{ 80, 80 }` and `{ 81, 81 }` into `{ 80, 81 }`), at
226
+ * most `gatewayConnectorContract.maximumListeningPortRanges` ranges per transport.
227
+ *
228
+ * A gateway reports every public socket it has open, not only its SmartProxy routes. dcrouter
229
+ * derives a route's transports as its inbound proxy listener keys do: `match.transport` `udp` is
230
+ * udp, `all` is both, `tcp` or absent is tcp. QUIC and HTTP/3 count under udp. Each transport is
231
+ * merged on its own, never across transports, so one port may appear in both lists.
232
+ */
233
+ export interface IGatewayListeningPorts {
234
+ tcp: IGatewayPortRange[];
235
+ udp: IGatewayPortRange[];
236
+ }
237
+ /**
238
+ * Everything a gateway reports about itself, in one document (`pushGatewayStatus`). It is also
239
+ * what the gateway's own status page and CLI read.
240
+ */
241
+ export interface IGatewayStatusDocument {
242
+ gatewayId: string;
243
+ /** `data.isReleaseVersion`. */
244
+ dcrouterVersion: string;
245
+ /** `data.isReleaseVersion`. */
246
+ interfacesVersion: string;
247
+ /** The controller the gateway stored. */
248
+ controller: IControllerPeerSet;
249
+ /** Unix milliseconds since the current controller connection; `null` while disconnected. */
250
+ connectedSince: number | null;
251
+ applied: IGatewayApplyReport;
252
+ /** Unix milliseconds of the last whole apply; `null` before the first. */
253
+ appliedAt: number | null;
254
+ publicIps: string[];
255
+ proxyIps: string[];
256
+ forwardSourceAddresses: string[];
257
+ /** Every port the gateway listens on, per transport (`IGatewayListeningPorts`). */
258
+ listeningPorts: IGatewayListeningPorts;
259
+ storage: {
260
+ backend: string;
261
+ path: string | null;
262
+ };
263
+ /** Each zone at most once. */
264
+ dnsZones: {
265
+ zone: string;
266
+ recordsServed: number;
267
+ }[];
268
+ }
269
+ /**
270
+ * The hello a gateway sends after `registerCloudlyClientSession` on its socket. The gateway is the
271
+ * one the verified machine identity names and is never a field here.
272
+ */
273
+ export interface IRegisterGatewaySessionRequest {
274
+ /**
275
+ * Counts up once per attempt within one gateway process and restarts at 0 with the process; a
276
+ * controller refuses one that does not advance.
277
+ */
278
+ registrationSequence: number;
279
+ /** `data.isReleaseVersion`. */
280
+ dcrouterVersion: string;
281
+ /** `data.isReleaseVersion`. */
282
+ interfacesVersion: string;
283
+ /** As in `IGatewayAdoptionFacts.controllerAreas`. */
284
+ controllerAreas: TGatewayConfigArea[];
285
+ /** The controller and epoch the gateway stored; `null` when it stored none. */
286
+ known: {
287
+ controllerId: string;
288
+ epoch: number;
289
+ } | null;
290
+ applied: IGatewayApplyReport;
291
+ }
292
+ /** One area table as the gateway holds it locally, as `exportGatewayArea` answers it. */
293
+ export interface IGatewayAreaExport {
294
+ area: TGatewayConfigArea;
295
+ /** `computeGatewayAreaTableDigest(area, content)`. */
296
+ digest: TSha256Digest;
297
+ content: unknown;
298
+ }
299
+ /**
300
+ * The canonical JSON an area table digest hashes: the digest domain, the area and the whole
301
+ * content. Throws for an unknown area and for content that is not strict canonical JSON (safe
302
+ * integers only, no `undefined`, no cycle, no accessor).
303
+ */
304
+ export declare const createGatewayAreaTableDigestInput: (areaArg: TGatewayConfigArea, contentArg: unknown) => string;
305
+ /**
306
+ * `sha256:<hex>` of `createGatewayAreaTableDigestInput`, through Web Crypto. The controller and the
307
+ * gateway digest a table with this one function, so an exported local table and the controller's
308
+ * compiled table of the same content have the same digest.
309
+ */
310
+ export declare const computeGatewayAreaTableDigest: (areaArg: TGatewayConfigArea, contentArg: unknown) => Promise<TSha256Digest>;
311
+ /**
312
+ * Validates one desired state and names every reason it is refused.
313
+ *
314
+ * The envelope only: every table's digest has the digest form and its content is strict canonical
315
+ * JSON, but whether the digest is `computeGatewayAreaTableDigest` of the content, what the content
316
+ * of an area must hold, and how the document orders against the one applied are the gateway's to
317
+ * judge (`invalid-table`, `desired-state-stale`).
318
+ */
319
+ export declare const validateGatewayDesiredState: (valueArg: unknown, pathArg?: string) => string[];
320
+ /** Validates one apply report and names every reason it is refused. */
321
+ export declare const validateGatewayApplyReport: (valueArg: unknown, pathArg?: string) => string[];
322
+ /** Validates the facts a gateway states at adoption and names every reason they are refused. */
323
+ export declare const validateGatewayAdoptionFacts: (valueArg: unknown, pathArg?: string) => string[];
324
+ /**
325
+ * Validates one status document and names every reason it is refused. A controller stores a
326
+ * status document only when this returns no errors.
327
+ */
328
+ export declare const validateGatewayStatusDocument: (valueArg: unknown, pathArg?: string) => string[];
329
+ /**
330
+ * Validates one gateway session hello and names every reason it is refused.
331
+ *
332
+ * Shape only: whether the sequence advances, and whether `known` names this controller at an
333
+ * epoch it may hold, is the controller's to decide against the session it holds.
334
+ */
335
+ export declare const validateRegisterGatewaySessionRequest: (valueArg: unknown, pathArg?: string) => string[];
336
+ /**
337
+ * Validates one exported area table and names every reason it is refused. Whether the digest is
338
+ * `computeGatewayAreaTableDigest` of the content is the controller's to check.
339
+ */
340
+ export declare const validateGatewayAreaExport: (valueArg: unknown, pathArg?: string) => string[];
341
+ /**
342
+ * Validates one gateway record and names every reason it is refused.
343
+ *
344
+ * The record alone: whether its name is unique, its location exists and at most one gateway is the
345
+ * controller gateway is the controller's to judge against the gateways it records.
346
+ */
347
+ export declare const validateGateway: (valueArg: unknown, pathArg?: string) => string[];