@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
@@ -0,0 +1,278 @@
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
+ * One gateway as its controller records it.
30
+ *
31
+ * `connection` says how the two reach each other. A `legacy` gateway is the dcrouter the
32
+ * controller still dials at its URL as the named gateway client. An `adopted` gateway dials the
33
+ * controller and is never dialled, so it carries no URL.
34
+ */
35
+ export interface IGateway {
36
+ id: string;
37
+ name: string;
38
+ /** The location the gateway stands in (`data.ILocation`); every gateway stands in one. */
39
+ locationId: string;
40
+ forwardSourceAddresses: string[];
41
+ connection: {
42
+ kind: 'legacy';
43
+ url: string;
44
+ gatewayClientId: string;
45
+ } | {
46
+ kind: 'adopted';
47
+ /** Unix milliseconds on the controller's clock. */
48
+ adoptedAt: number;
49
+ /** The machine identity the gateway authenticates as. */
50
+ machineUserId: string;
51
+ /** Raised by every re-adoption; the previous generation is dead from then on. */
52
+ credentialGeneration: number;
53
+ };
54
+ }
55
+ /** What a gateway states about itself when it is adopted (`adoptGateway`). */
56
+ export interface IGatewayAdoptionFacts {
57
+ /** The dcrouter release the gateway runs (`data.isReleaseVersion`). */
58
+ dcrouterVersion: string;
59
+ /** The release of this package the gateway speaks (`data.isReleaseVersion`). */
60
+ interfacesVersion: string;
61
+ /** The host name of the gateway's machine: dot-separated RFC 1123 labels. */
62
+ hostname: string;
63
+ /** Canonical IPv4 or IPv6 addresses, each at most once. */
64
+ publicIps: string[];
65
+ /** Canonical IPv4 or IPv6 addresses, each at most once. */
66
+ proxyIps: string[];
67
+ /** Canonical IPv4 or IPv6 addresses, each at most once. */
68
+ forwardSourceAddresses: string[];
69
+ /**
70
+ * The areas this gateway can take from a controller, as a canonical token list (sorted by
71
+ * `compareWireTokens`, each once). A controller never pushes an area the gateway does not name.
72
+ */
73
+ controllerAreas: TGatewayConfigArea[];
74
+ }
75
+ /** One whole area table of a desired state. */
76
+ export interface IGatewayAreaTable {
77
+ area: TGatewayConfigArea;
78
+ /** `computeGatewayAreaTableDigest(area, content)`. */
79
+ digest: TSha256Digest;
80
+ /**
81
+ * The whole table, strict canonical JSON. Untyped in this contract: each area's content type and
82
+ * validator ship with the release that moves that area to the controller.
83
+ */
84
+ content: unknown;
85
+ /**
86
+ * Set on the push that moves the area from the gateway to the controller: the digest
87
+ * `exportGatewayArea` answered. The gateway applies it only while its local table still has that
88
+ * digest and refuses `local-changed-since-export` otherwise. `null` on every other push.
89
+ */
90
+ takeover: {
91
+ localDigest: TSha256Digest;
92
+ } | null;
93
+ }
94
+ /**
95
+ * The whole desired state a controller pushes to one gateway (`applyDesiredState`).
96
+ *
97
+ * Documents are ordered by `(epoch, revision)` (`data.compareControllerRevisionOrder`): a newer one
98
+ * is applied, an equal one is an idempotent replay answered with the stored report, and an older
99
+ * one is refused `stale`.
100
+ */
101
+ export interface IGatewayDesiredState {
102
+ gatewayId: string;
103
+ controllerId: string;
104
+ epoch: number;
105
+ revision: number;
106
+ /** One table per controller-owned area, each area at most once. */
107
+ areas: IGatewayAreaTable[];
108
+ }
109
+ /**
110
+ * Every reason a gateway refuses an area of a desired state. Each is reported per area in
111
+ * `IGatewayAreaApplyState.refusal`.
112
+ */
113
+ export declare const gatewayApplyRefusals: readonly ["stale", "controller-mismatch", "invalid-table", "unsupported-area", "local-changed-since-export", "apply-failed"];
114
+ /** One of the reasons a gateway refuses an area of a desired state. */
115
+ export type TGatewayApplyRefusal = typeof gatewayApplyRefusals[number];
116
+ /** True for one of `gatewayApplyRefusals`. */
117
+ export declare const isGatewayApplyRefusal: (valueArg: unknown) => valueArg is TGatewayApplyRefusal;
118
+ /** Where one area of one gateway stands after the last desired state it received. */
119
+ export interface IGatewayAreaApplyState {
120
+ area: TGatewayConfigArea;
121
+ /** Who writes the area on this gateway. It moves to `controller` once and never back. */
122
+ owner: 'gateway' | 'controller';
123
+ /** The digest of the table the gateway serves for the area; `null` while it serves none. */
124
+ digest: TSha256Digest | null;
125
+ /** The controller revision of that table; `null` for a table no controller pushed. */
126
+ revision: number | null;
127
+ /**
128
+ * `applied` with no refusal; `rejected` with the refusal; `not-attempted` for an area a gateway
129
+ * did not reach because an earlier area of the same document was refused.
130
+ */
131
+ state: 'applied' | 'rejected' | 'not-attempted';
132
+ refusal: {
133
+ reason: TGatewayApplyRefusal;
134
+ detail: string;
135
+ } | null;
136
+ }
137
+ /** What a gateway applied, as `applyDesiredState` answers and the status document carries it. */
138
+ export interface IGatewayApplyReport {
139
+ /** The epoch of the last document applied whole; `null` before the first. */
140
+ epoch: number | null;
141
+ /**
142
+ * The revision of the last document applied whole; `null` before the first. It advances only
143
+ * when every area of a document is applied, so a gateway applied revision N exactly when this is
144
+ * at least N.
145
+ */
146
+ appliedRevision: number | null;
147
+ /** Each area at most once. */
148
+ areas: IGatewayAreaApplyState[];
149
+ }
150
+ /**
151
+ * An inclusive range of ports a gateway listens on, as a route's `match.ports` states it
152
+ * (SmartProxy's `{ from, to }`); one port is `{ from: port, to: port }`.
153
+ */
154
+ export interface IGatewayPortRange {
155
+ /** 1 to 65535. */
156
+ from: number;
157
+ /** `from` to 65535. */
158
+ to: number;
159
+ }
160
+ /**
161
+ * Every port a gateway listens on, per socket transport; each list in the canonical range form:
162
+ * sorted by `from`, and each range starts at least two ports after the previous one ends, so ranges
163
+ * neither overlap nor touch (a gateway merges `{ 80, 80 }` and `{ 81, 81 }` into `{ 80, 81 }`), at
164
+ * most `gatewayConnectorContract.maximumListeningPortRanges` ranges per transport.
165
+ *
166
+ * A gateway reports every public socket it has open, not only its SmartProxy routes. dcrouter
167
+ * derives a route's transports as its inbound proxy listener keys do: `match.transport` `udp` is
168
+ * udp, `all` is both, `tcp` or absent is tcp. QUIC and HTTP/3 count under udp. Each transport is
169
+ * merged on its own, never across transports, so one port may appear in both lists.
170
+ */
171
+ export interface IGatewayListeningPorts {
172
+ tcp: IGatewayPortRange[];
173
+ udp: IGatewayPortRange[];
174
+ }
175
+ /**
176
+ * Everything a gateway reports about itself, in one document (`pushGatewayStatus`). It is also
177
+ * what the gateway's own status page and CLI read.
178
+ */
179
+ export interface IGatewayStatusDocument {
180
+ gatewayId: string;
181
+ /** `data.isReleaseVersion`. */
182
+ dcrouterVersion: string;
183
+ /** `data.isReleaseVersion`. */
184
+ interfacesVersion: string;
185
+ /** The controller the gateway stored. */
186
+ controller: IControllerPeerSet;
187
+ /** Unix milliseconds since the current controller connection; `null` while disconnected. */
188
+ connectedSince: number | null;
189
+ applied: IGatewayApplyReport;
190
+ /** Unix milliseconds of the last whole apply; `null` before the first. */
191
+ appliedAt: number | null;
192
+ publicIps: string[];
193
+ proxyIps: string[];
194
+ forwardSourceAddresses: string[];
195
+ /** Every port the gateway listens on, per transport (`IGatewayListeningPorts`). */
196
+ listeningPorts: IGatewayListeningPorts;
197
+ storage: {
198
+ backend: string;
199
+ path: string | null;
200
+ };
201
+ /** Each zone at most once. */
202
+ dnsZones: {
203
+ zone: string;
204
+ recordsServed: number;
205
+ }[];
206
+ }
207
+ /**
208
+ * The hello a gateway sends after `registerCloudlyClientSession` on its socket. The gateway is the
209
+ * one the verified machine identity names and is never a field here.
210
+ */
211
+ export interface IRegisterGatewaySessionRequest {
212
+ /**
213
+ * Counts up once per attempt within one gateway process and restarts at 0 with the process; a
214
+ * controller refuses one that does not advance.
215
+ */
216
+ registrationSequence: number;
217
+ /** `data.isReleaseVersion`. */
218
+ dcrouterVersion: string;
219
+ /** `data.isReleaseVersion`. */
220
+ interfacesVersion: string;
221
+ /** As in `IGatewayAdoptionFacts.controllerAreas`. */
222
+ controllerAreas: TGatewayConfigArea[];
223
+ /** The controller and epoch the gateway stored; `null` when it stored none. */
224
+ known: {
225
+ controllerId: string;
226
+ epoch: number;
227
+ } | null;
228
+ applied: IGatewayApplyReport;
229
+ }
230
+ /** One area table as the gateway holds it locally, as `exportGatewayArea` answers it. */
231
+ export interface IGatewayAreaExport {
232
+ area: TGatewayConfigArea;
233
+ /** `computeGatewayAreaTableDigest(area, content)`. */
234
+ digest: TSha256Digest;
235
+ content: unknown;
236
+ }
237
+ /**
238
+ * The canonical JSON an area table digest hashes: the digest domain, the area and the whole
239
+ * content. Throws for an unknown area and for content that is not strict canonical JSON (safe
240
+ * integers only, no `undefined`, no cycle, no accessor).
241
+ */
242
+ export declare const createGatewayAreaTableDigestInput: (areaArg: TGatewayConfigArea, contentArg: unknown) => string;
243
+ /**
244
+ * `sha256:<hex>` of `createGatewayAreaTableDigestInput`, through Web Crypto. The controller and the
245
+ * gateway digest a table with this one function, so an exported local table and the controller's
246
+ * compiled table of the same content have the same digest.
247
+ */
248
+ export declare const computeGatewayAreaTableDigest: (areaArg: TGatewayConfigArea, contentArg: unknown) => Promise<TSha256Digest>;
249
+ /**
250
+ * Validates one desired state and names every reason it is refused.
251
+ *
252
+ * The envelope only: every table's digest has the digest form and its content is strict canonical
253
+ * JSON, but whether the digest is `computeGatewayAreaTableDigest` of the content, what the content
254
+ * of an area must hold, and how the document orders against the one applied are the gateway's to
255
+ * judge (`invalid-table`, `stale`).
256
+ */
257
+ export declare const validateGatewayDesiredState: (valueArg: unknown, pathArg?: string) => string[];
258
+ /** Validates one apply report and names every reason it is refused. */
259
+ export declare const validateGatewayApplyReport: (valueArg: unknown, pathArg?: string) => string[];
260
+ /** Validates the facts a gateway states at adoption and names every reason they are refused. */
261
+ export declare const validateGatewayAdoptionFacts: (valueArg: unknown, pathArg?: string) => string[];
262
+ /**
263
+ * Validates one status document and names every reason it is refused. A controller stores a
264
+ * status document only when this returns no errors.
265
+ */
266
+ export declare const validateGatewayStatusDocument: (valueArg: unknown, pathArg?: string) => string[];
267
+ /**
268
+ * Validates one gateway session hello and names every reason it is refused.
269
+ *
270
+ * Shape only: whether the sequence advances, and whether `known` names this controller at an
271
+ * epoch it may hold, is the controller's to decide against the session it holds.
272
+ */
273
+ export declare const validateRegisterGatewaySessionRequest: (valueArg: unknown, pathArg?: string) => string[];
274
+ /**
275
+ * Validates one exported area table and names every reason it is refused. Whether the digest is
276
+ * `computeGatewayAreaTableDigest` of the content is the controller's to check.
277
+ */
278
+ export declare const validateGatewayAreaExport: (valueArg: unknown, pathArg?: string) => string[];